LLVM 20.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"
24#include <cassert>
25#include <cstddef>
26#include <cstdint>
27#include <utility>
28
29#define DEBUG_TYPE "dxil-flatten-arrays"
30
31using namespace llvm;
32namespace {
33
34class DXILFlattenArraysLegacy : public ModulePass {
35
36public:
37 bool runOnModule(Module &M) override;
38 DXILFlattenArraysLegacy() : ModulePass(ID) {}
39
40 static char ID; // Pass identification.
41};
42
43struct GEPData {
44 ArrayType *ParentArrayType;
45 Value *ParendOperand;
48 bool AllIndicesAreConstInt;
49};
50
51class DXILFlattenArraysVisitor
52 : public InstVisitor<DXILFlattenArraysVisitor, bool> {
53public:
54 DXILFlattenArraysVisitor() {}
55 bool visit(Function &F);
56 // InstVisitor methods. They return true if the instruction was scalarized,
57 // false if nothing changed.
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;
82 bool finish();
83 ConstantInt *genConstFlattenIndices(ArrayRef<Value *> Indices,
85 IRBuilder<> &Builder);
86 Value *genInstructionFlattenIndices(ArrayRef<Value *> Indices,
88 IRBuilder<> &Builder);
89 void
90 recursivelyCollectGEPs(GetElementPtrInst &CurrGEP,
91 ArrayType *FlattenedArrayType, Value *PtrOperand,
92 unsigned &GEPChainUseCount,
95 bool AllIndicesAreConstInt = true);
96 bool visitGetElementPtrInstInGEPChain(GetElementPtrInst &GEP);
97 bool visitGetElementPtrInstInGEPChainBase(GEPData &GEPInfo,
99};
100} // namespace
101
102bool DXILFlattenArraysVisitor::finish() {
104 return true;
105}
106
107bool DXILFlattenArraysVisitor::isMultiDimensionalArray(Type *T) {
108 if (ArrayType *ArrType = dyn_cast<ArrayType>(T))
109 return isa<ArrayType>(ArrType->getElementType());
110 return false;
111}
112
113std::pair<unsigned, Type *>
114DXILFlattenArraysVisitor::getElementCountAndType(Type *ArrayTy) {
115 unsigned TotalElements = 1;
116 Type *CurrArrayTy = ArrayTy;
117 while (auto *InnerArrayTy = dyn_cast<ArrayType>(CurrArrayTy)) {
118 TotalElements *= InnerArrayTy->getNumElements();
119 CurrArrayTy = InnerArrayTy->getElementType();
120 }
121 return std::make_pair(TotalElements, CurrArrayTy);
122}
123
124ConstantInt *DXILFlattenArraysVisitor::genConstFlattenIndices(
125 ArrayRef<Value *> Indices, ArrayRef<uint64_t> Dims, IRBuilder<> &Builder) {
126 assert(Indices.size() == Dims.size() &&
127 "Indicies and dimmensions should be the same");
128 unsigned FlatIndex = 0;
129 unsigned Multiplier = 1;
130
131 for (int I = Indices.size() - 1; I >= 0; --I) {
132 unsigned DimSize = Dims[I];
133 ConstantInt *CIndex = dyn_cast<ConstantInt>(Indices[I]);
134 assert(CIndex && "This function expects all indicies to be ConstantInt");
135 FlatIndex += CIndex->getZExtValue() * Multiplier;
136 Multiplier *= DimSize;
137 }
138 return Builder.getInt32(FlatIndex);
139}
140
141Value *DXILFlattenArraysVisitor::genInstructionFlattenIndices(
142 ArrayRef<Value *> Indices, ArrayRef<uint64_t> Dims, IRBuilder<> &Builder) {
143 if (Indices.size() == 1)
144 return Indices[0];
145
146 Value *FlatIndex = Builder.getInt32(0);
147 unsigned Multiplier = 1;
148
149 for (int I = Indices.size() - 1; I >= 0; --I) {
150 unsigned DimSize = Dims[I];
151 Value *VMultiplier = Builder.getInt32(Multiplier);
152 Value *ScaledIndex = Builder.CreateMul(Indices[I], VMultiplier);
153 FlatIndex = Builder.CreateAdd(FlatIndex, ScaledIndex);
154 Multiplier *= DimSize;
155 }
156 return FlatIndex;
157}
158
159bool DXILFlattenArraysVisitor::visitLoadInst(LoadInst &LI) {
160 unsigned NumOperands = LI.getNumOperands();
161 for (unsigned I = 0; I < NumOperands; ++I) {
162 Value *CurrOpperand = LI.getOperand(I);
163 ConstantExpr *CE = dyn_cast<ConstantExpr>(CurrOpperand);
164 if (CE && CE->getOpcode() == Instruction::GetElementPtr) {
165 GetElementPtrInst *OldGEP =
166 cast<GetElementPtrInst>(CE->getAsInstruction());
167 OldGEP->insertBefore(&LI);
168
169 IRBuilder<> Builder(&LI);
170 LoadInst *NewLoad =
171 Builder.CreateLoad(LI.getType(), OldGEP, LI.getName());
172 NewLoad->setAlignment(LI.getAlign());
173 LI.replaceAllUsesWith(NewLoad);
174 LI.eraseFromParent();
175 visitGetElementPtrInst(*OldGEP);
176 return true;
177 }
178 }
179 return false;
180}
181
182bool DXILFlattenArraysVisitor::visitStoreInst(StoreInst &SI) {
183 unsigned NumOperands = SI.getNumOperands();
184 for (unsigned I = 0; I < NumOperands; ++I) {
185 Value *CurrOpperand = SI.getOperand(I);
186 ConstantExpr *CE = dyn_cast<ConstantExpr>(CurrOpperand);
187 if (CE && CE->getOpcode() == Instruction::GetElementPtr) {
188 GetElementPtrInst *OldGEP =
189 cast<GetElementPtrInst>(CE->getAsInstruction());
190 OldGEP->insertBefore(&SI);
191
192 IRBuilder<> Builder(&SI);
193 StoreInst *NewStore = Builder.CreateStore(SI.getValueOperand(), OldGEP);
194 NewStore->setAlignment(SI.getAlign());
195 SI.replaceAllUsesWith(NewStore);
196 SI.eraseFromParent();
197 visitGetElementPtrInst(*OldGEP);
198 return true;
199 }
200 }
201 return false;
202}
203
204bool DXILFlattenArraysVisitor::visitAllocaInst(AllocaInst &AI) {
205 if (!isMultiDimensionalArray(AI.getAllocatedType()))
206 return false;
207
208 ArrayType *ArrType = cast<ArrayType>(AI.getAllocatedType());
209 IRBuilder<> Builder(&AI);
210 auto [TotalElements, BaseType] = getElementCountAndType(ArrType);
211
212 ArrayType *FattenedArrayType = ArrayType::get(BaseType, TotalElements);
213 AllocaInst *FlatAlloca =
214 Builder.CreateAlloca(FattenedArrayType, nullptr, AI.getName() + ".flat");
215 FlatAlloca->setAlignment(AI.getAlign());
216 AI.replaceAllUsesWith(FlatAlloca);
217 AI.eraseFromParent();
218 return true;
219}
220
221void DXILFlattenArraysVisitor::recursivelyCollectGEPs(
222 GetElementPtrInst &CurrGEP, ArrayType *FlattenedArrayType,
223 Value *PtrOperand, unsigned &GEPChainUseCount, SmallVector<Value *> Indices,
224 SmallVector<uint64_t> Dims, bool AllIndicesAreConstInt) {
225 Value *LastIndex = CurrGEP.getOperand(CurrGEP.getNumOperands() - 1);
226 AllIndicesAreConstInt &= isa<ConstantInt>(LastIndex);
227 Indices.push_back(LastIndex);
228 assert(isa<ArrayType>(CurrGEP.getSourceElementType()));
229 Dims.push_back(
230 cast<ArrayType>(CurrGEP.getSourceElementType())->getNumElements());
231 bool IsMultiDimArr = isMultiDimensionalArray(CurrGEP.getSourceElementType());
232 if (!IsMultiDimArr) {
233 assert(GEPChainUseCount < FlattenedArrayType->getNumElements());
234 GEPChainMap.insert(
235 {&CurrGEP,
236 {std::move(FlattenedArrayType), PtrOperand, std::move(Indices),
237 std::move(Dims), AllIndicesAreConstInt}});
238 return;
239 }
240 bool GepUses = false;
241 for (auto *User : CurrGEP.users()) {
242 if (GetElementPtrInst *NestedGEP = dyn_cast<GetElementPtrInst>(User)) {
243 recursivelyCollectGEPs(*NestedGEP, FlattenedArrayType, PtrOperand,
244 ++GEPChainUseCount, Indices, Dims,
245 AllIndicesAreConstInt);
246 GepUses = true;
247 }
248 }
249 // This case is just incase the gep chain doesn't end with a 1d array.
250 if (IsMultiDimArr && GEPChainUseCount > 0 && !GepUses) {
251 GEPChainMap.insert(
252 {&CurrGEP,
253 {std::move(FlattenedArrayType), PtrOperand, std::move(Indices),
254 std::move(Dims), AllIndicesAreConstInt}});
255 }
256}
257
258bool DXILFlattenArraysVisitor::visitGetElementPtrInstInGEPChain(
260 GEPData GEPInfo = GEPChainMap.at(&GEP);
261 return visitGetElementPtrInstInGEPChainBase(GEPInfo, GEP);
262}
263bool DXILFlattenArraysVisitor::visitGetElementPtrInstInGEPChainBase(
264 GEPData &GEPInfo, GetElementPtrInst &GEP) {
265 IRBuilder<> Builder(&GEP);
266 Value *FlatIndex;
267 if (GEPInfo.AllIndicesAreConstInt)
268 FlatIndex = genConstFlattenIndices(GEPInfo.Indices, GEPInfo.Dims, Builder);
269 else
270 FlatIndex =
271 genInstructionFlattenIndices(GEPInfo.Indices, GEPInfo.Dims, Builder);
272
273 ArrayType *FlattenedArrayType = GEPInfo.ParentArrayType;
274 Value *FlatGEP =
275 Builder.CreateGEP(FlattenedArrayType, GEPInfo.ParendOperand, FlatIndex,
276 GEP.getName() + ".flat", GEP.isInBounds());
277
278 GEP.replaceAllUsesWith(FlatGEP);
279 GEP.eraseFromParent();
280 return true;
281}
282
283bool DXILFlattenArraysVisitor::visitGetElementPtrInst(GetElementPtrInst &GEP) {
284 auto It = GEPChainMap.find(&GEP);
285 if (It != GEPChainMap.end())
286 return visitGetElementPtrInstInGEPChain(GEP);
287 if (!isMultiDimensionalArray(GEP.getSourceElementType()))
288 return false;
289
290 ArrayType *ArrType = cast<ArrayType>(GEP.getSourceElementType());
291 IRBuilder<> Builder(&GEP);
292 auto [TotalElements, BaseType] = getElementCountAndType(ArrType);
293 ArrayType *FlattenedArrayType = ArrayType::get(BaseType, TotalElements);
294
295 Value *PtrOperand = GEP.getPointerOperand();
296
297 unsigned GEPChainUseCount = 0;
298 recursivelyCollectGEPs(GEP, FlattenedArrayType, PtrOperand, GEPChainUseCount);
299
300 // NOTE: hasNUses(0) is not the same as GEPChainUseCount == 0.
301 // Here recursion is used to get the length of the GEP chain.
302 // Handle zero uses here because there won't be an update via
303 // a child in the chain later.
304 if (GEPChainUseCount == 0) {
305 SmallVector<Value *> Indices({GEP.getOperand(GEP.getNumOperands() - 1)});
306 SmallVector<uint64_t> Dims({ArrType->getNumElements()});
307 bool AllIndicesAreConstInt = isa<ConstantInt>(Indices[0]);
308 GEPData GEPInfo{std::move(FlattenedArrayType), PtrOperand,
309 std::move(Indices), std::move(Dims), AllIndicesAreConstInt};
310 return visitGetElementPtrInstInGEPChainBase(GEPInfo, GEP);
311 }
312
313 PotentiallyDeadInstrs.emplace_back(&GEP);
314 return false;
315}
316
317bool DXILFlattenArraysVisitor::visit(Function &F) {
318 bool MadeChange = false;
320 for (BasicBlock *BB : make_early_inc_range(RPOT)) {
322 MadeChange |= InstVisitor::visit(I);
323 }
324 finish();
325 return MadeChange;
326}
327
329 SmallVectorImpl<Constant *> &Elements) {
330 // Base case: If Init is not an array, add it directly to the vector.
331 auto *ArrayTy = dyn_cast<ArrayType>(Init->getType());
332 if (!ArrayTy) {
333 Elements.push_back(Init);
334 return;
335 }
336 unsigned ArrSize = ArrayTy->getNumElements();
337 if (isa<ConstantAggregateZero>(Init)) {
338 for (unsigned I = 0; I < ArrSize; ++I)
339 Elements.push_back(Constant::getNullValue(ArrayTy->getElementType()));
340 return;
341 }
342
343 // Recursive case: Process each element in the array.
344 if (auto *ArrayConstant = dyn_cast<ConstantArray>(Init)) {
345 for (unsigned I = 0; I < ArrayConstant->getNumOperands(); ++I) {
346 collectElements(ArrayConstant->getOperand(I), Elements);
347 }
348 } else if (auto *DataArrayConstant = dyn_cast<ConstantDataArray>(Init)) {
349 for (unsigned I = 0; I < DataArrayConstant->getNumElements(); ++I) {
350 collectElements(DataArrayConstant->getElementAsConstant(I), Elements);
351 }
352 } else {
354 "Expected a ConstantArray or ConstantDataArray for array initializer!");
355 }
356}
357
359 ArrayType *FlattenedType,
360 LLVMContext &Ctx) {
361 // Handle ConstantAggregateZero (zero-initialized constants)
362 if (isa<ConstantAggregateZero>(Init))
363 return ConstantAggregateZero::get(FlattenedType);
364
365 // Handle UndefValue (undefined constants)
366 if (isa<UndefValue>(Init))
367 return UndefValue::get(FlattenedType);
368
369 if (!isa<ArrayType>(OrigType))
370 return Init;
371
372 SmallVector<Constant *> FlattenedElements;
373 collectElements(Init, FlattenedElements);
374 assert(FlattenedType->getNumElements() == FlattenedElements.size() &&
375 "The number of collected elements should match the FlattenedType");
376 return ConstantArray::get(FlattenedType, FlattenedElements);
377}
378
379static void
382 LLVMContext &Ctx = M.getContext();
383 for (GlobalVariable &G : M.globals()) {
384 Type *OrigType = G.getValueType();
385 if (!DXILFlattenArraysVisitor::isMultiDimensionalArray(OrigType))
386 continue;
387
388 ArrayType *ArrType = cast<ArrayType>(OrigType);
389 auto [TotalElements, BaseType] =
390 DXILFlattenArraysVisitor::getElementCountAndType(ArrType);
391 ArrayType *FattenedArrayType = ArrayType::get(BaseType, TotalElements);
392
393 // Create a new global variable with the updated type
394 // Note: Initializer is set via transformInitializer
395 GlobalVariable *NewGlobal =
396 new GlobalVariable(M, FattenedArrayType, G.isConstant(), G.getLinkage(),
397 /*Initializer=*/nullptr, G.getName() + ".1dim", &G,
398 G.getThreadLocalMode(), G.getAddressSpace(),
399 G.isExternallyInitialized());
400
401 // Copy relevant attributes
402 NewGlobal->setUnnamedAddr(G.getUnnamedAddr());
403 if (G.getAlignment() > 0) {
404 NewGlobal->setAlignment(G.getAlign());
405 }
406
407 if (G.hasInitializer()) {
408 Constant *Init = G.getInitializer();
409 Constant *NewInit =
410 transformInitializer(Init, OrigType, FattenedArrayType, Ctx);
411 NewGlobal->setInitializer(NewInit);
412 }
413 GlobalMap[&G] = NewGlobal;
414 }
415}
416
417static bool flattenArrays(Module &M) {
418 bool MadeChange = false;
419 DXILFlattenArraysVisitor Impl;
421 flattenGlobalArrays(M, GlobalMap);
422 for (auto &F : make_early_inc_range(M.functions())) {
423 if (F.isDeclaration())
424 continue;
425 MadeChange |= Impl.visit(F);
426 }
427 for (auto &[Old, New] : GlobalMap) {
428 Old->replaceAllUsesWith(New);
429 Old->eraseFromParent();
430 MadeChange = true;
431 }
432 return MadeChange;
433}
434
436 bool MadeChanges = flattenArrays(M);
437 if (!MadeChanges)
438 return PreservedAnalyses::all();
440 return PA;
441}
442
443bool DXILFlattenArraysLegacy::runOnModule(Module &M) {
444 return flattenArrays(M);
445}
446
447char DXILFlattenArraysLegacy::ID = 0;
448
449INITIALIZE_PASS_BEGIN(DXILFlattenArraysLegacy, DEBUG_TYPE,
450 "DXIL Array Flattener", false, false)
451INITIALIZE_PASS_END(DXILFlattenArraysLegacy, DEBUG_TYPE, "DXIL Array Flattener",
453
455 return new DXILFlattenArraysLegacy();
456}
Rewrite undef for PHI
static void collectElements(Constant *Init, SmallVectorImpl< Constant * > &Elements)
static bool flattenArrays(Module &M)
static void flattenGlobalArrays(Module &M, DenseMap< GlobalVariable *, GlobalVariable * > &GlobalMap)
static Constant * transformInitializer(Constant *Init, Type *OrigType, ArrayType *FlattenedType, LLVMContext &Ctx)
DXIL Array Flattener
#define DEBUG_TYPE
Hexagon Common GEP
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
#define G(x, y, z)
Definition: MD5.cpp:56
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:57
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:52
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static unsigned getNumElements(Type *Ty)
This file contains some templates that are useful if you are working with the STL at all.
an instruction to allocate memory on the stack
Definition: Instructions.h:63
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Definition: Instructions.h:124
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
Definition: Instructions.h:117
void setAlignment(Align Align)
Definition: Instructions.h:128
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:168
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
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:444
static ConstantAggregateZero * get(Type *Ty)
Definition: Constants.cpp:1672
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
Definition: Constants.cpp:1312
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:1108
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
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:157
This is an important base class in LLVM.
Definition: Constant.h:42
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Definition: Constants.cpp:373
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
Definition: Instructions.h:933
Type * getSourceElementType() const
Definition: Instructions.h:990
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
Definition: Globals.cpp:143
void setUnnamedAddr(UnnamedAddr Val)
Definition: GlobalValue.h:231
void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
Definition: Globals.cpp:492
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:1796
Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Definition: IRBuilder.h:1889
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition: IRBuilder.h:483
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:1813
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition: IRBuilder.h:1826
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1350
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1384
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2697
This instruction inserts a single (scalar) element into a VectorType value.
Base class for instruction visitors.
Definition: InstVisitor.h:78
RetTy visitFreezeInst(FreezeInst &I)
Definition: InstVisitor.h:200
RetTy visitFCmpInst(FCmpInst &I)
Definition: InstVisitor.h:167
RetTy visitExtractElementInst(ExtractElementInst &I)
Definition: InstVisitor.h:191
RetTy visitShuffleVectorInst(ShuffleVectorInst &I)
Definition: InstVisitor.h:193
RetTy visitBitCastInst(BitCastInst &I)
Definition: InstVisitor.h:187
void visit(Iterator Start, Iterator End)
Definition: InstVisitor.h:87
RetTy visitPHINode(PHINode &I)
Definition: InstVisitor.h:175
RetTy visitUnaryOperator(UnaryOperator &I)
Definition: InstVisitor.h:263
RetTy visitStoreInst(StoreInst &I)
Definition: InstVisitor.h:170
RetTy visitInsertElementInst(InsertElementInst &I)
Definition: InstVisitor.h:192
RetTy visitAllocaInst(AllocaInst &I)
Definition: InstVisitor.h:168
RetTy visitBinaryOperator(BinaryOperator &I)
Definition: InstVisitor.h:264
RetTy visitICmpInst(ICmpInst &I)
Definition: InstVisitor.h:166
RetTy visitCallInst(CallInst &I)
Definition: InstVisitor.h:223
RetTy visitCastInst(CastInst &I)
Definition: InstVisitor.h:262
RetTy visitSelectInst(SelectInst &I)
Definition: InstVisitor.h:189
RetTy visitGetElementPtrInst(GetElementPtrInst &I)
Definition: InstVisitor.h:174
void visitInstruction(Instruction &I)
Definition: InstVisitor.h:283
RetTy visitLoadInst(LoadInst &I)
Definition: InstVisitor.h:169
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
Definition: Instruction.cpp:97
InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:92
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
An instruction for reading from memory.
Definition: Instructions.h:176
void setAlignment(Align Align)
Definition: Instructions.h:215
Align getAlign() const
Return the alignment of the access that is being performed.
Definition: Instructions.h:211
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:251
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:117
This class represents the LLVM 'select' instruction.
This instruction constructs a fixed permutation of two input vectors.
size_t size() const
Definition: SmallVector.h:78
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
An instruction for storing to memory.
Definition: Instructions.h:292
void setAlignment(Align Align)
Definition: Instructions.h:337
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1859
Value * getOperand(unsigned i) const
Definition: User.h:228
unsigned getNumOperands() const
Definition: User.h:250
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:534
iterator_range< user_iterator > users()
Definition: Value.h:421
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
@ CE
Windows NT (Windows on ARM)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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:657
ModulePass * createDXILFlattenArraysLegacyPass()
Pass to flatten arrays into a one dimensional DXIL legal form.
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:561