LLVM 22.0.0git
SparcTargetMachine.cpp
Go to the documentation of this file.
1//===-- SparcTargetMachine.cpp - Define TargetMachine for Sparc -----------===//
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//
10//===----------------------------------------------------------------------===//
11
12#include "SparcTargetMachine.h"
13#include "LeonPasses.h"
14#include "Sparc.h"
18#include "llvm/CodeGen/Passes.h"
22#include <optional>
23using namespace llvm;
24
36
37static cl::opt<bool>
38 BranchRelaxation("sparc-enable-branch-relax", cl::Hidden, cl::init(true),
39 cl::desc("Relax out of range conditional branches"));
40
41static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {
42 return RM.value_or(Reloc::Static);
43}
44
45// Code models. Some only make sense for 64-bit code.
46//
47// SunCC Reloc CodeModel Constraints
48// abs32 Static Small text+data+bss linked below 2^32 bytes
49// abs44 Static Medium text+data+bss linked below 2^44 bytes
50// abs64 Static Large text smaller than 2^31 bytes
51// pic13 PIC_ Small GOT < 2^13 bytes
52// pic32 PIC_ Medium GOT < 2^32 bytes
53//
54// All code models require that the text segment is smaller than 2GB.
56getEffectiveSparcCodeModel(std::optional<CodeModel::Model> CM, Reloc::Model RM,
57 bool Is64Bit, bool JIT) {
58 if (CM) {
59 if (*CM == CodeModel::Tiny)
60 report_fatal_error("Target does not support the tiny CodeModel", false);
61 if (*CM == CodeModel::Kernel)
62 report_fatal_error("Target does not support the kernel CodeModel", false);
63 return *CM;
64 }
65 if (Is64Bit) {
66 if (JIT)
67 return CodeModel::Large;
69 }
70 return CodeModel::Small;
71}
72
73/// Create an ILP32 architecture model
75 StringRef CPU, StringRef FS,
77 std::optional<Reloc::Model> RM,
78 std::optional<CodeModel::Model> CM,
79 CodeGenOptLevel OL, bool JIT)
81 T, TT.computeDataLayout(), TT, CPU, FS, Options,
84 TT.isSPARC64(), JIT),
85 OL),
86 TLOF(std::make_unique<SparcELFTargetObjectFile>()) {
88}
89
91
92const SparcSubtarget *
94 Attribute CPUAttr = F.getFnAttribute("target-cpu");
95 Attribute TuneAttr = F.getFnAttribute("tune-cpu");
96 Attribute FSAttr = F.getFnAttribute("target-features");
97
98 std::string CPU =
99 CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
100 std::string TuneCPU =
101 TuneAttr.isValid() ? TuneAttr.getValueAsString().str() : CPU;
102 std::string FS =
103 FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
104
105 // FIXME: This is related to the code below to reset the target options,
106 // we need to know whether or not the soft float flag is set on the
107 // function, so we can enable it as a subtarget feature.
108 bool softFloat = F.getFnAttribute("use-soft-float").getValueAsBool();
109
110 if (softFloat)
111 FS += FS.empty() ? "+soft-float" : ",+soft-float";
112
113 auto &I = SubtargetMap[CPU + FS];
114 if (!I) {
115 // This needs to be done before we create a new subtarget since any
116 // creation will depend on the TM and the code generation flags on the
117 // function that reside in TargetOptions.
119 I = std::make_unique<SparcSubtarget>(CPU, TuneCPU, FS, *this);
120 }
121 return I.get();
122}
123
130
131namespace {
132/// Sparc Code Generator Pass Configuration Options.
133class SparcPassConfig : public TargetPassConfig {
134public:
135 SparcPassConfig(SparcTargetMachine &TM, PassManagerBase &PM)
136 : TargetPassConfig(TM, PM) {}
137
138 SparcTargetMachine &getSparcTargetMachine() const {
140 }
141
142 void addIRPasses() override;
143 bool addInstSelector() override;
144 void addPreEmitPass() override;
145};
146} // namespace
147
149 return new SparcPassConfig(*this, PM);
150}
151
152void SparcPassConfig::addIRPasses() {
154
156}
157
158bool SparcPassConfig::addInstSelector() {
159 addPass(createSparcISelDag(getSparcTargetMachine()));
160 return false;
161}
162
163void SparcPassConfig::addPreEmitPass(){
165 addPass(&BranchRelaxationPassID);
166
168 addPass(new InsertNOPLoad());
169 addPass(new DetectRoundChange());
170 addPass(new FixAllFDIVSQRT());
171 addPass(new ErrataWorkaround());
172}
173
174void SparcV8TargetMachine::anchor() { }
175
177 StringRef CPU, StringRef FS,
178 const TargetOptions &Options,
179 std::optional<Reloc::Model> RM,
180 std::optional<CodeModel::Model> CM,
181 CodeGenOptLevel OL, bool JIT)
182 : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT) {}
183
184void SparcV9TargetMachine::anchor() { }
185
187 StringRef CPU, StringRef FS,
188 const TargetOptions &Options,
189 std::optional<Reloc::Model> RM,
190 std::optional<CodeModel::Model> CM,
191 CodeGenOptLevel OL, bool JIT)
192 : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT) {}
193
194void SparcelTargetMachine::anchor() {}
195
197 StringRef CPU, StringRef FS,
198 const TargetOptions &Options,
199 std::optional<Reloc::Model> RM,
200 std::optional<CodeModel::Model> CM,
201 CodeGenOptLevel OL, bool JIT)
202 : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT) {}
static cl::opt< bool > BranchRelaxation("aarch64-enable-branch-relax", cl::Hidden, cl::init(true), cl::desc("Relax out of range conditional branches"))
#define LLVM_ABI
Definition Compiler.h:213
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
#define F(x, y, z)
Definition MD5.cpp:55
#define I(x, y, z)
Definition MD5.cpp:58
#define T
const GCNTargetMachine & getTM(const GCNSubtarget *STI)
static cl::opt< bool > BranchRelaxation("sparc-enable-branch-relax", cl::Hidden, cl::init(true), cl::desc("Relax out of range conditional branches"))
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSparcTarget()
static CodeModel::Model getEffectiveSparcCodeModel(std::optional< CodeModel::Model > CM, Reloc::Model RM, bool Is64Bit, bool JIT)
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
Target-Independent Code Generator Pass Configuration Options pass.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:69
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:223
CodeGenTargetMachineImpl(const Target &T, StringRef DataLayoutString, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, CodeGenOptLevel OL)
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...
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
SparcTargetMachine(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)
Create an ILP32 architecture model.
MachineFunctionInfo * createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F, const TargetSubtargetInfo *STI) const override
Create the target's instance of MachineFunctionInfo.
const SparcSubtarget * getSubtargetImpl(const Function &F) const override
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
~SparcTargetMachine() override
SparcV8TargetMachine(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)
SparcV9TargetMachine(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)
SparcelTargetMachine(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)
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
std::string str() const
str - Get the contents as an std::string.
Definition StringRef.h:233
std::unique_ptr< const MCSubtargetInfo > STI
TargetOptions Options
void resetTargetOptions(const Function &F) const
Reset the target options based on the function's attributes.
Target-Independent Code Generator Pass Configuration Options.
virtual void addIRPasses()
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
TargetSubtargetInfo - Generic base class for all target subtargets.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
void initializeSparcAsmPrinterPass(PassRegistry &)
Target & getTheSparcTarget()
static Reloc::Model getEffectiveRelocModel(std::optional< Reloc::Model > RM)
void initializeSparcDAGToDAGISelLegacyPass(PassRegistry &)
LLVM_ABI char & BranchRelaxationPassID
BranchRelaxation - This pass replaces branches that need to jump further than is supported by a branc...
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:167
void initializeErrataWorkaroundPass(PassRegistry &)
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:82
Target & getTheSparcV9Target()
FunctionPass * createSparcISelDag(SparcTargetMachine &TM)
createSparcISelDag - This pass converts a legalized DAG into a SPARC-specific DAG,...
Target & getTheSparcelTarget()
LLVM_ABI FunctionPass * createAtomicExpandLegacyPass()
AtomicExpandPass - At IR level this pass replace atomic instructions with __atomic_* library calls,...
FunctionPass * createSparcDelaySlotFillerPass()
createSparcDelaySlotFillerPass - Returns a pass that fills in delay slots in Sparc MachineFunctions
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:851
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.
RegisterTargetMachine - Helper template for registering a target machine implementation,...