llvm.org GIT mirror llvm / f49407b
- Track which callee-saved registers are spilled. - Some code clean up. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34783 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 13 years ago
3 changed file(s) with 55 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
212212
213213 // If LR has been forced spilled and no far jumps (i.e. BL) has been issued.
214214 // Undo the spill / restore of LR if possible.
215 if (!HasFarJump && AFI->isLRForceSpilled() && isThumb)
215 if (!HasFarJump && AFI->isLRSpilledForFarJump() && isThumb)
216216 MadeChange |= UndoLRSpillRestore();
217217
218218 BBSizes.clear();
1515
1616 #include "ARMSubtarget.h"
1717 #include "llvm/CodeGen/MachineFunction.h"
18 #include "llvm/Target/MRegisterInfo.h"
1819 #include "llvm/Target/TargetMachine.h"
1920 #include "llvm/ADT/BitVector.h"
2021
3637 /// processFunctionBeforeCalleeSavedScan().
3738 bool HasStackFrame;
3839
39 /// LRSForceSpilled - True if the LR register has been for spilled to enable
40 /// far jump.
41 bool LRForceSpilled;
40 /// LRSpilledForFarJump - True if the LR register has been for spilled to
41 /// enable far jump.
42 bool LRSpilledForFarJump;
4243
4344 /// R3IsLiveIn - True if R3 is live in to this function.
4445 /// FIXME: Remove when register scavenger for Thumb is done.
7273 BitVector GPRCS2Frames;
7374 BitVector DPRCSFrames;
7475
76 /// SpilledCSRegs - A BitVector mask of all spilled callee-saved registers.
77 ///
78 BitVector SpilledCSRegs;
79
7580 /// JumpTableUId - Unique id for jumptables.
7681 ///
7782 unsigned JumpTableUId;
8085 ARMFunctionInfo() :
8186 isThumb(false),
8287 VarArgsRegSaveSize(0), HasStackFrame(false),
83 LRForceSpilled(false), R3IsLiveIn(false),
88 LRSpilledForFarJump(false), R3IsLiveIn(false),
89 FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
90 GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
91 GPRCS1Frames(0), GPRCS2Frames(0), DPRCSFrames(0),
92 JumpTableUId(0) {}
93
94 ARMFunctionInfo(MachineFunction &MF) :
95 isThumb(MF.getTarget().getSubtarget().isThumb()),
96 VarArgsRegSaveSize(0), HasStackFrame(false),
97 LRSpilledForFarJump(false), R3IsLiveIn(false),
8498 FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
8599 GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
86100 GPRCS1Frames(32), GPRCS2Frames(32), DPRCSFrames(32),
87 JumpTableUId(0) {}
88
89 ARMFunctionInfo(MachineFunction &MF) :
90 isThumb(MF.getTarget().getSubtarget().isThumb()),
91 VarArgsRegSaveSize(0), HasStackFrame(false),
92 LRForceSpilled(false), R3IsLiveIn(false),
93 FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
94 GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
95 GPRCS1Frames(32), GPRCS2Frames(32), DPRCSFrames(32),
101 SpilledCSRegs(MF.getTarget().getRegisterInfo()->getNumRegs()),
96102 JumpTableUId(0) {}
97103
98104 bool isThumbFunction() const { return isThumb; }
103109 bool hasStackFrame() const { return HasStackFrame; }
104110 void setHasStackFrame(bool s) { HasStackFrame = s; }
105111
106 bool isLRForceSpilled() const { return LRForceSpilled; }
107 void setLRIsForceSpilled(bool s) { LRForceSpilled = s; }
108
109 bool isR3IsLiveIn() const { return R3IsLiveIn; }
112 bool isLRSpilledForFarJump() const { return LRSpilledForFarJump; }
113 void setLRIsSpilledForFarJump(bool s) { LRSpilledForFarJump = s; }
114
115 // FIXME: Remove when register scavenger for Thumb is done.
116 bool isR3LiveIn() const { return R3IsLiveIn; }
110117 void setR3IsLiveIn(bool l) { R3IsLiveIn = l; }
111118
112119 unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
181188 }
182189 }
183190
191 void setCSRegisterIsSpilled(unsigned Reg) {
192 SpilledCSRegs.set(Reg);
193 }
194
195 bool isCSRegisterSpilled(unsigned Reg) {
196 return SpilledCSRegs[Reg];
197 }
198
199 const BitVector &getSpilledCSRegisters() const {
200 return SpilledCSRegs;
201 }
202
184203 unsigned createJumpTableUId() {
185204 return JumpTableUId++;
186205 }
868868 .addReg(ARM::R2, false, false, true);
869869 TmpReg = ARM::R2;
870870 }
871 if (TmpReg == ARM::R3 && AFI->isR3IsLiveIn())
871 if (TmpReg == ARM::R3 && AFI->isR3LiveIn())
872872 BuildMI(MBB, II, TII.get(ARM::tMOVrr), ARM::R12)
873873 .addReg(ARM::R3, false, false, true);
874874 if (Opcode == ARM::tSpill) {
891891 if (ValReg == ARM::R3)
892892 BuildMI(MBB, NII, TII.get(ARM::tMOVrr), ARM::R2)
893893 .addReg(ARM::R12, false, false, true);
894 if (TmpReg == ARM::R3 && AFI->isR3IsLiveIn())
894 if (TmpReg == ARM::R3 && AFI->isR3LiveIn())
895895 BuildMI(MBB, NII, TII.get(ARM::tMOVrr), ARM::R3)
896896 .addReg(ARM::R12, false, false, true);
897897 } else
922922 unsigned NumGPRSpills = 0;
923923 SmallVector UnspilledCS1GPRs;
924924 SmallVector UnspilledCS2GPRs;
925 ARMFunctionInfo *AFI = MF.getInfo();
925926
926927 // Don't spill FP if the frame can be eliminated. This is determined
927928 // by scanning the callee-save registers to see if any is used.
931932 unsigned Reg = CSRegs[i];
932933 bool Spilled = false;
933934 if (MF.isPhysRegUsed(Reg)) {
935 AFI->setCSRegisterIsSpilled(Reg);
934936 Spilled = true;
935937 CanEliminateFrame = false;
936938 } else {
991993 }
992994 }
993995
994 ARMFunctionInfo *AFI = MF.getInfo();
995996 bool ForceLRSpill = false;
996997 if (!LRSpilled && AFI->isThumbFunction()) {
997998 unsigned FnSize = ARM::GetFunctionSize(MF);
998 // Force LR spill if the Thumb function size is > 2048. This enables the
999 // Force LR to be spilled if the Thumb function size is > 2048. This enables
9991000 // use of BL to implement far jump. If it turns out that it's not needed
1000 // the branch fix up path will undo it.
1001 // then the branch fix up path will undo it.
10011002 if (FnSize >= (1 << 11)) {
10021003 CanEliminateFrame = false;
10031004 ForceLRSpill = true;
10111012 // Spill LR as well so we can fold BX_RET to the registers restore (LDM).
10121013 if (!LRSpilled && CS1Spilled) {
10131014 MF.changePhyRegUsed(ARM::LR, true);
1015 AFI->setCSRegisterIsSpilled(ARM::LR);
10141016 NumGPRSpills++;
10151017 UnspilledCS1GPRs.erase(std::find(UnspilledCS1GPRs.begin(),
10161018 UnspilledCS1GPRs.end(), (unsigned)ARM::LR));
10291031 // the integer and double callee save areas.
10301032 unsigned TargetAlign = MF.getTarget().getFrameInfo()->getStackAlignment();
10311033 if (TargetAlign == 8 && (NumGPRSpills & 1)) {
1032 if (CS1Spilled && !UnspilledCS1GPRs.empty())
1033 MF.changePhyRegUsed(UnspilledCS1GPRs.front(), true);
1034 else if (!UnspilledCS2GPRs.empty())
1035 MF.changePhyRegUsed(UnspilledCS2GPRs.front(), true);
1034 if (CS1Spilled && !UnspilledCS1GPRs.empty()) {
1035 unsigned Reg = UnspilledCS1GPRs.front();
1036 MF.changePhyRegUsed(Reg, true);
1037 AFI->setCSRegisterIsSpilled(Reg);
1038 } else if (!UnspilledCS2GPRs.empty()) {
1039 unsigned Reg = UnspilledCS2GPRs.front();
1040 MF.changePhyRegUsed(Reg, true);
1041 AFI->setCSRegisterIsSpilled(Reg);
1042 }
10361043 }
10371044 }
10381045
10391046 if (ForceLRSpill) {
10401047 MF.changePhyRegUsed(ARM::LR, true);
1041 AFI->setLRIsForceSpilled(true);
1048 AFI->setCSRegisterIsSpilled(ARM::LR);
1049 AFI->setLRIsSpilledForFarJump(true);
10421050 }
10431051 }
10441052