LCOV - code coverage report
Current view: top level - lib/IR - IntrinsicInst.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 47 47 100.0 %
Date: 2018-06-17 00:07:59 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- InstrinsicInst.cpp - Intrinsic Instruction Wrappers ---------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file implements methods that make it really easy to deal with intrinsic
      11             : // functions.
      12             : //
      13             : // All intrinsic function calls are instances of the call instruction, so these
      14             : // are all subclasses of the CallInst class.  Note that none of these classes
      15             : // has state or virtual methods, which is an important part of this gross/neat
      16             : // hack working.
      17             : //
      18             : // In some cases, arguments to intrinsics need to be generic and are defined as
      19             : // type pointer to empty struct { }*.  To access the real item of interest the
      20             : // cast instruction needs to be stripped away.
      21             : //
      22             : //===----------------------------------------------------------------------===//
      23             : 
      24             : #include "llvm/IR/IntrinsicInst.h"
      25             : #include "llvm/ADT/StringSwitch.h"
      26             : #include "llvm/IR/Constants.h"
      27             : #include "llvm/IR/DebugInfoMetadata.h"
      28             : #include "llvm/IR/GlobalVariable.h"
      29             : #include "llvm/IR/Metadata.h"
      30             : #include "llvm/IR/Module.h"
      31             : #include "llvm/Support/raw_ostream.h"
      32             : using namespace llvm;
      33             : 
      34             : //===----------------------------------------------------------------------===//
      35             : /// DbgInfoIntrinsic - This is the common base class for debug info intrinsics
      36             : ///
      37             : 
      38     1268320 : Value *DbgInfoIntrinsic::getVariableLocation(bool AllowNullOp) const {
      39     1268320 :   Value *Op = getArgOperand(0);
      40     1268320 :   if (AllowNullOp && !Op)
      41             :     return nullptr;
      42             : 
      43     1268320 :   auto *MD = cast<MetadataAsValue>(Op)->getMetadata();
      44             :   if (auto *V = dyn_cast<ValueAsMetadata>(MD))
      45     1258965 :     return V->getValue();
      46             : 
      47             :   // When the value goes to null, it gets replaced by an empty MDNode.
      48             :   assert(!cast<MDNode>(MD)->getNumOperands() && "Expected an empty MDNode");
      49             :   return nullptr;
      50             : }
      51             : 
      52       11316 : Optional<uint64_t> DbgInfoIntrinsic::getFragmentSizeInBits() const {
      53       11316 :   if (auto Fragment = getExpression()->getFragmentInfo())
      54             :     return Fragment->SizeInBits;
      55       11162 :   return getVariable()->getSizeInBits();
      56             : }
      57             : 
      58       96599 : int llvm::Intrinsic::lookupLLVMIntrinsicByName(ArrayRef<const char *> NameTable,
      59             :                                                StringRef Name) {
      60             :   assert(Name.startswith("llvm."));
      61             : 
      62             :   // Do successive binary searches of the dotted name components. For
      63             :   // "llvm.gc.experimental.statepoint.p1i8.p1i32", we will find the range of
      64             :   // intrinsics starting with "llvm.gc", then "llvm.gc.experimental", then
      65             :   // "llvm.gc.experimental.statepoint", and then we will stop as the range is
      66             :   // size 1. During the search, we can skip the prefix that we already know is
      67             :   // identical. By using strncmp we consider names with differing suffixes to
      68             :   // be part of the equal range.
      69             :   size_t CmpStart = 0;
      70             :   size_t CmpEnd = 4; // Skip the "llvm" component.
      71       96599 :   const char *const *Low = NameTable.begin();
      72       96599 :   const char *const *High = NameTable.end();
      73             :   const char *const *LastLow = Low;
      74      639863 :   while (CmpEnd < Name.size() && High - Low > 0) {
      75             :     CmpStart = CmpEnd;
      76      271632 :     CmpEnd = Name.find('.', CmpStart + 1);
      77      188476 :     CmpEnd = CmpEnd == StringRef::npos ? Name.size() : CmpEnd;
      78     3284196 :     auto Cmp = [CmpStart, CmpEnd](const char *LHS, const char *RHS) {
      79     3284196 :       return strncmp(LHS + CmpStart, RHS + CmpStart, CmpEnd - CmpStart) < 0;
      80             :     };
      81             :     LastLow = Low;
      82      543264 :     std::tie(Low, High) = std::equal_range(Low, High, Name.data(), Cmp);
      83             :   }
      84       96599 :   if (High - Low > 0)
      85             :     LastLow = Low;
      86             : 
      87       96599 :   if (LastLow == NameTable.end())
      88             :     return -1;
      89       96599 :   StringRef NameFound = *LastLow;
      90             :   if (Name == NameFound ||
      91       27583 :       (Name.startswith(NameFound) && Name[NameFound.size()] == '.'))
      92       92390 :     return LastLow - NameTable.begin();
      93             :   return -1;
      94             : }
      95             : 
      96         837 : Value *InstrProfIncrementInst::getStep() const {
      97         837 :   if (InstrProfIncrementInstStep::classof(this)) {
      98           2 :     return const_cast<Value *>(getArgOperand(4));
      99             :   }
     100         835 :   const Module *M = getModule();
     101         835 :   LLVMContext &Context = M->getContext();
     102         835 :   return ConstantInt::get(Type::getInt64Ty(Context), 1);
     103             : }
     104             : 
     105             : ConstrainedFPIntrinsic::RoundingMode
     106         303 : ConstrainedFPIntrinsic::getRoundingMode() const {
     107         303 :   unsigned NumOperands = getNumArgOperands();
     108             :   Metadata *MD =
     109         606 :       dyn_cast<MetadataAsValue>(getArgOperand(NumOperands - 2))->getMetadata();
     110         606 :   if (!MD || !isa<MDString>(MD))
     111             :     return rmInvalid;
     112         303 :   StringRef RoundingArg = cast<MDString>(MD)->getString();
     113             : 
     114             :   // For dynamic rounding mode, we use round to nearest but we will set the
     115             :   // 'exact' SDNodeFlag so that the value will not be rounded.
     116         303 :   return StringSwitch<RoundingMode>(RoundingArg)
     117             :     .Case("round.dynamic",    rmDynamic)
     118             :     .Case("round.tonearest",  rmToNearest)
     119             :     .Case("round.downward",   rmDownward)
     120             :     .Case("round.upward",     rmUpward)
     121             :     .Case("round.towardzero", rmTowardZero)
     122             :     .Default(rmInvalid);
     123             : }
     124             : 
     125             : ConstrainedFPIntrinsic::ExceptionBehavior
     126         301 : ConstrainedFPIntrinsic::getExceptionBehavior() const {
     127         301 :   unsigned NumOperands = getNumArgOperands();
     128             :   Metadata *MD =
     129         602 :       dyn_cast<MetadataAsValue>(getArgOperand(NumOperands - 1))->getMetadata();
     130         602 :   if (!MD || !isa<MDString>(MD))
     131             :     return ebInvalid;
     132         301 :   StringRef ExceptionArg = cast<MDString>(MD)->getString();
     133         301 :   return StringSwitch<ExceptionBehavior>(ExceptionArg)
     134             :     .Case("fpexcept.ignore",  ebIgnore)
     135             :     .Case("fpexcept.maytrap", ebMayTrap)
     136             :     .Case("fpexcept.strict",  ebStrict)
     137             :     .Default(ebInvalid);
     138             : }
     139             : 
     140         235 : bool ConstrainedFPIntrinsic::isUnaryOp() const {
     141             :   switch (getIntrinsicID()) {
     142             :     default:
     143             :       return false;
     144         199 :     case Intrinsic::experimental_constrained_sqrt:
     145             :     case Intrinsic::experimental_constrained_sin:
     146             :     case Intrinsic::experimental_constrained_cos:
     147             :     case Intrinsic::experimental_constrained_exp:
     148             :     case Intrinsic::experimental_constrained_exp2:
     149             :     case Intrinsic::experimental_constrained_log:
     150             :     case Intrinsic::experimental_constrained_log10:
     151             :     case Intrinsic::experimental_constrained_log2:
     152             :     case Intrinsic::experimental_constrained_rint:
     153             :     case Intrinsic::experimental_constrained_nearbyint:
     154         199 :       return true;
     155             :   }
     156             : }
     157             : 
     158          63 : bool ConstrainedFPIntrinsic::isTernaryOp() const {
     159          63 :   switch (getIntrinsicID()) {
     160             :     default:
     161             :       return false;
     162          35 :     case Intrinsic::experimental_constrained_fma:
     163          35 :       return true;
     164             :   }
     165             : }
     166             : 

Generated by: LCOV version 1.13