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"
93#include "llvm/CodeGen/Passes.h"
104#include "llvm/IR/IntrinsicsAMDGPU.h"
105#include "llvm/IR/Module.h"
106#include "llvm/IR/PassManager.h"
107#include "llvm/IR/PatternMatch.h"
116#include "llvm/Transforms/IPO.h"
141#include <optional>
142
143using namespace llvm;
144using namespace llvm::PatternMatch;
145
146namespace {
147//===----------------------------------------------------------------------===//
148// AMDGPU CodeGen Pass Builder interface.
149//===----------------------------------------------------------------------===//
150
151class AMDGPUCodeGenPassBuilder : public CodeGenPassBuilder {
152 using Base = CodeGenPassBuilder;
153
154 GCNTargetMachine &getTM() const {
155 return static_cast<GCNTargetMachine &>(TM);
156 }
157
158public:
159 AMDGPUCodeGenPassBuilder(GCNTargetMachine &TM,
160 const CGPassBuilderOption &Opts,
161 PassInstrumentationCallbacks *PIC);
162
163 void addIRPasses(PassManagerWrapper &PMW) override;
164 void addCodeGenPrepare(PassManagerWrapper &PMW) override;
165 void addPreISel(PassManagerWrapper &PMW) override;
166 void addILPOpts(PassManagerWrapper &PMW) override;
167 void addAsmPrinterBegin(PassManagerWrapper &PMW) override;
168 void addAsmPrinter(PassManagerWrapper &PMW) override;
169 void addAsmPrinterEnd(PassManagerWrapper &PMW) override;
170 Error addInstSelector(PassManagerWrapper &PMW) override;
171 Error addIRTranslator(PassManagerWrapper &PMW) override;
172 void addPreLegalizeMachineIR(PassManagerWrapper &PMW) override;
173 Error addLegalizeMachineIR(PassManagerWrapper &PMW) override;
174 void addPreRegBankSelect(PassManagerWrapper &PMW) override;
175 Error addRegBankSelect(PassManagerWrapper &PMW) override;
176 void addPreGlobalInstructionSelect(PassManagerWrapper &PMW) override;
177 Error addGlobalInstructionSelect(PassManagerWrapper &PMW) override;
178 void addPreRewrite(PassManagerWrapper &PMW) override;
179 void addMachineSSAOptimization(PassManagerWrapper &PMW) override;
180 void addPostRegAlloc(PassManagerWrapper &PMW) override;
181 void addPreEmitPass(PassManagerWrapper &PMW) override;
182 Error addRegAssignAndRewriteFast(PassManagerWrapper &PMW) override;
183 Expected<bool>
184 addRegAssignAndRewriteOptimized(PassManagerWrapper &PMW) override;
185 void addPreRegAlloc(PassManagerWrapper &PMW) override;
186 Error addFastRegAlloc(PassManagerWrapper &PMW) override;
187 Error addOptimizedRegAlloc(PassManagerWrapper &PMW) override;
188 void addPreSched2(PassManagerWrapper &PMW) override;
189 void addPostBBSections(PassManagerWrapper &PMW) override;
190
191private:
192 Error validateRegAllocOptions() const;
193
194public:
195 /// Check if a pass is enabled given \p Opt option. The option always
196 /// overrides defaults if explicitly used. Otherwise its default will be used
197 /// given that a pass shall work at an optimization \p Level minimum.
198 bool isPassEnabled(const cl::opt<bool> &Opt,
199 CodeGenOptLevel Level = CodeGenOptLevel::Default) const;
200 void addEarlyCSEOrGVNPass(PassManagerWrapper &PMW);
201 void addStraightLineScalarOptimizationPasses(PassManagerWrapper &PMW);
202};
203
204class SGPRRegisterRegAlloc : public RegisterRegAllocBase<SGPRRegisterRegAlloc> {
205public:
206 SGPRRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
207 : RegisterRegAllocBase(N, D, C) {}
208};
209
210class VGPRRegisterRegAlloc : public RegisterRegAllocBase<VGPRRegisterRegAlloc> {
211public:
212 VGPRRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
213 : RegisterRegAllocBase(N, D, C) {}
214};
215
216class WWMRegisterRegAlloc : public RegisterRegAllocBase<WWMRegisterRegAlloc> {
217public:
218 WWMRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
219 : RegisterRegAllocBase(N, D, C) {}
220};
221
222static bool onlyAllocateSGPRs(const TargetRegisterInfo &TRI,
223 const MachineRegisterInfo &MRI,
224 const Register Reg) {
225 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
226 return static_cast<const SIRegisterInfo &>(TRI).isSGPRClass(RC);
227}
228
229static bool onlyAllocateVGPRs(const TargetRegisterInfo &TRI,
230 const MachineRegisterInfo &MRI,
231 const Register Reg) {
232 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
233 return !static_cast<const SIRegisterInfo &>(TRI).isSGPRClass(RC);
234}
235
236static bool onlyAllocateWWMRegs(const TargetRegisterInfo &TRI,
237 const MachineRegisterInfo &MRI,
238 const Register Reg) {
239 const SIMachineFunctionInfo *MFI =
241 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
242 return !static_cast<const SIRegisterInfo &>(TRI).isSGPRClass(RC) &&
244}
245
246/// -{sgpr|wwm|vgpr}-regalloc=... command line option.
247static FunctionPass *useDefaultRegisterAllocator() { return nullptr; }
248
249/// A dummy default pass factory indicates whether the register allocator is
250/// overridden on the command line.
251static llvm::once_flag InitializeDefaultSGPRRegisterAllocatorFlag;
252static llvm::once_flag InitializeDefaultVGPRRegisterAllocatorFlag;
253static llvm::once_flag InitializeDefaultWWMRegisterAllocatorFlag;
254
255static SGPRRegisterRegAlloc
256defaultSGPRRegAlloc("default",
257 "pick SGPR register allocator based on -O option",
259
260static cl::opt<SGPRRegisterRegAlloc::FunctionPassCtor, false,
262SGPRRegAlloc("sgpr-regalloc", cl::Hidden, cl::init(&useDefaultRegisterAllocator),
263 cl::desc("Register allocator to use for SGPRs"));
264
265static cl::opt<VGPRRegisterRegAlloc::FunctionPassCtor, false,
267VGPRRegAlloc("vgpr-regalloc", cl::Hidden, cl::init(&useDefaultRegisterAllocator),
268 cl::desc("Register allocator to use for VGPRs"));
269
270static cl::opt<WWMRegisterRegAlloc::FunctionPassCtor, false,
272 WWMRegAlloc("wwm-regalloc", cl::Hidden,
274 cl::desc("Register allocator to use for WWM registers"));
275
276// New pass manager register allocator options for AMDGPU
278 "sgpr-regalloc-npm", cl::Hidden, cl::init(RegAllocType::Default),
279 cl::desc("Register allocator for SGPRs (new pass manager)"));
280
282 "vgpr-regalloc-npm", cl::Hidden, cl::init(RegAllocType::Default),
283 cl::desc("Register allocator for VGPRs (new pass manager)"));
284
286 "wwm-regalloc-npm", cl::Hidden, cl::init(RegAllocType::Default),
287 cl::desc("Register allocator for WWM registers (new pass manager)"));
288
289/// Check if the given RegAllocType is supported for AMDGPU NPM register
290/// allocation. Only Fast and Greedy are supported; Basic and PBQP are not.
291static Error checkRegAllocSupported(RegAllocType RAType, StringRef RegName) {
292 if (RAType == RegAllocType::Basic || RAType == RegAllocType::PBQP) {
294 Twine("unsupported register allocator '") +
295 (RAType == RegAllocType::Basic ? "basic" : "pbqp") + "' for " +
296 RegName + " registers",
298 }
299 return Error::success();
300}
301
302Error AMDGPUCodeGenPassBuilder::validateRegAllocOptions() const {
303 // 1. Generic --regalloc-npm is not supported for AMDGPU.
304 if (Opt.RegAlloc != RegAllocType::Unset) {
306 "-regalloc-npm not supported for amdgcn. Use -sgpr-regalloc-npm, "
307 "-vgpr-regalloc-npm, and -wwm-regalloc-npm",
309 }
310
311 // 2. Legacy PM regalloc options are not compatible with NPM.
312 if (SGPRRegAlloc.getNumOccurrences() > 0 ||
313 VGPRRegAlloc.getNumOccurrences() > 0 ||
314 WWMRegAlloc.getNumOccurrences() > 0) {
316 "-sgpr-regalloc, -vgpr-regalloc, and -wwm-regalloc are legacy PM "
317 "options. Use -sgpr-regalloc-npm, -vgpr-regalloc-npm, and "
318 "-wwm-regalloc-npm with the new pass manager",
320 }
321
322 // 3. Only Fast and Greedy allocators are supported for AMDGPU.
323 if (auto Err = checkRegAllocSupported(SGPRRegAllocNPM, "SGPR"))
324 return Err;
325 if (auto Err = checkRegAllocSupported(WWMRegAllocNPM, "WWM"))
326 return Err;
327 if (auto Err = checkRegAllocSupported(VGPRRegAllocNPM, "VGPR"))
328 return Err;
329
330 return Error::success();
331}
332
333static void initializeDefaultSGPRRegisterAllocatorOnce() {
334 RegisterRegAlloc::FunctionPassCtor Ctor = SGPRRegisterRegAlloc::getDefault();
335
336 if (!Ctor) {
337 Ctor = SGPRRegAlloc;
338 SGPRRegisterRegAlloc::setDefault(SGPRRegAlloc);
339 }
340}
341
342static void initializeDefaultVGPRRegisterAllocatorOnce() {
343 RegisterRegAlloc::FunctionPassCtor Ctor = VGPRRegisterRegAlloc::getDefault();
344
345 if (!Ctor) {
346 Ctor = VGPRRegAlloc;
347 VGPRRegisterRegAlloc::setDefault(VGPRRegAlloc);
348 }
349}
350
351static void initializeDefaultWWMRegisterAllocatorOnce() {
352 RegisterRegAlloc::FunctionPassCtor Ctor = WWMRegisterRegAlloc::getDefault();
353
354 if (!Ctor) {
355 Ctor = WWMRegAlloc;
356 WWMRegisterRegAlloc::setDefault(WWMRegAlloc);
357 }
358}
359
360static FunctionPass *createBasicSGPRRegisterAllocator() {
361 return createBasicRegisterAllocator(onlyAllocateSGPRs);
362}
363
364static FunctionPass *createGreedySGPRRegisterAllocator() {
365 return createGreedyRegisterAllocator(onlyAllocateSGPRs);
366}
367
368static FunctionPass *createFastSGPRRegisterAllocator() {
369 return createFastRegisterAllocator(onlyAllocateSGPRs, false);
370}
371
372static FunctionPass *createBasicVGPRRegisterAllocator() {
373 return createBasicRegisterAllocator(onlyAllocateVGPRs);
374}
375
376static FunctionPass *createGreedyVGPRRegisterAllocator() {
377 return createGreedyRegisterAllocator(onlyAllocateVGPRs);
378}
379
380static FunctionPass *createFastVGPRRegisterAllocator() {
381 return createFastRegisterAllocator(onlyAllocateVGPRs, true);
382}
383
384static FunctionPass *createBasicWWMRegisterAllocator() {
385 return createBasicRegisterAllocator(onlyAllocateWWMRegs);
386}
387
388static FunctionPass *createGreedyWWMRegisterAllocator() {
389 return createGreedyRegisterAllocator(onlyAllocateWWMRegs);
390}
391
392static FunctionPass *createFastWWMRegisterAllocator() {
393 return createFastRegisterAllocator(onlyAllocateWWMRegs, false);
394}
395
396static SGPRRegisterRegAlloc basicRegAllocSGPR(
397 "basic", "basic register allocator", createBasicSGPRRegisterAllocator);
398static SGPRRegisterRegAlloc greedyRegAllocSGPR(
399 "greedy", "greedy register allocator", createGreedySGPRRegisterAllocator);
400
401static SGPRRegisterRegAlloc fastRegAllocSGPR(
402 "fast", "fast register allocator", createFastSGPRRegisterAllocator);
403
404
405static VGPRRegisterRegAlloc basicRegAllocVGPR(
406 "basic", "basic register allocator", createBasicVGPRRegisterAllocator);
407static VGPRRegisterRegAlloc greedyRegAllocVGPR(
408 "greedy", "greedy register allocator", createGreedyVGPRRegisterAllocator);
409
410static VGPRRegisterRegAlloc fastRegAllocVGPR(
411 "fast", "fast register allocator", createFastVGPRRegisterAllocator);
412static WWMRegisterRegAlloc basicRegAllocWWMReg("basic",
413 "basic register allocator",
414 createBasicWWMRegisterAllocator);
415static WWMRegisterRegAlloc
416 greedyRegAllocWWMReg("greedy", "greedy register allocator",
417 createGreedyWWMRegisterAllocator);
418static WWMRegisterRegAlloc fastRegAllocWWMReg("fast", "fast register allocator",
419 createFastWWMRegisterAllocator);
420
422 return Phase == ThinOrFullLTOPhase::FullLTOPreLink ||
423 Phase == ThinOrFullLTOPhase::ThinLTOPreLink;
424}
425} // anonymous namespace
426
427static cl::opt<bool>
429 cl::desc("Run early if-conversion"),
430 cl::init(false));
431
432static cl::opt<bool>
433OptExecMaskPreRA("amdgpu-opt-exec-mask-pre-ra", cl::Hidden,
434 cl::desc("Run pre-RA exec mask optimizations"),
435 cl::init(true));
436
437static cl::opt<bool>
438 LowerCtorDtor("amdgpu-lower-global-ctor-dtor",
439 cl::desc("Lower GPU ctor / dtors to globals on the device."),
440 cl::init(true), cl::Hidden);
441
442// Option to disable vectorizer for tests.
444 "amdgpu-load-store-vectorizer",
445 cl::desc("Enable load store vectorizer"),
446 cl::init(true),
447 cl::Hidden);
448
449// Option to control global loads scalarization
451 "amdgpu-scalarize-global-loads",
452 cl::desc("Enable global load scalarization"),
453 cl::init(true),
454 cl::Hidden);
455
456// Option to run internalize pass.
458 "amdgpu-internalize-symbols",
459 cl::desc("Enable elimination of non-kernel functions and unused globals"),
460 cl::init(false),
461 cl::Hidden);
462
463// Option to inline all early.
465 "amdgpu-early-inline-all",
466 cl::desc("Inline all functions early"),
467 cl::init(false),
468 cl::Hidden);
469
471 "amdgpu-enable-remove-incompatible-functions", cl::Hidden,
472 cl::desc("Enable removal of functions when they"
473 "use features not supported by the target GPU"),
474 cl::init(true));
475
477 "amdgpu-sdwa-peephole",
478 cl::desc("Enable SDWA peepholer"),
479 cl::init(true));
480
482 "amdgpu-dpp-combine",
483 cl::desc("Enable DPP combiner"),
484 cl::init(true));
485
486// Enable address space based alias analysis
488 cl::desc("Enable AMDGPU Alias Analysis"),
489 cl::init(true));
490
491static cl::opt<bool>
492 XnackSetting("amdgpu-xnack",
493 cl::desc("Force amdgpu.xnack value for testing"),
495
496static cl::opt<bool>
497 SramEccSetting("amdgpu-sramecc",
498 cl::desc("Force amdgpu.sramecc for testing"),
500
501// Enable lib calls simplifications
503 "amdgpu-simplify-libcall",
504 cl::desc("Enable amdgpu library simplifications"),
505 cl::init(true),
506 cl::Hidden);
507
509 "amdgpu-ir-lower-kernel-arguments",
510 cl::desc("Lower kernel argument loads in IR pass"),
511 cl::init(true),
512 cl::Hidden);
513
515 "amdgpu-reassign-regs",
516 cl::desc("Enable register reassign optimizations on gfx10+"),
517 cl::init(true),
518 cl::Hidden);
519
521 "amdgpu-opt-vgpr-liverange",
522 cl::desc("Enable VGPR liverange optimizations for if-else structure"),
523 cl::init(true), cl::Hidden);
524
526 "amdgpu-atomic-optimizer-strategy",
527 cl::desc("Select DPP or Iterative strategy for scan"),
530 clEnumValN(ScanOptions::DPP, "DPP", "Use DPP operations for scan"),
532 "Use Iterative approach for scan"),
533 clEnumValN(ScanOptions::None, "None", "Disable atomic optimizer")));
534
535// Enable Mode register optimization
537 "amdgpu-mode-register",
538 cl::desc("Enable mode register pass"),
539 cl::init(true),
540 cl::Hidden);
541
542// Enable GFX11+ s_delay_alu insertion
543static cl::opt<bool>
544 EnableInsertDelayAlu("amdgpu-enable-delay-alu",
545 cl::desc("Enable s_delay_alu insertion"),
546 cl::init(true), cl::Hidden);
547
548// Enable GFX11+ VOPD
549static cl::opt<bool>
550 EnableVOPD("amdgpu-enable-vopd",
551 cl::desc("Enable VOPD, dual issue of VALU in wave32"),
552 cl::init(true), cl::Hidden);
553
554// Option is used in lit tests to prevent deadcoding of patterns inspected.
555static cl::opt<bool>
556EnableDCEInRA("amdgpu-dce-in-ra",
557 cl::init(true), cl::Hidden,
558 cl::desc("Enable machine DCE inside regalloc"));
559
560static cl::opt<bool> EnableSetWavePriority("amdgpu-set-wave-priority",
561 cl::desc("Adjust wave priority"),
562 cl::init(false), cl::Hidden);
563
565 "amdgpu-scalar-ir-passes",
566 cl::desc("Enable scalar IR passes"),
567 cl::init(true),
568 cl::Hidden);
569
571 "amdgpu-enable-lower-exec-sync",
572 cl::desc("Enable lowering of execution synchronization."), cl::init(true),
573 cl::Hidden);
574
575static cl::opt<bool>
576 EnableSwLowerLDS("amdgpu-enable-sw-lower-lds",
577 cl::desc("Enable lowering of lds to global memory pass "
578 "and asan instrument resulting IR."),
579 cl::init(true), cl::Hidden);
580
582 "amdgpu-enable-object-linking",
583 cl::desc("Enable object linking for cross-TU LDS and ABI support"),
585 cl::Hidden);
586
588 "amdgpu-enable-lower-module-lds", cl::desc("Enable lower module lds pass"),
590 cl::Hidden);
591
593 "amdgpu-enable-pre-ra-optimizations",
594 cl::desc("Enable Pre-RA optimizations pass"), cl::init(true),
595 cl::Hidden);
596
598 "amdgpu-enable-promote-kernel-arguments",
599 cl::desc("Enable promotion of flat kernel pointer arguments to global"),
600 cl::Hidden, cl::init(true));
601
603 "amdgpu-enable-image-intrinsic-optimizer",
604 cl::desc("Enable image intrinsic optimizer pass"), cl::init(true),
605 cl::Hidden);
606
607static cl::opt<bool>
608 EnableLoopPrefetch("amdgpu-loop-prefetch",
609 cl::desc("Enable loop data prefetch on AMDGPU"),
610 cl::Hidden, cl::init(false));
611
613 AMDGPUSchedStrategy("amdgpu-sched-strategy",
614 cl::desc("Select custom AMDGPU scheduling strategy."),
615 cl::Hidden, cl::init(""));
616
617// Scheduler selection is consulted both when creating the scheduler and from
618// overrideSchedPolicy(), so keep the attribute and global command line handling
619// in one helper.
621 Attribute SchedStrategyAttr = F.getFnAttribute("amdgpu-sched-strategy");
622 if (SchedStrategyAttr.isValid())
623 return SchedStrategyAttr.getValueAsString();
624
625 if (!AMDGPUSchedStrategy.empty())
626 return AMDGPUSchedStrategy;
627
628 return "";
629}
630
631static void
633 const GCNSubtarget &ST) {
634 if (ST.hasGFX1250Insts() || ST.hasGFX950Insts())
635 return;
636
637 F.getContext().diagnose(DiagnosticInfoUnsupported(
638 F,
639 "'amdgpu-sched-strategy'='coexec' is only supported for gfx1250/gfx950",
641}
642
643static bool useNoopPostScheduler(const Function &F) {
644 Attribute PostSchedStrategyAttr =
645 F.getFnAttribute("amdgpu-post-sched-strategy");
646 return PostSchedStrategyAttr.isValid() &&
647 PostSchedStrategyAttr.getValueAsString() == "nop";
648}
649
651 "amdgpu-enable-rewrite-partial-reg-uses",
652 cl::desc("Enable rewrite partial reg uses pass"), cl::init(true),
653 cl::Hidden);
654
656 "amdgpu-enable-hipstdpar",
657 cl::desc("Enable HIP Standard Parallelism Offload support"), cl::init(false),
658 cl::Hidden);
659
660static cl::opt<bool>
661 EnableAMDGPUAttributor("amdgpu-attributor-enable",
662 cl::desc("Enable AMDGPUAttributorPass"),
663 cl::init(true), cl::Hidden);
664
666 "amdgpu-link-time-closed-world",
667 cl::desc("Whether has closed-world assumption at link time"),
668 cl::init(false), cl::Hidden);
669
671 "amdgpu-enable-uniform-intrinsic-combine",
672 cl::desc("Enable/Disable the Uniform Intrinsic Combine Pass"),
673 cl::init(true), cl::Hidden);
674
675static cl::opt<bool>
676 EnableMachinePipeliner("amdgpu-enable-pipeliner",
677 cl::desc("Enable Machine Pipeliner for AMDGCN"),
678 cl::init(false), cl::Hidden);
679
681 // Register the target
685
772}
773
774static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
775 return std::make_unique<AMDGPUTargetObjectFile>();
776}
777
781
782static ScheduleDAGInstrs *
784 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
785 ScheduleDAGMILive *DAG =
786 new GCNScheduleDAGMILive(C, std::make_unique<GCNMaxOccupancySchedStrategy>(C));
787 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
788 if (ST.shouldClusterStores())
789 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
791 DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
792 DAG->addMutation(createAMDGPUExportClusteringDAGMutation());
793 DAG->addMutation(createAMDGPUBarrierLatencyDAGMutation(C->MF));
794 DAG->addMutation(createAMDGPUHazardLatencyDAGMutation(C->MF));
795 return DAG;
796}
797
798static ScheduleDAGInstrs *
800 ScheduleDAGMILive *DAG =
801 new GCNScheduleDAGMILive(C, std::make_unique<GCNMaxILPSchedStrategy>(C));
803 return DAG;
804}
805
806static ScheduleDAGInstrs *
808 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
810 C, std::make_unique<GCNMaxMemoryClauseSchedStrategy>(C));
811 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
812 if (ST.shouldClusterStores())
813 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
814 DAG->addMutation(createAMDGPUExportClusteringDAGMutation());
815 DAG->addMutation(createAMDGPUBarrierLatencyDAGMutation(C->MF));
816 DAG->addMutation(createAMDGPUHazardLatencyDAGMutation(C->MF));
817 return DAG;
818}
819
820static ScheduleDAGInstrs *
822 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
823 auto *DAG = new GCNIterativeScheduler(
825 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
826 if (ST.shouldClusterStores())
827 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
829 return DAG;
830}
831
838
839static ScheduleDAGInstrs *
841 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
843 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
844 if (ST.shouldClusterStores())
845 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
846 DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
848 return DAG;
849}
850
851static MachineSchedRegistry
852SISchedRegistry("si", "Run SI's custom scheduler",
854
857 "Run GCN scheduler to maximize occupancy",
859
861 GCNMaxILPSchedRegistry("gcn-max-ilp", "Run GCN scheduler to maximize ilp",
863
865 "gcn-max-memory-clause", "Run GCN scheduler to maximize memory clause",
867
869 "gcn-iterative-max-occupancy-experimental",
870 "Run GCN scheduler to maximize occupancy (experimental)",
872
874 "gcn-iterative-minreg",
875 "Run GCN iterative scheduler for minimal register usage (experimental)",
877
879 "gcn-iterative-ilp",
880 "Run GCN iterative scheduler for ILP scheduling (experimental)",
882
885 if (!GPU.empty())
886 return GPU;
887
888 if (StringRef Name = AMDGPU::getArchNameFromSubArch(TT.getSubArch());
889 !Name.empty())
890 return Name;
891
892 // Need to default to a target with flat support for HSA.
893 if (TT.isAMDGCN())
894 return TT.getOS() == Triple::AMDHSA ? "generic-hsa" : "generic";
895
896 return "r600";
897}
898
900 // The AMDGPU toolchain only supports generating shared objects, so we
901 // must always use PIC.
902 return Reloc::PIC_;
903}
904
906 StringRef CPU, StringRef FS,
907 const TargetOptions &Options,
908 std::optional<Reloc::Model> RM,
909 std::optional<CodeModel::Model> CM,
914 OptLevel),
916 initAsmInfo();
917 if (TT.isAMDGCN()) {
918 // Triple is missing a representation for non-empty, but unrecognized
919 // subarches. Only permit no subarch for any subtarget if it was really
920 // empty.
921 bool IsUnknownSubArch =
922 TT.getSubArch() == Triple::NoSubArch && TT.getArchName().size() != 6;
923 if (IsUnknownSubArch)
924 reportFatalUsageError("unknown subarch " + TT.getArchName());
925
926 if (TT.getSubArch() != Triple::NoSubArch) {
928 Triple::SubArchType GPUSubArch = AMDGPU::getSubArch(Kind);
929 if (Kind != AMDGPU::GK_NONE && GPUSubArch != TT.getSubArch() &&
930 TT.getSubArch() != AMDGPU::getMajorSubArch(GPUSubArch)) {
931 reportFatalUsageError("invalid cpu '" + CPU + "' for subarch " +
932 TT.getArchName());
933 }
934 }
935
936 if (getMCSubtargetInfo().checkFeatures("+wavefrontsize64"))
938 else if (getMCSubtargetInfo().checkFeatures("+wavefrontsize32"))
940 }
942}
943
947
949
951 Attribute GPUAttr = F.getFnAttribute("target-cpu");
952 return GPUAttr.isValid() ? GPUAttr.getValueAsString() : getTargetCPU();
953}
954
956 Attribute FSAttr = F.getFnAttribute("target-features");
957
958 return FSAttr.isValid() ? FSAttr.getValueAsString()
960}
961
964 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
966 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
967 if (ST.shouldClusterStores())
968 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
969 return DAG;
970}
971
972/// Predicate for Internalize pass.
973static bool mustPreserveGV(const GlobalValue &GV) {
974 if (const Function *F = dyn_cast<Function>(&GV))
975 return F->isDeclaration() || F->getName().starts_with("__asan_") ||
976 F->getName().starts_with("__sanitizer_") ||
977 AMDGPU::isEntryFunctionCC(F->getCallingConv());
978
980 return !GV.use_empty();
981}
982
987
990 if (Params.empty())
992 Params.consume_front("strategy=");
993 auto Result = StringSwitch<std::optional<ScanOptions>>(Params)
994 .Case("dpp", ScanOptions::DPP)
995 .Cases({"iterative", ""}, ScanOptions::Iterative)
996 .Case("none", ScanOptions::None)
997 .Default(std::nullopt);
998 if (Result)
999 return *Result;
1000 return make_error<StringError>("invalid parameter", inconvertibleErrorCode());
1001}
1002
1006 while (!Params.empty()) {
1007 StringRef ParamName;
1008 std::tie(ParamName, Params) = Params.split(';');
1009 if (ParamName == "closed-world") {
1010 Result.IsClosedWorld = true;
1011 } else {
1013 formatv("invalid AMDGPUAttributor pass parameter '{0}' ", ParamName)
1014 .str(),
1016 }
1017 }
1018 return Result;
1019}
1020
1022
1023#define GET_PASS_REGISTRY "AMDGPUPassRegistry.def"
1025
1026 PB.registerPipelineParsingCallback(
1027 [this](StringRef Name, CGSCCPassManager &PM,
1029 if (Name == "amdgpu-attributor-cgscc" && getTargetTriple().isAMDGCN()) {
1031 *static_cast<GCNTargetMachine *>(this)));
1032 return true;
1033 }
1034 return false;
1035 });
1036
1037 PB.registerScalarOptimizerLateEPCallback(
1038 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1039 if (Level == OptimizationLevel::O0)
1040 return;
1041
1043 });
1044
1045 PB.registerVectorizerEndEPCallback(
1046 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1047 if (Level == OptimizationLevel::O0)
1048 return;
1049
1051 });
1052
1053 PB.registerPipelineEarlySimplificationEPCallback(
1054 [this](ModulePassManager &PM, OptimizationLevel Level,
1056 if (!isLTOPreLink(Phase) && getTargetTriple().isAMDGCN()) {
1057 // When we are not using -fgpu-rdc, we can run accelerator code
1058 // selection relatively early, but still after linking to prevent
1059 // eager removal of potentially reachable symbols.
1060 if (EnableHipStdPar) {
1063 }
1064
1066 }
1067
1068 if (Level == OptimizationLevel::O0)
1069 return;
1070
1071 // We don't want to run internalization at per-module stage.
1074 PM.addPass(GlobalDCEPass());
1075 }
1076
1079 });
1080
1081 PB.registerPeepholeEPCallback(
1082 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1083 if (Level == OptimizationLevel::O0)
1084 return;
1085
1089
1092 });
1093
1094 PB.registerCGSCCOptimizerLateEPCallback(
1095 [this](CGSCCPassManager &PM, OptimizationLevel Level) {
1096 if (Level == OptimizationLevel::O0)
1097 return;
1098
1100
1101 // Add promote kernel arguments pass to the opt pipeline right before
1102 // infer address spaces which is needed to do actual address space
1103 // rewriting.
1106
1107 // Add infer address spaces pass to the opt pipeline after inlining
1108 // but before SROA to increase SROA opportunities.
1110
1111 // This should run after inlining to have any chance of doing
1112 // anything, and before other cleanup optimizations.
1114
1115 // Promote alloca to vector before SROA and loop unroll. If we
1116 // manage to eliminate allocas before unroll we may choose to unroll
1117 // less.
1119
1120 PM.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
1121 });
1122
1123 // FIXME: Why is AMDGPUAttributor not in CGSCC?
1124 PB.registerOptimizerLastEPCallback([this](ModulePassManager &MPM,
1125 OptimizationLevel Level,
1127 if (Level != OptimizationLevel::O0) {
1128 if (!isLTOPreLink(Phase)) {
1129 if (EnableAMDGPUAttributor && getTargetTriple().isAMDGCN()) {
1131 MPM.addPass(AMDGPUAttributorPass(*this, Opts, Phase));
1132 }
1133 }
1134 }
1135 });
1136
1137 PB.registerFullLinkTimeOptimizationLastEPCallback(
1138 [this](ModulePassManager &PM, OptimizationLevel Level) {
1139 // Clean up redundant memory round-trips that the full-LTO pipeline,
1140 // unlike the non-LTO/ThinLTO ones, otherwise leaves for codegen.
1141 if (Level != OptimizationLevel::O0) {
1143 EarlyCSEPass(/*UseMemorySSA=*/true)));
1144 }
1145
1146 // When we are using -fgpu-rdc, we can only run accelerator code
1147 // selection after linking to prevent, otherwise we end up removing
1148 // potentially reachable symbols that were exported as external in other
1149 // modules.
1150 if (EnableHipStdPar) {
1153 }
1154 // We want to support the -lto-partitions=N option as "best effort".
1155 // For that, we need to lower LDS earlier in the pipeline before the
1156 // module is partitioned for codegen.
1159 if (EnableSwLowerLDS)
1163 if (Level != OptimizationLevel::O0) {
1164 // We only want to run this with O2 or higher since inliner and SROA
1165 // don't run in O1.
1166 if (Level != OptimizationLevel::O1) {
1167 PM.addPass(
1169 }
1170 // Do we really need internalization in LTO?
1171 if (InternalizeSymbols) {
1173 PM.addPass(GlobalDCEPass());
1174 }
1175 if (EnableAMDGPUAttributor && getTargetTriple().isAMDGCN()) {
1178 Opt.IsClosedWorld = true;
1181 }
1182 }
1183 if (!NoKernelInfoEndLTO) {
1185 FPM.addPass(KernelInfoPrinter(this));
1186 PM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1187 }
1188 });
1189
1190 PB.registerRegClassFilterParsingCallback(
1191 [](StringRef FilterName) -> RegAllocFilterFunc {
1192 if (FilterName == "sgpr")
1193 return onlyAllocateSGPRs;
1194 if (FilterName == "vgpr")
1195 return onlyAllocateVGPRs;
1196 if (FilterName == "wwm")
1197 return onlyAllocateWWMRegs;
1198 return nullptr;
1199 });
1200}
1201
1203 unsigned SrcAS,
1204 unsigned DestAS) const {
1205 return AMDGPU::isFlatGlobalAddrSpace(SrcAS) &&
1207}
1208
1210 if (auto *Arg = dyn_cast<Argument>(V);
1211 Arg &&
1212 AMDGPU::isModuleEntryFunctionCC(Arg->getParent()->getCallingConv()) &&
1213 !Arg->hasByRefAttr())
1215
1216 const auto *LD = dyn_cast<LoadInst>(V);
1217 if (!LD) // TODO: Handle invariant load like constant.
1219
1220 // It must be a generic pointer loaded.
1221 assert(V->getType()->getPointerAddressSpace() == AMDGPUAS::FLAT_ADDRESS);
1222
1223 const auto *Ptr = LD->getPointerOperand();
1224 if (Ptr->getType()->getPointerAddressSpace() != AMDGPUAS::CONSTANT_ADDRESS)
1226 // For a generic pointer loaded from the constant memory, it could be assumed
1227 // as a global pointer since the constant memory is only populated on the
1228 // host side. As implied by the offload programming model, only global
1229 // pointers could be referenced on the host side.
1231}
1232
1233std::pair<const Value *, unsigned>
1235 if (auto *II = dyn_cast<IntrinsicInst>(V)) {
1236 switch (II->getIntrinsicID()) {
1237 case Intrinsic::amdgcn_is_shared:
1238 return std::pair(II->getArgOperand(0), AMDGPUAS::LOCAL_ADDRESS);
1239 case Intrinsic::amdgcn_is_private:
1240 return std::pair(II->getArgOperand(0), AMDGPUAS::PRIVATE_ADDRESS);
1241 default:
1242 break;
1243 }
1244 return std::pair(nullptr, -1);
1245 }
1246 // Check the global pointer predication based on
1247 // (!is_share(p) && !is_private(p)). Note that logic 'and' is commutative and
1248 // the order of 'is_shared' and 'is_private' is not significant.
1249 Value *Ptr;
1250 if (match(
1251 const_cast<Value *>(V),
1254 m_Deferred(Ptr))))))
1255 return std::pair(Ptr, AMDGPUAS::GLOBAL_ADDRESS);
1256
1257 return std::pair(nullptr, -1);
1258}
1259
1260unsigned
1275
1277 Module &M, unsigned NumParts,
1278 function_ref<void(std::unique_ptr<Module> MPart)> ModuleCallback) {
1279 // FIXME(?): Would be better to use an already existing Analysis/PassManager,
1280 // but all current users of this API don't have one ready and would need to
1281 // create one anyway. Let's hide the boilerplate for now to keep it simple.
1282
1287
1288 PassBuilder PB(this);
1289 PB.registerModuleAnalyses(MAM);
1290 PB.registerFunctionAnalyses(FAM);
1291 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
1292
1294 MPM.addPass(AMDGPUSplitModulePass(NumParts, ModuleCallback));
1295 MPM.run(M, MAM);
1296 return true;
1297}
1298
1299//===----------------------------------------------------------------------===//
1300// GCN Target Machine (SI+)
1301//===----------------------------------------------------------------------===//
1302
1304 StringRef CPU, StringRef FS,
1305 const TargetOptions &Options,
1306 std::optional<Reloc::Model> RM,
1307 std::optional<CodeModel::Model> CM,
1308 CodeGenOptLevel OL, bool JIT)
1309 : AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {
1311}
1312
1313enum class OOBFlagValue {
1314 Any = 0,
1317};
1318
1319/// Returns the OOB mode encoded by a module flag.
1320/// An absent flag defaults to Any.
1321static OOBFlagValue getOOBFlagValue(const Module &M, StringRef FlagName) {
1322 const auto *Flag =
1323 mdconst::dyn_extract_or_null<ConstantInt>(M.getModuleFlag(FlagName));
1324 if (!Flag)
1325 return OOBFlagValue::Any;
1326 return static_cast<OOBFlagValue>(Flag->getZExtValue());
1327}
1328
1329/// Returns the xnack/sramecc setting encoded by a module flag.
1330/// Module flag values: 0 = disabled, 1 = enabled.
1331/// An absent flag defaults to Any.
1334 StringRef FlagName) {
1336
1337 if (XnackSetting.getNumOccurrences() > 0 && FlagName == "amdgpu.xnack")
1338 return XnackSetting ? TargetIDSetting::On : TargetIDSetting::Off;
1339 if (SramEccSetting.getNumOccurrences() > 0 && FlagName == "amdgpu.sramecc")
1340 return SramEccSetting ? TargetIDSetting::On : TargetIDSetting::Off;
1341
1342 const auto *Flag =
1343 mdconst::dyn_extract_or_null<ConstantInt>(M.getModuleFlag(FlagName));
1344 if (!Flag)
1345 return TargetIDSetting::Any;
1346 return Flag->getZExtValue() == 0 ? TargetIDSetting::Off : TargetIDSetting::On;
1347}
1348
1349const TargetSubtargetInfo *
1351 StringRef GPU = getGPUName(F);
1353
1354 const Module &M = *F.getParent();
1357 bool BufRelaxed = BufOOB == OOBFlagValue::Relaxed;
1358 bool TBufRelaxed = TBufOOB == OOBFlagValue::Relaxed;
1359
1361 TargetIDSetting Xnack = getTargetIDSettingFromModuleFlag(M, "amdgpu.xnack");
1362 TargetIDSetting SramEcc =
1363 getTargetIDSettingFromModuleFlag(M, "amdgpu.sramecc");
1364
1365 SmallString<128> SubtargetKey(GPU);
1366 SubtargetKey.append(FS);
1367 if (BufRelaxed)
1368 SubtargetKey.append(",buf-oob=1");
1369 if (TBufRelaxed)
1370 SubtargetKey.append(",tbuf-oob=1");
1371 if (Xnack != TargetIDSetting::Any) {
1372 SubtargetKey.append(",xnack=");
1373 SubtargetKey.push_back(Xnack == TargetIDSetting::On ? '1' : '0');
1374 }
1375 if (SramEcc != TargetIDSetting::Any) {
1376 SubtargetKey.append(",sramecc=");
1377 SubtargetKey.push_back(Xnack == TargetIDSetting::On ? '1' : '0');
1378 }
1379
1380 auto &I = SubtargetMap[SubtargetKey];
1381 if (!I) {
1383 Triple::SubArchType GPUSubArch = AMDGPU::getSubArch(Kind);
1384
1385 // Enforce the subtarget is covered by the subarch. Tolerate no subarch for
1386 // legacy compatibility.
1387 const Triple &TT = M.getTargetTriple();
1388 if (GPUSubArch != TT.getSubArch() && Kind != AMDGPU::GK_NONE) {
1389 // Check if this is a generic subarch which has subtargets. Ignore
1390 // unknown subtargets with a known subarch, since for whatever reason
1391 // the convention is to just print a warning and ignore unrecognized
1392 // subtargets.
1393 bool IsLegacyEmptySubArch = TT.getSubArch() == Triple::NoSubArch;
1394 if (!IsLegacyEmptySubArch &&
1395 AMDGPU::getMajorSubArch(GPUSubArch) != TT.getSubArch()) {
1396 F.getContext().emitError("invalid subtarget '" + Twine(GPU) +
1397 "' for subarch " + TT.getArchName());
1398 }
1399 }
1400
1401 I = std::make_unique<GCNSubtarget>(TargetTriple, GPU, FS, *this, BufRelaxed,
1402 TBufRelaxed, Xnack, SramEcc);
1403 }
1404
1405 I->setScalarizeGlobalBehavior(ScalarizeGlobal);
1406
1407 return I.get();
1408}
1409
1412 return TargetTransformInfo(std::make_unique<GCNTTIImpl>(this, F));
1413}
1414
1417 raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
1418 const CGPassBuilderOption &Opts, MCContext &Ctx,
1420 AMDGPUCodeGenPassBuilder CGPB(*this, Opts, PIC);
1421 return CGPB.buildPipeline(MPM, MAM, Out, DwoOut, FileType, Ctx);
1422}
1423
1426 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
1427 if (ST.enableSIScheduler())
1429
1430 StringRef SchedStrategy = AMDGPU::getSchedStrategy(C->MF->getFunction());
1431
1432 if (SchedStrategy == "max-ilp")
1434
1435 if (SchedStrategy == "max-memory-clause")
1437
1438 if (SchedStrategy == "iterative-ilp")
1440
1441 if (SchedStrategy == "iterative-minreg")
1442 return createMinRegScheduler(C);
1443
1444 if (SchedStrategy == "iterative-maxocc")
1446
1447 if (SchedStrategy == "coexec") {
1448 diagnoseUnsupportedCoExecSchedulerSelection(C->MF->getFunction(), ST);
1450 }
1451
1453}
1454
1457 if (useNoopPostScheduler(C->MF->getFunction()))
1459
1460 ScheduleDAGMI *DAG =
1461 new GCNPostScheduleDAGMILive(C, std::make_unique<PostGenericScheduler>(C),
1462 /*RemoveKillFlags=*/true);
1463 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
1465 if (ST.shouldClusterStores())
1468 if ((EnableVOPD.getNumOccurrences() ||
1470 EnableVOPD)
1475 return DAG;
1476}
1477//===----------------------------------------------------------------------===//
1478// AMDGPU Legacy Pass Setup
1479//===----------------------------------------------------------------------===//
1480
1481std::unique_ptr<CSEConfigBase> llvm::AMDGPUPassConfig::getCSEConfig() const {
1482 return getStandardCSEConfigForOpt(TM->getOptLevel());
1483}
1484
1485namespace {
1486
1487class GCNPassConfig final : public AMDGPUPassConfig {
1488public:
1489 GCNPassConfig(TargetMachine &TM, PassManagerBase &PM)
1490 : AMDGPUPassConfig(TM, PM) {
1491 substitutePass(&PostRASchedulerID, &PostMachineSchedulerID);
1492 }
1493
1494 GCNTargetMachine &getGCNTargetMachine() const {
1495 return getTM<GCNTargetMachine>();
1496 }
1497
1498 bool addPreISel() override;
1499 void addMachineSSAOptimization() override;
1500 bool addILPOpts() override;
1501 bool addInstSelector() override;
1502 bool addIRTranslator() override;
1503 void addPreLegalizeMachineIR() override;
1504 bool addLegalizeMachineIR() override;
1505 void addPreRegBankSelect() override;
1506 bool addRegBankSelect() override;
1507 void addPreGlobalInstructionSelect() override;
1508 bool addGlobalInstructionSelect() override;
1509 void addPreRegAlloc() override;
1510 void addFastRegAlloc() override;
1511 void addOptimizedRegAlloc() override;
1512
1513 FunctionPass *createSGPRAllocPass(bool Optimized);
1514 FunctionPass *createVGPRAllocPass(bool Optimized);
1515 FunctionPass *createWWMRegAllocPass(bool Optimized);
1516 FunctionPass *createRegAllocPass(bool Optimized) override;
1517
1518 bool addRegAssignAndRewriteFast() override;
1519 bool addRegAssignAndRewriteOptimized() override;
1520
1521 bool addPreRewrite() override;
1522 void addPostRegAlloc() override;
1523 void addPreSched2() override;
1524 void addPreEmitPass() override;
1525 void addPostBBSections() override;
1526};
1527
1528} // end anonymous namespace
1529
1531 : TargetPassConfig(TM, PM) {
1532 // Exceptions and StackMaps are not supported, so these passes will never do
1533 // anything.
1536 // Garbage collection is not supported.
1539}
1540
1547
1552 // ReassociateGEPs exposes more opportunities for SLSR. See
1553 // the example in reassociate-geps-and-slsr.ll.
1555 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
1556 // EarlyCSE can reuse.
1558 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
1560 // NaryReassociate on GEPs creates redundant common expressions, so run
1561 // EarlyCSE after it.
1563}
1564
1567
1568 if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN())
1570
1571 // There is no reason to run these.
1575
1576 if (TM.getTargetTriple().isAMDGCN())
1578
1579 if (LowerCtorDtor)
1581
1582 if (TM.getTargetTriple().isAMDGCN() &&
1585
1588
1589 // This can be disabled by passing ::Disable here or on the command line
1590 // with --expand-variadics-override=disable.
1592
1593 // Function calls are not supported, so make sure we inline everything.
1596
1597 // Handle uses of OpenCL image2d_t, image3d_t and sampler_t arguments.
1598 if (TM.getTargetTriple().getArch() == Triple::r600)
1600
1601 // Make enqueued block runtime handles externally visible.
1603
1604 // Lower special LDS accesses.
1607
1608 // Lower LDS accesses to global memory pass if address sanitizer is enabled.
1609 if (EnableSwLowerLDS)
1611
1612 // Runs before PromoteAlloca so the latter can account for function uses
1615 }
1616
1617 // Run atomic optimizer before Atomic Expand
1618 if ((TM.getTargetTriple().isAMDGCN()) &&
1619 (TM.getOptLevel() >= CodeGenOptLevel::Less) &&
1622 }
1623
1625
1626 if (TM.getOptLevel() > CodeGenOptLevel::None) {
1628
1631
1635 AAResults &AAR) {
1636 if (auto *WrapperPass = P.getAnalysisIfAvailable<AMDGPUAAWrapperPass>())
1637 AAR.addAAResult(WrapperPass->getResult());
1638 }));
1639 }
1640
1641 if (TM.getTargetTriple().isAMDGCN()) {
1642 // TODO: May want to move later or split into an early and late one.
1644 }
1645
1646 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
1647 // have expanded.
1648 if (TM.getOptLevel() > CodeGenOptLevel::Less)
1650 }
1651
1653
1654 // EarlyCSE is not always strong enough to clean up what LSR produces. For
1655 // example, GVN can combine
1656 //
1657 // %0 = add %a, %b
1658 // %1 = add %b, %a
1659 //
1660 // and
1661 //
1662 // %0 = shl nsw %a, 2
1663 // %1 = shl %a, 2
1664 //
1665 // but EarlyCSE can do neither of them.
1668}
1669
1671 if (TM->getTargetTriple().isAMDGCN() &&
1672 TM->getOptLevel() > CodeGenOptLevel::None)
1674
1675 if (TM->getTargetTriple().isAMDGCN() && EnableLowerKernelArguments)
1677
1679
1682
1683 if (TM->getTargetTriple().isAMDGCN()) {
1684 // This lowering has been placed after codegenprepare to take advantage of
1685 // address mode matching (which is why it isn't put with the LDS lowerings).
1686 // It could be placed anywhere before uniformity annotations (an analysis
1687 // that it changes by splitting up fat pointers into their components)
1688 // but has been put before switch lowering and CFG flattening so that those
1689 // passes can run on the more optimized control flow this pass creates in
1690 // many cases.
1693 }
1694
1695 // LowerSwitch pass may introduce unreachable blocks that can
1696 // cause unexpected behavior for subsequent passes. Placing it
1697 // here seems better that these blocks would get cleaned up by
1698 // UnreachableBlockElim inserted next in the pass flow.
1700}
1701
1703 if (TM->getOptLevel() > CodeGenOptLevel::None)
1705 return false;
1706}
1707
1712
1714 // Do nothing. GC is not supported.
1715 return false;
1716}
1717
1718//===----------------------------------------------------------------------===//
1719// GCN Legacy Pass Setup
1720//===----------------------------------------------------------------------===//
1721
1722bool GCNPassConfig::addPreISel() {
1724
1725 if (TM->getOptLevel() > CodeGenOptLevel::None) {
1726 addPass(createSinkingPass());
1728 }
1729
1730 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
1731 // regions formed by them.
1733 addPass(createFixIrreduciblePass());
1734 addPass(createUnifyLoopExitsPass());
1735 addPass(createStructurizeCFGPass(/*SkipUniformRegions=*/true));
1736
1739 // TODO: Move this right after structurizeCFG to avoid extra divergence
1740 // analysis. This depends on stopping SIAnnotateControlFlow from making
1741 // control flow modifications.
1743
1744 // SDAG requires LCSSA, GlobalISel does not. Disable LCSSA for -global-isel
1745 // without any of the fallback options.
1748 !isGlobalISelAbortEnabled())
1749 addPass(createLCSSAPass());
1750
1751 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1753
1754 return false;
1755}
1756
1757void GCNPassConfig::addMachineSSAOptimization() {
1759
1760 // We want to fold operands after PeepholeOptimizer has run (or as part of
1761 // it), because it will eliminate extra copies making it easier to fold the
1762 // real source operand. We want to eliminate dead instructions after, so that
1763 // we see fewer uses of the copies. We then need to clean up the dead
1764 // instructions leftover after the operands are folded as well.
1765 //
1766 // XXX - Can we get away without running DeadMachineInstructionElim again?
1767 addPass(&SIFoldOperandsLegacyID);
1768 if (EnableDPPCombine)
1769 addPass(&GCNDPPCombineLegacyID);
1771 if (isPassEnabled(EnableSDWAPeephole)) {
1772 addPass(&SIPeepholeSDWALegacyID);
1773 addPass(&EarlyMachineLICMID);
1774 addPass(&MachineCSELegacyID);
1775 addPass(&SIFoldOperandsLegacyID);
1776 }
1779}
1780
1781bool GCNPassConfig::addILPOpts() {
1783 addPass(&EarlyIfConverterLegacyID);
1784
1786 return false;
1787}
1788
1789bool GCNPassConfig::addInstSelector() {
1791 addPass(&SIFixSGPRCopiesLegacyID);
1793 return false;
1794}
1795
1796bool GCNPassConfig::addIRTranslator() {
1797 addPass(new IRTranslatorLegacy(getOptLevel()));
1798 return false;
1799}
1800
1801void GCNPassConfig::addPreLegalizeMachineIR() {
1802 bool IsOptLevelNone = getOptLevel() == CodeGenOptLevel::None;
1803 addPass(createAMDGPUPreLegalizeCombinerLegacyPass(IsOptLevelNone));
1804 addPass(new LocalizerLegacy());
1805}
1806
1807bool GCNPassConfig::addLegalizeMachineIR() {
1808 addPass(new LegalizerLegacy());
1809 return false;
1810}
1811
1812void GCNPassConfig::addPreRegBankSelect() {
1813 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1814 addPass(createAMDGPUPostLegalizeCombinerLegacy(IsOptNone));
1816}
1817
1818bool GCNPassConfig::addRegBankSelect() {
1821 return false;
1822}
1823
1824void GCNPassConfig::addPreGlobalInstructionSelect() {
1825 bool IsOptLevelNone = getOptLevel() == CodeGenOptLevel::None;
1826 addPass(createAMDGPURegBankCombinerLegacy(IsOptLevelNone));
1827}
1828
1829bool GCNPassConfig::addGlobalInstructionSelect() {
1830 addPass(new InstructionSelectLegacy(getOptLevel()));
1831 return false;
1832}
1833
1834void GCNPassConfig::addFastRegAlloc() {
1835 // FIXME: We have to disable the verifier here because of PHIElimination +
1836 // TwoAddressInstructions disabling it.
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
1844
1846}
1847
1848void GCNPassConfig::addPreRegAlloc() {
1849 if (getOptLevel() != CodeGenOptLevel::None)
1851 if (getOptLevel() >= CodeGenOptLevel::Default && EnableMachinePipeliner)
1852 addPass(&MachinePipelinerID);
1853}
1854
1855void GCNPassConfig::addOptimizedRegAlloc() {
1856 if (EnableDCEInRA)
1858
1859 if (OptVGPRLiveRange)
1861
1862 // This must be run immediately after phi elimination and before
1863 // TwoAddressInstructions, otherwise the processing of the tied operand of
1864 // SI_ELSE will introduce a copy of the tied operand source after the else.
1866
1869
1870 if (isPassEnabled(EnablePreRAOptimizations))
1872
1873 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
1874 // instructions that cause scheduling barriers.
1876
1877 if (OptExecMaskPreRA)
1879
1880 // This is not an essential optimization and it has a noticeable impact on
1881 // compilation time, so we only enable it from O2.
1882 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1884
1886}
1887
1888bool GCNPassConfig::addPreRewrite() {
1890 addPass(&GCNNSAReassignID);
1891
1893 return true;
1894}
1895
1896FunctionPass *GCNPassConfig::createSGPRAllocPass(bool Optimized) {
1897 // Initialize the global default.
1898 llvm::call_once(InitializeDefaultSGPRRegisterAllocatorFlag,
1899 initializeDefaultSGPRRegisterAllocatorOnce);
1900
1901 RegisterRegAlloc::FunctionPassCtor Ctor = SGPRRegisterRegAlloc::getDefault();
1902 if (Ctor != useDefaultRegisterAllocator)
1903 return Ctor();
1904
1905 if (Optimized)
1906 return createGreedyRegisterAllocator(onlyAllocateSGPRs);
1907
1908 return createFastRegisterAllocator(onlyAllocateSGPRs, false);
1909}
1910
1911FunctionPass *GCNPassConfig::createVGPRAllocPass(bool Optimized) {
1912 // Initialize the global default.
1913 llvm::call_once(InitializeDefaultVGPRRegisterAllocatorFlag,
1914 initializeDefaultVGPRRegisterAllocatorOnce);
1915
1916 RegisterRegAlloc::FunctionPassCtor Ctor = VGPRRegisterRegAlloc::getDefault();
1917 if (Ctor != useDefaultRegisterAllocator)
1918 return Ctor();
1919
1920 if (Optimized)
1921 return createGreedyVGPRRegisterAllocator();
1922
1923 return createFastVGPRRegisterAllocator();
1924}
1925
1926FunctionPass *GCNPassConfig::createWWMRegAllocPass(bool Optimized) {
1927 // Initialize the global default.
1928 llvm::call_once(InitializeDefaultWWMRegisterAllocatorFlag,
1929 initializeDefaultWWMRegisterAllocatorOnce);
1930
1931 RegisterRegAlloc::FunctionPassCtor Ctor = WWMRegisterRegAlloc::getDefault();
1932 if (Ctor != useDefaultRegisterAllocator)
1933 return Ctor();
1934
1935 if (Optimized)
1936 return createGreedyWWMRegisterAllocator();
1937
1938 return createFastWWMRegisterAllocator();
1939}
1940
1941FunctionPass *GCNPassConfig::createRegAllocPass(bool Optimized) {
1942 llvm_unreachable("should not be used");
1943}
1944
1946 "-regalloc not supported with amdgcn. Use -sgpr-regalloc, -wwm-regalloc, "
1947 "and -vgpr-regalloc";
1948
1949bool GCNPassConfig::addRegAssignAndRewriteFast() {
1950 if (!usingDefaultRegAlloc())
1952
1953 addPass(&GCNPreRALongBranchRegID);
1954
1955 addPass(createSGPRAllocPass(false));
1956
1957 // Equivalent of PEI for SGPRs.
1958 addPass(&SILowerSGPRSpillsLegacyID);
1959
1960 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1962
1963 // For allocating other wwm register operands.
1964 addPass(createWWMRegAllocPass(false));
1965
1966 addPass(&SILowerWWMCopiesLegacyID);
1968
1969 // For allocating per-thread VGPRs.
1970 addPass(createVGPRAllocPass(false));
1971
1972 return true;
1973}
1974
1975bool GCNPassConfig::addRegAssignAndRewriteOptimized() {
1976 if (!usingDefaultRegAlloc())
1978
1979 addPass(&GCNPreRALongBranchRegID);
1980
1981 addPass(createSGPRAllocPass(true));
1982
1983 // Commit allocated register changes. This is mostly necessary because too
1984 // many things rely on the use lists of the physical registers, such as the
1985 // verifier. This is only necessary with allocators which use LiveIntervals,
1986 // since FastRegAlloc does the replacements itself.
1987 addPass(createVirtRegRewriter(false));
1988
1989 // At this point, the sgpr-regalloc has been done and it is good to have the
1990 // stack slot coloring to try to optimize the SGPR spill stack indices before
1991 // attempting the custom SGPR spill lowering.
1992 addPass(&StackSlotColoringID);
1993
1994 // Equivalent of PEI for SGPRs.
1995 addPass(&SILowerSGPRSpillsLegacyID);
1996
1997 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1999
2000 // For allocating other whole wave mode registers.
2001 addPass(createWWMRegAllocPass(true));
2002 addPass(&SILowerWWMCopiesLegacyID);
2003 addPass(createVirtRegRewriter(false));
2005
2006 // For allocating per-thread VGPRs.
2007 addPass(createVGPRAllocPass(true));
2008
2009 addPreRewrite();
2010 addPass(&VirtRegRewriterID);
2011
2013
2014 return true;
2015}
2016
2017void GCNPassConfig::addPostRegAlloc() {
2018 addPass(&SIFixVGPRCopiesID);
2019 if (getOptLevel() > CodeGenOptLevel::None)
2022}
2023
2024void GCNPassConfig::addPreSched2() {
2025 if (TM->getOptLevel() > CodeGenOptLevel::None)
2027 addPass(&SIPostRABundlerLegacyID);
2028}
2029
2030void GCNPassConfig::addPreEmitPass() {
2031 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less))
2032 addPass(&GCNCreateVOPDID);
2033 addPass(createSIMemoryLegalizerPass());
2034 if (getOptLevel() > CodeGenOptLevel::None)
2036 addPass(createSIInsertWaitcntsPass());
2037
2038 addPass(createSIModeRegisterPass());
2039
2040 if (getOptLevel() > CodeGenOptLevel::None)
2041 addPass(&SIInsertHardClausesID);
2042
2044 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
2046 if (getOptLevel() > CodeGenOptLevel::None)
2047 addPass(&SIPreEmitPeepholeID);
2048 // The hazard recognizer that runs as part of the post-ra scheduler does not
2049 // guarantee to be able handle all hazards correctly. This is because if there
2050 // are multiple scheduling regions in a basic block, the regions are scheduled
2051 // bottom up, so when we begin to schedule a region we don't know what
2052 // instructions were emitted directly before it.
2053 //
2054 // Here we add a stand-alone hazard recognizer pass which can handle all
2055 // cases.
2056 addPass(&PostRAHazardRecognizerID);
2057
2059
2061
2062 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less))
2063 addPass(&AMDGPUInsertDelayAluID);
2064
2065 addPass(&BranchRelaxationPassID);
2066}
2067
2068void GCNPassConfig::addPostBBSections() {
2069 // We run this later to avoid passes like livedebugvalues and BBSections
2070 // having to deal with the apparent multi-entry functions we may generate.
2072}
2073
2075 return new GCNPassConfig(*this, PM);
2076}
2077
2083
2090
2094
2101
2104 SMDiagnostic &Error, SMRange &SourceRange) const {
2105 const yaml::SIMachineFunctionInfo &YamlMFI =
2106 static_cast<const yaml::SIMachineFunctionInfo &>(MFI_);
2107 MachineFunction &MF = PFS.MF;
2109 const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
2110
2111 if (MFI->initializeBaseYamlFields(YamlMFI, MF, PFS, Error, SourceRange))
2112 return true;
2113
2114 if (MFI->Occupancy == 0) {
2115 // Fixup the subtarget dependent default value.
2116 MFI->Occupancy = ST.getOccupancyWithWorkGroupSizes(MF).second;
2117 }
2118
2119 auto parseRegister = [&](const yaml::StringValue &RegName, Register &RegVal) {
2120 Register TempReg;
2121 if (parseNamedRegisterReference(PFS, TempReg, RegName.Value, Error)) {
2122 SourceRange = RegName.SourceRange;
2123 return true;
2124 }
2125 RegVal = TempReg;
2126
2127 return false;
2128 };
2129
2130 auto parseOptionalRegister = [&](const yaml::StringValue &RegName,
2131 Register &RegVal) {
2132 return !RegName.Value.empty() && parseRegister(RegName, RegVal);
2133 };
2134
2135 if (parseOptionalRegister(YamlMFI.VGPRForAGPRCopy, MFI->VGPRForAGPRCopy))
2136 return true;
2137
2138 if (parseOptionalRegister(YamlMFI.SGPRForEXECCopy, MFI->SGPRForEXECCopy))
2139 return true;
2140
2141 if (parseOptionalRegister(YamlMFI.LongBranchReservedReg,
2142 MFI->LongBranchReservedReg))
2143 return true;
2144
2145 auto diagnoseRegisterClass = [&](const yaml::StringValue &RegName) {
2146 // Create a diagnostic for a the register string literal.
2147 const MemoryBuffer &Buffer =
2148 *PFS.SM->getMemoryBuffer(PFS.SM->getMainFileID());
2149 Error = SMDiagnostic(*PFS.SM, SMLoc(), Buffer.getBufferIdentifier(), 1,
2150 RegName.Value.size(), SourceMgr::DK_Error,
2151 "incorrect register class for field", RegName.Value,
2152 {}, {});
2153 SourceRange = RegName.SourceRange;
2154 return true;
2155 };
2156
2157 if (parseRegister(YamlMFI.ScratchRSrcReg, MFI->ScratchRSrcReg) ||
2158 parseRegister(YamlMFI.FrameOffsetReg, MFI->FrameOffsetReg) ||
2159 parseRegister(YamlMFI.StackPtrOffsetReg, MFI->StackPtrOffsetReg))
2160 return true;
2161
2162 if (MFI->ScratchRSrcReg != AMDGPU::PRIVATE_RSRC_REG &&
2163 !AMDGPU::SGPR_128RegClass.contains(MFI->ScratchRSrcReg)) {
2164 return diagnoseRegisterClass(YamlMFI.ScratchRSrcReg);
2165 }
2166
2167 if (MFI->FrameOffsetReg != AMDGPU::FP_REG &&
2168 !AMDGPU::SGPR_32RegClass.contains(MFI->FrameOffsetReg)) {
2169 return diagnoseRegisterClass(YamlMFI.FrameOffsetReg);
2170 }
2171
2172 if (MFI->StackPtrOffsetReg != AMDGPU::SP_REG &&
2173 !AMDGPU::SGPR_32RegClass.contains(MFI->StackPtrOffsetReg)) {
2174 return diagnoseRegisterClass(YamlMFI.StackPtrOffsetReg);
2175 }
2176
2177 for (const auto &YamlReg : YamlMFI.WWMReservedRegs) {
2178 Register ParsedReg;
2179 if (parseRegister(YamlReg, ParsedReg))
2180 return true;
2181
2182 MFI->reserveWWMRegister(ParsedReg);
2183 }
2184
2185 for (const auto &[_, Info] : PFS.VRegInfosNamed) {
2186 MFI->setFlag(Info->VReg, Info->Flags);
2187 }
2188 for (const auto &[_, Info] : PFS.VRegInfos) {
2189 MFI->setFlag(Info->VReg, Info->Flags);
2190 }
2191
2192 for (const auto &YamlRegStr : YamlMFI.SpillPhysVGPRS) {
2193 Register ParsedReg;
2194 if (parseRegister(YamlRegStr, ParsedReg))
2195 return true;
2196 MFI->SpillPhysVGPRs.push_back(ParsedReg);
2197 }
2198
2199 auto parseAndCheckArgument = [&](const std::optional<yaml::SIArgument> &A,
2200 const TargetRegisterClass &RC,
2201 ArgDescriptor &Arg, unsigned UserSGPRs,
2202 unsigned SystemSGPRs) {
2203 // Skip parsing if it's not present.
2204 if (!A)
2205 return false;
2206
2207 if (A->IsRegister) {
2208 Register Reg;
2209 if (parseNamedRegisterReference(PFS, Reg, A->RegisterName.Value, Error)) {
2210 SourceRange = A->RegisterName.SourceRange;
2211 return true;
2212 }
2213 if (!RC.contains(Reg))
2214 return diagnoseRegisterClass(A->RegisterName);
2216 } else
2217 Arg = ArgDescriptor::createStack(A->StackOffset);
2218 // Check and apply the optional mask.
2219 if (A->Mask)
2220 Arg = ArgDescriptor::createArg(Arg, *A->Mask);
2221
2222 MFI->NumUserSGPRs += UserSGPRs;
2223 MFI->NumSystemSGPRs += SystemSGPRs;
2224 return false;
2225 };
2226
2227 if (YamlMFI.ArgInfo &&
2228 (parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentBuffer,
2229 AMDGPU::SGPR_128RegClass,
2230 MFI->ArgInfo.PrivateSegmentBuffer, 4, 0) ||
2231 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchPtr,
2232 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchPtr,
2233 2, 0) ||
2234 parseAndCheckArgument(YamlMFI.ArgInfo->QueuePtr, AMDGPU::SReg_64RegClass,
2235 MFI->ArgInfo.QueuePtr, 2, 0) ||
2236 parseAndCheckArgument(YamlMFI.ArgInfo->KernargSegmentPtr,
2237 AMDGPU::SReg_64RegClass,
2238 MFI->ArgInfo.KernargSegmentPtr, 2, 0) ||
2239 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchID,
2240 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchID,
2241 2, 0) ||
2242 parseAndCheckArgument(YamlMFI.ArgInfo->FlatScratchInit,
2243 AMDGPU::SReg_64RegClass,
2244 MFI->ArgInfo.FlatScratchInit, 2, 0) ||
2245 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentSize,
2246 AMDGPU::SGPR_32RegClass,
2247 MFI->ArgInfo.PrivateSegmentSize, 1, 0) ||
2248 parseAndCheckArgument(YamlMFI.ArgInfo->LDSKernelId,
2249 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.LDSKernelId,
2250 1, 0) ||
2251 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDX,
2252 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDX,
2253 0, 1) ||
2254 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDY,
2255 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDY,
2256 0, 1) ||
2257 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDZ,
2258 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDZ,
2259 0, 1) ||
2260 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupInfo,
2261 AMDGPU::SGPR_32RegClass,
2262 MFI->ArgInfo.WorkGroupInfo, 0, 1) ||
2263 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentWaveByteOffset,
2264 AMDGPU::SGPR_32RegClass,
2265 MFI->ArgInfo.PrivateSegmentWaveByteOffset, 0, 1) ||
2266 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitArgPtr,
2267 AMDGPU::SReg_64RegClass,
2268 MFI->ArgInfo.ImplicitArgPtr, 0, 0) ||
2269 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitBufferPtr,
2270 AMDGPU::SReg_64RegClass,
2271 MFI->ArgInfo.ImplicitBufferPtr, 2, 0) ||
2272 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDX,
2273 AMDGPU::VGPR_32RegClass, MFI->ArgInfo.WorkItemIDX,
2274 0, 0) ||
2275 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDY,
2276 AMDGPU::VGPR_32RegClass, MFI->ArgInfo.WorkItemIDY,
2277 0, 0) ||
2278 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDZ,
2279 AMDGPU::VGPR_32RegClass, MFI->ArgInfo.WorkItemIDZ,
2280 0, 0)))
2281 return true;
2282
2283 // Parse FirstKernArgPreloadReg separately, since it's a Register,
2284 // not ArgDescriptor.
2285 if (YamlMFI.ArgInfo && YamlMFI.ArgInfo->FirstKernArgPreloadReg) {
2286 const yaml::SIArgument &A = *YamlMFI.ArgInfo->FirstKernArgPreloadReg;
2287
2288 if (!A.IsRegister) {
2289 // For stack arguments, we don't have RegisterName.SourceRange,
2290 // but we should have some location info from the YAML parser
2291 const MemoryBuffer &Buffer =
2292 *PFS.SM->getMemoryBuffer(PFS.SM->getMainFileID());
2293 // Create a minimal valid source range
2295 SMRange Range(Loc, Loc);
2296
2298 *PFS.SM, Loc, Buffer.getBufferIdentifier(), 1, 0, SourceMgr::DK_Error,
2299 "firstKernArgPreloadReg must be a register, not a stack location", "",
2300 {}, {});
2301
2302 SourceRange = Range;
2303 return true;
2304 }
2305
2306 Register Reg;
2307 if (parseNamedRegisterReference(PFS, Reg, A.RegisterName.Value, Error)) {
2308 SourceRange = A.RegisterName.SourceRange;
2309 return true;
2310 }
2311
2312 if (!AMDGPU::SGPR_32RegClass.contains(Reg))
2313 return diagnoseRegisterClass(A.RegisterName);
2314
2315 MFI->ArgInfo.FirstKernArgPreloadReg = Reg;
2316 MFI->NumUserSGPRs += YamlMFI.NumKernargPreloadSGPRs;
2317 }
2318
2319 if (ST.hasFeature(AMDGPU::FeatureDX10ClampAndIEEEMode)) {
2320 MFI->Mode.IEEE = YamlMFI.Mode.IEEE;
2321 MFI->Mode.DX10Clamp = YamlMFI.Mode.DX10Clamp;
2322 }
2323
2324 // FIXME: Move proper support for denormal-fp-math into base MachineFunction
2325 MFI->Mode.FP32Denormals.Input = YamlMFI.Mode.FP32InputDenormals
2328 MFI->Mode.FP32Denormals.Output = YamlMFI.Mode.FP32OutputDenormals
2331
2338
2339 if (YamlMFI.HasInitWholeWave)
2340 MFI->setInitWholeWave();
2341
2342 return false;
2343}
2344
2345//===----------------------------------------------------------------------===//
2346// AMDGPU CodeGen Pass Builder interface.
2347//===----------------------------------------------------------------------===//
2348
2349AMDGPUCodeGenPassBuilder::AMDGPUCodeGenPassBuilder(
2350 GCNTargetMachine &TM, const CGPassBuilderOption &Opts,
2352 : CodeGenPassBuilder(TM, Opts, PIC) {
2353 Opt.MISchedPostRA = true;
2354 Opt.RequiresCodeGenSCCOrder = true;
2355 // Exceptions and StackMaps are not supported, so these passes will never do
2356 // anything.
2357 // Garbage collection is not supported.
2358 disablePass<StackMapLivenessPass, FuncletLayoutPass, PatchableFunctionPass,
2360}
2361
2362void AMDGPUCodeGenPassBuilder::addIRPasses(PassManagerWrapper &PMW) {
2363 if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN()) {
2364 flushFPMsToMPM(PMW);
2365 addModulePass(AMDGPURemoveIncompatibleFunctionsPass(TM), PMW);
2366 }
2367
2368 flushFPMsToMPM(PMW);
2369
2370 if (TM.getTargetTriple().isAMDGCN())
2371 addModulePass(AMDGPUPrintfRuntimeBindingPass(), PMW);
2372
2373 if (LowerCtorDtor)
2374 addModulePass(AMDGPUCtorDtorLoweringPass(), PMW);
2375
2376 if (isPassEnabled(EnableImageIntrinsicOptimizer))
2377 addFunctionPass(AMDGPUImageIntrinsicOptimizerPass(TM), PMW);
2378
2380 addFunctionPass(AMDGPUUniformIntrinsicCombinePass(), PMW);
2381 // This can be disabled by passing ::Disable here or on the command line
2382 // with --expand-variadics-override=disable.
2383 flushFPMsToMPM(PMW);
2385
2386 addModulePass(AMDGPUAlwaysInlinePass(), PMW);
2387 addModulePass(AlwaysInlinerPass(), PMW);
2388
2389 addModulePass(AMDGPUExportKernelRuntimeHandlesPass(), PMW);
2390
2392 addModulePass(AMDGPULowerExecSyncPass(), PMW);
2393
2394 if (EnableSwLowerLDS)
2395 addModulePass(AMDGPUSwLowerLDSPass(), PMW);
2396
2397 // Runs before PromoteAlloca so the latter can account for function uses
2399 addModulePass(AMDGPULowerModuleLDSPass(getTM()), PMW);
2400
2401 // Run atomic optimizer before Atomic Expand
2402 if (TM.getOptLevel() >= CodeGenOptLevel::Less &&
2404 addFunctionPass(
2406
2407 addFunctionPass(AtomicExpandPass(TM), PMW);
2408
2409 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2410 addFunctionPass(AMDGPUPromoteAllocaPass(TM), PMW);
2411 if (isPassEnabled(EnableScalarIRPasses))
2412 addStraightLineScalarOptimizationPasses(PMW);
2413
2414 // TODO: Handle EnableAMDGPUAliasAnalysis
2415
2416 // TODO: May want to move later or split into an early and late one.
2417 addFunctionPass(AMDGPUCodeGenPreparePass(TM), PMW);
2418
2419 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
2420 // have expanded.
2421 if (TM.getOptLevel() > CodeGenOptLevel::Less) {
2423 /*UseMemorySSA=*/true),
2424 PMW);
2425 }
2426 }
2427
2428 Base::addIRPasses(PMW);
2429
2430 // EarlyCSE is not always strong enough to clean up what LSR produces. For
2431 // example, GVN can combine
2432 //
2433 // %0 = add %a, %b
2434 // %1 = add %b, %a
2435 //
2436 // and
2437 //
2438 // %0 = shl nsw %a, 2
2439 // %1 = shl %a, 2
2440 //
2441 // but EarlyCSE can do neither of them.
2442 if (isPassEnabled(EnableScalarIRPasses))
2443 addEarlyCSEOrGVNPass(PMW);
2444}
2445
2446void AMDGPUCodeGenPassBuilder::addCodeGenPrepare(PassManagerWrapper &PMW) {
2447 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2448 flushFPMsToMPM(PMW);
2449 addModulePass(AMDGPUPreloadKernelArgumentsPass(TM), PMW);
2450 }
2451
2453 addFunctionPass(AMDGPULowerKernelArgumentsPass(TM), PMW);
2454
2455 Base::addCodeGenPrepare(PMW);
2456
2457 if (isPassEnabled(EnableLoadStoreVectorizer))
2458 addFunctionPass(LoadStoreVectorizerPass(), PMW);
2459
2460 // This lowering has been placed after codegenprepare to take advantage of
2461 // address mode matching (which is why it isn't put with the LDS lowerings).
2462 // It could be placed anywhere before uniformity annotations (an analysis
2463 // that it changes by splitting up fat pointers into their components)
2464 // but has been put before switch lowering and CFG flattening so that those
2465 // passes can run on the more optimized control flow this pass creates in
2466 // many cases.
2467 flushFPMsToMPM(PMW);
2468 addModulePass(AMDGPULowerBufferFatPointersPass(TM), PMW);
2469 flushFPMsToMPM(PMW);
2470 requireCGSCCOrder(PMW);
2471
2472 addModulePass(AMDGPULowerIntrinsicsPass(getTM()), PMW);
2473
2474 // LowerSwitch pass may introduce unreachable blocks that can cause unexpected
2475 // behavior for subsequent passes. Placing it here seems better that these
2476 // blocks would get cleaned up by UnreachableBlockElim inserted next in the
2477 // pass flow.
2478 addFunctionPass(LowerSwitchPass(), PMW);
2479}
2480
2481void AMDGPUCodeGenPassBuilder::addPreISel(PassManagerWrapper &PMW) {
2482
2483 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2484 addFunctionPass(FlattenCFGPass(), PMW);
2485 addFunctionPass(SinkingPass(), PMW);
2486 addFunctionPass(AMDGPULateCodeGenPreparePass(getTM()), PMW);
2487 }
2488
2489 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
2490 // regions formed by them.
2491
2492 addFunctionPass(AMDGPUUnifyDivergentExitNodesPass(), PMW);
2493 addFunctionPass(FixIrreduciblePass(), PMW);
2494 addFunctionPass(UnifyLoopExitsPass(), PMW);
2495 addFunctionPass(StructurizeCFGPass(/*SkipUniformRegions=*/true), PMW);
2496
2497 addFunctionPass(AMDGPUAnnotateUniformValuesPass(), PMW);
2498
2499 addFunctionPass(SIAnnotateControlFlowPass(getTM()), PMW);
2500
2501 // TODO: Move this right after structurizeCFG to avoid extra divergence
2502 // analysis. This depends on stopping SIAnnotateControlFlow from making
2503 // control flow modifications.
2504 addFunctionPass(AMDGPURewriteUndefForPHIPass(), PMW);
2505
2508 !isGlobalISelAbortEnabled())
2509 addFunctionPass(LCSSAPass(), PMW);
2510
2511 if (TM.getOptLevel() > CodeGenOptLevel::Less) {
2512 flushFPMsToMPM(PMW);
2513 addModulePass(AMDGPUPerfHintAnalysisPass(getTM()), PMW);
2514 }
2515}
2516
2517void AMDGPUCodeGenPassBuilder::addILPOpts(PassManagerWrapper &PMW) {
2519 addMachineFunctionPass(EarlyIfConverterPass(), PMW);
2520
2521 Base::addILPOpts(PMW);
2522}
2523
2524void AMDGPUCodeGenPassBuilder::addAsmPrinterBegin(PassManagerWrapper &PMW) {
2525 addModulePass(AMDGPUAsmPrinterBeginPass(), PMW,
2526 /*Force=*/true);
2527}
2528
2529void AMDGPUCodeGenPassBuilder::addAsmPrinter(PassManagerWrapper &PMW) {
2530 addMachineFunctionPass(AMDGPUAsmPrinterPass(), PMW);
2531}
2532
2533void AMDGPUCodeGenPassBuilder::addAsmPrinterEnd(PassManagerWrapper &PMW) {
2534 addModulePass(AMDGPUAsmPrinterEndPass(), PMW);
2535}
2536
2537Error AMDGPUCodeGenPassBuilder::addInstSelector(PassManagerWrapper &PMW) {
2538 addMachineFunctionPass(AMDGPUISelDAGToDAGPass(TM), PMW);
2539 addMachineFunctionPass(SIFixSGPRCopiesPass(), PMW);
2540 addMachineFunctionPass(SILowerI1CopiesPass(), PMW);
2541 return Error::success();
2542}
2543
2544Error AMDGPUCodeGenPassBuilder::addIRTranslator(PassManagerWrapper &PMW) {
2545 addMachineFunctionPass(IRTranslatorPass(getOptLevel()), PMW);
2546 return Error::success();
2547}
2548
2549void AMDGPUCodeGenPassBuilder::addPreLegalizeMachineIR(
2550 PassManagerWrapper &PMW) {
2551 addMachineFunctionPass(AMDGPUPreLegalizerCombinerPass(), PMW);
2552 addMachineFunctionPass(LocalizerPass(), PMW);
2553}
2554
2555Error AMDGPUCodeGenPassBuilder::addLegalizeMachineIR(PassManagerWrapper &PMW) {
2556 addMachineFunctionPass(LegalizerPass(), PMW);
2557 return Error::success();
2558}
2559
2560void AMDGPUCodeGenPassBuilder::addPreRegBankSelect(PassManagerWrapper &PMW) {
2561 addMachineFunctionPass(AMDGPUPostLegalizerCombinerPass(), PMW);
2562 addMachineFunctionPass(AMDGPUGlobalISelDivergenceLoweringPass(), PMW);
2563}
2564
2565Error AMDGPUCodeGenPassBuilder::addRegBankSelect(PassManagerWrapper &PMW) {
2566 addMachineFunctionPass(AMDGPURegBankSelectPass(), PMW);
2567 addMachineFunctionPass(AMDGPURegBankLegalizePass(), PMW);
2568 return Error::success();
2569}
2570
2571void AMDGPUCodeGenPassBuilder::addPreGlobalInstructionSelect(
2572 PassManagerWrapper &PMW) {
2573 bool IsOptLevelNone = getOptLevel() == CodeGenOptLevel::None;
2574 addMachineFunctionPass(AMDGPURegBankCombinerPass(IsOptLevelNone), PMW);
2575}
2576
2577Error AMDGPUCodeGenPassBuilder::addGlobalInstructionSelect(
2578 PassManagerWrapper &PMW) {
2579 addMachineFunctionPass(InstructionSelectPass(getOptLevel()), PMW);
2580 return Error::success();
2581}
2582
2583void AMDGPUCodeGenPassBuilder::addPreRewrite(PassManagerWrapper &PMW) {
2584 if (EnableRegReassign) {
2585 addMachineFunctionPass(GCNNSAReassignPass(), PMW);
2586 }
2587
2588 addMachineFunctionPass(AMDGPURewriteAGPRCopyMFMAPass(), PMW);
2589}
2590
2591void AMDGPUCodeGenPassBuilder::addMachineSSAOptimization(
2592 PassManagerWrapper &PMW) {
2593 Base::addMachineSSAOptimization(PMW);
2594
2595 addMachineFunctionPass(SIFoldOperandsPass(), PMW);
2596 if (EnableDPPCombine) {
2597 addMachineFunctionPass(GCNDPPCombinePass(), PMW);
2598 }
2599 addMachineFunctionPass(SILoadStoreOptimizerPass(), PMW);
2600 if (isPassEnabled(EnableSDWAPeephole)) {
2601 addMachineFunctionPass(SIPeepholeSDWAPass(), PMW);
2602 addMachineFunctionPass(EarlyMachineLICMPass(), PMW);
2603 addMachineFunctionPass(MachineCSEPass(), PMW);
2604 addMachineFunctionPass(SIFoldOperandsPass(), PMW);
2605 }
2606 addMachineFunctionPass(DeadMachineInstructionElimPass(), PMW);
2607 addMachineFunctionPass(SIShrinkInstructionsPass(), PMW);
2608}
2609
2610Error AMDGPUCodeGenPassBuilder::addFastRegAlloc(PassManagerWrapper &PMW) {
2611 insertPass<PHIEliminationPass>(SILowerControlFlowPass());
2612
2613 insertPass<TwoAddressInstructionPass>(SIWholeQuadModePass());
2614
2615 return Base::addFastRegAlloc(PMW);
2616}
2617
2618Error AMDGPUCodeGenPassBuilder::addRegAssignAndRewriteFast(
2619 PassManagerWrapper &PMW) {
2620 if (auto Err = validateRegAllocOptions())
2621 return Err;
2622
2623 addMachineFunctionPass(GCNPreRALongBranchRegPass(), PMW);
2624
2625 // SGPR allocation - default to fast at -O0.
2626 if (SGPRRegAllocNPM == RegAllocType::Greedy)
2627 addMachineFunctionPass(RAGreedyPass({onlyAllocateSGPRs, "sgpr"}), PMW);
2628 else
2629 addMachineFunctionPass(RegAllocFastPass({onlyAllocateSGPRs, "sgpr", false}),
2630 PMW);
2631
2632 // Equivalent of PEI for SGPRs.
2633 addMachineFunctionPass(SILowerSGPRSpillsPass(), PMW);
2634
2635 // To Allocate wwm registers used in whole quad mode operations (for shaders).
2636 addMachineFunctionPass(SIPreAllocateWWMRegsPass(), PMW);
2637
2638 // WWM allocation - default to fast at -O0.
2639 if (WWMRegAllocNPM == RegAllocType::Greedy)
2640 addMachineFunctionPass(RAGreedyPass({onlyAllocateWWMRegs, "wwm"}), PMW);
2641 else
2642 addMachineFunctionPass(
2643 RegAllocFastPass({onlyAllocateWWMRegs, "wwm", false}), PMW);
2644
2645 addMachineFunctionPass(SILowerWWMCopiesPass(), PMW);
2646 addMachineFunctionPass(AMDGPUReserveWWMRegsPass(), PMW);
2647
2648 // VGPR allocation - default to fast at -O0.
2649 if (VGPRRegAllocNPM == RegAllocType::Greedy)
2650 addMachineFunctionPass(RAGreedyPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2651 else
2652 addMachineFunctionPass(RegAllocFastPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2653
2654 return Error::success();
2655}
2656
2657Error AMDGPUCodeGenPassBuilder::addOptimizedRegAlloc(PassManagerWrapper &PMW) {
2658 if (EnableDCEInRA)
2659 insertPass<DetectDeadLanesPass>(DeadMachineInstructionElimPass());
2660
2661 if (OptVGPRLiveRange)
2662 insertPass<RequireAnalysisPass<MachineLoopAnalysis, MachineFunction>>(
2664
2665 // This must be run immediately after phi elimination and before
2666 // TwoAddressInstructions, otherwise the processing of the tied operand of
2667 // SI_ELSE will introduce a copy of the tied operand source after the else.
2668 insertPass<PHIEliminationPass>(SILowerControlFlowPass());
2669
2671 insertPass<RenameIndependentSubregsPass>(GCNRewritePartialRegUsesPass());
2672
2673 if (isPassEnabled(EnablePreRAOptimizations))
2674 insertPass<MachineSchedulerPass>(GCNPreRAOptimizationsPass());
2675
2676 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
2677 // instructions that cause scheduling barriers.
2678 insertPass<MachineSchedulerPass>(SIWholeQuadModePass());
2679
2680 if (OptExecMaskPreRA)
2681 insertPass<MachineSchedulerPass>(SIOptimizeExecMaskingPreRAPass());
2682
2683 // This is not an essential optimization and it has a noticeable impact on
2684 // compilation time, so we only enable it from O2.
2685 if (TM.getOptLevel() > CodeGenOptLevel::Less)
2686 insertPass<MachineSchedulerPass>(SIFormMemoryClausesPass());
2687
2688 return Base::addOptimizedRegAlloc(PMW);
2689}
2690
2691void AMDGPUCodeGenPassBuilder::addPreRegAlloc(PassManagerWrapper &PMW) {
2692 if (getOptLevel() != CodeGenOptLevel::None)
2693 addMachineFunctionPass(AMDGPUPrepareAGPRAllocPass(), PMW);
2694 if (getOptLevel() >= CodeGenOptLevel::Default && EnableMachinePipeliner)
2695 addMachineFunctionPass(MachinePipelinerPass(), PMW);
2696}
2697
2698Expected<bool> AMDGPUCodeGenPassBuilder::addRegAssignAndRewriteOptimized(
2699 PassManagerWrapper &PMW) {
2700 if (auto Err = validateRegAllocOptions())
2701 return Err;
2702
2703 addMachineFunctionPass(GCNPreRALongBranchRegPass(), PMW);
2704
2705 // SGPR allocation - default to greedy at -O1 and above.
2706 if (SGPRRegAllocNPM == RegAllocType::Fast)
2707 addMachineFunctionPass(RegAllocFastPass({onlyAllocateSGPRs, "sgpr", false}),
2708 PMW);
2709 else
2710 addMachineFunctionPass(RAGreedyPass({onlyAllocateSGPRs, "sgpr"}), PMW);
2711
2712 // Commit allocated register changes. This is mostly necessary because too
2713 // many things rely on the use lists of the physical registers, such as the
2714 // verifier. This is only necessary with allocators which use LiveIntervals,
2715 // since FastRegAlloc does the replacements itself.
2716 addMachineFunctionPass(VirtRegRewriterPass(false), PMW);
2717
2718 // At this point, the sgpr-regalloc has been done and it is good to have the
2719 // stack slot coloring to try to optimize the SGPR spill stack indices before
2720 // attempting the custom SGPR spill lowering.
2721 addMachineFunctionPass(StackSlotColoringPass(), PMW);
2722
2723 // Equivalent of PEI for SGPRs.
2724 addMachineFunctionPass(SILowerSGPRSpillsPass(), PMW);
2725
2726 // To Allocate wwm registers used in whole quad mode operations (for shaders).
2727 addMachineFunctionPass(SIPreAllocateWWMRegsPass(), PMW);
2728
2729 // WWM allocation - default to greedy at -O1 and above.
2730 if (WWMRegAllocNPM == RegAllocType::Fast)
2731 addMachineFunctionPass(
2732 RegAllocFastPass({onlyAllocateWWMRegs, "wwm", false}), PMW);
2733 else
2734 addMachineFunctionPass(RAGreedyPass({onlyAllocateWWMRegs, "wwm"}), PMW);
2735 addMachineFunctionPass(SILowerWWMCopiesPass(), PMW);
2736 addMachineFunctionPass(VirtRegRewriterPass(false), PMW);
2737 addMachineFunctionPass(AMDGPUReserveWWMRegsPass(), PMW);
2738
2739 // VGPR allocation - default to greedy at -O1 and above.
2740 if (VGPRRegAllocNPM == RegAllocType::Fast)
2741 addMachineFunctionPass(RegAllocFastPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2742 else
2743 addMachineFunctionPass(RAGreedyPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2744
2745 addPreRewrite(PMW);
2746 addMachineFunctionPass(VirtRegRewriterPass(true), PMW);
2747
2748 addMachineFunctionPass(AMDGPUMarkLastScratchLoadPass(), PMW);
2749 return true;
2750}
2751
2752void AMDGPUCodeGenPassBuilder::addPostRegAlloc(PassManagerWrapper &PMW) {
2753 addMachineFunctionPass(SIFixVGPRCopiesPass(), PMW);
2754 if (TM.getOptLevel() > CodeGenOptLevel::None)
2755 addMachineFunctionPass(SIOptimizeExecMaskingPass(), PMW);
2756 Base::addPostRegAlloc(PMW);
2757}
2758
2759void AMDGPUCodeGenPassBuilder::addPreSched2(PassManagerWrapper &PMW) {
2760 if (TM.getOptLevel() > CodeGenOptLevel::None)
2761 addMachineFunctionPass(SIShrinkInstructionsPass(), PMW);
2762 addMachineFunctionPass(SIPostRABundlerPass(), PMW);
2763}
2764
2765void AMDGPUCodeGenPassBuilder::addPostBBSections(PassManagerWrapper &PMW) {
2766 // We run this later to avoid passes like livedebugvalues and BBSections
2767 // having to deal with the apparent multi-entry functions we may generate.
2768 addMachineFunctionPass(AMDGPUPreloadKernArgPrologPass(), PMW);
2769}
2770
2771void AMDGPUCodeGenPassBuilder::addPreEmitPass(PassManagerWrapper &PMW) {
2772 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less)) {
2773 addMachineFunctionPass(GCNCreateVOPDPass(), PMW);
2774 }
2775
2776 addMachineFunctionPass(SIMemoryLegalizerPass(), PMW);
2777 if (TM.getOptLevel() > CodeGenOptLevel::None)
2778 addMachineFunctionPass(SIPostRA16BitMovFoldingPass(), PMW);
2779 addMachineFunctionPass(SIInsertWaitcntsPass(), PMW);
2780
2781 addMachineFunctionPass(SIModeRegisterPass(), PMW);
2782
2783 if (TM.getOptLevel() > CodeGenOptLevel::None)
2784 addMachineFunctionPass(SIInsertHardClausesPass(), PMW);
2785
2786 addMachineFunctionPass(SILateBranchLoweringPass(), PMW);
2787
2788 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
2789 addMachineFunctionPass(AMDGPUSetWavePriorityPass(), PMW);
2790
2791 if (TM.getOptLevel() > CodeGenOptLevel::None)
2792 addMachineFunctionPass(SIPreEmitPeepholePass(), PMW);
2793
2794 // The hazard recognizer that runs as part of the post-ra scheduler does not
2795 // guarantee to be able handle all hazards correctly. This is because if there
2796 // are multiple scheduling regions in a basic block, the regions are scheduled
2797 // bottom up, so when we begin to schedule a region we don't know what
2798 // instructions were emitted directly before it.
2799 //
2800 // Here we add a stand-alone hazard recognizer pass which can handle all
2801 // cases.
2802 addMachineFunctionPass(PostRAHazardRecognizerPass(), PMW);
2803 addMachineFunctionPass(AMDGPUWaitSGPRHazardsPass(), PMW);
2804 addMachineFunctionPass(AMDGPULowerVGPREncodingPass(), PMW);
2805
2806 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less)) {
2807 addMachineFunctionPass(AMDGPUInsertDelayAluPass(), PMW);
2808 }
2809
2810 addMachineFunctionPass(BranchRelaxationPass(), PMW);
2811}
2812
2813bool AMDGPUCodeGenPassBuilder::isPassEnabled(const cl::opt<bool> &Opt,
2814 CodeGenOptLevel Level) const {
2815 if (Opt.getNumOccurrences())
2816 return Opt;
2817 if (TM.getOptLevel() < Level)
2818 return false;
2819 return Opt;
2820}
2821
2822void AMDGPUCodeGenPassBuilder::addEarlyCSEOrGVNPass(PassManagerWrapper &PMW) {
2823 if (TM.getOptLevel() == CodeGenOptLevel::Aggressive)
2824 addFunctionPass(GVNPass(), PMW);
2825 else
2826 addFunctionPass(EarlyCSEPass(), PMW);
2827}
2828
2829void AMDGPUCodeGenPassBuilder::addStraightLineScalarOptimizationPasses(
2830 PassManagerWrapper &PMW) {
2832 addFunctionPass(LoopDataPrefetchPass(), PMW);
2833
2834 addFunctionPass(SeparateConstOffsetFromGEPPass(), PMW);
2835
2836 // ReassociateGEPs exposes more opportunities for SLSR. See
2837 // the example in reassociate-geps-and-slsr.ll.
2838 addFunctionPass(StraightLineStrengthReducePass(), PMW);
2839
2840 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
2841 // EarlyCSE can reuse.
2842 addEarlyCSEOrGVNPass(PMW);
2843
2844 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
2845 addFunctionPass(NaryReassociatePass(), PMW);
2846
2847 // NaryReassociate on GEPs creates redundant common expressions, so run
2848 // EarlyCSE after it.
2849 addFunctionPass(EarlyCSEPass(), PMW);
2850}
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 cl::opt< bool > EnableMachinePipeliner("aarch64-enable-pipeliner", cl::desc("Enable Machine Pipeliner for AArch64"), cl::init(false), cl::Hidden)
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:857
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:328
#define LLVM_ABI
Definition Compiler.h:215
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
Analysis that tracks defined/used subregister lanes across COPY instructions and instructions that ge...
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.
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.
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.
bool isNoopAddrSpaceCast(const DataLayout &DL, unsigned SrcAS, unsigned DestAS) const override
Returns true if a cast between SrcAS and DestAS is a noop.
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)
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:106
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:266
This class provides access to building LLVM's passes.
CodeGenTargetMachineImpl(const Target &T, 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.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
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.
const TargetSubtargetInfo * getSubtargetImpl(const Function &) const override
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
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.
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:40
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:68
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:305
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:148
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition SourceMgr.h:141
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
const DataLayout DL
DataLayout for the target: keep ABI type size and alignment.
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:348
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:720
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 &)
char & SILowerControlFlowLegacyID
void initializeAMDGPURegBankCombinerLegacyPass(PassRegistry &)
LLVM_ABI Pass * createLoadStoreVectorizerPass()
Create a legacy pass manager instance of the LoadStoreVectorizer pass.
FunctionPass * createAMDGPURegBankCombinerLegacy(bool IsOptLevelNone)
void initializeAMDGPUPostLegalizerCombinerLegacyPass(PassRegistry &)
std::unique_ptr< ScheduleDAGMutation > createIGroupLPDAGMutation(AMDGPU::SchedulingPhase Phase)
Phase specifes whether or not this is a reentry into the IGroupLPDAGMutation.
void initializeAMDGPUDAGToDAGISelLegacyPass(PassRegistry &)
char & AMDGPUReserveWWMRegsLegacyID
LLVM_ABI FunctionPass * createNaryReassociatePass()
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.
FunctionPass * createAMDGPUPostLegalizeCombinerLegacy(bool IsOptNone)
void initializeAMDGPUNextUseAnalysisLegacyPassPass(PassRegistry &)
void initializeR600ExpandSpecialInstrsPassPass(PassRegistry &)
void initializeR600PacketizerPass(PassRegistry &)
void initializeAMDGPURegBankSelectLegacyPass(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 &)
void initializeAMDGPURegBankLegalizeLegacyPass(PassRegistry &)
char & SILoadStoreOptimizerLegacyID
void initializeAMDGPUPreLegalizerCombinerLegacyPass(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:381
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()
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()
LLVM_ABI char & MachineLoopInfoID
MachineLoopInfo - This pass is a loop analysis pass.
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.
char & SIPostRA16BitMovFoldingLegacyID
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:256
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 &)
ScheduleDAGInstrs * createGCNNoopPostMachineScheduler(MachineSchedContext *C)
void initializeAMDGPUExportKernelRuntimeHandlesLegacyPass(PassRegistry &)
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:227
@ Default
-O2, -Os, -Oz
Definition CodeGen.h:230
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)
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.
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 char & MachinePipelinerID
This pass performs software pipelining on machine instructions.
LLVM_ABI FunctionPass * createGVNPass()
Definition GVN.cpp:4442
void initializeAMDGPURewriteAGPRCopyMFMALegacyPass(PassRegistry &)
void initializeAMDGPUNextUseAnalysisPrinterLegacyPassPass(PassRegistry &)
void initializeSIPostRABundlerLegacyPass(PassRegistry &)
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.
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 * createAMDGPURegBankSelectLegacyPass()
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 * createAMDGPUPreLegalizeCombinerLegacyPass(bool IsOptLevelNone)
FunctionPass * createSIMemoryLegalizerPass()
void initializeAMDGPULateCodeGenPrepareLegacyPass(PassRegistry &)
void initializeSIOptimizeVGPRLiveRangeLegacyPass(PassRegistry &)
void initializeSIPeepholeSDWALegacyPass(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 * createAMDGPULateCodeGenPrepareLegacyPass()
LLVM_ABI FunctionPass * createAtomicExpandLegacyPass()
AtomicExpandPass - At IR level this pass replace atomic instructions with __atomic_* library calls,...
void initializeAMDGPUGlobalISelDivergenceLoweringLegacyPass(PassRegistry &)
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
void initializeSIPostRA16BitMovFoldingLegacyPass(PassRegistry &)
FunctionPass * createAMDGPURegBankLegalizeLegacyPass()
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.