LCOV - code coverage report
Current view: top level - include/llvm/Analysis - MemoryLocation.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 15 20 75.0 %
Date: 2018-05-20 00:06:23 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- MemoryLocation.h - Memory location descriptions ----------*- C++ -*-===//
       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             : /// \file
      10             : /// This file provides utility analysis objects describing memory locations.
      11             : /// These are used both by the Alias Analysis infrastructure and more
      12             : /// specialized memory analysis layers.
      13             : ///
      14             : //===----------------------------------------------------------------------===//
      15             : 
      16             : #ifndef LLVM_ANALYSIS_MEMORYLOCATION_H
      17             : #define LLVM_ANALYSIS_MEMORYLOCATION_H
      18             : 
      19             : #include "llvm/ADT/Optional.h"
      20             : #include "llvm/ADT/DenseMapInfo.h"
      21             : #include "llvm/IR/CallSite.h"
      22             : #include "llvm/IR/Metadata.h"
      23             : 
      24             : namespace llvm {
      25             : 
      26             : class LoadInst;
      27             : class StoreInst;
      28             : class MemTransferInst;
      29             : class MemIntrinsic;
      30             : class AtomicMemTransferInst;
      31             : class AtomicMemIntrinsic;
      32             : class AnyMemTransferInst;
      33             : class AnyMemIntrinsic;
      34             : class TargetLibraryInfo;
      35             : 
      36             : /// Representation for a specific memory location.
      37             : ///
      38             : /// This abstraction can be used to represent a specific location in memory.
      39             : /// The goal of the location is to represent enough information to describe
      40             : /// abstract aliasing, modification, and reference behaviors of whatever
      41             : /// value(s) are stored in memory at the particular location.
      42             : ///
      43             : /// The primary user of this interface is LLVM's Alias Analysis, but other
      44             : /// memory analyses such as MemoryDependence can use it as well.
      45             : class MemoryLocation {
      46             : public:
      47             :   /// UnknownSize - This is a special value which can be used with the
      48             :   /// size arguments in alias queries to indicate that the caller does not
      49             :   /// know the sizes of the potential memory references.
      50             :   enum : uint64_t { UnknownSize = ~UINT64_C(0) };
      51             : 
      52             :   /// The address of the start of the location.
      53             :   const Value *Ptr;
      54             : 
      55             :   /// The maximum size of the location, in address-units, or
      56             :   /// UnknownSize if the size is not known.
      57             :   ///
      58             :   /// Note that an unknown size does not mean the pointer aliases the entire
      59             :   /// virtual address space, because there are restrictions on stepping out of
      60             :   /// one object and into another. See
      61             :   /// http://llvm.org/docs/LangRef.html#pointeraliasing
      62             :   uint64_t Size;
      63             : 
      64             :   /// The metadata nodes which describes the aliasing of the location (each
      65             :   /// member is null if that kind of information is unavailable).
      66             :   AAMDNodes AATags;
      67             : 
      68             :   /// Return a location with information about the memory reference by the given
      69             :   /// instruction.
      70             :   static MemoryLocation get(const LoadInst *LI);
      71             :   static MemoryLocation get(const StoreInst *SI);
      72             :   static MemoryLocation get(const VAArgInst *VI);
      73             :   static MemoryLocation get(const AtomicCmpXchgInst *CXI);
      74             :   static MemoryLocation get(const AtomicRMWInst *RMWI);
      75             :   static MemoryLocation get(const Instruction *Inst) {
      76      835561 :     return *MemoryLocation::getOrNone(Inst);
      77             :   }
      78      941159 :   static Optional<MemoryLocation> getOrNone(const Instruction *Inst) {
      79      941159 :     switch (Inst->getOpcode()) {
      80             :     case Instruction::Load:
      81     1860542 :       return get(cast<LoadInst>(Inst));
      82             :     case Instruction::Store:
      83       21726 :       return get(cast<StoreInst>(Inst));
      84             :     case Instruction::VAArg:
      85           0 :       return get(cast<VAArgInst>(Inst));
      86             :     case Instruction::AtomicCmpXchg:
      87           0 :       return get(cast<AtomicCmpXchgInst>(Inst));
      88             :     case Instruction::AtomicRMW:
      89           0 :       return get(cast<AtomicRMWInst>(Inst));
      90             :     default:
      91             :       return None;
      92             :     }
      93             :   }
      94             : 
      95             :   /// Return a location representing the source of a memory transfer.
      96             :   static MemoryLocation getForSource(const MemTransferInst *MTI);
      97             :   static MemoryLocation getForSource(const AtomicMemTransferInst *MTI);
      98             :   static MemoryLocation getForSource(const AnyMemTransferInst *MTI);
      99             : 
     100             :   /// Return a location representing the destination of a memory set or
     101             :   /// transfer.
     102             :   static MemoryLocation getForDest(const MemIntrinsic *MI);
     103             :   static MemoryLocation getForDest(const AtomicMemIntrinsic *MI);
     104             :   static MemoryLocation getForDest(const AnyMemIntrinsic *MI);
     105             : 
     106             :   /// Return a location representing a particular argument of a call.
     107             :   static MemoryLocation getForArgument(ImmutableCallSite CS, unsigned ArgIdx,
     108             :                                        const TargetLibraryInfo &TLI);
     109             : 
     110             :   explicit MemoryLocation(const Value *Ptr = nullptr,
     111             :                           uint64_t Size = UnknownSize,
     112             :                           const AAMDNodes &AATags = AAMDNodes())
     113    34777116 :       : Ptr(Ptr), Size(Size), AATags(AATags) {}
     114             : 
     115             :   MemoryLocation getWithNewPtr(const Value *NewPtr) const {
     116       18807 :     MemoryLocation Copy(*this);
     117       18807 :     Copy.Ptr = NewPtr;
     118             :     return Copy;
     119             :   }
     120             : 
     121             :   MemoryLocation getWithNewSize(uint64_t NewSize) const {
     122           0 :     MemoryLocation Copy(*this);
     123           0 :     Copy.Size = NewSize;
     124             :     return Copy;
     125             :   }
     126             : 
     127             :   MemoryLocation getWithoutAATags() const {
     128        4259 :     MemoryLocation Copy(*this);
     129        4259 :     Copy.AATags = AAMDNodes();
     130             :     return Copy;
     131             :   }
     132             : 
     133             :   bool operator==(const MemoryLocation &Other) const {
     134    90220515 :     return Ptr == Other.Ptr && Size == Other.Size && AATags == Other.AATags;
     135             :   }
     136             : };
     137             : 
     138             : // Specialize DenseMapInfo for MemoryLocation.
     139             : template <> struct DenseMapInfo<MemoryLocation> {
     140             :   static inline MemoryLocation getEmptyKey() {
     141             :     return MemoryLocation(DenseMapInfo<const Value *>::getEmptyKey(), 0);
     142             :   }
     143             :   static inline MemoryLocation getTombstoneKey() {
     144             :     return MemoryLocation(DenseMapInfo<const Value *>::getTombstoneKey(), 0);
     145             :   }
     146    55050455 :   static unsigned getHashValue(const MemoryLocation &Val) {
     147   110100910 :     return DenseMapInfo<const Value *>::getHashValue(Val.Ptr) ^
     148    55050455 :            DenseMapInfo<uint64_t>::getHashValue(Val.Size) ^
     149    55050455 :            DenseMapInfo<AAMDNodes>::getHashValue(Val.AATags);
     150             :   }
     151             :   static bool isEqual(const MemoryLocation &LHS, const MemoryLocation &RHS) {
     152             :     return LHS == RHS;
     153             :   }
     154             : };
     155             : }
     156             : 
     157             : #endif

Generated by: LCOV version 1.13