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 "DXILFlattenArrays.h"
14#include "DirectX.h"
16#include "llvm/ADT/STLExtras.h"
17#include "llvm/IR/BasicBlock.h"
19#include "llvm/IR/IRBuilder.h"
20#include "llvm/IR/InstVisitor.h"
25#include <cassert>
26#include <cstddef>
27#include <cstdint>
28#include <utility>
29
30#define DEBUG_TYPE "dxil-flatten-arrays"
31
32using namespace llvm;
33namespace {
34
35class DXILFlattenArraysLegacy : public ModulePass {
36
37public:
38 bool runOnModule(Module &M) override;
39 DXILFlattenArraysLegacy() : ModulePass(ID) {}
40
41 static char ID; // Pass identification.
42};
43
44struct GEPInfo {
45 ArrayType *RootFlattenedArrayType;
46 Value *RootPointerOperand;
48 APInt ConstantOffset;
49};
50
51class DXILFlattenArraysVisitor
52 : public InstVisitor<DXILFlattenArraysVisitor, bool> {
53public:
54 DXILFlattenArraysVisitor(
56 : GlobalMap(GlobalMap) {}
57 bool visit(Function &F);
58 // InstVisitor methods. They return true if the instruction was scalarized,
59 // false if nothing changed.
60 bool visitGetElementPtrInst(GetElementPtrInst &GEPI);
61 bool visitAllocaInst(AllocaInst &AI);
62 bool visitInstruction(Instruction &I) { return false; }
63 bool visitSelectInst(SelectInst &SI) { return false; }
64 bool visitICmpInst(ICmpInst &ICI) { return false; }
65 bool visitFCmpInst(FCmpInst &FCI) { return false; }
66 bool visitUnaryOperator(UnaryOperator &UO) { return false; }
67 bool visitBinaryOperator(BinaryOperator &BO) { return false; }
68 bool visitCastInst(CastInst &CI) { return false; }
69 bool visitBitCastInst(BitCastInst &BCI) { return false; }
70 bool visitInsertElementInst(InsertElementInst &IEI) { return false; }
71 bool visitExtractElementInst(ExtractElementInst &EEI) { return false; }
72 bool visitShuffleVectorInst(ShuffleVectorInst &SVI) { return false; }
73 bool visitPHINode(PHINode &PHI) { return false; }
74 bool visitLoadInst(LoadInst &LI);
75 bool visitStoreInst(StoreInst &SI);
76 bool visitCallInst(CallInst &ICI) { return false; }
77 bool visitFreezeInst(FreezeInst &FI) { return false; }
78 static bool isMultiDimensionalArray(Type *T);
79 static std::pair<unsigned, Type *> getElementCountAndType(Type *ArrayTy);
80
81private:
82 SmallVector<WeakTrackingVH> PotentiallyDeadInstrs;
85 bool finish();
86 ConstantInt *genConstFlattenIndices(ArrayRef<Value *> Indices,
88 IRBuilder<> &Builder);
89 Value *genInstructionFlattenIndices(ArrayRef<Value *> Indices,
91 IRBuilder<> &Builder);
92};
93} // namespace
94
95bool DXILFlattenArraysVisitor::finish() {
96 GEPChainInfoMap.clear();
98 return true;
99}
100
101bool DXILFlattenArraysVisitor::isMultiDimensionalArray(Type *T) {
102 if (ArrayType *ArrType = dyn_cast<ArrayType>(T))
103 return isa<ArrayType>(ArrType->getElementType());
104 return false;
105}
106
107std::pair<unsigned, Type *>
108DXILFlattenArraysVisitor::getElementCountAndType(Type *ArrayTy) {
109 unsigned TotalElements = 1;
110 Type *CurrArrayTy = ArrayTy;
111 while (auto *InnerArrayTy = dyn_cast<ArrayType>(CurrArrayTy)) {
112 TotalElements *= InnerArrayTy->getNumElements();
113 CurrArrayTy = InnerArrayTy->getElementType();
114 }
115 return std::make_pair(TotalElements, CurrArrayTy);
116}
117
118ConstantInt *DXILFlattenArraysVisitor::genConstFlattenIndices(
119 ArrayRef<Value *> Indices, ArrayRef<uint64_t> Dims, IRBuilder<> &Builder) {
120 assert(Indices.size() == Dims.size() &&
121 "Indicies and dimmensions should be the same");
122 unsigned FlatIndex = 0;
123 unsigned Multiplier = 1;
124
125 for (int I = Indices.size() - 1; I >= 0; --I) {
126 unsigned DimSize = Dims[I];
127 ConstantInt *CIndex = dyn_cast<ConstantInt>(Indices[I]);
128 assert(CIndex && "This function expects all indicies to be ConstantInt");
129 FlatIndex += CIndex->getZExtValue() * Multiplier;
130 Multiplier *= DimSize;
131 }
132 return Builder.getInt32(FlatIndex);
133}
134
135Value *DXILFlattenArraysVisitor::genInstructionFlattenIndices(
136 ArrayRef<Value *> Indices, ArrayRef<uint64_t> Dims, IRBuilder<> &Builder) {
137 if (Indices.size() == 1)
138 return Indices[0];
139
140 Value *FlatIndex = Builder.getInt32(0);
141 unsigned Multiplier = 1;
142
143 for (int I = Indices.size() - 1; I >= 0; --I) {
144 unsigned DimSize = Dims[I];
145 Value *VMultiplier = Builder.getInt32(Multiplier);
146 Value *ScaledIndex = Builder.CreateMul(Indices[I], VMultiplier);
147 FlatIndex = Builder.CreateAdd(FlatIndex, ScaledIndex);
148 Multiplier *= DimSize;
149 }
150 return FlatIndex;
151}
152
153bool DXILFlattenArraysVisitor::visitLoadInst(LoadInst &LI) {
154 unsigned NumOperands = LI.getNumOperands();
155 for (unsigned I = 0; I < NumOperands; ++I) {
156 Value *CurrOpperand = LI.getOperand(I);
157 ConstantExpr *CE = dyn_cast<ConstantExpr>(CurrOpperand);
158 if (CE && CE->getOpcode() == Instruction::GetElementPtr) {
159 GetElementPtrInst *OldGEP =
160 cast<GetElementPtrInst>(CE->getAsInstruction());
161 OldGEP->insertBefore(LI.getIterator());
162
163 IRBuilder<> Builder(&LI);
164 LoadInst *NewLoad =
165 Builder.CreateLoad(LI.getType(), OldGEP, LI.getName());
166 NewLoad->setAlignment(LI.getAlign());
167 LI.replaceAllUsesWith(NewLoad);
168 LI.eraseFromParent();
169 visitGetElementPtrInst(*OldGEP);
170 return true;
171 }
172 }
173 return false;
174}
175
176bool DXILFlattenArraysVisitor::visitStoreInst(StoreInst &SI) {
177 unsigned NumOperands = SI.getNumOperands();
178 for (unsigned I = 0; I < NumOperands; ++I) {
179 Value *CurrOpperand = SI.getOperand(I);
180 ConstantExpr *CE = dyn_cast<ConstantExpr>(CurrOpperand);
181 if (CE && CE->getOpcode() == Instruction::GetElementPtr) {
182 GetElementPtrInst *OldGEP =
183 cast<GetElementPtrInst>(CE->getAsInstruction());
184 OldGEP->insertBefore(SI.getIterator());
185
186 IRBuilder<> Builder(&SI);
187 StoreInst *NewStore = Builder.CreateStore(SI.getValueOperand(), OldGEP);
188 NewStore->setAlignment(SI.getAlign());
189 SI.replaceAllUsesWith(NewStore);
190 SI.eraseFromParent();
191 visitGetElementPtrInst(*OldGEP);
192 return true;
193 }
194 }
195 return false;
196}
197
198bool DXILFlattenArraysVisitor::visitAllocaInst(AllocaInst &AI) {
199 if (!isMultiDimensionalArray(AI.getAllocatedType()))
200 return false;
201
203 IRBuilder<> Builder(&AI);
204 auto [TotalElements, BaseType] = getElementCountAndType(ArrType);
205
206 ArrayType *FattenedArrayType = ArrayType::get(BaseType, TotalElements);
207 AllocaInst *FlatAlloca =
208 Builder.CreateAlloca(FattenedArrayType, nullptr, AI.getName() + ".1dim");
209 FlatAlloca->setAlignment(AI.getAlign());
210 AI.replaceAllUsesWith(FlatAlloca);
211 AI.eraseFromParent();
212 return true;
213}
214
215bool DXILFlattenArraysVisitor::visitGetElementPtrInst(GetElementPtrInst &GEP) {
216 // Do not visit GEPs more than once
217 if (GEPChainInfoMap.contains(cast<GEPOperator>(&GEP)))
218 return false;
219
220 Value *PtrOperand = GEP.getPointerOperand();
221 // It shouldn't(?) be possible for the pointer operand of a GEP to be a PHI
222 // node unless HLSL has pointers. If this assumption is incorrect or HLSL gets
223 // pointer types, then the handling of this case can be implemented later.
224 assert(!isa<PHINode>(PtrOperand) &&
225 "Pointer operand of GEP should not be a PHI Node");
226
227 // Replace a GEP ConstantExpr pointer operand with a GEP instruction so that
228 // it can be visited
229 if (auto *PtrOpGEPCE = dyn_cast<ConstantExpr>(PtrOperand);
230 PtrOpGEPCE && PtrOpGEPCE->getOpcode() == Instruction::GetElementPtr) {
231 GetElementPtrInst *OldGEPI =
232 cast<GetElementPtrInst>(PtrOpGEPCE->getAsInstruction());
233 OldGEPI->insertBefore(GEP.getIterator());
234
235 SmallVector<Value *> Indices(GEP.indices());
236 GetElementPtrInst *NewGEPI = GetElementPtrInst::Create(
237 GEP.getSourceElementType(), OldGEPI, Indices, GEP.getNoWrapFlags(),
238 GEP.getName(), GEP.getIterator());
239
240 GEP.replaceAllUsesWith(NewGEPI);
241 GEP.eraseFromParent();
242 visitGetElementPtrInst(*OldGEPI);
243 visitGetElementPtrInst(*NewGEPI);
244 return true;
245 }
246
247 // Construct GEPInfo for this GEP
248 GEPInfo Info;
249
250 // Obtain the variable and constant byte offsets computed by this GEP
251 const DataLayout &DL = GEP.getDataLayout();
252 unsigned BitWidth = DL.getIndexTypeSizeInBits(GEP.getType());
253 Info.ConstantOffset = {BitWidth, 0};
254 [[maybe_unused]] bool Success = GEP.collectOffset(
255 DL, BitWidth, Info.VariableOffsets, Info.ConstantOffset);
256 assert(Success && "Failed to collect offsets for GEP");
257
258 // If there is a parent GEP, inherit the root array type and pointer, and
259 // merge the byte offsets. Otherwise, this GEP is itself the root of a GEP
260 // chain and we need to deterine the root array type
261 if (auto *PtrOpGEP = dyn_cast<GEPOperator>(PtrOperand)) {
262
263 // If the parent GEP was not processed, then we do not want to process its
264 // descendants. This can happen if the GEP chain is for an unsupported type
265 // such as a struct -- we do not flatten structs nor GEP chains for structs
266 if (!GEPChainInfoMap.contains(PtrOpGEP))
267 return false;
268
269 GEPInfo &PGEPInfo = GEPChainInfoMap[PtrOpGEP];
270 Info.RootFlattenedArrayType = PGEPInfo.RootFlattenedArrayType;
271 Info.RootPointerOperand = PGEPInfo.RootPointerOperand;
272 for (auto &VariableOffset : PGEPInfo.VariableOffsets)
273 Info.VariableOffsets.insert(VariableOffset);
274 Info.ConstantOffset += PGEPInfo.ConstantOffset;
275 } else {
276 Info.RootPointerOperand = PtrOperand;
277
278 // We should try to determine the type of the root from the pointer rather
279 // than the GEP's source element type because this could be a scalar GEP
280 // into an array-typed pointer from an Alloca or Global Variable.
281 Type *RootTy = GEP.getSourceElementType();
282 if (auto *GlobalVar = dyn_cast<GlobalVariable>(PtrOperand)) {
283 if (GlobalMap.contains(GlobalVar))
284 GlobalVar = GlobalMap[GlobalVar];
285 Info.RootPointerOperand = GlobalVar;
286 RootTy = GlobalVar->getValueType();
287 } else if (auto *Alloca = dyn_cast<AllocaInst>(PtrOperand))
288 RootTy = Alloca->getAllocatedType();
289 assert(!isMultiDimensionalArray(RootTy) &&
290 "Expected root array type to be flattened");
291
292 // If the root type is not an array, we don't need to do any flattening
293 if (!isa<ArrayType>(RootTy))
294 return false;
295
296 Info.RootFlattenedArrayType = cast<ArrayType>(RootTy);
297 }
298
299 // GEPs without users or GEPs with non-GEP users should be replaced such that
300 // the chain of GEPs they are a part of are collapsed to a single GEP into a
301 // flattened array.
302 bool ReplaceThisGEP = GEP.users().empty();
303 for (Value *User : GEP.users())
304 if (!isa<GetElementPtrInst>(User))
305 ReplaceThisGEP = true;
306
307 if (ReplaceThisGEP) {
308 unsigned BytesPerElem =
309 DL.getTypeAllocSize(Info.RootFlattenedArrayType->getArrayElementType());
310 assert(isPowerOf2_32(BytesPerElem) &&
311 "Bytes per element should be a power of 2");
312
313 // Compute the 32-bit index for this flattened GEP from the constant and
314 // variable byte offsets in the GEPInfo
315 IRBuilder<> Builder(&GEP);
316 Value *ZeroIndex = Builder.getInt32(0);
317 uint64_t ConstantOffset =
318 Info.ConstantOffset.udiv(BytesPerElem).getZExtValue();
319 assert(ConstantOffset < UINT32_MAX &&
320 "Constant byte offset for flat GEP index must fit within 32 bits");
321 Value *FlattenedIndex = Builder.getInt32(ConstantOffset);
322 for (auto [VarIndex, Multiplier] : Info.VariableOffsets) {
323 assert(Multiplier.getActiveBits() <= 32 &&
324 "The multiplier for a flat GEP index must fit within 32 bits");
325 assert(VarIndex->getType()->isIntegerTy(32) &&
326 "Expected i32-typed GEP indices");
327 Value *VI;
328 if (Multiplier.getZExtValue() % BytesPerElem != 0) {
329 // This can happen, e.g., with i8 GEPs. To handle this we just divide
330 // by BytesPerElem using an instruction after multiplying VarIndex by
331 // Multiplier.
332 VI = Builder.CreateMul(VarIndex,
333 Builder.getInt32(Multiplier.getZExtValue()));
334 VI = Builder.CreateLShr(VI, Builder.getInt32(Log2_32(BytesPerElem)));
335 } else
336 VI = Builder.CreateMul(
337 VarIndex,
338 Builder.getInt32(Multiplier.getZExtValue() / BytesPerElem));
339 FlattenedIndex = Builder.CreateAdd(FlattenedIndex, VI);
340 }
341
342 // Construct a new GEP for the flattened array to replace the current GEP
343 GetElementPtrInst *NewGEP = GetElementPtrInst::Create(
344 Info.RootFlattenedArrayType, Info.RootPointerOperand,
345 {ZeroIndex, FlattenedIndex}, GEP.getNoWrapFlags(), GEP.getName(),
346 Builder.GetInsertPoint());
347
348 // Replace the current GEP with the new GEP. Store GEPInfo into the map
349 // for later use in case this GEP was not the end of the chain
350 GEPChainInfoMap.insert({cast<GEPOperator>(NewGEP), std::move(Info)});
351 GEP.replaceAllUsesWith(NewGEP);
352 GEP.eraseFromParent();
353 return true;
354 }
355
356 // This GEP is potentially dead at the end of the pass since it may not have
357 // any users anymore after GEP chains have been collapsed. We retain store
358 // GEPInfo for GEPs down the chain to use to compute their indices.
359 GEPChainInfoMap.insert({cast<GEPOperator>(&GEP), std::move(Info)});
360 PotentiallyDeadInstrs.emplace_back(&GEP);
361 return false;
362}
363
364bool DXILFlattenArraysVisitor::visit(Function &F) {
365 bool MadeChange = false;
366 ReversePostOrderTraversal<Function *> RPOT(&F);
367 for (BasicBlock *BB : make_early_inc_range(RPOT)) {
368 for (Instruction &I : make_early_inc_range(*BB))
369 MadeChange |= InstVisitor::visit(I);
370 }
371 finish();
372 return MadeChange;
373}
374
376 SmallVectorImpl<Constant *> &Elements) {
377 // Base case: If Init is not an array, add it directly to the vector.
378 auto *ArrayTy = dyn_cast<ArrayType>(Init->getType());
379 if (!ArrayTy) {
380 Elements.push_back(Init);
381 return;
382 }
383 unsigned ArrSize = ArrayTy->getNumElements();
385 for (unsigned I = 0; I < ArrSize; ++I)
386 Elements.push_back(Constant::getNullValue(ArrayTy->getElementType()));
387 return;
388 }
389
390 // Recursive case: Process each element in the array.
391 if (auto *ArrayConstant = dyn_cast<ConstantArray>(Init)) {
392 for (unsigned I = 0; I < ArrayConstant->getNumOperands(); ++I) {
393 collectElements(ArrayConstant->getOperand(I), Elements);
394 }
395 } else if (auto *DataArrayConstant = dyn_cast<ConstantDataArray>(Init)) {
396 for (unsigned I = 0; I < DataArrayConstant->getNumElements(); ++I) {
397 collectElements(DataArrayConstant->getElementAsConstant(I), Elements);
398 }
399 } else {
401 "Expected a ConstantArray or ConstantDataArray for array initializer!");
402 }
403}
404
406 ArrayType *FlattenedType,
407 LLVMContext &Ctx) {
408 // Handle ConstantAggregateZero (zero-initialized constants)
410 return ConstantAggregateZero::get(FlattenedType);
411
412 // Handle UndefValue (undefined constants)
414 return UndefValue::get(FlattenedType);
415
416 if (!isa<ArrayType>(OrigType))
417 return Init;
418
419 SmallVector<Constant *> FlattenedElements;
420 collectElements(Init, FlattenedElements);
421 assert(FlattenedType->getNumElements() == FlattenedElements.size() &&
422 "The number of collected elements should match the FlattenedType");
423 return ConstantArray::get(FlattenedType, FlattenedElements);
424}
425
428 LLVMContext &Ctx = M.getContext();
429 for (GlobalVariable &G : M.globals()) {
430 Type *OrigType = G.getValueType();
431 if (!DXILFlattenArraysVisitor::isMultiDimensionalArray(OrigType))
432 continue;
433
434 ArrayType *ArrType = cast<ArrayType>(OrigType);
435 auto [TotalElements, BaseType] =
436 DXILFlattenArraysVisitor::getElementCountAndType(ArrType);
437 ArrayType *FattenedArrayType = ArrayType::get(BaseType, TotalElements);
438
439 // Create a new global variable with the updated type
440 // Note: Initializer is set via transformInitializer
441 GlobalVariable *NewGlobal =
442 new GlobalVariable(M, FattenedArrayType, G.isConstant(), G.getLinkage(),
443 /*Initializer=*/nullptr, G.getName() + ".1dim", &G,
444 G.getThreadLocalMode(), G.getAddressSpace(),
445 G.isExternallyInitialized());
446
447 // Copy relevant attributes
448 NewGlobal->setUnnamedAddr(G.getUnnamedAddr());
449 if (G.getAlign()) {
450 NewGlobal->setAlignment(G.getAlign());
451 }
452
453 if (G.hasInitializer()) {
454 Constant *Init = G.getInitializer();
455 Constant *NewInit =
456 transformInitializer(Init, OrigType, FattenedArrayType, Ctx);
457 NewGlobal->setInitializer(NewInit);
458 }
459 GlobalMap[&G] = NewGlobal;
460 }
461}
462
463static bool flattenArrays(Module &M) {
464 bool MadeChange = false;
466 flattenGlobalArrays(M, GlobalMap);
467 DXILFlattenArraysVisitor Impl(GlobalMap);
468 for (auto &F : make_early_inc_range(M.functions())) {
469 if (F.isDeclaration())
470 continue;
471 MadeChange |= Impl.visit(F);
472 }
473 for (auto &[Old, New] : GlobalMap) {
474 Old->replaceAllUsesWith(New);
475 Old->eraseFromParent();
476 MadeChange = true;
477 }
478 return MadeChange;
479}
480
482 bool MadeChanges = flattenArrays(M);
483 if (!MadeChanges)
484 return PreservedAnalyses::all();
486 return PA;
487}
488
489bool DXILFlattenArraysLegacy::runOnModule(Module &M) {
490 return flattenArrays(M);
491}
492
493char DXILFlattenArraysLegacy::ID = 0;
494
495INITIALIZE_PASS_BEGIN(DXILFlattenArraysLegacy, DEBUG_TYPE,
496 "DXIL Array Flattener", false, false)
497INITIALIZE_PASS_END(DXILFlattenArraysLegacy, DEBUG_TYPE, "DXIL Array Flattener",
499
501 return new DXILFlattenArraysLegacy();
502}
#define Success
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned 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:43
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:1890
BasicBlock::iterator GetInsertPoint() const
Definition IRBuilder.h:174
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1538
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition IRBuilder.h:475
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:1917
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition IRBuilder.h:1936
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1428
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1462
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2920
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:68
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:255
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:553
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:319
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()
Pass to flatten arrays into a one dimensional DXIL legal form.
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:342