33 cl::desc(
"Disable Sparc leaf procedure optimization."),
45 unsigned ADDri)
const {
51 if (NumBytes >= -4096 && NumBytes < 4096) {
52 BuildMI(MBB, MBBI, dl, TII.get(ADDri), SP::O6)
53 .addReg(SP::O6).
addImm(NumBytes);
64 BuildMI(MBB, MBBI, dl, TII.get(SP::SETHIi), SP::G1)
65 .addImm(
HI22(NumBytes));
66 BuildMI(MBB, MBBI, dl, TII.get(SP::ORri), SP::G1)
68 BuildMI(MBB, MBBI, dl, TII.get(ADDrr), SP::O6)
69 .addReg(SP::O6).
addReg(SP::G1);
77 BuildMI(MBB, MBBI, dl, TII.get(SP::SETHIi), SP::G1)
78 .addImm(
HIX22(NumBytes));
79 BuildMI(MBB, MBBI, dl, TII.get(SP::XORri), SP::G1)
81 BuildMI(MBB, MBBI, dl, TII.get(ADDrr), SP::O6)
82 .addReg(SP::O6).
addReg(SP::G1);
89 assert(&MF.
front() == &MBB &&
"Shrink-wrapping not yet supported");
100 bool NeedsStackRealignment = RegInfo.needsStackRealignment(MF);
109 "stack re-alignment, but LLVM couldn't handle it " 110 "(probably because it has a dynamic alloca).");
113 int NumBytes = (int) MFI.getStackSize();
115 unsigned SAVEri = SP::SAVEri;
116 unsigned SAVErr = SP::SAVErr;
141 NumBytes += MFI.getMaxCallFrameSize();
149 if (MFI.getMaxAlignment() > 0) {
150 NumBytes =
alignTo(NumBytes, MFI.getMaxAlignment());
154 MFI.setStackSize(NumBytes);
156 emitSPAdjustment(MF, MBB, MBBI, -NumBytes, SAVErr, SAVEri);
158 unsigned regFP = RegInfo.getDwarfRegNum(SP::I6,
true);
163 BuildMI(MBB, MBBI, dl, TII.
get(TargetOpcode::CFI_INSTRUCTION))
164 .addCFIIndex(CFIIndex);
168 BuildMI(MBB, MBBI, dl, TII.
get(TargetOpcode::CFI_INSTRUCTION))
169 .addCFIIndex(CFIIndex);
171 unsigned regInRA = RegInfo.getDwarfRegNum(SP::I7,
true);
172 unsigned regOutRA = RegInfo.getDwarfRegNum(SP::O7,
true);
176 BuildMI(MBB, MBBI, dl, TII.
get(TargetOpcode::CFI_INSTRUCTION))
177 .addCFIIndex(CFIIndex);
179 if (NeedsStackRealignment) {
181 unsigned regUnbiased;
184 regUnbiased = SP::G1;
186 BuildMI(MBB, MBBI, dl, TII.
get(SP::ADDri), regUnbiased)
187 .addReg(SP::O6).
addImm(Bias);
189 regUnbiased = SP::O6;
192 int MaxAlign = MFI.getMaxAlignment();
193 BuildMI(MBB, MBBI, dl, TII.
get(SP::ANDNri), regUnbiased)
194 .addReg(regUnbiased).
addImm(MaxAlign - 1);
198 BuildMI(MBB, MBBI, dl, TII.
get(SP::ADDri), SP::O6)
199 .addReg(regUnbiased).
addImm(-Bias);
210 if (MI.
getOpcode() == SP::ADJCALLSTACKDOWN)
214 emitSPAdjustment(MF, MBB, I, Size, SP::ADDrr, SP::ADDri);
227 assert(MBBI->getOpcode() == SP::RETL &&
228 "Can only put epilog before 'retl' instruction!");
230 BuildMI(MBB, MBBI, dl, TII.get(SP::RESTORErr), SP::G0).addReg(SP::G0)
240 emitSPAdjustment(MF, MBB, MBBI, NumBytes, SP::ADDrr, SP::ADDri);
263 unsigned &FrameReg)
const {
268 bool isFixed = MFI.isFixedObjectIndex(FI);
281 }
else if (isFixed) {
284 }
else if (RegInfo->needsStackRealignment(MF)) {
309 for (
unsigned reg = SP::I0; reg <= SP::I7; ++reg)
313 for (
unsigned reg = SP::L0; reg <= SP::L7; ++reg)
332 void SparcFrameLowering::remapRegsForLeafProc(
MachineFunction &MF)
const {
335 for (
unsigned reg = SP::I0; reg <= SP::I7; ++reg) {
339 unsigned mapped_reg = reg - SP::I0 + SP::O0;
345 if ((reg - SP::I0) % 2 == 0) {
346 unsigned preg = (reg - SP::I0) / 2 + SP::I0_I1;
347 unsigned mapped_preg = preg - SP::I0_I1 + SP::O0_O1;
355 for (
unsigned reg = SP::I0_I1; reg <= SP::I6_I7; ++reg) {
359 MBB->
addLiveIn(reg - SP::I0_I1 + SP::O0_O1);
361 for (
unsigned reg = SP::I0; reg <= SP::I7; ++reg) {
370 #ifdef EXPENSIVE_CHECKS 371 MF.
verify(0,
"After LeafProc Remapping");
383 remapRegsForLeafProc(MF);
DILocation * get() const
Get the underlying DILocation.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
unsigned getFrameRegister(const MachineFunction &MF) const override
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register...
int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const override
getFrameIndexReference - This method should return the base register and offset used to reference a f...
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
const SparcInstrInfo * getInstrInfo() const override
static unsigned LO10(int64_t imm)
void removeLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll())
Remove the specified register from the live in set.
void setLeafProc(bool rhs)
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
const HexagonInstrInfo * TII
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst)
static unsigned HIX22(int64_t imm)
bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
static unsigned HI22(int64_t imm)
int64_t getStackPointerBias() const
The 64-bit ABI uses biased stack and frame pointers, so the stack frame of the current function is th...
iterator getLastNonDebugInstr()
Returns an iterator to the last non-debug instruction in the basic block, or end().
virtual const TargetInstrInfo * getInstrInfo() const
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
int getAdjustedFrameSize(int stackSize) const
Given a actual stack size as determined by FrameInfo, this function returns adjusted framesize which ...
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
initializer< Ty > init(const Ty &Val)
void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
unsigned const MachineRegisterInfo * MRI
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static unsigned LOX10(int64_t imm)
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register)
.cfi_def_cfa_register modifies a rule for computing CFA.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
static MCCFIInstruction createWindowSave(MCSymbol *L)
.cfi_window_save SPARC register window is saved.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool is64Bit(const char *name)
static cl::opt< bool > DisableLeafProc("disable-sparc-leaf-proc", cl::init(false), cl::desc("Disable Sparc leaf procedure optimization."), cl::Hidden)
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
const MachineBasicBlock & front() const
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
const SparcRegisterInfo * getRegisterInfo() const override
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required, we reserve argument space for call sites in the function immediately on entry to the current function.
static bool LLVM_ATTRIBUTE_UNUSED verifyLeafProcRegUse(MachineRegisterInfo *MRI)
Iterator for intrusive lists based on ilist_node.
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
Information about stack frame layout on the target.
bool isLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
bool isPhysRegUsed(unsigned PhysReg) const
Return true if the specified register is modified or read in this function.
void replaceRegWith(unsigned FromReg, unsigned ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
SparcFrameLowering(const SparcSubtarget &ST)
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool verify(Pass *p=nullptr, const char *Banner=nullptr, bool AbortOnError=true) const
Run the current MachineFunction through the machine code verifier, useful for debugger use...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool needsStackRealignment(const MachineFunction &MF) const
True if storage within the function requires the stack pointer to be aligned more than the normal cal...
#define LLVM_ATTRIBUTE_UNUSED
const MachineOperand & getOperand(unsigned i) const
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
static MCCFIInstruction createRegister(MCSymbol *L, unsigned Register1, unsigned Register2)
.cfi_register Previous value of Register1 is saved in register Register2.
bool hasCalls() const
Return true if the current function has any function calls.