@@ -33,6 +33,51 @@ DisableLeafProc("disable-sparc-leaf-proc",
33
33
cl::Hidden);
34
34
35
35
36
+ void SparcFrameLowering::emitSPAdjustment (MachineFunction &MF,
37
+ MachineBasicBlock &MBB,
38
+ MachineBasicBlock::iterator MBBI,
39
+ int NumBytes,
40
+ unsigned ADDrr,
41
+ unsigned ADDri) const {
42
+
43
+ DebugLoc dl = (MBBI != MBB.end ()) ? MBBI->getDebugLoc () : DebugLoc ();
44
+ const SparcInstrInfo &TII =
45
+ *static_cast <const SparcInstrInfo*>(MF.getTarget ().getInstrInfo ());
46
+
47
+ if (NumBytes >= -4096 && NumBytes < 4096 ) {
48
+ BuildMI (MBB, MBBI, dl, TII.get (ADDri), SP::O6)
49
+ .addReg (SP::O6).addImm (NumBytes);
50
+ return ;
51
+ }
52
+
53
+ // Emit this the hard way. This clobbers G1 which we always know is
54
+ // available here.
55
+ if (NumBytes >= 0 ) {
56
+ // Emit nonnegative numbers with sethi + or.
57
+ // sethi %hi(NumBytes), %g1
58
+ // or %g1, %lo(NumBytes), %g1
59
+ // add %sp, %g1, %sp
60
+ BuildMI (MBB, MBBI, dl, TII.get (SP::SETHIi), SP::G1)
61
+ .addImm (HI22 (NumBytes));
62
+ BuildMI (MBB, MBBI, dl, TII.get (SP::ORri), SP::G1)
63
+ .addReg (SP::G1).addImm (LO10 (NumBytes));
64
+ BuildMI (MBB, MBBI, dl, TII.get (ADDrr), SP::O6)
65
+ .addReg (SP::O6).addReg (SP::G1);
66
+ return ;
67
+ }
68
+
69
+ // Emit negative numbers with sethi + xor.
70
+ // sethi %hix(NumBytes), %g1
71
+ // xor %g1, %lox(NumBytes), %g1
72
+ // add %sp, %g1, %sp
73
+ BuildMI (MBB, MBBI, dl, TII.get (SP::SETHIi), SP::G1)
74
+ .addImm (HIX22 (NumBytes));
75
+ BuildMI (MBB, MBBI, dl, TII.get (SP::XORri), SP::G1)
76
+ .addReg (SP::G1).addImm (LOX10 (NumBytes));
77
+ BuildMI (MBB, MBBI, dl, TII.get (ADDrr), SP::O6)
78
+ .addReg (SP::O6).addReg (SP::G1);
79
+ }
80
+
36
81
void SparcFrameLowering::emitPrologue (MachineFunction &MF) const {
37
82
SparcMachineFunctionInfo *FuncInfo = MF.getInfo <SparcMachineFunctionInfo>();
38
83
@@ -55,21 +100,8 @@ void SparcFrameLowering::emitPrologue(MachineFunction &MF) const {
55
100
SAVErr = SP::ADDrr;
56
101
}
57
102
NumBytes = - SubTarget.getAdjustedFrameSize (NumBytes);
103
+ emitSPAdjustment (MF, MBB, MBBI, NumBytes, SAVErr, SAVEri);
58
104
59
- if (NumBytes >= -4096 ) {
60
- BuildMI (MBB, MBBI, dl, TII.get (SAVEri), SP::O6)
61
- .addReg (SP::O6).addImm (NumBytes);
62
- } else {
63
- // Emit this the hard way. This clobbers G1 which we always know is
64
- // available here.
65
- unsigned OffHi = (unsigned )NumBytes >> 10U ;
66
- BuildMI (MBB, MBBI, dl, TII.get (SP::SETHIi), SP::G1).addImm (OffHi);
67
- // Emit G1 = G1 + I6
68
- BuildMI (MBB, MBBI, dl, TII.get (SP::ORri), SP::G1)
69
- .addReg (SP::G1).addImm (NumBytes & ((1 << 10 )-1 ));
70
- BuildMI (MBB, MBBI, dl, TII.get (SAVErr), SP::O6)
71
- .addReg (SP::O6).addReg (SP::G1);
72
- }
73
105
MachineModuleInfo &MMI = MF.getMMI ();
74
106
const MCRegisterInfo *MRI = MMI.getContext ().getRegisterInfo ();
75
107
MCSymbol *FrameLabel = MMI.getContext ().CreateTempSymbol ();
@@ -100,11 +132,9 @@ eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
100
132
int Size = MI.getOperand (0 ).getImm ();
101
133
if (MI.getOpcode () == SP::ADJCALLSTACKDOWN)
102
134
Size = -Size ;
103
- const SparcInstrInfo &TII =
104
- *static_cast <const SparcInstrInfo*>(MF.getTarget ().getInstrInfo ());
135
+
105
136
if (Size )
106
- BuildMI (MBB, I, DL, TII.get (SP::ADDri), SP::O6).addReg (SP::O6)
107
- .addImm (Size );
137
+ emitSPAdjustment (MF, MBB, I, Size , SP::ADDrr, SP::ADDri);
108
138
}
109
139
MBB.erase (I);
110
140
}
@@ -131,21 +161,7 @@ void SparcFrameLowering::emitEpilogue(MachineFunction &MF,
131
161
return ;
132
162
133
163
NumBytes = SubTarget.getAdjustedFrameSize (NumBytes);
134
-
135
- if (NumBytes < 4096 ) {
136
- BuildMI (MBB, MBBI, dl, TII.get (SP::ADDri), SP::O6)
137
- .addReg (SP::O6).addImm (NumBytes);
138
- } else {
139
- // Emit this the hard way. This clobbers G1 which we always know is
140
- // available here.
141
- unsigned OffHi = (unsigned )NumBytes >> 10U ;
142
- BuildMI (MBB, MBBI, dl, TII.get (SP::SETHIi), SP::G1).addImm (OffHi);
143
- // Emit G1 = G1 + I6
144
- BuildMI (MBB, MBBI, dl, TII.get (SP::ORri), SP::G1)
145
- .addReg (SP::G1).addImm (NumBytes & ((1 << 10 )-1 ));
146
- BuildMI (MBB, MBBI, dl, TII.get (SP::ADDrr), SP::O6)
147
- .addReg (SP::O6).addReg (SP::G1);
148
- }
164
+ emitSPAdjustment (MF, MBB, MBBI, NumBytes, SP::ADDrr, SP::ADDri);
149
165
}
150
166
151
167
bool SparcFrameLowering::hasReservedCallFrame (const MachineFunction &MF) const {
0 commit comments