LLVM 23.0.0git
AMDGPULateCodeGenPrepare.cpp
Go to the documentation of this file.
1//===-- AMDGPUCodeGenPrepare.cpp ------------------------------------------===//
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
10/// This pass does misc. AMDGPU optimizations on IR *just* before instruction
11/// selection.
12//
13//===----------------------------------------------------------------------===//
14
15#include "AMDGPU.h"
16#include "AMDGPUMemoryUtils.h"
17#include "AMDGPUTargetMachine.h"
22#include "llvm/IR/IRBuilder.h"
23#include "llvm/IR/InstVisitor.h"
24#include "llvm/IR/IntrinsicsAMDGPU.h"
29
30#define DEBUG_TYPE "amdgpu-late-codegenprepare"
31
32using namespace llvm;
33
34// Scalar load widening needs running after load-store-vectorizer as that pass
35// doesn't handle overlapping cases. In addition, this pass enhances the
36// widening to handle cases where scalar sub-dword loads are naturally aligned
37// only but not dword aligned.
38static cl::opt<bool>
39 WidenLoads("amdgpu-late-codegenprepare-widen-constant-loads",
40 cl::desc("Widen sub-dword constant address space loads in "
41 "AMDGPULateCodeGenPrepare"),
43
44namespace {
45
46class AMDGPULateCodeGenPrepare
47 : public InstVisitor<AMDGPULateCodeGenPrepare, bool> {
48 Function &F;
49 const DataLayout &DL;
50 const GCNSubtarget &ST;
51
52 AssumptionCache *const AC;
54
56
57public:
58 AMDGPULateCodeGenPrepare(Function &F, const GCNSubtarget &ST,
60 : F(F), DL(F.getDataLayout()), ST(ST), AC(AC), UA(UA) {}
61 bool run();
62 bool visitInstruction(Instruction &) { return false; }
63
64 // Check if the specified value is at least DWORD aligned.
65 bool isDWORDAligned(const Value *V) const {
66 KnownBits Known = computeKnownBits(V, DL, AC);
67 return Known.countMinTrailingZeros() >= 2;
68 }
69
70 bool canWidenScalarExtLoad(LoadInst &LI) const;
71 bool visitLoadInst(LoadInst &LI);
72};
73
75
76class LiveRegOptimizer {
77private:
78 Module &Mod;
79 const DataLayout &DL;
80 const GCNSubtarget &ST;
81
82 /// The scalar type to convert to
83 Type *const ConvertToScalar;
84 /// Map of Value -> Converted Value
85 ValueToValueMap ValMap;
86 /// Map of containing conversions from Optimal Type -> Original Type per BB.
87 DenseMap<BasicBlock *, ValueToValueMap> BBUseValMap;
88
89public:
90 /// Calculate the and \p return the type to convert to given a problematic \p
91 /// OriginalType. In some instances, we may widen the type (e.g. v2i8 -> i32).
92 Type *calculateConvertType(Type *OriginalType);
93 /// Convert the virtual register defined by \p V to the compatible vector of
94 /// legal type
95 Value *convertToOptType(Instruction *V, BasicBlock::iterator &InstPt);
96 /// Convert the virtual register defined by \p V back to the original type \p
97 /// ConvertType, stripping away the MSBs in cases where there was an imperfect
98 /// fit (e.g. v2i32 -> v7i8)
99 Value *convertFromOptType(Type *ConvertType, Instruction *V,
100 BasicBlock::iterator &InstPt,
101 BasicBlock *InsertBlock);
102 /// Check for problematic PHI nodes or cross-bb values based on the value
103 /// defined by \p I, and coerce to legal types if necessary. For problematic
104 /// PHI node, we coerce all incoming values in a single invocation.
105 bool optimizeLiveType(Instruction *I,
106 SmallVectorImpl<WeakTrackingVH> &DeadInsts);
107
108 // Whether or not the type should be replaced to avoid inefficient
109 // legalization code
110 bool shouldReplace(Type *ITy) {
111 FixedVectorType *VTy = dyn_cast<FixedVectorType>(ITy);
112 if (!VTy)
113 return false;
114
115 const auto *TLI = ST.getTargetLowering();
116
117 Type *EltTy = VTy->getElementType();
118 // If the element size is not less than the convert to scalar size, then we
119 // can't do any bit packing
120 if (!EltTy->isIntegerTy() ||
121 EltTy->getScalarSizeInBits() > ConvertToScalar->getScalarSizeInBits())
122 return false;
123
124 // Only coerce illegal types
126 TLI->getTypeConversion(EltTy->getContext(), EVT::getEVT(EltTy, false));
127 return LK.first != TargetLoweringBase::TypeLegal;
128 }
129
130 bool isOpLegal(const Instruction *I) {
132 return true;
133
134 // Any store is a profitable sink (prevents flip-flopping)
135 if (isa<StoreInst>(I))
136 return true;
137
138 if (auto *BO = dyn_cast<BinaryOperator>(I)) {
139 if (auto *VT = dyn_cast<FixedVectorType>(BO->getType())) {
140 if (const auto *IT = dyn_cast<IntegerType>(VT->getElementType())) {
141 unsigned EB = IT->getBitWidth();
142 unsigned EC = VT->getNumElements();
143 // Check for SDWA-compatible operation
144 if ((EB == 8 || EB == 16) && ST.hasSDWA() && EC * EB <= 32) {
145 switch (BO->getOpcode()) {
146 case Instruction::Add:
147 case Instruction::Sub:
148 case Instruction::And:
149 case Instruction::Or:
150 case Instruction::Xor:
151 return true;
152 default:
153 break;
154 }
155 }
156 }
157 }
158 }
159
160 return false;
161 }
162
163 bool isCoercionProfitable(Instruction *II) {
164 SmallPtrSet<Instruction *, 4> CVisited;
165 SmallVector<Instruction *, 4> UserList;
166
167 // Check users for profitable conditions (across block user which can
168 // natively handle the illegal vector).
169 for (User *V : II->users())
170 if (auto *UseInst = dyn_cast<Instruction>(V))
171 UserList.push_back(UseInst);
172
173 auto IsLookThru = [](Instruction *II) {
174 if (const auto *Intr = dyn_cast<IntrinsicInst>(II))
175 return Intr->getIntrinsicID() == Intrinsic::amdgcn_perm;
176 return isa<PHINode, ShuffleVectorInst, InsertElementInst,
177 ExtractElementInst, CastInst>(II);
178 };
179
180 while (!UserList.empty()) {
181 auto CII = UserList.pop_back_val();
182 if (!CVisited.insert(CII).second)
183 continue;
184
185 // Same-BB filter must look at the *user*; and allow non-lookthrough
186 // users when the def is a PHI (loop-header pattern).
187 if (CII->getParent() == II->getParent() && !IsLookThru(CII) &&
189 continue;
190
191 if (isOpLegal(CII))
192 return true;
193
194 if (IsLookThru(CII))
195 for (User *V : CII->users())
196 if (auto *UseInst = dyn_cast<Instruction>(V))
197 UserList.push_back(UseInst);
198 }
199 return false;
200 }
201
202 LiveRegOptimizer(Module &Mod, const GCNSubtarget &ST)
203 : Mod(Mod), DL(Mod.getDataLayout()), ST(ST),
204 ConvertToScalar(Type::getInt32Ty(Mod.getContext())) {}
205};
206
207} // end anonymous namespace
208
209bool AMDGPULateCodeGenPrepare::run() {
210 // "Optimize" the virtual regs that cross basic block boundaries. When
211 // building the SelectionDAG, vectors of illegal types that cross basic blocks
212 // will be scalarized and widened, with each scalar living in its
213 // own register. To work around this, this optimization converts the
214 // vectors to equivalent vectors of legal type (which are converted back
215 // before uses in subsequent blocks), to pack the bits into fewer physical
216 // registers (used in CopyToReg/CopyFromReg pairs).
217 LiveRegOptimizer LRO(*F.getParent(), ST);
218
219 bool Changed = false;
220
221 bool HasScalarSubwordLoads = ST.hasScalarSubwordLoads();
222
223 for (auto &BB : reverse(F))
224 for (Instruction &I : make_early_inc_range(reverse(BB))) {
225 Changed |= !HasScalarSubwordLoads && visit(I);
226 Changed |= LRO.optimizeLiveType(&I, DeadInsts);
227 }
228
230 return Changed;
231}
232
233Type *LiveRegOptimizer::calculateConvertType(Type *OriginalType) {
234 assert(OriginalType->getScalarSizeInBits() <=
235 ConvertToScalar->getScalarSizeInBits());
236
237 FixedVectorType *VTy = cast<FixedVectorType>(OriginalType);
238
239 TypeSize OriginalSize = DL.getTypeSizeInBits(VTy);
240 TypeSize ConvertScalarSize = DL.getTypeSizeInBits(ConvertToScalar);
241 unsigned ConvertEltCount =
242 (OriginalSize + ConvertScalarSize - 1) / ConvertScalarSize;
243
244 if (OriginalSize <= ConvertScalarSize)
245 return IntegerType::get(Mod.getContext(), ConvertScalarSize);
246
247 return VectorType::get(Type::getIntNTy(Mod.getContext(), ConvertScalarSize),
248 ConvertEltCount, false);
249}
250
251Value *LiveRegOptimizer::convertToOptType(Instruction *V,
252 BasicBlock::iterator &InsertPt) {
253 FixedVectorType *VTy = cast<FixedVectorType>(V->getType());
254 Type *NewTy = calculateConvertType(V->getType());
255
256 TypeSize OriginalSize = DL.getTypeSizeInBits(VTy);
257 TypeSize NewSize = DL.getTypeSizeInBits(NewTy);
258
259 IRBuilder<> Builder(V->getParent(), InsertPt);
260 // If there is a bitsize match, we can fit the old vector into a new vector of
261 // desired type.
262 if (OriginalSize == NewSize)
263 return Builder.CreateBitCast(V, NewTy, V->getName() + ".bc");
264
265 // If there is a bitsize mismatch, we must use a wider vector.
266 assert(NewSize > OriginalSize);
267 uint64_t ExpandedVecElementCount = NewSize / VTy->getScalarSizeInBits();
268
269 SmallVector<int, 8> ShuffleMask;
270 uint64_t OriginalElementCount = VTy->getElementCount().getFixedValue();
271 for (unsigned I = 0; I < OriginalElementCount; I++)
272 ShuffleMask.push_back(I);
273
274 for (uint64_t I = OriginalElementCount; I < ExpandedVecElementCount; I++)
275 ShuffleMask.push_back(OriginalElementCount);
276
277 Value *ExpandedVec = Builder.CreateShuffleVector(V, ShuffleMask);
278 return Builder.CreateBitCast(ExpandedVec, NewTy, V->getName() + ".bc");
279}
280
281Value *LiveRegOptimizer::convertFromOptType(Type *ConvertType, Instruction *V,
282 BasicBlock::iterator &InsertPt,
283 BasicBlock *InsertBB) {
284 FixedVectorType *NewVTy = cast<FixedVectorType>(ConvertType);
285
286 TypeSize OriginalSize = DL.getTypeSizeInBits(V->getType());
287 TypeSize NewSize = DL.getTypeSizeInBits(NewVTy);
288
289 IRBuilder<> Builder(InsertBB, InsertPt);
290 // If there is a bitsize match, we simply convert back to the original type.
291 if (OriginalSize == NewSize)
292 return Builder.CreateBitCast(V, NewVTy, V->getName() + ".bc");
293
294 // If there is a bitsize mismatch, then we must have used a wider value to
295 // hold the bits.
296 assert(OriginalSize > NewSize);
297 // For wide scalars, we can just truncate the value.
298 if (!V->getType()->isVectorTy()) {
300 Builder.CreateTrunc(V, IntegerType::get(Mod.getContext(), NewSize)));
301 return cast<Instruction>(Builder.CreateBitCast(Trunc, NewVTy));
302 }
303
304 // For wider vectors, we must strip the MSBs to convert back to the original
305 // type.
306 VectorType *ExpandedVT = VectorType::get(
307 Type::getIntNTy(Mod.getContext(), NewVTy->getScalarSizeInBits()),
308 (OriginalSize / NewVTy->getScalarSizeInBits()), false);
309 Instruction *Converted =
310 cast<Instruction>(Builder.CreateBitCast(V, ExpandedVT));
311
312 unsigned NarrowElementCount = NewVTy->getElementCount().getFixedValue();
313 SmallVector<int, 8> ShuffleMask(NarrowElementCount);
314 std::iota(ShuffleMask.begin(), ShuffleMask.end(), 0);
315
316 return Builder.CreateShuffleVector(Converted, ShuffleMask);
317}
318
319bool LiveRegOptimizer::optimizeLiveType(
320 Instruction *I, SmallVectorImpl<WeakTrackingVH> &DeadInsts) {
321 SmallVector<Instruction *, 4> Worklist;
322 SmallPtrSet<PHINode *, 4> PhiNodes;
323 SmallPtrSet<Instruction *, 4> Defs;
324 SmallPtrSet<Instruction *, 4> Uses;
325 SmallPtrSet<Instruction *, 4> Visited;
326
327 Worklist.push_back(cast<Instruction>(I));
328 while (!Worklist.empty()) {
329 Instruction *II = Worklist.pop_back_val();
330
331 if (!Visited.insert(II).second)
332 continue;
333
334 if (!shouldReplace(II->getType()))
335 continue;
336
337 if (!isCoercionProfitable(II))
338 continue;
339
340 if (PHINode *Phi = dyn_cast<PHINode>(II)) {
341 PhiNodes.insert(Phi);
342 // Collect all the incoming values of problematic PHI nodes.
343 for (Value *V : Phi->incoming_values()) {
344 // Repeat the collection process for newly found PHI nodes.
345 if (PHINode *OpPhi = dyn_cast<PHINode>(V)) {
346 if (!PhiNodes.count(OpPhi) && !Visited.count(OpPhi))
347 Worklist.push_back(OpPhi);
348 continue;
349 }
350
352 // Other incoming value types (e.g. vector literals) are unhandled
353 if (!IncInst && !isa<ConstantAggregateZero>(V))
354 return false;
355
356 // Collect all other incoming values for coercion.
357 if (IncInst)
358 Defs.insert(IncInst);
359 }
360 }
361
362 // Collect all relevant uses.
363 for (User *V : II->users()) {
364 // Repeat the collection process for problematic PHI nodes.
365 if (PHINode *OpPhi = dyn_cast<PHINode>(V)) {
366 if (!PhiNodes.count(OpPhi) && !Visited.count(OpPhi))
367 Worklist.push_back(OpPhi);
368 continue;
369 }
370
371 Instruction *UseInst = cast<Instruction>(V);
372 // Collect all uses of PHINodes and any use the crosses BB boundaries.
373 if (UseInst->getParent() != II->getParent() || isa<PHINode>(II)) {
374 Uses.insert(UseInst);
375 if (!isa<PHINode>(II))
376 Defs.insert(II);
377 }
378 }
379 }
380
381 // Coerce and track the defs.
382 for (Instruction *D : Defs) {
383 if (!ValMap.contains(D)) {
384 BasicBlock::iterator InsertPt = std::next(D->getIterator());
385 Value *ConvertVal = convertToOptType(D, InsertPt);
386 assert(ConvertVal);
387 ValMap[D] = ConvertVal;
388 }
389 }
390
391 // Construct new-typed PHI nodes.
392 for (PHINode *Phi : PhiNodes) {
393 ValMap[Phi] = PHINode::Create(calculateConvertType(Phi->getType()),
394 Phi->getNumIncomingValues(),
395 Phi->getName() + ".tc", Phi->getIterator());
396 }
397
398 // Connect all the PHI nodes with their new incoming values.
399 for (PHINode *Phi : PhiNodes) {
400 PHINode *NewPhi = cast<PHINode>(ValMap[Phi]);
401 bool MissingIncVal = false;
402 for (int I = 0, E = Phi->getNumIncomingValues(); I < E; I++) {
403 Value *IncVal = Phi->getIncomingValue(I);
404 if (isa<ConstantAggregateZero>(IncVal)) {
405 Type *NewType = calculateConvertType(Phi->getType());
406 NewPhi->addIncoming(ConstantInt::get(NewType, 0, false),
407 Phi->getIncomingBlock(I));
408 } else if (Value *Val = ValMap.lookup(IncVal))
409 NewPhi->addIncoming(Val, Phi->getIncomingBlock(I));
410 else
411 MissingIncVal = true;
412 }
413 if (MissingIncVal) {
414 Value *DeadVal = ValMap[Phi];
415 // The coercion chain of the PHI is broken. Delete the Phi
416 // from the ValMap and any connected / user Phis.
417 SmallVector<Value *, 4> PHIWorklist;
418 SmallPtrSet<Value *, 4> VisitedPhis;
419 PHIWorklist.push_back(DeadVal);
420 while (!PHIWorklist.empty()) {
421 Value *NextDeadValue = PHIWorklist.pop_back_val();
422 VisitedPhis.insert(NextDeadValue);
423 auto OriginalPhi =
424 llvm::find_if(PhiNodes, [this, &NextDeadValue](PHINode *CandPhi) {
425 return ValMap[CandPhi] == NextDeadValue;
426 });
427 // This PHI may have already been removed from maps when
428 // unwinding a previous Phi
429 if (OriginalPhi != PhiNodes.end())
430 ValMap.erase(*OriginalPhi);
431
432 DeadInsts.emplace_back(cast<Instruction>(NextDeadValue));
433
434 for (User *U : NextDeadValue->users()) {
435 if (!VisitedPhis.contains(cast<PHINode>(U)))
436 PHIWorklist.push_back(U);
437 }
438 }
439 } else {
440 DeadInsts.emplace_back(cast<Instruction>(Phi));
441 }
442 }
443 // Coerce back to the original type and replace the uses.
444 for (Instruction *U : Uses) {
445 // Replace all converted operands for a use.
446 for (auto [OpIdx, Op] : enumerate(U->operands())) {
447 if (Value *Val = ValMap.lookup(Op)) {
448 Value *NewVal = nullptr;
449 if (BBUseValMap.contains(U->getParent()) &&
450 BBUseValMap[U->getParent()].contains(Val))
451 NewVal = BBUseValMap[U->getParent()][Val];
452 else {
453 BasicBlock::iterator InsertPt = U->getParent()->getFirstNonPHIIt();
454 // We may pick up ops that were previously converted for users in
455 // other blocks. If there is an originally typed definition of the Op
456 // already in this block, simply reuse it.
458 U->getParent() == cast<Instruction>(Op)->getParent()) {
459 NewVal = Op;
460 } else {
461 NewVal =
462 convertFromOptType(Op->getType(), cast<Instruction>(ValMap[Op]),
463 InsertPt, U->getParent());
464 BBUseValMap[U->getParent()][ValMap[Op]] = NewVal;
465 }
466 }
467 assert(NewVal);
468 U->setOperand(OpIdx, NewVal);
469 }
470 }
471 }
472
473 return true;
474}
475
476bool AMDGPULateCodeGenPrepare::canWidenScalarExtLoad(LoadInst &LI) const {
477 unsigned AS = LI.getPointerAddressSpace();
478 // Skip non-constant address space.
479 if (AS != AMDGPUAS::CONSTANT_ADDRESS &&
481 return false;
482 // Skip non-simple loads.
483 if (!LI.isSimple())
484 return false;
485 Type *Ty = LI.getType();
486 // Skip aggregate types.
487 if (Ty->isAggregateType())
488 return false;
489 unsigned TySize = DL.getTypeStoreSize(Ty);
490 // Only handle sub-DWORD loads.
491 if (TySize >= 4)
492 return false;
493 // That load must be at least naturally aligned.
494 if (LI.getAlign() < DL.getABITypeAlign(Ty))
495 return false;
496 // It should be uniform, i.e. a scalar load.
497 return UA.isUniformAtDef(&LI);
498}
499
500bool AMDGPULateCodeGenPrepare::visitLoadInst(LoadInst &LI) {
501 if (!WidenLoads)
502 return false;
503
504 // Skip if that load is already aligned on DWORD at least as it's handled in
505 // SDAG.
506 if (LI.getAlign() >= 4)
507 return false;
508
509 if (!canWidenScalarExtLoad(LI))
510 return false;
511
512 int64_t Offset = 0;
513 auto *Base =
515 // If that base is not DWORD aligned, it's not safe to perform the following
516 // transforms.
517 if (!isDWORDAligned(Base))
518 return false;
519
520 int64_t Adjust = Offset & 0x3;
521 if (Adjust == 0) {
522 // With a zero adjust, the original alignment could be promoted with a
523 // better one.
524 LI.setAlignment(Align(4));
525 return true;
526 }
527
528 IRBuilder<> IRB(&LI);
529 IRB.SetCurrentDebugLocation(LI.getDebugLoc());
530
531 unsigned LdBits = DL.getTypeStoreSizeInBits(LI.getType());
532 auto *IntNTy = Type::getIntNTy(LI.getContext(), LdBits);
533
534 auto *NewPtr = IRB.CreateConstGEP1_64(
535 IRB.getInt8Ty(),
536 IRB.CreateAddrSpaceCast(Base, LI.getPointerOperand()->getType()),
537 Offset - Adjust);
538
539 LoadInst *NewLd = IRB.CreateAlignedLoad(IRB.getInt32Ty(), NewPtr, Align(4));
541
542 unsigned ShAmt = Adjust * 8;
543 Value *NewVal = IRB.CreateBitCast(
544 IRB.CreateTrunc(IRB.CreateLShr(NewLd, ShAmt),
545 DL.typeSizeEqualsStoreSize(LI.getType()) ? IntNTy
546 : LI.getType()),
547 LI.getType());
548 LI.replaceAllUsesWith(NewVal);
549 DeadInsts.emplace_back(&LI);
550
551 return true;
552}
553
554PreservedAnalyses
556 const GCNSubtarget &ST = TM.getSubtarget<GCNSubtarget>(F);
557 AssumptionCache &AC = FAM.getResult<AssumptionAnalysis>(F);
558 UniformityInfo &UI = FAM.getResult<UniformityInfoAnalysis>(F);
559
560 bool Changed = AMDGPULateCodeGenPrepare(F, ST, &AC, UI).run();
561
562 if (!Changed)
563 return PreservedAnalyses::all();
566 return PA;
567}
568
570public:
571 static char ID;
572
574
575 StringRef getPassName() const override {
576 return "AMDGPU IR late optimizations";
577 }
578
579 void getAnalysisUsage(AnalysisUsage &AU) const override {
583 // Invalidates UniformityInfo
584 AU.setPreservesCFG();
585 }
586
587 bool runOnFunction(Function &F) override;
588};
589
591 if (skipFunction(F))
592 return false;
593
595 const TargetMachine &TM = TPC.getTM<TargetMachine>();
596 const GCNSubtarget &ST = TM.getSubtarget<GCNSubtarget>(F);
597
598 AssumptionCache &AC =
599 getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
600 UniformityInfo &UI =
601 getAnalysis<UniformityInfoWrapperPass>().getUniformityInfo();
602
603 return AMDGPULateCodeGenPrepare(F, ST, &AC, UI).run();
604}
605
607 "AMDGPU IR late optimizations", false, false)
612 "AMDGPU IR late optimizations", false, false)
613
615
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static cl::opt< bool > WidenLoads("amdgpu-late-codegenprepare-widen-constant-loads", cl::desc("Widen sub-dword constant address space loads in " "AMDGPULateCodeGenPrepare"), cl::ReallyHidden, cl::init(true))
The AMDGPU TargetMachine interface definition for hw codegen targets.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate any type of IT block"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow complex IT blocks")))
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool runOnFunction(Function &F, bool PostInlining)
#define DEBUG_TYPE
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Machine Check Debug Module
MachineInstr unsigned OpIdx
uint64_t IntrinsicInst * II
if(auto Err=PB.parsePassPipeline(MPM, Passes)) return wrap(std MPM run * Mod
FunctionAnalysisManager FAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition PassSupport.h:42
#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
Remove Loads Into Fake Uses
static void visit(BasicBlock &Start, std::function< bool(BasicBlock *)> op)
Target-Independent Code Generator Pass Configuration Options pass.
LLVM IR instance of the generic uniformity analysis.
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
PreservedAnalyses run(Function &, FunctionAnalysisManager &)
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:270
A function analysis which provides an AssumptionCache.
An immutable pass that tracks lazily created AssumptionCache objects.
A cache of @llvm.assume calls within a function.
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:170
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
ValueT lookup(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or a default constructed value if no such entry exists.
Definition DenseMap.h:252
bool erase(const KeyT &Val)
Definition DenseMap.h:379
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
Definition DenseMap.h:216
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
FunctionPass(char &pid)
Definition Pass.h:316
bool skipFunction(const Function &F) const
Optional passes call this function to check whether the pass should be skipped.
Definition Pass.cpp:188
bool isUniformAtDef(ConstValueRefT V) const
Whether V is uniform/non-divergent at its definition.
Base class for instruction visitors.
Definition InstVisitor.h:78
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:350
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
void setAlignment(Align Align)
Value * getPointerOperand()
bool isSimple() const
Align getAlign() const
Return the alignment of the access that is being performed.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition Analysis.h:115
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:151
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::pair< LegalizeTypeAction, EVT > LegalizeKind
LegalizeKind holds the legalization kind that needs to happen to EVT in order to type-legalize it.
Primary interface to the complete machine description for the target machine.
const STC & getSubtarget(const Function &F) const
This method returns a pointer to the specified type of TargetSubtargetInfo.
Target-Independent Code Generator Pass Configuration Options.
TMC & getTM() const
Get the right type of TargetMachine for this target.
bool isAggregateType() const
Return true if the type is an aggregate type.
Definition Type.h:319
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition Type.h:130
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.cpp:232
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:257
Analysis pass which computes UniformityInfo.
Legacy analysis pass which computes a CycleInfo.
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:255
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition Value.cpp:552
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:258
iterator_range< user_iterator > users()
Definition Value.h:426
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
Type * getElementType() const
constexpr ScalarTy getFixedValue() const
Definition TypeSize.h:200
const ParentTy * getParent() const
Definition ilist_node.h:34
Changed
@ CONSTANT_ADDRESS_32BIT
Address space for 32-bit constant memory.
@ CONSTANT_ADDRESS
Address space for constant memory (VTX2).
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
void copyMetadataForWidenedLoad(LoadInst &Dest, const LoadInst &Source)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
initializer< Ty > init(const Ty &Val)
DXILDebugInfoMap run(Module &M)
NodeAddr< PhiNode * > Phi
Definition RDFGraph.h:390
Context & getContext() const
Definition BasicBlock.h:99
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
This is an optimization pass for GlobalISel generic memory operations.
GenericUniformityInfo< SSAContext > UniformityInfo
@ Offset
Definition DWP.cpp:558
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition STLExtras.h:2553
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.
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:633
auto reverse(ContainerTy &&C)
Definition STLExtras.h:407
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
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
IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >
DWARFExpression::Operation Op
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:550
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1771
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
FunctionPass * createAMDGPULateCodeGenPrepareLegacyPass()
DenseMap< const Value *, Value * > ValueToValueMap
static LLVM_ABI EVT getEVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
Definition KnownBits.h:256