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 addRegAssignAndRewriteFast(PassManagerWrapper &PMW) const;
166 Expected<bool> addRegAssignAndRewriteOptimized(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
473static cl::opt<bool>
474 XnackSetting("amdgpu-xnack",
475 cl::desc("Force amdgpu.xnack value for testing"),
477
478static cl::opt<bool>
479 SramEccSetting("amdgpu-sramecc",
480 cl::desc("Force amdgpu.sramecc for testing"),
482
483// Enable lib calls simplifications
485 "amdgpu-simplify-libcall",
486 cl::desc("Enable amdgpu library simplifications"),
487 cl::init(true),
488 cl::Hidden);
489
491 "amdgpu-ir-lower-kernel-arguments",
492 cl::desc("Lower kernel argument loads in IR pass"),
493 cl::init(true),
494 cl::Hidden);
495
497 "amdgpu-reassign-regs",
498 cl::desc("Enable register reassign optimizations on gfx10+"),
499 cl::init(true),
500 cl::Hidden);
501
503 "amdgpu-opt-vgpr-liverange",
504 cl::desc("Enable VGPR liverange optimizations for if-else structure"),
505 cl::init(true), cl::Hidden);
506
508 "amdgpu-atomic-optimizer-strategy",
509 cl::desc("Select DPP or Iterative strategy for scan"),
512 clEnumValN(ScanOptions::DPP, "DPP", "Use DPP operations for scan"),
514 "Use Iterative approach for scan"),
515 clEnumValN(ScanOptions::None, "None", "Disable atomic optimizer")));
516
517// Enable Mode register optimization
519 "amdgpu-mode-register",
520 cl::desc("Enable mode register pass"),
521 cl::init(true),
522 cl::Hidden);
523
524// Enable GFX11+ s_delay_alu insertion
525static cl::opt<bool>
526 EnableInsertDelayAlu("amdgpu-enable-delay-alu",
527 cl::desc("Enable s_delay_alu insertion"),
528 cl::init(true), cl::Hidden);
529
530// Enable GFX11+ VOPD
531static cl::opt<bool>
532 EnableVOPD("amdgpu-enable-vopd",
533 cl::desc("Enable VOPD, dual issue of VALU in wave32"),
534 cl::init(true), cl::Hidden);
535
536// Option is used in lit tests to prevent deadcoding of patterns inspected.
537static cl::opt<bool>
538EnableDCEInRA("amdgpu-dce-in-ra",
539 cl::init(true), cl::Hidden,
540 cl::desc("Enable machine DCE inside regalloc"));
541
542static cl::opt<bool> EnableSetWavePriority("amdgpu-set-wave-priority",
543 cl::desc("Adjust wave priority"),
544 cl::init(false), cl::Hidden);
545
547 "amdgpu-scalar-ir-passes",
548 cl::desc("Enable scalar IR passes"),
549 cl::init(true),
550 cl::Hidden);
551
553 "amdgpu-enable-lower-exec-sync",
554 cl::desc("Enable lowering of execution synchronization."), cl::init(true),
555 cl::Hidden);
556
557static cl::opt<bool>
558 EnableSwLowerLDS("amdgpu-enable-sw-lower-lds",
559 cl::desc("Enable lowering of lds to global memory pass "
560 "and asan instrument resulting IR."),
561 cl::init(true), cl::Hidden);
562
564 "amdgpu-enable-object-linking",
565 cl::desc("Enable object linking for cross-TU LDS and ABI support"),
567 cl::Hidden);
568
570 "amdgpu-enable-lower-module-lds", cl::desc("Enable lower module lds pass"),
572 cl::Hidden);
573
575 "amdgpu-enable-pre-ra-optimizations",
576 cl::desc("Enable Pre-RA optimizations pass"), cl::init(true),
577 cl::Hidden);
578
580 "amdgpu-enable-promote-kernel-arguments",
581 cl::desc("Enable promotion of flat kernel pointer arguments to global"),
582 cl::Hidden, cl::init(true));
583
585 "amdgpu-enable-image-intrinsic-optimizer",
586 cl::desc("Enable image intrinsic optimizer pass"), cl::init(true),
587 cl::Hidden);
588
589static cl::opt<bool>
590 EnableLoopPrefetch("amdgpu-loop-prefetch",
591 cl::desc("Enable loop data prefetch on AMDGPU"),
592 cl::Hidden, cl::init(false));
593
595 AMDGPUSchedStrategy("amdgpu-sched-strategy",
596 cl::desc("Select custom AMDGPU scheduling strategy."),
597 cl::Hidden, cl::init(""));
598
599// Scheduler selection is consulted both when creating the scheduler and from
600// overrideSchedPolicy(), so keep the attribute and global command line handling
601// in one helper.
603 Attribute SchedStrategyAttr = F.getFnAttribute("amdgpu-sched-strategy");
604 if (SchedStrategyAttr.isValid())
605 return SchedStrategyAttr.getValueAsString();
606
607 if (!AMDGPUSchedStrategy.empty())
608 return AMDGPUSchedStrategy;
609
610 return "";
611}
612
613static void
615 const GCNSubtarget &ST) {
616 if (ST.hasGFX1250Insts())
617 return;
618
619 F.getContext().diagnose(DiagnosticInfoUnsupported(
620 F, "'amdgpu-sched-strategy'='coexec' is only supported for gfx1250",
622}
623
624static bool useNoopPostScheduler(const Function &F) {
625 Attribute PostSchedStrategyAttr =
626 F.getFnAttribute("amdgpu-post-sched-strategy");
627 return PostSchedStrategyAttr.isValid() &&
628 PostSchedStrategyAttr.getValueAsString() == "nop";
629}
630
632 "amdgpu-enable-rewrite-partial-reg-uses",
633 cl::desc("Enable rewrite partial reg uses pass"), cl::init(true),
634 cl::Hidden);
635
637 "amdgpu-enable-hipstdpar",
638 cl::desc("Enable HIP Standard Parallelism Offload support"), cl::init(false),
639 cl::Hidden);
640
641static cl::opt<bool>
642 EnableAMDGPUAttributor("amdgpu-attributor-enable",
643 cl::desc("Enable AMDGPUAttributorPass"),
644 cl::init(true), cl::Hidden);
645
647 "amdgpu-link-time-closed-world",
648 cl::desc("Whether has closed-world assumption at link time"),
649 cl::init(false), cl::Hidden);
650
652 "amdgpu-enable-uniform-intrinsic-combine",
653 cl::desc("Enable/Disable the Uniform Intrinsic Combine Pass"),
654 cl::init(true), cl::Hidden);
655
657 // Register the target
661
747}
748
749static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
750 return std::make_unique<AMDGPUTargetObjectFile>();
751}
752
756
757static ScheduleDAGInstrs *
759 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
760 ScheduleDAGMILive *DAG =
761 new GCNScheduleDAGMILive(C, std::make_unique<GCNMaxOccupancySchedStrategy>(C));
762 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
763 if (ST.shouldClusterStores())
764 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
766 DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
767 DAG->addMutation(createAMDGPUExportClusteringDAGMutation());
768 DAG->addMutation(createAMDGPUBarrierLatencyDAGMutation(C->MF));
769 DAG->addMutation(createAMDGPUHazardLatencyDAGMutation(C->MF));
770 return DAG;
771}
772
773static ScheduleDAGInstrs *
775 ScheduleDAGMILive *DAG =
776 new GCNScheduleDAGMILive(C, std::make_unique<GCNMaxILPSchedStrategy>(C));
778 return DAG;
779}
780
781static ScheduleDAGInstrs *
783 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
785 C, std::make_unique<GCNMaxMemoryClauseSchedStrategy>(C));
786 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
787 if (ST.shouldClusterStores())
788 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
789 DAG->addMutation(createAMDGPUExportClusteringDAGMutation());
790 DAG->addMutation(createAMDGPUBarrierLatencyDAGMutation(C->MF));
791 DAG->addMutation(createAMDGPUHazardLatencyDAGMutation(C->MF));
792 return DAG;
793}
794
795static ScheduleDAGInstrs *
797 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
798 auto *DAG = new GCNIterativeScheduler(
800 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
801 if (ST.shouldClusterStores())
802 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
804 return DAG;
805}
806
813
814static ScheduleDAGInstrs *
816 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
818 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
819 if (ST.shouldClusterStores())
820 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
821 DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
823 return DAG;
824}
825
826static MachineSchedRegistry
827SISchedRegistry("si", "Run SI's custom scheduler",
829
832 "Run GCN scheduler to maximize occupancy",
834
836 GCNMaxILPSchedRegistry("gcn-max-ilp", "Run GCN scheduler to maximize ilp",
838
840 "gcn-max-memory-clause", "Run GCN scheduler to maximize memory clause",
842
844 "gcn-iterative-max-occupancy-experimental",
845 "Run GCN scheduler to maximize occupancy (experimental)",
847
849 "gcn-iterative-minreg",
850 "Run GCN iterative scheduler for minimal register usage (experimental)",
852
854 "gcn-iterative-ilp",
855 "Run GCN iterative scheduler for ILP scheduling (experimental)",
857
860 if (!GPU.empty())
861 return GPU;
862
863 if (StringRef Name = AMDGPU::getArchNameFromSubArch(TT.getSubArch());
864 !Name.empty())
865 return Name;
866
867 // Need to default to a target with flat support for HSA.
868 if (TT.isAMDGCN())
869 return TT.getOS() == Triple::AMDHSA ? "generic-hsa" : "generic";
870
871 return "r600";
872}
873
875 // The AMDGPU toolchain only supports generating shared objects, so we
876 // must always use PIC.
877 return Reloc::PIC_;
878}
879
881 StringRef CPU, StringRef FS,
882 const TargetOptions &Options,
883 std::optional<Reloc::Model> RM,
884 std::optional<CodeModel::Model> CM,
887 T, TT.computeDataLayout(), TT, getGPUOrDefault(TT, CPU), FS, Options,
889 OptLevel),
891 initAsmInfo();
892 if (TT.isAMDGCN()) {
893 // Triple is missing a representation for non-empty, but unrecognized
894 // subarches. Only permit no subarch for any subtarget if it was really
895 // empty.
896 bool IsUnknownSubArch =
897 TT.getSubArch() == Triple::NoSubArch && TT.getArchName().size() != 6;
898 if (IsUnknownSubArch)
899 reportFatalUsageError("unknown subarch " + TT.getArchName());
900
901 if (TT.getSubArch() != Triple::NoSubArch) {
903 Triple::SubArchType GPUSubArch = AMDGPU::getSubArch(Kind);
904 if (Kind != AMDGPU::GK_NONE && GPUSubArch != TT.getSubArch() &&
905 TT.getSubArch() != AMDGPU::getMajorSubArch(GPUSubArch)) {
906 reportFatalUsageError("invalid cpu '" + CPU + "' for subarch " +
907 TT.getArchName());
908 }
909 }
910
911 if (getMCSubtargetInfo().checkFeatures("+wavefrontsize64"))
913 else if (getMCSubtargetInfo().checkFeatures("+wavefrontsize32"))
915 }
917}
918
922
924
926 Attribute GPUAttr = F.getFnAttribute("target-cpu");
927 return GPUAttr.isValid() ? GPUAttr.getValueAsString() : getTargetCPU();
928}
929
931 Attribute FSAttr = F.getFnAttribute("target-features");
932
933 return FSAttr.isValid() ? FSAttr.getValueAsString()
935}
936
939 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
941 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
942 if (ST.shouldClusterStores())
943 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
944 return DAG;
945}
946
947/// Predicate for Internalize pass.
948static bool mustPreserveGV(const GlobalValue &GV) {
949 if (const Function *F = dyn_cast<Function>(&GV))
950 return F->isDeclaration() || F->getName().starts_with("__asan_") ||
951 F->getName().starts_with("__sanitizer_") ||
952 AMDGPU::isEntryFunctionCC(F->getCallingConv());
953
955 return !GV.use_empty();
956}
957
962
965 if (Params.empty())
967 Params.consume_front("strategy=");
968 auto Result = StringSwitch<std::optional<ScanOptions>>(Params)
969 .Case("dpp", ScanOptions::DPP)
970 .Cases({"iterative", ""}, ScanOptions::Iterative)
971 .Case("none", ScanOptions::None)
972 .Default(std::nullopt);
973 if (Result)
974 return *Result;
975 return make_error<StringError>("invalid parameter", inconvertibleErrorCode());
976}
977
981 while (!Params.empty()) {
982 StringRef ParamName;
983 std::tie(ParamName, Params) = Params.split(';');
984 if (ParamName == "closed-world") {
985 Result.IsClosedWorld = true;
986 } else {
988 formatv("invalid AMDGPUAttributor pass parameter '{0}' ", ParamName)
989 .str(),
991 }
992 }
993 return Result;
994}
995
997
998#define GET_PASS_REGISTRY "AMDGPUPassRegistry.def"
1000
1001 // TODO: Move this into the base CodeGenPassBuilder once all
1002 // targets that currently implement it have a ported asm-printer pass.
1003 if (PIC) {
1004 PIC->addClassToPassName(AMDGPUAsmPrinterBeginPass::name(),
1005 "amdgpu-asm-printer-begin");
1006 PIC->addClassToPassName(AMDGPUAsmPrinterPass::name(), "amdgpu-asm-printer");
1007 PIC->addClassToPassName(AMDGPUAsmPrinterEndPass::name(),
1008 "amdgpu-asm-printer-end");
1009 }
1010
1011 PB.registerPipelineParsingCallback(
1012 [this](StringRef Name, CGSCCPassManager &PM,
1014 if (Name == "amdgpu-attributor-cgscc" && getTargetTriple().isAMDGCN()) {
1016 *static_cast<GCNTargetMachine *>(this)));
1017 return true;
1018 }
1019 return false;
1020 });
1021
1022 PB.registerScalarOptimizerLateEPCallback(
1023 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1024 if (Level == OptimizationLevel::O0)
1025 return;
1026
1028 });
1029
1030 PB.registerVectorizerEndEPCallback(
1031 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1032 if (Level == OptimizationLevel::O0)
1033 return;
1034
1036 });
1037
1038 PB.registerPipelineEarlySimplificationEPCallback(
1039 [this](ModulePassManager &PM, OptimizationLevel Level,
1041 if (!isLTOPreLink(Phase) && getTargetTriple().isAMDGCN()) {
1042 // When we are not using -fgpu-rdc, we can run accelerator code
1043 // selection relatively early, but still after linking to prevent
1044 // eager removal of potentially reachable symbols.
1045 if (EnableHipStdPar) {
1048 }
1049
1051 }
1052
1053 if (Level == OptimizationLevel::O0)
1054 return;
1055
1056 // We don't want to run internalization at per-module stage.
1059 PM.addPass(GlobalDCEPass());
1060 }
1061
1064 });
1065
1066 PB.registerPeepholeEPCallback(
1067 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1068 if (Level == OptimizationLevel::O0)
1069 return;
1070
1074
1077 });
1078
1079 PB.registerCGSCCOptimizerLateEPCallback(
1080 [this](CGSCCPassManager &PM, OptimizationLevel Level) {
1081 if (Level == OptimizationLevel::O0)
1082 return;
1083
1085
1086 // Add promote kernel arguments pass to the opt pipeline right before
1087 // infer address spaces which is needed to do actual address space
1088 // rewriting.
1091
1092 // Add infer address spaces pass to the opt pipeline after inlining
1093 // but before SROA to increase SROA opportunities.
1095
1096 // This should run after inlining to have any chance of doing
1097 // anything, and before other cleanup optimizations.
1099
1100 // Promote alloca to vector before SROA and loop unroll. If we
1101 // manage to eliminate allocas before unroll we may choose to unroll
1102 // less.
1104
1105 PM.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
1106 });
1107
1108 // FIXME: Why is AMDGPUAttributor not in CGSCC?
1109 PB.registerOptimizerLastEPCallback([this](ModulePassManager &MPM,
1110 OptimizationLevel Level,
1112 if (Level != OptimizationLevel::O0) {
1113 if (!isLTOPreLink(Phase)) {
1114 if (EnableAMDGPUAttributor && getTargetTriple().isAMDGCN()) {
1116 MPM.addPass(AMDGPUAttributorPass(*this, Opts, Phase));
1117 }
1118 }
1119 }
1120 });
1121
1122 PB.registerFullLinkTimeOptimizationLastEPCallback(
1123 [this](ModulePassManager &PM, OptimizationLevel Level) {
1124 // Clean up redundant memory round-trips that the full-LTO pipeline,
1125 // unlike the non-LTO/ThinLTO ones, otherwise leaves for codegen.
1126 if (Level != OptimizationLevel::O0) {
1128 EarlyCSEPass(/*UseMemorySSA=*/true)));
1129 }
1130
1131 // When we are using -fgpu-rdc, we can only run accelerator code
1132 // selection after linking to prevent, otherwise we end up removing
1133 // potentially reachable symbols that were exported as external in other
1134 // modules.
1135 if (EnableHipStdPar) {
1138 }
1139 // We want to support the -lto-partitions=N option as "best effort".
1140 // For that, we need to lower LDS earlier in the pipeline before the
1141 // module is partitioned for codegen.
1144 if (EnableSwLowerLDS)
1148 if (Level != OptimizationLevel::O0) {
1149 // We only want to run this with O2 or higher since inliner and SROA
1150 // don't run in O1.
1151 if (Level != OptimizationLevel::O1) {
1152 PM.addPass(
1154 }
1155 // Do we really need internalization in LTO?
1156 if (InternalizeSymbols) {
1158 PM.addPass(GlobalDCEPass());
1159 }
1160 if (EnableAMDGPUAttributor && getTargetTriple().isAMDGCN()) {
1163 Opt.IsClosedWorld = true;
1166 }
1167 }
1168 if (!NoKernelInfoEndLTO) {
1170 FPM.addPass(KernelInfoPrinter(this));
1171 PM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1172 }
1173 });
1174
1175 PB.registerRegClassFilterParsingCallback(
1176 [](StringRef FilterName) -> RegAllocFilterFunc {
1177 if (FilterName == "sgpr")
1178 return onlyAllocateSGPRs;
1179 if (FilterName == "vgpr")
1180 return onlyAllocateVGPRs;
1181 if (FilterName == "wwm")
1182 return onlyAllocateWWMRegs;
1183 return nullptr;
1184 });
1185}
1186
1188 unsigned DestAS) const {
1189 return AMDGPU::isFlatGlobalAddrSpace(SrcAS) &&
1191}
1192
1194 if (auto *Arg = dyn_cast<Argument>(V);
1195 Arg &&
1196 AMDGPU::isModuleEntryFunctionCC(Arg->getParent()->getCallingConv()) &&
1197 !Arg->hasByRefAttr())
1199
1200 const auto *LD = dyn_cast<LoadInst>(V);
1201 if (!LD) // TODO: Handle invariant load like constant.
1203
1204 // It must be a generic pointer loaded.
1205 assert(V->getType()->getPointerAddressSpace() == AMDGPUAS::FLAT_ADDRESS);
1206
1207 const auto *Ptr = LD->getPointerOperand();
1208 if (Ptr->getType()->getPointerAddressSpace() != AMDGPUAS::CONSTANT_ADDRESS)
1210 // For a generic pointer loaded from the constant memory, it could be assumed
1211 // as a global pointer since the constant memory is only populated on the
1212 // host side. As implied by the offload programming model, only global
1213 // pointers could be referenced on the host side.
1215}
1216
1217std::pair<const Value *, unsigned>
1219 if (auto *II = dyn_cast<IntrinsicInst>(V)) {
1220 switch (II->getIntrinsicID()) {
1221 case Intrinsic::amdgcn_is_shared:
1222 return std::pair(II->getArgOperand(0), AMDGPUAS::LOCAL_ADDRESS);
1223 case Intrinsic::amdgcn_is_private:
1224 return std::pair(II->getArgOperand(0), AMDGPUAS::PRIVATE_ADDRESS);
1225 default:
1226 break;
1227 }
1228 return std::pair(nullptr, -1);
1229 }
1230 // Check the global pointer predication based on
1231 // (!is_share(p) && !is_private(p)). Note that logic 'and' is commutative and
1232 // the order of 'is_shared' and 'is_private' is not significant.
1233 Value *Ptr;
1234 if (match(
1235 const_cast<Value *>(V),
1238 m_Deferred(Ptr))))))
1239 return std::pair(Ptr, AMDGPUAS::GLOBAL_ADDRESS);
1240
1241 return std::pair(nullptr, -1);
1242}
1243
1244unsigned
1259
1261 Module &M, unsigned NumParts,
1262 function_ref<void(std::unique_ptr<Module> MPart)> ModuleCallback) {
1263 // FIXME(?): Would be better to use an already existing Analysis/PassManager,
1264 // but all current users of this API don't have one ready and would need to
1265 // create one anyway. Let's hide the boilerplate for now to keep it simple.
1266
1271
1272 PassBuilder PB(this);
1273 PB.registerModuleAnalyses(MAM);
1274 PB.registerFunctionAnalyses(FAM);
1275 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
1276
1278 MPM.addPass(AMDGPUSplitModulePass(NumParts, ModuleCallback));
1279 MPM.run(M, MAM);
1280 return true;
1281}
1282
1283//===----------------------------------------------------------------------===//
1284// GCN Target Machine (SI+)
1285//===----------------------------------------------------------------------===//
1286
1288 StringRef CPU, StringRef FS,
1289 const TargetOptions &Options,
1290 std::optional<Reloc::Model> RM,
1291 std::optional<CodeModel::Model> CM,
1292 CodeGenOptLevel OL, bool JIT)
1293 : AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {
1295}
1296
1297enum class OOBFlagValue {
1298 Any = 0,
1301};
1302
1303/// Returns the OOB mode encoded by a module flag.
1304/// An absent flag defaults to Any.
1305static OOBFlagValue getOOBFlagValue(const Module &M, StringRef FlagName) {
1306 const auto *Flag =
1307 mdconst::dyn_extract_or_null<ConstantInt>(M.getModuleFlag(FlagName));
1308 if (!Flag)
1309 return OOBFlagValue::Any;
1310 return static_cast<OOBFlagValue>(Flag->getZExtValue());
1311}
1312
1313/// Returns the xnack/sramecc setting encoded by a module flag.
1314/// Module flag values: 0 = disabled, 1 = enabled.
1315/// An absent flag defaults to Any.
1318 StringRef FlagName) {
1320
1321 if (XnackSetting.getNumOccurrences() > 0 && FlagName == "amdgpu.xnack")
1322 return XnackSetting ? TargetIDSetting::On : TargetIDSetting::Off;
1323 if (SramEccSetting.getNumOccurrences() > 0 && FlagName == "amdgpu.sramecc")
1324 return SramEccSetting ? TargetIDSetting::On : TargetIDSetting::Off;
1325
1326 const auto *Flag =
1327 mdconst::dyn_extract_or_null<ConstantInt>(M.getModuleFlag(FlagName));
1328 if (!Flag)
1329 return TargetIDSetting::Any;
1330 return Flag->getZExtValue() == 0 ? TargetIDSetting::Off : TargetIDSetting::On;
1331}
1332
1333const TargetSubtargetInfo *
1335 StringRef GPU = getGPUName(F);
1337
1338 const Module &M = *F.getParent();
1341 bool BufRelaxed = BufOOB == OOBFlagValue::Relaxed;
1342 bool TBufRelaxed = TBufOOB == OOBFlagValue::Relaxed;
1343
1345 TargetIDSetting Xnack = getTargetIDSettingFromModuleFlag(M, "amdgpu.xnack");
1346 TargetIDSetting SramEcc =
1347 getTargetIDSettingFromModuleFlag(M, "amdgpu.sramecc");
1348
1349 SmallString<128> SubtargetKey(GPU);
1350 SubtargetKey.append(FS);
1351 if (BufRelaxed)
1352 SubtargetKey.append(",buf-oob=1");
1353 if (TBufRelaxed)
1354 SubtargetKey.append(",tbuf-oob=1");
1355 if (Xnack != TargetIDSetting::Any) {
1356 SubtargetKey.append(",xnack=");
1357 SubtargetKey.push_back(Xnack == TargetIDSetting::On ? '1' : '0');
1358 }
1359 if (SramEcc != TargetIDSetting::Any) {
1360 SubtargetKey.append(",sramecc=");
1361 SubtargetKey.push_back(Xnack == TargetIDSetting::On ? '1' : '0');
1362 }
1363
1364 auto &I = SubtargetMap[SubtargetKey];
1365 if (!I) {
1367 Triple::SubArchType GPUSubArch = AMDGPU::getSubArch(Kind);
1368
1369 // Enforce the subtarget is covered by the subarch. Tolerate no subarch for
1370 // legacy compatibility.
1371 const Triple &TT = M.getTargetTriple();
1372 if (GPUSubArch != TT.getSubArch() && Kind != AMDGPU::GK_NONE) {
1373 // Check if this is a generic subarch which has subtargets. Ignore
1374 // unknown subtargets with a known subarch, since for whatever reason
1375 // the convention is to just print a warning and ignore unrecognized
1376 // subtargets.
1377 bool IsLegacyEmptySubArch = TT.getSubArch() == Triple::NoSubArch;
1378 if (!IsLegacyEmptySubArch &&
1379 AMDGPU::getMajorSubArch(GPUSubArch) != TT.getSubArch()) {
1380 F.getContext().emitError("invalid subtarget '" + Twine(GPU) +
1381 "' for subarch " + TT.getArchName());
1382 }
1383 }
1384
1385 I = std::make_unique<GCNSubtarget>(TargetTriple, GPU, FS, *this, BufRelaxed,
1386 TBufRelaxed, Xnack, SramEcc);
1387 }
1388
1389 I->setScalarizeGlobalBehavior(ScalarizeGlobal);
1390
1391 return I.get();
1392}
1393
1396 return TargetTransformInfo(std::make_unique<GCNTTIImpl>(this, F));
1397}
1398
1401 raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
1402 const CGPassBuilderOption &Opts, MCContext &Ctx,
1404 AMDGPUCodeGenPassBuilder CGPB(*this, Opts, PIC);
1405 return CGPB.buildPipeline(MPM, MAM, Out, DwoOut, FileType, Ctx);
1406}
1407
1410 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
1411 if (ST.enableSIScheduler())
1413
1414 StringRef SchedStrategy = AMDGPU::getSchedStrategy(C->MF->getFunction());
1415
1416 if (SchedStrategy == "max-ilp")
1418
1419 if (SchedStrategy == "max-memory-clause")
1421
1422 if (SchedStrategy == "iterative-ilp")
1424
1425 if (SchedStrategy == "iterative-minreg")
1426 return createMinRegScheduler(C);
1427
1428 if (SchedStrategy == "iterative-maxocc")
1430
1431 if (SchedStrategy == "coexec") {
1432 diagnoseUnsupportedCoExecSchedulerSelection(C->MF->getFunction(), ST);
1434 }
1435
1437}
1438
1441 if (useNoopPostScheduler(C->MF->getFunction()))
1443
1444 ScheduleDAGMI *DAG =
1445 new GCNPostScheduleDAGMILive(C, std::make_unique<PostGenericScheduler>(C),
1446 /*RemoveKillFlags=*/true);
1447 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
1449 if (ST.shouldClusterStores())
1452 if ((EnableVOPD.getNumOccurrences() ||
1454 EnableVOPD)
1459 return DAG;
1460}
1461//===----------------------------------------------------------------------===//
1462// AMDGPU Legacy Pass Setup
1463//===----------------------------------------------------------------------===//
1464
1465std::unique_ptr<CSEConfigBase> llvm::AMDGPUPassConfig::getCSEConfig() const {
1466 return getStandardCSEConfigForOpt(TM->getOptLevel());
1467}
1468
1469namespace {
1470
1471class GCNPassConfig final : public AMDGPUPassConfig {
1472public:
1473 GCNPassConfig(TargetMachine &TM, PassManagerBase &PM)
1474 : AMDGPUPassConfig(TM, PM) {
1475 substitutePass(&PostRASchedulerID, &PostMachineSchedulerID);
1476 }
1477
1478 GCNTargetMachine &getGCNTargetMachine() const {
1479 return getTM<GCNTargetMachine>();
1480 }
1481
1482 bool addPreISel() override;
1483 void addMachineSSAOptimization() override;
1484 bool addILPOpts() override;
1485 bool addInstSelector() override;
1486 bool addIRTranslator() override;
1487 void addPreLegalizeMachineIR() override;
1488 bool addLegalizeMachineIR() override;
1489 void addPreRegBankSelect() override;
1490 bool addRegBankSelect() override;
1491 void addPreGlobalInstructionSelect() override;
1492 bool addGlobalInstructionSelect() override;
1493 void addPreRegAlloc() override;
1494 void addFastRegAlloc() override;
1495 void addOptimizedRegAlloc() override;
1496
1497 FunctionPass *createSGPRAllocPass(bool Optimized);
1498 FunctionPass *createVGPRAllocPass(bool Optimized);
1499 FunctionPass *createWWMRegAllocPass(bool Optimized);
1500 FunctionPass *createRegAllocPass(bool Optimized) override;
1501
1502 bool addRegAssignAndRewriteFast() override;
1503 bool addRegAssignAndRewriteOptimized() override;
1504
1505 bool addPreRewrite() override;
1506 void addPostRegAlloc() override;
1507 void addPreSched2() override;
1508 void addPreEmitPass() override;
1509 void addPostBBSections() override;
1510};
1511
1512} // end anonymous namespace
1513
1515 : TargetPassConfig(TM, PM) {
1516 // Exceptions and StackMaps are not supported, so these passes will never do
1517 // anything.
1520 // Garbage collection is not supported.
1523}
1524
1531
1536 // ReassociateGEPs exposes more opportunities for SLSR. See
1537 // the example in reassociate-geps-and-slsr.ll.
1539 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
1540 // EarlyCSE can reuse.
1542 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
1544 // NaryReassociate on GEPs creates redundant common expressions, so run
1545 // EarlyCSE after it.
1547}
1548
1551
1552 if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN())
1554
1555 // There is no reason to run these.
1559
1560 if (TM.getTargetTriple().isAMDGCN())
1562
1563 if (LowerCtorDtor)
1565
1566 if (TM.getTargetTriple().isAMDGCN() &&
1569
1572
1573 // This can be disabled by passing ::Disable here or on the command line
1574 // with --expand-variadics-override=disable.
1576
1577 // Function calls are not supported, so make sure we inline everything.
1580
1581 // Handle uses of OpenCL image2d_t, image3d_t and sampler_t arguments.
1582 if (TM.getTargetTriple().getArch() == Triple::r600)
1584
1585 // Make enqueued block runtime handles externally visible.
1587
1588 // Lower special LDS accesses.
1591
1592 // Lower LDS accesses to global memory pass if address sanitizer is enabled.
1593 if (EnableSwLowerLDS)
1595
1596 // Runs before PromoteAlloca so the latter can account for function uses
1599 }
1600
1601 // Run atomic optimizer before Atomic Expand
1602 if ((TM.getTargetTriple().isAMDGCN()) &&
1603 (TM.getOptLevel() >= CodeGenOptLevel::Less) &&
1606 }
1607
1609
1610 if (TM.getOptLevel() > CodeGenOptLevel::None) {
1612
1615
1619 AAResults &AAR) {
1620 if (auto *WrapperPass = P.getAnalysisIfAvailable<AMDGPUAAWrapperPass>())
1621 AAR.addAAResult(WrapperPass->getResult());
1622 }));
1623 }
1624
1625 if (TM.getTargetTriple().isAMDGCN()) {
1626 // TODO: May want to move later or split into an early and late one.
1628 }
1629
1630 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
1631 // have expanded.
1632 if (TM.getOptLevel() > CodeGenOptLevel::Less)
1634 }
1635
1637
1638 // EarlyCSE is not always strong enough to clean up what LSR produces. For
1639 // example, GVN can combine
1640 //
1641 // %0 = add %a, %b
1642 // %1 = add %b, %a
1643 //
1644 // and
1645 //
1646 // %0 = shl nsw %a, 2
1647 // %1 = shl %a, 2
1648 //
1649 // but EarlyCSE can do neither of them.
1652}
1653
1655 if (TM->getTargetTriple().isAMDGCN() &&
1656 TM->getOptLevel() > CodeGenOptLevel::None)
1658
1659 if (TM->getTargetTriple().isAMDGCN() && EnableLowerKernelArguments)
1661
1663
1666
1667 if (TM->getTargetTriple().isAMDGCN()) {
1668 // This lowering has been placed after codegenprepare to take advantage of
1669 // address mode matching (which is why it isn't put with the LDS lowerings).
1670 // It could be placed anywhere before uniformity annotations (an analysis
1671 // that it changes by splitting up fat pointers into their components)
1672 // but has been put before switch lowering and CFG flattening so that those
1673 // passes can run on the more optimized control flow this pass creates in
1674 // many cases.
1677 }
1678
1679 // LowerSwitch pass may introduce unreachable blocks that can
1680 // cause unexpected behavior for subsequent passes. Placing it
1681 // here seems better that these blocks would get cleaned up by
1682 // UnreachableBlockElim inserted next in the pass flow.
1684}
1685
1687 if (TM->getOptLevel() > CodeGenOptLevel::None)
1689 return false;
1690}
1691
1696
1698 // Do nothing. GC is not supported.
1699 return false;
1700}
1701
1702//===----------------------------------------------------------------------===//
1703// GCN Legacy Pass Setup
1704//===----------------------------------------------------------------------===//
1705
1706bool GCNPassConfig::addPreISel() {
1708
1709 if (TM->getOptLevel() > CodeGenOptLevel::None) {
1710 addPass(createSinkingPass());
1712 }
1713
1714 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
1715 // regions formed by them.
1717 addPass(createFixIrreduciblePass());
1718 addPass(createUnifyLoopExitsPass());
1719 addPass(createStructurizeCFGPass(false)); // true -> SkipUniformRegions
1720
1723 // TODO: Move this right after structurizeCFG to avoid extra divergence
1724 // analysis. This depends on stopping SIAnnotateControlFlow from making
1725 // control flow modifications.
1727
1728 // SDAG requires LCSSA, GlobalISel does not. Disable LCSSA for -global-isel
1729 // without any of the fallback options.
1732 !isGlobalISelAbortEnabled())
1733 addPass(createLCSSAPass());
1734
1735 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1737
1738 return false;
1739}
1740
1741void GCNPassConfig::addMachineSSAOptimization() {
1743
1744 // We want to fold operands after PeepholeOptimizer has run (or as part of
1745 // it), because it will eliminate extra copies making it easier to fold the
1746 // real source operand. We want to eliminate dead instructions after, so that
1747 // we see fewer uses of the copies. We then need to clean up the dead
1748 // instructions leftover after the operands are folded as well.
1749 //
1750 // XXX - Can we get away without running DeadMachineInstructionElim again?
1751 addPass(&SIFoldOperandsLegacyID);
1752 if (EnableDPPCombine)
1753 addPass(&GCNDPPCombineLegacyID);
1755 if (isPassEnabled(EnableSDWAPeephole)) {
1756 addPass(&SIPeepholeSDWALegacyID);
1757 addPass(&EarlyMachineLICMID);
1758 addPass(&MachineCSELegacyID);
1759 addPass(&SIFoldOperandsLegacyID);
1760 }
1763}
1764
1765bool GCNPassConfig::addILPOpts() {
1767 addPass(&EarlyIfConverterLegacyID);
1768
1770 return false;
1771}
1772
1773bool GCNPassConfig::addInstSelector() {
1775 addPass(&SIFixSGPRCopiesLegacyID);
1777 return false;
1778}
1779
1780bool GCNPassConfig::addIRTranslator() {
1781 addPass(new IRTranslator(getOptLevel()));
1782 return false;
1783}
1784
1785void GCNPassConfig::addPreLegalizeMachineIR() {
1786 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1787 addPass(createAMDGPUPreLegalizeCombiner(IsOptNone));
1788 addPass(new Localizer());
1789}
1790
1791bool GCNPassConfig::addLegalizeMachineIR() {
1792 addPass(new Legalizer());
1793 return false;
1794}
1795
1796void GCNPassConfig::addPreRegBankSelect() {
1797 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1798 addPass(createAMDGPUPostLegalizeCombiner(IsOptNone));
1800}
1801
1802bool GCNPassConfig::addRegBankSelect() {
1805 return false;
1806}
1807
1808void GCNPassConfig::addPreGlobalInstructionSelect() {
1809 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1810 addPass(createAMDGPURegBankCombiner(IsOptNone));
1811}
1812
1813bool GCNPassConfig::addGlobalInstructionSelect() {
1814 addPass(new InstructionSelect(getOptLevel()));
1815 return false;
1816}
1817
1818void GCNPassConfig::addFastRegAlloc() {
1819 // FIXME: We have to disable the verifier here because of PHIElimination +
1820 // TwoAddressInstructions disabling it.
1821
1822 // This must be run immediately after phi elimination and before
1823 // TwoAddressInstructions, otherwise the processing of the tied operand of
1824 // SI_ELSE will introduce a copy of the tied operand source after the else.
1826
1828
1830}
1831
1832void GCNPassConfig::addPreRegAlloc() {
1833 if (getOptLevel() != CodeGenOptLevel::None)
1835}
1836
1837void GCNPassConfig::addOptimizedRegAlloc() {
1838 if (EnableDCEInRA)
1840
1841 // FIXME: when an instruction has a Killed operand, and the instruction is
1842 // inside a bundle, seems only the BUNDLE instruction appears as the Kills of
1843 // the register in LiveVariables, this would trigger a failure in verifier,
1844 // we should fix it and enable the verifier.
1845 if (OptVGPRLiveRange)
1847
1848 // This must be run immediately after phi elimination and before
1849 // TwoAddressInstructions, otherwise the processing of the tied operand of
1850 // SI_ELSE will introduce a copy of the tied operand source after the else.
1852
1855
1856 if (isPassEnabled(EnablePreRAOptimizations))
1858
1859 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
1860 // instructions that cause scheduling barriers.
1862
1863 if (OptExecMaskPreRA)
1865
1866 // This is not an essential optimization and it has a noticeable impact on
1867 // compilation time, so we only enable it from O2.
1868 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1870
1872}
1873
1874bool GCNPassConfig::addPreRewrite() {
1876 addPass(&GCNNSAReassignID);
1877
1879 return true;
1880}
1881
1882FunctionPass *GCNPassConfig::createSGPRAllocPass(bool Optimized) {
1883 // Initialize the global default.
1884 llvm::call_once(InitializeDefaultSGPRRegisterAllocatorFlag,
1885 initializeDefaultSGPRRegisterAllocatorOnce);
1886
1887 RegisterRegAlloc::FunctionPassCtor Ctor = SGPRRegisterRegAlloc::getDefault();
1888 if (Ctor != useDefaultRegisterAllocator)
1889 return Ctor();
1890
1891 if (Optimized)
1892 return createGreedyRegisterAllocator(onlyAllocateSGPRs);
1893
1894 return createFastRegisterAllocator(onlyAllocateSGPRs, false);
1895}
1896
1897FunctionPass *GCNPassConfig::createVGPRAllocPass(bool Optimized) {
1898 // Initialize the global default.
1899 llvm::call_once(InitializeDefaultVGPRRegisterAllocatorFlag,
1900 initializeDefaultVGPRRegisterAllocatorOnce);
1901
1902 RegisterRegAlloc::FunctionPassCtor Ctor = VGPRRegisterRegAlloc::getDefault();
1903 if (Ctor != useDefaultRegisterAllocator)
1904 return Ctor();
1905
1906 if (Optimized)
1907 return createGreedyVGPRRegisterAllocator();
1908
1909 return createFastVGPRRegisterAllocator();
1910}
1911
1912FunctionPass *GCNPassConfig::createWWMRegAllocPass(bool Optimized) {
1913 // Initialize the global default.
1914 llvm::call_once(InitializeDefaultWWMRegisterAllocatorFlag,
1915 initializeDefaultWWMRegisterAllocatorOnce);
1916
1917 RegisterRegAlloc::FunctionPassCtor Ctor = WWMRegisterRegAlloc::getDefault();
1918 if (Ctor != useDefaultRegisterAllocator)
1919 return Ctor();
1920
1921 if (Optimized)
1922 return createGreedyWWMRegisterAllocator();
1923
1924 return createFastWWMRegisterAllocator();
1925}
1926
1927FunctionPass *GCNPassConfig::createRegAllocPass(bool Optimized) {
1928 llvm_unreachable("should not be used");
1929}
1930
1932 "-regalloc not supported with amdgcn. Use -sgpr-regalloc, -wwm-regalloc, "
1933 "and -vgpr-regalloc";
1934
1935bool GCNPassConfig::addRegAssignAndRewriteFast() {
1936 if (!usingDefaultRegAlloc())
1938
1939 addPass(&GCNPreRALongBranchRegID);
1940
1941 addPass(createSGPRAllocPass(false));
1942
1943 // Equivalent of PEI for SGPRs.
1944 addPass(&SILowerSGPRSpillsLegacyID);
1945
1946 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1948
1949 // For allocating other wwm register operands.
1950 addPass(createWWMRegAllocPass(false));
1951
1952 addPass(&SILowerWWMCopiesLegacyID);
1954
1955 // For allocating per-thread VGPRs.
1956 addPass(createVGPRAllocPass(false));
1957
1958 return true;
1959}
1960
1961bool GCNPassConfig::addRegAssignAndRewriteOptimized() {
1962 if (!usingDefaultRegAlloc())
1964
1965 addPass(&GCNPreRALongBranchRegID);
1966
1967 addPass(createSGPRAllocPass(true));
1968
1969 // Commit allocated register changes. This is mostly necessary because too
1970 // many things rely on the use lists of the physical registers, such as the
1971 // verifier. This is only necessary with allocators which use LiveIntervals,
1972 // since FastRegAlloc does the replacements itself.
1973 addPass(createVirtRegRewriter(false));
1974
1975 // At this point, the sgpr-regalloc has been done and it is good to have the
1976 // stack slot coloring to try to optimize the SGPR spill stack indices before
1977 // attempting the custom SGPR spill lowering.
1978 addPass(&StackSlotColoringID);
1979
1980 // Equivalent of PEI for SGPRs.
1981 addPass(&SILowerSGPRSpillsLegacyID);
1982
1983 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1985
1986 // For allocating other whole wave mode registers.
1987 addPass(createWWMRegAllocPass(true));
1988 addPass(&SILowerWWMCopiesLegacyID);
1989 addPass(createVirtRegRewriter(false));
1991
1992 // For allocating per-thread VGPRs.
1993 addPass(createVGPRAllocPass(true));
1994
1995 addPreRewrite();
1996 addPass(&VirtRegRewriterID);
1997
1999
2000 return true;
2001}
2002
2003void GCNPassConfig::addPostRegAlloc() {
2004 addPass(&SIFixVGPRCopiesID);
2005 if (getOptLevel() > CodeGenOptLevel::None)
2008}
2009
2010void GCNPassConfig::addPreSched2() {
2011 if (TM->getOptLevel() > CodeGenOptLevel::None)
2013 addPass(&SIPostRABundlerLegacyID);
2014}
2015
2016void GCNPassConfig::addPreEmitPass() {
2017 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less))
2018 addPass(&GCNCreateVOPDID);
2019 addPass(createSIMemoryLegalizerPass());
2020 addPass(createSIInsertWaitcntsPass());
2021
2022 addPass(createSIModeRegisterPass());
2023
2024 if (getOptLevel() > CodeGenOptLevel::None)
2025 addPass(&SIInsertHardClausesID);
2026
2028 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
2030 if (getOptLevel() > CodeGenOptLevel::None)
2031 addPass(&SIPreEmitPeepholeID);
2032 // The hazard recognizer that runs as part of the post-ra scheduler does not
2033 // guarantee to be able handle all hazards correctly. This is because if there
2034 // are multiple scheduling regions in a basic block, the regions are scheduled
2035 // bottom up, so when we begin to schedule a region we don't know what
2036 // instructions were emitted directly before it.
2037 //
2038 // Here we add a stand-alone hazard recognizer pass which can handle all
2039 // cases.
2040 addPass(&PostRAHazardRecognizerID);
2041
2043
2045
2046 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less))
2047 addPass(&AMDGPUInsertDelayAluID);
2048
2049 addPass(&BranchRelaxationPassID);
2050}
2051
2052void GCNPassConfig::addPostBBSections() {
2053 // We run this later to avoid passes like livedebugvalues and BBSections
2054 // having to deal with the apparent multi-entry functions we may generate.
2056}
2057
2059 return new GCNPassConfig(*this, PM);
2060}
2061
2067
2074
2078
2085
2088 SMDiagnostic &Error, SMRange &SourceRange) const {
2089 const yaml::SIMachineFunctionInfo &YamlMFI =
2090 static_cast<const yaml::SIMachineFunctionInfo &>(MFI_);
2091 MachineFunction &MF = PFS.MF;
2093 const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
2094
2095 if (MFI->initializeBaseYamlFields(YamlMFI, MF, PFS, Error, SourceRange))
2096 return true;
2097
2098 if (MFI->Occupancy == 0) {
2099 // Fixup the subtarget dependent default value.
2100 MFI->Occupancy = ST.getOccupancyWithWorkGroupSizes(MF).second;
2101 }
2102
2103 auto parseRegister = [&](const yaml::StringValue &RegName, Register &RegVal) {
2104 Register TempReg;
2105 if (parseNamedRegisterReference(PFS, TempReg, RegName.Value, Error)) {
2106 SourceRange = RegName.SourceRange;
2107 return true;
2108 }
2109 RegVal = TempReg;
2110
2111 return false;
2112 };
2113
2114 auto parseOptionalRegister = [&](const yaml::StringValue &RegName,
2115 Register &RegVal) {
2116 return !RegName.Value.empty() && parseRegister(RegName, RegVal);
2117 };
2118
2119 if (parseOptionalRegister(YamlMFI.VGPRForAGPRCopy, MFI->VGPRForAGPRCopy))
2120 return true;
2121
2122 if (parseOptionalRegister(YamlMFI.SGPRForEXECCopy, MFI->SGPRForEXECCopy))
2123 return true;
2124
2125 if (parseOptionalRegister(YamlMFI.LongBranchReservedReg,
2126 MFI->LongBranchReservedReg))
2127 return true;
2128
2129 auto diagnoseRegisterClass = [&](const yaml::StringValue &RegName) {
2130 // Create a diagnostic for a the register string literal.
2131 const MemoryBuffer &Buffer =
2132 *PFS.SM->getMemoryBuffer(PFS.SM->getMainFileID());
2133 Error = SMDiagnostic(*PFS.SM, SMLoc(), Buffer.getBufferIdentifier(), 1,
2134 RegName.Value.size(), SourceMgr::DK_Error,
2135 "incorrect register class for field", RegName.Value,
2136 {}, {});
2137 SourceRange = RegName.SourceRange;
2138 return true;
2139 };
2140
2141 if (parseRegister(YamlMFI.ScratchRSrcReg, MFI->ScratchRSrcReg) ||
2142 parseRegister(YamlMFI.FrameOffsetReg, MFI->FrameOffsetReg) ||
2143 parseRegister(YamlMFI.StackPtrOffsetReg, MFI->StackPtrOffsetReg))
2144 return true;
2145
2146 if (MFI->ScratchRSrcReg != AMDGPU::PRIVATE_RSRC_REG &&
2147 !AMDGPU::SGPR_128RegClass.contains(MFI->ScratchRSrcReg)) {
2148 return diagnoseRegisterClass(YamlMFI.ScratchRSrcReg);
2149 }
2150
2151 if (MFI->FrameOffsetReg != AMDGPU::FP_REG &&
2152 !AMDGPU::SGPR_32RegClass.contains(MFI->FrameOffsetReg)) {
2153 return diagnoseRegisterClass(YamlMFI.FrameOffsetReg);
2154 }
2155
2156 if (MFI->StackPtrOffsetReg != AMDGPU::SP_REG &&
2157 !AMDGPU::SGPR_32RegClass.contains(MFI->StackPtrOffsetReg)) {
2158 return diagnoseRegisterClass(YamlMFI.StackPtrOffsetReg);
2159 }
2160
2161 for (const auto &YamlReg : YamlMFI.WWMReservedRegs) {
2162 Register ParsedReg;
2163 if (parseRegister(YamlReg, ParsedReg))
2164 return true;
2165
2166 MFI->reserveWWMRegister(ParsedReg);
2167 }
2168
2169 for (const auto &[_, Info] : PFS.VRegInfosNamed) {
2170 MFI->setFlag(Info->VReg, Info->Flags);
2171 }
2172 for (const auto &[_, Info] : PFS.VRegInfos) {
2173 MFI->setFlag(Info->VReg, Info->Flags);
2174 }
2175
2176 for (const auto &YamlRegStr : YamlMFI.SpillPhysVGPRS) {
2177 Register ParsedReg;
2178 if (parseRegister(YamlRegStr, ParsedReg))
2179 return true;
2180 MFI->SpillPhysVGPRs.push_back(ParsedReg);
2181 }
2182
2183 auto parseAndCheckArgument = [&](const std::optional<yaml::SIArgument> &A,
2184 const TargetRegisterClass &RC,
2185 ArgDescriptor &Arg, unsigned UserSGPRs,
2186 unsigned SystemSGPRs) {
2187 // Skip parsing if it's not present.
2188 if (!A)
2189 return false;
2190
2191 if (A->IsRegister) {
2192 Register Reg;
2193 if (parseNamedRegisterReference(PFS, Reg, A->RegisterName.Value, Error)) {
2194 SourceRange = A->RegisterName.SourceRange;
2195 return true;
2196 }
2197 if (!RC.contains(Reg))
2198 return diagnoseRegisterClass(A->RegisterName);
2200 } else
2201 Arg = ArgDescriptor::createStack(A->StackOffset);
2202 // Check and apply the optional mask.
2203 if (A->Mask)
2204 Arg = ArgDescriptor::createArg(Arg, *A->Mask);
2205
2206 MFI->NumUserSGPRs += UserSGPRs;
2207 MFI->NumSystemSGPRs += SystemSGPRs;
2208 return false;
2209 };
2210
2211 if (YamlMFI.ArgInfo &&
2212 (parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentBuffer,
2213 AMDGPU::SGPR_128RegClass,
2214 MFI->ArgInfo.PrivateSegmentBuffer, 4, 0) ||
2215 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchPtr,
2216 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchPtr,
2217 2, 0) ||
2218 parseAndCheckArgument(YamlMFI.ArgInfo->QueuePtr, AMDGPU::SReg_64RegClass,
2219 MFI->ArgInfo.QueuePtr, 2, 0) ||
2220 parseAndCheckArgument(YamlMFI.ArgInfo->KernargSegmentPtr,
2221 AMDGPU::SReg_64RegClass,
2222 MFI->ArgInfo.KernargSegmentPtr, 2, 0) ||
2223 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchID,
2224 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchID,
2225 2, 0) ||
2226 parseAndCheckArgument(YamlMFI.ArgInfo->FlatScratchInit,
2227 AMDGPU::SReg_64RegClass,
2228 MFI->ArgInfo.FlatScratchInit, 2, 0) ||
2229 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentSize,
2230 AMDGPU::SGPR_32RegClass,
2231 MFI->ArgInfo.PrivateSegmentSize, 0, 0) ||
2232 parseAndCheckArgument(YamlMFI.ArgInfo->LDSKernelId,
2233 AMDGPU::SGPR_32RegClass,
2234 MFI->ArgInfo.LDSKernelId, 0, 1) ||
2235 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDX,
2236 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDX,
2237 0, 1) ||
2238 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDY,
2239 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDY,
2240 0, 1) ||
2241 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDZ,
2242 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDZ,
2243 0, 1) ||
2244 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupInfo,
2245 AMDGPU::SGPR_32RegClass,
2246 MFI->ArgInfo.WorkGroupInfo, 0, 1) ||
2247 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentWaveByteOffset,
2248 AMDGPU::SGPR_32RegClass,
2249 MFI->ArgInfo.PrivateSegmentWaveByteOffset, 0, 1) ||
2250 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitArgPtr,
2251 AMDGPU::SReg_64RegClass,
2252 MFI->ArgInfo.ImplicitArgPtr, 0, 0) ||
2253 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitBufferPtr,
2254 AMDGPU::SReg_64RegClass,
2255 MFI->ArgInfo.ImplicitBufferPtr, 2, 0) ||
2256 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDX,
2257 AMDGPU::VGPR_32RegClass,
2258 MFI->ArgInfo.WorkItemIDX, 0, 0) ||
2259 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDY,
2260 AMDGPU::VGPR_32RegClass,
2261 MFI->ArgInfo.WorkItemIDY, 0, 0) ||
2262 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDZ,
2263 AMDGPU::VGPR_32RegClass,
2264 MFI->ArgInfo.WorkItemIDZ, 0, 0)))
2265 return true;
2266
2267 // Parse FirstKernArgPreloadReg separately, since it's a Register,
2268 // not ArgDescriptor.
2269 if (YamlMFI.ArgInfo && YamlMFI.ArgInfo->FirstKernArgPreloadReg) {
2270 const yaml::SIArgument &A = *YamlMFI.ArgInfo->FirstKernArgPreloadReg;
2271
2272 if (!A.IsRegister) {
2273 // For stack arguments, we don't have RegisterName.SourceRange,
2274 // but we should have some location info from the YAML parser
2275 const MemoryBuffer &Buffer =
2276 *PFS.SM->getMemoryBuffer(PFS.SM->getMainFileID());
2277 // Create a minimal valid source range
2279 SMRange Range(Loc, Loc);
2280
2282 *PFS.SM, Loc, Buffer.getBufferIdentifier(), 1, 0, SourceMgr::DK_Error,
2283 "firstKernArgPreloadReg must be a register, not a stack location", "",
2284 {}, {});
2285
2286 SourceRange = Range;
2287 return true;
2288 }
2289
2290 Register Reg;
2291 if (parseNamedRegisterReference(PFS, Reg, A.RegisterName.Value, Error)) {
2292 SourceRange = A.RegisterName.SourceRange;
2293 return true;
2294 }
2295
2296 if (!AMDGPU::SGPR_32RegClass.contains(Reg))
2297 return diagnoseRegisterClass(A.RegisterName);
2298
2299 MFI->ArgInfo.FirstKernArgPreloadReg = Reg;
2300 MFI->NumUserSGPRs += YamlMFI.NumKernargPreloadSGPRs;
2301 }
2302
2303 if (ST.hasFeature(AMDGPU::FeatureDX10ClampAndIEEEMode)) {
2304 MFI->Mode.IEEE = YamlMFI.Mode.IEEE;
2305 MFI->Mode.DX10Clamp = YamlMFI.Mode.DX10Clamp;
2306 }
2307
2308 // FIXME: Move proper support for denormal-fp-math into base MachineFunction
2309 MFI->Mode.FP32Denormals.Input = YamlMFI.Mode.FP32InputDenormals
2312 MFI->Mode.FP32Denormals.Output = YamlMFI.Mode.FP32OutputDenormals
2315
2322
2323 if (YamlMFI.HasInitWholeWave)
2324 MFI->setInitWholeWave();
2325
2326 return false;
2327}
2328
2329//===----------------------------------------------------------------------===//
2330// AMDGPU CodeGen Pass Builder interface.
2331//===----------------------------------------------------------------------===//
2332
2333AMDGPUCodeGenPassBuilder::AMDGPUCodeGenPassBuilder(
2334 GCNTargetMachine &TM, const CGPassBuilderOption &Opts,
2336 : CodeGenPassBuilder(TM, Opts, PIC) {
2337 Opt.MISchedPostRA = true;
2338 Opt.RequiresCodeGenSCCOrder = true;
2339 // Exceptions and StackMaps are not supported, so these passes will never do
2340 // anything.
2341 // Garbage collection is not supported.
2342 disablePass<StackMapLivenessPass, FuncletLayoutPass, PatchableFunctionPass,
2344}
2345
2346void AMDGPUCodeGenPassBuilder::addIRPasses(PassManagerWrapper &PMW) const {
2347 if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN()) {
2348 flushFPMsToMPM(PMW);
2349 addModulePass(AMDGPURemoveIncompatibleFunctionsPass(TM), PMW);
2350 }
2351
2352 flushFPMsToMPM(PMW);
2353
2354 if (TM.getTargetTriple().isAMDGCN())
2355 addModulePass(AMDGPUPrintfRuntimeBindingPass(), PMW);
2356
2357 if (LowerCtorDtor)
2358 addModulePass(AMDGPUCtorDtorLoweringPass(), PMW);
2359
2360 if (isPassEnabled(EnableImageIntrinsicOptimizer))
2361 addFunctionPass(AMDGPUImageIntrinsicOptimizerPass(TM), PMW);
2362
2364 addFunctionPass(AMDGPUUniformIntrinsicCombinePass(), PMW);
2365 // This can be disabled by passing ::Disable here or on the command line
2366 // with --expand-variadics-override=disable.
2367 flushFPMsToMPM(PMW);
2369
2370 addModulePass(AMDGPUAlwaysInlinePass(), PMW);
2371 addModulePass(AlwaysInlinerPass(), PMW);
2372
2373 addModulePass(AMDGPUExportKernelRuntimeHandlesPass(), PMW);
2374
2376 addModulePass(AMDGPULowerExecSyncPass(), PMW);
2377
2378 if (EnableSwLowerLDS)
2379 addModulePass(AMDGPUSwLowerLDSPass(), PMW);
2380
2381 // Runs before PromoteAlloca so the latter can account for function uses
2383 addModulePass(AMDGPULowerModuleLDSPass(TM), PMW);
2384
2385 // Run atomic optimizer before Atomic Expand
2386 if (TM.getOptLevel() >= CodeGenOptLevel::Less &&
2388 addFunctionPass(
2390
2391 addFunctionPass(AtomicExpandPass(TM), PMW);
2392
2393 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2394 addFunctionPass(AMDGPUPromoteAllocaPass(TM), PMW);
2395 if (isPassEnabled(EnableScalarIRPasses))
2396 addStraightLineScalarOptimizationPasses(PMW);
2397
2398 // TODO: Handle EnableAMDGPUAliasAnalysis
2399
2400 // TODO: May want to move later or split into an early and late one.
2401 addFunctionPass(AMDGPUCodeGenPreparePass(TM), PMW);
2402
2403 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
2404 // have expanded.
2405 if (TM.getOptLevel() > CodeGenOptLevel::Less) {
2407 /*UseMemorySSA=*/true),
2408 PMW);
2409 }
2410 }
2411
2412 Base::addIRPasses(PMW);
2413
2414 // EarlyCSE is not always strong enough to clean up what LSR produces. For
2415 // example, GVN can combine
2416 //
2417 // %0 = add %a, %b
2418 // %1 = add %b, %a
2419 //
2420 // and
2421 //
2422 // %0 = shl nsw %a, 2
2423 // %1 = shl %a, 2
2424 //
2425 // but EarlyCSE can do neither of them.
2426 if (isPassEnabled(EnableScalarIRPasses))
2427 addEarlyCSEOrGVNPass(PMW);
2428}
2429
2430void AMDGPUCodeGenPassBuilder::addCodeGenPrepare(
2431 PassManagerWrapper &PMW) const {
2432 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2433 flushFPMsToMPM(PMW);
2434 addModulePass(AMDGPUPreloadKernelArgumentsPass(TM), PMW);
2435 }
2436
2438 addFunctionPass(AMDGPULowerKernelArgumentsPass(TM), PMW);
2439
2440 Base::addCodeGenPrepare(PMW);
2441
2442 if (isPassEnabled(EnableLoadStoreVectorizer))
2443 addFunctionPass(LoadStoreVectorizerPass(), PMW);
2444
2445 // This lowering has been placed after codegenprepare to take advantage of
2446 // address mode matching (which is why it isn't put with the LDS lowerings).
2447 // It could be placed anywhere before uniformity annotations (an analysis
2448 // that it changes by splitting up fat pointers into their components)
2449 // but has been put before switch lowering and CFG flattening so that those
2450 // passes can run on the more optimized control flow this pass creates in
2451 // many cases.
2452 flushFPMsToMPM(PMW);
2453 addModulePass(AMDGPULowerBufferFatPointersPass(TM), PMW);
2454 flushFPMsToMPM(PMW);
2455 requireCGSCCOrder(PMW);
2456
2457 addModulePass(AMDGPULowerIntrinsicsPass(TM), PMW);
2458
2459 // LowerSwitch pass may introduce unreachable blocks that can cause unexpected
2460 // behavior for subsequent passes. Placing it here seems better that these
2461 // blocks would get cleaned up by UnreachableBlockElim inserted next in the
2462 // pass flow.
2463 addFunctionPass(LowerSwitchPass(), PMW);
2464}
2465
2466void AMDGPUCodeGenPassBuilder::addPreISel(PassManagerWrapper &PMW) const {
2467
2468 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2469 addFunctionPass(FlattenCFGPass(), PMW);
2470 addFunctionPass(SinkingPass(), PMW);
2471 addFunctionPass(AMDGPULateCodeGenPreparePass(TM), PMW);
2472 }
2473
2474 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
2475 // regions formed by them.
2476
2477 addFunctionPass(AMDGPUUnifyDivergentExitNodesPass(), PMW);
2478 addFunctionPass(FixIrreduciblePass(), PMW);
2479 addFunctionPass(UnifyLoopExitsPass(), PMW);
2480 addFunctionPass(StructurizeCFGPass(/*SkipUniformRegions=*/false), PMW);
2481
2482 addFunctionPass(AMDGPUAnnotateUniformValuesPass(), PMW);
2483
2484 addFunctionPass(SIAnnotateControlFlowPass(TM), PMW);
2485
2486 // TODO: Move this right after structurizeCFG to avoid extra divergence
2487 // analysis. This depends on stopping SIAnnotateControlFlow from making
2488 // control flow modifications.
2489 addFunctionPass(AMDGPURewriteUndefForPHIPass(), PMW);
2490
2493 !isGlobalISelAbortEnabled())
2494 addFunctionPass(LCSSAPass(), PMW);
2495
2496 if (TM.getOptLevel() > CodeGenOptLevel::Less) {
2497 flushFPMsToMPM(PMW);
2498 addModulePass(AMDGPUPerfHintAnalysisPass(TM), PMW);
2499 }
2500}
2501
2502void AMDGPUCodeGenPassBuilder::addILPOpts(PassManagerWrapper &PMW) const {
2504 addMachineFunctionPass(EarlyIfConverterPass(), PMW);
2505
2506 Base::addILPOpts(PMW);
2507}
2508
2509void AMDGPUCodeGenPassBuilder::addAsmPrinterBegin(
2510 PassManagerWrapper &PMW) const {
2511 addModulePass(AMDGPUAsmPrinterBeginPass(), PMW,
2512 /*Force=*/true);
2513}
2514
2515void AMDGPUCodeGenPassBuilder::addAsmPrinter(PassManagerWrapper &PMW) const {
2516 addMachineFunctionPass(AMDGPUAsmPrinterPass(), PMW);
2517}
2518
2519void AMDGPUCodeGenPassBuilder::addAsmPrinterEnd(PassManagerWrapper &PMW) const {
2520 addModulePass(AMDGPUAsmPrinterEndPass(), PMW);
2521}
2522
2523Error AMDGPUCodeGenPassBuilder::addInstSelector(PassManagerWrapper &PMW) const {
2524 addMachineFunctionPass(AMDGPUISelDAGToDAGPass(TM), PMW);
2525 addMachineFunctionPass(SIFixSGPRCopiesPass(), PMW);
2526 addMachineFunctionPass(SILowerI1CopiesPass(), PMW);
2527 return Error::success();
2528}
2529
2530void AMDGPUCodeGenPassBuilder::addPreRewrite(PassManagerWrapper &PMW) const {
2531 if (EnableRegReassign) {
2532 addMachineFunctionPass(GCNNSAReassignPass(), PMW);
2533 }
2534
2535 addMachineFunctionPass(AMDGPURewriteAGPRCopyMFMAPass(), PMW);
2536}
2537
2538void AMDGPUCodeGenPassBuilder::addMachineSSAOptimization(
2539 PassManagerWrapper &PMW) const {
2540 Base::addMachineSSAOptimization(PMW);
2541
2542 addMachineFunctionPass(SIFoldOperandsPass(), PMW);
2543 if (EnableDPPCombine) {
2544 addMachineFunctionPass(GCNDPPCombinePass(), PMW);
2545 }
2546 addMachineFunctionPass(SILoadStoreOptimizerPass(), PMW);
2547 if (isPassEnabled(EnableSDWAPeephole)) {
2548 addMachineFunctionPass(SIPeepholeSDWAPass(), PMW);
2549 addMachineFunctionPass(EarlyMachineLICMPass(), PMW);
2550 addMachineFunctionPass(MachineCSEPass(), PMW);
2551 addMachineFunctionPass(SIFoldOperandsPass(), PMW);
2552 }
2553 addMachineFunctionPass(DeadMachineInstructionElimPass(), PMW);
2554 addMachineFunctionPass(SIShrinkInstructionsPass(), PMW);
2555}
2556
2557Error AMDGPUCodeGenPassBuilder::addFastRegAlloc(PassManagerWrapper &PMW) const {
2558 insertPass<PHIEliminationPass>(SILowerControlFlowPass());
2559
2560 insertPass<TwoAddressInstructionPass>(SIWholeQuadModePass());
2561
2562 return Base::addFastRegAlloc(PMW);
2563}
2564
2565Error AMDGPUCodeGenPassBuilder::addRegAssignAndRewriteFast(
2566 PassManagerWrapper &PMW) const {
2567 if (auto Err = validateRegAllocOptions())
2568 return Err;
2569
2570 addMachineFunctionPass(GCNPreRALongBranchRegPass(), PMW);
2571
2572 // SGPR allocation - default to fast at -O0.
2573 if (SGPRRegAllocNPM == RegAllocType::Greedy)
2574 addMachineFunctionPass(RAGreedyPass({onlyAllocateSGPRs, "sgpr"}), PMW);
2575 else
2576 addMachineFunctionPass(RegAllocFastPass({onlyAllocateSGPRs, "sgpr", false}),
2577 PMW);
2578
2579 // Equivalent of PEI for SGPRs.
2580 addMachineFunctionPass(SILowerSGPRSpillsPass(), PMW);
2581
2582 // To Allocate wwm registers used in whole quad mode operations (for shaders).
2583 addMachineFunctionPass(SIPreAllocateWWMRegsPass(), PMW);
2584
2585 // WWM allocation - default to fast at -O0.
2586 if (WWMRegAllocNPM == RegAllocType::Greedy)
2587 addMachineFunctionPass(RAGreedyPass({onlyAllocateWWMRegs, "wwm"}), PMW);
2588 else
2589 addMachineFunctionPass(
2590 RegAllocFastPass({onlyAllocateWWMRegs, "wwm", false}), PMW);
2591
2592 addMachineFunctionPass(SILowerWWMCopiesPass(), PMW);
2593 addMachineFunctionPass(AMDGPUReserveWWMRegsPass(), PMW);
2594
2595 // VGPR allocation - default to fast at -O0.
2596 if (VGPRRegAllocNPM == RegAllocType::Greedy)
2597 addMachineFunctionPass(RAGreedyPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2598 else
2599 addMachineFunctionPass(RegAllocFastPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2600
2601 return Error::success();
2602}
2603
2604Error AMDGPUCodeGenPassBuilder::addOptimizedRegAlloc(
2605 PassManagerWrapper &PMW) const {
2606 if (EnableDCEInRA)
2607 insertPass<DetectDeadLanesPass>(DeadMachineInstructionElimPass());
2608
2609 // FIXME: when an instruction has a Killed operand, and the instruction is
2610 // inside a bundle, seems only the BUNDLE instruction appears as the Kills of
2611 // the register in LiveVariables, this would trigger a failure in verifier,
2612 // we should fix it and enable the verifier.
2613 if (OptVGPRLiveRange)
2614 insertPass<RequireAnalysisPass<LiveVariablesAnalysis, MachineFunction>>(
2616
2617 // This must be run immediately after phi elimination and before
2618 // TwoAddressInstructions, otherwise the processing of the tied operand of
2619 // SI_ELSE will introduce a copy of the tied operand source after the else.
2620 insertPass<PHIEliminationPass>(SILowerControlFlowPass());
2621
2623 insertPass<RenameIndependentSubregsPass>(GCNRewritePartialRegUsesPass());
2624
2625 if (isPassEnabled(EnablePreRAOptimizations))
2626 insertPass<MachineSchedulerPass>(GCNPreRAOptimizationsPass());
2627
2628 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
2629 // instructions that cause scheduling barriers.
2630 insertPass<MachineSchedulerPass>(SIWholeQuadModePass());
2631
2632 if (OptExecMaskPreRA)
2633 insertPass<MachineSchedulerPass>(SIOptimizeExecMaskingPreRAPass());
2634
2635 // This is not an essential optimization and it has a noticeable impact on
2636 // compilation time, so we only enable it from O2.
2637 if (TM.getOptLevel() > CodeGenOptLevel::Less)
2638 insertPass<MachineSchedulerPass>(SIFormMemoryClausesPass());
2639
2640 return Base::addOptimizedRegAlloc(PMW);
2641}
2642
2643void AMDGPUCodeGenPassBuilder::addPreRegAlloc(PassManagerWrapper &PMW) const {
2644 if (getOptLevel() != CodeGenOptLevel::None)
2645 addMachineFunctionPass(AMDGPUPrepareAGPRAllocPass(), PMW);
2646}
2647
2648Expected<bool> AMDGPUCodeGenPassBuilder::addRegAssignAndRewriteOptimized(
2649 PassManagerWrapper &PMW) const {
2650 if (auto Err = validateRegAllocOptions())
2651 return Err;
2652
2653 addMachineFunctionPass(GCNPreRALongBranchRegPass(), PMW);
2654
2655 // SGPR allocation - default to greedy at -O1 and above.
2656 if (SGPRRegAllocNPM == RegAllocType::Fast)
2657 addMachineFunctionPass(RegAllocFastPass({onlyAllocateSGPRs, "sgpr", false}),
2658 PMW);
2659 else
2660 addMachineFunctionPass(RAGreedyPass({onlyAllocateSGPRs, "sgpr"}), PMW);
2661
2662 // Commit allocated register changes. This is mostly necessary because too
2663 // many things rely on the use lists of the physical registers, such as the
2664 // verifier. This is only necessary with allocators which use LiveIntervals,
2665 // since FastRegAlloc does the replacements itself.
2666 addMachineFunctionPass(VirtRegRewriterPass(false), PMW);
2667
2668 // At this point, the sgpr-regalloc has been done and it is good to have the
2669 // stack slot coloring to try to optimize the SGPR spill stack indices before
2670 // attempting the custom SGPR spill lowering.
2671 addMachineFunctionPass(StackSlotColoringPass(), PMW);
2672
2673 // Equivalent of PEI for SGPRs.
2674 addMachineFunctionPass(SILowerSGPRSpillsPass(), PMW);
2675
2676 // To Allocate wwm registers used in whole quad mode operations (for shaders).
2677 addMachineFunctionPass(SIPreAllocateWWMRegsPass(), PMW);
2678
2679 // WWM allocation - default to greedy at -O1 and above.
2680 if (WWMRegAllocNPM == RegAllocType::Fast)
2681 addMachineFunctionPass(
2682 RegAllocFastPass({onlyAllocateWWMRegs, "wwm", false}), PMW);
2683 else
2684 addMachineFunctionPass(RAGreedyPass({onlyAllocateWWMRegs, "wwm"}), PMW);
2685 addMachineFunctionPass(SILowerWWMCopiesPass(), PMW);
2686 addMachineFunctionPass(VirtRegRewriterPass(false), PMW);
2687 addMachineFunctionPass(AMDGPUReserveWWMRegsPass(), PMW);
2688
2689 // VGPR allocation - default to greedy at -O1 and above.
2690 if (VGPRRegAllocNPM == RegAllocType::Fast)
2691 addMachineFunctionPass(RegAllocFastPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2692 else
2693 addMachineFunctionPass(RAGreedyPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2694
2695 addPreRewrite(PMW);
2696 addMachineFunctionPass(VirtRegRewriterPass(true), PMW);
2697
2698 addMachineFunctionPass(AMDGPUMarkLastScratchLoadPass(), PMW);
2699 return true;
2700}
2701
2702void AMDGPUCodeGenPassBuilder::addPostRegAlloc(PassManagerWrapper &PMW) const {
2703 addMachineFunctionPass(SIFixVGPRCopiesPass(), PMW);
2704 if (TM.getOptLevel() > CodeGenOptLevel::None)
2705 addMachineFunctionPass(SIOptimizeExecMaskingPass(), PMW);
2706 Base::addPostRegAlloc(PMW);
2707}
2708
2709void AMDGPUCodeGenPassBuilder::addPreSched2(PassManagerWrapper &PMW) const {
2710 if (TM.getOptLevel() > CodeGenOptLevel::None)
2711 addMachineFunctionPass(SIShrinkInstructionsPass(), PMW);
2712 addMachineFunctionPass(SIPostRABundlerPass(), PMW);
2713}
2714
2715void AMDGPUCodeGenPassBuilder::addPostBBSections(
2716 PassManagerWrapper &PMW) const {
2717 // We run this later to avoid passes like livedebugvalues and BBSections
2718 // having to deal with the apparent multi-entry functions we may generate.
2719 addMachineFunctionPass(AMDGPUPreloadKernArgPrologPass(), PMW);
2720}
2721
2722void AMDGPUCodeGenPassBuilder::addPreEmitPass(PassManagerWrapper &PMW) const {
2723 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less)) {
2724 addMachineFunctionPass(GCNCreateVOPDPass(), PMW);
2725 }
2726
2727 addMachineFunctionPass(SIMemoryLegalizerPass(), PMW);
2728 addMachineFunctionPass(SIInsertWaitcntsPass(), PMW);
2729
2730 addMachineFunctionPass(SIModeRegisterPass(), PMW);
2731
2732 if (TM.getOptLevel() > CodeGenOptLevel::None)
2733 addMachineFunctionPass(SIInsertHardClausesPass(), PMW);
2734
2735 addMachineFunctionPass(SILateBranchLoweringPass(), PMW);
2736
2737 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
2738 addMachineFunctionPass(AMDGPUSetWavePriorityPass(), PMW);
2739
2740 if (TM.getOptLevel() > CodeGenOptLevel::None)
2741 addMachineFunctionPass(SIPreEmitPeepholePass(), PMW);
2742
2743 // The hazard recognizer that runs as part of the post-ra scheduler does not
2744 // guarantee to be able handle all hazards correctly. This is because if there
2745 // are multiple scheduling regions in a basic block, the regions are scheduled
2746 // bottom up, so when we begin to schedule a region we don't know what
2747 // instructions were emitted directly before it.
2748 //
2749 // Here we add a stand-alone hazard recognizer pass which can handle all
2750 // cases.
2751 addMachineFunctionPass(PostRAHazardRecognizerPass(), PMW);
2752 addMachineFunctionPass(AMDGPUWaitSGPRHazardsPass(), PMW);
2753 addMachineFunctionPass(AMDGPULowerVGPREncodingPass(), PMW);
2754
2755 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less)) {
2756 addMachineFunctionPass(AMDGPUInsertDelayAluPass(), PMW);
2757 }
2758
2759 addMachineFunctionPass(BranchRelaxationPass(), PMW);
2760}
2761
2762bool AMDGPUCodeGenPassBuilder::isPassEnabled(const cl::opt<bool> &Opt,
2763 CodeGenOptLevel Level) const {
2764 if (Opt.getNumOccurrences())
2765 return Opt;
2766 if (TM.getOptLevel() < Level)
2767 return false;
2768 return Opt;
2769}
2770
2771void AMDGPUCodeGenPassBuilder::addEarlyCSEOrGVNPass(
2772 PassManagerWrapper &PMW) const {
2773 if (TM.getOptLevel() == CodeGenOptLevel::Aggressive)
2774 addFunctionPass(GVNPass(), PMW);
2775 else
2776 addFunctionPass(EarlyCSEPass(), PMW);
2777}
2778
2779void AMDGPUCodeGenPassBuilder::addStraightLineScalarOptimizationPasses(
2780 PassManagerWrapper &PMW) const {
2782 addFunctionPass(LoopDataPrefetchPass(), PMW);
2783
2784 addFunctionPass(SeparateConstOffsetFromGEPPass(), PMW);
2785
2786 // ReassociateGEPs exposes more opportunities for SLSR. See
2787 // the example in reassociate-geps-and-slsr.ll.
2788 addFunctionPass(StraightLineStrengthReducePass(), PMW);
2789
2790 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
2791 // EarlyCSE can reuse.
2792 addEarlyCSEOrGVNPass(PMW);
2793
2794 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
2795 addFunctionPass(NaryReassociatePass(), PMW);
2796
2797 // NaryReassociate on GEPs creates redundant common expressions, so run
2798 // EarlyCSE after it.
2799 addFunctionPass(EarlyCSEPass(), PMW);
2800}
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 cl::opt< bool > SramEccSetting("amdgpu-sramecc", cl::desc("Force amdgpu.sramecc for testing"), cl::ReallyHidden)
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 > XnackSetting("amdgpu-xnack", cl::desc("Force amdgpu.xnack value for testing"), cl::ReallyHidden)
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.
static AMDGPU::TargetIDSetting getTargetIDSettingFromModuleFlag(const Module &M, StringRef FlagName)
Get xnack/sramecc setting from module flag or cl::opt (for testing).
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:123
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:308
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
void push_back(const T &Elt)
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:48
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:545
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:392
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:4061
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,...
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.