LLVM 22.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"
28#include "llvm/PassRegistry.h"
29#include <memory>
30#include <optional>
31
32using namespace llvm;
33
34#define DEBUG_TYPE "m68k"
35
46
47namespace {
48
49Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {
50 // If not defined we default to static
51 return RM.value_or(Reloc::Static);
52}
53
54CodeModel::Model getEffectiveCodeModel(std::optional<CodeModel::Model> CM,
55 bool JIT) {
56 if (!CM) {
57 return CodeModel::Small;
58 } else if (CM == CodeModel::Kernel) {
59 llvm_unreachable("Kernel code model is not implemented yet");
60 }
61 return CM.value();
62}
63} // end anonymous namespace
64
66 StringRef CPU, StringRef FS,
68 std::optional<Reloc::Model> RM,
69 std::optional<CodeModel::Model> CM,
70 CodeGenOptLevel OL, bool JIT)
71 : CodeGenTargetMachineImpl(T, TT.computeDataLayout(), TT, CPU, FS, Options,
73 ::getEffectiveCodeModel(CM, JIT), OL),
74 TLOF(std::make_unique<M68kELFTargetObjectFile>()),
75 Subtarget(TT, CPU, FS, *this) {
77}
78
80
81const M68kSubtarget *
83 Attribute CPUAttr = F.getFnAttribute("target-cpu");
84 Attribute FSAttr = F.getFnAttribute("target-features");
85
86 auto CPU = CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
87 auto FS = FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
88
89 auto &I = SubtargetMap[CPU + FS];
90 if (!I) {
91 // This needs to be done before we create a new subtarget since any
92 // creation will depend on the TM and the code generation flags on the
93 // function that reside in TargetOptions.
95 I = std::make_unique<M68kSubtarget>(TargetTriple, CPU, FS, *this);
96 }
97 return I.get();
98}
99
106
107//===----------------------------------------------------------------------===//
108// Pass Pipeline Configuration
109//===----------------------------------------------------------------------===//
110
111namespace {
112class M68kPassConfig : public TargetPassConfig {
113public:
114 M68kPassConfig(M68kTargetMachine &TM, PassManagerBase &PM)
115 : TargetPassConfig(TM, PM) {}
116
117 M68kTargetMachine &getM68kTargetMachine() const {
119 }
120
121 const M68kSubtarget &getM68kSubtarget() const {
122 return *getM68kTargetMachine().getSubtargetImpl();
123 }
124 void addIRPasses() override;
125 bool addIRTranslator() override;
126 bool addLegalizeMachineIR() override;
127 bool addRegBankSelect() override;
128 bool addGlobalInstructionSelect() override;
129 bool addInstSelector() override;
130 void addPreSched2() override;
131 void addPreEmitPass() override;
132};
133} // namespace
134
136 return new M68kPassConfig(*this, PM);
137}
138
139void M68kPassConfig::addIRPasses() {
142}
143
144bool M68kPassConfig::addInstSelector() {
145 // Install an instruction selector.
146 addPass(createM68kISelDag(getM68kTargetMachine()));
148 return false;
149}
150
151bool M68kPassConfig::addIRTranslator() {
152 addPass(new IRTranslator());
153 return false;
154}
155
156bool M68kPassConfig::addLegalizeMachineIR() {
157 addPass(new Legalizer());
158 return false;
159}
160
161bool M68kPassConfig::addRegBankSelect() {
162 addPass(new RegBankSelect());
163 return false;
164}
165
166bool M68kPassConfig::addGlobalInstructionSelect() {
167 addPass(new InstructionSelect());
168 return false;
169}
170
171void M68kPassConfig::addPreSched2() { addPass(createM68kExpandPseudoPass()); }
172
173void M68kPassConfig::addPreEmitPass() {
175}
static Reloc::Model getEffectiveRelocModel()
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
DXIL Legalizer
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:55
#define I(x, y, z)
Definition MD5.cpp:58
#define T
This file describes the interface of the MachineFunctionPass responsible for assigning the generic vi...
const GCNTargetMachine & getTM(const GCNSubtarget *STI)
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)
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 ...
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.
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:225
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with.
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 ...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
FunctionPass * createM68kISelDag(M68kTargetMachine &TM)
This pass converts a legalized DAG into a M68k-specific DAG, ready for instruction scheduling.
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
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,...
void initializeM68kAsmPrinterPass(PassRegistry &)
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:867
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,...