LLVM  6.0.0svn
MemoryLocation.cpp
Go to the documentation of this file.
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 
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 
23  LI->getAAMetadata(AATags);
24  const auto &DL = LI->getModule()->getDataLayout();
25 
26  return MemoryLocation(LI->getPointerOperand(),
27  DL.getTypeStoreSize(LI->getType()), AATags);
28 }
29 
32  SI->getAAMetadata(AATags);
33  const auto &DL = SI->getModule()->getDataLayout();
34 
35  return MemoryLocation(SI->getPointerOperand(),
36  DL.getTypeStoreSize(SI->getValueOperand()->getType()),
37  AATags);
38 }
39 
42  VI->getAAMetadata(AATags);
43 
45 }
46 
49  CXI->getAAMetadata(AATags);
50  const auto &DL = CXI->getModule()->getDataLayout();
51 
52  return MemoryLocation(
53  CXI->getPointerOperand(),
54  DL.getTypeStoreSize(CXI->getCompareOperand()->getType()), AATags);
55 }
56 
59  RMWI->getAAMetadata(AATags);
60  const auto &DL = RMWI->getModule()->getDataLayout();
61 
62  return MemoryLocation(RMWI->getPointerOperand(),
63  DL.getTypeStoreSize(RMWI->getValOperand()->getType()),
64  AATags);
65 }
66 
68  uint64_t Size = UnknownSize;
69  if (ConstantInt *C = dyn_cast<ConstantInt>(MTI->getLength()))
70  Size = C->getValue().getZExtValue();
71 
72  // memcpy/memmove can have AA tags. For memcpy, they apply
73  // to both the source and the destination.
75  MTI->getAAMetadata(AATags);
76 
77  return MemoryLocation(MTI->getRawSource(), Size, AATags);
78 }
79 
81  uint64_t Size = UnknownSize;
82  if (ConstantInt *C = dyn_cast<ConstantInt>(MTI->getLength()))
83  Size = C->getValue().getZExtValue();
84 
85  // memcpy/memmove can have AA tags. For memcpy, they apply
86  // to both the source and the destination.
88  MTI->getAAMetadata(AATags);
89 
90  return MemoryLocation(MTI->getRawDest(), Size, AATags);
91 }
92 
94  unsigned ArgIdx,
95  const TargetLibraryInfo &TLI) {
97  CS->getAAMetadata(AATags);
98  const Value *Arg = CS.getArgument(ArgIdx);
99 
100  // We may be able to produce an exact size for known intrinsics.
101  if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(CS.getInstruction())) {
102  const DataLayout &DL = II->getModule()->getDataLayout();
103 
104  switch (II->getIntrinsicID()) {
105  default:
106  break;
107  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  if (ConstantInt *LenCI = dyn_cast<ConstantInt>(II->getArgOperand(2)))
113  return MemoryLocation(Arg, LenCI->getZExtValue(), AATags);
114  break;
115 
116  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  Arg, cast<ConstantInt>(II->getArgOperand(0))->getZExtValue(), AATags);
122 
123  case Intrinsic::invariant_end:
124  assert(ArgIdx == 2 && "Invalid argument index");
125  return MemoryLocation(
126  Arg, cast<ConstantInt>(II->getArgOperand(1))->getZExtValue(), AATags);
127 
128  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  return MemoryLocation(Arg, DL.getTypeStoreSize(II->getType()), AATags);
133 
134  case Intrinsic::arm_neon_vst1:
135  assert(ArgIdx == 0 && "Invalid argument index");
136  return MemoryLocation(
137  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  if (CS.getCalledFunction() && TLI.getLibFunc(*CS.getCalledFunction(), F) &&
147  F == LibFunc_memset_pattern16 && TLI.has(F)) {
148  assert((ArgIdx == 0 || ArgIdx == 1) &&
149  "Invalid argument index for memset_pattern16");
150  if (ArgIdx == 1)
151  return MemoryLocation(Arg, 16, AATags);
152  if (const ConstantInt *LenCI = dyn_cast<ConstantInt>(CS.getArgument(2)))
153  return MemoryLocation(Arg, LenCI->getZExtValue(), AATags);
154  }
155  // FIXME: Handle memset_pattern4 and memset_pattern8 also.
156 
157  return MemoryLocation(CS.getArgument(ArgIdx), UnknownSize, AATags);
158 }
uint64_t CallInst * C
Value * getValueOperand()
Definition: Instructions.h:395
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
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
F(f)
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
Value * getLength() const
Value * getRawSource() const
Return the arguments to the instruction.
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:361
InstrTy * getInstruction() const
Definition: CallSite.h:92
Value * getPointerOperand()
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
static MemoryLocation getForDest(const MemIntrinsic *MI)
Return a location representing the destination of a memory set or transfer.
bool has(LibFunc F) const
Tests whether a library function is available.
An instruction for storing to memory.
Definition: Instructions.h:306
void getAAMetadata(AAMDNodes &N, bool Merge=false) const
Fills the AAMDNodes structure with AA metadata from this instruction.
static MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
Value * getPointerOperand()
Definition: Instructions.h:270
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.
Representation for a specific memory location.
Value * getValOperand()
Definition: Instructions.h:783
This is the common base class for memset/memcpy/memmove.
This is the shared class of boolean and integer constants.
Definition: Constants.h:84
ValTy * getArgument(unsigned ArgNo) const
Definition: CallSite.h:186
Module.h This file contains the declarations for the Module class.
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
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:57
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
amdgpu Simplify well known AMD library false Value Value * Arg
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 ...
This file provides utility analysis objects describing memory locations.
Value * getPointerOperand()
Definition: Instructions.h:779
Establish a view to a call site for examination.
Definition: CallSite.h:713
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it&#39;s an indirect...
Definition: CallSite.h:107
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:73
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
Definition: DataLayout.h:386
MemoryLocation(const Value *Ptr=nullptr, uint64_t Size=UnknownSize, const AAMDNodes &AATags=AAMDNodes())
Value * getPointerOperand()
Definition: Instructions.h:398
Value * getRawDest() const
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:44
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.