LLVM 24.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"
19#include "llvm/Analysis/Loads.h"
23#include "llvm/IR/IRBuilder.h"
24#include "llvm/IR/InstVisitor.h"
25#include "llvm/IR/IntrinsicsAMDGPU.h"
28
29#define DEBUG_TYPE "amdgpu-late-codegenprepare"
30
31using namespace llvm;
32
33namespace {
34
35class AMDGPULateCodeGenPrepare
36 : public InstVisitor<AMDGPULateCodeGenPrepare, bool> {
37 Function &F;
38 const DataLayout &DL;
39 const GCNSubtarget &ST;
40
41 AssumptionCache *const AC;
43
45
46public:
47 AMDGPULateCodeGenPrepare(Function &F, const GCNSubtarget &ST,
49 : F(F), DL(F.getDataLayout()), ST(ST), AC(AC), UA(UA) {}
50 bool run();
51 bool visitInstruction(Instruction &) { return false; }
52
53 // Widening may read padding bytes past the original access, so require the
54 // whole AccessSize-byte range at Base to be dereferenceable, not just Base
55 // itself aligned.
56 bool isSafeToWidenLoad(const Value *Base, uint64_t AccessSize,
57 const Instruction *CtxI) const {
59 Base, Align(4),
60 APInt(DL.getIndexTypeSizeInBits(Base->getType()), AccessSize),
61 SimplifyQuery(DL, /*TLI=*/nullptr, /*DT=*/nullptr, AC, CtxI));
62 }
63
64 bool canWidenScalarExtLoad(LoadInst &LI) const;
65 bool visitLoadInst(LoadInst &LI);
66};
67
69
70class LiveRegOptimizer {
71private:
72 Module &Mod;
73 const DataLayout &DL;
74 const GCNSubtarget &ST;
75
76 /// The scalar type to convert to
77 Type *const ConvertToScalar;
78 /// Map of Value -> Converted Value
79 ValueToValueMap ValMap;
80 /// Map of containing conversions from Optimal Type -> Original Type per BB.
82
83public:
84 /// Calculate the and \p return the type to convert to given a problematic \p
85 /// OriginalType. In some instances, we may widen the type (e.g. v2i8 -> i32).
86 Type *calculateConvertType(Type *OriginalType);
87 /// Convert the virtual register defined by \p V to the compatible vector of
88 /// legal type
89 Value *convertToOptType(Instruction *V, BasicBlock::iterator &InstPt);
90 /// Convert the virtual register defined by \p V back to the original type \p
91 /// ConvertType, stripping away the MSBs in cases where there was an imperfect
92 /// fit (e.g. v2i32 -> v7i8)
93 Value *convertFromOptType(Type *ConvertType, Instruction *V,
95 BasicBlock *InsertBlock);
96 /// Check for problematic PHI nodes or cross-bb values based on the value
97 /// defined by \p I, and coerce to legal types if necessary. For problematic
98 /// PHI node, we coerce all incoming values in a single invocation.
99 bool optimizeLiveType(Instruction *I,
101
102 // Whether or not the type should be replaced to avoid inefficient
103 // legalization code
104 bool shouldReplace(Type *ITy) {
106 if (!VTy)
107 return false;
108
109 const auto *TLI = ST.getTargetLowering();
110
111 Type *EltTy = VTy->getElementType();
112 // If the element size is not is not a multiple scalar size, then we can't
113 // do any bit packing
114 if (!EltTy->isIntegerTy() ||
115 ConvertToScalar->getScalarSizeInBits() % EltTy->getScalarSizeInBits())
116 return false;
117
118 // Only coerce illegal types
120 TLI->getTypeConversion(EltTy->getContext(), EVT::getEVT(EltTy, false));
121 return LK.first != TargetLoweringBase::TypeLegal;
122 }
123
124 bool isOpLegal(const Instruction *I) {
126 return true;
127
128 // Any store is a profitable sink (prevents flip-flopping)
129 if (isa<StoreInst>(I))
130 return true;
131
132 if (auto *BO = dyn_cast<BinaryOperator>(I)) {
133 if (auto *VT = dyn_cast<FixedVectorType>(BO->getType())) {
134 if (const auto *IT = dyn_cast<IntegerType>(VT->getElementType())) {
135 unsigned EB = IT->getBitWidth();
136 unsigned EC = VT->getNumElements();
137 // Check for SDWA-compatible operation
138 if ((EB == 8 || EB == 16) && ST.hasSDWA() && EC * EB <= 32) {
139 switch (BO->getOpcode()) {
140 case Instruction::Add:
141 case Instruction::Sub:
142 case Instruction::And:
143 case Instruction::Or:
144 case Instruction::Xor:
145 return true;
146 default:
147 break;
148 }
149 }
150 }
151 }
152 }
153
154 return false;
155 }
156
157 bool isCoercionProfitable(Instruction *II) {
160
161 // Check users for profitable conditions (across block user which can
162 // natively handle the illegal vector).
163 for (User *V : II->users())
164 if (auto *UseInst = dyn_cast<Instruction>(V))
165 UserList.push_back(UseInst);
166
167 auto IsLookThru = [](Instruction *II) {
168 if (const auto *Intr = dyn_cast<IntrinsicInst>(II))
169 return Intr->getIntrinsicID() == Intrinsic::amdgcn_perm;
172 };
173
174 while (!UserList.empty()) {
175 auto CII = UserList.pop_back_val();
176 if (!CVisited.insert(CII).second)
177 continue;
178
179 // Same-BB filter must look at the *user*; and allow non-lookthrough
180 // users when the def is a PHI (loop-header pattern).
181 if (CII->getParent() == II->getParent() && !IsLookThru(CII) &&
183 continue;
184
185 if (isOpLegal(CII))
186 return true;
187
188 if (IsLookThru(CII))
189 for (User *V : CII->users())
190 if (auto *UseInst = dyn_cast<Instruction>(V))
191 UserList.push_back(UseInst);
192 }
193 return false;
194 }
195
196 LiveRegOptimizer(Module &Mod, const GCNSubtarget &ST)
197 : Mod(Mod), DL(Mod.getDataLayout()), ST(ST),
198 ConvertToScalar(Type::getInt32Ty(Mod.getContext())) {}
199};
200
201} // end anonymous namespace
202
203bool AMDGPULateCodeGenPrepare::run() {
204 // "Optimize" the virtual regs that cross basic block boundaries. When
205 // building the SelectionDAG, vectors of illegal types that cross basic blocks
206 // will be scalarized and widened, with each scalar living in its
207 // own register. To work around this, this optimization converts the
208 // vectors to equivalent vectors of legal type (which are converted back
209 // before uses in subsequent blocks), to pack the bits into fewer physical
210 // registers (used in CopyToReg/CopyFromReg pairs).
211 LiveRegOptimizer LRO(*F.getParent(), ST);
212
213 bool Changed = false;
214
215 bool HasScalarSubwordLoads = ST.hasScalarSubwordLoads();
216
217 for (auto &BB : reverse(F))
218 for (Instruction &I : make_early_inc_range(reverse(BB))) {
219 Changed |= !HasScalarSubwordLoads && visit(I);
220 Changed |= LRO.optimizeLiveType(&I, DeadInsts);
221 }
222
224 return Changed;
225}
226
227Type *LiveRegOptimizer::calculateConvertType(Type *OriginalType) {
228 assert(OriginalType->getScalarSizeInBits() <=
229 ConvertToScalar->getScalarSizeInBits());
230
231 FixedVectorType *VTy = cast<FixedVectorType>(OriginalType);
232
233 TypeSize OriginalSize = DL.getTypeSizeInBits(VTy);
234 TypeSize ConvertScalarSize = DL.getTypeSizeInBits(ConvertToScalar);
235 unsigned ConvertEltCount =
236 (OriginalSize + ConvertScalarSize - 1) / ConvertScalarSize;
237
238 if (OriginalSize <= ConvertScalarSize)
239 return IntegerType::get(Mod.getContext(), ConvertScalarSize);
240
241 return VectorType::get(Type::getIntNTy(Mod.getContext(), ConvertScalarSize),
242 ConvertEltCount, false);
243}
244
245Value *LiveRegOptimizer::convertToOptType(Instruction *V,
246 BasicBlock::iterator &InsertPt) {
247 FixedVectorType *VTy = cast<FixedVectorType>(V->getType());
248 Type *NewTy = calculateConvertType(V->getType());
249
250 TypeSize OriginalSize = DL.getTypeSizeInBits(VTy);
251 TypeSize NewSize = DL.getTypeSizeInBits(NewTy);
252
253 IRBuilder<> Builder(InsertPt);
254 // If there is a bitsize match, we can fit the old vector into a new vector of
255 // desired type.
256 if (OriginalSize == NewSize)
257 return Builder.CreateBitCast(V, NewTy, V->getName() + ".bc");
258
259 // If there is a bitsize mismatch, we must use a wider vector.
260 assert(NewSize > OriginalSize);
261 uint64_t ExpandedVecElementCount = NewSize / VTy->getScalarSizeInBits();
262
263 SmallVector<int, 8> ShuffleMask;
264 uint64_t OriginalElementCount = VTy->getElementCount().getFixedValue();
265 for (unsigned I = 0; I < OriginalElementCount; I++)
266 ShuffleMask.push_back(I);
267
268 for (uint64_t I = OriginalElementCount; I < ExpandedVecElementCount; I++)
269 ShuffleMask.push_back(OriginalElementCount);
270
271 Value *ExpandedVec = Builder.CreateShuffleVector(V, ShuffleMask);
272 return Builder.CreateBitCast(ExpandedVec, NewTy, V->getName() + ".bc");
273}
274
275Value *LiveRegOptimizer::convertFromOptType(Type *ConvertType, Instruction *V,
276 BasicBlock::iterator &InsertPt,
277 BasicBlock *InsertBB) {
278 FixedVectorType *NewVTy = cast<FixedVectorType>(ConvertType);
279
280 TypeSize OriginalSize = DL.getTypeSizeInBits(V->getType());
281 TypeSize NewSize = DL.getTypeSizeInBits(NewVTy);
282
283 IRBuilder<> Builder(InsertPt);
284 // If there is a bitsize match, we simply convert back to the original type.
285 if (OriginalSize == NewSize)
286 return Builder.CreateBitCast(V, NewVTy, V->getName() + ".bc");
287
288 // If there is a bitsize mismatch, then we must have used a wider value to
289 // hold the bits.
290 assert(OriginalSize > NewSize);
291 // For wide scalars, we can just truncate the value.
292 if (!V->getType()->isVectorTy()) {
294 Builder.CreateTrunc(V, IntegerType::get(Mod.getContext(), NewSize)));
295 return cast<Instruction>(Builder.CreateBitCast(Trunc, NewVTy));
296 }
297
298 // For wider vectors, we must strip the MSBs to convert back to the original
299 // type.
300 VectorType *ExpandedVT = VectorType::get(
301 Type::getIntNTy(Mod.getContext(), NewVTy->getScalarSizeInBits()),
302 (OriginalSize / NewVTy->getScalarSizeInBits()), false);
303 Instruction *Converted =
304 cast<Instruction>(Builder.CreateBitCast(V, ExpandedVT));
305
306 unsigned NarrowElementCount = NewVTy->getElementCount().getFixedValue();
307 SmallVector<int, 8> ShuffleMask(NarrowElementCount);
308 std::iota(ShuffleMask.begin(), ShuffleMask.end(), 0);
309
310 return Builder.CreateShuffleVector(Converted, ShuffleMask);
311}
312
313bool LiveRegOptimizer::optimizeLiveType(
314 Instruction *I, SmallVectorImpl<WeakTrackingVH> &DeadInsts) {
315 SmallVector<Instruction *, 4> Worklist;
316 SmallPtrSet<PHINode *, 4> PhiNodes;
317 SmallPtrSet<Instruction *, 4> Defs;
318 SmallPtrSet<Instruction *, 4> Uses;
319 SmallPtrSet<Instruction *, 4> Visited;
320
321 Worklist.push_back(cast<Instruction>(I));
322 while (!Worklist.empty()) {
323 Instruction *II = Worklist.pop_back_val();
324
325 if (!Visited.insert(II).second)
326 continue;
327
328 if (!shouldReplace(II->getType()))
329 continue;
330
331 if (!isCoercionProfitable(II))
332 continue;
333
334 if (PHINode *Phi = dyn_cast<PHINode>(II)) {
335 PhiNodes.insert(Phi);
336 // Collect all the incoming values of problematic PHI nodes.
337 for (Value *V : Phi->incoming_values()) {
338 // Repeat the collection process for newly found PHI nodes.
339 if (PHINode *OpPhi = dyn_cast<PHINode>(V)) {
340 if (!PhiNodes.count(OpPhi) && !Visited.count(OpPhi))
341 Worklist.push_back(OpPhi);
342 continue;
343 }
344
346 // Other incoming value types (e.g. vector literals) are unhandled
347 if (!IncInst && !isa<ConstantAggregateZero>(V))
348 return false;
349
350 // Collect all other incoming values for coercion.
351 if (IncInst && !IncInst->isTerminator())
352 Defs.insert(IncInst);
353 }
354 }
355
356 // Collect all relevant uses.
357 for (User *V : II->users()) {
358 // Repeat the collection process for problematic PHI nodes.
359 if (PHINode *OpPhi = dyn_cast<PHINode>(V)) {
360 if (!PhiNodes.count(OpPhi) && !Visited.count(OpPhi))
361 Worklist.push_back(OpPhi);
362 continue;
363 }
364
365 Instruction *UseInst = cast<Instruction>(V);
366 // Collect all uses of PHINodes and any use the crosses BB boundaries.
367 if (UseInst->getParent() != II->getParent() || isa<PHINode>(II)) {
368 Uses.insert(UseInst);
369 if (!isa<PHINode>(II) && !II->isTerminator())
370 Defs.insert(II);
371 }
372 }
373 }
374
375 // Coerce and track the defs.
376 for (Instruction *D : Defs) {
377 if (!ValMap.contains(D)) {
378 BasicBlock::iterator InsertPt = std::next(D->getIterator());
379 Value *ConvertVal = convertToOptType(D, InsertPt);
380 assert(ConvertVal);
381 ValMap[D] = ConvertVal;
382 }
383 }
384
385 // Construct new-typed PHI nodes.
386 for (PHINode *Phi : PhiNodes) {
387 ValMap[Phi] = PHINode::Create(calculateConvertType(Phi->getType()),
388 Phi->getNumIncomingValues(),
389 Phi->getName() + ".tc", Phi->getIterator());
390 }
391
392 // Connect all the PHI nodes with their new incoming values.
393 for (PHINode *Phi : PhiNodes) {
394 PHINode *NewPhi = cast<PHINode>(ValMap[Phi]);
395 bool MissingIncVal = false;
396 for (int I = 0, E = Phi->getNumIncomingValues(); I < E; I++) {
397 Value *IncVal = Phi->getIncomingValue(I);
398 if (isa<ConstantAggregateZero>(IncVal)) {
399 Type *NewType = calculateConvertType(Phi->getType());
400 NewPhi->addIncoming(ConstantInt::get(NewType, 0, false),
401 Phi->getIncomingBlock(I));
402 } else if (Value *Val = ValMap.lookup(IncVal))
403 NewPhi->addIncoming(Val, Phi->getIncomingBlock(I));
404 else
405 MissingIncVal = true;
406 }
407 if (MissingIncVal) {
408 Value *DeadVal = ValMap[Phi];
409 // The coercion chain of the PHI is broken. Delete the Phi
410 // from the ValMap and any connected / user Phis.
411 SmallVector<Value *, 4> PHIWorklist;
412 SmallPtrSet<Value *, 4> VisitedPhis;
413 PHIWorklist.push_back(DeadVal);
414 while (!PHIWorklist.empty()) {
415 Value *NextDeadValue = PHIWorklist.pop_back_val();
416 VisitedPhis.insert(NextDeadValue);
417 auto OriginalPhi =
418 llvm::find_if(PhiNodes, [this, &NextDeadValue](PHINode *CandPhi) {
419 return ValMap[CandPhi] == NextDeadValue;
420 });
421 // This PHI may have already been removed from maps when
422 // unwinding a previous Phi
423 if (OriginalPhi != PhiNodes.end())
424 ValMap.erase(*OriginalPhi);
425
426 for (User *U : NextDeadValue->users()) {
427 if (!VisitedPhis.contains(cast<PHINode>(U)))
428 PHIWorklist.push_back(U);
429 }
430 NextDeadValue->replaceAllUsesWith(
431 PoisonValue::get(NextDeadValue->getType()));
432
433 DeadInsts.emplace_back(cast<Instruction>(NextDeadValue));
434 }
435 } else {
436 DeadInsts.emplace_back(cast<Instruction>(Phi));
437 }
438 }
439 // Coerce back to the original type and replace the uses.
440 for (Instruction *U : Uses) {
441 // Replace all converted operands for a use.
442 for (auto [OpIdx, Op] : enumerate(U->operands())) {
443 if (Value *Val = ValMap.lookup(Op)) {
444 Value *NewVal = nullptr;
445 if (BBUseValMap.contains(U->getParent()) &&
446 BBUseValMap[U->getParent()].contains(Val))
447 NewVal = BBUseValMap[U->getParent()][Val];
448 else {
449 // Not getFirstNonPHIIt, which would insert in front of a landingpad.
450 BasicBlock::iterator InsertPt = U->getParent()->getFirstInsertionPt();
451 // We may pick up ops that were previously converted for users in
452 // other blocks. If there is an originally typed definition of the Op
453 // already in this block, simply reuse it.
455 U->getParent() == cast<Instruction>(Op)->getParent()) {
456 NewVal = Op;
457 } else {
458 NewVal =
459 convertFromOptType(Op->getType(), cast<Instruction>(ValMap[Op]),
460 InsertPt, U->getParent());
461 BBUseValMap[U->getParent()][ValMap[Op]] = NewVal;
462 }
463 }
464 assert(NewVal);
465 U->setOperand(OpIdx, NewVal);
466 }
467 }
468 }
469
470 return true;
471}
472
473bool AMDGPULateCodeGenPrepare::canWidenScalarExtLoad(LoadInst &LI) const {
474 unsigned AS = LI.getPointerAddressSpace();
475 // Skip non-constant address space.
476 if (AS != AMDGPUAS::CONSTANT_ADDRESS &&
478 return false;
479 // Skip non-simple loads.
480 if (!LI.isSimple())
481 return false;
482 Type *Ty = LI.getType();
483 // Skip aggregate types.
484 if (Ty->isAggregateType())
485 return false;
486 unsigned TySize = DL.getTypeStoreSize(Ty);
487 // Only handle sub-DWORD loads.
488 if (TySize >= 4)
489 return false;
490 // That load must be at least naturally aligned.
491 if (LI.getAlign() < DL.getABITypeAlign(Ty))
492 return false;
493 // It should be uniform, i.e. a scalar load.
494 return UA.isUniformAtDef(&LI);
495}
496
497bool AMDGPULateCodeGenPrepare::visitLoadInst(LoadInst &LI) {
498 if (!ST.getCLOpts().late_codegenprepare_widen_constant_loads)
499 return false;
500
501 // Skip if that load is already aligned on DWORD at least as it's handled in
502 // SDAG.
503 if (LI.getAlign() >= 4)
504 return false;
505
506 if (!canWidenScalarExtLoad(LI))
507 return false;
508
509 int64_t Offset = 0;
510 auto *Base =
512
513 int64_t Adjust = Offset & 0x3;
514 int64_t AccessOffset = Offset - Adjust;
515 if (AccessOffset < 0 || !isSafeToWidenLoad(Base, AccessOffset + 4, &LI))
516 return false;
517
518 IRBuilder<> IRB(&LI);
519 IRB.SetCurrentDebugLocation(LI.getDebugLoc());
520
521 unsigned LdBits = DL.getTypeStoreSizeInBits(LI.getType());
522 auto *IntNTy = Type::getIntNTy(LI.getContext(), LdBits);
523
524 auto *NewPtr = IRB.CreateConstGEP1_64(
525 IRB.getInt8Ty(),
526 IRB.CreateAddrSpaceCast(Base, LI.getPointerOperand()->getType()),
527 Offset - Adjust);
528
529 LoadInst *NewLd = IRB.CreateAlignedLoad(IRB.getInt32Ty(), NewPtr, Align(4));
531
532 unsigned ShAmt = Adjust * 8;
533 Value *Shifted = ShAmt ? IRB.CreateLShr(NewLd, ShAmt) : NewLd;
534 Value *NewVal = IRB.CreateBitCast(
535 IRB.CreateTrunc(Shifted, DL.typeSizeEqualsStoreSize(LI.getType())
536 ? IntNTy
537 : LI.getType()),
538 LI.getType());
539 LI.replaceAllUsesWith(NewVal);
540 DeadInsts.emplace_back(&LI);
541
542 return true;
543}
544
545PreservedAnalyses
547 const GCNSubtarget &ST = TM.getSubtarget<GCNSubtarget>(F);
548 AssumptionCache &AC = FAM.getResult<AssumptionAnalysis>(F);
549 UniformityInfo &UI = FAM.getResult<UniformityInfoAnalysis>(F);
550
551 bool Changed = AMDGPULateCodeGenPrepare(F, ST, &AC, UI).run();
552
553 if (!Changed)
554 return PreservedAnalyses::all();
557 return PA;
558}
559
561public:
562 static char ID;
563
565
566 StringRef getPassName() const override {
567 return "AMDGPU IR late optimizations";
568 }
569
570 void getAnalysisUsage(AnalysisUsage &AU) const override {
574 // Invalidates UniformityInfo
575 AU.setPreservesCFG();
576 }
577
578 bool runOnFunction(Function &F) override;
579};
580
582 if (skipFunction(F))
583 return false;
584
586 const TargetMachine &TM = TPC.getTM<TargetMachine>();
587 const GCNSubtarget &ST = TM.getSubtarget<GCNSubtarget>(F);
588
589 AssumptionCache &AC =
590 getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
591 UniformityInfo &UI =
592 getAnalysis<UniformityInfoWrapperPass>().getUniformityInfo();
593
594 return AMDGPULateCodeGenPrepare(F, ST, &AC, UI).run();
595}
596
598 "AMDGPU IR late optimizations", false, false)
603 "AMDGPU IR late optimizations", false, false)
604
606
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
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
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 &)
const AMDGPUOptions & getCLOpts() const
Class for arbitrary precision integers.
Definition APInt.h:78
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:280
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.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:170
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
This is the base class for all instructions that perform data casts.
Definition InstrTypes.h:512
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
Definition DenseMap.h:757
bool erase(const KeyT &Val)
Definition DenseMap.h:930
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:793
This instruction extracts a single (scalar) element from a VectorType value.
Class to represent fixed width SIMD vectors.
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:312
FunctionPass(char &pid)
Definition Pass.h:314
bool skipFunction(const Function &F) const
Optional passes call this function to check whether the pass should be skipped.
Definition Pass.cpp:197
bool hasScalarSubwordLoads() const
bool isUniformAtDef(ConstValueRefT V) const
Whether V is uniform/non-divergent at its definition.
This instruction inserts a single (scalar) element into a VectorType value.
Base class for instruction visitors.
Definition InstVisitor.h:78
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
bool isTerminator() const
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:338
An instruction for reading from memory.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Value * getPointerOperand()
bool isSimple() const
Align getAlign() const
Return the alignment of the access that is being performed.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
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 ...
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
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
This instruction constructs a fixed permutation of two input vectors.
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
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:299
bool isAggregateType() const
Return true if the type is an aggregate type.
Definition Type.h:314
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:222
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:252
Analysis pass which computes UniformityInfo.
Legacy analysis pass which computes a CycleInfo.
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
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:260
iterator_range< user_iterator > users()
Definition Value.h:428
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:201
const ParentTy * getParent() const
Definition ilist_node.h:34
@ 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)
NodeAddr< PhiNode * > Phi
Definition RDFGraph.h:390
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:577
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:2570
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:649
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
IRBuilder(LLVMContext &, FolderTy, InserterTy) -> IRBuilder< FolderTy, InserterTy >
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
@ Mod
The access may modify the value stored in memory.
Definition ModRef.h:34
DWARFExpression::Operation Op
LLVM_ABI bool isDereferenceableAndAlignedPointer(const Value *V, Type *Ty, Align Alignment, const SimplifyQuery &Q, bool IgnoreFree=false)
Returns true if V is always a dereferenceable pointer with alignment greater or equal than requested.
Definition Loads.cpp:246
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
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:1788
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
FunctionPass * createAMDGPULateCodeGenPrepareLegacyPass()
DenseMap< const Value *, Value * > ValueToValueMap
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
static LLVM_ABI EVT getEVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.