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 (Instruction *UseInst : II->users())
164 UserList.push_back(UseInst);
165
166 auto IsLookThru = [](Instruction *II) {
167 if (const auto *Intr = dyn_cast<IntrinsicInst>(II))
168 return Intr->getIntrinsicID() == Intrinsic::amdgcn_perm;
171 };
172
173 while (!UserList.empty()) {
174 auto CII = UserList.pop_back_val();
175 if (!CVisited.insert(CII).second)
176 continue;
177
178 // Same-BB filter must look at the *user*; and allow non-lookthrough
179 // users when the def is a PHI (loop-header pattern).
180 if (CII->getParent() == II->getParent() && !IsLookThru(CII) &&
182 continue;
183
184 if (isOpLegal(CII))
185 return true;
186
187 if (IsLookThru(CII))
188 for (Instruction *UseInst : CII->users())
189 UserList.push_back(UseInst);
190 }
191 return false;
192 }
193
194 LiveRegOptimizer(Module &Mod, const GCNSubtarget &ST)
195 : Mod(Mod), DL(Mod.getDataLayout()), ST(ST),
196 ConvertToScalar(Type::getInt32Ty(Mod.getContext())) {}
197};
198
199} // end anonymous namespace
200
201bool AMDGPULateCodeGenPrepare::run() {
202 // "Optimize" the virtual regs that cross basic block boundaries. When
203 // building the SelectionDAG, vectors of illegal types that cross basic blocks
204 // will be scalarized and widened, with each scalar living in its
205 // own register. To work around this, this optimization converts the
206 // vectors to equivalent vectors of legal type (which are converted back
207 // before uses in subsequent blocks), to pack the bits into fewer physical
208 // registers (used in CopyToReg/CopyFromReg pairs).
209 LiveRegOptimizer LRO(*F.getParent(), ST);
210
211 bool Changed = false;
212
213 bool HasScalarSubwordLoads = ST.hasScalarSubwordLoads();
214
215 for (auto &BB : reverse(F))
216 for (Instruction &I : make_early_inc_range(reverse(BB))) {
217 Changed |= !HasScalarSubwordLoads && visit(I);
218 Changed |= LRO.optimizeLiveType(&I, DeadInsts);
219 }
220
222 return Changed;
223}
224
225Type *LiveRegOptimizer::calculateConvertType(Type *OriginalType) {
226 assert(OriginalType->getScalarSizeInBits() <=
227 ConvertToScalar->getScalarSizeInBits());
228
229 FixedVectorType *VTy = cast<FixedVectorType>(OriginalType);
230
231 TypeSize OriginalSize = DL.getTypeSizeInBits(VTy);
232 TypeSize ConvertScalarSize = DL.getTypeSizeInBits(ConvertToScalar);
233 unsigned ConvertEltCount =
234 (OriginalSize + ConvertScalarSize - 1) / ConvertScalarSize;
235
236 if (OriginalSize <= ConvertScalarSize)
237 return IntegerType::get(Mod.getContext(), ConvertScalarSize);
238
239 return VectorType::get(Type::getIntNTy(Mod.getContext(), ConvertScalarSize),
240 ConvertEltCount, false);
241}
242
243Value *LiveRegOptimizer::convertToOptType(Instruction *V,
245 FixedVectorType *VTy = cast<FixedVectorType>(V->getType());
246 Type *NewTy = calculateConvertType(V->getType());
247
248 TypeSize OriginalSize = DL.getTypeSizeInBits(VTy);
249 TypeSize NewSize = DL.getTypeSizeInBits(NewTy);
250
251 IRBuilder<> Builder(InsertPt);
252 // If there is a bitsize match, we can fit the old vector into a new vector of
253 // desired type.
254 if (OriginalSize == NewSize)
255 return Builder.CreateBitCast(V, NewTy, V->getName() + ".bc");
256
257 // If there is a bitsize mismatch, we must use a wider vector.
258 assert(NewSize > OriginalSize);
259 uint64_t ExpandedVecElementCount = NewSize / VTy->getScalarSizeInBits();
260
261 SmallVector<int, 8> ShuffleMask;
262 uint64_t OriginalElementCount = VTy->getElementCount().getFixedValue();
263 for (unsigned I = 0; I < OriginalElementCount; I++)
264 ShuffleMask.push_back(I);
265
266 for (uint64_t I = OriginalElementCount; I < ExpandedVecElementCount; I++)
267 ShuffleMask.push_back(OriginalElementCount);
268
269 Value *ExpandedVec = Builder.CreateShuffleVector(V, ShuffleMask);
270 return Builder.CreateBitCast(ExpandedVec, NewTy, V->getName() + ".bc");
271}
272
273Value *LiveRegOptimizer::convertFromOptType(Type *ConvertType, Instruction *V,
275 BasicBlock *InsertBB) {
276 FixedVectorType *NewVTy = cast<FixedVectorType>(ConvertType);
277
278 TypeSize OriginalSize = DL.getTypeSizeInBits(V->getType());
279 TypeSize NewSize = DL.getTypeSizeInBits(NewVTy);
280
281 IRBuilder<> Builder(InsertPt);
282 // If there is a bitsize match, we simply convert back to the original type.
283 if (OriginalSize == NewSize)
284 return Builder.CreateBitCast(V, NewVTy, V->getName() + ".bc");
285
286 // If there is a bitsize mismatch, then we must have used a wider value to
287 // hold the bits.
288 assert(OriginalSize > NewSize);
289 // For wide scalars, we can just truncate the value.
290 if (!V->getType()->isVectorTy()) {
292 Builder.CreateTrunc(V, IntegerType::get(Mod.getContext(), NewSize)));
293 return cast<Instruction>(Builder.CreateBitCast(Trunc, NewVTy));
294 }
295
296 // For wider vectors, we must strip the MSBs to convert back to the original
297 // type.
298 VectorType *ExpandedVT = VectorType::get(
299 Type::getIntNTy(Mod.getContext(), NewVTy->getScalarSizeInBits()),
300 (OriginalSize / NewVTy->getScalarSizeInBits()), false);
301 Instruction *Converted =
302 cast<Instruction>(Builder.CreateBitCast(V, ExpandedVT));
303
304 unsigned NarrowElementCount = NewVTy->getElementCount().getFixedValue();
305 SmallVector<int, 8> ShuffleMask(NarrowElementCount);
306 std::iota(ShuffleMask.begin(), ShuffleMask.end(), 0);
307
308 return Builder.CreateShuffleVector(Converted, ShuffleMask);
309}
310
311bool LiveRegOptimizer::optimizeLiveType(
312 Instruction *I, SmallVectorImpl<WeakTrackingVH> &DeadInsts) {
313 SmallVector<Instruction *, 4> Worklist;
314 SmallPtrSet<PHINode *, 4> PhiNodes;
315 SmallPtrSet<Instruction *, 4> Defs;
316 SmallPtrSet<Instruction *, 4> Uses;
317 SmallPtrSet<Instruction *, 4> Visited;
318
319 Worklist.push_back(cast<Instruction>(I));
320 while (!Worklist.empty()) {
321 Instruction *II = Worklist.pop_back_val();
322
323 if (!Visited.insert(II).second)
324 continue;
325
326 if (!shouldReplace(II->getType()))
327 continue;
328
329 if (!isCoercionProfitable(II))
330 continue;
331
332 if (PHINode *Phi = dyn_cast<PHINode>(II)) {
333 PhiNodes.insert(Phi);
334 // Collect all the incoming values of problematic PHI nodes.
335 for (Value *V : Phi->incoming_values()) {
336 // Repeat the collection process for newly found PHI nodes.
337 if (PHINode *OpPhi = dyn_cast<PHINode>(V)) {
338 if (!PhiNodes.count(OpPhi) && !Visited.count(OpPhi))
339 Worklist.push_back(OpPhi);
340 continue;
341 }
342
344 // Other incoming value types (e.g. vector literals) are unhandled
345 if (!IncInst && !isa<ConstantAggregateZero>(V))
346 return false;
347
348 // Collect all other incoming values for coercion.
349 if (IncInst && !IncInst->isTerminator())
350 Defs.insert(IncInst);
351 }
352 }
353
354 // Collect all relevant uses.
355 for (Instruction *UseInst : II->users()) {
356 // Repeat the collection process for problematic PHI nodes.
357 if (PHINode *OpPhi = dyn_cast<PHINode>(UseInst)) {
358 if (!PhiNodes.count(OpPhi) && !Visited.count(OpPhi))
359 Worklist.push_back(OpPhi);
360 continue;
361 }
362
363 // Collect all uses of PHINodes and any use the crosses BB boundaries.
364 if (UseInst->getParent() != II->getParent() || isa<PHINode>(II)) {
365 Uses.insert(UseInst);
366 if (!isa<PHINode>(II) && !II->isTerminator())
367 Defs.insert(II);
368 }
369 }
370 }
371
372 // Coerce and track the defs.
373 for (Instruction *D : Defs) {
374 if (!ValMap.contains(D)) {
375 BasicBlock::iterator InsertPt = std::next(D->getIterator());
376 Value *ConvertVal = convertToOptType(D, InsertPt);
377 assert(ConvertVal);
378 ValMap[D] = ConvertVal;
379 }
380 }
381
382 // Construct new-typed PHI nodes.
383 for (PHINode *Phi : PhiNodes) {
384 ValMap[Phi] = PHINode::Create(calculateConvertType(Phi->getType()),
385 Phi->getNumIncomingValues(),
386 Phi->getName() + ".tc", Phi->getIterator());
387 }
388
389 // Connect all the PHI nodes with their new incoming values.
390 for (PHINode *Phi : PhiNodes) {
391 PHINode *NewPhi = cast<PHINode>(ValMap[Phi]);
392 bool MissingIncVal = false;
393 for (int I = 0, E = Phi->getNumIncomingValues(); I < E; I++) {
394 Value *IncVal = Phi->getIncomingValue(I);
395 if (isa<ConstantAggregateZero>(IncVal)) {
396 Type *NewType = calculateConvertType(Phi->getType());
397 NewPhi->addIncoming(ConstantInt::get(NewType, 0, false),
398 Phi->getIncomingBlock(I));
399 } else if (Value *Val = ValMap.lookup(IncVal))
400 NewPhi->addIncoming(Val, Phi->getIncomingBlock(I));
401 else
402 MissingIncVal = true;
403 }
404 if (MissingIncVal) {
405 Value *DeadVal = ValMap[Phi];
406 // The coercion chain of the PHI is broken. Delete the Phi
407 // from the ValMap and any connected / user Phis.
408 SmallVector<Value *, 4> PHIWorklist;
409 SmallPtrSet<Value *, 4> VisitedPhis;
410 PHIWorklist.push_back(DeadVal);
411 while (!PHIWorklist.empty()) {
412 Value *NextDeadValue = PHIWorklist.pop_back_val();
413 VisitedPhis.insert(NextDeadValue);
414 auto OriginalPhi =
415 llvm::find_if(PhiNodes, [this, &NextDeadValue](PHINode *CandPhi) {
416 return ValMap[CandPhi] == NextDeadValue;
417 });
418 // This PHI may have already been removed from maps when
419 // unwinding a previous Phi
420 if (OriginalPhi != PhiNodes.end())
421 ValMap.erase(*OriginalPhi);
422
423 for (User *U : NextDeadValue->users()) {
424 if (!VisitedPhis.contains(cast<PHINode>(U)))
425 PHIWorklist.push_back(U);
426 }
427 NextDeadValue->replaceAllUsesWith(
428 PoisonValue::get(NextDeadValue->getType()));
429
430 DeadInsts.emplace_back(cast<Instruction>(NextDeadValue));
431 }
432 } else {
433 DeadInsts.emplace_back(cast<Instruction>(Phi));
434 }
435 }
436 // Coerce back to the original type and replace the uses.
437 for (Instruction *U : Uses) {
438 // Replace all converted operands for a use.
439 for (auto [OpIdx, Op] : enumerate(U->operands())) {
440 if (Value *Val = ValMap.lookup(Op)) {
441 Value *NewVal = nullptr;
442 if (BBUseValMap.contains(U->getParent()) &&
443 BBUseValMap[U->getParent()].contains(Val))
444 NewVal = BBUseValMap[U->getParent()][Val];
445 else {
446 // Not getFirstNonPHIIt, which would insert in front of a landingpad.
447 BasicBlock::iterator InsertPt = U->getParent()->getFirstInsertionPt();
448 // We may pick up ops that were previously converted for users in
449 // other blocks. If there is an originally typed definition of the Op
450 // already in this block, simply reuse it.
452 U->getParent() == cast<Instruction>(Op)->getParent()) {
453 NewVal = Op;
454 } else {
455 NewVal =
456 convertFromOptType(Op->getType(), cast<Instruction>(ValMap[Op]),
457 InsertPt, U->getParent());
458 BBUseValMap[U->getParent()][ValMap[Op]] = NewVal;
459 }
460 }
461 assert(NewVal);
462 U->setOperand(OpIdx, NewVal);
463 }
464 }
465 }
466
467 return true;
468}
469
470bool AMDGPULateCodeGenPrepare::canWidenScalarExtLoad(LoadInst &LI) const {
471 unsigned AS = LI.getPointerAddressSpace();
472 // Skip non-constant address space.
473 if (AS != AMDGPUAS::CONSTANT_ADDRESS &&
475 return false;
476 // Skip non-simple loads.
477 if (!LI.isSimple())
478 return false;
479 Type *Ty = LI.getType();
480 // Skip aggregate types.
481 if (Ty->isAggregateType())
482 return false;
483 unsigned TySize = DL.getTypeStoreSize(Ty);
484 // Only handle sub-DWORD loads.
485 if (TySize >= 4)
486 return false;
487 // That load must be at least naturally aligned.
488 if (LI.getAlign() < DL.getABITypeAlign(Ty))
489 return false;
490 // It should be uniform, i.e. a scalar load.
491 return UA.isUniformAtDef(&LI);
492}
493
494bool AMDGPULateCodeGenPrepare::visitLoadInst(LoadInst &LI) {
495 if (!ST.getCLOpts().late_codegenprepare_widen_constant_loads)
496 return false;
497
498 // Skip if that load is already aligned on DWORD at least as it's handled in
499 // SDAG.
500 if (LI.getAlign() >= 4)
501 return false;
502
503 if (!canWidenScalarExtLoad(LI))
504 return false;
505
506 int64_t Offset = 0;
507 auto *Base =
509
510 int64_t Adjust = Offset & 0x3;
511 int64_t AccessOffset = Offset - Adjust;
512 if (AccessOffset < 0 || !isSafeToWidenLoad(Base, AccessOffset + 4, &LI))
513 return false;
514
515 IRBuilder<> IRB(&LI);
516 IRB.SetCurrentDebugLocation(LI.getDebugLoc());
517
518 unsigned LdBits = DL.getTypeStoreSizeInBits(LI.getType());
519 auto *IntNTy = Type::getIntNTy(LI.getContext(), LdBits);
520
521 auto *NewPtr = IRB.CreateConstGEP1_64(
522 IRB.getInt8Ty(),
523 IRB.CreateAddrSpaceCast(Base, LI.getPointerOperand()->getType()),
524 Offset - Adjust);
525
526 LoadInst *NewLd = IRB.CreateAlignedLoad(IRB.getInt32Ty(), NewPtr, Align(4));
528
529 unsigned ShAmt = Adjust * 8;
530 Value *Shifted = ShAmt ? IRB.CreateLShr(NewLd, ShAmt) : NewLd;
531 Value *NewVal = IRB.CreateBitCast(
532 IRB.CreateTrunc(Shifted, DL.typeSizeEqualsStoreSize(LI.getType())
533 ? IntNTy
534 : LI.getType()),
535 LI.getType());
536 LI.replaceAllUsesWith(NewVal);
537 DeadInsts.emplace_back(&LI);
538
539 return true;
540}
541
542PreservedAnalyses
544 const GCNSubtarget &ST = TM.getSubtarget<GCNSubtarget>(F);
545 AssumptionCache &AC = FAM.getResult<AssumptionAnalysis>(F);
546 UniformityInfo &UI = FAM.getResult<UniformityInfoAnalysis>(F);
547
548 bool Changed = AMDGPULateCodeGenPrepare(F, ST, &AC, UI).run();
549
550 if (!Changed)
551 return PreservedAnalyses::all();
554 return PA;
555}
556
558public:
559 static char ID;
560
562
563 StringRef getPassName() const override {
564 return "AMDGPU IR late optimizations";
565 }
566
567 void getAnalysisUsage(AnalysisUsage &AU) const override {
571 // Invalidates UniformityInfo
572 AU.setPreservesCFG();
573 }
574
575 bool runOnFunction(Function &F) override;
576};
577
579 if (skipFunction(F))
580 return false;
581
583 const TargetMachine &TM = TPC.getTM<TargetMachine>();
584 const GCNSubtarget &ST = TM.getSubtarget<GCNSubtarget>(F);
585
586 AssumptionCache &AC =
587 getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
588 UniformityInfo &UI =
589 getAnalysis<UniformityInfoWrapperPass>().getUniformityInfo();
590
591 return AMDGPULateCodeGenPrepare(F, ST, &AC, UI).run();
592}
593
595 "AMDGPU IR late optimizations", false, false)
600 "AMDGPU IR late optimizations", false, false)
601
603
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo MachineBasicBlock::iterator InsertPt
uint64_t uint64_t
The AMDGPU TargetMachine interface definition for hw codegen targets.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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:61
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:169
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:63
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.
This class represents a freeze function that returns random concrete value if an operand is either a ...
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
iterator_range< user_iterator > users()
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:333
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)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
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:294
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.h:354
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
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
@ 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:2575
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:247
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:538
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.