LLVM  6.0.0svn
MemoryLocation.h
Go to the documentation of this file.
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 TargetLibraryInfo;
31 
32 /// Representation for a specific memory location.
33 ///
34 /// This abstraction can be used to represent a specific location in memory.
35 /// The goal of the location is to represent enough information to describe
36 /// abstract aliasing, modification, and reference behaviors of whatever
37 /// value(s) are stored in memory at the particular location.
38 ///
39 /// The primary user of this interface is LLVM's Alias Analysis, but other
40 /// memory analyses such as MemoryDependence can use it as well.
42 public:
43  /// UnknownSize - This is a special value which can be used with the
44  /// size arguments in alias queries to indicate that the caller does not
45  /// know the sizes of the potential memory references.
46  enum : uint64_t { UnknownSize = ~UINT64_C(0) };
47 
48  /// The address of the start of the location.
49  const Value *Ptr;
50 
51  /// The maximum size of the location, in address-units, or
52  /// UnknownSize if the size is not known.
53  ///
54  /// Note that an unknown size does not mean the pointer aliases the entire
55  /// virtual address space, because there are restrictions on stepping out of
56  /// one object and into another. See
57  /// http://llvm.org/docs/LangRef.html#pointeraliasing
58  uint64_t Size;
59 
60  /// The metadata nodes which describes the aliasing of the location (each
61  /// member is null if that kind of information is unavailable).
63 
64  /// Return a location with information about the memory reference by the given
65  /// instruction.
66  static MemoryLocation get(const LoadInst *LI);
67  static MemoryLocation get(const StoreInst *SI);
68  static MemoryLocation get(const VAArgInst *VI);
69  static MemoryLocation get(const AtomicCmpXchgInst *CXI);
70  static MemoryLocation get(const AtomicRMWInst *RMWI);
71  static MemoryLocation get(const Instruction *Inst) {
72  return *MemoryLocation::getOrNone(Inst);
73  }
75  switch (Inst->getOpcode()) {
76  case Instruction::Load:
77  return get(cast<LoadInst>(Inst));
78  case Instruction::Store:
79  return get(cast<StoreInst>(Inst));
80  case Instruction::VAArg:
81  return get(cast<VAArgInst>(Inst));
82  case Instruction::AtomicCmpXchg:
83  return get(cast<AtomicCmpXchgInst>(Inst));
84  case Instruction::AtomicRMW:
85  return get(cast<AtomicRMWInst>(Inst));
86  default:
87  return None;
88  }
89  }
90 
91  /// Return a location representing the source of a memory transfer.
92  static MemoryLocation getForSource(const MemTransferInst *MTI);
93 
94  /// Return a location representing the destination of a memory set or
95  /// transfer.
97 
98  /// Return a location representing a particular argument of a call.
99  static MemoryLocation getForArgument(ImmutableCallSite CS, unsigned ArgIdx,
100  const TargetLibraryInfo &TLI);
101 
102  explicit MemoryLocation(const Value *Ptr = nullptr,
103  uint64_t Size = UnknownSize,
104  const AAMDNodes &AATags = AAMDNodes())
105  : Ptr(Ptr), Size(Size), AATags(AATags) {}
106 
107  MemoryLocation getWithNewPtr(const Value *NewPtr) const {
108  MemoryLocation Copy(*this);
109  Copy.Ptr = NewPtr;
110  return Copy;
111  }
112 
113  MemoryLocation getWithNewSize(uint64_t NewSize) const {
114  MemoryLocation Copy(*this);
115  Copy.Size = NewSize;
116  return Copy;
117  }
118 
120  MemoryLocation Copy(*this);
121  Copy.AATags = AAMDNodes();
122  return Copy;
123  }
124 
125  bool operator==(const MemoryLocation &Other) const {
126  return Ptr == Other.Ptr && Size == Other.Size && AATags == Other.AATags;
127  }
128 };
129 
130 // Specialize DenseMapInfo for MemoryLocation.
131 template <> struct DenseMapInfo<MemoryLocation> {
132  static inline MemoryLocation getEmptyKey() {
134  }
135  static inline MemoryLocation getTombstoneKey() {
137  }
138  static unsigned getHashValue(const MemoryLocation &Val) {
142  }
143  static bool isEqual(const MemoryLocation &LHS, const MemoryLocation &RHS) {
144  return LHS == RHS;
145  }
146 };
147 }
148 
149 #endif
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
Definition: Instructions.h:514
MemoryLocation getWithNewPtr(const Value *NewPtr) const
This file contains the declarations for metadata subclasses.
An instruction for reading from memory.
Definition: Instructions.h:164
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Definition: Instructions.h:677
static Optional< MemoryLocation > getOrNone(const Instruction *Inst)
static MemoryLocation getForDest(const MemIntrinsic *MI)
Return a location representing the destination of a memory set or transfer.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:125
An instruction for storing to memory.
Definition: Instructions.h:306
MemoryLocation getWithoutAATags() const
bool operator==(const MemoryLocation &Other) const
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
static MemoryLocation getForArgument(ImmutableCallSite CS, unsigned ArgIdx, const TargetLibraryInfo &TLI)
Return a location representing a particular argument of a call.
const Value * Ptr
The address of the start of the location.
Representation for a specific memory location.
This is the common base class for memset/memcpy/memmove.
Provides information about what library functions are available for the current target.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition: Metadata.h:642
static bool isEqual(const MemoryLocation &LHS, const MemoryLocation &RHS)
This class wraps the llvm.memcpy/memmove intrinsics.
AAMDNodes AATags
The metadata nodes which describes the aliasing of the location (each member is null if that kind of ...
Establish a view to a call site for examination.
Definition: CallSite.h:713
MemoryLocation getWithNewSize(uint64_t NewSize) const
LLVM Value Representation.
Definition: Value.h:73
IRTranslator LLVM IR MI
MemoryLocation(const Value *Ptr=nullptr, uint64_t Size=UnknownSize, const AAMDNodes &AATags=AAMDNodes())
static MemoryLocation getTombstoneKey()
static MemoryLocation getEmptyKey()
static unsigned getHashValue(const MemoryLocation &Val)
uint64_t Size
The maximum size of the location, in address-units, or UnknownSize if the size is not known...
static MemoryLocation getForSource(const MemTransferInst *MTI)
Return a location representing the source of a memory transfer.