LLVM 20.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
32protected:
33 std::unique_ptr<TargetLoweringObjectFile> TLOF;
34
35 StringRef getGPUName(const Function &F) const;
37
38public:
41
42 AMDGPUTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
44 std::optional<Reloc::Model> RM,
45 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL);
47
50 getSubtargetImpl(const Function &) const override = 0;
51
53 return TLOF.get();
54 }
55
58
59 /// Get the integer value of a null pointer in the given address space.
60 static int64_t getNullPointerValue(unsigned AddrSpace);
61
62 bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override;
63
64 unsigned getAssumedAddrSpace(const Value *V) const override;
65
66 std::pair<const Value *, unsigned>
67 getPredicatedAddrSpace(const Value *V) const override;
68
69 unsigned getAddressSpaceForPseudoSourceKind(unsigned Kind) const override;
70
71 bool splitModule(Module &M, unsigned NumParts,
72 function_ref<void(std::unique_ptr<Module> MPart)>
73 ModuleCallback) override;
74};
75
76//===----------------------------------------------------------------------===//
77// GCN Target Machine (SI+)
78//===----------------------------------------------------------------------===//
79
81private:
82 mutable StringMap<std::unique_ptr<GCNSubtarget>> SubtargetMap;
83
84public:
85 GCNTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
87 std::optional<Reloc::Model> RM,
88 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
89 bool JIT);
90
92
93 const TargetSubtargetInfo *getSubtargetImpl(const Function &) const override;
94
96
97 bool useIPRA() const override { return true; }
98
100 raw_pwrite_stream *DwoOut,
101 CodeGenFileType FileType,
102 const CGPassBuilderOption &Opts,
104
106
109 const TargetSubtargetInfo *STI) const override;
110
113 convertFuncInfoToYAML(const MachineFunction &MF) const override;
117 SMRange &SourceRange) const override;
118};
119
120//===----------------------------------------------------------------------===//
121// AMDGPU Pass Setup - For Legacy Pass Manager.
122//===----------------------------------------------------------------------===//
123
125public:
127
129 return getTM<AMDGPUTargetMachine>();
130 }
131
134
137 void addIRPasses() override;
138 void addCodeGenPrepare() override;
139 bool addPreISel() override;
140 bool addInstSelector() override;
141 bool addGCPasses() override;
142
143 std::unique_ptr<CSEConfigBase> getCSEConfig() const override;
144
145 /// Check if a pass is enabled given \p Opt option. The option always
146 /// overrides defaults if explicitly used. Otherwise its default will
147 /// be used given that a pass shall work at an optimization \p Level
148 /// minimum.
151 if (Opt.getNumOccurrences())
152 return Opt;
153 if (TM->getOptLevel() < Level)
154 return false;
155 return Opt;
156 }
157};
158
159//===----------------------------------------------------------------------===//
160// AMDGPU CodeGen Pass Builder interface.
161//===----------------------------------------------------------------------===//
162
164 : public CodeGenPassBuilder<AMDGPUCodeGenPassBuilder, GCNTargetMachine> {
166
167public:
169 const CGPassBuilderOption &Opts,
171
172 void addIRPasses(AddIRPass &) const;
173 void addCodeGenPrepare(AddIRPass &) const;
174 void addPreISel(AddIRPass &addPass) const;
175 void addILPOpts(AddMachinePass &) const;
176 void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const;
177 Error addInstSelector(AddMachinePass &) const;
178 void addMachineSSAOptimization(AddMachinePass &) const;
179
180 /// Check if a pass is enabled given \p Opt option. The option always
181 /// overrides defaults if explicitly used. Otherwise its default will be used
182 /// given that a pass shall work at an optimization \p Level minimum.
183 bool isPassEnabled(const cl::opt<bool> &Opt,
185 void addEarlyCSEOrGVNPass(AddIRPass &) const;
186 void addStraightLineScalarOptimizationPasses(AddIRPass &) const;
187};
188
189} // end namespace llvm
190
191#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETMACHINE_H
Interfaces for producing common pass manager configurations.
AMD GCN specific subclass of TargetSubtarget.
#define F(x, y, z)
Definition: MD5.cpp:55
PassInstrumentationCallbacks PIC
PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)
Basic Register Allocator
Target-Independent Code Generator Pass Configuration Options pass.
A manager for alias analyses.
Error addInstSelector(AddMachinePass &) const
void addMachineSSAOptimization(AddMachinePass &) const
void addEarlyCSEOrGVNPass(AddIRPass &) const
void addStraightLineScalarOptimizationPasses(AddIRPass &) const
void addPreISel(AddIRPass &addPass) const
void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const
void addCodeGenPrepare(AddIRPass &) const
void addILPOpts(AddMachinePass &) const
bool isPassEnabled(const cl::opt< bool > &Opt, CodeGenOptLevel Level=CodeGenOptLevel::Default) const
Check if a pass is enabled given Opt option.
AMDGPUTargetMachine & getAMDGPUTargetMachine() const
std::unique_ptr< CSEConfigBase > getCSEConfig() const override
Returns the CSEConfig object to use for the current optimization level.
ScheduleDAGInstrs * createMachineScheduler(MachineSchedContext *C) const override
Create an instance of ScheduleDAGInstrs to be run within the standard MachineScheduler pass for this ...
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.
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
static int64_t getNullPointerValue(unsigned AddrSpace)
Get the integer value of a null pointer in the given address space.
unsigned getAddressSpaceForPseudoSourceKind(unsigned Kind) const override
getAddressSpaceForPseudoSourceKind - Given the kind of memory (e.g.
const TargetSubtargetInfo * getSubtargetImpl() const
TargetLoweringObjectFile * getObjFileLowering() const override
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
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.
const TargetSubtargetInfo * getSubtargetImpl(const Function &) const override=0
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
This class provides access to building LLVM's passes.
std::function< Expected< std::unique_ptr< MCStreamer > >(MCContext &)> CreateMCStreamer
implements a set of functionality in the TargetMachine class for targets that make use of the indepen...
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
Get a TargetTransformInfo implementation for the target.
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.
Error buildCodeGenPipeline(ModulePassManager &MPM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, const CGPassBuilderOption &Opts, PassInstrumentationCallbacks *PIC) override
yaml::MachineFunctionInfo * createDefaultFuncInfoYAML() const override
Allocate and return a default initialized instance of the YAML representation for the MachineFunction...
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.
MachineFunctionInfo * createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F, const TargetSubtargetInfo *STI) const override
Create the target's instance of MachineFunctionInfo.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
This class provides access to building LLVM's passes.
Definition: PassBuilder.h:105
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:281
Represents a range in source code.
Definition: SMLoc.h:48
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:128
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
std::unique_ptr< const MCSubtargetInfo > STI
TargetOptions Options
Target-Independent Code Generator Pass Configuration Options.
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:44
LLVM Value Representation.
Definition: Value.h:74
int getNumOccurrences() const
Definition: CommandLine.h:399
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.
Definition: raw_ostream.h:434
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition: CodeGen.h:83
CodeGenOptLevel
Code generation optimization level.
Definition: CodeGen.h:54
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...
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.