LCOV - code coverage report
Current view: top level - lib/IR - Operator.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 23 23 100.0 %
Date: 2017-09-14 15:23:50 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- Operator.cpp - Implement the LLVM operators -----------------------===//
       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 the non-inline methods for the LLVM Operator classes.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/IR/Operator.h"
      15             : #include "llvm/IR/DataLayout.h"
      16             : #include "llvm/IR/GetElementPtrTypeIterator.h"
      17             : #include "llvm/IR/Instructions.h"
      18             : #include "llvm/IR/Type.h"
      19             : 
      20             : #include "ConstantsContext.h"
      21             : 
      22             : namespace llvm {
      23    40352199 : Type *GEPOperator::getSourceElementType() const {
      24     7142174 :   if (auto *I = dyn_cast<GetElementPtrInst>(this))
      25     7142174 :     return I->getSourceElementType();
      26    33210025 :   return cast<GetElementPtrConstantExpr>(this)->getSourceElementType();
      27             : }
      28             : 
      29     9843209 : Type *GEPOperator::getResultElementType() const {
      30        1741 :   if (auto *I = dyn_cast<GetElementPtrInst>(this))
      31        1741 :     return I->getResultElementType();
      32     9841468 :   return cast<GetElementPtrConstantExpr>(this)->getResultElementType();
      33             : }
      34             : 
      35     8013779 : bool GEPOperator::accumulateConstantOffset(const DataLayout &DL,
      36             :                                            APInt &Offset) const {
      37             :   assert(Offset.getBitWidth() ==
      38             :              DL.getPointerSizeInBits(getPointerAddressSpace()) &&
      39             :          "The offset must have exactly as many bits as our pointer.");
      40             : 
      41    23900075 :   for (gep_type_iterator GTI = gep_type_begin(this), GTE = gep_type_end(this);
      42    23900075 :        GTI != GTE; ++GTI) {
      43    47943994 :     ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand());
      44             :     if (!OpC)
      45      142553 :       return false;
      46    15886296 :     if (OpC->isZero())
      47    21671493 :       continue;
      48             : 
      49             :     // Handle a struct index, which adds its field offset to the pointer.
      50       83243 :     if (StructType *STy = GTI.getStructTypeOrNull()) {
      51       83243 :       unsigned ElementIdx = OpC->getZExtValue();
      52       83243 :       const StructLayout *SL = DL.getStructLayout(STy);
      53      249729 :       Offset += APInt(Offset.getBitWidth(), SL->getElementOffset(ElementIdx));
      54       83243 :       continue;
      55             :     }
      56             : 
      57             :     // For array or vector indices, scale the index by the size of the type.
      58    10017856 :     APInt Index = OpC->getValue().sextOrTrunc(Offset.getBitWidth());
      59    20035712 :     Offset += Index * APInt(Offset.getBitWidth(),
      60             :                             DL.getTypeAllocSize(GTI.getIndexedType()));
      61             :   }
      62     7871226 :   return true;
      63             : }
      64             : }

Generated by: LCOV version 1.13