LCOV - code coverage report
Current view: top level - lib/Analysis - MemoryLocation.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 51 62 82.3 %
Date: 2017-09-14 15:23:50 Functions: 7 8 87.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- MemoryLocation.cpp - Memory location descriptions -------------------==//
       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             : #include "llvm/Analysis/MemoryLocation.h"
      11             : #include "llvm/Analysis/TargetLibraryInfo.h"
      12             : #include "llvm/IR/BasicBlock.h"
      13             : #include "llvm/IR/DataLayout.h"
      14             : #include "llvm/IR/Instructions.h"
      15             : #include "llvm/IR/IntrinsicInst.h"
      16             : #include "llvm/IR/LLVMContext.h"
      17             : #include "llvm/IR/Module.h"
      18             : #include "llvm/IR/Type.h"
      19             : using namespace llvm;
      20             : 
      21     4699415 : MemoryLocation MemoryLocation::get(const LoadInst *LI) {
      22     4699415 :   AAMDNodes AATags;
      23     4699415 :   LI->getAAMetadata(AATags);
      24     4699415 :   const auto &DL = LI->getModule()->getDataLayout();
      25             : 
      26             :   return MemoryLocation(LI->getPointerOperand(),
      27    18797660 :                         DL.getTypeStoreSize(LI->getType()), AATags);
      28             : }
      29             : 
      30     9392469 : MemoryLocation MemoryLocation::get(const StoreInst *SI) {
      31     9392469 :   AAMDNodes AATags;
      32     9392469 :   SI->getAAMetadata(AATags);
      33     9392469 :   const auto &DL = SI->getModule()->getDataLayout();
      34             : 
      35             :   return MemoryLocation(SI->getPointerOperand(),
      36             :                         DL.getTypeStoreSize(SI->getValueOperand()->getType()),
      37    37569876 :                         AATags);
      38             : }
      39             : 
      40           6 : MemoryLocation MemoryLocation::get(const VAArgInst *VI) {
      41           6 :   AAMDNodes AATags;
      42           6 :   VI->getAAMetadata(AATags);
      43             : 
      44          12 :   return MemoryLocation(VI->getPointerOperand(), UnknownSize, AATags);
      45             : }
      46             : 
      47           0 : MemoryLocation MemoryLocation::get(const AtomicCmpXchgInst *CXI) {
      48           0 :   AAMDNodes AATags;
      49           0 :   CXI->getAAMetadata(AATags);
      50           0 :   const auto &DL = CXI->getModule()->getDataLayout();
      51             : 
      52             :   return MemoryLocation(
      53             :       CXI->getPointerOperand(),
      54           0 :       DL.getTypeStoreSize(CXI->getCompareOperand()->getType()), AATags);
      55             : }
      56             : 
      57           2 : MemoryLocation MemoryLocation::get(const AtomicRMWInst *RMWI) {
      58           2 :   AAMDNodes AATags;
      59           2 :   RMWI->getAAMetadata(AATags);
      60           2 :   const auto &DL = RMWI->getModule()->getDataLayout();
      61             : 
      62             :   return MemoryLocation(RMWI->getPointerOperand(),
      63             :                         DL.getTypeStoreSize(RMWI->getValOperand()->getType()),
      64           8 :                         AATags);
      65             : }
      66             : 
      67        5770 : MemoryLocation MemoryLocation::getForSource(const MemTransferInst *MTI) {
      68        5770 :   uint64_t Size = UnknownSize;
      69       14389 :   if (ConstantInt *C = dyn_cast<ConstantInt>(MTI->getLength()))
      70        2849 :     Size = C->getValue().getZExtValue();
      71             : 
      72             :   // memcpy/memmove can have AA tags. For memcpy, they apply
      73             :   // to both the source and the destination.
      74        5770 :   AAMDNodes AATags;
      75        5770 :   MTI->getAAMetadata(AATags);
      76             : 
      77       11540 :   return MemoryLocation(MTI->getRawSource(), Size, AATags);
      78             : }
      79             : 
      80       11133 : MemoryLocation MemoryLocation::getForDest(const MemIntrinsic *MTI) {
      81       11133 :   uint64_t Size = UnknownSize;
      82       19271 :   if (ConstantInt *C = dyn_cast<ConstantInt>(MTI->getLength()))
      83        8138 :     Size = C->getValue().getZExtValue();
      84             : 
      85             :   // memcpy/memmove can have AA tags. For memcpy, they apply
      86             :   // to both the source and the destination.
      87       11133 :   AAMDNodes AATags;
      88       11133 :   MTI->getAAMetadata(AATags);
      89             : 
      90       22266 :   return MemoryLocation(MTI->getRawDest(), Size, AATags);
      91             : }
      92             : 
      93     4309205 : MemoryLocation MemoryLocation::getForArgument(ImmutableCallSite CS,
      94             :                                               unsigned ArgIdx,
      95             :                                               const TargetLibraryInfo &TLI) {
      96     4309205 :   AAMDNodes AATags;
      97     4309205 :   CS->getAAMetadata(AATags);
      98     4309205 :   const Value *Arg = CS.getArgument(ArgIdx);
      99             : 
     100             :   // We may be able to produce an exact size for known intrinsics.
     101     8608611 :   if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(CS.getInstruction())) {
     102     4299406 :     const DataLayout &DL = II->getModule()->getDataLayout();
     103             : 
     104     4299406 :     switch (II->getIntrinsicID()) {
     105             :     default:
     106             :       break;
     107     3627294 :     case Intrinsic::memset:
     108             :     case Intrinsic::memcpy:
     109             :     case Intrinsic::memmove:
     110             :       assert((ArgIdx == 0 || ArgIdx == 1) &&
     111             :              "Invalid argument index for memory intrinsic");
     112    10874569 :       if (ConstantInt *LenCI = dyn_cast<ConstantInt>(II->getArgOperand(2)))
     113     3619981 :         return MemoryLocation(Arg, LenCI->getZExtValue(), AATags);
     114             :       break;
     115             : 
     116      671102 :     case Intrinsic::lifetime_start:
     117             :     case Intrinsic::lifetime_end:
     118             :     case Intrinsic::invariant_start:
     119             :       assert(ArgIdx == 1 && "Invalid argument index");
     120             :       return MemoryLocation(
     121     2684408 :           Arg, cast<ConstantInt>(II->getArgOperand(0))->getZExtValue(), AATags);
     122             : 
     123           0 :     case Intrinsic::invariant_end:
     124             :       assert(ArgIdx == 2 && "Invalid argument index");
     125             :       return MemoryLocation(
     126           0 :           Arg, cast<ConstantInt>(II->getArgOperand(1))->getZExtValue(), AATags);
     127             : 
     128           0 :     case Intrinsic::arm_neon_vld1:
     129             :       assert(ArgIdx == 0 && "Invalid argument index");
     130             :       // LLVM's vld1 and vst1 intrinsics currently only support a single
     131             :       // vector register.
     132           0 :       return MemoryLocation(Arg, DL.getTypeStoreSize(II->getType()), AATags);
     133             : 
     134           0 :     case Intrinsic::arm_neon_vst1:
     135             :       assert(ArgIdx == 0 && "Invalid argument index");
     136             :       return MemoryLocation(
     137           0 :           Arg, DL.getTypeStoreSize(II->getArgOperand(1)->getType()), AATags);
     138             :     }
     139             :   }
     140             : 
     141             :   // We can bound the aliasing properties of memset_pattern16 just as we can
     142             :   // for memcpy/memset.  This is particularly important because the
     143             :   // LoopIdiomRecognizer likes to turn loops into calls to memset_pattern16
     144             :   // whenever possible.
     145             :   LibFunc F;
     146       64087 :   if (CS.getCalledFunction() && TLI.getLibFunc(*CS.getCalledFunction(), F) &&
     147        9725 :       F == LibFunc_memset_pattern16 && TLI.has(F)) {
     148             :     assert((ArgIdx == 0 || ArgIdx == 1) &&
     149             :            "Invalid argument index for memset_pattern16");
     150           2 :     if (ArgIdx == 1)
     151             :       return MemoryLocation(Arg, 16, AATags);
     152           2 :     if (const ConstantInt *LenCI = dyn_cast<ConstantInt>(CS.getArgument(2)))
     153           1 :       return MemoryLocation(Arg, LenCI->getZExtValue(), AATags);
     154             :   }
     155             :   // FIXME: Handle memset_pattern4 and memset_pattern8 also.
     156             : 
     157       18120 :   return MemoryLocation(CS.getArgument(ArgIdx), UnknownSize, AATags);
     158             : }

Generated by: LCOV version 1.13