LLVM: lib/Target/MSP430/MSP430FrameLowering.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
22
23using namespace llvm;
24
28 STI(STI), TII(*STI.getInstrInfo()), TRI(STI.getRegisterInfo()) {}
29
32
36}
37
40}
41
52}
53
56 const DebugLoc &DL, bool IsPrologue) const {
60
61
63
64
68 unsigned DwarfReg = MRI->getDwarfRegNum(Reg, true);
69
70 if (IsPrologue) {
73 } else {
76 }
77 }
78}
79
82 assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported");
87
90
91
93 int stackGrowth = -2;
94
97
98 uint64_t FrameSize = StackSize - 2;
100
101
102
103
105
106
110
111
112
116
117
118 unsigned DwarfFramePtr = TRI->getDwarfRegNum(MSP430::R4, true);
123
124
128
129
130
134
135
137 MBBJ.addLiveIn(MSP430::R4);
138 } else
140
141
144 (MBBI->getOpcode() == MSP430::PUSH16r)) {
146
147 if ((MF)) {
148
149
150 assert(StackSize && "Expected stack frame");
155 }
156 }
157
160
161 if (NumBytes) {
162
163
164
165
166
167
168
169 if (NumBytes) {
175
176 MI->getOperand(3).setIsDead();
177 }
178 if ((MF)) {
179
184 }
185 }
186
188}
189
196
198 unsigned RetOpcode = MBBI->getOpcode();
200
201 switch (RetOpcode) {
202 case MSP430::RET:
203 case MSP430::RETI: break;
204 default:
205 llvm_unreachable("Can only insert epilog into returning blocks");
206 }
207
208
212
215
216 uint64_t FrameSize = StackSize - 2;
217 NumBytes = FrameSize - CSSize;
218
219
222 unsigned DwarfStackPtr = TRI->getDwarfRegNum(MSP430::SP, true);
228 unsigned DwarfFramePtr = TRI->getDwarfRegNum(MSP430::R4, true);
233 --AfterPop;
234 }
235 } else
236 NumBytes = StackSize - CSSize;
237
238
242 unsigned Opc = PI->getOpcode();
244 !PI->isTerminator())
245 break;
246 FirstCSPop = PI;
248 }
249 MBBI = FirstCSPop;
250
252
253
254
255
256
257
262 if (CSSize) {
268
269 MI->getOperand(3).setIsDead();
270 }
271 } else {
272
273 if (NumBytes) {
279
280 MI->getOperand(3).setIsDead();
281
282 if ((MF)) {
283
287 }
288 }
289 }
290
291 if ((MF)) {
292 MBBI = FirstCSPop;
293 int64_t Offset = -(int64_t)CSSize - 2;
294
295
298 unsigned Opc = PI->getOpcode();
300 if (Opc == MSP430::POP16r) {
305 }
306 }
307 }
309}
310
311
316 return false;
317
320
325
328
333 }
334 return true;
335}
336
341 return false;
342
345
348
352
353 return true;
354}
355
362
363
364
365
368 if (Amount != 0) {
369
370
371
373
375 if (Old.getOpcode() == TII.getCallFrameSetupOpcode()) {
376 New =
380 } else {
382
384 if (Amount)
386 MSP430::SP)
389 }
390
391 if (New) {
392
393 New->getOperand(3).setIsDead();
394
395
397 }
398 }
399 } else if (I->getOpcode() == TII.getCallFrameDestroyOpcode()) {
400
401
408 if ((MF)) {
412 }
413
414 New->getOperand(3).setIsDead();
415
417 }
418 }
419
421}
422
423void
426
429 (void)FrameIdx;
431 "Slot for FP register must be last in order to be found!");
432 }
433}
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
const HexagonInstrInfo * TII
unsigned const TargetRegisterInfo * TRI
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_def_cfa_register modifies a rule for computing CFA.
static MCCFIInstruction createRestore(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_restore says that the rule for Register is now the same as it was at the beginning of the functi...
static MCCFIInstruction cfiDefCfa(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it.
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
static MCCFIInstruction cfiDefCfaOffset(MCSymbol *L, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa_offset modifies a rule for computing CFA.
static MCCFIInstruction createAdjustCfaOffset(MCSymbol *L, int64_t Adjustment, SMLoc Loc={})
.cfi_adjust_cfa_offset Same as .cfi_def_cfa_offset, but Offset is a relative value that is added/subt...
const MCRegisterInfo * getRegisterInfo() const
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
MSP430FrameLowering(const MSP430Subtarget &STI)
bool hasFPImpl(const MachineFunction &MF) const override
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
void emitCalleeSavedFrameMoves(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, bool IsPrologue) const
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
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...
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
const MSP430RegisterInfo * TRI
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
void BuildCFI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, const MCCFIInstruction &CFIInst, MachineInstr::MIFlag Flag=MachineInstr::NoFlags) const
Wraps up getting a CFI index and building a MachineInstr for it.
const MSP430InstrInfo & TII
int64_t getFramePoppedByCallee(const MachineInstr &I) const
MSP430MachineFunctionInfo - This class is derived from MachineFunction and contains private MSP430 ta...
unsigned getCalleeSavedFrameSize() const
void setCalleeSavedFrameSize(unsigned bytes)
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
bool isReturnBlock() const
Convenience function that returns true if the block ends in a return instruction.
iterator getLastNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the last non-debug instruction in the basic block, or end().
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
int getObjectIndexBegin() const
Return the minimum frame object index.
void setOffsetAdjustment(int64_t Adj)
Set the correction for frame offsets.
unsigned addFrameInst(const MCCFIInstruction &Inst)
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.
MCContext & getContext() const
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineBasicBlock & front() const
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Wrapper class representing virtual and physical registers.
StackOffset holds a fixed and a scalable offset in bytes.
Information about stack frame layout on the target.
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
TargetInstrInfo - Interface to description of machine instruction set.
bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetInstrInfo * getInstrInfo() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ Kill
The last use of a register.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
auto reverse(ContainerTy &&C)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
This struct is a compact representation of a valid (non-zero power of two) alignment.