LLVM 24.0.0git
M68kTargetMachine.cpp
Go to the documentation of this file.
1//===-- M68kTargetMachine.cpp - M68k Target Machine -------------*- 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/// This file contains implementation for M68k target machine.
11///
12//===----------------------------------------------------------------------===//
13
14#include "M68kTargetMachine.h"
15#include "M68k.h"
16#include "M68kMachineFunction.h"
17#include "M68kSubtarget.h"
24#include "llvm/CodeGen/Passes.h"
29#include "llvm/PassRegistry.h"
30#include <memory>
31#include <optional>
32
33using namespace llvm;
34
35#define DEBUG_TYPE "m68k"
36
48
49namespace {
50
51Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {
52 // If not defined we default to static
53 return RM.value_or(Reloc::Static);
54}
55
56CodeModel::Model getEffectiveCodeModel(std::optional<CodeModel::Model> CM,
57 bool JIT) {
58 if (!CM) {
59 return CodeModel::Small;
60 } else if (CM == CodeModel::Kernel) {
61 llvm_unreachable("Kernel code model is not implemented yet");
62 }
63 return CM.value();
64}
65} // end anonymous namespace
66
68 StringRef CPU, StringRef FS,
70 std::optional<Reloc::Model> RM,
71 std::optional<CodeModel::Model> CM,
72 CodeGenOptLevel OL, bool JIT)
73 : CodeGenTargetMachineImpl(T, TT, CPU, FS, Options,
75 ::getEffectiveCodeModel(CM, JIT), OL),
76 CLOpts(cl::LibraryOptionsContext::get<M68kOptions>(
77 Options.MCOptions.LibraryOptions)),
78 TLOF(std::make_unique<M68kELFTargetObjectFile>()),
79 Subtarget(TT, CPU, FS, *this) {
81}
82
84
85const M68kSubtarget *
87 AttributeSet FnAttrs = F.getAttributes().getFnAttrs();
88 const Module *M = F.getParent();
89 if (const M68kSubtarget *ST = LastSubtarget.lookup(FnAttrs, M))
90 return ST;
91
92 SubtargetAttrs Attrs;
93 Attrs.CPU = FnAttrs.getAttribute("target-cpu");
94 Attrs.FS = FnAttrs.getAttribute("target-features");
95
96 if (const M68kSubtarget *ST = LastSubtarget.lookup(FnAttrs, M, Attrs))
97 return ST;
98
99 auto CPU =
100 Attrs.CPU.isValid() ? Attrs.CPU.getValueAsString().str() : TargetCPU;
101 auto FS = Attrs.FS.isValid() ? Attrs.FS.getValueAsString().str() : TargetFS;
102
103 auto &I = SubtargetMap[CPU + FS];
104 if (!I)
105 I = std::make_unique<M68kSubtarget>(TargetTriple, CPU, FS, *this);
106 LastSubtarget.set(FnAttrs, M, Attrs, I.get());
107 return I.get();
108}
109
116
117//===----------------------------------------------------------------------===//
118// Pass Pipeline Configuration
119//===----------------------------------------------------------------------===//
120
121namespace {
122class M68kPassConfig : public TargetPassConfig {
123public:
124 M68kPassConfig(M68kTargetMachine &TM, PassManagerBase &PM)
125 : TargetPassConfig(TM, PM) {}
126
127 M68kTargetMachine &getM68kTargetMachine() const {
129 }
130
131 const M68kSubtarget &getM68kSubtarget() const {
132 return *getM68kTargetMachine().getSubtargetImpl();
133 }
134 void addIRPasses() override;
135 bool addIRTranslator() override;
136 bool addLegalizeMachineIR() override;
137 bool addRegBankSelect() override;
138 bool addGlobalInstructionSelect() override;
139 bool addInstSelector() override;
140 void addPreSched2() override;
141 void addPreEmitPass() override;
142};
143} // namespace
144
146 return new M68kPassConfig(*this, PM);
147}
148
149void M68kPassConfig::addIRPasses() {
152}
153
154bool M68kPassConfig::addInstSelector() {
155 // Install an instruction selector.
156 addPass(createM68kISelDag(getM68kTargetMachine()));
158 return false;
159}
160
161bool M68kPassConfig::addIRTranslator() {
162 addPass(new IRTranslatorLegacy());
163 return false;
164}
165
166bool M68kPassConfig::addLegalizeMachineIR() {
167 addPass(new LegalizerLegacy());
168 return false;
169}
170
171bool M68kPassConfig::addRegBankSelect() {
172 addPass(new RegBankSelectLegacy());
173 return false;
174}
175
176bool M68kPassConfig::addGlobalInstructionSelect() {
177 addPass(new InstructionSelectLegacy(getOptLevel()));
178 return false;
179}
180
181void M68kPassConfig::addPreSched2() { addPass(createM68kExpandPseudoPass()); }
182
183void M68kPassConfig::addPreEmitPass() {
185}
static Reloc::Model getEffectiveRelocModel()
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
This file declares the IRTranslator pass.
This file declares the M68k specific subclass of MachineFunctionInfo.
This file declares the M68k specific subclass of TargetSubtargetInfo.
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeM68kTarget()
This file declares the M68k specific subclass of TargetMachine.
This file contains declarations for M68k ELF object file lowering.
This file contains the entry points for global functions defined in the M68k target library,...
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define T
This file describes the interface of the MachineFunctionPass responsible for assigning the generic vi...
const GCNTargetMachine & getTM(const GCNSubtarget *STI)
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:445
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)
This pass is responsible for selecting generic machine instructions to target-specific instructions.
const M68kSubtarget * getSubtargetImpl() const
MachineFunctionInfo * createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F, const TargetSubtargetInfo *STI) const override
Create the target's instance of MachineFunctionInfo.
M68kTargetMachine(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)
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This pass implements the reg bank selector pass used in the GlobalISel pipeline.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with.
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.
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.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This namespace contains all of the command line option processing machinery.
This is an optimization pass for GlobalISel generic memory operations.
void initializeM68kGlobalBaseRegPass(PassRegistry &)
void initializeM68kExpandPseudoPass(PassRegistry &)
void initializeM68kCollapseMOVEMPass(PassRegistry &)
FunctionPass * createM68kGlobalBaseRegPass()
This pass initializes a global base register for PIC on M68k.
static Reloc::Model getEffectiveRelocModel(std::optional< Reloc::Model > RM)
CodeModel::Model getEffectiveCodeModel(std::optional< CodeModel::Model > CM, CodeModel::Model Default)
Helper method for getting the code model, returning Default if CM does not have a value.
FunctionPass * createM68kCollapseMOVEMPass()
Finds sequential MOVEM instruction and collapse them into a single one.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
FunctionPass * createM68kISelDag(M68kTargetMachine &TM)
This pass converts a legalized DAG into a M68k-specific DAG, ready for instruction scheduling.
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:280
void initializeM68kDAGToDAGISelLegacyPass(PassRegistry &)
LLVM_ABI void initializeGlobalISel(PassRegistry &)
Initialize all passes linked into the GlobalISel library.
Target & getTheM68kTarget()
FunctionPass * createM68kExpandPseudoPass()
Return a Machine IR pass that expands M68k-specific pseudo instructions into a sequence of actual ins...
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
void initializeM68kAsmPrinterPass(PassRegistry &)
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,...