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