LLVM  15.0.0git
AMDGPUTargetMachine.h
Go to the documentation of this file.
1 //===-- AMDGPUTargetMachine.h - AMDGPU TargetMachine Interface --*- C++ -*-===//
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 /// The AMDGPU TargetMachine interface definition for hw codegen targets.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETMACHINE_H
15 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETMACHINE_H
16 
17 #include "GCNSubtarget.h"
20 #include <utility>
21 
22 namespace llvm {
23 
24 //===----------------------------------------------------------------------===//
25 // AMDGPU Target Machine (R600+)
26 //===----------------------------------------------------------------------===//
27 
29 protected:
30  std::unique_ptr<TargetLoweringObjectFile> TLOF;
31 
32  StringRef getGPUName(const Function &F) const;
33  StringRef getFeatureString(const Function &F) const;
34 
35 public:
37  static bool EnableFunctionCalls;
38  static bool EnableLowerModuleLDS;
39 
40  AMDGPUTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
44  ~AMDGPUTargetMachine() override;
45 
47  const TargetSubtargetInfo *getSubtargetImpl(const Function &) const override = 0;
48 
50  return TLOF.get();
51  }
52 
53  void adjustPassManager(PassManagerBuilder &) override;
54 
56  void registerDefaultAliasAnalyses(AAManager &) override;
57 
58  /// Get the integer value of a null pointer in the given address space.
59  static int64_t getNullPointerValue(unsigned AddrSpace);
60 
61  bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override;
62 
63  unsigned getAssumedAddrSpace(const Value *V) const override;
64 
65  std::pair<const Value *, unsigned>
66  getPredicatedAddrSpace(const Value *V) const override;
67 
68  unsigned getAddressSpaceForPseudoSourceKind(unsigned Kind) const override;
69 };
70 
71 //===----------------------------------------------------------------------===//
72 // GCN Target Machine (SI+)
73 //===----------------------------------------------------------------------===//
74 
75 class GCNTargetMachine final : public AMDGPUTargetMachine {
76 private:
77  mutable StringMap<std::unique_ptr<GCNSubtarget>> SubtargetMap;
78 
79 public:
80  GCNTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
83  CodeGenOpt::Level OL, bool JIT);
84 
86 
87  const TargetSubtargetInfo *getSubtargetImpl(const Function &) const override;
88 
90 
91  bool useIPRA() const override {
92  return true;
93  }
94 
97  convertFuncInfoToYAML(const MachineFunction &MF) const override;
101  SMRange &SourceRange) const override;
102 };
103 
104 //===----------------------------------------------------------------------===//
105 // AMDGPU Pass Setup
106 //===----------------------------------------------------------------------===//
107 
109 public:
111 
113  return getTM<AMDGPUTargetMachine>();
114  }
115 
118 
119  void addEarlyCSEOrGVNPass();
121  void addIRPasses() override;
122  void addCodeGenPrepare() override;
123  bool addPreISel() override;
124  bool addInstSelector() override;
125  bool addGCPasses() override;
126 
127  std::unique_ptr<CSEConfigBase> getCSEConfig() const override;
128 
129  /// Check if a pass is enabled given \p Opt option. The option always
130  /// overrides defaults if explicitly used. Otherwise its default will
131  /// be used given that a pass shall work at an optimization \p Level
132  /// minimum.
133  bool isPassEnabled(const cl::opt<bool> &Opt,
135  if (Opt.getNumOccurrences())
136  return Opt;
137  if (TM->getOptLevel() < Level)
138  return false;
139  return Opt;
140  }
141 };
142 
143 } // end namespace llvm
144 
145 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETMACHINE_H
llvm::TargetMachine::getOptLevel
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
Definition: TargetMachine.cpp:186
llvm::AAManager
A manager for alias analyses.
Definition: AliasAnalysis.h:1303
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::AMDGPUTargetMachine::registerDefaultAliasAnalyses
void registerDefaultAliasAnalyses(AAManager &) override
Allow the target to register alias analyses with the AAManager for use with the new pass manager.
Definition: AMDGPUTargetMachine.cpp:610
llvm::GCNTargetMachine::convertFuncInfoToYAML
yaml::MachineFunctionInfo * convertFuncInfoToYAML(const MachineFunction &MF) const override
Allocate and initialize an instance of the YAML representation of the MachineFunctionInfo.
Definition: AMDGPUTargetMachine.cpp:1414
llvm::TargetOptions
Definition: TargetOptions.h:124
llvm::Function
Definition: Function.h:60
llvm::yaml::MachineFunctionInfo
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.
Definition: MIRYamlMapping.h:676
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:145
llvm::TargetTransformInfo
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Definition: TargetTransformInfo.h:168
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::AMDGPUTargetMachine::TLOF
std::unique_ptr< TargetLoweringObjectFile > TLOF
Definition: AMDGPUTargetMachine.h:30
llvm::AMDGPUPassConfig
Definition: AMDGPUTargetMachine.h:108
llvm::TargetMachine::RM
Reloc::Model RM
Definition: TargetMachine.h:100
llvm::Optional< Reloc::Model >
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::GCNTargetMachine::parseMachineFunctionInfo
bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &, PerFunctionMIParsingState &PFS, SMDiagnostic &Error, SMRange &SourceRange) const override
Parse out the target's MachineFunctionInfo from the YAML reprsentation.
Definition: AMDGPUTargetMachine.cpp:1420
llvm::AMDGPUPassConfig::addGCPasses
bool addGCPasses() override
addGCPasses - Add late codegen passes that analyze code for garbage collection.
Definition: AMDGPUTargetMachine.cpp:1098
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::TargetLoweringObjectFile
Definition: TargetLoweringObjectFile.h:45
llvm::AMDGPUPassConfig::addIRPasses
void addIRPasses() override
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
Definition: AMDGPUTargetMachine.cpp:972
llvm::GCNTargetMachine::GCNTargetMachine
GCNTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, TargetOptions Options, Optional< Reloc::Model > RM, Optional< CodeModel::Model > CM, CodeGenOpt::Level OL, bool JIT)
Definition: AMDGPUTargetMachine.cpp:833
llvm::TargetPassConfig::TM
LLVMTargetMachine * TM
Definition: TargetPassConfig.h:122
llvm::AMDGPUTargetMachine
Definition: AMDGPUTargetMachine.h:28
TargetMachine.h
GCNSubtarget.h
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::PassBuilder
This class provides access to building LLVM's passes.
Definition: PassBuilder.h:94
llvm::SMDiagnostic
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:281
llvm::AMDGPUTargetMachine::getNullPointerValue
static int64_t getNullPointerValue(unsigned AddrSpace)
Get the integer value of a null pointer in the given address space.
Definition: AMDGPUTargetMachine.cpp:752
llvm::cl::Option::getNumOccurrences
int getNumOccurrences() const
Definition: CommandLine.h:395
llvm::AMDGPUTargetMachine::getAddressSpaceForPseudoSourceKind
unsigned getAddressSpaceForPseudoSourceKind(unsigned Kind) const override
getAddressSpaceForPseudoSourceKind - Given the kind of memory (e.g.
Definition: AMDGPUTargetMachine.cpp:813
llvm::AMDGPUPassConfig::addCodeGenPrepare
void addCodeGenPrepare() override
Add pass to prepare the LLVM IR for code generation.
Definition: AMDGPUTargetMachine.cpp:1062
llvm::AMDGPUTargetMachine::~AMDGPUTargetMachine
~AMDGPUTargetMachine() override
llvm::AMDGPUTargetMachine::getSubtargetImpl
const TargetSubtargetInfo * getSubtargetImpl() const
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:110
llvm::PassManagerBuilder
PassManagerBuilder - This class is used to set up a standard optimization sequence for languages like...
Definition: PassManagerBuilder.h:57
llvm::AMDGPUPassConfig::addInstSelector
bool addInstSelector() override
addInstSelector - This method should install an instruction selector pass, which converts from LLVM c...
Definition: AMDGPUTargetMachine.cpp:1093
PB
PassBuilder PB(Machine, PassOpts->PTO, None, &PIC)
llvm::TargetPassConfig
Target-Independent Code Generator Pass Configuration Options.
Definition: TargetPassConfig.h:84
llvm::AMDGPUTargetMachine::getFeatureString
StringRef getFeatureString(const Function &F) const
Definition: AMDGPUTargetMachine.cpp:518
llvm::cl::opt< bool >
llvm::CodeGenOpt::Default
@ Default
Definition: CodeGen.h:55
llvm::EngineKind::JIT
@ JIT
Definition: ExecutionEngine.h:524
llvm::MachineSchedContext
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
Definition: MachineScheduler.h:125
llvm::AMDGPUPassConfig::createMachineScheduler
ScheduleDAGInstrs * createMachineScheduler(MachineSchedContext *C) const override
Create an instance of ScheduleDAGInstrs to be run within the standard MachineScheduler pass for this ...
Definition: AMDGPUTargetMachine.cpp:1104
TargetPassConfig.h
llvm::TargetMachine::Options
TargetOptions Options
Definition: TargetMachine.h:118
llvm::X86AS::FS
@ FS
Definition: X86.h:192
llvm::AMDGPUPassConfig::addStraightLineScalarOptimizationPasses
void addStraightLineScalarOptimizationPasses()
Definition: AMDGPUTargetMachine.cpp:955
llvm::AMDGPUTargetMachine::getPredicatedAddrSpace
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,...
Definition: AMDGPUTargetMachine.cpp:786
llvm::AMDGPUPassConfig::getAMDGPUTargetMachine
AMDGPUTargetMachine & getAMDGPUTargetMachine() const
Definition: AMDGPUTargetMachine.h:112
llvm::AMDGPUPassConfig::AMDGPUPassConfig
AMDGPUPassConfig(LLVMTargetMachine &TM, PassManagerBase &PM)
Definition: AMDGPUTargetMachine.cpp:937
llvm::AMDGPUTargetMachine::EnableLowerModuleLDS
static bool EnableLowerModuleLDS
Definition: AMDGPUTargetMachine.h:38
llvm::MachineFunction
Definition: MachineFunction.h:257
llvm::GCNTargetMachine
Definition: AMDGPUTargetMachine.h:75
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::AMDGPUPassConfig::addPreISel
bool addPreISel() override
Methods with trivial inline returns are convenient points in the common codegen pass pipeline where t...
Definition: AMDGPUTargetMachine.cpp:1087
llvm::PICLevel::Level
Level
Definition: CodeGen.h:33
llvm::CodeGenOpt::Level
Level
Definition: CodeGen.h:52
llvm::AMDGPUPassConfig::getCSEConfig
std::unique_ptr< CSEConfigBase > getCSEConfig() const override
Returns the CSEConfig object to use for the current optimization level.
Definition: AMDGPUTargetMachine.cpp:872
llvm::AMDGPUTargetMachine::getObjFileLowering
TargetLoweringObjectFile * getObjFileLowering() const override
Definition: AMDGPUTargetMachine.h:49
llvm::TargetSubtargetInfo
TargetSubtargetInfo - Generic base class for all target subtargets.
Definition: TargetSubtargetInfo.h:60
llvm::GCNTargetMachine::createPassConfig
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
Definition: AMDGPUTargetMachine.cpp:1405
llvm::PerFunctionMIParsingState
Definition: MIParser.h:162
llvm::GCNTargetMachine::getTargetTransformInfo
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
Get a TargetTransformInfo implementation for the target.
Definition: AMDGPUTargetMachine.cpp:864
llvm::AMDGPUTargetMachine::registerPassBuilderCallbacks
void registerPassBuilderCallbacks(PassBuilder &PB) override
Allow the target to modify the pass pipeline with New Pass Manager (similar to adjustPassManager for ...
Definition: AMDGPUTargetMachine.cpp:614
llvm::AMDGPUPassConfig::addEarlyCSEOrGVNPass
void addEarlyCSEOrGVNPass()
Definition: AMDGPUTargetMachine.cpp:948
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::AMDGPUTargetMachine::isNoopAddrSpaceCast
bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override
Returns true if a cast between SrcAS and DestAS is a noop.
Definition: AMDGPUTargetMachine.cpp:760
llvm::AMDGPUTargetMachine::adjustPassManager
void adjustPassManager(PassManagerBuilder &) override
Allow the target to modify the pass manager, e.g.
Definition: AMDGPUTargetMachine.cpp:536
llvm::LLVMTargetMachine
This class describes a target machine that is implemented with the LLVM target-independent code gener...
Definition: TargetMachine.h:411
llvm::AMDGPUPassConfig::isPassEnabled
bool isPassEnabled(const cl::opt< bool > &Opt, CodeGenOpt::Level Level=CodeGenOpt::Default) const
Check if a pass is enabled given Opt option.
Definition: AMDGPUTargetMachine.h:133
llvm::AMDGPUTargetMachine::EnableFunctionCalls
static bool EnableFunctionCalls
Definition: AMDGPUTargetMachine.h:37
llvm::AMDGPUTargetMachine::getAssumedAddrSpace
unsigned getAssumedAddrSpace(const Value *V) const override
If the specified generic pointer could be assumed as a pointer to a specific address space,...
Definition: AMDGPUTargetMachine.cpp:766
llvm::SMRange
Represents a range in source code.
Definition: SMLoc.h:48
llvm::legacy::PassManagerBase
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
Definition: LegacyPassManager.h:39
llvm::AMDGPUTargetMachine::getGPUName
StringRef getGPUName(const Function &F) const
Definition: AMDGPUTargetMachine.cpp:513
llvm::GCNTargetMachine::useIPRA
bool useIPRA() const override
True if the target wants to use interprocedural register allocation by default.
Definition: AMDGPUTargetMachine.h:91
llvm::ScheduleDAGInstrs
A ScheduleDAG for scheduling lists of MachineInstr.
Definition: ScheduleDAGInstrs.h:119
llvm::AMDGPUTargetMachine::AMDGPUTargetMachine
AMDGPUTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, TargetOptions Options, Optional< Reloc::Model > RM, Optional< CodeModel::Model > CM, CodeGenOpt::Level OL)
Definition: AMDGPUTargetMachine.cpp:488
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::AMDGPUTargetMachine::EnableLateStructurizeCFG
static bool EnableLateStructurizeCFG
Definition: AMDGPUTargetMachine.h:36
llvm::GCNTargetMachine::createDefaultFuncInfoYAML
yaml::MachineFunctionInfo * createDefaultFuncInfoYAML() const override
Allocate and return a default initialized instance of the YAML representation for the MachineFunction...
Definition: AMDGPUTargetMachine.cpp:1409