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 "amdgpu-enable-uniform-intrinsic-combine",
531 cl::desc("Enable/Disable the Uniform Intrinsic Combine Pass"),
532 cl::init(true), cl::Hidden);
533
535 // Register the target
538
621}
622
623static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
624 return std::make_unique<AMDGPUTargetObjectFile>();
625}
626
630
631static ScheduleDAGInstrs *
633 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
634 ScheduleDAGMILive *DAG =
635 new GCNScheduleDAGMILive(C, std::make_unique<GCNMaxOccupancySchedStrategy>(C));
636 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
637 if (ST.shouldClusterStores())
638 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
640 DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
641 DAG->addMutation(createAMDGPUExportClusteringDAGMutation());
642 return DAG;
643}
644
645static ScheduleDAGInstrs *
647 ScheduleDAGMILive *DAG =
648 new GCNScheduleDAGMILive(C, std::make_unique<GCNMaxILPSchedStrategy>(C));
650 return DAG;
651}
652
653static ScheduleDAGInstrs *
655 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
657 C, std::make_unique<GCNMaxMemoryClauseSchedStrategy>(C));
658 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
659 if (ST.shouldClusterStores())
660 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
661 DAG->addMutation(createAMDGPUExportClusteringDAGMutation());
662 return DAG;
663}
664
665static ScheduleDAGInstrs *
667 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
668 auto *DAG = new GCNIterativeScheduler(
670 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
671 if (ST.shouldClusterStores())
672 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
674 return DAG;
675}
676
683
684static ScheduleDAGInstrs *
686 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
688 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
689 if (ST.shouldClusterStores())
690 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
691 DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
693 return DAG;
694}
695
697SISchedRegistry("si", "Run SI's custom scheduler",
699
702 "Run GCN scheduler to maximize occupancy",
704
706 GCNMaxILPSchedRegistry("gcn-max-ilp", "Run GCN scheduler to maximize ilp",
708
710 "gcn-max-memory-clause", "Run GCN scheduler to maximize memory clause",
712
714 "gcn-iterative-max-occupancy-experimental",
715 "Run GCN scheduler to maximize occupancy (experimental)",
717
719 "gcn-iterative-minreg",
720 "Run GCN iterative scheduler for minimal register usage (experimental)",
722
724 "gcn-iterative-ilp",
725 "Run GCN iterative scheduler for ILP scheduling (experimental)",
727
730 if (!GPU.empty())
731 return GPU;
732
733 // Need to default to a target with flat support for HSA.
734 if (TT.isAMDGCN())
735 return TT.getOS() == Triple::AMDHSA ? "generic-hsa" : "generic";
736
737 return "r600";
738}
739
740static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {
741 // The AMDGPU toolchain only supports generating shared objects, so we
742 // must always use PIC.
743 return Reloc::PIC_;
744}
745
747 StringRef CPU, StringRef FS,
748 const TargetOptions &Options,
749 std::optional<Reloc::Model> RM,
750 std::optional<CodeModel::Model> CM,
753 T, TT.computeDataLayout(), TT, getGPUOrDefault(TT, CPU), FS, Options,
757 initAsmInfo();
758 if (TT.isAMDGCN()) {
759 if (getMCSubtargetInfo()->checkFeatures("+wavefrontsize64"))
761 else if (getMCSubtargetInfo()->checkFeatures("+wavefrontsize32"))
763 }
764}
765
768
770
772 Attribute GPUAttr = F.getFnAttribute("target-cpu");
773 return GPUAttr.isValid() ? GPUAttr.getValueAsString() : getTargetCPU();
774}
775
777 Attribute FSAttr = F.getFnAttribute("target-features");
778
779 return FSAttr.isValid() ? FSAttr.getValueAsString()
781}
782
785 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
787 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
788 if (ST.shouldClusterStores())
789 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
790 return DAG;
791}
792
793/// Predicate for Internalize pass.
794static bool mustPreserveGV(const GlobalValue &GV) {
795 if (const Function *F = dyn_cast<Function>(&GV))
796 return F->isDeclaration() || F->getName().starts_with("__asan_") ||
797 F->getName().starts_with("__sanitizer_") ||
798 AMDGPU::isEntryFunctionCC(F->getCallingConv());
799
801 return !GV.use_empty();
802}
803
807
810 if (Params.empty())
812 Params.consume_front("strategy=");
813 auto Result = StringSwitch<std::optional<ScanOptions>>(Params)
814 .Case("dpp", ScanOptions::DPP)
815 .Cases("iterative", "", ScanOptions::Iterative)
816 .Case("none", ScanOptions::None)
817 .Default(std::nullopt);
818 if (Result)
819 return *Result;
820 return make_error<StringError>("invalid parameter", inconvertibleErrorCode());
821}
822
826 while (!Params.empty()) {
827 StringRef ParamName;
828 std::tie(ParamName, Params) = Params.split(';');
829 if (ParamName == "closed-world") {
830 Result.IsClosedWorld = true;
831 } else {
833 formatv("invalid AMDGPUAttributor pass parameter '{0}' ", ParamName)
834 .str(),
836 }
837 }
838 return Result;
839}
840
842
843#define GET_PASS_REGISTRY "AMDGPUPassRegistry.def"
845
846 PB.registerScalarOptimizerLateEPCallback(
847 [](FunctionPassManager &FPM, OptimizationLevel Level) {
848 if (Level == OptimizationLevel::O0)
849 return;
850
852 });
853
854 PB.registerVectorizerEndEPCallback(
855 [](FunctionPassManager &FPM, OptimizationLevel Level) {
856 if (Level == OptimizationLevel::O0)
857 return;
858
860 });
861
862 PB.registerPipelineEarlySimplificationEPCallback(
865 if (!isLTOPreLink(Phase)) {
866 // When we are not using -fgpu-rdc, we can run accelerator code
867 // selection relatively early, but still after linking to prevent
868 // eager removal of potentially reachable symbols.
869 if (EnableHipStdPar) {
872 }
874 }
875
876 if (Level == OptimizationLevel::O0)
877 return;
878
879 // We don't want to run internalization at per-module stage.
883 }
884
887
890 });
891
892 PB.registerPeepholeEPCallback(
893 [](FunctionPassManager &FPM, OptimizationLevel Level) {
894 if (Level == OptimizationLevel::O0)
895 return;
896
900 });
901
902 PB.registerCGSCCOptimizerLateEPCallback(
903 [this](CGSCCPassManager &PM, OptimizationLevel Level) {
904 if (Level == OptimizationLevel::O0)
905 return;
906
908
909 // Add promote kernel arguments pass to the opt pipeline right before
910 // infer address spaces which is needed to do actual address space
911 // rewriting.
912 if (Level.getSpeedupLevel() > OptimizationLevel::O1.getSpeedupLevel() &&
915
916 // Add infer address spaces pass to the opt pipeline after inlining
917 // but before SROA to increase SROA opportunities.
919
920 // This should run after inlining to have any chance of doing
921 // anything, and before other cleanup optimizations.
923
924 if (Level != OptimizationLevel::O0) {
925 // Promote alloca to vector before SROA and loop unroll. If we
926 // manage to eliminate allocas before unroll we may choose to unroll
927 // less.
929 }
930
931 PM.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
932 });
933
934 // FIXME: Why is AMDGPUAttributor not in CGSCC?
935 PB.registerOptimizerLastEPCallback([this](ModulePassManager &MPM,
936 OptimizationLevel Level,
938 if (Level != OptimizationLevel::O0) {
939 if (!isLTOPreLink(Phase)) {
940 if (EnableAMDGPUAttributor && getTargetTriple().isAMDGCN()) {
942 MPM.addPass(AMDGPUAttributorPass(*this, Opts, Phase));
943 }
944 }
945 }
946 });
947
948 PB.registerFullLinkTimeOptimizationLastEPCallback(
949 [this](ModulePassManager &PM, OptimizationLevel Level) {
950 // When we are using -fgpu-rdc, we can only run accelerator code
951 // selection after linking to prevent, otherwise we end up removing
952 // potentially reachable symbols that were exported as external in other
953 // modules.
954 if (EnableHipStdPar) {
957 }
958 // We want to support the -lto-partitions=N option as "best effort".
959 // For that, we need to lower LDS earlier in the pipeline before the
960 // module is partitioned for codegen.
962 PM.addPass(AMDGPUSwLowerLDSPass(*this));
965 if (Level != OptimizationLevel::O0) {
966 // We only want to run this with O2 or higher since inliner and SROA
967 // don't run in O1.
968 if (Level != OptimizationLevel::O1) {
969 PM.addPass(
971 }
972 // Do we really need internalization in LTO?
973 if (InternalizeSymbols) {
976 }
977 if (EnableAMDGPUAttributor && getTargetTriple().isAMDGCN()) {
980 Opt.IsClosedWorld = true;
983 }
984 }
985 if (!NoKernelInfoEndLTO) {
987 FPM.addPass(KernelInfoPrinter(this));
988 PM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
989 }
990 });
991
992 PB.registerRegClassFilterParsingCallback(
993 [](StringRef FilterName) -> RegAllocFilterFunc {
994 if (FilterName == "sgpr")
995 return onlyAllocateSGPRs;
996 if (FilterName == "vgpr")
997 return onlyAllocateVGPRs;
998 if (FilterName == "wwm")
999 return onlyAllocateWWMRegs;
1000 return nullptr;
1001 });
1002}
1003
1004int64_t AMDGPUTargetMachine::getNullPointerValue(unsigned AddrSpace) {
1005 return (AddrSpace == AMDGPUAS::LOCAL_ADDRESS ||
1006 AddrSpace == AMDGPUAS::PRIVATE_ADDRESS ||
1007 AddrSpace == AMDGPUAS::REGION_ADDRESS)
1008 ? -1
1009 : 0;
1010}
1011
1013 unsigned DestAS) const {
1014 return AMDGPU::isFlatGlobalAddrSpace(SrcAS) &&
1016}
1017
1019 if (auto *Arg = dyn_cast<Argument>(V);
1020 Arg &&
1021 AMDGPU::isModuleEntryFunctionCC(Arg->getParent()->getCallingConv()) &&
1022 !Arg->hasByRefAttr())
1024
1025 const auto *LD = dyn_cast<LoadInst>(V);
1026 if (!LD) // TODO: Handle invariant load like constant.
1028
1029 // It must be a generic pointer loaded.
1030 assert(V->getType()->getPointerAddressSpace() == AMDGPUAS::FLAT_ADDRESS);
1031
1032 const auto *Ptr = LD->getPointerOperand();
1033 if (Ptr->getType()->getPointerAddressSpace() != AMDGPUAS::CONSTANT_ADDRESS)
1035 // For a generic pointer loaded from the constant memory, it could be assumed
1036 // as a global pointer since the constant memory is only populated on the
1037 // host side. As implied by the offload programming model, only global
1038 // pointers could be referenced on the host side.
1040}
1041
1042std::pair<const Value *, unsigned>
1044 if (auto *II = dyn_cast<IntrinsicInst>(V)) {
1045 switch (II->getIntrinsicID()) {
1046 case Intrinsic::amdgcn_is_shared:
1047 return std::pair(II->getArgOperand(0), AMDGPUAS::LOCAL_ADDRESS);
1048 case Intrinsic::amdgcn_is_private:
1049 return std::pair(II->getArgOperand(0), AMDGPUAS::PRIVATE_ADDRESS);
1050 default:
1051 break;
1052 }
1053 return std::pair(nullptr, -1);
1054 }
1055 // Check the global pointer predication based on
1056 // (!is_share(p) && !is_private(p)). Note that logic 'and' is commutative and
1057 // the order of 'is_shared' and 'is_private' is not significant.
1058 Value *Ptr;
1059 if (match(
1060 const_cast<Value *>(V),
1063 m_Deferred(Ptr))))))
1064 return std::pair(Ptr, AMDGPUAS::GLOBAL_ADDRESS);
1065
1066 return std::pair(nullptr, -1);
1067}
1068
1069unsigned
1084
1086 Module &M, unsigned NumParts,
1087 function_ref<void(std::unique_ptr<Module> MPart)> ModuleCallback) {
1088 // FIXME(?): Would be better to use an already existing Analysis/PassManager,
1089 // but all current users of this API don't have one ready and would need to
1090 // create one anyway. Let's hide the boilerplate for now to keep it simple.
1091
1096
1097 PassBuilder PB(this);
1098 PB.registerModuleAnalyses(MAM);
1099 PB.registerFunctionAnalyses(FAM);
1100 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
1101
1103 MPM.addPass(AMDGPUSplitModulePass(NumParts, ModuleCallback));
1104 MPM.run(M, MAM);
1105 return true;
1106}
1107
1108//===----------------------------------------------------------------------===//
1109// GCN Target Machine (SI+)
1110//===----------------------------------------------------------------------===//
1111
1113 StringRef CPU, StringRef FS,
1114 const TargetOptions &Options,
1115 std::optional<Reloc::Model> RM,
1116 std::optional<CodeModel::Model> CM,
1117 CodeGenOptLevel OL, bool JIT)
1118 : AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {}
1119
1120const TargetSubtargetInfo *
1122 StringRef GPU = getGPUName(F);
1124
1125 SmallString<128> SubtargetKey(GPU);
1126 SubtargetKey.append(FS);
1127
1128 auto &I = SubtargetMap[SubtargetKey];
1129 if (!I) {
1130 // This needs to be done before we create a new subtarget since any
1131 // creation will depend on the TM and the code generation flags on the
1132 // function that reside in TargetOptions.
1134 I = std::make_unique<GCNSubtarget>(TargetTriple, GPU, FS, *this);
1135 }
1136
1137 I->setScalarizeGlobalBehavior(ScalarizeGlobal);
1138
1139 return I.get();
1140}
1141
1144 return TargetTransformInfo(std::make_unique<GCNTTIImpl>(this, F));
1145}
1146
1149 CodeGenFileType FileType, const CGPassBuilderOption &Opts,
1151 AMDGPUCodeGenPassBuilder CGPB(*this, Opts, PIC);
1152 return CGPB.buildPipeline(MPM, Out, DwoOut, FileType);
1153}
1154
1157 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
1158 if (ST.enableSIScheduler())
1160
1161 Attribute SchedStrategyAttr =
1162 C->MF->getFunction().getFnAttribute("amdgpu-sched-strategy");
1163 StringRef SchedStrategy = SchedStrategyAttr.isValid()
1164 ? SchedStrategyAttr.getValueAsString()
1166
1167 if (SchedStrategy == "max-ilp")
1169
1170 if (SchedStrategy == "max-memory-clause")
1172
1173 if (SchedStrategy == "iterative-ilp")
1175
1176 if (SchedStrategy == "iterative-minreg")
1177 return createMinRegScheduler(C);
1178
1179 if (SchedStrategy == "iterative-maxocc")
1181
1183}
1184
1187 ScheduleDAGMI *DAG =
1188 new GCNPostScheduleDAGMILive(C, std::make_unique<PostGenericScheduler>(C),
1189 /*RemoveKillFlags=*/true);
1190 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
1192 if (ST.shouldClusterStores())
1195 if ((EnableVOPD.getNumOccurrences() ||
1197 EnableVOPD)
1200 return DAG;
1201}
1202//===----------------------------------------------------------------------===//
1203// AMDGPU Legacy Pass Setup
1204//===----------------------------------------------------------------------===//
1205
1206std::unique_ptr<CSEConfigBase> llvm::AMDGPUPassConfig::getCSEConfig() const {
1207 return getStandardCSEConfigForOpt(TM->getOptLevel());
1208}
1209
1210namespace {
1211
1212class GCNPassConfig final : public AMDGPUPassConfig {
1213public:
1214 GCNPassConfig(TargetMachine &TM, PassManagerBase &PM)
1215 : AMDGPUPassConfig(TM, PM) {
1216 // It is necessary to know the register usage of the entire call graph. We
1217 // allow calls without EnableAMDGPUFunctionCalls if they are marked
1218 // noinline, so this is always required.
1219 setRequiresCodeGenSCCOrder(true);
1220 substitutePass(&PostRASchedulerID, &PostMachineSchedulerID);
1221 }
1222
1223 GCNTargetMachine &getGCNTargetMachine() const {
1224 return getTM<GCNTargetMachine>();
1225 }
1226
1227 bool addPreISel() override;
1228 void addMachineSSAOptimization() override;
1229 bool addILPOpts() override;
1230 bool addInstSelector() override;
1231 bool addIRTranslator() override;
1232 void addPreLegalizeMachineIR() override;
1233 bool addLegalizeMachineIR() override;
1234 void addPreRegBankSelect() override;
1235 bool addRegBankSelect() override;
1236 void addPreGlobalInstructionSelect() override;
1237 bool addGlobalInstructionSelect() override;
1238 void addPreRegAlloc() override;
1239 void addFastRegAlloc() override;
1240 void addOptimizedRegAlloc() override;
1241
1242 FunctionPass *createSGPRAllocPass(bool Optimized);
1243 FunctionPass *createVGPRAllocPass(bool Optimized);
1244 FunctionPass *createWWMRegAllocPass(bool Optimized);
1245 FunctionPass *createRegAllocPass(bool Optimized) override;
1246
1247 bool addRegAssignAndRewriteFast() override;
1248 bool addRegAssignAndRewriteOptimized() override;
1249
1250 bool addPreRewrite() override;
1251 void addPostRegAlloc() override;
1252 void addPreSched2() override;
1253 void addPreEmitPass() override;
1254 void addPostBBSections() override;
1255};
1256
1257} // end anonymous namespace
1258
1260 : TargetPassConfig(TM, PM) {
1261 // Exceptions and StackMaps are not supported, so these passes will never do
1262 // anything.
1265 // Garbage collection is not supported.
1268}
1269
1276
1281 // ReassociateGEPs exposes more opportunities for SLSR. See
1282 // the example in reassociate-geps-and-slsr.ll.
1284 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
1285 // EarlyCSE can reuse.
1287 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
1289 // NaryReassociate on GEPs creates redundant common expressions, so run
1290 // EarlyCSE after it.
1292}
1293
1296
1297 if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN())
1299
1300 // There is no reason to run these.
1304
1306 if (LowerCtorDtor)
1308
1309 if (TM.getTargetTriple().isAMDGCN() &&
1312
1313 // This can be disabled by passing ::Disable here or on the command line
1314 // with --expand-variadics-override=disable.
1316
1317 // Function calls are not supported, so make sure we inline everything.
1320
1321 // Handle uses of OpenCL image2d_t, image3d_t and sampler_t arguments.
1322 if (TM.getTargetTriple().getArch() == Triple::r600)
1324
1325 // Make enqueued block runtime handles externally visible.
1327
1328 // Lower LDS accesses to global memory pass if address sanitizer is enabled.
1329 if (EnableSwLowerLDS)
1331
1332 // Runs before PromoteAlloca so the latter can account for function uses
1335 }
1336
1337 // Run atomic optimizer before Atomic Expand
1338 if ((TM.getTargetTriple().isAMDGCN()) &&
1339 (TM.getOptLevel() >= CodeGenOptLevel::Less) &&
1342 }
1343
1345
1346 if (TM.getOptLevel() > CodeGenOptLevel::None) {
1348
1351
1355 AAResults &AAR) {
1356 if (auto *WrapperPass = P.getAnalysisIfAvailable<AMDGPUAAWrapperPass>())
1357 AAR.addAAResult(WrapperPass->getResult());
1358 }));
1359 }
1360
1361 if (TM.getTargetTriple().isAMDGCN()) {
1362 // TODO: May want to move later or split into an early and late one.
1364 }
1365
1366 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
1367 // have expanded.
1368 if (TM.getOptLevel() > CodeGenOptLevel::Less)
1370 }
1371
1373
1374 // EarlyCSE is not always strong enough to clean up what LSR produces. For
1375 // example, GVN can combine
1376 //
1377 // %0 = add %a, %b
1378 // %1 = add %b, %a
1379 //
1380 // and
1381 //
1382 // %0 = shl nsw %a, 2
1383 // %1 = shl %a, 2
1384 //
1385 // but EarlyCSE can do neither of them.
1388}
1389
1391 if (TM->getTargetTriple().isAMDGCN() &&
1392 TM->getOptLevel() > CodeGenOptLevel::None)
1394
1395 if (TM->getTargetTriple().isAMDGCN() && EnableLowerKernelArguments)
1397
1399
1402
1403 if (TM->getTargetTriple().isAMDGCN()) {
1404 // This lowering has been placed after codegenprepare to take advantage of
1405 // address mode matching (which is why it isn't put with the LDS lowerings).
1406 // It could be placed anywhere before uniformity annotations (an analysis
1407 // that it changes by splitting up fat pointers into their components)
1408 // but has been put before switch lowering and CFG flattening so that those
1409 // passes can run on the more optimized control flow this pass creates in
1410 // many cases.
1413 // In accordance with the above FIXME, manually force all the
1414 // function-level passes into a CGSCCPassManager.
1415 addPass(new DummyCGSCCPass());
1416 }
1417
1418 // LowerSwitch pass may introduce unreachable blocks that can
1419 // cause unexpected behavior for subsequent passes. Placing it
1420 // here seems better that these blocks would get cleaned up by
1421 // UnreachableBlockElim inserted next in the pass flow.
1423}
1424
1426 if (TM->getOptLevel() > CodeGenOptLevel::None)
1428 return false;
1429}
1430
1435
1437 // Do nothing. GC is not supported.
1438 return false;
1439}
1440
1441//===----------------------------------------------------------------------===//
1442// GCN Legacy Pass Setup
1443//===----------------------------------------------------------------------===//
1444
1445bool GCNPassConfig::addPreISel() {
1447
1448 if (TM->getOptLevel() > CodeGenOptLevel::None)
1449 addPass(createSinkingPass());
1450
1451 if (TM->getOptLevel() > CodeGenOptLevel::None)
1453
1454 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
1455 // regions formed by them.
1457 addPass(createFixIrreduciblePass());
1458 addPass(createUnifyLoopExitsPass());
1459 addPass(createStructurizeCFGPass(false)); // true -> SkipUniformRegions
1460
1463 // TODO: Move this right after structurizeCFG to avoid extra divergence
1464 // analysis. This depends on stopping SIAnnotateControlFlow from making
1465 // control flow modifications.
1467
1468 // SDAG requires LCSSA, GlobalISel does not. Disable LCSSA for -global-isel
1469 // with -new-reg-bank-select and without any of the fallback options.
1471 !isGlobalISelAbortEnabled() || !NewRegBankSelect)
1472 addPass(createLCSSAPass());
1473
1474 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1476
1477 return false;
1478}
1479
1480void GCNPassConfig::addMachineSSAOptimization() {
1482
1483 // We want to fold operands after PeepholeOptimizer has run (or as part of
1484 // it), because it will eliminate extra copies making it easier to fold the
1485 // real source operand. We want to eliminate dead instructions after, so that
1486 // we see fewer uses of the copies. We then need to clean up the dead
1487 // instructions leftover after the operands are folded as well.
1488 //
1489 // XXX - Can we get away without running DeadMachineInstructionElim again?
1490 addPass(&SIFoldOperandsLegacyID);
1491 if (EnableDPPCombine)
1492 addPass(&GCNDPPCombineLegacyID);
1494 if (isPassEnabled(EnableSDWAPeephole)) {
1495 addPass(&SIPeepholeSDWALegacyID);
1496 addPass(&EarlyMachineLICMID);
1497 addPass(&MachineCSELegacyID);
1498 addPass(&SIFoldOperandsLegacyID);
1499 }
1502}
1503
1504bool GCNPassConfig::addILPOpts() {
1506 addPass(&EarlyIfConverterLegacyID);
1507
1509 return false;
1510}
1511
1512bool GCNPassConfig::addInstSelector() {
1514 addPass(&SIFixSGPRCopiesLegacyID);
1516 return false;
1517}
1518
1519bool GCNPassConfig::addIRTranslator() {
1520 addPass(new IRTranslator(getOptLevel()));
1521 return false;
1522}
1523
1524void GCNPassConfig::addPreLegalizeMachineIR() {
1525 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1526 addPass(createAMDGPUPreLegalizeCombiner(IsOptNone));
1527 addPass(new Localizer());
1528}
1529
1530bool GCNPassConfig::addLegalizeMachineIR() {
1531 addPass(new Legalizer());
1532 return false;
1533}
1534
1535void GCNPassConfig::addPreRegBankSelect() {
1536 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1537 addPass(createAMDGPUPostLegalizeCombiner(IsOptNone));
1539}
1540
1541bool GCNPassConfig::addRegBankSelect() {
1542 if (NewRegBankSelect) {
1545 } else {
1546 addPass(new RegBankSelect());
1547 }
1548 return false;
1549}
1550
1551void GCNPassConfig::addPreGlobalInstructionSelect() {
1552 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1553 addPass(createAMDGPURegBankCombiner(IsOptNone));
1554}
1555
1556bool GCNPassConfig::addGlobalInstructionSelect() {
1557 addPass(new InstructionSelect(getOptLevel()));
1558 return false;
1559}
1560
1561void GCNPassConfig::addFastRegAlloc() {
1562 // FIXME: We have to disable the verifier here because of PHIElimination +
1563 // TwoAddressInstructions disabling it.
1564
1565 // This must be run immediately after phi elimination and before
1566 // TwoAddressInstructions, otherwise the processing of the tied operand of
1567 // SI_ELSE will introduce a copy of the tied operand source after the else.
1569
1571
1573}
1574
1575void GCNPassConfig::addPreRegAlloc() {
1576 if (getOptLevel() != CodeGenOptLevel::None)
1578}
1579
1580void GCNPassConfig::addOptimizedRegAlloc() {
1581 if (EnableDCEInRA)
1583
1584 // FIXME: when an instruction has a Killed operand, and the instruction is
1585 // inside a bundle, seems only the BUNDLE instruction appears as the Kills of
1586 // the register in LiveVariables, this would trigger a failure in verifier,
1587 // we should fix it and enable the verifier.
1588 if (OptVGPRLiveRange)
1590
1591 // This must be run immediately after phi elimination and before
1592 // TwoAddressInstructions, otherwise the processing of the tied operand of
1593 // SI_ELSE will introduce a copy of the tied operand source after the else.
1595
1598
1599 if (isPassEnabled(EnablePreRAOptimizations))
1601
1602 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
1603 // instructions that cause scheduling barriers.
1605
1606 if (OptExecMaskPreRA)
1608
1609 // This is not an essential optimization and it has a noticeable impact on
1610 // compilation time, so we only enable it from O2.
1611 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1613
1615}
1616
1617bool GCNPassConfig::addPreRewrite() {
1619 addPass(&GCNNSAReassignID);
1620
1622 return true;
1623}
1624
1625FunctionPass *GCNPassConfig::createSGPRAllocPass(bool Optimized) {
1626 // Initialize the global default.
1627 llvm::call_once(InitializeDefaultSGPRRegisterAllocatorFlag,
1628 initializeDefaultSGPRRegisterAllocatorOnce);
1629
1630 RegisterRegAlloc::FunctionPassCtor Ctor = SGPRRegisterRegAlloc::getDefault();
1631 if (Ctor != useDefaultRegisterAllocator)
1632 return Ctor();
1633
1634 if (Optimized)
1635 return createGreedyRegisterAllocator(onlyAllocateSGPRs);
1636
1637 return createFastRegisterAllocator(onlyAllocateSGPRs, false);
1638}
1639
1640FunctionPass *GCNPassConfig::createVGPRAllocPass(bool Optimized) {
1641 // Initialize the global default.
1642 llvm::call_once(InitializeDefaultVGPRRegisterAllocatorFlag,
1643 initializeDefaultVGPRRegisterAllocatorOnce);
1644
1645 RegisterRegAlloc::FunctionPassCtor Ctor = VGPRRegisterRegAlloc::getDefault();
1646 if (Ctor != useDefaultRegisterAllocator)
1647 return Ctor();
1648
1649 if (Optimized)
1650 return createGreedyVGPRRegisterAllocator();
1651
1652 return createFastVGPRRegisterAllocator();
1653}
1654
1655FunctionPass *GCNPassConfig::createWWMRegAllocPass(bool Optimized) {
1656 // Initialize the global default.
1657 llvm::call_once(InitializeDefaultWWMRegisterAllocatorFlag,
1658 initializeDefaultWWMRegisterAllocatorOnce);
1659
1660 RegisterRegAlloc::FunctionPassCtor Ctor = WWMRegisterRegAlloc::getDefault();
1661 if (Ctor != useDefaultRegisterAllocator)
1662 return Ctor();
1663
1664 if (Optimized)
1665 return createGreedyWWMRegisterAllocator();
1666
1667 return createFastWWMRegisterAllocator();
1668}
1669
1670FunctionPass *GCNPassConfig::createRegAllocPass(bool Optimized) {
1671 llvm_unreachable("should not be used");
1672}
1673
1675 "-regalloc not supported with amdgcn. Use -sgpr-regalloc, -wwm-regalloc, "
1676 "and -vgpr-regalloc";
1677
1678bool GCNPassConfig::addRegAssignAndRewriteFast() {
1679 if (!usingDefaultRegAlloc())
1681
1682 addPass(&GCNPreRALongBranchRegID);
1683
1684 addPass(createSGPRAllocPass(false));
1685
1686 // Equivalent of PEI for SGPRs.
1687 addPass(&SILowerSGPRSpillsLegacyID);
1688
1689 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1691
1692 // For allocating other wwm register operands.
1693 addPass(createWWMRegAllocPass(false));
1694
1695 addPass(&SILowerWWMCopiesLegacyID);
1697
1698 // For allocating per-thread VGPRs.
1699 addPass(createVGPRAllocPass(false));
1700
1701 return true;
1702}
1703
1704bool GCNPassConfig::addRegAssignAndRewriteOptimized() {
1705 if (!usingDefaultRegAlloc())
1707
1708 addPass(&GCNPreRALongBranchRegID);
1709
1710 addPass(createSGPRAllocPass(true));
1711
1712 // Commit allocated register changes. This is mostly necessary because too
1713 // many things rely on the use lists of the physical registers, such as the
1714 // verifier. This is only necessary with allocators which use LiveIntervals,
1715 // since FastRegAlloc does the replacements itself.
1716 addPass(createVirtRegRewriter(false));
1717
1718 // At this point, the sgpr-regalloc has been done and it is good to have the
1719 // stack slot coloring to try to optimize the SGPR spill stack indices before
1720 // attempting the custom SGPR spill lowering.
1721 addPass(&StackSlotColoringID);
1722
1723 // Equivalent of PEI for SGPRs.
1724 addPass(&SILowerSGPRSpillsLegacyID);
1725
1726 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1728
1729 // For allocating other whole wave mode registers.
1730 addPass(createWWMRegAllocPass(true));
1731 addPass(&SILowerWWMCopiesLegacyID);
1732 addPass(createVirtRegRewriter(false));
1734
1735 // For allocating per-thread VGPRs.
1736 addPass(createVGPRAllocPass(true));
1737
1738 addPreRewrite();
1739 addPass(&VirtRegRewriterID);
1740
1742
1743 return true;
1744}
1745
1746void GCNPassConfig::addPostRegAlloc() {
1747 addPass(&SIFixVGPRCopiesID);
1748 if (getOptLevel() > CodeGenOptLevel::None)
1751}
1752
1753void GCNPassConfig::addPreSched2() {
1754 if (TM->getOptLevel() > CodeGenOptLevel::None)
1756 addPass(&SIPostRABundlerLegacyID);
1757}
1758
1759void GCNPassConfig::addPreEmitPass() {
1760 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less))
1761 addPass(&GCNCreateVOPDID);
1762 addPass(createSIMemoryLegalizerPass());
1763 addPass(createSIInsertWaitcntsPass());
1764
1765 addPass(createSIModeRegisterPass());
1766
1767 if (getOptLevel() > CodeGenOptLevel::None)
1768 addPass(&SIInsertHardClausesID);
1769
1771 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
1773 if (getOptLevel() > CodeGenOptLevel::None)
1774 addPass(&SIPreEmitPeepholeID);
1775 // The hazard recognizer that runs as part of the post-ra scheduler does not
1776 // guarantee to be able handle all hazards correctly. This is because if there
1777 // are multiple scheduling regions in a basic block, the regions are scheduled
1778 // bottom up, so when we begin to schedule a region we don't know what
1779 // instructions were emitted directly before it.
1780 //
1781 // Here we add a stand-alone hazard recognizer pass which can handle all
1782 // cases.
1783 addPass(&PostRAHazardRecognizerID);
1784
1786
1788
1789 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less))
1790 addPass(&AMDGPUInsertDelayAluID);
1791
1792 addPass(&BranchRelaxationPassID);
1793}
1794
1795void GCNPassConfig::addPostBBSections() {
1796 // We run this later to avoid passes like livedebugvalues and BBSections
1797 // having to deal with the apparent multi-entry functions we may generate.
1799}
1800
1802 return new GCNPassConfig(*this, PM);
1803}
1804
1810
1817
1821
1828
1831 SMDiagnostic &Error, SMRange &SourceRange) const {
1832 const yaml::SIMachineFunctionInfo &YamlMFI =
1833 static_cast<const yaml::SIMachineFunctionInfo &>(MFI_);
1834 MachineFunction &MF = PFS.MF;
1836 const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
1837
1838 if (MFI->initializeBaseYamlFields(YamlMFI, MF, PFS, Error, SourceRange))
1839 return true;
1840
1841 if (MFI->Occupancy == 0) {
1842 // Fixup the subtarget dependent default value.
1843 MFI->Occupancy = ST.getOccupancyWithWorkGroupSizes(MF).second;
1844 }
1845
1846 auto parseRegister = [&](const yaml::StringValue &RegName, Register &RegVal) {
1847 Register TempReg;
1848 if (parseNamedRegisterReference(PFS, TempReg, RegName.Value, Error)) {
1849 SourceRange = RegName.SourceRange;
1850 return true;
1851 }
1852 RegVal = TempReg;
1853
1854 return false;
1855 };
1856
1857 auto parseOptionalRegister = [&](const yaml::StringValue &RegName,
1858 Register &RegVal) {
1859 return !RegName.Value.empty() && parseRegister(RegName, RegVal);
1860 };
1861
1862 if (parseOptionalRegister(YamlMFI.VGPRForAGPRCopy, MFI->VGPRForAGPRCopy))
1863 return true;
1864
1865 if (parseOptionalRegister(YamlMFI.SGPRForEXECCopy, MFI->SGPRForEXECCopy))
1866 return true;
1867
1868 if (parseOptionalRegister(YamlMFI.LongBranchReservedReg,
1869 MFI->LongBranchReservedReg))
1870 return true;
1871
1872 auto diagnoseRegisterClass = [&](const yaml::StringValue &RegName) {
1873 // Create a diagnostic for a the register string literal.
1874 const MemoryBuffer &Buffer =
1875 *PFS.SM->getMemoryBuffer(PFS.SM->getMainFileID());
1876 Error = SMDiagnostic(*PFS.SM, SMLoc(), Buffer.getBufferIdentifier(), 1,
1877 RegName.Value.size(), SourceMgr::DK_Error,
1878 "incorrect register class for field", RegName.Value,
1879 {}, {});
1880 SourceRange = RegName.SourceRange;
1881 return true;
1882 };
1883
1884 if (parseRegister(YamlMFI.ScratchRSrcReg, MFI->ScratchRSrcReg) ||
1885 parseRegister(YamlMFI.FrameOffsetReg, MFI->FrameOffsetReg) ||
1886 parseRegister(YamlMFI.StackPtrOffsetReg, MFI->StackPtrOffsetReg))
1887 return true;
1888
1889 if (MFI->ScratchRSrcReg != AMDGPU::PRIVATE_RSRC_REG &&
1890 !AMDGPU::SGPR_128RegClass.contains(MFI->ScratchRSrcReg)) {
1891 return diagnoseRegisterClass(YamlMFI.ScratchRSrcReg);
1892 }
1893
1894 if (MFI->FrameOffsetReg != AMDGPU::FP_REG &&
1895 !AMDGPU::SGPR_32RegClass.contains(MFI->FrameOffsetReg)) {
1896 return diagnoseRegisterClass(YamlMFI.FrameOffsetReg);
1897 }
1898
1899 if (MFI->StackPtrOffsetReg != AMDGPU::SP_REG &&
1900 !AMDGPU::SGPR_32RegClass.contains(MFI->StackPtrOffsetReg)) {
1901 return diagnoseRegisterClass(YamlMFI.StackPtrOffsetReg);
1902 }
1903
1904 for (const auto &YamlReg : YamlMFI.WWMReservedRegs) {
1905 Register ParsedReg;
1906 if (parseRegister(YamlReg, ParsedReg))
1907 return true;
1908
1909 MFI->reserveWWMRegister(ParsedReg);
1910 }
1911
1912 for (const auto &[_, Info] : PFS.VRegInfosNamed) {
1913 MFI->setFlag(Info->VReg, Info->Flags);
1914 }
1915 for (const auto &[_, Info] : PFS.VRegInfos) {
1916 MFI->setFlag(Info->VReg, Info->Flags);
1917 }
1918
1919 for (const auto &YamlRegStr : YamlMFI.SpillPhysVGPRS) {
1920 Register ParsedReg;
1921 if (parseRegister(YamlRegStr, ParsedReg))
1922 return true;
1923 MFI->SpillPhysVGPRs.push_back(ParsedReg);
1924 }
1925
1926 auto parseAndCheckArgument = [&](const std::optional<yaml::SIArgument> &A,
1927 const TargetRegisterClass &RC,
1928 ArgDescriptor &Arg, unsigned UserSGPRs,
1929 unsigned SystemSGPRs) {
1930 // Skip parsing if it's not present.
1931 if (!A)
1932 return false;
1933
1934 if (A->IsRegister) {
1935 Register Reg;
1936 if (parseNamedRegisterReference(PFS, Reg, A->RegisterName.Value, Error)) {
1937 SourceRange = A->RegisterName.SourceRange;
1938 return true;
1939 }
1940 if (!RC.contains(Reg))
1941 return diagnoseRegisterClass(A->RegisterName);
1943 } else
1944 Arg = ArgDescriptor::createStack(A->StackOffset);
1945 // Check and apply the optional mask.
1946 if (A->Mask)
1947 Arg = ArgDescriptor::createArg(Arg, *A->Mask);
1948
1949 MFI->NumUserSGPRs += UserSGPRs;
1950 MFI->NumSystemSGPRs += SystemSGPRs;
1951 return false;
1952 };
1953
1954 if (YamlMFI.ArgInfo &&
1955 (parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentBuffer,
1956 AMDGPU::SGPR_128RegClass,
1957 MFI->ArgInfo.PrivateSegmentBuffer, 4, 0) ||
1958 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchPtr,
1959 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchPtr,
1960 2, 0) ||
1961 parseAndCheckArgument(YamlMFI.ArgInfo->QueuePtr, AMDGPU::SReg_64RegClass,
1962 MFI->ArgInfo.QueuePtr, 2, 0) ||
1963 parseAndCheckArgument(YamlMFI.ArgInfo->KernargSegmentPtr,
1964 AMDGPU::SReg_64RegClass,
1965 MFI->ArgInfo.KernargSegmentPtr, 2, 0) ||
1966 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchID,
1967 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchID,
1968 2, 0) ||
1969 parseAndCheckArgument(YamlMFI.ArgInfo->FlatScratchInit,
1970 AMDGPU::SReg_64RegClass,
1971 MFI->ArgInfo.FlatScratchInit, 2, 0) ||
1972 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentSize,
1973 AMDGPU::SGPR_32RegClass,
1974 MFI->ArgInfo.PrivateSegmentSize, 0, 0) ||
1975 parseAndCheckArgument(YamlMFI.ArgInfo->LDSKernelId,
1976 AMDGPU::SGPR_32RegClass,
1977 MFI->ArgInfo.LDSKernelId, 0, 1) ||
1978 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDX,
1979 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDX,
1980 0, 1) ||
1981 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDY,
1982 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDY,
1983 0, 1) ||
1984 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDZ,
1985 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDZ,
1986 0, 1) ||
1987 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupInfo,
1988 AMDGPU::SGPR_32RegClass,
1989 MFI->ArgInfo.WorkGroupInfo, 0, 1) ||
1990 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentWaveByteOffset,
1991 AMDGPU::SGPR_32RegClass,
1992 MFI->ArgInfo.PrivateSegmentWaveByteOffset, 0, 1) ||
1993 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitArgPtr,
1994 AMDGPU::SReg_64RegClass,
1995 MFI->ArgInfo.ImplicitArgPtr, 0, 0) ||
1996 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitBufferPtr,
1997 AMDGPU::SReg_64RegClass,
1998 MFI->ArgInfo.ImplicitBufferPtr, 2, 0) ||
1999 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDX,
2000 AMDGPU::VGPR_32RegClass,
2001 MFI->ArgInfo.WorkItemIDX, 0, 0) ||
2002 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDY,
2003 AMDGPU::VGPR_32RegClass,
2004 MFI->ArgInfo.WorkItemIDY, 0, 0) ||
2005 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDZ,
2006 AMDGPU::VGPR_32RegClass,
2007 MFI->ArgInfo.WorkItemIDZ, 0, 0)))
2008 return true;
2009
2010 if (ST.hasIEEEMode())
2011 MFI->Mode.IEEE = YamlMFI.Mode.IEEE;
2012 if (ST.hasDX10ClampMode())
2013 MFI->Mode.DX10Clamp = YamlMFI.Mode.DX10Clamp;
2014
2015 // FIXME: Move proper support for denormal-fp-math into base MachineFunction
2016 MFI->Mode.FP32Denormals.Input = YamlMFI.Mode.FP32InputDenormals
2019 MFI->Mode.FP32Denormals.Output = YamlMFI.Mode.FP32OutputDenormals
2022
2029
2030 if (YamlMFI.HasInitWholeWave)
2031 MFI->setInitWholeWave();
2032
2033 return false;
2034}
2035
2036//===----------------------------------------------------------------------===//
2037// AMDGPU CodeGen Pass Builder interface.
2038//===----------------------------------------------------------------------===//
2039
2040AMDGPUCodeGenPassBuilder::AMDGPUCodeGenPassBuilder(
2041 GCNTargetMachine &TM, const CGPassBuilderOption &Opts,
2043 : CodeGenPassBuilder(TM, Opts, PIC) {
2044 Opt.MISchedPostRA = true;
2045 Opt.RequiresCodeGenSCCOrder = true;
2046 // Exceptions and StackMaps are not supported, so these passes will never do
2047 // anything.
2048 // Garbage collection is not supported.
2049 disablePass<StackMapLivenessPass, FuncletLayoutPass,
2051}
2052
2053void AMDGPUCodeGenPassBuilder::addIRPasses(AddIRPass &addPass) const {
2054 if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN())
2056
2058 if (LowerCtorDtor)
2059 addPass(AMDGPUCtorDtorLoweringPass());
2060
2061 if (isPassEnabled(EnableImageIntrinsicOptimizer))
2063
2064 // This can be disabled by passing ::Disable here or on the command line
2065 // with --expand-variadics-override=disable.
2067
2068 addPass(AMDGPUAlwaysInlinePass());
2069 addPass(AlwaysInlinerPass());
2070
2072
2073 if (EnableSwLowerLDS)
2074 addPass(AMDGPUSwLowerLDSPass(TM));
2075
2076 // Runs before PromoteAlloca so the latter can account for function uses
2078 addPass(AMDGPULowerModuleLDSPass(TM));
2079
2080 // Run atomic optimizer before Atomic Expand
2081 if (TM.getOptLevel() >= CodeGenOptLevel::Less &&
2084
2085 addPass(AtomicExpandPass(&TM));
2086
2087 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2088 addPass(AMDGPUPromoteAllocaPass(TM));
2089 if (isPassEnabled(EnableScalarIRPasses))
2090 addStraightLineScalarOptimizationPasses(addPass);
2091
2092 // TODO: Handle EnableAMDGPUAliasAnalysis
2093
2094 // TODO: May want to move later or split into an early and late one.
2095 addPass(AMDGPUCodeGenPreparePass(TM));
2096
2097 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
2098 // have expanded.
2099 if (TM.getOptLevel() > CodeGenOptLevel::Less) {
2101 /*UseMemorySSA=*/true));
2102 }
2103 }
2104
2105 Base::addIRPasses(addPass);
2106
2107 // EarlyCSE is not always strong enough to clean up what LSR produces. For
2108 // example, GVN can combine
2109 //
2110 // %0 = add %a, %b
2111 // %1 = add %b, %a
2112 //
2113 // and
2114 //
2115 // %0 = shl nsw %a, 2
2116 // %1 = shl %a, 2
2117 //
2118 // but EarlyCSE can do neither of them.
2119 if (isPassEnabled(EnableScalarIRPasses))
2120 addEarlyCSEOrGVNPass(addPass);
2121}
2122
2123void AMDGPUCodeGenPassBuilder::addCodeGenPrepare(AddIRPass &addPass) const {
2124 if (TM.getOptLevel() > CodeGenOptLevel::None)
2126
2128 addPass(AMDGPULowerKernelArgumentsPass(TM));
2129
2130 Base::addCodeGenPrepare(addPass);
2131
2132 if (isPassEnabled(EnableLoadStoreVectorizer))
2133 addPass(LoadStoreVectorizerPass());
2134
2135 // This lowering has been placed after codegenprepare to take advantage of
2136 // address mode matching (which is why it isn't put with the LDS lowerings).
2137 // It could be placed anywhere before uniformity annotations (an analysis
2138 // that it changes by splitting up fat pointers into their components)
2139 // but has been put before switch lowering and CFG flattening so that those
2140 // passes can run on the more optimized control flow this pass creates in
2141 // many cases.
2143 addPass.requireCGSCCOrder();
2144
2145 addPass(AMDGPULowerIntrinsicsPass(TM));
2146
2147 // LowerSwitch pass may introduce unreachable blocks that can cause unexpected
2148 // behavior for subsequent passes. Placing it here seems better that these
2149 // blocks would get cleaned up by UnreachableBlockElim inserted next in the
2150 // pass flow.
2151 addPass(LowerSwitchPass());
2152}
2153
2154void AMDGPUCodeGenPassBuilder::addPreISel(AddIRPass &addPass) const {
2155
2156 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2157 addPass(FlattenCFGPass());
2158 addPass(SinkingPass());
2159 addPass(AMDGPULateCodeGenPreparePass(TM));
2160 }
2161
2162 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
2163 // regions formed by them.
2164
2166 addPass(FixIrreduciblePass());
2167 addPass(UnifyLoopExitsPass());
2168 addPass(StructurizeCFGPass(/*SkipUniformRegions=*/false));
2169
2171
2172 addPass(SIAnnotateControlFlowPass(TM));
2173
2174 // TODO: Move this right after structurizeCFG to avoid extra divergence
2175 // analysis. This depends on stopping SIAnnotateControlFlow from making
2176 // control flow modifications.
2178
2180 !isGlobalISelAbortEnabled() || !NewRegBankSelect)
2181 addPass(LCSSAPass());
2182
2183 if (TM.getOptLevel() > CodeGenOptLevel::Less)
2184 addPass(AMDGPUPerfHintAnalysisPass(TM));
2185
2186 // FIXME: Why isn't this queried as required from AMDGPUISelDAGToDAG, and why
2187 // isn't this in addInstSelector?
2189 /*Force=*/true);
2190}
2191
2192void AMDGPUCodeGenPassBuilder::addILPOpts(AddMachinePass &addPass) const {
2194 addPass(EarlyIfConverterPass());
2195
2196 Base::addILPOpts(addPass);
2197}
2198
2199void AMDGPUCodeGenPassBuilder::addAsmPrinter(AddMachinePass &addPass,
2200 CreateMCStreamer) const {
2201 // TODO: Add AsmPrinter.
2202}
2203
2204Error AMDGPUCodeGenPassBuilder::addInstSelector(AddMachinePass &addPass) const {
2205 addPass(AMDGPUISelDAGToDAGPass(TM));
2206 addPass(SIFixSGPRCopiesPass());
2207 addPass(SILowerI1CopiesPass());
2208 return Error::success();
2209}
2210
2211void AMDGPUCodeGenPassBuilder::addPreRewrite(AddMachinePass &addPass) const {
2212 if (EnableRegReassign) {
2213 addPass(GCNNSAReassignPass());
2214 }
2215}
2216
2217void AMDGPUCodeGenPassBuilder::addMachineSSAOptimization(
2218 AddMachinePass &addPass) const {
2219 Base::addMachineSSAOptimization(addPass);
2220
2221 addPass(SIFoldOperandsPass());
2222 if (EnableDPPCombine) {
2223 addPass(GCNDPPCombinePass());
2224 }
2225 addPass(SILoadStoreOptimizerPass());
2226 if (isPassEnabled(EnableSDWAPeephole)) {
2227 addPass(SIPeepholeSDWAPass());
2228 addPass(EarlyMachineLICMPass());
2229 addPass(MachineCSEPass());
2230 addPass(SIFoldOperandsPass());
2231 }
2233 addPass(SIShrinkInstructionsPass());
2234}
2235
2236void AMDGPUCodeGenPassBuilder::addOptimizedRegAlloc(
2237 AddMachinePass &addPass) const {
2238 if (EnableDCEInRA)
2239 insertPass<DetectDeadLanesPass>(DeadMachineInstructionElimPass());
2240
2241 // FIXME: when an instruction has a Killed operand, and the instruction is
2242 // inside a bundle, seems only the BUNDLE instruction appears as the Kills of
2243 // the register in LiveVariables, this would trigger a failure in verifier,
2244 // we should fix it and enable the verifier.
2245 if (OptVGPRLiveRange)
2246 insertPass<RequireAnalysisPass<LiveVariablesAnalysis, MachineFunction>>(
2248
2249 // This must be run immediately after phi elimination and before
2250 // TwoAddressInstructions, otherwise the processing of the tied operand of
2251 // SI_ELSE will introduce a copy of the tied operand source after the else.
2252 insertPass<PHIEliminationPass>(SILowerControlFlowPass());
2253
2255 insertPass<RenameIndependentSubregsPass>(GCNRewritePartialRegUsesPass());
2256
2257 if (isPassEnabled(EnablePreRAOptimizations))
2258 insertPass<MachineSchedulerPass>(GCNPreRAOptimizationsPass());
2259
2260 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
2261 // instructions that cause scheduling barriers.
2262 insertPass<MachineSchedulerPass>(SIWholeQuadModePass());
2263
2264 if (OptExecMaskPreRA)
2265 insertPass<MachineSchedulerPass>(SIOptimizeExecMaskingPreRAPass());
2266
2267 // This is not an essential optimization and it has a noticeable impact on
2268 // compilation time, so we only enable it from O2.
2269 if (TM.getOptLevel() > CodeGenOptLevel::Less)
2270 insertPass<MachineSchedulerPass>(SIFormMemoryClausesPass());
2271
2272 Base::addOptimizedRegAlloc(addPass);
2273}
2274
2275void AMDGPUCodeGenPassBuilder::addPreRegAlloc(AddMachinePass &addPass) const {
2276 if (getOptLevel() != CodeGenOptLevel::None)
2277 addPass(AMDGPUPrepareAGPRAllocPass());
2278}
2279
2280Error AMDGPUCodeGenPassBuilder::addRegAssignmentOptimized(
2281 AddMachinePass &addPass) const {
2282 // TODO: Check --regalloc-npm option
2283
2284 addPass(GCNPreRALongBranchRegPass());
2285
2286 addPass(RAGreedyPass({onlyAllocateSGPRs, "sgpr"}));
2287
2288 // Commit allocated register changes. This is mostly necessary because too
2289 // many things rely on the use lists of the physical registers, such as the
2290 // verifier. This is only necessary with allocators which use LiveIntervals,
2291 // since FastRegAlloc does the replacements itself.
2292 addPass(VirtRegRewriterPass(false));
2293
2294 // At this point, the sgpr-regalloc has been done and it is good to have the
2295 // stack slot coloring to try to optimize the SGPR spill stack indices before
2296 // attempting the custom SGPR spill lowering.
2297 addPass(StackSlotColoringPass());
2298
2299 // Equivalent of PEI for SGPRs.
2300 addPass(SILowerSGPRSpillsPass());
2301
2302 // To Allocate wwm registers used in whole quad mode operations (for shaders).
2303 addPass(SIPreAllocateWWMRegsPass());
2304
2305 // For allocating other wwm register operands.
2306 addPass(RAGreedyPass({onlyAllocateWWMRegs, "wwm"}));
2307 addPass(SILowerWWMCopiesPass());
2308 addPass(VirtRegRewriterPass(false));
2309 addPass(AMDGPUReserveWWMRegsPass());
2310
2311 // For allocating per-thread VGPRs.
2312 addPass(RAGreedyPass({onlyAllocateVGPRs, "vgpr"}));
2313
2314
2315 addPreRewrite(addPass);
2316 addPass(VirtRegRewriterPass(true));
2317
2319 return Error::success();
2320}
2321
2322void AMDGPUCodeGenPassBuilder::addPostRegAlloc(AddMachinePass &addPass) const {
2323 addPass(SIFixVGPRCopiesPass());
2324 if (TM.getOptLevel() > CodeGenOptLevel::None)
2325 addPass(SIOptimizeExecMaskingPass());
2326 Base::addPostRegAlloc(addPass);
2327}
2328
2329void AMDGPUCodeGenPassBuilder::addPreSched2(AddMachinePass &addPass) const {
2330 if (TM.getOptLevel() > CodeGenOptLevel::None)
2331 addPass(SIShrinkInstructionsPass());
2332 addPass(SIPostRABundlerPass());
2333}
2334
2335void AMDGPUCodeGenPassBuilder::addPreEmitPass(AddMachinePass &addPass) const {
2336 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less)) {
2337 addPass(GCNCreateVOPDPass());
2338 }
2339
2340 addPass(SIMemoryLegalizerPass());
2341 addPass(SIInsertWaitcntsPass());
2342
2343 // TODO: addPass(SIModeRegisterPass());
2344
2345 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2346 // TODO: addPass(SIInsertHardClausesPass());
2347 }
2348
2349 addPass(SILateBranchLoweringPass());
2350
2351 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
2352 addPass(AMDGPUSetWavePriorityPass());
2353
2354 if (TM.getOptLevel() > CodeGenOptLevel::None)
2355 addPass(SIPreEmitPeepholePass());
2356
2357 // The hazard recognizer that runs as part of the post-ra scheduler does not
2358 // guarantee to be able handle all hazards correctly. This is because if there
2359 // are multiple scheduling regions in a basic block, the regions are scheduled
2360 // bottom up, so when we begin to schedule a region we don't know what
2361 // instructions were emitted directly before it.
2362 //
2363 // Here we add a stand-alone hazard recognizer pass which can handle all
2364 // cases.
2365 addPass(PostRAHazardRecognizerPass());
2366 addPass(AMDGPUWaitSGPRHazardsPass());
2367 addPass(AMDGPULowerVGPREncodingPass());
2368
2369 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less)) {
2370 addPass(AMDGPUInsertDelayAluPass());
2371 }
2372
2373 addPass(BranchRelaxationPass());
2374}
2375
2376bool AMDGPUCodeGenPassBuilder::isPassEnabled(const cl::opt<bool> &Opt,
2377 CodeGenOptLevel Level) const {
2378 if (Opt.getNumOccurrences())
2379 return Opt;
2380 if (TM.getOptLevel() < Level)
2381 return false;
2382 return Opt;
2383}
2384
2385void AMDGPUCodeGenPassBuilder::addEarlyCSEOrGVNPass(AddIRPass &addPass) const {
2386 if (TM.getOptLevel() == CodeGenOptLevel::Aggressive)
2387 addPass(GVNPass());
2388 else
2389 addPass(EarlyCSEPass());
2390}
2391
2392void AMDGPUCodeGenPassBuilder::addStraightLineScalarOptimizationPasses(
2393 AddIRPass &addPass) const {
2395 addPass(LoopDataPrefetchPass());
2396
2398
2399 // ReassociateGEPs exposes more opportunities for SLSR. See
2400 // the example in reassociate-geps-and-slsr.ll.
2402
2403 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
2404 // EarlyCSE can reuse.
2405 addEarlyCSEOrGVNPass(addPass);
2406
2407 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
2408 addPass(NaryReassociatePass());
2409
2410 // NaryReassociate on GEPs creates redundant common expressions, so run
2411 // EarlyCSE after it.
2412 addPass(EarlyCSEPass());
2413}
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 cl::opt< bool > EnableUniformIntrinsicCombine("amdgpu-enable-uniform-intrinsic-combine", cl::desc("Enable/Disable the Uniform Intrinsic Combine Pass"), cl::init(true), cl::Hidden)
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:127
Pass to remove unused function declarations.
Definition GlobalDCE.h:38
This pass is responsible for selecting generic machine instructions to target-specific instructions.
A pass that internalizes all functions and variables other than those that must be preserved accordin...
Definition Internalize.h:37
Converts loops into loop-closed SSA form.
Definition LCSSA.h:38
Performs Loop Invariant Code Motion Pass.
Definition LICM.h:66
This pass implements the localization mechanism described at the top of this file.
Definition Localizer.h:43
An optimization pass inserting data prefetches in loops.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
void addDelegate(Delegate *delegate)
MachineSchedRegistry provides a selection of available machine instruction schedulers.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
static LLVM_ABI const OptimizationLevel O0
Disable as many optimizations as possible.
static LLVM_ABI const OptimizationLevel O1
Optimize quickly without destroying debuggability.
This class provides access to building LLVM's passes.
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same_v< PassT, PassManager > > addPass(PassT &&Pass)
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Pass interface - Implemented by all 'passes'.
Definition Pass.h:99
This pass implements the reg bank selector pass used in the GlobalISel pipeline.
RegisterPassParser class - Handle the addition of new machine passes.
RegisterRegAllocBase class - Track the registration of register allocators.
Wrapper class representing virtual and physical registers.
Definition Register.h:19
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
bool initializeBaseYamlFields(const yaml::SIMachineFunctionInfo &YamlMFI, const MachineFunction &MF, PerFunctionMIParsingState &PFS, SMDiagnostic &Error, SMRange &SourceRange)
void setFlag(Register Reg, uint8_t Flag)
bool checkFlag(Register Reg, uint8_t Flag) const
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition SourceMgr.h:282
Represents a location in source code.
Definition SMLoc.h:23
Represents a range in source code.
Definition SMLoc.h:48
A ScheduleDAG for scheduling lists of MachineInstr.
ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules machine instructions while...
ScheduleDAGMI is an implementation of ScheduleDAGInstrs that simply schedules machine instructions ac...
void addMutation(std::unique_ptr< ScheduleDAGMutation > Mutation)
Add a postprocessing step to the DAG builder.
const TargetInstrInfo * TII
Target instruction information.
const TargetRegisterInfo * TRI
Target processor register info.
Move instructions into successor blocks when possible.
Definition Sink.h:24
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
void append(StringRef RHS)
Append from a StringRef.
Definition SmallString.h:68
unsigned getMainFileID() const
Definition SourceMgr.h:133
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition SourceMgr.h:126
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:702
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:143
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition StringRef.h:637
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
StringSwitch & Cases(StringLiteral S0, StringLiteral S1, T Value)
Primary interface to the complete machine description for the target machine.
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with.
const Triple & getTargetTriple() const
const MCSubtargetInfo * getMCSubtargetInfo() const
StringRef getTargetFeatureString() const
StringRef getTargetCPU() const
std::unique_ptr< const MCSubtargetInfo > STI
TargetOptions Options
void resetTargetOptions(const Function &F) const
Reset the target options based on the function's attributes.
std::unique_ptr< const MCRegisterInfo > MRI
CodeGenOptLevel OptLevel
Target-Independent Code Generator Pass Configuration Options.
virtual void addCodeGenPrepare()
Add pass to prepare the LLVM IR for code generation.
virtual bool addILPOpts()
Add passes that optimize instruction level parallelism for out-of-order targets.
virtual void addPostRegAlloc()
This method may be implemented by targets that want to run passes after register allocation pass pipe...
CodeGenOptLevel getOptLevel() const
virtual void addOptimizedRegAlloc()
addOptimizedRegAlloc - Add passes related to register allocation.
virtual void addIRPasses()
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
virtual void addFastRegAlloc()
addFastRegAlloc - Add the minimum set of target-independent passes that are required for fast registe...
virtual void addMachineSSAOptimization()
addMachineSSAOptimization - Add standard passes that optimize machine instructions in SSA form.
void disablePass(AnalysisID PassID)
Allow the target to disable a specific standard pass by default.
AnalysisID addPass(AnalysisID PassID)
Utilities for targets to add passes to the pass manager.
TargetPassConfig(TargetMachine &TM, PassManagerBase &PM)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
LLVM Value Representation.
Definition Value.h:75
bool use_empty() const
Definition Value.h:346
int getNumOccurrences() const
An efficient, type-erasing, non-owning reference to a callable.
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
An abstract base class for streams implementations that also support a pwrite operation.
Interfaces for registering analysis passes, producing common pass manager configurations,...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ REGION_ADDRESS
Address space for region memory. (GDS)
@ LOCAL_ADDRESS
Address space for local memory.
@ CONSTANT_ADDRESS
Address space for constant memory (VTX2).
@ FLAT_ADDRESS
Address space for flat memory.
@ GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
@ PRIVATE_ADDRESS
Address space for private memory.
bool isFlatGlobalAddrSpace(unsigned AS)
LLVM_READNONE constexpr bool isModuleEntryFunctionCC(CallingConv::ID CC)
LLVM_READNONE constexpr bool isEntryFunctionCC(CallingConv::ID CC)
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
BinaryOp_match< SrcTy, SpecificConstantMatch, TargetOpcode::G_XOR, true > m_Not(const SrcTy &&Src)
Matches a register not-ed by a G_XOR.
BinaryOp_match< LHS, RHS, Instruction::And, true > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
bool match(Val *V, const Pattern &P)
IntrinsicID_match m_Intrinsic()
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
deferredval_ty< Value > m_Deferred(Value *const &V)
Like m_Specific(), but works if the specific value to match is determined as part of the same match()...
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
template class LLVM_TEMPLATE_ABI opt< bool >
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
LocationClass< Ty > location(Ty &L)
This is an optimization pass for GlobalISel generic memory operations.
ScheduleDAGMILive * createSchedLive(MachineSchedContext *C)
Create the standard converging machine scheduler.
LLVM_ABI FunctionPass * createFlattenCFGPass()
LLVM_ABI FunctionPass * createFastRegisterAllocator()
FastRegisterAllocation Pass - This pass register allocates as fast as possible.
LLVM_ABI char & EarlyMachineLICMID
This pass performs loop invariant code motion on machine instructions.
ImmutablePass * createAMDGPUAAWrapperPass()
LLVM_ABI char & PostRAHazardRecognizerID
PostRAHazardRecognizer - This pass runs the post-ra hazard recognizer.
std::function< bool(const TargetRegisterInfo &TRI, const MachineRegisterInfo &MRI, const Register Reg)> RegAllocFilterFunc
Filter function for register classes during regalloc.
FunctionPass * createAMDGPUSetWavePriorityPass()
LLVM_ABI Pass * createLCSSAPass()
Definition LCSSA.cpp:525
void initializeAMDGPUMarkLastScratchLoadLegacyPass(PassRegistry &)
void initializeAMDGPUInsertDelayAluLegacyPass(PassRegistry &)
void initializeSIOptimizeExecMaskingPreRALegacyPass(PassRegistry &)
char & GCNPreRAOptimizationsID
LLVM_ABI char & GCLoweringID
GCLowering Pass - Used by gc.root to perform its default lowering operations.
void initializeSIInsertHardClausesLegacyPass(PassRegistry &)
ModulePass * createExpandVariadicsPass(ExpandVariadicsMode)
FunctionPass * createSIAnnotateControlFlowLegacyPass()
Create the annotation pass.
FunctionPass * createSIModeRegisterPass()
void initializeGCNPreRAOptimizationsLegacyPass(PassRegistry &)
void initializeSILowerWWMCopiesLegacyPass(PassRegistry &)
LLVM_ABI FunctionPass * createGreedyRegisterAllocator()
Greedy register allocation pass - This pass implements a global register allocator for optimized buil...
void initializeAMDGPUAAWrapperPassPass(PassRegistry &)
void initializeSIShrinkInstructionsLegacyPass(PassRegistry &)
ModulePass * createAMDGPULowerBufferFatPointersPass()
void initializeR600ClauseMergePassPass(PassRegistry &)
ModulePass * createAMDGPUCtorDtorLoweringLegacyPass()
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:644
ModuleToFunctionPassAdaptor createModuleToFunctionPassAdaptor(FunctionPassT &&Pass, bool EagerlyInvalidate=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
ModulePass * createAMDGPUSwLowerLDSLegacyPass(const AMDGPUTargetMachine *TM=nullptr)
void initializeGCNRewritePartialRegUsesLegacyPass(llvm::PassRegistry &)
void initializeAMDGPURewriteUndefForPHILegacyPass(PassRegistry &)
char & GCNRewritePartialRegUsesID
void initializeAMDGPUSwLowerLDSLegacyPass(PassRegistry &)
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:98
void initializeAMDGPULowerVGPREncodingLegacyPass(PassRegistry &)
char & AMDGPUWaitSGPRHazardsLegacyID
void initializeSILowerSGPRSpillsLegacyPass(PassRegistry &)
LLVM_ABI Pass * createLoadStoreVectorizerPass()
Create a legacy pass manager instance of the LoadStoreVectorizer pass.
std::unique_ptr< ScheduleDAGMutation > createIGroupLPDAGMutation(AMDGPU::SchedulingPhase Phase)
Phase specifes whether or not this is a reentry into the IGroupLPDAGMutation.
void initializeAMDGPUDAGToDAGISelLegacyPass(PassRegistry &)
FunctionPass * createAMDGPURegBankCombiner(bool IsOptNone)
LLVM_ABI FunctionPass * createNaryReassociatePass()
char & AMDGPUReserveWWMRegsLegacyID
void initializeAMDGPUWaitSGPRHazardsLegacyPass(PassRegistry &)
LLVM_ABI char & PatchableFunctionID
This pass implements the "patchable-function" attribute.
char & SIOptimizeExecMaskingLegacyID
LLVM_ABI char & PostRASchedulerID
PostRAScheduler - This pass performs post register allocation scheduling.
void initializeR600ExpandSpecialInstrsPassPass(PassRegistry &)
void initializeR600PacketizerPass(PassRegistry &)
std::unique_ptr< ScheduleDAGMutation > createVOPDPairingMutation()
ModulePass * createAMDGPUExportKernelRuntimeHandlesLegacyPass()
ModulePass * createAMDGPUAlwaysInlinePass(bool GlobalOpt=true)
void initializeAMDGPUAsmPrinterPass(PassRegistry &)
void initializeSIFoldOperandsLegacyPass(PassRegistry &)
char & SILoadStoreOptimizerLegacyID
void initializeAMDGPUGlobalISelDivergenceLoweringPass(PassRegistry &)
PassManager< LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, CGSCCUpdateResult & > CGSCCPassManager
The CGSCC pass manager.
LLVM_ABI std::unique_ptr< CSEConfigBase > getStandardCSEConfigForOpt(CodeGenOptLevel Level)
Definition CSEInfo.cpp:89
Target & getTheR600Target()
The target for R600 GPUs.
LLVM_ABI char & MachineSchedulerID
MachineScheduler - This pass schedules machine instructions.
LLVM_ABI Pass * createStructurizeCFGPass(bool SkipUniformRegions=false)
When SkipUniformRegions is true the structizer will not structurize regions that only contain uniform...
LLVM_ABI char & PostMachineSchedulerID
PostMachineScheduler - This pass schedules machine instructions postRA.
LLVM_ABI Pass * createLICMPass()
Definition LICM.cpp:388
char & SIFormMemoryClausesID
void initializeSILoadStoreOptimizerLegacyPass(PassRegistry &)
void initializeAMDGPULowerModuleLDSLegacyPass(PassRegistry &)
AnalysisManager< LazyCallGraph::SCC, LazyCallGraph & > CGSCCAnalysisManager
The CGSCC analysis manager.
void initializeAMDGPUCtorDtorLoweringLegacyPass(PassRegistry &)
LLVM_ABI char & EarlyIfConverterLegacyID
EarlyIfConverter - This pass performs if-conversion on SSA form by inserting cmov instructions.
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
void initializeAMDGPURegBankCombinerPass(PassRegistry &)
ThinOrFullLTOPhase
This enumerates the LLVM full LTO or ThinLTO optimization phases.
Definition Pass.h:77
@ FullLTOPreLink
Full LTO prelink phase.
Definition Pass.h:85
@ FullLTOPostLink
Full LTO postlink (backend compile) phase.
Definition Pass.h:87
@ ThinLTOPreLink
ThinLTO prelink (summary) phase.
Definition Pass.h:81
char & AMDGPUUnifyDivergentExitNodesID
void initializeAMDGPUPrepareAGPRAllocLegacyPass(PassRegistry &)
FunctionPass * createAMDGPUAtomicOptimizerPass(ScanOptions ScanStrategy)
FunctionPass * createAMDGPUPreloadKernArgPrologLegacyPass()
char & SIOptimizeVGPRLiveRangeLegacyID
LLVM_ABI char & ShadowStackGCLoweringID
ShadowStackGCLowering - Implements the custom lowering mechanism used by the shadow stack GC.
char & GCNNSAReassignID
void initializeAMDGPURewriteOutArgumentsPass(PassRegistry &)
static Reloc::Model getEffectiveRelocModel(std::optional< Reloc::Model > RM)
void initializeAMDGPUExternalAAWrapperPass(PassRegistry &)
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
void initializeAMDGPULowerKernelArgumentsPass(PassRegistry &)
FunctionToLoopPassAdaptor createFunctionToLoopPassAdaptor(LoopPassT &&Pass, bool UseMemorySSA=false, bool UseBlockFrequencyInfo=false)
A function to deduce a loop pass type and wrap it in the templated adaptor.
void initializeSIModeRegisterLegacyPass(PassRegistry &)
CodeModel::Model getEffectiveCodeModel(std::optional< CodeModel::Model > CM, CodeModel::Model Default)
Helper method for getting the code model, returning Default if CM does not have a value.
void initializeAMDGPUPreloadKernelArgumentsLegacyPass(PassRegistry &)
char & SILateBranchLoweringPassID
LLVM_ABI char & BranchRelaxationPassID
BranchRelaxation - This pass replaces branches that need to jump further than is supported by a branc...
LLVM_ABI FunctionPass * createSinkingPass()
Definition Sink.cpp:275
CGSCCToFunctionPassAdaptor createCGSCCToFunctionPassAdaptor(FunctionPassT &&Pass, bool EagerlyInvalidate=false, bool NoRerun=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
void initializeSIMemoryLegalizerLegacyPass(PassRegistry &)
ModulePass * createAMDGPULowerIntrinsicsLegacyPass()
void initializeR600MachineCFGStructurizerPass(PassRegistry &)
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition CodeGen.h:111
char & GCNDPPCombineLegacyID
PassManager< Module > ModulePassManager
Convenience typedef for a pass manager over modules.
LLVM_ABI std::unique_ptr< ScheduleDAGMutation > createStoreClusterDAGMutation(const TargetInstrInfo *TII, const TargetRegisterInfo *TRI, bool ReorderWhileClustering=false)
If ReorderWhileClustering is set to true, no attempt will be made to reduce reordering due to store c...
LLVM_ABI FunctionPass * createLoopDataPrefetchPass()
FunctionPass * createAMDGPULowerKernelArgumentsPass()
char & AMDGPUInsertDelayAluID
std::unique_ptr< ScheduleDAGMutation > createAMDGPUMacroFusionDAGMutation()
Note that you have to add: DAG.addMutation(createAMDGPUMacroFusionDAGMutation()); to AMDGPUTargetMach...
LLVM_ABI char & StackMapLivenessID
StackMapLiveness - This pass analyses the register live-out set of stackmap/patchpoint intrinsics and...
void initializeGCNPreRALongBranchRegLegacyPass(PassRegistry &)
char & SILowerWWMCopiesLegacyID
LLVM_ABI FunctionPass * createUnifyLoopExitsPass()
char & SIOptimizeExecMaskingPreRAID
LLVM_ABI FunctionPass * createFixIrreduciblePass()
void initializeR600EmitClauseMarkersPass(PassRegistry &)
LLVM_ABI char & FuncletLayoutID
This pass lays out funclets contiguously.
LLVM_ABI char & DetectDeadLanesID
This pass adds dead/undef flags after analyzing subregister lanes.
void initializeAMDGPUPostLegalizerCombinerPass(PassRegistry &)
void initializeAMDGPUExportKernelRuntimeHandlesLegacyPass(PassRegistry &)
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:82
void initializeSIInsertWaitcntsLegacyPass(PassRegistry &)
ModulePass * createAMDGPUPreloadKernelArgumentsLegacyPass(const TargetMachine *)
ModulePass * createAMDGPUPrintfRuntimeBinding()
LLVM_ABI char & StackSlotColoringID
StackSlotColoring - This pass performs stack slot coloring.
LLVM_ABI Pass * createAlwaysInlinerLegacyPass(bool InsertLifetime=true)
Create a legacy pass manager instance of a pass to inline and remove functions marked as "always_inli...
void initializeR600ControlFlowFinalizerPass(PassRegistry &)
void initializeAMDGPUImageIntrinsicOptimizerPass(PassRegistry &)
void initializeSILateBranchLoweringLegacyPass(PassRegistry &)
void initializeSILowerControlFlowLegacyPass(PassRegistry &)
void initializeSIFormMemoryClausesLegacyPass(PassRegistry &)
char & SIPreAllocateWWMRegsLegacyID
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
ModulePass * createAMDGPULowerModuleLDSLegacyPass(const AMDGPUTargetMachine *TM=nullptr)
void initializeAMDGPUPreLegalizerCombinerPass(PassRegistry &)
FunctionPass * createAMDGPUPromoteAlloca()
LLVM_ABI FunctionPass * createSeparateConstOffsetFromGEPPass(bool LowerGEP=false)
void initializeAMDGPUReserveWWMRegsLegacyPass(PassRegistry &)
char & SIPreEmitPeepholeID
char & SIPostRABundlerLegacyID
ModulePass * createAMDGPURemoveIncompatibleFunctionsPass(const TargetMachine *)
void initializeGCNRegPressurePrinterPass(PassRegistry &)
void initializeSILowerI1CopiesLegacyPass(PassRegistry &)
char & SILowerSGPRSpillsLegacyID
void initializeAMDGPUArgumentUsageInfoPass(PassRegistry &)
LLVM_ABI FunctionPass * createBasicRegisterAllocator()
BasicRegisterAllocation Pass - This pass implements a degenerate global register allocator using the ...
LLVM_ABI void initializeGlobalISel(PassRegistry &)
Initialize all passes linked into the GlobalISel library.
char & SILowerControlFlowLegacyID
ModulePass * createR600OpenCLImageTypeLoweringPass()
FunctionPass * createAMDGPUCodeGenPreparePass()
void initializeSIAnnotateControlFlowLegacyPass(PassRegistry &)
FunctionPass * createAMDGPUISelDag(TargetMachine &TM, CodeGenOptLevel OptLevel)
This pass converts a legalized DAG into a AMDGPU-specific.
void initializeGCNCreateVOPDLegacyPass(PassRegistry &)
void initializeSIPreAllocateWWMRegsLegacyPass(PassRegistry &)
void initializeSIFixVGPRCopiesLegacyPass(PassRegistry &)
Target & getTheGCNTarget()
The target for GCN GPUs.
void initializeSIFixSGPRCopiesLegacyPass(PassRegistry &)
void initializeAMDGPUAtomicOptimizerPass(PassRegistry &)
void initializeAMDGPULowerIntrinsicsLegacyPass(PassRegistry &)
LLVM_ABI FunctionPass * createGVNPass()
Create a legacy GVN pass.
Definition GVN.cpp:3483
void initializeAMDGPURewriteAGPRCopyMFMALegacyPass(PassRegistry &)
void initializeSIPostRABundlerLegacyPass(PassRegistry &)
FunctionPass * createAMDGPURegBankSelectPass()
FunctionPass * createAMDGPURegBankLegalizePass()
LLVM_ABI char & MachineCSELegacyID
MachineCSE - This pass performs global CSE on machine instructions.
char & SIWholeQuadModeID
LLVM_ABI std::unique_ptr< ScheduleDAGMutation > createLoadClusterDAGMutation(const TargetInstrInfo *TII, const TargetRegisterInfo *TRI, bool ReorderWhileClustering=false)
If ReorderWhileClustering is set to true, no attempt will be made to reduce reordering due to store c...
PassManager< Function > FunctionPassManager
Convenience typedef for a pass manager over functions.
LLVM_ABI char & LiveVariablesID
LiveVariables pass - This pass computes the set of blocks in which each variable is life and sets mac...
void initializeAMDGPUCodeGenPreparePass(PassRegistry &)
FunctionPass * createAMDGPURewriteUndefForPHILegacyPass()
void initializeSIOptimizeExecMaskingLegacyPass(PassRegistry &)
void call_once(once_flag &flag, Function &&F, Args &&... ArgList)
Execute the function specified as a parameter once.
Definition Threading.h:86
FunctionPass * createSILowerI1CopiesLegacyPass()
FunctionPass * createAMDGPUPostLegalizeCombiner(bool IsOptNone)
void initializeAMDGPULowerKernelAttributesPass(PassRegistry &)
char & SIInsertHardClausesID
char & SIFixSGPRCopiesLegacyID
void initializeGCNDPPCombineLegacyPass(PassRegistry &)
char & GCNCreateVOPDID
char & SIPeepholeSDWALegacyID
LLVM_ABI char & VirtRegRewriterID
VirtRegRewriter pass.
char & SIFixVGPRCopiesID
char & SIFoldOperandsLegacyID
void initializeGCNNSAReassignLegacyPass(PassRegistry &)
char & AMDGPUPrepareAGPRAllocLegacyID
LLVM_ABI FunctionPass * createLowerSwitchPass()
void initializeAMDGPUPreloadKernArgPrologLegacyPass(PassRegistry &)
LLVM_ABI FunctionPass * createVirtRegRewriter(bool ClearVirtRegs=true)
void initializeR600VectorRegMergerPass(PassRegistry &)
char & AMDGPURewriteAGPRCopyMFMALegacyID
char & AMDGPULowerVGPREncodingLegacyID
FunctionPass * createAMDGPUGlobalISelDivergenceLoweringPass()
FunctionPass * createSIMemoryLegalizerPass()
void initializeAMDGPULateCodeGenPrepareLegacyPass(PassRegistry &)
void initializeSIOptimizeVGPRLiveRangeLegacyPass(PassRegistry &)
void initializeSIPeepholeSDWALegacyPass(PassRegistry &)
void initializeAMDGPURegBankLegalizePass(PassRegistry &)
LLVM_ABI char & TwoAddressInstructionPassID
TwoAddressInstruction - This pass reduces two-address instructions to use two operands.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
FunctionPass * createAMDGPUPreLegalizeCombiner(bool IsOptNone)
void initializeAMDGPURegBankSelectPass(PassRegistry &)
FunctionPass * createAMDGPULateCodeGenPrepareLegacyPass()
LLVM_ABI FunctionPass * createAtomicExpandLegacyPass()
AtomicExpandPass - At IR level this pass replace atomic instructions with __atomic_* library calls,...
MCRegisterInfo * createGCNMCRegisterInfo(AMDGPUDwarfFlavour DwarfFlavour)
LLVM_ABI FunctionPass * createStraightLineStrengthReducePass()
FunctionPass * createAMDGPUImageIntrinsicOptimizerPass(const TargetMachine *)
void initializeAMDGPUUnifyDivergentExitNodesPass(PassRegistry &)
void initializeAMDGPULowerBufferFatPointersPass(PassRegistry &)
FunctionPass * createSIInsertWaitcntsPass()
FunctionPass * createAMDGPUAnnotateUniformValuesLegacy()
LLVM_ABI FunctionPass * createEarlyCSEPass(bool UseMemorySSA=false)
void initializeSIWholeQuadModeLegacyPass(PassRegistry &)
LLVM_ABI char & PHIEliminationID
PHIElimination - This pass eliminates machine instruction PHI nodes by inserting copy instructions.
LLVM_ABI llvm::cl::opt< bool > NoKernelInfoEndLTO
bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
void initializeAMDGPUResourceUsageAnalysisWrapperPassPass(PassRegistry &)
FunctionPass * createSIShrinkInstructionsLegacyPass()
char & AMDGPUMarkLastScratchLoadID
LLVM_ABI char & RenameIndependentSubregsID
This pass detects subregister lanes in a virtual register that are used independently of other lanes ...
void initializeAMDGPUAnnotateUniformValuesLegacyPass(PassRegistry &)
std::unique_ptr< ScheduleDAGMutation > createAMDGPUExportClusteringDAGMutation()
void initializeAMDGPUPrintfRuntimeBindingPass(PassRegistry &)
void initializeAMDGPUPromoteAllocaPass(PassRegistry &)
void initializeAMDGPURemoveIncompatibleFunctionsLegacyPass(PassRegistry &)
void initializeAMDGPUAlwaysInlinePass(PassRegistry &)
LLVM_ABI char & DeadMachineInstructionElimID
DeadMachineInstructionElim - This pass removes dead machine instructions.
void initializeSIPreEmitPeepholeLegacyPass(PassRegistry &)
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
char & AMDGPUPerfHintAnalysisLegacyID
LLVM_ABI ImmutablePass * createExternalAAWrapperPass(std::function< void(Pass &, Function &, AAResults &)> Callback)
A wrapper pass around a callback which can be used to populate the AAResults in the AAResultsWrapperP...
char & GCNPreRALongBranchRegID
LLVM_ABI CGPassBuilderOption getCGPassBuilderOption()
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:180
void initializeAMDGPUPromoteKernelArgumentsPass(PassRegistry &)
#define N
static ArgDescriptor createStack(unsigned Offset, unsigned Mask=~0u)
static ArgDescriptor createArg(const ArgDescriptor &Arg, unsigned Mask)
static ArgDescriptor createRegister(Register Reg, unsigned Mask=~0u)
DenormalModeKind Input
Denormal treatment kind for floating point instruction inputs in the default floating-point environme...
@ PreserveSign
The sign of a flushed-to-zero number is preserved in the sign of 0.
@ IEEE
IEEE-754 denormal numbers preserved.
DenormalModeKind Output
Denormal flushing mode for floating point instruction results in the default floating point environme...
A simple and fast domtree-based CSE pass.
Definition EarlyCSE.h:31
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
static FuncInfoTy * create(BumpPtrAllocator &Allocator, const Function &F, const SubtargetTy *STI)
Factory function: default behavior is to call new using the supplied allocator.
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
StringMap< VRegInfo * > VRegInfosNamed
Definition MIParser.h:177
DenseMap< Register, VRegInfo * > VRegInfos
Definition MIParser.h:176
RegisterTargetMachine - Helper template for registering a target machine implementation,...
A utility pass template to force an analysis result to be available.
bool DX10Clamp
Used by the vector ALU to force DX10-style treatment of NaNs: when set, clamp NaN to zero; otherwise,...
DenormalMode FP64FP16Denormals
If this is set, neither input or output denormals are flushed for both f64 and f16/v2f16 instructions...
bool IEEE
Floating point opcodes that support exception flag gathering quiet and propagate signaling NaN inputs...
DenormalMode FP32Denormals
If this is set, neither input or output denormals are flushed for most f32 instructions.
The llvm::once_flag structure.
Definition Threading.h:67
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.
SmallVector< StringValue > WWMReservedRegs
std::optional< SIArgumentInfo > ArgInfo
SmallVector< StringValue, 2 > SpillPhysVGPRS
A wrapper around std::string which contains a source range that's being set during parsing.