llvm.org GIT mirror llvm / f864a32
Change eliminateCallFramePseudoInstr() to return an iterator This will become necessary in a subsequent change to make this method merge adjacent stack adjustments, i.e. it might erase the previous and/or next instruction. It also greatly simplifies the calls to this function from Prolog- EpilogInserter. Previously, that had a bunch of logic to resume iteration after the call; now it just continues with the returned iterator. Note that this changes the behaviour of PEI a little. Previously, it attempted to re-visit the new instruction created by eliminateCallFramePseudoInstr(). That code was added in r36625, but I can't see any reason for it: the new instructions will obviously not be pseudo instructions, they will not have FrameIndex operands, and we have already accounted for the stack adjustment. Differential Revision: http://reviews.llvm.org/D18627 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265036 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 4 years ago
33 changed file(s) with 86 addition(s) and 97 deletion(s). Raw diff Collapse all Expand all
5050
5151 * The C API function LLVMGetDataLayout is deprecated
5252 in favor of LLVMGetDataLayoutStr.
53
54 * ``TargetFrameLowering::eliminateCallFramePseudoInstr`` now returns an
55 iterator to the next instruction instead of ``void``. Targets that previously
56 did ``MBB.erase(I); return;`` now probably want ``return MBB.erase(I);``.
5357
5458 .. NOTE
5559 For small 1-3 sentence descriptions, just add an entry at the end of
272272 report_fatal_error("WinEH not implemented for this target");
273273 }
274274
275 /// eliminateCallFramePseudoInstr - This method is called during prolog/epilog
276 /// code insertion to eliminate call frame setup and destroy pseudo
277 /// instructions (but only if the Target is using them). It is responsible
278 /// for eliminating these instructions, replacing them with concrete
279 /// instructions. This method need only be implemented if using call frame
280 /// setup/destroy pseudo instructions.
281 ///
282 virtual void
275 /// This method is called during prolog/epilog code insertion to eliminate
276 /// call frame setup and destroy pseudo instructions (but only if the Target
277 /// is using them). It is responsible for eliminating these instructions,
278 /// replacing them with concrete instructions. This method need only be
279 /// implemented if using call frame setup/destroy pseudo instructions.
280 /// Returns an iterator pointing to the instruction after the replaced one.
281 virtual MachineBasicBlock::iterator
283282 eliminateCallFramePseudoInstr(MachineFunction &MF,
284283 MachineBasicBlock &MBB,
285284 MachineBasicBlock::iterator MI) const {
890890 InsideCallSequence = (I->getOpcode() == FrameSetupOpcode);
891891 SPAdj += TII.getSPAdjust(I);
892892
893 MachineBasicBlock::iterator PrevI = BB->end();
894 if (I != BB->begin()) PrevI = std::prev(I);
895 TFI->eliminateCallFramePseudoInstr(Fn, *BB, I);
896
897 // Visit the instructions created by eliminateCallFramePseudoInstr().
898 if (PrevI == BB->end())
899 I = BB->begin(); // The replaced instr was the first in the block.
900 else
901 I = std::next(PrevI);
893 I = TFI->eliminateCallFramePseudoInstr(Fn, *BB, I);
902894 continue;
903895 }
904896
152152 return !MF.getFrameInfo()->hasVarSizedObjects();
153153 }
154154
155 void AArch64FrameLowering::eliminateCallFramePseudoInstr(
155 MachineBasicBlock::iterator AArch64FrameLowering::eliminateCallFramePseudoInstr(
156156 MachineFunction &MF, MachineBasicBlock &MBB,
157157 MachineBasicBlock::iterator I) const {
158158 const AArch64InstrInfo *TII =
195195 emitFrameOffset(MBB, I, DL, AArch64::SP, AArch64::SP, -CalleePopAmount,
196196 TII);
197197 }
198 MBB.erase(I);
198 return MBB.erase(I);
199199 }
200200
201201 void AArch64FrameLowering::emitCalleeSavedFrameMoves(
2626 void emitCalleeSavedFrameMoves(MachineBasicBlock &MBB,
2727 MachineBasicBlock::iterator MBBI) const;
2828
29 void eliminateCallFramePseudoInstr(MachineFunction &MF,
30 MachineBasicBlock &MBB,
31 MachineBasicBlock::iterator I) const override;
29 MachineBasicBlock::iterator
30 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
31 MachineBasicBlock::iterator I) const override;
3232
3333 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
3434 /// the function.
17251725 }
17261726 }
17271727
1728
1729 void ARMFrameLowering::
1730 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
1731 MachineBasicBlock::iterator I) const {
1728 MachineBasicBlock::iterator ARMFrameLowering::eliminateCallFramePseudoInstr(
1729 MachineFunction &MF, MachineBasicBlock &MBB,
1730 MachineBasicBlock::iterator I) const {
17321731 const ARMBaseInstrInfo &TII =
17331732 *static_cast(MF.getSubtarget().getInstrInfo());
17341733 if (!hasReservedCallFrame(MF)) {
17681767 }
17691768 }
17701769 }
1771 MBB.erase(I);
1770 return MBB.erase(I);
17721771 }
17731772
17741773 /// Get the minimum constant for ARM that is greater than or equal to the
7373 bool(*Func)(unsigned, bool),
7474 unsigned NumAlignedDPRCS2Regs) const;
7575
76 void
76 MachineBasicBlock::iterator
7777 eliminateCallFramePseudoInstr(MachineFunction &MF,
7878 MachineBasicBlock &MBB,
7979 MachineBasicBlock::iterator MI) const override;
4848 }
4949
5050
51 void Thumb1FrameLowering::
51 MachineBasicBlock::iterator Thumb1FrameLowering::
5252 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
5353 MachineBasicBlock::iterator I) const {
5454 const Thumb1InstrInfo &TII =
7979 }
8080 }
8181 }
82 MBB.erase(I);
82 return MBB.erase(I);
8383 }
8484
8585 void Thumb1FrameLowering::emitPrologue(MachineFunction &MF,
4040
4141 bool hasReservedCallFrame(const MachineFunction &MF) const override;
4242
43 void
43 MachineBasicBlock::iterator
4444 eliminateCallFramePseudoInstr(MachineFunction &MF,
4545 MachineBasicBlock &MBB,
4646 MachineBasicBlock::iterator MI) const override;
3030 void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
3131 RegScavenger *RS) const override;
3232
33 void
33 MachineBasicBlock::iterator
3434 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
3535 MachineBasicBlock::iterator MI) const override {
36 MBB.erase(MI);
36 return MBB.erase(MI);
3737 }
3838 };
3939 }
10591059 return true;
10601060 }
10611061
1062
1063 void HexagonFrameLowering::eliminateCallFramePseudoInstr(MachineFunction &MF,
1064 MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const {
1062 MachineBasicBlock::iterator HexagonFrameLowering::eliminateCallFramePseudoInstr(
1063 MachineFunction &MF, MachineBasicBlock &MBB,
1064 MachineBasicBlock::iterator I) const {
10651065 MachineInstr &MI = *I;
10661066 unsigned Opc = MI.getOpcode();
10671067 (void)Opc; // Silence compiler warning.
10681068 assert((Opc == Hexagon::ADJCALLSTACKDOWN || Opc == Hexagon::ADJCALLSTACKUP) &&
10691069 "Cannot handle this call frame pseudo instruction");
1070 MBB.erase(I);
1070 return MBB.erase(I);
10711071 }
10721072
10731073
4141 return true;
4242 }
4343
44 void eliminateCallFramePseudoInstr(MachineFunction &MF,
45 MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const override;
44 MachineBasicBlock::iterator
45 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
46 MachineBasicBlock::iterator I) const override;
4647 void processFunctionBeforeFrameFinalized(MachineFunction &MF,
4748 RegScavenger *RS = nullptr) const override;
4849 void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
138138 replaceAdjDynAllocPseudo(MF);
139139 }
140140
141 void LanaiFrameLowering::eliminateCallFramePseudoInstr(
141 MachineBasicBlock::iterator LanaiFrameLowering::eliminateCallFramePseudoInstr(
142142 MachineFunction &MF, MachineBasicBlock &MBB,
143143 MachineBasicBlock::iterator I) const {
144144 // Discard ADJCALLSTACKDOWN, ADJCALLSTACKUP instructions.
145 MBB.erase(I);
145 return MBB.erase(I);
146146 }
147147
148148 // The function epilogue should not depend on the current stack pointer!
4141 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
4242 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
4343
44 void
44 MachineBasicBlock::iterator
4545 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
4646 MachineBasicBlock::iterator I) const override;
4747
223223 return true;
224224 }
225225
226 void MSP430FrameLowering::
227 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
228 MachineBasicBlock::iterator I) const {
226 MachineBasicBlock::iterator MSP430FrameLowering::eliminateCallFramePseudoInstr(
227 MachineFunction &MF, MachineBasicBlock &MBB,
228 MachineBasicBlock::iterator I) const {
229229 const MSP430InstrInfo &TII =
230230 *static_cast(MF.getSubtarget().getInstrInfo());
231231 unsigned StackAlign = getStackAlignment();
282282 }
283283 }
284284
285 MBB.erase(I);
285 return MBB.erase(I);
286286 }
287287
288288 void
2929 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
3030 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
3131
32 void eliminateCallFramePseudoInstr(MachineFunction &MF,
33 MachineBasicBlock &MBB,
34 MachineBasicBlock::iterator I) const override;
32 MachineBasicBlock::iterator
33 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
34 MachineBasicBlock::iterator I) const override;
3535
3636 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
3737 MachineBasicBlock::iterator MI,
142142 }
143143
144144 // Eliminate ADJCALLSTACKDOWN, ADJCALLSTACKUP pseudo instructions
145 void MipsFrameLowering::
145 MachineBasicBlock::iterator MipsFrameLowering::
146146 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
147147 MachineBasicBlock::iterator I) const {
148148 unsigned SP = STI.getABI().IsN64() ? Mips::SP_64 : Mips::SP;
155155 STI.getInstrInfo()->adjustStackPtr(SP, Amount, MBB, I);
156156 }
157157
158 MBB.erase(I);
158 return MBB.erase(I);
159159 }
3535
3636 bool isFPCloseToIncomingSP() const override { return false; }
3737
38 void
38 MachineBasicBlock::iterator
3939 eliminateCallFramePseudoInstr(MachineFunction &MF,
4040 MachineBasicBlock &MBB,
4141 MachineBasicBlock::iterator I) const override;
6969
7070 // This function eliminates ADJCALLSTACKDOWN,
7171 // ADJCALLSTACKUP pseudo instructions
72 void NVPTXFrameLowering::eliminateCallFramePseudoInstr(
72 MachineBasicBlock::iterator NVPTXFrameLowering::eliminateCallFramePseudoInstr(
7373 MachineFunction &MF, MachineBasicBlock &MBB,
7474 MachineBasicBlock::iterator I) const {
7575 // Simply discard ADJCALLSTACKDOWN,
7676 // ADJCALLSTACKUP instructions.
77 MBB.erase(I);
77 return MBB.erase(I);
7878 }
2525 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
2626 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
2727
28 void
28 MachineBasicBlock::iterator
2929 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
3030 MachineBasicBlock::iterator I) const override;
3131 };
17691769 .addReg(MoveReg, getKillRegState(true)));
17701770 }
17711771
1772 void PPCFrameLowering::
1772 MachineBasicBlock::iterator PPCFrameLowering::
17731773 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
17741774 MachineBasicBlock::iterator I) const {
17751775 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
18061806 }
18071807 }
18081808 // Simply discard ADJCALLSTACKDOWN, ADJCALLSTACKUP instructions.
1809 MBB.erase(I);
1809 return MBB.erase(I);
18101810 }
18111811
18121812 bool
9292 const std::vector &CSI,
9393 const TargetRegisterInfo *TRI) const override;
9494
95 void eliminateCallFramePseudoInstr(MachineFunction &MF,
96 MachineBasicBlock &MBB,
97 MachineBasicBlock::iterator I) const override;
95 MachineBasicBlock::iterator
96 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
97 MachineBasicBlock::iterator I) const override;
9898
9999 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
100100 MachineBasicBlock::iterator MI,
182182 }
183183 }
184184
185 void SparcFrameLowering::
185 MachineBasicBlock::iterator SparcFrameLowering::
186186 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
187187 MachineBasicBlock::iterator I) const {
188188 if (!hasReservedCallFrame(MF)) {
194194 if (Size)
195195 emitSPAdjustment(MF, MBB, I, Size, SP::ADDrr, SP::ADDri);
196196 }
197 MBB.erase(I);
197 return MBB.erase(I);
198198 }
199199
200200
2828 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
2929 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
3030
31 void
31 MachineBasicBlock::iterator
3232 eliminateCallFramePseudoInstr(MachineFunction &MF,
3333 MachineBasicBlock &MBB,
3434 MachineBasicBlock::iterator I) const override;
510510 return true;
511511 }
512512
513 void SystemZFrameLowering::
513 MachineBasicBlock::iterator SystemZFrameLowering::
514514 eliminateCallFramePseudoInstr(MachineFunction &MF,
515515 MachineBasicBlock &MBB,
516516 MachineBasicBlock::iterator MI) const {
519519 case SystemZ::ADJCALLSTACKUP:
520520 assert(hasReservedCallFrame(MF) &&
521521 "ADJSTACKDOWN and ADJSTACKUP should be no-ops");
522 MBB.erase(MI);
522 return MBB.erase(MI);
523523 break;
524524
525525 default:
4545 int getFrameIndexReference(const MachineFunction &MF, int FI,
4646 unsigned &FrameReg) const override;
4747 bool hasReservedCallFrame(const MachineFunction &MF) const override;
48 void eliminateCallFramePseudoInstr(MachineFunction &MF,
49 MachineBasicBlock &MBB,
50 MachineBasicBlock::iterator MI) const
51 override;
48 MachineBasicBlock::iterator
49 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
50 MachineBasicBlock::iterator MI) const override;
5251
5352 // Return the number of bytes in the callee-allocated part of the frame.
5453 uint64_t getAllocatedStackSize(const MachineFunction &MF) const;
9999 MF.getInfo()->stackifyVReg(SPAddr);
100100 }
101101
102 void WebAssemblyFrameLowering::eliminateCallFramePseudoInstr(
102 MachineBasicBlock::iterator
103 WebAssemblyFrameLowering::eliminateCallFramePseudoInstr(
103104 MachineFunction &MF, MachineBasicBlock &MBB,
104105 MachineBasicBlock::iterator I) const {
105106 assert(!I->getOperand(0).getImm() && hasFP(MF) &&
110111 DebugLoc DL = I->getDebugLoc();
111112 writeSPToMemory(WebAssembly::SP32, MF, MBB, I, I, DL);
112113 }
113 MBB.erase(I);
114 return MBB.erase(I);
114115 }
115116
116117 void WebAssemblyFrameLowering::emitPrologue(MachineFunction &MF,
3333 /*TransientStackAlignment=*/16,
3434 /*StackRealignable=*/true) {}
3535
36 void eliminateCallFramePseudoInstr(
36 MachineBasicBlock::iterator eliminateCallFramePseudoInstr(
3737 MachineFunction &MF, MachineBasicBlock &MBB,
3838 MachineBasicBlock::iterator I) const override;
3939
876876 I->getOpcode() == FrameDestroyOpcode) {
877877 InsideCallSequence = (I->getOpcode() == FrameSetupOpcode);
878878 SPAdj += TII.getSPAdjust(I);
879
880 MachineBasicBlock::iterator PrevI = BB->end();
881 if (I != BB->begin()) PrevI = std::prev(I);
882 TFI->eliminateCallFramePseudoInstr(Fn, *BB, I);
883
884 // Visit the instructions created by eliminateCallFramePseudoInstr().
885 if (PrevI == BB->end())
886 I = BB->begin(); // The replaced instr was the first in the block.
887 else
888 I = std::next(PrevI);
879 I = TFI->eliminateCallFramePseudoInstr(Fn, *BB, I);
889880 continue;
890881 }
891882
24762476 return true;
24772477 }
24782478
2479 void X86FrameLowering::
2479 MachineBasicBlock::iterator X86FrameLowering::
24802480 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
24812481 MachineBasicBlock::iterator I) const {
24822482 bool reserveCallFrame = hasReservedCallFrame(MF);
25202520 MCCFIInstruction::createGnuArgsSize(nullptr, Amount));
25212521
25222522 if (Amount == 0)
2523 return;
2523 return I;
25242524
25252525 // Factor out the amount that gets handled inside the sequence
25262526 // (Pushes of argument for frame setup, callee pops for frame destroy)
25602560 }
25612561 }
25622562
2563 return;
2563 return I;
25642564 }
25652565
25662566 if (isDestroy && InternalAmt) {
25702570 // We are not tracking the stack pointer adjustment by the callee, so make
25712571 // sure we restore the stack pointer immediately after the call, there may
25722572 // be spill code inserted between the CALL and ADJCALLSTACKUP instructions.
2573 MachineBasicBlock::iterator CI = I;
25732574 MachineBasicBlock::iterator B = MBB.begin();
2574 while (I != B && !std::prev(I)->isCall())
2575 while (CI != B && !std::prev(I)->isCall())
25752576 --I;
2576 BuildStackAdjustment(MBB, I, DL, -InternalAmt, /*InEpilogue=*/false);
2577 }
2577 BuildStackAdjustment(MBB, CI, DL, -InternalAmt, /*InEpilogue=*/false);
2578 }
2579
2580 return I;
25782581 }
25792582
25802583 bool X86FrameLowering::canUseAsEpilogue(const MachineBasicBlock &MBB) const {
102102 int getFrameIndexReferenceFromSP(const MachineFunction &MF, int FI,
103103 unsigned &FrameReg) const override;
104104
105 void eliminateCallFramePseudoInstr(MachineFunction &MF,
106 MachineBasicBlock &MBB,
107 MachineBasicBlock::iterator MI) const override;
105 MachineBasicBlock::iterator
106 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
107 MachineBasicBlock::iterator MI) const override;
108108
109109 unsigned getWinEHParentFrameOffset(const MachineFunction &MF) const override;
110110
481481
482482 // This function eliminates ADJCALLSTACKDOWN,
483483 // ADJCALLSTACKUP pseudo instructions
484 void XCoreFrameLowering::
485 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
486 MachineBasicBlock::iterator I) const {
484 MachineBasicBlock::iterator XCoreFrameLowering::eliminateCallFramePseudoInstr(
485 MachineFunction &MF, MachineBasicBlock &MBB,
486 MachineBasicBlock::iterator I) const {
487487 const XCoreInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
488488 if (!hasReservedCallFrame(MF)) {
489489 // Turn the adjcallstackdown instruction into 'extsp ' and the
527527 }
528528 }
529529
530 MBB.erase(I);
530 return MBB.erase(I);
531531 }
532532
533533 void XCoreFrameLowering::determineCalleeSaves(MachineFunction &MF,
4040 const std::vector &CSI,
4141 const TargetRegisterInfo *TRI) const override;
4242
43 void eliminateCallFramePseudoInstr(MachineFunction &MF,
44 MachineBasicBlock &MBB,
43 MachineBasicBlock::iterator
44 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
4545 MachineBasicBlock::iterator I) const override;
4646
4747 bool hasFP(const MachineFunction &MF) const override;