LLVM  6.0.0svn
VNCoercion.cpp
Go to the documentation of this file.
6 #include "llvm/IR/IRBuilder.h"
8 #include "llvm/Support/Debug.h"
9 
10 #define DEBUG_TYPE "vncoerce"
11 namespace llvm {
12 namespace VNCoercion {
13 
14 /// Return true if coerceAvailableValueToLoadType will succeed.
15 bool canCoerceMustAliasedValueToLoad(Value *StoredVal, Type *LoadTy,
16  const DataLayout &DL) {
17  // If the loaded or stored value is an first class array or struct, don't try
18  // to transform them. We need to be able to bitcast to integer.
19  if (LoadTy->isStructTy() || LoadTy->isArrayTy() ||
20  StoredVal->getType()->isStructTy() || StoredVal->getType()->isArrayTy())
21  return false;
22 
23  // The store has to be at least as big as the load.
24  if (DL.getTypeSizeInBits(StoredVal->getType()) < DL.getTypeSizeInBits(LoadTy))
25  return false;
26 
27  // Don't coerce non-integral pointers to integers or vice versa.
28  if (DL.isNonIntegralPointerType(StoredVal->getType()) !=
29  DL.isNonIntegralPointerType(LoadTy))
30  return false;
31 
32  return true;
33 }
34 
35 template <class T, class HelperClass>
36 static T *coerceAvailableValueToLoadTypeHelper(T *StoredVal, Type *LoadedTy,
37  HelperClass &Helper,
38  const DataLayout &DL) {
39  assert(canCoerceMustAliasedValueToLoad(StoredVal, LoadedTy, DL) &&
40  "precondition violation - materialization can't fail");
41  if (auto *C = dyn_cast<Constant>(StoredVal))
42  if (auto *FoldedStoredVal = ConstantFoldConstant(C, DL))
43  StoredVal = FoldedStoredVal;
44 
45  // If this is already the right type, just return it.
46  Type *StoredValTy = StoredVal->getType();
47 
48  uint64_t StoredValSize = DL.getTypeSizeInBits(StoredValTy);
49  uint64_t LoadedValSize = DL.getTypeSizeInBits(LoadedTy);
50 
51  // If the store and reload are the same size, we can always reuse it.
52  if (StoredValSize == LoadedValSize) {
53  // Pointer to Pointer -> use bitcast.
54  if (StoredValTy->isPtrOrPtrVectorTy() && LoadedTy->isPtrOrPtrVectorTy()) {
55  StoredVal = Helper.CreateBitCast(StoredVal, LoadedTy);
56  } else {
57  // Convert source pointers to integers, which can be bitcast.
58  if (StoredValTy->isPtrOrPtrVectorTy()) {
59  StoredValTy = DL.getIntPtrType(StoredValTy);
60  StoredVal = Helper.CreatePtrToInt(StoredVal, StoredValTy);
61  }
62 
63  Type *TypeToCastTo = LoadedTy;
64  if (TypeToCastTo->isPtrOrPtrVectorTy())
65  TypeToCastTo = DL.getIntPtrType(TypeToCastTo);
66 
67  if (StoredValTy != TypeToCastTo)
68  StoredVal = Helper.CreateBitCast(StoredVal, TypeToCastTo);
69 
70  // Cast to pointer if the load needs a pointer type.
71  if (LoadedTy->isPtrOrPtrVectorTy())
72  StoredVal = Helper.CreateIntToPtr(StoredVal, LoadedTy);
73  }
74 
75  if (auto *C = dyn_cast<ConstantExpr>(StoredVal))
76  if (auto *FoldedStoredVal = ConstantFoldConstant(C, DL))
77  StoredVal = FoldedStoredVal;
78 
79  return StoredVal;
80  }
81  // If the loaded value is smaller than the available value, then we can
82  // extract out a piece from it. If the available value is too small, then we
83  // can't do anything.
84  assert(StoredValSize >= LoadedValSize &&
85  "canCoerceMustAliasedValueToLoad fail");
86 
87  // Convert source pointers to integers, which can be manipulated.
88  if (StoredValTy->isPtrOrPtrVectorTy()) {
89  StoredValTy = DL.getIntPtrType(StoredValTy);
90  StoredVal = Helper.CreatePtrToInt(StoredVal, StoredValTy);
91  }
92 
93  // Convert vectors and fp to integer, which can be manipulated.
94  if (!StoredValTy->isIntegerTy()) {
95  StoredValTy = IntegerType::get(StoredValTy->getContext(), StoredValSize);
96  StoredVal = Helper.CreateBitCast(StoredVal, StoredValTy);
97  }
98 
99  // If this is a big-endian system, we need to shift the value down to the low
100  // bits so that a truncate will work.
101  if (DL.isBigEndian()) {
102  uint64_t ShiftAmt = DL.getTypeStoreSizeInBits(StoredValTy) -
103  DL.getTypeStoreSizeInBits(LoadedTy);
104  StoredVal = Helper.CreateLShr(
105  StoredVal, ConstantInt::get(StoredVal->getType(), ShiftAmt));
106  }
107 
108  // Truncate the integer to the right size now.
109  Type *NewIntTy = IntegerType::get(StoredValTy->getContext(), LoadedValSize);
110  StoredVal = Helper.CreateTruncOrBitCast(StoredVal, NewIntTy);
111 
112  if (LoadedTy != NewIntTy) {
113  // If the result is a pointer, inttoptr.
114  if (LoadedTy->isPtrOrPtrVectorTy())
115  StoredVal = Helper.CreateIntToPtr(StoredVal, LoadedTy);
116  else
117  // Otherwise, bitcast.
118  StoredVal = Helper.CreateBitCast(StoredVal, LoadedTy);
119  }
120 
121  if (auto *C = dyn_cast<Constant>(StoredVal))
122  if (auto *FoldedStoredVal = ConstantFoldConstant(C, DL))
123  StoredVal = FoldedStoredVal;
124 
125  return StoredVal;
126 }
127 
128 /// If we saw a store of a value to memory, and
129 /// then a load from a must-aliased pointer of a different type, try to coerce
130 /// the stored value. LoadedTy is the type of the load we want to replace.
131 /// IRB is IRBuilder used to insert new instructions.
132 ///
133 /// If we can't do it, return null.
135  IRBuilder<> &IRB, const DataLayout &DL) {
136  return coerceAvailableValueToLoadTypeHelper(StoredVal, LoadedTy, IRB, DL);
137 }
138 
139 /// This function is called when we have a memdep query of a load that ends up
140 /// being a clobbering memory write (store, memset, memcpy, memmove). This
141 /// means that the write *may* provide bits used by the load but we can't be
142 /// sure because the pointers don't must-alias.
143 ///
144 /// Check this case to see if there is anything more we can do before we give
145 /// up. This returns -1 if we have to give up, or a byte number in the stored
146 /// value of the piece that feeds the load.
147 static int analyzeLoadFromClobberingWrite(Type *LoadTy, Value *LoadPtr,
148  Value *WritePtr,
149  uint64_t WriteSizeInBits,
150  const DataLayout &DL) {
151  // If the loaded or stored value is a first class array or struct, don't try
152  // to transform them. We need to be able to bitcast to integer.
153  if (LoadTy->isStructTy() || LoadTy->isArrayTy())
154  return -1;
155 
156  int64_t StoreOffset = 0, LoadOffset = 0;
157  Value *StoreBase =
158  GetPointerBaseWithConstantOffset(WritePtr, StoreOffset, DL);
159  Value *LoadBase = GetPointerBaseWithConstantOffset(LoadPtr, LoadOffset, DL);
160  if (StoreBase != LoadBase)
161  return -1;
162 
163  // If the load and store are to the exact same address, they should have been
164  // a must alias. AA must have gotten confused.
165  // FIXME: Study to see if/when this happens. One case is forwarding a memset
166  // to a load from the base of the memset.
167 
168  // If the load and store don't overlap at all, the store doesn't provide
169  // anything to the load. In this case, they really don't alias at all, AA
170  // must have gotten confused.
171  uint64_t LoadSize = DL.getTypeSizeInBits(LoadTy);
172 
173  if ((WriteSizeInBits & 7) | (LoadSize & 7))
174  return -1;
175  uint64_t StoreSize = WriteSizeInBits / 8; // Convert to bytes.
176  LoadSize /= 8;
177 
178  bool isAAFailure = false;
179  if (StoreOffset < LoadOffset)
180  isAAFailure = StoreOffset + int64_t(StoreSize) <= LoadOffset;
181  else
182  isAAFailure = LoadOffset + int64_t(LoadSize) <= StoreOffset;
183 
184  if (isAAFailure)
185  return -1;
186 
187  // If the Load isn't completely contained within the stored bits, we don't
188  // have all the bits to feed it. We could do something crazy in the future
189  // (issue a smaller load then merge the bits in) but this seems unlikely to be
190  // valuable.
191  if (StoreOffset > LoadOffset ||
192  StoreOffset + StoreSize < LoadOffset + LoadSize)
193  return -1;
194 
195  // Okay, we can do this transformation. Return the number of bytes into the
196  // store that the load is.
197  return LoadOffset - StoreOffset;
198 }
199 
200 /// This function is called when we have a
201 /// memdep query of a load that ends up being a clobbering store.
203  StoreInst *DepSI, const DataLayout &DL) {
204  // Cannot handle reading from store of first-class aggregate yet.
205  if (DepSI->getValueOperand()->getType()->isStructTy() ||
206  DepSI->getValueOperand()->getType()->isArrayTy())
207  return -1;
208 
209  Value *StorePtr = DepSI->getPointerOperand();
210  uint64_t StoreSize =
211  DL.getTypeSizeInBits(DepSI->getValueOperand()->getType());
212  return analyzeLoadFromClobberingWrite(LoadTy, LoadPtr, StorePtr, StoreSize,
213  DL);
214 }
215 
216 /// This function is called when we have a
217 /// memdep query of a load that ends up being clobbered by another load. See if
218 /// the other load can feed into the second load.
219 int analyzeLoadFromClobberingLoad(Type *LoadTy, Value *LoadPtr, LoadInst *DepLI,
220  const DataLayout &DL) {
221  // Cannot handle reading from store of first-class aggregate yet.
222  if (DepLI->getType()->isStructTy() || DepLI->getType()->isArrayTy())
223  return -1;
224 
225  Value *DepPtr = DepLI->getPointerOperand();
226  uint64_t DepSize = DL.getTypeSizeInBits(DepLI->getType());
227  int R = analyzeLoadFromClobberingWrite(LoadTy, LoadPtr, DepPtr, DepSize, DL);
228  if (R != -1)
229  return R;
230 
231  // If we have a load/load clobber an DepLI can be widened to cover this load,
232  // then we should widen it!
233  int64_t LoadOffs = 0;
234  const Value *LoadBase =
235  GetPointerBaseWithConstantOffset(LoadPtr, LoadOffs, DL);
236  unsigned LoadSize = DL.getTypeStoreSize(LoadTy);
237 
239  LoadBase, LoadOffs, LoadSize, DepLI);
240  if (Size == 0)
241  return -1;
242 
243  // Check non-obvious conditions enforced by MDA which we rely on for being
244  // able to materialize this potentially available value
245  assert(DepLI->isSimple() && "Cannot widen volatile/atomic load!");
246  assert(DepLI->getType()->isIntegerTy() && "Can't widen non-integer load");
247 
248  return analyzeLoadFromClobberingWrite(LoadTy, LoadPtr, DepPtr, Size * 8, DL);
249 }
250 
252  MemIntrinsic *MI, const DataLayout &DL) {
253  // If the mem operation is a non-constant size, we can't handle it.
254  ConstantInt *SizeCst = dyn_cast<ConstantInt>(MI->getLength());
255  if (!SizeCst)
256  return -1;
257  uint64_t MemSizeInBits = SizeCst->getZExtValue() * 8;
258 
259  // If this is memset, we just need to see if the offset is valid in the size
260  // of the memset..
261  if (MI->getIntrinsicID() == Intrinsic::memset)
262  return analyzeLoadFromClobberingWrite(LoadTy, LoadPtr, MI->getDest(),
263  MemSizeInBits, DL);
264 
265  // If we have a memcpy/memmove, the only case we can handle is if this is a
266  // copy from constant memory. In that case, we can read directly from the
267  // constant memory.
268  MemTransferInst *MTI = cast<MemTransferInst>(MI);
269 
270  Constant *Src = dyn_cast<Constant>(MTI->getSource());
271  if (!Src)
272  return -1;
273 
275  if (!GV || !GV->isConstant())
276  return -1;
277 
278  // See if the access is within the bounds of the transfer.
279  int Offset = analyzeLoadFromClobberingWrite(LoadTy, LoadPtr, MI->getDest(),
280  MemSizeInBits, DL);
281  if (Offset == -1)
282  return Offset;
283 
284  unsigned AS = Src->getType()->getPointerAddressSpace();
285  // Otherwise, see if we can constant fold a load from the constant with the
286  // offset applied as appropriate.
287  Src =
288  ConstantExpr::getBitCast(Src, Type::getInt8PtrTy(Src->getContext(), AS));
289  Constant *OffsetCst =
290  ConstantInt::get(Type::getInt64Ty(Src->getContext()), (unsigned)Offset);
291  Src = ConstantExpr::getGetElementPtr(Type::getInt8Ty(Src->getContext()), Src,
292  OffsetCst);
293  Src = ConstantExpr::getBitCast(Src, PointerType::get(LoadTy, AS));
294  if (ConstantFoldLoadFromConstPtr(Src, LoadTy, DL))
295  return Offset;
296  return -1;
297 }
298 
299 template <class T, class HelperClass>
300 static T *getStoreValueForLoadHelper(T *SrcVal, unsigned Offset, Type *LoadTy,
301  HelperClass &Helper,
302  const DataLayout &DL) {
303  LLVMContext &Ctx = SrcVal->getType()->getContext();
304 
305  // If two pointers are in the same address space, they have the same size,
306  // so we don't need to do any truncation, etc. This avoids introducing
307  // ptrtoint instructions for pointers that may be non-integral.
308  if (SrcVal->getType()->isPointerTy() && LoadTy->isPointerTy() &&
309  cast<PointerType>(SrcVal->getType())->getAddressSpace() ==
310  cast<PointerType>(LoadTy)->getAddressSpace()) {
311  return SrcVal;
312  }
313 
314  uint64_t StoreSize = (DL.getTypeSizeInBits(SrcVal->getType()) + 7) / 8;
315  uint64_t LoadSize = (DL.getTypeSizeInBits(LoadTy) + 7) / 8;
316  // Compute which bits of the stored value are being used by the load. Convert
317  // to an integer type to start with.
318  if (SrcVal->getType()->isPtrOrPtrVectorTy())
319  SrcVal = Helper.CreatePtrToInt(SrcVal, DL.getIntPtrType(SrcVal->getType()));
320  if (!SrcVal->getType()->isIntegerTy())
321  SrcVal = Helper.CreateBitCast(SrcVal, IntegerType::get(Ctx, StoreSize * 8));
322 
323  // Shift the bits to the least significant depending on endianness.
324  unsigned ShiftAmt;
325  if (DL.isLittleEndian())
326  ShiftAmt = Offset * 8;
327  else
328  ShiftAmt = (StoreSize - LoadSize - Offset) * 8;
329  if (ShiftAmt)
330  SrcVal = Helper.CreateLShr(SrcVal,
331  ConstantInt::get(SrcVal->getType(), ShiftAmt));
332 
333  if (LoadSize != StoreSize)
334  SrcVal = Helper.CreateTruncOrBitCast(SrcVal,
335  IntegerType::get(Ctx, LoadSize * 8));
336  return SrcVal;
337 }
338 
339 /// This function is called when we have a memdep query of a load that ends up
340 /// being a clobbering store. This means that the store provides bits used by
341 /// the load but the pointers don't must-alias. Check this case to see if
342 /// there is anything more we can do before we give up.
343 Value *getStoreValueForLoad(Value *SrcVal, unsigned Offset, Type *LoadTy,
344  Instruction *InsertPt, const DataLayout &DL) {
345 
346  IRBuilder<> Builder(InsertPt);
347  SrcVal = getStoreValueForLoadHelper(SrcVal, Offset, LoadTy, Builder, DL);
348  return coerceAvailableValueToLoadTypeHelper(SrcVal, LoadTy, Builder, DL);
349 }
350 
352  Type *LoadTy, const DataLayout &DL) {
354  SrcVal = getStoreValueForLoadHelper(SrcVal, Offset, LoadTy, F, DL);
355  return coerceAvailableValueToLoadTypeHelper(SrcVal, LoadTy, F, DL);
356 }
357 
358 /// This function is called when we have a memdep query of a load that ends up
359 /// being a clobbering load. This means that the load *may* provide bits used
360 /// by the load but we can't be sure because the pointers don't must-alias.
361 /// Check this case to see if there is anything more we can do before we give
362 /// up.
363 Value *getLoadValueForLoad(LoadInst *SrcVal, unsigned Offset, Type *LoadTy,
364  Instruction *InsertPt, const DataLayout &DL) {
365  // If Offset+LoadTy exceeds the size of SrcVal, then we must be wanting to
366  // widen SrcVal out to a larger load.
367  unsigned SrcValStoreSize = DL.getTypeStoreSize(SrcVal->getType());
368  unsigned LoadSize = DL.getTypeStoreSize(LoadTy);
369  if (Offset + LoadSize > SrcValStoreSize) {
370  assert(SrcVal->isSimple() && "Cannot widen volatile/atomic load!");
371  assert(SrcVal->getType()->isIntegerTy() && "Can't widen non-integer load");
372  // If we have a load/load clobber an DepLI can be widened to cover this
373  // load, then we should widen it to the next power of 2 size big enough!
374  unsigned NewLoadSize = Offset + LoadSize;
375  if (!isPowerOf2_32(NewLoadSize))
376  NewLoadSize = NextPowerOf2(NewLoadSize);
377 
378  Value *PtrVal = SrcVal->getPointerOperand();
379  // Insert the new load after the old load. This ensures that subsequent
380  // memdep queries will find the new load. We can't easily remove the old
381  // load completely because it is already in the value numbering table.
382  IRBuilder<> Builder(SrcVal->getParent(), ++BasicBlock::iterator(SrcVal));
383  Type *DestPTy = IntegerType::get(LoadTy->getContext(), NewLoadSize * 8);
384  DestPTy =
385  PointerType::get(DestPTy, PtrVal->getType()->getPointerAddressSpace());
386  Builder.SetCurrentDebugLocation(SrcVal->getDebugLoc());
387  PtrVal = Builder.CreateBitCast(PtrVal, DestPTy);
388  LoadInst *NewLoad = Builder.CreateLoad(PtrVal);
389  NewLoad->takeName(SrcVal);
390  NewLoad->setAlignment(SrcVal->getAlignment());
391 
392  DEBUG(dbgs() << "GVN WIDENED LOAD: " << *SrcVal << "\n");
393  DEBUG(dbgs() << "TO: " << *NewLoad << "\n");
394 
395  // Replace uses of the original load with the wider load. On a big endian
396  // system, we need to shift down to get the relevant bits.
397  Value *RV = NewLoad;
398  if (DL.isBigEndian())
399  RV = Builder.CreateLShr(RV, (NewLoadSize - SrcValStoreSize) * 8);
400  RV = Builder.CreateTrunc(RV, SrcVal->getType());
401  SrcVal->replaceAllUsesWith(RV);
402 
403  SrcVal = NewLoad;
404  }
405 
406  return getStoreValueForLoad(SrcVal, Offset, LoadTy, InsertPt, DL);
407 }
408 
410  Type *LoadTy, const DataLayout &DL) {
411  unsigned SrcValStoreSize = DL.getTypeStoreSize(SrcVal->getType());
412  unsigned LoadSize = DL.getTypeStoreSize(LoadTy);
413  if (Offset + LoadSize > SrcValStoreSize)
414  return nullptr;
415  return getConstantStoreValueForLoad(SrcVal, Offset, LoadTy, DL);
416 }
417 
418 template <class T, class HelperClass>
420  Type *LoadTy, HelperClass &Helper,
421  const DataLayout &DL) {
422  LLVMContext &Ctx = LoadTy->getContext();
423  uint64_t LoadSize = DL.getTypeSizeInBits(LoadTy) / 8;
424 
425  // We know that this method is only called when the mem transfer fully
426  // provides the bits for the load.
427  if (MemSetInst *MSI = dyn_cast<MemSetInst>(SrcInst)) {
428  // memset(P, 'x', 1234) -> splat('x'), even if x is a variable, and
429  // independently of what the offset is.
430  T *Val = cast<T>(MSI->getValue());
431  if (LoadSize != 1)
432  Val =
433  Helper.CreateZExtOrBitCast(Val, IntegerType::get(Ctx, LoadSize * 8));
434  T *OneElt = Val;
435 
436  // Splat the value out to the right number of bits.
437  for (unsigned NumBytesSet = 1; NumBytesSet != LoadSize;) {
438  // If we can double the number of bytes set, do it.
439  if (NumBytesSet * 2 <= LoadSize) {
440  T *ShVal = Helper.CreateShl(
441  Val, ConstantInt::get(Val->getType(), NumBytesSet * 8));
442  Val = Helper.CreateOr(Val, ShVal);
443  NumBytesSet <<= 1;
444  continue;
445  }
446 
447  // Otherwise insert one byte at a time.
448  T *ShVal = Helper.CreateShl(Val, ConstantInt::get(Val->getType(), 1 * 8));
449  Val = Helper.CreateOr(OneElt, ShVal);
450  ++NumBytesSet;
451  }
452 
453  return coerceAvailableValueToLoadTypeHelper(Val, LoadTy, Helper, DL);
454  }
455 
456  // Otherwise, this is a memcpy/memmove from a constant global.
457  MemTransferInst *MTI = cast<MemTransferInst>(SrcInst);
458  Constant *Src = cast<Constant>(MTI->getSource());
459  unsigned AS = Src->getType()->getPointerAddressSpace();
460 
461  // Otherwise, see if we can constant fold a load from the constant with the
462  // offset applied as appropriate.
463  Src =
464  ConstantExpr::getBitCast(Src, Type::getInt8PtrTy(Src->getContext(), AS));
465  Constant *OffsetCst =
466  ConstantInt::get(Type::getInt64Ty(Src->getContext()), (unsigned)Offset);
467  Src = ConstantExpr::getGetElementPtr(Type::getInt8Ty(Src->getContext()), Src,
468  OffsetCst);
469  Src = ConstantExpr::getBitCast(Src, PointerType::get(LoadTy, AS));
470  return ConstantFoldLoadFromConstPtr(Src, LoadTy, DL);
471 }
472 
473 /// This function is called when we have a
474 /// memdep query of a load that ends up being a clobbering mem intrinsic.
476  Type *LoadTy, Instruction *InsertPt,
477  const DataLayout &DL) {
478  IRBuilder<> Builder(InsertPt);
479  return getMemInstValueForLoadHelper<Value, IRBuilder<>>(SrcInst, Offset,
480  LoadTy, Builder, DL);
481 }
482 
484  Type *LoadTy, const DataLayout &DL) {
485  // The only case analyzeLoadFromClobberingMemInst cannot be converted to a
486  // constant is when it's a memset of a non-constant.
487  if (auto *MSI = dyn_cast<MemSetInst>(SrcInst))
488  if (!isa<Constant>(MSI->getValue()))
489  return nullptr;
491  return getMemInstValueForLoadHelper<Constant, ConstantFolder>(SrcInst, Offset,
492  LoadTy, F, DL);
493 }
494 } // namespace VNCoercion
495 } // namespace llvm
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
uint64_t getTypeStoreSizeInBits(Type *Ty) const
Returns the maximum number of bits that may be overwritten by storing the specified type; always a mu...
Definition: DataLayout.h:394
bool isSimple() const
Definition: Instructions.h:262
int analyzeLoadFromClobberingLoad(Type *LoadTy, Value *LoadPtr, LoadInst *DepLI, const DataLayout &DL)
This function determines whether a value for the pointer LoadPtr can be extracted from the load at De...
Definition: VNCoercion.cpp:219
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant *> IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
Definition: Constants.h:1115
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
Definition: Type.cpp:617
This class wraps the llvm.memset intrinsic.
F(f)
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:503
An instruction for reading from memory.
Definition: Instructions.h:164
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:177
Value * getLength() const
Constant * getConstantMemInstValueForLoad(MemIntrinsic *SrcInst, unsigned Offset, Type *LoadTy, const DataLayout &DL)
Definition: VNCoercion.cpp:483
Value * getMemInstValueForLoad(MemIntrinsic *SrcInst, unsigned Offset, Type *LoadTy, Instruction *InsertPt, const DataLayout &DL)
If analyzeLoadFromClobberingMemInst returned an offset, this function can be used to actually perform...
Definition: VNCoercion.cpp:475
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:130
Value * getDest() const
This is just like getRawDest, but it strips off any cast instructions (including addrspacecast) that ...
Value * coerceAvailableValueToLoadType(Value *StoredVal, Type *LoadedTy, IRBuilder<> &IRB, const DataLayout &DL)
If we saw a store of a value to memory, and then a load from a must-aliased pointer of a different ty...
Definition: VNCoercion.cpp:134
static unsigned getLoadLoadClobberFullWidthSize(const Value *MemLocBase, int64_t MemLocOffs, unsigned MemLocSize, const LoadInst *LI)
Looks at a memory location for a load (specified by MemLocBase, Offs, and Size) and compares it again...
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
int analyzeLoadFromClobberingMemInst(Type *LoadTy, Value *LoadPtr, MemIntrinsic *DepMI, const DataLayout &DL)
This function determines whether a value for the pointer LoadPtr can be extracted from the memory int...
Definition: VNCoercion.cpp:251
Constant * getConstantStoreValueForLoad(Constant *SrcVal, unsigned Offset, Type *LoadTy, const DataLayout &DL)
Definition: VNCoercion.cpp:351
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:197
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:668
Constant * ConstantFoldConstant(const Constant *C, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldConstant - Attempt to fold the constant using the specified DataLayout.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
Value * GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset, const DataLayout &DL)
Analyze the specified pointer to see if it can be expressed as a base pointer plus a constant offset...
bool canCoerceMustAliasedValueToLoad(Value *StoredVal, Type *LoadTy, const DataLayout &DL)
Return true if CoerceAvailableValueToLoadType would succeed if it was called.
Definition: VNCoercion.cpp:15
static T * getStoreValueForLoadHelper(T *SrcVal, unsigned Offset, Type *LoadTy, HelperClass &Helper, const DataLayout &DL)
Definition: VNCoercion.cpp:300
ConstantFolder - Create constants with minimum, target independent, folding.
bool isLittleEndian() const
Layout endianness...
Definition: DataLayout.h:216
An instruction for storing to memory.
Definition: Instructions.h:306
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:430
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:292
int analyzeLoadFromClobberingStore(Type *LoadTy, Value *LoadPtr, StoreInst *DepSI, const DataLayout &DL)
This function determines whether a value for the pointer LoadPtr can be extracted from the store at D...
Definition: VNCoercion.cpp:202
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1678
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
Definition: DataLayout.cpp:702
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition: Constants.h:149
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:421
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
This is an important base class in LLVM.
Definition: Constant.h:42
Constant * getConstantLoadValueForLoad(Constant *SrcVal, unsigned Offset, Type *LoadTy, const DataLayout &DL)
Definition: VNCoercion.cpp:409
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:221
static int analyzeLoadFromClobberingWrite(Type *LoadTy, Value *LoadPtr, Value *WritePtr, uint64_t WriteSizeInBits, const DataLayout &DL)
This function is called when we have a memdep query of a load that ends up being a clobbering memory ...
Definition: VNCoercion.cpp:147
Value * getPointerOperand()
Definition: Instructions.h:270
Value * getLoadValueForLoad(LoadInst *SrcVal, unsigned Offset, Type *LoadTy, Instruction *InsertPt, const DataLayout &DL)
If analyzeLoadFromClobberingLoad returned an offset, this function can be used to actually perform th...
Definition: VNCoercion.cpp:363
void setAlignment(unsigned Align)
Constant * ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty, const DataLayout &DL)
ConstantFoldLoadFromConstPtr - Return the value that a load from C would produce if it is constant an...
uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
Definition: MathExtras.h:632
const AMDGPUAS & AS
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:220
Value * GetUnderlyingObject(Value *V, const DataLayout &DL, unsigned MaxLookup=6)
This method strips off any GEP address adjustments and pointer casts from the specified value...
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
Definition: IntrinsicInst.h:51
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition: Type.h:224
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:240
This is the common base class for memset/memcpy/memmove.
This is the shared class of boolean and integer constants.
Definition: Constants.h:84
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:560
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
static T * coerceAvailableValueToLoadTypeHelper(T *StoredVal, Type *LoadedTy, HelperClass &Helper, const DataLayout &DL)
Definition: VNCoercion.cpp:36
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:91
bool isNonIntegralPointerType(PointerType *PT) const
Definition: DataLayout.h:330
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:530
This class wraps the llvm.memcpy/memmove intrinsics.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:284
unsigned getAlignment() const
Return the alignment of the access that is being performed.
Definition: Instructions.h:226
Value * getStoreValueForLoad(Value *SrcVal, unsigned Offset, Type *LoadTy, Instruction *InsertPt, const DataLayout &DL)
If analyzeLoadFromClobberingStore returned an offset, this function can be used to actually perform t...
Definition: VNCoercion.cpp:343
Value * getSource() const
This is just like getRawSource, but it strips off any cast instructions that feed it...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
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
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
#define DEBUG(X)
Definition: Debug.h:118
T * getMemInstValueForLoadHelper(MemIntrinsic *SrcInst, unsigned Offset, Type *LoadTy, HelperClass &Helper, const DataLayout &DL)
Definition: VNCoercion.cpp:419
IRTranslator LLVM IR MI
bool isBigEndian() const
Definition: DataLayout.h:217
Value * getPointerOperand()
Definition: Instructions.h:398
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:174
bool isStructTy() const
True if this is an instance of StructType.
Definition: Type.h:215
bool isArrayTy() const
True if this is an instance of ArrayType.
Definition: Type.h:218
const BasicBlock * getParent() const
Definition: Instruction.h:66