LLVM  5.0.0
AMDGPUTargetMachine.cpp
Go to the documentation of this file.
1 //===-- AMDGPUTargetMachine.cpp - TargetMachine for hw codegen targets-----===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// \file
11 /// \brief The AMDGPU target machine contains all of the hardware specific
12 /// information needed to emit code for R600 and SI GPUs.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #include "AMDGPUTargetMachine.h"
17 #include "AMDGPU.h"
18 #include "AMDGPUAliasAnalysis.h"
19 #include "AMDGPUCallLowering.h"
21 #include "AMDGPULegalizerInfo.h"
22 #include "AMDGPUMacroFusion.h"
23 #include "AMDGPUTargetObjectFile.h"
25 #include "GCNIterativeScheduler.h"
26 #include "GCNSchedStrategy.h"
27 #include "R600MachineScheduler.h"
28 #include "SIMachineScheduler.h"
33 #include "llvm/CodeGen/Passes.h"
35 #include "llvm/IR/Attributes.h"
36 #include "llvm/IR/Function.h"
38 #include "llvm/Pass.h"
40 #include "llvm/Support/Compiler.h"
43 #include "llvm/Transforms/IPO.h"
46 #include "llvm/Transforms/Scalar.h"
49 #include <memory>
50 
51 using namespace llvm;
52 
54  "r600-ir-structurize",
55  cl::desc("Use StructurizeCFG IR pass"),
56  cl::init(true));
57 
59  "amdgpu-sroa",
60  cl::desc("Run SROA after promote alloca pass"),
62  cl::init(true));
63 
64 static cl::opt<bool>
65 EnableEarlyIfConversion("amdgpu-early-ifcvt", cl::Hidden,
66  cl::desc("Run early if-conversion"),
67  cl::init(false));
68 
70  "r600-if-convert",
71  cl::desc("Use if conversion pass"),
73  cl::init(true));
74 
75 // Option to disable vectorizer for tests.
77  "amdgpu-load-store-vectorizer",
78  cl::desc("Enable load store vectorizer"),
79  cl::init(true),
80  cl::Hidden);
81 
82 // Option to to control global loads scalarization
84  "amdgpu-scalarize-global-loads",
85  cl::desc("Enable global load scalarization"),
86  cl::init(true),
87  cl::Hidden);
88 
89 // Option to run internalize pass.
91  "amdgpu-internalize-symbols",
92  cl::desc("Enable elimination of non-kernel functions and unused globals"),
93  cl::init(false),
94  cl::Hidden);
95 
96 // Option to inline all early.
98  "amdgpu-early-inline-all",
99  cl::desc("Inline all functions early"),
100  cl::init(false),
101  cl::Hidden);
102 
104  "amdgpu-sdwa-peephole",
105  cl::desc("Enable SDWA peepholer"),
106  cl::init(true));
107 
108 // Enable address space based alias analysis
109 static cl::opt<bool> EnableAMDGPUAliasAnalysis("enable-amdgpu-aa", cl::Hidden,
110  cl::desc("Enable AMDGPU Alias Analysis"),
111  cl::init(true));
112 
113 // Option to enable new waitcnt insertion pass.
115  "enable-si-insert-waitcnts",
116  cl::desc("Use new waitcnt insertion pass"),
117  cl::init(true));
118 
119 // Option to run late CFG structurizer
121  "amdgpu-late-structurize",
122  cl::desc("Enable late CFG structurization"),
123  cl::init(false),
124  cl::Hidden);
125 
126 extern "C" void LLVMInitializeAMDGPUTarget() {
127  // Register the target
130 
157 }
158 
159 static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
160  return llvm::make_unique<AMDGPUTargetObjectFile>();
161 }
162 
164  return new ScheduleDAGMILive(C, llvm::make_unique<R600SchedStrategy>());
165 }
166 
168  return new SIScheduleDAGMI(C);
169 }
170 
171 static ScheduleDAGInstrs *
173  ScheduleDAGMILive *DAG =
174  new GCNScheduleDAGMILive(C, make_unique<GCNMaxOccupancySchedStrategy>(C));
178  return DAG;
179 }
180 
181 static ScheduleDAGInstrs *
183  auto DAG = new GCNIterativeScheduler(C,
185  DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
186  DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
187  return DAG;
188 }
189 
191  return new GCNIterativeScheduler(C,
193 }
194 
196 R600SchedRegistry("r600", "Run R600's custom scheduler",
198 
200 SISchedRegistry("si", "Run SI's custom scheduler",
202 
204 GCNMaxOccupancySchedRegistry("gcn-max-occupancy",
205  "Run GCN scheduler to maximize occupancy",
207 
209 IterativeGCNMaxOccupancySchedRegistry("gcn-max-occupancy-experimental",
210  "Run GCN scheduler to maximize occupancy (experimental)",
212 
214 GCNMinRegSchedRegistry("gcn-minreg",
215  "Run GCN iterative scheduler for minimal register usage (experimental)",
217 
218 static StringRef computeDataLayout(const Triple &TT) {
219  if (TT.getArch() == Triple::r600) {
220  // 32-bit pointers.
221  return "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128"
222  "-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64";
223  }
224 
225  // 32-bit private, local, and region pointers. 64-bit global, constant and
226  // flat.
227  if (TT.getEnvironmentName() == "amdgiz" ||
228  TT.getEnvironmentName() == "amdgizcl")
229  return "e-p:64:64-p1:64:64-p2:64:64-p3:32:32-p4:32:32-p5:32:32"
230  "-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128"
231  "-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-A5";
232  return "e-p:32:32-p1:64:64-p2:64:64-p3:32:32-p4:64:64-p5:32:32"
233  "-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128"
234  "-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64";
235 }
236 
238 static StringRef getGPUOrDefault(const Triple &TT, StringRef GPU) {
239  if (!GPU.empty())
240  return GPU;
241 
242  // HSA only supports CI+, so change the default GPU to a CI for HSA.
243  if (TT.getArch() == Triple::amdgcn)
244  return (TT.getOS() == Triple::AMDHSA) ? "kaveri" : "tahiti";
245 
246  return "r600";
247 }
248 
250  // The AMDGPU toolchain only supports generating shared objects, so we
251  // must always use PIC.
252  return Reloc::PIC_;
253 }
254 
256  StringRef CPU, StringRef FS,
257  TargetOptions Options,
259  CodeModel::Model CM,
260  CodeGenOpt::Level OptLevel)
261  : LLVMTargetMachine(T, computeDataLayout(TT), TT, getGPUOrDefault(TT, CPU),
262  FS, Options, getEffectiveRelocModel(RM), CM, OptLevel),
263  TLOF(createTLOF(getTargetTriple())) {
264  AS = AMDGPU::getAMDGPUAS(TT);
265  initAsmInfo();
266 }
267 
269 
271  Attribute GPUAttr = F.getFnAttribute("target-cpu");
272  return GPUAttr.hasAttribute(Attribute::None) ?
273  getTargetCPU() : GPUAttr.getValueAsString();
274 }
275 
277  Attribute FSAttr = F.getFnAttribute("target-features");
278 
279  return FSAttr.hasAttribute(Attribute::None) ?
281  FSAttr.getValueAsString();
282 }
283 
285  return createExternalAAWrapperPass([](Pass &P, Function &, AAResults &AAR) {
286  if (auto *WrapperPass = P.getAnalysisIfAvailable<AMDGPUAAWrapperPass>())
287  AAR.addAAResult(WrapperPass->getResult());
288  });
289 }
290 
292  Builder.DivergentTarget = true;
293 
294  bool Internalize = InternalizeSymbols &&
297  bool EarlyInline = EarlyInlineAll &&
300 
301  Builder.addExtension(
303  [Internalize, EarlyInline, AMDGPUAA](const PassManagerBuilder &,
305  if (AMDGPUAA) {
308  }
310  if (Internalize) {
311  PM.add(createInternalizePass([=](const GlobalValue &GV) -> bool {
312  if (const Function *F = dyn_cast<Function>(&GV)) {
313  if (F->isDeclaration())
314  return true;
315  switch (F->getCallingConv()) {
316  default:
317  return false;
325  return true;
326  }
327  }
328  return !GV.use_empty();
329  }));
330  PM.add(createGlobalDCEPass());
331  }
332  if (EarlyInline)
334  });
335 
336  Builder.addExtension(
338  [AMDGPUAA](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
339  if (AMDGPUAA) {
342  }
343  });
344 
345  Builder.addExtension(
348  // Add infer address spaces pass to the opt pipeline after inlining
349  // but before SROA to increase SROA opportunities.
351  });
352 }
353 
354 //===----------------------------------------------------------------------===//
355 // R600 Target Machine (R600 -> Cayman)
356 //===----------------------------------------------------------------------===//
357 
359  StringRef CPU, StringRef FS,
360  TargetOptions Options,
363  : AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {
365 }
366 
368  const Function &F) const {
369  StringRef GPU = getGPUName(F);
370  StringRef FS = getFeatureString(F);
371 
372  SmallString<128> SubtargetKey(GPU);
373  SubtargetKey.append(FS);
374 
375  auto &I = SubtargetMap[SubtargetKey];
376  if (!I) {
377  // This needs to be done before we create a new subtarget since any
378  // creation will depend on the TM and the code generation flags on the
379  // function that reside in TargetOptions.
381  I = llvm::make_unique<R600Subtarget>(TargetTriple, GPU, FS, *this);
382  }
383 
384  return I.get();
385 }
386 
387 //===----------------------------------------------------------------------===//
388 // GCN Target Machine (SI+)
389 //===----------------------------------------------------------------------===//
390 
392  StringRef CPU, StringRef FS,
393  TargetOptions Options,
396  : AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {}
397 
399  StringRef GPU = getGPUName(F);
400  StringRef FS = getFeatureString(F);
401 
402  SmallString<128> SubtargetKey(GPU);
403  SubtargetKey.append(FS);
404 
405  auto &I = SubtargetMap[SubtargetKey];
406  if (!I) {
407  // This needs to be done before we create a new subtarget since any
408  // creation will depend on the TM and the code generation flags on the
409  // function that reside in TargetOptions.
411  I = llvm::make_unique<SISubtarget>(TargetTriple, GPU, FS, *this);
412  }
413 
414  I->setScalarizeGlobalBehavior(ScalarizeGlobal);
415 
416  return I.get();
417 }
418 
419 //===----------------------------------------------------------------------===//
420 // AMDGPU Pass Setup
421 //===----------------------------------------------------------------------===//
422 
423 namespace {
424 
425 class AMDGPUPassConfig : public TargetPassConfig {
426 public:
427  AMDGPUPassConfig(LLVMTargetMachine &TM, PassManagerBase &PM)
428  : TargetPassConfig(TM, PM) {
429  // Exceptions and StackMaps are not supported, so these passes will never do
430  // anything.
431  disablePass(&StackMapLivenessID);
432  disablePass(&FuncletLayoutID);
433  }
434 
435  AMDGPUTargetMachine &getAMDGPUTargetMachine() const {
436  return getTM<AMDGPUTargetMachine>();
437  }
438 
440  createMachineScheduler(MachineSchedContext *C) const override {
444  return DAG;
445  }
446 
447  void addEarlyCSEOrGVNPass();
448  void addStraightLineScalarOptimizationPasses();
449  void addIRPasses() override;
450  void addCodeGenPrepare() override;
451  bool addPreISel() override;
452  bool addInstSelector() override;
453  bool addGCPasses() override;
454 };
455 
456 class R600PassConfig final : public AMDGPUPassConfig {
457 public:
458  R600PassConfig(LLVMTargetMachine &TM, PassManagerBase &PM)
459  : AMDGPUPassConfig(TM, PM) {}
460 
461  ScheduleDAGInstrs *createMachineScheduler(
462  MachineSchedContext *C) const override {
463  return createR600MachineScheduler(C);
464  }
465 
466  bool addPreISel() override;
467  void addPreRegAlloc() override;
468  void addPreSched2() override;
469  void addPreEmitPass() override;
470 };
471 
472 class GCNPassConfig final : public AMDGPUPassConfig {
473 public:
474  GCNPassConfig(LLVMTargetMachine &TM, PassManagerBase &PM)
475  : AMDGPUPassConfig(TM, PM) {}
476 
477  GCNTargetMachine &getGCNTargetMachine() const {
478  return getTM<GCNTargetMachine>();
479  }
480 
482  createMachineScheduler(MachineSchedContext *C) const override;
483 
484  bool addPreISel() override;
485  void addMachineSSAOptimization() override;
486  bool addILPOpts() override;
487  bool addInstSelector() override;
488 #ifdef LLVM_BUILD_GLOBAL_ISEL
489  bool addIRTranslator() override;
490  bool addLegalizeMachineIR() override;
491  bool addRegBankSelect() override;
492  bool addGlobalInstructionSelect() override;
493 #endif
494  void addFastRegAlloc(FunctionPass *RegAllocPass) override;
495  void addOptimizedRegAlloc(FunctionPass *RegAllocPass) override;
496  void addPreRegAlloc() override;
497  void addPostRegAlloc() override;
498  void addPreSched2() override;
499  void addPreEmitPass() override;
500 };
501 
502 } // end anonymous namespace
503 
505  return TargetIRAnalysis([this](const Function &F) {
506  return TargetTransformInfo(AMDGPUTTIImpl(this, F));
507  });
508 }
509 
510 void AMDGPUPassConfig::addEarlyCSEOrGVNPass() {
511  if (getOptLevel() == CodeGenOpt::Aggressive)
512  addPass(createGVNPass());
513  else
514  addPass(createEarlyCSEPass());
515 }
516 
517 void AMDGPUPassConfig::addStraightLineScalarOptimizationPasses() {
520  // ReassociateGEPs exposes more opportunites for SLSR. See
521  // the example in reassociate-geps-and-slsr.ll.
523  // SeparateConstOffsetFromGEP and SLSR creates common expressions which GVN or
524  // EarlyCSE can reuse.
525  addEarlyCSEOrGVNPass();
526  // Run NaryReassociate after EarlyCSE/GVN to be more effective.
527  addPass(createNaryReassociatePass());
528  // NaryReassociate on GEPs creates redundant common expressions, so run
529  // EarlyCSE after it.
530  addPass(createEarlyCSEPass());
531 }
532 
533 void AMDGPUPassConfig::addIRPasses() {
534  const AMDGPUTargetMachine &TM = getAMDGPUTargetMachine();
535 
536  // There is no reason to run these.
537  disablePass(&StackMapLivenessID);
538  disablePass(&FuncletLayoutID);
539  disablePass(&PatchableFunctionID);
540 
542 
543  // Function calls are not supported, so make sure we inline everything.
544  addPass(createAMDGPUAlwaysInlinePass());
546  // We need to add the barrier noop pass, otherwise adding the function
547  // inlining pass will cause all of the PassConfigs passes to be run
548  // one function at a time, which means if we have a nodule with two
549  // functions, then we will generate code for the first function
550  // without ever running any passes on the second.
551  addPass(createBarrierNoopPass());
552 
553  if (TM.getTargetTriple().getArch() == Triple::amdgcn) {
554  // TODO: May want to move later or split into an early and late one.
555 
557  }
558 
559  // Handle uses of OpenCL image2d_t, image3d_t and sampler_t arguments.
561 
562  if (TM.getOptLevel() > CodeGenOpt::None) {
563  addPass(createInferAddressSpacesPass());
564  addPass(createAMDGPUPromoteAlloca());
565 
566  if (EnableSROA)
567  addPass(createSROAPass());
568 
569  addStraightLineScalarOptimizationPasses();
570 
572  addPass(createAMDGPUAAWrapperPass());
574  AAResults &AAR) {
575  if (auto *WrapperPass = P.getAnalysisIfAvailable<AMDGPUAAWrapperPass>())
576  AAR.addAAResult(WrapperPass->getResult());
577  }));
578  }
579  }
580 
582 
583  // EarlyCSE is not always strong enough to clean up what LSR produces. For
584  // example, GVN can combine
585  //
586  // %0 = add %a, %b
587  // %1 = add %b, %a
588  //
589  // and
590  //
591  // %0 = shl nsw %a, 2
592  // %1 = shl %a, 2
593  //
594  // but EarlyCSE can do neither of them.
595  if (getOptLevel() != CodeGenOpt::None)
596  addEarlyCSEOrGVNPass();
597 }
598 
599 void AMDGPUPassConfig::addCodeGenPrepare() {
601 
604 }
605 
606 bool AMDGPUPassConfig::addPreISel() {
607  addPass(createFlattenCFGPass());
608  return false;
609 }
610 
611 bool AMDGPUPassConfig::addInstSelector() {
612  addPass(createAMDGPUISelDag(getAMDGPUTargetMachine(), getOptLevel()));
613  return false;
614 }
615 
616 bool AMDGPUPassConfig::addGCPasses() {
617  // Do nothing. GC is not supported.
618  return false;
619 }
620 
621 //===----------------------------------------------------------------------===//
622 // R600 Pass Setup
623 //===----------------------------------------------------------------------===//
624 
625 bool R600PassConfig::addPreISel() {
626  AMDGPUPassConfig::addPreISel();
627 
629  addPass(createStructurizeCFGPass());
630  return false;
631 }
632 
633 void R600PassConfig::addPreRegAlloc() {
634  addPass(createR600VectorRegMerger());
635 }
636 
637 void R600PassConfig::addPreSched2() {
638  addPass(createR600EmitClauseMarkers(), false);
640  addPass(&IfConverterID, false);
641  addPass(createR600ClauseMergePass(), false);
642 }
643 
644 void R600PassConfig::addPreEmitPass() {
645  addPass(createAMDGPUCFGStructurizerPass(), false);
646  addPass(createR600ExpandSpecialInstrsPass(), false);
647  addPass(&FinalizeMachineBundlesID, false);
648  addPass(createR600Packetizer(), false);
649  addPass(createR600ControlFlowFinalizer(), false);
650 }
651 
653  return new R600PassConfig(*this, PM);
654 }
655 
656 //===----------------------------------------------------------------------===//
657 // GCN Pass Setup
658 //===----------------------------------------------------------------------===//
659 
660 ScheduleDAGInstrs *GCNPassConfig::createMachineScheduler(
661  MachineSchedContext *C) const {
662  const SISubtarget &ST = C->MF->getSubtarget<SISubtarget>();
663  if (ST.enableSIScheduler())
664  return createSIMachineScheduler(C);
666 }
667 
668 bool GCNPassConfig::addPreISel() {
669  AMDGPUPassConfig::addPreISel();
670 
671  // FIXME: We need to run a pass to propagate the attributes when calls are
672  // supported.
674 
675  // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
676  // regions formed by them.
678  if (!LateCFGStructurize) {
679  addPass(createStructurizeCFGPass(true)); // true -> SkipUniformRegions
680  }
681  addPass(createSinkingPass());
683  if (!LateCFGStructurize) {
685  }
686 
687  return false;
688 }
689 
690 void GCNPassConfig::addMachineSSAOptimization() {
692 
693  // We want to fold operands after PeepholeOptimizer has run (or as part of
694  // it), because it will eliminate extra copies making it easier to fold the
695  // real source operand. We want to eliminate dead instructions after, so that
696  // we see fewer uses of the copies. We then need to clean up the dead
697  // instructions leftover after the operands are folded as well.
698  //
699  // XXX - Can we get away without running DeadMachineInstructionElim again?
700  addPass(&SIFoldOperandsID);
702  addPass(&SILoadStoreOptimizerID);
703  if (EnableSDWAPeephole) {
704  addPass(&SIPeepholeSDWAID);
705  addPass(&MachineLICMID);
706  addPass(&MachineCSEID);
707  addPass(&SIFoldOperandsID);
709  }
711 }
712 
713 bool GCNPassConfig::addILPOpts() {
715  addPass(&EarlyIfConverterID);
716 
718  return false;
719 }
720 
721 bool GCNPassConfig::addInstSelector() {
722  AMDGPUPassConfig::addInstSelector();
723  addPass(createSILowerI1CopiesPass());
724  addPass(&SIFixSGPRCopiesID);
725  return false;
726 }
727 
728 #ifdef LLVM_BUILD_GLOBAL_ISEL
729 bool GCNPassConfig::addIRTranslator() {
730  addPass(new IRTranslator());
731  return false;
732 }
733 
734 bool GCNPassConfig::addLegalizeMachineIR() {
735  addPass(new Legalizer());
736  return false;
737 }
738 
739 bool GCNPassConfig::addRegBankSelect() {
740  addPass(new RegBankSelect());
741  return false;
742 }
743 
744 bool GCNPassConfig::addGlobalInstructionSelect() {
745  addPass(new InstructionSelect());
746  return false;
747 }
748 
749 #endif
750 
751 void GCNPassConfig::addPreRegAlloc() {
752  if (LateCFGStructurize) {
754  }
755  addPass(createSIWholeQuadModePass());
756 }
757 
758 void GCNPassConfig::addFastRegAlloc(FunctionPass *RegAllocPass) {
759  // FIXME: We have to disable the verifier here because of PHIElimination +
760  // TwoAddressInstructions disabling it.
761 
762  // This must be run immediately after phi elimination and before
763  // TwoAddressInstructions, otherwise the processing of the tied operand of
764  // SI_ELSE will introduce a copy of the tied operand source after the else.
765  insertPass(&PHIEliminationID, &SILowerControlFlowID, false);
766 
767  TargetPassConfig::addFastRegAlloc(RegAllocPass);
768 }
769 
770 void GCNPassConfig::addOptimizedRegAlloc(FunctionPass *RegAllocPass) {
771  // This needs to be run directly before register allocation because earlier
772  // passes might recompute live intervals.
774 
775  // This must be run immediately after phi elimination and before
776  // TwoAddressInstructions, otherwise the processing of the tied operand of
777  // SI_ELSE will introduce a copy of the tied operand source after the else.
778  insertPass(&PHIEliminationID, &SILowerControlFlowID, false);
779 
781 }
782 
783 void GCNPassConfig::addPostRegAlloc() {
784  addPass(&SIFixVGPRCopiesID);
785  addPass(&SIOptimizeExecMaskingID);
787 }
788 
789 void GCNPassConfig::addPreSched2() {
790 }
791 
792 void GCNPassConfig::addPreEmitPass() {
793  // The hazard recognizer that runs as part of the post-ra scheduler does not
794  // guarantee to be able handle all hazards correctly. This is because if there
795  // are multiple scheduling regions in a basic block, the regions are scheduled
796  // bottom up, so when we begin to schedule a region we don't know what
797  // instructions were emitted directly before it.
798  //
799  // Here we add a stand-alone hazard recognizer pass which can handle all
800  // cases.
801  addPass(&PostRAHazardRecognizerID);
802 
804  addPass(createSIInsertWaitcntsPass());
805  else
806  addPass(createSIInsertWaitsPass());
808  addPass(&SIInsertSkipsPassID);
810  addPass(&BranchRelaxationPassID);
811 }
812 
814  return new GCNPassConfig(*this, PM);
815 }
816 
FunctionPass * createSpeculativeExecutionPass()
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:81
Calling convention used for Mesa compute shaders.
Definition: CallingConv.h:196
OSType getOS() const
getOS - Get the parsed operating system type of this triple.
Definition: Triple.h:290
FunctionPass * createStraightLineStrengthReducePass()
FunctionPass * createGVNPass(bool NoLoads=false)
Create a legacy GVN pass.
Definition: GVN.cpp:2364
StringRef getTargetCPU() const
Target & getTheGCNTarget()
The target for GCN GPUs.
char & AMDGPUUnifyDivergentExitNodesID
void addAAResult(AAResultT &AAResult)
Register a specific AA result.
This file a TargetTransformInfo::Concept conforming object specific to the AMDGPU target machine...
FunctionPass * createSIAnnotateControlFlowPass()
Create the annotation pass.
ModulePass * createAMDGPUAlwaysInlinePass(bool GlobalOpt=true)
static LLVM_READNONE StringRef getGPUOrDefault(const Triple &TT, StringRef GPU)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
PassManagerBuilder - This class is used to set up a standard optimization sequence for languages like...
const AMDGPUSubtarget * getSubtargetImpl() const
void initializeSIFixVGPRCopiesPass(PassRegistry &)
virtual void addIRPasses()
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
static cl::opt< bool > EnableLoadStoreVectorizer("amdgpu-load-store-vectorizer", cl::desc("Enable load store vectorizer"), cl::init(true), cl::Hidden)
void initializeSIInsertWaitcntsPass(PassRegistry &)
void initializeAMDGPUAnnotateKernelFeaturesPass(PassRegistry &)
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with...
Definition: TargetMachine.h:75
char & SILoadStoreOptimizerID
Target & getTheAMDGPUTarget()
The target which supports all AMD GPUs.
char & MachineLICMID
MachineLICM - This pass performs LICM on machine instructions.
char & SIPeepholeSDWAID
This file describes how to lower LLVM calls to machine code calls.
char & FuncletLayoutID
This pass lays out funclets contiguously.
AMDGPUAS getAMDGPUAS(const Module &M)
char & EarlyIfConverterID
EarlyIfConverter - This pass performs if-conversion on SSA form by inserting cmov instructions...
Analysis pass providing the TargetTransformInfo.
void initializeAMDGPUAnnotateUniformValuesPass(PassRegistry &)
FunctionPass * createAMDGPUPromoteAlloca()
virtual void add(Pass *P)=0
Add a pass to the queue of passes to run.
char & BranchRelaxationPassID
BranchRelaxation - This pass replaces branches that need to jump further than is supported by a branc...
FunctionPass * createAMDGPUCodeGenPreparePass()
Calling convention used for Mesa geometry shaders.
Definition: CallingConv.h:190
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:262
R600 Machine Scheduler interface.
char & MachineSchedulerID
MachineScheduler - This pass schedules machine instructions.
FunctionPass * createAMDGPUCFGStructurizerPass()
MachineSchedRegistry provides a selection of available machine instruction schedulers.
virtual void addMachineSSAOptimization()
addMachineSSAOptimization - Add standard passes that optimize machine instructions in SSA form...
void initializeAMDGPUAAWrapperPassPass(PassRegistry &)
FunctionPass * createAMDGPUISelDag(TargetMachine &TM, CodeGenOpt::Level OptLevel)
This pass converts a legalized DAG into a AMDGPU-specific.
static std::unique_ptr< TargetLoweringObjectFile > createTLOF(const Triple &TT)
void initializeAMDGPUPromoteAllocaPass(PassRegistry &)
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
Definition: Attributes.cpp:202
FunctionPass * createSIInsertWaitcntsPass()
ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules machine instructions while...
const Triple & getTargetTriple() const
bool enableSIScheduler() const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
This file declares the targeting of the InstructionSelector class for AMDGPU.
AnalysisType * getAnalysisIfAvailable() const
getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to get analysis information tha...
static cl::opt< bool > EnableSDWAPeephole("amdgpu-sdwa-peephole", cl::desc("Enable SDWA peepholer"), cl::init(true))
Pass * createLoadStoreVectorizerPass()
This file declares the AMDGPU-specific subclass of TargetLoweringObjectFile.
GCNTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, TargetOptions Options, Optional< Reloc::Model > RM, CodeModel::Model CM, CodeGenOpt::Level OL)
Pass * createAMDGPUAnnotateKernelFeaturesPass()
void initializeAMDGPUCodeGenPreparePass(PassRegistry &)
This file contains the simple types necessary to represent the attributes associated with functions a...
No attributes have been set.
Definition: Attributes.h:72
FunctionPass * createSinkingPass()
Definition: Sink.cpp:306
R600TargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, TargetOptions Options, Optional< Reloc::Model > RM, CodeModel::Model CM, CodeGenOpt::Level OL)
char & SIFixControlFlowLiveIntervalsID
EP_ModuleOptimizerEarly - This extension point allows adding passes just before the main module-level...
char & FinalizeMachineBundlesID
FinalizeMachineBundles - This pass finalize machine instruction bundles (created earlier, e.g.
static MachineSchedRegistry R600SchedRegistry("r600","Run R600's custom scheduler", createR600MachineScheduler)
Target-Independent Code Generator Pass Configuration Options.
Calling convention used for Mesa hull shaders.
Definition: CallingConv.h:206
static StringRef computeDataLayout(const Triple &TT)
static cl::opt< bool > ScalarizeGlobal("amdgpu-scalarize-global-loads", cl::desc("Enable global load scalarization"), cl::init(true), cl::Hidden)
#define F(x, y, z)
Definition: MD5.cpp:55
FunctionPass * createR600ExpandSpecialInstrsPass()
char & MachineCSEID
MachineCSE - This pass performs global CSE on machine instructions.
Definition: MachineCSE.cpp:110
FunctionPass * createAMDGPUMachineCFGStructurizerPass()
FunctionPass * createSILowerI1CopiesPass()
void initializeSIOptimizeExecMaskingPass(PassRegistry &)
char & DeadMachineInstructionElimID
DeadMachineInstructionElim - This pass removes dead machine instructions.
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:281
ScheduleDAGMILive * createGenericSchedLive(MachineSchedContext *C)
Create the standard converging machine scheduler.
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
virtual bool addILPOpts()
Add passes that optimize instruction level parallelism for out-of-order targets.
void initializeSIFixSGPRCopiesPass(PassRegistry &)
void initializeAMDGPULowerIntrinsicsPass(PassRegistry &)
ModulePass * createGlobalDCEPass()
createGlobalDCEPass - This transform is designed to eliminate unreachable internal globals (functions...
FunctionPass * createR600VectorRegMerger()
static MachineSchedRegistry GCNMinRegSchedRegistry("gcn-minreg","Run GCN iterative scheduler for minimal register usage (experimental)", createMinRegScheduler)
static ScheduleDAGInstrs * createIterativeGCNMaxOccupancyMachineScheduler(MachineSchedContext *C)
static cl::opt< bool > InternalizeSymbols("amdgpu-internalize-symbols", cl::desc("Enable elimination of non-kernel functions and unused globals"), cl::init(false), cl::Hidden)
SI Machine Scheduler interface.
void append(in_iter S, in_iter E)
Append from an iterator pair.
Definition: SmallString.h:75
SPIR_KERNEL - Calling convention for SPIR kernel functions.
Definition: CallingConv.h:137
char & PHIEliminationID
PHIElimination - This pass eliminates machine instruction PHI nodes by inserting copy instructions...
ImmutablePass * createExternalAAWrapperPass(std::function< void(Pass &, Function &, AAResults &)> Callback)
A wrapper pass around a callback which can be used to populate the AAResults in the AAResultsWrapperP...
StringRef getEnvironmentName() const
getEnvironmentName - Get the optional environment (fourth) component of the triple, or "" if empty.
Definition: Triple.cpp:936
#define P(N)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:401
FunctionPass * createSeparateConstOffsetFromGEPPass(const TargetMachine *TM=nullptr, bool LowerGEP=false)
FunctionPass * createSIDebuggerInsertNopsPass()
static Reloc::Model getEffectiveRelocModel(Optional< Reloc::Model > RM)
This pass implements the reg bank selector pass used in the GlobalISel pipeline.
Definition: RegBankSelect.h:91
FunctionPass * createFlattenCFGPass()
FunctionPass * createSIWholeQuadModePass()
This file provides the interface for LLVM's Global Value Numbering pass which eliminates fully redund...
static cl::opt< bool > EarlyInlineAll("amdgpu-early-inline-all", cl::desc("Inline all functions early"), cl::init(false), cl::Hidden)
char & SIInsertSkipsPassID
virtual void addOptimizedRegAlloc(FunctionPass *RegAllocPass)
addOptimizedRegAlloc - Add passes related to register allocation.
void adjustPassManager(PassManagerBuilder &) override
Allow the target to modify the pass manager, e.g.
void LLVMInitializeAMDGPUTarget()
void initializeSIPeepholeSDWAPass(PassRegistry &)
static MachineSchedRegistry GCNMaxOccupancySchedRegistry("gcn-max-occupancy","Run GCN scheduler to maximize occupancy", createGCNMaxOccupancyMachineScheduler)
static cl::opt< bool > EnableSROA("amdgpu-sroa", cl::desc("Run SROA after promote alloca pass"), cl::ReallyHidden, cl::init(true))
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
FunctionPass * createR600ControlFlowFinalizer()
Legacy wrapper pass to provide the AMDGPUAAResult object.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
static MachineSchedRegistry SISchedRegistry("si","Run SI's custom scheduler", createSIMachineScheduler)
This class describes a target machine that is implemented with the LLVM target-independent code gener...
ModulePass * createBarrierNoopPass()
createBarrierNoopPass - This pass is purely a module pass barrier in a pass manager.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
Pass * createAlwaysInlinerLegacyPass(bool InsertLifetime=true)
Create a legacy pass manager instance of a pass to inline and remove functions marked as "always_inli...
AMDGPUTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, TargetOptions Options, Optional< Reloc::Model > RM, CodeModel::Model CM, CodeGenOpt::Level OL)
void initializeSILowerControlFlowPass(PassRegistry &)
static ScheduleDAGInstrs * createMinRegScheduler(MachineSchedContext *C)
ModulePass * createAMDGPULowerIntrinsicsPass()
virtual void addCodeGenPrepare()
Add pass to prepare the LLVM IR for code generation.
FunctionPass * createR600ClauseMergePass()
The AMDGPU TargetMachine interface definition for hw codgen targets.
static cl::opt< bool > EnableR600IfConvert("r600-if-convert", cl::desc("Use if conversion pass"), cl::ReallyHidden, cl::init(true))
std::unique_ptr< ScheduleDAGMutation > createStoreClusterDAGMutation(const TargetInstrInfo *TII, const TargetRegisterInfo *TRI)
static ScheduleDAGInstrs * createR600MachineScheduler(MachineSchedContext *C)
std::unique_ptr< ScheduleDAGMutation > createAMDGPUMacroFusionDAGMutation()
Note that you have to add: DAG.addMutation(createAMDGPUMacroFusionDAGMutation()); to AMDGPUPassConfig...
void initializeSIShrinkInstructionsPass(PassRegistry &)
Calling convention used for Mesa vertex shaders.
Definition: CallingConv.h:187
Analysis pass providing a never-invalidated alias analysis result.
EP_EarlyAsPossible - This extension point allows adding passes before any other transformations, allowing them to see the code as it is coming out of the frontend.
void initializeSIInsertSkipsPass(PassRegistry &)
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
FunctionPass * createAMDGPUAnnotateUniformValues()
This is the AMGPU address space based alias analysis pass.
Provides passes to inlining "always_inline" functions.
char & SIOptimizeExecMaskingID
EP_CGSCCOptimizerLate - This extension point allows adding CallGraphSCC passes at the end of the main...
StringRef getFeatureString(const Function &F) const
std::unique_ptr< ScheduleDAGMutation > createLoadClusterDAGMutation(const TargetInstrInfo *TII, const TargetRegisterInfo *TRI)
ImmutablePass class - This class is used to provide information that does not need to be run...
Definition: Pass.h:266
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
StringRef getTargetFeatureString() const
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
char & StackMapLivenessID
StackMapLiveness - This pass analyses the register live-out set of stackmap/patchpoint intrinsics and...
ModulePass * createInternalizePass(std::function< bool(const GlobalValue &)> MustPreserveGV)
createInternalizePass - This pass loops over all of the functions in the input module, internalizing all globals (functions and variables) it can.
Calling convention used for Mesa pixel shaders.
Definition: CallingConv.h:193
void initializeSIWholeQuadModePass(PassRegistry &)
void setRequiresStructuredCFG(bool Value)
ImmutablePass * createAMDGPUAAWrapperPass()
char & SIFixVGPRCopiesID
static cl::opt< bool > EnableSIInsertWaitcntsPass("enable-si-insert-waitcnts", cl::desc("Use new waitcnt insertion pass"), cl::init(true))
FunctionPass * createR600EmitClauseMarkers()
This pass is responsible for selecting generic machine instructions to target-specific instructions...
void initializeAMDGPUUnifyMetadataPass(PassRegistry &)
Target - Wrapper for Target specific information.
virtual void addPostRegAlloc()
This method may be implemented by targets that want to run passes after register allocation pass pipe...
This file declares the targeting of the Machinelegalizer class for AMDGPU.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
virtual void addFastRegAlloc(FunctionPass *RegAllocPass)
addFastRegAlloc - Add the minimum set of target-independent passes that are required for fast registe...
FunctionPass * createR600Packetizer()
void initializeSILoadStoreOptimizerPass(PassRegistry &)
char & SILowerControlFlowID
ModulePass * createAMDGPUUnifyMetadataPass()
void initializeSIAnnotateControlFlowPass(PassRegistry &)
A ScheduleDAG for scheduling lists of MachineInstr.
char & PatchableFunctionID
This pass implements the "patchable-function" attribute.
FunctionPass * createInferAddressSpacesPass()
void initializeSIFoldOperandsPass(PassRegistry &)
char & SIFoldOperandsID
const TargetRegisterInfo * TRI
Target processor register info.
Definition: ScheduleDAG.h:569
FunctionPass * createSIShrinkInstructionsPass()
static cl::opt< bool > EnableAMDGPUAliasAnalysis("enable-amdgpu-aa", cl::Hidden, cl::desc("Enable AMDGPU Alias Analysis"), cl::init(true))
static cl::opt< bool > LateCFGStructurize("amdgpu-late-structurize", cl::desc("Enable late CFG structurization"), cl::init(false), cl::Hidden)
void initializeSIDebuggerInsertNopsPass(PassRegistry &)
#define C
Definition: LargeTest.cpp:25
char & IfConverterID
IfConverter - This pass performs machine code if conversion.
#define LLVM_READNONE
Definition: Compiler.h:161
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
char & SIFixSGPRCopiesID
void initializeSIInsertWaitsPass(PassRegistry &)
#define I(x, y, z)
Definition: MD5.cpp:58
void resetTargetOptions(const Function &F) const
Reset the target options based on the function's attributes.
FunctionPass * createSROAPass()
Definition: SROA.cpp:4312
StringRef getGPUName(const Function &F) const
const TargetInstrInfo * TII
Target instruction information.
Definition: ScheduleDAG.h:568
TargetIRAnalysis getTargetIRAnalysis() override
Get a TargetIRAnalysis implementation for the target.
FunctionPass * createSIInsertWaitsPass()
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:195
bool use_empty() const
Definition: Value.h:322
This file declares the IRTranslator pass.
RegisterTargetMachine - Helper template for registering a target machine implementation, for use in the target machine initialization function.
static MachineSchedRegistry IterativeGCNMaxOccupancySchedRegistry("gcn-max-occupancy-experimental","Run GCN scheduler to maximize occupancy (experimental)", createIterativeGCNMaxOccupancyMachineScheduler)
void initializeSIFixControlFlowLiveIntervalsPass(PassRegistry &)
char & PostRAHazardRecognizerID
createPostRAHazardRecognizer - This pass runs the post-ra hazard recognizer.
FunctionPass * createEarlyCSEPass(bool UseMemorySSA=false)
Definition: EarlyCSE.cpp:1086
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:40
void initializeSILowerI1CopiesPass(PassRegistry &)
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
void addExtension(ExtensionPointTy Ty, ExtensionFn Fn)
void initializeAMDGPUUnifyDivergentExitNodesPass(PassRegistry &)
ModulePass * createAMDGPUOpenCLImageTypeLoweringPass()
static cl::opt< bool > EnableR600StructurizeCFG("r600-ir-structurize", cl::desc("Use StructurizeCFG IR pass"), cl::init(true))
Pass * createStructurizeCFGPass(bool SkipUniformRegions=false)
When SkipUniformRegions is true the structizer will not structurize regions that only contain uniform...
void initializeAMDGPUAlwaysInlinePass(PassRegistry &)
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
Calling convention for AMDGPU code object kernels.
Definition: CallingConv.h:199
static ImmutablePass * createAMDGPUExternalAAWrapperPass()
static ScheduleDAGInstrs * createSIMachineScheduler(MachineSchedContext *C)
static ScheduleDAGInstrs * createGCNMaxOccupancyMachineScheduler(MachineSchedContext *C)
static cl::opt< bool > EnableEarlyIfConversion("amdgpu-early-ifcvt", cl::Hidden, cl::desc("Run early if-conversion"), cl::init(false))
void addMutation(std::unique_ptr< ScheduleDAGMutation > Mutation)
Add a postprocessing step to the DAG builder.
FunctionPass * createNaryReassociatePass()