llvm.org GIT mirror llvm / 6ed9284
Compute correct frame sizes for SPARC v9 64-bit frames. The save area is twice as big and there is no struct return slot. The stack pointer is always 16-byte aligned (after adding the bias). Also eliminate the stack adjustment instructions around calls when the function has a reserved stack frame. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179083 91177308-0d34-0410-b5e6-96231b3b80d8 Jakob Stoklund Olesen 7 years ago
4 changed file(s) with 56 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
3636 // Get the number of bytes to allocate from the FrameInfo
3737 int NumBytes = (int) MFI->getStackSize();
3838
39 // Emit the correct save instruction based on the number of bytes in
40 // the frame. Minimum stack frame size according to V8 ABI is:
41 // 16 words for register window spill
42 // 1 word for address of returned aggregate-value
43 // + 6 words for passing parameters on the stack
44 // ----------
45 // 23 words * 4 bytes per word = 92 bytes
46 NumBytes += 92;
39 if (SubTarget.is64Bit()) {
40 // All 64-bit stack frames must be 16-byte aligned, and must reserve space
41 // for spilling the 16 window registers at %sp+BIAS..%sp+BIAS+128.
42 NumBytes += 128;
43 // Frames with calls must also reserve space for 6 outgoing arguments
44 // whether they are used or not. LowerCall_64 takes care of that.
45 assert(NumBytes % 16 == 0 && "Stack size not 16-byte aligned");
46 } else {
47 // Emit the correct save instruction based on the number of bytes in
48 // the frame. Minimum stack frame size according to V8 ABI is:
49 // 16 words for register window spill
50 // 1 word for address of returned aggregate-value
51 // + 6 words for passing parameters on the stack
52 // ----------
53 // 23 words * 4 bytes per word = 92 bytes
54 NumBytes += 92;
4755
48 // Round up to next doubleword boundary -- a double-word boundary
49 // is required by the ABI.
50 NumBytes = (NumBytes + 7) & ~7;
56 // Round up to next doubleword boundary -- a double-word boundary
57 // is required by the ABI.
58 NumBytes = RoundUpToAlignment(NumBytes, 8);
59 }
5160 NumBytes = -NumBytes;
5261
5362 if (NumBytes >= -4096) {
6978 void SparcFrameLowering::
7079 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
7180 MachineBasicBlock::iterator I) const {
72 MachineInstr &MI = *I;
73 DebugLoc dl = MI.getDebugLoc();
74 int Size = MI.getOperand(0).getImm();
75 if (MI.getOpcode() == SP::ADJCALLSTACKDOWN)
76 Size = -Size;
77 const SparcInstrInfo &TII =
78 *static_cast(MF.getTarget().getInstrInfo());
79 if (Size)
80 BuildMI(MBB, I, dl, TII.get(SP::ADDri), SP::O6).addReg(SP::O6).addImm(Size);
81 if (!hasReservedCallFrame(MF)) {
82 MachineInstr &MI = *I;
83 DebugLoc DL = MI.getDebugLoc();
84 int Size = MI.getOperand(0).getImm();
85 if (MI.getOpcode() == SP::ADJCALLSTACKDOWN)
86 Size = -Size;
87 const SparcInstrInfo &TII =
88 *static_cast(MF.getTarget().getInstrInfo());
89 if (Size)
90 BuildMI(MBB, I, DL, TII.get(SP::ADDri), SP::O6).addReg(SP::O6)
91 .addImm(Size);
92 }
8193 MBB.erase(I);
8294 }
8395
2121 class SparcSubtarget;
2222
2323 class SparcFrameLowering : public TargetFrameLowering {
24 const SparcSubtarget &SubTarget;
2425 public:
25 explicit SparcFrameLowering(const SparcSubtarget &/*sti*/)
26 : TargetFrameLowering(TargetFrameLowering::StackGrowsDown, 8, 0) {
27 }
26 explicit SparcFrameLowering(const SparcSubtarget &ST)
27 : TargetFrameLowering(TargetFrameLowering::StackGrowsDown,
28 ST.is64Bit() ? 16 : 8, 0, ST.is64Bit() ? 16 : 8),
29 SubTarget(ST) {}
2830
2931 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
3032 /// the function.
911911
912912 // Get the size of the outgoing arguments stack space requirement.
913913 // The stack offset computed by CC_Sparc64 includes all arguments.
914 // We always allocate space for 6 arguments in the prolog.
915 unsigned ArgsSize = std::max(6*8u, CCInfo.getNextStackOffset()) - 6*8u;
914 // Called functions expect 6 argument words to exist in the stack frame, used
915 // or not.
916 unsigned ArgsSize = std::max(6*8u, CCInfo.getNextStackOffset());
916917
917918 // Keep stack frames 16-byte aligned.
918919 ArgsSize = RoundUpToAlignment(ArgsSize, 16);
0 ; RUN: llc < %s -march=sparcv9 -disable-sparc-delay-filler | FileCheck %s
11
22 ; CHECK: intarg
3 ; The save/restore frame is not strictly necessary here, but we would need to
4 ; refer to %o registers instead.
5 ; CHECK: save %sp, -128, %sp
36 ; CHECK: stb %i0, [%i4]
47 ; CHECK: stb %i1, [%i4]
58 ; CHECK: sth %i2, [%i4]
1013 ; CHECK: st [[R]], [%i4]
1114 ; CHECK: ldx [%fp+2231], [[R:%[gilo][0-7]]]
1215 ; CHECK: stx [[R]], [%i4]
16 ; CHECK: restore
1317 define void @intarg(i8 %a0, ; %i0
1418 i8 %a1, ; %i1
1519 i16 %a2, ; %i2
3337 }
3438
3539 ; CHECK: call_intarg
40 ; 16 saved + 8 args.
41 ; CHECK: save %sp, -192, %sp
3642 ; Sign-extend and store the full 64 bits.
3743 ; CHECK: sra %i0, 0, [[R:%[gilo][0-7]]]
3844 ; CHECK: stx [[R]], [%sp+2223]
3945 ; Use %o0-%o5 for outgoing arguments
4046 ; CHECK: or %g0, 5, %o5
4147 ; CHECK: call intarg
48 ; CHECK-NOT: add %sp
49 ; CHECK: restore
4250 define void @call_intarg(i32 %i0, i8* %i1) {
4351 call void @intarg(i8 0, i8 1, i16 2, i32 3, i8* undef, i32 5, i32 %i0, i8* %i1)
4452 ret void
4553 }
4654
4755 ; CHECK: floatarg
56 ; CHECK: save %sp, -128, %sp
4857 ; CHECK: fstod %f1,
4958 ; CHECK: faddd %f2,
5059 ; CHECK: faddd %f4,
8089 }
8190
8291 ; CHECK: call_floatarg
92 ; CHECK: save %sp, -272, %sp
8393 ; Store 4 bytes, right-aligned in slot.
8494 ; CHECK: st %f1, [%sp+2307]
8595 ; Store 8 bytes in full slot.
8696 ; CHECK: std %f2, [%sp+2311]
8797 ; CHECK: fmovd %f2, %f4
8898 ; CHECK: call floatarg
99 ; CHECK-NOT: add %sp
100 ; CHECK: restore
89101 define void @call_floatarg(float %f1, double %d2, float %f5, double *%p) {
90102 %r = call double @floatarg(float %f5, double %d2, double %d2, double %d2,
91103 float %f5, float %f5, float %f5, float %f5,
126138 ; CHECK: fmovd %f2, %f6
127139 ; CHECK: fmovd %f2, %f16
128140 ; CHECK: call mixedarg
141 ; CHECK-NOT: add %sp
142 ; CHECK: restore
129143 define void @call_mixedarg(i64 %i0, double %f2, i16* %i2) {
130144 call void @mixedarg(i8 undef,
131145 float undef,
154168 }
155169
156170 ; CHECK: call_inreg_fi
171 ; Allocate space for 6 arguments, even when only 2 are used.
172 ; CHECK: save %sp, -176, %sp
157173 ; CHECK: sllx %i1, 32, %o0
158174 ; CHECK: fmovs %f5, %f1
159175 ; CHECK: call inreg_fi