LLVM 23.0.0git
VNCoercion.cpp
Go to the documentation of this file.
4#include "llvm/IR/IRBuilder.h"
6
7#define DEBUG_TYPE "vncoerce"
8
9using namespace llvm;
10using namespace VNCoercion;
11
13 return Ty->isStructTy() || Ty->isArrayTy() || isa<ScalableVectorType>(Ty);
14}
15
16/// Return true if coerceAvailableValueToLoadType will succeed.
18 Function *F) {
19 Type *StoredTy = StoredVal->getType();
20 if (StoredTy == LoadTy)
21 return true;
22
23 const DataLayout &DL = F->getDataLayout();
24 TypeSize MinStoreSize = DL.getTypeSizeInBits(StoredTy);
25 TypeSize LoadSize = DL.getTypeSizeInBits(LoadTy);
26 if (isa<ScalableVectorType>(StoredTy) && isa<ScalableVectorType>(LoadTy) &&
27 MinStoreSize == LoadSize)
28 return true;
29
30 // If the loaded/stored value is a first class array/struct, don't try to
31 // transform them. We need to be able to bitcast to integer. For scalable
32 // vectors forwarded to fixed-sized vectors @llvm.vector.extract is used.
33 if (isa<ScalableVectorType>(StoredTy) && isa<FixedVectorType>(LoadTy)) {
34 if (StoredTy->getScalarType() != LoadTy->getScalarType())
35 return false;
36
37 // If it is known at compile-time that the VScale is larger than one,
38 // use that information to allow for wider loads.
39 const auto &Attrs = F->getAttributes().getFnAttrs();
40 unsigned MinVScale = Attrs.getVScaleRangeMin();
41 MinStoreSize =
42 TypeSize::getFixed(MinStoreSize.getKnownMinValue() * MinVScale);
43 } else if (isFirstClassAggregateOrScalableType(LoadTy) ||
45 return false;
46 }
47
48 // The store size must be byte-aligned to support future type casts.
49 if (llvm::alignTo(MinStoreSize, 8) != MinStoreSize)
50 return false;
51
52 // The store has to be at least as big as the load.
53 if (!TypeSize::isKnownGE(MinStoreSize, LoadSize))
54 return false;
55
56 bool StoredNI = DL.isNonIntegralPointerType(StoredTy->getScalarType());
57 bool LoadNI = DL.isNonIntegralPointerType(LoadTy->getScalarType());
58 // Don't coerce non-integral pointers to integers or vice versa.
59 if (StoredNI != LoadNI) {
60 // As a special case, allow coercion of memset used to initialize
61 // an array w/null. Despite non-integral pointers not generally having a
62 // specific bit pattern, we do assume null is zero.
63 if (auto *CI = dyn_cast<Constant>(StoredVal))
64 return CI->isNullValue();
65 return false;
66 } else if (StoredNI && LoadNI &&
67 StoredTy->getPointerAddressSpace() !=
68 LoadTy->getPointerAddressSpace()) {
69 return false;
70 }
71
72 // The implementation below uses inttoptr for vectors of unequal size; we
73 // can't allow this for non integral pointers. We could teach it to extract
74 // exact subvectors if desired.
75 if (StoredNI && (StoredTy->isScalableTy() || MinStoreSize != LoadSize))
76 return false;
77
78 if (StoredTy->isTargetExtTy() || LoadTy->isTargetExtTy())
79 return false;
80
81 return true;
82}
83
84/// If we saw a store of a value to memory, and
85/// then a load from a must-aliased pointer of a different type, try to coerce
86/// the stored value. LoadedTy is the type of the load we want to replace.
87/// IRB is IRBuilder used to insert new instructions.
88///
89/// If we can't do it, return null.
91 Type *LoadedTy,
92 IRBuilderBase &Helper,
93 Function *F) {
94 assert(canCoerceMustAliasedValueToLoad(StoredVal, LoadedTy, F) &&
95 "precondition violation - materialization can't fail");
96 const DataLayout &DL = F->getDataLayout();
97 if (auto *C = dyn_cast<Constant>(StoredVal))
98 StoredVal = ConstantFoldConstant(C, DL);
99
100 // If this is already the right type, just return it.
101 Type *StoredValTy = StoredVal->getType();
102
103 // If this is a scalable vector forwarded to a fixed vector load, create
104 // a @llvm.vector.extract instead of bitcasts.
105 if (isa<ScalableVectorType>(StoredVal->getType()) &&
106 isa<FixedVectorType>(LoadedTy)) {
107 return Helper.CreateIntrinsic(LoadedTy, Intrinsic::vector_extract,
108 {StoredVal, Helper.getInt64(0)});
109 }
110
111 TypeSize StoredValSize = DL.getTypeSizeInBits(StoredValTy);
112 TypeSize LoadedValSize = DL.getTypeSizeInBits(LoadedTy);
113
114 // If the store and reload are the same size, we can always reuse it.
115 if (StoredValSize == LoadedValSize) {
116 // Pointer to Pointer -> use bitcast.
117 if (StoredValTy->isPtrOrPtrVectorTy() && LoadedTy->isPtrOrPtrVectorTy()) {
118 StoredVal = Helper.CreateBitCast(StoredVal, LoadedTy);
119 } else {
120 // Convert source pointers to integers, which can be bitcast.
121 if (StoredValTy->isPtrOrPtrVectorTy()) {
122 StoredValTy = DL.getIntPtrType(StoredValTy);
123 StoredVal = Helper.CreatePtrToInt(StoredVal, StoredValTy);
124 }
125
126 Type *TypeToCastTo = LoadedTy;
127 if (TypeToCastTo->isPtrOrPtrVectorTy())
128 TypeToCastTo = DL.getIntPtrType(TypeToCastTo);
129
130 if (StoredValTy != TypeToCastTo)
131 StoredVal = Helper.CreateBitCast(StoredVal, TypeToCastTo);
132
133 // Cast to pointer if the load needs a pointer type.
134 if (LoadedTy->isPtrOrPtrVectorTy())
135 StoredVal = Helper.CreateIntToPtr(StoredVal, LoadedTy);
136 }
137
138 if (auto *C = dyn_cast<ConstantExpr>(StoredVal))
139 StoredVal = ConstantFoldConstant(C, DL);
140
141 return StoredVal;
142 }
143 // If the loaded value is smaller than the available value, then we can
144 // extract out a piece from it. If the available value is too small, then we
145 // can't do anything.
146 assert(!StoredValSize.isScalable() &&
147 TypeSize::isKnownGE(StoredValSize, LoadedValSize) &&
148 "canCoerceMustAliasedValueToLoad fail");
149
150 // Convert source pointers to integers, which can be manipulated.
151 if (StoredValTy->isPtrOrPtrVectorTy()) {
152 StoredValTy = DL.getIntPtrType(StoredValTy);
153 StoredVal = Helper.CreatePtrToInt(StoredVal, StoredValTy);
154 }
155
156 // Convert vectors and fp to integer, which can be manipulated.
157 if (!StoredValTy->isIntegerTy()) {
158 StoredValTy = IntegerType::get(StoredValTy->getContext(), StoredValSize);
159 StoredVal = Helper.CreateBitCast(StoredVal, StoredValTy);
160 }
161
162 // If this is a big-endian system, we need to shift the value down to the low
163 // bits so that a truncate will work.
164 if (DL.isBigEndian()) {
165 uint64_t ShiftAmt = DL.getTypeStoreSizeInBits(StoredValTy).getFixedValue() -
166 DL.getTypeStoreSizeInBits(LoadedTy).getFixedValue();
167 StoredVal = Helper.CreateLShr(
168 StoredVal, ConstantInt::get(StoredVal->getType(), ShiftAmt));
169 }
170
171 // Truncate the integer to the right size now.
172 Type *NewIntTy = IntegerType::get(StoredValTy->getContext(), LoadedValSize);
173 StoredVal = Helper.CreateTruncOrBitCast(StoredVal, NewIntTy);
174
175 if (LoadedTy != NewIntTy) {
176 // If the result is a pointer, inttoptr.
177 if (LoadedTy->isPtrOrPtrVectorTy())
178 StoredVal = Helper.CreateIntToPtr(StoredVal, LoadedTy);
179 else
180 // Otherwise, bitcast.
181 StoredVal = Helper.CreateBitCast(StoredVal, LoadedTy);
182 }
183
184 if (auto *C = dyn_cast<Constant>(StoredVal))
185 StoredVal = ConstantFoldConstant(C, DL);
186
187 return StoredVal;
188}
189
190/// This function is called when we have a memdep query of a load that ends up
191/// being a clobbering memory write (store, memset, memcpy, memmove). This
192/// means that the write *may* provide bits used by the load but we can't be
193/// sure because the pointers don't must-alias.
194///
195/// Check this case to see if there is anything more we can do before we give
196/// up. This returns -1 if we have to give up, or a byte number in the stored
197/// value of the piece that feeds the load.
198static int analyzeLoadFromClobberingWrite(Type *LoadTy, Value *LoadPtr,
199 Value *WritePtr,
200 uint64_t WriteSizeInBits,
201 const DataLayout &DL) {
202 // If the loaded/stored value is a first class array/struct, or scalable type,
203 // don't try to transform them. We need to be able to bitcast to integer.
205 return -1;
206
207 int64_t StoreOffset = 0, LoadOffset = 0;
208 Value *StoreBase =
209 GetPointerBaseWithConstantOffset(WritePtr, StoreOffset, DL);
210 Value *LoadBase = GetPointerBaseWithConstantOffset(LoadPtr, LoadOffset, DL);
211 if (StoreBase != LoadBase)
212 return -1;
213
214 uint64_t LoadSize = DL.getTypeSizeInBits(LoadTy).getFixedValue();
215
216 if ((WriteSizeInBits & 7) | (LoadSize & 7))
217 return -1;
218 uint64_t StoreSize = WriteSizeInBits / 8; // Convert to bytes.
219 LoadSize /= 8;
220
221 // If the Load isn't completely contained within the stored bits, we don't
222 // have all the bits to feed it. We could do something crazy in the future
223 // (issue a smaller load then merge the bits in) but this seems unlikely to be
224 // valuable.
225 if (StoreOffset > LoadOffset ||
226 StoreOffset + int64_t(StoreSize) < LoadOffset + int64_t(LoadSize))
227 return -1;
228
229 // Okay, we can do this transformation. Return the number of bytes into the
230 // store that the load is.
231 return LoadOffset - StoreOffset;
232}
233
234/// This function is called when we have a
235/// memdep query of a load that ends up being a clobbering store.
237 StoreInst *DepSI,
238 const DataLayout &DL) {
239 auto *StoredVal = DepSI->getValueOperand();
240
241 // Cannot handle reading from store of first-class aggregate or scalable type.
242 if (isFirstClassAggregateOrScalableType(StoredVal->getType()))
243 return -1;
244
245 if (!canCoerceMustAliasedValueToLoad(StoredVal, LoadTy, DepSI->getFunction()))
246 return -1;
247
248 Value *StorePtr = DepSI->getPointerOperand();
249 uint64_t StoreSize =
250 DL.getTypeSizeInBits(DepSI->getValueOperand()->getType()).getFixedValue();
251 return analyzeLoadFromClobberingWrite(LoadTy, LoadPtr, StorePtr, StoreSize,
252 DL);
253}
254
255/// This function is called when we have a
256/// memdep query of a load that ends up being clobbered by another load. See if
257/// the other load can feed into the second load.
259 LoadInst *DepLI,
260 const DataLayout &DL) {
261 // Cannot handle reading from store of first-class aggregate or scalable type.
263 return -1;
264
265 if (!canCoerceMustAliasedValueToLoad(DepLI, LoadTy, DepLI->getFunction()))
266 return -1;
267
268 Value *DepPtr = DepLI->getPointerOperand();
269 uint64_t DepSize = DL.getTypeSizeInBits(DepLI->getType()).getFixedValue();
270 return analyzeLoadFromClobberingWrite(LoadTy, LoadPtr, DepPtr, DepSize, DL);
271}
272
275 const DataLayout &DL) {
276 // If the mem operation is a non-constant size, we can't handle it.
277 ConstantInt *SizeCst = dyn_cast<ConstantInt>(MI->getLength());
278 if (!SizeCst)
279 return -1;
280 uint64_t MemSizeInBits = SizeCst->getZExtValue() * 8;
281
282 // If this is memset, we just need to see if the offset is valid in the size
283 // of the memset..
284 if (const auto *Memset = dyn_cast<MemSetInst>(MI)) {
285 if (DL.isNonIntegralPointerType(LoadTy->getScalarType())) {
286 auto *CI = dyn_cast<ConstantInt>(Memset->getValue());
287 if (!CI || !CI->isZero())
288 return -1;
289 }
290 return analyzeLoadFromClobberingWrite(LoadTy, LoadPtr, MI->getDest(),
291 MemSizeInBits, DL);
292 }
293
294 // If we have a memcpy/memmove, the only case we can handle is if this is a
295 // copy from constant memory. In that case, we can read directly from the
296 // constant memory.
298
300 if (!Src)
301 return -1;
302
304 if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer())
305 return -1;
306
307 // See if the access is within the bounds of the transfer.
308 int Offset = analyzeLoadFromClobberingWrite(LoadTy, LoadPtr, MI->getDest(),
309 MemSizeInBits, DL);
310 if (Offset == -1)
311 return Offset;
312
313 // Otherwise, see if we can constant fold a load from the constant with the
314 // offset applied as appropriate.
315 unsigned IndexSize = DL.getIndexTypeSizeInBits(Src->getType());
316 if (ConstantFoldLoadFromConstPtr(Src, LoadTy, APInt(IndexSize, Offset), DL))
317 return Offset;
318 return -1;
319}
320
322 Type *LoadTy, IRBuilderBase &Builder,
323 const DataLayout &DL) {
324 LLVMContext &Ctx = SrcVal->getType()->getContext();
325
326 // If two pointers are in the same address space, they have the same size,
327 // so we don't need to do any truncation, etc. This avoids introducing
328 // ptrtoint instructions for pointers that may be non-integral.
329 if (SrcVal->getType()->isPointerTy() && LoadTy->isPointerTy() &&
330 cast<PointerType>(SrcVal->getType())->getAddressSpace() ==
331 cast<PointerType>(LoadTy)->getAddressSpace()) {
332 return SrcVal;
333 }
334
335 // Return scalable values directly to avoid needing to bitcast to integer
336 // types, as we do not support non-zero Offsets.
337 if (isa<ScalableVectorType>(LoadTy)) {
338 assert(Offset == 0 && "Expected a zero offset for scalable types");
339 return SrcVal;
340 }
341
342 // For the case of a scalable vector being forwarded to a fixed-sized load,
343 // only equal element types are allowed and a @llvm.vector.extract will be
344 // used instead of bitcasts.
345 if (isa<ScalableVectorType>(SrcVal->getType()) &&
346 isa<FixedVectorType>(LoadTy)) {
347 assert(Offset == 0 &&
348 SrcVal->getType()->getScalarType() == LoadTy->getScalarType());
349 return SrcVal;
350 }
351
352 uint64_t StoreSize =
353 (DL.getTypeSizeInBits(SrcVal->getType()).getFixedValue() + 7) / 8;
354 uint64_t LoadSize = (DL.getTypeSizeInBits(LoadTy).getFixedValue() + 7) / 8;
355 // Compute which bits of the stored value are being used by the load. Convert
356 // to an integer type to start with.
357 if (SrcVal->getType()->isPtrOrPtrVectorTy())
358 SrcVal =
359 Builder.CreatePtrToInt(SrcVal, DL.getIntPtrType(SrcVal->getType()));
360 if (!SrcVal->getType()->isIntegerTy())
361 SrcVal =
362 Builder.CreateBitCast(SrcVal, IntegerType::get(Ctx, StoreSize * 8));
363
364 // Shift the bits to the least significant depending on endianness.
365 unsigned ShiftAmt;
366 if (DL.isLittleEndian())
367 ShiftAmt = Offset * 8;
368 else
369 ShiftAmt = (StoreSize - LoadSize - Offset) * 8;
370 if (ShiftAmt)
371 SrcVal = Builder.CreateLShr(SrcVal,
372 ConstantInt::get(SrcVal->getType(), ShiftAmt));
373
374 if (LoadSize != StoreSize)
375 SrcVal = Builder.CreateTruncOrBitCast(SrcVal,
376 IntegerType::get(Ctx, LoadSize * 8));
377 return SrcVal;
378}
379
381 Instruction *InsertPt, Function *F) {
382 const DataLayout &DL = F->getDataLayout();
383#ifndef NDEBUG
384 TypeSize MinSrcValSize = DL.getTypeStoreSize(SrcVal->getType());
385 TypeSize LoadSize = DL.getTypeStoreSize(LoadTy);
386 if (MinSrcValSize.isScalable() && !LoadSize.isScalable())
387 MinSrcValSize =
388 TypeSize::getFixed(MinSrcValSize.getKnownMinValue() *
389 F->getAttributes().getFnAttrs().getVScaleRangeMin());
390 assert((MinSrcValSize.isScalable() || Offset + LoadSize <= MinSrcValSize) &&
391 "Expected Offset + LoadSize <= SrcValSize");
392 assert((!MinSrcValSize.isScalable() ||
393 (Offset == 0 && TypeSize::isKnownLE(LoadSize, MinSrcValSize))) &&
394 "Expected offset of zero and LoadSize <= SrcValSize");
395#endif
396 IRBuilder<> Builder(InsertPt);
397 SrcVal = getStoreValueForLoadHelper(SrcVal, Offset, LoadTy, Builder, DL);
398 return coerceAvailableValueToLoadType(SrcVal, LoadTy, Builder, F);
399}
400
402 Type *LoadTy,
403 const DataLayout &DL) {
404#ifndef NDEBUG
405 unsigned SrcValSize = DL.getTypeStoreSize(SrcVal->getType()).getFixedValue();
406 unsigned LoadSize = DL.getTypeStoreSize(LoadTy).getFixedValue();
407 assert(Offset + LoadSize <= SrcValSize);
408#endif
409 return ConstantFoldLoadFromConst(SrcVal, LoadTy, APInt(32, Offset), DL);
410}
411
412/// This function is called when we have a
413/// memdep query of a load that ends up being a clobbering mem intrinsic.
415 unsigned Offset, Type *LoadTy,
416 Instruction *InsertPt,
417 const DataLayout &DL) {
418 LLVMContext &Ctx = LoadTy->getContext();
419 uint64_t LoadSize = DL.getTypeSizeInBits(LoadTy).getFixedValue() / 8;
420 IRBuilder<> Builder(InsertPt);
421
422 // We know that this method is only called when the mem transfer fully
423 // provides the bits for the load.
424 if (MemSetInst *MSI = dyn_cast<MemSetInst>(SrcInst)) {
425 // memset(P, 'x', 1234) -> splat('x'), even if x is a variable, and
426 // independently of what the offset is.
427 Value *Val = MSI->getValue();
428 if (LoadSize != 1)
429 Val =
430 Builder.CreateZExtOrBitCast(Val, IntegerType::get(Ctx, LoadSize * 8));
431 Value *OneElt = Val;
432
433 // Splat the value out to the right number of bits.
434 for (unsigned NumBytesSet = 1; NumBytesSet != LoadSize;) {
435 // If we can double the number of bytes set, do it.
436 if (NumBytesSet * 2 <= LoadSize) {
437 Value *ShVal = Builder.CreateShl(
438 Val, ConstantInt::get(Val->getType(), NumBytesSet * 8));
439 Val = Builder.CreateOr(Val, ShVal);
440 NumBytesSet <<= 1;
441 continue;
442 }
443
444 // Otherwise insert one byte at a time.
445 Value *ShVal =
446 Builder.CreateShl(Val, ConstantInt::get(Val->getType(), 1 * 8));
447 Val = Builder.CreateOr(OneElt, ShVal);
448 ++NumBytesSet;
449 }
450
451 return coerceAvailableValueToLoadType(Val, LoadTy, Builder,
452 InsertPt->getFunction());
453 }
454
455 // Otherwise, this is a memcpy/memmove from a constant global.
457 Constant *Src = cast<Constant>(MTI->getSource());
458 unsigned IndexSize = DL.getIndexTypeSizeInBits(Src->getType());
459 return ConstantFoldLoadFromConstPtr(Src, LoadTy, APInt(IndexSize, Offset),
460 DL);
461}
462
464 unsigned Offset,
465 Type *LoadTy,
466 const DataLayout &DL) {
467 LLVMContext &Ctx = LoadTy->getContext();
468 uint64_t LoadSize = DL.getTypeSizeInBits(LoadTy).getFixedValue() / 8;
469
470 // We know that this method is only called when the mem transfer fully
471 // provides the bits for the load.
472 if (MemSetInst *MSI = dyn_cast<MemSetInst>(SrcInst)) {
473 auto *Val = dyn_cast<ConstantInt>(MSI->getValue());
474 if (!Val)
475 return nullptr;
476
477 Val = ConstantInt::get(Ctx, APInt::getSplat(LoadSize * 8, Val->getValue()));
478 return ConstantFoldLoadFromConst(Val, LoadTy, DL);
479 }
480
481 // Otherwise, this is a memcpy/memmove from a constant global.
483 Constant *Src = cast<Constant>(MTI->getSource());
484 unsigned IndexSize = DL.getIndexTypeSizeInBits(Src->getType());
485 return ConstantFoldLoadFromConstPtr(Src, LoadTy, APInt(IndexSize, Offset),
486 DL);
487}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition MD5.cpp:54
static bool isFirstClassAggregateOrScalableType(Type *Ty)
static Value * getStoreValueForLoadHelper(Value *SrcVal, unsigned Offset, Type *LoadTy, IRBuilderBase &Builder, const DataLayout &DL)
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 ...
Class for arbitrary precision integers.
Definition APInt.h:78
static LLVM_ABI APInt getSplat(unsigned NewLen, const APInt &V)
Return a value containing V broadcasted over NewLen bits.
Definition APInt.cpp:651
This is the shared class of boolean and integer constants.
Definition Constants.h:87
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:168
This is an important base class in LLVM.
Definition Constant.h:43
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
bool hasDefinitiveInitializer() const
hasDefinitiveInitializer - Whether the global variable has an initializer, and any other instances of...
Common base class shared among various IRBuilders.
Definition IRBuilder.h:114
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2171
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1516
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
Definition IRBuilder.h:527
LLVM_ABI CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > Types, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with Args, mangled using Types.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2176
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2166
Value * CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2202
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2787
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:318
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
An instruction for reading from memory.
Value * getPointerOperand()
This is the common base class for memset/memcpy/memmove.
This class wraps the llvm.memset and llvm.memset.inline intrinsics.
Value * getSource() const
This is just like getRawSource, but it strips off any cast instructions that feed it,...
This class wraps the llvm.memcpy/memmove intrinsics.
An instruction for storing to memory.
Value * getValueOperand()
Value * getPointerOperand()
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:343
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
LLVM_ABI bool isScalableTy(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this is a type whose size is a known multiple of vscale.
Definition Type.cpp:61
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:267
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:352
bool isTargetExtTy() const
Return true if this is a target extension type.
Definition Type.h:203
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition Type.h:128
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition Type.h:270
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:240
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
static constexpr bool isKnownLE(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
Definition TypeSize.h:230
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition TypeSize.h:168
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition TypeSize.h:165
static constexpr bool isKnownGE(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
Definition TypeSize.h:237
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
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...
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...
Constant * getConstantValueForLoad(Constant *SrcVal, unsigned Offset, Type *LoadTy, const DataLayout &DL)
Value * coerceAvailableValueToLoadType(Value *StoredVal, Type *LoadedTy, IRBuilderBase &IRB, Function *F)
If we saw a store of a value to memory, and then a load from a must-aliased pointer of a different ty...
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...
Constant * getConstantMemInstValueForLoad(MemIntrinsic *SrcInst, unsigned Offset, Type *LoadTy, const DataLayout &DL)
Value * getValueForLoad(Value *SrcVal, unsigned Offset, Type *LoadTy, Instruction *InsertPt, Function *F)
If analyzeLoadFromClobberingStore/Load returned an offset, this function can be used to actually perf...
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...
bool canCoerceMustAliasedValueToLoad(Value *StoredVal, Type *LoadTy, Function *F)
Return true if CoerceAvailableValueToLoadType would succeed if it was called.
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ Offset
Definition DWP.cpp:532
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
Value * GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset, const DataLayout &DL, bool AllowNonInbounds=true)
Analyze the specified pointer to see if it can be expressed as a base pointer plus a constant offset.
LLVM_ABI Constant * ConstantFoldConstant(const Constant *C, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldConstant - Fold the constant using the specified DataLayout.
LLVM_ABI Constant * ConstantFoldLoadFromConst(Constant *C, Type *Ty, const APInt &Offset, const DataLayout &DL)
Extract value of C at the given Offset reinterpreted as Ty.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:144
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
LLVM_ABI Constant * ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty, APInt Offset, const DataLayout &DL)
Return the value that a load from C with offset Offset would produce if it is constant and determinab...
LLVM_ABI const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=MaxLookupSearchDepth)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....