LLVM 24.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"
20#include "AMDGPUAsmPrinter.h"
26#include "AMDGPUHazardLatency.h"
27#include "AMDGPUIGroupLP.h"
28#include "AMDGPUISelDAGToDAG.h"
30#include "AMDGPUMacroFusion.h"
38#include "AMDGPUSplitModule.h"
43#include "GCNDPPCombine.h"
45#include "GCNNSAReassign.h"
49#include "GCNSchedStrategy.h"
50#include "GCNVOPDUtils.h"
51#include "R600.h"
52#include "R600TargetMachine.h"
53#include "SIFixSGPRCopies.h"
54#include "SIFixVGPRCopies.h"
55#include "SIFoldOperands.h"
56#include "SIFormMemoryClauses.h"
58#include "SILowerControlFlow.h"
59#include "SILowerSGPRSpills.h"
60#include "SILowerWWMCopies.h"
62#include "SIMachineScheduler.h"
66#include "SIPeepholeSDWA.h"
67#include "SIPostRABundler.h"
70#include "SIWholeQuadMode.h"
91#include "llvm/CodeGen/Passes.h"
96#include "llvm/IR/IntrinsicsAMDGPU.h"
97#include "llvm/IR/Module.h"
98#include "llvm/IR/PassManager.h"
108#include "llvm/Transforms/IPO.h"
133#include <optional>
134
135using namespace llvm;
136using namespace llvm::PatternMatch;
137
138namespace {
139//===----------------------------------------------------------------------===//
140// AMDGPU CodeGen Pass Builder interface.
141//===----------------------------------------------------------------------===//
142
143class AMDGPUCodeGenPassBuilder
144 : public CodeGenPassBuilder<AMDGPUCodeGenPassBuilder, GCNTargetMachine> {
145 using Base = CodeGenPassBuilder<AMDGPUCodeGenPassBuilder, GCNTargetMachine>;
146
147public:
148 AMDGPUCodeGenPassBuilder(GCNTargetMachine &TM,
149 const CGPassBuilderOption &Opts,
150 PassInstrumentationCallbacks *PIC);
151
152 void addIRPasses(PassManagerWrapper &PMW) const;
153 void addCodeGenPrepare(PassManagerWrapper &PMW) const;
154 void addPreISel(PassManagerWrapper &PMW) const;
155 void addILPOpts(PassManagerWrapper &PMWM) const;
156 void addAsmPrinterBegin(PassManagerWrapper &PMW) const;
157 void addAsmPrinter(PassManagerWrapper &PMW) const;
158 void addAsmPrinterEnd(PassManagerWrapper &PMW) const;
159 Error addInstSelector(PassManagerWrapper &PMW) const;
160 void addPreRewrite(PassManagerWrapper &PMW) const;
161 void addMachineSSAOptimization(PassManagerWrapper &PMW) const;
162 void addPostRegAlloc(PassManagerWrapper &PMW) const;
163 void addPreEmitPass(PassManagerWrapper &PMWM) const;
164 void addPreEmitRegAlloc(PassManagerWrapper &PMW) const;
165 Error addRegAssignmentFast(PassManagerWrapper &PMW) const;
166 Error addRegAssignmentOptimized(PassManagerWrapper &PMW) const;
167 void addPreRegAlloc(PassManagerWrapper &PMW) const;
168 Error addFastRegAlloc(PassManagerWrapper &PMW) const;
169 Error addOptimizedRegAlloc(PassManagerWrapper &PMW) const;
170 void addPreSched2(PassManagerWrapper &PMW) const;
171 void addPostBBSections(PassManagerWrapper &PMW) const;
172
173private:
174 Error validateRegAllocOptions() const;
175
176public:
177 /// Check if a pass is enabled given \p Opt option. The option always
178 /// overrides defaults if explicitly used. Otherwise its default will be used
179 /// given that a pass shall work at an optimization \p Level minimum.
180 bool isPassEnabled(const cl::opt<bool> &Opt,
181 CodeGenOptLevel Level = CodeGenOptLevel::Default) const;
182 void addEarlyCSEOrGVNPass(PassManagerWrapper &PMW) const;
183 void addStraightLineScalarOptimizationPasses(PassManagerWrapper &PMW) const;
184};
185
186class SGPRRegisterRegAlloc : public RegisterRegAllocBase<SGPRRegisterRegAlloc> {
187public:
188 SGPRRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
189 : RegisterRegAllocBase(N, D, C) {}
190};
191
192class VGPRRegisterRegAlloc : public RegisterRegAllocBase<VGPRRegisterRegAlloc> {
193public:
194 VGPRRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
195 : RegisterRegAllocBase(N, D, C) {}
196};
197
198class WWMRegisterRegAlloc : public RegisterRegAllocBase<WWMRegisterRegAlloc> {
199public:
200 WWMRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
201 : RegisterRegAllocBase(N, D, C) {}
202};
203
204static bool onlyAllocateSGPRs(const TargetRegisterInfo &TRI,
205 const MachineRegisterInfo &MRI,
206 const Register Reg) {
207 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
208 return static_cast<const SIRegisterInfo &>(TRI).isSGPRClass(RC);
209}
210
211static bool onlyAllocateVGPRs(const TargetRegisterInfo &TRI,
212 const MachineRegisterInfo &MRI,
213 const Register Reg) {
214 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
215 return !static_cast<const SIRegisterInfo &>(TRI).isSGPRClass(RC);
216}
217
218static bool onlyAllocateWWMRegs(const TargetRegisterInfo &TRI,
219 const MachineRegisterInfo &MRI,
220 const Register Reg) {
221 const SIMachineFunctionInfo *MFI =
223 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
224 return !static_cast<const SIRegisterInfo &>(TRI).isSGPRClass(RC) &&
226}
227
228/// -{sgpr|wwm|vgpr}-regalloc=... command line option.
229static FunctionPass *useDefaultRegisterAllocator() { return nullptr; }
230
231/// A dummy default pass factory indicates whether the register allocator is
232/// overridden on the command line.
233static llvm::once_flag InitializeDefaultSGPRRegisterAllocatorFlag;
234static llvm::once_flag InitializeDefaultVGPRRegisterAllocatorFlag;
235static llvm::once_flag InitializeDefaultWWMRegisterAllocatorFlag;
236
237static SGPRRegisterRegAlloc
238defaultSGPRRegAlloc("default",
239 "pick SGPR register allocator based on -O option",
241
242static cl::opt<SGPRRegisterRegAlloc::FunctionPassCtor, false,
244SGPRRegAlloc("sgpr-regalloc", cl::Hidden, cl::init(&useDefaultRegisterAllocator),
245 cl::desc("Register allocator to use for SGPRs"));
246
247static cl::opt<VGPRRegisterRegAlloc::FunctionPassCtor, false,
249VGPRRegAlloc("vgpr-regalloc", cl::Hidden, cl::init(&useDefaultRegisterAllocator),
250 cl::desc("Register allocator to use for VGPRs"));
251
252static cl::opt<WWMRegisterRegAlloc::FunctionPassCtor, false,
254 WWMRegAlloc("wwm-regalloc", cl::Hidden,
256 cl::desc("Register allocator to use for WWM registers"));
257
258// New pass manager register allocator options for AMDGPU
260 "sgpr-regalloc-npm", cl::Hidden, cl::init(RegAllocType::Default),
261 cl::desc("Register allocator for SGPRs (new pass manager)"));
262
264 "vgpr-regalloc-npm", cl::Hidden, cl::init(RegAllocType::Default),
265 cl::desc("Register allocator for VGPRs (new pass manager)"));
266
268 "wwm-regalloc-npm", cl::Hidden, cl::init(RegAllocType::Default),
269 cl::desc("Register allocator for WWM registers (new pass manager)"));
270
271/// Check if the given RegAllocType is supported for AMDGPU NPM register
272/// allocation. Only Fast and Greedy are supported; Basic and PBQP are not.
273static Error checkRegAllocSupported(RegAllocType RAType, StringRef RegName) {
274 if (RAType == RegAllocType::Basic || RAType == RegAllocType::PBQP) {
276 Twine("unsupported register allocator '") +
277 (RAType == RegAllocType::Basic ? "basic" : "pbqp") + "' for " +
278 RegName + " registers",
280 }
281 return Error::success();
282}
283
284Error AMDGPUCodeGenPassBuilder::validateRegAllocOptions() const {
285 // 1. Generic --regalloc-npm is not supported for AMDGPU.
286 if (Opt.RegAlloc != RegAllocType::Unset) {
288 "-regalloc-npm not supported for amdgcn. Use -sgpr-regalloc-npm, "
289 "-vgpr-regalloc-npm, and -wwm-regalloc-npm",
291 }
292
293 // 2. Legacy PM regalloc options are not compatible with NPM.
294 if (SGPRRegAlloc.getNumOccurrences() > 0 ||
295 VGPRRegAlloc.getNumOccurrences() > 0 ||
296 WWMRegAlloc.getNumOccurrences() > 0) {
298 "-sgpr-regalloc, -vgpr-regalloc, and -wwm-regalloc are legacy PM "
299 "options. Use -sgpr-regalloc-npm, -vgpr-regalloc-npm, and "
300 "-wwm-regalloc-npm with the new pass manager",
302 }
303
304 // 3. Only Fast and Greedy allocators are supported for AMDGPU.
305 if (auto Err = checkRegAllocSupported(SGPRRegAllocNPM, "SGPR"))
306 return Err;
307 if (auto Err = checkRegAllocSupported(WWMRegAllocNPM, "WWM"))
308 return Err;
309 if (auto Err = checkRegAllocSupported(VGPRRegAllocNPM, "VGPR"))
310 return Err;
311
312 return Error::success();
313}
314
315static void initializeDefaultSGPRRegisterAllocatorOnce() {
316 RegisterRegAlloc::FunctionPassCtor Ctor = SGPRRegisterRegAlloc::getDefault();
317
318 if (!Ctor) {
319 Ctor = SGPRRegAlloc;
320 SGPRRegisterRegAlloc::setDefault(SGPRRegAlloc);
321 }
322}
323
324static void initializeDefaultVGPRRegisterAllocatorOnce() {
325 RegisterRegAlloc::FunctionPassCtor Ctor = VGPRRegisterRegAlloc::getDefault();
326
327 if (!Ctor) {
328 Ctor = VGPRRegAlloc;
329 VGPRRegisterRegAlloc::setDefault(VGPRRegAlloc);
330 }
331}
332
333static void initializeDefaultWWMRegisterAllocatorOnce() {
334 RegisterRegAlloc::FunctionPassCtor Ctor = WWMRegisterRegAlloc::getDefault();
335
336 if (!Ctor) {
337 Ctor = WWMRegAlloc;
338 WWMRegisterRegAlloc::setDefault(WWMRegAlloc);
339 }
340}
341
342static FunctionPass *createBasicSGPRRegisterAllocator() {
343 return createBasicRegisterAllocator(onlyAllocateSGPRs);
344}
345
346static FunctionPass *createGreedySGPRRegisterAllocator() {
347 return createGreedyRegisterAllocator(onlyAllocateSGPRs);
348}
349
350static FunctionPass *createFastSGPRRegisterAllocator() {
351 return createFastRegisterAllocator(onlyAllocateSGPRs, false);
352}
353
354static FunctionPass *createBasicVGPRRegisterAllocator() {
355 return createBasicRegisterAllocator(onlyAllocateVGPRs);
356}
357
358static FunctionPass *createGreedyVGPRRegisterAllocator() {
359 return createGreedyRegisterAllocator(onlyAllocateVGPRs);
360}
361
362static FunctionPass *createFastVGPRRegisterAllocator() {
363 return createFastRegisterAllocator(onlyAllocateVGPRs, true);
364}
365
366static FunctionPass *createBasicWWMRegisterAllocator() {
367 return createBasicRegisterAllocator(onlyAllocateWWMRegs);
368}
369
370static FunctionPass *createGreedyWWMRegisterAllocator() {
371 return createGreedyRegisterAllocator(onlyAllocateWWMRegs);
372}
373
374static FunctionPass *createFastWWMRegisterAllocator() {
375 return createFastRegisterAllocator(onlyAllocateWWMRegs, false);
376}
377
378static SGPRRegisterRegAlloc basicRegAllocSGPR(
379 "basic", "basic register allocator", createBasicSGPRRegisterAllocator);
380static SGPRRegisterRegAlloc greedyRegAllocSGPR(
381 "greedy", "greedy register allocator", createGreedySGPRRegisterAllocator);
382
383static SGPRRegisterRegAlloc fastRegAllocSGPR(
384 "fast", "fast register allocator", createFastSGPRRegisterAllocator);
385
386
387static VGPRRegisterRegAlloc basicRegAllocVGPR(
388 "basic", "basic register allocator", createBasicVGPRRegisterAllocator);
389static VGPRRegisterRegAlloc greedyRegAllocVGPR(
390 "greedy", "greedy register allocator", createGreedyVGPRRegisterAllocator);
391
392static VGPRRegisterRegAlloc fastRegAllocVGPR(
393 "fast", "fast register allocator", createFastVGPRRegisterAllocator);
394static WWMRegisterRegAlloc basicRegAllocWWMReg("basic",
395 "basic register allocator",
396 createBasicWWMRegisterAllocator);
397static WWMRegisterRegAlloc
398 greedyRegAllocWWMReg("greedy", "greedy register allocator",
399 createGreedyWWMRegisterAllocator);
400static WWMRegisterRegAlloc fastRegAllocWWMReg("fast", "fast register allocator",
401 createFastWWMRegisterAllocator);
402
404 return Phase == ThinOrFullLTOPhase::FullLTOPreLink ||
405 Phase == ThinOrFullLTOPhase::ThinLTOPreLink;
406}
407} // anonymous namespace
408
409static cl::opt<bool>
411 cl::desc("Run early if-conversion"),
412 cl::init(false));
413
414static cl::opt<bool>
415OptExecMaskPreRA("amdgpu-opt-exec-mask-pre-ra", cl::Hidden,
416 cl::desc("Run pre-RA exec mask optimizations"),
417 cl::init(true));
418
419static cl::opt<bool>
420 LowerCtorDtor("amdgpu-lower-global-ctor-dtor",
421 cl::desc("Lower GPU ctor / dtors to globals on the device."),
422 cl::init(true), cl::Hidden);
423
424// Option to disable vectorizer for tests.
426 "amdgpu-load-store-vectorizer",
427 cl::desc("Enable load store vectorizer"),
428 cl::init(true),
429 cl::Hidden);
430
431// Option to control global loads scalarization
433 "amdgpu-scalarize-global-loads",
434 cl::desc("Enable global load scalarization"),
435 cl::init(true),
436 cl::Hidden);
437
438// Option to run internalize pass.
440 "amdgpu-internalize-symbols",
441 cl::desc("Enable elimination of non-kernel functions and unused globals"),
442 cl::init(false),
443 cl::Hidden);
444
445// Option to inline all early.
447 "amdgpu-early-inline-all",
448 cl::desc("Inline all functions early"),
449 cl::init(false),
450 cl::Hidden);
451
453 "amdgpu-enable-remove-incompatible-functions", cl::Hidden,
454 cl::desc("Enable removal of functions when they"
455 "use features not supported by the target GPU"),
456 cl::init(true));
457
459 "amdgpu-sdwa-peephole",
460 cl::desc("Enable SDWA peepholer"),
461 cl::init(true));
462
464 "amdgpu-dpp-combine",
465 cl::desc("Enable DPP combiner"),
466 cl::init(true));
467
468// Enable address space based alias analysis
470 cl::desc("Enable AMDGPU Alias Analysis"),
471 cl::init(true));
472
473// Enable lib calls simplifications
475 "amdgpu-simplify-libcall",
476 cl::desc("Enable amdgpu library simplifications"),
477 cl::init(true),
478 cl::Hidden);
479
481 "amdgpu-ir-lower-kernel-arguments",
482 cl::desc("Lower kernel argument loads in IR pass"),
483 cl::init(true),
484 cl::Hidden);
485
487 "amdgpu-reassign-regs",
488 cl::desc("Enable register reassign optimizations on gfx10+"),
489 cl::init(true),
490 cl::Hidden);
491
493 "amdgpu-opt-vgpr-liverange",
494 cl::desc("Enable VGPR liverange optimizations for if-else structure"),
495 cl::init(true), cl::Hidden);
496
498 "amdgpu-atomic-optimizer-strategy",
499 cl::desc("Select DPP or Iterative strategy for scan"),
502 clEnumValN(ScanOptions::DPP, "DPP", "Use DPP operations for scan"),
504 "Use Iterative approach for scan"),
505 clEnumValN(ScanOptions::None, "None", "Disable atomic optimizer")));
506
507// Enable Mode register optimization
509 "amdgpu-mode-register",
510 cl::desc("Enable mode register pass"),
511 cl::init(true),
512 cl::Hidden);
513
514// Enable GFX11+ s_delay_alu insertion
515static cl::opt<bool>
516 EnableInsertDelayAlu("amdgpu-enable-delay-alu",
517 cl::desc("Enable s_delay_alu insertion"),
518 cl::init(true), cl::Hidden);
519
520// Enable GFX11+ VOPD
521static cl::opt<bool>
522 EnableVOPD("amdgpu-enable-vopd",
523 cl::desc("Enable VOPD, dual issue of VALU in wave32"),
524 cl::init(true), cl::Hidden);
525
526// Option is used in lit tests to prevent deadcoding of patterns inspected.
527static cl::opt<bool>
528EnableDCEInRA("amdgpu-dce-in-ra",
529 cl::init(true), cl::Hidden,
530 cl::desc("Enable machine DCE inside regalloc"));
531
532static cl::opt<bool> EnableSetWavePriority("amdgpu-set-wave-priority",
533 cl::desc("Adjust wave priority"),
534 cl::init(false), cl::Hidden);
535
537 "amdgpu-scalar-ir-passes",
538 cl::desc("Enable scalar IR passes"),
539 cl::init(true),
540 cl::Hidden);
541
543 "amdgpu-enable-lower-exec-sync",
544 cl::desc("Enable lowering of execution synchronization."), cl::init(true),
545 cl::Hidden);
546
547static cl::opt<bool>
548 EnableSwLowerLDS("amdgpu-enable-sw-lower-lds",
549 cl::desc("Enable lowering of lds to global memory pass "
550 "and asan instrument resulting IR."),
551 cl::init(true), cl::Hidden);
552
554 "amdgpu-enable-object-linking",
555 cl::desc("Enable object linking for cross-TU LDS and ABI support"),
557 cl::Hidden);
558
560 "amdgpu-enable-lower-module-lds", cl::desc("Enable lower module lds pass"),
562 cl::Hidden);
563
565 "amdgpu-enable-pre-ra-optimizations",
566 cl::desc("Enable Pre-RA optimizations pass"), cl::init(true),
567 cl::Hidden);
568
570 "amdgpu-enable-promote-kernel-arguments",
571 cl::desc("Enable promotion of flat kernel pointer arguments to global"),
572 cl::Hidden, cl::init(true));
573
575 "amdgpu-enable-image-intrinsic-optimizer",
576 cl::desc("Enable image intrinsic optimizer pass"), cl::init(true),
577 cl::Hidden);
578
579static cl::opt<bool>
580 EnableLoopPrefetch("amdgpu-loop-prefetch",
581 cl::desc("Enable loop data prefetch on AMDGPU"),
582 cl::Hidden, cl::init(false));
583
585 AMDGPUSchedStrategy("amdgpu-sched-strategy",
586 cl::desc("Select custom AMDGPU scheduling strategy."),
587 cl::Hidden, cl::init(""));
588
589// Scheduler selection is consulted both when creating the scheduler and from
590// overrideSchedPolicy(), so keep the attribute and global command line handling
591// in one helper.
593 Attribute SchedStrategyAttr = F.getFnAttribute("amdgpu-sched-strategy");
594 if (SchedStrategyAttr.isValid())
595 return SchedStrategyAttr.getValueAsString();
596
597 if (!AMDGPUSchedStrategy.empty())
598 return AMDGPUSchedStrategy;
599
600 return "";
601}
602
603static void
605 const GCNSubtarget &ST) {
606 if (ST.hasGFX1250Insts())
607 return;
608
609 F.getContext().diagnose(DiagnosticInfoUnsupported(
610 F, "'amdgpu-sched-strategy'='coexec' is only supported for gfx1250",
612}
613
614static bool useNoopPostScheduler(const Function &F) {
615 Attribute PostSchedStrategyAttr =
616 F.getFnAttribute("amdgpu-post-sched-strategy");
617 return PostSchedStrategyAttr.isValid() &&
618 PostSchedStrategyAttr.getValueAsString() == "nop";
619}
620
622 "amdgpu-enable-rewrite-partial-reg-uses",
623 cl::desc("Enable rewrite partial reg uses pass"), cl::init(true),
624 cl::Hidden);
625
627 "amdgpu-enable-hipstdpar",
628 cl::desc("Enable HIP Standard Parallelism Offload support"), cl::init(false),
629 cl::Hidden);
630
631static cl::opt<bool>
632 EnableAMDGPUAttributor("amdgpu-attributor-enable",
633 cl::desc("Enable AMDGPUAttributorPass"),
634 cl::init(true), cl::Hidden);
635
637 "amdgpu-link-time-closed-world",
638 cl::desc("Whether has closed-world assumption at link time"),
639 cl::init(false), cl::Hidden);
640
642 "amdgpu-enable-uniform-intrinsic-combine",
643 cl::desc("Enable/Disable the Uniform Intrinsic Combine Pass"),
644 cl::init(true), cl::Hidden);
645
647 // Register the target
651
737}
738
739static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
740 return std::make_unique<AMDGPUTargetObjectFile>();
741}
742
746
747static ScheduleDAGInstrs *
749 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
750 ScheduleDAGMILive *DAG =
751 new GCNScheduleDAGMILive(C, std::make_unique<GCNMaxOccupancySchedStrategy>(C));
752 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
753 if (ST.shouldClusterStores())
754 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
756 DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
757 DAG->addMutation(createAMDGPUExportClusteringDAGMutation());
758 DAG->addMutation(createAMDGPUBarrierLatencyDAGMutation(C->MF));
759 DAG->addMutation(createAMDGPUHazardLatencyDAGMutation(C->MF));
760 return DAG;
761}
762
763static ScheduleDAGInstrs *
765 ScheduleDAGMILive *DAG =
766 new GCNScheduleDAGMILive(C, std::make_unique<GCNMaxILPSchedStrategy>(C));
768 return DAG;
769}
770
771static ScheduleDAGInstrs *
773 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
775 C, std::make_unique<GCNMaxMemoryClauseSchedStrategy>(C));
776 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
777 if (ST.shouldClusterStores())
778 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
779 DAG->addMutation(createAMDGPUExportClusteringDAGMutation());
780 DAG->addMutation(createAMDGPUBarrierLatencyDAGMutation(C->MF));
781 DAG->addMutation(createAMDGPUHazardLatencyDAGMutation(C->MF));
782 return DAG;
783}
784
785static ScheduleDAGInstrs *
787 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
788 auto *DAG = new GCNIterativeScheduler(
790 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
791 if (ST.shouldClusterStores())
792 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
794 return DAG;
795}
796
803
804static ScheduleDAGInstrs *
806 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
808 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
809 if (ST.shouldClusterStores())
810 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
811 DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
813 return DAG;
814}
815
816static MachineSchedRegistry
817SISchedRegistry("si", "Run SI's custom scheduler",
819
822 "Run GCN scheduler to maximize occupancy",
824
826 GCNMaxILPSchedRegistry("gcn-max-ilp", "Run GCN scheduler to maximize ilp",
828
830 "gcn-max-memory-clause", "Run GCN scheduler to maximize memory clause",
832
834 "gcn-iterative-max-occupancy-experimental",
835 "Run GCN scheduler to maximize occupancy (experimental)",
837
839 "gcn-iterative-minreg",
840 "Run GCN iterative scheduler for minimal register usage (experimental)",
842
844 "gcn-iterative-ilp",
845 "Run GCN iterative scheduler for ILP scheduling (experimental)",
847
850 if (!GPU.empty())
851 return GPU;
852
853 if (StringRef Name = AMDGPU::getArchNameFromSubArch(TT.getSubArch());
854 !Name.empty())
855 return Name;
856
857 // Need to default to a target with flat support for HSA.
858 if (TT.isAMDGCN())
859 return TT.getOS() == Triple::AMDHSA ? "generic-hsa" : "generic";
860
861 return "r600";
862}
863
865 // The AMDGPU toolchain only supports generating shared objects, so we
866 // must always use PIC.
867 return Reloc::PIC_;
868}
869
871 StringRef CPU, StringRef FS,
872 const TargetOptions &Options,
873 std::optional<Reloc::Model> RM,
874 std::optional<CodeModel::Model> CM,
877 T, TT.computeDataLayout(), TT, getGPUOrDefault(TT, CPU), FS, Options,
879 OptLevel),
881 initAsmInfo();
882 if (TT.isAMDGCN()) {
883 // Triple is missing a representation for non-empty, but unrecognized
884 // subarches. Only permit no subarch for any subtarget if it was really
885 // empty.
886 bool IsUnknownSubArch =
887 TT.getSubArch() == Triple::NoSubArch && TT.getArchName().size() != 6;
888 if (IsUnknownSubArch)
889 reportFatalUsageError("unknown subarch " + TT.getArchName());
890
891 if (TT.getSubArch() != Triple::NoSubArch) {
893 Triple::SubArchType GPUSubArch = AMDGPU::getSubArch(Kind);
894 if (Kind != AMDGPU::GK_NONE && GPUSubArch != TT.getSubArch() &&
895 TT.getSubArch() != AMDGPU::getMajorSubArch(GPUSubArch)) {
896 reportFatalUsageError("invalid cpu '" + CPU + "' for subarch " +
897 TT.getArchName());
898 }
899 }
900
901 if (getMCSubtargetInfo().checkFeatures("+wavefrontsize64"))
903 else if (getMCSubtargetInfo().checkFeatures("+wavefrontsize32"))
905 }
907}
908
912
914
916 Attribute GPUAttr = F.getFnAttribute("target-cpu");
917 return GPUAttr.isValid() ? GPUAttr.getValueAsString() : getTargetCPU();
918}
919
921 Attribute FSAttr = F.getFnAttribute("target-features");
922
923 return FSAttr.isValid() ? FSAttr.getValueAsString()
925}
926
929 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
931 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
932 if (ST.shouldClusterStores())
933 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
934 return DAG;
935}
936
937/// Predicate for Internalize pass.
938static bool mustPreserveGV(const GlobalValue &GV) {
939 if (const Function *F = dyn_cast<Function>(&GV))
940 return F->isDeclaration() || F->getName().starts_with("__asan_") ||
941 F->getName().starts_with("__sanitizer_") ||
942 AMDGPU::isEntryFunctionCC(F->getCallingConv());
943
945 return !GV.use_empty();
946}
947
952
955 if (Params.empty())
957 Params.consume_front("strategy=");
958 auto Result = StringSwitch<std::optional<ScanOptions>>(Params)
959 .Case("dpp", ScanOptions::DPP)
960 .Cases({"iterative", ""}, ScanOptions::Iterative)
961 .Case("none", ScanOptions::None)
962 .Default(std::nullopt);
963 if (Result)
964 return *Result;
965 return make_error<StringError>("invalid parameter", inconvertibleErrorCode());
966}
967
971 while (!Params.empty()) {
972 StringRef ParamName;
973 std::tie(ParamName, Params) = Params.split(';');
974 if (ParamName == "closed-world") {
975 Result.IsClosedWorld = true;
976 } else {
978 formatv("invalid AMDGPUAttributor pass parameter '{0}' ", ParamName)
979 .str(),
981 }
982 }
983 return Result;
984}
985
987
988#define GET_PASS_REGISTRY "AMDGPUPassRegistry.def"
990
991 // TODO: Move this into the base CodeGenPassBuilder once all
992 // targets that currently implement it have a ported asm-printer pass.
993 if (PIC) {
994 PIC->addClassToPassName(AMDGPUAsmPrinterBeginPass::name(),
995 "amdgpu-asm-printer-begin");
996 PIC->addClassToPassName(AMDGPUAsmPrinterPass::name(), "amdgpu-asm-printer");
997 PIC->addClassToPassName(AMDGPUAsmPrinterEndPass::name(),
998 "amdgpu-asm-printer-end");
999 }
1000
1001 PB.registerPipelineParsingCallback(
1002 [this](StringRef Name, CGSCCPassManager &PM,
1004 if (Name == "amdgpu-attributor-cgscc" && getTargetTriple().isAMDGCN()) {
1006 *static_cast<GCNTargetMachine *>(this)));
1007 return true;
1008 }
1009 return false;
1010 });
1011
1012 PB.registerScalarOptimizerLateEPCallback(
1013 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1014 if (Level == OptimizationLevel::O0)
1015 return;
1016
1018 });
1019
1020 PB.registerVectorizerEndEPCallback(
1021 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1022 if (Level == OptimizationLevel::O0)
1023 return;
1024
1026 });
1027
1028 PB.registerPipelineEarlySimplificationEPCallback(
1029 [this](ModulePassManager &PM, OptimizationLevel Level,
1031 if (!isLTOPreLink(Phase) && getTargetTriple().isAMDGCN()) {
1032 // When we are not using -fgpu-rdc, we can run accelerator code
1033 // selection relatively early, but still after linking to prevent
1034 // eager removal of potentially reachable symbols.
1035 if (EnableHipStdPar) {
1038 }
1039
1041 }
1042
1043 if (Level == OptimizationLevel::O0)
1044 return;
1045
1046 // We don't want to run internalization at per-module stage.
1049 PM.addPass(GlobalDCEPass());
1050 }
1051
1054 });
1055
1056 PB.registerPeepholeEPCallback(
1057 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1058 if (Level == OptimizationLevel::O0)
1059 return;
1060
1064
1067 });
1068
1069 PB.registerCGSCCOptimizerLateEPCallback(
1070 [this](CGSCCPassManager &PM, OptimizationLevel Level) {
1071 if (Level == OptimizationLevel::O0)
1072 return;
1073
1075
1076 // Add promote kernel arguments pass to the opt pipeline right before
1077 // infer address spaces which is needed to do actual address space
1078 // rewriting.
1081
1082 // Add infer address spaces pass to the opt pipeline after inlining
1083 // but before SROA to increase SROA opportunities.
1085
1086 // This should run after inlining to have any chance of doing
1087 // anything, and before other cleanup optimizations.
1089
1090 // Promote alloca to vector before SROA and loop unroll. If we
1091 // manage to eliminate allocas before unroll we may choose to unroll
1092 // less.
1094
1095 PM.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
1096 });
1097
1098 // FIXME: Why is AMDGPUAttributor not in CGSCC?
1099 PB.registerOptimizerLastEPCallback([this](ModulePassManager &MPM,
1100 OptimizationLevel Level,
1102 if (Level != OptimizationLevel::O0) {
1103 if (!isLTOPreLink(Phase)) {
1104 if (EnableAMDGPUAttributor && getTargetTriple().isAMDGCN()) {
1106 MPM.addPass(AMDGPUAttributorPass(*this, Opts, Phase));
1107 }
1108 }
1109 }
1110 });
1111
1112 PB.registerFullLinkTimeOptimizationLastEPCallback(
1113 [this](ModulePassManager &PM, OptimizationLevel Level) {
1114 // When we are using -fgpu-rdc, we can only run accelerator code
1115 // selection after linking to prevent, otherwise we end up removing
1116 // potentially reachable symbols that were exported as external in other
1117 // modules.
1118 if (EnableHipStdPar) {
1121 }
1122 // We want to support the -lto-partitions=N option as "best effort".
1123 // For that, we need to lower LDS earlier in the pipeline before the
1124 // module is partitioned for codegen.
1127 if (EnableSwLowerLDS)
1131 if (Level != OptimizationLevel::O0) {
1132 // We only want to run this with O2 or higher since inliner and SROA
1133 // don't run in O1.
1134 if (Level != OptimizationLevel::O1) {
1135 PM.addPass(
1137 }
1138 // Do we really need internalization in LTO?
1139 if (InternalizeSymbols) {
1141 PM.addPass(GlobalDCEPass());
1142 }
1143 if (EnableAMDGPUAttributor && getTargetTriple().isAMDGCN()) {
1146 Opt.IsClosedWorld = true;
1149 }
1150 }
1151 if (!NoKernelInfoEndLTO) {
1153 FPM.addPass(KernelInfoPrinter(this));
1154 PM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1155 }
1156 });
1157
1158 PB.registerRegClassFilterParsingCallback(
1159 [](StringRef FilterName) -> RegAllocFilterFunc {
1160 if (FilterName == "sgpr")
1161 return onlyAllocateSGPRs;
1162 if (FilterName == "vgpr")
1163 return onlyAllocateVGPRs;
1164 if (FilterName == "wwm")
1165 return onlyAllocateWWMRegs;
1166 return nullptr;
1167 });
1168}
1169
1171 unsigned DestAS) const {
1172 return AMDGPU::isFlatGlobalAddrSpace(SrcAS) &&
1174}
1175
1177 if (auto *Arg = dyn_cast<Argument>(V);
1178 Arg &&
1179 AMDGPU::isModuleEntryFunctionCC(Arg->getParent()->getCallingConv()) &&
1180 !Arg->hasByRefAttr())
1182
1183 const auto *LD = dyn_cast<LoadInst>(V);
1184 if (!LD) // TODO: Handle invariant load like constant.
1186
1187 // It must be a generic pointer loaded.
1188 assert(V->getType()->getPointerAddressSpace() == AMDGPUAS::FLAT_ADDRESS);
1189
1190 const auto *Ptr = LD->getPointerOperand();
1191 if (Ptr->getType()->getPointerAddressSpace() != AMDGPUAS::CONSTANT_ADDRESS)
1193 // For a generic pointer loaded from the constant memory, it could be assumed
1194 // as a global pointer since the constant memory is only populated on the
1195 // host side. As implied by the offload programming model, only global
1196 // pointers could be referenced on the host side.
1198}
1199
1200std::pair<const Value *, unsigned>
1202 if (auto *II = dyn_cast<IntrinsicInst>(V)) {
1203 switch (II->getIntrinsicID()) {
1204 case Intrinsic::amdgcn_is_shared:
1205 return std::pair(II->getArgOperand(0), AMDGPUAS::LOCAL_ADDRESS);
1206 case Intrinsic::amdgcn_is_private:
1207 return std::pair(II->getArgOperand(0), AMDGPUAS::PRIVATE_ADDRESS);
1208 default:
1209 break;
1210 }
1211 return std::pair(nullptr, -1);
1212 }
1213 // Check the global pointer predication based on
1214 // (!is_share(p) && !is_private(p)). Note that logic 'and' is commutative and
1215 // the order of 'is_shared' and 'is_private' is not significant.
1216 Value *Ptr;
1217 if (match(
1218 const_cast<Value *>(V),
1221 m_Deferred(Ptr))))))
1222 return std::pair(Ptr, AMDGPUAS::GLOBAL_ADDRESS);
1223
1224 return std::pair(nullptr, -1);
1225}
1226
1227unsigned
1242
1244 Module &M, unsigned NumParts,
1245 function_ref<void(std::unique_ptr<Module> MPart)> ModuleCallback) {
1246 // FIXME(?): Would be better to use an already existing Analysis/PassManager,
1247 // but all current users of this API don't have one ready and would need to
1248 // create one anyway. Let's hide the boilerplate for now to keep it simple.
1249
1254
1255 PassBuilder PB(this);
1256 PB.registerModuleAnalyses(MAM);
1257 PB.registerFunctionAnalyses(FAM);
1258 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
1259
1261 MPM.addPass(AMDGPUSplitModulePass(NumParts, ModuleCallback));
1262 MPM.run(M, MAM);
1263 return true;
1264}
1265
1266//===----------------------------------------------------------------------===//
1267// GCN Target Machine (SI+)
1268//===----------------------------------------------------------------------===//
1269
1271 StringRef CPU, StringRef FS,
1272 const TargetOptions &Options,
1273 std::optional<Reloc::Model> RM,
1274 std::optional<CodeModel::Model> CM,
1275 CodeGenOptLevel OL, bool JIT)
1276 : AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {
1278}
1279
1280enum class OOBFlagValue {
1281 Any = 0,
1284};
1285
1286/// Returns the OOB mode encoded by a module flag.
1287/// An absent flag defaults to Any.
1288static OOBFlagValue getOOBFlagValue(const Module &M, StringRef FlagName) {
1289 const auto *Flag =
1290 mdconst::dyn_extract_or_null<ConstantInt>(M.getModuleFlag(FlagName));
1291 if (!Flag)
1292 return OOBFlagValue::Any;
1293 return static_cast<OOBFlagValue>(Flag->getZExtValue());
1294}
1295
1296const TargetSubtargetInfo *
1298 StringRef GPU = getGPUName(F);
1300
1301 const Module &M = *F.getParent();
1304 bool BufRelaxed = BufOOB == OOBFlagValue::Relaxed;
1305 bool TBufRelaxed = TBufOOB == OOBFlagValue::Relaxed;
1306 SmallString<128> SubtargetKey(GPU);
1307 SubtargetKey.append(FS);
1308 if (BufRelaxed)
1309 SubtargetKey.append(",buf-oob=1");
1310 if (TBufRelaxed)
1311 SubtargetKey.append(",tbuf-oob=1");
1312
1313 auto &I = SubtargetMap[SubtargetKey];
1314 if (!I) {
1316 Triple::SubArchType GPUSubArch = AMDGPU::getSubArch(Kind);
1317
1318 // Enforce the subtarget is covered by the subarch. Tolerate no subarch for
1319 // legacy compatibility.
1320 const Triple &TT = M.getTargetTriple();
1321 if (GPUSubArch != TT.getSubArch() && Kind != AMDGPU::GK_NONE) {
1322 // Check if this is a generic subarch which has subtargets. Ignore
1323 // unknown subtargets with a known subarch, since for whatever reason
1324 // the convention is to just print a warning and ignore unrecognized
1325 // subtargets.
1326 bool IsLegacyEmptySubArch = TT.getSubArch() == Triple::NoSubArch;
1327 if (!IsLegacyEmptySubArch &&
1328 AMDGPU::getMajorSubArch(GPUSubArch) != TT.getSubArch()) {
1329 F.getContext().emitError("invalid subtarget '" + Twine(GPU) +
1330 "' for subarch " + TT.getArchName());
1331 }
1332 }
1333
1334 I = std::make_unique<GCNSubtarget>(TargetTriple, GPU, FS, *this, BufRelaxed,
1335 TBufRelaxed);
1336 }
1337
1338 I->setScalarizeGlobalBehavior(ScalarizeGlobal);
1339
1340 return I.get();
1341}
1342
1345 return TargetTransformInfo(std::make_unique<GCNTTIImpl>(this, F));
1346}
1347
1350 raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
1351 const CGPassBuilderOption &Opts, MCContext &Ctx,
1353 AMDGPUCodeGenPassBuilder CGPB(*this, Opts, PIC);
1354 return CGPB.buildPipeline(MPM, MAM, Out, DwoOut, FileType, Ctx);
1355}
1356
1359 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
1360 if (ST.enableSIScheduler())
1362
1363 StringRef SchedStrategy = AMDGPU::getSchedStrategy(C->MF->getFunction());
1364
1365 if (SchedStrategy == "max-ilp")
1367
1368 if (SchedStrategy == "max-memory-clause")
1370
1371 if (SchedStrategy == "iterative-ilp")
1373
1374 if (SchedStrategy == "iterative-minreg")
1375 return createMinRegScheduler(C);
1376
1377 if (SchedStrategy == "iterative-maxocc")
1379
1380 if (SchedStrategy == "coexec") {
1381 diagnoseUnsupportedCoExecSchedulerSelection(C->MF->getFunction(), ST);
1383 }
1384
1386}
1387
1390 if (useNoopPostScheduler(C->MF->getFunction()))
1392
1393 ScheduleDAGMI *DAG =
1394 new GCNPostScheduleDAGMILive(C, std::make_unique<PostGenericScheduler>(C),
1395 /*RemoveKillFlags=*/true);
1396 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
1398 if (ST.shouldClusterStores())
1401 if ((EnableVOPD.getNumOccurrences() ||
1403 EnableVOPD)
1408 return DAG;
1409}
1410//===----------------------------------------------------------------------===//
1411// AMDGPU Legacy Pass Setup
1412//===----------------------------------------------------------------------===//
1413
1414std::unique_ptr<CSEConfigBase> llvm::AMDGPUPassConfig::getCSEConfig() const {
1415 return getStandardCSEConfigForOpt(TM->getOptLevel());
1416}
1417
1418namespace {
1419
1420class GCNPassConfig final : public AMDGPUPassConfig {
1421public:
1422 GCNPassConfig(TargetMachine &TM, PassManagerBase &PM)
1423 : AMDGPUPassConfig(TM, PM) {
1424 substitutePass(&PostRASchedulerID, &PostMachineSchedulerID);
1425 }
1426
1427 GCNTargetMachine &getGCNTargetMachine() const {
1428 return getTM<GCNTargetMachine>();
1429 }
1430
1431 bool addPreISel() override;
1432 void addMachineSSAOptimization() override;
1433 bool addILPOpts() override;
1434 bool addInstSelector() override;
1435 bool addIRTranslator() override;
1436 void addPreLegalizeMachineIR() override;
1437 bool addLegalizeMachineIR() override;
1438 void addPreRegBankSelect() override;
1439 bool addRegBankSelect() override;
1440 void addPreGlobalInstructionSelect() override;
1441 bool addGlobalInstructionSelect() override;
1442 void addPreRegAlloc() override;
1443 void addFastRegAlloc() override;
1444 void addOptimizedRegAlloc() override;
1445
1446 FunctionPass *createSGPRAllocPass(bool Optimized);
1447 FunctionPass *createVGPRAllocPass(bool Optimized);
1448 FunctionPass *createWWMRegAllocPass(bool Optimized);
1449 FunctionPass *createRegAllocPass(bool Optimized) override;
1450
1451 bool addRegAssignAndRewriteFast() override;
1452 bool addRegAssignAndRewriteOptimized() override;
1453
1454 bool addPreRewrite() override;
1455 void addPostRegAlloc() override;
1456 void addPreSched2() override;
1457 void addPreEmitPass() override;
1458 void addPostBBSections() override;
1459};
1460
1461} // end anonymous namespace
1462
1464 : TargetPassConfig(TM, PM) {
1465 // Exceptions and StackMaps are not supported, so these passes will never do
1466 // anything.
1469 // Garbage collection is not supported.
1472}
1473
1480
1485 // ReassociateGEPs exposes more opportunities for SLSR. See
1486 // the example in reassociate-geps-and-slsr.ll.
1488 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
1489 // EarlyCSE can reuse.
1491 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
1493 // NaryReassociate on GEPs creates redundant common expressions, so run
1494 // EarlyCSE after it.
1496}
1497
1500
1501 if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN())
1503
1504 // There is no reason to run these.
1508
1509 if (TM.getTargetTriple().isAMDGCN())
1511
1512 if (LowerCtorDtor)
1514
1515 if (TM.getTargetTriple().isAMDGCN() &&
1518
1521
1522 // This can be disabled by passing ::Disable here or on the command line
1523 // with --expand-variadics-override=disable.
1525
1526 // Function calls are not supported, so make sure we inline everything.
1529
1530 // Handle uses of OpenCL image2d_t, image3d_t and sampler_t arguments.
1531 if (TM.getTargetTriple().getArch() == Triple::r600)
1533
1534 // Make enqueued block runtime handles externally visible.
1536
1537 // Lower special LDS accesses.
1540
1541 // Lower LDS accesses to global memory pass if address sanitizer is enabled.
1542 if (EnableSwLowerLDS)
1544
1545 // Runs before PromoteAlloca so the latter can account for function uses
1548 }
1549
1550 // Run atomic optimizer before Atomic Expand
1551 if ((TM.getTargetTriple().isAMDGCN()) &&
1552 (TM.getOptLevel() >= CodeGenOptLevel::Less) &&
1555 }
1556
1558
1559 if (TM.getOptLevel() > CodeGenOptLevel::None) {
1561
1564
1568 AAResults &AAR) {
1569 if (auto *WrapperPass = P.getAnalysisIfAvailable<AMDGPUAAWrapperPass>())
1570 AAR.addAAResult(WrapperPass->getResult());
1571 }));
1572 }
1573
1574 if (TM.getTargetTriple().isAMDGCN()) {
1575 // TODO: May want to move later or split into an early and late one.
1577 }
1578
1579 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
1580 // have expanded.
1581 if (TM.getOptLevel() > CodeGenOptLevel::Less)
1583 }
1584
1586
1587 // EarlyCSE is not always strong enough to clean up what LSR produces. For
1588 // example, GVN can combine
1589 //
1590 // %0 = add %a, %b
1591 // %1 = add %b, %a
1592 //
1593 // and
1594 //
1595 // %0 = shl nsw %a, 2
1596 // %1 = shl %a, 2
1597 //
1598 // but EarlyCSE can do neither of them.
1601}
1602
1604 if (TM->getTargetTriple().isAMDGCN() &&
1605 TM->getOptLevel() > CodeGenOptLevel::None)
1607
1608 if (TM->getTargetTriple().isAMDGCN() && EnableLowerKernelArguments)
1610
1612
1615
1616 if (TM->getTargetTriple().isAMDGCN()) {
1617 // This lowering has been placed after codegenprepare to take advantage of
1618 // address mode matching (which is why it isn't put with the LDS lowerings).
1619 // It could be placed anywhere before uniformity annotations (an analysis
1620 // that it changes by splitting up fat pointers into their components)
1621 // but has been put before switch lowering and CFG flattening so that those
1622 // passes can run on the more optimized control flow this pass creates in
1623 // many cases.
1626 }
1627
1628 // LowerSwitch pass may introduce unreachable blocks that can
1629 // cause unexpected behavior for subsequent passes. Placing it
1630 // here seems better that these blocks would get cleaned up by
1631 // UnreachableBlockElim inserted next in the pass flow.
1633}
1634
1636 if (TM->getOptLevel() > CodeGenOptLevel::None)
1638 return false;
1639}
1640
1645
1647 // Do nothing. GC is not supported.
1648 return false;
1649}
1650
1651//===----------------------------------------------------------------------===//
1652// GCN Legacy Pass Setup
1653//===----------------------------------------------------------------------===//
1654
1655bool GCNPassConfig::addPreISel() {
1657
1658 if (TM->getOptLevel() > CodeGenOptLevel::None) {
1659 addPass(createSinkingPass());
1661 }
1662
1663 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
1664 // regions formed by them.
1666 addPass(createFixIrreduciblePass());
1667 addPass(createUnifyLoopExitsPass());
1668 addPass(createStructurizeCFGPass(false)); // true -> SkipUniformRegions
1669
1672 // TODO: Move this right after structurizeCFG to avoid extra divergence
1673 // analysis. This depends on stopping SIAnnotateControlFlow from making
1674 // control flow modifications.
1676
1677 // SDAG requires LCSSA, GlobalISel does not. Disable LCSSA for -global-isel
1678 // without any of the fallback options.
1681 !isGlobalISelAbortEnabled())
1682 addPass(createLCSSAPass());
1683
1684 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1686
1687 return false;
1688}
1689
1690void GCNPassConfig::addMachineSSAOptimization() {
1692
1693 // We want to fold operands after PeepholeOptimizer has run (or as part of
1694 // it), because it will eliminate extra copies making it easier to fold the
1695 // real source operand. We want to eliminate dead instructions after, so that
1696 // we see fewer uses of the copies. We then need to clean up the dead
1697 // instructions leftover after the operands are folded as well.
1698 //
1699 // XXX - Can we get away without running DeadMachineInstructionElim again?
1700 addPass(&SIFoldOperandsLegacyID);
1701 if (EnableDPPCombine)
1702 addPass(&GCNDPPCombineLegacyID);
1704 if (isPassEnabled(EnableSDWAPeephole)) {
1705 addPass(&SIPeepholeSDWALegacyID);
1706 addPass(&EarlyMachineLICMID);
1707 addPass(&MachineCSELegacyID);
1708 addPass(&SIFoldOperandsLegacyID);
1709 }
1712}
1713
1714bool GCNPassConfig::addILPOpts() {
1716 addPass(&EarlyIfConverterLegacyID);
1717
1719 return false;
1720}
1721
1722bool GCNPassConfig::addInstSelector() {
1724 addPass(&SIFixSGPRCopiesLegacyID);
1726 return false;
1727}
1728
1729bool GCNPassConfig::addIRTranslator() {
1730 addPass(new IRTranslator(getOptLevel()));
1731 return false;
1732}
1733
1734void GCNPassConfig::addPreLegalizeMachineIR() {
1735 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1736 addPass(createAMDGPUPreLegalizeCombiner(IsOptNone));
1737 addPass(new Localizer());
1738}
1739
1740bool GCNPassConfig::addLegalizeMachineIR() {
1741 addPass(new Legalizer());
1742 return false;
1743}
1744
1745void GCNPassConfig::addPreRegBankSelect() {
1746 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1747 addPass(createAMDGPUPostLegalizeCombiner(IsOptNone));
1749}
1750
1751bool GCNPassConfig::addRegBankSelect() {
1754 return false;
1755}
1756
1757void GCNPassConfig::addPreGlobalInstructionSelect() {
1758 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1759 addPass(createAMDGPURegBankCombiner(IsOptNone));
1760}
1761
1762bool GCNPassConfig::addGlobalInstructionSelect() {
1763 addPass(new InstructionSelect(getOptLevel()));
1764 return false;
1765}
1766
1767void GCNPassConfig::addFastRegAlloc() {
1768 // FIXME: We have to disable the verifier here because of PHIElimination +
1769 // TwoAddressInstructions disabling it.
1770
1771 // This must be run immediately after phi elimination and before
1772 // TwoAddressInstructions, otherwise the processing of the tied operand of
1773 // SI_ELSE will introduce a copy of the tied operand source after the else.
1775
1777
1779}
1780
1781void GCNPassConfig::addPreRegAlloc() {
1782 if (getOptLevel() != CodeGenOptLevel::None)
1784}
1785
1786void GCNPassConfig::addOptimizedRegAlloc() {
1787 if (EnableDCEInRA)
1789
1790 // FIXME: when an instruction has a Killed operand, and the instruction is
1791 // inside a bundle, seems only the BUNDLE instruction appears as the Kills of
1792 // the register in LiveVariables, this would trigger a failure in verifier,
1793 // we should fix it and enable the verifier.
1794 if (OptVGPRLiveRange)
1796
1797 // This must be run immediately after phi elimination and before
1798 // TwoAddressInstructions, otherwise the processing of the tied operand of
1799 // SI_ELSE will introduce a copy of the tied operand source after the else.
1801
1804
1805 if (isPassEnabled(EnablePreRAOptimizations))
1807
1808 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
1809 // instructions that cause scheduling barriers.
1811
1812 if (OptExecMaskPreRA)
1814
1815 // This is not an essential optimization and it has a noticeable impact on
1816 // compilation time, so we only enable it from O2.
1817 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1819
1821}
1822
1823bool GCNPassConfig::addPreRewrite() {
1825 addPass(&GCNNSAReassignID);
1826
1828 return true;
1829}
1830
1831FunctionPass *GCNPassConfig::createSGPRAllocPass(bool Optimized) {
1832 // Initialize the global default.
1833 llvm::call_once(InitializeDefaultSGPRRegisterAllocatorFlag,
1834 initializeDefaultSGPRRegisterAllocatorOnce);
1835
1836 RegisterRegAlloc::FunctionPassCtor Ctor = SGPRRegisterRegAlloc::getDefault();
1837 if (Ctor != useDefaultRegisterAllocator)
1838 return Ctor();
1839
1840 if (Optimized)
1841 return createGreedyRegisterAllocator(onlyAllocateSGPRs);
1842
1843 return createFastRegisterAllocator(onlyAllocateSGPRs, false);
1844}
1845
1846FunctionPass *GCNPassConfig::createVGPRAllocPass(bool Optimized) {
1847 // Initialize the global default.
1848 llvm::call_once(InitializeDefaultVGPRRegisterAllocatorFlag,
1849 initializeDefaultVGPRRegisterAllocatorOnce);
1850
1851 RegisterRegAlloc::FunctionPassCtor Ctor = VGPRRegisterRegAlloc::getDefault();
1852 if (Ctor != useDefaultRegisterAllocator)
1853 return Ctor();
1854
1855 if (Optimized)
1856 return createGreedyVGPRRegisterAllocator();
1857
1858 return createFastVGPRRegisterAllocator();
1859}
1860
1861FunctionPass *GCNPassConfig::createWWMRegAllocPass(bool Optimized) {
1862 // Initialize the global default.
1863 llvm::call_once(InitializeDefaultWWMRegisterAllocatorFlag,
1864 initializeDefaultWWMRegisterAllocatorOnce);
1865
1866 RegisterRegAlloc::FunctionPassCtor Ctor = WWMRegisterRegAlloc::getDefault();
1867 if (Ctor != useDefaultRegisterAllocator)
1868 return Ctor();
1869
1870 if (Optimized)
1871 return createGreedyWWMRegisterAllocator();
1872
1873 return createFastWWMRegisterAllocator();
1874}
1875
1876FunctionPass *GCNPassConfig::createRegAllocPass(bool Optimized) {
1877 llvm_unreachable("should not be used");
1878}
1879
1881 "-regalloc not supported with amdgcn. Use -sgpr-regalloc, -wwm-regalloc, "
1882 "and -vgpr-regalloc";
1883
1884bool GCNPassConfig::addRegAssignAndRewriteFast() {
1885 if (!usingDefaultRegAlloc())
1887
1888 addPass(&GCNPreRALongBranchRegID);
1889
1890 addPass(createSGPRAllocPass(false));
1891
1892 // Equivalent of PEI for SGPRs.
1893 addPass(&SILowerSGPRSpillsLegacyID);
1894
1895 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1897
1898 // For allocating other wwm register operands.
1899 addPass(createWWMRegAllocPass(false));
1900
1901 addPass(&SILowerWWMCopiesLegacyID);
1903
1904 // For allocating per-thread VGPRs.
1905 addPass(createVGPRAllocPass(false));
1906
1907 return true;
1908}
1909
1910bool GCNPassConfig::addRegAssignAndRewriteOptimized() {
1911 if (!usingDefaultRegAlloc())
1913
1914 addPass(&GCNPreRALongBranchRegID);
1915
1916 addPass(createSGPRAllocPass(true));
1917
1918 // Commit allocated register changes. This is mostly necessary because too
1919 // many things rely on the use lists of the physical registers, such as the
1920 // verifier. This is only necessary with allocators which use LiveIntervals,
1921 // since FastRegAlloc does the replacements itself.
1922 addPass(createVirtRegRewriter(false));
1923
1924 // At this point, the sgpr-regalloc has been done and it is good to have the
1925 // stack slot coloring to try to optimize the SGPR spill stack indices before
1926 // attempting the custom SGPR spill lowering.
1927 addPass(&StackSlotColoringID);
1928
1929 // Equivalent of PEI for SGPRs.
1930 addPass(&SILowerSGPRSpillsLegacyID);
1931
1932 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1934
1935 // For allocating other whole wave mode registers.
1936 addPass(createWWMRegAllocPass(true));
1937 addPass(&SILowerWWMCopiesLegacyID);
1938 addPass(createVirtRegRewriter(false));
1940
1941 // For allocating per-thread VGPRs.
1942 addPass(createVGPRAllocPass(true));
1943
1944 addPreRewrite();
1945 addPass(&VirtRegRewriterID);
1946
1948
1949 return true;
1950}
1951
1952void GCNPassConfig::addPostRegAlloc() {
1953 addPass(&SIFixVGPRCopiesID);
1954 if (getOptLevel() > CodeGenOptLevel::None)
1957}
1958
1959void GCNPassConfig::addPreSched2() {
1960 if (TM->getOptLevel() > CodeGenOptLevel::None)
1962 addPass(&SIPostRABundlerLegacyID);
1963}
1964
1965void GCNPassConfig::addPreEmitPass() {
1966 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less))
1967 addPass(&GCNCreateVOPDID);
1968 addPass(createSIMemoryLegalizerPass());
1969 addPass(createSIInsertWaitcntsPass());
1970
1971 addPass(createSIModeRegisterPass());
1972
1973 if (getOptLevel() > CodeGenOptLevel::None)
1974 addPass(&SIInsertHardClausesID);
1975
1977 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
1979 if (getOptLevel() > CodeGenOptLevel::None)
1980 addPass(&SIPreEmitPeepholeID);
1981 // The hazard recognizer that runs as part of the post-ra scheduler does not
1982 // guarantee to be able handle all hazards correctly. This is because if there
1983 // are multiple scheduling regions in a basic block, the regions are scheduled
1984 // bottom up, so when we begin to schedule a region we don't know what
1985 // instructions were emitted directly before it.
1986 //
1987 // Here we add a stand-alone hazard recognizer pass which can handle all
1988 // cases.
1989 addPass(&PostRAHazardRecognizerID);
1990
1992
1994
1995 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less))
1996 addPass(&AMDGPUInsertDelayAluID);
1997
1998 addPass(&BranchRelaxationPassID);
1999}
2000
2001void GCNPassConfig::addPostBBSections() {
2002 // We run this later to avoid passes like livedebugvalues and BBSections
2003 // having to deal with the apparent multi-entry functions we may generate.
2005}
2006
2008 return new GCNPassConfig(*this, PM);
2009}
2010
2016
2023
2027
2034
2037 SMDiagnostic &Error, SMRange &SourceRange) const {
2038 const yaml::SIMachineFunctionInfo &YamlMFI =
2039 static_cast<const yaml::SIMachineFunctionInfo &>(MFI_);
2040 MachineFunction &MF = PFS.MF;
2042 const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
2043
2044 if (MFI->initializeBaseYamlFields(YamlMFI, MF, PFS, Error, SourceRange))
2045 return true;
2046
2047 if (MFI->Occupancy == 0) {
2048 // Fixup the subtarget dependent default value.
2049 MFI->Occupancy = ST.getOccupancyWithWorkGroupSizes(MF).second;
2050 }
2051
2052 auto parseRegister = [&](const yaml::StringValue &RegName, Register &RegVal) {
2053 Register TempReg;
2054 if (parseNamedRegisterReference(PFS, TempReg, RegName.Value, Error)) {
2055 SourceRange = RegName.SourceRange;
2056 return true;
2057 }
2058 RegVal = TempReg;
2059
2060 return false;
2061 };
2062
2063 auto parseOptionalRegister = [&](const yaml::StringValue &RegName,
2064 Register &RegVal) {
2065 return !RegName.Value.empty() && parseRegister(RegName, RegVal);
2066 };
2067
2068 if (parseOptionalRegister(YamlMFI.VGPRForAGPRCopy, MFI->VGPRForAGPRCopy))
2069 return true;
2070
2071 if (parseOptionalRegister(YamlMFI.SGPRForEXECCopy, MFI->SGPRForEXECCopy))
2072 return true;
2073
2074 if (parseOptionalRegister(YamlMFI.LongBranchReservedReg,
2075 MFI->LongBranchReservedReg))
2076 return true;
2077
2078 auto diagnoseRegisterClass = [&](const yaml::StringValue &RegName) {
2079 // Create a diagnostic for a the register string literal.
2080 const MemoryBuffer &Buffer =
2081 *PFS.SM->getMemoryBuffer(PFS.SM->getMainFileID());
2082 Error = SMDiagnostic(*PFS.SM, SMLoc(), Buffer.getBufferIdentifier(), 1,
2083 RegName.Value.size(), SourceMgr::DK_Error,
2084 "incorrect register class for field", RegName.Value,
2085 {}, {});
2086 SourceRange = RegName.SourceRange;
2087 return true;
2088 };
2089
2090 if (parseRegister(YamlMFI.ScratchRSrcReg, MFI->ScratchRSrcReg) ||
2091 parseRegister(YamlMFI.FrameOffsetReg, MFI->FrameOffsetReg) ||
2092 parseRegister(YamlMFI.StackPtrOffsetReg, MFI->StackPtrOffsetReg))
2093 return true;
2094
2095 if (MFI->ScratchRSrcReg != AMDGPU::PRIVATE_RSRC_REG &&
2096 !AMDGPU::SGPR_128RegClass.contains(MFI->ScratchRSrcReg)) {
2097 return diagnoseRegisterClass(YamlMFI.ScratchRSrcReg);
2098 }
2099
2100 if (MFI->FrameOffsetReg != AMDGPU::FP_REG &&
2101 !AMDGPU::SGPR_32RegClass.contains(MFI->FrameOffsetReg)) {
2102 return diagnoseRegisterClass(YamlMFI.FrameOffsetReg);
2103 }
2104
2105 if (MFI->StackPtrOffsetReg != AMDGPU::SP_REG &&
2106 !AMDGPU::SGPR_32RegClass.contains(MFI->StackPtrOffsetReg)) {
2107 return diagnoseRegisterClass(YamlMFI.StackPtrOffsetReg);
2108 }
2109
2110 for (const auto &YamlReg : YamlMFI.WWMReservedRegs) {
2111 Register ParsedReg;
2112 if (parseRegister(YamlReg, ParsedReg))
2113 return true;
2114
2115 MFI->reserveWWMRegister(ParsedReg);
2116 }
2117
2118 for (const auto &[_, Info] : PFS.VRegInfosNamed) {
2119 MFI->setFlag(Info->VReg, Info->Flags);
2120 }
2121 for (const auto &[_, Info] : PFS.VRegInfos) {
2122 MFI->setFlag(Info->VReg, Info->Flags);
2123 }
2124
2125 for (const auto &YamlRegStr : YamlMFI.SpillPhysVGPRS) {
2126 Register ParsedReg;
2127 if (parseRegister(YamlRegStr, ParsedReg))
2128 return true;
2129 MFI->SpillPhysVGPRs.push_back(ParsedReg);
2130 }
2131
2132 auto parseAndCheckArgument = [&](const std::optional<yaml::SIArgument> &A,
2133 const TargetRegisterClass &RC,
2134 ArgDescriptor &Arg, unsigned UserSGPRs,
2135 unsigned SystemSGPRs) {
2136 // Skip parsing if it's not present.
2137 if (!A)
2138 return false;
2139
2140 if (A->IsRegister) {
2141 Register Reg;
2142 if (parseNamedRegisterReference(PFS, Reg, A->RegisterName.Value, Error)) {
2143 SourceRange = A->RegisterName.SourceRange;
2144 return true;
2145 }
2146 if (!RC.contains(Reg))
2147 return diagnoseRegisterClass(A->RegisterName);
2149 } else
2150 Arg = ArgDescriptor::createStack(A->StackOffset);
2151 // Check and apply the optional mask.
2152 if (A->Mask)
2153 Arg = ArgDescriptor::createArg(Arg, *A->Mask);
2154
2155 MFI->NumUserSGPRs += UserSGPRs;
2156 MFI->NumSystemSGPRs += SystemSGPRs;
2157 return false;
2158 };
2159
2160 if (YamlMFI.ArgInfo &&
2161 (parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentBuffer,
2162 AMDGPU::SGPR_128RegClass,
2163 MFI->ArgInfo.PrivateSegmentBuffer, 4, 0) ||
2164 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchPtr,
2165 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchPtr,
2166 2, 0) ||
2167 parseAndCheckArgument(YamlMFI.ArgInfo->QueuePtr, AMDGPU::SReg_64RegClass,
2168 MFI->ArgInfo.QueuePtr, 2, 0) ||
2169 parseAndCheckArgument(YamlMFI.ArgInfo->KernargSegmentPtr,
2170 AMDGPU::SReg_64RegClass,
2171 MFI->ArgInfo.KernargSegmentPtr, 2, 0) ||
2172 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchID,
2173 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchID,
2174 2, 0) ||
2175 parseAndCheckArgument(YamlMFI.ArgInfo->FlatScratchInit,
2176 AMDGPU::SReg_64RegClass,
2177 MFI->ArgInfo.FlatScratchInit, 2, 0) ||
2178 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentSize,
2179 AMDGPU::SGPR_32RegClass,
2180 MFI->ArgInfo.PrivateSegmentSize, 0, 0) ||
2181 parseAndCheckArgument(YamlMFI.ArgInfo->LDSKernelId,
2182 AMDGPU::SGPR_32RegClass,
2183 MFI->ArgInfo.LDSKernelId, 0, 1) ||
2184 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDX,
2185 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDX,
2186 0, 1) ||
2187 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDY,
2188 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDY,
2189 0, 1) ||
2190 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDZ,
2191 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDZ,
2192 0, 1) ||
2193 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupInfo,
2194 AMDGPU::SGPR_32RegClass,
2195 MFI->ArgInfo.WorkGroupInfo, 0, 1) ||
2196 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentWaveByteOffset,
2197 AMDGPU::SGPR_32RegClass,
2198 MFI->ArgInfo.PrivateSegmentWaveByteOffset, 0, 1) ||
2199 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitArgPtr,
2200 AMDGPU::SReg_64RegClass,
2201 MFI->ArgInfo.ImplicitArgPtr, 0, 0) ||
2202 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitBufferPtr,
2203 AMDGPU::SReg_64RegClass,
2204 MFI->ArgInfo.ImplicitBufferPtr, 2, 0) ||
2205 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDX,
2206 AMDGPU::VGPR_32RegClass,
2207 MFI->ArgInfo.WorkItemIDX, 0, 0) ||
2208 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDY,
2209 AMDGPU::VGPR_32RegClass,
2210 MFI->ArgInfo.WorkItemIDY, 0, 0) ||
2211 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDZ,
2212 AMDGPU::VGPR_32RegClass,
2213 MFI->ArgInfo.WorkItemIDZ, 0, 0)))
2214 return true;
2215
2216 // Parse FirstKernArgPreloadReg separately, since it's a Register,
2217 // not ArgDescriptor.
2218 if (YamlMFI.ArgInfo && YamlMFI.ArgInfo->FirstKernArgPreloadReg) {
2219 const yaml::SIArgument &A = *YamlMFI.ArgInfo->FirstKernArgPreloadReg;
2220
2221 if (!A.IsRegister) {
2222 // For stack arguments, we don't have RegisterName.SourceRange,
2223 // but we should have some location info from the YAML parser
2224 const MemoryBuffer &Buffer =
2225 *PFS.SM->getMemoryBuffer(PFS.SM->getMainFileID());
2226 // Create a minimal valid source range
2228 SMRange Range(Loc, Loc);
2229
2231 *PFS.SM, Loc, Buffer.getBufferIdentifier(), 1, 0, SourceMgr::DK_Error,
2232 "firstKernArgPreloadReg must be a register, not a stack location", "",
2233 {}, {});
2234
2235 SourceRange = Range;
2236 return true;
2237 }
2238
2239 Register Reg;
2240 if (parseNamedRegisterReference(PFS, Reg, A.RegisterName.Value, Error)) {
2241 SourceRange = A.RegisterName.SourceRange;
2242 return true;
2243 }
2244
2245 if (!AMDGPU::SGPR_32RegClass.contains(Reg))
2246 return diagnoseRegisterClass(A.RegisterName);
2247
2248 MFI->ArgInfo.FirstKernArgPreloadReg = Reg;
2249 MFI->NumUserSGPRs += YamlMFI.NumKernargPreloadSGPRs;
2250 }
2251
2252 if (ST.hasFeature(AMDGPU::FeatureDX10ClampAndIEEEMode)) {
2253 MFI->Mode.IEEE = YamlMFI.Mode.IEEE;
2254 MFI->Mode.DX10Clamp = YamlMFI.Mode.DX10Clamp;
2255 }
2256
2257 // FIXME: Move proper support for denormal-fp-math into base MachineFunction
2258 MFI->Mode.FP32Denormals.Input = YamlMFI.Mode.FP32InputDenormals
2261 MFI->Mode.FP32Denormals.Output = YamlMFI.Mode.FP32OutputDenormals
2264
2271
2272 if (YamlMFI.HasInitWholeWave)
2273 MFI->setInitWholeWave();
2274
2275 return false;
2276}
2277
2278//===----------------------------------------------------------------------===//
2279// AMDGPU CodeGen Pass Builder interface.
2280//===----------------------------------------------------------------------===//
2281
2282AMDGPUCodeGenPassBuilder::AMDGPUCodeGenPassBuilder(
2283 GCNTargetMachine &TM, const CGPassBuilderOption &Opts,
2285 : CodeGenPassBuilder(TM, Opts, PIC) {
2286 Opt.MISchedPostRA = true;
2287 Opt.RequiresCodeGenSCCOrder = true;
2288 // Exceptions and StackMaps are not supported, so these passes will never do
2289 // anything.
2290 // Garbage collection is not supported.
2291 disablePass<StackMapLivenessPass, FuncletLayoutPass, PatchableFunctionPass,
2293}
2294
2295void AMDGPUCodeGenPassBuilder::addIRPasses(PassManagerWrapper &PMW) const {
2296 if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN()) {
2297 flushFPMsToMPM(PMW);
2298 addModulePass(AMDGPURemoveIncompatibleFunctionsPass(TM), PMW);
2299 }
2300
2301 flushFPMsToMPM(PMW);
2302
2303 if (TM.getTargetTriple().isAMDGCN())
2304 addModulePass(AMDGPUPrintfRuntimeBindingPass(), PMW);
2305
2306 if (LowerCtorDtor)
2307 addModulePass(AMDGPUCtorDtorLoweringPass(), PMW);
2308
2309 if (isPassEnabled(EnableImageIntrinsicOptimizer))
2310 addFunctionPass(AMDGPUImageIntrinsicOptimizerPass(TM), PMW);
2311
2313 addFunctionPass(AMDGPUUniformIntrinsicCombinePass(), PMW);
2314 // This can be disabled by passing ::Disable here or on the command line
2315 // with --expand-variadics-override=disable.
2316 flushFPMsToMPM(PMW);
2318
2319 addModulePass(AMDGPUAlwaysInlinePass(), PMW);
2320 addModulePass(AlwaysInlinerPass(), PMW);
2321
2322 addModulePass(AMDGPUExportKernelRuntimeHandlesPass(), PMW);
2323
2325 addModulePass(AMDGPULowerExecSyncPass(), PMW);
2326
2327 if (EnableSwLowerLDS)
2328 addModulePass(AMDGPUSwLowerLDSPass(), PMW);
2329
2330 // Runs before PromoteAlloca so the latter can account for function uses
2332 addModulePass(AMDGPULowerModuleLDSPass(TM), PMW);
2333
2334 // Run atomic optimizer before Atomic Expand
2335 if (TM.getOptLevel() >= CodeGenOptLevel::Less &&
2337 addFunctionPass(
2339
2340 addFunctionPass(AtomicExpandPass(TM), PMW);
2341
2342 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2343 addFunctionPass(AMDGPUPromoteAllocaPass(TM), PMW);
2344 if (isPassEnabled(EnableScalarIRPasses))
2345 addStraightLineScalarOptimizationPasses(PMW);
2346
2347 // TODO: Handle EnableAMDGPUAliasAnalysis
2348
2349 // TODO: May want to move later or split into an early and late one.
2350 addFunctionPass(AMDGPUCodeGenPreparePass(TM), PMW);
2351
2352 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
2353 // have expanded.
2354 if (TM.getOptLevel() > CodeGenOptLevel::Less) {
2356 /*UseMemorySSA=*/true),
2357 PMW);
2358 }
2359 }
2360
2361 Base::addIRPasses(PMW);
2362
2363 // EarlyCSE is not always strong enough to clean up what LSR produces. For
2364 // example, GVN can combine
2365 //
2366 // %0 = add %a, %b
2367 // %1 = add %b, %a
2368 //
2369 // and
2370 //
2371 // %0 = shl nsw %a, 2
2372 // %1 = shl %a, 2
2373 //
2374 // but EarlyCSE can do neither of them.
2375 if (isPassEnabled(EnableScalarIRPasses))
2376 addEarlyCSEOrGVNPass(PMW);
2377}
2378
2379void AMDGPUCodeGenPassBuilder::addCodeGenPrepare(
2380 PassManagerWrapper &PMW) const {
2381 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2382 flushFPMsToMPM(PMW);
2383 addModulePass(AMDGPUPreloadKernelArgumentsPass(TM), PMW);
2384 }
2385
2387 addFunctionPass(AMDGPULowerKernelArgumentsPass(TM), PMW);
2388
2389 Base::addCodeGenPrepare(PMW);
2390
2391 if (isPassEnabled(EnableLoadStoreVectorizer))
2392 addFunctionPass(LoadStoreVectorizerPass(), PMW);
2393
2394 // This lowering has been placed after codegenprepare to take advantage of
2395 // address mode matching (which is why it isn't put with the LDS lowerings).
2396 // It could be placed anywhere before uniformity annotations (an analysis
2397 // that it changes by splitting up fat pointers into their components)
2398 // but has been put before switch lowering and CFG flattening so that those
2399 // passes can run on the more optimized control flow this pass creates in
2400 // many cases.
2401 flushFPMsToMPM(PMW);
2402 addModulePass(AMDGPULowerBufferFatPointersPass(TM), PMW);
2403 flushFPMsToMPM(PMW);
2404 requireCGSCCOrder(PMW);
2405
2406 addModulePass(AMDGPULowerIntrinsicsPass(TM), PMW);
2407
2408 // LowerSwitch pass may introduce unreachable blocks that can cause unexpected
2409 // behavior for subsequent passes. Placing it here seems better that these
2410 // blocks would get cleaned up by UnreachableBlockElim inserted next in the
2411 // pass flow.
2412 addFunctionPass(LowerSwitchPass(), PMW);
2413}
2414
2415void AMDGPUCodeGenPassBuilder::addPreISel(PassManagerWrapper &PMW) const {
2416
2417 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2418 addFunctionPass(FlattenCFGPass(), PMW);
2419 addFunctionPass(SinkingPass(), PMW);
2420 addFunctionPass(AMDGPULateCodeGenPreparePass(TM), PMW);
2421 }
2422
2423 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
2424 // regions formed by them.
2425
2426 addFunctionPass(AMDGPUUnifyDivergentExitNodesPass(), PMW);
2427 addFunctionPass(FixIrreduciblePass(), PMW);
2428 addFunctionPass(UnifyLoopExitsPass(), PMW);
2429 addFunctionPass(StructurizeCFGPass(/*SkipUniformRegions=*/false), PMW);
2430
2431 addFunctionPass(AMDGPUAnnotateUniformValuesPass(), PMW);
2432
2433 addFunctionPass(SIAnnotateControlFlowPass(TM), PMW);
2434
2435 // TODO: Move this right after structurizeCFG to avoid extra divergence
2436 // analysis. This depends on stopping SIAnnotateControlFlow from making
2437 // control flow modifications.
2438 addFunctionPass(AMDGPURewriteUndefForPHIPass(), PMW);
2439
2442 !isGlobalISelAbortEnabled())
2443 addFunctionPass(LCSSAPass(), PMW);
2444
2445 if (TM.getOptLevel() > CodeGenOptLevel::Less) {
2446 flushFPMsToMPM(PMW);
2447 addModulePass(AMDGPUPerfHintAnalysisPass(TM), PMW);
2448 }
2449
2450 // FIXME: Why isn't this queried as required from AMDGPUISelDAGToDAG, and why
2451 // isn't this in addInstSelector?
2453 /*Force=*/true);
2454}
2455
2456void AMDGPUCodeGenPassBuilder::addILPOpts(PassManagerWrapper &PMW) const {
2458 addMachineFunctionPass(EarlyIfConverterPass(), PMW);
2459
2460 Base::addILPOpts(PMW);
2461}
2462
2463void AMDGPUCodeGenPassBuilder::addAsmPrinterBegin(
2464 PassManagerWrapper &PMW) const {
2465 addModulePass(AMDGPUAsmPrinterBeginPass(), PMW,
2466 /*Force=*/true);
2467}
2468
2469void AMDGPUCodeGenPassBuilder::addAsmPrinter(PassManagerWrapper &PMW) const {
2470 addMachineFunctionPass(AMDGPUAsmPrinterPass(), PMW);
2471}
2472
2473void AMDGPUCodeGenPassBuilder::addAsmPrinterEnd(PassManagerWrapper &PMW) const {
2474 addModulePass(AMDGPUAsmPrinterEndPass(), PMW);
2475}
2476
2477Error AMDGPUCodeGenPassBuilder::addInstSelector(PassManagerWrapper &PMW) const {
2478 addMachineFunctionPass(AMDGPUISelDAGToDAGPass(TM), PMW);
2479 addMachineFunctionPass(SIFixSGPRCopiesPass(), PMW);
2480 addMachineFunctionPass(SILowerI1CopiesPass(), PMW);
2481 return Error::success();
2482}
2483
2484void AMDGPUCodeGenPassBuilder::addPreRewrite(PassManagerWrapper &PMW) const {
2485 if (EnableRegReassign) {
2486 addMachineFunctionPass(GCNNSAReassignPass(), PMW);
2487 }
2488
2489 addMachineFunctionPass(AMDGPURewriteAGPRCopyMFMAPass(), PMW);
2490}
2491
2492void AMDGPUCodeGenPassBuilder::addMachineSSAOptimization(
2493 PassManagerWrapper &PMW) const {
2494 Base::addMachineSSAOptimization(PMW);
2495
2496 addMachineFunctionPass(SIFoldOperandsPass(), PMW);
2497 if (EnableDPPCombine) {
2498 addMachineFunctionPass(GCNDPPCombinePass(), PMW);
2499 }
2500 addMachineFunctionPass(SILoadStoreOptimizerPass(), PMW);
2501 if (isPassEnabled(EnableSDWAPeephole)) {
2502 addMachineFunctionPass(SIPeepholeSDWAPass(), PMW);
2503 addMachineFunctionPass(EarlyMachineLICMPass(), PMW);
2504 addMachineFunctionPass(MachineCSEPass(), PMW);
2505 addMachineFunctionPass(SIFoldOperandsPass(), PMW);
2506 }
2507 addMachineFunctionPass(DeadMachineInstructionElimPass(), PMW);
2508 addMachineFunctionPass(SIShrinkInstructionsPass(), PMW);
2509}
2510
2511Error AMDGPUCodeGenPassBuilder::addFastRegAlloc(PassManagerWrapper &PMW) const {
2512 insertPass<PHIEliminationPass>(SILowerControlFlowPass());
2513
2514 insertPass<TwoAddressInstructionPass>(SIWholeQuadModePass());
2515
2516 return Base::addFastRegAlloc(PMW);
2517}
2518
2519Error AMDGPUCodeGenPassBuilder::addRegAssignmentFast(
2520 PassManagerWrapper &PMW) const {
2521 if (auto Err = validateRegAllocOptions())
2522 return Err;
2523
2524 addMachineFunctionPass(GCNPreRALongBranchRegPass(), PMW);
2525
2526 // SGPR allocation - default to fast at -O0.
2527 if (SGPRRegAllocNPM == RegAllocType::Greedy)
2528 addMachineFunctionPass(RAGreedyPass({onlyAllocateSGPRs, "sgpr"}), PMW);
2529 else
2530 addMachineFunctionPass(RegAllocFastPass({onlyAllocateSGPRs, "sgpr", false}),
2531 PMW);
2532
2533 // Equivalent of PEI for SGPRs.
2534 addMachineFunctionPass(SILowerSGPRSpillsPass(), PMW);
2535
2536 // To Allocate wwm registers used in whole quad mode operations (for shaders).
2537 addMachineFunctionPass(SIPreAllocateWWMRegsPass(), PMW);
2538
2539 // WWM allocation - default to fast at -O0.
2540 if (WWMRegAllocNPM == RegAllocType::Greedy)
2541 addMachineFunctionPass(RAGreedyPass({onlyAllocateWWMRegs, "wwm"}), PMW);
2542 else
2543 addMachineFunctionPass(
2544 RegAllocFastPass({onlyAllocateWWMRegs, "wwm", false}), PMW);
2545
2546 addMachineFunctionPass(SILowerWWMCopiesPass(), PMW);
2547 addMachineFunctionPass(AMDGPUReserveWWMRegsPass(), PMW);
2548
2549 // VGPR allocation - default to fast at -O0.
2550 if (VGPRRegAllocNPM == RegAllocType::Greedy)
2551 addMachineFunctionPass(RAGreedyPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2552 else
2553 addMachineFunctionPass(RegAllocFastPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2554
2555 return Error::success();
2556}
2557
2558Error AMDGPUCodeGenPassBuilder::addOptimizedRegAlloc(
2559 PassManagerWrapper &PMW) const {
2560 if (EnableDCEInRA)
2561 insertPass<DetectDeadLanesPass>(DeadMachineInstructionElimPass());
2562
2563 // FIXME: when an instruction has a Killed operand, and the instruction is
2564 // inside a bundle, seems only the BUNDLE instruction appears as the Kills of
2565 // the register in LiveVariables, this would trigger a failure in verifier,
2566 // we should fix it and enable the verifier.
2567 if (OptVGPRLiveRange)
2568 insertPass<RequireAnalysisPass<LiveVariablesAnalysis, MachineFunction>>(
2570
2571 // This must be run immediately after phi elimination and before
2572 // TwoAddressInstructions, otherwise the processing of the tied operand of
2573 // SI_ELSE will introduce a copy of the tied operand source after the else.
2574 insertPass<PHIEliminationPass>(SILowerControlFlowPass());
2575
2577 insertPass<RenameIndependentSubregsPass>(GCNRewritePartialRegUsesPass());
2578
2579 if (isPassEnabled(EnablePreRAOptimizations))
2580 insertPass<MachineSchedulerPass>(GCNPreRAOptimizationsPass());
2581
2582 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
2583 // instructions that cause scheduling barriers.
2584 insertPass<MachineSchedulerPass>(SIWholeQuadModePass());
2585
2586 if (OptExecMaskPreRA)
2587 insertPass<MachineSchedulerPass>(SIOptimizeExecMaskingPreRAPass());
2588
2589 // This is not an essential optimization and it has a noticeable impact on
2590 // compilation time, so we only enable it from O2.
2591 if (TM.getOptLevel() > CodeGenOptLevel::Less)
2592 insertPass<MachineSchedulerPass>(SIFormMemoryClausesPass());
2593
2594 return Base::addOptimizedRegAlloc(PMW);
2595}
2596
2597void AMDGPUCodeGenPassBuilder::addPreRegAlloc(PassManagerWrapper &PMW) const {
2598 if (getOptLevel() != CodeGenOptLevel::None)
2599 addMachineFunctionPass(AMDGPUPrepareAGPRAllocPass(), PMW);
2600}
2601
2602Error AMDGPUCodeGenPassBuilder::addRegAssignmentOptimized(
2603 PassManagerWrapper &PMW) const {
2604 if (auto Err = validateRegAllocOptions())
2605 return Err;
2606
2607 addMachineFunctionPass(GCNPreRALongBranchRegPass(), PMW);
2608
2609 // SGPR allocation - default to greedy at -O1 and above.
2610 if (SGPRRegAllocNPM == RegAllocType::Fast)
2611 addMachineFunctionPass(RegAllocFastPass({onlyAllocateSGPRs, "sgpr", false}),
2612 PMW);
2613 else
2614 addMachineFunctionPass(RAGreedyPass({onlyAllocateSGPRs, "sgpr"}), PMW);
2615
2616 // Commit allocated register changes. This is mostly necessary because too
2617 // many things rely on the use lists of the physical registers, such as the
2618 // verifier. This is only necessary with allocators which use LiveIntervals,
2619 // since FastRegAlloc does the replacements itself.
2620 addMachineFunctionPass(VirtRegRewriterPass(false), PMW);
2621
2622 // At this point, the sgpr-regalloc has been done and it is good to have the
2623 // stack slot coloring to try to optimize the SGPR spill stack indices before
2624 // attempting the custom SGPR spill lowering.
2625 addMachineFunctionPass(StackSlotColoringPass(), PMW);
2626
2627 // Equivalent of PEI for SGPRs.
2628 addMachineFunctionPass(SILowerSGPRSpillsPass(), PMW);
2629
2630 // To Allocate wwm registers used in whole quad mode operations (for shaders).
2631 addMachineFunctionPass(SIPreAllocateWWMRegsPass(), PMW);
2632
2633 // WWM allocation - default to greedy at -O1 and above.
2634 if (WWMRegAllocNPM == RegAllocType::Fast)
2635 addMachineFunctionPass(
2636 RegAllocFastPass({onlyAllocateWWMRegs, "wwm", false}), PMW);
2637 else
2638 addMachineFunctionPass(RAGreedyPass({onlyAllocateWWMRegs, "wwm"}), PMW);
2639 addMachineFunctionPass(SILowerWWMCopiesPass(), PMW);
2640 addMachineFunctionPass(VirtRegRewriterPass(false), PMW);
2641 addMachineFunctionPass(AMDGPUReserveWWMRegsPass(), PMW);
2642
2643 // VGPR allocation - default to greedy at -O1 and above.
2644 if (VGPRRegAllocNPM == RegAllocType::Fast)
2645 addMachineFunctionPass(RegAllocFastPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2646 else
2647 addMachineFunctionPass(RAGreedyPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2648
2649 addPreRewrite(PMW);
2650 addMachineFunctionPass(VirtRegRewriterPass(true), PMW);
2651
2652 addMachineFunctionPass(AMDGPUMarkLastScratchLoadPass(), PMW);
2653 return Error::success();
2654}
2655
2656void AMDGPUCodeGenPassBuilder::addPostRegAlloc(PassManagerWrapper &PMW) const {
2657 addMachineFunctionPass(SIFixVGPRCopiesPass(), PMW);
2658 if (TM.getOptLevel() > CodeGenOptLevel::None)
2659 addMachineFunctionPass(SIOptimizeExecMaskingPass(), PMW);
2660 Base::addPostRegAlloc(PMW);
2661}
2662
2663void AMDGPUCodeGenPassBuilder::addPreSched2(PassManagerWrapper &PMW) const {
2664 if (TM.getOptLevel() > CodeGenOptLevel::None)
2665 addMachineFunctionPass(SIShrinkInstructionsPass(), PMW);
2666 addMachineFunctionPass(SIPostRABundlerPass(), PMW);
2667}
2668
2669void AMDGPUCodeGenPassBuilder::addPostBBSections(
2670 PassManagerWrapper &PMW) const {
2671 // We run this later to avoid passes like livedebugvalues and BBSections
2672 // having to deal with the apparent multi-entry functions we may generate.
2673 addMachineFunctionPass(AMDGPUPreloadKernArgPrologPass(), PMW);
2674}
2675
2676void AMDGPUCodeGenPassBuilder::addPreEmitPass(PassManagerWrapper &PMW) const {
2677 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less)) {
2678 addMachineFunctionPass(GCNCreateVOPDPass(), PMW);
2679 }
2680
2681 addMachineFunctionPass(SIMemoryLegalizerPass(), PMW);
2682 addMachineFunctionPass(SIInsertWaitcntsPass(), PMW);
2683
2684 addMachineFunctionPass(SIModeRegisterPass(), PMW);
2685
2686 if (TM.getOptLevel() > CodeGenOptLevel::None)
2687 addMachineFunctionPass(SIInsertHardClausesPass(), PMW);
2688
2689 addMachineFunctionPass(SILateBranchLoweringPass(), PMW);
2690
2691 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
2692 addMachineFunctionPass(AMDGPUSetWavePriorityPass(), PMW);
2693
2694 if (TM.getOptLevel() > CodeGenOptLevel::None)
2695 addMachineFunctionPass(SIPreEmitPeepholePass(), PMW);
2696
2697 // The hazard recognizer that runs as part of the post-ra scheduler does not
2698 // guarantee to be able handle all hazards correctly. This is because if there
2699 // are multiple scheduling regions in a basic block, the regions are scheduled
2700 // bottom up, so when we begin to schedule a region we don't know what
2701 // instructions were emitted directly before it.
2702 //
2703 // Here we add a stand-alone hazard recognizer pass which can handle all
2704 // cases.
2705 addMachineFunctionPass(PostRAHazardRecognizerPass(), PMW);
2706 addMachineFunctionPass(AMDGPUWaitSGPRHazardsPass(), PMW);
2707 addMachineFunctionPass(AMDGPULowerVGPREncodingPass(), PMW);
2708
2709 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less)) {
2710 addMachineFunctionPass(AMDGPUInsertDelayAluPass(), PMW);
2711 }
2712
2713 addMachineFunctionPass(BranchRelaxationPass(), PMW);
2714}
2715
2716bool AMDGPUCodeGenPassBuilder::isPassEnabled(const cl::opt<bool> &Opt,
2717 CodeGenOptLevel Level) const {
2718 if (Opt.getNumOccurrences())
2719 return Opt;
2720 if (TM.getOptLevel() < Level)
2721 return false;
2722 return Opt;
2723}
2724
2725void AMDGPUCodeGenPassBuilder::addEarlyCSEOrGVNPass(
2726 PassManagerWrapper &PMW) const {
2727 if (TM.getOptLevel() == CodeGenOptLevel::Aggressive)
2728 addFunctionPass(GVNPass(), PMW);
2729 else
2730 addFunctionPass(EarlyCSEPass(), PMW);
2731}
2732
2733void AMDGPUCodeGenPassBuilder::addStraightLineScalarOptimizationPasses(
2734 PassManagerWrapper &PMW) const {
2736 addFunctionPass(LoopDataPrefetchPass(), PMW);
2737
2738 addFunctionPass(SeparateConstOffsetFromGEPPass(), PMW);
2739
2740 // ReassociateGEPs exposes more opportunities for SLSR. See
2741 // the example in reassociate-geps-and-slsr.ll.
2742 addFunctionPass(StraightLineStrengthReducePass(), PMW);
2743
2744 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
2745 // EarlyCSE can reuse.
2746 addEarlyCSEOrGVNPass(PMW);
2747
2748 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
2749 addFunctionPass(NaryReassociatePass(), PMW);
2750
2751 // NaryReassociate on GEPs creates redundant common expressions, so run
2752 // EarlyCSE after it.
2753 addFunctionPass(EarlyCSEPass(), PMW);
2754}
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.
AMDGPU Assembly printer class.
Coexecution-focused scheduling strategy for AMDGPU.
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 Reloc::Model getEffectiveRelocModel()
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 OOBFlagValue getOOBFlagValue(const Module &M, StringRef FlagName)
Returns the OOB mode encoded by a module flag.
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 cl::opt< bool, true > EnableObjectLinking("amdgpu-enable-object-linking", cl::desc("Enable object linking for cross-TU LDS and ABI support"), cl::location(AMDGPUTargetMachine::EnableObjectLinking), cl::init(false), 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 void diagnoseUnsupportedCoExecSchedulerSelection(const Function &F, const GCNSubtarget &ST)
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 bool useNoopPostScheduler(const Function &F)
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)
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 > 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 ScheduleDAGInstrs * createGCNMaxOccupancyMachineScheduler(MachineSchedContext *C)
static cl::opt< bool > EnableLowerExecSync("amdgpu-enable-lower-exec-sync", cl::desc("Enable lowering of execution synchronization."), cl::init(true), cl::Hidden)
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.
#define X(NUM, ENUM, NAME)
Definition ELF.h:856
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:317
#define LLVM_ABI
Definition Compiler.h:215
#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.
Module.h This file contains the declarations for the Module class.
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:54
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
#define T
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
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 bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:484
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
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
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".
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:105
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:261
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.
Diagnostic information for unsupported feature in backend.
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
LowerIntrinsics - This pass rewrites calls to the llvm.gcread or llvm.gcwrite intrinsics,...
Definition GCMetadata.h:229
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.
yaml::MachineFunctionInfo * createDefaultFuncInfoYAML() const override
Allocate and return a default initialized instance of the YAML representation for the MachineFunction...
Error buildCodeGenPipeline(ModulePassManager &MPM, ModuleAnalysisManager &MAM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, const CGPassBuilderOption &Opts, MCContext &Ctx, PassInstrumentationCallbacks *PIC) override
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:131
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
static void setUseExtended(bool Enable)
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.
Context object for machine code objects.
Definition MCContext.h:83
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,...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
void addDelegate(Delegate *delegate)
const MachineFunction & getMF() const
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.
const char * getBufferStart() const
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
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
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:20
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:303
Represents a location in source code.
Definition SMLoc.h:22
static SMLoc getFromPointer(const char *Ptr)
Definition SMLoc.h:35
Represents a range in source code.
Definition SMLoc.h:47
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:151
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition SourceMgr.h:144
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:736
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
bool consume_front(char Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition StringRef.h:661
A switch()-like statement whose cases are string literals.
StringSwitch & Cases(std::initializer_list< StringLiteral > CaseStrings, 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
std::unique_ptr< const MCRegisterInfo > MRI
CodeGenOptLevel OptLevel
void setEnableDefaultMachineVerifier(bool Enable)
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
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
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.
@ 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.
constexpr StringLiteral BufferFlag("amdgpu.buffer.oob.mode")
constexpr StringLiteral TBufferFlag("amdgpu.tbuffer.oob.mode")
StringRef getSchedStrategy(const Function &F)
GPUKind
GPU kinds supported by the AMDGPU target.
bool isFlatGlobalAddrSpace(unsigned AS)
LLVM_READNONE constexpr bool isModuleEntryFunctionCC(CallingConv::ID CC)
LLVM_READNONE constexpr bool isEntryFunctionCC(CallingConv::ID CC)
LLVM_ABI Triple::SubArchType getSubArch(GPUKind AK)
LLVM_ABI StringRef getArchNameFromSubArch(Triple::SubArchType SubArch)
Returns the canonical GPU name for an AMDGPU subarch, e.g.
LLVM_ABI GPUKind parseArchAMDGCN(StringRef CPU)
LLVM_ABI Triple::SubArchType getMajorSubArch(Triple::SubArchType SubArch)
@ 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)
match_deferred< 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()...
auto m_Value()
Match an arbitrary value and ignore it.
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
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)
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract_or_null(Y &&MD)
Extract a Value from Metadata, if any, allowing null.
Definition Metadata.h:709
This is an optimization pass for GlobalISel generic memory operations.
ScheduleDAGMILive * createSchedLive(MachineSchedContext *C)
Create the standard converging machine scheduler.
LLVM_ABI FunctionPass * createFlattenCFGPass()
ModulePass * createAMDGPUSwLowerLDSLegacyPass()
std::unique_ptr< ScheduleDAGMutation > createAMDGPUBarrierLatencyDAGMutation(MachineFunction *MF)
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 &)
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:643
ModuleToFunctionPassAdaptor createModuleToFunctionPassAdaptor(FunctionPassT &&Pass, bool EagerlyInvalidate=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
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:94
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 initializeAMDGPUNextUseAnalysisLegacyPassPass(PassRegistry &)
void initializeR600ExpandSpecialInstrsPassPass(PassRegistry &)
void initializeR600PacketizerPass(PassRegistry &)
@ O1
Optimize quickly without destroying debuggability.
@ O0
Disable as many optimizations as possible.
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:85
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:386
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.
FunctionPass * createAMDGPUUniformIntrinsicCombineLegacyPass()
void initializeAMDGPURegBankCombinerPass(PassRegistry &)
ThinOrFullLTOPhase
This enumerates the LLVM full LTO or ThinLTO optimization phases.
Definition Pass.h:77
@ FullLTOPostLink
Full LTO postlink (backend compile) phase.
Definition Pass.h:87
char & AMDGPUUnifyDivergentExitNodesID
void initializeAMDGPUPrepareAGPRAllocLegacyPass(PassRegistry &)
FunctionPass * createAMDGPUAtomicOptimizerPass(ScanOptions ScanStrategy)
FunctionPass * createAMDGPUPreloadKernArgPrologLegacyPass()
char & SIOptimizeVGPRLiveRangeLegacyID
LLVM_ABI char & ShadowStackGCLoweringID
ShadowStackGCLowering - Implements the custom lowering mechanism used by the shadow stack GC.
char & GCNNSAReassignID
void initializeAMDGPURewriteOutArgumentsPass(PassRegistry &)
static Reloc::Model getEffectiveRelocModel(std::optional< Reloc::Model > RM)
void initializeAMDGPUExternalAAWrapperPass(PassRegistry &)
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
void initializeAMDGPULowerKernelArgumentsPass(PassRegistry &)
void initializeSIModeRegisterLegacyPass(PassRegistry &)
CodeModel::Model getEffectiveCodeModel(std::optional< CodeModel::Model > CM, CodeModel::Model Default)
Helper method for getting the code model, returning Default if CM does not have a value.
void initializeAMDGPUPreloadKernelArgumentsLegacyPass(PassRegistry &)
LLVM_ABI ModulePass * createExpandVariadicsPass(ExpandVariadicsMode)
char & SILateBranchLoweringPassID
FunctionToLoopPassAdaptor createFunctionToLoopPassAdaptor(LoopPassT &&Pass, bool UseMemorySSA=false)
A function to deduce a loop pass type and wrap it in the templated adaptor.
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 initializeAMDGPULowerExecSyncLegacyPass(PassRegistry &)
void initializeAMDGPUPostLegalizerCombinerPass(PassRegistry &)
ScheduleDAGInstrs * createGCNNoopPostMachineScheduler(MachineSchedContext *C)
void initializeAMDGPUExportKernelRuntimeHandlesLegacyPass(PassRegistry &)
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
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 initializeAMDGPUUniformIntrinsicCombineLegacyPass(PassRegistry &)
ScheduleDAGInstrs * createGCNCoExecMachineScheduler(MachineSchedContext *C)
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()
Definition GVN.cpp:4070
void initializeAMDGPURewriteAGPRCopyMFMALegacyPass(PassRegistry &)
void initializeAMDGPUNextUseAnalysisPrinterLegacyPassPass(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 &)
LLVM_ABI FunctionPass * createLowerSwitchPass()
void initializeAMDGPUPreloadKernArgPrologLegacyPass(PassRegistry &)
Target & getTheGCNLegacyTarget()
The target for GCN GPUs, registered under the legacy "amdgcn" architecture name for use with -march.
LLVM_ABI FunctionPass * createVirtRegRewriter(bool ClearVirtRegs=true)
void initializeR600VectorRegMergerPass(PassRegistry &)
char & AMDGPURewriteAGPRCopyMFMALegacyID
ModulePass * createAMDGPULowerExecSyncLegacyPass()
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()
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:390
FunctionPass * createAMDGPUImageIntrinsicOptimizerPass(const TargetMachine *)
void initializeAMDGPULowerBufferFatPointersPass(PassRegistry &)
void initializeAMDGPUUnifyDivergentExitNodesLegacyPass(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
LLVM_ABI bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
void initializeAMDGPUResourceUsageAnalysisWrapperPassPass(PassRegistry &)
FunctionPass * createSIShrinkInstructionsLegacyPass()
char & AMDGPUPrepareAGPRAllocLegacyID
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 &)
std::unique_ptr< ScheduleDAGMutation > createAMDGPUHazardLatencyDAGMutation(MachineFunction *MF)
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
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
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:177
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:180
DenseMap< Register, VRegInfo * > VRegInfos
Definition MIParser.h:179
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.