LLVM: lib/Target/MSP430/MSP430FrameLowering.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
23
24using namespace llvm;
25
30
38
42
54
57 const DebugLoc &DL, bool IsPrologue) const {
61
62
64
65
69 unsigned DwarfReg = MRI->getDwarfRegNum(Reg, true);
70
71 if (IsPrologue) {
74 } else {
77 }
78 }
79}
80
83 assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported");
88
91
92
94 int stackGrowth = -2;
95
98
99 uint64_t FrameSize = StackSize - 2;
101
102
103
104
106
107
111
112
113
117
118
119 unsigned DwarfFramePtr = TRI->getDwarfRegNum(MSP430::R4, true);
124
125
129
130
131
135
136
138 MBBJ.addLiveIn(MSP430::R4);
139 } else
141
142
145 (MBBI->getOpcode() == MSP430::PUSH16r)) {
147
148 if ((MF)) {
149
150
151 assert(StackSize && "Expected stack frame");
156 }
157 }
158
161
162 if (NumBytes) {
163
164
165
166
167
168
169
170 if (NumBytes) {
176
177 MI->getOperand(3).setIsDead();
178 }
179 if ((MF)) {
180
185 }
186 }
187
189}
190
197
199 unsigned RetOpcode = MBBI->getOpcode();
201
202 switch (RetOpcode) {
203 case MSP430::RET:
204 case MSP430::RETI: break;
205 default:
206 llvm_unreachable("Can only insert epilog into returning blocks");
207 }
208
209
213
216
217 uint64_t FrameSize = StackSize - 2;
218 NumBytes = FrameSize - CSSize;
219
220
223 unsigned DwarfStackPtr = TRI->getDwarfRegNum(MSP430::SP, true);
228 if (.succ_empty() &&
.isReturnBlock()) {
229 unsigned DwarfFramePtr = TRI->getDwarfRegNum(MSP430::R4, true);
234 --AfterPop;
235 }
236 } else
237 NumBytes = StackSize - CSSize;
238
239
241 while (MBBI != MBB.begin()) {
243 unsigned Opc = PI->getOpcode();
245 !PI->isTerminator())
246 break;
247 FirstCSPop = PI;
249 }
250 MBBI = FirstCSPop;
251
253
254
255
256
257
258
263 if (CSSize) {
269
270 MI->getOperand(3).setIsDead();
271 }
272 } else {
273
274 if (NumBytes) {
280
281 MI->getOperand(3).setIsDead();
282
283 if ((MF)) {
284
288 }
289 }
290 }
291
292 if ((MF)) {
293 MBBI = FirstCSPop;
294 int64_t Offset = -(int64_t)CSSize - 2;
295
296
297 while (MBBI != MBB.end()) {
299 unsigned Opc = PI->getOpcode();
301 if (Opc == MSP430::POP16r) {
306 }
307 }
308 }
310}
311
312
317 return false;
318
320 if (MI != MBB.end()) DL = MI->getDebugLoc();
321
326
329
330 MBB.addLiveIn(Reg);
334 }
335 return true;
336}
337
342 return false;
343
345 if (MI != MBB.end()) DL = MI->getDebugLoc();
346
349
353
354 return true;
355}
356
363
364
365
366
369 if (Amount != 0) {
370
371
372
374
376 if (Old.getOpcode() == TII.getCallFrameSetupOpcode()) {
377 New =
381 } else {
383
384 Amount -= TII.getFramePoppedByCallee(Old);
385 if (Amount)
387 MSP430::SP)
390 }
391
392 if (New) {
393
394 New->getOperand(3).setIsDead();
395
396
398 }
399 }
400 } else if (I->getOpcode() == TII.getCallFrameDestroyOpcode()) {
401
402
403 if (uint64_t CalleeAmt = TII.getFramePoppedByCallee(*I)) {
409 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
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
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.
Helper class for creating CFI instructions and inserting them into MIR.
void buildAdjustCFAOffset(int64_t Adjustment) const
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.
const MCRegisterInfo * getRegisterInfo() const
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Wrapper class representing physical registers. Should be passed by value.
MSP430FrameLowering(const MSP430Subtarget &STI)
Definition MSP430FrameLowering.cpp:26
const MSP430Subtarget & STI
bool hasFPImpl(const MachineFunction &MF) const override
Definition MSP430FrameLowering.cpp:31
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
Definition MSP430FrameLowering.cpp:191
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...
Definition MSP430FrameLowering.cpp:313
void emitCalleeSavedFrameMoves(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, bool IsPrologue) const
Definition MSP430FrameLowering.cpp:55
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
Definition MSP430FrameLowering.cpp:81
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...
Definition MSP430FrameLowering.cpp:357
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
Definition MSP430FrameLowering.cpp:39
const MSP430RegisterInfo * TRI
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
Definition MSP430FrameLowering.cpp:424
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...
Definition MSP430FrameLowering.cpp:338
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.
Definition MSP430FrameLowering.cpp:43
const MSP430InstrInfo & TII
MSP430MachineFunctionInfo - This class is derived from MachineFunction and contains private MSP430 ta...
unsigned getCalleeSavedFrameSize() const
void setCalleeSavedFrameSize(unsigned bytes)
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
LLVM_ABI 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...
StackOffset holds a fixed and a scalable offset in bytes.
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
TargetFrameLowering(StackDirection D, Align StackAl, int LAO, Align TransAl=Align(1), bool StackReal=true)
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.
LLVM_ABI 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.