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
1387 if (TM->getTargetTriple().isAMDGCN()) {
1388 // This lowering has been placed after codegenprepare to take advantage of
1389 // address mode matching (which is why it isn't put with the LDS lowerings).
1390 // It could be placed anywhere before uniformity annotations (an analysis
1391 // that it changes by splitting up fat pointers into their components)
1392 // but has been put before switch lowering and CFG flattening so that those
1393 // passes can run on the more optimized control flow this pass creates in
1394 // many cases.
1395 //
1396 // FIXME: This should ideally be put after the LoadStoreVectorizer.
1397 // However, due to some annoying facts about ResourceUsageAnalysis,
1398 // (especially as exercised in the resource-usage-dead-function test),
1399 // we need all the function passes codegenprepare all the way through
1400 // said resource usage analysis to run on the call graph produced
1401 // before codegenprepare runs (because codegenprepare will knock some
1402 // nodes out of the graph, which leads to function-level passes not
1403 // being run on them, which causes crashes in the resource usage analysis).
1406 // In accordance with the above FIXME, manually force all the
1407 // function-level passes into a CGSCCPassManager.
1408 addPass(new DummyCGSCCPass());
1409 }
1410
1412
1415
1416 // LowerSwitch pass may introduce unreachable blocks that can
1417 // cause unexpected behavior for subsequent passes. Placing it
1418 // here seems better that these blocks would get cleaned up by
1419 // UnreachableBlockElim inserted next in the pass flow.
1421}
1422
1424 if (TM->getOptLevel() > CodeGenOptLevel::None)
1426 return false;
1427}
1428
1433
1435 // Do nothing. GC is not supported.
1436 return false;
1437}
1438
1439//===----------------------------------------------------------------------===//
1440// GCN Legacy Pass Setup
1441//===----------------------------------------------------------------------===//
1442
1443bool GCNPassConfig::addPreISel() {
1445
1446 if (TM->getOptLevel() > CodeGenOptLevel::None)
1447 addPass(createSinkingPass());
1448
1449 if (TM->getOptLevel() > CodeGenOptLevel::None)
1451
1452 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
1453 // regions formed by them.
1455 addPass(createFixIrreduciblePass());
1456 addPass(createUnifyLoopExitsPass());
1457 addPass(createStructurizeCFGPass(false)); // true -> SkipUniformRegions
1458
1461 // TODO: Move this right after structurizeCFG to avoid extra divergence
1462 // analysis. This depends on stopping SIAnnotateControlFlow from making
1463 // control flow modifications.
1465
1466 // SDAG requires LCSSA, GlobalISel does not. Disable LCSSA for -global-isel
1467 // with -new-reg-bank-select and without any of the fallback options.
1469 !isGlobalISelAbortEnabled() || !NewRegBankSelect)
1470 addPass(createLCSSAPass());
1471
1472 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1474
1475 return false;
1476}
1477
1478void GCNPassConfig::addMachineSSAOptimization() {
1480
1481 // We want to fold operands after PeepholeOptimizer has run (or as part of
1482 // it), because it will eliminate extra copies making it easier to fold the
1483 // real source operand. We want to eliminate dead instructions after, so that
1484 // we see fewer uses of the copies. We then need to clean up the dead
1485 // instructions leftover after the operands are folded as well.
1486 //
1487 // XXX - Can we get away without running DeadMachineInstructionElim again?
1488 addPass(&SIFoldOperandsLegacyID);
1489 if (EnableDPPCombine)
1490 addPass(&GCNDPPCombineLegacyID);
1492 if (isPassEnabled(EnableSDWAPeephole)) {
1493 addPass(&SIPeepholeSDWALegacyID);
1494 addPass(&EarlyMachineLICMID);
1495 addPass(&MachineCSELegacyID);
1496 addPass(&SIFoldOperandsLegacyID);
1497 }
1500}
1501
1502bool GCNPassConfig::addILPOpts() {
1504 addPass(&EarlyIfConverterLegacyID);
1505
1507 return false;
1508}
1509
1510bool GCNPassConfig::addInstSelector() {
1512 addPass(&SIFixSGPRCopiesLegacyID);
1514 return false;
1515}
1516
1517bool GCNPassConfig::addIRTranslator() {
1518 addPass(new IRTranslator(getOptLevel()));
1519 return false;
1520}
1521
1522void GCNPassConfig::addPreLegalizeMachineIR() {
1523 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1524 addPass(createAMDGPUPreLegalizeCombiner(IsOptNone));
1525 addPass(new Localizer());
1526}
1527
1528bool GCNPassConfig::addLegalizeMachineIR() {
1529 addPass(new Legalizer());
1530 return false;
1531}
1532
1533void GCNPassConfig::addPreRegBankSelect() {
1534 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1535 addPass(createAMDGPUPostLegalizeCombiner(IsOptNone));
1537}
1538
1539bool GCNPassConfig::addRegBankSelect() {
1540 if (NewRegBankSelect) {
1543 } else {
1544 addPass(new RegBankSelect());
1545 }
1546 return false;
1547}
1548
1549void GCNPassConfig::addPreGlobalInstructionSelect() {
1550 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1551 addPass(createAMDGPURegBankCombiner(IsOptNone));
1552}
1553
1554bool GCNPassConfig::addGlobalInstructionSelect() {
1555 addPass(new InstructionSelect(getOptLevel()));
1556 return false;
1557}
1558
1559void GCNPassConfig::addFastRegAlloc() {
1560 // FIXME: We have to disable the verifier here because of PHIElimination +
1561 // TwoAddressInstructions disabling it.
1562
1563 // This must be run immediately after phi elimination and before
1564 // TwoAddressInstructions, otherwise the processing of the tied operand of
1565 // SI_ELSE will introduce a copy of the tied operand source after the else.
1567
1569
1571}
1572
1573void GCNPassConfig::addPreRegAlloc() {
1574 if (getOptLevel() != CodeGenOptLevel::None)
1576}
1577
1578void GCNPassConfig::addOptimizedRegAlloc() {
1579 if (EnableDCEInRA)
1581
1582 // FIXME: when an instruction has a Killed operand, and the instruction is
1583 // inside a bundle, seems only the BUNDLE instruction appears as the Kills of
1584 // the register in LiveVariables, this would trigger a failure in verifier,
1585 // we should fix it and enable the verifier.
1586 if (OptVGPRLiveRange)
1588
1589 // This must be run immediately after phi elimination and before
1590 // TwoAddressInstructions, otherwise the processing of the tied operand of
1591 // SI_ELSE will introduce a copy of the tied operand source after the else.
1593
1596
1597 if (isPassEnabled(EnablePreRAOptimizations))
1599
1600 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
1601 // instructions that cause scheduling barriers.
1603
1604 if (OptExecMaskPreRA)
1606
1607 // This is not an essential optimization and it has a noticeable impact on
1608 // compilation time, so we only enable it from O2.
1609 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1611
1613}
1614
1615bool GCNPassConfig::addPreRewrite() {
1617 addPass(&GCNNSAReassignID);
1618
1620 return true;
1621}
1622
1623FunctionPass *GCNPassConfig::createSGPRAllocPass(bool Optimized) {
1624 // Initialize the global default.
1625 llvm::call_once(InitializeDefaultSGPRRegisterAllocatorFlag,
1626 initializeDefaultSGPRRegisterAllocatorOnce);
1627
1628 RegisterRegAlloc::FunctionPassCtor Ctor = SGPRRegisterRegAlloc::getDefault();
1629 if (Ctor != useDefaultRegisterAllocator)
1630 return Ctor();
1631
1632 if (Optimized)
1633 return createGreedyRegisterAllocator(onlyAllocateSGPRs);
1634
1635 return createFastRegisterAllocator(onlyAllocateSGPRs, false);
1636}
1637
1638FunctionPass *GCNPassConfig::createVGPRAllocPass(bool Optimized) {
1639 // Initialize the global default.
1640 llvm::call_once(InitializeDefaultVGPRRegisterAllocatorFlag,
1641 initializeDefaultVGPRRegisterAllocatorOnce);
1642
1643 RegisterRegAlloc::FunctionPassCtor Ctor = VGPRRegisterRegAlloc::getDefault();
1644 if (Ctor != useDefaultRegisterAllocator)
1645 return Ctor();
1646
1647 if (Optimized)
1648 return createGreedyVGPRRegisterAllocator();
1649
1650 return createFastVGPRRegisterAllocator();
1651}
1652
1653FunctionPass *GCNPassConfig::createWWMRegAllocPass(bool Optimized) {
1654 // Initialize the global default.
1655 llvm::call_once(InitializeDefaultWWMRegisterAllocatorFlag,
1656 initializeDefaultWWMRegisterAllocatorOnce);
1657
1658 RegisterRegAlloc::FunctionPassCtor Ctor = WWMRegisterRegAlloc::getDefault();
1659 if (Ctor != useDefaultRegisterAllocator)
1660 return Ctor();
1661
1662 if (Optimized)
1663 return createGreedyWWMRegisterAllocator();
1664
1665 return createFastWWMRegisterAllocator();
1666}
1667
1668FunctionPass *GCNPassConfig::createRegAllocPass(bool Optimized) {
1669 llvm_unreachable("should not be used");
1670}
1671
1673 "-regalloc not supported with amdgcn. Use -sgpr-regalloc, -wwm-regalloc, "
1674 "and -vgpr-regalloc";
1675
1676bool GCNPassConfig::addRegAssignAndRewriteFast() {
1677 if (!usingDefaultRegAlloc())
1679
1680 addPass(&GCNPreRALongBranchRegID);
1681
1682 addPass(createSGPRAllocPass(false));
1683
1684 // Equivalent of PEI for SGPRs.
1685 addPass(&SILowerSGPRSpillsLegacyID);
1686
1687 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1689
1690 // For allocating other wwm register operands.
1691 addPass(createWWMRegAllocPass(false));
1692
1693 addPass(&SILowerWWMCopiesLegacyID);
1695
1696 // For allocating per-thread VGPRs.
1697 addPass(createVGPRAllocPass(false));
1698
1699 return true;
1700}
1701
1702bool GCNPassConfig::addRegAssignAndRewriteOptimized() {
1703 if (!usingDefaultRegAlloc())
1705
1706 addPass(&GCNPreRALongBranchRegID);
1707
1708 addPass(createSGPRAllocPass(true));
1709
1710 // Commit allocated register changes. This is mostly necessary because too
1711 // many things rely on the use lists of the physical registers, such as the
1712 // verifier. This is only necessary with allocators which use LiveIntervals,
1713 // since FastRegAlloc does the replacements itself.
1714 addPass(createVirtRegRewriter(false));
1715
1716 // At this point, the sgpr-regalloc has been done and it is good to have the
1717 // stack slot coloring to try to optimize the SGPR spill stack indices before
1718 // attempting the custom SGPR spill lowering.
1719 addPass(&StackSlotColoringID);
1720
1721 // Equivalent of PEI for SGPRs.
1722 addPass(&SILowerSGPRSpillsLegacyID);
1723
1724 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1726
1727 // For allocating other whole wave mode registers.
1728 addPass(createWWMRegAllocPass(true));
1729 addPass(&SILowerWWMCopiesLegacyID);
1730 addPass(createVirtRegRewriter(false));
1732
1733 // For allocating per-thread VGPRs.
1734 addPass(createVGPRAllocPass(true));
1735
1736 addPreRewrite();
1737 addPass(&VirtRegRewriterID);
1738
1740
1741 return true;
1742}
1743
1744void GCNPassConfig::addPostRegAlloc() {
1745 addPass(&SIFixVGPRCopiesID);
1746 if (getOptLevel() > CodeGenOptLevel::None)
1749}
1750
1751void GCNPassConfig::addPreSched2() {
1752 if (TM->getOptLevel() > CodeGenOptLevel::None)
1754 addPass(&SIPostRABundlerLegacyID);
1755}
1756
1757void GCNPassConfig::addPreEmitPass() {
1758 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less))
1759 addPass(&GCNCreateVOPDID);
1760 addPass(createSIMemoryLegalizerPass());
1761 addPass(createSIInsertWaitcntsPass());
1762
1763 addPass(createSIModeRegisterPass());
1764
1765 if (getOptLevel() > CodeGenOptLevel::None)
1766 addPass(&SIInsertHardClausesID);
1767
1769 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
1771 if (getOptLevel() > CodeGenOptLevel::None)
1772 addPass(&SIPreEmitPeepholeID);
1773 // The hazard recognizer that runs as part of the post-ra scheduler does not
1774 // guarantee to be able handle all hazards correctly. This is because if there
1775 // are multiple scheduling regions in a basic block, the regions are scheduled
1776 // bottom up, so when we begin to schedule a region we don't know what
1777 // instructions were emitted directly before it.
1778 //
1779 // Here we add a stand-alone hazard recognizer pass which can handle all
1780 // cases.
1781 addPass(&PostRAHazardRecognizerID);
1782
1784
1786
1787 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less))
1788 addPass(&AMDGPUInsertDelayAluID);
1789
1790 addPass(&BranchRelaxationPassID);
1791}
1792
1793void GCNPassConfig::addPostBBSections() {
1794 // We run this later to avoid passes like livedebugvalues and BBSections
1795 // having to deal with the apparent multi-entry functions we may generate.
1797}
1798
1800 return new GCNPassConfig(*this, PM);
1801}
1802
1808
1815
1819
1826
1829 SMDiagnostic &Error, SMRange &SourceRange) const {
1830 const yaml::SIMachineFunctionInfo &YamlMFI =
1831 static_cast<const yaml::SIMachineFunctionInfo &>(MFI_);
1832 MachineFunction &MF = PFS.MF;
1834 const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
1835
1836 if (MFI->initializeBaseYamlFields(YamlMFI, MF, PFS, Error, SourceRange))
1837 return true;
1838
1839 if (MFI->Occupancy == 0) {
1840 // Fixup the subtarget dependent default value.
1841 MFI->Occupancy = ST.getOccupancyWithWorkGroupSizes(MF).second;
1842 }
1843
1844 auto parseRegister = [&](const yaml::StringValue &RegName, Register &RegVal) {
1845 Register TempReg;
1846 if (parseNamedRegisterReference(PFS, TempReg, RegName.Value, Error)) {
1847 SourceRange = RegName.SourceRange;
1848 return true;
1849 }
1850 RegVal = TempReg;
1851
1852 return false;
1853 };
1854
1855 auto parseOptionalRegister = [&](const yaml::StringValue &RegName,
1856 Register &RegVal) {
1857 return !RegName.Value.empty() && parseRegister(RegName, RegVal);
1858 };
1859
1860 if (parseOptionalRegister(YamlMFI.VGPRForAGPRCopy, MFI->VGPRForAGPRCopy))
1861 return true;
1862
1863 if (parseOptionalRegister(YamlMFI.SGPRForEXECCopy, MFI->SGPRForEXECCopy))
1864 return true;
1865
1866 if (parseOptionalRegister(YamlMFI.LongBranchReservedReg,
1867 MFI->LongBranchReservedReg))
1868 return true;
1869
1870 auto diagnoseRegisterClass = [&](const yaml::StringValue &RegName) {
1871 // Create a diagnostic for a the register string literal.
1872 const MemoryBuffer &Buffer =
1873 *PFS.SM->getMemoryBuffer(PFS.SM->getMainFileID());
1874 Error = SMDiagnostic(*PFS.SM, SMLoc(), Buffer.getBufferIdentifier(), 1,
1875 RegName.Value.size(), SourceMgr::DK_Error,
1876 "incorrect register class for field", RegName.Value,
1877 {}, {});
1878 SourceRange = RegName.SourceRange;
1879 return true;
1880 };
1881
1882 if (parseRegister(YamlMFI.ScratchRSrcReg, MFI->ScratchRSrcReg) ||
1883 parseRegister(YamlMFI.FrameOffsetReg, MFI->FrameOffsetReg) ||
1884 parseRegister(YamlMFI.StackPtrOffsetReg, MFI->StackPtrOffsetReg))
1885 return true;
1886
1887 if (MFI->ScratchRSrcReg != AMDGPU::PRIVATE_RSRC_REG &&
1888 !AMDGPU::SGPR_128RegClass.contains(MFI->ScratchRSrcReg)) {
1889 return diagnoseRegisterClass(YamlMFI.ScratchRSrcReg);
1890 }
1891
1892 if (MFI->FrameOffsetReg != AMDGPU::FP_REG &&
1893 !AMDGPU::SGPR_32RegClass.contains(MFI->FrameOffsetReg)) {
1894 return diagnoseRegisterClass(YamlMFI.FrameOffsetReg);
1895 }
1896
1897 if (MFI->StackPtrOffsetReg != AMDGPU::SP_REG &&
1898 !AMDGPU::SGPR_32RegClass.contains(MFI->StackPtrOffsetReg)) {
1899 return diagnoseRegisterClass(YamlMFI.StackPtrOffsetReg);
1900 }
1901
1902 for (const auto &YamlReg : YamlMFI.WWMReservedRegs) {
1903 Register ParsedReg;
1904 if (parseRegister(YamlReg, ParsedReg))
1905 return true;
1906
1907 MFI->reserveWWMRegister(ParsedReg);
1908 }
1909
1910 for (const auto &[_, Info] : PFS.VRegInfosNamed) {
1911 MFI->setFlag(Info->VReg, Info->Flags);
1912 }
1913 for (const auto &[_, Info] : PFS.VRegInfos) {
1914 MFI->setFlag(Info->VReg, Info->Flags);
1915 }
1916
1917 for (const auto &YamlRegStr : YamlMFI.SpillPhysVGPRS) {
1918 Register ParsedReg;
1919 if (parseRegister(YamlRegStr, ParsedReg))
1920 return true;
1921 MFI->SpillPhysVGPRs.push_back(ParsedReg);
1922 }
1923
1924 auto parseAndCheckArgument = [&](const std::optional<yaml::SIArgument> &A,
1925 const TargetRegisterClass &RC,
1926 ArgDescriptor &Arg, unsigned UserSGPRs,
1927 unsigned SystemSGPRs) {
1928 // Skip parsing if it's not present.
1929 if (!A)
1930 return false;
1931
1932 if (A->IsRegister) {
1933 Register Reg;
1934 if (parseNamedRegisterReference(PFS, Reg, A->RegisterName.Value, Error)) {
1935 SourceRange = A->RegisterName.SourceRange;
1936 return true;
1937 }
1938 if (!RC.contains(Reg))
1939 return diagnoseRegisterClass(A->RegisterName);
1941 } else
1942 Arg = ArgDescriptor::createStack(A->StackOffset);
1943 // Check and apply the optional mask.
1944 if (A->Mask)
1945 Arg = ArgDescriptor::createArg(Arg, *A->Mask);
1946
1947 MFI->NumUserSGPRs += UserSGPRs;
1948 MFI->NumSystemSGPRs += SystemSGPRs;
1949 return false;
1950 };
1951
1952 if (YamlMFI.ArgInfo &&
1953 (parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentBuffer,
1954 AMDGPU::SGPR_128RegClass,
1955 MFI->ArgInfo.PrivateSegmentBuffer, 4, 0) ||
1956 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchPtr,
1957 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchPtr,
1958 2, 0) ||
1959 parseAndCheckArgument(YamlMFI.ArgInfo->QueuePtr, AMDGPU::SReg_64RegClass,
1960 MFI->ArgInfo.QueuePtr, 2, 0) ||
1961 parseAndCheckArgument(YamlMFI.ArgInfo->KernargSegmentPtr,
1962 AMDGPU::SReg_64RegClass,
1963 MFI->ArgInfo.KernargSegmentPtr, 2, 0) ||
1964 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchID,
1965 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchID,
1966 2, 0) ||
1967 parseAndCheckArgument(YamlMFI.ArgInfo->FlatScratchInit,
1968 AMDGPU::SReg_64RegClass,
1969 MFI->ArgInfo.FlatScratchInit, 2, 0) ||
1970 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentSize,
1971 AMDGPU::SGPR_32RegClass,
1972 MFI->ArgInfo.PrivateSegmentSize, 0, 0) ||
1973 parseAndCheckArgument(YamlMFI.ArgInfo->LDSKernelId,
1974 AMDGPU::SGPR_32RegClass,
1975 MFI->ArgInfo.LDSKernelId, 0, 1) ||
1976 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDX,
1977 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDX,
1978 0, 1) ||
1979 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDY,
1980 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDY,
1981 0, 1) ||
1982 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDZ,
1983 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDZ,
1984 0, 1) ||
1985 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupInfo,
1986 AMDGPU::SGPR_32RegClass,
1987 MFI->ArgInfo.WorkGroupInfo, 0, 1) ||
1988 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentWaveByteOffset,
1989 AMDGPU::SGPR_32RegClass,
1990 MFI->ArgInfo.PrivateSegmentWaveByteOffset, 0, 1) ||
1991 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitArgPtr,
1992 AMDGPU::SReg_64RegClass,
1993 MFI->ArgInfo.ImplicitArgPtr, 0, 0) ||
1994 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitBufferPtr,
1995 AMDGPU::SReg_64RegClass,
1996 MFI->ArgInfo.ImplicitBufferPtr, 2, 0) ||
1997 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDX,
1998 AMDGPU::VGPR_32RegClass,
1999 MFI->ArgInfo.WorkItemIDX, 0, 0) ||
2000 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDY,
2001 AMDGPU::VGPR_32RegClass,
2002 MFI->ArgInfo.WorkItemIDY, 0, 0) ||
2003 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDZ,
2004 AMDGPU::VGPR_32RegClass,
2005 MFI->ArgInfo.WorkItemIDZ, 0, 0)))
2006 return true;
2007
2008 if (ST.hasIEEEMode())
2009 MFI->Mode.IEEE = YamlMFI.Mode.IEEE;
2010 if (ST.hasDX10ClampMode())
2011 MFI->Mode.DX10Clamp = YamlMFI.Mode.DX10Clamp;
2012
2013 // FIXME: Move proper support for denormal-fp-math into base MachineFunction
2014 MFI->Mode.FP32Denormals.Input = YamlMFI.Mode.FP32InputDenormals
2017 MFI->Mode.FP32Denormals.Output = YamlMFI.Mode.FP32OutputDenormals
2020
2027
2028 if (YamlMFI.HasInitWholeWave)
2029 MFI->setInitWholeWave();
2030
2031 return false;
2032}
2033
2034//===----------------------------------------------------------------------===//
2035// AMDGPU CodeGen Pass Builder interface.
2036//===----------------------------------------------------------------------===//
2037
2038AMDGPUCodeGenPassBuilder::AMDGPUCodeGenPassBuilder(
2039 GCNTargetMachine &TM, const CGPassBuilderOption &Opts,
2041 : CodeGenPassBuilder(TM, Opts, PIC) {
2042 Opt.MISchedPostRA = true;
2043 Opt.RequiresCodeGenSCCOrder = true;
2044 // Exceptions and StackMaps are not supported, so these passes will never do
2045 // anything.
2046 // Garbage collection is not supported.
2047 disablePass<StackMapLivenessPass, FuncletLayoutPass,
2049}
2050
2051void AMDGPUCodeGenPassBuilder::addIRPasses(AddIRPass &addPass) const {
2052 if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN())
2054
2056 if (LowerCtorDtor)
2057 addPass(AMDGPUCtorDtorLoweringPass());
2058
2059 if (isPassEnabled(EnableImageIntrinsicOptimizer))
2061
2062 // This can be disabled by passing ::Disable here or on the command line
2063 // with --expand-variadics-override=disable.
2065
2066 addPass(AMDGPUAlwaysInlinePass());
2067 addPass(AlwaysInlinerPass());
2068
2070
2071 if (EnableSwLowerLDS)
2072 addPass(AMDGPUSwLowerLDSPass(TM));
2073
2074 // Runs before PromoteAlloca so the latter can account for function uses
2076 addPass(AMDGPULowerModuleLDSPass(TM));
2077
2078 // Run atomic optimizer before Atomic Expand
2079 if (TM.getOptLevel() >= CodeGenOptLevel::Less &&
2082
2083 addPass(AtomicExpandPass(&TM));
2084
2085 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2086 addPass(AMDGPUPromoteAllocaPass(TM));
2087 if (isPassEnabled(EnableScalarIRPasses))
2088 addStraightLineScalarOptimizationPasses(addPass);
2089
2090 // TODO: Handle EnableAMDGPUAliasAnalysis
2091
2092 // TODO: May want to move later or split into an early and late one.
2093 addPass(AMDGPUCodeGenPreparePass(TM));
2094
2095 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
2096 // have expanded.
2097 if (TM.getOptLevel() > CodeGenOptLevel::Less) {
2099 /*UseMemorySSA=*/true));
2100 }
2101 }
2102
2103 Base::addIRPasses(addPass);
2104
2105 // EarlyCSE is not always strong enough to clean up what LSR produces. For
2106 // example, GVN can combine
2107 //
2108 // %0 = add %a, %b
2109 // %1 = add %b, %a
2110 //
2111 // and
2112 //
2113 // %0 = shl nsw %a, 2
2114 // %1 = shl %a, 2
2115 //
2116 // but EarlyCSE can do neither of them.
2117 if (isPassEnabled(EnableScalarIRPasses))
2118 addEarlyCSEOrGVNPass(addPass);
2119}
2120
2121void AMDGPUCodeGenPassBuilder::addCodeGenPrepare(AddIRPass &addPass) const {
2122 if (TM.getOptLevel() > CodeGenOptLevel::None)
2124
2126 addPass(AMDGPULowerKernelArgumentsPass(TM));
2127
2128 // This lowering has been placed after codegenprepare to take advantage of
2129 // address mode matching (which is why it isn't put with the LDS lowerings).
2130 // It could be placed anywhere before uniformity annotations (an analysis
2131 // that it changes by splitting up fat pointers into their components)
2132 // but has been put before switch lowering and CFG flattening so that those
2133 // passes can run on the more optimized control flow this pass creates in
2134 // many cases.
2135 //
2136 // FIXME: This should ideally be put after the LoadStoreVectorizer.
2137 // However, due to some annoying facts about ResourceUsageAnalysis,
2138 // (especially as exercised in the resource-usage-dead-function test),
2139 // we need all the function passes codegenprepare all the way through
2140 // said resource usage analysis to run on the call graph produced
2141 // before codegenprepare runs (because codegenprepare will knock some
2142 // nodes out of the graph, which leads to function-level passes not
2143 // being run on them, which causes crashes in the resource usage analysis).
2145 addPass.requireCGSCCOrder();
2146
2147 addPass(AMDGPULowerIntrinsicsPass(TM));
2148
2149 Base::addCodeGenPrepare(addPass);
2150
2151 if (isPassEnabled(EnableLoadStoreVectorizer))
2152 addPass(LoadStoreVectorizerPass());
2153
2154 // LowerSwitch pass may introduce unreachable blocks that can cause unexpected
2155 // behavior for subsequent passes. Placing it here seems better that these
2156 // blocks would get cleaned up by UnreachableBlockElim inserted next in the
2157 // pass flow.
2158 addPass(LowerSwitchPass());
2159}
2160
2161void AMDGPUCodeGenPassBuilder::addPreISel(AddIRPass &addPass) const {
2162
2163 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2164 addPass(FlattenCFGPass());
2165 addPass(SinkingPass());
2166 addPass(AMDGPULateCodeGenPreparePass(TM));
2167 }
2168
2169 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
2170 // regions formed by them.
2171
2173 addPass(FixIrreduciblePass());
2174 addPass(UnifyLoopExitsPass());
2175 addPass(StructurizeCFGPass(/*SkipUniformRegions=*/false));
2176
2178
2179 addPass(SIAnnotateControlFlowPass(TM));
2180
2181 // TODO: Move this right after structurizeCFG to avoid extra divergence
2182 // analysis. This depends on stopping SIAnnotateControlFlow from making
2183 // control flow modifications.
2185
2187 !isGlobalISelAbortEnabled() || !NewRegBankSelect)
2188 addPass(LCSSAPass());
2189
2190 if (TM.getOptLevel() > CodeGenOptLevel::Less)
2191 addPass(AMDGPUPerfHintAnalysisPass(TM));
2192
2193 // FIXME: Why isn't this queried as required from AMDGPUISelDAGToDAG, and why
2194 // isn't this in addInstSelector?
2196 /*Force=*/true);
2197}
2198
2199void AMDGPUCodeGenPassBuilder::addILPOpts(AddMachinePass &addPass) const {
2201 addPass(EarlyIfConverterPass());
2202
2203 Base::addILPOpts(addPass);
2204}
2205
2206void AMDGPUCodeGenPassBuilder::addAsmPrinter(AddMachinePass &addPass,
2207 CreateMCStreamer) const {
2208 // TODO: Add AsmPrinter.
2209}
2210
2211Error AMDGPUCodeGenPassBuilder::addInstSelector(AddMachinePass &addPass) const {
2212 addPass(AMDGPUISelDAGToDAGPass(TM));
2213 addPass(SIFixSGPRCopiesPass());
2214 addPass(SILowerI1CopiesPass());
2215 return Error::success();
2216}
2217
2218void AMDGPUCodeGenPassBuilder::addPreRewrite(AddMachinePass &addPass) const {
2219 if (EnableRegReassign) {
2220 addPass(GCNNSAReassignPass());
2221 }
2222}
2223
2224void AMDGPUCodeGenPassBuilder::addMachineSSAOptimization(
2225 AddMachinePass &addPass) const {
2226 Base::addMachineSSAOptimization(addPass);
2227
2228 addPass(SIFoldOperandsPass());
2229 if (EnableDPPCombine) {
2230 addPass(GCNDPPCombinePass());
2231 }
2232 addPass(SILoadStoreOptimizerPass());
2233 if (isPassEnabled(EnableSDWAPeephole)) {
2234 addPass(SIPeepholeSDWAPass());
2235 addPass(EarlyMachineLICMPass());
2236 addPass(MachineCSEPass());
2237 addPass(SIFoldOperandsPass());
2238 }
2240 addPass(SIShrinkInstructionsPass());
2241}
2242
2243void AMDGPUCodeGenPassBuilder::addOptimizedRegAlloc(
2244 AddMachinePass &addPass) const {
2245 if (EnableDCEInRA)
2246 insertPass<DetectDeadLanesPass>(DeadMachineInstructionElimPass());
2247
2248 // FIXME: when an instruction has a Killed operand, and the instruction is
2249 // inside a bundle, seems only the BUNDLE instruction appears as the Kills of
2250 // the register in LiveVariables, this would trigger a failure in verifier,
2251 // we should fix it and enable the verifier.
2252 if (OptVGPRLiveRange)
2253 insertPass<RequireAnalysisPass<LiveVariablesAnalysis, MachineFunction>>(
2255
2256 // This must be run immediately after phi elimination and before
2257 // TwoAddressInstructions, otherwise the processing of the tied operand of
2258 // SI_ELSE will introduce a copy of the tied operand source after the else.
2259 insertPass<PHIEliminationPass>(SILowerControlFlowPass());
2260
2262 insertPass<RenameIndependentSubregsPass>(GCNRewritePartialRegUsesPass());
2263
2264 if (isPassEnabled(EnablePreRAOptimizations))
2265 insertPass<MachineSchedulerPass>(GCNPreRAOptimizationsPass());
2266
2267 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
2268 // instructions that cause scheduling barriers.
2269 insertPass<MachineSchedulerPass>(SIWholeQuadModePass());
2270
2271 if (OptExecMaskPreRA)
2272 insertPass<MachineSchedulerPass>(SIOptimizeExecMaskingPreRAPass());
2273
2274 // This is not an essential optimization and it has a noticeable impact on
2275 // compilation time, so we only enable it from O2.
2276 if (TM.getOptLevel() > CodeGenOptLevel::Less)
2277 insertPass<MachineSchedulerPass>(SIFormMemoryClausesPass());
2278
2279 Base::addOptimizedRegAlloc(addPass);
2280}
2281
2282void AMDGPUCodeGenPassBuilder::addPreRegAlloc(AddMachinePass &addPass) const {
2283 if (getOptLevel() != CodeGenOptLevel::None)
2284 addPass(AMDGPUPrepareAGPRAllocPass());
2285}
2286
2287Error AMDGPUCodeGenPassBuilder::addRegAssignmentOptimized(
2288 AddMachinePass &addPass) const {
2289 // TODO: Check --regalloc-npm option
2290
2291 addPass(GCNPreRALongBranchRegPass());
2292
2293 addPass(RAGreedyPass({onlyAllocateSGPRs, "sgpr"}));
2294
2295 // Commit allocated register changes. This is mostly necessary because too
2296 // many things rely on the use lists of the physical registers, such as the
2297 // verifier. This is only necessary with allocators which use LiveIntervals,
2298 // since FastRegAlloc does the replacements itself.
2299 addPass(VirtRegRewriterPass(false));
2300
2301 // At this point, the sgpr-regalloc has been done and it is good to have the
2302 // stack slot coloring to try to optimize the SGPR spill stack indices before
2303 // attempting the custom SGPR spill lowering.
2304 addPass(StackSlotColoringPass());
2305
2306 // Equivalent of PEI for SGPRs.
2307 addPass(SILowerSGPRSpillsPass());
2308
2309 // To Allocate wwm registers used in whole quad mode operations (for shaders).
2310 addPass(SIPreAllocateWWMRegsPass());
2311
2312 // For allocating other wwm register operands.
2313 addPass(RAGreedyPass({onlyAllocateWWMRegs, "wwm"}));
2314 addPass(SILowerWWMCopiesPass());
2315 addPass(VirtRegRewriterPass(false));
2316 addPass(AMDGPUReserveWWMRegsPass());
2317
2318 // For allocating per-thread VGPRs.
2319 addPass(RAGreedyPass({onlyAllocateVGPRs, "vgpr"}));
2320
2321
2322 addPreRewrite(addPass);
2323 addPass(VirtRegRewriterPass(true));
2324
2326 return Error::success();
2327}
2328
2329void AMDGPUCodeGenPassBuilder::addPostRegAlloc(AddMachinePass &addPass) const {
2330 addPass(SIFixVGPRCopiesPass());
2331 if (TM.getOptLevel() > CodeGenOptLevel::None)
2332 addPass(SIOptimizeExecMaskingPass());
2333 Base::addPostRegAlloc(addPass);
2334}
2335
2336void AMDGPUCodeGenPassBuilder::addPreSched2(AddMachinePass &addPass) const {
2337 if (TM.getOptLevel() > CodeGenOptLevel::None)
2338 addPass(SIShrinkInstructionsPass());
2339 addPass(SIPostRABundlerPass());
2340}
2341
2342void AMDGPUCodeGenPassBuilder::addPreEmitPass(AddMachinePass &addPass) const {
2343 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less)) {
2344 addPass(GCNCreateVOPDPass());
2345 }
2346
2347 addPass(SIMemoryLegalizerPass());
2348 addPass(SIInsertWaitcntsPass());
2349
2350 // TODO: addPass(SIModeRegisterPass());
2351
2352 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2353 // TODO: addPass(SIInsertHardClausesPass());
2354 }
2355
2356 addPass(SILateBranchLoweringPass());
2357
2358 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
2359 addPass(AMDGPUSetWavePriorityPass());
2360
2361 if (TM.getOptLevel() > CodeGenOptLevel::None)
2362 addPass(SIPreEmitPeepholePass());
2363
2364 // The hazard recognizer that runs as part of the post-ra scheduler does not
2365 // guarantee to be able handle all hazards correctly. This is because if there
2366 // are multiple scheduling regions in a basic block, the regions are scheduled
2367 // bottom up, so when we begin to schedule a region we don't know what
2368 // instructions were emitted directly before it.
2369 //
2370 // Here we add a stand-alone hazard recognizer pass which can handle all
2371 // cases.
2372 addPass(PostRAHazardRecognizerPass());
2373 addPass(AMDGPUWaitSGPRHazardsPass());
2374 addPass(AMDGPULowerVGPREncodingPass());
2375
2376 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less)) {
2377 addPass(AMDGPUInsertDelayAluPass());
2378 }
2379
2380 addPass(BranchRelaxationPass());
2381}
2382
2383bool AMDGPUCodeGenPassBuilder::isPassEnabled(const cl::opt<bool> &Opt,
2384 CodeGenOptLevel Level) const {
2385 if (Opt.getNumOccurrences())
2386 return Opt;
2387 if (TM.getOptLevel() < Level)
2388 return false;
2389 return Opt;
2390}
2391
2392void AMDGPUCodeGenPassBuilder::addEarlyCSEOrGVNPass(AddIRPass &addPass) const {
2393 if (TM.getOptLevel() == CodeGenOptLevel::Aggressive)
2394 addPass(GVNPass());
2395 else
2396 addPass(EarlyCSEPass());
2397}
2398
2399void AMDGPUCodeGenPassBuilder::addStraightLineScalarOptimizationPasses(
2400 AddIRPass &addPass) const {
2402 addPass(LoopDataPrefetchPass());
2403
2405
2406 // ReassociateGEPs exposes more opportunities for SLSR. See
2407 // the example in reassociate-geps-and-slsr.ll.
2409
2410 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
2411 // EarlyCSE can reuse.
2412 addEarlyCSEOrGVNPass(addPass);
2413
2414 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
2415 addPass(NaryReassociatePass());
2416
2417 // NaryReassociate on GEPs creates redundant common expressions, so run
2418 // EarlyCSE after it.
2419 addPass(EarlyCSEPass());
2420}
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:710
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:151
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition StringRef.h:645
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.
LLVM_ABI llvm::cl::opt< bool > NoKernelInfoEndLTO
This file defines the TargetMachine class.
@ 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:649
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:384
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 &)
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)
FunctionToLoopPassAdaptor createFunctionToLoopPassAdaptor(LoopPassT &&Pass, bool UseMemorySSA=false, bool UseBlockFrequencyInfo=false, bool UseBranchProbabilityInfo=false)
A function to deduce a loop pass type and wrap it in the templated adaptor.
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.
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.