LLVM 24.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 "llvm/MC/MCStreamer.h"
22#include <optional>
23#include <utility>
24
25namespace llvm {
26
27//===----------------------------------------------------------------------===//
28// AMDGPU Target Machine (R600+)
29//===----------------------------------------------------------------------===//
30
31namespace AMDGPU {
32StringRef getSchedStrategy(const AMDGPUOptions &CLOpts, const Function &F);
33}
34
36protected:
37 const AMDGPUOptions &CLOpts;
38 std::unique_ptr<TargetLoweringObjectFile> TLOF;
39
40public:
44
45 AMDGPUTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
47 std::optional<Reloc::Model> RM,
48 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL);
50
51 const AMDGPUOptions &getCLOpts() const { return CLOpts; }
52
54 getSubtargetImpl(const Function &) const override = 0;
55
57 return TLOF.get();
58 }
59
62
63 bool isNoopAddrSpaceCast(const DataLayout &DL, unsigned SrcAS,
64 unsigned DestAS) const override;
65
66 unsigned getAssumedAddrSpace(const Value *V) const override;
67
68 std::pair<const Value *, unsigned>
69 getPredicatedAddrSpace(const Value *V) const override;
70
71 unsigned getAddressSpaceForPseudoSourceKind(unsigned Kind) const override;
72
73 bool splitModule(Module &M, unsigned NumParts,
74 function_ref<void(std::unique_ptr<Module> MPart)>
75 ModuleCallback) override;
78};
79
80//===----------------------------------------------------------------------===//
81// GCN Target Machine (SI+)
82//===----------------------------------------------------------------------===//
83
85private:
86 mutable StringMap<std::unique_ptr<GCNSubtarget>> SubtargetMap;
87
88 /// The attributes that select a subtarget.
89 struct SubtargetAttrs {
90 Attribute GPU, FS;
91 bool BufRelaxed = false;
92 bool TBufRelaxed = false;
93 AMDGPU::TargetIDSetting Xnack = AMDGPU::TargetIDSetting::Any;
94 AMDGPU::TargetIDSetting SramEcc = AMDGPU::TargetIDSetting::Any;
95
96 bool operator==(const SubtargetAttrs &RHS) const {
97 return GPU == RHS.GPU && FS == RHS.FS && BufRelaxed == RHS.BufRelaxed &&
98 TBufRelaxed == RHS.TBufRelaxed && Xnack == RHS.Xnack &&
99 SramEcc == RHS.SramEcc;
100 }
101
102 bool operator!=(const SubtargetAttrs &RHS) const { return !(*this == RHS); }
103 };
105
106public:
107 GCNTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
109 std::optional<Reloc::Model> RM,
110 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
111 bool JIT);
112
114
115 const TargetSubtargetInfo *getSubtargetImpl(const Function &) const override;
116
118
119 bool useIPRA() const override { return true; }
120
123 CodeGenFileType FileType,
124 const CGPassBuilderOption &Opts, MCContext &Ctx,
126
128
129 /// Get xnack/sramecc setting from module flag or command line option (for
130 /// testing).
131 /// Returns Any if not specified.
133 getTargetIDSettingFromModuleFlag(const Module &M, StringRef FlagName) const;
134
137 const TargetSubtargetInfo *STI) const override;
138
141 convertFuncInfoToYAML(const MachineFunction &MF) const override;
145 SMRange &SourceRange) const override;
150};
151
152//===----------------------------------------------------------------------===//
153// AMDGPU Pass Setup - For Legacy Pass Manager.
154//===----------------------------------------------------------------------===//
155
157protected:
158 const AMDGPUOptions &CLOpts;
159
160public:
162
168 void addIRPasses() override;
169 void addCodeGenPrepare() override;
170 bool addPreISel() override;
171 bool addInstSelector() override;
172 bool addGCPasses() override;
173
174 std::unique_ptr<CSEConfigBase> getCSEConfig() const override;
175
176 /// Check if a pass is enabled given \p Opt option. The option always
177 /// overrides defaults if explicitly used. Otherwise the pass is enabled at an
178 /// optimization \p Level minimum.
181 return valueOr(Opt, TM->getOptLevel() >= Level);
182 }
183};
184
185} // end namespace llvm
186
187#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETMACHINE_H
unsigned NumParts
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
AMD GCN specific subclass of TargetSubtarget.
Cache of the last subtarget a TargetMachine returned, to skip building the subtarget key for consecut...
#define F(x, y, z)
Definition MD5.cpp:54
#define T
ModuleAnalysisManager MAM
PassBuilder PB(Mod->getContext(), Machine, PassOpts->PTO, std::nullopt, &PIC)
PassInstrumentationCallbacks PIC
Basic Register Allocator
Target-Independent Code Generator Pass Configuration Options pass.
Value * RHS
A manager for alias analyses.
AMDGPUTargetMachine & getAMDGPUTargetMachine() const
std::unique_ptr< CSEConfigBase > getCSEConfig() const override
Returns the CSEConfig object to use for the current optimization level.
const AMDGPUOptions & CLOpts
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)
bool isPassEnabled(BoolOrDefault Opt, CodeGenOptLevel Level=CodeGenOptLevel::Default) const
Check if a pass is enabled given Opt option.
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.
std::unique_ptr< TargetLoweringObjectFile > TLOF
unsigned getAddressSpaceForPseudoSourceKind(unsigned Kind) const override
getAddressSpaceForPseudoSourceKind - Given the kind of memory (e.g.
TargetLoweringObjectFile * getObjFileLowering() const override
bool isNoopAddrSpaceCast(const DataLayout &DL, unsigned SrcAS, unsigned DestAS) const override
Returns true if a cast between SrcAS and DestAS is a noop.
void registerDefaultAliasAnalyses(AAManager &) override
Allow the target to register alias analyses with the AAManager for use with the new pass manager.
std::pair< const Value *, unsigned > getPredicatedAddrSpace(const Value *V) const override
If the specified predicate checks whether a generic pointer falls within a specified address space,...
ScheduleDAGInstrs * createMachineScheduler(MachineSchedContext *C) const override
Create an instance of ScheduleDAGInstrs to be run within the standard MachineScheduler pass for this ...
const AMDGPUOptions & CLOpts
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)
const AMDGPUOptions & getCLOpts() const
void registerPassBuilderCallbacks(PassBuilder &PB) override
Allow the target to modify the pass pipeline.
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.
const TargetSubtargetInfo * getSubtargetImpl(const Function &) const override=0
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:107
CodeGenTargetMachineImpl(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, CodeGenOptLevel OL)
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
Get a TargetTransformInfo implementation for the target.
const TargetSubtargetInfo * getSubtargetImpl(const Function &) const override
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
ScheduleDAGInstrs * createPostMachineScheduler(MachineSchedContext *C) const override
Similar to createMachineScheduler but used when postRA machine scheduling is enabled.
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 ...
bool useIPRA() const override
True if the target wants to use interprocedural register allocation by default.
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)
AMDGPU::TargetIDSetting getTargetIDSettingFromModuleFlag(const Module &M, StringRef FlagName) const
Get xnack/sramecc setting from module flag or command line option (for testing).
MachineFunctionInfo * createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F, const TargetSubtargetInfo *STI) const override
Create the target's instance of MachineFunctionInfo.
Cache of the last subtarget returned by getSubtargetImpl.
Context object for machine code objects.
Definition MCContext.h:84
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 ...
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition SourceMgr.h:307
Represents a range in source code.
Definition SMLoc.h:47
A ScheduleDAG for scheduling lists of MachineInstr.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:129
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Primary interface to the complete machine description for the target machine.
std::unique_ptr< const MCSubtargetInfo > STI
TargetOptions Options
Target-Independent Code Generator Pass Configuration Options.
TargetPassConfig(TargetMachine &TM, PassManagerBase &PM)
TMC & getTM() const
Get the right type of TargetMachine for this target.
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
LLVM Value Representation.
Definition Value.h:75
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.
StringRef getSchedStrategy(const AMDGPUOptions &CLOpts, const Function &F)
This is an optimization pass for GlobalISel generic memory operations.
bool operator!=(uint64_t V1, const APInt &V2)
Definition APInt.h:2139
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition CodeGen.h:309
PassManager< Module > ModulePassManager
Convenience typedef for a pass manager over modules.
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:280
@ Default
-O2, -Os, -Oz
Definition CodeGen.h:283
constexpr bool valueOr(BoolOrDefault X, bool Default)
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:391
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.