LLVM 24.0.0git
MipsMachineFunction.cpp
Go to the documentation of this file.
1//===-- MipsMachineFunctionInfo.cpp - Private data used for Mips ----------===//
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
11#include "MipsSubtarget.h"
18
19using namespace llvm;
20
21static cl::opt<bool>
22FixGlobalBaseReg("mips-fix-global-base-reg", cl::Hidden, cl::init(true),
23 cl::desc("Always use $gp as the global base register."));
24
28 &Src2DstMBB) const {
29 return DestMF.cloneInfo<MipsFunctionInfo>(*this);
30}
31
33
35 return GlobalBaseReg;
36}
37
39 auto &STI = MF.getSubtarget<MipsSubtarget>();
40
41 if (STI.inMips16Mode())
42 return Mips::CPU16RegsRegClass;
43
44 if (STI.inMicroMipsMode())
45 return Mips::GPRMM16RegClass;
46
47 if (STI.getABI().IsN64())
48 return Mips::GPR64RegClass;
49
50 return Mips::GPR32RegClass;
51}
52
54 if (!GlobalBaseReg)
55 GlobalBaseReg =
57 return GlobalBaseReg;
58}
59
61 if (!GlobalBaseReg) {
64 }
65 return GlobalBaseReg;
66}
67
69 if (!GlobalBaseReg)
70 return;
71
74 MachineRegisterInfo &RegInfo = MF.getRegInfo();
77 const TargetRegisterClass *RC;
78 const MipsABIInfo &ABI = MF.getSubtarget<MipsSubtarget>().getABI();
79 RC = (ABI.IsN64()) ? &Mips::GPR64RegClass : &Mips::GPR32RegClass;
80
81 Register V0 = RegInfo.createVirtualRegister(RC);
82 Register V1 = RegInfo.createVirtualRegister(RC);
83
84 MCRegister T9 = ABI.getTempRegPtr(9);
85
86 if (ABI.IsN64()) {
87 MF.getRegInfo().addLiveIn(T9);
88 MBB.addLiveIn(T9);
89
90 // lui $v0, %hi(%neg(%gp_rel(fname)))
91 // daddu $v1, $v0, $t9
92 // daddiu $globalbasereg, $v1, %lo(%neg(%gp_rel(fname)))
93 const GlobalValue *FName = &MF.getFunction();
94 BuildMI(MBB, I, DL, TII.get(Mips::LUi64), V0)
96 BuildMI(MBB, I, DL, TII.get(Mips::DADDu), V1).addReg(V0).addReg(T9);
97 BuildMI(MBB, I, DL, TII.get(Mips::DADDiu), GlobalBaseReg).addReg(V1)
99 return;
100 }
101
102 if (!MF.getTarget().isPositionIndependent()) {
103 // Set global register to __gnu_local_gp.
104 //
105 // lui $v0, %hi(__gnu_local_gp)
106 // addiu $globalbasereg, $v0, %lo(__gnu_local_gp)
107 BuildMI(MBB, I, DL, TII.get(Mips::LUi), V0)
108 .addExternalSymbol("__gnu_local_gp", MipsII::MO_ABS_HI);
109 BuildMI(MBB, I, DL, TII.get(Mips::ADDiu), GlobalBaseReg).addReg(V0)
110 .addExternalSymbol("__gnu_local_gp", MipsII::MO_ABS_LO);
111 return;
112 }
113
114 MF.getRegInfo().addLiveIn(T9);
115 MBB.addLiveIn(T9);
116
117 if (ABI.IsN32()) {
118 // lui $v0, %hi(%neg(%gp_rel(fname)))
119 // addu $v1, $v0, $t9
120 // addiu $globalbasereg, $v1, %lo(%neg(%gp_rel(fname)))
121 const GlobalValue *FName = &MF.getFunction();
122 BuildMI(MBB, I, DL, TII.get(Mips::LUi), V0)
124 BuildMI(MBB, I, DL, TII.get(Mips::ADDu), V1).addReg(V0).addReg(T9);
125 BuildMI(MBB, I, DL, TII.get(Mips::ADDiu), GlobalBaseReg).addReg(V1)
127 return;
128 }
129
130 assert(ABI.IsO32());
131
132 // For O32 ABI, the following instruction sequence is emitted to initialize
133 // the global base register:
134 //
135 // 0. lui $2, %hi(_gp_disp)
136 // 1. addiu $2, $2, %lo(_gp_disp)
137 // 2. addu $globalbasereg, $2, $t9
138 //
139 // We emit only the last instruction here.
140 //
141 // GNU linker requires that the first two instructions appear at the beginning
142 // of a function and no instructions be inserted before or between them.
143 // The two instructions are emitted during lowering to MC layer in order to
144 // avoid any reordering.
145 //
146 // Register $2 (Mips::V0) is added to the list of live-in registers to ensure
147 // the value instruction 1 (addiu) defines is valid when instruction 2 (addu)
148 // reads it.
149 MF.getRegInfo().addLiveIn(Mips::V0);
150 MBB.addLiveIn(Mips::V0);
151 BuildMI(MBB, I, DL, TII.get(Mips::ADDu), GlobalBaseReg)
152 .addReg(Mips::V0)
153 .addReg(T9);
154}
155
158 for (int &I : EhDataRegFI) {
159 const TargetRegisterClass &RC =
160 MF.getSubtarget<MipsSubtarget>().getABI().IsN64() ? Mips::GPR64RegClass
161 : Mips::GPR32RegClass;
162
163 I = MF.getFrameInfo().CreateStackObject(TRI.getSpillSize(RC),
164 TRI.getSpillAlign(RC), false);
165 }
166}
167
169 // ISRs require spill slots for Status & ErrorPC Coprocessor 0 registers.
170 // The current implementation only supports Mips32r2+ not Mips64rX. Status
171 // is always 32 bits, ErrorPC is 32 or 64 bits dependent on architecture,
172 // however Mips32r2+ is the supported architecture.
173 const TargetRegisterClass &RC = Mips::GPR32RegClass;
175
176 for (int &I : ISRDataRegFI)
177 I = MF.getFrameInfo().CreateStackObject(TRI.getSpillSize(RC),
178 TRI.getSpillAlign(RC), false);
179}
180
182 return CallsEhReturn && (FI == EhDataRegFI[0] || FI == EhDataRegFI[1]
183 || FI == EhDataRegFI[2] || FI == EhDataRegFI[3]);
184}
185
187 return IsISR && (FI == ISRDataRegFI[0] || FI == ISRDataRegFI[1]);
188}
193
198
200 const TargetRegisterClass *RC) {
202 if (MoveF64ViaSpillFI == -1) {
203 MoveF64ViaSpillFI = MF.getFrameInfo().CreateStackObject(
204 TRI.getSpillSize(*RC), TRI.getSpillAlign(*RC), false);
205 }
206 return MoveF64ViaSpillFI;
207}
208
209void MipsFunctionInfo::anchor() {}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
const HexagonInstrInfo * TII
#define I(x, y, z)
Definition MD5.cpp:57
Register const TargetRegisterInfo * TRI
static cl::opt< bool > FixGlobalBaseReg("mips-fix-global-base-reg", cl::Hidden, cl::init(true), cl::desc("Always use $gp as the global base register."))
static const TargetRegisterClass & getGlobalBaseRegClass(MachineFunction &MF)
A debug info location.
Definition DebugLoc.h:126
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
MachineInstrBundleIterator< MachineInstr > iterator
LLVM_ABI int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it.
PseudoSourceValueManager & getPSVManager() const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * cloneInfo(const Ty &Old)
const MachineBasicBlock & front() const
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned TargetFlags=0) const
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned TargetFlags=0) const
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
void addLiveIn(MCRegister Reg, Register vreg=Register())
addLiveIn - Add the specified register as a live-in.
Register getGlobalBaseRegForGlobalISel(MachineFunction &MF)
MachinePointerInfo callPtrInfo(MachineFunction &MF, const char *ES)
Create a MachinePointerInfo that has an ExternalSymbolPseudoSourceValue object representing a GOT ent...
int getMoveF64ViaSpillFI(MachineFunction &MF, const TargetRegisterClass *RC)
Register getGlobalBaseReg(MachineFunction &MF)
MachineFunctionInfo * clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF, const DenseMap< MachineBasicBlock *, MachineBasicBlock * > &Src2DstMBB) const override
Make a functionally equivalent copy of this MachineFunctionInfo in MF.
MipsFunctionInfo(const Function &F, const TargetSubtargetInfo *STI)
bool isEhDataRegFI(int FI) const
void createEhDataRegsFI(MachineFunction &MF)
void initGlobalBaseReg(MachineFunction &MF)
~MipsFunctionInfo() override
void createISRRegFI(MachineFunction &MF)
LLVM_ABI const PseudoSourceValue * getExternalSymbolCallEntry(const char *ES)
LLVM_ABI const PseudoSourceValue * getGlobalValueCallEntry(const GlobalValue *GV)
Wrapper class representing virtual and physical registers.
Definition Register.h:20
TargetInstrInfo - Interface to description of machine instruction set.
bool isPositionIndependent() const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:390
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
This class contains a discriminated union of information about pointers in memory operands,...