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,
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,
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,
238 const Register Reg) {
239 const SIMachineFunctionInfo *MFI =
240 MRI.getMF().getInfo<SIMachineFunctionInfo>();
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 run internalize pass.
451 "amdgpu-internalize-symbols",
452 cl::desc("Enable elimination of non-kernel functions and unused globals"),
453 cl::init(false),
454 cl::Hidden);
455
456// Option to inline all early.
458 "amdgpu-early-inline-all",
459 cl::desc("Inline all functions early"),
460 cl::init(false),
461 cl::Hidden);
462
464 "amdgpu-enable-remove-incompatible-functions", cl::Hidden,
465 cl::desc("Enable removal of functions when they"
466 "use features not supported by the target GPU"),
467 cl::init(true));
468
470 "amdgpu-sdwa-peephole",
471 cl::desc("Enable SDWA peepholer"),
472 cl::init(true));
473
475 "amdgpu-dpp-combine",
476 cl::desc("Enable DPP combiner"),
477 cl::init(true));
478
479// Enable address space based alias analysis
481 cl::desc("Enable AMDGPU Alias Analysis"),
482 cl::init(true));
483
484static cl::opt<bool>
485 XnackSetting("amdgpu-xnack",
486 cl::desc("Force amdgpu.xnack value for testing"),
488
489static cl::opt<bool>
490 SramEccSetting("amdgpu-sramecc",
491 cl::desc("Force amdgpu.sramecc for testing"),
493
494// Enable lib calls simplifications
496 "amdgpu-simplify-libcall",
497 cl::desc("Enable amdgpu library simplifications"),
498 cl::init(true),
499 cl::Hidden);
500
502 "amdgpu-ir-lower-kernel-arguments",
503 cl::desc("Lower kernel argument loads in IR pass"),
504 cl::init(true),
505 cl::Hidden);
506
508 "amdgpu-reassign-regs",
509 cl::desc("Enable register reassign optimizations on gfx10+"),
510 cl::init(true),
511 cl::Hidden);
512
514 "amdgpu-opt-vgpr-liverange",
515 cl::desc("Enable VGPR liverange optimizations for if-else structure"),
516 cl::init(true), cl::Hidden);
517
519 "amdgpu-atomic-optimizer-strategy",
520 cl::desc("Select DPP or Iterative strategy for scan"),
523 clEnumValN(ScanOptions::DPP, "DPP", "Use DPP operations for scan"),
525 "Use Iterative approach for scan"),
526 clEnumValN(ScanOptions::None, "None", "Disable atomic optimizer")));
527
528// Enable Mode register optimization
530 "amdgpu-mode-register",
531 cl::desc("Enable mode register pass"),
532 cl::init(true),
533 cl::Hidden);
534
535// Enable GFX11+ s_delay_alu insertion
536static cl::opt<bool>
537 EnableInsertDelayAlu("amdgpu-enable-delay-alu",
538 cl::desc("Enable s_delay_alu insertion"),
539 cl::init(true), cl::Hidden);
540
541// Enable GFX11+ VOPD
542static cl::opt<bool>
543 EnableVOPD("amdgpu-enable-vopd",
544 cl::desc("Enable VOPD, dual issue of VALU in wave32"),
545 cl::init(true), cl::Hidden);
546
547// Option is used in lit tests to prevent deadcoding of patterns inspected.
548static cl::opt<bool>
549EnableDCEInRA("amdgpu-dce-in-ra",
550 cl::init(true), cl::Hidden,
551 cl::desc("Enable machine DCE inside regalloc"));
552
553static cl::opt<bool> EnableSetWavePriority("amdgpu-set-wave-priority",
554 cl::desc("Adjust wave priority"),
555 cl::init(false), cl::Hidden);
556
558 "amdgpu-scalar-ir-passes",
559 cl::desc("Enable scalar IR passes"),
560 cl::init(true),
561 cl::Hidden);
562
564 "amdgpu-enable-lower-exec-sync",
565 cl::desc("Enable lowering of execution synchronization."), cl::init(true),
566 cl::Hidden);
567
568static cl::opt<bool>
569 EnableSwLowerLDS("amdgpu-enable-sw-lower-lds",
570 cl::desc("Enable lowering of lds to global memory pass "
571 "and asan instrument resulting IR."),
572 cl::init(true), cl::Hidden);
573
575 "amdgpu-enable-object-linking",
576 cl::desc("Enable object linking for cross-TU LDS and ABI support"),
578 cl::Hidden);
579
581 "amdgpu-enable-lower-module-lds", cl::desc("Enable lower module lds pass"),
583 cl::Hidden);
584
586 "amdgpu-enable-pre-ra-optimizations",
587 cl::desc("Enable Pre-RA optimizations pass"), cl::init(true),
588 cl::Hidden);
589
591 "amdgpu-enable-promote-kernel-arguments",
592 cl::desc("Enable promotion of flat kernel pointer arguments to global"),
593 cl::Hidden, cl::init(true));
594
596 "amdgpu-enable-image-intrinsic-optimizer",
597 cl::desc("Enable image intrinsic optimizer pass"), cl::init(true),
598 cl::Hidden);
599
600static cl::opt<bool>
601 EnableLoopPrefetch("amdgpu-loop-prefetch",
602 cl::desc("Enable loop data prefetch on AMDGPU"),
603 cl::Hidden, cl::init(false));
604
606 AMDGPUSchedStrategy("amdgpu-sched-strategy",
607 cl::desc("Select custom AMDGPU scheduling strategy."),
608 cl::Hidden, cl::init(""));
609
610// Scheduler selection is consulted both when creating the scheduler and from
611// overrideSchedPolicy(), so keep the attribute and global command line handling
612// in one helper.
614 Attribute SchedStrategyAttr = F.getFnAttribute("amdgpu-sched-strategy");
615 if (SchedStrategyAttr.isValid())
616 return SchedStrategyAttr.getValueAsString();
617
618 if (!AMDGPUSchedStrategy.empty())
619 return AMDGPUSchedStrategy;
620
621 return "";
622}
623
624static void
626 const GCNSubtarget &ST) {
627 if (ST.hasGFX1250Insts() || ST.hasGFX950Insts())
628 return;
629
630 F.getContext().diagnose(DiagnosticInfoUnsupported(
631 F,
632 "'amdgpu-sched-strategy'='coexec' is only supported for gfx1250/gfx950",
634}
635
636static bool useNoopPostScheduler(const Function &F) {
637 Attribute PostSchedStrategyAttr =
638 F.getFnAttribute("amdgpu-post-sched-strategy");
639 return PostSchedStrategyAttr.isValid() &&
640 PostSchedStrategyAttr.getValueAsString() == "nop";
641}
642
644 "amdgpu-enable-rewrite-partial-reg-uses",
645 cl::desc("Enable rewrite partial reg uses pass"), cl::init(true),
646 cl::Hidden);
647
649 "amdgpu-enable-hipstdpar",
650 cl::desc("Enable HIP Standard Parallelism Offload support"), cl::init(false),
651 cl::Hidden);
652
653static cl::opt<bool>
654 EnableAMDGPUAttributor("amdgpu-attributor-enable",
655 cl::desc("Enable AMDGPUAttributorPass"),
656 cl::init(true), cl::Hidden);
657
659 "amdgpu-link-time-closed-world",
660 cl::desc("Whether has closed-world assumption at link time"),
661 cl::init(false), cl::Hidden);
662
664 "amdgpu-enable-uniform-intrinsic-combine",
665 cl::desc("Enable/Disable the Uniform Intrinsic Combine Pass"),
666 cl::init(true), cl::Hidden);
667
668static cl::opt<bool>
669 UseSSAMachineScheduler("amdgpu-use-ssa-machine-scheduler",
670 cl::desc("Use the machine scheduler in SSA mode."),
671 cl::init(false), cl::Hidden);
672
674 // Register the target
678
765}
766
767static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
768 return std::make_unique<AMDGPUTargetObjectFile>();
769}
770
774
775static ScheduleDAGInstrs *
777 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
778 ScheduleDAGMILive *DAG =
779 new GCNScheduleDAGMILive(C, std::make_unique<GCNMaxOccupancySchedStrategy>(C));
780 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII));
781 if (ST.shouldClusterStores())
782 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII));
784 DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
785 DAG->addMutation(createAMDGPUExportClusteringDAGMutation());
786 DAG->addMutation(createAMDGPUBarrierLatencyDAGMutation(C->MF));
787 DAG->addMutation(createAMDGPUHazardLatencyDAGMutation(C->MF));
788 return DAG;
789}
790
791static ScheduleDAGInstrs *
793 ScheduleDAGMILive *DAG =
794 new GCNScheduleDAGMILive(C, std::make_unique<GCNMaxILPSchedStrategy>(C));
796 return DAG;
797}
798
799static ScheduleDAGInstrs *
801 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
803 C, std::make_unique<GCNMaxMemoryClauseSchedStrategy>(C));
804 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII));
805 if (ST.shouldClusterStores())
806 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII));
807 DAG->addMutation(createAMDGPUExportClusteringDAGMutation());
808 DAG->addMutation(createAMDGPUBarrierLatencyDAGMutation(C->MF));
809 DAG->addMutation(createAMDGPUHazardLatencyDAGMutation(C->MF));
810 return DAG;
811}
812
813static ScheduleDAGInstrs *
815 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
816 auto *DAG = new GCNIterativeScheduler(
818 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII));
819 if (ST.shouldClusterStores())
820 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII));
822 return DAG;
823}
824
831
832static ScheduleDAGInstrs *
834 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
836 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII));
837 if (ST.shouldClusterStores())
838 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII));
839 DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
841 return DAG;
842}
843
844static MachineSchedRegistry
845SISchedRegistry("si", "Run SI's custom scheduler",
847
850 "Run GCN scheduler to maximize occupancy",
852
854 GCNMaxILPSchedRegistry("gcn-max-ilp", "Run GCN scheduler to maximize ilp",
856
858 "gcn-max-memory-clause", "Run GCN scheduler to maximize memory clause",
860
862 "gcn-iterative-max-occupancy-experimental",
863 "Run GCN scheduler to maximize occupancy (experimental)",
865
867 "gcn-iterative-minreg",
868 "Run GCN iterative scheduler for minimal register usage (experimental)",
870
872 "gcn-iterative-ilp",
873 "Run GCN iterative scheduler for ILP scheduling (experimental)",
875
878 if (!GPU.empty())
879 return GPU;
880
881 if (StringRef Name = AMDGPU::getArchNameFromSubArch(TT.getSubArch());
882 !Name.empty())
883 return Name;
884
885 // Need to default to a target with flat support for HSA.
886 if (TT.isAMDGCN())
887 return TT.getOS() == Triple::AMDHSA ? "generic-hsa" : "generic";
888
889 return "r600";
890}
891
893 // The AMDGPU toolchain only supports generating shared objects, so we
894 // must always use PIC.
895 return Reloc::PIC_;
896}
897
899 StringRef CPU, StringRef FS,
900 const TargetOptions &Options,
901 std::optional<Reloc::Model> RM,
902 std::optional<CodeModel::Model> CM,
907 OptLevel),
909 initAsmInfo();
910 if (TT.isAMDGCN()) {
911 // Triple is missing a representation for non-empty, but unrecognized
912 // subarches. Only permit no subarch for any subtarget if it was really
913 // empty.
914 bool IsUnknownSubArch =
915 TT.getSubArch() == Triple::NoSubArch && TT.getArchName().size() != 6;
916 if (IsUnknownSubArch)
917 reportFatalUsageError("unknown subarch " + TT.getArchName());
918
919 if (TT.getSubArch() != Triple::NoSubArch) {
921 Triple::SubArchType GPUSubArch = AMDGPU::getSubArch(Kind);
922 if (Kind != AMDGPU::GK_NONE && GPUSubArch != TT.getSubArch() &&
923 TT.getSubArch() != AMDGPU::getMajorSubArch(GPUSubArch)) {
924 reportFatalUsageError("invalid cpu '" + CPU + "' for subarch " +
925 TT.getArchName());
926 }
927 }
928
929 if (getMCSubtargetInfo().checkFeatures("+wavefrontsize64"))
931 else if (getMCSubtargetInfo().checkFeatures("+wavefrontsize32"))
933 }
935}
936
940
942
944 Attribute GPUAttr = F.getFnAttribute("target-cpu");
945 return GPUAttr.isValid() ? GPUAttr.getValueAsString() : getTargetCPU();
946}
947
949 Attribute FSAttr = F.getFnAttribute("target-features");
950
951 return FSAttr.isValid() ? FSAttr.getValueAsString()
953}
954
957 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
959 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII));
960 if (ST.shouldClusterStores())
961 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII));
962 return DAG;
963}
964
965/// Predicate for Internalize pass.
966static bool mustPreserveGV(const GlobalValue &GV) {
967 if (const Function *F = dyn_cast<Function>(&GV))
968 return F->isDeclaration() || F->getName().starts_with("__asan_") ||
969 F->getName().starts_with("__sanitizer_") ||
970 AMDGPU::isEntryFunctionCC(F->getCallingConv());
971
973 return !GV.use_empty();
974}
975
980
983 if (Params.empty())
985 Params.consume_front("strategy=");
986 auto Result = StringSwitch<std::optional<ScanOptions>>(Params)
987 .Case("dpp", ScanOptions::DPP)
988 .Cases({"iterative", ""}, ScanOptions::Iterative)
989 .Case("none", ScanOptions::None)
990 .Default(std::nullopt);
991 if (Result)
992 return *Result;
993 return make_error<StringError>("invalid parameter", inconvertibleErrorCode());
994}
995
999 while (!Params.empty()) {
1000 StringRef ParamName;
1001 std::tie(ParamName, Params) = Params.split(';');
1002 if (ParamName == "closed-world") {
1003 Result.IsClosedWorld = true;
1004 } else {
1006 formatv("invalid AMDGPUAttributor pass parameter '{0}' ", ParamName)
1007 .str(),
1009 }
1010 }
1011 return Result;
1012}
1013
1015
1016#define GET_PASS_REGISTRY "AMDGPUPassRegistry.def"
1018
1019 PB.registerPipelineParsingCallback(
1020 [this](StringRef Name, CGSCCPassManager &PM,
1022 if (Name == "amdgpu-attributor-cgscc" && getTargetTriple().isAMDGCN()) {
1024 *static_cast<GCNTargetMachine *>(this)));
1025 return true;
1026 }
1027 return false;
1028 });
1029
1030 PB.registerScalarOptimizerLateEPCallback(
1031 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1032 if (Level == OptimizationLevel::O0)
1033 return;
1034
1036 });
1037
1038 PB.registerVectorizerEndEPCallback(
1039 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1040 if (Level == OptimizationLevel::O0)
1041 return;
1042
1044 });
1045
1046 PB.registerPipelineEarlySimplificationEPCallback(
1047 [this](ModulePassManager &PM, OptimizationLevel Level,
1049 if (!isLTOPreLink(Phase) && getTargetTriple().isAMDGCN()) {
1050 // When we are not using -fgpu-rdc, we can run accelerator code
1051 // selection relatively early, but still after linking to prevent
1052 // eager removal of potentially reachable symbols.
1053 if (EnableHipStdPar) {
1056 }
1057
1059 }
1060
1061 if (Level == OptimizationLevel::O0)
1062 return;
1063
1064 // We don't want to run internalization at per-module stage.
1067 PM.addPass(GlobalDCEPass());
1068 }
1069
1072 });
1073
1074 PB.registerPeepholeEPCallback(
1075 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1076 if (Level == OptimizationLevel::O0)
1077 return;
1078
1082
1085 });
1086
1087 PB.registerCGSCCOptimizerLateEPCallback(
1088 [this](CGSCCPassManager &PM, OptimizationLevel Level) {
1089 if (Level == OptimizationLevel::O0)
1090 return;
1091
1093
1094 // Add promote kernel arguments pass to the opt pipeline right before
1095 // infer address spaces which is needed to do actual address space
1096 // rewriting.
1099
1100 // Add infer address spaces pass to the opt pipeline after inlining
1101 // but before SROA to increase SROA opportunities.
1103
1104 // This should run after inlining to have any chance of doing
1105 // anything, and before other cleanup optimizations.
1107
1108 // Promote alloca to vector before SROA and loop unroll. If we
1109 // manage to eliminate allocas before unroll we may choose to unroll
1110 // less.
1112
1113 PM.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
1114 });
1115
1116 // FIXME: Why is AMDGPUAttributor not in CGSCC?
1117 PB.registerOptimizerLastEPCallback([this](ModulePassManager &MPM,
1118 OptimizationLevel Level,
1120 if (Level != OptimizationLevel::O0) {
1121 if (!isLTOPreLink(Phase)) {
1122 if (EnableAMDGPUAttributor && getTargetTriple().isAMDGCN()) {
1124 MPM.addPass(AMDGPUAttributorPass(*this, Opts, Phase));
1125 }
1126 }
1127 }
1128 });
1129
1130 PB.registerFullLinkTimeOptimizationLastEPCallback(
1131 [this](ModulePassManager &PM, OptimizationLevel Level) {
1132 // Clean up redundant memory round-trips that the full-LTO pipeline,
1133 // unlike the non-LTO/ThinLTO ones, otherwise leaves for codegen.
1134 if (Level != OptimizationLevel::O0) {
1136 EarlyCSEPass(/*UseMemorySSA=*/true)));
1137 }
1138
1139 // When we are using -fgpu-rdc, we can only run accelerator code
1140 // selection after linking to prevent, otherwise we end up removing
1141 // potentially reachable symbols that were exported as external in other
1142 // modules.
1143 if (EnableHipStdPar) {
1146 }
1147 // We want to support the -lto-partitions=N option as "best effort".
1148 // For that, we need to lower LDS earlier in the pipeline before the
1149 // module is partitioned for codegen.
1152 if (EnableSwLowerLDS)
1156 if (Level != OptimizationLevel::O0) {
1157 // We only want to run this with O2 or higher since inliner and SROA
1158 // don't run in O1.
1159 if (Level != OptimizationLevel::O1) {
1160 PM.addPass(
1162 }
1163 // Do we really need internalization in LTO?
1164 if (InternalizeSymbols) {
1166 PM.addPass(GlobalDCEPass());
1167 }
1168 if (EnableAMDGPUAttributor && getTargetTriple().isAMDGCN()) {
1171 Opt.IsClosedWorld = true;
1174 }
1175 }
1176 if (!NoKernelInfoEndLTO) {
1178 FPM.addPass(KernelInfoPrinter(this));
1179 PM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1180 }
1181 });
1182
1183 PB.registerRegClassFilterParsingCallback(
1184 [](StringRef FilterName) -> RegAllocFilterFunc {
1185 if (FilterName == "sgpr")
1186 return onlyAllocateSGPRs;
1187 if (FilterName == "vgpr")
1188 return onlyAllocateVGPRs;
1189 if (FilterName == "wwm")
1190 return onlyAllocateWWMRegs;
1191 return nullptr;
1192 });
1193}
1194
1196 unsigned SrcAS,
1197 unsigned DestAS) const {
1198 return AMDGPU::isFlatGlobalAddrSpace(SrcAS) &&
1200}
1201
1203 if (auto *Arg = dyn_cast<Argument>(V);
1204 Arg &&
1205 AMDGPU::isModuleEntryFunctionCC(Arg->getParent()->getCallingConv()) &&
1206 !Arg->hasByRefAttr())
1208
1209 const auto *LD = dyn_cast<LoadInst>(V);
1210 if (!LD) // TODO: Handle invariant load like constant.
1212
1213 // It must be a generic pointer loaded.
1214 assert(V->getType()->getPointerAddressSpace() == AMDGPUAS::FLAT_ADDRESS);
1215
1216 const auto *Ptr = LD->getPointerOperand();
1217 if (Ptr->getType()->getPointerAddressSpace() != AMDGPUAS::CONSTANT_ADDRESS)
1219 // For a generic pointer loaded from the constant memory, it could be assumed
1220 // as a global pointer since the constant memory is only populated on the
1221 // host side. As implied by the offload programming model, only global
1222 // pointers could be referenced on the host side.
1224}
1225
1226std::pair<const Value *, unsigned>
1228 if (auto *II = dyn_cast<IntrinsicInst>(V)) {
1229 switch (II->getIntrinsicID()) {
1230 case Intrinsic::amdgcn_is_shared:
1231 return std::pair(II->getArgOperand(0), AMDGPUAS::LOCAL_ADDRESS);
1232 case Intrinsic::amdgcn_is_private:
1233 return std::pair(II->getArgOperand(0), AMDGPUAS::PRIVATE_ADDRESS);
1234 default:
1235 break;
1236 }
1237 return std::pair(nullptr, -1);
1238 }
1239 // Check the global pointer predication based on
1240 // (!is_share(p) && !is_private(p)). Note that logic 'and' is commutative and
1241 // the order of 'is_shared' and 'is_private' is not significant.
1242 Value *Ptr;
1243 if (match(
1244 const_cast<Value *>(V),
1247 m_Deferred(Ptr))))))
1248 return std::pair(Ptr, AMDGPUAS::GLOBAL_ADDRESS);
1249
1250 return std::pair(nullptr, -1);
1251}
1252
1253unsigned
1268
1270 Module &M, unsigned NumParts,
1271 function_ref<void(std::unique_ptr<Module> MPart)> ModuleCallback) {
1272 // FIXME(?): Would be better to use an already existing Analysis/PassManager,
1273 // but all current users of this API don't have one ready and would need to
1274 // create one anyway. Let's hide the boilerplate for now to keep it simple.
1275
1280
1281 PassBuilder PB(M.getContext(), this);
1282 PB.registerModuleAnalyses(MAM);
1283 PB.registerFunctionAnalyses(FAM);
1284 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
1285
1287 MPM.addPass(AMDGPUSplitModulePass(NumParts, ModuleCallback));
1288 MPM.run(M, MAM);
1289 return true;
1290}
1291
1292//===----------------------------------------------------------------------===//
1293// GCN Target Machine (SI+)
1294//===----------------------------------------------------------------------===//
1295
1297 StringRef CPU, StringRef FS,
1298 const TargetOptions &Options,
1299 std::optional<Reloc::Model> RM,
1300 std::optional<CodeModel::Model> CM,
1301 CodeGenOptLevel OL, bool JIT)
1302 : AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {
1304 // addFastRegAlloc inserts SIWholeQuadMode after TwoAddressInstructionPass.
1306}
1307
1308enum class OOBFlagValue {
1309 Any = 0,
1312};
1313
1314/// Returns the OOB mode encoded by a module flag.
1315/// An absent flag defaults to Any.
1316static OOBFlagValue getOOBFlagValue(const Module &M, StringRef FlagName) {
1317 const auto *Flag =
1318 mdconst::dyn_extract_or_null<ConstantInt>(M.getModuleFlag(FlagName));
1319 if (!Flag)
1320 return OOBFlagValue::Any;
1321 return static_cast<OOBFlagValue>(Flag->getZExtValue());
1322}
1323
1324/// Returns the xnack/sramecc setting encoded by a module flag.
1325/// Module flag values: 0 = disabled, 1 = enabled.
1326/// An absent flag defaults to Any.
1329 StringRef FlagName) {
1331
1332 if (XnackSetting.getNumOccurrences() > 0 && FlagName == "amdgpu.xnack")
1333 return XnackSetting ? TargetIDSetting::On : TargetIDSetting::Off;
1334 if (SramEccSetting.getNumOccurrences() > 0 && FlagName == "amdgpu.sramecc")
1335 return SramEccSetting ? TargetIDSetting::On : TargetIDSetting::Off;
1336
1337 const auto *Flag =
1338 mdconst::dyn_extract_or_null<ConstantInt>(M.getModuleFlag(FlagName));
1339 if (!Flag)
1340 return TargetIDSetting::Any;
1341 return Flag->getZExtValue() == 0 ? TargetIDSetting::Off : TargetIDSetting::On;
1342}
1343
1344const TargetSubtargetInfo *
1346 StringRef GPU = getGPUName(F);
1348
1349 const Module &M = *F.getParent();
1352 bool BufRelaxed = BufOOB == OOBFlagValue::Relaxed;
1353 bool TBufRelaxed = TBufOOB == OOBFlagValue::Relaxed;
1354
1356 TargetIDSetting Xnack = getTargetIDSettingFromModuleFlag(M, "amdgpu.xnack");
1357 TargetIDSetting SramEcc =
1358 getTargetIDSettingFromModuleFlag(M, "amdgpu.sramecc");
1359
1360 SmallString<128> SubtargetKey(GPU);
1361 SubtargetKey.append(FS);
1362 if (BufRelaxed)
1363 SubtargetKey.append(",buf-oob=1");
1364 if (TBufRelaxed)
1365 SubtargetKey.append(",tbuf-oob=1");
1366 if (Xnack != TargetIDSetting::Any) {
1367 SubtargetKey.append(",xnack=");
1368 SubtargetKey.push_back(Xnack == TargetIDSetting::On ? '1' : '0');
1369 }
1370 if (SramEcc != TargetIDSetting::Any) {
1371 SubtargetKey.append(",sramecc=");
1372 SubtargetKey.push_back(SramEcc == TargetIDSetting::On ? '1' : '0');
1373 }
1374
1375 auto &I = SubtargetMap[SubtargetKey];
1376 if (!I) {
1378 Triple::SubArchType GPUSubArch = AMDGPU::getSubArch(Kind);
1379
1380 // Enforce the subtarget is covered by the subarch. Tolerate no subarch for
1381 // legacy compatibility.
1382 const Triple &TT = M.getTargetTriple();
1383 if (GPUSubArch != TT.getSubArch() && Kind != AMDGPU::GK_NONE) {
1384 // Check if this is a generic subarch which has subtargets. Ignore
1385 // unknown subtargets with a known subarch, since for whatever reason
1386 // the convention is to just print a warning and ignore unrecognized
1387 // subtargets.
1388 bool IsLegacyEmptySubArch = TT.getSubArch() == Triple::NoSubArch;
1389 if (!IsLegacyEmptySubArch &&
1390 AMDGPU::getMajorSubArch(GPUSubArch) != TT.getSubArch()) {
1391 F.getContext().emitError("invalid subtarget '" + Twine(GPU) +
1392 "' for subarch " + TT.getArchName());
1393 }
1394 }
1395
1396 I = std::make_unique<GCNSubtarget>(TargetTriple, GPU, FS, *this, BufRelaxed,
1397 TBufRelaxed, Xnack, SramEcc);
1398 }
1399
1400 return I.get();
1401}
1402
1405 return TargetTransformInfo(std::make_unique<GCNTTIImpl>(this, F));
1406}
1407
1410 raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
1411 const CGPassBuilderOption &Opts, MCContext &Ctx,
1413 AMDGPUCodeGenPassBuilder CGPB(*this, Opts, PIC);
1414 return CGPB.buildPipeline(MPM, MAM, Out, DwoOut, FileType, Ctx);
1415}
1416
1419 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
1420 if (ST.enableSIScheduler())
1422
1423 StringRef SchedStrategy = AMDGPU::getSchedStrategy(C->MF->getFunction());
1424
1425 if (SchedStrategy == "max-ilp")
1427
1428 if (SchedStrategy == "max-memory-clause")
1430
1431 if (SchedStrategy == "iterative-ilp")
1433
1434 if (SchedStrategy == "iterative-minreg")
1435 return createMinRegScheduler(C);
1436
1437 if (SchedStrategy == "iterative-maxocc")
1439
1440 if (SchedStrategy == "coexec") {
1441 diagnoseUnsupportedCoExecSchedulerSelection(C->MF->getFunction(), ST);
1443 }
1444
1446}
1447
1450 if (useNoopPostScheduler(C->MF->getFunction()))
1452
1453 ScheduleDAGMI *DAG =
1454 new GCNPostScheduleDAGMILive(C, std::make_unique<PostGenericScheduler>(C),
1455 /*RemoveKillFlags=*/true);
1456 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
1458 if (ST.shouldClusterStores())
1461 if ((EnableVOPD.getNumOccurrences() ||
1463 EnableVOPD)
1468 return DAG;
1469}
1470//===----------------------------------------------------------------------===//
1471// AMDGPU Legacy Pass Setup
1472//===----------------------------------------------------------------------===//
1473
1474std::unique_ptr<CSEConfigBase> llvm::AMDGPUPassConfig::getCSEConfig() const {
1475 return getStandardCSEConfigForOpt(TM->getOptLevel());
1476}
1477
1478namespace {
1479
1480class GCNPassConfig final : public AMDGPUPassConfig {
1481public:
1482 GCNPassConfig(TargetMachine &TM, PassManagerBase &PM)
1483 : AMDGPUPassConfig(TM, PM) {
1484 substitutePass(&PostRASchedulerID, &PostMachineSchedulerID);
1485 }
1486
1487 bool addPreISel() override;
1488 void addMachineSSAOptimization() override;
1489 bool addILPOpts() override;
1490 bool addInstSelector() override;
1491 bool addIRTranslator() override;
1492 void addPreLegalizeMachineIR() override;
1493 bool addLegalizeMachineIR() override;
1494 void addPreRegBankSelect() override;
1495 bool addRegBankSelect() override;
1496 void addPreGlobalInstructionSelect() override;
1497 bool addGlobalInstructionSelect() override;
1498 void addPreRegAlloc() override;
1499 void addFastRegAlloc() override;
1500 void addOptimizedRegAlloc() override;
1501
1502 FunctionPass *createSGPRAllocPass(bool Optimized);
1503 FunctionPass *createVGPRAllocPass(bool Optimized);
1504 FunctionPass *createWWMRegAllocPass(bool Optimized);
1505 FunctionPass *createRegAllocPass(bool Optimized) override;
1506
1507 bool addRegAssignAndRewriteFast() override;
1508 bool addRegAssignAndRewriteOptimized() override;
1509
1510 bool addPreRewrite() override;
1511 void addPostRegAlloc() override;
1512 void addPreSched2() override;
1513 void addPreEmitPass() override;
1514 void addPostBBSections() override;
1515};
1516
1517} // end anonymous namespace
1518
1520 : TargetPassConfig(TM, PM) {
1521 // Exceptions and StackMaps are not supported, so these passes will never do
1522 // anything.
1525 // Garbage collection is not supported.
1528
1530 // Use SSA Machine Scheduler instead of regular Machine Scheduler.
1533 }
1534}
1535
1542
1547 // ReassociateGEPs exposes more opportunities for SLSR. See
1548 // the example in reassociate-geps-and-slsr.ll.
1550 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
1551 // EarlyCSE can reuse.
1553 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
1555 // NaryReassociate on GEPs creates redundant common expressions, so run
1556 // EarlyCSE after it.
1558}
1559
1562
1563 if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN())
1565
1566 // There is no reason to run these.
1570
1571 if (TM.getTargetTriple().isAMDGCN())
1573
1574 if (LowerCtorDtor)
1576
1577 if (TM.getTargetTriple().isAMDGCN() &&
1580
1583
1584 // This can be disabled by passing ::Disable here or on the command line
1585 // with --expand-variadics-override=disable.
1587
1588 // Function calls are not supported, so make sure we inline everything.
1591
1592 // Handle uses of OpenCL image2d_t, image3d_t and sampler_t arguments.
1593 if (TM.getTargetTriple().getArch() == Triple::r600)
1595
1596 // Make enqueued block runtime handles externally visible.
1598
1599 // Lower special LDS accesses.
1602
1603 // Lower LDS accesses to global memory pass if address sanitizer is enabled.
1604 if (EnableSwLowerLDS)
1606
1607 // Runs before PromoteAlloca so the latter can account for function uses
1610 }
1611
1612 // Run atomic optimizer before Atomic Expand
1613 if ((TM.getTargetTriple().isAMDGCN()) &&
1614 (TM.getOptLevel() >= CodeGenOptLevel::Less) &&
1617 }
1618
1620
1621 if (TM.getOptLevel() > CodeGenOptLevel::None) {
1623
1626
1630 AAResults &AAR) {
1631 if (auto *WrapperPass = P.getAnalysisIfAvailable<AMDGPUAAWrapperPass>())
1632 AAR.addAAResult(WrapperPass->getResult());
1633 }));
1634 }
1635
1636 if (TM.getTargetTriple().isAMDGCN()) {
1637 // TODO: May want to move later or split into an early and late one.
1639 }
1640
1641 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
1642 // have expanded.
1643 if (TM.getOptLevel() > CodeGenOptLevel::Less)
1645 }
1646
1648
1649 // EarlyCSE is not always strong enough to clean up what LSR produces. For
1650 // example, GVN can combine
1651 //
1652 // %0 = add %a, %b
1653 // %1 = add %b, %a
1654 //
1655 // and
1656 //
1657 // %0 = shl nsw %a, 2
1658 // %1 = shl %a, 2
1659 //
1660 // but EarlyCSE can do neither of them.
1663}
1664
1666 if (TM->getTargetTriple().isAMDGCN() &&
1667 TM->getOptLevel() > CodeGenOptLevel::None)
1669
1670 if (TM->getTargetTriple().isAMDGCN() && EnableLowerKernelArguments)
1672
1674
1677
1678 if (TM->getTargetTriple().isAMDGCN()) {
1679 // This lowering has been placed after codegenprepare to take advantage of
1680 // address mode matching (which is why it isn't put with the LDS lowerings).
1681 // It could be placed anywhere before uniformity annotations (an analysis
1682 // that it changes by splitting up fat pointers into their components)
1683 // but has been put before switch lowering and CFG flattening so that those
1684 // passes can run on the more optimized control flow this pass creates in
1685 // many cases.
1688 }
1689
1690 // LowerSwitch pass may introduce unreachable blocks that can
1691 // cause unexpected behavior for subsequent passes. Placing it
1692 // here seems better that these blocks would get cleaned up by
1693 // UnreachableBlockElim inserted next in the pass flow.
1695}
1696
1698 if (TM->getOptLevel() > CodeGenOptLevel::None)
1700 return false;
1701}
1702
1707
1709 // Do nothing. GC is not supported.
1710 return false;
1711}
1712
1713//===----------------------------------------------------------------------===//
1714// GCN Legacy Pass Setup
1715//===----------------------------------------------------------------------===//
1716
1717bool GCNPassConfig::addPreISel() {
1719
1720 if (TM->getOptLevel() > CodeGenOptLevel::None) {
1721 addPass(createSinkingPass());
1723 }
1724
1725 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
1726 // regions formed by them.
1728 addPass(createFixIrreduciblePass());
1729 addPass(createUnifyLoopExitsPass());
1730 addPass(createStructurizeCFGPass(/*SkipUniformRegions=*/true));
1731
1734 // TODO: Move this right after structurizeCFG to avoid extra divergence
1735 // analysis. This depends on stopping SIAnnotateControlFlow from making
1736 // control flow modifications.
1738
1739 // SDAG requires LCSSA, GlobalISel does not. Disable LCSSA for -global-isel
1740 // without any of the fallback options.
1743 !isGlobalISelAbortEnabled())
1744 addPass(createLCSSAPass());
1745
1746 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1748
1749 return false;
1750}
1751
1752void GCNPassConfig::addMachineSSAOptimization() {
1754
1755 // We want to fold operands after PeepholeOptimizer has run (or as part of
1756 // it), because it will eliminate extra copies making it easier to fold the
1757 // real source operand. We want to eliminate dead instructions after, so that
1758 // we see fewer uses of the copies. We then need to clean up the dead
1759 // instructions leftover after the operands are folded as well.
1760 //
1761 // XXX - Can we get away without running DeadMachineInstructionElim again?
1762 addPass(&SIFoldOperandsLegacyID);
1763 if (EnableDPPCombine)
1764 addPass(&GCNDPPCombineLegacyID);
1766 if (isPassEnabled(EnableSDWAPeephole)) {
1767 addPass(&SIPeepholeSDWALegacyID);
1768 addPass(&EarlyMachineLICMID);
1769 addPass(&MachineCSELegacyID);
1770 addPass(&SIFoldOperandsLegacyID);
1771 }
1774}
1775
1776bool GCNPassConfig::addILPOpts() {
1778 addPass(&EarlyIfConverterLegacyID);
1779
1781 return false;
1782}
1783
1784bool GCNPassConfig::addInstSelector() {
1786 addPass(&SIFixSGPRCopiesLegacyID);
1788 return false;
1789}
1790
1791bool GCNPassConfig::addIRTranslator() {
1792 addPass(new IRTranslatorLegacy(getOptLevel()));
1793 return false;
1794}
1795
1796void GCNPassConfig::addPreLegalizeMachineIR() {
1797 bool IsOptLevelNone = getOptLevel() == CodeGenOptLevel::None;
1798 addPass(createAMDGPUPreLegalizeCombinerLegacyPass(IsOptLevelNone));
1799 addPass(new LocalizerLegacy());
1800}
1801
1802bool GCNPassConfig::addLegalizeMachineIR() {
1803 addPass(new LegalizerLegacy());
1804 return false;
1805}
1806
1807void GCNPassConfig::addPreRegBankSelect() {
1808 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1809 addPass(createAMDGPUPostLegalizeCombinerLegacy(IsOptNone));
1811}
1812
1813bool GCNPassConfig::addRegBankSelect() {
1816 return false;
1817}
1818
1819void GCNPassConfig::addPreGlobalInstructionSelect() {
1820 bool IsOptLevelNone = getOptLevel() == CodeGenOptLevel::None;
1821 addPass(createAMDGPURegBankCombinerLegacy(IsOptLevelNone));
1822}
1823
1824bool GCNPassConfig::addGlobalInstructionSelect() {
1825 addPass(new InstructionSelectLegacy(getOptLevel()));
1826 return false;
1827}
1828
1829void GCNPassConfig::addFastRegAlloc() {
1830 // FIXME: We have to disable the verifier here because of PHIElimination +
1831 // TwoAddressInstructions disabling it.
1832
1833 // This must be run immediately after phi elimination and before
1834 // TwoAddressInstructions, otherwise the processing of the tied operand of
1835 // SI_ELSE will introduce a copy of the tied operand source after the else.
1837
1839
1841}
1842
1843void GCNPassConfig::addPreRegAlloc() {
1844 if (getOptLevel() != CodeGenOptLevel::None)
1846}
1847
1848void GCNPassConfig::addOptimizedRegAlloc() {
1849 if (EnableDCEInRA)
1851
1852 if (OptVGPRLiveRange)
1854
1855 // This must be run immediately after phi elimination and before
1856 // TwoAddressInstructions, otherwise the processing of the tied operand of
1857 // SI_ELSE will introduce a copy of the tied operand source after the else.
1859
1862
1863 // Insertion point for passes depends on whether MachineScheduler is enabled.
1866
1867 if (isPassEnabled(EnablePreRAOptimizations))
1868 insertPass(EndOfPreRA, &GCNPreRAOptimizationsID);
1869
1870 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
1871 // instructions that cause scheduling barriers.
1872 insertPass(EndOfPreRA, &SIWholeQuadModeID);
1873
1874 if (OptExecMaskPreRA)
1875 insertPass(EndOfPreRA, &SIOptimizeExecMaskingPreRAID);
1876
1877 // This is not an essential optimization and it has a noticeable impact on
1878 // compilation time, so we only enable it from O2.
1879 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1880 insertPass(EndOfPreRA, &SIFormMemoryClausesID);
1881
1883}
1884
1885bool GCNPassConfig::addPreRewrite() {
1887 addPass(&GCNNSAReassignID);
1888
1890 return true;
1891}
1892
1893FunctionPass *GCNPassConfig::createSGPRAllocPass(bool Optimized) {
1894 // Initialize the global default.
1895 llvm::call_once(InitializeDefaultSGPRRegisterAllocatorFlag,
1896 initializeDefaultSGPRRegisterAllocatorOnce);
1897
1898 RegisterRegAlloc::FunctionPassCtor Ctor = SGPRRegisterRegAlloc::getDefault();
1899 if (Ctor != useDefaultRegisterAllocator)
1900 return Ctor();
1901
1902 if (Optimized)
1903 return createGreedyRegisterAllocator(onlyAllocateSGPRs);
1904
1905 return createFastRegisterAllocator(onlyAllocateSGPRs, false);
1906}
1907
1908FunctionPass *GCNPassConfig::createVGPRAllocPass(bool Optimized) {
1909 // Initialize the global default.
1910 llvm::call_once(InitializeDefaultVGPRRegisterAllocatorFlag,
1911 initializeDefaultVGPRRegisterAllocatorOnce);
1912
1913 RegisterRegAlloc::FunctionPassCtor Ctor = VGPRRegisterRegAlloc::getDefault();
1914 if (Ctor != useDefaultRegisterAllocator)
1915 return Ctor();
1916
1917 if (Optimized)
1918 return createGreedyVGPRRegisterAllocator();
1919
1920 return createFastVGPRRegisterAllocator();
1921}
1922
1923FunctionPass *GCNPassConfig::createWWMRegAllocPass(bool Optimized) {
1924 // Initialize the global default.
1925 llvm::call_once(InitializeDefaultWWMRegisterAllocatorFlag,
1926 initializeDefaultWWMRegisterAllocatorOnce);
1927
1928 RegisterRegAlloc::FunctionPassCtor Ctor = WWMRegisterRegAlloc::getDefault();
1929 if (Ctor != useDefaultRegisterAllocator)
1930 return Ctor();
1931
1932 if (Optimized)
1933 return createGreedyWWMRegisterAllocator();
1934
1935 return createFastWWMRegisterAllocator();
1936}
1937
1938FunctionPass *GCNPassConfig::createRegAllocPass(bool Optimized) {
1939 llvm_unreachable("should not be used");
1940}
1941
1943 "-regalloc not supported with amdgcn. Use -sgpr-regalloc, -wwm-regalloc, "
1944 "and -vgpr-regalloc";
1945
1946bool GCNPassConfig::addRegAssignAndRewriteFast() {
1947 if (!usingDefaultRegAlloc())
1949
1950 addPass(&GCNPreRALongBranchRegID);
1951
1952 addPass(createSGPRAllocPass(false));
1953
1954 // Equivalent of PEI for SGPRs.
1955 addPass(&SILowerSGPRSpillsLegacyID);
1956
1957 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1959
1960 // For allocating other wwm register operands.
1961 addPass(createWWMRegAllocPass(false));
1962
1963 addPass(&SILowerWWMCopiesLegacyID);
1965
1966 // For allocating per-thread VGPRs.
1967 addPass(createVGPRAllocPass(false));
1968
1969 return true;
1970}
1971
1972bool GCNPassConfig::addRegAssignAndRewriteOptimized() {
1973 if (!usingDefaultRegAlloc())
1975
1976 addPass(&GCNPreRALongBranchRegID);
1977
1978 addPass(createSGPRAllocPass(true));
1979
1980 // Commit allocated register changes. This is mostly necessary because too
1981 // many things rely on the use lists of the physical registers, such as the
1982 // verifier. This is only necessary with allocators which use LiveIntervals,
1983 // since FastRegAlloc does the replacements itself.
1984 addPass(createVirtRegRewriter(false));
1985
1986 // At this point, the sgpr-regalloc has been done and it is good to have the
1987 // stack slot coloring to try to optimize the SGPR spill stack indices before
1988 // attempting the custom SGPR spill lowering.
1989 addPass(&StackSlotColoringID);
1990
1991 // Equivalent of PEI for SGPRs.
1992 addPass(&SILowerSGPRSpillsLegacyID);
1993
1994 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1996
1997 // For allocating other whole wave mode registers.
1998 addPass(createWWMRegAllocPass(true));
1999 addPass(&SILowerWWMCopiesLegacyID);
2000 addPass(createVirtRegRewriter(false));
2002
2003 // For allocating per-thread VGPRs.
2004 addPass(createVGPRAllocPass(true));
2005
2006 addPreRewrite();
2007 addPass(&VirtRegRewriterID);
2008
2010
2011 return true;
2012}
2013
2014void GCNPassConfig::addPostRegAlloc() {
2015 addPass(&SIFixVGPRCopiesID);
2016 if (getOptLevel() > CodeGenOptLevel::None)
2019}
2020
2021void GCNPassConfig::addPreSched2() {
2022 if (TM->getOptLevel() > CodeGenOptLevel::None)
2024 addPass(&SIPostRABundlerLegacyID);
2025}
2026
2027void GCNPassConfig::addPreEmitPass() {
2028 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less))
2029 addPass(&GCNCreateVOPDID);
2030 addPass(createSIMemoryLegalizerPass());
2031 if (getOptLevel() > CodeGenOptLevel::None)
2033 addPass(createSIInsertWaitcntsPass());
2034
2035 addPass(createSIModeRegisterPass());
2036
2037 if (getOptLevel() > CodeGenOptLevel::None)
2038 addPass(&SIInsertHardClausesID);
2039
2041 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
2043 if (getOptLevel() > CodeGenOptLevel::None)
2044 addPass(&SIPreEmitPeepholeID);
2045 // The hazard recognizer that runs as part of the post-ra scheduler does not
2046 // guarantee to be able handle all hazards correctly. This is because if there
2047 // are multiple scheduling regions in a basic block, the regions are scheduled
2048 // bottom up, so when we begin to schedule a region we don't know what
2049 // instructions were emitted directly before it.
2050 //
2051 // Here we add a stand-alone hazard recognizer pass which can handle all
2052 // cases.
2053 addPass(&PostRAHazardRecognizerID);
2054
2056
2058
2059 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less))
2060 addPass(&AMDGPUInsertDelayAluID);
2061
2062 addPass(&BranchRelaxationPassID);
2063}
2064
2065void GCNPassConfig::addPostBBSections() {
2066 // We run this later to avoid passes like livedebugvalues and BBSections
2067 // having to deal with the apparent multi-entry functions we may generate.
2069}
2070
2072 return new GCNPassConfig(*this, PM);
2073}
2074
2080
2087
2091
2098
2101 SMDiagnostic &Error, SMRange &SourceRange) const {
2102 const yaml::SIMachineFunctionInfo &YamlMFI =
2103 static_cast<const yaml::SIMachineFunctionInfo &>(MFI_);
2104 MachineFunction &MF = PFS.MF;
2106 const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
2107
2108 if (MFI->initializeBaseYamlFields(YamlMFI, MF, PFS, Error, SourceRange))
2109 return true;
2110
2111 if (MFI->Occupancy == 0) {
2112 // Fixup the subtarget dependent default value.
2113 MFI->Occupancy = ST.getOccupancyWithWorkGroupSizes(MF).second;
2114 }
2115
2116 auto parseRegister = [&](const yaml::StringValue &RegName, Register &RegVal) {
2117 Register TempReg;
2118 if (parseNamedRegisterReference(PFS, TempReg, RegName.Value, Error)) {
2119 SourceRange = RegName.SourceRange;
2120 return true;
2121 }
2122 RegVal = TempReg;
2123
2124 return false;
2125 };
2126
2127 auto parseOptionalRegister = [&](const yaml::StringValue &RegName,
2128 Register &RegVal) {
2129 return !RegName.Value.empty() && parseRegister(RegName, RegVal);
2130 };
2131
2132 if (parseOptionalRegister(YamlMFI.VGPRForAGPRCopy, MFI->VGPRForAGPRCopy))
2133 return true;
2134
2135 if (parseOptionalRegister(YamlMFI.SGPRForEXECCopy, MFI->SGPRForEXECCopy))
2136 return true;
2137
2138 if (parseOptionalRegister(YamlMFI.LongBranchReservedReg,
2139 MFI->LongBranchReservedReg))
2140 return true;
2141
2142 auto diagnoseRegisterClass = [&](const yaml::StringValue &RegName) {
2143 // Create a diagnostic for a the register string literal.
2144 const MemoryBuffer &Buffer =
2145 *PFS.SM->getMemoryBuffer(PFS.SM->getMainFileID());
2146 Error = SMDiagnostic(*PFS.SM, SMLoc(), Buffer.getBufferIdentifier(), 1,
2147 RegName.Value.size(), SourceMgr::DK_Error,
2148 "incorrect register class for field", RegName.Value,
2149 {}, {});
2150 SourceRange = RegName.SourceRange;
2151 return true;
2152 };
2153
2154 if (parseRegister(YamlMFI.ScratchRSrcReg, MFI->ScratchRSrcReg) ||
2155 parseRegister(YamlMFI.FrameOffsetReg, MFI->FrameOffsetReg) ||
2156 parseRegister(YamlMFI.StackPtrOffsetReg, MFI->StackPtrOffsetReg))
2157 return true;
2158
2159 if (MFI->ScratchRSrcReg != AMDGPU::PRIVATE_RSRC_REG &&
2160 !AMDGPU::SGPR_128RegClass.contains(MFI->ScratchRSrcReg)) {
2161 return diagnoseRegisterClass(YamlMFI.ScratchRSrcReg);
2162 }
2163
2164 if (MFI->FrameOffsetReg != AMDGPU::FP_REG &&
2165 !AMDGPU::SGPR_32RegClass.contains(MFI->FrameOffsetReg)) {
2166 return diagnoseRegisterClass(YamlMFI.FrameOffsetReg);
2167 }
2168
2169 if (MFI->StackPtrOffsetReg != AMDGPU::SP_REG &&
2170 !AMDGPU::SGPR_32RegClass.contains(MFI->StackPtrOffsetReg)) {
2171 return diagnoseRegisterClass(YamlMFI.StackPtrOffsetReg);
2172 }
2173
2174 for (const auto &YamlReg : YamlMFI.WWMReservedRegs) {
2175 Register ParsedReg;
2176 if (parseRegister(YamlReg, ParsedReg))
2177 return true;
2178
2179 MFI->reserveWWMRegister(ParsedReg);
2180 }
2181
2182 for (const auto &[_, Info] : PFS.VRegInfosNamed) {
2183 MFI->setFlag(Info->VReg, Info->Flags);
2184 }
2185 for (const auto &[_, Info] : PFS.VRegInfos) {
2186 MFI->setFlag(Info->VReg, Info->Flags);
2187 }
2188
2189 for (const auto &YamlRegStr : YamlMFI.SpillPhysVGPRS) {
2190 Register ParsedReg;
2191 if (parseRegister(YamlRegStr, ParsedReg))
2192 return true;
2193 MFI->SpillPhysVGPRs.push_back(ParsedReg);
2194 }
2195
2196 auto parseAndCheckArgument = [&](const std::optional<yaml::SIArgument> &A,
2197 const TargetRegisterClass &RC,
2198 ArgDescriptor &Arg, unsigned UserSGPRs,
2199 unsigned SystemSGPRs) {
2200 // Skip parsing if it's not present.
2201 if (!A)
2202 return false;
2203
2204 if (A->IsRegister) {
2205 Register Reg;
2206 if (parseNamedRegisterReference(PFS, Reg, A->RegisterName.Value, Error)) {
2207 SourceRange = A->RegisterName.SourceRange;
2208 return true;
2209 }
2210 if (!RC.contains(Reg))
2211 return diagnoseRegisterClass(A->RegisterName);
2213 } else
2214 Arg = ArgDescriptor::createStack(A->StackOffset);
2215 // Check and apply the optional mask.
2216 if (A->Mask)
2217 Arg = ArgDescriptor::createArg(Arg, *A->Mask);
2218
2219 MFI->NumUserSGPRs += UserSGPRs;
2220 MFI->NumSystemSGPRs += SystemSGPRs;
2221 return false;
2222 };
2223
2224 if (YamlMFI.ArgInfo &&
2225 (parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentBuffer,
2226 AMDGPU::SGPR_128RegClass,
2227 MFI->ArgInfo.PrivateSegmentBuffer, 4, 0) ||
2228 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchPtr,
2229 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchPtr,
2230 2, 0) ||
2231 parseAndCheckArgument(YamlMFI.ArgInfo->QueuePtr, AMDGPU::SReg_64RegClass,
2232 MFI->ArgInfo.QueuePtr, 2, 0) ||
2233 parseAndCheckArgument(YamlMFI.ArgInfo->KernargSegmentPtr,
2234 AMDGPU::SReg_64RegClass,
2235 MFI->ArgInfo.KernargSegmentPtr, 2, 0) ||
2236 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchID,
2237 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchID,
2238 2, 0) ||
2239 parseAndCheckArgument(YamlMFI.ArgInfo->FlatScratchInit,
2240 AMDGPU::SReg_64RegClass,
2241 MFI->ArgInfo.FlatScratchInit, 2, 0) ||
2242 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentSize,
2243 AMDGPU::SGPR_32RegClass,
2244 MFI->ArgInfo.PrivateSegmentSize, 1, 0) ||
2245 parseAndCheckArgument(YamlMFI.ArgInfo->LDSKernelId,
2246 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.LDSKernelId,
2247 1, 0) ||
2248 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDX,
2249 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDX,
2250 0, 1) ||
2251 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDY,
2252 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDY,
2253 0, 1) ||
2254 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDZ,
2255 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDZ,
2256 0, 1) ||
2257 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupInfo,
2258 AMDGPU::SGPR_32RegClass,
2259 MFI->ArgInfo.WorkGroupInfo, 0, 1) ||
2260 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentWaveByteOffset,
2261 AMDGPU::SGPR_32RegClass,
2262 MFI->ArgInfo.PrivateSegmentWaveByteOffset, 0, 1) ||
2263 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitArgPtr,
2264 AMDGPU::SReg_64RegClass,
2265 MFI->ArgInfo.ImplicitArgPtr, 0, 0) ||
2266 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitBufferPtr,
2267 AMDGPU::SReg_64RegClass,
2268 MFI->ArgInfo.ImplicitBufferPtr, 2, 0) ||
2269 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDX,
2270 AMDGPU::VGPR_32RegClass, MFI->ArgInfo.WorkItemIDX,
2271 0, 0) ||
2272 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDY,
2273 AMDGPU::VGPR_32RegClass, MFI->ArgInfo.WorkItemIDY,
2274 0, 0) ||
2275 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDZ,
2276 AMDGPU::VGPR_32RegClass, MFI->ArgInfo.WorkItemIDZ,
2277 0, 0)))
2278 return true;
2279
2280 // Parse FirstKernArgPreloadReg separately, since it's a Register,
2281 // not ArgDescriptor.
2282 if (YamlMFI.ArgInfo && YamlMFI.ArgInfo->FirstKernArgPreloadReg) {
2283 const yaml::SIArgument &A = *YamlMFI.ArgInfo->FirstKernArgPreloadReg;
2284
2285 if (!A.IsRegister) {
2286 // For stack arguments, we don't have RegisterName.SourceRange,
2287 // but we should have some location info from the YAML parser
2288 const MemoryBuffer &Buffer =
2289 *PFS.SM->getMemoryBuffer(PFS.SM->getMainFileID());
2290 // Create a minimal valid source range
2292 SMRange Range(Loc, Loc);
2293
2295 *PFS.SM, Loc, Buffer.getBufferIdentifier(), 1, 0, SourceMgr::DK_Error,
2296 "firstKernArgPreloadReg must be a register, not a stack location", "",
2297 {}, {});
2298
2299 SourceRange = Range;
2300 return true;
2301 }
2302
2303 Register Reg;
2304 if (parseNamedRegisterReference(PFS, Reg, A.RegisterName.Value, Error)) {
2305 SourceRange = A.RegisterName.SourceRange;
2306 return true;
2307 }
2308
2309 if (!AMDGPU::SGPR_32RegClass.contains(Reg))
2310 return diagnoseRegisterClass(A.RegisterName);
2311
2312 MFI->ArgInfo.FirstKernArgPreloadReg = Reg;
2313 MFI->NumUserSGPRs += YamlMFI.NumKernargPreloadSGPRs;
2314 }
2315
2316 if (ST.hasFeature(AMDGPU::FeatureDX10ClampAndIEEEMode)) {
2317 MFI->Mode.IEEE = YamlMFI.Mode.IEEE;
2318 MFI->Mode.DX10Clamp = YamlMFI.Mode.DX10Clamp;
2319 }
2320
2321 // FIXME: Move proper support for denormal-fp-math into base MachineFunction
2322 MFI->Mode.FP32Denormals.Input = YamlMFI.Mode.FP32InputDenormals
2325 MFI->Mode.FP32Denormals.Output = YamlMFI.Mode.FP32OutputDenormals
2328
2335
2336 if (YamlMFI.HasInitWholeWave)
2337 MFI->setInitWholeWave();
2338
2339 return false;
2340}
2341
2342//===----------------------------------------------------------------------===//
2343// AMDGPU CodeGen Pass Builder interface.
2344//===----------------------------------------------------------------------===//
2345
2346AMDGPUCodeGenPassBuilder::AMDGPUCodeGenPassBuilder(
2347 GCNTargetMachine &TM, const CGPassBuilderOption &Opts,
2349 : CodeGenPassBuilder(TM, Opts, PIC) {
2350 Opt.MISchedPostRA = true;
2351 Opt.RequiresCodeGenSCCOrder = true;
2352 Opt.EnableSSAMachineScheduler = UseSSAMachineScheduler;
2353 // Exceptions and StackMaps are not supported, so these passes will never do
2354 // anything.
2355 // Garbage collection is not supported.
2356 disablePass<StackMapLivenessPass, FuncletLayoutPass, PatchableFunctionPass,
2358
2359 // If enabled, use the SSA machine scheduler instead of the regular machine
2360 // scheduler.
2361 if (Opt.EnableSSAMachineScheduler)
2362 disablePass<MachineSchedulerPass>();
2363}
2364
2365void AMDGPUCodeGenPassBuilder::addIRPasses(PassManagerWrapper &PMW) {
2367 flushFPMsToMPM(PMW);
2368 addModulePass(AMDGPURemoveIncompatibleFunctionsPass(TM), PMW);
2369 }
2370
2371 flushFPMsToMPM(PMW);
2372
2373 if (TM.getTargetTriple().isAMDGCN())
2374 addModulePass(AMDGPUPrintfRuntimeBindingPass(), PMW);
2375
2376 if (LowerCtorDtor)
2377 addModulePass(AMDGPUCtorDtorLoweringPass(), PMW);
2378
2379 if (isPassEnabled(EnableImageIntrinsicOptimizer))
2380 addFunctionPass(AMDGPUImageIntrinsicOptimizerPass(TM), PMW);
2381
2383 addFunctionPass(AMDGPUUniformIntrinsicCombinePass(), PMW);
2384 // This can be disabled by passing ::Disable here or on the command line
2385 // with --expand-variadics-override=disable.
2386 flushFPMsToMPM(PMW);
2388
2389 addModulePass(AMDGPUAlwaysInlinePass(), PMW);
2390 addModulePass(AlwaysInlinerPass(), PMW);
2391
2392 addModulePass(AMDGPUExportKernelRuntimeHandlesPass(), PMW);
2393
2395 addModulePass(AMDGPULowerExecSyncPass(), PMW);
2396
2397 if (EnableSwLowerLDS)
2398 addModulePass(AMDGPUSwLowerLDSPass(), PMW);
2399
2400 // Runs before PromoteAlloca so the latter can account for function uses
2402 addModulePass(AMDGPULowerModuleLDSPass(getTM()), PMW);
2403
2404 // Run atomic optimizer before Atomic Expand
2405 if (TM.getOptLevel() >= CodeGenOptLevel::Less &&
2407 addFunctionPass(
2409
2410 addFunctionPass(AtomicExpandPass(TM), PMW);
2411
2413 addFunctionPass(AMDGPUPromoteAllocaPass(TM), PMW);
2414 if (isPassEnabled(EnableScalarIRPasses))
2415 addStraightLineScalarOptimizationPasses(PMW);
2416
2417 // TODO: Handle EnableAMDGPUAliasAnalysis
2418
2419 // TODO: May want to move later or split into an early and late one.
2420 addFunctionPass(AMDGPUCodeGenPreparePass(TM), PMW);
2421
2422 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
2423 // have expanded.
2426 /*UseMemorySSA=*/true),
2427 PMW);
2428 }
2429 }
2430
2431 Base::addIRPasses(PMW);
2432
2433 // EarlyCSE is not always strong enough to clean up what LSR produces. For
2434 // example, GVN can combine
2435 //
2436 // %0 = add %a, %b
2437 // %1 = add %b, %a
2438 //
2439 // and
2440 //
2441 // %0 = shl nsw %a, 2
2442 // %1 = shl %a, 2
2443 //
2444 // but EarlyCSE can do neither of them.
2445 if (isPassEnabled(EnableScalarIRPasses))
2446 addEarlyCSEOrGVNPass(PMW);
2447}
2448
2449void AMDGPUCodeGenPassBuilder::addCodeGenPrepare(PassManagerWrapper &PMW) {
2451 flushFPMsToMPM(PMW);
2452 addModulePass(AMDGPUPreloadKernelArgumentsPass(TM), PMW);
2453 }
2454
2456 addFunctionPass(AMDGPULowerKernelArgumentsPass(TM), PMW);
2457
2458 Base::addCodeGenPrepare(PMW);
2459
2460 if (isPassEnabled(EnableLoadStoreVectorizer))
2461 addFunctionPass(LoadStoreVectorizerPass(), PMW);
2462
2463 // This lowering has been placed after codegenprepare to take advantage of
2464 // address mode matching (which is why it isn't put with the LDS lowerings).
2465 // It could be placed anywhere before uniformity annotations (an analysis
2466 // that it changes by splitting up fat pointers into their components)
2467 // but has been put before switch lowering and CFG flattening so that those
2468 // passes can run on the more optimized control flow this pass creates in
2469 // many cases.
2470 flushFPMsToMPM(PMW);
2471 addModulePass(AMDGPULowerBufferFatPointersPass(TM), PMW);
2472 flushFPMsToMPM(PMW);
2473 requireCGSCCOrder(PMW);
2474
2475 addModulePass(AMDGPULowerIntrinsicsPass(getTM()), PMW);
2476
2477 // LowerSwitch pass may introduce unreachable blocks that can cause unexpected
2478 // behavior for subsequent passes. Placing it here seems better that these
2479 // blocks would get cleaned up by UnreachableBlockElim inserted next in the
2480 // pass flow.
2481 addFunctionPass(LowerSwitchPass(), PMW);
2482}
2483
2484void AMDGPUCodeGenPassBuilder::addPreISel(PassManagerWrapper &PMW) {
2485
2487 addFunctionPass(FlattenCFGPass(), PMW);
2488 addFunctionPass(SinkingPass(), PMW);
2489 addFunctionPass(AMDGPULateCodeGenPreparePass(getTM()), PMW);
2490 }
2491
2492 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
2493 // regions formed by them.
2494
2495 addFunctionPass(AMDGPUUnifyDivergentExitNodesPass(), PMW);
2496 addFunctionPass(FixIrreduciblePass(), PMW);
2497 addFunctionPass(UnifyLoopExitsPass(), PMW);
2498 addFunctionPass(StructurizeCFGPass(/*SkipUniformRegions=*/true), PMW);
2499
2500 addFunctionPass(AMDGPUAnnotateUniformValuesPass(), PMW);
2501
2502 addFunctionPass(SIAnnotateControlFlowPass(getTM()), PMW);
2503
2504 // TODO: Move this right after structurizeCFG to avoid extra divergence
2505 // analysis. This depends on stopping SIAnnotateControlFlow from making
2506 // control flow modifications.
2507 addFunctionPass(AMDGPURewriteUndefForPHIPass(), PMW);
2508
2509 if (getCGPassBuilderOption(TM).EnableGlobalISelOption !=
2511 !isGlobalISelAbortEnabled())
2512 addFunctionPass(LCSSAPass(), PMW);
2513
2515 flushFPMsToMPM(PMW);
2516 addModulePass(AMDGPUPerfHintAnalysisPass(getTM()), PMW);
2517 }
2518}
2519
2520void AMDGPUCodeGenPassBuilder::addILPOpts(PassManagerWrapper &PMW) {
2522 addMachineFunctionPass(EarlyIfConverterPass(), PMW);
2523
2524 Base::addILPOpts(PMW);
2525}
2526
2527void AMDGPUCodeGenPassBuilder::addAsmPrinterBegin(PassManagerWrapper &PMW) {
2528 addModulePass(AMDGPUAsmPrinterBeginPass(), PMW,
2529 /*Force=*/true);
2530}
2531
2532void AMDGPUCodeGenPassBuilder::addAsmPrinter(PassManagerWrapper &PMW) {
2533 addMachineFunctionPass(AMDGPUAsmPrinterPass(), PMW);
2534}
2535
2536void AMDGPUCodeGenPassBuilder::addAsmPrinterEnd(PassManagerWrapper &PMW) {
2537 addModulePass(AMDGPUAsmPrinterEndPass(), PMW);
2538}
2539
2540Error AMDGPUCodeGenPassBuilder::addInstSelector(PassManagerWrapper &PMW) {
2541 addMachineFunctionPass(AMDGPUISelDAGToDAGPass(TM), PMW);
2542 addMachineFunctionPass(SIFixSGPRCopiesPass(), PMW);
2543 addMachineFunctionPass(SILowerI1CopiesPass(), PMW);
2544 return Error::success();
2545}
2546
2547Error AMDGPUCodeGenPassBuilder::addIRTranslator(PassManagerWrapper &PMW) {
2548 addMachineFunctionPass(IRTranslatorPass(getOptLevel()), PMW);
2549 return Error::success();
2550}
2551
2552void AMDGPUCodeGenPassBuilder::addPreLegalizeMachineIR(
2553 PassManagerWrapper &PMW) {
2554 addMachineFunctionPass(AMDGPUPreLegalizerCombinerPass(), PMW);
2555 addMachineFunctionPass(LocalizerPass(), PMW);
2556}
2557
2558Error AMDGPUCodeGenPassBuilder::addLegalizeMachineIR(PassManagerWrapper &PMW) {
2559 addMachineFunctionPass(LegalizerPass(), PMW);
2560 return Error::success();
2561}
2562
2563void AMDGPUCodeGenPassBuilder::addPreRegBankSelect(PassManagerWrapper &PMW) {
2564 addMachineFunctionPass(AMDGPUPostLegalizerCombinerPass(), PMW);
2565 addMachineFunctionPass(AMDGPUGlobalISelDivergenceLoweringPass(), PMW);
2566}
2567
2568Error AMDGPUCodeGenPassBuilder::addRegBankSelect(PassManagerWrapper &PMW) {
2569 addMachineFunctionPass(AMDGPURegBankSelectPass(), PMW);
2570 addMachineFunctionPass(AMDGPURegBankLegalizePass(), PMW);
2571 return Error::success();
2572}
2573
2574void AMDGPUCodeGenPassBuilder::addPreGlobalInstructionSelect(
2575 PassManagerWrapper &PMW) {
2576 bool IsOptLevelNone = getOptLevel() == CodeGenOptLevel::None;
2577 addMachineFunctionPass(AMDGPURegBankCombinerPass(IsOptLevelNone), PMW);
2578}
2579
2580Error AMDGPUCodeGenPassBuilder::addGlobalInstructionSelect(
2581 PassManagerWrapper &PMW) {
2582 addMachineFunctionPass(InstructionSelectPass(getOptLevel()), PMW);
2583 return Error::success();
2584}
2585
2586void AMDGPUCodeGenPassBuilder::addPreRewrite(PassManagerWrapper &PMW) {
2587 if (EnableRegReassign) {
2588 addMachineFunctionPass(GCNNSAReassignPass(), PMW);
2589 }
2590
2591 addMachineFunctionPass(AMDGPURewriteAGPRCopyMFMAPass(), PMW);
2592}
2593
2594void AMDGPUCodeGenPassBuilder::addMachineSSAOptimization(
2595 PassManagerWrapper &PMW) {
2596 Base::addMachineSSAOptimization(PMW);
2597
2598 addMachineFunctionPass(SIFoldOperandsPass(), PMW);
2599 if (EnableDPPCombine) {
2600 addMachineFunctionPass(GCNDPPCombinePass(), PMW);
2601 }
2602 addMachineFunctionPass(SILoadStoreOptimizerPass(), PMW);
2603 if (isPassEnabled(EnableSDWAPeephole)) {
2604 addMachineFunctionPass(SIPeepholeSDWAPass(), PMW);
2605 addMachineFunctionPass(EarlyMachineLICMPass(), PMW);
2606 addMachineFunctionPass(MachineCSEPass(), PMW);
2607 addMachineFunctionPass(SIFoldOperandsPass(), PMW);
2608 }
2609 addMachineFunctionPass(DeadMachineInstructionElimPass(), PMW);
2610 addMachineFunctionPass(SIShrinkInstructionsPass(), PMW);
2611}
2612
2613Error AMDGPUCodeGenPassBuilder::addFastRegAlloc(PassManagerWrapper &PMW) {
2614 insertPass<PHIEliminationPass>(SILowerControlFlowPass());
2615
2616 insertPass<TwoAddressInstructionPass>(SIWholeQuadModePass());
2617
2618 return Base::addFastRegAlloc(PMW);
2619}
2620
2621Error AMDGPUCodeGenPassBuilder::addRegAssignAndRewriteFast(
2622 PassManagerWrapper &PMW) {
2623 if (auto Err = validateRegAllocOptions())
2624 return Err;
2625
2626 addMachineFunctionPass(GCNPreRALongBranchRegPass(), PMW);
2627
2628 // SGPR allocation - default to fast at -O0.
2629 if (SGPRRegAllocNPM == RegAllocType::Greedy)
2630 addMachineFunctionPass(RAGreedyPass({onlyAllocateSGPRs, "sgpr"}), PMW);
2631 else
2632 addMachineFunctionPass(RegAllocFastPass({onlyAllocateSGPRs, "sgpr", false}),
2633 PMW);
2634
2635 // Equivalent of PEI for SGPRs.
2636 addMachineFunctionPass(SILowerSGPRSpillsPass(), PMW);
2637
2638 // To Allocate wwm registers used in whole quad mode operations (for shaders).
2639 addMachineFunctionPass(SIPreAllocateWWMRegsPass(), PMW);
2640
2641 // WWM allocation - default to fast at -O0.
2642 if (WWMRegAllocNPM == RegAllocType::Greedy)
2643 addMachineFunctionPass(RAGreedyPass({onlyAllocateWWMRegs, "wwm"}), PMW);
2644 else
2645 addMachineFunctionPass(
2646 RegAllocFastPass({onlyAllocateWWMRegs, "wwm", false}), PMW);
2647
2648 addMachineFunctionPass(SILowerWWMCopiesPass(), PMW);
2649 addMachineFunctionPass(AMDGPUReserveWWMRegsPass(), PMW);
2650
2651 // VGPR allocation - default to fast at -O0.
2652 if (VGPRRegAllocNPM == RegAllocType::Greedy)
2653 addMachineFunctionPass(RAGreedyPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2654 else
2655 addMachineFunctionPass(RegAllocFastPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2656
2657 return Error::success();
2658}
2659
2660Error AMDGPUCodeGenPassBuilder::addOptimizedRegAlloc(PassManagerWrapper &PMW) {
2661 if (EnableDCEInRA)
2662 insertPass<DetectDeadLanesPass>(DeadMachineInstructionElimPass());
2663
2664 if (OptVGPRLiveRange)
2665 insertPass<RequireAnalysisPass<MachineLoopAnalysis, MachineFunction>>(
2667
2668 // This must be run immediately after phi elimination and before
2669 // TwoAddressInstructions, otherwise the processing of the tied operand of
2670 // SI_ELSE will introduce a copy of the tied operand source after the else.
2671 insertPass<PHIEliminationPass>(SILowerControlFlowPass());
2672
2674 insertPass<RenameIndependentSubregsPass>(GCNRewritePartialRegUsesPass());
2675
2676 // Following passes run at the end of the pre-RA pipeline, so the pass they
2677 // are anchored on depends on which scheduler is enabled.
2678 auto insertAtEndOfPreRA = [this](auto &&Pass) {
2679 if (Opt.EnableSSAMachineScheduler)
2680 insertPass<RenameIndependentSubregsPass>(std::move(Pass));
2681 else
2682 insertPass<MachineSchedulerPass>(std::move(Pass));
2683 };
2684
2685 if (isPassEnabled(EnablePreRAOptimizations))
2686 insertAtEndOfPreRA(GCNPreRAOptimizationsPass());
2687
2688 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
2689 // instructions that cause scheduling barriers.
2690 insertAtEndOfPreRA(SIWholeQuadModePass());
2691
2692 if (OptExecMaskPreRA)
2693 insertAtEndOfPreRA(SIOptimizeExecMaskingPreRAPass());
2694
2695 // This is not an essential optimization and it has a noticeable impact on
2696 // compilation time, so we only enable it from O2.
2698 insertAtEndOfPreRA(SIFormMemoryClausesPass());
2699
2700 return Base::addOptimizedRegAlloc(PMW);
2701}
2702
2703void AMDGPUCodeGenPassBuilder::addPreRegAlloc(PassManagerWrapper &PMW) {
2704 if (getOptLevel() != CodeGenOptLevel::None)
2705 addMachineFunctionPass(AMDGPUPrepareAGPRAllocPass(), PMW);
2706}
2707
2708Expected<bool> AMDGPUCodeGenPassBuilder::addRegAssignAndRewriteOptimized(
2709 PassManagerWrapper &PMW) {
2710 if (auto Err = validateRegAllocOptions())
2711 return Err;
2712
2713 addMachineFunctionPass(GCNPreRALongBranchRegPass(), PMW);
2714
2715 // SGPR allocation - default to greedy at -O1 and above.
2716 if (SGPRRegAllocNPM == RegAllocType::Fast)
2717 addMachineFunctionPass(RegAllocFastPass({onlyAllocateSGPRs, "sgpr", false}),
2718 PMW);
2719 else
2720 addMachineFunctionPass(RAGreedyPass({onlyAllocateSGPRs, "sgpr"}), PMW);
2721
2722 // Commit allocated register changes. This is mostly necessary because too
2723 // many things rely on the use lists of the physical registers, such as the
2724 // verifier. This is only necessary with allocators which use LiveIntervals,
2725 // since FastRegAlloc does the replacements itself.
2726 addMachineFunctionPass(VirtRegRewriterPass(false), PMW);
2727
2728 // At this point, the sgpr-regalloc has been done and it is good to have the
2729 // stack slot coloring to try to optimize the SGPR spill stack indices before
2730 // attempting the custom SGPR spill lowering.
2731 addMachineFunctionPass(StackSlotColoringPass(), PMW);
2732
2733 // Equivalent of PEI for SGPRs.
2734 addMachineFunctionPass(SILowerSGPRSpillsPass(), PMW);
2735
2736 // To Allocate wwm registers used in whole quad mode operations (for shaders).
2737 addMachineFunctionPass(SIPreAllocateWWMRegsPass(), PMW);
2738
2739 // WWM allocation - default to greedy at -O1 and above.
2740 if (WWMRegAllocNPM == RegAllocType::Fast)
2741 addMachineFunctionPass(
2742 RegAllocFastPass({onlyAllocateWWMRegs, "wwm", false}), PMW);
2743 else
2744 addMachineFunctionPass(RAGreedyPass({onlyAllocateWWMRegs, "wwm"}), PMW);
2745 addMachineFunctionPass(SILowerWWMCopiesPass(), PMW);
2746 addMachineFunctionPass(VirtRegRewriterPass(false), PMW);
2747 addMachineFunctionPass(AMDGPUReserveWWMRegsPass(), PMW);
2748
2749 // VGPR allocation - default to greedy at -O1 and above.
2750 if (VGPRRegAllocNPM == RegAllocType::Fast)
2751 addMachineFunctionPass(RegAllocFastPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2752 else
2753 addMachineFunctionPass(RAGreedyPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2754
2755 addPreRewrite(PMW);
2756 addMachineFunctionPass(VirtRegRewriterPass(true), PMW);
2757
2758 addMachineFunctionPass(AMDGPUMarkLastScratchLoadPass(), PMW);
2759 return true;
2760}
2761
2762void AMDGPUCodeGenPassBuilder::addPostRegAlloc(PassManagerWrapper &PMW) {
2763 addMachineFunctionPass(SIFixVGPRCopiesPass(), PMW);
2765 addMachineFunctionPass(SIOptimizeExecMaskingPass(), PMW);
2766 Base::addPostRegAlloc(PMW);
2767}
2768
2769void AMDGPUCodeGenPassBuilder::addPreSched2(PassManagerWrapper &PMW) {
2771 addMachineFunctionPass(SIShrinkInstructionsPass(), PMW);
2772 addMachineFunctionPass(SIPostRABundlerPass(), PMW);
2773}
2774
2775void AMDGPUCodeGenPassBuilder::addPostBBSections(PassManagerWrapper &PMW) {
2776 // We run this later to avoid passes like livedebugvalues and BBSections
2777 // having to deal with the apparent multi-entry functions we may generate.
2778 addMachineFunctionPass(AMDGPUPreloadKernArgPrologPass(), PMW);
2779}
2780
2781void AMDGPUCodeGenPassBuilder::addPreEmitPass(PassManagerWrapper &PMW) {
2782 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less)) {
2783 addMachineFunctionPass(GCNCreateVOPDPass(), PMW);
2784 }
2785
2786 addMachineFunctionPass(SIMemoryLegalizerPass(), PMW);
2788 addMachineFunctionPass(SIPostRA16BitMovFoldingPass(), PMW);
2789 addMachineFunctionPass(SIInsertWaitcntsPass(), PMW);
2790
2791 addMachineFunctionPass(SIModeRegisterPass(), PMW);
2792
2794 addMachineFunctionPass(SIInsertHardClausesPass(), PMW);
2795
2796 addMachineFunctionPass(SILateBranchLoweringPass(), PMW);
2797
2798 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
2799 addMachineFunctionPass(AMDGPUSetWavePriorityPass(), PMW);
2800
2802 addMachineFunctionPass(SIPreEmitPeepholePass(), PMW);
2803
2804 // The hazard recognizer that runs as part of the post-ra scheduler does not
2805 // guarantee to be able handle all hazards correctly. This is because if there
2806 // are multiple scheduling regions in a basic block, the regions are scheduled
2807 // bottom up, so when we begin to schedule a region we don't know what
2808 // instructions were emitted directly before it.
2809 //
2810 // Here we add a stand-alone hazard recognizer pass which can handle all
2811 // cases.
2812 addMachineFunctionPass(PostRAHazardRecognizerPass(), PMW);
2813 addMachineFunctionPass(AMDGPUWaitSGPRHazardsPass(), PMW);
2814 addMachineFunctionPass(AMDGPULowerVGPREncodingPass(), PMW);
2815
2816 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less)) {
2817 addMachineFunctionPass(AMDGPUInsertDelayAluPass(), PMW);
2818 }
2819
2820 addMachineFunctionPass(BranchRelaxationPass(), PMW);
2821}
2822
2823bool AMDGPUCodeGenPassBuilder::isPassEnabled(const cl::opt<bool> &Opt,
2824 CodeGenOptLevel Level) const {
2825 if (Opt.getNumOccurrences())
2826 return Opt;
2827 if (TM.getOptLevel() < Level)
2828 return false;
2829 return Opt;
2830}
2831
2832void AMDGPUCodeGenPassBuilder::addEarlyCSEOrGVNPass(PassManagerWrapper &PMW) {
2834 addFunctionPass(GVNPass(), PMW);
2835 else
2836 addFunctionPass(EarlyCSEPass(), PMW);
2837}
2838
2839void AMDGPUCodeGenPassBuilder::addStraightLineScalarOptimizationPasses(
2840 PassManagerWrapper &PMW) {
2842 addFunctionPass(LoopDataPrefetchPass(), PMW);
2843
2844 addFunctionPass(SeparateConstOffsetFromGEPPass(), PMW);
2845
2846 // ReassociateGEPs exposes more opportunities for SLSR. See
2847 // the example in reassociate-geps-and-slsr.ll.
2848 addFunctionPass(StraightLineStrengthReducePass(), PMW);
2849
2850 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
2851 // EarlyCSE can reuse.
2852 addEarlyCSEOrGVNPass(PMW);
2853
2854 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
2855 addFunctionPass(NaryReassociatePass(), PMW);
2856
2857 // NaryReassociate on GEPs creates redundant common expressions, so run
2858 // EarlyCSE after it.
2859 addFunctionPass(EarlyCSEPass(), PMW);
2860}
aarch64 falkor hwpf fix Falkor HW Prefetch Fix Late Phase
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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 cl::opt< bool > EnableEarlyIfConversion("amdgpu-early-ifcvt", cl::Hidden, cl::desc("Run early if-conversion"), cl::init(false))
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 > UseSSAMachineScheduler("amdgpu-use-ssa-machine-scheduler", cl::desc("Use the machine scheduler in SSA mode."), cl::init(false), 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:665
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:327
#define LLVM_ABI
Definition Compiler.h:211
#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
PassBuilder PB(Mod->getContext(), Machine, PassOpts->PTO, std::nullopt, &PIC)
PassInstrumentationCallbacks PIC
static bool isLTOPreLink(ThinOrFullLTOPhase Phase)
The AMDGPU TargetMachine interface definition for hw codegen targets.
MachineRegisterInfo & MRI
const GCNTargetMachine & getTM(const GCNSubtarget *STI)
SI Machine Scheduler interface.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:480
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static FunctionPass * useDefaultRegisterAllocator()
-regalloc=... command line option.
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:262
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:312
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:73
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,...
void addDelegate(Delegate *delegate)
MachineSchedRegistry provides a selection of available machine instruction schedulers.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
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:97
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:307
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.
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:150
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
void setEnableTiedFastRegAlloc(bool Value)
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)
void setEnableSSAMachineScheduler(bool Enable)
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
bool isAMDGCN() const
Tests whether the target is AMDGCN.
Definition Triple.h:996
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 &)
LLVM_ABI std::unique_ptr< ScheduleDAGMutation > createLoadClusterDAGMutation(const TargetInstrInfo *TII, bool ReorderWhileClustering=false)
If ReorderWhileClustering is set to true, no attempt will be made to reduce reordering due to store c...
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 std::unique_ptr< ScheduleDAGMutation > createStoreClusterDAGMutation(const TargetInstrInfo *TII, bool ReorderWhileClustering=false)
If ReorderWhileClustering is set to true, no attempt will be made to reduce reordering due to store c...
LLVM_ABI Pass * createLICMPass()
Definition LICM.cpp:341
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:75
@ FullLTOPostLink
Full LTO postlink (backend compile) phase.
Definition Pass.h:85
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:274
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 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
void initializeSIInsertWaitcntsLegacyPass(PassRegistry &)
LLVM_ABI CGPassBuilderOption getCGPassBuilderOption(const TargetMachine &TM)
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 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
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:391
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.
const void * AnalysisID
Definition Pass.h:51
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 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)
cl::boolOrDefault EnableGlobalISelOption
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.