LLVM 17.0.0git
M68kSubtarget.cpp
Go to the documentation of this file.
1//===-- M68kSubtarget.cpp - M68k Subtarget Information ----------*- 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 implements the M68k specific subclass of TargetSubtargetInfo.
11///
12//===----------------------------------------------------------------------===//
13
14#include "M68kSubtarget.h"
18
19#include "M68k.h"
20#include "M68kMachineFunction.h"
21#include "M68kRegisterInfo.h"
22#include "M68kTargetMachine.h"
23
25#include "llvm/IR/Attributes.h"
26#include "llvm/IR/Function.h"
30
31using namespace llvm;
32
33#define DEBUG_TYPE "m68k-subtarget"
34
35#define GET_SUBTARGETINFO_TARGET_DESC
36#define GET_SUBTARGETINFO_CTOR
37#include "M68kGenSubtargetInfo.inc"
38
39extern bool FixGlobalBaseReg;
40
41/// Select the M68k CPU for the given triple and cpu name.
43 if (CPU.empty() || CPU == "generic") {
44 CPU = "M68000";
45 }
46 return CPU;
47}
48
49void M68kSubtarget::anchor() {}
50
52 const M68kTargetMachine &TM)
53 : M68kGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), TM(TM), TSInfo(),
54 InstrInfo(initializeSubtargetDependencies(CPU, TT, FS, TM)),
55 FrameLowering(*this, this->getStackAlignment()), TLInfo(TM, *this),
56 TargetTriple(TT) {
58 Legalizer.reset(new M68kLegalizerInfo(*this));
59
60 auto *RBI = new M68kRegisterBankInfo(*getRegisterInfo());
61 RegBankInfo.reset(RBI);
63}
64
66 return CallLoweringInfo.get();
67}
68
70 return InstSelector.get();
71}
72
74 return Legalizer.get();
75}
76
78 return RegBankInfo.get();
79}
80
83}
84
85bool M68kSubtarget::isLegalToCallImmediateAddr() const { return true; }
86
87bool M68kSubtarget::abiUsesSoftFloat() const { return true; }
88
90 StringRef CPU, Triple TT, StringRef FS, const M68kTargetMachine &TM) {
91 std::string CPUName = selectM68kCPU(TT, CPU).str();
92
93 // Parse features string.
94 ParseSubtargetFeatures(CPUName, CPUName, FS);
95
96 // Initialize scheduling itinerary for the specified CPU.
97 InstrItins = getInstrItineraryForCPU(CPUName);
98
100
101 return *this;
102}
103
104//===----------------------------------------------------------------------===//
105// Code Model
106//
107// Key assumptions:
108// - Whenever possible we use pc-rel encoding since it is smaller(16 bit) than
109// absolute(32 bit).
110// - GOT is reachable within 16 bit offset for both Small and Medium models.
111// - Code section is reachable within 16 bit offset for both models.
112//
113// ---------------------+-------------------------+--------------------------
114// | Small | Medium
115// +-------------------------+------------+-------------
116// | Static | PIC | Static | PIC
117// ---------------------+------------+------------+------------+-------------
118// branch | pc-rel | pc-rel | pc-rel | pc-rel
119// ---------------------+------------+------------+------------+-------------
120// call global | @PLT | @PLT | @PLT | @PLT
121// ---------------------+------------+------------+------------+-------------
122// call internal | pc-rel | pc-rel | pc-rel | pc-rel
123// ---------------------+------------+------------+------------+-------------
124// data local | pc-rel | pc-rel | ~pc-rel | ^pc-rel
125// ---------------------+------------+------------+------------+-------------
126// data local big* | pc-rel | pc-rel | absolute | @GOTOFF
127// ---------------------+------------+------------+------------+-------------
128// data global | pc-rel | @GOTPCREL | ~pc-rel | @GOTPCREL
129// ---------------------+------------+------------+------------+-------------
130// data global big* | pc-rel | @GOTPCREL | absolute | @GOTPCREL
131// ---------------------+------------+------------+------------+-------------
132//
133// * Big data potentially cannot be reached within 16 bit offset and requires
134// special handling for old(x00 and x10) CPUs. Normally these symbols go into
135// separate .ldata section which mapped after normal .data and .text, but I
136// don't really know how this must be done for M68k atm... will try to dig
137// this info out from GCC. For now CPUs prior to M68020 will use static ref
138// for Static Model and @GOT based references for PIC.
139//
140// ~ These are absolute for older CPUs for now.
141// ^ These are @GOTOFF for older CPUs for now.
142//===----------------------------------------------------------------------===//
143
144/// Classify a blockaddress reference for the current subtarget according to how
145/// we should reference it in a non-pcrel context.
147 // Unless we start to support Large Code Model branching is always pc-rel
149}
150
151unsigned char
153 switch (TM.getCodeModel()) {
154 default:
155 llvm_unreachable("Unsupported code model");
156 case CodeModel::Small:
157 case CodeModel::Kernel: {
159 }
160 case CodeModel::Medium: {
161 if (isPositionIndependent()) {
162 // On M68020 and better we can fit big any data offset into dips field.
163 if (atLeastM68020()) {
165 }
166 // Otherwise we could check the data size and make sure it will fit into
167 // 16 bit offset. For now we will be conservative and go with @GOTOFF
168 return M68kII::MO_GOTOFF;
169 } else {
170 if (atLeastM68020()) {
172 }
174 }
175 }
176 }
177}
178
180 if (TM.shouldAssumeDSOLocal(M, nullptr))
181 return classifyLocalReference(nullptr);
182
184 return M68kII::MO_GOTPCREL;
185
186 return M68kII::MO_GOT;
187}
188
189unsigned char
191 return classifyGlobalReference(GV, *GV->getParent());
192}
193
195 const Module &M) const {
196 if (TM.shouldAssumeDSOLocal(M, GV))
197 return classifyLocalReference(GV);
198
199 switch (TM.getCodeModel()) {
200 default:
201 llvm_unreachable("Unsupported code model");
202 case CodeModel::Small:
203 case CodeModel::Kernel: {
205 return M68kII::MO_GOTPCREL;
207 }
208 case CodeModel::Medium: {
210 return M68kII::MO_GOTPCREL;
211
212 if (atLeastM68020())
214
216 }
217 }
218}
219
221 if (isPositionIndependent()) {
222 // The only time we want to use GOTOFF(used when with EK_Custom32) is when
223 // the potential delta between the jump target and table base can be larger
224 // than displacement field, which is True for older CPUs(16 bit disp)
225 // in Medium model(can have large data way beyond 16 bit).
228
230 }
231
232 // In non-pic modes, just use the address of a block.
234}
235
236unsigned char
239}
240
241unsigned char
243 const Module &M) const {
244 // local always use pc-rel referencing
245 if (TM.shouldAssumeDSOLocal(M, GV))
246 return M68kII::MO_NO_FLAG;
247
248 // If the function is marked as non-lazy, generate an indirect call
249 // which loads from the GOT directly. This avoids run-time overhead
250 // at the cost of eager binding.
251 auto *F = dyn_cast_or_null<Function>(GV);
252 if (F && F->hasFnAttribute(Attribute::NonLazyBind)) {
253 return M68kII::MO_GOTPCREL;
254 }
255
256 // otherwise linker will figure this out
257 return M68kII::MO_PLT;
258}
This file contains the simple types necessary to represent the attributes associated with functions a...
This file implements the lowering of LLVM calls to machine code calls for GlobalISel.
This file declares the targeting of the MachineLegalizer class for M68k.
This file declares the M68k specific subclass of MachineFunctionInfo.
This file declares the targeting of the RegisterBankInfo class for M68k.
This file contains the M68k implementation of the TargetRegisterInfo class.
bool FixGlobalBaseReg
static StringRef selectM68kCPU(Triple TT, StringRef CPU)
Select the M68k CPU for the given triple and cpu name.
This file declares the M68k specific subclass of TargetSubtargetInfo.
This file declares the M68k specific subclass of TargetMachine.
This file contains the entry points for global functions defined in the M68k target library,...
#define F(x, y, z)
Definition: MD5.cpp:55
const char LLVMTargetMachineRef TM
return InstrInfo
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:652
Provides the logic to select generic machine instructions.
This class provides the information for the target register banks.
unsigned char classifyExternalReference(const Module &M) const
Classify a external variable reference for the current subtarget according to how we should reference...
InstrItineraryData InstrItins
Definition: M68kSubtarget.h:56
const M68kTargetLowering * getTargetLowering() const override
M68kSubtarget(const Triple &TT, StringRef CPU, StringRef FS, const M68kTargetMachine &_TM)
This constructor initializes the data members to match that of the specified triple.
unsigned char classifyBlockAddressReference() const
Classify a blockaddress reference for the current subtarget according to how we should reference it i...
const LegalizerInfo * getLegalizerInfo() const override
const RegisterBankInfo * getRegBankInfo() const override
bool isLegalToCallImmediateAddr() const
Return true if the subtarget allows calls to immediate address.
std::unique_ptr< CallLowering > CallLoweringInfo
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
Parses features string setting specified subtarget options.
const M68kTargetMachine & TM
Definition: M68kSubtarget.h:61
unsigned char classifyGlobalReference(const GlobalValue *GV, const Module &M) const
Classify a global variable reference for the current subtarget according to how we should reference i...
const CallLowering * getCallLowering() const override
unsigned getJumpTableEncoding() const
InstructionSelector * getInstructionSelector() const override
std::unique_ptr< RegisterBankInfo > RegBankInfo
unsigned char classifyLocalReference(const GlobalValue *GV) const
Classify a global variable reference for the current subtarget according to how we should reference i...
unsigned stackAlignment
The minimum alignment known to hold of the stack frame on entry to the function and which must be mai...
Definition: M68kSubtarget.h:70
const M68kRegisterInfo * getRegisterInfo() const override
bool abiUsesSoftFloat() const
bool atLeastM68020() const
Definition: M68kSubtarget.h:86
bool isPositionIndependent() const
M68kSubtarget & initializeSubtargetDependencies(StringRef CPU, Triple TT, StringRef FS, const M68kTargetMachine &TM)
unsigned char classifyGlobalFunctionReference(const GlobalValue *GV, const Module &M) const
Classify a global function reference for the current subtarget.
std::unique_ptr< InstructionSelector > InstSelector
@ EK_LabelDifference32
EK_LabelDifference32 - Each entry is the address of the block minus the address of the jump table.
@ EK_Custom32
EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the TargetLowering::LowerCustomJ...
@ EK_BlockAddress
EK_BlockAddress - Each entry is a plain address of block, e.g.: .word LBB123.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
Holds all the information related to register banks.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:222
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
bool isPositionIndependent() const
bool shouldAssumeDSOLocal(const Module &M, const GlobalValue *GV) const
CodeModel::Model getCodeModel() const
Returns the code model.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ MO_GOTOFF
On a symbol operand this indicates that the immediate is the offset to the location of the symbol nam...
Definition: M68kBaseInfo.h:121
@ MO_PLT
On a symbol operand this indicates that the immediate is offset to the PLT entry of symbol name from ...
Definition: M68kBaseInfo.h:133
@ MO_GOT
On a symbol operand this indicates that the immediate is the offset to the GOT entry for the symbol n...
Definition: M68kBaseInfo.h:115
@ MO_ABSOLUTE_ADDRESS
On a symbol operand this indicates that the immediate is the absolute address of the symbol.
Definition: M68kBaseInfo.h:105
@ MO_GOTPCREL
On a symbol operand this indicates that the immediate is offset to the GOT entry for the symbol name ...
Definition: M68kBaseInfo.h:127
@ MO_PC_RELATIVE_ADDRESS
On a symbol operand this indicates that the immediate is the pc-relative address of the symbol.
Definition: M68kBaseInfo.h:109
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
InstructionSelector * createM68kInstructionSelector(const M68kTargetMachine &TM, const M68kSubtarget &Subtarget, const M68kRegisterBankInfo &RBI)
This struct provides the information for the target register banks.