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-07-13 00:08:38 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     1218867 : Value *DbgInfoIntrinsic::getVariableLocation(bool AllowNullOp) const {
      39     1218867 :   Value *Op = getArgOperand(0);
      40     1218867 :   if (AllowNullOp && !Op)
      41             :     return nullptr;
      42             : 
      43     1218867 :   auto *MD = cast<MetadataAsValue>(Op)->getMetadata();
      44             :   if (auto *V = dyn_cast<ValueAsMetadata>(MD))
      45     1209469 :     return V->getValue();
      46             : 
      47             :   // When the value goes to null, it gets replaced by an empty MDNode.
      48             :   assert((isa<DbgLabelInst>(this)
      49             :           || !cast<MDNode>(MD)->getNumOperands())
      50             :          && "DbgValueInst Expected an empty MDNode");
      51             : 
      52             :   return nullptr;
      53             : }
      54             : 
      55       12496 : Optional<uint64_t> DbgInfoIntrinsic::getFragmentSizeInBits() const {
      56       12496 :   if (auto Fragment = getExpression()->getFragmentInfo())
      57             :     return Fragment->SizeInBits;
      58       12340 :   return getVariable()->getSizeInBits();
      59             : }
      60             : 
      61       98044 : int llvm::Intrinsic::lookupLLVMIntrinsicByName(ArrayRef<const char *> NameTable,
      62             :                                                StringRef Name) {
      63             :   assert(Name.startswith("llvm."));
      64             : 
      65             :   // Do successive binary searches of the dotted name components. For
      66             :   // "llvm.gc.experimental.statepoint.p1i8.p1i32", we will find the range of
      67             :   // intrinsics starting with "llvm.gc", then "llvm.gc.experimental", then
      68             :   // "llvm.gc.experimental.statepoint", and then we will stop as the range is
      69             :   // size 1. During the search, we can skip the prefix that we already know is
      70             :   // identical. By using strncmp we consider names with differing suffixes to
      71             :   // be part of the equal range.
      72             :   size_t CmpStart = 0;
      73             :   size_t CmpEnd = 4; // Skip the "llvm" component.
      74       98044 :   const char *const *Low = NameTable.begin();
      75       98044 :   const char *const *High = NameTable.end();
      76             :   const char *const *LastLow = Low;
      77      652208 :   while (CmpEnd < Name.size() && High - Low > 0) {
      78             :     CmpStart = CmpEnd;
      79      277082 :     CmpEnd = Name.find('.', CmpStart + 1);
      80      192570 :     CmpEnd = CmpEnd == StringRef::npos ? Name.size() : CmpEnd;
      81     3323727 :     auto Cmp = [CmpStart, CmpEnd](const char *LHS, const char *RHS) {
      82     3323727 :       return strncmp(LHS + CmpStart, RHS + CmpStart, CmpEnd - CmpStart) < 0;
      83             :     };
      84             :     LastLow = Low;
      85      554164 :     std::tie(Low, High) = std::equal_range(Low, High, Name.data(), Cmp);
      86             :   }
      87       98044 :   if (High - Low > 0)
      88             :     LastLow = Low;
      89             : 
      90       98044 :   if (LastLow == NameTable.end())
      91             :     return -1;
      92       98044 :   StringRef NameFound = *LastLow;
      93             :   if (Name == NameFound ||
      94       28137 :       (Name.startswith(NameFound) && Name[NameFound.size()] == '.'))
      95       93685 :     return LastLow - NameTable.begin();
      96             :   return -1;
      97             : }
      98             : 
      99         837 : Value *InstrProfIncrementInst::getStep() const {
     100         837 :   if (InstrProfIncrementInstStep::classof(this)) {
     101           2 :     return const_cast<Value *>(getArgOperand(4));
     102             :   }
     103         835 :   const Module *M = getModule();
     104         835 :   LLVMContext &Context = M->getContext();
     105         835 :   return ConstantInt::get(Type::getInt64Ty(Context), 1);
     106             : }
     107             : 
     108             : ConstrainedFPIntrinsic::RoundingMode
     109         303 : ConstrainedFPIntrinsic::getRoundingMode() const {
     110         303 :   unsigned NumOperands = getNumArgOperands();
     111             :   Metadata *MD =
     112         606 :       dyn_cast<MetadataAsValue>(getArgOperand(NumOperands - 2))->getMetadata();
     113         606 :   if (!MD || !isa<MDString>(MD))
     114             :     return rmInvalid;
     115         303 :   StringRef RoundingArg = cast<MDString>(MD)->getString();
     116             : 
     117             :   // For dynamic rounding mode, we use round to nearest but we will set the
     118             :   // 'exact' SDNodeFlag so that the value will not be rounded.
     119         303 :   return StringSwitch<RoundingMode>(RoundingArg)
     120             :     .Case("round.dynamic",    rmDynamic)
     121             :     .Case("round.tonearest",  rmToNearest)
     122             :     .Case("round.downward",   rmDownward)
     123             :     .Case("round.upward",     rmUpward)
     124             :     .Case("round.towardzero", rmTowardZero)
     125             :     .Default(rmInvalid);
     126             : }
     127             : 
     128             : ConstrainedFPIntrinsic::ExceptionBehavior
     129         301 : ConstrainedFPIntrinsic::getExceptionBehavior() const {
     130         301 :   unsigned NumOperands = getNumArgOperands();
     131             :   Metadata *MD =
     132         602 :       dyn_cast<MetadataAsValue>(getArgOperand(NumOperands - 1))->getMetadata();
     133         602 :   if (!MD || !isa<MDString>(MD))
     134             :     return ebInvalid;
     135         301 :   StringRef ExceptionArg = cast<MDString>(MD)->getString();
     136         301 :   return StringSwitch<ExceptionBehavior>(ExceptionArg)
     137             :     .Case("fpexcept.ignore",  ebIgnore)
     138             :     .Case("fpexcept.maytrap", ebMayTrap)
     139             :     .Case("fpexcept.strict",  ebStrict)
     140             :     .Default(ebInvalid);
     141             : }
     142             : 
     143         235 : bool ConstrainedFPIntrinsic::isUnaryOp() const {
     144             :   switch (getIntrinsicID()) {
     145             :     default:
     146             :       return false;
     147         199 :     case Intrinsic::experimental_constrained_sqrt:
     148             :     case Intrinsic::experimental_constrained_sin:
     149             :     case Intrinsic::experimental_constrained_cos:
     150             :     case Intrinsic::experimental_constrained_exp:
     151             :     case Intrinsic::experimental_constrained_exp2:
     152             :     case Intrinsic::experimental_constrained_log:
     153             :     case Intrinsic::experimental_constrained_log10:
     154             :     case Intrinsic::experimental_constrained_log2:
     155             :     case Intrinsic::experimental_constrained_rint:
     156             :     case Intrinsic::experimental_constrained_nearbyint:
     157         199 :       return true;
     158             :   }
     159             : }
     160             : 
     161          63 : bool ConstrainedFPIntrinsic::isTernaryOp() const {
     162          63 :   switch (getIntrinsicID()) {
     163             :     default:
     164             :       return false;
     165          35 :     case Intrinsic::experimental_constrained_fma:
     166          35 :       return true;
     167             :   }
     168             : }
     169             : 

Generated by: LCOV version 1.13