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"
92#include "llvm/CodeGen/Passes.h"
103#include "llvm/IR/IntrinsicsAMDGPU.h"
104#include "llvm/IR/Module.h"
105#include "llvm/IR/PassManager.h"
106#include "llvm/IR/PatternMatch.h"
115#include "llvm/Transforms/IPO.h"
140#include <optional>
141
142using namespace llvm;
143using namespace llvm::PatternMatch;
144
145namespace {
146//===----------------------------------------------------------------------===//
147// AMDGPU CodeGen Pass Builder interface.
148//===----------------------------------------------------------------------===//
149
150class AMDGPUCodeGenPassBuilder : public CodeGenPassBuilder {
151 using Base = CodeGenPassBuilder;
152
153 GCNTargetMachine &getTM() const {
154 return static_cast<GCNTargetMachine &>(TM);
155 }
156
157public:
158 AMDGPUCodeGenPassBuilder(GCNTargetMachine &TM,
159 const CGPassBuilderOption &Opts,
160 PassInstrumentationCallbacks *PIC);
161
162 void addIRPasses(PassManagerWrapper &PMW) override;
163 void addCodeGenPrepare(PassManagerWrapper &PMW) override;
164 void addPreISel(PassManagerWrapper &PMW) override;
165 void addILPOpts(PassManagerWrapper &PMW) override;
166 void addAsmPrinterBegin(PassManagerWrapper &PMW) override;
167 void addAsmPrinter(PassManagerWrapper &PMW) override;
168 void addAsmPrinterEnd(PassManagerWrapper &PMW) override;
169 Error addInstSelector(PassManagerWrapper &PMW) override;
170 void addPreRewrite(PassManagerWrapper &PMW) override;
171 void addMachineSSAOptimization(PassManagerWrapper &PMW) override;
172 void addPostRegAlloc(PassManagerWrapper &PMW) override;
173 void addPreEmitPass(PassManagerWrapper &PMW) override;
174 Error addRegAssignAndRewriteFast(PassManagerWrapper &PMW) override;
175 Expected<bool>
176 addRegAssignAndRewriteOptimized(PassManagerWrapper &PMW) override;
177 void addPreRegAlloc(PassManagerWrapper &PMW) override;
178 Error addFastRegAlloc(PassManagerWrapper &PMW) override;
179 Error addOptimizedRegAlloc(PassManagerWrapper &PMW) override;
180 void addPreSched2(PassManagerWrapper &PMW) override;
181 void addPostBBSections(PassManagerWrapper &PMW) override;
182
183private:
184 Error validateRegAllocOptions() const;
185
186public:
187 /// Check if a pass is enabled given \p Opt option. The option always
188 /// overrides defaults if explicitly used. Otherwise its default will be used
189 /// given that a pass shall work at an optimization \p Level minimum.
190 bool isPassEnabled(const cl::opt<bool> &Opt,
191 CodeGenOptLevel Level = CodeGenOptLevel::Default) const;
192 void addEarlyCSEOrGVNPass(PassManagerWrapper &PMW);
193 void addStraightLineScalarOptimizationPasses(PassManagerWrapper &PMW);
194};
195
196class SGPRRegisterRegAlloc : public RegisterRegAllocBase<SGPRRegisterRegAlloc> {
197public:
198 SGPRRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
199 : RegisterRegAllocBase(N, D, C) {}
200};
201
202class VGPRRegisterRegAlloc : public RegisterRegAllocBase<VGPRRegisterRegAlloc> {
203public:
204 VGPRRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
205 : RegisterRegAllocBase(N, D, C) {}
206};
207
208class WWMRegisterRegAlloc : public RegisterRegAllocBase<WWMRegisterRegAlloc> {
209public:
210 WWMRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
211 : RegisterRegAllocBase(N, D, C) {}
212};
213
214static bool onlyAllocateSGPRs(const TargetRegisterInfo &TRI,
215 const MachineRegisterInfo &MRI,
216 const Register Reg) {
217 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
218 return static_cast<const SIRegisterInfo &>(TRI).isSGPRClass(RC);
219}
220
221static bool onlyAllocateVGPRs(const TargetRegisterInfo &TRI,
222 const MachineRegisterInfo &MRI,
223 const Register Reg) {
224 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
225 return !static_cast<const SIRegisterInfo &>(TRI).isSGPRClass(RC);
226}
227
228static bool onlyAllocateWWMRegs(const TargetRegisterInfo &TRI,
229 const MachineRegisterInfo &MRI,
230 const Register Reg) {
231 const SIMachineFunctionInfo *MFI =
233 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
234 return !static_cast<const SIRegisterInfo &>(TRI).isSGPRClass(RC) &&
236}
237
238/// -{sgpr|wwm|vgpr}-regalloc=... command line option.
239static FunctionPass *useDefaultRegisterAllocator() { return nullptr; }
240
241/// A dummy default pass factory indicates whether the register allocator is
242/// overridden on the command line.
243static llvm::once_flag InitializeDefaultSGPRRegisterAllocatorFlag;
244static llvm::once_flag InitializeDefaultVGPRRegisterAllocatorFlag;
245static llvm::once_flag InitializeDefaultWWMRegisterAllocatorFlag;
246
247static SGPRRegisterRegAlloc
248defaultSGPRRegAlloc("default",
249 "pick SGPR register allocator based on -O option",
251
252static cl::opt<SGPRRegisterRegAlloc::FunctionPassCtor, false,
254SGPRRegAlloc("sgpr-regalloc", cl::Hidden, cl::init(&useDefaultRegisterAllocator),
255 cl::desc("Register allocator to use for SGPRs"));
256
257static cl::opt<VGPRRegisterRegAlloc::FunctionPassCtor, false,
259VGPRRegAlloc("vgpr-regalloc", cl::Hidden, cl::init(&useDefaultRegisterAllocator),
260 cl::desc("Register allocator to use for VGPRs"));
261
262static cl::opt<WWMRegisterRegAlloc::FunctionPassCtor, false,
264 WWMRegAlloc("wwm-regalloc", cl::Hidden,
266 cl::desc("Register allocator to use for WWM registers"));
267
268// New pass manager register allocator options for AMDGPU
270 "sgpr-regalloc-npm", cl::Hidden, cl::init(RegAllocType::Default),
271 cl::desc("Register allocator for SGPRs (new pass manager)"));
272
274 "vgpr-regalloc-npm", cl::Hidden, cl::init(RegAllocType::Default),
275 cl::desc("Register allocator for VGPRs (new pass manager)"));
276
278 "wwm-regalloc-npm", cl::Hidden, cl::init(RegAllocType::Default),
279 cl::desc("Register allocator for WWM registers (new pass manager)"));
280
281/// Check if the given RegAllocType is supported for AMDGPU NPM register
282/// allocation. Only Fast and Greedy are supported; Basic and PBQP are not.
283static Error checkRegAllocSupported(RegAllocType RAType, StringRef RegName) {
284 if (RAType == RegAllocType::Basic || RAType == RegAllocType::PBQP) {
286 Twine("unsupported register allocator '") +
287 (RAType == RegAllocType::Basic ? "basic" : "pbqp") + "' for " +
288 RegName + " registers",
290 }
291 return Error::success();
292}
293
294Error AMDGPUCodeGenPassBuilder::validateRegAllocOptions() const {
295 // 1. Generic --regalloc-npm is not supported for AMDGPU.
296 if (Opt.RegAlloc != RegAllocType::Unset) {
298 "-regalloc-npm not supported for amdgcn. Use -sgpr-regalloc-npm, "
299 "-vgpr-regalloc-npm, and -wwm-regalloc-npm",
301 }
302
303 // 2. Legacy PM regalloc options are not compatible with NPM.
304 if (SGPRRegAlloc.getNumOccurrences() > 0 ||
305 VGPRRegAlloc.getNumOccurrences() > 0 ||
306 WWMRegAlloc.getNumOccurrences() > 0) {
308 "-sgpr-regalloc, -vgpr-regalloc, and -wwm-regalloc are legacy PM "
309 "options. Use -sgpr-regalloc-npm, -vgpr-regalloc-npm, and "
310 "-wwm-regalloc-npm with the new pass manager",
312 }
313
314 // 3. Only Fast and Greedy allocators are supported for AMDGPU.
315 if (auto Err = checkRegAllocSupported(SGPRRegAllocNPM, "SGPR"))
316 return Err;
317 if (auto Err = checkRegAllocSupported(WWMRegAllocNPM, "WWM"))
318 return Err;
319 if (auto Err = checkRegAllocSupported(VGPRRegAllocNPM, "VGPR"))
320 return Err;
321
322 return Error::success();
323}
324
325static void initializeDefaultSGPRRegisterAllocatorOnce() {
326 RegisterRegAlloc::FunctionPassCtor Ctor = SGPRRegisterRegAlloc::getDefault();
327
328 if (!Ctor) {
329 Ctor = SGPRRegAlloc;
330 SGPRRegisterRegAlloc::setDefault(SGPRRegAlloc);
331 }
332}
333
334static void initializeDefaultVGPRRegisterAllocatorOnce() {
335 RegisterRegAlloc::FunctionPassCtor Ctor = VGPRRegisterRegAlloc::getDefault();
336
337 if (!Ctor) {
338 Ctor = VGPRRegAlloc;
339 VGPRRegisterRegAlloc::setDefault(VGPRRegAlloc);
340 }
341}
342
343static void initializeDefaultWWMRegisterAllocatorOnce() {
344 RegisterRegAlloc::FunctionPassCtor Ctor = WWMRegisterRegAlloc::getDefault();
345
346 if (!Ctor) {
347 Ctor = WWMRegAlloc;
348 WWMRegisterRegAlloc::setDefault(WWMRegAlloc);
349 }
350}
351
352static FunctionPass *createBasicSGPRRegisterAllocator() {
353 return createBasicRegisterAllocator(onlyAllocateSGPRs);
354}
355
356static FunctionPass *createGreedySGPRRegisterAllocator() {
357 return createGreedyRegisterAllocator(onlyAllocateSGPRs);
358}
359
360static FunctionPass *createFastSGPRRegisterAllocator() {
361 return createFastRegisterAllocator(onlyAllocateSGPRs, false);
362}
363
364static FunctionPass *createBasicVGPRRegisterAllocator() {
365 return createBasicRegisterAllocator(onlyAllocateVGPRs);
366}
367
368static FunctionPass *createGreedyVGPRRegisterAllocator() {
369 return createGreedyRegisterAllocator(onlyAllocateVGPRs);
370}
371
372static FunctionPass *createFastVGPRRegisterAllocator() {
373 return createFastRegisterAllocator(onlyAllocateVGPRs, true);
374}
375
376static FunctionPass *createBasicWWMRegisterAllocator() {
377 return createBasicRegisterAllocator(onlyAllocateWWMRegs);
378}
379
380static FunctionPass *createGreedyWWMRegisterAllocator() {
381 return createGreedyRegisterAllocator(onlyAllocateWWMRegs);
382}
383
384static FunctionPass *createFastWWMRegisterAllocator() {
385 return createFastRegisterAllocator(onlyAllocateWWMRegs, false);
386}
387
388static SGPRRegisterRegAlloc basicRegAllocSGPR(
389 "basic", "basic register allocator", createBasicSGPRRegisterAllocator);
390static SGPRRegisterRegAlloc greedyRegAllocSGPR(
391 "greedy", "greedy register allocator", createGreedySGPRRegisterAllocator);
392
393static SGPRRegisterRegAlloc fastRegAllocSGPR(
394 "fast", "fast register allocator", createFastSGPRRegisterAllocator);
395
396
397static VGPRRegisterRegAlloc basicRegAllocVGPR(
398 "basic", "basic register allocator", createBasicVGPRRegisterAllocator);
399static VGPRRegisterRegAlloc greedyRegAllocVGPR(
400 "greedy", "greedy register allocator", createGreedyVGPRRegisterAllocator);
401
402static VGPRRegisterRegAlloc fastRegAllocVGPR(
403 "fast", "fast register allocator", createFastVGPRRegisterAllocator);
404static WWMRegisterRegAlloc basicRegAllocWWMReg("basic",
405 "basic register allocator",
406 createBasicWWMRegisterAllocator);
407static WWMRegisterRegAlloc
408 greedyRegAllocWWMReg("greedy", "greedy register allocator",
409 createGreedyWWMRegisterAllocator);
410static WWMRegisterRegAlloc fastRegAllocWWMReg("fast", "fast register allocator",
411 createFastWWMRegisterAllocator);
412
414 return Phase == ThinOrFullLTOPhase::FullLTOPreLink ||
415 Phase == ThinOrFullLTOPhase::ThinLTOPreLink;
416}
417} // anonymous namespace
418
419static cl::opt<bool>
421 cl::desc("Run early if-conversion"),
422 cl::init(false));
423
424static cl::opt<bool>
425OptExecMaskPreRA("amdgpu-opt-exec-mask-pre-ra", cl::Hidden,
426 cl::desc("Run pre-RA exec mask optimizations"),
427 cl::init(true));
428
429static cl::opt<bool>
430 LowerCtorDtor("amdgpu-lower-global-ctor-dtor",
431 cl::desc("Lower GPU ctor / dtors to globals on the device."),
432 cl::init(true), cl::Hidden);
433
434// Option to disable vectorizer for tests.
436 "amdgpu-load-store-vectorizer",
437 cl::desc("Enable load store vectorizer"),
438 cl::init(true),
439 cl::Hidden);
440
441// Option to control global loads scalarization
443 "amdgpu-scalarize-global-loads",
444 cl::desc("Enable global load scalarization"),
445 cl::init(true),
446 cl::Hidden);
447
448// Option to run internalize pass.
450 "amdgpu-internalize-symbols",
451 cl::desc("Enable elimination of non-kernel functions and unused globals"),
452 cl::init(false),
453 cl::Hidden);
454
455// Option to inline all early.
457 "amdgpu-early-inline-all",
458 cl::desc("Inline all functions early"),
459 cl::init(false),
460 cl::Hidden);
461
463 "amdgpu-enable-remove-incompatible-functions", cl::Hidden,
464 cl::desc("Enable removal of functions when they"
465 "use features not supported by the target GPU"),
466 cl::init(true));
467
469 "amdgpu-sdwa-peephole",
470 cl::desc("Enable SDWA peepholer"),
471 cl::init(true));
472
474 "amdgpu-dpp-combine",
475 cl::desc("Enable DPP combiner"),
476 cl::init(true));
477
478// Enable address space based alias analysis
480 cl::desc("Enable AMDGPU Alias Analysis"),
481 cl::init(true));
482
483static cl::opt<bool>
484 XnackSetting("amdgpu-xnack",
485 cl::desc("Force amdgpu.xnack value for testing"),
487
488static cl::opt<bool>
489 SramEccSetting("amdgpu-sramecc",
490 cl::desc("Force amdgpu.sramecc for testing"),
492
493// Enable lib calls simplifications
495 "amdgpu-simplify-libcall",
496 cl::desc("Enable amdgpu library simplifications"),
497 cl::init(true),
498 cl::Hidden);
499
501 "amdgpu-ir-lower-kernel-arguments",
502 cl::desc("Lower kernel argument loads in IR pass"),
503 cl::init(true),
504 cl::Hidden);
505
507 "amdgpu-reassign-regs",
508 cl::desc("Enable register reassign optimizations on gfx10+"),
509 cl::init(true),
510 cl::Hidden);
511
513 "amdgpu-opt-vgpr-liverange",
514 cl::desc("Enable VGPR liverange optimizations for if-else structure"),
515 cl::init(true), cl::Hidden);
516
518 "amdgpu-atomic-optimizer-strategy",
519 cl::desc("Select DPP or Iterative strategy for scan"),
522 clEnumValN(ScanOptions::DPP, "DPP", "Use DPP operations for scan"),
524 "Use Iterative approach for scan"),
525 clEnumValN(ScanOptions::None, "None", "Disable atomic optimizer")));
526
527// Enable Mode register optimization
529 "amdgpu-mode-register",
530 cl::desc("Enable mode register pass"),
531 cl::init(true),
532 cl::Hidden);
533
534// Enable GFX11+ s_delay_alu insertion
535static cl::opt<bool>
536 EnableInsertDelayAlu("amdgpu-enable-delay-alu",
537 cl::desc("Enable s_delay_alu insertion"),
538 cl::init(true), cl::Hidden);
539
540// Enable GFX11+ VOPD
541static cl::opt<bool>
542 EnableVOPD("amdgpu-enable-vopd",
543 cl::desc("Enable VOPD, dual issue of VALU in wave32"),
544 cl::init(true), cl::Hidden);
545
546// Option is used in lit tests to prevent deadcoding of patterns inspected.
547static cl::opt<bool>
548EnableDCEInRA("amdgpu-dce-in-ra",
549 cl::init(true), cl::Hidden,
550 cl::desc("Enable machine DCE inside regalloc"));
551
552static cl::opt<bool> EnableSetWavePriority("amdgpu-set-wave-priority",
553 cl::desc("Adjust wave priority"),
554 cl::init(false), cl::Hidden);
555
557 "amdgpu-scalar-ir-passes",
558 cl::desc("Enable scalar IR passes"),
559 cl::init(true),
560 cl::Hidden);
561
563 "amdgpu-enable-lower-exec-sync",
564 cl::desc("Enable lowering of execution synchronization."), cl::init(true),
565 cl::Hidden);
566
567static cl::opt<bool>
568 EnableSwLowerLDS("amdgpu-enable-sw-lower-lds",
569 cl::desc("Enable lowering of lds to global memory pass "
570 "and asan instrument resulting IR."),
571 cl::init(true), cl::Hidden);
572
574 "amdgpu-enable-object-linking",
575 cl::desc("Enable object linking for cross-TU LDS and ABI support"),
577 cl::Hidden);
578
580 "amdgpu-enable-lower-module-lds", cl::desc("Enable lower module lds pass"),
582 cl::Hidden);
583
585 "amdgpu-enable-pre-ra-optimizations",
586 cl::desc("Enable Pre-RA optimizations pass"), cl::init(true),
587 cl::Hidden);
588
590 "amdgpu-enable-promote-kernel-arguments",
591 cl::desc("Enable promotion of flat kernel pointer arguments to global"),
592 cl::Hidden, cl::init(true));
593
595 "amdgpu-enable-image-intrinsic-optimizer",
596 cl::desc("Enable image intrinsic optimizer pass"), cl::init(true),
597 cl::Hidden);
598
599static cl::opt<bool>
600 EnableLoopPrefetch("amdgpu-loop-prefetch",
601 cl::desc("Enable loop data prefetch on AMDGPU"),
602 cl::Hidden, cl::init(false));
603
605 AMDGPUSchedStrategy("amdgpu-sched-strategy",
606 cl::desc("Select custom AMDGPU scheduling strategy."),
607 cl::Hidden, cl::init(""));
608
609// Scheduler selection is consulted both when creating the scheduler and from
610// overrideSchedPolicy(), so keep the attribute and global command line handling
611// in one helper.
613 Attribute SchedStrategyAttr = F.getFnAttribute("amdgpu-sched-strategy");
614 if (SchedStrategyAttr.isValid())
615 return SchedStrategyAttr.getValueAsString();
616
617 if (!AMDGPUSchedStrategy.empty())
618 return AMDGPUSchedStrategy;
619
620 return "";
621}
622
623static void
625 const GCNSubtarget &ST) {
626 if (ST.hasGFX1250Insts() || ST.hasGFX950Insts())
627 return;
628
629 F.getContext().diagnose(DiagnosticInfoUnsupported(
630 F,
631 "'amdgpu-sched-strategy'='coexec' is only supported for gfx1250/gfx950",
633}
634
635static bool useNoopPostScheduler(const Function &F) {
636 Attribute PostSchedStrategyAttr =
637 F.getFnAttribute("amdgpu-post-sched-strategy");
638 return PostSchedStrategyAttr.isValid() &&
639 PostSchedStrategyAttr.getValueAsString() == "nop";
640}
641
643 "amdgpu-enable-rewrite-partial-reg-uses",
644 cl::desc("Enable rewrite partial reg uses pass"), cl::init(true),
645 cl::Hidden);
646
648 "amdgpu-enable-hipstdpar",
649 cl::desc("Enable HIP Standard Parallelism Offload support"), cl::init(false),
650 cl::Hidden);
651
652static cl::opt<bool>
653 EnableAMDGPUAttributor("amdgpu-attributor-enable",
654 cl::desc("Enable AMDGPUAttributorPass"),
655 cl::init(true), cl::Hidden);
656
658 "amdgpu-link-time-closed-world",
659 cl::desc("Whether has closed-world assumption at link time"),
660 cl::init(false), cl::Hidden);
661
663 "amdgpu-enable-uniform-intrinsic-combine",
664 cl::desc("Enable/Disable the Uniform Intrinsic Combine Pass"),
665 cl::init(true), cl::Hidden);
666
667static cl::opt<bool>
668 EnableMachinePipeliner("amdgpu-enable-pipeliner",
669 cl::desc("Enable Machine Pipeliner for AMDGCN"),
670 cl::init(false), cl::Hidden);
671
673 // Register the target
677
763}
764
765static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
766 return std::make_unique<AMDGPUTargetObjectFile>();
767}
768
772
773static ScheduleDAGInstrs *
775 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
776 ScheduleDAGMILive *DAG =
777 new GCNScheduleDAGMILive(C, std::make_unique<GCNMaxOccupancySchedStrategy>(C));
778 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
779 if (ST.shouldClusterStores())
780 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
782 DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
783 DAG->addMutation(createAMDGPUExportClusteringDAGMutation());
784 DAG->addMutation(createAMDGPUBarrierLatencyDAGMutation(C->MF));
785 DAG->addMutation(createAMDGPUHazardLatencyDAGMutation(C->MF));
786 return DAG;
787}
788
789static ScheduleDAGInstrs *
791 ScheduleDAGMILive *DAG =
792 new GCNScheduleDAGMILive(C, std::make_unique<GCNMaxILPSchedStrategy>(C));
794 return DAG;
795}
796
797static ScheduleDAGInstrs *
799 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
801 C, std::make_unique<GCNMaxMemoryClauseSchedStrategy>(C));
802 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
803 if (ST.shouldClusterStores())
804 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
805 DAG->addMutation(createAMDGPUExportClusteringDAGMutation());
806 DAG->addMutation(createAMDGPUBarrierLatencyDAGMutation(C->MF));
807 DAG->addMutation(createAMDGPUHazardLatencyDAGMutation(C->MF));
808 return DAG;
809}
810
811static ScheduleDAGInstrs *
813 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
814 auto *DAG = new GCNIterativeScheduler(
816 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
817 if (ST.shouldClusterStores())
818 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
820 return DAG;
821}
822
829
830static ScheduleDAGInstrs *
832 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
834 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
835 if (ST.shouldClusterStores())
836 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
837 DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
839 return DAG;
840}
841
842static MachineSchedRegistry
843SISchedRegistry("si", "Run SI's custom scheduler",
845
848 "Run GCN scheduler to maximize occupancy",
850
852 GCNMaxILPSchedRegistry("gcn-max-ilp", "Run GCN scheduler to maximize ilp",
854
856 "gcn-max-memory-clause", "Run GCN scheduler to maximize memory clause",
858
860 "gcn-iterative-max-occupancy-experimental",
861 "Run GCN scheduler to maximize occupancy (experimental)",
863
865 "gcn-iterative-minreg",
866 "Run GCN iterative scheduler for minimal register usage (experimental)",
868
870 "gcn-iterative-ilp",
871 "Run GCN iterative scheduler for ILP scheduling (experimental)",
873
876 if (!GPU.empty())
877 return GPU;
878
879 if (StringRef Name = AMDGPU::getArchNameFromSubArch(TT.getSubArch());
880 !Name.empty())
881 return Name;
882
883 // Need to default to a target with flat support for HSA.
884 if (TT.isAMDGCN())
885 return TT.getOS() == Triple::AMDHSA ? "generic-hsa" : "generic";
886
887 return "r600";
888}
889
891 // The AMDGPU toolchain only supports generating shared objects, so we
892 // must always use PIC.
893 return Reloc::PIC_;
894}
895
897 StringRef CPU, StringRef FS,
898 const TargetOptions &Options,
899 std::optional<Reloc::Model> RM,
900 std::optional<CodeModel::Model> CM,
903 T, TT.computeDataLayout(), TT, getGPUOrDefault(TT, CPU), FS, Options,
905 OptLevel),
907 initAsmInfo();
908 if (TT.isAMDGCN()) {
909 // Triple is missing a representation for non-empty, but unrecognized
910 // subarches. Only permit no subarch for any subtarget if it was really
911 // empty.
912 bool IsUnknownSubArch =
913 TT.getSubArch() == Triple::NoSubArch && TT.getArchName().size() != 6;
914 if (IsUnknownSubArch)
915 reportFatalUsageError("unknown subarch " + TT.getArchName());
916
917 if (TT.getSubArch() != Triple::NoSubArch) {
919 Triple::SubArchType GPUSubArch = AMDGPU::getSubArch(Kind);
920 if (Kind != AMDGPU::GK_NONE && GPUSubArch != TT.getSubArch() &&
921 TT.getSubArch() != AMDGPU::getMajorSubArch(GPUSubArch)) {
922 reportFatalUsageError("invalid cpu '" + CPU + "' for subarch " +
923 TT.getArchName());
924 }
925 }
926
927 if (getMCSubtargetInfo().checkFeatures("+wavefrontsize64"))
929 else if (getMCSubtargetInfo().checkFeatures("+wavefrontsize32"))
931 }
933}
934
938
940
942 Attribute GPUAttr = F.getFnAttribute("target-cpu");
943 return GPUAttr.isValid() ? GPUAttr.getValueAsString() : getTargetCPU();
944}
945
947 Attribute FSAttr = F.getFnAttribute("target-features");
948
949 return FSAttr.isValid() ? FSAttr.getValueAsString()
951}
952
955 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
957 DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
958 if (ST.shouldClusterStores())
959 DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
960 return DAG;
961}
962
963/// Predicate for Internalize pass.
964static bool mustPreserveGV(const GlobalValue &GV) {
965 if (const Function *F = dyn_cast<Function>(&GV))
966 return F->isDeclaration() || F->getName().starts_with("__asan_") ||
967 F->getName().starts_with("__sanitizer_") ||
968 AMDGPU::isEntryFunctionCC(F->getCallingConv());
969
971 return !GV.use_empty();
972}
973
978
981 if (Params.empty())
983 Params.consume_front("strategy=");
984 auto Result = StringSwitch<std::optional<ScanOptions>>(Params)
985 .Case("dpp", ScanOptions::DPP)
986 .Cases({"iterative", ""}, ScanOptions::Iterative)
987 .Case("none", ScanOptions::None)
988 .Default(std::nullopt);
989 if (Result)
990 return *Result;
991 return make_error<StringError>("invalid parameter", inconvertibleErrorCode());
992}
993
997 while (!Params.empty()) {
998 StringRef ParamName;
999 std::tie(ParamName, Params) = Params.split(';');
1000 if (ParamName == "closed-world") {
1001 Result.IsClosedWorld = true;
1002 } else {
1004 formatv("invalid AMDGPUAttributor pass parameter '{0}' ", ParamName)
1005 .str(),
1007 }
1008 }
1009 return Result;
1010}
1011
1013
1014#define GET_PASS_REGISTRY "AMDGPUPassRegistry.def"
1016
1017 PB.registerPipelineParsingCallback(
1018 [this](StringRef Name, CGSCCPassManager &PM,
1020 if (Name == "amdgpu-attributor-cgscc" && getTargetTriple().isAMDGCN()) {
1022 *static_cast<GCNTargetMachine *>(this)));
1023 return true;
1024 }
1025 return false;
1026 });
1027
1028 PB.registerScalarOptimizerLateEPCallback(
1029 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1030 if (Level == OptimizationLevel::O0)
1031 return;
1032
1034 });
1035
1036 PB.registerVectorizerEndEPCallback(
1037 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1038 if (Level == OptimizationLevel::O0)
1039 return;
1040
1042 });
1043
1044 PB.registerPipelineEarlySimplificationEPCallback(
1045 [this](ModulePassManager &PM, OptimizationLevel Level,
1047 if (!isLTOPreLink(Phase) && getTargetTriple().isAMDGCN()) {
1048 // When we are not using -fgpu-rdc, we can run accelerator code
1049 // selection relatively early, but still after linking to prevent
1050 // eager removal of potentially reachable symbols.
1051 if (EnableHipStdPar) {
1054 }
1055
1057 }
1058
1059 if (Level == OptimizationLevel::O0)
1060 return;
1061
1062 // We don't want to run internalization at per-module stage.
1065 PM.addPass(GlobalDCEPass());
1066 }
1067
1070 });
1071
1072 PB.registerPeepholeEPCallback(
1073 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1074 if (Level == OptimizationLevel::O0)
1075 return;
1076
1080
1083 });
1084
1085 PB.registerCGSCCOptimizerLateEPCallback(
1086 [this](CGSCCPassManager &PM, OptimizationLevel Level) {
1087 if (Level == OptimizationLevel::O0)
1088 return;
1089
1091
1092 // Add promote kernel arguments pass to the opt pipeline right before
1093 // infer address spaces which is needed to do actual address space
1094 // rewriting.
1097
1098 // Add infer address spaces pass to the opt pipeline after inlining
1099 // but before SROA to increase SROA opportunities.
1101
1102 // This should run after inlining to have any chance of doing
1103 // anything, and before other cleanup optimizations.
1105
1106 // Promote alloca to vector before SROA and loop unroll. If we
1107 // manage to eliminate allocas before unroll we may choose to unroll
1108 // less.
1110
1111 PM.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
1112 });
1113
1114 // FIXME: Why is AMDGPUAttributor not in CGSCC?
1115 PB.registerOptimizerLastEPCallback([this](ModulePassManager &MPM,
1116 OptimizationLevel Level,
1118 if (Level != OptimizationLevel::O0) {
1119 if (!isLTOPreLink(Phase)) {
1120 if (EnableAMDGPUAttributor && getTargetTriple().isAMDGCN()) {
1122 MPM.addPass(AMDGPUAttributorPass(*this, Opts, Phase));
1123 }
1124 }
1125 }
1126 });
1127
1128 PB.registerFullLinkTimeOptimizationLastEPCallback(
1129 [this](ModulePassManager &PM, OptimizationLevel Level) {
1130 // Clean up redundant memory round-trips that the full-LTO pipeline,
1131 // unlike the non-LTO/ThinLTO ones, otherwise leaves for codegen.
1132 if (Level != OptimizationLevel::O0) {
1134 EarlyCSEPass(/*UseMemorySSA=*/true)));
1135 }
1136
1137 // When we are using -fgpu-rdc, we can only run accelerator code
1138 // selection after linking to prevent, otherwise we end up removing
1139 // potentially reachable symbols that were exported as external in other
1140 // modules.
1141 if (EnableHipStdPar) {
1144 }
1145 // We want to support the -lto-partitions=N option as "best effort".
1146 // For that, we need to lower LDS earlier in the pipeline before the
1147 // module is partitioned for codegen.
1150 if (EnableSwLowerLDS)
1154 if (Level != OptimizationLevel::O0) {
1155 // We only want to run this with O2 or higher since inliner and SROA
1156 // don't run in O1.
1157 if (Level != OptimizationLevel::O1) {
1158 PM.addPass(
1160 }
1161 // Do we really need internalization in LTO?
1162 if (InternalizeSymbols) {
1164 PM.addPass(GlobalDCEPass());
1165 }
1166 if (EnableAMDGPUAttributor && getTargetTriple().isAMDGCN()) {
1169 Opt.IsClosedWorld = true;
1172 }
1173 }
1174 if (!NoKernelInfoEndLTO) {
1176 FPM.addPass(KernelInfoPrinter(this));
1177 PM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1178 }
1179 });
1180
1181 PB.registerRegClassFilterParsingCallback(
1182 [](StringRef FilterName) -> RegAllocFilterFunc {
1183 if (FilterName == "sgpr")
1184 return onlyAllocateSGPRs;
1185 if (FilterName == "vgpr")
1186 return onlyAllocateVGPRs;
1187 if (FilterName == "wwm")
1188 return onlyAllocateWWMRegs;
1189 return nullptr;
1190 });
1191}
1192
1194 unsigned DestAS) const {
1195 return AMDGPU::isFlatGlobalAddrSpace(SrcAS) &&
1197}
1198
1200 if (auto *Arg = dyn_cast<Argument>(V);
1201 Arg &&
1202 AMDGPU::isModuleEntryFunctionCC(Arg->getParent()->getCallingConv()) &&
1203 !Arg->hasByRefAttr())
1205
1206 const auto *LD = dyn_cast<LoadInst>(V);
1207 if (!LD) // TODO: Handle invariant load like constant.
1209
1210 // It must be a generic pointer loaded.
1211 assert(V->getType()->getPointerAddressSpace() == AMDGPUAS::FLAT_ADDRESS);
1212
1213 const auto *Ptr = LD->getPointerOperand();
1214 if (Ptr->getType()->getPointerAddressSpace() != AMDGPUAS::CONSTANT_ADDRESS)
1216 // For a generic pointer loaded from the constant memory, it could be assumed
1217 // as a global pointer since the constant memory is only populated on the
1218 // host side. As implied by the offload programming model, only global
1219 // pointers could be referenced on the host side.
1221}
1222
1223std::pair<const Value *, unsigned>
1225 if (auto *II = dyn_cast<IntrinsicInst>(V)) {
1226 switch (II->getIntrinsicID()) {
1227 case Intrinsic::amdgcn_is_shared:
1228 return std::pair(II->getArgOperand(0), AMDGPUAS::LOCAL_ADDRESS);
1229 case Intrinsic::amdgcn_is_private:
1230 return std::pair(II->getArgOperand(0), AMDGPUAS::PRIVATE_ADDRESS);
1231 default:
1232 break;
1233 }
1234 return std::pair(nullptr, -1);
1235 }
1236 // Check the global pointer predication based on
1237 // (!is_share(p) && !is_private(p)). Note that logic 'and' is commutative and
1238 // the order of 'is_shared' and 'is_private' is not significant.
1239 Value *Ptr;
1240 if (match(
1241 const_cast<Value *>(V),
1244 m_Deferred(Ptr))))))
1245 return std::pair(Ptr, AMDGPUAS::GLOBAL_ADDRESS);
1246
1247 return std::pair(nullptr, -1);
1248}
1249
1250unsigned
1265
1267 Module &M, unsigned NumParts,
1268 function_ref<void(std::unique_ptr<Module> MPart)> ModuleCallback) {
1269 // FIXME(?): Would be better to use an already existing Analysis/PassManager,
1270 // but all current users of this API don't have one ready and would need to
1271 // create one anyway. Let's hide the boilerplate for now to keep it simple.
1272
1277
1278 PassBuilder PB(this);
1279 PB.registerModuleAnalyses(MAM);
1280 PB.registerFunctionAnalyses(FAM);
1281 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
1282
1284 MPM.addPass(AMDGPUSplitModulePass(NumParts, ModuleCallback));
1285 MPM.run(M, MAM);
1286 return true;
1287}
1288
1289//===----------------------------------------------------------------------===//
1290// GCN Target Machine (SI+)
1291//===----------------------------------------------------------------------===//
1292
1294 StringRef CPU, StringRef FS,
1295 const TargetOptions &Options,
1296 std::optional<Reloc::Model> RM,
1297 std::optional<CodeModel::Model> CM,
1298 CodeGenOptLevel OL, bool JIT)
1299 : AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {
1301}
1302
1303enum class OOBFlagValue {
1304 Any = 0,
1307};
1308
1309/// Returns the OOB mode encoded by a module flag.
1310/// An absent flag defaults to Any.
1311static OOBFlagValue getOOBFlagValue(const Module &M, StringRef FlagName) {
1312 const auto *Flag =
1313 mdconst::dyn_extract_or_null<ConstantInt>(M.getModuleFlag(FlagName));
1314 if (!Flag)
1315 return OOBFlagValue::Any;
1316 return static_cast<OOBFlagValue>(Flag->getZExtValue());
1317}
1318
1319/// Returns the xnack/sramecc setting encoded by a module flag.
1320/// Module flag values: 0 = disabled, 1 = enabled.
1321/// An absent flag defaults to Any.
1324 StringRef FlagName) {
1326
1327 if (XnackSetting.getNumOccurrences() > 0 && FlagName == "amdgpu.xnack")
1328 return XnackSetting ? TargetIDSetting::On : TargetIDSetting::Off;
1329 if (SramEccSetting.getNumOccurrences() > 0 && FlagName == "amdgpu.sramecc")
1330 return SramEccSetting ? TargetIDSetting::On : TargetIDSetting::Off;
1331
1332 const auto *Flag =
1333 mdconst::dyn_extract_or_null<ConstantInt>(M.getModuleFlag(FlagName));
1334 if (!Flag)
1335 return TargetIDSetting::Any;
1336 return Flag->getZExtValue() == 0 ? TargetIDSetting::Off : TargetIDSetting::On;
1337}
1338
1339const TargetSubtargetInfo *
1341 StringRef GPU = getGPUName(F);
1343
1344 const Module &M = *F.getParent();
1347 bool BufRelaxed = BufOOB == OOBFlagValue::Relaxed;
1348 bool TBufRelaxed = TBufOOB == OOBFlagValue::Relaxed;
1349
1351 TargetIDSetting Xnack = getTargetIDSettingFromModuleFlag(M, "amdgpu.xnack");
1352 TargetIDSetting SramEcc =
1353 getTargetIDSettingFromModuleFlag(M, "amdgpu.sramecc");
1354
1355 SmallString<128> SubtargetKey(GPU);
1356 SubtargetKey.append(FS);
1357 if (BufRelaxed)
1358 SubtargetKey.append(",buf-oob=1");
1359 if (TBufRelaxed)
1360 SubtargetKey.append(",tbuf-oob=1");
1361 if (Xnack != TargetIDSetting::Any) {
1362 SubtargetKey.append(",xnack=");
1363 SubtargetKey.push_back(Xnack == TargetIDSetting::On ? '1' : '0');
1364 }
1365 if (SramEcc != TargetIDSetting::Any) {
1366 SubtargetKey.append(",sramecc=");
1367 SubtargetKey.push_back(Xnack == TargetIDSetting::On ? '1' : '0');
1368 }
1369
1370 auto &I = SubtargetMap[SubtargetKey];
1371 if (!I) {
1373 Triple::SubArchType GPUSubArch = AMDGPU::getSubArch(Kind);
1374
1375 // Enforce the subtarget is covered by the subarch. Tolerate no subarch for
1376 // legacy compatibility.
1377 const Triple &TT = M.getTargetTriple();
1378 if (GPUSubArch != TT.getSubArch() && Kind != AMDGPU::GK_NONE) {
1379 // Check if this is a generic subarch which has subtargets. Ignore
1380 // unknown subtargets with a known subarch, since for whatever reason
1381 // the convention is to just print a warning and ignore unrecognized
1382 // subtargets.
1383 bool IsLegacyEmptySubArch = TT.getSubArch() == Triple::NoSubArch;
1384 if (!IsLegacyEmptySubArch &&
1385 AMDGPU::getMajorSubArch(GPUSubArch) != TT.getSubArch()) {
1386 F.getContext().emitError("invalid subtarget '" + Twine(GPU) +
1387 "' for subarch " + TT.getArchName());
1388 }
1389 }
1390
1391 I = std::make_unique<GCNSubtarget>(TargetTriple, GPU, FS, *this, BufRelaxed,
1392 TBufRelaxed, Xnack, SramEcc);
1393 }
1394
1395 I->setScalarizeGlobalBehavior(ScalarizeGlobal);
1396
1397 return I.get();
1398}
1399
1402 return TargetTransformInfo(std::make_unique<GCNTTIImpl>(this, F));
1403}
1404
1407 raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
1408 const CGPassBuilderOption &Opts, MCContext &Ctx,
1410 AMDGPUCodeGenPassBuilder CGPB(*this, Opts, PIC);
1411 return CGPB.buildPipeline(MPM, MAM, Out, DwoOut, FileType, Ctx);
1412}
1413
1416 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
1417 if (ST.enableSIScheduler())
1419
1420 StringRef SchedStrategy = AMDGPU::getSchedStrategy(C->MF->getFunction());
1421
1422 if (SchedStrategy == "max-ilp")
1424
1425 if (SchedStrategy == "max-memory-clause")
1427
1428 if (SchedStrategy == "iterative-ilp")
1430
1431 if (SchedStrategy == "iterative-minreg")
1432 return createMinRegScheduler(C);
1433
1434 if (SchedStrategy == "iterative-maxocc")
1436
1437 if (SchedStrategy == "coexec") {
1438 diagnoseUnsupportedCoExecSchedulerSelection(C->MF->getFunction(), ST);
1440 }
1441
1443}
1444
1447 if (useNoopPostScheduler(C->MF->getFunction()))
1449
1450 ScheduleDAGMI *DAG =
1451 new GCNPostScheduleDAGMILive(C, std::make_unique<PostGenericScheduler>(C),
1452 /*RemoveKillFlags=*/true);
1453 const GCNSubtarget &ST = C->MF->getSubtarget<GCNSubtarget>();
1455 if (ST.shouldClusterStores())
1458 if ((EnableVOPD.getNumOccurrences() ||
1460 EnableVOPD)
1465 return DAG;
1466}
1467//===----------------------------------------------------------------------===//
1468// AMDGPU Legacy Pass Setup
1469//===----------------------------------------------------------------------===//
1470
1471std::unique_ptr<CSEConfigBase> llvm::AMDGPUPassConfig::getCSEConfig() const {
1472 return getStandardCSEConfigForOpt(TM->getOptLevel());
1473}
1474
1475namespace {
1476
1477class GCNPassConfig final : public AMDGPUPassConfig {
1478public:
1479 GCNPassConfig(TargetMachine &TM, PassManagerBase &PM)
1480 : AMDGPUPassConfig(TM, PM) {
1481 substitutePass(&PostRASchedulerID, &PostMachineSchedulerID);
1482 }
1483
1484 GCNTargetMachine &getGCNTargetMachine() const {
1485 return getTM<GCNTargetMachine>();
1486 }
1487
1488 bool addPreISel() override;
1489 void addMachineSSAOptimization() override;
1490 bool addILPOpts() override;
1491 bool addInstSelector() override;
1492 bool addIRTranslator() override;
1493 void addPreLegalizeMachineIR() override;
1494 bool addLegalizeMachineIR() override;
1495 void addPreRegBankSelect() override;
1496 bool addRegBankSelect() override;
1497 void addPreGlobalInstructionSelect() override;
1498 bool addGlobalInstructionSelect() override;
1499 void addPreRegAlloc() override;
1500 void addFastRegAlloc() override;
1501 void addOptimizedRegAlloc() override;
1502
1503 FunctionPass *createSGPRAllocPass(bool Optimized);
1504 FunctionPass *createVGPRAllocPass(bool Optimized);
1505 FunctionPass *createWWMRegAllocPass(bool Optimized);
1506 FunctionPass *createRegAllocPass(bool Optimized) override;
1507
1508 bool addRegAssignAndRewriteFast() override;
1509 bool addRegAssignAndRewriteOptimized() override;
1510
1511 bool addPreRewrite() override;
1512 void addPostRegAlloc() override;
1513 void addPreSched2() override;
1514 void addPreEmitPass() override;
1515 void addPostBBSections() override;
1516};
1517
1518} // end anonymous namespace
1519
1521 : TargetPassConfig(TM, PM) {
1522 // Exceptions and StackMaps are not supported, so these passes will never do
1523 // anything.
1526 // Garbage collection is not supported.
1529}
1530
1537
1542 // ReassociateGEPs exposes more opportunities for SLSR. See
1543 // the example in reassociate-geps-and-slsr.ll.
1545 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
1546 // EarlyCSE can reuse.
1548 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
1550 // NaryReassociate on GEPs creates redundant common expressions, so run
1551 // EarlyCSE after it.
1553}
1554
1557
1558 if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN())
1560
1561 // There is no reason to run these.
1565
1566 if (TM.getTargetTriple().isAMDGCN())
1568
1569 if (LowerCtorDtor)
1571
1572 if (TM.getTargetTriple().isAMDGCN() &&
1575
1578
1579 // This can be disabled by passing ::Disable here or on the command line
1580 // with --expand-variadics-override=disable.
1582
1583 // Function calls are not supported, so make sure we inline everything.
1586
1587 // Handle uses of OpenCL image2d_t, image3d_t and sampler_t arguments.
1588 if (TM.getTargetTriple().getArch() == Triple::r600)
1590
1591 // Make enqueued block runtime handles externally visible.
1593
1594 // Lower special LDS accesses.
1597
1598 // Lower LDS accesses to global memory pass if address sanitizer is enabled.
1599 if (EnableSwLowerLDS)
1601
1602 // Runs before PromoteAlloca so the latter can account for function uses
1605 }
1606
1607 // Run atomic optimizer before Atomic Expand
1608 if ((TM.getTargetTriple().isAMDGCN()) &&
1609 (TM.getOptLevel() >= CodeGenOptLevel::Less) &&
1612 }
1613
1615
1616 if (TM.getOptLevel() > CodeGenOptLevel::None) {
1618
1621
1625 AAResults &AAR) {
1626 if (auto *WrapperPass = P.getAnalysisIfAvailable<AMDGPUAAWrapperPass>())
1627 AAR.addAAResult(WrapperPass->getResult());
1628 }));
1629 }
1630
1631 if (TM.getTargetTriple().isAMDGCN()) {
1632 // TODO: May want to move later or split into an early and late one.
1634 }
1635
1636 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
1637 // have expanded.
1638 if (TM.getOptLevel() > CodeGenOptLevel::Less)
1640 }
1641
1643
1644 // EarlyCSE is not always strong enough to clean up what LSR produces. For
1645 // example, GVN can combine
1646 //
1647 // %0 = add %a, %b
1648 // %1 = add %b, %a
1649 //
1650 // and
1651 //
1652 // %0 = shl nsw %a, 2
1653 // %1 = shl %a, 2
1654 //
1655 // but EarlyCSE can do neither of them.
1658}
1659
1661 if (TM->getTargetTriple().isAMDGCN() &&
1662 TM->getOptLevel() > CodeGenOptLevel::None)
1664
1665 if (TM->getTargetTriple().isAMDGCN() && EnableLowerKernelArguments)
1667
1669
1672
1673 if (TM->getTargetTriple().isAMDGCN()) {
1674 // This lowering has been placed after codegenprepare to take advantage of
1675 // address mode matching (which is why it isn't put with the LDS lowerings).
1676 // It could be placed anywhere before uniformity annotations (an analysis
1677 // that it changes by splitting up fat pointers into their components)
1678 // but has been put before switch lowering and CFG flattening so that those
1679 // passes can run on the more optimized control flow this pass creates in
1680 // many cases.
1683 }
1684
1685 // LowerSwitch pass may introduce unreachable blocks that can
1686 // cause unexpected behavior for subsequent passes. Placing it
1687 // here seems better that these blocks would get cleaned up by
1688 // UnreachableBlockElim inserted next in the pass flow.
1690}
1691
1693 if (TM->getOptLevel() > CodeGenOptLevel::None)
1695 return false;
1696}
1697
1702
1704 // Do nothing. GC is not supported.
1705 return false;
1706}
1707
1708//===----------------------------------------------------------------------===//
1709// GCN Legacy Pass Setup
1710//===----------------------------------------------------------------------===//
1711
1712bool GCNPassConfig::addPreISel() {
1714
1715 if (TM->getOptLevel() > CodeGenOptLevel::None) {
1716 addPass(createSinkingPass());
1718 }
1719
1720 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
1721 // regions formed by them.
1723 addPass(createFixIrreduciblePass());
1724 addPass(createUnifyLoopExitsPass());
1725 addPass(createStructurizeCFGPass(false)); // true -> SkipUniformRegions
1726
1729 // TODO: Move this right after structurizeCFG to avoid extra divergence
1730 // analysis. This depends on stopping SIAnnotateControlFlow from making
1731 // control flow modifications.
1733
1734 // SDAG requires LCSSA, GlobalISel does not. Disable LCSSA for -global-isel
1735 // without any of the fallback options.
1738 !isGlobalISelAbortEnabled())
1739 addPass(createLCSSAPass());
1740
1741 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1743
1744 return false;
1745}
1746
1747void GCNPassConfig::addMachineSSAOptimization() {
1749
1750 // We want to fold operands after PeepholeOptimizer has run (or as part of
1751 // it), because it will eliminate extra copies making it easier to fold the
1752 // real source operand. We want to eliminate dead instructions after, so that
1753 // we see fewer uses of the copies. We then need to clean up the dead
1754 // instructions leftover after the operands are folded as well.
1755 //
1756 // XXX - Can we get away without running DeadMachineInstructionElim again?
1757 addPass(&SIFoldOperandsLegacyID);
1758 if (EnableDPPCombine)
1759 addPass(&GCNDPPCombineLegacyID);
1761 if (isPassEnabled(EnableSDWAPeephole)) {
1762 addPass(&SIPeepholeSDWALegacyID);
1763 addPass(&EarlyMachineLICMID);
1764 addPass(&MachineCSELegacyID);
1765 addPass(&SIFoldOperandsLegacyID);
1766 }
1769}
1770
1771bool GCNPassConfig::addILPOpts() {
1773 addPass(&EarlyIfConverterLegacyID);
1774
1776 return false;
1777}
1778
1779bool GCNPassConfig::addInstSelector() {
1781 addPass(&SIFixSGPRCopiesLegacyID);
1783 return false;
1784}
1785
1786bool GCNPassConfig::addIRTranslator() {
1787 addPass(new IRTranslatorLegacy(getOptLevel()));
1788 return false;
1789}
1790
1791void GCNPassConfig::addPreLegalizeMachineIR() {
1792 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1793 addPass(createAMDGPUPreLegalizeCombiner(IsOptNone));
1794 addPass(new LocalizerLegacy());
1795}
1796
1797bool GCNPassConfig::addLegalizeMachineIR() {
1798 addPass(new LegalizerLegacy());
1799 return false;
1800}
1801
1802void GCNPassConfig::addPreRegBankSelect() {
1803 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1804 addPass(createAMDGPUPostLegalizeCombiner(IsOptNone));
1806}
1807
1808bool GCNPassConfig::addRegBankSelect() {
1811 return false;
1812}
1813
1814void GCNPassConfig::addPreGlobalInstructionSelect() {
1815 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
1816 addPass(createAMDGPURegBankCombiner(IsOptNone));
1817}
1818
1819bool GCNPassConfig::addGlobalInstructionSelect() {
1820 addPass(new InstructionSelectLegacy(getOptLevel()));
1821 return false;
1822}
1823
1824void GCNPassConfig::addFastRegAlloc() {
1825 // FIXME: We have to disable the verifier here because of PHIElimination +
1826 // TwoAddressInstructions disabling it.
1827
1828 // This must be run immediately after phi elimination and before
1829 // TwoAddressInstructions, otherwise the processing of the tied operand of
1830 // SI_ELSE will introduce a copy of the tied operand source after the else.
1832
1834
1836}
1837
1838void GCNPassConfig::addPreRegAlloc() {
1839 if (getOptLevel() != CodeGenOptLevel::None)
1841 if (getOptLevel() >= CodeGenOptLevel::Default && EnableMachinePipeliner)
1842 addPass(&MachinePipelinerID);
1843}
1844
1845void GCNPassConfig::addOptimizedRegAlloc() {
1846 if (EnableDCEInRA)
1848
1849 // FIXME: when an instruction has a Killed operand, and the instruction is
1850 // inside a bundle, seems only the BUNDLE instruction appears as the Kills of
1851 // the register in LiveVariables, this would trigger a failure in verifier,
1852 // we should fix it and enable the verifier.
1853 if (OptVGPRLiveRange)
1855
1856 // This must be run immediately after phi elimination and before
1857 // TwoAddressInstructions, otherwise the processing of the tied operand of
1858 // SI_ELSE will introduce a copy of the tied operand source after the else.
1860
1863
1864 if (isPassEnabled(EnablePreRAOptimizations))
1866
1867 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
1868 // instructions that cause scheduling barriers.
1870
1871 if (OptExecMaskPreRA)
1873
1874 // This is not an essential optimization and it has a noticeable impact on
1875 // compilation time, so we only enable it from O2.
1876 if (TM->getOptLevel() > CodeGenOptLevel::Less)
1878
1880}
1881
1882bool GCNPassConfig::addPreRewrite() {
1884 addPass(&GCNNSAReassignID);
1885
1887 return true;
1888}
1889
1890FunctionPass *GCNPassConfig::createSGPRAllocPass(bool Optimized) {
1891 // Initialize the global default.
1892 llvm::call_once(InitializeDefaultSGPRRegisterAllocatorFlag,
1893 initializeDefaultSGPRRegisterAllocatorOnce);
1894
1895 RegisterRegAlloc::FunctionPassCtor Ctor = SGPRRegisterRegAlloc::getDefault();
1896 if (Ctor != useDefaultRegisterAllocator)
1897 return Ctor();
1898
1899 if (Optimized)
1900 return createGreedyRegisterAllocator(onlyAllocateSGPRs);
1901
1902 return createFastRegisterAllocator(onlyAllocateSGPRs, false);
1903}
1904
1905FunctionPass *GCNPassConfig::createVGPRAllocPass(bool Optimized) {
1906 // Initialize the global default.
1907 llvm::call_once(InitializeDefaultVGPRRegisterAllocatorFlag,
1908 initializeDefaultVGPRRegisterAllocatorOnce);
1909
1910 RegisterRegAlloc::FunctionPassCtor Ctor = VGPRRegisterRegAlloc::getDefault();
1911 if (Ctor != useDefaultRegisterAllocator)
1912 return Ctor();
1913
1914 if (Optimized)
1915 return createGreedyVGPRRegisterAllocator();
1916
1917 return createFastVGPRRegisterAllocator();
1918}
1919
1920FunctionPass *GCNPassConfig::createWWMRegAllocPass(bool Optimized) {
1921 // Initialize the global default.
1922 llvm::call_once(InitializeDefaultWWMRegisterAllocatorFlag,
1923 initializeDefaultWWMRegisterAllocatorOnce);
1924
1925 RegisterRegAlloc::FunctionPassCtor Ctor = WWMRegisterRegAlloc::getDefault();
1926 if (Ctor != useDefaultRegisterAllocator)
1927 return Ctor();
1928
1929 if (Optimized)
1930 return createGreedyWWMRegisterAllocator();
1931
1932 return createFastWWMRegisterAllocator();
1933}
1934
1935FunctionPass *GCNPassConfig::createRegAllocPass(bool Optimized) {
1936 llvm_unreachable("should not be used");
1937}
1938
1940 "-regalloc not supported with amdgcn. Use -sgpr-regalloc, -wwm-regalloc, "
1941 "and -vgpr-regalloc";
1942
1943bool GCNPassConfig::addRegAssignAndRewriteFast() {
1944 if (!usingDefaultRegAlloc())
1946
1947 addPass(&GCNPreRALongBranchRegID);
1948
1949 addPass(createSGPRAllocPass(false));
1950
1951 // Equivalent of PEI for SGPRs.
1952 addPass(&SILowerSGPRSpillsLegacyID);
1953
1954 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1956
1957 // For allocating other wwm register operands.
1958 addPass(createWWMRegAllocPass(false));
1959
1960 addPass(&SILowerWWMCopiesLegacyID);
1962
1963 // For allocating per-thread VGPRs.
1964 addPass(createVGPRAllocPass(false));
1965
1966 return true;
1967}
1968
1969bool GCNPassConfig::addRegAssignAndRewriteOptimized() {
1970 if (!usingDefaultRegAlloc())
1972
1973 addPass(&GCNPreRALongBranchRegID);
1974
1975 addPass(createSGPRAllocPass(true));
1976
1977 // Commit allocated register changes. This is mostly necessary because too
1978 // many things rely on the use lists of the physical registers, such as the
1979 // verifier. This is only necessary with allocators which use LiveIntervals,
1980 // since FastRegAlloc does the replacements itself.
1981 addPass(createVirtRegRewriter(false));
1982
1983 // At this point, the sgpr-regalloc has been done and it is good to have the
1984 // stack slot coloring to try to optimize the SGPR spill stack indices before
1985 // attempting the custom SGPR spill lowering.
1986 addPass(&StackSlotColoringID);
1987
1988 // Equivalent of PEI for SGPRs.
1989 addPass(&SILowerSGPRSpillsLegacyID);
1990
1991 // To Allocate wwm registers used in whole quad mode operations (for shaders).
1993
1994 // For allocating other whole wave mode registers.
1995 addPass(createWWMRegAllocPass(true));
1996 addPass(&SILowerWWMCopiesLegacyID);
1997 addPass(createVirtRegRewriter(false));
1999
2000 // For allocating per-thread VGPRs.
2001 addPass(createVGPRAllocPass(true));
2002
2003 addPreRewrite();
2004 addPass(&VirtRegRewriterID);
2005
2007
2008 return true;
2009}
2010
2011void GCNPassConfig::addPostRegAlloc() {
2012 addPass(&SIFixVGPRCopiesID);
2013 if (getOptLevel() > CodeGenOptLevel::None)
2016}
2017
2018void GCNPassConfig::addPreSched2() {
2019 if (TM->getOptLevel() > CodeGenOptLevel::None)
2021 addPass(&SIPostRABundlerLegacyID);
2022}
2023
2024void GCNPassConfig::addPreEmitPass() {
2025 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less))
2026 addPass(&GCNCreateVOPDID);
2027 addPass(createSIMemoryLegalizerPass());
2028 addPass(createSIInsertWaitcntsPass());
2029
2030 addPass(createSIModeRegisterPass());
2031
2032 if (getOptLevel() > CodeGenOptLevel::None)
2033 addPass(&SIInsertHardClausesID);
2034
2036 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
2038 if (getOptLevel() > CodeGenOptLevel::None)
2039 addPass(&SIPreEmitPeepholeID);
2040 // The hazard recognizer that runs as part of the post-ra scheduler does not
2041 // guarantee to be able handle all hazards correctly. This is because if there
2042 // are multiple scheduling regions in a basic block, the regions are scheduled
2043 // bottom up, so when we begin to schedule a region we don't know what
2044 // instructions were emitted directly before it.
2045 //
2046 // Here we add a stand-alone hazard recognizer pass which can handle all
2047 // cases.
2048 addPass(&PostRAHazardRecognizerID);
2049
2051
2053
2054 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less))
2055 addPass(&AMDGPUInsertDelayAluID);
2056
2057 addPass(&BranchRelaxationPassID);
2058}
2059
2060void GCNPassConfig::addPostBBSections() {
2061 // We run this later to avoid passes like livedebugvalues and BBSections
2062 // having to deal with the apparent multi-entry functions we may generate.
2064}
2065
2067 return new GCNPassConfig(*this, PM);
2068}
2069
2075
2082
2086
2093
2096 SMDiagnostic &Error, SMRange &SourceRange) const {
2097 const yaml::SIMachineFunctionInfo &YamlMFI =
2098 static_cast<const yaml::SIMachineFunctionInfo &>(MFI_);
2099 MachineFunction &MF = PFS.MF;
2101 const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
2102
2103 if (MFI->initializeBaseYamlFields(YamlMFI, MF, PFS, Error, SourceRange))
2104 return true;
2105
2106 if (MFI->Occupancy == 0) {
2107 // Fixup the subtarget dependent default value.
2108 MFI->Occupancy = ST.getOccupancyWithWorkGroupSizes(MF).second;
2109 }
2110
2111 auto parseRegister = [&](const yaml::StringValue &RegName, Register &RegVal) {
2112 Register TempReg;
2113 if (parseNamedRegisterReference(PFS, TempReg, RegName.Value, Error)) {
2114 SourceRange = RegName.SourceRange;
2115 return true;
2116 }
2117 RegVal = TempReg;
2118
2119 return false;
2120 };
2121
2122 auto parseOptionalRegister = [&](const yaml::StringValue &RegName,
2123 Register &RegVal) {
2124 return !RegName.Value.empty() && parseRegister(RegName, RegVal);
2125 };
2126
2127 if (parseOptionalRegister(YamlMFI.VGPRForAGPRCopy, MFI->VGPRForAGPRCopy))
2128 return true;
2129
2130 if (parseOptionalRegister(YamlMFI.SGPRForEXECCopy, MFI->SGPRForEXECCopy))
2131 return true;
2132
2133 if (parseOptionalRegister(YamlMFI.LongBranchReservedReg,
2134 MFI->LongBranchReservedReg))
2135 return true;
2136
2137 auto diagnoseRegisterClass = [&](const yaml::StringValue &RegName) {
2138 // Create a diagnostic for a the register string literal.
2139 const MemoryBuffer &Buffer =
2140 *PFS.SM->getMemoryBuffer(PFS.SM->getMainFileID());
2141 Error = SMDiagnostic(*PFS.SM, SMLoc(), Buffer.getBufferIdentifier(), 1,
2142 RegName.Value.size(), SourceMgr::DK_Error,
2143 "incorrect register class for field", RegName.Value,
2144 {}, {});
2145 SourceRange = RegName.SourceRange;
2146 return true;
2147 };
2148
2149 if (parseRegister(YamlMFI.ScratchRSrcReg, MFI->ScratchRSrcReg) ||
2150 parseRegister(YamlMFI.FrameOffsetReg, MFI->FrameOffsetReg) ||
2151 parseRegister(YamlMFI.StackPtrOffsetReg, MFI->StackPtrOffsetReg))
2152 return true;
2153
2154 if (MFI->ScratchRSrcReg != AMDGPU::PRIVATE_RSRC_REG &&
2155 !AMDGPU::SGPR_128RegClass.contains(MFI->ScratchRSrcReg)) {
2156 return diagnoseRegisterClass(YamlMFI.ScratchRSrcReg);
2157 }
2158
2159 if (MFI->FrameOffsetReg != AMDGPU::FP_REG &&
2160 !AMDGPU::SGPR_32RegClass.contains(MFI->FrameOffsetReg)) {
2161 return diagnoseRegisterClass(YamlMFI.FrameOffsetReg);
2162 }
2163
2164 if (MFI->StackPtrOffsetReg != AMDGPU::SP_REG &&
2165 !AMDGPU::SGPR_32RegClass.contains(MFI->StackPtrOffsetReg)) {
2166 return diagnoseRegisterClass(YamlMFI.StackPtrOffsetReg);
2167 }
2168
2169 for (const auto &YamlReg : YamlMFI.WWMReservedRegs) {
2170 Register ParsedReg;
2171 if (parseRegister(YamlReg, ParsedReg))
2172 return true;
2173
2174 MFI->reserveWWMRegister(ParsedReg);
2175 }
2176
2177 for (const auto &[_, Info] : PFS.VRegInfosNamed) {
2178 MFI->setFlag(Info->VReg, Info->Flags);
2179 }
2180 for (const auto &[_, Info] : PFS.VRegInfos) {
2181 MFI->setFlag(Info->VReg, Info->Flags);
2182 }
2183
2184 for (const auto &YamlRegStr : YamlMFI.SpillPhysVGPRS) {
2185 Register ParsedReg;
2186 if (parseRegister(YamlRegStr, ParsedReg))
2187 return true;
2188 MFI->SpillPhysVGPRs.push_back(ParsedReg);
2189 }
2190
2191 auto parseAndCheckArgument = [&](const std::optional<yaml::SIArgument> &A,
2192 const TargetRegisterClass &RC,
2193 ArgDescriptor &Arg, unsigned UserSGPRs,
2194 unsigned SystemSGPRs) {
2195 // Skip parsing if it's not present.
2196 if (!A)
2197 return false;
2198
2199 if (A->IsRegister) {
2200 Register Reg;
2201 if (parseNamedRegisterReference(PFS, Reg, A->RegisterName.Value, Error)) {
2202 SourceRange = A->RegisterName.SourceRange;
2203 return true;
2204 }
2205 if (!RC.contains(Reg))
2206 return diagnoseRegisterClass(A->RegisterName);
2208 } else
2209 Arg = ArgDescriptor::createStack(A->StackOffset);
2210 // Check and apply the optional mask.
2211 if (A->Mask)
2212 Arg = ArgDescriptor::createArg(Arg, *A->Mask);
2213
2214 MFI->NumUserSGPRs += UserSGPRs;
2215 MFI->NumSystemSGPRs += SystemSGPRs;
2216 return false;
2217 };
2218
2219 if (YamlMFI.ArgInfo &&
2220 (parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentBuffer,
2221 AMDGPU::SGPR_128RegClass,
2222 MFI->ArgInfo.PrivateSegmentBuffer, 4, 0) ||
2223 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchPtr,
2224 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchPtr,
2225 2, 0) ||
2226 parseAndCheckArgument(YamlMFI.ArgInfo->QueuePtr, AMDGPU::SReg_64RegClass,
2227 MFI->ArgInfo.QueuePtr, 2, 0) ||
2228 parseAndCheckArgument(YamlMFI.ArgInfo->KernargSegmentPtr,
2229 AMDGPU::SReg_64RegClass,
2230 MFI->ArgInfo.KernargSegmentPtr, 2, 0) ||
2231 parseAndCheckArgument(YamlMFI.ArgInfo->DispatchID,
2232 AMDGPU::SReg_64RegClass, MFI->ArgInfo.DispatchID,
2233 2, 0) ||
2234 parseAndCheckArgument(YamlMFI.ArgInfo->FlatScratchInit,
2235 AMDGPU::SReg_64RegClass,
2236 MFI->ArgInfo.FlatScratchInit, 2, 0) ||
2237 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentSize,
2238 AMDGPU::SGPR_32RegClass,
2239 MFI->ArgInfo.PrivateSegmentSize, 1, 0) ||
2240 parseAndCheckArgument(YamlMFI.ArgInfo->LDSKernelId,
2241 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.LDSKernelId,
2242 1, 0) ||
2243 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDX,
2244 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDX,
2245 0, 1) ||
2246 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDY,
2247 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDY,
2248 0, 1) ||
2249 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupIDZ,
2250 AMDGPU::SGPR_32RegClass, MFI->ArgInfo.WorkGroupIDZ,
2251 0, 1) ||
2252 parseAndCheckArgument(YamlMFI.ArgInfo->WorkGroupInfo,
2253 AMDGPU::SGPR_32RegClass,
2254 MFI->ArgInfo.WorkGroupInfo, 0, 1) ||
2255 parseAndCheckArgument(YamlMFI.ArgInfo->PrivateSegmentWaveByteOffset,
2256 AMDGPU::SGPR_32RegClass,
2257 MFI->ArgInfo.PrivateSegmentWaveByteOffset, 0, 1) ||
2258 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitArgPtr,
2259 AMDGPU::SReg_64RegClass,
2260 MFI->ArgInfo.ImplicitArgPtr, 0, 0) ||
2261 parseAndCheckArgument(YamlMFI.ArgInfo->ImplicitBufferPtr,
2262 AMDGPU::SReg_64RegClass,
2263 MFI->ArgInfo.ImplicitBufferPtr, 2, 0) ||
2264 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDX,
2265 AMDGPU::VGPR_32RegClass, MFI->ArgInfo.WorkItemIDX,
2266 0, 0) ||
2267 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDY,
2268 AMDGPU::VGPR_32RegClass, MFI->ArgInfo.WorkItemIDY,
2269 0, 0) ||
2270 parseAndCheckArgument(YamlMFI.ArgInfo->WorkItemIDZ,
2271 AMDGPU::VGPR_32RegClass, MFI->ArgInfo.WorkItemIDZ,
2272 0, 0)))
2273 return true;
2274
2275 // Parse FirstKernArgPreloadReg separately, since it's a Register,
2276 // not ArgDescriptor.
2277 if (YamlMFI.ArgInfo && YamlMFI.ArgInfo->FirstKernArgPreloadReg) {
2278 const yaml::SIArgument &A = *YamlMFI.ArgInfo->FirstKernArgPreloadReg;
2279
2280 if (!A.IsRegister) {
2281 // For stack arguments, we don't have RegisterName.SourceRange,
2282 // but we should have some location info from the YAML parser
2283 const MemoryBuffer &Buffer =
2284 *PFS.SM->getMemoryBuffer(PFS.SM->getMainFileID());
2285 // Create a minimal valid source range
2287 SMRange Range(Loc, Loc);
2288
2290 *PFS.SM, Loc, Buffer.getBufferIdentifier(), 1, 0, SourceMgr::DK_Error,
2291 "firstKernArgPreloadReg must be a register, not a stack location", "",
2292 {}, {});
2293
2294 SourceRange = Range;
2295 return true;
2296 }
2297
2298 Register Reg;
2299 if (parseNamedRegisterReference(PFS, Reg, A.RegisterName.Value, Error)) {
2300 SourceRange = A.RegisterName.SourceRange;
2301 return true;
2302 }
2303
2304 if (!AMDGPU::SGPR_32RegClass.contains(Reg))
2305 return diagnoseRegisterClass(A.RegisterName);
2306
2307 MFI->ArgInfo.FirstKernArgPreloadReg = Reg;
2308 MFI->NumUserSGPRs += YamlMFI.NumKernargPreloadSGPRs;
2309 }
2310
2311 if (ST.hasFeature(AMDGPU::FeatureDX10ClampAndIEEEMode)) {
2312 MFI->Mode.IEEE = YamlMFI.Mode.IEEE;
2313 MFI->Mode.DX10Clamp = YamlMFI.Mode.DX10Clamp;
2314 }
2315
2316 // FIXME: Move proper support for denormal-fp-math into base MachineFunction
2317 MFI->Mode.FP32Denormals.Input = YamlMFI.Mode.FP32InputDenormals
2320 MFI->Mode.FP32Denormals.Output = YamlMFI.Mode.FP32OutputDenormals
2323
2330
2331 if (YamlMFI.HasInitWholeWave)
2332 MFI->setInitWholeWave();
2333
2334 return false;
2335}
2336
2337//===----------------------------------------------------------------------===//
2338// AMDGPU CodeGen Pass Builder interface.
2339//===----------------------------------------------------------------------===//
2340
2341AMDGPUCodeGenPassBuilder::AMDGPUCodeGenPassBuilder(
2342 GCNTargetMachine &TM, const CGPassBuilderOption &Opts,
2344 : CodeGenPassBuilder(TM, Opts, PIC) {
2345 Opt.MISchedPostRA = true;
2346 Opt.RequiresCodeGenSCCOrder = true;
2347 // Exceptions and StackMaps are not supported, so these passes will never do
2348 // anything.
2349 // Garbage collection is not supported.
2350 disablePass<StackMapLivenessPass, FuncletLayoutPass, PatchableFunctionPass,
2352}
2353
2354void AMDGPUCodeGenPassBuilder::addIRPasses(PassManagerWrapper &PMW) {
2355 if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN()) {
2356 flushFPMsToMPM(PMW);
2357 addModulePass(AMDGPURemoveIncompatibleFunctionsPass(TM), PMW);
2358 }
2359
2360 flushFPMsToMPM(PMW);
2361
2362 if (TM.getTargetTriple().isAMDGCN())
2363 addModulePass(AMDGPUPrintfRuntimeBindingPass(), PMW);
2364
2365 if (LowerCtorDtor)
2366 addModulePass(AMDGPUCtorDtorLoweringPass(), PMW);
2367
2368 if (isPassEnabled(EnableImageIntrinsicOptimizer))
2369 addFunctionPass(AMDGPUImageIntrinsicOptimizerPass(TM), PMW);
2370
2372 addFunctionPass(AMDGPUUniformIntrinsicCombinePass(), PMW);
2373 // This can be disabled by passing ::Disable here or on the command line
2374 // with --expand-variadics-override=disable.
2375 flushFPMsToMPM(PMW);
2377
2378 addModulePass(AMDGPUAlwaysInlinePass(), PMW);
2379 addModulePass(AlwaysInlinerPass(), PMW);
2380
2381 addModulePass(AMDGPUExportKernelRuntimeHandlesPass(), PMW);
2382
2384 addModulePass(AMDGPULowerExecSyncPass(), PMW);
2385
2386 if (EnableSwLowerLDS)
2387 addModulePass(AMDGPUSwLowerLDSPass(), PMW);
2388
2389 // Runs before PromoteAlloca so the latter can account for function uses
2391 addModulePass(AMDGPULowerModuleLDSPass(getTM()), PMW);
2392
2393 // Run atomic optimizer before Atomic Expand
2394 if (TM.getOptLevel() >= CodeGenOptLevel::Less &&
2396 addFunctionPass(
2398
2399 addFunctionPass(AtomicExpandPass(TM), PMW);
2400
2401 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2402 addFunctionPass(AMDGPUPromoteAllocaPass(TM), PMW);
2403 if (isPassEnabled(EnableScalarIRPasses))
2404 addStraightLineScalarOptimizationPasses(PMW);
2405
2406 // TODO: Handle EnableAMDGPUAliasAnalysis
2407
2408 // TODO: May want to move later or split into an early and late one.
2409 addFunctionPass(AMDGPUCodeGenPreparePass(TM), PMW);
2410
2411 // Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
2412 // have expanded.
2413 if (TM.getOptLevel() > CodeGenOptLevel::Less) {
2415 /*UseMemorySSA=*/true),
2416 PMW);
2417 }
2418 }
2419
2420 Base::addIRPasses(PMW);
2421
2422 // EarlyCSE is not always strong enough to clean up what LSR produces. For
2423 // example, GVN can combine
2424 //
2425 // %0 = add %a, %b
2426 // %1 = add %b, %a
2427 //
2428 // and
2429 //
2430 // %0 = shl nsw %a, 2
2431 // %1 = shl %a, 2
2432 //
2433 // but EarlyCSE can do neither of them.
2434 if (isPassEnabled(EnableScalarIRPasses))
2435 addEarlyCSEOrGVNPass(PMW);
2436}
2437
2438void AMDGPUCodeGenPassBuilder::addCodeGenPrepare(PassManagerWrapper &PMW) {
2439 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2440 flushFPMsToMPM(PMW);
2441 addModulePass(AMDGPUPreloadKernelArgumentsPass(TM), PMW);
2442 }
2443
2445 addFunctionPass(AMDGPULowerKernelArgumentsPass(TM), PMW);
2446
2447 Base::addCodeGenPrepare(PMW);
2448
2449 if (isPassEnabled(EnableLoadStoreVectorizer))
2450 addFunctionPass(LoadStoreVectorizerPass(), PMW);
2451
2452 // This lowering has been placed after codegenprepare to take advantage of
2453 // address mode matching (which is why it isn't put with the LDS lowerings).
2454 // It could be placed anywhere before uniformity annotations (an analysis
2455 // that it changes by splitting up fat pointers into their components)
2456 // but has been put before switch lowering and CFG flattening so that those
2457 // passes can run on the more optimized control flow this pass creates in
2458 // many cases.
2459 flushFPMsToMPM(PMW);
2460 addModulePass(AMDGPULowerBufferFatPointersPass(TM), PMW);
2461 flushFPMsToMPM(PMW);
2462 requireCGSCCOrder(PMW);
2463
2464 addModulePass(AMDGPULowerIntrinsicsPass(getTM()), PMW);
2465
2466 // LowerSwitch pass may introduce unreachable blocks that can cause unexpected
2467 // behavior for subsequent passes. Placing it here seems better that these
2468 // blocks would get cleaned up by UnreachableBlockElim inserted next in the
2469 // pass flow.
2470 addFunctionPass(LowerSwitchPass(), PMW);
2471}
2472
2473void AMDGPUCodeGenPassBuilder::addPreISel(PassManagerWrapper &PMW) {
2474
2475 if (TM.getOptLevel() > CodeGenOptLevel::None) {
2476 addFunctionPass(FlattenCFGPass(), PMW);
2477 addFunctionPass(SinkingPass(), PMW);
2478 addFunctionPass(AMDGPULateCodeGenPreparePass(getTM()), PMW);
2479 }
2480
2481 // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
2482 // regions formed by them.
2483
2484 addFunctionPass(AMDGPUUnifyDivergentExitNodesPass(), PMW);
2485 addFunctionPass(FixIrreduciblePass(), PMW);
2486 addFunctionPass(UnifyLoopExitsPass(), PMW);
2487 addFunctionPass(StructurizeCFGPass(/*SkipUniformRegions=*/false), PMW);
2488
2489 addFunctionPass(AMDGPUAnnotateUniformValuesPass(), PMW);
2490
2491 addFunctionPass(SIAnnotateControlFlowPass(getTM()), PMW);
2492
2493 // TODO: Move this right after structurizeCFG to avoid extra divergence
2494 // analysis. This depends on stopping SIAnnotateControlFlow from making
2495 // control flow modifications.
2496 addFunctionPass(AMDGPURewriteUndefForPHIPass(), PMW);
2497
2500 !isGlobalISelAbortEnabled())
2501 addFunctionPass(LCSSAPass(), PMW);
2502
2503 if (TM.getOptLevel() > CodeGenOptLevel::Less) {
2504 flushFPMsToMPM(PMW);
2505 addModulePass(AMDGPUPerfHintAnalysisPass(getTM()), PMW);
2506 }
2507}
2508
2509void AMDGPUCodeGenPassBuilder::addILPOpts(PassManagerWrapper &PMW) {
2511 addMachineFunctionPass(EarlyIfConverterPass(), PMW);
2512
2513 Base::addILPOpts(PMW);
2514}
2515
2516void AMDGPUCodeGenPassBuilder::addAsmPrinterBegin(PassManagerWrapper &PMW) {
2517 addModulePass(AMDGPUAsmPrinterBeginPass(), PMW,
2518 /*Force=*/true);
2519}
2520
2521void AMDGPUCodeGenPassBuilder::addAsmPrinter(PassManagerWrapper &PMW) {
2522 addMachineFunctionPass(AMDGPUAsmPrinterPass(), PMW);
2523}
2524
2525void AMDGPUCodeGenPassBuilder::addAsmPrinterEnd(PassManagerWrapper &PMW) {
2526 addModulePass(AMDGPUAsmPrinterEndPass(), PMW);
2527}
2528
2529Error AMDGPUCodeGenPassBuilder::addInstSelector(PassManagerWrapper &PMW) {
2530 addMachineFunctionPass(AMDGPUISelDAGToDAGPass(TM), PMW);
2531 addMachineFunctionPass(SIFixSGPRCopiesPass(), PMW);
2532 addMachineFunctionPass(SILowerI1CopiesPass(), PMW);
2533 return Error::success();
2534}
2535
2536void AMDGPUCodeGenPassBuilder::addPreRewrite(PassManagerWrapper &PMW) {
2537 if (EnableRegReassign) {
2538 addMachineFunctionPass(GCNNSAReassignPass(), PMW);
2539 }
2540
2541 addMachineFunctionPass(AMDGPURewriteAGPRCopyMFMAPass(), PMW);
2542}
2543
2544void AMDGPUCodeGenPassBuilder::addMachineSSAOptimization(
2545 PassManagerWrapper &PMW) {
2546 Base::addMachineSSAOptimization(PMW);
2547
2548 addMachineFunctionPass(SIFoldOperandsPass(), PMW);
2549 if (EnableDPPCombine) {
2550 addMachineFunctionPass(GCNDPPCombinePass(), PMW);
2551 }
2552 addMachineFunctionPass(SILoadStoreOptimizerPass(), PMW);
2553 if (isPassEnabled(EnableSDWAPeephole)) {
2554 addMachineFunctionPass(SIPeepholeSDWAPass(), PMW);
2555 addMachineFunctionPass(EarlyMachineLICMPass(), PMW);
2556 addMachineFunctionPass(MachineCSEPass(), PMW);
2557 addMachineFunctionPass(SIFoldOperandsPass(), PMW);
2558 }
2559 addMachineFunctionPass(DeadMachineInstructionElimPass(), PMW);
2560 addMachineFunctionPass(SIShrinkInstructionsPass(), PMW);
2561}
2562
2563Error AMDGPUCodeGenPassBuilder::addFastRegAlloc(PassManagerWrapper &PMW) {
2564 insertPass<PHIEliminationPass>(SILowerControlFlowPass());
2565
2566 insertPass<TwoAddressInstructionPass>(SIWholeQuadModePass());
2567
2568 return Base::addFastRegAlloc(PMW);
2569}
2570
2571Error AMDGPUCodeGenPassBuilder::addRegAssignAndRewriteFast(
2572 PassManagerWrapper &PMW) {
2573 if (auto Err = validateRegAllocOptions())
2574 return Err;
2575
2576 addMachineFunctionPass(GCNPreRALongBranchRegPass(), PMW);
2577
2578 // SGPR allocation - default to fast at -O0.
2579 if (SGPRRegAllocNPM == RegAllocType::Greedy)
2580 addMachineFunctionPass(RAGreedyPass({onlyAllocateSGPRs, "sgpr"}), PMW);
2581 else
2582 addMachineFunctionPass(RegAllocFastPass({onlyAllocateSGPRs, "sgpr", false}),
2583 PMW);
2584
2585 // Equivalent of PEI for SGPRs.
2586 addMachineFunctionPass(SILowerSGPRSpillsPass(), PMW);
2587
2588 // To Allocate wwm registers used in whole quad mode operations (for shaders).
2589 addMachineFunctionPass(SIPreAllocateWWMRegsPass(), PMW);
2590
2591 // WWM allocation - default to fast at -O0.
2592 if (WWMRegAllocNPM == RegAllocType::Greedy)
2593 addMachineFunctionPass(RAGreedyPass({onlyAllocateWWMRegs, "wwm"}), PMW);
2594 else
2595 addMachineFunctionPass(
2596 RegAllocFastPass({onlyAllocateWWMRegs, "wwm", false}), PMW);
2597
2598 addMachineFunctionPass(SILowerWWMCopiesPass(), PMW);
2599 addMachineFunctionPass(AMDGPUReserveWWMRegsPass(), PMW);
2600
2601 // VGPR allocation - default to fast at -O0.
2602 if (VGPRRegAllocNPM == RegAllocType::Greedy)
2603 addMachineFunctionPass(RAGreedyPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2604 else
2605 addMachineFunctionPass(RegAllocFastPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2606
2607 return Error::success();
2608}
2609
2610Error AMDGPUCodeGenPassBuilder::addOptimizedRegAlloc(PassManagerWrapper &PMW) {
2611 if (EnableDCEInRA)
2612 insertPass<DetectDeadLanesPass>(DeadMachineInstructionElimPass());
2613
2614 // FIXME: when an instruction has a Killed operand, and the instruction is
2615 // inside a bundle, seems only the BUNDLE instruction appears as the Kills of
2616 // the register in LiveVariables, this would trigger a failure in verifier,
2617 // we should fix it and enable the verifier.
2618 if (OptVGPRLiveRange)
2619 insertPass<RequireAnalysisPass<LiveVariablesAnalysis, MachineFunction>>(
2621
2622 // This must be run immediately after phi elimination and before
2623 // TwoAddressInstructions, otherwise the processing of the tied operand of
2624 // SI_ELSE will introduce a copy of the tied operand source after the else.
2625 insertPass<PHIEliminationPass>(SILowerControlFlowPass());
2626
2628 insertPass<RenameIndependentSubregsPass>(GCNRewritePartialRegUsesPass());
2629
2630 if (isPassEnabled(EnablePreRAOptimizations))
2631 insertPass<MachineSchedulerPass>(GCNPreRAOptimizationsPass());
2632
2633 // Allow the scheduler to run before SIWholeQuadMode inserts exec manipulation
2634 // instructions that cause scheduling barriers.
2635 insertPass<MachineSchedulerPass>(SIWholeQuadModePass());
2636
2637 if (OptExecMaskPreRA)
2638 insertPass<MachineSchedulerPass>(SIOptimizeExecMaskingPreRAPass());
2639
2640 // This is not an essential optimization and it has a noticeable impact on
2641 // compilation time, so we only enable it from O2.
2642 if (TM.getOptLevel() > CodeGenOptLevel::Less)
2643 insertPass<MachineSchedulerPass>(SIFormMemoryClausesPass());
2644
2645 return Base::addOptimizedRegAlloc(PMW);
2646}
2647
2648void AMDGPUCodeGenPassBuilder::addPreRegAlloc(PassManagerWrapper &PMW) {
2649 if (getOptLevel() != CodeGenOptLevel::None)
2650 addMachineFunctionPass(AMDGPUPrepareAGPRAllocPass(), PMW);
2651}
2652
2653Expected<bool> AMDGPUCodeGenPassBuilder::addRegAssignAndRewriteOptimized(
2654 PassManagerWrapper &PMW) {
2655 if (auto Err = validateRegAllocOptions())
2656 return Err;
2657
2658 addMachineFunctionPass(GCNPreRALongBranchRegPass(), PMW);
2659
2660 // SGPR allocation - default to greedy at -O1 and above.
2661 if (SGPRRegAllocNPM == RegAllocType::Fast)
2662 addMachineFunctionPass(RegAllocFastPass({onlyAllocateSGPRs, "sgpr", false}),
2663 PMW);
2664 else
2665 addMachineFunctionPass(RAGreedyPass({onlyAllocateSGPRs, "sgpr"}), PMW);
2666
2667 // Commit allocated register changes. This is mostly necessary because too
2668 // many things rely on the use lists of the physical registers, such as the
2669 // verifier. This is only necessary with allocators which use LiveIntervals,
2670 // since FastRegAlloc does the replacements itself.
2671 addMachineFunctionPass(VirtRegRewriterPass(false), PMW);
2672
2673 // At this point, the sgpr-regalloc has been done and it is good to have the
2674 // stack slot coloring to try to optimize the SGPR spill stack indices before
2675 // attempting the custom SGPR spill lowering.
2676 addMachineFunctionPass(StackSlotColoringPass(), PMW);
2677
2678 // Equivalent of PEI for SGPRs.
2679 addMachineFunctionPass(SILowerSGPRSpillsPass(), PMW);
2680
2681 // To Allocate wwm registers used in whole quad mode operations (for shaders).
2682 addMachineFunctionPass(SIPreAllocateWWMRegsPass(), PMW);
2683
2684 // WWM allocation - default to greedy at -O1 and above.
2685 if (WWMRegAllocNPM == RegAllocType::Fast)
2686 addMachineFunctionPass(
2687 RegAllocFastPass({onlyAllocateWWMRegs, "wwm", false}), PMW);
2688 else
2689 addMachineFunctionPass(RAGreedyPass({onlyAllocateWWMRegs, "wwm"}), PMW);
2690 addMachineFunctionPass(SILowerWWMCopiesPass(), PMW);
2691 addMachineFunctionPass(VirtRegRewriterPass(false), PMW);
2692 addMachineFunctionPass(AMDGPUReserveWWMRegsPass(), PMW);
2693
2694 // VGPR allocation - default to greedy at -O1 and above.
2695 if (VGPRRegAllocNPM == RegAllocType::Fast)
2696 addMachineFunctionPass(RegAllocFastPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2697 else
2698 addMachineFunctionPass(RAGreedyPass({onlyAllocateVGPRs, "vgpr"}), PMW);
2699
2700 addPreRewrite(PMW);
2701 addMachineFunctionPass(VirtRegRewriterPass(true), PMW);
2702
2703 addMachineFunctionPass(AMDGPUMarkLastScratchLoadPass(), PMW);
2704 return true;
2705}
2706
2707void AMDGPUCodeGenPassBuilder::addPostRegAlloc(PassManagerWrapper &PMW) {
2708 addMachineFunctionPass(SIFixVGPRCopiesPass(), PMW);
2709 if (TM.getOptLevel() > CodeGenOptLevel::None)
2710 addMachineFunctionPass(SIOptimizeExecMaskingPass(), PMW);
2711 Base::addPostRegAlloc(PMW);
2712}
2713
2714void AMDGPUCodeGenPassBuilder::addPreSched2(PassManagerWrapper &PMW) {
2715 if (TM.getOptLevel() > CodeGenOptLevel::None)
2716 addMachineFunctionPass(SIShrinkInstructionsPass(), PMW);
2717 addMachineFunctionPass(SIPostRABundlerPass(), PMW);
2718}
2719
2720void AMDGPUCodeGenPassBuilder::addPostBBSections(PassManagerWrapper &PMW) {
2721 // We run this later to avoid passes like livedebugvalues and BBSections
2722 // having to deal with the apparent multi-entry functions we may generate.
2723 addMachineFunctionPass(AMDGPUPreloadKernArgPrologPass(), PMW);
2724}
2725
2726void AMDGPUCodeGenPassBuilder::addPreEmitPass(PassManagerWrapper &PMW) {
2727 if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less)) {
2728 addMachineFunctionPass(GCNCreateVOPDPass(), PMW);
2729 }
2730
2731 addMachineFunctionPass(SIMemoryLegalizerPass(), PMW);
2732 addMachineFunctionPass(SIInsertWaitcntsPass(), PMW);
2733
2734 addMachineFunctionPass(SIModeRegisterPass(), PMW);
2735
2736 if (TM.getOptLevel() > CodeGenOptLevel::None)
2737 addMachineFunctionPass(SIInsertHardClausesPass(), PMW);
2738
2739 addMachineFunctionPass(SILateBranchLoweringPass(), PMW);
2740
2741 if (isPassEnabled(EnableSetWavePriority, CodeGenOptLevel::Less))
2742 addMachineFunctionPass(AMDGPUSetWavePriorityPass(), PMW);
2743
2744 if (TM.getOptLevel() > CodeGenOptLevel::None)
2745 addMachineFunctionPass(SIPreEmitPeepholePass(), PMW);
2746
2747 // The hazard recognizer that runs as part of the post-ra scheduler does not
2748 // guarantee to be able handle all hazards correctly. This is because if there
2749 // are multiple scheduling regions in a basic block, the regions are scheduled
2750 // bottom up, so when we begin to schedule a region we don't know what
2751 // instructions were emitted directly before it.
2752 //
2753 // Here we add a stand-alone hazard recognizer pass which can handle all
2754 // cases.
2755 addMachineFunctionPass(PostRAHazardRecognizerPass(), PMW);
2756 addMachineFunctionPass(AMDGPUWaitSGPRHazardsPass(), PMW);
2757 addMachineFunctionPass(AMDGPULowerVGPREncodingPass(), PMW);
2758
2759 if (isPassEnabled(EnableInsertDelayAlu, CodeGenOptLevel::Less)) {
2760 addMachineFunctionPass(AMDGPUInsertDelayAluPass(), PMW);
2761 }
2762
2763 addMachineFunctionPass(BranchRelaxationPass(), PMW);
2764}
2765
2766bool AMDGPUCodeGenPassBuilder::isPassEnabled(const cl::opt<bool> &Opt,
2767 CodeGenOptLevel Level) const {
2768 if (Opt.getNumOccurrences())
2769 return Opt;
2770 if (TM.getOptLevel() < Level)
2771 return false;
2772 return Opt;
2773}
2774
2775void AMDGPUCodeGenPassBuilder::addEarlyCSEOrGVNPass(PassManagerWrapper &PMW) {
2776 if (TM.getOptLevel() == CodeGenOptLevel::Aggressive)
2777 addFunctionPass(GVNPass(), PMW);
2778 else
2779 addFunctionPass(EarlyCSEPass(), PMW);
2780}
2781
2782void AMDGPUCodeGenPassBuilder::addStraightLineScalarOptimizationPasses(
2783 PassManagerWrapper &PMW) {
2785 addFunctionPass(LoopDataPrefetchPass(), PMW);
2786
2787 addFunctionPass(SeparateConstOffsetFromGEPPass(), PMW);
2788
2789 // ReassociateGEPs exposes more opportunities for SLSR. See
2790 // the example in reassociate-geps-and-slsr.ll.
2791 addFunctionPass(StraightLineStrengthReducePass(), PMW);
2792
2793 // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
2794 // EarlyCSE can reuse.
2795 addEarlyCSEOrGVNPass(PMW);
2796
2797 // Run NaryReassociate after EarlyCSE/GVN to be more effective.
2798 addFunctionPass(NaryReassociatePass(), PMW);
2799
2800 // NaryReassociate on GEPs creates redundant common expressions, so run
2801 // EarlyCSE after it.
2802 addFunctionPass(EarlyCSEPass(), PMW);
2803}
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:105
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition Attributes.h:261
This class provides access to building LLVM's passes.
CodeGenTargetMachineImpl(const Target &T, StringRef DataLayoutString, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, CodeGenOptLevel OL)
LLVM_ABI void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
Diagnostic information for unsupported feature in backend.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
LowerIntrinsics - This pass rewrites calls to the llvm.gcread or llvm.gcwrite intrinsics,...
Definition GCMetadata.h:229
const SIRegisterInfo * getRegisterInfo() const override
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
Get a TargetTransformInfo implementation for the target.
ScheduleDAGInstrs * createPostMachineScheduler(MachineSchedContext *C) const override
Similar to createMachineScheduler but used when postRA machine scheduling is enabled.
static AMDGPU::TargetIDSetting getTargetIDSettingFromModuleFlag(const Module &M, StringRef FlagName)
Get xnack/sramecc setting from module flag or cl::opt (for testing).
ScheduleDAGInstrs * createMachineScheduler(MachineSchedContext *C) const override
Create an instance of ScheduleDAGInstrs to be run within the standard MachineScheduler pass for this ...
void registerMachineRegisterInfoCallback(MachineFunction &MF) const override
bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &, PerFunctionMIParsingState &PFS, SMDiagnostic &Error, SMRange &SourceRange) const override
Parse out the target's MachineFunctionInfo from the YAML reprsentation.
yaml::MachineFunctionInfo * convertFuncInfoToYAML(const MachineFunction &MF) const override
Allocate and initialize an instance of the YAML representation of the MachineFunctionInfo.
yaml::MachineFunctionInfo * createDefaultFuncInfoYAML() const override
Allocate and return a default initialized instance of the YAML representation for the MachineFunction...
Error buildCodeGenPipeline(ModulePassManager &MPM, ModuleAnalysisManager &MAM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, const CGPassBuilderOption &Opts, MCContext &Ctx, PassInstrumentationCallbacks *PIC) override
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
GCNTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM, CodeGenOptLevel OL, bool JIT)
MachineFunctionInfo * createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F, const TargetSubtargetInfo *STI) const override
Create the target's instance of MachineFunctionInfo.
The core GVN pass object.
Definition GVN.h:123
Pass to remove unused function declarations.
Definition GlobalDCE.h:38
This pass is responsible for selecting generic machine instructions to target-specific instructions.
A pass that internalizes all functions and variables other than those that must be preserved accordin...
Definition Internalize.h:37
Converts loops into loop-closed SSA form.
Definition LCSSA.h:38
Performs Loop Invariant Code Motion Pass.
Definition LICM.h:66
static void setUseExtended(bool Enable)
This pass implements the localization mechanism described at the top of this file.
Definition Localizer.h: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:346
int getNumOccurrences() const
An efficient, type-erasing, non-owning reference to a callable.
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
An abstract base class for streams implementations that also support a pwrite operation.
Interfaces for registering analysis passes, producing common pass manager configurations,...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ LOCAL_ADDRESS
Address space for local memory.
@ CONSTANT_ADDRESS
Address space for constant memory (VTX2).
@ FLAT_ADDRESS
Address space for flat memory.
@ GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
@ PRIVATE_ADDRESS
Address space for private memory.
constexpr StringLiteral BufferFlag("amdgpu.buffer.oob.mode")
constexpr StringLiteral TBufferFlag("amdgpu.tbuffer.oob.mode")
StringRef getSchedStrategy(const Function &F)
bool isFlatGlobalAddrSpace(unsigned AS)
LLVM_READNONE constexpr bool isModuleEntryFunctionCC(CallingConv::ID CC)
GPUKind
GPU kinds supported by the AMDGPU target.
LLVM_READNONE constexpr bool isEntryFunctionCC(CallingConv::ID CC)
LLVM_ABI Triple::SubArchType getSubArch(GPUKind AK)
LLVM_ABI StringRef getArchNameFromSubArch(Triple::SubArchType SubArch)
Returns the canonical GPU name for an AMDGPU subarch, e.g.
LLVM_ABI GPUKind parseArchAMDGCN(StringRef CPU)
LLVM_ABI Triple::SubArchType getMajorSubArch(Triple::SubArchType SubArch)
BinaryOp_match< SrcTy, SpecificConstantMatch, TargetOpcode::G_XOR, true > m_Not(const SrcTy &&Src)
Matches a register not-ed by a G_XOR.
BinaryOp_match< LHS, RHS, Instruction::And, true > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
bool match(Val *V, const Pattern &P)
match_deferred< Value > m_Deferred(Value *const &V)
Like m_Specific(), but works if the specific value to match is determined as part of the same match()...
auto m_Value()
Match an arbitrary value and ignore it.
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
template class LLVM_TEMPLATE_ABI opt< bool >
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
LocationClass< Ty > location(Ty &L)
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract_or_null(Y &&MD)
Extract a Value from Metadata, if any, allowing null.
Definition Metadata.h:709
This is an optimization pass for GlobalISel generic memory operations.
ScheduleDAGMILive * createSchedLive(MachineSchedContext *C)
Create the standard converging machine scheduler.
LLVM_ABI FunctionPass * createFlattenCFGPass()
ModulePass * createAMDGPUSwLowerLDSLegacyPass()
std::unique_ptr< ScheduleDAGMutation > createAMDGPUBarrierLatencyDAGMutation(MachineFunction *MF)
LLVM_ABI FunctionPass * createFastRegisterAllocator()
FastRegisterAllocation Pass - This pass register allocates as fast as possible.
LLVM_ABI char & EarlyMachineLICMID
This pass performs loop invariant code motion on machine instructions.
ImmutablePass * createAMDGPUAAWrapperPass()
LLVM_ABI char & PostRAHazardRecognizerID
PostRAHazardRecognizer - This pass runs the post-ra hazard recognizer.
std::function< bool(const TargetRegisterInfo &TRI, const MachineRegisterInfo &MRI, const Register Reg)> RegAllocFilterFunc
Filter function for register classes during regalloc.
FunctionPass * createAMDGPUSetWavePriorityPass()
LLVM_ABI Pass * createLCSSAPass()
Definition LCSSA.cpp:544
void initializeAMDGPUMarkLastScratchLoadLegacyPass(PassRegistry &)
void initializeAMDGPUInsertDelayAluLegacyPass(PassRegistry &)
void initializeSIOptimizeExecMaskingPreRALegacyPass(PassRegistry &)
char & GCNPreRAOptimizationsID
LLVM_ABI char & GCLoweringID
GCLowering Pass - Used by gc.root to perform its default lowering operations.
void initializeSIInsertHardClausesLegacyPass(PassRegistry &)
FunctionPass * createSIAnnotateControlFlowLegacyPass()
Create the annotation pass.
FunctionPass * createSIModeRegisterPass()
void initializeGCNPreRAOptimizationsLegacyPass(PassRegistry &)
void initializeSILowerWWMCopiesLegacyPass(PassRegistry &)
LLVM_ABI FunctionPass * createGreedyRegisterAllocator()
Greedy register allocation pass - This pass implements a global register allocator for optimized buil...
void initializeAMDGPUAAWrapperPassPass(PassRegistry &)
void initializeSIShrinkInstructionsLegacyPass(PassRegistry &)
ModulePass * createAMDGPULowerBufferFatPointersPass()
void initializeR600ClauseMergePassPass(PassRegistry &)
ModulePass * createAMDGPUCtorDtorLoweringLegacyPass()
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
ModuleToFunctionPassAdaptor createModuleToFunctionPassAdaptor(FunctionPassT &&Pass, bool EagerlyInvalidate=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
void initializeGCNRewritePartialRegUsesLegacyPass(llvm::PassRegistry &)
void initializeAMDGPURewriteUndefForPHILegacyPass(PassRegistry &)
char & GCNRewritePartialRegUsesID
void initializeAMDGPUSwLowerLDSLegacyPass(PassRegistry &)
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:94
void initializeAMDGPULowerVGPREncodingLegacyPass(PassRegistry &)
char & AMDGPUWaitSGPRHazardsLegacyID
void initializeSILowerSGPRSpillsLegacyPass(PassRegistry &)
LLVM_ABI Pass * createLoadStoreVectorizerPass()
Create a legacy pass manager instance of the LoadStoreVectorizer pass.
std::unique_ptr< ScheduleDAGMutation > createIGroupLPDAGMutation(AMDGPU::SchedulingPhase Phase)
Phase specifes whether or not this is a reentry into the IGroupLPDAGMutation.
void initializeAMDGPUDAGToDAGISelLegacyPass(PassRegistry &)
FunctionPass * createAMDGPURegBankCombiner(bool IsOptNone)
LLVM_ABI FunctionPass * createNaryReassociatePass()
char & AMDGPUReserveWWMRegsLegacyID
void initializeAMDGPUWaitSGPRHazardsLegacyPass(PassRegistry &)
LLVM_ABI char & PatchableFunctionID
This pass implements the "patchable-function" attribute.
char & SIOptimizeExecMaskingLegacyID
LLVM_ABI char & PostRASchedulerID
PostRAScheduler - This pass performs post register allocation scheduling.
void initializeAMDGPUNextUseAnalysisLegacyPassPass(PassRegistry &)
void initializeR600ExpandSpecialInstrsPassPass(PassRegistry &)
void initializeR600PacketizerPass(PassRegistry &)
@ O1
Optimize quickly without destroying debuggability.
@ O0
Disable as many optimizations as possible.
std::unique_ptr< ScheduleDAGMutation > createVOPDPairingMutation()
ModulePass * createAMDGPUExportKernelRuntimeHandlesLegacyPass()
ModulePass * createAMDGPUAlwaysInlinePass(bool GlobalOpt=true)
void initializeAMDGPUAsmPrinterPass(PassRegistry &)
void initializeSIFoldOperandsLegacyPass(PassRegistry &)
char & SILoadStoreOptimizerLegacyID
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:394
char & SIFormMemoryClausesID
void initializeSILoadStoreOptimizerLegacyPass(PassRegistry &)
void initializeAMDGPULowerModuleLDSLegacyPass(PassRegistry &)
AnalysisManager< LazyCallGraph::SCC, LazyCallGraph & > CGSCCAnalysisManager
The CGSCC analysis manager.
void initializeAMDGPUCtorDtorLoweringLegacyPass(PassRegistry &)
LLVM_ABI char & EarlyIfConverterLegacyID
EarlyIfConverter - This pass performs if-conversion on SSA form by inserting cmov instructions.
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
FunctionPass * createAMDGPUUniformIntrinsicCombineLegacyPass()
void initializeAMDGPURegBankCombinerPass(PassRegistry &)
ThinOrFullLTOPhase
This enumerates the LLVM full LTO or ThinLTO optimization phases.
Definition Pass.h:77
@ FullLTOPostLink
Full LTO postlink (backend compile) phase.
Definition Pass.h:87
char & AMDGPUUnifyDivergentExitNodesID
void initializeAMDGPUPrepareAGPRAllocLegacyPass(PassRegistry &)
FunctionPass * createAMDGPUAtomicOptimizerPass(ScanOptions ScanStrategy)
FunctionPass * createAMDGPUPreloadKernArgPrologLegacyPass()
char & SIOptimizeVGPRLiveRangeLegacyID
LLVM_ABI char & ShadowStackGCLoweringID
ShadowStackGCLowering - Implements the custom lowering mechanism used by the shadow stack GC.
char & GCNNSAReassignID
void initializeAMDGPURewriteOutArgumentsPass(PassRegistry &)
static Reloc::Model getEffectiveRelocModel(std::optional< Reloc::Model > RM)
void initializeAMDGPUExternalAAWrapperPass(PassRegistry &)
char & SIFoldOperandsLegacyID
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
void initializeAMDGPULowerKernelArgumentsPass(PassRegistry &)
void initializeSIModeRegisterLegacyPass(PassRegistry &)
CodeModel::Model getEffectiveCodeModel(std::optional< CodeModel::Model > CM, CodeModel::Model Default)
Helper method for getting the code model, returning Default if CM does not have a value.
void initializeAMDGPUPreloadKernelArgumentsLegacyPass(PassRegistry &)
LLVM_ABI ModulePass * createExpandVariadicsPass(ExpandVariadicsMode)
char & SILateBranchLoweringPassID
FunctionToLoopPassAdaptor createFunctionToLoopPassAdaptor(LoopPassT &&Pass, bool UseMemorySSA=false)
A function to deduce a loop pass type and wrap it in the templated adaptor.
LLVM_ABI char & BranchRelaxationPassID
BranchRelaxation - This pass replaces branches that need to jump further than is supported by a branc...
LLVM_ABI FunctionPass * createSinkingPass()
Definition Sink.cpp:273
CGSCCToFunctionPassAdaptor createCGSCCToFunctionPassAdaptor(FunctionPassT &&Pass, bool EagerlyInvalidate=false, bool NoRerun=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
void initializeSIMemoryLegalizerLegacyPass(PassRegistry &)
ModulePass * createAMDGPULowerIntrinsicsLegacyPass()
void initializeR600MachineCFGStructurizerPass(PassRegistry &)
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition CodeGen.h:178
char & GCNDPPCombineLegacyID
PassManager< Module > ModulePassManager
Convenience typedef for a pass manager over modules.
LLVM_ABI std::unique_ptr< ScheduleDAGMutation > createStoreClusterDAGMutation(const TargetInstrInfo *TII, const TargetRegisterInfo *TRI, bool ReorderWhileClustering=false)
If ReorderWhileClustering is set to true, no attempt will be made to reduce reordering due to store c...
LLVM_ABI FunctionPass * createLoopDataPrefetchPass()
FunctionPass * createAMDGPULowerKernelArgumentsPass()
char & AMDGPUInsertDelayAluID
std::unique_ptr< ScheduleDAGMutation > createAMDGPUMacroFusionDAGMutation()
Note that you have to add: DAG.addMutation(createAMDGPUMacroFusionDAGMutation()); to AMDGPUTargetMach...
LLVM_ABI char & StackMapLivenessID
StackMapLiveness - This pass analyses the register live-out set of stackmap/patchpoint intrinsics and...
void initializeGCNPreRALongBranchRegLegacyPass(PassRegistry &)
char & SILowerWWMCopiesLegacyID
LLVM_ABI FunctionPass * createUnifyLoopExitsPass()
char & SIOptimizeExecMaskingPreRAID
LLVM_ABI FunctionPass * createFixIrreduciblePass()
void initializeR600EmitClauseMarkersPass(PassRegistry &)
LLVM_ABI char & FuncletLayoutID
This pass lays out funclets contiguously.
LLVM_ABI char & DetectDeadLanesID
This pass adds dead/undef flags after analyzing subregister lanes.
void initializeAMDGPULowerExecSyncLegacyPass(PassRegistry &)
void initializeAMDGPUPostLegalizerCombinerPass(PassRegistry &)
ScheduleDAGInstrs * createGCNNoopPostMachineScheduler(MachineSchedContext *C)
void initializeAMDGPUExportKernelRuntimeHandlesLegacyPass(PassRegistry &)
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:149
@ Default
-O2, -Os, -Oz
Definition CodeGen.h:152
void initializeSIInsertWaitcntsLegacyPass(PassRegistry &)
ModulePass * createAMDGPUPreloadKernelArgumentsLegacyPass(const TargetMachine *)
ModulePass * createAMDGPUPrintfRuntimeBinding()
LLVM_ABI char & StackSlotColoringID
StackSlotColoring - This pass performs stack slot coloring.
LLVM_ABI Pass * createAlwaysInlinerLegacyPass(bool InsertLifetime=true)
Create a legacy pass manager instance of a pass to inline and remove functions marked as "always_inli...
void initializeR600ControlFlowFinalizerPass(PassRegistry &)
void initializeAMDGPUImageIntrinsicOptimizerPass(PassRegistry &)
void initializeSILateBranchLoweringLegacyPass(PassRegistry &)
void initializeSILowerControlFlowLegacyPass(PassRegistry &)
void initializeSIFormMemoryClausesLegacyPass(PassRegistry &)
char & SIPreAllocateWWMRegsLegacyID
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
ModulePass * createAMDGPULowerModuleLDSLegacyPass(const AMDGPUTargetMachine *TM=nullptr)
void initializeAMDGPUPreLegalizerCombinerPass(PassRegistry &)
FunctionPass * createAMDGPUPromoteAlloca()
LLVM_ABI FunctionPass * createSeparateConstOffsetFromGEPPass(bool LowerGEP=false)
void initializeAMDGPUReserveWWMRegsLegacyPass(PassRegistry &)
char & SIPreEmitPeepholeID
char & SIPostRABundlerLegacyID
ModulePass * createAMDGPURemoveIncompatibleFunctionsPass(const TargetMachine *)
void initializeGCNRegPressurePrinterPass(PassRegistry &)
void initializeSILowerI1CopiesLegacyPass(PassRegistry &)
LLVM_ABI ImmutablePass * createExternalAAWrapperPass(std::function< void(Pass &, Function &, AAResults &)> Callback, bool RunEarly=false)
A wrapper pass around a callback which can be used to populate the AAResults in the AAResultsWrapperP...
char & SILowerSGPRSpillsLegacyID
LLVM_ABI FunctionPass * createBasicRegisterAllocator()
BasicRegisterAllocation Pass - This pass implements a degenerate global register allocator using the ...
LLVM_ABI void initializeGlobalISel(PassRegistry &)
Initialize all passes linked into the GlobalISel library.
char & SILowerControlFlowLegacyID
ModulePass * createR600OpenCLImageTypeLoweringPass()
FunctionPass * createAMDGPUCodeGenPreparePass()
void initializeSIAnnotateControlFlowLegacyPass(PassRegistry &)
FunctionPass * createAMDGPUISelDag(TargetMachine &TM, CodeGenOptLevel OptLevel)
This pass converts a legalized DAG into a AMDGPU-specific.
void initializeGCNCreateVOPDLegacyPass(PassRegistry &)
void initializeAMDGPUUniformIntrinsicCombineLegacyPass(PassRegistry &)
ScheduleDAGInstrs * createGCNCoExecMachineScheduler(MachineSchedContext *C)
void initializeSIPreAllocateWWMRegsLegacyPass(PassRegistry &)
void initializeSIFixVGPRCopiesLegacyPass(PassRegistry &)
Target & getTheGCNTarget()
The target for GCN GPUs.
void initializeSIFixSGPRCopiesLegacyPass(PassRegistry &)
void initializeAMDGPUAtomicOptimizerPass(PassRegistry &)
void initializeAMDGPULowerIntrinsicsLegacyPass(PassRegistry &)
LLVM_ABI char & MachinePipelinerID
This pass performs software pipelining on machine instructions.
LLVM_ABI FunctionPass * createGVNPass()
Definition GVN.cpp:4096
void initializeAMDGPURewriteAGPRCopyMFMALegacyPass(PassRegistry &)
void initializeAMDGPUNextUseAnalysisPrinterLegacyPassPass(PassRegistry &)
void initializeSIPostRABundlerLegacyPass(PassRegistry &)
FunctionPass * createAMDGPURegBankSelectPass()
FunctionPass * createAMDGPURegBankLegalizePass()
LLVM_ABI char & MachineCSELegacyID
MachineCSE - This pass performs global CSE on machine instructions.
char & SIWholeQuadModeID
LLVM_ABI std::unique_ptr< ScheduleDAGMutation > createLoadClusterDAGMutation(const TargetInstrInfo *TII, const TargetRegisterInfo *TRI, bool ReorderWhileClustering=false)
If ReorderWhileClustering is set to true, no attempt will be made to reduce reordering due to store c...
PassManager< Function > FunctionPassManager
Convenience typedef for a pass manager over functions.
LLVM_ABI char & LiveVariablesID
LiveVariables pass - This pass computes the set of blocks in which each variable is life and sets mac...
void initializeAMDGPUCodeGenPreparePass(PassRegistry &)
FunctionPass * createAMDGPURewriteUndefForPHILegacyPass()
void initializeSIOptimizeExecMaskingLegacyPass(PassRegistry &)
void call_once(once_flag &flag, Function &&F, Args &&... ArgList)
Execute the function specified as a parameter once.
Definition Threading.h:86
FunctionPass * createSILowerI1CopiesLegacyPass()
FunctionPass * createAMDGPUPostLegalizeCombiner(bool IsOptNone)
void initializeAMDGPULowerKernelAttributesPass(PassRegistry &)
char & SIInsertHardClausesID
char & SIFixSGPRCopiesLegacyID
void initializeGCNDPPCombineLegacyPass(PassRegistry &)
char & GCNCreateVOPDID
char & SIPeepholeSDWALegacyID
LLVM_ABI char & VirtRegRewriterID
VirtRegRewriter pass.
char & SIFixVGPRCopiesID
void initializeGCNNSAReassignLegacyPass(PassRegistry &)
LLVM_ABI FunctionPass * createLowerSwitchPass()
void initializeAMDGPUPreloadKernArgPrologLegacyPass(PassRegistry &)
Target & getTheGCNLegacyTarget()
The target for GCN GPUs, registered under the legacy "amdgcn" architecture name for use with -march.
LLVM_ABI FunctionPass * createVirtRegRewriter(bool ClearVirtRegs=true)
void initializeR600VectorRegMergerPass(PassRegistry &)
char & AMDGPURewriteAGPRCopyMFMALegacyID
ModulePass * createAMDGPULowerExecSyncLegacyPass()
char & AMDGPULowerVGPREncodingLegacyID
FunctionPass * createAMDGPUGlobalISelDivergenceLoweringPass()
FunctionPass * createSIMemoryLegalizerPass()
void initializeAMDGPULateCodeGenPrepareLegacyPass(PassRegistry &)
void initializeSIOptimizeVGPRLiveRangeLegacyPass(PassRegistry &)
void initializeSIPeepholeSDWALegacyPass(PassRegistry &)
void initializeAMDGPURegBankLegalizePass(PassRegistry &)
LLVM_ABI char & TwoAddressInstructionPassID
TwoAddressInstruction - This pass reduces two-address instructions to use two operands.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
FunctionPass * createAMDGPUPreLegalizeCombiner(bool IsOptNone)
void initializeAMDGPURegBankSelectPass(PassRegistry &)
FunctionPass * createAMDGPULateCodeGenPrepareLegacyPass()
LLVM_ABI FunctionPass * createAtomicExpandLegacyPass()
AtomicExpandPass - At IR level this pass replace atomic instructions with __atomic_* library calls,...
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
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.