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"
20#include "llvm/CodeGen/Passes.h"
25#include <optional>
26using namespace llvm;
27
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, CPU, FS, Options, getEffectiveRelocModel(RM),
83 TT.isSPARC64(), JIT),
84 OL),
85 CLOpts(cl::LibraryOptionsContext::get<SparcOptions>(
86 Options.MCOptions.LibraryOptions)),
87 TLOF(std::make_unique<SparcELFTargetObjectFile>()) {
89}
90
92
93const SparcSubtarget *
95 AttributeSet FnAttrs = F.getAttributes().getFnAttrs();
96 const Module *M = F.getParent();
97 if (const SparcSubtarget *ST = LastSubtarget.lookup(FnAttrs, M))
98 return ST;
99
100 SubtargetAttrs Attrs;
101 Attrs.CPU = FnAttrs.getAttribute("target-cpu");
102 Attrs.TuneCPU = FnAttrs.getAttribute("tune-cpu");
103 Attrs.FS = FnAttrs.getAttribute("target-features");
104 Attrs.SoftFloat = FnAttrs.getAttribute("use-soft-float");
105
106 if (const SparcSubtarget *ST = LastSubtarget.lookup(FnAttrs, M, Attrs))
107 return ST;
108
109 StringRef CPU =
110 Attrs.CPU.isValid() ? Attrs.CPU.getValueAsString() : StringRef(TargetCPU);
111 StringRef TuneCPU =
112 Attrs.TuneCPU.isValid() ? Attrs.TuneCPU.getValueAsString() : CPU;
113 StringRef FS =
114 Attrs.FS.isValid() ? Attrs.FS.getValueAsString() : StringRef(TargetFS);
115
116 SmallString<256> Key({CPU, TuneCPU});
117
118 // Keep track of the start of the feature portion of the string.
119 unsigned FSStart = Key.size();
120 Key += FS;
121
122 // FIXME: This is related to the code below to reset the target options,
123 // we need to know whether or not the soft float flag is set on the
124 // function, so we can enable it as a subtarget feature.
125 if (Attrs.SoftFloat.getValueAsBool())
126 Key += FS.empty() ? "+soft-float" : ",+soft-float";
127
128 auto &I = SubtargetMap[Key];
129 if (!I)
130 I = std::make_unique<SparcSubtarget>(CPU, TuneCPU, Key.substr(FSStart),
131 *this);
132 LastSubtarget.set(FnAttrs, M, Attrs, I.get());
133 return I.get();
134}
135
142
143namespace {
144/// Sparc Code Generator Pass Configuration Options.
145class SparcPassConfig : public TargetPassConfig {
146public:
147 SparcPassConfig(SparcTargetMachine &TM, PassManagerBase &PM)
148 : TargetPassConfig(TM, PM) {}
149
150 SparcTargetMachine &getSparcTargetMachine() const {
152 }
153
154 void addIRPasses() override;
155 bool addInstSelector() override;
156 void addPreEmitPass() override;
157};
158} // namespace
159
161 return new SparcPassConfig(*this, PM);
162}
163
166 return TargetTransformInfo(std::make_unique<SparcTTIImpl>(this, F));
167}
168
169void SparcPassConfig::addIRPasses() {
171
173}
174
175bool SparcPassConfig::addInstSelector() {
176 addPass(createSparcDAGToDAGISelLegacyPass(getSparcTargetMachine(),
177 getOptLevel()));
178 return false;
179}
180
181void SparcPassConfig::addPreEmitPass(){
182 if (getSparcTargetMachine().getCLOpts().enable_branch_relax)
183 addPass(&BranchRelaxationPassID);
184
186 addPass(new SparcErrataWorkaroundLegacy());
187}
188
189void SparcV8TargetMachine::anchor() { }
190
192 StringRef CPU, StringRef FS,
193 const TargetOptions &Options,
194 std::optional<Reloc::Model> RM,
195 std::optional<CodeModel::Model> CM,
196 CodeGenOptLevel OL, bool JIT)
197 : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT) {}
198
199void SparcV9TargetMachine::anchor() { }
200
202 StringRef CPU, StringRef FS,
203 const TargetOptions &Options,
204 std::optional<Reloc::Model> RM,
205 std::optional<CodeModel::Model> CM,
206 CodeGenOptLevel OL, bool JIT)
207 : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT) {}
208
209void SparcelTargetMachine::anchor() {}
210
212 StringRef CPU, StringRef FS,
213 const TargetOptions &Options,
214 std::optional<Reloc::Model> RM,
215 std::optional<CodeModel::Model> CM,
216 CodeGenOptLevel OL, bool JIT)
217 : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT) {}
static Reloc::Model getEffectiveRelocModel()
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
#define LLVM_ABI
Definition Compiler.h:211
#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)
This file defines the SmallString class.
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.
This class holds the attributes for a particular argument, parameter, function, or return value.
Definition Attributes.h:448
LLVM_ABI Attribute getAttribute(Attribute::AttrKind Kind) const
Return the attribute object.
CodeGenTargetMachineImpl(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, CodeGenOptLevel OL)
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
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...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:28
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::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 with cl::parseCommandLineOptions.
const AArch64MCOptions & getCLOpts(const MCTargetOptions &Options)
This namespace contains all of the command line option processing machinery.
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...
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
void initializeSparcErrataWorkaroundLegacyPass(PassRegistry &)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:280
Target & getTheSparcV9Target()
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
FunctionPass * createSparcDAGToDAGISelLegacyPass(SparcTargetMachine &TM, CodeGenOptLevel OptLevel)
createSparcISelDag - This pass converts a legalized DAG into a SPARC-specific DAG,...
FunctionPass * createSparcDelaySlotFillerLegacyPass()
createSparcDelaySlotFillerPass - Returns a pass that fills in delay slots in Sparc MachineFunctions
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:391
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879
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,...