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 PB.registerPipelineParsingCallback(
1002 [this](StringRef Name, CGSCCPassManager &PM,
1004 if (Name == "amdgpu-attributor-cgscc" && getTargetTriple().isAMDGCN()) {
1006 *static_cast<GCNTargetMachine *>(this)));
1007 return true;
1008 }
1009 return false;
1010 });
1011
1012 PB.registerScalarOptimizerLateEPCallback(
1013 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1014 if (Level == OptimizationLevel::O0)
1015 return;
1016
1018 });
1019
1020 PB.registerVectorizerEndEPCallback(
1021 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1022 if (Level == OptimizationLevel::O0)
1023 return;
1024
1026 });
1027
1028 PB.registerPipelineEarlySimplificationEPCallback(
1029 [this](ModulePassManager &PM, OptimizationLevel Level,
1031 if (!isLTOPreLink(Phase) && getTargetTriple().isAMDGCN()) {
1032 // When we are not using -fgpu-rdc, we can run accelerator code
1033 // selection relatively early, but still after linking to prevent
1034 // eager removal of potentially reachable symbols.
1035 if (EnableHipStdPar) {
1038 }
1039
1041 }
1042
1043 if (Level == OptimizationLevel::O0)
1044 return;
1045
1046 // We don't want to run internalization at per-module stage.
1049 PM.addPass(GlobalDCEPass());
1050 }
1051
1054 });
1055
1056 PB.registerPeepholeEPCallback(
1057 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1058 if (Level == OptimizationLevel::O0)
1059 return;
1060
1064
1067 });
1068
1069 PB.registerCGSCCOptimizerLateEPCallback(
1070 [this](CGSCCPassManager &PM, OptimizationLevel Level) {
1071 if (Level == OptimizationLevel::O0)
1072 return;
1073
1075
1076 // Add promote kernel arguments pass to the opt pipeline right before
1077 // infer address spaces which is needed to do actual address space
1078 // rewriting.
1081
1082 // Add infer address spaces pass to the opt pipeline after inlining
1083 // but before SROA to increase SROA opportunities.
1085
1086 // This should run after inlining to have any chance of doing
1087 // anything, and before other cleanup optimizations.
1089
1090 // Promote alloca to vector before SROA and loop unroll. If we
1091 // manage to eliminate allocas before unroll we may choose to unroll
1092 // less.
1094
1095 PM.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
1096 });
1097
1098 // FIXME: Why is AMDGPUAttributor not in CGSCC?
1099 PB.registerOptimizerLastEPCallback([this](ModulePassManager &MPM,
1100 OptimizationLevel Level,
1102 if (Level != OptimizationLevel::O0) {
1103 if (!isLTOPreLink(Phase)) {
1104 if (EnableAMDGPUAttributor && getTargetTriple().isAMDGCN()) {
1106 MPM.addPass(AMDGPUAttributorPass(*this, Opts, Phase));
1107 }
1108 }
1109 }
1110 });
1111
1112 PB.registerFullLinkTimeOptimizationLastEPCallback(
1113 [this](ModulePassManager &PM, OptimizationLevel Level) {
1114 // Clean up redundant memory round-trips that the full-LTO pipeline,
1115 // unlike the non-LTO/ThinLTO ones, otherwise leaves for codegen.
1116 if (Level != OptimizationLevel::O0) {
1118 EarlyCSEPass(/*UseMemorySSA=*/true)));
1119 }
1120
1121 // When we are using -fgpu-rdc, we can only run accelerator code
1122 // selection after linking to prevent, otherwise we end up removing
1123 // potentially reachable symbols that were exported as external in other
1124 // modules.
1125 if (EnableHipStdPar) {
1128 }
1129 // We want to support the -lto-partitions=N option as "best effort".
1130 // For that, we need to lower LDS earlier in the pipeline before the
1131 // module is partitioned for codegen.
1134 if (EnableSwLowerLDS)
1138 if (Level != OptimizationLevel::O0) {
1139 // We only want to run this with O2 or higher since inliner and SROA
1140 // don't run in O1.
1141 if (Level != OptimizationLevel::O1) {
1142 PM.addPass(
1144 }
1145 // Do we really need internalization in LTO?
1146 if (InternalizeSymbols) {
1148 PM.addPass(GlobalDCEPass());
1149 }
1150 if (EnableAMDGPUAttributor && getTargetTriple().isAMDGCN()) {
1153 Opt.IsClosedWorld = true;
1156 }
1157 }
1158 if (!NoKernelInfoEndLTO) {
1160 FPM.addPass(KernelInfoPrinter(this));
1161 PM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1162 }
1163 });
1164
1165 PB.registerRegClassFilterParsingCallback(
1166 [](StringRef FilterName) -> RegAllocFilterFunc {
1167 if (FilterName == "sgpr")
1168 return onlyAllocateSGPRs;
1169 if (FilterName == "vgpr")
1170 return onlyAllocateVGPRs;
1171 if (FilterName == "wwm")
1172 return onlyAllocateWWMRegs;
1173 return nullptr;
1174 });
1175}
1176
1178 unsigned DestAS) const {
1179 return AMDGPU::isFlatGlobalAddrSpace(SrcAS) &&
1181}
1182
1184 if (auto *Arg = dyn_cast<Argument>(V);
1185 Arg &&
1186 AMDGPU::isModuleEntryFunctionCC(Arg->getParent()->getCallingConv()) &&
1187 !Arg->hasByRefAttr())
1189
1190 const auto *LD = dyn_cast<LoadInst>(V);
1191 if (!LD) // TODO: Handle invariant load like constant.
1193
1194 // It must be a generic pointer loaded.
1195 assert(V->getType()->getPointerAddressSpace() == AMDGPUAS::FLAT_ADDRESS);
1196
1197 const auto *Ptr = LD->getPointerOperand();
1198 if (Ptr->getType()->getPointerAddressSpace() != AMDGPUAS::CONSTANT_ADDRESS)
1200 // For a generic pointer loaded from the constant memory, it could be assumed
1201 // as a global pointer since the constant memory is only populated on the
1202 // host side. As implied by the offload programming model, only global
1203 // pointers could be referenced on the host side.
1205}
1206
1207std::pair<const Value *, unsigned>
1209 if (auto *II = dyn_cast<IntrinsicInst>(V)) {
1210 switch (II->getIntrinsicID()) {
1211 case Intrinsic::amdgcn_is_shared:
1212 return std::pair(II->getArgOperand(0), AMDGPUAS::LOCAL_ADDRESS);
1213 case Intrinsic::amdgcn_is_private:
1214 return std::pair(II->getArgOperand(0), AMDGPUAS::PRIVATE_ADDRESS);
1215 default:
1216 break;
1217 }
1218 return std::pair(nullptr, -1);
1219 }
1220 // Check the global pointer predication based on
1221 // (!is_share(p) && !is_private(p)). Note that logic 'and' is commutative and
1222 // the order of 'is_shared' and 'is_private' is not significant.
1223 Value *Ptr;
1224 if (match(
1225 const_cast<Value *>(V),
1228 m_Deferred(Ptr))))))
1229 return std::pair(Ptr, AMDGPUAS::GLOBAL_ADDRESS);
1230
1231 return std::pair(nullptr, -1);
1232}
1233
1234unsigned
1249
1251 Module &M, unsigned NumParts,
1252 function_ref<void(std::unique_ptr<Module> MPart)> ModuleCallback) {
1253 // FIXME(?): Would be better to use an already existing Analysis/PassManager,
1254 // but all current users of this API don't have one ready and would need to
1255 // create one anyway. Let's hide the boilerplate for now to keep it simple.
1256
1261
1262 PassBuilder PB(this);
1263 PB.registerModuleAnalyses(MAM);
1264 PB.registerFunctionAnalyses(FAM);
1265 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
1266
1268 MPM.addPass(AMDGPUSplitModulePass(NumParts, ModuleCallback));
1269 MPM.run(M, MAM);
1270 return true;
1271}
1272
1273//===----------------------------------------------------------------------===//
1274// GCN Target Machine (SI+)
1275//===----------------------------------------------------------------------===//
1276
1278 StringRef CPU, StringRef FS,
1279 const TargetOptions &Options,
1280 std::optional<Reloc::Model> RM,
1281 std::optional<CodeModel::Model> CM,
1282 CodeGenOptLevel OL, bool JIT)
1283 : AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {
1285}
1286
1287enum class OOBFlagValue {
1288 Any = 0,
1291};
1292
1293/// Returns the OOB mode encoded by a module flag.
1294/// An absent flag defaults to Any.
1295static OOBFlagValue getOOBFlagValue(const Module &M, StringRef FlagName) {
1296 const auto *Flag =
1297 mdconst::dyn_extract_or_null<ConstantInt>(M.getModuleFlag(FlagName));
1298 if (!Flag)
1299 return OOBFlagValue::Any;
1300 return static_cast<OOBFlagValue>(Flag->getZExtValue());
1301}
1302
1303/// Returns the xnack/sramecc setting encoded by a module flag.
1304/// Module flag values: 0 = disabled, 1 = enabled.
1305/// An absent flag defaults to Any.
1308 StringRef FlagName) {
1310
1311 if (XnackSetting.getNumOccurrences() > 0 && FlagName == "amdgpu.xnack")
1312 return XnackSetting ? TargetIDSetting::On : TargetIDSetting::Off;
1313 if (SramEccSetting.getNumOccurrences() > 0 && FlagName == "amdgpu.sramecc")
1314 return SramEccSetting ? TargetIDSetting::On : TargetIDSetting::Off;
1315
1316 const auto *Flag =
1317 mdconst::dyn_extract_or_null<ConstantInt>(M.getModuleFlag(FlagName));
1318 if (!Flag)
1319 return TargetIDSetting::Any;
1320 return Flag->getZExtValue() == 0 ? TargetIDSetting::Off : TargetIDSetting::On;
1321}
1322
1323const TargetSubtargetInfo *
1325 StringRef GPU = getGPUName(F);
1327
1328 const Module &M = *F.getParent();
1331 bool BufRelaxed = BufOOB == OOBFlagValue::Relaxed;
1332 bool TBufRelaxed = TBufOOB == OOBFlagValue::Relaxed;
1333
1335 TargetIDSetting Xnack = getTargetIDSettingFromModuleFlag(M, "amdgpu.xnack");
1336 TargetIDSetting SramEcc =
1337 getTargetIDSettingFromModuleFlag(M, "amdgpu.sramecc");
1338
1339 SmallString<128> SubtargetKey(GPU);
1340 SubtargetKey.append(FS);
1341 if (BufRelaxed)
1342 SubtargetKey.append(",buf-oob=1");
1343 if (TBufRelaxed)
1344 SubtargetKey.append(",tbuf-oob=1");
1345 if (Xnack != TargetIDSetting::Any) {
1346 SubtargetKey.append(",xnack=");
1347 SubtargetKey.push_back(Xnack == TargetIDSetting::On ? '1' : '0');
1348 }
1349 if (SramEcc != TargetIDSetting::Any) {
1350 SubtargetKey.append(",sramecc=");
1351 SubtargetKey.push_back(Xnack == TargetIDSetting::On ? '1' : '0');
1352 }
1353
1354 auto &I = SubtargetMap[SubtargetKey];
1355 if (!I) {
1357 Triple::SubArchType GPUSubArch = AMDGPU::getSubArch(Kind);
1358
1359 // Enforce the subtarget is covered by the subarch. Tolerate no subarch for
1360 // legacy compatibility.
1361 const Triple &TT = M.getTargetTriple();
1362 if (GPUSubArch != TT.getSubArch() && Kind != AMDGPU::GK_NONE) {
1363 // Check if this is a generic subarch which has subtargets. Ignore
1364 // unknown subtargets with a known subarch, since for whatever reason
1365 // the convention is to just print a warning and ignore unrecognized
1366 // subtargets.
1367 bool IsLegacyEmptySubArch = TT.getSubArch() == Triple::NoSubArch;
1368 if (!IsLegacyEmptySubArch &&
1369 AMDGPU::getMajorSubArch(GPUSubArch) != TT.getSubArch()) {
1370 F.getContext().emitError("invalid subtarget '" + Twine(GPU) +
1371 "' for subarch " + TT.getArchName());
1372 }
1373 }
1374
1375 I = std::make_unique<GCNSubtarget>(TargetTriple, GPU, FS, *this, BufRelaxed,
1376 TBufRelaxed, Xnack, SramEcc);
1377 }
1378
1379 I->setScalarizeGlobalBehavior(ScalarizeGlobal);
1380
1381 return I.get();
1382}
1383
1386 return TargetTransformInfo(std::make_unique<GCNTTIImpl>(this, F));
1387}
1388
1391 raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
1392 const CGPassBuilderOption &Opts, MCContext &Ctx,
1394 AMDGPUCodeGenPassBuilder CGPB(*this, Opts, PIC);
1395 return CGPB.buildPipeline(MPM, MAM, Out, DwoOut, FileType, Ctx);
1396}
1397
1400 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
1401 if (ST.enableSIScheduler())
1403
1404 StringRef SchedStrategy = AMDGPU::getSchedStrategy(C->MF->getFunction());
1405
1406 if (SchedStrategy == "max-ilp")
1408
1409 if (SchedStrategy == "max-memory-clause")
1411
1412 if (SchedStrategy == "iterative-ilp")
1414
1415 if (SchedStrategy == "iterative-minreg")
1416 return createMinRegScheduler(C);
1417
1418 if (SchedStrategy == "iterative-maxocc")
1420
1421 if (SchedStrategy == "coexec") {
1422 diagnoseUnsupportedCoExecSchedulerSelection(C->MF->getFunction(), ST);
1424 }
1425
1427}
1428
1431 if (useNoopPostScheduler(C->MF->getFunction()))
1433
1434 ScheduleDAGMI *DAG =
1435 new GCNPostScheduleDAGMILive(C, std::make_unique<PostGenericScheduler>(C),
1436 /*RemoveKillFlags=*/true);
1437 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
1439 if (ST.shouldClusterStores())
1442 if ((EnableVOPD.getNumOccurrences() ||
1444 EnableVOPD)
1449 return DAG;
1450}
1451//===----------------------------------------------------------------------===//
1452// AMDGPU Legacy Pass Setup
1453//===----------------------------------------------------------------------===//
1454
1455std::unique_ptr<CSEConfigBase> llvm::AMDGPUPassConfig::getCSEConfig() const {
1456 return getStandardCSEConfigForOpt(TM->getOptLevel());
1457}
1458
1459namespace {
1460
1461class GCNPassConfig final : public AMDGPUPassConfig {
1462public:
1463 GCNPassConfig(TargetMachine &TM, PassManagerBase &PM)
1464 : AMDGPUPassConfig(TM, PM) {
1465 substitutePass(&PostRASchedulerID, &PostMachineSchedulerID);
1466 }
1467
1468 GCNTargetMachine &getGCNTargetMachine() const {
1469 return getTM<GCNTargetMachine>();
1470 }
1471
1472 bool addPreISel() override;
1473 void addMachineSSAOptimization() override;
1474 bool addILPOpts() override;
1475 bool addInstSelector() override;
1476 bool addIRTranslator() override;
1477 void addPreLegalizeMachineIR() override;
1478 bool addLegalizeMachineIR() override;
1479 void addPreRegBankSelect() override;
1480 bool addRegBankSelect() override;
1481 void addPreGlobalInstructionSelect() override;
1482 bool addGlobalInstructionSelect() override;
1483 void addPreRegAlloc() override;
1484 void addFastRegAlloc() override;
1485 void addOptimizedRegAlloc() override;
1486
1487 FunctionPass *createSGPRAllocPass(bool Optimized);
1488 FunctionPass *createVGPRAllocPass(bool Optimized);
1489 FunctionPass *createWWMRegAllocPass(bool Optimized);
1490 FunctionPass *createRegAllocPass(bool Optimized) override;
1491
1492 bool addRegAssignAndRewriteFast() override;
1493 bool addRegAssignAndRewriteOptimized() override;
1494
1495 bool addPreRewrite() override;
1496 void addPostRegAlloc() override;
1497 void addPreSched2() override;
1498 void addPreEmitPass() override;
1499 void addPostBBSections() override;
1500};
1501
1502} // end anonymous namespace
1503
1505 : TargetPassConfig(TM, PM) {
1506 // Exceptions and StackMaps are not supported, so these passes will never do
1507 // anything.
1510 // Garbage collection is not supported.
1513}
1514
1521
1526 // ReassociateGEPs exposes more opportunities for SLSR. See
1527 // the example in reassociate-geps-and-slsr.ll.
1529 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
1530 // EarlyCSE can reuse.
1532 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
1534 // NaryReassociate on GEPs creates redundant common expressions, so run
1535 // EarlyCSE after it.
1537}
1538
1541
1542 if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN())
1544
1545 // There is no reason to run these.
1549
1550 if (TM.getTargetTriple().isAMDGCN())
1552
1553 if (LowerCtorDtor)
1555
1556 if (TM.getTargetTriple().isAMDGCN() &&
1559
1562
1563 // This can be disabled by passing ::Disable here or on the command line
1564 // with --expand-variadics-override=disable.
1566
1567 // Function calls are not supported, so make sure we inline everything.
1570
1571 // Handle uses of OpenCL image2d_t, image3d_t and sampler_t arguments.
1572 if (TM.getTargetTriple().getArch() == Triple::r600)
1574
1575 // Make enqueued block runtime handles externally visible.
1577
1578 // Lower special LDS accesses.
1581
1582 // Lower LDS accesses to global memory pass if address sanitizer is enabled.
1583 if (EnableSwLowerLDS)
1585
1586 // Runs before PromoteAlloca so the latter can account for function uses
1589 }
1590
1591 // Run atomic optimizer before Atomic Expand
1592 if ((TM.getTargetTriple().isAMDGCN()) &&
1593 (TM.getOptLevel() >= CodeGenOptLevel::Less) &&
1596 }
1597
1599
1600 if (TM.getOptLevel() > CodeGenOptLevel::None) {
1602
1605
1609 AAResults &AAR) {
1610 if (auto *WrapperPass = P.getAnalysisIfAvailable<AMDGPUAAWrapperPass>())
1611 AAR.addAAResult(WrapperPass->getResult());
1612 }));
1613 }
1614
1615 if (TM.getTargetTriple().isAMDGCN()) {
1616 // TODO: May want to move later or split into an early and late one.
1618 }
1619
1620 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
1621 // have expanded.
1622 if (TM.getOptLevel() > CodeGenOptLevel::Less)
1624 }
1625
1627
1628 // EarlyCSE is not always strong enough to clean up what LSR produces. For
1629 // example, GVN can combine
1630 //
1631 // %0 = add %a, %b
1632 // %1 = add %b, %a
1633 //
1634 // and
1635 //
1636 // %0 = shl nsw %a, 2
1637 // %1 = shl %a, 2
1638 //
1639 // but EarlyCSE can do neither of them.
1642}
1643
1645 if (TM->getTargetTriple().isAMDGCN() &&
1646 TM->getOptLevel() > CodeGenOptLevel::None)
1648
1649 if (TM->getTargetTriple().isAMDGCN() && EnableLowerKernelArguments)
1651
1653
1656
1657 if (TM->getTargetTriple().isAMDGCN()) {
1658 // This lowering has been placed after codegenprepare to take advantage of
1659 // address mode matching (which is why it isn't put with the LDS lowerings).
1660 // It could be placed anywhere before uniformity annotations (an analysis
1661 // that it changes by splitting up fat pointers into their components)
1662 // but has been put before switch lowering and CFG flattening so that those
1663 // passes can run on the more optimized control flow this pass creates in
1664 // many cases.
1667 }
1668
1669 // LowerSwitch pass may introduce unreachable blocks that can
1670 // cause unexpected behavior for subsequent passes. Placing it
1671 // here seems better that these blocks would get cleaned up by
1672 // UnreachableBlockElim inserted next in the pass flow.
1674}
1675
1677 if (TM->getOptLevel() > CodeGenOptLevel::None)
1679 return false;
1680}
1681
1686
1688 // Do nothing. GC is not supported.
1689 return false;
1690}
1691
1692//===----------------------------------------------------------------------===//
1693// GCN Legacy Pass Setup
1694//===----------------------------------------------------------------------===//
1695
1696bool GCNPassConfig::addPreISel() {
1698
1699 if (TM->getOptLevel() > CodeGenOptLevel::None) {
1700 addPass(createSinkingPass());
1702 }
1703
1704 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
1705 // regions formed by them.
1707 addPass(createFixIrreduciblePass());
1708 addPass(createUnifyLoopExitsPass());
1709 addPass(createStructurizeCFGPass(false)); // true -> SkipUniformRegions
1710
1713 // TODO: Move this right after structurizeCFG to avoid extra divergence
1714 // analysis. This depends on stopping SIAnnotateControlFlow from making
1715 // control flow modifications.
1717
1718 // SDAG requires LCSSA, GlobalISel does not. Disable LCSSA for -global-isel
1719 // without any of the fallback options.
1722 !isGlobalISelAbortEnabled())
1723 addPass(createLCSSAPass());
1724
1725 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1727
1728 return false;
1729}
1730
1731void GCNPassConfig::addMachineSSAOptimization() {
1733
1734 // We want to fold operands after PeepholeOptimizer has run (or as part of
1735 // it), because it will eliminate extra copies making it easier to fold the
1736 // real source operand. We want to eliminate dead instructions after, so that
1737 // we see fewer uses of the copies. We then need to clean up the dead
1738 // instructions leftover after the operands are folded as well.
1739 //
1740 // XXX - Can we get away without running DeadMachineInstructionElim again?
1741 addPass(&SIFoldOperandsLegacyID);
1742 if (EnableDPPCombine)
1743 addPass(&GCNDPPCombineLegacyID);
1745 if (isPassEnabled(EnableSDWAPeephole)) {
1746 addPass(&SIPeepholeSDWALegacyID);
1747 addPass(&EarlyMachineLICMID);
1748 addPass(&MachineCSELegacyID);
1749 addPass(&SIFoldOperandsLegacyID);
1750 }
1753}
1754
1755bool GCNPassConfig::addILPOpts() {
1757 addPass(&EarlyIfConverterLegacyID);
1758
1760 return false;
1761}
1762
1763bool GCNPassConfig::addInstSelector() {
1765 addPass(&SIFixSGPRCopiesLegacyID);
1767 return false;
1768}
1769
1770bool GCNPassConfig::addIRTranslator() {
1771 addPass(new IRTranslator(getOptLevel()));
1772 return false;
1773}
1774
1775void GCNPassConfig::addPreLegalizeMachineIR() {
1776 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1777 addPass(createAMDGPUPreLegalizeCombiner(IsOptNone));
1778 addPass(new Localizer());
1779}
1780
1781bool GCNPassConfig::addLegalizeMachineIR() {
1782 addPass(new Legalizer());
1783 return false;
1784}
1785
1786void GCNPassConfig::addPreRegBankSelect() {
1787 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1788 addPass(createAMDGPUPostLegalizeCombiner(IsOptNone));
1790}
1791
1792bool GCNPassConfig::addRegBankSelect() {
1795 return false;
1796}
1797
1798void GCNPassConfig::addPreGlobalInstructionSelect() {
1799 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1800 addPass(createAMDGPURegBankCombiner(IsOptNone));
1801}
1802
1803bool GCNPassConfig::addGlobalInstructionSelect() {
1804 addPass(new InstructionSelect(getOptLevel()));
1805 return false;
1806}
1807
1808void GCNPassConfig::addFastRegAlloc() {
1809 // FIXME: We have to disable the verifier here because of PHIElimination +
1810 // TwoAddressInstructions disabling it.
1811
1812 // This must be run immediately after phi elimination and before
1813 // TwoAddressInstructions, otherwise the processing of the tied operand of
1814 // SI_ELSE will introduce a copy of the tied operand source after the else.
1816
1818
1820}
1821
1822void GCNPassConfig::addPreRegAlloc() {
1823 if (getOptLevel() != CodeGenOptLevel::None)
1825}
1826
1827void GCNPassConfig::addOptimizedRegAlloc() {
1828 if (EnableDCEInRA)
1830
1831 // FIXME: when an instruction has a Killed operand, and the instruction is
1832 // inside a bundle, seems only the BUNDLE instruction appears as the Kills of
1833 // the register in LiveVariables, this would trigger a failure in verifier,
1834 // we should fix it and enable the verifier.
1835 if (OptVGPRLiveRange)
1837
1838 // This must be run immediately after phi elimination and before
1839 // TwoAddressInstructions, otherwise the processing of the tied operand of
1840 // SI_ELSE will introduce a copy of the tied operand source after the else.
1842
1845
1846 if (isPassEnabled(EnablePreRAOptimizations))
1848
1849 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
1850 // instructions that cause scheduling barriers.
1852
1853 if (OptExecMaskPreRA)
1855
1856 // This is not an essential optimization and it has a noticeable impact on
1857 // compilation time, so we only enable it from O2.
1858 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1860
1862}
1863
1864bool GCNPassConfig::addPreRewrite() {
1866 addPass(&GCNNSAReassignID);
1867
1869 return true;
1870}
1871
1872FunctionPass *GCNPassConfig::createSGPRAllocPass(bool Optimized) {
1873 // Initialize the global default.
1874 llvm::call_once(InitializeDefaultSGPRRegisterAllocatorFlag,
1875 initializeDefaultSGPRRegisterAllocatorOnce);
1876
1877 RegisterRegAlloc::FunctionPassCtor Ctor = SGPRRegisterRegAlloc::getDefault();
1878 if (Ctor != useDefaultRegisterAllocator)
1879 return Ctor();
1880
1881 if (Optimized)
1882 return createGreedyRegisterAllocator(onlyAllocateSGPRs);
1883
1884 return createFastRegisterAllocator(onlyAllocateSGPRs, false);
1885}
1886
1887FunctionPass *GCNPassConfig::createVGPRAllocPass(bool Optimized) {
1888 // Initialize the global default.
1889 llvm::call_once(InitializeDefaultVGPRRegisterAllocatorFlag,
1890 initializeDefaultVGPRRegisterAllocatorOnce);
1891
1892 RegisterRegAlloc::FunctionPassCtor Ctor = VGPRRegisterRegAlloc::getDefault();
1893 if (Ctor != useDefaultRegisterAllocator)
1894 return Ctor();
1895
1896 if (Optimized)
1897 return createGreedyVGPRRegisterAllocator();
1898
1899 return createFastVGPRRegisterAllocator();
1900}
1901
1902FunctionPass *GCNPassConfig::createWWMRegAllocPass(bool Optimized) {
1903 // Initialize the global default.
1904 llvm::call_once(InitializeDefaultWWMRegisterAllocatorFlag,
1905 initializeDefaultWWMRegisterAllocatorOnce);
1906
1907 RegisterRegAlloc::FunctionPassCtor Ctor = WWMRegisterRegAlloc::getDefault();
1908 if (Ctor != useDefaultRegisterAllocator)
1909 return Ctor();
1910
1911 if (Optimized)
1912 return createGreedyWWMRegisterAllocator();
1913
1914 return createFastWWMRegisterAllocator();
1915}
1916
1917FunctionPass *GCNPassConfig::createRegAllocPass(bool Optimized) {
1918 llvm_unreachable("should not be used");
1919}
1920
1922 "-regalloc not supported with amdgcn. Use -sgpr-regalloc, -wwm-regalloc, "
1923 "and -vgpr-regalloc";
1924
1925bool GCNPassConfig::addRegAssignAndRewriteFast() {
1926 if (!usingDefaultRegAlloc())
1928
1929 addPass(&GCNPreRALongBranchRegID);
1930
1931 addPass(createSGPRAllocPass(false));
1932
1933 // Equivalent of PEI for SGPRs.
1934 addPass(&SILowerSGPRSpillsLegacyID);
1935
1936 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1938
1939 // For allocating other wwm register operands.
1940 addPass(createWWMRegAllocPass(false));
1941
1942 addPass(&SILowerWWMCopiesLegacyID);
1944
1945 // For allocating per-thread VGPRs.
1946 addPass(createVGPRAllocPass(false));
1947
1948 return true;
1949}
1950
1951bool GCNPassConfig::addRegAssignAndRewriteOptimized() {
1952 if (!usingDefaultRegAlloc())
1954
1955 addPass(&GCNPreRALongBranchRegID);
1956
1957 addPass(createSGPRAllocPass(true));
1958
1959 // Commit allocated register changes. This is mostly necessary because too
1960 // many things rely on the use lists of the physical registers, such as the
1961 // verifier. This is only necessary with allocators which use LiveIntervals,
1962 // since FastRegAlloc does the replacements itself.
1963 addPass(createVirtRegRewriter(false));
1964
1965 // At this point, the sgpr-regalloc has been done and it is good to have the
1966 // stack slot coloring to try to optimize the SGPR spill stack indices before
1967 // attempting the custom SGPR spill lowering.
1968 addPass(&StackSlotColoringID);
1969
1970 // Equivalent of PEI for SGPRs.
1971 addPass(&SILowerSGPRSpillsLegacyID);
1972
1973 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1975
1976 // For allocating other whole wave mode registers.
1977 addPass(createWWMRegAllocPass(true));
1978 addPass(&SILowerWWMCopiesLegacyID);
1979 addPass(createVirtRegRewriter(false));
1981
1982 // For allocating per-thread VGPRs.
1983 addPass(createVGPRAllocPass(true));
1984
1985 addPreRewrite();
1986 addPass(&VirtRegRewriterID);
1987
1989
1990 return true;
1991}
1992
1993void GCNPassConfig::addPostRegAlloc() {
1994 addPass(&SIFixVGPRCopiesID);
1995 if (getOptLevel() > CodeGenOptLevel::None)
1998}
1999
2000void GCNPassConfig::addPreSched2() {
2001 if (TM->getOptLevel() > CodeGenOptLevel::None)
2003 addPass(&SIPostRABundlerLegacyID);
2004}
2005
2006void GCNPassConfig::addPreEmitPass() {
2007 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less))
2008 addPass(&GCNCreateVOPDID);
2009 addPass(createSIMemoryLegalizerPass());
2010 addPass(createSIInsertWaitcntsPass());
2011
2012 addPass(createSIModeRegisterPass());
2013
2014 if (getOptLevel() > CodeGenOptLevel::None)
2015 addPass(&SIInsertHardClausesID);
2016
2018 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
2020 if (getOptLevel() > CodeGenOptLevel::None)
2021 addPass(&SIPreEmitPeepholeID);
2022 // The hazard recognizer that runs as part of the post-ra scheduler does not
2023 // guarantee to be able handle all hazards correctly. This is because if there
2024 // are multiple scheduling regions in a basic block, the regions are scheduled
2025 // bottom up, so when we begin to schedule a region we don't know what
2026 // instructions were emitted directly before it.
2027 //
2028 // Here we add a stand-alone hazard recognizer pass which can handle all
2029 // cases.
2030 addPass(&PostRAHazardRecognizerID);
2031
2033
2035
2036 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less))
2037 addPass(&AMDGPUInsertDelayAluID);
2038
2039 addPass(&BranchRelaxationPassID);
2040}
2041
2042void GCNPassConfig::addPostBBSections() {
2043 // We run this later to avoid passes like livedebugvalues and BBSections
2044 // having to deal with the apparent multi-entry functions we may generate.
2046}
2047
2049 return new GCNPassConfig(*this, PM);
2050}
2051
2057
2064
2068
2075
2078 SMDiagnostic &Error, SMRange &SourceRange) const {
2079 const yaml::SIMachineFunctionInfo &YamlMFI =
2080 static_cast<const yaml::SIMachineFunctionInfo &>(MFI_);
2081 MachineFunction &MF = PFS.MF;
2083 const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
2084
2085 if (MFI->initializeBaseYamlFields(YamlMFI, MF, PFS, Error, SourceRange))
2086 return true;
2087
2088 if (MFI->Occupancy == 0) {
2089 // Fixup the subtarget dependent default value.
2090 MFI->Occupancy = ST.getOccupancyWithWorkGroupSizes(MF).second;
2091 }
2092
2093 auto parseRegister = [&](const yaml::StringValue &RegName, Register &RegVal) {
2094 Register TempReg;
2095 if (parseNamedRegisterReference(PFS, TempReg, RegName.Value, Error)) {
2096 SourceRange = RegName.SourceRange;
2097 return true;
2098 }
2099 RegVal = TempReg;
2100
2101 return false;
2102 };
2103
2104 auto parseOptionalRegister = [&](const yaml::StringValue &RegName,
2105 Register &RegVal) {
2106 return !RegName.Value.empty() && parseRegister(RegName, RegVal);
2107 };
2108
2109 if (parseOptionalRegister(YamlMFI.VGPRForAGPRCopy, MFI->VGPRForAGPRCopy))
2110 return true;
2111
2112 if (parseOptionalRegister(YamlMFI.SGPRForEXECCopy, MFI->SGPRForEXECCopy))
2113 return true;
2114
2115 if (parseOptionalRegister(YamlMFI.LongBranchReservedReg,
2116 MFI->LongBranchReservedReg))
2117 return true;
2118
2119 auto diagnoseRegisterClass = [&](const yaml::StringValue &RegName) {
2120 // Create a diagnostic for a the register string literal.
2121 const MemoryBuffer &Buffer =
2122 *PFS.SM->getMemoryBuffer(PFS.SM->getMainFileID());
2123 Error = SMDiagnostic(*PFS.SM, SMLoc(), Buffer.getBufferIdentifier(), 1,
2124 RegName.Value.size(), SourceMgr::DK_Error,
2125 "incorrect register class for field", RegName.Value,
2126 {}, {});
2127 SourceRange = RegName.SourceRange;
2128 return true;
2129 };
2130
2131 if (parseRegister(YamlMFI.ScratchRSrcReg, MFI->ScratchRSrcReg) ||
2132 parseRegister(YamlMFI.FrameOffsetReg, MFI->FrameOffsetReg) ||
2133 parseRegister(YamlMFI.StackPtrOffsetReg, MFI->StackPtrOffsetReg))
2134 return true;
2135
2136 if (MFI->ScratchRSrcReg != AMDGPU::PRIVATE_RSRC_REG &&
2137 !AMDGPU::SGPR_128RegClass.contains(MFI->ScratchRSrcReg)) {
2138 return diagnoseRegisterClass(YamlMFI.ScratchRSrcReg);
2139 }
2140
2141 if (MFI->FrameOffsetReg != AMDGPU::FP_REG &&
2142 !AMDGPU::SGPR_32RegClass.contains(MFI->FrameOffsetReg)) {
2143 return diagnoseRegisterClass(YamlMFI.FrameOffsetReg);
2144 }
2145
2146 if (MFI->StackPtrOffsetReg != AMDGPU::SP_REG &&
2147 !AMDGPU::SGPR_32RegClass.contains(MFI->StackPtrOffsetReg)) {
2148 return diagnoseRegisterClass(YamlMFI.StackPtrOffsetReg);
2149 }
2150
2151 for (const auto &YamlReg : YamlMFI.WWMReservedRegs) {
2152 Register ParsedReg;
2153 if (parseRegister(YamlReg, ParsedReg))
2154 return true;
2155
2156 MFI->reserveWWMRegister(ParsedReg);
2157 }
2158
2159 for (const auto &[_, Info] : PFS.VRegInfosNamed) {
2160 MFI->setFlag(Info->VReg, Info->Flags);
2161 }
2162 for (const auto &[_, Info] : PFS.VRegInfos) {
2163 MFI->setFlag(Info->VReg, Info->Flags);
2164 }
2165
2166 for (const auto &YamlRegStr : YamlMFI.SpillPhysVGPRS) {
2167 Register ParsedReg;
2168 if (parseRegister(YamlRegStr, ParsedReg))
2169 return true;
2170 MFI->SpillPhysVGPRs.push_back(ParsedReg);
2171 }
2172
2173 auto parseAndCheckArgument = [&](const std::optional<yaml::SIArgument> &A,
2174 const TargetRegisterClass &RC,
2175 ArgDescriptor &Arg, unsigned UserSGPRs,
2176 unsigned SystemSGPRs) {
2177 // Skip parsing if it's not present.
2178 if (!A)
2179 return false;
2180
2181 if (A->IsRegister) {
2182 Register Reg;
2183 if (parseNamedRegisterReference(PFS, Reg, A->RegisterName.Value, Error)) {
2184 SourceRange = A->RegisterName.SourceRange;
2185 return true;
2186 }
2187 if (!RC.contains(Reg))
2188 return diagnoseRegisterClass(A->RegisterName);
2190 } else
2191 Arg = ArgDescriptor::createStack(A->StackOffset);
2192 // Check and apply the optional mask.
2193 if (A->Mask)
2194 Arg = ArgDescriptor::createArg(Arg, *A->Mask);
2195
2196 MFI->NumUserSGPRs += UserSGPRs;
2197 MFI->NumSystemSGPRs += SystemSGPRs;
2198 return false;
2199 };
2200
2201 if (YamlMFI.ArgInfo &&
2202 (parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentBuffer,
2203 AMDGPU::SGPR_128RegClass,
2204 MFI->ArgInfo.PrivateSegmentBuffer, 4, 0) ||
2205 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchPtr,
2206 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchPtr,
2207 2, 0) ||
2208 parseAndCheckArgument(YamlMFI.ArgInfo->QueuePtr, AMDGPU::SReg_64RegClass,
2209 MFI->ArgInfo.QueuePtr, 2, 0) ||
2210 parseAndCheckArgument(YamlMFI.ArgInfo->KernargSegmentPtr,
2211 AMDGPU::SReg_64RegClass,
2212 MFI->ArgInfo.KernargSegmentPtr, 2, 0) ||
2213 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchID,
2214 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchID,
2215 2, 0) ||
2216 parseAndCheckArgument(YamlMFI.ArgInfo->FlatScratchInit,
2217 AMDGPU::SReg_64RegClass,
2218 MFI->ArgInfo.FlatScratchInit, 2, 0) ||
2219 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentSize,
2220 AMDGPU::SGPR_32RegClass,
2221 MFI->ArgInfo.PrivateSegmentSize, 0, 0) ||
2222 parseAndCheckArgument(YamlMFI.ArgInfo->LDSKernelId,
2223 AMDGPU::SGPR_32RegClass,
2224 MFI->ArgInfo.LDSKernelId, 0, 1) ||
2225 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDX,
2226 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDX,
2227 0, 1) ||
2228 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDY,
2229 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDY,
2230 0, 1) ||
2231 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDZ,
2232 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDZ,
2233 0, 1) ||
2234 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupInfo,
2235 AMDGPU::SGPR_32RegClass,
2236 MFI->ArgInfo.WorkGroupInfo, 0, 1) ||
2237 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentWaveByteOffset,
2238 AMDGPU::SGPR_32RegClass,
2239 MFI->ArgInfo.PrivateSegmentWaveByteOffset, 0, 1) ||
2240 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitArgPtr,
2241 AMDGPU::SReg_64RegClass,
2242 MFI->ArgInfo.ImplicitArgPtr, 0, 0) ||
2243 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitBufferPtr,
2244 AMDGPU::SReg_64RegClass,
2245 MFI->ArgInfo.ImplicitBufferPtr, 2, 0) ||
2246 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDX,
2247 AMDGPU::VGPR_32RegClass,
2248 MFI->ArgInfo.WorkItemIDX, 0, 0) ||
2249 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDY,
2250 AMDGPU::VGPR_32RegClass,
2251 MFI->ArgInfo.WorkItemIDY, 0, 0) ||
2252 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDZ,
2253 AMDGPU::VGPR_32RegClass,
2254 MFI->ArgInfo.WorkItemIDZ, 0, 0)))
2255 return true;
2256
2257 // Parse FirstKernArgPreloadReg separately, since it's a Register,
2258 // not ArgDescriptor.
2259 if (YamlMFI.ArgInfo && YamlMFI.ArgInfo->FirstKernArgPreloadReg) {
2260 const yaml::SIArgument &A = *YamlMFI.ArgInfo->FirstKernArgPreloadReg;
2261
2262 if (!A.IsRegister) {
2263 // For stack arguments, we don't have RegisterName.SourceRange,
2264 // but we should have some location info from the YAML parser
2265 const MemoryBuffer &Buffer =
2266 *PFS.SM->getMemoryBuffer(PFS.SM->getMainFileID());
2267 // Create a minimal valid source range
2269 SMRange Range(Loc, Loc);
2270
2272 *PFS.SM, Loc, Buffer.getBufferIdentifier(), 1, 0, SourceMgr::DK_Error,
2273 "firstKernArgPreloadReg must be a register, not a stack location", "",
2274 {}, {});
2275
2276 SourceRange = Range;
2277 return true;
2278 }
2279
2280 Register Reg;
2281 if (parseNamedRegisterReference(PFS, Reg, A.RegisterName.Value, Error)) {
2282 SourceRange = A.RegisterName.SourceRange;
2283 return true;
2284 }
2285
2286 if (!AMDGPU::SGPR_32RegClass.contains(Reg))
2287 return diagnoseRegisterClass(A.RegisterName);
2288
2289 MFI->ArgInfo.FirstKernArgPreloadReg = Reg;
2290 MFI->NumUserSGPRs += YamlMFI.NumKernargPreloadSGPRs;
2291 }
2292
2293 if (ST.hasFeature(AMDGPU::FeatureDX10ClampAndIEEEMode)) {
2294 MFI->Mode.IEEE = YamlMFI.Mode.IEEE;
2295 MFI->Mode.DX10Clamp = YamlMFI.Mode.DX10Clamp;
2296 }
2297
2298 // FIXME: Move proper support for denormal-fp-math into base MachineFunction
2299 MFI->Mode.FP32Denormals.Input = YamlMFI.Mode.FP32InputDenormals
2302 MFI->Mode.FP32Denormals.Output = YamlMFI.Mode.FP32OutputDenormals
2305
2312
2313 if (YamlMFI.HasInitWholeWave)
2314 MFI->setInitWholeWave();
2315
2316 return false;
2317}
2318
2319//===----------------------------------------------------------------------===//
2320// AMDGPU CodeGen Pass Builder interface.
2321//===----------------------------------------------------------------------===//
2322
2323AMDGPUCodeGenPassBuilder::AMDGPUCodeGenPassBuilder(
2324 GCNTargetMachine &TM, const CGPassBuilderOption &Opts,
2326 : CodeGenPassBuilder(TM, Opts, PIC) {
2327 Opt.MISchedPostRA = true;
2328 Opt.RequiresCodeGenSCCOrder = true;
2329 // Exceptions and StackMaps are not supported, so these passes will never do
2330 // anything.
2331 // Garbage collection is not supported.
2332 disablePass<StackMapLivenessPass, FuncletLayoutPass, PatchableFunctionPass,
2334}
2335
2336void AMDGPUCodeGenPassBuilder::addIRPasses(PassManagerWrapper &PMW) const {
2337 if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN()) {
2338 flushFPMsToMPM(PMW);
2339 addModulePass(AMDGPURemoveIncompatibleFunctionsPass(TM), PMW);
2340 }
2341
2342 flushFPMsToMPM(PMW);
2343
2344 if (TM.getTargetTriple().isAMDGCN())
2345 addModulePass(AMDGPUPrintfRuntimeBindingPass(), PMW);
2346
2347 if (LowerCtorDtor)
2348 addModulePass(AMDGPUCtorDtorLoweringPass(), PMW);
2349
2350 if (isPassEnabled(EnableImageIntrinsicOptimizer))
2351 addFunctionPass(AMDGPUImageIntrinsicOptimizerPass(TM), PMW);
2352
2354 addFunctionPass(AMDGPUUniformIntrinsicCombinePass(), PMW);
2355 // This can be disabled by passing ::Disable here or on the command line
2356 // with --expand-variadics-override=disable.
2357 flushFPMsToMPM(PMW);
2359
2360 addModulePass(AMDGPUAlwaysInlinePass(), PMW);
2361 addModulePass(AlwaysInlinerPass(), PMW);
2362
2363 addModulePass(AMDGPUExportKernelRuntimeHandlesPass(), PMW);
2364
2366 addModulePass(AMDGPULowerExecSyncPass(), PMW);
2367
2368 if (EnableSwLowerLDS)
2369 addModulePass(AMDGPUSwLowerLDSPass(), PMW);
2370
2371 // Runs before PromoteAlloca so the latter can account for function uses
2373 addModulePass(AMDGPULowerModuleLDSPass(TM), PMW);
2374
2375 // Run atomic optimizer before Atomic Expand
2376 if (TM.getOptLevel() >= CodeGenOptLevel::Less &&
2378 addFunctionPass(
2380
2381 addFunctionPass(AtomicExpandPass(TM), PMW);
2382
2383 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2384 addFunctionPass(AMDGPUPromoteAllocaPass(TM), PMW);
2385 if (isPassEnabled(EnableScalarIRPasses))
2386 addStraightLineScalarOptimizationPasses(PMW);
2387
2388 // TODO: Handle EnableAMDGPUAliasAnalysis
2389
2390 // TODO: May want to move later or split into an early and late one.
2391 addFunctionPass(AMDGPUCodeGenPreparePass(TM), PMW);
2392
2393 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
2394 // have expanded.
2395 if (TM.getOptLevel() > CodeGenOptLevel::Less) {
2397 /*UseMemorySSA=*/true),
2398 PMW);
2399 }
2400 }
2401
2402 Base::addIRPasses(PMW);
2403
2404 // EarlyCSE is not always strong enough to clean up what LSR produces. For
2405 // example, GVN can combine
2406 //
2407 // %0 = add %a, %b
2408 // %1 = add %b, %a
2409 //
2410 // and
2411 //
2412 // %0 = shl nsw %a, 2
2413 // %1 = shl %a, 2
2414 //
2415 // but EarlyCSE can do neither of them.
2416 if (isPassEnabled(EnableScalarIRPasses))
2417 addEarlyCSEOrGVNPass(PMW);
2418}
2419
2420void AMDGPUCodeGenPassBuilder::addCodeGenPrepare(
2421 PassManagerWrapper &PMW) const {
2422 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2423 flushFPMsToMPM(PMW);
2424 addModulePass(AMDGPUPreloadKernelArgumentsPass(TM), PMW);
2425 }
2426
2428 addFunctionPass(AMDGPULowerKernelArgumentsPass(TM), PMW);
2429
2430 Base::addCodeGenPrepare(PMW);
2431
2432 if (isPassEnabled(EnableLoadStoreVectorizer))
2433 addFunctionPass(LoadStoreVectorizerPass(), PMW);
2434
2435 // This lowering has been placed after codegenprepare to take advantage of
2436 // address mode matching (which is why it isn't put with the LDS lowerings).
2437 // It could be placed anywhere before uniformity annotations (an analysis
2438 // that it changes by splitting up fat pointers into their components)
2439 // but has been put before switch lowering and CFG flattening so that those
2440 // passes can run on the more optimized control flow this pass creates in
2441 // many cases.
2442 flushFPMsToMPM(PMW);
2443 addModulePass(AMDGPULowerBufferFatPointersPass(TM), PMW);
2444 flushFPMsToMPM(PMW);
2445 requireCGSCCOrder(PMW);
2446
2447 addModulePass(AMDGPULowerIntrinsicsPass(TM), PMW);
2448
2449 // LowerSwitch pass may introduce unreachable blocks that can cause unexpected
2450 // behavior for subsequent passes. Placing it here seems better that these
2451 // blocks would get cleaned up by UnreachableBlockElim inserted next in the
2452 // pass flow.
2453 addFunctionPass(LowerSwitchPass(), PMW);
2454}
2455
2456void AMDGPUCodeGenPassBuilder::addPreISel(PassManagerWrapper &PMW) const {
2457
2458 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2459 addFunctionPass(FlattenCFGPass(), PMW);
2460 addFunctionPass(SinkingPass(), PMW);
2461 addFunctionPass(AMDGPULateCodeGenPreparePass(TM), PMW);
2462 }
2463
2464 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
2465 // regions formed by them.
2466
2467 addFunctionPass(AMDGPUUnifyDivergentExitNodesPass(), PMW);
2468 addFunctionPass(FixIrreduciblePass(), PMW);
2469 addFunctionPass(UnifyLoopExitsPass(), PMW);
2470 addFunctionPass(StructurizeCFGPass(/*SkipUniformRegions=*/false), PMW);
2471
2472 addFunctionPass(AMDGPUAnnotateUniformValuesPass(), PMW);
2473
2474 addFunctionPass(SIAnnotateControlFlowPass(TM), PMW);
2475
2476 // TODO: Move this right after structurizeCFG to avoid extra divergence
2477 // analysis. This depends on stopping SIAnnotateControlFlow from making
2478 // control flow modifications.
2479 addFunctionPass(AMDGPURewriteUndefForPHIPass(), PMW);
2480
2483 !isGlobalISelAbortEnabled())
2484 addFunctionPass(LCSSAPass(), PMW);
2485
2486 if (TM.getOptLevel() > CodeGenOptLevel::Less) {
2487 flushFPMsToMPM(PMW);
2488 addModulePass(AMDGPUPerfHintAnalysisPass(TM), PMW);
2489 }
2490}
2491
2492void AMDGPUCodeGenPassBuilder::addILPOpts(PassManagerWrapper &PMW) const {
2494 addMachineFunctionPass(EarlyIfConverterPass(), PMW);
2495
2496 Base::addILPOpts(PMW);
2497}
2498
2499void AMDGPUCodeGenPassBuilder::addAsmPrinterBegin(
2500 PassManagerWrapper &PMW) const {
2501 addModulePass(AMDGPUAsmPrinterBeginPass(), PMW,
2502 /*Force=*/true);
2503}
2504
2505void AMDGPUCodeGenPassBuilder::addAsmPrinter(PassManagerWrapper &PMW) const {
2506 addMachineFunctionPass(AMDGPUAsmPrinterPass(), PMW);
2507}
2508
2509void AMDGPUCodeGenPassBuilder::addAsmPrinterEnd(PassManagerWrapper &PMW) const {
2510 addModulePass(AMDGPUAsmPrinterEndPass(), PMW);
2511}
2512
2513Error AMDGPUCodeGenPassBuilder::addInstSelector(PassManagerWrapper &PMW) const {
2514 addMachineFunctionPass(AMDGPUISelDAGToDAGPass(TM), PMW);
2515 addMachineFunctionPass(SIFixSGPRCopiesPass(), PMW);
2516 addMachineFunctionPass(SILowerI1CopiesPass(), PMW);
2517 return Error::success();
2518}
2519
2520void AMDGPUCodeGenPassBuilder::addPreRewrite(PassManagerWrapper &PMW) const {
2521 if (EnableRegReassign) {
2522 addMachineFunctionPass(GCNNSAReassignPass(), PMW);
2523 }
2524
2525 addMachineFunctionPass(AMDGPURewriteAGPRCopyMFMAPass(), PMW);
2526}
2527
2528void AMDGPUCodeGenPassBuilder::addMachineSSAOptimization(
2529 PassManagerWrapper &PMW) const {
2530 Base::addMachineSSAOptimization(PMW);
2531
2532 addMachineFunctionPass(SIFoldOperandsPass(), PMW);
2533 if (EnableDPPCombine) {
2534 addMachineFunctionPass(GCNDPPCombinePass(), PMW);
2535 }
2536 addMachineFunctionPass(SILoadStoreOptimizerPass(), PMW);
2537 if (isPassEnabled(EnableSDWAPeephole)) {
2538 addMachineFunctionPass(SIPeepholeSDWAPass(), PMW);
2539 addMachineFunctionPass(EarlyMachineLICMPass(), PMW);
2540 addMachineFunctionPass(MachineCSEPass(), PMW);
2541 addMachineFunctionPass(SIFoldOperandsPass(), PMW);
2542 }
2543 addMachineFunctionPass(DeadMachineInstructionElimPass(), PMW);
2544 addMachineFunctionPass(SIShrinkInstructionsPass(), PMW);
2545}
2546
2547Error AMDGPUCodeGenPassBuilder::addFastRegAlloc(PassManagerWrapper &PMW) const {
2548 insertPass<PHIEliminationPass>(SILowerControlFlowPass());
2549
2550 insertPass<TwoAddressInstructionPass>(SIWholeQuadModePass());
2551
2552 return Base::addFastRegAlloc(PMW);
2553}
2554
2555Error AMDGPUCodeGenPassBuilder::addRegAssignAndRewriteFast(
2556 PassManagerWrapper &PMW) const {
2557 if (auto Err = validateRegAllocOptions())
2558 return Err;
2559
2560 addMachineFunctionPass(GCNPreRALongBranchRegPass(), PMW);
2561
2562 // SGPR allocation - default to fast at -O0.
2563 if (SGPRRegAllocNPM == RegAllocType::Greedy)
2564 addMachineFunctionPass(RAGreedyPass({onlyAllocateSGPRs, "sgpr"}), PMW);
2565 else
2566 addMachineFunctionPass(RegAllocFastPass({onlyAllocateSGPRs, "sgpr", false}),
2567 PMW);
2568
2569 // Equivalent of PEI for SGPRs.
2570 addMachineFunctionPass(SILowerSGPRSpillsPass(), PMW);
2571
2572 // To Allocate wwm registers used in whole quad mode operations (for shaders).
2573 addMachineFunctionPass(SIPreAllocateWWMRegsPass(), PMW);
2574
2575 // WWM allocation - default to fast at -O0.
2576 if (WWMRegAllocNPM == RegAllocType::Greedy)
2577 addMachineFunctionPass(RAGreedyPass({onlyAllocateWWMRegs, "wwm"}), PMW);
2578 else
2579 addMachineFunctionPass(
2580 RegAllocFastPass({onlyAllocateWWMRegs, "wwm", false}), PMW);
2581
2582 addMachineFunctionPass(SILowerWWMCopiesPass(), PMW);
2583 addMachineFunctionPass(AMDGPUReserveWWMRegsPass(), PMW);
2584
2585 // VGPR allocation - default to fast at -O0.
2586 if (VGPRRegAllocNPM == RegAllocType::Greedy)
2587 addMachineFunctionPass(RAGreedyPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2588 else
2589 addMachineFunctionPass(RegAllocFastPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2590
2591 return Error::success();
2592}
2593
2594Error AMDGPUCodeGenPassBuilder::addOptimizedRegAlloc(
2595 PassManagerWrapper &PMW) const {
2596 if (EnableDCEInRA)
2597 insertPass<DetectDeadLanesPass>(DeadMachineInstructionElimPass());
2598
2599 // FIXME: when an instruction has a Killed operand, and the instruction is
2600 // inside a bundle, seems only the BUNDLE instruction appears as the Kills of
2601 // the register in LiveVariables, this would trigger a failure in verifier,
2602 // we should fix it and enable the verifier.
2603 if (OptVGPRLiveRange)
2604 insertPass<RequireAnalysisPass<LiveVariablesAnalysis, MachineFunction>>(
2606
2607 // This must be run immediately after phi elimination and before
2608 // TwoAddressInstructions, otherwise the processing of the tied operand of
2609 // SI_ELSE will introduce a copy of the tied operand source after the else.
2610 insertPass<PHIEliminationPass>(SILowerControlFlowPass());
2611
2613 insertPass<RenameIndependentSubregsPass>(GCNRewritePartialRegUsesPass());
2614
2615 if (isPassEnabled(EnablePreRAOptimizations))
2616 insertPass<MachineSchedulerPass>(GCNPreRAOptimizationsPass());
2617
2618 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
2619 // instructions that cause scheduling barriers.
2620 insertPass<MachineSchedulerPass>(SIWholeQuadModePass());
2621
2622 if (OptExecMaskPreRA)
2623 insertPass<MachineSchedulerPass>(SIOptimizeExecMaskingPreRAPass());
2624
2625 // This is not an essential optimization and it has a noticeable impact on
2626 // compilation time, so we only enable it from O2.
2627 if (TM.getOptLevel() > CodeGenOptLevel::Less)
2628 insertPass<MachineSchedulerPass>(SIFormMemoryClausesPass());
2629
2630 return Base::addOptimizedRegAlloc(PMW);
2631}
2632
2633void AMDGPUCodeGenPassBuilder::addPreRegAlloc(PassManagerWrapper &PMW) const {
2634 if (getOptLevel() != CodeGenOptLevel::None)
2635 addMachineFunctionPass(AMDGPUPrepareAGPRAllocPass(), PMW);
2636}
2637
2638Expected<bool> AMDGPUCodeGenPassBuilder::addRegAssignAndRewriteOptimized(
2639 PassManagerWrapper &PMW) const {
2640 if (auto Err = validateRegAllocOptions())
2641 return Err;
2642
2643 addMachineFunctionPass(GCNPreRALongBranchRegPass(), PMW);
2644
2645 // SGPR allocation - default to greedy at -O1 and above.
2646 if (SGPRRegAllocNPM == RegAllocType::Fast)
2647 addMachineFunctionPass(RegAllocFastPass({onlyAllocateSGPRs, "sgpr", false}),
2648 PMW);
2649 else
2650 addMachineFunctionPass(RAGreedyPass({onlyAllocateSGPRs, "sgpr"}), PMW);
2651
2652 // Commit allocated register changes. This is mostly necessary because too
2653 // many things rely on the use lists of the physical registers, such as the
2654 // verifier. This is only necessary with allocators which use LiveIntervals,
2655 // since FastRegAlloc does the replacements itself.
2656 addMachineFunctionPass(VirtRegRewriterPass(false), PMW);
2657
2658 // At this point, the sgpr-regalloc has been done and it is good to have the
2659 // stack slot coloring to try to optimize the SGPR spill stack indices before
2660 // attempting the custom SGPR spill lowering.
2661 addMachineFunctionPass(StackSlotColoringPass(), PMW);
2662
2663 // Equivalent of PEI for SGPRs.
2664 addMachineFunctionPass(SILowerSGPRSpillsPass(), PMW);
2665
2666 // To Allocate wwm registers used in whole quad mode operations (for shaders).
2667 addMachineFunctionPass(SIPreAllocateWWMRegsPass(), PMW);
2668
2669 // WWM allocation - default to greedy at -O1 and above.
2670 if (WWMRegAllocNPM == RegAllocType::Fast)
2671 addMachineFunctionPass(
2672 RegAllocFastPass({onlyAllocateWWMRegs, "wwm", false}), PMW);
2673 else
2674 addMachineFunctionPass(RAGreedyPass({onlyAllocateWWMRegs, "wwm"}), PMW);
2675 addMachineFunctionPass(SILowerWWMCopiesPass(), PMW);
2676 addMachineFunctionPass(VirtRegRewriterPass(false), PMW);
2677 addMachineFunctionPass(AMDGPUReserveWWMRegsPass(), PMW);
2678
2679 // VGPR allocation - default to greedy at -O1 and above.
2680 if (VGPRRegAllocNPM == RegAllocType::Fast)
2681 addMachineFunctionPass(RegAllocFastPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2682 else
2683 addMachineFunctionPass(RAGreedyPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2684
2685 addPreRewrite(PMW);
2686 addMachineFunctionPass(VirtRegRewriterPass(true), PMW);
2687
2688 addMachineFunctionPass(AMDGPUMarkLastScratchLoadPass(), PMW);
2689 return true;
2690}
2691
2692void AMDGPUCodeGenPassBuilder::addPostRegAlloc(PassManagerWrapper &PMW) const {
2693 addMachineFunctionPass(SIFixVGPRCopiesPass(), PMW);
2694 if (TM.getOptLevel() > CodeGenOptLevel::None)
2695 addMachineFunctionPass(SIOptimizeExecMaskingPass(), PMW);
2696 Base::addPostRegAlloc(PMW);
2697}
2698
2699void AMDGPUCodeGenPassBuilder::addPreSched2(PassManagerWrapper &PMW) const {
2700 if (TM.getOptLevel() > CodeGenOptLevel::None)
2701 addMachineFunctionPass(SIShrinkInstructionsPass(), PMW);
2702 addMachineFunctionPass(SIPostRABundlerPass(), PMW);
2703}
2704
2705void AMDGPUCodeGenPassBuilder::addPostBBSections(
2706 PassManagerWrapper &PMW) const {
2707 // We run this later to avoid passes like livedebugvalues and BBSections
2708 // having to deal with the apparent multi-entry functions we may generate.
2709 addMachineFunctionPass(AMDGPUPreloadKernArgPrologPass(), PMW);
2710}
2711
2712void AMDGPUCodeGenPassBuilder::addPreEmitPass(PassManagerWrapper &PMW) const {
2713 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less)) {
2714 addMachineFunctionPass(GCNCreateVOPDPass(), PMW);
2715 }
2716
2717 addMachineFunctionPass(SIMemoryLegalizerPass(), PMW);
2718 addMachineFunctionPass(SIInsertWaitcntsPass(), PMW);
2719
2720 addMachineFunctionPass(SIModeRegisterPass(), PMW);
2721
2722 if (TM.getOptLevel() > CodeGenOptLevel::None)
2723 addMachineFunctionPass(SIInsertHardClausesPass(), PMW);
2724
2725 addMachineFunctionPass(SILateBranchLoweringPass(), PMW);
2726
2727 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
2728 addMachineFunctionPass(AMDGPUSetWavePriorityPass(), PMW);
2729
2730 if (TM.getOptLevel() > CodeGenOptLevel::None)
2731 addMachineFunctionPass(SIPreEmitPeepholePass(), PMW);
2732
2733 // The hazard recognizer that runs as part of the post-ra scheduler does not
2734 // guarantee to be able handle all hazards correctly. This is because if there
2735 // are multiple scheduling regions in a basic block, the regions are scheduled
2736 // bottom up, so when we begin to schedule a region we don't know what
2737 // instructions were emitted directly before it.
2738 //
2739 // Here we add a stand-alone hazard recognizer pass which can handle all
2740 // cases.
2741 addMachineFunctionPass(PostRAHazardRecognizerPass(), PMW);
2742 addMachineFunctionPass(AMDGPUWaitSGPRHazardsPass(), PMW);
2743 addMachineFunctionPass(AMDGPULowerVGPREncodingPass(), PMW);
2744
2745 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less)) {
2746 addMachineFunctionPass(AMDGPUInsertDelayAluPass(), PMW);
2747 }
2748
2749 addMachineFunctionPass(BranchRelaxationPass(), PMW);
2750}
2751
2752bool AMDGPUCodeGenPassBuilder::isPassEnabled(const cl::opt<bool> &Opt,
2753 CodeGenOptLevel Level) const {
2754 if (Opt.getNumOccurrences())
2755 return Opt;
2756 if (TM.getOptLevel() < Level)
2757 return false;
2758 return Opt;
2759}
2760
2761void AMDGPUCodeGenPassBuilder::addEarlyCSEOrGVNPass(
2762 PassManagerWrapper &PMW) const {
2763 if (TM.getOptLevel() == CodeGenOptLevel::Aggressive)
2764 addFunctionPass(GVNPass(), PMW);
2765 else
2766 addFunctionPass(EarlyCSEPass(), PMW);
2767}
2768
2769void AMDGPUCodeGenPassBuilder::addStraightLineScalarOptimizationPasses(
2770 PassManagerWrapper &PMW) const {
2772 addFunctionPass(LoopDataPrefetchPass(), PMW);
2773
2774 addFunctionPass(SeparateConstOffsetFromGEPPass(), PMW);
2775
2776 // ReassociateGEPs exposes more opportunities for SLSR. See
2777 // the example in reassociate-geps-and-slsr.ll.
2778 addFunctionPass(StraightLineStrengthReducePass(), PMW);
2779
2780 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
2781 // EarlyCSE can reuse.
2782 addEarlyCSEOrGVNPass(PMW);
2783
2784 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
2785 addFunctionPass(NaryReassociatePass(), PMW);
2786
2787 // NaryReassociate on GEPs creates redundant common expressions, so run
2788 // EarlyCSE after it.
2789 addFunctionPass(EarlyCSEPass(), PMW);
2790}
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< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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:323
#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)
bool isFlatGlobalAddrSpace(unsigned AS)
LLVM_READNONE constexpr bool isModuleEntryFunctionCC(CallingConv::ID CC)
GPUKind
GPU kinds supported by the AMDGPU target.
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)
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:544
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 &)
char & SIFoldOperandsLegacyID
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:273
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:178
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:149
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 &)
LLVM_ABI ImmutablePass * createExternalAAWrapperPass(std::function< void(Pass &, Function &, AAResults &)> Callback, bool RunEarly=false)
A wrapper pass around a callback which can be used to populate the AAResults in the AAResultsWrapperP...
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:4065
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
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
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.