LLVM 22.0.0git
AMDGPUTargetMachine.cpp
Go to the documentation of this file.
1//===-- AMDGPUTargetMachine.cpp - TargetMachine for hw codegen targets-----===//
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 file contains both AMDGPU target machine and the CodeGen pass builder.
11/// The AMDGPU target machine contains all of the hardware specific information
12/// needed to emit code for SI+ GPUs in the legacy pass manager pipeline. The
13/// CodeGen pass builder handles the pass pipeline for new pass manager.
14//
15//===----------------------------------------------------------------------===//
16
17#include "AMDGPUTargetMachine.h"
18#include "AMDGPU.h"
19#include "AMDGPUAliasAnalysis.h"
23#include "AMDGPUIGroupLP.h"
24#include "AMDGPUISelDAGToDAG.h"
26#include "AMDGPUMacroFusion.h"
33#include "AMDGPUSplitModule.h"
38#include "GCNDPPCombine.h"
40#include "GCNNSAReassign.h"
44#include "GCNSchedStrategy.h"
45#include "GCNVOPDUtils.h"
46#include "R600.h"
47#include "R600TargetMachine.h"
48#include "SIFixSGPRCopies.h"
49#include "SIFixVGPRCopies.h"
50#include "SIFoldOperands.h"
51#include "SIFormMemoryClauses.h"
53#include "SILowerControlFlow.h"
54#include "SILowerSGPRSpills.h"
55#include "SILowerWWMCopies.h"
57#include "SIMachineScheduler.h"
61#include "SIPeepholeSDWA.h"
62#include "SIPostRABundler.h"
65#include "SIWholeQuadMode.h"
85#include "llvm/CodeGen/Passes.h"
89#include "llvm/IR/IntrinsicsAMDGPU.h"
90#include "llvm/IR/PassManager.h"
99#include "llvm/Transforms/IPO.h"
124#include <optional>
125
126using namespace llvm;
127using namespace llvm::PatternMatch;
128
129namespace {
130//===----------------------------------------------------------------------===//
131// AMDGPU CodeGen Pass Builder interface.
132//===----------------------------------------------------------------------===//
133
134class AMDGPUCodeGenPassBuilder
135 : public CodeGenPassBuilder<AMDGPUCodeGenPassBuilder, GCNTargetMachine> {
136 using Base = CodeGenPassBuilder<AMDGPUCodeGenPassBuilder, GCNTargetMachine>;
137
138public:
139 AMDGPUCodeGenPassBuilder(GCNTargetMachine &TM,
140 const CGPassBuilderOption &Opts,
141 PassInstrumentationCallbacks *PIC);
142
143 void addIRPasses(AddIRPass &) const;
144 void addCodeGenPrepare(AddIRPass &) const;
145 void addPreISel(AddIRPass &addPass) const;
146 void addILPOpts(AddMachinePass &) const;
147 void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const;
148 Error addInstSelector(AddMachinePass &) const;
149 void addPreRewrite(AddMachinePass &) const;
150 void addMachineSSAOptimization(AddMachinePass &) const;
151 void addPostRegAlloc(AddMachinePass &) const;
152 void addPreEmitPass(AddMachinePass &) const;
153 void addPreEmitRegAlloc(AddMachinePass &) const;
154 Error addRegAssignmentOptimized(AddMachinePass &) const;
155 void addPreRegAlloc(AddMachinePass &) const;
156 void addOptimizedRegAlloc(AddMachinePass &) const;
157 void addPreSched2(AddMachinePass &) const;
158
159 /// Check if a pass is enabled given \p Opt option. The option always
160 /// overrides defaults if explicitly used. Otherwise its default will be used
161 /// given that a pass shall work at an optimization \p Level minimum.
162 bool isPassEnabled(const cl::opt<bool> &Opt,
163 CodeGenOptLevel Level = CodeGenOptLevel::Default) const;
164 void addEarlyCSEOrGVNPass(AddIRPass &) const;
165 void addStraightLineScalarOptimizationPasses(AddIRPass &) const;
166};
167
168class SGPRRegisterRegAlloc : public RegisterRegAllocBase<SGPRRegisterRegAlloc> {
169public:
170 SGPRRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
171 : RegisterRegAllocBase(N, D, C) {}
172};
173
174class VGPRRegisterRegAlloc : public RegisterRegAllocBase<VGPRRegisterRegAlloc> {
175public:
176 VGPRRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
177 : RegisterRegAllocBase(N, D, C) {}
178};
179
180class WWMRegisterRegAlloc : public RegisterRegAllocBase<WWMRegisterRegAlloc> {
181public:
182 WWMRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
183 : RegisterRegAllocBase(N, D, C) {}
184};
185
186static bool onlyAllocateSGPRs(const TargetRegisterInfo &TRI,
188 const Register Reg) {
189 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
190 return static_cast<const SIRegisterInfo &>(TRI).isSGPRClass(RC);
191}
192
193static bool onlyAllocateVGPRs(const TargetRegisterInfo &TRI,
195 const Register Reg) {
196 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
197 return !static_cast<const SIRegisterInfo &>(TRI).isSGPRClass(RC);
198}
199
200static bool onlyAllocateWWMRegs(const TargetRegisterInfo &TRI,
202 const Register Reg) {
203 const SIMachineFunctionInfo *MFI =
204 MRI.getMF().getInfo<SIMachineFunctionInfo>();
205 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
206 return !static_cast<const SIRegisterInfo &>(TRI).isSGPRClass(RC) &&
208}
209
210/// -{sgpr|wwm|vgpr}-regalloc=... command line option.
211static FunctionPass *useDefaultRegisterAllocator() { return nullptr; }
212
213/// A dummy default pass factory indicates whether the register allocator is
214/// overridden on the command line.
215static llvm::once_flag InitializeDefaultSGPRRegisterAllocatorFlag;
216static llvm::once_flag InitializeDefaultVGPRRegisterAllocatorFlag;
217static llvm::once_flag InitializeDefaultWWMRegisterAllocatorFlag;
218
219static SGPRRegisterRegAlloc
220defaultSGPRRegAlloc("default",
221 "pick SGPR register allocator based on -O option",
223
224static cl::opt<SGPRRegisterRegAlloc::FunctionPassCtor, false,
226SGPRRegAlloc("sgpr-regalloc", cl::Hidden, cl::init(&useDefaultRegisterAllocator),
227 cl::desc("Register allocator to use for SGPRs"));
228
229static cl::opt<VGPRRegisterRegAlloc::FunctionPassCtor, false,
231VGPRRegAlloc("vgpr-regalloc", cl::Hidden, cl::init(&useDefaultRegisterAllocator),
232 cl::desc("Register allocator to use for VGPRs"));
233
234static cl::opt<WWMRegisterRegAlloc::FunctionPassCtor, false,
236 WWMRegAlloc("wwm-regalloc", cl::Hidden,
238 cl::desc("Register allocator to use for WWM registers"));
239
240static void initializeDefaultSGPRRegisterAllocatorOnce() {
241 RegisterRegAlloc::FunctionPassCtor Ctor = SGPRRegisterRegAlloc::getDefault();
242
243 if (!Ctor) {
244 Ctor = SGPRRegAlloc;
245 SGPRRegisterRegAlloc::setDefault(SGPRRegAlloc);
246 }
247}
248
249static void initializeDefaultVGPRRegisterAllocatorOnce() {
250 RegisterRegAlloc::FunctionPassCtor Ctor = VGPRRegisterRegAlloc::getDefault();
251
252 if (!Ctor) {
253 Ctor = VGPRRegAlloc;
254 VGPRRegisterRegAlloc::setDefault(VGPRRegAlloc);
255 }
256}
257
258static void initializeDefaultWWMRegisterAllocatorOnce() {
259 RegisterRegAlloc::FunctionPassCtor Ctor = WWMRegisterRegAlloc::getDefault();
260
261 if (!Ctor) {
262 Ctor = WWMRegAlloc;
263 WWMRegisterRegAlloc::setDefault(WWMRegAlloc);
264 }
265}
266
267static FunctionPass *createBasicSGPRRegisterAllocator() {
268 return createBasicRegisterAllocator(onlyAllocateSGPRs);
269}
270
271static FunctionPass *createGreedySGPRRegisterAllocator() {
272 return createGreedyRegisterAllocator(onlyAllocateSGPRs);
273}
274
275static FunctionPass *createFastSGPRRegisterAllocator() {
276 return createFastRegisterAllocator(onlyAllocateSGPRs, false);
277}
278
279static FunctionPass *createBasicVGPRRegisterAllocator() {
280 return createBasicRegisterAllocator(onlyAllocateVGPRs);
281}
282
283static FunctionPass *createGreedyVGPRRegisterAllocator() {
284 return createGreedyRegisterAllocator(onlyAllocateVGPRs);
285}
286
287static FunctionPass *createFastVGPRRegisterAllocator() {
288 return createFastRegisterAllocator(onlyAllocateVGPRs, true);
289}
290
291static FunctionPass *createBasicWWMRegisterAllocator() {
292 return createBasicRegisterAllocator(onlyAllocateWWMRegs);
293}
294
295static FunctionPass *createGreedyWWMRegisterAllocator() {
296 return createGreedyRegisterAllocator(onlyAllocateWWMRegs);
297}
298
299static FunctionPass *createFastWWMRegisterAllocator() {
300 return createFastRegisterAllocator(onlyAllocateWWMRegs, false);
301}
302
303static SGPRRegisterRegAlloc basicRegAllocSGPR(
304 "basic", "basic register allocator", createBasicSGPRRegisterAllocator);
305static SGPRRegisterRegAlloc greedyRegAllocSGPR(
306 "greedy", "greedy register allocator", createGreedySGPRRegisterAllocator);
307
308static SGPRRegisterRegAlloc fastRegAllocSGPR(
309 "fast", "fast register allocator", createFastSGPRRegisterAllocator);
310
311
312static VGPRRegisterRegAlloc basicRegAllocVGPR(
313 "basic", "basic register allocator", createBasicVGPRRegisterAllocator);
314static VGPRRegisterRegAlloc greedyRegAllocVGPR(
315 "greedy", "greedy register allocator", createGreedyVGPRRegisterAllocator);
316
317static VGPRRegisterRegAlloc fastRegAllocVGPR(
318 "fast", "fast register allocator", createFastVGPRRegisterAllocator);
319static WWMRegisterRegAlloc basicRegAllocWWMReg("basic",
320 "basic register allocator",
321 createBasicWWMRegisterAllocator);
322static WWMRegisterRegAlloc
323 greedyRegAllocWWMReg("greedy", "greedy register allocator",
324 createGreedyWWMRegisterAllocator);
325static WWMRegisterRegAlloc fastRegAllocWWMReg("fast", "fast register allocator",
326 createFastWWMRegisterAllocator);
327
331}
332} // anonymous namespace
333
334static cl::opt<bool>
336 cl::desc("Run early if-conversion"),
337 cl::init(false));
338
339static cl::opt<bool>
340OptExecMaskPreRA("amdgpu-opt-exec-mask-pre-ra", cl::Hidden,
341 cl::desc("Run pre-RA exec mask optimizations"),
342 cl::init(true));
343
344static cl::opt<bool>
345 LowerCtorDtor("amdgpu-lower-global-ctor-dtor",
346 cl::desc("Lower GPU ctor / dtors to globals on the device."),
347 cl::init(true), cl::Hidden);
348
349// Option to disable vectorizer for tests.
351 "amdgpu-load-store-vectorizer",
352 cl::desc("Enable load store vectorizer"),
353 cl::init(true),
354 cl::Hidden);
355
356// Option to control global loads scalarization
358 "amdgpu-scalarize-global-loads",
359 cl::desc("Enable global load scalarization"),
360 cl::init(true),
361 cl::Hidden);
362
363// Option to run internalize pass.
365 "amdgpu-internalize-symbols",
366 cl::desc("Enable elimination of non-kernel functions and unused globals"),
367 cl::init(false),
368 cl::Hidden);
369
370// Option to inline all early.
372 "amdgpu-early-inline-all",
373 cl::desc("Inline all functions early"),
374 cl::init(false),
375 cl::Hidden);
376
378 "amdgpu-enable-remove-incompatible-functions", cl::Hidden,
379 cl::desc("Enable removal of functions when they"
380 "use features not supported by the target GPU"),
381 cl::init(true));
382
384 "amdgpu-sdwa-peephole",
385 cl::desc("Enable SDWA peepholer"),
386 cl::init(true));
387
389 "amdgpu-dpp-combine",
390 cl::desc("Enable DPP combiner"),
391 cl::init(true));
392
393// Enable address space based alias analysis
395 cl::desc("Enable AMDGPU Alias Analysis"),
396 cl::init(true));
397
398// Enable lib calls simplifications
400 "amdgpu-simplify-libcall",
401 cl::desc("Enable amdgpu library simplifications"),
402 cl::init(true),
403 cl::Hidden);
404
406 "amdgpu-ir-lower-kernel-arguments",
407 cl::desc("Lower kernel argument loads in IR pass"),
408 cl::init(true),
409 cl::Hidden);
410
412 "amdgpu-reassign-regs",
413 cl::desc("Enable register reassign optimizations on gfx10+"),
414 cl::init(true),
415 cl::Hidden);
416
418 "amdgpu-opt-vgpr-liverange",
419 cl::desc("Enable VGPR liverange optimizations for if-else structure"),
420 cl::init(true), cl::Hidden);
421
423 "amdgpu-atomic-optimizer-strategy",
424 cl::desc("Select DPP or Iterative strategy for scan"),
427 clEnumValN(ScanOptions::DPP, "DPP", "Use DPP operations for scan"),
429 "Use Iterative approach for scan"),
430 clEnumValN(ScanOptions::None, "None", "Disable atomic optimizer")));
431
432// Enable Mode register optimization
434 "amdgpu-mode-register",
435 cl::desc("Enable mode register pass"),
436 cl::init(true),
437 cl::Hidden);
438
439// Enable GFX11+ s_delay_alu insertion
440static cl::opt<bool>
441 EnableInsertDelayAlu("amdgpu-enable-delay-alu",
442 cl::desc("Enable s_delay_alu insertion"),
443 cl::init(true), cl::Hidden);
444
445// Enable GFX11+ VOPD
446static cl::opt<bool>
447 EnableVOPD("amdgpu-enable-vopd",
448 cl::desc("Enable VOPD, dual issue of VALU in wave32"),
449 cl::init(true), cl::Hidden);
450
451// Option is used in lit tests to prevent deadcoding of patterns inspected.
452static cl::opt<bool>
453EnableDCEInRA("amdgpu-dce-in-ra",
454 cl::init(true), cl::Hidden,
455 cl::desc("Enable machine DCE inside regalloc"));
456
457static cl::opt<bool> EnableSetWavePriority("amdgpu-set-wave-priority",
458 cl::desc("Adjust wave priority"),
459 cl::init(false), cl::Hidden);
460
462 "amdgpu-scalar-ir-passes",
463 cl::desc("Enable scalar IR passes"),
464 cl::init(true),
465 cl::Hidden);
466
467static cl::opt<bool>
468 EnableSwLowerLDS("amdgpu-enable-sw-lower-lds",
469 cl::desc("Enable lowering of lds to global memory pass "
470 "and asan instrument resulting IR."),
471 cl::init(true), cl::Hidden);
472
474 "amdgpu-enable-lower-module-lds", cl::desc("Enable lower module lds pass"),
476 cl::Hidden);
477
479 "amdgpu-enable-pre-ra-optimizations",
480 cl::desc("Enable Pre-RA optimizations pass"), cl::init(true),
481 cl::Hidden);
482
484 "amdgpu-enable-promote-kernel-arguments",
485 cl::desc("Enable promotion of flat kernel pointer arguments to global"),
486 cl::Hidden, cl::init(true));
487
489 "amdgpu-enable-image-intrinsic-optimizer",
490 cl::desc("Enable image intrinsic optimizer pass"), cl::init(true),
491 cl::Hidden);
492
493static cl::opt<bool>
494 EnableLoopPrefetch("amdgpu-loop-prefetch",
495 cl::desc("Enable loop data prefetch on AMDGPU"),
496 cl::Hidden, cl::init(false));
497
499 AMDGPUSchedStrategy("amdgpu-sched-strategy",
500 cl::desc("Select custom AMDGPU scheduling strategy."),
501 cl::Hidden, cl::init(""));
502
504 "amdgpu-enable-rewrite-partial-reg-uses",
505 cl::desc("Enable rewrite partial reg uses pass"), cl::init(true),
506 cl::Hidden);
507
509 "amdgpu-enable-hipstdpar",
510 cl::desc("Enable HIP Standard Parallelism Offload support"), cl::init(false),
511 cl::Hidden);
512
513static cl::opt<bool>
514 EnableAMDGPUAttributor("amdgpu-attributor-enable",
515 cl::desc("Enable AMDGPUAttributorPass"),
516 cl::init(true), cl::Hidden);
517
519 "new-reg-bank-select",
520 cl::desc("Run amdgpu-regbankselect and amdgpu-regbanklegalize instead of "
521 "regbankselect"),
522 cl::init(false), cl::Hidden);
523
525 "amdgpu-link-time-closed-world",
526 cl::desc("Whether has closed-world assumption at link time"),
527 cl::init(false), cl::Hidden);
528
530 // Register the target
533
616}
617
618static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
619 return std::make_unique<AMDGPUTargetObjectFile>();
620}
621
625
626static ScheduleDAGInstrs *
628 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
629 ScheduleDAGMILive *DAG =
630 new GCNScheduleDAGMILive(C, std::make_unique<GCNMaxOccupancySchedStrategy>(C));
631 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
632 if (ST.shouldClusterStores())
633 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
635 DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
636 DAG->addMutation(createAMDGPUExportClusteringDAGMutation());
637 return DAG;
638}
639
640static ScheduleDAGInstrs *
642 ScheduleDAGMILive *DAG =
643 new GCNScheduleDAGMILive(C, std::make_unique<GCNMaxILPSchedStrategy>(C));
645 return DAG;
646}
647
648static ScheduleDAGInstrs *
650 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
652 C, std::make_unique<GCNMaxMemoryClauseSchedStrategy>(C));
653 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
654 if (ST.shouldClusterStores())
655 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
656 DAG->addMutation(createAMDGPUExportClusteringDAGMutation());
657 return DAG;
658}
659
660static ScheduleDAGInstrs *
662 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
663 auto *DAG = new GCNIterativeScheduler(
665 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
666 if (ST.shouldClusterStores())
667 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
669 return DAG;
670}
671
678
679static ScheduleDAGInstrs *
681 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
683 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
684 if (ST.shouldClusterStores())
685 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
686 DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
688 return DAG;
689}
690
692SISchedRegistry("si", "Run SI's custom scheduler",
694
697 "Run GCN scheduler to maximize occupancy",
699
701 GCNMaxILPSchedRegistry("gcn-max-ilp", "Run GCN scheduler to maximize ilp",
703
705 "gcn-max-memory-clause", "Run GCN scheduler to maximize memory clause",
707
709 "gcn-iterative-max-occupancy-experimental",
710 "Run GCN scheduler to maximize occupancy (experimental)",
712
714 "gcn-iterative-minreg",
715 "Run GCN iterative scheduler for minimal register usage (experimental)",
717
719 "gcn-iterative-ilp",
720 "Run GCN iterative scheduler for ILP scheduling (experimental)",
722
725 if (!GPU.empty())
726 return GPU;
727
728 // Need to default to a target with flat support for HSA.
729 if (TT.isAMDGCN())
730 return TT.getOS() == Triple::AMDHSA ? "generic-hsa" : "generic";
731
732 return "r600";
733}
734
735static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {
736 // The AMDGPU toolchain only supports generating shared objects, so we
737 // must always use PIC.
738 return Reloc::PIC_;
739}
740
742 StringRef CPU, StringRef FS,
743 const TargetOptions &Options,
744 std::optional<Reloc::Model> RM,
745 std::optional<CodeModel::Model> CM,
748 T, TT.computeDataLayout(), TT, getGPUOrDefault(TT, CPU), FS, Options,
752 initAsmInfo();
753 if (TT.isAMDGCN()) {
754 if (getMCSubtargetInfo()->checkFeatures("+wavefrontsize64"))
756 else if (getMCSubtargetInfo()->checkFeatures("+wavefrontsize32"))
758 }
759}
760
763
765
767 Attribute GPUAttr = F.getFnAttribute("target-cpu");
768 return GPUAttr.isValid() ? GPUAttr.getValueAsString() : getTargetCPU();
769}
770
772 Attribute FSAttr = F.getFnAttribute("target-features");
773
774 return FSAttr.isValid() ? FSAttr.getValueAsString()
776}
777
780 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
782 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
783 if (ST.shouldClusterStores())
784 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
785 return DAG;
786}
787
788/// Predicate for Internalize pass.
789static bool mustPreserveGV(const GlobalValue &GV) {
790 if (const Function *F = dyn_cast<Function>(&GV))
791 return F->isDeclaration() || F->getName().starts_with("__asan_") ||
792 F->getName().starts_with("__sanitizer_") ||
793 AMDGPU::isEntryFunctionCC(F->getCallingConv());
794
796 return !GV.use_empty();
797}
798
802
805 if (Params.empty())
807 Params.consume_front("strategy=");
808 auto Result = StringSwitch<std::optional<ScanOptions>>(Params)
809 .Case("dpp", ScanOptions::DPP)
810 .Cases("iterative", "", ScanOptions::Iterative)
811 .Case("none", ScanOptions::None)
812 .Default(std::nullopt);
813 if (Result)
814 return *Result;
815 return make_error<StringError>("invalid parameter", inconvertibleErrorCode());
816}
817
821 while (!Params.empty()) {
822 StringRef ParamName;
823 std::tie(ParamName, Params) = Params.split(';');
824 if (ParamName == "closed-world") {
825 Result.IsClosedWorld = true;
826 } else {
828 formatv("invalid AMDGPUAttributor pass parameter '{0}' ", ParamName)
829 .str(),
831 }
832 }
833 return Result;
834}
835
837
838#define GET_PASS_REGISTRY "AMDGPUPassRegistry.def"
840
841 PB.registerScalarOptimizerLateEPCallback(
842 [](FunctionPassManager &FPM, OptimizationLevel Level) {
843 if (Level == OptimizationLevel::O0)
844 return;
845
847 });
848
849 PB.registerVectorizerEndEPCallback(
850 [](FunctionPassManager &FPM, OptimizationLevel Level) {
851 if (Level == OptimizationLevel::O0)
852 return;
853
855 });
856
857 PB.registerPipelineEarlySimplificationEPCallback(
860 if (!isLTOPreLink(Phase)) {
861 // When we are not using -fgpu-rdc, we can run accelerator code
862 // selection relatively early, but still after linking to prevent
863 // eager removal of potentially reachable symbols.
864 if (EnableHipStdPar) {
867 }
869 }
870
871 if (Level == OptimizationLevel::O0)
872 return;
873
874 // We don't want to run internalization at per-module stage.
878 }
879
882 });
883
884 PB.registerPeepholeEPCallback(
885 [](FunctionPassManager &FPM, OptimizationLevel Level) {
886 if (Level == OptimizationLevel::O0)
887 return;
888
892 });
893
894 PB.registerCGSCCOptimizerLateEPCallback(
895 [this](CGSCCPassManager &PM, OptimizationLevel Level) {
896 if (Level == OptimizationLevel::O0)
897 return;
898
900
901 // Add promote kernel arguments pass to the opt pipeline right before
902 // infer address spaces which is needed to do actual address space
903 // rewriting.
904 if (Level.getSpeedupLevel() > OptimizationLevel::O1.getSpeedupLevel() &&
907
908 // Add infer address spaces pass to the opt pipeline after inlining
909 // but before SROA to increase SROA opportunities.
911
912 // This should run after inlining to have any chance of doing
913 // anything, and before other cleanup optimizations.
915
916 if (Level != OptimizationLevel::O0) {
917 // Promote alloca to vector before SROA and loop unroll. If we
918 // manage to eliminate allocas before unroll we may choose to unroll
919 // less.
921 }
922
923 PM.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
924 });
925
926 // FIXME: Why is AMDGPUAttributor not in CGSCC?
927 PB.registerOptimizerLastEPCallback([this](ModulePassManager &MPM,
928 OptimizationLevel Level,
930 if (Level != OptimizationLevel::O0) {
931 if (!isLTOPreLink(Phase)) {
933 MPM.addPass(AMDGPUAttributorPass(*this, Opts, Phase));
934 }
935 }
936 });
937
938 PB.registerFullLinkTimeOptimizationLastEPCallback(
939 [this](ModulePassManager &PM, OptimizationLevel Level) {
940 // When we are using -fgpu-rdc, we can only run accelerator code
941 // selection after linking to prevent, otherwise we end up removing
942 // potentially reachable symbols that were exported as external in other
943 // modules.
944 if (EnableHipStdPar) {
947 }
948 // We want to support the -lto-partitions=N option as "best effort".
949 // For that, we need to lower LDS earlier in the pipeline before the
950 // module is partitioned for codegen.
952 PM.addPass(AMDGPUSwLowerLDSPass(*this));
955 if (Level != OptimizationLevel::O0) {
956 // We only want to run this with O2 or higher since inliner and SROA
957 // don't run in O1.
958 if (Level != OptimizationLevel::O1) {
959 PM.addPass(
961 }
962 // Do we really need internalization in LTO?
963 if (InternalizeSymbols) {
966 }
970 Opt.IsClosedWorld = true;
973 }
974 }
975 if (!NoKernelInfoEndLTO) {
977 FPM.addPass(KernelInfoPrinter(this));
978 PM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
979 }
980 });
981
982 PB.registerRegClassFilterParsingCallback(
983 [](StringRef FilterName) -> RegAllocFilterFunc {
984 if (FilterName == "sgpr")
985 return onlyAllocateSGPRs;
986 if (FilterName == "vgpr")
987 return onlyAllocateVGPRs;
988 if (FilterName == "wwm")
989 return onlyAllocateWWMRegs;
990 return nullptr;
991 });
992}
993
994int64_t AMDGPUTargetMachine::getNullPointerValue(unsigned AddrSpace) {
995 return (AddrSpace == AMDGPUAS::LOCAL_ADDRESS ||
996 AddrSpace == AMDGPUAS::PRIVATE_ADDRESS ||
997 AddrSpace == AMDGPUAS::REGION_ADDRESS)
998 ? -1
999 : 0;
1000}
1001
1003 unsigned DestAS) const {
1004 return AMDGPU::isFlatGlobalAddrSpace(SrcAS) &&
1006}
1007
1009 if (auto *Arg = dyn_cast<Argument>(V);
1010 Arg &&
1011 AMDGPU::isModuleEntryFunctionCC(Arg->getParent()->getCallingConv()) &&
1012 !Arg->hasByRefAttr())
1014
1015 const auto *LD = dyn_cast<LoadInst>(V);
1016 if (!LD) // TODO: Handle invariant load like constant.
1018
1019 // It must be a generic pointer loaded.
1020 assert(V->getType()->getPointerAddressSpace() == AMDGPUAS::FLAT_ADDRESS);
1021
1022 const auto *Ptr = LD->getPointerOperand();
1023 if (Ptr->getType()->getPointerAddressSpace() != AMDGPUAS::CONSTANT_ADDRESS)
1025 // For a generic pointer loaded from the constant memory, it could be assumed
1026 // as a global pointer since the constant memory is only populated on the
1027 // host side. As implied by the offload programming model, only global
1028 // pointers could be referenced on the host side.
1030}
1031
1032std::pair<const Value *, unsigned>
1034 if (auto *II = dyn_cast<IntrinsicInst>(V)) {
1035 switch (II->getIntrinsicID()) {
1036 case Intrinsic::amdgcn_is_shared:
1037 return std::pair(II->getArgOperand(0), AMDGPUAS::LOCAL_ADDRESS);
1038 case Intrinsic::amdgcn_is_private:
1039 return std::pair(II->getArgOperand(0), AMDGPUAS::PRIVATE_ADDRESS);
1040 default:
1041 break;
1042 }
1043 return std::pair(nullptr, -1);
1044 }
1045 // Check the global pointer predication based on
1046 // (!is_share(p) && !is_private(p)). Note that logic 'and' is commutative and
1047 // the order of 'is_shared' and 'is_private' is not significant.
1048 Value *Ptr;
1049 if (match(
1050 const_cast<Value *>(V),
1053 m_Deferred(Ptr))))))
1054 return std::pair(Ptr, AMDGPUAS::GLOBAL_ADDRESS);
1055
1056 return std::pair(nullptr, -1);
1057}
1058
1059unsigned
1074
1076 Module &M, unsigned NumParts,
1077 function_ref<void(std::unique_ptr<Module> MPart)> ModuleCallback) {
1078 // FIXME(?): Would be better to use an already existing Analysis/PassManager,
1079 // but all current users of this API don't have one ready and would need to
1080 // create one anyway. Let's hide the boilerplate for now to keep it simple.
1081
1086
1087 PassBuilder PB(this);
1088 PB.registerModuleAnalyses(MAM);
1089 PB.registerFunctionAnalyses(FAM);
1090 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
1091
1093 MPM.addPass(AMDGPUSplitModulePass(NumParts, ModuleCallback));
1094 MPM.run(M, MAM);
1095 return true;
1096}
1097
1098//===----------------------------------------------------------------------===//
1099// GCN Target Machine (SI+)
1100//===----------------------------------------------------------------------===//
1101
1103 StringRef CPU, StringRef FS,
1104 const TargetOptions &Options,
1105 std::optional<Reloc::Model> RM,
1106 std::optional<CodeModel::Model> CM,
1107 CodeGenOptLevel OL, bool JIT)
1108 : AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {}
1109
1110const TargetSubtargetInfo *
1112 StringRef GPU = getGPUName(F);
1114
1115 SmallString<128> SubtargetKey(GPU);
1116 SubtargetKey.append(FS);
1117
1118 auto &I = SubtargetMap[SubtargetKey];
1119 if (!I) {
1120 // This needs to be done before we create a new subtarget since any
1121 // creation will depend on the TM and the code generation flags on the
1122 // function that reside in TargetOptions.
1124 I = std::make_unique<GCNSubtarget>(TargetTriple, GPU, FS, *this);
1125 }
1126
1127 I->setScalarizeGlobalBehavior(ScalarizeGlobal);
1128
1129 return I.get();
1130}
1131
1134 return TargetTransformInfo(std::make_unique<GCNTTIImpl>(this, F));
1135}
1136
1139 CodeGenFileType FileType, const CGPassBuilderOption &Opts,
1141 AMDGPUCodeGenPassBuilder CGPB(*this, Opts, PIC);
1142 return CGPB.buildPipeline(MPM, Out, DwoOut, FileType);
1143}
1144
1147 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
1148 if (ST.enableSIScheduler())
1150
1151 Attribute SchedStrategyAttr =
1152 C->MF->getFunction().getFnAttribute("amdgpu-sched-strategy");
1153 StringRef SchedStrategy = SchedStrategyAttr.isValid()
1154 ? SchedStrategyAttr.getValueAsString()
1156
1157 if (SchedStrategy == "max-ilp")
1159
1160 if (SchedStrategy == "max-memory-clause")
1162
1163 if (SchedStrategy == "iterative-ilp")
1165
1166 if (SchedStrategy == "iterative-minreg")
1167 return createMinRegScheduler(C);
1168
1169 if (SchedStrategy == "iterative-maxocc")
1171
1173}
1174
1177 ScheduleDAGMI *DAG =
1178 new GCNPostScheduleDAGMILive(C, std::make_unique<PostGenericScheduler>(C),
1179 /*RemoveKillFlags=*/true);
1180 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
1182 if (ST.shouldClusterStores())
1185 if ((EnableVOPD.getNumOccurrences() ||
1187 EnableVOPD)
1190 return DAG;
1191}
1192//===----------------------------------------------------------------------===//
1193// AMDGPU Legacy Pass Setup
1194//===----------------------------------------------------------------------===//
1195
1196std::unique_ptr<CSEConfigBase> llvm::AMDGPUPassConfig::getCSEConfig() const {
1197 return getStandardCSEConfigForOpt(TM->getOptLevel());
1198}
1199
1200namespace {
1201
1202class GCNPassConfig final : public AMDGPUPassConfig {
1203public:
1204 GCNPassConfig(TargetMachine &TM, PassManagerBase &PM)
1205 : AMDGPUPassConfig(TM, PM) {
1206 // It is necessary to know the register usage of the entire call graph. We
1207 // allow calls without EnableAMDGPUFunctionCalls if they are marked
1208 // noinline, so this is always required.
1209 setRequiresCodeGenSCCOrder(true);
1210 substitutePass(&PostRASchedulerID, &PostMachineSchedulerID);
1211 }
1212
1213 GCNTargetMachine &getGCNTargetMachine() const {
1214 return getTM<GCNTargetMachine>();
1215 }
1216
1217 bool addPreISel() override;
1218 void addMachineSSAOptimization() override;
1219 bool addILPOpts() override;
1220 bool addInstSelector() override;
1221 bool addIRTranslator() override;
1222 void addPreLegalizeMachineIR() override;
1223 bool addLegalizeMachineIR() override;
1224 void addPreRegBankSelect() override;
1225 bool addRegBankSelect() override;
1226 void addPreGlobalInstructionSelect() override;
1227 bool addGlobalInstructionSelect() override;
1228 void addPreRegAlloc() override;
1229 void addFastRegAlloc() override;
1230 void addOptimizedRegAlloc() override;
1231
1232 FunctionPass *createSGPRAllocPass(bool Optimized);
1233 FunctionPass *createVGPRAllocPass(bool Optimized);
1234 FunctionPass *createWWMRegAllocPass(bool Optimized);
1235 FunctionPass *createRegAllocPass(bool Optimized) override;
1236
1237 bool addRegAssignAndRewriteFast() override;
1238 bool addRegAssignAndRewriteOptimized() override;
1239
1240 bool addPreRewrite() override;
1241 void addPostRegAlloc() override;
1242 void addPreSched2() override;
1243 void addPreEmitPass() override;
1244 void addPostBBSections() override;
1245};
1246
1247} // end anonymous namespace
1248
1250 : TargetPassConfig(TM, PM) {
1251 // Exceptions and StackMaps are not supported, so these passes will never do
1252 // anything.
1255 // Garbage collection is not supported.
1258}
1259
1266
1271 // ReassociateGEPs exposes more opportunities for SLSR. See
1272 // the example in reassociate-geps-and-slsr.ll.
1274 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
1275 // EarlyCSE can reuse.
1277 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
1279 // NaryReassociate on GEPs creates redundant common expressions, so run
1280 // EarlyCSE after it.
1282}
1283
1286
1287 if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN())
1289
1290 // There is no reason to run these.
1294
1296 if (LowerCtorDtor)
1298
1301
1302 // This can be disabled by passing ::Disable here or on the command line
1303 // with --expand-variadics-override=disable.
1305
1306 // Function calls are not supported, so make sure we inline everything.
1309
1310 // Handle uses of OpenCL image2d_t, image3d_t and sampler_t arguments.
1311 if (TM.getTargetTriple().getArch() == Triple::r600)
1313
1314 // Make enqueued block runtime handles externally visible.
1316
1317 // Lower LDS accesses to global memory pass if address sanitizer is enabled.
1318 if (EnableSwLowerLDS)
1320
1321 // Runs before PromoteAlloca so the latter can account for function uses
1324 }
1325
1326 // Run atomic optimizer before Atomic Expand
1327 if ((TM.getTargetTriple().isAMDGCN()) &&
1328 (TM.getOptLevel() >= CodeGenOptLevel::Less) &&
1331 }
1332
1334
1335 if (TM.getOptLevel() > CodeGenOptLevel::None) {
1337
1340
1344 AAResults &AAR) {
1345 if (auto *WrapperPass = P.getAnalysisIfAvailable<AMDGPUAAWrapperPass>())
1346 AAR.addAAResult(WrapperPass->getResult());
1347 }));
1348 }
1349
1350 if (TM.getTargetTriple().isAMDGCN()) {
1351 // TODO: May want to move later or split into an early and late one.
1353 }
1354
1355 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
1356 // have expanded.
1357 if (TM.getOptLevel() > CodeGenOptLevel::Less)
1359 }
1360
1362
1363 // EarlyCSE is not always strong enough to clean up what LSR produces. For
1364 // example, GVN can combine
1365 //
1366 // %0 = add %a, %b
1367 // %1 = add %b, %a
1368 //
1369 // and
1370 //
1371 // %0 = shl nsw %a, 2
1372 // %1 = shl %a, 2
1373 //
1374 // but EarlyCSE can do neither of them.
1377}
1378
1380 if (TM->getTargetTriple().isAMDGCN() &&
1381 TM->getOptLevel() > CodeGenOptLevel::None)
1383
1384 if (TM->getTargetTriple().isAMDGCN() && EnableLowerKernelArguments)
1386
1388
1391
1392 if (TM->getTargetTriple().isAMDGCN()) {
1393 // This lowering has been placed after codegenprepare to take advantage of
1394 // address mode matching (which is why it isn't put with the LDS lowerings).
1395 // It could be placed anywhere before uniformity annotations (an analysis
1396 // that it changes by splitting up fat pointers into their components)
1397 // but has been put before switch lowering and CFG flattening so that those
1398 // passes can run on the more optimized control flow this pass creates in
1399 // many cases.
1402 // In accordance with the above FIXME, manually force all the
1403 // function-level passes into a CGSCCPassManager.
1404 addPass(new DummyCGSCCPass());
1405 }
1406
1407 // LowerSwitch pass may introduce unreachable blocks that can
1408 // cause unexpected behavior for subsequent passes. Placing it
1409 // here seems better that these blocks would get cleaned up by
1410 // UnreachableBlockElim inserted next in the pass flow.
1412}
1413
1415 if (TM->getOptLevel() > CodeGenOptLevel::None)
1417 return false;
1418}
1419
1424
1426 // Do nothing. GC is not supported.
1427 return false;
1428}
1429
1430//===----------------------------------------------------------------------===//
1431// GCN Legacy Pass Setup
1432//===----------------------------------------------------------------------===//
1433
1434bool GCNPassConfig::addPreISel() {
1436
1437 if (TM->getOptLevel() > CodeGenOptLevel::None)
1438 addPass(createSinkingPass());
1439
1440 if (TM->getOptLevel() > CodeGenOptLevel::None)
1442
1443 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
1444 // regions formed by them.
1446 addPass(createFixIrreduciblePass());
1447 addPass(createUnifyLoopExitsPass());
1448 addPass(createStructurizeCFGPass(false)); // true -> SkipUniformRegions
1449
1452 // TODO: Move this right after structurizeCFG to avoid extra divergence
1453 // analysis. This depends on stopping SIAnnotateControlFlow from making
1454 // control flow modifications.
1456
1457 // SDAG requires LCSSA, GlobalISel does not. Disable LCSSA for -global-isel
1458 // with -new-reg-bank-select and without any of the fallback options.
1460 !isGlobalISelAbortEnabled() || !NewRegBankSelect)
1461 addPass(createLCSSAPass());
1462
1463 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1465
1466 return false;
1467}
1468
1469void GCNPassConfig::addMachineSSAOptimization() {
1471
1472 // We want to fold operands after PeepholeOptimizer has run (or as part of
1473 // it), because it will eliminate extra copies making it easier to fold the
1474 // real source operand. We want to eliminate dead instructions after, so that
1475 // we see fewer uses of the copies. We then need to clean up the dead
1476 // instructions leftover after the operands are folded as well.
1477 //
1478 // XXX - Can we get away without running DeadMachineInstructionElim again?
1479 addPass(&SIFoldOperandsLegacyID);
1480 if (EnableDPPCombine)
1481 addPass(&GCNDPPCombineLegacyID);
1483 if (isPassEnabled(EnableSDWAPeephole)) {
1484 addPass(&SIPeepholeSDWALegacyID);
1485 addPass(&EarlyMachineLICMID);
1486 addPass(&MachineCSELegacyID);
1487 addPass(&SIFoldOperandsLegacyID);
1488 }
1491}
1492
1493bool GCNPassConfig::addILPOpts() {
1495 addPass(&EarlyIfConverterLegacyID);
1496
1498 return false;
1499}
1500
1501bool GCNPassConfig::addInstSelector() {
1503 addPass(&SIFixSGPRCopiesLegacyID);
1505 return false;
1506}
1507
1508bool GCNPassConfig::addIRTranslator() {
1509 addPass(new IRTranslator(getOptLevel()));
1510 return false;
1511}
1512
1513void GCNPassConfig::addPreLegalizeMachineIR() {
1514 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1515 addPass(createAMDGPUPreLegalizeCombiner(IsOptNone));
1516 addPass(new Localizer());
1517}
1518
1519bool GCNPassConfig::addLegalizeMachineIR() {
1520 addPass(new Legalizer());
1521 return false;
1522}
1523
1524void GCNPassConfig::addPreRegBankSelect() {
1525 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1526 addPass(createAMDGPUPostLegalizeCombiner(IsOptNone));
1528}
1529
1530bool GCNPassConfig::addRegBankSelect() {
1531 if (NewRegBankSelect) {
1534 } else {
1535 addPass(new RegBankSelect());
1536 }
1537 return false;
1538}
1539
1540void GCNPassConfig::addPreGlobalInstructionSelect() {
1541 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1542 addPass(createAMDGPURegBankCombiner(IsOptNone));
1543}
1544
1545bool GCNPassConfig::addGlobalInstructionSelect() {
1546 addPass(new InstructionSelect(getOptLevel()));
1547 return false;
1548}
1549
1550void GCNPassConfig::addFastRegAlloc() {
1551 // FIXME: We have to disable the verifier here because of PHIElimination +
1552 // TwoAddressInstructions disabling it.
1553
1554 // This must be run immediately after phi elimination and before
1555 // TwoAddressInstructions, otherwise the processing of the tied operand of
1556 // SI_ELSE will introduce a copy of the tied operand source after the else.
1558
1560
1562}
1563
1564void GCNPassConfig::addPreRegAlloc() {
1565 if (getOptLevel() != CodeGenOptLevel::None)
1567}
1568
1569void GCNPassConfig::addOptimizedRegAlloc() {
1570 if (EnableDCEInRA)
1572
1573 // FIXME: when an instruction has a Killed operand, and the instruction is
1574 // inside a bundle, seems only the BUNDLE instruction appears as the Kills of
1575 // the register in LiveVariables, this would trigger a failure in verifier,
1576 // we should fix it and enable the verifier.
1577 if (OptVGPRLiveRange)
1579
1580 // This must be run immediately after phi elimination and before
1581 // TwoAddressInstructions, otherwise the processing of the tied operand of
1582 // SI_ELSE will introduce a copy of the tied operand source after the else.
1584
1587
1588 if (isPassEnabled(EnablePreRAOptimizations))
1590
1591 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
1592 // instructions that cause scheduling barriers.
1594
1595 if (OptExecMaskPreRA)
1597
1598 // This is not an essential optimization and it has a noticeable impact on
1599 // compilation time, so we only enable it from O2.
1600 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1602
1604}
1605
1606bool GCNPassConfig::addPreRewrite() {
1608 addPass(&GCNNSAReassignID);
1609
1611 return true;
1612}
1613
1614FunctionPass *GCNPassConfig::createSGPRAllocPass(bool Optimized) {
1615 // Initialize the global default.
1616 llvm::call_once(InitializeDefaultSGPRRegisterAllocatorFlag,
1617 initializeDefaultSGPRRegisterAllocatorOnce);
1618
1619 RegisterRegAlloc::FunctionPassCtor Ctor = SGPRRegisterRegAlloc::getDefault();
1620 if (Ctor != useDefaultRegisterAllocator)
1621 return Ctor();
1622
1623 if (Optimized)
1624 return createGreedyRegisterAllocator(onlyAllocateSGPRs);
1625
1626 return createFastRegisterAllocator(onlyAllocateSGPRs, false);
1627}
1628
1629FunctionPass *GCNPassConfig::createVGPRAllocPass(bool Optimized) {
1630 // Initialize the global default.
1631 llvm::call_once(InitializeDefaultVGPRRegisterAllocatorFlag,
1632 initializeDefaultVGPRRegisterAllocatorOnce);
1633
1634 RegisterRegAlloc::FunctionPassCtor Ctor = VGPRRegisterRegAlloc::getDefault();
1635 if (Ctor != useDefaultRegisterAllocator)
1636 return Ctor();
1637
1638 if (Optimized)
1639 return createGreedyVGPRRegisterAllocator();
1640
1641 return createFastVGPRRegisterAllocator();
1642}
1643
1644FunctionPass *GCNPassConfig::createWWMRegAllocPass(bool Optimized) {
1645 // Initialize the global default.
1646 llvm::call_once(InitializeDefaultWWMRegisterAllocatorFlag,
1647 initializeDefaultWWMRegisterAllocatorOnce);
1648
1649 RegisterRegAlloc::FunctionPassCtor Ctor = WWMRegisterRegAlloc::getDefault();
1650 if (Ctor != useDefaultRegisterAllocator)
1651 return Ctor();
1652
1653 if (Optimized)
1654 return createGreedyWWMRegisterAllocator();
1655
1656 return createFastWWMRegisterAllocator();
1657}
1658
1659FunctionPass *GCNPassConfig::createRegAllocPass(bool Optimized) {
1660 llvm_unreachable("should not be used");
1661}
1662
1664 "-regalloc not supported with amdgcn. Use -sgpr-regalloc, -wwm-regalloc, "
1665 "and -vgpr-regalloc";
1666
1667bool GCNPassConfig::addRegAssignAndRewriteFast() {
1668 if (!usingDefaultRegAlloc())
1670
1671 addPass(&GCNPreRALongBranchRegID);
1672
1673 addPass(createSGPRAllocPass(false));
1674
1675 // Equivalent of PEI for SGPRs.
1676 addPass(&SILowerSGPRSpillsLegacyID);
1677
1678 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1680
1681 // For allocating other wwm register operands.
1682 addPass(createWWMRegAllocPass(false));
1683
1684 addPass(&SILowerWWMCopiesLegacyID);
1686
1687 // For allocating per-thread VGPRs.
1688 addPass(createVGPRAllocPass(false));
1689
1690 return true;
1691}
1692
1693bool GCNPassConfig::addRegAssignAndRewriteOptimized() {
1694 if (!usingDefaultRegAlloc())
1696
1697 addPass(&GCNPreRALongBranchRegID);
1698
1699 addPass(createSGPRAllocPass(true));
1700
1701 // Commit allocated register changes. This is mostly necessary because too
1702 // many things rely on the use lists of the physical registers, such as the
1703 // verifier. This is only necessary with allocators which use LiveIntervals,
1704 // since FastRegAlloc does the replacements itself.
1705 addPass(createVirtRegRewriter(false));
1706
1707 // At this point, the sgpr-regalloc has been done and it is good to have the
1708 // stack slot coloring to try to optimize the SGPR spill stack indices before
1709 // attempting the custom SGPR spill lowering.
1710 addPass(&StackSlotColoringID);
1711
1712 // Equivalent of PEI for SGPRs.
1713 addPass(&SILowerSGPRSpillsLegacyID);
1714
1715 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1717
1718 // For allocating other whole wave mode registers.
1719 addPass(createWWMRegAllocPass(true));
1720 addPass(&SILowerWWMCopiesLegacyID);
1721 addPass(createVirtRegRewriter(false));
1723
1724 // For allocating per-thread VGPRs.
1725 addPass(createVGPRAllocPass(true));
1726
1727 addPreRewrite();
1728 addPass(&VirtRegRewriterID);
1729
1731
1732 return true;
1733}
1734
1735void GCNPassConfig::addPostRegAlloc() {
1736 addPass(&SIFixVGPRCopiesID);
1737 if (getOptLevel() > CodeGenOptLevel::None)
1740}
1741
1742void GCNPassConfig::addPreSched2() {
1743 if (TM->getOptLevel() > CodeGenOptLevel::None)
1745 addPass(&SIPostRABundlerLegacyID);
1746}
1747
1748void GCNPassConfig::addPreEmitPass() {
1749 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less))
1750 addPass(&GCNCreateVOPDID);
1751 addPass(createSIMemoryLegalizerPass());
1752 addPass(createSIInsertWaitcntsPass());
1753
1754 addPass(createSIModeRegisterPass());
1755
1756 if (getOptLevel() > CodeGenOptLevel::None)
1757 addPass(&SIInsertHardClausesID);
1758
1760 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
1762 if (getOptLevel() > CodeGenOptLevel::None)
1763 addPass(&SIPreEmitPeepholeID);
1764 // The hazard recognizer that runs as part of the post-ra scheduler does not
1765 // guarantee to be able handle all hazards correctly. This is because if there
1766 // are multiple scheduling regions in a basic block, the regions are scheduled
1767 // bottom up, so when we begin to schedule a region we don't know what
1768 // instructions were emitted directly before it.
1769 //
1770 // Here we add a stand-alone hazard recognizer pass which can handle all
1771 // cases.
1772 addPass(&PostRAHazardRecognizerID);
1773
1775
1777
1778 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less))
1779 addPass(&AMDGPUInsertDelayAluID);
1780
1781 addPass(&BranchRelaxationPassID);
1782}
1783
1784void GCNPassConfig::addPostBBSections() {
1785 // We run this later to avoid passes like livedebugvalues and BBSections
1786 // having to deal with the apparent multi-entry functions we may generate.
1788}
1789
1791 return new GCNPassConfig(*this, PM);
1792}
1793
1799
1806
1810
1817
1820 SMDiagnostic &Error, SMRange &SourceRange) const {
1821 const yaml::SIMachineFunctionInfo &YamlMFI =
1822 static_cast<const yaml::SIMachineFunctionInfo &>(MFI_);
1823 MachineFunction &MF = PFS.MF;
1825 const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
1826
1827 if (MFI->initializeBaseYamlFields(YamlMFI, MF, PFS, Error, SourceRange))
1828 return true;
1829
1830 if (MFI->Occupancy == 0) {
1831 // Fixup the subtarget dependent default value.
1832 MFI->Occupancy = ST.getOccupancyWithWorkGroupSizes(MF).second;
1833 }
1834
1835 auto parseRegister = [&](const yaml::StringValue &RegName, Register &RegVal) {
1836 Register TempReg;
1837 if (parseNamedRegisterReference(PFS, TempReg, RegName.Value, Error)) {
1838 SourceRange = RegName.SourceRange;
1839 return true;
1840 }
1841 RegVal = TempReg;
1842
1843 return false;
1844 };
1845
1846 auto parseOptionalRegister = [&](const yaml::StringValue &RegName,
1847 Register &RegVal) {
1848 return !RegName.Value.empty() && parseRegister(RegName, RegVal);
1849 };
1850
1851 if (parseOptionalRegister(YamlMFI.VGPRForAGPRCopy, MFI->VGPRForAGPRCopy))
1852 return true;
1853
1854 if (parseOptionalRegister(YamlMFI.SGPRForEXECCopy, MFI->SGPRForEXECCopy))
1855 return true;
1856
1857 if (parseOptionalRegister(YamlMFI.LongBranchReservedReg,
1858 MFI->LongBranchReservedReg))
1859 return true;
1860
1861 auto diagnoseRegisterClass = [&](const yaml::StringValue &RegName) {
1862 // Create a diagnostic for a the register string literal.
1863 const MemoryBuffer &Buffer =
1864 *PFS.SM->getMemoryBuffer(PFS.SM->getMainFileID());
1865 Error = SMDiagnostic(*PFS.SM, SMLoc(), Buffer.getBufferIdentifier(), 1,
1866 RegName.Value.size(), SourceMgr::DK_Error,
1867 "incorrect register class for field", RegName.Value,
1868 {}, {});
1869 SourceRange = RegName.SourceRange;
1870 return true;
1871 };
1872
1873 if (parseRegister(YamlMFI.ScratchRSrcReg, MFI->ScratchRSrcReg) ||
1874 parseRegister(YamlMFI.FrameOffsetReg, MFI->FrameOffsetReg) ||
1875 parseRegister(YamlMFI.StackPtrOffsetReg, MFI->StackPtrOffsetReg))
1876 return true;
1877
1878 if (MFI->ScratchRSrcReg != AMDGPU::PRIVATE_RSRC_REG &&
1879 !AMDGPU::SGPR_128RegClass.contains(MFI->ScratchRSrcReg)) {
1880 return diagnoseRegisterClass(YamlMFI.ScratchRSrcReg);
1881 }
1882
1883 if (MFI->FrameOffsetReg != AMDGPU::FP_REG &&
1884 !AMDGPU::SGPR_32RegClass.contains(MFI->FrameOffsetReg)) {
1885 return diagnoseRegisterClass(YamlMFI.FrameOffsetReg);
1886 }
1887
1888 if (MFI->StackPtrOffsetReg != AMDGPU::SP_REG &&
1889 !AMDGPU::SGPR_32RegClass.contains(MFI->StackPtrOffsetReg)) {
1890 return diagnoseRegisterClass(YamlMFI.StackPtrOffsetReg);
1891 }
1892
1893 for (const auto &YamlReg : YamlMFI.WWMReservedRegs) {
1894 Register ParsedReg;
1895 if (parseRegister(YamlReg, ParsedReg))
1896 return true;
1897
1898 MFI->reserveWWMRegister(ParsedReg);
1899 }
1900
1901 for (const auto &[_, Info] : PFS.VRegInfosNamed) {
1902 MFI->setFlag(Info->VReg, Info->Flags);
1903 }
1904 for (const auto &[_, Info] : PFS.VRegInfos) {
1905 MFI->setFlag(Info->VReg, Info->Flags);
1906 }
1907
1908 for (const auto &YamlRegStr : YamlMFI.SpillPhysVGPRS) {
1909 Register ParsedReg;
1910 if (parseRegister(YamlRegStr, ParsedReg))
1911 return true;
1912 MFI->SpillPhysVGPRs.push_back(ParsedReg);
1913 }
1914
1915 auto parseAndCheckArgument = [&](const std::optional<yaml::SIArgument> &A,
1916 const TargetRegisterClass &RC,
1917 ArgDescriptor &Arg, unsigned UserSGPRs,
1918 unsigned SystemSGPRs) {
1919 // Skip parsing if it's not present.
1920 if (!A)
1921 return false;
1922
1923 if (A->IsRegister) {
1924 Register Reg;
1925 if (parseNamedRegisterReference(PFS, Reg, A->RegisterName.Value, Error)) {
1926 SourceRange = A->RegisterName.SourceRange;
1927 return true;
1928 }
1929 if (!RC.contains(Reg))
1930 return diagnoseRegisterClass(A->RegisterName);
1932 } else
1933 Arg = ArgDescriptor::createStack(A->StackOffset);
1934 // Check and apply the optional mask.
1935 if (A->Mask)
1936 Arg = ArgDescriptor::createArg(Arg, *A->Mask);
1937
1938 MFI->NumUserSGPRs += UserSGPRs;
1939 MFI->NumSystemSGPRs += SystemSGPRs;
1940 return false;
1941 };
1942
1943 if (YamlMFI.ArgInfo &&
1944 (parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentBuffer,
1945 AMDGPU::SGPR_128RegClass,
1946 MFI->ArgInfo.PrivateSegmentBuffer, 4, 0) ||
1947 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchPtr,
1948 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchPtr,
1949 2, 0) ||
1950 parseAndCheckArgument(YamlMFI.ArgInfo->QueuePtr, AMDGPU::SReg_64RegClass,
1951 MFI->ArgInfo.QueuePtr, 2, 0) ||
1952 parseAndCheckArgument(YamlMFI.ArgInfo->KernargSegmentPtr,
1953 AMDGPU::SReg_64RegClass,
1954 MFI->ArgInfo.KernargSegmentPtr, 2, 0) ||
1955 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchID,
1956 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchID,
1957 2, 0) ||
1958 parseAndCheckArgument(YamlMFI.ArgInfo->FlatScratchInit,
1959 AMDGPU::SReg_64RegClass,
1960 MFI->ArgInfo.FlatScratchInit, 2, 0) ||
1961 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentSize,
1962 AMDGPU::SGPR_32RegClass,
1963 MFI->ArgInfo.PrivateSegmentSize, 0, 0) ||
1964 parseAndCheckArgument(YamlMFI.ArgInfo->LDSKernelId,
1965 AMDGPU::SGPR_32RegClass,
1966 MFI->ArgInfo.LDSKernelId, 0, 1) ||
1967 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDX,
1968 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDX,
1969 0, 1) ||
1970 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDY,
1971 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDY,
1972 0, 1) ||
1973 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDZ,
1974 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDZ,
1975 0, 1) ||
1976 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupInfo,
1977 AMDGPU::SGPR_32RegClass,
1978 MFI->ArgInfo.WorkGroupInfo, 0, 1) ||
1979 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentWaveByteOffset,
1980 AMDGPU::SGPR_32RegClass,
1981 MFI->ArgInfo.PrivateSegmentWaveByteOffset, 0, 1) ||
1982 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitArgPtr,
1983 AMDGPU::SReg_64RegClass,
1984 MFI->ArgInfo.ImplicitArgPtr, 0, 0) ||
1985 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitBufferPtr,
1986 AMDGPU::SReg_64RegClass,
1987 MFI->ArgInfo.ImplicitBufferPtr, 2, 0) ||
1988 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDX,
1989 AMDGPU::VGPR_32RegClass,
1990 MFI->ArgInfo.WorkItemIDX, 0, 0) ||
1991 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDY,
1992 AMDGPU::VGPR_32RegClass,
1993 MFI->ArgInfo.WorkItemIDY, 0, 0) ||
1994 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDZ,
1995 AMDGPU::VGPR_32RegClass,
1996 MFI->ArgInfo.WorkItemIDZ, 0, 0)))
1997 return true;
1998
1999 if (ST.hasIEEEMode())
2000 MFI->Mode.IEEE = YamlMFI.Mode.IEEE;
2001 if (ST.hasDX10ClampMode())
2002 MFI->Mode.DX10Clamp = YamlMFI.Mode.DX10Clamp;
2003
2004 // FIXME: Move proper support for denormal-fp-math into base MachineFunction
2005 MFI->Mode.FP32Denormals.Input = YamlMFI.Mode.FP32InputDenormals
2008 MFI->Mode.FP32Denormals.Output = YamlMFI.Mode.FP32OutputDenormals
2011
2018
2019 if (YamlMFI.HasInitWholeWave)
2020 MFI->setInitWholeWave();
2021
2022 return false;
2023}
2024
2025//===----------------------------------------------------------------------===//
2026// AMDGPU CodeGen Pass Builder interface.
2027//===----------------------------------------------------------------------===//
2028
2029AMDGPUCodeGenPassBuilder::AMDGPUCodeGenPassBuilder(
2030 GCNTargetMachine &TM, const CGPassBuilderOption &Opts,
2032 : CodeGenPassBuilder(TM, Opts, PIC) {
2033 Opt.MISchedPostRA = true;
2034 Opt.RequiresCodeGenSCCOrder = true;
2035 // Exceptions and StackMaps are not supported, so these passes will never do
2036 // anything.
2037 // Garbage collection is not supported.
2038 disablePass<StackMapLivenessPass, FuncletLayoutPass,
2040}
2041
2042void AMDGPUCodeGenPassBuilder::addIRPasses(AddIRPass &addPass) const {
2043 if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN())
2045
2047 if (LowerCtorDtor)
2048 addPass(AMDGPUCtorDtorLoweringPass());
2049
2050 if (isPassEnabled(EnableImageIntrinsicOptimizer))
2052
2053 // This can be disabled by passing ::Disable here or on the command line
2054 // with --expand-variadics-override=disable.
2056
2057 addPass(AMDGPUAlwaysInlinePass());
2058 addPass(AlwaysInlinerPass());
2059
2061
2062 if (EnableSwLowerLDS)
2063 addPass(AMDGPUSwLowerLDSPass(TM));
2064
2065 // Runs before PromoteAlloca so the latter can account for function uses
2067 addPass(AMDGPULowerModuleLDSPass(TM));
2068
2069 // Run atomic optimizer before Atomic Expand
2070 if (TM.getOptLevel() >= CodeGenOptLevel::Less &&
2073
2074 addPass(AtomicExpandPass(&TM));
2075
2076 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2077 addPass(AMDGPUPromoteAllocaPass(TM));
2078 if (isPassEnabled(EnableScalarIRPasses))
2079 addStraightLineScalarOptimizationPasses(addPass);
2080
2081 // TODO: Handle EnableAMDGPUAliasAnalysis
2082
2083 // TODO: May want to move later or split into an early and late one.
2084 addPass(AMDGPUCodeGenPreparePass(TM));
2085
2086 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
2087 // have expanded.
2088 if (TM.getOptLevel() > CodeGenOptLevel::Less) {
2090 /*UseMemorySSA=*/true));
2091 }
2092 }
2093
2094 Base::addIRPasses(addPass);
2095
2096 // EarlyCSE is not always strong enough to clean up what LSR produces. For
2097 // example, GVN can combine
2098 //
2099 // %0 = add %a, %b
2100 // %1 = add %b, %a
2101 //
2102 // and
2103 //
2104 // %0 = shl nsw %a, 2
2105 // %1 = shl %a, 2
2106 //
2107 // but EarlyCSE can do neither of them.
2108 if (isPassEnabled(EnableScalarIRPasses))
2109 addEarlyCSEOrGVNPass(addPass);
2110}
2111
2112void AMDGPUCodeGenPassBuilder::addCodeGenPrepare(AddIRPass &addPass) const {
2113 if (TM.getOptLevel() > CodeGenOptLevel::None)
2115
2117 addPass(AMDGPULowerKernelArgumentsPass(TM));
2118
2119 Base::addCodeGenPrepare(addPass);
2120
2121 if (isPassEnabled(EnableLoadStoreVectorizer))
2122 addPass(LoadStoreVectorizerPass());
2123
2124 // This lowering has been placed after codegenprepare to take advantage of
2125 // address mode matching (which is why it isn't put with the LDS lowerings).
2126 // It could be placed anywhere before uniformity annotations (an analysis
2127 // that it changes by splitting up fat pointers into their components)
2128 // but has been put before switch lowering and CFG flattening so that those
2129 // passes can run on the more optimized control flow this pass creates in
2130 // many cases.
2132 addPass.requireCGSCCOrder();
2133
2134 addPass(AMDGPULowerIntrinsicsPass(TM));
2135
2136 // LowerSwitch pass may introduce unreachable blocks that can cause unexpected
2137 // behavior for subsequent passes. Placing it here seems better that these
2138 // blocks would get cleaned up by UnreachableBlockElim inserted next in the
2139 // pass flow.
2140 addPass(LowerSwitchPass());
2141}
2142
2143void AMDGPUCodeGenPassBuilder::addPreISel(AddIRPass &addPass) const {
2144
2145 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2146 addPass(FlattenCFGPass());
2147 addPass(SinkingPass());
2148 addPass(AMDGPULateCodeGenPreparePass(TM));
2149 }
2150
2151 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
2152 // regions formed by them.
2153
2155 addPass(FixIrreduciblePass());
2156 addPass(UnifyLoopExitsPass());
2157 addPass(StructurizeCFGPass(/*SkipUniformRegions=*/false));
2158
2160
2161 addPass(SIAnnotateControlFlowPass(TM));
2162
2163 // TODO: Move this right after structurizeCFG to avoid extra divergence
2164 // analysis. This depends on stopping SIAnnotateControlFlow from making
2165 // control flow modifications.
2167
2169 !isGlobalISelAbortEnabled() || !NewRegBankSelect)
2170 addPass(LCSSAPass());
2171
2172 if (TM.getOptLevel() > CodeGenOptLevel::Less)
2173 addPass(AMDGPUPerfHintAnalysisPass(TM));
2174
2175 // FIXME: Why isn't this queried as required from AMDGPUISelDAGToDAG, and why
2176 // isn't this in addInstSelector?
2178 /*Force=*/true);
2179}
2180
2181void AMDGPUCodeGenPassBuilder::addILPOpts(AddMachinePass &addPass) const {
2183 addPass(EarlyIfConverterPass());
2184
2185 Base::addILPOpts(addPass);
2186}
2187
2188void AMDGPUCodeGenPassBuilder::addAsmPrinter(AddMachinePass &addPass,
2189 CreateMCStreamer) const {
2190 // TODO: Add AsmPrinter.
2191}
2192
2193Error AMDGPUCodeGenPassBuilder::addInstSelector(AddMachinePass &addPass) const {
2194 addPass(AMDGPUISelDAGToDAGPass(TM));
2195 addPass(SIFixSGPRCopiesPass());
2196 addPass(SILowerI1CopiesPass());
2197 return Error::success();
2198}
2199
2200void AMDGPUCodeGenPassBuilder::addPreRewrite(AddMachinePass &addPass) const {
2201 if (EnableRegReassign) {
2202 addPass(GCNNSAReassignPass());
2203 }
2204}
2205
2206void AMDGPUCodeGenPassBuilder::addMachineSSAOptimization(
2207 AddMachinePass &addPass) const {
2208 Base::addMachineSSAOptimization(addPass);
2209
2210 addPass(SIFoldOperandsPass());
2211 if (EnableDPPCombine) {
2212 addPass(GCNDPPCombinePass());
2213 }
2214 addPass(SILoadStoreOptimizerPass());
2215 if (isPassEnabled(EnableSDWAPeephole)) {
2216 addPass(SIPeepholeSDWAPass());
2217 addPass(EarlyMachineLICMPass());
2218 addPass(MachineCSEPass());
2219 addPass(SIFoldOperandsPass());
2220 }
2222 addPass(SIShrinkInstructionsPass());
2223}
2224
2225void AMDGPUCodeGenPassBuilder::addOptimizedRegAlloc(
2226 AddMachinePass &addPass) const {
2227 if (EnableDCEInRA)
2228 insertPass<DetectDeadLanesPass>(DeadMachineInstructionElimPass());
2229
2230 // FIXME: when an instruction has a Killed operand, and the instruction is
2231 // inside a bundle, seems only the BUNDLE instruction appears as the Kills of
2232 // the register in LiveVariables, this would trigger a failure in verifier,
2233 // we should fix it and enable the verifier.
2234 if (OptVGPRLiveRange)
2235 insertPass<RequireAnalysisPass<LiveVariablesAnalysis, MachineFunction>>(
2237
2238 // This must be run immediately after phi elimination and before
2239 // TwoAddressInstructions, otherwise the processing of the tied operand of
2240 // SI_ELSE will introduce a copy of the tied operand source after the else.
2241 insertPass<PHIEliminationPass>(SILowerControlFlowPass());
2242
2244 insertPass<RenameIndependentSubregsPass>(GCNRewritePartialRegUsesPass());
2245
2246 if (isPassEnabled(EnablePreRAOptimizations))
2247 insertPass<MachineSchedulerPass>(GCNPreRAOptimizationsPass());
2248
2249 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
2250 // instructions that cause scheduling barriers.
2251 insertPass<MachineSchedulerPass>(SIWholeQuadModePass());
2252
2253 if (OptExecMaskPreRA)
2254 insertPass<MachineSchedulerPass>(SIOptimizeExecMaskingPreRAPass());
2255
2256 // This is not an essential optimization and it has a noticeable impact on
2257 // compilation time, so we only enable it from O2.
2258 if (TM.getOptLevel() > CodeGenOptLevel::Less)
2259 insertPass<MachineSchedulerPass>(SIFormMemoryClausesPass());
2260
2261 Base::addOptimizedRegAlloc(addPass);
2262}
2263
2264void AMDGPUCodeGenPassBuilder::addPreRegAlloc(AddMachinePass &addPass) const {
2265 if (getOptLevel() != CodeGenOptLevel::None)
2266 addPass(AMDGPUPrepareAGPRAllocPass());
2267}
2268
2269Error AMDGPUCodeGenPassBuilder::addRegAssignmentOptimized(
2270 AddMachinePass &addPass) const {
2271 // TODO: Check --regalloc-npm option
2272
2273 addPass(GCNPreRALongBranchRegPass());
2274
2275 addPass(RAGreedyPass({onlyAllocateSGPRs, "sgpr"}));
2276
2277 // Commit allocated register changes. This is mostly necessary because too
2278 // many things rely on the use lists of the physical registers, such as the
2279 // verifier. This is only necessary with allocators which use LiveIntervals,
2280 // since FastRegAlloc does the replacements itself.
2281 addPass(VirtRegRewriterPass(false));
2282
2283 // At this point, the sgpr-regalloc has been done and it is good to have the
2284 // stack slot coloring to try to optimize the SGPR spill stack indices before
2285 // attempting the custom SGPR spill lowering.
2286 addPass(StackSlotColoringPass());
2287
2288 // Equivalent of PEI for SGPRs.
2289 addPass(SILowerSGPRSpillsPass());
2290
2291 // To Allocate wwm registers used in whole quad mode operations (for shaders).
2292 addPass(SIPreAllocateWWMRegsPass());
2293
2294 // For allocating other wwm register operands.
2295 addPass(RAGreedyPass({onlyAllocateWWMRegs, "wwm"}));
2296 addPass(SILowerWWMCopiesPass());
2297 addPass(VirtRegRewriterPass(false));
2298 addPass(AMDGPUReserveWWMRegsPass());
2299
2300 // For allocating per-thread VGPRs.
2301 addPass(RAGreedyPass({onlyAllocateVGPRs, "vgpr"}));
2302
2303
2304 addPreRewrite(addPass);
2305 addPass(VirtRegRewriterPass(true));
2306
2308 return Error::success();
2309}
2310
2311void AMDGPUCodeGenPassBuilder::addPostRegAlloc(AddMachinePass &addPass) const {
2312 addPass(SIFixVGPRCopiesPass());
2313 if (TM.getOptLevel() > CodeGenOptLevel::None)
2314 addPass(SIOptimizeExecMaskingPass());
2315 Base::addPostRegAlloc(addPass);
2316}
2317
2318void AMDGPUCodeGenPassBuilder::addPreSched2(AddMachinePass &addPass) const {
2319 if (TM.getOptLevel() > CodeGenOptLevel::None)
2320 addPass(SIShrinkInstructionsPass());
2321 addPass(SIPostRABundlerPass());
2322}
2323
2324void AMDGPUCodeGenPassBuilder::addPreEmitPass(AddMachinePass &addPass) const {
2325 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less)) {
2326 addPass(GCNCreateVOPDPass());
2327 }
2328
2329 addPass(SIMemoryLegalizerPass());
2330 addPass(SIInsertWaitcntsPass());
2331
2332 // TODO: addPass(SIModeRegisterPass());
2333
2334 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2335 // TODO: addPass(SIInsertHardClausesPass());
2336 }
2337
2338 addPass(SILateBranchLoweringPass());
2339
2340 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
2341 addPass(AMDGPUSetWavePriorityPass());
2342
2343 if (TM.getOptLevel() > CodeGenOptLevel::None)
2344 addPass(SIPreEmitPeepholePass());
2345
2346 // The hazard recognizer that runs as part of the post-ra scheduler does not
2347 // guarantee to be able handle all hazards correctly. This is because if there
2348 // are multiple scheduling regions in a basic block, the regions are scheduled
2349 // bottom up, so when we begin to schedule a region we don't know what
2350 // instructions were emitted directly before it.
2351 //
2352 // Here we add a stand-alone hazard recognizer pass which can handle all
2353 // cases.
2354 addPass(PostRAHazardRecognizerPass());
2355 addPass(AMDGPUWaitSGPRHazardsPass());
2356 addPass(AMDGPULowerVGPREncodingPass());
2357
2358 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less)) {
2359 addPass(AMDGPUInsertDelayAluPass());
2360 }
2361
2362 addPass(BranchRelaxationPass());
2363}
2364
2365bool AMDGPUCodeGenPassBuilder::isPassEnabled(const cl::opt<bool> &Opt,
2366 CodeGenOptLevel Level) const {
2367 if (Opt.getNumOccurrences())
2368 return Opt;
2369 if (TM.getOptLevel() < Level)
2370 return false;
2371 return Opt;
2372}
2373
2374void AMDGPUCodeGenPassBuilder::addEarlyCSEOrGVNPass(AddIRPass &addPass) const {
2375 if (TM.getOptLevel() == CodeGenOptLevel::Aggressive)
2376 addPass(GVNPass());
2377 else
2378 addPass(EarlyCSEPass());
2379}
2380
2381void AMDGPUCodeGenPassBuilder::addStraightLineScalarOptimizationPasses(
2382 AddIRPass &addPass) const {
2384 addPass(LoopDataPrefetchPass());
2385
2387
2388 // ReassociateGEPs exposes more opportunities for SLSR. See
2389 // the example in reassociate-geps-and-slsr.ll.
2391
2392 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
2393 // EarlyCSE can reuse.
2394 addEarlyCSEOrGVNPass(addPass);
2395
2396 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
2397 addPass(NaryReassociatePass());
2398
2399 // NaryReassociate on GEPs creates redundant common expressions, so run
2400 // EarlyCSE after it.
2401 addPass(EarlyCSEPass());
2402}
unsigned const MachineRegisterInfo * MRI
aarch64 falkor hwpf fix Falkor HW Prefetch Fix Late Phase
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static cl::opt< bool > EnableEarlyIfConversion("aarch64-enable-early-ifcvt", cl::Hidden, cl::desc("Run early if-conversion"), cl::init(true))
static std::unique_ptr< TargetLoweringObjectFile > createTLOF(const Triple &TT)
This is the AMGPU address space based alias analysis pass.
Defines an instruction selector for the AMDGPU target.
Analyzes if a function potentially memory bound and if a kernel kernel may benefit from limiting numb...
Analyzes how many registers and other resources are used by functions.
static cl::opt< bool > EnableDCEInRA("amdgpu-dce-in-ra", cl::init(true), cl::Hidden, cl::desc("Enable machine DCE inside regalloc"))
static cl::opt< bool, true > EnableLowerModuleLDS("amdgpu-enable-lower-module-lds", cl::desc("Enable lower module lds pass"), cl::location(AMDGPUTargetMachine::EnableLowerModuleLDS), cl::init(true), cl::Hidden)
static MachineSchedRegistry GCNMaxMemoryClauseSchedRegistry("gcn-max-memory-clause", "Run GCN scheduler to maximize memory clause", createGCNMaxMemoryClauseMachineScheduler)
static MachineSchedRegistry SISchedRegistry("si", "Run SI's custom scheduler", createSIMachineScheduler)
static ScheduleDAGInstrs * createIterativeILPMachineScheduler(MachineSchedContext *C)
static cl::opt< bool > EarlyInlineAll("amdgpu-early-inline-all", cl::desc("Inline all functions early"), cl::init(false), cl::Hidden)
static cl::opt< bool > EnableSwLowerLDS("amdgpu-enable-sw-lower-lds", cl::desc("Enable lowering of lds to global memory pass " "and asan instrument resulting IR."), cl::init(true), cl::Hidden)
static cl::opt< bool > EnableLowerKernelArguments("amdgpu-ir-lower-kernel-arguments", cl::desc("Lower kernel argument loads in IR pass"), cl::init(true), cl::Hidden)
static ScheduleDAGInstrs * createGCNMaxILPMachineScheduler(MachineSchedContext *C)
static cl::opt< bool > EnableSDWAPeephole("amdgpu-sdwa-peephole", cl::desc("Enable SDWA peepholer"), cl::init(true))
static MachineSchedRegistry GCNMinRegSchedRegistry("gcn-iterative-minreg", "Run GCN iterative scheduler for minimal register usage (experimental)", createMinRegScheduler)
static cl::opt< bool > EnableImageIntrinsicOptimizer("amdgpu-enable-image-intrinsic-optimizer", cl::desc("Enable image intrinsic optimizer pass"), cl::init(true), cl::Hidden)
static cl::opt< bool > HasClosedWorldAssumption("amdgpu-link-time-closed-world", cl::desc("Whether has closed-world assumption at link time"), cl::init(false), cl::Hidden)
static ScheduleDAGInstrs * createGCNMaxMemoryClauseMachineScheduler(MachineSchedContext *C)
static cl::opt< bool > EnableSIModeRegisterPass("amdgpu-mode-register", cl::desc("Enable mode register pass"), cl::init(true), cl::Hidden)
static cl::opt< std::string > AMDGPUSchedStrategy("amdgpu-sched-strategy", cl::desc("Select custom AMDGPU scheduling strategy."), cl::Hidden, cl::init(""))
static cl::opt< bool > EnableDPPCombine("amdgpu-dpp-combine", cl::desc("Enable DPP combiner"), cl::init(true))
static MachineSchedRegistry IterativeGCNMaxOccupancySchedRegistry("gcn-iterative-max-occupancy-experimental", "Run GCN scheduler to maximize occupancy (experimental)", createIterativeGCNMaxOccupancyMachineScheduler)
static cl::opt< bool > EnableSetWavePriority("amdgpu-set-wave-priority", cl::desc("Adjust wave priority"), cl::init(false), cl::Hidden)
static cl::opt< bool > LowerCtorDtor("amdgpu-lower-global-ctor-dtor", cl::desc("Lower GPU ctor / dtors to globals on the device."), cl::init(true), cl::Hidden)
static cl::opt< bool > OptExecMaskPreRA("amdgpu-opt-exec-mask-pre-ra", cl::Hidden, cl::desc("Run pre-RA exec mask optimizations"), cl::init(true))
static cl::opt< bool > EnablePromoteKernelArguments("amdgpu-enable-promote-kernel-arguments", cl::desc("Enable promotion of flat kernel pointer arguments to global"), cl::Hidden, cl::init(true))
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget()
static cl::opt< bool > EnableRewritePartialRegUses("amdgpu-enable-rewrite-partial-reg-uses", cl::desc("Enable rewrite partial reg uses pass"), cl::init(true), cl::Hidden)
static cl::opt< bool > EnableLibCallSimplify("amdgpu-simplify-libcall", cl::desc("Enable amdgpu library simplifications"), cl::init(true), cl::Hidden)
static MachineSchedRegistry GCNMaxILPSchedRegistry("gcn-max-ilp", "Run GCN scheduler to maximize ilp", createGCNMaxILPMachineScheduler)
static cl::opt< bool > InternalizeSymbols("amdgpu-internalize-symbols", cl::desc("Enable elimination of non-kernel functions and unused globals"), cl::init(false), cl::Hidden)
static cl::opt< bool > EnableAMDGPUAttributor("amdgpu-attributor-enable", cl::desc("Enable AMDGPUAttributorPass"), cl::init(true), cl::Hidden)
static LLVM_READNONE StringRef getGPUOrDefault(const Triple &TT, StringRef GPU)
static Reloc::Model getEffectiveRelocModel(std::optional< Reloc::Model > RM)
Expected< AMDGPUAttributorOptions > parseAMDGPUAttributorPassOptions(StringRef Params)
static cl::opt< bool > EnableAMDGPUAliasAnalysis("enable-amdgpu-aa", cl::Hidden, cl::desc("Enable AMDGPU Alias Analysis"), cl::init(true))
static Expected< ScanOptions > parseAMDGPUAtomicOptimizerStrategy(StringRef Params)
static ScheduleDAGInstrs * createMinRegScheduler(MachineSchedContext *C)
static cl::opt< bool > EnableHipStdPar("amdgpu-enable-hipstdpar", cl::desc("Enable HIP Standard Parallelism Offload support"), cl::init(false), cl::Hidden)
static cl::opt< bool > EnableInsertDelayAlu("amdgpu-enable-delay-alu", cl::desc("Enable s_delay_alu insertion"), cl::init(true), cl::Hidden)
static ScheduleDAGInstrs * createIterativeGCNMaxOccupancyMachineScheduler(MachineSchedContext *C)
static cl::opt< bool > EnableLoadStoreVectorizer("amdgpu-load-store-vectorizer", cl::desc("Enable load store vectorizer"), cl::init(true), cl::Hidden)
static bool mustPreserveGV(const GlobalValue &GV)
Predicate for Internalize pass.
static cl::opt< bool > EnableLoopPrefetch("amdgpu-loop-prefetch", cl::desc("Enable loop data prefetch on AMDGPU"), cl::Hidden, cl::init(false))
static cl::opt< bool > NewRegBankSelect("new-reg-bank-select", cl::desc("Run amdgpu-regbankselect and amdgpu-regbanklegalize instead of " "regbankselect"), cl::init(false), cl::Hidden)
static cl::opt< bool > RemoveIncompatibleFunctions("amdgpu-enable-remove-incompatible-functions", cl::Hidden, cl::desc("Enable removal of functions when they" "use features not supported by the target GPU"), cl::init(true))
static cl::opt< bool > EnableScalarIRPasses("amdgpu-scalar-ir-passes", cl::desc("Enable scalar IR passes"), cl::init(true), cl::Hidden)
static cl::opt< bool > EnableRegReassign("amdgpu-reassign-regs", cl::desc("Enable register reassign optimizations on gfx10+"), cl::init(true), cl::Hidden)
static cl::opt< bool > OptVGPRLiveRange("amdgpu-opt-vgpr-liverange", cl::desc("Enable VGPR liverange optimizations for if-else structure"), cl::init(true), cl::Hidden)
static ScheduleDAGInstrs * createSIMachineScheduler(MachineSchedContext *C)
static cl::opt< bool > EnablePreRAOptimizations("amdgpu-enable-pre-ra-optimizations", cl::desc("Enable Pre-RA optimizations pass"), cl::init(true), cl::Hidden)
static cl::opt< ScanOptions > AMDGPUAtomicOptimizerStrategy("amdgpu-atomic-optimizer-strategy", cl::desc("Select DPP or Iterative strategy for scan"), cl::init(ScanOptions::Iterative), cl::values(clEnumValN(ScanOptions::DPP, "DPP", "Use DPP operations for scan"), clEnumValN(ScanOptions::Iterative, "Iterative", "Use Iterative approach for scan"), clEnumValN(ScanOptions::None, "None", "Disable atomic optimizer")))
static cl::opt< bool > EnableVOPD("amdgpu-enable-vopd", cl::desc("Enable VOPD, dual issue of VALU in wave32"), cl::init(true), cl::Hidden)
static cl::opt< bool > EnableEarlyIfConversion("amdgpu-early-ifcvt", cl::Hidden, cl::desc("Run early if-conversion"), cl::init(false))
static ScheduleDAGInstrs * createGCNMaxOccupancyMachineScheduler(MachineSchedContext *C)
static MachineSchedRegistry GCNILPSchedRegistry("gcn-iterative-ilp", "Run GCN iterative scheduler for ILP scheduling (experimental)", createIterativeILPMachineScheduler)
static cl::opt< bool > ScalarizeGlobal("amdgpu-scalarize-global-loads", cl::desc("Enable global load scalarization"), cl::init(true), cl::Hidden)
static const char RegAllocOptNotSupportedMessage[]
static MachineSchedRegistry GCNMaxOccupancySchedRegistry("gcn-max-occupancy", "Run GCN scheduler to maximize occupancy", createGCNMaxOccupancyMachineScheduler)
The AMDGPU TargetMachine interface definition for hw codegen targets.
This file declares the AMDGPU-specific subclass of TargetLoweringObjectFile.
This file a TargetTransformInfoImplBase conforming object specific to the AMDGPU target machine.
Provides passes to inlining "always_inline" functions.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This header provides classes for managing passes over SCCs of the call graph.
Provides analysis for continuously CSEing during GISel passes.
Interfaces for producing common pass manager configurations.
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
#define LLVM_READNONE
Definition Compiler.h:315
#define LLVM_ABI
Definition Compiler.h:213
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
DXIL Legalizer
This file provides the interface for a simple, fast CSE pass.
This file defines the class GCNIterativeScheduler, which uses an iterative approach to find a best sc...
This file provides the interface for LLVM's Global Value Numbering pass which eliminates fully redund...
#define _
AcceleratorCodeSelection - Identify all functions reachable from a kernel, removing those that are un...
This file declares the IRTranslator pass.
This header defines various interfaces for pass management in LLVM.
#define RegName(no)
This file provides the interface for LLVM's Loop Data Prefetching Pass.
This header provides classes for managing a pipeline of passes over loops in LLVM IR.
#define F(x, y, z)
Definition MD5.cpp:55
#define I(x, y, z)
Definition MD5.cpp:58
Register Reg
Register const TargetRegisterInfo * TRI
#define T
uint64_t IntrinsicInst * II
#define P(N)
CGSCCAnalysisManager CGAM
LoopAnalysisManager LAM
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
PassInstrumentationCallbacks PIC
PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)
static bool isLTOPreLink(ThinOrFullLTOPhase Phase)
The AMDGPU TargetMachine interface definition for hw codegen targets.
This file describes the interface of the MachineFunctionPass responsible for assigning the generic vi...
const GCNTargetMachine & getTM(const GCNSubtarget *STI)
SI Machine Scheduler interface.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
static FunctionPass * useDefaultRegisterAllocator()
-regalloc=... command line option.
static cl::opt< cl::boolOrDefault > EnableGlobalISelOption("global-isel", cl::Hidden, cl::desc("Enable the \"global\" instruction selector"))
Target-Independent Code Generator Pass Configuration Options pass.
LLVM IR instance of the generic uniformity analysis.
static std::unique_ptr< TargetLoweringObjectFile > createTLOF()
A manager for alias analyses.
void registerFunctionAnalysis()
Register a specific AA result.
void addAAResult(AAResultT &AAResult)
Register a specific AA result.
Legacy wrapper pass to provide the AMDGPUAAResult object.
Analysis pass providing a never-invalidated alias analysis result.
Lower llvm.global_ctors and llvm.global_dtors to special kernels.
AMDGPUTargetMachine & getAMDGPUTargetMachine() const
std::unique_ptr< CSEConfigBase > getCSEConfig() const override
Returns the CSEConfig object to use for the current optimization level.
bool isPassEnabled(const cl::opt< bool > &Opt, CodeGenOptLevel Level=CodeGenOptLevel::Default) const
Check if a pass is enabled given Opt option.
bool addPreISel() override
Methods with trivial inline returns are convenient points in the common codegen pass pipeline where t...
bool addInstSelector() override
addInstSelector - This method should install an instruction selector pass, which converts from LLVM c...
bool addGCPasses() override
addGCPasses - Add late codegen passes that analyze code for garbage collection.
AMDGPUPassConfig(TargetMachine &TM, PassManagerBase &PM)
void addIRPasses() override
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
void addCodeGenPrepare() override
Add pass to prepare the LLVM IR for code generation.
Splits the module M into N linkable partitions.
std::unique_ptr< TargetLoweringObjectFile > TLOF
static int64_t getNullPointerValue(unsigned AddrSpace)
Get the integer value of a null pointer in the given address space.
unsigned getAddressSpaceForPseudoSourceKind(unsigned Kind) const override
getAddressSpaceForPseudoSourceKind - Given the kind of memory (e.g.
const TargetSubtargetInfo * getSubtargetImpl() const
void registerDefaultAliasAnalyses(AAManager &) override
Allow the target to register alias analyses with the AAManager for use with the new pass manager.
std::pair< const Value *, unsigned > getPredicatedAddrSpace(const Value *V) const override
If the specified predicate checks whether a generic pointer falls within a specified address space,...
StringRef getFeatureString(const Function &F) const
ScheduleDAGInstrs * createMachineScheduler(MachineSchedContext *C) const override
Create an instance of ScheduleDAGInstrs to be run within the standard MachineScheduler pass for this ...
AMDGPUTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM, CodeGenOptLevel OL)
bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override
Returns true if a cast between SrcAS and DestAS is a noop.
void registerPassBuilderCallbacks(PassBuilder &PB) override
Allow the target to modify the pass pipeline.
StringRef getGPUName(const Function &F) const
unsigned getAssumedAddrSpace(const Value *V) const override
If the specified generic pointer could be assumed as a pointer to a specific address space,...
bool splitModule(Module &M, unsigned NumParts, function_ref< void(std::unique_ptr< Module > MPart)> ModuleCallback) override
Entry point for module splitting.
Inlines functions marked as "always_inline".
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:69
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition Attributes.h:223
This class provides access to building LLVM's passes.
CodeGenTargetMachineImpl(const Target &T, StringRef DataLayoutString, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, CodeGenOptLevel OL)
LLVM_ABI void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
This pass is required by interprocedural register allocation.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
const SIRegisterInfo * getRegisterInfo() const override
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
Get a TargetTransformInfo implementation for the target.
ScheduleDAGInstrs * createPostMachineScheduler(MachineSchedContext *C) const override
Similar to createMachineScheduler but used when postRA machine scheduling is enabled.
ScheduleDAGInstrs * createMachineScheduler(MachineSchedContext *C) const override
Create an instance of ScheduleDAGInstrs to be run within the standard MachineScheduler pass for this ...
void registerMachineRegisterInfoCallback(MachineFunction &MF) const override
bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &, PerFunctionMIParsingState &PFS, SMDiagnostic &Error, SMRange &SourceRange) const override
Parse out the target's MachineFunctionInfo from the YAML reprsentation.
yaml::MachineFunctionInfo * convertFuncInfoToYAML(const MachineFunction &MF) const override
Allocate and initialize an instance of the YAML representation of the MachineFunctionInfo.
Error buildCodeGenPipeline(ModulePassManager &MPM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, const CGPassBuilderOption &Opts, PassInstrumentationCallbacks *PIC) override
yaml::MachineFunctionInfo * createDefaultFuncInfoYAML() const override
Allocate and return a default initialized instance of the YAML representation for the MachineFunction...
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
GCNTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM, CodeGenOptLevel OL, bool JIT)
MachineFunctionInfo * createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F, const TargetSubtargetInfo *STI) const override
Create the target's instance of MachineFunctionInfo.
The core GVN pass object.
Definition GVN.h:126
Pass to remove unused function declarations.
Definition GlobalDCE.h:38
This pass is responsible for selecting generic machine instructions to target-specific instructions.
A pass that internalizes all functions and variables other than those that must be preserved accordin...
Definition Internalize.h:37
Converts loops into loop-closed SSA form.
Definition LCSSA.h:38
Performs Loop Invariant Code Motion Pass.
Definition LICM.h:66
This pass implements the localization mechanism described at the top of this file.
Definition Localizer.h:43
An optimization pass inserting data prefetches in loops.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
void addDelegate(Delegate *delegate)
MachineSchedRegistry provides a selection of available machine instruction schedulers.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
static LLVM_ABI const OptimizationLevel O0
Disable as many optimizations as possible.
static LLVM_ABI const OptimizationLevel O1
Optimize quickly without destroying debuggability.
This class provides access to building LLVM's passes.
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same_v< PassT, PassManager > > addPass(PassT &&Pass)
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Pass interface - Implemented by all 'passes'.
Definition Pass.h:99
This pass implements the reg bank selector pass used in the GlobalISel pipeline.
RegisterPassParser class - Handle the addition of new machine passes.
RegisterRegAllocBase class - Track the registration of register allocators.
Wrapper class representing virtual and physical registers.
Definition Register.h:19
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
bool initializeBaseYamlFields(const yaml::SIMachineFunctionInfo &YamlMFI, const MachineFunction &MF, PerFunctionMIParsingState &PFS, SMDiagnostic &Error, SMRange &SourceRange)
void setFlag(Register Reg, uint8_t Flag)
bool checkFlag(Register Reg, uint8_t Flag) const
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition SourceMgr.h:282
Represents a location in source code.
Definition SMLoc.h:23
Represents a range in source code.
Definition SMLoc.h:48
A ScheduleDAG for scheduling lists of MachineInstr.
ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules machine instructions while...
ScheduleDAGMI is an implementation of ScheduleDAGInstrs that simply schedules machine instructions ac...
void addMutation(std::unique_ptr< ScheduleDAGMutation > Mutation)
Add a postprocessing step to the DAG builder.
const TargetInstrInfo * TII
Target instruction information.
const TargetRegisterInfo * TRI
Target processor register info.
Move instructions into successor blocks when possible.
Definition Sink.h:24
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
void append(StringRef RHS)
Append from a StringRef.
Definition SmallString.h:68
unsigned getMainFileID() const
Definition SourceMgr.h:133
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition SourceMgr.h:126
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:702
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:143
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition StringRef.h:637
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
StringSwitch & Cases(StringLiteral S0, StringLiteral S1, T Value)
Primary interface to the complete machine description for the target machine.
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with.
const Triple & getTargetTriple() const
const MCSubtargetInfo * getMCSubtargetInfo() const
StringRef getTargetFeatureString() const
StringRef getTargetCPU() const
std::unique_ptr< const MCSubtargetInfo > STI
TargetOptions Options
void resetTargetOptions(const Function &F) const
Reset the target options based on the function's attributes.
std::unique_ptr< const MCRegisterInfo > MRI
CodeGenOptLevel OptLevel
Target-Independent Code Generator Pass Configuration Options.
virtual void addCodeGenPrepare()
Add pass to prepare the LLVM IR for code generation.
virtual bool addILPOpts()
Add passes that optimize instruction level parallelism for out-of-order targets.
virtual void addPostRegAlloc()
This method may be implemented by targets that want to run passes after register allocation pass pipe...
CodeGenOptLevel getOptLevel() const
virtual void addOptimizedRegAlloc()
addOptimizedRegAlloc - Add passes related to register allocation.
virtual void addIRPasses()
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
virtual void addFastRegAlloc()
addFastRegAlloc - Add the minimum set of target-independent passes that are required for fast registe...
virtual void addMachineSSAOptimization()
addMachineSSAOptimization - Add standard passes that optimize machine instructions in SSA form.
void disablePass(AnalysisID PassID)
Allow the target to disable a specific standard pass by default.
AnalysisID addPass(AnalysisID PassID)
Utilities for targets to add passes to the pass manager.
TargetPassConfig(TargetMachine &TM, PassManagerBase &PM)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
LLVM Value Representation.
Definition Value.h:75
bool use_empty() const
Definition Value.h:346
int getNumOccurrences() const
An efficient, type-erasing, non-owning reference to a callable.
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
An abstract base class for streams implementations that also support a pwrite operation.
Interfaces for registering analysis passes, producing common pass manager configurations,...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ REGION_ADDRESS
Address space for region memory. (GDS)
@ LOCAL_ADDRESS
Address space for local memory.
@ CONSTANT_ADDRESS
Address space for constant memory (VTX2).
@ FLAT_ADDRESS
Address space for flat memory.
@ GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
@ PRIVATE_ADDRESS
Address space for private memory.
bool isFlatGlobalAddrSpace(unsigned AS)
LLVM_READNONE constexpr bool isModuleEntryFunctionCC(CallingConv::ID CC)
LLVM_READNONE constexpr bool isEntryFunctionCC(CallingConv::ID CC)
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
BinaryOp_match< SrcTy, SpecificConstantMatch, TargetOpcode::G_XOR, true > m_Not(const SrcTy &&Src)
Matches a register not-ed by a G_XOR.
BinaryOp_match< LHS, RHS, Instruction::And, true > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
bool match(Val *V, const Pattern &P)
IntrinsicID_match m_Intrinsic()
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
deferredval_ty< Value > m_Deferred(Value *const &V)
Like m_Specific(), but works if the specific value to match is determined as part of the same match()...
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
template class LLVM_TEMPLATE_ABI opt< bool >
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
LocationClass< Ty > location(Ty &L)
This is an optimization pass for GlobalISel generic memory operations.
ScheduleDAGMILive * createSchedLive(MachineSchedContext *C)
Create the standard converging machine scheduler.
LLVM_ABI FunctionPass * createFlattenCFGPass()
LLVM_ABI FunctionPass * createFastRegisterAllocator()
FastRegisterAllocation Pass - This pass register allocates as fast as possible.
LLVM_ABI char & EarlyMachineLICMID
This pass performs loop invariant code motion on machine instructions.
ImmutablePass * createAMDGPUAAWrapperPass()
LLVM_ABI char & PostRAHazardRecognizerID
PostRAHazardRecognizer - This pass runs the post-ra hazard recognizer.
std::function< bool(const TargetRegisterInfo &TRI, const MachineRegisterInfo &MRI, const Register Reg)> RegAllocFilterFunc
Filter function for register classes during regalloc.
FunctionPass * createAMDGPUSetWavePriorityPass()
LLVM_ABI Pass * createLCSSAPass()
Definition LCSSA.cpp:525
void initializeAMDGPUMarkLastScratchLoadLegacyPass(PassRegistry &)
void initializeAMDGPUInsertDelayAluLegacyPass(PassRegistry &)
void initializeSIOptimizeExecMaskingPreRALegacyPass(PassRegistry &)
char & GCNPreRAOptimizationsID
LLVM_ABI char & GCLoweringID
GCLowering Pass - Used by gc.root to perform its default lowering operations.
void initializeSIInsertHardClausesLegacyPass(PassRegistry &)
ModulePass * createExpandVariadicsPass(ExpandVariadicsMode)
FunctionPass * createSIAnnotateControlFlowLegacyPass()
Create the annotation pass.
FunctionPass * createSIModeRegisterPass()
void initializeGCNPreRAOptimizationsLegacyPass(PassRegistry &)
void initializeSILowerWWMCopiesLegacyPass(PassRegistry &)
LLVM_ABI FunctionPass * createGreedyRegisterAllocator()
Greedy register allocation pass - This pass implements a global register allocator for optimized buil...
void initializeAMDGPUAAWrapperPassPass(PassRegistry &)
void initializeSIShrinkInstructionsLegacyPass(PassRegistry &)
ModulePass * createAMDGPULowerBufferFatPointersPass()
void initializeR600ClauseMergePassPass(PassRegistry &)
ModulePass * createAMDGPUCtorDtorLoweringLegacyPass()
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:644
ModuleToFunctionPassAdaptor createModuleToFunctionPassAdaptor(FunctionPassT &&Pass, bool EagerlyInvalidate=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
ModulePass * createAMDGPUSwLowerLDSLegacyPass(const AMDGPUTargetMachine *TM=nullptr)
void initializeGCNRewritePartialRegUsesLegacyPass(llvm::PassRegistry &)
void initializeAMDGPURewriteUndefForPHILegacyPass(PassRegistry &)
char & GCNRewritePartialRegUsesID
void initializeAMDGPUSwLowerLDSLegacyPass(PassRegistry &)
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:98
void initializeAMDGPULowerVGPREncodingLegacyPass(PassRegistry &)
char & AMDGPUWaitSGPRHazardsLegacyID
void initializeSILowerSGPRSpillsLegacyPass(PassRegistry &)
LLVM_ABI Pass * createLoadStoreVectorizerPass()
Create a legacy pass manager instance of the LoadStoreVectorizer pass.
std::unique_ptr< ScheduleDAGMutation > createIGroupLPDAGMutation(AMDGPU::SchedulingPhase Phase)
Phase specifes whether or not this is a reentry into the IGroupLPDAGMutation.
void initializeAMDGPUDAGToDAGISelLegacyPass(PassRegistry &)
FunctionPass * createAMDGPURegBankCombiner(bool IsOptNone)
LLVM_ABI FunctionPass * createNaryReassociatePass()
char & AMDGPUReserveWWMRegsLegacyID
void initializeAMDGPUWaitSGPRHazardsLegacyPass(PassRegistry &)
LLVM_ABI char & PatchableFunctionID
This pass implements the "patchable-function" attribute.
char & SIOptimizeExecMaskingLegacyID
LLVM_ABI char & PostRASchedulerID
PostRAScheduler - This pass performs post register allocation scheduling.
void initializeR600ExpandSpecialInstrsPassPass(PassRegistry &)
void initializeR600PacketizerPass(PassRegistry &)
std::unique_ptr< ScheduleDAGMutation > createVOPDPairingMutation()
ModulePass * createAMDGPUExportKernelRuntimeHandlesLegacyPass()
ModulePass * createAMDGPUAlwaysInlinePass(bool GlobalOpt=true)
void initializeAMDGPUAsmPrinterPass(PassRegistry &)
void initializeSIFoldOperandsLegacyPass(PassRegistry &)
char & SILoadStoreOptimizerLegacyID
void initializeAMDGPUGlobalISelDivergenceLoweringPass(PassRegistry &)
PassManager< LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, CGSCCUpdateResult & > CGSCCPassManager
The CGSCC pass manager.
LLVM_ABI std::unique_ptr< CSEConfigBase > getStandardCSEConfigForOpt(CodeGenOptLevel Level)
Definition CSEInfo.cpp:89
Target & getTheR600Target()
The target for R600 GPUs.
LLVM_ABI char & MachineSchedulerID
MachineScheduler - This pass schedules machine instructions.
LLVM_ABI Pass * createStructurizeCFGPass(bool SkipUniformRegions=false)
When SkipUniformRegions is true the structizer will not structurize regions that only contain uniform...
LLVM_ABI char & PostMachineSchedulerID
PostMachineScheduler - This pass schedules machine instructions postRA.
LLVM_ABI Pass * createLICMPass()
Definition LICM.cpp:388
char & SIFormMemoryClausesID
void initializeSILoadStoreOptimizerLegacyPass(PassRegistry &)
void initializeAMDGPULowerModuleLDSLegacyPass(PassRegistry &)
AnalysisManager< LazyCallGraph::SCC, LazyCallGraph & > CGSCCAnalysisManager
The CGSCC analysis manager.
void initializeAMDGPUCtorDtorLoweringLegacyPass(PassRegistry &)
LLVM_ABI char & EarlyIfConverterLegacyID
EarlyIfConverter - This pass performs if-conversion on SSA form by inserting cmov instructions.
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
void initializeAMDGPURegBankCombinerPass(PassRegistry &)
ThinOrFullLTOPhase
This enumerates the LLVM full LTO or ThinLTO optimization phases.
Definition Pass.h:77
@ FullLTOPreLink
Full LTO prelink phase.
Definition Pass.h:85
@ FullLTOPostLink
Full LTO postlink (backend compile) phase.
Definition Pass.h:87
@ ThinLTOPreLink
ThinLTO prelink (summary) phase.
Definition Pass.h:81
char & AMDGPUUnifyDivergentExitNodesID
void initializeAMDGPUPrepareAGPRAllocLegacyPass(PassRegistry &)
FunctionPass * createAMDGPUAtomicOptimizerPass(ScanOptions ScanStrategy)
FunctionPass * createAMDGPUPreloadKernArgPrologLegacyPass()
char & SIOptimizeVGPRLiveRangeLegacyID
LLVM_ABI char & ShadowStackGCLoweringID
ShadowStackGCLowering - Implements the custom lowering mechanism used by the shadow stack GC.
char & GCNNSAReassignID
void initializeAMDGPURewriteOutArgumentsPass(PassRegistry &)
static Reloc::Model getEffectiveRelocModel(std::optional< Reloc::Model > RM)
void initializeAMDGPUExternalAAWrapperPass(PassRegistry &)
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
void initializeAMDGPULowerKernelArgumentsPass(PassRegistry &)
FunctionToLoopPassAdaptor createFunctionToLoopPassAdaptor(LoopPassT &&Pass, bool UseMemorySSA=false, bool UseBlockFrequencyInfo=false)
A function to deduce a loop pass type and wrap it in the templated adaptor.
void initializeSIModeRegisterLegacyPass(PassRegistry &)
CodeModel::Model getEffectiveCodeModel(std::optional< CodeModel::Model > CM, CodeModel::Model Default)
Helper method for getting the code model, returning Default if CM does not have a value.
void initializeAMDGPUPreloadKernelArgumentsLegacyPass(PassRegistry &)
char & SILateBranchLoweringPassID
LLVM_ABI char & BranchRelaxationPassID
BranchRelaxation - This pass replaces branches that need to jump further than is supported by a branc...
LLVM_ABI FunctionPass * createSinkingPass()
Definition Sink.cpp:275
CGSCCToFunctionPassAdaptor createCGSCCToFunctionPassAdaptor(FunctionPassT &&Pass, bool EagerlyInvalidate=false, bool NoRerun=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
void initializeSIMemoryLegalizerLegacyPass(PassRegistry &)
ModulePass * createAMDGPULowerIntrinsicsLegacyPass()
void initializeR600MachineCFGStructurizerPass(PassRegistry &)
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition CodeGen.h:111
char & GCNDPPCombineLegacyID
PassManager< Module > ModulePassManager
Convenience typedef for a pass manager over modules.
LLVM_ABI std::unique_ptr< ScheduleDAGMutation > createStoreClusterDAGMutation(const TargetInstrInfo *TII, const TargetRegisterInfo *TRI, bool ReorderWhileClustering=false)
If ReorderWhileClustering is set to true, no attempt will be made to reduce reordering due to store c...
LLVM_ABI FunctionPass * createLoopDataPrefetchPass()
FunctionPass * createAMDGPULowerKernelArgumentsPass()
char & AMDGPUInsertDelayAluID
std::unique_ptr< ScheduleDAGMutation > createAMDGPUMacroFusionDAGMutation()
Note that you have to add: DAG.addMutation(createAMDGPUMacroFusionDAGMutation()); to AMDGPUTargetMach...
LLVM_ABI char & StackMapLivenessID
StackMapLiveness - This pass analyses the register live-out set of stackmap/patchpoint intrinsics and...
void initializeGCNPreRALongBranchRegLegacyPass(PassRegistry &)
char & SILowerWWMCopiesLegacyID
LLVM_ABI FunctionPass * createUnifyLoopExitsPass()
char & SIOptimizeExecMaskingPreRAID
LLVM_ABI FunctionPass * createFixIrreduciblePass()
void initializeR600EmitClauseMarkersPass(PassRegistry &)
LLVM_ABI char & FuncletLayoutID
This pass lays out funclets contiguously.
LLVM_ABI char & DetectDeadLanesID
This pass adds dead/undef flags after analyzing subregister lanes.
void initializeAMDGPUPostLegalizerCombinerPass(PassRegistry &)
void initializeAMDGPUExportKernelRuntimeHandlesLegacyPass(PassRegistry &)
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:82
void initializeSIInsertWaitcntsLegacyPass(PassRegistry &)
ModulePass * createAMDGPUPreloadKernelArgumentsLegacyPass(const TargetMachine *)
ModulePass * createAMDGPUPrintfRuntimeBinding()
LLVM_ABI char & StackSlotColoringID
StackSlotColoring - This pass performs stack slot coloring.
LLVM_ABI Pass * createAlwaysInlinerLegacyPass(bool InsertLifetime=true)
Create a legacy pass manager instance of a pass to inline and remove functions marked as "always_inli...
void initializeR600ControlFlowFinalizerPass(PassRegistry &)
void initializeAMDGPUImageIntrinsicOptimizerPass(PassRegistry &)
void initializeSILateBranchLoweringLegacyPass(PassRegistry &)
void initializeSILowerControlFlowLegacyPass(PassRegistry &)
void initializeSIFormMemoryClausesLegacyPass(PassRegistry &)
char & SIPreAllocateWWMRegsLegacyID
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
ModulePass * createAMDGPULowerModuleLDSLegacyPass(const AMDGPUTargetMachine *TM=nullptr)
void initializeAMDGPUPreLegalizerCombinerPass(PassRegistry &)
FunctionPass * createAMDGPUPromoteAlloca()
LLVM_ABI FunctionPass * createSeparateConstOffsetFromGEPPass(bool LowerGEP=false)
void initializeAMDGPUReserveWWMRegsLegacyPass(PassRegistry &)
char & SIPreEmitPeepholeID
char & SIPostRABundlerLegacyID
ModulePass * createAMDGPURemoveIncompatibleFunctionsPass(const TargetMachine *)
void initializeGCNRegPressurePrinterPass(PassRegistry &)
void initializeSILowerI1CopiesLegacyPass(PassRegistry &)
char & SILowerSGPRSpillsLegacyID
void initializeAMDGPUArgumentUsageInfoPass(PassRegistry &)
LLVM_ABI FunctionPass * createBasicRegisterAllocator()
BasicRegisterAllocation Pass - This pass implements a degenerate global register allocator using the ...
LLVM_ABI void initializeGlobalISel(PassRegistry &)
Initialize all passes linked into the GlobalISel library.
char & SILowerControlFlowLegacyID
ModulePass * createR600OpenCLImageTypeLoweringPass()
FunctionPass * createAMDGPUCodeGenPreparePass()
void initializeSIAnnotateControlFlowLegacyPass(PassRegistry &)
FunctionPass * createAMDGPUISelDag(TargetMachine &TM, CodeGenOptLevel OptLevel)
This pass converts a legalized DAG into a AMDGPU-specific.
void initializeGCNCreateVOPDLegacyPass(PassRegistry &)
void initializeSIPreAllocateWWMRegsLegacyPass(PassRegistry &)
void initializeSIFixVGPRCopiesLegacyPass(PassRegistry &)
Target & getTheGCNTarget()
The target for GCN GPUs.
void initializeSIFixSGPRCopiesLegacyPass(PassRegistry &)
void initializeAMDGPUAtomicOptimizerPass(PassRegistry &)
void initializeAMDGPULowerIntrinsicsLegacyPass(PassRegistry &)
LLVM_ABI FunctionPass * createGVNPass()
Create a legacy GVN pass.
Definition GVN.cpp:3449
void initializeAMDGPURewriteAGPRCopyMFMALegacyPass(PassRegistry &)
void initializeSIPostRABundlerLegacyPass(PassRegistry &)
FunctionPass * createAMDGPURegBankSelectPass()
FunctionPass * createAMDGPURegBankLegalizePass()
LLVM_ABI char & MachineCSELegacyID
MachineCSE - This pass performs global CSE on machine instructions.
char & SIWholeQuadModeID
LLVM_ABI std::unique_ptr< ScheduleDAGMutation > createLoadClusterDAGMutation(const TargetInstrInfo *TII, const TargetRegisterInfo *TRI, bool ReorderWhileClustering=false)
If ReorderWhileClustering is set to true, no attempt will be made to reduce reordering due to store c...
PassManager< Function > FunctionPassManager
Convenience typedef for a pass manager over functions.
LLVM_ABI char & LiveVariablesID
LiveVariables pass - This pass computes the set of blocks in which each variable is life and sets mac...
void initializeAMDGPUCodeGenPreparePass(PassRegistry &)
FunctionPass * createAMDGPURewriteUndefForPHILegacyPass()
void initializeSIOptimizeExecMaskingLegacyPass(PassRegistry &)
void call_once(once_flag &flag, Function &&F, Args &&... ArgList)
Execute the function specified as a parameter once.
Definition Threading.h:86
FunctionPass * createSILowerI1CopiesLegacyPass()
FunctionPass * createAMDGPUPostLegalizeCombiner(bool IsOptNone)
void initializeAMDGPULowerKernelAttributesPass(PassRegistry &)
char & SIInsertHardClausesID
char & SIFixSGPRCopiesLegacyID
void initializeGCNDPPCombineLegacyPass(PassRegistry &)
char & GCNCreateVOPDID
char & SIPeepholeSDWALegacyID
LLVM_ABI char & VirtRegRewriterID
VirtRegRewriter pass.
char & SIFixVGPRCopiesID
char & SIFoldOperandsLegacyID
void initializeGCNNSAReassignLegacyPass(PassRegistry &)
char & AMDGPUPrepareAGPRAllocLegacyID
LLVM_ABI FunctionPass * createLowerSwitchPass()
void initializeAMDGPUPreloadKernArgPrologLegacyPass(PassRegistry &)
LLVM_ABI FunctionPass * createVirtRegRewriter(bool ClearVirtRegs=true)
void initializeR600VectorRegMergerPass(PassRegistry &)
char & AMDGPURewriteAGPRCopyMFMALegacyID
char & AMDGPULowerVGPREncodingLegacyID
FunctionPass * createAMDGPUGlobalISelDivergenceLoweringPass()
FunctionPass * createSIMemoryLegalizerPass()
void initializeAMDGPULateCodeGenPrepareLegacyPass(PassRegistry &)
void initializeSIOptimizeVGPRLiveRangeLegacyPass(PassRegistry &)
void initializeSIPeepholeSDWALegacyPass(PassRegistry &)
void initializeAMDGPURegBankLegalizePass(PassRegistry &)
LLVM_ABI char & TwoAddressInstructionPassID
TwoAddressInstruction - This pass reduces two-address instructions to use two operands.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
FunctionPass * createAMDGPUPreLegalizeCombiner(bool IsOptNone)
void initializeAMDGPURegBankSelectPass(PassRegistry &)
FunctionPass * createAMDGPULateCodeGenPrepareLegacyPass()
LLVM_ABI FunctionPass * createAtomicExpandLegacyPass()
AtomicExpandPass - At IR level this pass replace atomic instructions with __atomic_* library calls,...
MCRegisterInfo * createGCNMCRegisterInfo(AMDGPUDwarfFlavour DwarfFlavour)
LLVM_ABI FunctionPass * createStraightLineStrengthReducePass()
FunctionPass * createAMDGPUImageIntrinsicOptimizerPass(const TargetMachine *)
void initializeAMDGPUUnifyDivergentExitNodesPass(PassRegistry &)
void initializeAMDGPULowerBufferFatPointersPass(PassRegistry &)
FunctionPass * createSIInsertWaitcntsPass()
FunctionPass * createAMDGPUAnnotateUniformValuesLegacy()
LLVM_ABI FunctionPass * createEarlyCSEPass(bool UseMemorySSA=false)
void initializeSIWholeQuadModeLegacyPass(PassRegistry &)
LLVM_ABI char & PHIEliminationID
PHIElimination - This pass eliminates machine instruction PHI nodes by inserting copy instructions.
LLVM_ABI llvm::cl::opt< bool > NoKernelInfoEndLTO
bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
void initializeAMDGPUResourceUsageAnalysisWrapperPassPass(PassRegistry &)
FunctionPass * createSIShrinkInstructionsLegacyPass()
char & AMDGPUMarkLastScratchLoadID
LLVM_ABI char & RenameIndependentSubregsID
This pass detects subregister lanes in a virtual register that are used independently of other lanes ...
void initializeAMDGPUAnnotateUniformValuesLegacyPass(PassRegistry &)
std::unique_ptr< ScheduleDAGMutation > createAMDGPUExportClusteringDAGMutation()
void initializeAMDGPUPrintfRuntimeBindingPass(PassRegistry &)
void initializeAMDGPUPromoteAllocaPass(PassRegistry &)
void initializeAMDGPURemoveIncompatibleFunctionsLegacyPass(PassRegistry &)
void initializeAMDGPUAlwaysInlinePass(PassRegistry &)
LLVM_ABI char & DeadMachineInstructionElimID
DeadMachineInstructionElim - This pass removes dead machine instructions.
void initializeSIPreEmitPeepholeLegacyPass(PassRegistry &)
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
char & AMDGPUPerfHintAnalysisLegacyID
LLVM_ABI ImmutablePass * createExternalAAWrapperPass(std::function< void(Pass &, Function &, AAResults &)> Callback)
A wrapper pass around a callback which can be used to populate the AAResults in the AAResultsWrapperP...
char & GCNPreRALongBranchRegID
LLVM_ABI CGPassBuilderOption getCGPassBuilderOption()
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:180
void initializeAMDGPUPromoteKernelArgumentsPass(PassRegistry &)
#define N
static ArgDescriptor createStack(unsigned Offset, unsigned Mask=~0u)
static ArgDescriptor createArg(const ArgDescriptor &Arg, unsigned Mask)
static ArgDescriptor createRegister(Register Reg, unsigned Mask=~0u)
DenormalModeKind Input
Denormal treatment kind for floating point instruction inputs in the default floating-point environme...
@ PreserveSign
The sign of a flushed-to-zero number is preserved in the sign of 0.
@ IEEE
IEEE-754 denormal numbers preserved.
DenormalModeKind Output
Denormal flushing mode for floating point instruction results in the default floating point environme...
A simple and fast domtree-based CSE pass.
Definition EarlyCSE.h:31
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
static FuncInfoTy * create(BumpPtrAllocator &Allocator, const Function &F, const SubtargetTy *STI)
Factory function: default behavior is to call new using the supplied allocator.
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
StringMap< VRegInfo * > VRegInfosNamed
Definition MIParser.h:177
DenseMap< Register, VRegInfo * > VRegInfos
Definition MIParser.h:176
RegisterTargetMachine - Helper template for registering a target machine implementation,...
A utility pass template to force an analysis result to be available.
bool DX10Clamp
Used by the vector ALU to force DX10-style treatment of NaNs: when set, clamp NaN to zero; otherwise,...
DenormalMode FP64FP16Denormals
If this is set, neither input or output denormals are flushed for both f64 and f16/v2f16 instructions...
bool IEEE
Floating point opcodes that support exception flag gathering quiet and propagate signaling NaN inputs...
DenormalMode FP32Denormals
If this is set, neither input or output denormals are flushed for most f32 instructions.
The llvm::once_flag structure.
Definition Threading.h:67
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.
SmallVector< StringValue > WWMReservedRegs
std::optional< SIArgumentInfo > ArgInfo
SmallVector< StringValue, 2 > SpillPhysVGPRS
A wrapper around std::string which contains a source range that's being set during parsing.