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 void addPreRewrite(PassManagerWrapper &PMW) override;
172 void addMachineSSAOptimization(PassManagerWrapper &PMW) override;
173 void addPostRegAlloc(PassManagerWrapper &PMW) override;
174 void addPreEmitPass(PassManagerWrapper &PMW) override;
175 Error addRegAssignAndRewriteFast(PassManagerWrapper &PMW) override;
176 Expected<bool>
177 addRegAssignAndRewriteOptimized(PassManagerWrapper &PMW) override;
178 void addPreRegAlloc(PassManagerWrapper &PMW) override;
179 Error addFastRegAlloc(PassManagerWrapper &PMW) override;
180 Error addOptimizedRegAlloc(PassManagerWrapper &PMW) override;
181 void addPreSched2(PassManagerWrapper &PMW) override;
182 void addPostBBSections(PassManagerWrapper &PMW) override;
183
184private:
185 Error validateRegAllocOptions() const;
186
187public:
188 /// Check if a pass is enabled given \p Opt option. The option always
189 /// overrides defaults if explicitly used. Otherwise its default will be used
190 /// given that a pass shall work at an optimization \p Level minimum.
191 bool isPassEnabled(const cl::opt<bool> &Opt,
192 CodeGenOptLevel Level = CodeGenOptLevel::Default) const;
193 void addEarlyCSEOrGVNPass(PassManagerWrapper &PMW);
194 void addStraightLineScalarOptimizationPasses(PassManagerWrapper &PMW);
195};
196
197class SGPRRegisterRegAlloc : public RegisterRegAllocBase<SGPRRegisterRegAlloc> {
198public:
199 SGPRRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
200 : RegisterRegAllocBase(N, D, C) {}
201};
202
203class VGPRRegisterRegAlloc : public RegisterRegAllocBase<VGPRRegisterRegAlloc> {
204public:
205 VGPRRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
206 : RegisterRegAllocBase(N, D, C) {}
207};
208
209class WWMRegisterRegAlloc : public RegisterRegAllocBase<WWMRegisterRegAlloc> {
210public:
211 WWMRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
212 : RegisterRegAllocBase(N, D, C) {}
213};
214
215static bool onlyAllocateSGPRs(const TargetRegisterInfo &TRI,
216 const MachineRegisterInfo &MRI,
217 const Register Reg) {
218 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
219 return static_cast<const SIRegisterInfo &>(TRI).isSGPRClass(RC);
220}
221
222static bool onlyAllocateVGPRs(const TargetRegisterInfo &TRI,
223 const MachineRegisterInfo &MRI,
224 const Register Reg) {
225 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
226 return !static_cast<const SIRegisterInfo &>(TRI).isSGPRClass(RC);
227}
228
229static bool onlyAllocateWWMRegs(const TargetRegisterInfo &TRI,
230 const MachineRegisterInfo &MRI,
231 const Register Reg) {
232 const SIMachineFunctionInfo *MFI =
234 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
235 return !static_cast<const SIRegisterInfo &>(TRI).isSGPRClass(RC) &&
237}
238
239/// -{sgpr|wwm|vgpr}-regalloc=... command line option.
240static FunctionPass *useDefaultRegisterAllocator() { return nullptr; }
241
242/// A dummy default pass factory indicates whether the register allocator is
243/// overridden on the command line.
244static llvm::once_flag InitializeDefaultSGPRRegisterAllocatorFlag;
245static llvm::once_flag InitializeDefaultVGPRRegisterAllocatorFlag;
246static llvm::once_flag InitializeDefaultWWMRegisterAllocatorFlag;
247
248static SGPRRegisterRegAlloc
249defaultSGPRRegAlloc("default",
250 "pick SGPR register allocator based on -O option",
252
253static cl::opt<SGPRRegisterRegAlloc::FunctionPassCtor, false,
255SGPRRegAlloc("sgpr-regalloc", cl::Hidden, cl::init(&useDefaultRegisterAllocator),
256 cl::desc("Register allocator to use for SGPRs"));
257
258static cl::opt<VGPRRegisterRegAlloc::FunctionPassCtor, false,
260VGPRRegAlloc("vgpr-regalloc", cl::Hidden, cl::init(&useDefaultRegisterAllocator),
261 cl::desc("Register allocator to use for VGPRs"));
262
263static cl::opt<WWMRegisterRegAlloc::FunctionPassCtor, false,
265 WWMRegAlloc("wwm-regalloc", cl::Hidden,
267 cl::desc("Register allocator to use for WWM registers"));
268
269// New pass manager register allocator options for AMDGPU
271 "sgpr-regalloc-npm", cl::Hidden, cl::init(RegAllocType::Default),
272 cl::desc("Register allocator for SGPRs (new pass manager)"));
273
275 "vgpr-regalloc-npm", cl::Hidden, cl::init(RegAllocType::Default),
276 cl::desc("Register allocator for VGPRs (new pass manager)"));
277
279 "wwm-regalloc-npm", cl::Hidden, cl::init(RegAllocType::Default),
280 cl::desc("Register allocator for WWM registers (new pass manager)"));
281
282/// Check if the given RegAllocType is supported for AMDGPU NPM register
283/// allocation. Only Fast and Greedy are supported; Basic and PBQP are not.
284static Error checkRegAllocSupported(RegAllocType RAType, StringRef RegName) {
285 if (RAType == RegAllocType::Basic || RAType == RegAllocType::PBQP) {
287 Twine("unsupported register allocator '") +
288 (RAType == RegAllocType::Basic ? "basic" : "pbqp") + "' for " +
289 RegName + " registers",
291 }
292 return Error::success();
293}
294
295Error AMDGPUCodeGenPassBuilder::validateRegAllocOptions() const {
296 // 1. Generic --regalloc-npm is not supported for AMDGPU.
297 if (Opt.RegAlloc != RegAllocType::Unset) {
299 "-regalloc-npm not supported for amdgcn. Use -sgpr-regalloc-npm, "
300 "-vgpr-regalloc-npm, and -wwm-regalloc-npm",
302 }
303
304 // 2. Legacy PM regalloc options are not compatible with NPM.
305 if (SGPRRegAlloc.getNumOccurrences() > 0 ||
306 VGPRRegAlloc.getNumOccurrences() > 0 ||
307 WWMRegAlloc.getNumOccurrences() > 0) {
309 "-sgpr-regalloc, -vgpr-regalloc, and -wwm-regalloc are legacy PM "
310 "options. Use -sgpr-regalloc-npm, -vgpr-regalloc-npm, and "
311 "-wwm-regalloc-npm with the new pass manager",
313 }
314
315 // 3. Only Fast and Greedy allocators are supported for AMDGPU.
316 if (auto Err = checkRegAllocSupported(SGPRRegAllocNPM, "SGPR"))
317 return Err;
318 if (auto Err = checkRegAllocSupported(WWMRegAllocNPM, "WWM"))
319 return Err;
320 if (auto Err = checkRegAllocSupported(VGPRRegAllocNPM, "VGPR"))
321 return Err;
322
323 return Error::success();
324}
325
326static void initializeDefaultSGPRRegisterAllocatorOnce() {
327 RegisterRegAlloc::FunctionPassCtor Ctor = SGPRRegisterRegAlloc::getDefault();
328
329 if (!Ctor) {
330 Ctor = SGPRRegAlloc;
331 SGPRRegisterRegAlloc::setDefault(SGPRRegAlloc);
332 }
333}
334
335static void initializeDefaultVGPRRegisterAllocatorOnce() {
336 RegisterRegAlloc::FunctionPassCtor Ctor = VGPRRegisterRegAlloc::getDefault();
337
338 if (!Ctor) {
339 Ctor = VGPRRegAlloc;
340 VGPRRegisterRegAlloc::setDefault(VGPRRegAlloc);
341 }
342}
343
344static void initializeDefaultWWMRegisterAllocatorOnce() {
345 RegisterRegAlloc::FunctionPassCtor Ctor = WWMRegisterRegAlloc::getDefault();
346
347 if (!Ctor) {
348 Ctor = WWMRegAlloc;
349 WWMRegisterRegAlloc::setDefault(WWMRegAlloc);
350 }
351}
352
353static FunctionPass *createBasicSGPRRegisterAllocator() {
354 return createBasicRegisterAllocator(onlyAllocateSGPRs);
355}
356
357static FunctionPass *createGreedySGPRRegisterAllocator() {
358 return createGreedyRegisterAllocator(onlyAllocateSGPRs);
359}
360
361static FunctionPass *createFastSGPRRegisterAllocator() {
362 return createFastRegisterAllocator(onlyAllocateSGPRs, false);
363}
364
365static FunctionPass *createBasicVGPRRegisterAllocator() {
366 return createBasicRegisterAllocator(onlyAllocateVGPRs);
367}
368
369static FunctionPass *createGreedyVGPRRegisterAllocator() {
370 return createGreedyRegisterAllocator(onlyAllocateVGPRs);
371}
372
373static FunctionPass *createFastVGPRRegisterAllocator() {
374 return createFastRegisterAllocator(onlyAllocateVGPRs, true);
375}
376
377static FunctionPass *createBasicWWMRegisterAllocator() {
378 return createBasicRegisterAllocator(onlyAllocateWWMRegs);
379}
380
381static FunctionPass *createGreedyWWMRegisterAllocator() {
382 return createGreedyRegisterAllocator(onlyAllocateWWMRegs);
383}
384
385static FunctionPass *createFastWWMRegisterAllocator() {
386 return createFastRegisterAllocator(onlyAllocateWWMRegs, false);
387}
388
389static SGPRRegisterRegAlloc basicRegAllocSGPR(
390 "basic", "basic register allocator", createBasicSGPRRegisterAllocator);
391static SGPRRegisterRegAlloc greedyRegAllocSGPR(
392 "greedy", "greedy register allocator", createGreedySGPRRegisterAllocator);
393
394static SGPRRegisterRegAlloc fastRegAllocSGPR(
395 "fast", "fast register allocator", createFastSGPRRegisterAllocator);
396
397
398static VGPRRegisterRegAlloc basicRegAllocVGPR(
399 "basic", "basic register allocator", createBasicVGPRRegisterAllocator);
400static VGPRRegisterRegAlloc greedyRegAllocVGPR(
401 "greedy", "greedy register allocator", createGreedyVGPRRegisterAllocator);
402
403static VGPRRegisterRegAlloc fastRegAllocVGPR(
404 "fast", "fast register allocator", createFastVGPRRegisterAllocator);
405static WWMRegisterRegAlloc basicRegAllocWWMReg("basic",
406 "basic register allocator",
407 createBasicWWMRegisterAllocator);
408static WWMRegisterRegAlloc
409 greedyRegAllocWWMReg("greedy", "greedy register allocator",
410 createGreedyWWMRegisterAllocator);
411static WWMRegisterRegAlloc fastRegAllocWWMReg("fast", "fast register allocator",
412 createFastWWMRegisterAllocator);
413
415 return Phase == ThinOrFullLTOPhase::FullLTOPreLink ||
416 Phase == ThinOrFullLTOPhase::ThinLTOPreLink;
417}
418} // anonymous namespace
419
420static cl::opt<bool>
422 cl::desc("Run early if-conversion"),
423 cl::init(false));
424
425static cl::opt<bool>
426OptExecMaskPreRA("amdgpu-opt-exec-mask-pre-ra", cl::Hidden,
427 cl::desc("Run pre-RA exec mask optimizations"),
428 cl::init(true));
429
430static cl::opt<bool>
431 LowerCtorDtor("amdgpu-lower-global-ctor-dtor",
432 cl::desc("Lower GPU ctor / dtors to globals on the device."),
433 cl::init(true), cl::Hidden);
434
435// Option to disable vectorizer for tests.
437 "amdgpu-load-store-vectorizer",
438 cl::desc("Enable load store vectorizer"),
439 cl::init(true),
440 cl::Hidden);
441
442// Option to control global loads scalarization
444 "amdgpu-scalarize-global-loads",
445 cl::desc("Enable global load scalarization"),
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 EnableMachinePipeliner("amdgpu-enable-pipeliner",
670 cl::desc("Enable Machine Pipeliner for AMDGCN"),
671 cl::init(false), cl::Hidden);
672
674 // Register the target
678
764}
765
766static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
767 return std::make_unique<AMDGPUTargetObjectFile>();
768}
769
773
774static ScheduleDAGInstrs *
776 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
777 ScheduleDAGMILive *DAG =
778 new GCNScheduleDAGMILive(C, std::make_unique<GCNMaxOccupancySchedStrategy>(C));
779 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
780 if (ST.shouldClusterStores())
781 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
783 DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
784 DAG->addMutation(createAMDGPUExportClusteringDAGMutation());
785 DAG->addMutation(createAMDGPUBarrierLatencyDAGMutation(C->MF));
786 DAG->addMutation(createAMDGPUHazardLatencyDAGMutation(C->MF));
787 return DAG;
788}
789
790static ScheduleDAGInstrs *
792 ScheduleDAGMILive *DAG =
793 new GCNScheduleDAGMILive(C, std::make_unique<GCNMaxILPSchedStrategy>(C));
795 return DAG;
796}
797
798static ScheduleDAGInstrs *
800 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
802 C, std::make_unique<GCNMaxMemoryClauseSchedStrategy>(C));
803 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
804 if (ST.shouldClusterStores())
805 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
806 DAG->addMutation(createAMDGPUExportClusteringDAGMutation());
807 DAG->addMutation(createAMDGPUBarrierLatencyDAGMutation(C->MF));
808 DAG->addMutation(createAMDGPUHazardLatencyDAGMutation(C->MF));
809 return DAG;
810}
811
812static ScheduleDAGInstrs *
814 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
815 auto *DAG = new GCNIterativeScheduler(
817 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
818 if (ST.shouldClusterStores())
819 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
821 return DAG;
822}
823
830
831static ScheduleDAGInstrs *
833 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
835 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
836 if (ST.shouldClusterStores())
837 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
838 DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
840 return DAG;
841}
842
843static MachineSchedRegistry
844SISchedRegistry("si", "Run SI's custom scheduler",
846
849 "Run GCN scheduler to maximize occupancy",
851
853 GCNMaxILPSchedRegistry("gcn-max-ilp", "Run GCN scheduler to maximize ilp",
855
857 "gcn-max-memory-clause", "Run GCN scheduler to maximize memory clause",
859
861 "gcn-iterative-max-occupancy-experimental",
862 "Run GCN scheduler to maximize occupancy (experimental)",
864
866 "gcn-iterative-minreg",
867 "Run GCN iterative scheduler for minimal register usage (experimental)",
869
871 "gcn-iterative-ilp",
872 "Run GCN iterative scheduler for ILP scheduling (experimental)",
874
877 if (!GPU.empty())
878 return GPU;
879
880 if (StringRef Name = AMDGPU::getArchNameFromSubArch(TT.getSubArch());
881 !Name.empty())
882 return Name;
883
884 // Need to default to a target with flat support for HSA.
885 if (TT.isAMDGCN())
886 return TT.getOS() == Triple::AMDHSA ? "generic-hsa" : "generic";
887
888 return "r600";
889}
890
892 // The AMDGPU toolchain only supports generating shared objects, so we
893 // must always use PIC.
894 return Reloc::PIC_;
895}
896
898 StringRef CPU, StringRef FS,
899 const TargetOptions &Options,
900 std::optional<Reloc::Model> RM,
901 std::optional<CodeModel::Model> CM,
904 T, TT.computeDataLayout(), TT, getGPUOrDefault(TT, CPU), FS, Options,
906 OptLevel),
908 initAsmInfo();
909 if (TT.isAMDGCN()) {
910 // Triple is missing a representation for non-empty, but unrecognized
911 // subarches. Only permit no subarch for any subtarget if it was really
912 // empty.
913 bool IsUnknownSubArch =
914 TT.getSubArch() == Triple::NoSubArch && TT.getArchName().size() != 6;
915 if (IsUnknownSubArch)
916 reportFatalUsageError("unknown subarch " + TT.getArchName());
917
918 if (TT.getSubArch() != Triple::NoSubArch) {
920 Triple::SubArchType GPUSubArch = AMDGPU::getSubArch(Kind);
921 if (Kind != AMDGPU::GK_NONE && GPUSubArch != TT.getSubArch() &&
922 TT.getSubArch() != AMDGPU::getMajorSubArch(GPUSubArch)) {
923 reportFatalUsageError("invalid cpu '" + CPU + "' for subarch " +
924 TT.getArchName());
925 }
926 }
927
928 if (getMCSubtargetInfo().checkFeatures("+wavefrontsize64"))
930 else if (getMCSubtargetInfo().checkFeatures("+wavefrontsize32"))
932 }
934}
935
939
941
943 Attribute GPUAttr = F.getFnAttribute("target-cpu");
944 return GPUAttr.isValid() ? GPUAttr.getValueAsString() : getTargetCPU();
945}
946
948 Attribute FSAttr = F.getFnAttribute("target-features");
949
950 return FSAttr.isValid() ? FSAttr.getValueAsString()
952}
953
956 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
958 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
959 if (ST.shouldClusterStores())
960 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
961 return DAG;
962}
963
964/// Predicate for Internalize pass.
965static bool mustPreserveGV(const GlobalValue &GV) {
966 if (const Function *F = dyn_cast<Function>(&GV))
967 return F->isDeclaration() || F->getName().starts_with("__asan_") ||
968 F->getName().starts_with("__sanitizer_") ||
969 AMDGPU::isEntryFunctionCC(F->getCallingConv());
970
972 return !GV.use_empty();
973}
974
979
982 if (Params.empty())
984 Params.consume_front("strategy=");
985 auto Result = StringSwitch<std::optional<ScanOptions>>(Params)
986 .Case("dpp", ScanOptions::DPP)
987 .Cases({"iterative", ""}, ScanOptions::Iterative)
988 .Case("none", ScanOptions::None)
989 .Default(std::nullopt);
990 if (Result)
991 return *Result;
992 return make_error<StringError>("invalid parameter", inconvertibleErrorCode());
993}
994
998 while (!Params.empty()) {
999 StringRef ParamName;
1000 std::tie(ParamName, Params) = Params.split(';');
1001 if (ParamName == "closed-world") {
1002 Result.IsClosedWorld = true;
1003 } else {
1005 formatv("invalid AMDGPUAttributor pass parameter '{0}' ", ParamName)
1006 .str(),
1008 }
1009 }
1010 return Result;
1011}
1012
1014
1015#define GET_PASS_REGISTRY "AMDGPUPassRegistry.def"
1017
1018 PB.registerPipelineParsingCallback(
1019 [this](StringRef Name, CGSCCPassManager &PM,
1021 if (Name == "amdgpu-attributor-cgscc" && getTargetTriple().isAMDGCN()) {
1023 *static_cast<GCNTargetMachine *>(this)));
1024 return true;
1025 }
1026 return false;
1027 });
1028
1029 PB.registerScalarOptimizerLateEPCallback(
1030 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1031 if (Level == OptimizationLevel::O0)
1032 return;
1033
1035 });
1036
1037 PB.registerVectorizerEndEPCallback(
1038 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1039 if (Level == OptimizationLevel::O0)
1040 return;
1041
1043 });
1044
1045 PB.registerPipelineEarlySimplificationEPCallback(
1046 [this](ModulePassManager &PM, OptimizationLevel Level,
1048 if (!isLTOPreLink(Phase) && getTargetTriple().isAMDGCN()) {
1049 // When we are not using -fgpu-rdc, we can run accelerator code
1050 // selection relatively early, but still after linking to prevent
1051 // eager removal of potentially reachable symbols.
1052 if (EnableHipStdPar) {
1055 }
1056
1058 }
1059
1060 if (Level == OptimizationLevel::O0)
1061 return;
1062
1063 // We don't want to run internalization at per-module stage.
1066 PM.addPass(GlobalDCEPass());
1067 }
1068
1071 });
1072
1073 PB.registerPeepholeEPCallback(
1074 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1075 if (Level == OptimizationLevel::O0)
1076 return;
1077
1081
1084 });
1085
1086 PB.registerCGSCCOptimizerLateEPCallback(
1087 [this](CGSCCPassManager &PM, OptimizationLevel Level) {
1088 if (Level == OptimizationLevel::O0)
1089 return;
1090
1092
1093 // Add promote kernel arguments pass to the opt pipeline right before
1094 // infer address spaces which is needed to do actual address space
1095 // rewriting.
1098
1099 // Add infer address spaces pass to the opt pipeline after inlining
1100 // but before SROA to increase SROA opportunities.
1102
1103 // This should run after inlining to have any chance of doing
1104 // anything, and before other cleanup optimizations.
1106
1107 // Promote alloca to vector before SROA and loop unroll. If we
1108 // manage to eliminate allocas before unroll we may choose to unroll
1109 // less.
1111
1112 PM.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
1113 });
1114
1115 // FIXME: Why is AMDGPUAttributor not in CGSCC?
1116 PB.registerOptimizerLastEPCallback([this](ModulePassManager &MPM,
1117 OptimizationLevel Level,
1119 if (Level != OptimizationLevel::O0) {
1120 if (!isLTOPreLink(Phase)) {
1121 if (EnableAMDGPUAttributor && getTargetTriple().isAMDGCN()) {
1123 MPM.addPass(AMDGPUAttributorPass(*this, Opts, Phase));
1124 }
1125 }
1126 }
1127 });
1128
1129 PB.registerFullLinkTimeOptimizationLastEPCallback(
1130 [this](ModulePassManager &PM, OptimizationLevel Level) {
1131 // Clean up redundant memory round-trips that the full-LTO pipeline,
1132 // unlike the non-LTO/ThinLTO ones, otherwise leaves for codegen.
1133 if (Level != OptimizationLevel::O0) {
1135 EarlyCSEPass(/*UseMemorySSA=*/true)));
1136 }
1137
1138 // When we are using -fgpu-rdc, we can only run accelerator code
1139 // selection after linking to prevent, otherwise we end up removing
1140 // potentially reachable symbols that were exported as external in other
1141 // modules.
1142 if (EnableHipStdPar) {
1145 }
1146 // We want to support the -lto-partitions=N option as "best effort".
1147 // For that, we need to lower LDS earlier in the pipeline before the
1148 // module is partitioned for codegen.
1151 if (EnableSwLowerLDS)
1155 if (Level != OptimizationLevel::O0) {
1156 // We only want to run this with O2 or higher since inliner and SROA
1157 // don't run in O1.
1158 if (Level != OptimizationLevel::O1) {
1159 PM.addPass(
1161 }
1162 // Do we really need internalization in LTO?
1163 if (InternalizeSymbols) {
1165 PM.addPass(GlobalDCEPass());
1166 }
1167 if (EnableAMDGPUAttributor && getTargetTriple().isAMDGCN()) {
1170 Opt.IsClosedWorld = true;
1173 }
1174 }
1175 if (!NoKernelInfoEndLTO) {
1177 FPM.addPass(KernelInfoPrinter(this));
1178 PM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1179 }
1180 });
1181
1182 PB.registerRegClassFilterParsingCallback(
1183 [](StringRef FilterName) -> RegAllocFilterFunc {
1184 if (FilterName == "sgpr")
1185 return onlyAllocateSGPRs;
1186 if (FilterName == "vgpr")
1187 return onlyAllocateVGPRs;
1188 if (FilterName == "wwm")
1189 return onlyAllocateWWMRegs;
1190 return nullptr;
1191 });
1192}
1193
1195 unsigned DestAS) const {
1196 return AMDGPU::isFlatGlobalAddrSpace(SrcAS) &&
1198}
1199
1201 if (auto *Arg = dyn_cast<Argument>(V);
1202 Arg &&
1203 AMDGPU::isModuleEntryFunctionCC(Arg->getParent()->getCallingConv()) &&
1204 !Arg->hasByRefAttr())
1206
1207 const auto *LD = dyn_cast<LoadInst>(V);
1208 if (!LD) // TODO: Handle invariant load like constant.
1210
1211 // It must be a generic pointer loaded.
1212 assert(V->getType()->getPointerAddressSpace() == AMDGPUAS::FLAT_ADDRESS);
1213
1214 const auto *Ptr = LD->getPointerOperand();
1215 if (Ptr->getType()->getPointerAddressSpace() != AMDGPUAS::CONSTANT_ADDRESS)
1217 // For a generic pointer loaded from the constant memory, it could be assumed
1218 // as a global pointer since the constant memory is only populated on the
1219 // host side. As implied by the offload programming model, only global
1220 // pointers could be referenced on the host side.
1222}
1223
1224std::pair<const Value *, unsigned>
1226 if (auto *II = dyn_cast<IntrinsicInst>(V)) {
1227 switch (II->getIntrinsicID()) {
1228 case Intrinsic::amdgcn_is_shared:
1229 return std::pair(II->getArgOperand(0), AMDGPUAS::LOCAL_ADDRESS);
1230 case Intrinsic::amdgcn_is_private:
1231 return std::pair(II->getArgOperand(0), AMDGPUAS::PRIVATE_ADDRESS);
1232 default:
1233 break;
1234 }
1235 return std::pair(nullptr, -1);
1236 }
1237 // Check the global pointer predication based on
1238 // (!is_share(p) && !is_private(p)). Note that logic 'and' is commutative and
1239 // the order of 'is_shared' and 'is_private' is not significant.
1240 Value *Ptr;
1241 if (match(
1242 const_cast<Value *>(V),
1245 m_Deferred(Ptr))))))
1246 return std::pair(Ptr, AMDGPUAS::GLOBAL_ADDRESS);
1247
1248 return std::pair(nullptr, -1);
1249}
1250
1251unsigned
1266
1268 Module &M, unsigned NumParts,
1269 function_ref<void(std::unique_ptr<Module> MPart)> ModuleCallback) {
1270 // FIXME(?): Would be better to use an already existing Analysis/PassManager,
1271 // but all current users of this API don't have one ready and would need to
1272 // create one anyway. Let's hide the boilerplate for now to keep it simple.
1273
1278
1279 PassBuilder PB(this);
1280 PB.registerModuleAnalyses(MAM);
1281 PB.registerFunctionAnalyses(FAM);
1282 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
1283
1285 MPM.addPass(AMDGPUSplitModulePass(NumParts, ModuleCallback));
1286 MPM.run(M, MAM);
1287 return true;
1288}
1289
1290//===----------------------------------------------------------------------===//
1291// GCN Target Machine (SI+)
1292//===----------------------------------------------------------------------===//
1293
1295 StringRef CPU, StringRef FS,
1296 const TargetOptions &Options,
1297 std::optional<Reloc::Model> RM,
1298 std::optional<CodeModel::Model> CM,
1299 CodeGenOptLevel OL, bool JIT)
1300 : AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {
1302}
1303
1304enum class OOBFlagValue {
1305 Any = 0,
1308};
1309
1310/// Returns the OOB mode encoded by a module flag.
1311/// An absent flag defaults to Any.
1312static OOBFlagValue getOOBFlagValue(const Module &M, StringRef FlagName) {
1313 const auto *Flag =
1314 mdconst::dyn_extract_or_null<ConstantInt>(M.getModuleFlag(FlagName));
1315 if (!Flag)
1316 return OOBFlagValue::Any;
1317 return static_cast<OOBFlagValue>(Flag->getZExtValue());
1318}
1319
1320/// Returns the xnack/sramecc setting encoded by a module flag.
1321/// Module flag values: 0 = disabled, 1 = enabled.
1322/// An absent flag defaults to Any.
1325 StringRef FlagName) {
1327
1328 if (XnackSetting.getNumOccurrences() > 0 && FlagName == "amdgpu.xnack")
1329 return XnackSetting ? TargetIDSetting::On : TargetIDSetting::Off;
1330 if (SramEccSetting.getNumOccurrences() > 0 && FlagName == "amdgpu.sramecc")
1331 return SramEccSetting ? TargetIDSetting::On : TargetIDSetting::Off;
1332
1333 const auto *Flag =
1334 mdconst::dyn_extract_or_null<ConstantInt>(M.getModuleFlag(FlagName));
1335 if (!Flag)
1336 return TargetIDSetting::Any;
1337 return Flag->getZExtValue() == 0 ? TargetIDSetting::Off : TargetIDSetting::On;
1338}
1339
1340const TargetSubtargetInfo *
1342 StringRef GPU = getGPUName(F);
1344
1345 const Module &M = *F.getParent();
1348 bool BufRelaxed = BufOOB == OOBFlagValue::Relaxed;
1349 bool TBufRelaxed = TBufOOB == OOBFlagValue::Relaxed;
1350
1352 TargetIDSetting Xnack = getTargetIDSettingFromModuleFlag(M, "amdgpu.xnack");
1353 TargetIDSetting SramEcc =
1354 getTargetIDSettingFromModuleFlag(M, "amdgpu.sramecc");
1355
1356 SmallString<128> SubtargetKey(GPU);
1357 SubtargetKey.append(FS);
1358 if (BufRelaxed)
1359 SubtargetKey.append(",buf-oob=1");
1360 if (TBufRelaxed)
1361 SubtargetKey.append(",tbuf-oob=1");
1362 if (Xnack != TargetIDSetting::Any) {
1363 SubtargetKey.append(",xnack=");
1364 SubtargetKey.push_back(Xnack == TargetIDSetting::On ? '1' : '0');
1365 }
1366 if (SramEcc != TargetIDSetting::Any) {
1367 SubtargetKey.append(",sramecc=");
1368 SubtargetKey.push_back(Xnack == TargetIDSetting::On ? '1' : '0');
1369 }
1370
1371 auto &I = SubtargetMap[SubtargetKey];
1372 if (!I) {
1374 Triple::SubArchType GPUSubArch = AMDGPU::getSubArch(Kind);
1375
1376 // Enforce the subtarget is covered by the subarch. Tolerate no subarch for
1377 // legacy compatibility.
1378 const Triple &TT = M.getTargetTriple();
1379 if (GPUSubArch != TT.getSubArch() && Kind != AMDGPU::GK_NONE) {
1380 // Check if this is a generic subarch which has subtargets. Ignore
1381 // unknown subtargets with a known subarch, since for whatever reason
1382 // the convention is to just print a warning and ignore unrecognized
1383 // subtargets.
1384 bool IsLegacyEmptySubArch = TT.getSubArch() == Triple::NoSubArch;
1385 if (!IsLegacyEmptySubArch &&
1386 AMDGPU::getMajorSubArch(GPUSubArch) != TT.getSubArch()) {
1387 F.getContext().emitError("invalid subtarget '" + Twine(GPU) +
1388 "' for subarch " + TT.getArchName());
1389 }
1390 }
1391
1392 I = std::make_unique<GCNSubtarget>(TargetTriple, GPU, FS, *this, BufRelaxed,
1393 TBufRelaxed, Xnack, SramEcc);
1394 }
1395
1396 I->setScalarizeGlobalBehavior(ScalarizeGlobal);
1397
1398 return I.get();
1399}
1400
1403 return TargetTransformInfo(std::make_unique<GCNTTIImpl>(this, F));
1404}
1405
1408 raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
1409 const CGPassBuilderOption &Opts, MCContext &Ctx,
1411 AMDGPUCodeGenPassBuilder CGPB(*this, Opts, PIC);
1412 return CGPB.buildPipeline(MPM, MAM, Out, DwoOut, FileType, Ctx);
1413}
1414
1417 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
1418 if (ST.enableSIScheduler())
1420
1421 StringRef SchedStrategy = AMDGPU::getSchedStrategy(C->MF->getFunction());
1422
1423 if (SchedStrategy == "max-ilp")
1425
1426 if (SchedStrategy == "max-memory-clause")
1428
1429 if (SchedStrategy == "iterative-ilp")
1431
1432 if (SchedStrategy == "iterative-minreg")
1433 return createMinRegScheduler(C);
1434
1435 if (SchedStrategy == "iterative-maxocc")
1437
1438 if (SchedStrategy == "coexec") {
1439 diagnoseUnsupportedCoExecSchedulerSelection(C->MF->getFunction(), ST);
1441 }
1442
1444}
1445
1448 if (useNoopPostScheduler(C->MF->getFunction()))
1450
1451 ScheduleDAGMI *DAG =
1452 new GCNPostScheduleDAGMILive(C, std::make_unique<PostGenericScheduler>(C),
1453 /*RemoveKillFlags=*/true);
1454 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
1456 if (ST.shouldClusterStores())
1459 if ((EnableVOPD.getNumOccurrences() ||
1461 EnableVOPD)
1466 return DAG;
1467}
1468//===----------------------------------------------------------------------===//
1469// AMDGPU Legacy Pass Setup
1470//===----------------------------------------------------------------------===//
1471
1472std::unique_ptr<CSEConfigBase> llvm::AMDGPUPassConfig::getCSEConfig() const {
1473 return getStandardCSEConfigForOpt(TM->getOptLevel());
1474}
1475
1476namespace {
1477
1478class GCNPassConfig final : public AMDGPUPassConfig {
1479public:
1480 GCNPassConfig(TargetMachine &TM, PassManagerBase &PM)
1481 : AMDGPUPassConfig(TM, PM) {
1482 substitutePass(&PostRASchedulerID, &PostMachineSchedulerID);
1483 }
1484
1485 GCNTargetMachine &getGCNTargetMachine() const {
1486 return getTM<GCNTargetMachine>();
1487 }
1488
1489 bool addPreISel() override;
1490 void addMachineSSAOptimization() override;
1491 bool addILPOpts() override;
1492 bool addInstSelector() override;
1493 bool addIRTranslator() override;
1494 void addPreLegalizeMachineIR() override;
1495 bool addLegalizeMachineIR() override;
1496 void addPreRegBankSelect() override;
1497 bool addRegBankSelect() override;
1498 void addPreGlobalInstructionSelect() override;
1499 bool addGlobalInstructionSelect() override;
1500 void addPreRegAlloc() override;
1501 void addFastRegAlloc() override;
1502 void addOptimizedRegAlloc() override;
1503
1504 FunctionPass *createSGPRAllocPass(bool Optimized);
1505 FunctionPass *createVGPRAllocPass(bool Optimized);
1506 FunctionPass *createWWMRegAllocPass(bool Optimized);
1507 FunctionPass *createRegAllocPass(bool Optimized) override;
1508
1509 bool addRegAssignAndRewriteFast() override;
1510 bool addRegAssignAndRewriteOptimized() override;
1511
1512 bool addPreRewrite() override;
1513 void addPostRegAlloc() override;
1514 void addPreSched2() override;
1515 void addPreEmitPass() override;
1516 void addPostBBSections() override;
1517};
1518
1519} // end anonymous namespace
1520
1522 : TargetPassConfig(TM, PM) {
1523 // Exceptions and StackMaps are not supported, so these passes will never do
1524 // anything.
1527 // Garbage collection is not supported.
1530}
1531
1538
1543 // ReassociateGEPs exposes more opportunities for SLSR. See
1544 // the example in reassociate-geps-and-slsr.ll.
1546 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
1547 // EarlyCSE can reuse.
1549 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
1551 // NaryReassociate on GEPs creates redundant common expressions, so run
1552 // EarlyCSE after it.
1554}
1555
1558
1559 if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN())
1561
1562 // There is no reason to run these.
1566
1567 if (TM.getTargetTriple().isAMDGCN())
1569
1570 if (LowerCtorDtor)
1572
1573 if (TM.getTargetTriple().isAMDGCN() &&
1576
1579
1580 // This can be disabled by passing ::Disable here or on the command line
1581 // with --expand-variadics-override=disable.
1583
1584 // Function calls are not supported, so make sure we inline everything.
1587
1588 // Handle uses of OpenCL image2d_t, image3d_t and sampler_t arguments.
1589 if (TM.getTargetTriple().getArch() == Triple::r600)
1591
1592 // Make enqueued block runtime handles externally visible.
1594
1595 // Lower special LDS accesses.
1598
1599 // Lower LDS accesses to global memory pass if address sanitizer is enabled.
1600 if (EnableSwLowerLDS)
1602
1603 // Runs before PromoteAlloca so the latter can account for function uses
1606 }
1607
1608 // Run atomic optimizer before Atomic Expand
1609 if ((TM.getTargetTriple().isAMDGCN()) &&
1610 (TM.getOptLevel() >= CodeGenOptLevel::Less) &&
1613 }
1614
1616
1617 if (TM.getOptLevel() > CodeGenOptLevel::None) {
1619
1622
1626 AAResults &AAR) {
1627 if (auto *WrapperPass = P.getAnalysisIfAvailable<AMDGPUAAWrapperPass>())
1628 AAR.addAAResult(WrapperPass->getResult());
1629 }));
1630 }
1631
1632 if (TM.getTargetTriple().isAMDGCN()) {
1633 // TODO: May want to move later or split into an early and late one.
1635 }
1636
1637 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
1638 // have expanded.
1639 if (TM.getOptLevel() > CodeGenOptLevel::Less)
1641 }
1642
1644
1645 // EarlyCSE is not always strong enough to clean up what LSR produces. For
1646 // example, GVN can combine
1647 //
1648 // %0 = add %a, %b
1649 // %1 = add %b, %a
1650 //
1651 // and
1652 //
1653 // %0 = shl nsw %a, 2
1654 // %1 = shl %a, 2
1655 //
1656 // but EarlyCSE can do neither of them.
1659}
1660
1662 if (TM->getTargetTriple().isAMDGCN() &&
1663 TM->getOptLevel() > CodeGenOptLevel::None)
1665
1666 if (TM->getTargetTriple().isAMDGCN() && EnableLowerKernelArguments)
1668
1670
1673
1674 if (TM->getTargetTriple().isAMDGCN()) {
1675 // This lowering has been placed after codegenprepare to take advantage of
1676 // address mode matching (which is why it isn't put with the LDS lowerings).
1677 // It could be placed anywhere before uniformity annotations (an analysis
1678 // that it changes by splitting up fat pointers into their components)
1679 // but has been put before switch lowering and CFG flattening so that those
1680 // passes can run on the more optimized control flow this pass creates in
1681 // many cases.
1684 }
1685
1686 // LowerSwitch pass may introduce unreachable blocks that can
1687 // cause unexpected behavior for subsequent passes. Placing it
1688 // here seems better that these blocks would get cleaned up by
1689 // UnreachableBlockElim inserted next in the pass flow.
1691}
1692
1694 if (TM->getOptLevel() > CodeGenOptLevel::None)
1696 return false;
1697}
1698
1703
1705 // Do nothing. GC is not supported.
1706 return false;
1707}
1708
1709//===----------------------------------------------------------------------===//
1710// GCN Legacy Pass Setup
1711//===----------------------------------------------------------------------===//
1712
1713bool GCNPassConfig::addPreISel() {
1715
1716 if (TM->getOptLevel() > CodeGenOptLevel::None) {
1717 addPass(createSinkingPass());
1719 }
1720
1721 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
1722 // regions formed by them.
1724 addPass(createFixIrreduciblePass());
1725 addPass(createUnifyLoopExitsPass());
1726 addPass(createStructurizeCFGPass(false)); // true -> SkipUniformRegions
1727
1730 // TODO: Move this right after structurizeCFG to avoid extra divergence
1731 // analysis. This depends on stopping SIAnnotateControlFlow from making
1732 // control flow modifications.
1734
1735 // SDAG requires LCSSA, GlobalISel does not. Disable LCSSA for -global-isel
1736 // without any of the fallback options.
1739 !isGlobalISelAbortEnabled())
1740 addPass(createLCSSAPass());
1741
1742 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1744
1745 return false;
1746}
1747
1748void GCNPassConfig::addMachineSSAOptimization() {
1750
1751 // We want to fold operands after PeepholeOptimizer has run (or as part of
1752 // it), because it will eliminate extra copies making it easier to fold the
1753 // real source operand. We want to eliminate dead instructions after, so that
1754 // we see fewer uses of the copies. We then need to clean up the dead
1755 // instructions leftover after the operands are folded as well.
1756 //
1757 // XXX - Can we get away without running DeadMachineInstructionElim again?
1758 addPass(&SIFoldOperandsLegacyID);
1759 if (EnableDPPCombine)
1760 addPass(&GCNDPPCombineLegacyID);
1762 if (isPassEnabled(EnableSDWAPeephole)) {
1763 addPass(&SIPeepholeSDWALegacyID);
1764 addPass(&EarlyMachineLICMID);
1765 addPass(&MachineCSELegacyID);
1766 addPass(&SIFoldOperandsLegacyID);
1767 }
1770}
1771
1772bool GCNPassConfig::addILPOpts() {
1774 addPass(&EarlyIfConverterLegacyID);
1775
1777 return false;
1778}
1779
1780bool GCNPassConfig::addInstSelector() {
1782 addPass(&SIFixSGPRCopiesLegacyID);
1784 return false;
1785}
1786
1787bool GCNPassConfig::addIRTranslator() {
1788 addPass(new IRTranslatorLegacy(getOptLevel()));
1789 return false;
1790}
1791
1792void GCNPassConfig::addPreLegalizeMachineIR() {
1793 bool IsOptLevelNone = getOptLevel() == CodeGenOptLevel::None;
1794 addPass(createAMDGPUPreLegalizeCombinerLegacyPass(IsOptLevelNone));
1795 addPass(new LocalizerLegacy());
1796}
1797
1798bool GCNPassConfig::addLegalizeMachineIR() {
1799 addPass(new LegalizerLegacy());
1800 return false;
1801}
1802
1803void GCNPassConfig::addPreRegBankSelect() {
1804 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1805 addPass(createAMDGPUPostLegalizeCombinerLegacy(IsOptNone));
1807}
1808
1809bool GCNPassConfig::addRegBankSelect() {
1812 return false;
1813}
1814
1815void GCNPassConfig::addPreGlobalInstructionSelect() {
1816 bool IsOptLevelNone = getOptLevel() == CodeGenOptLevel::None;
1817 addPass(createAMDGPURegBankCombinerLegacy(IsOptLevelNone));
1818}
1819
1820bool GCNPassConfig::addGlobalInstructionSelect() {
1821 addPass(new InstructionSelectLegacy(getOptLevel()));
1822 return false;
1823}
1824
1825void GCNPassConfig::addFastRegAlloc() {
1826 // FIXME: We have to disable the verifier here because of PHIElimination +
1827 // TwoAddressInstructions disabling it.
1828
1829 // This must be run immediately after phi elimination and before
1830 // TwoAddressInstructions, otherwise the processing of the tied operand of
1831 // SI_ELSE will introduce a copy of the tied operand source after the else.
1833
1835
1837}
1838
1839void GCNPassConfig::addPreRegAlloc() {
1840 if (getOptLevel() != CodeGenOptLevel::None)
1842 if (getOptLevel() >= CodeGenOptLevel::Default && EnableMachinePipeliner)
1843 addPass(&MachinePipelinerID);
1844}
1845
1846void GCNPassConfig::addOptimizedRegAlloc() {
1847 if (EnableDCEInRA)
1849
1850 // FIXME: when an instruction has a Killed operand, and the instruction is
1851 // inside a bundle, seems only the BUNDLE instruction appears as the Kills of
1852 // the register in LiveVariables, this would trigger a failure in verifier,
1853 // we should fix it and enable the verifier.
1854 if (OptVGPRLiveRange)
1856
1857 // This must be run immediately after phi elimination and before
1858 // TwoAddressInstructions, otherwise the processing of the tied operand of
1859 // SI_ELSE will introduce a copy of the tied operand source after the else.
1861
1864
1865 if (isPassEnabled(EnablePreRAOptimizations))
1867
1868 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
1869 // instructions that cause scheduling barriers.
1871
1872 if (OptExecMaskPreRA)
1874
1875 // This is not an essential optimization and it has a noticeable impact on
1876 // compilation time, so we only enable it from O2.
1877 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1879
1881}
1882
1883bool GCNPassConfig::addPreRewrite() {
1885 addPass(&GCNNSAReassignID);
1886
1888 return true;
1889}
1890
1891FunctionPass *GCNPassConfig::createSGPRAllocPass(bool Optimized) {
1892 // Initialize the global default.
1893 llvm::call_once(InitializeDefaultSGPRRegisterAllocatorFlag,
1894 initializeDefaultSGPRRegisterAllocatorOnce);
1895
1896 RegisterRegAlloc::FunctionPassCtor Ctor = SGPRRegisterRegAlloc::getDefault();
1897 if (Ctor != useDefaultRegisterAllocator)
1898 return Ctor();
1899
1900 if (Optimized)
1901 return createGreedyRegisterAllocator(onlyAllocateSGPRs);
1902
1903 return createFastRegisterAllocator(onlyAllocateSGPRs, false);
1904}
1905
1906FunctionPass *GCNPassConfig::createVGPRAllocPass(bool Optimized) {
1907 // Initialize the global default.
1908 llvm::call_once(InitializeDefaultVGPRRegisterAllocatorFlag,
1909 initializeDefaultVGPRRegisterAllocatorOnce);
1910
1911 RegisterRegAlloc::FunctionPassCtor Ctor = VGPRRegisterRegAlloc::getDefault();
1912 if (Ctor != useDefaultRegisterAllocator)
1913 return Ctor();
1914
1915 if (Optimized)
1916 return createGreedyVGPRRegisterAllocator();
1917
1918 return createFastVGPRRegisterAllocator();
1919}
1920
1921FunctionPass *GCNPassConfig::createWWMRegAllocPass(bool Optimized) {
1922 // Initialize the global default.
1923 llvm::call_once(InitializeDefaultWWMRegisterAllocatorFlag,
1924 initializeDefaultWWMRegisterAllocatorOnce);
1925
1926 RegisterRegAlloc::FunctionPassCtor Ctor = WWMRegisterRegAlloc::getDefault();
1927 if (Ctor != useDefaultRegisterAllocator)
1928 return Ctor();
1929
1930 if (Optimized)
1931 return createGreedyWWMRegisterAllocator();
1932
1933 return createFastWWMRegisterAllocator();
1934}
1935
1936FunctionPass *GCNPassConfig::createRegAllocPass(bool Optimized) {
1937 llvm_unreachable("should not be used");
1938}
1939
1941 "-regalloc not supported with amdgcn. Use -sgpr-regalloc, -wwm-regalloc, "
1942 "and -vgpr-regalloc";
1943
1944bool GCNPassConfig::addRegAssignAndRewriteFast() {
1945 if (!usingDefaultRegAlloc())
1947
1948 addPass(&GCNPreRALongBranchRegID);
1949
1950 addPass(createSGPRAllocPass(false));
1951
1952 // Equivalent of PEI for SGPRs.
1953 addPass(&SILowerSGPRSpillsLegacyID);
1954
1955 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1957
1958 // For allocating other wwm register operands.
1959 addPass(createWWMRegAllocPass(false));
1960
1961 addPass(&SILowerWWMCopiesLegacyID);
1963
1964 // For allocating per-thread VGPRs.
1965 addPass(createVGPRAllocPass(false));
1966
1967 return true;
1968}
1969
1970bool GCNPassConfig::addRegAssignAndRewriteOptimized() {
1971 if (!usingDefaultRegAlloc())
1973
1974 addPass(&GCNPreRALongBranchRegID);
1975
1976 addPass(createSGPRAllocPass(true));
1977
1978 // Commit allocated register changes. This is mostly necessary because too
1979 // many things rely on the use lists of the physical registers, such as the
1980 // verifier. This is only necessary with allocators which use LiveIntervals,
1981 // since FastRegAlloc does the replacements itself.
1982 addPass(createVirtRegRewriter(false));
1983
1984 // At this point, the sgpr-regalloc has been done and it is good to have the
1985 // stack slot coloring to try to optimize the SGPR spill stack indices before
1986 // attempting the custom SGPR spill lowering.
1987 addPass(&StackSlotColoringID);
1988
1989 // Equivalent of PEI for SGPRs.
1990 addPass(&SILowerSGPRSpillsLegacyID);
1991
1992 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1994
1995 // For allocating other whole wave mode registers.
1996 addPass(createWWMRegAllocPass(true));
1997 addPass(&SILowerWWMCopiesLegacyID);
1998 addPass(createVirtRegRewriter(false));
2000
2001 // For allocating per-thread VGPRs.
2002 addPass(createVGPRAllocPass(true));
2003
2004 addPreRewrite();
2005 addPass(&VirtRegRewriterID);
2006
2008
2009 return true;
2010}
2011
2012void GCNPassConfig::addPostRegAlloc() {
2013 addPass(&SIFixVGPRCopiesID);
2014 if (getOptLevel() > CodeGenOptLevel::None)
2017}
2018
2019void GCNPassConfig::addPreSched2() {
2020 if (TM->getOptLevel() > CodeGenOptLevel::None)
2022 addPass(&SIPostRABundlerLegacyID);
2023}
2024
2025void GCNPassConfig::addPreEmitPass() {
2026 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less))
2027 addPass(&GCNCreateVOPDID);
2028 addPass(createSIMemoryLegalizerPass());
2029 addPass(createSIInsertWaitcntsPass());
2030
2031 addPass(createSIModeRegisterPass());
2032
2033 if (getOptLevel() > CodeGenOptLevel::None)
2034 addPass(&SIInsertHardClausesID);
2035
2037 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
2039 if (getOptLevel() > CodeGenOptLevel::None)
2040 addPass(&SIPreEmitPeepholeID);
2041 // The hazard recognizer that runs as part of the post-ra scheduler does not
2042 // guarantee to be able handle all hazards correctly. This is because if there
2043 // are multiple scheduling regions in a basic block, the regions are scheduled
2044 // bottom up, so when we begin to schedule a region we don't know what
2045 // instructions were emitted directly before it.
2046 //
2047 // Here we add a stand-alone hazard recognizer pass which can handle all
2048 // cases.
2049 addPass(&PostRAHazardRecognizerID);
2050
2052
2054
2055 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less))
2056 addPass(&AMDGPUInsertDelayAluID);
2057
2058 addPass(&BranchRelaxationPassID);
2059}
2060
2061void GCNPassConfig::addPostBBSections() {
2062 // We run this later to avoid passes like livedebugvalues and BBSections
2063 // having to deal with the apparent multi-entry functions we may generate.
2065}
2066
2068 return new GCNPassConfig(*this, PM);
2069}
2070
2076
2083
2087
2094
2097 SMDiagnostic &Error, SMRange &SourceRange) const {
2098 const yaml::SIMachineFunctionInfo &YamlMFI =
2099 static_cast<const yaml::SIMachineFunctionInfo &>(MFI_);
2100 MachineFunction &MF = PFS.MF;
2102 const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
2103
2104 if (MFI->initializeBaseYamlFields(YamlMFI, MF, PFS, Error, SourceRange))
2105 return true;
2106
2107 if (MFI->Occupancy == 0) {
2108 // Fixup the subtarget dependent default value.
2109 MFI->Occupancy = ST.getOccupancyWithWorkGroupSizes(MF).second;
2110 }
2111
2112 auto parseRegister = [&](const yaml::StringValue &RegName, Register &RegVal) {
2113 Register TempReg;
2114 if (parseNamedRegisterReference(PFS, TempReg, RegName.Value, Error)) {
2115 SourceRange = RegName.SourceRange;
2116 return true;
2117 }
2118 RegVal = TempReg;
2119
2120 return false;
2121 };
2122
2123 auto parseOptionalRegister = [&](const yaml::StringValue &RegName,
2124 Register &RegVal) {
2125 return !RegName.Value.empty() && parseRegister(RegName, RegVal);
2126 };
2127
2128 if (parseOptionalRegister(YamlMFI.VGPRForAGPRCopy, MFI->VGPRForAGPRCopy))
2129 return true;
2130
2131 if (parseOptionalRegister(YamlMFI.SGPRForEXECCopy, MFI->SGPRForEXECCopy))
2132 return true;
2133
2134 if (parseOptionalRegister(YamlMFI.LongBranchReservedReg,
2135 MFI->LongBranchReservedReg))
2136 return true;
2137
2138 auto diagnoseRegisterClass = [&](const yaml::StringValue &RegName) {
2139 // Create a diagnostic for a the register string literal.
2140 const MemoryBuffer &Buffer =
2141 *PFS.SM->getMemoryBuffer(PFS.SM->getMainFileID());
2142 Error = SMDiagnostic(*PFS.SM, SMLoc(), Buffer.getBufferIdentifier(), 1,
2143 RegName.Value.size(), SourceMgr::DK_Error,
2144 "incorrect register class for field", RegName.Value,
2145 {}, {});
2146 SourceRange = RegName.SourceRange;
2147 return true;
2148 };
2149
2150 if (parseRegister(YamlMFI.ScratchRSrcReg, MFI->ScratchRSrcReg) ||
2151 parseRegister(YamlMFI.FrameOffsetReg, MFI->FrameOffsetReg) ||
2152 parseRegister(YamlMFI.StackPtrOffsetReg, MFI->StackPtrOffsetReg))
2153 return true;
2154
2155 if (MFI->ScratchRSrcReg != AMDGPU::PRIVATE_RSRC_REG &&
2156 !AMDGPU::SGPR_128RegClass.contains(MFI->ScratchRSrcReg)) {
2157 return diagnoseRegisterClass(YamlMFI.ScratchRSrcReg);
2158 }
2159
2160 if (MFI->FrameOffsetReg != AMDGPU::FP_REG &&
2161 !AMDGPU::SGPR_32RegClass.contains(MFI->FrameOffsetReg)) {
2162 return diagnoseRegisterClass(YamlMFI.FrameOffsetReg);
2163 }
2164
2165 if (MFI->StackPtrOffsetReg != AMDGPU::SP_REG &&
2166 !AMDGPU::SGPR_32RegClass.contains(MFI->StackPtrOffsetReg)) {
2167 return diagnoseRegisterClass(YamlMFI.StackPtrOffsetReg);
2168 }
2169
2170 for (const auto &YamlReg : YamlMFI.WWMReservedRegs) {
2171 Register ParsedReg;
2172 if (parseRegister(YamlReg, ParsedReg))
2173 return true;
2174
2175 MFI->reserveWWMRegister(ParsedReg);
2176 }
2177
2178 for (const auto &[_, Info] : PFS.VRegInfosNamed) {
2179 MFI->setFlag(Info->VReg, Info->Flags);
2180 }
2181 for (const auto &[_, Info] : PFS.VRegInfos) {
2182 MFI->setFlag(Info->VReg, Info->Flags);
2183 }
2184
2185 for (const auto &YamlRegStr : YamlMFI.SpillPhysVGPRS) {
2186 Register ParsedReg;
2187 if (parseRegister(YamlRegStr, ParsedReg))
2188 return true;
2189 MFI->SpillPhysVGPRs.push_back(ParsedReg);
2190 }
2191
2192 auto parseAndCheckArgument = [&](const std::optional<yaml::SIArgument> &A,
2193 const TargetRegisterClass &RC,
2194 ArgDescriptor &Arg, unsigned UserSGPRs,
2195 unsigned SystemSGPRs) {
2196 // Skip parsing if it's not present.
2197 if (!A)
2198 return false;
2199
2200 if (A->IsRegister) {
2201 Register Reg;
2202 if (parseNamedRegisterReference(PFS, Reg, A->RegisterName.Value, Error)) {
2203 SourceRange = A->RegisterName.SourceRange;
2204 return true;
2205 }
2206 if (!RC.contains(Reg))
2207 return diagnoseRegisterClass(A->RegisterName);
2209 } else
2210 Arg = ArgDescriptor::createStack(A->StackOffset);
2211 // Check and apply the optional mask.
2212 if (A->Mask)
2213 Arg = ArgDescriptor::createArg(Arg, *A->Mask);
2214
2215 MFI->NumUserSGPRs += UserSGPRs;
2216 MFI->NumSystemSGPRs += SystemSGPRs;
2217 return false;
2218 };
2219
2220 if (YamlMFI.ArgInfo &&
2221 (parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentBuffer,
2222 AMDGPU::SGPR_128RegClass,
2223 MFI->ArgInfo.PrivateSegmentBuffer, 4, 0) ||
2224 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchPtr,
2225 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchPtr,
2226 2, 0) ||
2227 parseAndCheckArgument(YamlMFI.ArgInfo->QueuePtr, AMDGPU::SReg_64RegClass,
2228 MFI->ArgInfo.QueuePtr, 2, 0) ||
2229 parseAndCheckArgument(YamlMFI.ArgInfo->KernargSegmentPtr,
2230 AMDGPU::SReg_64RegClass,
2231 MFI->ArgInfo.KernargSegmentPtr, 2, 0) ||
2232 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchID,
2233 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchID,
2234 2, 0) ||
2235 parseAndCheckArgument(YamlMFI.ArgInfo->FlatScratchInit,
2236 AMDGPU::SReg_64RegClass,
2237 MFI->ArgInfo.FlatScratchInit, 2, 0) ||
2238 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentSize,
2239 AMDGPU::SGPR_32RegClass,
2240 MFI->ArgInfo.PrivateSegmentSize, 1, 0) ||
2241 parseAndCheckArgument(YamlMFI.ArgInfo->LDSKernelId,
2242 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.LDSKernelId,
2243 1, 0) ||
2244 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDX,
2245 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDX,
2246 0, 1) ||
2247 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDY,
2248 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDY,
2249 0, 1) ||
2250 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDZ,
2251 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDZ,
2252 0, 1) ||
2253 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupInfo,
2254 AMDGPU::SGPR_32RegClass,
2255 MFI->ArgInfo.WorkGroupInfo, 0, 1) ||
2256 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentWaveByteOffset,
2257 AMDGPU::SGPR_32RegClass,
2258 MFI->ArgInfo.PrivateSegmentWaveByteOffset, 0, 1) ||
2259 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitArgPtr,
2260 AMDGPU::SReg_64RegClass,
2261 MFI->ArgInfo.ImplicitArgPtr, 0, 0) ||
2262 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitBufferPtr,
2263 AMDGPU::SReg_64RegClass,
2264 MFI->ArgInfo.ImplicitBufferPtr, 2, 0) ||
2265 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDX,
2266 AMDGPU::VGPR_32RegClass, MFI->ArgInfo.WorkItemIDX,
2267 0, 0) ||
2268 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDY,
2269 AMDGPU::VGPR_32RegClass, MFI->ArgInfo.WorkItemIDY,
2270 0, 0) ||
2271 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDZ,
2272 AMDGPU::VGPR_32RegClass, MFI->ArgInfo.WorkItemIDZ,
2273 0, 0)))
2274 return true;
2275
2276 // Parse FirstKernArgPreloadReg separately, since it's a Register,
2277 // not ArgDescriptor.
2278 if (YamlMFI.ArgInfo && YamlMFI.ArgInfo->FirstKernArgPreloadReg) {
2279 const yaml::SIArgument &A = *YamlMFI.ArgInfo->FirstKernArgPreloadReg;
2280
2281 if (!A.IsRegister) {
2282 // For stack arguments, we don't have RegisterName.SourceRange,
2283 // but we should have some location info from the YAML parser
2284 const MemoryBuffer &Buffer =
2285 *PFS.SM->getMemoryBuffer(PFS.SM->getMainFileID());
2286 // Create a minimal valid source range
2288 SMRange Range(Loc, Loc);
2289
2291 *PFS.SM, Loc, Buffer.getBufferIdentifier(), 1, 0, SourceMgr::DK_Error,
2292 "firstKernArgPreloadReg must be a register, not a stack location", "",
2293 {}, {});
2294
2295 SourceRange = Range;
2296 return true;
2297 }
2298
2299 Register Reg;
2300 if (parseNamedRegisterReference(PFS, Reg, A.RegisterName.Value, Error)) {
2301 SourceRange = A.RegisterName.SourceRange;
2302 return true;
2303 }
2304
2305 if (!AMDGPU::SGPR_32RegClass.contains(Reg))
2306 return diagnoseRegisterClass(A.RegisterName);
2307
2308 MFI->ArgInfo.FirstKernArgPreloadReg = Reg;
2309 MFI->NumUserSGPRs += YamlMFI.NumKernargPreloadSGPRs;
2310 }
2311
2312 if (ST.hasFeature(AMDGPU::FeatureDX10ClampAndIEEEMode)) {
2313 MFI->Mode.IEEE = YamlMFI.Mode.IEEE;
2314 MFI->Mode.DX10Clamp = YamlMFI.Mode.DX10Clamp;
2315 }
2316
2317 // FIXME: Move proper support for denormal-fp-math into base MachineFunction
2318 MFI->Mode.FP32Denormals.Input = YamlMFI.Mode.FP32InputDenormals
2321 MFI->Mode.FP32Denormals.Output = YamlMFI.Mode.FP32OutputDenormals
2324
2331
2332 if (YamlMFI.HasInitWholeWave)
2333 MFI->setInitWholeWave();
2334
2335 return false;
2336}
2337
2338//===----------------------------------------------------------------------===//
2339// AMDGPU CodeGen Pass Builder interface.
2340//===----------------------------------------------------------------------===//
2341
2342AMDGPUCodeGenPassBuilder::AMDGPUCodeGenPassBuilder(
2343 GCNTargetMachine &TM, const CGPassBuilderOption &Opts,
2345 : CodeGenPassBuilder(TM, Opts, PIC) {
2346 Opt.MISchedPostRA = true;
2347 Opt.RequiresCodeGenSCCOrder = true;
2348 // Exceptions and StackMaps are not supported, so these passes will never do
2349 // anything.
2350 // Garbage collection is not supported.
2351 disablePass<StackMapLivenessPass, FuncletLayoutPass, PatchableFunctionPass,
2353}
2354
2355void AMDGPUCodeGenPassBuilder::addIRPasses(PassManagerWrapper &PMW) {
2356 if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN()) {
2357 flushFPMsToMPM(PMW);
2358 addModulePass(AMDGPURemoveIncompatibleFunctionsPass(TM), PMW);
2359 }
2360
2361 flushFPMsToMPM(PMW);
2362
2363 if (TM.getTargetTriple().isAMDGCN())
2364 addModulePass(AMDGPUPrintfRuntimeBindingPass(), PMW);
2365
2366 if (LowerCtorDtor)
2367 addModulePass(AMDGPUCtorDtorLoweringPass(), PMW);
2368
2369 if (isPassEnabled(EnableImageIntrinsicOptimizer))
2370 addFunctionPass(AMDGPUImageIntrinsicOptimizerPass(TM), PMW);
2371
2373 addFunctionPass(AMDGPUUniformIntrinsicCombinePass(), PMW);
2374 // This can be disabled by passing ::Disable here or on the command line
2375 // with --expand-variadics-override=disable.
2376 flushFPMsToMPM(PMW);
2378
2379 addModulePass(AMDGPUAlwaysInlinePass(), PMW);
2380 addModulePass(AlwaysInlinerPass(), PMW);
2381
2382 addModulePass(AMDGPUExportKernelRuntimeHandlesPass(), PMW);
2383
2385 addModulePass(AMDGPULowerExecSyncPass(), PMW);
2386
2387 if (EnableSwLowerLDS)
2388 addModulePass(AMDGPUSwLowerLDSPass(), PMW);
2389
2390 // Runs before PromoteAlloca so the latter can account for function uses
2392 addModulePass(AMDGPULowerModuleLDSPass(getTM()), PMW);
2393
2394 // Run atomic optimizer before Atomic Expand
2395 if (TM.getOptLevel() >= CodeGenOptLevel::Less &&
2397 addFunctionPass(
2399
2400 addFunctionPass(AtomicExpandPass(TM), PMW);
2401
2402 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2403 addFunctionPass(AMDGPUPromoteAllocaPass(TM), PMW);
2404 if (isPassEnabled(EnableScalarIRPasses))
2405 addStraightLineScalarOptimizationPasses(PMW);
2406
2407 // TODO: Handle EnableAMDGPUAliasAnalysis
2408
2409 // TODO: May want to move later or split into an early and late one.
2410 addFunctionPass(AMDGPUCodeGenPreparePass(TM), PMW);
2411
2412 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
2413 // have expanded.
2414 if (TM.getOptLevel() > CodeGenOptLevel::Less) {
2416 /*UseMemorySSA=*/true),
2417 PMW);
2418 }
2419 }
2420
2421 Base::addIRPasses(PMW);
2422
2423 // EarlyCSE is not always strong enough to clean up what LSR produces. For
2424 // example, GVN can combine
2425 //
2426 // %0 = add %a, %b
2427 // %1 = add %b, %a
2428 //
2429 // and
2430 //
2431 // %0 = shl nsw %a, 2
2432 // %1 = shl %a, 2
2433 //
2434 // but EarlyCSE can do neither of them.
2435 if (isPassEnabled(EnableScalarIRPasses))
2436 addEarlyCSEOrGVNPass(PMW);
2437}
2438
2439void AMDGPUCodeGenPassBuilder::addCodeGenPrepare(PassManagerWrapper &PMW) {
2440 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2441 flushFPMsToMPM(PMW);
2442 addModulePass(AMDGPUPreloadKernelArgumentsPass(TM), PMW);
2443 }
2444
2446 addFunctionPass(AMDGPULowerKernelArgumentsPass(TM), PMW);
2447
2448 Base::addCodeGenPrepare(PMW);
2449
2450 if (isPassEnabled(EnableLoadStoreVectorizer))
2451 addFunctionPass(LoadStoreVectorizerPass(), PMW);
2452
2453 // This lowering has been placed after codegenprepare to take advantage of
2454 // address mode matching (which is why it isn't put with the LDS lowerings).
2455 // It could be placed anywhere before uniformity annotations (an analysis
2456 // that it changes by splitting up fat pointers into their components)
2457 // but has been put before switch lowering and CFG flattening so that those
2458 // passes can run on the more optimized control flow this pass creates in
2459 // many cases.
2460 flushFPMsToMPM(PMW);
2461 addModulePass(AMDGPULowerBufferFatPointersPass(TM), PMW);
2462 flushFPMsToMPM(PMW);
2463 requireCGSCCOrder(PMW);
2464
2465 addModulePass(AMDGPULowerIntrinsicsPass(getTM()), PMW);
2466
2467 // LowerSwitch pass may introduce unreachable blocks that can cause unexpected
2468 // behavior for subsequent passes. Placing it here seems better that these
2469 // blocks would get cleaned up by UnreachableBlockElim inserted next in the
2470 // pass flow.
2471 addFunctionPass(LowerSwitchPass(), PMW);
2472}
2473
2474void AMDGPUCodeGenPassBuilder::addPreISel(PassManagerWrapper &PMW) {
2475
2476 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2477 addFunctionPass(FlattenCFGPass(), PMW);
2478 addFunctionPass(SinkingPass(), PMW);
2479 addFunctionPass(AMDGPULateCodeGenPreparePass(getTM()), PMW);
2480 }
2481
2482 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
2483 // regions formed by them.
2484
2485 addFunctionPass(AMDGPUUnifyDivergentExitNodesPass(), PMW);
2486 addFunctionPass(FixIrreduciblePass(), PMW);
2487 addFunctionPass(UnifyLoopExitsPass(), PMW);
2488 addFunctionPass(StructurizeCFGPass(/*SkipUniformRegions=*/false), PMW);
2489
2490 addFunctionPass(AMDGPUAnnotateUniformValuesPass(), PMW);
2491
2492 addFunctionPass(SIAnnotateControlFlowPass(getTM()), PMW);
2493
2494 // TODO: Move this right after structurizeCFG to avoid extra divergence
2495 // analysis. This depends on stopping SIAnnotateControlFlow from making
2496 // control flow modifications.
2497 addFunctionPass(AMDGPURewriteUndefForPHIPass(), PMW);
2498
2501 !isGlobalISelAbortEnabled())
2502 addFunctionPass(LCSSAPass(), PMW);
2503
2504 if (TM.getOptLevel() > CodeGenOptLevel::Less) {
2505 flushFPMsToMPM(PMW);
2506 addModulePass(AMDGPUPerfHintAnalysisPass(getTM()), PMW);
2507 }
2508}
2509
2510void AMDGPUCodeGenPassBuilder::addILPOpts(PassManagerWrapper &PMW) {
2512 addMachineFunctionPass(EarlyIfConverterPass(), PMW);
2513
2514 Base::addILPOpts(PMW);
2515}
2516
2517void AMDGPUCodeGenPassBuilder::addAsmPrinterBegin(PassManagerWrapper &PMW) {
2518 addModulePass(AMDGPUAsmPrinterBeginPass(), PMW,
2519 /*Force=*/true);
2520}
2521
2522void AMDGPUCodeGenPassBuilder::addAsmPrinter(PassManagerWrapper &PMW) {
2523 addMachineFunctionPass(AMDGPUAsmPrinterPass(), PMW);
2524}
2525
2526void AMDGPUCodeGenPassBuilder::addAsmPrinterEnd(PassManagerWrapper &PMW) {
2527 addModulePass(AMDGPUAsmPrinterEndPass(), PMW);
2528}
2529
2530Error AMDGPUCodeGenPassBuilder::addInstSelector(PassManagerWrapper &PMW) {
2531 addMachineFunctionPass(AMDGPUISelDAGToDAGPass(TM), PMW);
2532 addMachineFunctionPass(SIFixSGPRCopiesPass(), PMW);
2533 addMachineFunctionPass(SILowerI1CopiesPass(), PMW);
2534 return Error::success();
2535}
2536
2537void AMDGPUCodeGenPassBuilder::addPreRewrite(PassManagerWrapper &PMW) {
2538 if (EnableRegReassign) {
2539 addMachineFunctionPass(GCNNSAReassignPass(), PMW);
2540 }
2541
2542 addMachineFunctionPass(AMDGPURewriteAGPRCopyMFMAPass(), PMW);
2543}
2544
2545void AMDGPUCodeGenPassBuilder::addMachineSSAOptimization(
2546 PassManagerWrapper &PMW) {
2547 Base::addMachineSSAOptimization(PMW);
2548
2549 addMachineFunctionPass(SIFoldOperandsPass(), PMW);
2550 if (EnableDPPCombine) {
2551 addMachineFunctionPass(GCNDPPCombinePass(), PMW);
2552 }
2553 addMachineFunctionPass(SILoadStoreOptimizerPass(), PMW);
2554 if (isPassEnabled(EnableSDWAPeephole)) {
2555 addMachineFunctionPass(SIPeepholeSDWAPass(), PMW);
2556 addMachineFunctionPass(EarlyMachineLICMPass(), PMW);
2557 addMachineFunctionPass(MachineCSEPass(), PMW);
2558 addMachineFunctionPass(SIFoldOperandsPass(), PMW);
2559 }
2560 addMachineFunctionPass(DeadMachineInstructionElimPass(), PMW);
2561 addMachineFunctionPass(SIShrinkInstructionsPass(), PMW);
2562}
2563
2564Error AMDGPUCodeGenPassBuilder::addFastRegAlloc(PassManagerWrapper &PMW) {
2565 insertPass<PHIEliminationPass>(SILowerControlFlowPass());
2566
2567 insertPass<TwoAddressInstructionPass>(SIWholeQuadModePass());
2568
2569 return Base::addFastRegAlloc(PMW);
2570}
2571
2572Error AMDGPUCodeGenPassBuilder::addRegAssignAndRewriteFast(
2573 PassManagerWrapper &PMW) {
2574 if (auto Err = validateRegAllocOptions())
2575 return Err;
2576
2577 addMachineFunctionPass(GCNPreRALongBranchRegPass(), PMW);
2578
2579 // SGPR allocation - default to fast at -O0.
2580 if (SGPRRegAllocNPM == RegAllocType::Greedy)
2581 addMachineFunctionPass(RAGreedyPass({onlyAllocateSGPRs, "sgpr"}), PMW);
2582 else
2583 addMachineFunctionPass(RegAllocFastPass({onlyAllocateSGPRs, "sgpr", false}),
2584 PMW);
2585
2586 // Equivalent of PEI for SGPRs.
2587 addMachineFunctionPass(SILowerSGPRSpillsPass(), PMW);
2588
2589 // To Allocate wwm registers used in whole quad mode operations (for shaders).
2590 addMachineFunctionPass(SIPreAllocateWWMRegsPass(), PMW);
2591
2592 // WWM allocation - default to fast at -O0.
2593 if (WWMRegAllocNPM == RegAllocType::Greedy)
2594 addMachineFunctionPass(RAGreedyPass({onlyAllocateWWMRegs, "wwm"}), PMW);
2595 else
2596 addMachineFunctionPass(
2597 RegAllocFastPass({onlyAllocateWWMRegs, "wwm", false}), PMW);
2598
2599 addMachineFunctionPass(SILowerWWMCopiesPass(), PMW);
2600 addMachineFunctionPass(AMDGPUReserveWWMRegsPass(), PMW);
2601
2602 // VGPR allocation - default to fast at -O0.
2603 if (VGPRRegAllocNPM == RegAllocType::Greedy)
2604 addMachineFunctionPass(RAGreedyPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2605 else
2606 addMachineFunctionPass(RegAllocFastPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2607
2608 return Error::success();
2609}
2610
2611Error AMDGPUCodeGenPassBuilder::addOptimizedRegAlloc(PassManagerWrapper &PMW) {
2612 if (EnableDCEInRA)
2613 insertPass<DetectDeadLanesPass>(DeadMachineInstructionElimPass());
2614
2615 // FIXME: when an instruction has a Killed operand, and the instruction is
2616 // inside a bundle, seems only the BUNDLE instruction appears as the Kills of
2617 // the register in LiveVariables, this would trigger a failure in verifier,
2618 // we should fix it and enable the verifier.
2619 if (OptVGPRLiveRange)
2620 insertPass<RequireAnalysisPass<LiveVariablesAnalysis, MachineFunction>>(
2622
2623 // This must be run immediately after phi elimination and before
2624 // TwoAddressInstructions, otherwise the processing of the tied operand of
2625 // SI_ELSE will introduce a copy of the tied operand source after the else.
2626 insertPass<PHIEliminationPass>(SILowerControlFlowPass());
2627
2629 insertPass<RenameIndependentSubregsPass>(GCNRewritePartialRegUsesPass());
2630
2631 if (isPassEnabled(EnablePreRAOptimizations))
2632 insertPass<MachineSchedulerPass>(GCNPreRAOptimizationsPass());
2633
2634 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
2635 // instructions that cause scheduling barriers.
2636 insertPass<MachineSchedulerPass>(SIWholeQuadModePass());
2637
2638 if (OptExecMaskPreRA)
2639 insertPass<MachineSchedulerPass>(SIOptimizeExecMaskingPreRAPass());
2640
2641 // This is not an essential optimization and it has a noticeable impact on
2642 // compilation time, so we only enable it from O2.
2643 if (TM.getOptLevel() > CodeGenOptLevel::Less)
2644 insertPass<MachineSchedulerPass>(SIFormMemoryClausesPass());
2645
2646 return Base::addOptimizedRegAlloc(PMW);
2647}
2648
2649void AMDGPUCodeGenPassBuilder::addPreRegAlloc(PassManagerWrapper &PMW) {
2650 if (getOptLevel() != CodeGenOptLevel::None)
2651 addMachineFunctionPass(AMDGPUPrepareAGPRAllocPass(), PMW);
2652 if (getOptLevel() >= CodeGenOptLevel::Default && EnableMachinePipeliner)
2653 addMachineFunctionPass(MachinePipelinerPass(), PMW);
2654}
2655
2656Expected<bool> AMDGPUCodeGenPassBuilder::addRegAssignAndRewriteOptimized(
2657 PassManagerWrapper &PMW) {
2658 if (auto Err = validateRegAllocOptions())
2659 return Err;
2660
2661 addMachineFunctionPass(GCNPreRALongBranchRegPass(), PMW);
2662
2663 // SGPR allocation - default to greedy at -O1 and above.
2664 if (SGPRRegAllocNPM == RegAllocType::Fast)
2665 addMachineFunctionPass(RegAllocFastPass({onlyAllocateSGPRs, "sgpr", false}),
2666 PMW);
2667 else
2668 addMachineFunctionPass(RAGreedyPass({onlyAllocateSGPRs, "sgpr"}), PMW);
2669
2670 // Commit allocated register changes. This is mostly necessary because too
2671 // many things rely on the use lists of the physical registers, such as the
2672 // verifier. This is only necessary with allocators which use LiveIntervals,
2673 // since FastRegAlloc does the replacements itself.
2674 addMachineFunctionPass(VirtRegRewriterPass(false), PMW);
2675
2676 // At this point, the sgpr-regalloc has been done and it is good to have the
2677 // stack slot coloring to try to optimize the SGPR spill stack indices before
2678 // attempting the custom SGPR spill lowering.
2679 addMachineFunctionPass(StackSlotColoringPass(), PMW);
2680
2681 // Equivalent of PEI for SGPRs.
2682 addMachineFunctionPass(SILowerSGPRSpillsPass(), PMW);
2683
2684 // To Allocate wwm registers used in whole quad mode operations (for shaders).
2685 addMachineFunctionPass(SIPreAllocateWWMRegsPass(), PMW);
2686
2687 // WWM allocation - default to greedy at -O1 and above.
2688 if (WWMRegAllocNPM == RegAllocType::Fast)
2689 addMachineFunctionPass(
2690 RegAllocFastPass({onlyAllocateWWMRegs, "wwm", false}), PMW);
2691 else
2692 addMachineFunctionPass(RAGreedyPass({onlyAllocateWWMRegs, "wwm"}), PMW);
2693 addMachineFunctionPass(SILowerWWMCopiesPass(), PMW);
2694 addMachineFunctionPass(VirtRegRewriterPass(false), PMW);
2695 addMachineFunctionPass(AMDGPUReserveWWMRegsPass(), PMW);
2696
2697 // VGPR allocation - default to greedy at -O1 and above.
2698 if (VGPRRegAllocNPM == RegAllocType::Fast)
2699 addMachineFunctionPass(RegAllocFastPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2700 else
2701 addMachineFunctionPass(RAGreedyPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2702
2703 addPreRewrite(PMW);
2704 addMachineFunctionPass(VirtRegRewriterPass(true), PMW);
2705
2706 addMachineFunctionPass(AMDGPUMarkLastScratchLoadPass(), PMW);
2707 return true;
2708}
2709
2710void AMDGPUCodeGenPassBuilder::addPostRegAlloc(PassManagerWrapper &PMW) {
2711 addMachineFunctionPass(SIFixVGPRCopiesPass(), PMW);
2712 if (TM.getOptLevel() > CodeGenOptLevel::None)
2713 addMachineFunctionPass(SIOptimizeExecMaskingPass(), PMW);
2714 Base::addPostRegAlloc(PMW);
2715}
2716
2717void AMDGPUCodeGenPassBuilder::addPreSched2(PassManagerWrapper &PMW) {
2718 if (TM.getOptLevel() > CodeGenOptLevel::None)
2719 addMachineFunctionPass(SIShrinkInstructionsPass(), PMW);
2720 addMachineFunctionPass(SIPostRABundlerPass(), PMW);
2721}
2722
2723void AMDGPUCodeGenPassBuilder::addPostBBSections(PassManagerWrapper &PMW) {
2724 // We run this later to avoid passes like livedebugvalues and BBSections
2725 // having to deal with the apparent multi-entry functions we may generate.
2726 addMachineFunctionPass(AMDGPUPreloadKernArgPrologPass(), PMW);
2727}
2728
2729void AMDGPUCodeGenPassBuilder::addPreEmitPass(PassManagerWrapper &PMW) {
2730 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less)) {
2731 addMachineFunctionPass(GCNCreateVOPDPass(), PMW);
2732 }
2733
2734 addMachineFunctionPass(SIMemoryLegalizerPass(), PMW);
2735 addMachineFunctionPass(SIInsertWaitcntsPass(), PMW);
2736
2737 addMachineFunctionPass(SIModeRegisterPass(), PMW);
2738
2739 if (TM.getOptLevel() > CodeGenOptLevel::None)
2740 addMachineFunctionPass(SIInsertHardClausesPass(), PMW);
2741
2742 addMachineFunctionPass(SILateBranchLoweringPass(), PMW);
2743
2744 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
2745 addMachineFunctionPass(AMDGPUSetWavePriorityPass(), PMW);
2746
2747 if (TM.getOptLevel() > CodeGenOptLevel::None)
2748 addMachineFunctionPass(SIPreEmitPeepholePass(), PMW);
2749
2750 // The hazard recognizer that runs as part of the post-ra scheduler does not
2751 // guarantee to be able handle all hazards correctly. This is because if there
2752 // are multiple scheduling regions in a basic block, the regions are scheduled
2753 // bottom up, so when we begin to schedule a region we don't know what
2754 // instructions were emitted directly before it.
2755 //
2756 // Here we add a stand-alone hazard recognizer pass which can handle all
2757 // cases.
2758 addMachineFunctionPass(PostRAHazardRecognizerPass(), PMW);
2759 addMachineFunctionPass(AMDGPUWaitSGPRHazardsPass(), PMW);
2760 addMachineFunctionPass(AMDGPULowerVGPREncodingPass(), PMW);
2761
2762 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less)) {
2763 addMachineFunctionPass(AMDGPUInsertDelayAluPass(), PMW);
2764 }
2765
2766 addMachineFunctionPass(BranchRelaxationPass(), PMW);
2767}
2768
2769bool AMDGPUCodeGenPassBuilder::isPassEnabled(const cl::opt<bool> &Opt,
2770 CodeGenOptLevel Level) const {
2771 if (Opt.getNumOccurrences())
2772 return Opt;
2773 if (TM.getOptLevel() < Level)
2774 return false;
2775 return Opt;
2776}
2777
2778void AMDGPUCodeGenPassBuilder::addEarlyCSEOrGVNPass(PassManagerWrapper &PMW) {
2779 if (TM.getOptLevel() == CodeGenOptLevel::Aggressive)
2780 addFunctionPass(GVNPass(), PMW);
2781 else
2782 addFunctionPass(EarlyCSEPass(), PMW);
2783}
2784
2785void AMDGPUCodeGenPassBuilder::addStraightLineScalarOptimizationPasses(
2786 PassManagerWrapper &PMW) {
2788 addFunctionPass(LoopDataPrefetchPass(), PMW);
2789
2790 addFunctionPass(SeparateConstOffsetFromGEPPass(), PMW);
2791
2792 // ReassociateGEPs exposes more opportunities for SLSR. See
2793 // the example in reassociate-geps-and-slsr.ll.
2794 addFunctionPass(StraightLineStrengthReducePass(), PMW);
2795
2796 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
2797 // EarlyCSE can reuse.
2798 addEarlyCSEOrGVNPass(PMW);
2799
2800 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
2801 addFunctionPass(NaryReassociatePass(), PMW);
2802
2803 // NaryReassociate on GEPs creates redundant common expressions, so run
2804 // EarlyCSE after it.
2805 addFunctionPass(EarlyCSEPass(), PMW);
2806}
aarch64 falkor hwpf fix Falkor HW Prefetch Fix Late Phase
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static cl::opt< bool > EnableEarlyIfConversion("aarch64-enable-early-ifcvt", cl::Hidden, cl::desc("Run early if-conversion"), cl::init(true))
static cl::opt< bool > EnableMachinePipeliner("aarch64-enable-pipeliner", cl::desc("Enable Machine Pipeliner for AArch64"), cl::init(false), cl::Hidden)
static std::unique_ptr< TargetLoweringObjectFile > createTLOF(const Triple &TT)
This is the AMGPU address space based alias analysis pass.
AMDGPU Assembly printer class.
Coexecution-focused scheduling strategy for AMDGPU.
Defines an instruction selector for the AMDGPU target.
Analyzes if a function potentially memory bound and if a kernel kernel may benefit from limiting numb...
Analyzes how many registers and other resources are used by functions.
static cl::opt< bool > EnableDCEInRA("amdgpu-dce-in-ra", cl::init(true), cl::Hidden, cl::desc("Enable machine DCE inside regalloc"))
static cl::opt< bool, true > EnableLowerModuleLDS("amdgpu-enable-lower-module-lds", cl::desc("Enable lower module lds pass"), cl::location(AMDGPUTargetMachine::EnableLowerModuleLDS), cl::init(true), cl::Hidden)
static MachineSchedRegistry GCNMaxMemoryClauseSchedRegistry("gcn-max-memory-clause", "Run GCN scheduler to maximize memory clause", createGCNMaxMemoryClauseMachineScheduler)
static Reloc::Model getEffectiveRelocModel()
static cl::opt< bool > EnableUniformIntrinsicCombine("amdgpu-enable-uniform-intrinsic-combine", cl::desc("Enable/Disable the Uniform Intrinsic Combine Pass"), cl::init(true), cl::Hidden)
static MachineSchedRegistry SISchedRegistry("si", "Run SI's custom scheduler", createSIMachineScheduler)
static ScheduleDAGInstrs * createIterativeILPMachineScheduler(MachineSchedContext *C)
static cl::opt< bool > EarlyInlineAll("amdgpu-early-inline-all", cl::desc("Inline all functions early"), cl::init(false), cl::Hidden)
static OOBFlagValue getOOBFlagValue(const Module &M, StringRef FlagName)
Returns the OOB mode encoded by a module flag.
static cl::opt< bool > EnableSwLowerLDS("amdgpu-enable-sw-lower-lds", cl::desc("Enable lowering of lds to global memory pass " "and asan instrument resulting IR."), cl::init(true), cl::Hidden)
static cl::opt< bool > EnableLowerKernelArguments("amdgpu-ir-lower-kernel-arguments", cl::desc("Lower kernel argument loads in IR pass"), cl::init(true), cl::Hidden)
static cl::opt< bool, true > EnableObjectLinking("amdgpu-enable-object-linking", cl::desc("Enable object linking for cross-TU LDS and ABI support"), cl::location(AMDGPUTargetMachine::EnableObjectLinking), cl::init(false), cl::Hidden)
static ScheduleDAGInstrs * createGCNMaxILPMachineScheduler(MachineSchedContext *C)
static cl::opt< bool > EnableSDWAPeephole("amdgpu-sdwa-peephole", cl::desc("Enable SDWA peepholer"), cl::init(true))
static MachineSchedRegistry GCNMinRegSchedRegistry("gcn-iterative-minreg", "Run GCN iterative scheduler for minimal register usage (experimental)", createMinRegScheduler)
static cl::opt< bool > SramEccSetting("amdgpu-sramecc", cl::desc("Force amdgpu.sramecc for testing"), cl::ReallyHidden)
static void diagnoseUnsupportedCoExecSchedulerSelection(const Function &F, const GCNSubtarget &ST)
static cl::opt< bool > EnableImageIntrinsicOptimizer("amdgpu-enable-image-intrinsic-optimizer", cl::desc("Enable image intrinsic optimizer pass"), cl::init(true), cl::Hidden)
static cl::opt< bool > HasClosedWorldAssumption("amdgpu-link-time-closed-world", cl::desc("Whether has closed-world assumption at link time"), cl::init(false), cl::Hidden)
static bool useNoopPostScheduler(const Function &F)
static ScheduleDAGInstrs * createGCNMaxMemoryClauseMachineScheduler(MachineSchedContext *C)
static cl::opt< bool > EnableSIModeRegisterPass("amdgpu-mode-register", cl::desc("Enable mode register pass"), cl::init(true), cl::Hidden)
static cl::opt< std::string > AMDGPUSchedStrategy("amdgpu-sched-strategy", cl::desc("Select custom AMDGPU scheduling strategy."), cl::Hidden, cl::init(""))
static cl::opt< bool > EnableDPPCombine("amdgpu-dpp-combine", cl::desc("Enable DPP combiner"), cl::init(true))
static MachineSchedRegistry IterativeGCNMaxOccupancySchedRegistry("gcn-iterative-max-occupancy-experimental", "Run GCN scheduler to maximize occupancy (experimental)", createIterativeGCNMaxOccupancyMachineScheduler)
static cl::opt< bool > EnableSetWavePriority("amdgpu-set-wave-priority", cl::desc("Adjust wave priority"), cl::init(false), cl::Hidden)
static cl::opt< bool > LowerCtorDtor("amdgpu-lower-global-ctor-dtor", cl::desc("Lower GPU ctor / dtors to globals on the device."), cl::init(true), cl::Hidden)
static cl::opt< bool > XnackSetting("amdgpu-xnack", cl::desc("Force amdgpu.xnack value for testing"), cl::ReallyHidden)
static cl::opt< bool > OptExecMaskPreRA("amdgpu-opt-exec-mask-pre-ra", cl::Hidden, cl::desc("Run pre-RA exec mask optimizations"), cl::init(true))
static cl::opt< bool > EnablePromoteKernelArguments("amdgpu-enable-promote-kernel-arguments", cl::desc("Enable promotion of flat kernel pointer arguments to global"), cl::Hidden, cl::init(true))
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget()
static cl::opt< bool > EnableRewritePartialRegUses("amdgpu-enable-rewrite-partial-reg-uses", cl::desc("Enable rewrite partial reg uses pass"), cl::init(true), cl::Hidden)
static cl::opt< bool > EnableLibCallSimplify("amdgpu-simplify-libcall", cl::desc("Enable amdgpu library simplifications"), cl::init(true), cl::Hidden)
static MachineSchedRegistry GCNMaxILPSchedRegistry("gcn-max-ilp", "Run GCN scheduler to maximize ilp", createGCNMaxILPMachineScheduler)
static cl::opt< bool > InternalizeSymbols("amdgpu-internalize-symbols", cl::desc("Enable elimination of non-kernel functions and unused globals"), cl::init(false), cl::Hidden)
static cl::opt< bool > EnableAMDGPUAttributor("amdgpu-attributor-enable", cl::desc("Enable AMDGPUAttributorPass"), cl::init(true), cl::Hidden)
static LLVM_READNONE StringRef getGPUOrDefault(const Triple &TT, StringRef GPU)
Expected< AMDGPUAttributorOptions > parseAMDGPUAttributorPassOptions(StringRef Params)
static cl::opt< bool > EnableAMDGPUAliasAnalysis("enable-amdgpu-aa", cl::Hidden, cl::desc("Enable AMDGPU Alias Analysis"), cl::init(true))
static Expected< ScanOptions > parseAMDGPUAtomicOptimizerStrategy(StringRef Params)
static ScheduleDAGInstrs * createMinRegScheduler(MachineSchedContext *C)
static cl::opt< bool > EnableHipStdPar("amdgpu-enable-hipstdpar", cl::desc("Enable HIP Standard Parallelism Offload support"), cl::init(false), cl::Hidden)
static cl::opt< bool > EnableInsertDelayAlu("amdgpu-enable-delay-alu", cl::desc("Enable s_delay_alu insertion"), cl::init(true), cl::Hidden)
static ScheduleDAGInstrs * createIterativeGCNMaxOccupancyMachineScheduler(MachineSchedContext *C)
static cl::opt< bool > EnableLoadStoreVectorizer("amdgpu-load-store-vectorizer", cl::desc("Enable load store vectorizer"), cl::init(true), cl::Hidden)
static bool mustPreserveGV(const GlobalValue &GV)
Predicate for Internalize pass.
static cl::opt< bool > EnableLoopPrefetch("amdgpu-loop-prefetch", cl::desc("Enable loop data prefetch on AMDGPU"), cl::Hidden, cl::init(false))
static cl::opt< bool > RemoveIncompatibleFunctions("amdgpu-enable-remove-incompatible-functions", cl::Hidden, cl::desc("Enable removal of functions when they" "use features not supported by the target GPU"), cl::init(true))
static cl::opt< bool > EnableScalarIRPasses("amdgpu-scalar-ir-passes", cl::desc("Enable scalar IR passes"), cl::init(true), cl::Hidden)
static cl::opt< bool > EnableRegReassign("amdgpu-reassign-regs", cl::desc("Enable register reassign optimizations on gfx10+"), cl::init(true), cl::Hidden)
static cl::opt< bool > OptVGPRLiveRange("amdgpu-opt-vgpr-liverange", cl::desc("Enable VGPR liverange optimizations for if-else structure"), cl::init(true), cl::Hidden)
static ScheduleDAGInstrs * createSIMachineScheduler(MachineSchedContext *C)
static cl::opt< bool > EnablePreRAOptimizations("amdgpu-enable-pre-ra-optimizations", cl::desc("Enable Pre-RA optimizations pass"), cl::init(true), cl::Hidden)
static cl::opt< ScanOptions > AMDGPUAtomicOptimizerStrategy("amdgpu-atomic-optimizer-strategy", cl::desc("Select DPP or Iterative strategy for scan"), cl::init(ScanOptions::Iterative), cl::values(clEnumValN(ScanOptions::DPP, "DPP", "Use DPP operations for scan"), clEnumValN(ScanOptions::Iterative, "Iterative", "Use Iterative approach for scan"), clEnumValN(ScanOptions::None, "None", "Disable atomic optimizer")))
static cl::opt< bool > EnableVOPD("amdgpu-enable-vopd", cl::desc("Enable VOPD, dual issue of VALU in wave32"), cl::init(true), cl::Hidden)
static ScheduleDAGInstrs * createGCNMaxOccupancyMachineScheduler(MachineSchedContext *C)
static cl::opt< bool > EnableLowerExecSync("amdgpu-enable-lower-exec-sync", cl::desc("Enable lowering of execution synchronization."), cl::init(true), cl::Hidden)
static MachineSchedRegistry GCNILPSchedRegistry("gcn-iterative-ilp", "Run GCN iterative scheduler for ILP scheduling (experimental)", createIterativeILPMachineScheduler)
static cl::opt< bool > ScalarizeGlobal("amdgpu-scalarize-global-loads", cl::desc("Enable global load scalarization"), cl::init(true), cl::Hidden)
static const char RegAllocOptNotSupportedMessage[]
static MachineSchedRegistry GCNMaxOccupancySchedRegistry("gcn-max-occupancy", "Run GCN scheduler to maximize occupancy", createGCNMaxOccupancyMachineScheduler)
The AMDGPU TargetMachine interface definition for hw codegen targets.
This file declares the AMDGPU-specific subclass of TargetLoweringObjectFile.
This file a TargetTransformInfoImplBase conforming object specific to the AMDGPU target machine.
Provides passes to inlining "always_inline" functions.
#define X(NUM, ENUM, NAME)
Definition ELF.h:857
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This header provides classes for managing passes over SCCs of the call graph.
Provides analysis for continuously CSEing during GISel passes.
Interfaces for producing common pass manager configurations.
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
#define LLVM_READNONE
Definition Compiler.h:323
#define LLVM_ABI
Definition Compiler.h:215
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
Analysis that tracks defined/used subregister lanes across COPY instructions and instructions that ge...
This file provides the interface for a simple, fast CSE pass.
This file defines the class GCNIterativeScheduler, which uses an iterative approach to find a best sc...
This file provides the interface for LLVM's Global Value Numbering pass which eliminates fully redund...
#define _
AcceleratorCodeSelection - Identify all functions reachable from a kernel, removing those that are un...
This file declares the IRTranslator pass.
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
#define RegName(no)
This file provides the interface for LLVM's Loop Data Prefetching Pass.
This header provides classes for managing a pipeline of passes over loops in LLVM IR.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
#define T
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
#define P(N)
CGSCCAnalysisManager CGAM
LoopAnalysisManager LAM
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
PassInstrumentationCallbacks PIC
PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)
static bool isLTOPreLink(ThinOrFullLTOPhase Phase)
The AMDGPU TargetMachine interface definition for hw codegen targets.
const GCNTargetMachine & getTM(const GCNSubtarget *STI)
SI Machine Scheduler interface.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:484
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static FunctionPass * useDefaultRegisterAllocator()
-regalloc=... command line option.
static cl::opt< cl::boolOrDefault > EnableGlobalISelOption("global-isel", cl::Hidden, cl::desc("Enable the \"global\" instruction selector"))
Target-Independent Code Generator Pass Configuration Options pass.
static std::unique_ptr< TargetLoweringObjectFile > createTLOF()
A manager for alias analyses.
void registerFunctionAnalysis()
Register a specific AA result.
void addAAResult(AAResultT &AAResult)
Register a specific AA result.
Legacy wrapper pass to provide the AMDGPUAAResult object.
Analysis pass providing a never-invalidated alias analysis result.
Lower llvm.global_ctors and llvm.global_dtors to special kernels.
AMDGPUTargetMachine & getAMDGPUTargetMachine() const
std::unique_ptr< CSEConfigBase > getCSEConfig() const override
Returns the CSEConfig object to use for the current optimization level.
bool isPassEnabled(const cl::opt< bool > &Opt, CodeGenOptLevel Level=CodeGenOptLevel::Default) const
Check if a pass is enabled given Opt option.
bool addPreISel() override
Methods with trivial inline returns are convenient points in the common codegen pass pipeline where t...
bool addInstSelector() override
addInstSelector - This method should install an instruction selector pass, which converts from LLVM c...
bool addGCPasses() override
addGCPasses - Add late codegen passes that analyze code for garbage collection.
AMDGPUPassConfig(TargetMachine &TM, PassManagerBase &PM)
void addIRPasses() override
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
void addCodeGenPrepare() override
Add pass to prepare the LLVM IR for code generation.
Splits the module M into N linkable partitions.
std::unique_ptr< TargetLoweringObjectFile > TLOF
unsigned getAddressSpaceForPseudoSourceKind(unsigned Kind) const override
getAddressSpaceForPseudoSourceKind - Given the kind of memory (e.g.
const TargetSubtargetInfo * getSubtargetImpl() const
void registerDefaultAliasAnalyses(AAManager &) override
Allow the target to register alias analyses with the AAManager for use with the new pass manager.
std::pair< const Value *, unsigned > getPredicatedAddrSpace(const Value *V) const override
If the specified predicate checks whether a generic pointer falls within a specified address space,...
StringRef getFeatureString(const Function &F) const
ScheduleDAGInstrs * createMachineScheduler(MachineSchedContext *C) const override
Create an instance of ScheduleDAGInstrs to be run within the standard MachineScheduler pass for this ...
AMDGPUTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM, CodeGenOptLevel OL)
bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override
Returns true if a cast between SrcAS and DestAS is a noop.
void registerPassBuilderCallbacks(PassBuilder &PB) override
Allow the target to modify the pass pipeline.
StringRef getGPUName(const Function &F) const
unsigned getAssumedAddrSpace(const Value *V) const override
If the specified generic pointer could be assumed as a pointer to a specific address space,...
bool splitModule(Module &M, unsigned NumParts, function_ref< void(std::unique_ptr< Module > MPart)> ModuleCallback) override
Entry point for module splitting.
Inlines functions marked as "always_inline".
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:106
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition Attributes.h:266
This class provides access to building LLVM's passes.
CodeGenTargetMachineImpl(const Target &T, StringRef DataLayoutString, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, CodeGenOptLevel OL)
LLVM_ABI void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
Diagnostic information for unsupported feature in backend.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
LowerIntrinsics - This pass rewrites calls to the llvm.gcread or llvm.gcwrite intrinsics,...
Definition GCMetadata.h:229
const SIRegisterInfo * getRegisterInfo() const override
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
Get a TargetTransformInfo implementation for the target.
ScheduleDAGInstrs * createPostMachineScheduler(MachineSchedContext *C) const override
Similar to createMachineScheduler but used when postRA machine scheduling is enabled.
static AMDGPU::TargetIDSetting getTargetIDSettingFromModuleFlag(const Module &M, StringRef FlagName)
Get xnack/sramecc setting from module flag or cl::opt (for testing).
ScheduleDAGInstrs * createMachineScheduler(MachineSchedContext *C) const override
Create an instance of ScheduleDAGInstrs to be run within the standard MachineScheduler pass for this ...
void registerMachineRegisterInfoCallback(MachineFunction &MF) const override
bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &, PerFunctionMIParsingState &PFS, SMDiagnostic &Error, SMRange &SourceRange) const override
Parse out the target's MachineFunctionInfo from the YAML reprsentation.
yaml::MachineFunctionInfo * convertFuncInfoToYAML(const MachineFunction &MF) const override
Allocate and initialize an instance of the YAML representation of the MachineFunctionInfo.
yaml::MachineFunctionInfo * createDefaultFuncInfoYAML() const override
Allocate and return a default initialized instance of the YAML representation for the MachineFunction...
Error buildCodeGenPipeline(ModulePassManager &MPM, ModuleAnalysisManager &MAM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, const CGPassBuilderOption &Opts, MCContext &Ctx, PassInstrumentationCallbacks *PIC) override
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
GCNTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM, CodeGenOptLevel OL, bool JIT)
MachineFunctionInfo * createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F, const TargetSubtargetInfo *STI) const override
Create the target's instance of MachineFunctionInfo.
The core GVN pass object.
Definition GVN.h:123
Pass to remove unused function declarations.
Definition GlobalDCE.h:38
This pass is responsible for selecting generic machine instructions to target-specific instructions.
A pass that internalizes all functions and variables other than those that must be preserved accordin...
Definition Internalize.h:37
Converts loops into loop-closed SSA form.
Definition LCSSA.h:38
Performs Loop Invariant Code Motion Pass.
Definition LICM.h:66
static void setUseExtended(bool Enable)
This pass implements the localization mechanism described at the top of this file.
Definition Localizer.h:40
An optimization pass inserting data prefetches in loops.
Context object for machine code objects.
Definition MCContext.h:83
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
void addDelegate(Delegate *delegate)
const MachineFunction & getMF() const
MachineSchedRegistry provides a selection of available machine instruction schedulers.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
const char * getBufferStart() const
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
This class provides access to building LLVM's passes.
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same_v< PassT, PassManager > > addPass(PassT &&Pass)
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Pass interface - Implemented by all 'passes'.
Definition Pass.h:99
RegisterPassParser class - Handle the addition of new machine passes.
RegisterRegAllocBase class - Track the registration of register allocators.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
bool initializeBaseYamlFields(const yaml::SIMachineFunctionInfo &YamlMFI, const MachineFunction &MF, PerFunctionMIParsingState &PFS, SMDiagnostic &Error, SMRange &SourceRange)
void setFlag(Register Reg, uint8_t Flag)
bool checkFlag(Register Reg, uint8_t Flag) const
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition SourceMgr.h:308
Represents a location in source code.
Definition SMLoc.h:22
static SMLoc getFromPointer(const char *Ptr)
Definition SMLoc.h:35
Represents a range in source code.
Definition SMLoc.h:47
A ScheduleDAG for scheduling lists of MachineInstr.
ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules machine instructions while...
ScheduleDAGMI is an implementation of ScheduleDAGInstrs that simply schedules machine instructions ac...
void addMutation(std::unique_ptr< ScheduleDAGMutation > Mutation)
Add a postprocessing step to the DAG builder.
const TargetInstrInfo * TII
Target instruction information.
const TargetRegisterInfo * TRI
Target processor register info.
Move instructions into successor blocks when possible.
Definition Sink.h:24
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
void append(StringRef RHS)
Append from a StringRef.
Definition SmallString.h:68
void push_back(const T &Elt)
unsigned getMainFileID() const
Definition SourceMgr.h:151
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition SourceMgr.h:144
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:736
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
bool consume_front(char Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition StringRef.h:661
A switch()-like statement whose cases are string literals.
StringSwitch & Cases(std::initializer_list< StringLiteral > CaseStrings, T Value)
Primary interface to the complete machine description for the target machine.
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with.
const Triple & getTargetTriple() const
const MCSubtargetInfo & getMCSubtargetInfo() const
StringRef getTargetFeatureString() const
StringRef getTargetCPU() const
std::unique_ptr< const MCSubtargetInfo > STI
TargetOptions Options
std::unique_ptr< const MCRegisterInfo > MRI
CodeGenOptLevel OptLevel
void setEnableDefaultMachineVerifier(bool Enable)
Target-Independent Code Generator Pass Configuration Options.
virtual void addCodeGenPrepare()
Add pass to prepare the LLVM IR for code generation.
virtual bool addILPOpts()
Add passes that optimize instruction level parallelism for out-of-order targets.
virtual void addPostRegAlloc()
This method may be implemented by targets that want to run passes after register allocation pass pipe...
CodeGenOptLevel getOptLevel() const
virtual void addOptimizedRegAlloc()
addOptimizedRegAlloc - Add passes related to register allocation.
virtual void addIRPasses()
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
virtual void addFastRegAlloc()
addFastRegAlloc - Add the minimum set of target-independent passes that are required for fast registe...
virtual void addMachineSSAOptimization()
addMachineSSAOptimization - Add standard passes that optimize machine instructions in SSA form.
void disablePass(AnalysisID PassID)
Allow the target to disable a specific standard pass by default.
AnalysisID addPass(AnalysisID PassID)
Utilities for targets to add passes to the pass manager.
TargetPassConfig(TargetMachine &TM, PassManagerBase &PM)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM Value Representation.
Definition Value.h:75
bool use_empty() const
Definition Value.h: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:709
This is an optimization pass for GlobalISel generic memory operations.
ScheduleDAGMILive * createSchedLive(MachineSchedContext *C)
Create the standard converging machine scheduler.
LLVM_ABI FunctionPass * createFlattenCFGPass()
ModulePass * createAMDGPUSwLowerLDSLegacyPass()
std::unique_ptr< ScheduleDAGMutation > createAMDGPUBarrierLatencyDAGMutation(MachineFunction *MF)
LLVM_ABI FunctionPass * createFastRegisterAllocator()
FastRegisterAllocation Pass - This pass register allocates as fast as possible.
LLVM_ABI char & EarlyMachineLICMID
This pass performs loop invariant code motion on machine instructions.
ImmutablePass * createAMDGPUAAWrapperPass()
LLVM_ABI char & PostRAHazardRecognizerID
PostRAHazardRecognizer - This pass runs the post-ra hazard recognizer.
std::function< bool(const TargetRegisterInfo &TRI, const MachineRegisterInfo &MRI, const Register Reg)> RegAllocFilterFunc
Filter function for register classes during regalloc.
FunctionPass * createAMDGPUSetWavePriorityPass()
LLVM_ABI Pass * createLCSSAPass()
Definition LCSSA.cpp:544
void initializeAMDGPUMarkLastScratchLoadLegacyPass(PassRegistry &)
void initializeAMDGPUInsertDelayAluLegacyPass(PassRegistry &)
void initializeSIOptimizeExecMaskingPreRALegacyPass(PassRegistry &)
char & GCNPreRAOptimizationsID
LLVM_ABI char & GCLoweringID
GCLowering Pass - Used by gc.root to perform its default lowering operations.
void initializeSIInsertHardClausesLegacyPass(PassRegistry &)
FunctionPass * createSIAnnotateControlFlowLegacyPass()
Create the annotation pass.
FunctionPass * createSIModeRegisterPass()
void initializeGCNPreRAOptimizationsLegacyPass(PassRegistry &)
void initializeSILowerWWMCopiesLegacyPass(PassRegistry &)
LLVM_ABI FunctionPass * createGreedyRegisterAllocator()
Greedy register allocation pass - This pass implements a global register allocator for optimized buil...
void initializeAMDGPUAAWrapperPassPass(PassRegistry &)
void initializeSIShrinkInstructionsLegacyPass(PassRegistry &)
ModulePass * createAMDGPULowerBufferFatPointersPass()
void initializeR600ClauseMergePassPass(PassRegistry &)
ModulePass * createAMDGPUCtorDtorLoweringLegacyPass()
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
ModuleToFunctionPassAdaptor createModuleToFunctionPassAdaptor(FunctionPassT &&Pass, bool EagerlyInvalidate=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
void initializeGCNRewritePartialRegUsesLegacyPass(llvm::PassRegistry &)
void initializeAMDGPURewriteUndefForPHILegacyPass(PassRegistry &)
char & GCNRewritePartialRegUsesID
void initializeAMDGPUSwLowerLDSLegacyPass(PassRegistry &)
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:94
void initializeAMDGPULowerVGPREncodingLegacyPass(PassRegistry &)
char & AMDGPUWaitSGPRHazardsLegacyID
void initializeSILowerSGPRSpillsLegacyPass(PassRegistry &)
void initializeAMDGPURegBankCombinerLegacyPass(PassRegistry &)
LLVM_ABI Pass * createLoadStoreVectorizerPass()
Create a legacy pass manager instance of the LoadStoreVectorizer pass.
FunctionPass * createAMDGPURegBankCombinerLegacy(bool IsOptLevelNone)
void initializeAMDGPUPostLegalizerCombinerLegacyPass(PassRegistry &)
std::unique_ptr< ScheduleDAGMutation > createIGroupLPDAGMutation(AMDGPU::SchedulingPhase Phase)
Phase specifes whether or not this is a reentry into the IGroupLPDAGMutation.
void initializeAMDGPUDAGToDAGISelLegacyPass(PassRegistry &)
char & AMDGPUReserveWWMRegsLegacyID
LLVM_ABI FunctionPass * createNaryReassociatePass()
void initializeAMDGPUWaitSGPRHazardsLegacyPass(PassRegistry &)
LLVM_ABI char & PatchableFunctionID
This pass implements the "patchable-function" attribute.
char & SIOptimizeExecMaskingLegacyID
LLVM_ABI char & PostRASchedulerID
PostRAScheduler - This pass performs post register allocation scheduling.
FunctionPass * createAMDGPUPostLegalizeCombinerLegacy(bool IsOptNone)
void initializeAMDGPUNextUseAnalysisLegacyPassPass(PassRegistry &)
void initializeR600ExpandSpecialInstrsPassPass(PassRegistry &)
void initializeR600PacketizerPass(PassRegistry &)
void initializeAMDGPURegBankSelectLegacyPass(PassRegistry &)
@ O1
Optimize quickly without destroying debuggability.
@ O0
Disable as many optimizations as possible.
std::unique_ptr< ScheduleDAGMutation > createVOPDPairingMutation()
ModulePass * createAMDGPUExportKernelRuntimeHandlesLegacyPass()
ModulePass * createAMDGPUAlwaysInlinePass(bool GlobalOpt=true)
void initializeAMDGPUAsmPrinterPass(PassRegistry &)
void initializeSIFoldOperandsLegacyPass(PassRegistry &)
void initializeAMDGPURegBankLegalizeLegacyPass(PassRegistry &)
char & SILoadStoreOptimizerLegacyID
void initializeAMDGPUPreLegalizerCombinerLegacyPass(PassRegistry &)
PassManager< LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, CGSCCUpdateResult & > CGSCCPassManager
The CGSCC pass manager.
LLVM_ABI std::unique_ptr< CSEConfigBase > getStandardCSEConfigForOpt(CodeGenOptLevel Level)
Definition CSEInfo.cpp:85
Target & getTheR600Target()
The target for R600 GPUs.
LLVM_ABI char & MachineSchedulerID
MachineScheduler - This pass schedules machine instructions.
LLVM_ABI Pass * createStructurizeCFGPass(bool SkipUniformRegions=false)
When SkipUniformRegions is true the structizer will not structurize regions that only contain uniform...
LLVM_ABI char & PostMachineSchedulerID
PostMachineScheduler - This pass schedules machine instructions postRA.
LLVM_ABI Pass * createLICMPass()
Definition LICM.cpp:392
char & SIFormMemoryClausesID
void initializeSILoadStoreOptimizerLegacyPass(PassRegistry &)
void initializeAMDGPULowerModuleLDSLegacyPass(PassRegistry &)
AnalysisManager< LazyCallGraph::SCC, LazyCallGraph & > CGSCCAnalysisManager
The CGSCC analysis manager.
void initializeAMDGPUCtorDtorLoweringLegacyPass(PassRegistry &)
LLVM_ABI char & EarlyIfConverterLegacyID
EarlyIfConverter - This pass performs if-conversion on SSA form by inserting cmov instructions.
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
FunctionPass * createAMDGPUUniformIntrinsicCombineLegacyPass()
ThinOrFullLTOPhase
This enumerates the LLVM full LTO or ThinLTO optimization phases.
Definition Pass.h:77
@ FullLTOPostLink
Full LTO postlink (backend compile) phase.
Definition Pass.h:87
char & AMDGPUUnifyDivergentExitNodesID
void initializeAMDGPUPrepareAGPRAllocLegacyPass(PassRegistry &)
FunctionPass * createAMDGPUAtomicOptimizerPass(ScanOptions ScanStrategy)
FunctionPass * createAMDGPUPreloadKernArgPrologLegacyPass()
char & SIOptimizeVGPRLiveRangeLegacyID
LLVM_ABI char & ShadowStackGCLoweringID
ShadowStackGCLowering - Implements the custom lowering mechanism used by the shadow stack GC.
char & GCNNSAReassignID
void initializeAMDGPURewriteOutArgumentsPass(PassRegistry &)
static Reloc::Model getEffectiveRelocModel(std::optional< Reloc::Model > RM)
void initializeAMDGPUExternalAAWrapperPass(PassRegistry &)
char & SIFoldOperandsLegacyID
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
void initializeAMDGPULowerKernelArgumentsPass(PassRegistry &)
void initializeSIModeRegisterLegacyPass(PassRegistry &)
CodeModel::Model getEffectiveCodeModel(std::optional< CodeModel::Model > CM, CodeModel::Model Default)
Helper method for getting the code model, returning Default if CM does not have a value.
void initializeAMDGPUPreloadKernelArgumentsLegacyPass(PassRegistry &)
LLVM_ABI ModulePass * createExpandVariadicsPass(ExpandVariadicsMode)
char & SILateBranchLoweringPassID
FunctionToLoopPassAdaptor createFunctionToLoopPassAdaptor(LoopPassT &&Pass, bool UseMemorySSA=false)
A function to deduce a loop pass type and wrap it in the templated adaptor.
LLVM_ABI char & BranchRelaxationPassID
BranchRelaxation - This pass replaces branches that need to jump further than is supported by a branc...
LLVM_ABI FunctionPass * createSinkingPass()
Definition Sink.cpp:273
CGSCCToFunctionPassAdaptor createCGSCCToFunctionPassAdaptor(FunctionPassT &&Pass, bool EagerlyInvalidate=false, bool NoRerun=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
void initializeSIMemoryLegalizerLegacyPass(PassRegistry &)
ModulePass * createAMDGPULowerIntrinsicsLegacyPass()
void initializeR600MachineCFGStructurizerPass(PassRegistry &)
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition CodeGen.h:206
char & GCNDPPCombineLegacyID
PassManager< Module > ModulePassManager
Convenience typedef for a pass manager over modules.
LLVM_ABI std::unique_ptr< ScheduleDAGMutation > createStoreClusterDAGMutation(const TargetInstrInfo *TII, const TargetRegisterInfo *TRI, bool ReorderWhileClustering=false)
If ReorderWhileClustering is set to true, no attempt will be made to reduce reordering due to store c...
LLVM_ABI FunctionPass * createLoopDataPrefetchPass()
FunctionPass * createAMDGPULowerKernelArgumentsPass()
char & AMDGPUInsertDelayAluID
std::unique_ptr< ScheduleDAGMutation > createAMDGPUMacroFusionDAGMutation()
Note that you have to add: DAG.addMutation(createAMDGPUMacroFusionDAGMutation()); to AMDGPUTargetMach...
LLVM_ABI char & StackMapLivenessID
StackMapLiveness - This pass analyses the register live-out set of stackmap/patchpoint intrinsics and...
void initializeGCNPreRALongBranchRegLegacyPass(PassRegistry &)
char & SILowerWWMCopiesLegacyID
LLVM_ABI FunctionPass * createUnifyLoopExitsPass()
char & SIOptimizeExecMaskingPreRAID
LLVM_ABI FunctionPass * createFixIrreduciblePass()
void initializeR600EmitClauseMarkersPass(PassRegistry &)
LLVM_ABI char & FuncletLayoutID
This pass lays out funclets contiguously.
LLVM_ABI char & DetectDeadLanesID
This pass adds dead/undef flags after analyzing subregister lanes.
void initializeAMDGPULowerExecSyncLegacyPass(PassRegistry &)
ScheduleDAGInstrs * createGCNNoopPostMachineScheduler(MachineSchedContext *C)
void initializeAMDGPUExportKernelRuntimeHandlesLegacyPass(PassRegistry &)
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:177
@ Default
-O2, -Os, -Oz
Definition CodeGen.h:180
void initializeSIInsertWaitcntsLegacyPass(PassRegistry &)
ModulePass * createAMDGPUPreloadKernelArgumentsLegacyPass(const TargetMachine *)
ModulePass * createAMDGPUPrintfRuntimeBinding()
LLVM_ABI char & StackSlotColoringID
StackSlotColoring - This pass performs stack slot coloring.
LLVM_ABI Pass * createAlwaysInlinerLegacyPass(bool InsertLifetime=true)
Create a legacy pass manager instance of a pass to inline and remove functions marked as "always_inli...
void initializeR600ControlFlowFinalizerPass(PassRegistry &)
void initializeAMDGPUImageIntrinsicOptimizerPass(PassRegistry &)
void initializeSILateBranchLoweringLegacyPass(PassRegistry &)
void initializeSILowerControlFlowLegacyPass(PassRegistry &)
void initializeSIFormMemoryClausesLegacyPass(PassRegistry &)
char & SIPreAllocateWWMRegsLegacyID
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
ModulePass * createAMDGPULowerModuleLDSLegacyPass(const AMDGPUTargetMachine *TM=nullptr)
FunctionPass * createAMDGPUPromoteAlloca()
LLVM_ABI FunctionPass * createSeparateConstOffsetFromGEPPass(bool LowerGEP=false)
void initializeAMDGPUReserveWWMRegsLegacyPass(PassRegistry &)
char & SIPreEmitPeepholeID
char & SIPostRABundlerLegacyID
ModulePass * createAMDGPURemoveIncompatibleFunctionsPass(const TargetMachine *)
void initializeGCNRegPressurePrinterPass(PassRegistry &)
void initializeSILowerI1CopiesLegacyPass(PassRegistry &)
LLVM_ABI ImmutablePass * createExternalAAWrapperPass(std::function< void(Pass &, Function &, AAResults &)> Callback, bool RunEarly=false)
A wrapper pass around a callback which can be used to populate the AAResults in the AAResultsWrapperP...
char & SILowerSGPRSpillsLegacyID
LLVM_ABI FunctionPass * createBasicRegisterAllocator()
BasicRegisterAllocation Pass - This pass implements a degenerate global register allocator using the ...
LLVM_ABI void initializeGlobalISel(PassRegistry &)
Initialize all passes linked into the GlobalISel library.
char & SILowerControlFlowLegacyID
ModulePass * createR600OpenCLImageTypeLoweringPass()
FunctionPass * createAMDGPUCodeGenPreparePass()
void initializeSIAnnotateControlFlowLegacyPass(PassRegistry &)
FunctionPass * createAMDGPUISelDag(TargetMachine &TM, CodeGenOptLevel OptLevel)
This pass converts a legalized DAG into a AMDGPU-specific.
void initializeGCNCreateVOPDLegacyPass(PassRegistry &)
void initializeAMDGPUUniformIntrinsicCombineLegacyPass(PassRegistry &)
ScheduleDAGInstrs * createGCNCoExecMachineScheduler(MachineSchedContext *C)
void initializeSIPreAllocateWWMRegsLegacyPass(PassRegistry &)
void initializeSIFixVGPRCopiesLegacyPass(PassRegistry &)
Target & getTheGCNTarget()
The target for GCN GPUs.
void initializeSIFixSGPRCopiesLegacyPass(PassRegistry &)
void initializeAMDGPUAtomicOptimizerPass(PassRegistry &)
void initializeAMDGPULowerIntrinsicsLegacyPass(PassRegistry &)
LLVM_ABI char & MachinePipelinerID
This pass performs software pipelining on machine instructions.
LLVM_ABI FunctionPass * createGVNPass()
Definition GVN.cpp:4099
void initializeAMDGPURewriteAGPRCopyMFMALegacyPass(PassRegistry &)
void initializeAMDGPUNextUseAnalysisPrinterLegacyPassPass(PassRegistry &)
void initializeSIPostRABundlerLegacyPass(PassRegistry &)
LLVM_ABI char & MachineCSELegacyID
MachineCSE - This pass performs global CSE on machine instructions.
char & SIWholeQuadModeID
LLVM_ABI std::unique_ptr< ScheduleDAGMutation > createLoadClusterDAGMutation(const TargetInstrInfo *TII, const TargetRegisterInfo *TRI, bool ReorderWhileClustering=false)
If ReorderWhileClustering is set to true, no attempt will be made to reduce reordering due to store c...
PassManager< Function > FunctionPassManager
Convenience typedef for a pass manager over functions.
LLVM_ABI char & LiveVariablesID
LiveVariables pass - This pass computes the set of blocks in which each variable is life and sets mac...
void initializeAMDGPUCodeGenPreparePass(PassRegistry &)
FunctionPass * createAMDGPURewriteUndefForPHILegacyPass()
void initializeSIOptimizeExecMaskingLegacyPass(PassRegistry &)
void call_once(once_flag &flag, Function &&F, Args &&... ArgList)
Execute the function specified as a parameter once.
Definition Threading.h:86
FunctionPass * createSILowerI1CopiesLegacyPass()
FunctionPass * createAMDGPURegBankSelectLegacyPass()
void initializeAMDGPULowerKernelAttributesPass(PassRegistry &)
char & SIInsertHardClausesID
char & SIFixSGPRCopiesLegacyID
void initializeGCNDPPCombineLegacyPass(PassRegistry &)
char & GCNCreateVOPDID
char & SIPeepholeSDWALegacyID
LLVM_ABI char & VirtRegRewriterID
VirtRegRewriter pass.
char & SIFixVGPRCopiesID
void initializeGCNNSAReassignLegacyPass(PassRegistry &)
LLVM_ABI FunctionPass * createLowerSwitchPass()
void initializeAMDGPUPreloadKernArgPrologLegacyPass(PassRegistry &)
Target & getTheGCNLegacyTarget()
The target for GCN GPUs, registered under the legacy "amdgcn" architecture name for use with -march.
LLVM_ABI FunctionPass * createVirtRegRewriter(bool ClearVirtRegs=true)
void initializeR600VectorRegMergerPass(PassRegistry &)
char & AMDGPURewriteAGPRCopyMFMALegacyID
ModulePass * createAMDGPULowerExecSyncLegacyPass()
char & AMDGPULowerVGPREncodingLegacyID
FunctionPass * createAMDGPUGlobalISelDivergenceLoweringPass()
FunctionPass * createAMDGPUPreLegalizeCombinerLegacyPass(bool IsOptLevelNone)
FunctionPass * createSIMemoryLegalizerPass()
void initializeAMDGPULateCodeGenPrepareLegacyPass(PassRegistry &)
void initializeSIOptimizeVGPRLiveRangeLegacyPass(PassRegistry &)
void initializeSIPeepholeSDWALegacyPass(PassRegistry &)
LLVM_ABI char & TwoAddressInstructionPassID
TwoAddressInstruction - This pass reduces two-address instructions to use two operands.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
FunctionPass * createAMDGPULateCodeGenPrepareLegacyPass()
LLVM_ABI FunctionPass * createAtomicExpandLegacyPass()
AtomicExpandPass - At IR level this pass replace atomic instructions with __atomic_* library calls,...
void initializeAMDGPUGlobalISelDivergenceLoweringLegacyPass(PassRegistry &)
MCRegisterInfo * createGCNMCRegisterInfo(AMDGPUDwarfFlavour DwarfFlavour)
LLVM_ABI FunctionPass * createStraightLineStrengthReducePass()
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:390
FunctionPass * createAMDGPUImageIntrinsicOptimizerPass(const TargetMachine *)
void initializeAMDGPULowerBufferFatPointersPass(PassRegistry &)
void initializeAMDGPUUnifyDivergentExitNodesLegacyPass(PassRegistry &)
FunctionPass * createSIInsertWaitcntsPass()
FunctionPass * createAMDGPUAnnotateUniformValuesLegacy()
LLVM_ABI FunctionPass * createEarlyCSEPass(bool UseMemorySSA=false)
void initializeSIWholeQuadModeLegacyPass(PassRegistry &)
LLVM_ABI char & PHIEliminationID
PHIElimination - This pass eliminates machine instruction PHI nodes by inserting copy instructions.
LLVM_ABI llvm::cl::opt< bool > NoKernelInfoEndLTO
LLVM_ABI bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
void initializeAMDGPUResourceUsageAnalysisWrapperPassPass(PassRegistry &)
FunctionPass * createSIShrinkInstructionsLegacyPass()
char & AMDGPUPrepareAGPRAllocLegacyID
char & AMDGPUMarkLastScratchLoadID
LLVM_ABI char & RenameIndependentSubregsID
This pass detects subregister lanes in a virtual register that are used independently of other lanes ...
void initializeAMDGPUAnnotateUniformValuesLegacyPass(PassRegistry &)
std::unique_ptr< ScheduleDAGMutation > createAMDGPUExportClusteringDAGMutation()
void initializeAMDGPUPrintfRuntimeBindingPass(PassRegistry &)
void initializeAMDGPUPromoteAllocaPass(PassRegistry &)
void initializeAMDGPURemoveIncompatibleFunctionsLegacyPass(PassRegistry &)
std::unique_ptr< ScheduleDAGMutation > createAMDGPUHazardLatencyDAGMutation(MachineFunction *MF)
void initializeAMDGPUAlwaysInlinePass(PassRegistry &)
LLVM_ABI char & DeadMachineInstructionElimID
DeadMachineInstructionElim - This pass removes dead machine instructions.
void initializeSIPreEmitPeepholeLegacyPass(PassRegistry &)
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
char & AMDGPUPerfHintAnalysisLegacyID
char & GCNPreRALongBranchRegID
FunctionPass * createAMDGPURegBankLegalizeLegacyPass()
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
LLVM_ABI CGPassBuilderOption getCGPassBuilderOption()
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:177
void initializeAMDGPUPromoteKernelArgumentsPass(PassRegistry &)
#define N
static ArgDescriptor createStack(unsigned Offset, unsigned Mask=~0u)
static ArgDescriptor createArg(const ArgDescriptor &Arg, unsigned Mask)
static ArgDescriptor createRegister(Register Reg, unsigned Mask=~0u)
DenormalModeKind Input
Denormal treatment kind for floating point instruction inputs in the default floating-point environme...
@ PreserveSign
The sign of a flushed-to-zero number is preserved in the sign of 0.
@ IEEE
IEEE-754 denormal numbers preserved.
DenormalModeKind Output
Denormal flushing mode for floating point instruction results in the default floating point environme...
A simple and fast domtree-based CSE pass.
Definition EarlyCSE.h:31
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
static FuncInfoTy * create(BumpPtrAllocator &Allocator, const Function &F, const SubtargetTy *STI)
Factory function: default behavior is to call new using the supplied allocator.
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
StringMap< VRegInfo * > VRegInfosNamed
Definition MIParser.h:179
DenseMap< Register, VRegInfo * > VRegInfos
Definition MIParser.h:178
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.