LLVM 24.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"
19#include "llvm/CodeGen/Passes.h"
24#include <optional>
25using namespace llvm;
26
39
40static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {
41 return RM.value_or(Reloc::Static);
42}
43
44// Code models. Some only make sense for 64-bit code.
45//
46// SunCC Reloc CodeModel Constraints
47// abs32 Static Small text+data+bss linked below 2^32 bytes
48// abs44 Static Medium text+data+bss linked below 2^44 bytes
49// abs64 Static Large text smaller than 2^31 bytes
50// pic13 PIC_ Small GOT < 2^13 bytes
51// pic32 PIC_ Medium GOT < 2^32 bytes
52//
53// All code models require that the text segment is smaller than 2GB.
55getEffectiveSparcCodeModel(std::optional<CodeModel::Model> CM, Reloc::Model RM,
56 bool Is64Bit, bool JIT) {
57 if (CM) {
58 if (*CM == CodeModel::Tiny)
59 report_fatal_error("Target does not support the tiny CodeModel", false);
60 if (*CM == CodeModel::Kernel)
61 report_fatal_error("Target does not support the kernel CodeModel", false);
62 return *CM;
63 }
64 if (Is64Bit) {
65 if (JIT)
66 return CodeModel::Large;
68 }
69 return CodeModel::Small;
70}
71
72/// Create an ILP32 architecture model
74 StringRef CPU, StringRef FS,
76 std::optional<Reloc::Model> RM,
77 std::optional<CodeModel::Model> CM,
78 CodeGenOptLevel OL, bool JIT)
80 T, TT, CPU, FS, Options, getEffectiveRelocModel(RM),
82 TT.isSPARC64(), JIT),
83 OL),
84 CLOpts(SparcOptions::Global),
85 TLOF(std::make_unique<SparcELFTargetObjectFile>()) {
87}
88
90
91const SparcSubtarget *
93 Attribute CPUAttr = F.getFnAttribute("target-cpu");
94 Attribute TuneAttr = F.getFnAttribute("tune-cpu");
95 Attribute FSAttr = F.getFnAttribute("target-features");
96
97 std::string CPU =
98 CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
99 std::string TuneCPU =
100 TuneAttr.isValid() ? TuneAttr.getValueAsString().str() : CPU;
101 std::string FS =
102 FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
103
104 // FIXME: This is related to the code below to reset the target options,
105 // we need to know whether or not the soft float flag is set on the
106 // function, so we can enable it as a subtarget feature.
107 bool softFloat = F.getFnAttribute("use-soft-float").getValueAsBool();
108
109 if (softFloat)
110 FS += FS.empty() ? "+soft-float" : ",+soft-float";
111
112 auto &I = SubtargetMap[CPU + FS];
113 if (!I)
114 I = std::make_unique<SparcSubtarget>(CPU, TuneCPU, FS, *this);
115 return I.get();
116}
117
124
125namespace {
126/// Sparc Code Generator Pass Configuration Options.
127class SparcPassConfig : public TargetPassConfig {
128public:
129 SparcPassConfig(SparcTargetMachine &TM, PassManagerBase &PM)
130 : TargetPassConfig(TM, PM) {}
131
132 SparcTargetMachine &getSparcTargetMachine() const {
134 }
135
136 void addIRPasses() override;
137 bool addInstSelector() override;
138 void addPreEmitPass() override;
139};
140} // namespace
141
143 return new SparcPassConfig(*this, PM);
144}
145
148 return TargetTransformInfo(std::make_unique<SparcTTIImpl>(this, F));
149}
150
151void SparcPassConfig::addIRPasses() {
153
155}
156
157bool SparcPassConfig::addInstSelector() {
158 addPass(createSparcISelDag(getSparcTargetMachine()));
159 return false;
160}
161
162void SparcPassConfig::addPreEmitPass(){
163 if (getSparcTargetMachine().getCLOpts().enable_branch_relax)
164 addPass(&BranchRelaxationPassID);
165
167 addPass(new InsertNOPLoad());
168 addPass(new DetectRoundChange());
169 addPass(new FixAllFDIVSQRT());
170 addPass(new ErrataWorkaround());
171}
172
173void SparcV8TargetMachine::anchor() { }
174
176 StringRef CPU, StringRef FS,
177 const TargetOptions &Options,
178 std::optional<Reloc::Model> RM,
179 std::optional<CodeModel::Model> CM,
180 CodeGenOptLevel OL, bool JIT)
181 : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT) {}
182
183void SparcV9TargetMachine::anchor() { }
184
186 StringRef CPU, StringRef FS,
187 const TargetOptions &Options,
188 std::optional<Reloc::Model> RM,
189 std::optional<CodeModel::Model> CM,
190 CodeGenOptLevel OL, bool JIT)
191 : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT) {}
192
193void SparcelTargetMachine::anchor() {}
194
196 StringRef CPU, StringRef FS,
197 const TargetOptions &Options,
198 std::optional<Reloc::Model> RM,
199 std::optional<CodeModel::Model> CM,
200 CodeGenOptLevel OL, bool JIT)
201 : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT) {}
static Reloc::Model getEffectiveRelocModel()
#define X(NUM, ENUM, NAME)
Definition ELF.h:857
#define LLVM_ABI
Definition Compiler.h:215
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define T
const GCNTargetMachine & getTM(const GCNSubtarget *STI)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSparcTarget()
static CodeModel::Model getEffectiveSparcCodeModel(std::optional< CodeModel::Model > CM, Reloc::Model RM, bool Is64Bit, bool JIT)
This file a TargetTransformInfoImplBase conforming object specific to the SPARC target machine.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
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:106
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:266
CodeGenTargetMachineImpl(const Target &T, 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.
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
Get a TargetTransformInfo implementation for the target.
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)
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::string str() const
Get the contents as an std::string.
Definition StringRef.h:222
std::unique_ptr< const MCSubtargetInfo > STI
TargetOptions Options
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.
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
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
Registers T::Global with cl::ParseCommandLineOptions.
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:163
void initializeErrataWorkaroundPass(PassRegistry &)
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:227
Target & getTheSparcV9Target()
@ Global
Append to llvm.global_dtors.
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,...
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:390
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:878
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,...