LLVM 24.0.0git
DXILFlattenArrays.cpp
Go to the documentation of this file.
1//===- DXILFlattenArrays.cpp - Flattens DXIL Arrays-----------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===---------------------------------------------------------------------===//
8///
9/// \file This file contains a pass to flatten arrays for the DirectX Backend.
10///
11//===----------------------------------------------------------------------===//
12
13#include "DirectX.h"
15#include "llvm/ADT/STLExtras.h"
16#include "llvm/IR/BasicBlock.h"
18#include "llvm/IR/IRBuilder.h"
19#include "llvm/IR/InstVisitor.h"
24#include <cassert>
25#include <cstdint>
26#include <utility>
27
28#define DEBUG_TYPE "dxil-flatten-arrays"
29
30using namespace llvm;
31namespace {
32
33class DXILFlattenArraysLegacy : public ModulePass {
34
35public:
36 bool runOnModule(Module &M) override;
37 DXILFlattenArraysLegacy() : ModulePass(ID) {}
38
39 static char ID; // Pass identification.
40};
41
42struct GEPInfo {
43 ArrayType *RootFlattenedArrayType;
44 Value *RootPointerOperand;
46 APInt ConstantOffset;
47};
48
49class DXILFlattenArraysVisitor
50 : public InstVisitor<DXILFlattenArraysVisitor, bool> {
51public:
52 DXILFlattenArraysVisitor(
54 : GlobalMap(GlobalMap) {}
55 bool visit(Function &F);
56 // InstVisitor methods. They return true if the instruction was scalarized,
57 // false if nothing changed.
58 bool visitGetElementPtrInst(GetElementPtrInst &GEPI);
59 bool visitAllocaInst(AllocaInst &AI);
60 bool visitInstruction(Instruction &I) { return false; }
61 bool visitSelectInst(SelectInst &SI) { return false; }
62 bool visitICmpInst(ICmpInst &ICI) { return false; }
63 bool visitFCmpInst(FCmpInst &FCI) { return false; }
64 bool visitUnaryOperator(UnaryOperator &UO) { return false; }
65 bool visitBinaryOperator(BinaryOperator &BO) { return false; }
66 bool visitCastInst(CastInst &CI) { return false; }
67 bool visitBitCastInst(BitCastInst &BCI) { return false; }
68 bool visitInsertElementInst(InsertElementInst &IEI) { return false; }
69 bool visitExtractElementInst(ExtractElementInst &EEI) { return false; }
70 bool visitShuffleVectorInst(ShuffleVectorInst &SVI) { return false; }
71 bool visitPHINode(PHINode &PHI) { return false; }
72 bool visitLoadInst(LoadInst &LI);
73 bool visitStoreInst(StoreInst &SI);
74 bool visitCallInst(CallInst &ICI) { return false; }
75 bool visitFreezeInst(FreezeInst &FI) { return false; }
76 static bool isMultiDimensionalArray(Type *T);
77 static std::pair<unsigned, Type *> getElementCountAndType(Type *ArrayTy);
78
79private:
80 SmallVector<WeakTrackingVH> PotentiallyDeadInstrs;
83 bool finish();
84 ConstantInt *genConstFlattenIndices(ArrayRef<Value *> Indices,
86 IRBuilder<> &Builder);
87 Value *genInstructionFlattenIndices(ArrayRef<Value *> Indices,
89 IRBuilder<> &Builder);
90};
91} // namespace
92
93bool DXILFlattenArraysVisitor::finish() {
94 GEPChainInfoMap.clear();
96 return true;
97}
98
99bool DXILFlattenArraysVisitor::isMultiDimensionalArray(Type *T) {
100 if (ArrayType *ArrType = dyn_cast<ArrayType>(T))
101 return isa<ArrayType>(ArrType->getElementType());
102 return false;
103}
104
105std::pair<unsigned, Type *>
106DXILFlattenArraysVisitor::getElementCountAndType(Type *ArrayTy) {
107 unsigned TotalElements = 1;
108 Type *CurrArrayTy = ArrayTy;
109 while (auto *InnerArrayTy = dyn_cast<ArrayType>(CurrArrayTy)) {
110 TotalElements *= InnerArrayTy->getNumElements();
111 CurrArrayTy = InnerArrayTy->getElementType();
112 }
113 return std::make_pair(TotalElements, CurrArrayTy);
114}
115
116ConstantInt *DXILFlattenArraysVisitor::genConstFlattenIndices(
117 ArrayRef<Value *> Indices, ArrayRef<uint64_t> Dims, IRBuilder<> &Builder) {
118 assert(Indices.size() == Dims.size() &&
119 "Indicies and dimmensions should be the same");
120 unsigned FlatIndex = 0;
121 unsigned Multiplier = 1;
122
123 for (int I = Indices.size() - 1; I >= 0; --I) {
124 unsigned DimSize = Dims[I];
125 ConstantInt *CIndex = dyn_cast<ConstantInt>(Indices[I]);
126 assert(CIndex && "This function expects all indicies to be ConstantInt");
127 FlatIndex += CIndex->getZExtValue() * Multiplier;
128 Multiplier *= DimSize;
129 }
130 return Builder.getInt32(FlatIndex);
131}
132
133Value *DXILFlattenArraysVisitor::genInstructionFlattenIndices(
134 ArrayRef<Value *> Indices, ArrayRef<uint64_t> Dims, IRBuilder<> &Builder) {
135 if (Indices.size() == 1)
136 return Indices[0];
137
138 Value *FlatIndex = Builder.getInt32(0);
139 unsigned Multiplier = 1;
140
141 for (int I = Indices.size() - 1; I >= 0; --I) {
142 unsigned DimSize = Dims[I];
143 Value *VMultiplier = Builder.getInt32(Multiplier);
144 Value *ScaledIndex = Builder.CreateMul(Indices[I], VMultiplier);
145 FlatIndex = Builder.CreateAdd(FlatIndex, ScaledIndex);
146 Multiplier *= DimSize;
147 }
148 return FlatIndex;
149}
150
151bool DXILFlattenArraysVisitor::visitLoadInst(LoadInst &LI) {
152 unsigned NumOperands = LI.getNumOperands();
153 for (unsigned I = 0; I < NumOperands; ++I) {
154 Value *CurrOpperand = LI.getOperand(I);
155 ConstantExpr *CE = dyn_cast<ConstantExpr>(CurrOpperand);
156 if (CE && CE->getOpcode() == Instruction::GetElementPtr) {
157 GetElementPtrInst *OldGEP =
158 cast<GetElementPtrInst>(CE->getAsInstruction());
159 OldGEP->insertBefore(LI.getIterator());
160
161 IRBuilder<> Builder(&LI);
162 LoadInst *NewLoad =
163 Builder.CreateLoad(LI.getType(), OldGEP, LI.getName());
164 NewLoad->setAlignment(LI.getAlign());
165 LI.replaceAllUsesWith(NewLoad);
166 LI.eraseFromParent();
167 visitGetElementPtrInst(*OldGEP);
168 return true;
169 }
170 }
171 return false;
172}
173
174bool DXILFlattenArraysVisitor::visitStoreInst(StoreInst &SI) {
175 unsigned NumOperands = SI.getNumOperands();
176 for (unsigned I = 0; I < NumOperands; ++I) {
177 Value *CurrOpperand = SI.getOperand(I);
178 ConstantExpr *CE = dyn_cast<ConstantExpr>(CurrOpperand);
179 if (CE && CE->getOpcode() == Instruction::GetElementPtr) {
180 GetElementPtrInst *OldGEP =
181 cast<GetElementPtrInst>(CE->getAsInstruction());
182 OldGEP->insertBefore(SI.getIterator());
183
184 IRBuilder<> Builder(&SI);
185 StoreInst *NewStore = Builder.CreateStore(SI.getValueOperand(), OldGEP);
186 NewStore->setAlignment(SI.getAlign());
187 SI.replaceAllUsesWith(NewStore);
188 SI.eraseFromParent();
189 visitGetElementPtrInst(*OldGEP);
190 return true;
191 }
192 }
193 return false;
194}
195
196bool DXILFlattenArraysVisitor::visitAllocaInst(AllocaInst &AI) {
197 if (!isMultiDimensionalArray(AI.getAllocatedType()))
198 return false;
199
201 IRBuilder<> Builder(&AI);
202 auto [TotalElements, BaseType] = getElementCountAndType(ArrType);
203
204 ArrayType *FattenedArrayType = ArrayType::get(BaseType, TotalElements);
205 AllocaInst *FlatAlloca =
206 Builder.CreateAlloca(FattenedArrayType, nullptr, AI.getName() + ".1dim");
207 FlatAlloca->setAlignment(AI.getAlign());
208 AI.replaceAllUsesWith(FlatAlloca);
209 AI.eraseFromParent();
210 return true;
211}
212
213bool DXILFlattenArraysVisitor::visitGetElementPtrInst(GetElementPtrInst &GEP) {
214 // Do not visit GEPs more than once
215 if (GEPChainInfoMap.contains(cast<GEPOperator>(&GEP)))
216 return false;
217
218 Value *PtrOperand = GEP.getPointerOperand();
219 // It shouldn't(?) be possible for the pointer operand of a GEP to be a PHI
220 // node unless HLSL has pointers. If this assumption is incorrect or HLSL gets
221 // pointer types, then the handling of this case can be implemented later.
222 assert(!isa<PHINode>(PtrOperand) &&
223 "Pointer operand of GEP should not be a PHI Node");
224
225 // Replace a GEP ConstantExpr pointer operand with a GEP instruction so that
226 // it can be visited
227 if (auto *PtrOpGEPCE = dyn_cast<ConstantExpr>(PtrOperand);
228 PtrOpGEPCE && PtrOpGEPCE->getOpcode() == Instruction::GetElementPtr) {
229 GetElementPtrInst *OldGEPI =
230 cast<GetElementPtrInst>(PtrOpGEPCE->getAsInstruction());
231 OldGEPI->insertBefore(GEP.getIterator());
232
233 SmallVector<Value *> Indices(GEP.indices());
234 GetElementPtrInst *NewGEPI = GetElementPtrInst::Create(
235 GEP.getSourceElementType(), OldGEPI, Indices, GEP.getNoWrapFlags(),
236 GEP.getName(), GEP.getIterator());
237
238 GEP.replaceAllUsesWith(NewGEPI);
239 GEP.eraseFromParent();
240 visitGetElementPtrInst(*OldGEPI);
241 visitGetElementPtrInst(*NewGEPI);
242 return true;
243 }
244
245 // Construct GEPInfo for this GEP
246 GEPInfo Info;
247
248 // Obtain the variable and constant byte offsets computed by this GEP
249 const DataLayout &DL = GEP.getDataLayout();
250 unsigned BitWidth = DL.getIndexTypeSizeInBits(GEP.getType());
251 Info.ConstantOffset = {BitWidth, 0};
252 [[maybe_unused]] bool Success = GEP.collectOffset(
253 DL, BitWidth, Info.VariableOffsets, Info.ConstantOffset);
254 assert(Success && "Failed to collect offsets for GEP");
255
256 // If there is a parent GEP, inherit the root array type and pointer, and
257 // merge the byte offsets. Otherwise, this GEP is itself the root of a GEP
258 // chain and we need to deterine the root array type
259 if (auto *PtrOpGEP = dyn_cast<GEPOperator>(PtrOperand)) {
260
261 // If the parent GEP was not processed, then we do not want to process its
262 // descendants. This can happen if the GEP chain is for an unsupported type
263 // such as a struct -- we do not flatten structs nor GEP chains for structs
264 if (!GEPChainInfoMap.contains(PtrOpGEP))
265 return false;
266
267 GEPInfo &PGEPInfo = GEPChainInfoMap[PtrOpGEP];
268 Info.RootFlattenedArrayType = PGEPInfo.RootFlattenedArrayType;
269 Info.RootPointerOperand = PGEPInfo.RootPointerOperand;
270 for (auto &VariableOffset : PGEPInfo.VariableOffsets)
271 Info.VariableOffsets.insert(VariableOffset);
272 Info.ConstantOffset += PGEPInfo.ConstantOffset;
273 } else {
274 Info.RootPointerOperand = PtrOperand;
275
276 // We should try to determine the type of the root from the pointer rather
277 // than the GEP's source element type because this could be a scalar GEP
278 // into an array-typed pointer from an Alloca or Global Variable.
279 Type *RootTy = GEP.getSourceElementType();
280 if (auto *GlobalVar = dyn_cast<GlobalVariable>(PtrOperand)) {
281 if (GlobalMap.contains(GlobalVar))
282 GlobalVar = GlobalMap[GlobalVar];
283 Info.RootPointerOperand = GlobalVar;
284 RootTy = GlobalVar->getValueType();
285 } else if (auto *Alloca = dyn_cast<AllocaInst>(PtrOperand))
286 RootTy = Alloca->getAllocatedType();
287 assert(!isMultiDimensionalArray(RootTy) &&
288 "Expected root array type to be flattened");
289
290 // If the root type is not an array, we don't need to do any flattening
291 if (!isa<ArrayType>(RootTy))
292 return false;
293
294 Info.RootFlattenedArrayType = cast<ArrayType>(RootTy);
295 }
296
297 // GEPs without users or GEPs with non-GEP users should be replaced such that
298 // the chain of GEPs they are a part of are collapsed to a single GEP into a
299 // flattened array.
300 bool ReplaceThisGEP = GEP.users().empty();
301 for (Value *User : GEP.users())
302 if (!isa<GetElementPtrInst>(User))
303 ReplaceThisGEP = true;
304
305 if (ReplaceThisGEP) {
306 unsigned BytesPerElem =
307 DL.getTypeAllocSize(Info.RootFlattenedArrayType->getArrayElementType());
308 assert(isPowerOf2_32(BytesPerElem) &&
309 "Bytes per element should be a power of 2");
310
311 // Compute the 32-bit index for this flattened GEP from the constant and
312 // variable byte offsets in the GEPInfo
313 IRBuilder<> Builder(&GEP);
314 Value *ZeroIndex = Builder.getInt32(0);
315 uint64_t ConstantOffset =
316 Info.ConstantOffset.udiv(BytesPerElem).getZExtValue();
317 assert(ConstantOffset < UINT32_MAX &&
318 "Constant byte offset for flat GEP index must fit within 32 bits");
319 Value *FlattenedIndex = Builder.getInt32(ConstantOffset);
320 for (auto [VarIndex, Multiplier] : Info.VariableOffsets) {
321 assert(Multiplier.getActiveBits() <= 32 &&
322 "The multiplier for a flat GEP index must fit within 32 bits");
323 assert(VarIndex->getType()->isIntegerTy(32) &&
324 "Expected i32-typed GEP indices");
325 Value *VI;
326 if (Multiplier.getZExtValue() % BytesPerElem != 0) {
327 // This can happen, e.g., with i8 GEPs. To handle this we just divide
328 // by BytesPerElem using an instruction after multiplying VarIndex by
329 // Multiplier.
330 VI = Builder.CreateMul(VarIndex,
331 Builder.getInt32(Multiplier.getZExtValue()));
332 VI = Builder.CreateLShr(VI, Builder.getInt32(Log2_32(BytesPerElem)));
333 } else
334 VI = Builder.CreateMul(
335 VarIndex,
336 Builder.getInt32(Multiplier.getZExtValue() / BytesPerElem));
337 FlattenedIndex = Builder.CreateAdd(FlattenedIndex, VI);
338 }
339
340 // Construct a new GEP for the flattened array to replace the current GEP
341 GetElementPtrInst *NewGEP = GetElementPtrInst::Create(
342 Info.RootFlattenedArrayType, Info.RootPointerOperand,
343 {ZeroIndex, FlattenedIndex}, GEP.getNoWrapFlags(), GEP.getName(),
344 Builder.GetInsertPoint());
345
346 // Replace the current GEP with the new GEP. Store GEPInfo into the map
347 // for later use in case this GEP was not the end of the chain
348 GEPChainInfoMap.insert({cast<GEPOperator>(NewGEP), std::move(Info)});
349 GEP.replaceAllUsesWith(NewGEP);
350 GEP.eraseFromParent();
351 return true;
352 }
353
354 // This GEP is potentially dead at the end of the pass since it may not have
355 // any users anymore after GEP chains have been collapsed. We retain store
356 // GEPInfo for GEPs down the chain to use to compute their indices.
357 GEPChainInfoMap.insert({cast<GEPOperator>(&GEP), std::move(Info)});
358 PotentiallyDeadInstrs.emplace_back(&GEP);
359 return false;
360}
361
362bool DXILFlattenArraysVisitor::visit(Function &F) {
363 bool MadeChange = false;
364 ReversePostOrderTraversal<Function *> RPOT(&F);
365 for (BasicBlock *BB : make_early_inc_range(RPOT)) {
366 for (Instruction &I : make_early_inc_range(*BB))
367 MadeChange |= InstVisitor::visit(I);
368 }
369 finish();
370 return MadeChange;
371}
372
374 SmallVectorImpl<Constant *> &Elements) {
375 // Base case: If Init is not an array, add it directly to the vector.
376 auto *ArrayTy = dyn_cast<ArrayType>(Init->getType());
377 if (!ArrayTy) {
378 Elements.push_back(Init);
379 return;
380 }
381 unsigned ArrSize = ArrayTy->getNumElements();
383 for (unsigned I = 0; I < ArrSize; ++I)
384 Elements.push_back(Constant::getNullValue(ArrayTy->getElementType()));
385 return;
386 }
387
388 // Recursive case: Process each element in the array.
389 if (auto *ArrayConstant = dyn_cast<ConstantArray>(Init)) {
390 for (unsigned I = 0; I < ArrayConstant->getNumOperands(); ++I) {
391 collectElements(ArrayConstant->getOperand(I), Elements);
392 }
393 } else if (auto *DataArrayConstant = dyn_cast<ConstantDataArray>(Init)) {
394 for (unsigned I = 0; I < DataArrayConstant->getNumElements(); ++I) {
395 collectElements(DataArrayConstant->getElementAsConstant(I), Elements);
396 }
397 } else {
399 "Expected a ConstantArray or ConstantDataArray for array initializer!");
400 }
401}
402
404 ArrayType *FlattenedType,
405 LLVMContext &Ctx) {
406 // Handle ConstantAggregateZero (zero-initialized constants)
408 return ConstantAggregateZero::get(FlattenedType);
409
410 // Handle UndefValue (undefined constants)
412 return UndefValue::get(FlattenedType);
413
414 if (!isa<ArrayType>(OrigType))
415 return Init;
416
417 SmallVector<Constant *> FlattenedElements;
418 collectElements(Init, FlattenedElements);
419 assert(FlattenedType->getNumElements() == FlattenedElements.size() &&
420 "The number of collected elements should match the FlattenedType");
421 return ConstantArray::get(FlattenedType, FlattenedElements);
422}
423
426 LLVMContext &Ctx = M.getContext();
427 for (GlobalVariable &G : M.globals()) {
428 Type *OrigType = G.getValueType();
429 if (!DXILFlattenArraysVisitor::isMultiDimensionalArray(OrigType))
430 continue;
431
432 ArrayType *ArrType = cast<ArrayType>(OrigType);
433 auto [TotalElements, BaseType] =
434 DXILFlattenArraysVisitor::getElementCountAndType(ArrType);
435 ArrayType *FattenedArrayType = ArrayType::get(BaseType, TotalElements);
436
437 // Create a new global variable with the updated type
438 // Note: Initializer is set via transformInitializer
439 GlobalVariable *NewGlobal =
440 new GlobalVariable(M, FattenedArrayType, G.isConstant(), G.getLinkage(),
441 /*Initializer=*/nullptr, G.getName() + ".1dim", &G,
442 G.getThreadLocalMode(), G.getAddressSpace(),
443 G.isExternallyInitialized());
444
445 // Copy relevant attributes
446 NewGlobal->setUnnamedAddr(G.getUnnamedAddr());
447 if (G.getAlign()) {
448 NewGlobal->setAlignment(G.getAlign());
449 }
450
451 if (G.hasInitializer()) {
452 Constant *Init = G.getInitializer();
453 Constant *NewInit =
454 transformInitializer(Init, OrigType, FattenedArrayType, Ctx);
455 NewGlobal->setInitializer(NewInit);
456 }
457 GlobalMap[&G] = NewGlobal;
458 }
459}
460
461static bool flattenArrays(Module &M) {
462 bool MadeChange = false;
464 flattenGlobalArrays(M, GlobalMap);
465 DXILFlattenArraysVisitor Impl(GlobalMap);
466 for (auto &F : make_early_inc_range(M.functions())) {
467 if (F.isDeclaration())
468 continue;
469 MadeChange |= Impl.visit(F);
470 }
471 for (auto &[Old, New] : GlobalMap) {
472 Old->replaceAllUsesWith(New);
473 Old->eraseFromParent();
474 MadeChange = true;
475 }
476 return MadeChange;
477}
478
481 bool MadeChanges = flattenArrays(M);
482 if (!MadeChanges)
483 return PreservedAnalyses::all();
485 return PA;
486}
487
488bool DXILFlattenArraysLegacy::runOnModule(Module &M) {
489 return flattenArrays(M);
490}
491
492char DXILFlattenArraysLegacy::ID = 0;
493
494INITIALIZE_PASS_BEGIN(DXILFlattenArraysLegacy, DEBUG_TYPE,
495 "DXIL Array Flattener", false, false)
496INITIALIZE_PASS_END(DXILFlattenArraysLegacy, DEBUG_TYPE, "DXIL Array Flattener",
498
500 return new DXILFlattenArraysLegacy();
501}
#define Success
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
Rewrite undef for PHI
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static Constant * transformInitializer(Constant *Init, Type *OrigType, Type *NewType, LLVMContext &Ctx)
static void collectElements(Constant *Init, SmallVectorImpl< Constant * > &Elements)
static bool flattenArrays(Module &M)
static void flattenGlobalArrays(Module &M, SmallDenseMap< GlobalVariable *, GlobalVariable * > &GlobalMap)
#define DEBUG_TYPE
Hexagon Common GEP
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define G(x, y, z)
Definition MD5.cpp:55
#define T
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
static void visit(BasicBlock &Start, std::function< bool(BasicBlock *)> op)
This file contains some templates that are useful if you are working with the STL at all.
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
Class for arbitrary precision integers.
Definition APInt.h:78
an instruction to allocate memory on the stack
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
void setAlignment(Align Align)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
This class represents a no-op cast from one type to another.
This class represents a function call, abstracting a target machine's calling convention.
This is the base class for all instructions that perform data casts.
Definition InstrTypes.h:512
static LLVM_ABI ConstantAggregateZero * get(Type *Ty)
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
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:44
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
This instruction extracts a single (scalar) element from a VectorType value.
This instruction compares its operands according to the predicate given to the constructor.
This class represents a freeze function that returns random concrete value if an operand is either a ...
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
void setUnnamedAddr(UnnamedAddr Val)
LLVM_ABI void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
Definition Globals.cpp:613
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalVariable.
This instruction compares its operands according to the predicate given to the constructor.
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
Definition IRBuilder.h:1880
BasicBlock::iterator GetInsertPoint() const
Definition IRBuilder.h:176
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1528
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition IRBuilder.h:465
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
Definition IRBuilder.h:1907
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition IRBuilder.h:1925
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1418
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1452
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2949
This instruction inserts a single (scalar) element into a VectorType value.
Base class for instruction visitors.
Definition InstVisitor.h:78
void visit(Iterator Start, Iterator End)
Definition InstVisitor.h:87
LLVM_ABI void insertBefore(InstListType::iterator InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified position.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
An instruction for reading from memory.
void setAlignment(Align Align)
Align getAlign() const
Return the alignment of the access that is being performed.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition Pass.h:253
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
This class represents the LLVM 'select' instruction.
This instruction constructs a fixed permutation of two input vectors.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
void setAlignment(Align Align)
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Value * getOperand(unsigned i) const
Definition User.h:207
unsigned getNumOperands() const
Definition User.h:229
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition Value.cpp:548
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:314
self_iterator getIterator()
Definition ilist_node.h:123
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ CE
Windows NT (Windows on ARM)
Definition MCAsmInfo.h:51
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition STLExtras.h:649
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
ModulePass * createDXILFlattenArraysLegacyPass()
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition MathExtras.h:326
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition MathExtras.h:280
IRBuilder(LLVMContext &, FolderTy, InserterTy) -> IRBuilder< FolderTy, InserterTy >
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
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
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI bool RecursivelyDeleteTriviallyDeadInstructionsPermissive(SmallVectorImpl< WeakTrackingVH > &DeadInsts, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())
Same functionality as RecursivelyDeleteTriviallyDeadInstructions, but allow instructions that are not...
Definition Local.cpp:537
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
A MapVector that performs no allocations if smaller than a certain size.
Definition MapVector.h:344