Skip to content

Commit 96c9c21

Browse files
committed
[m88k] Remove use of ADJCALLSTACKDOWN/ADJCALLSTACKUP
The ABI uses a reserved call frame, which is statically reserved in the prologue. Following the discussion in llvm/llvm-project#77812, these pseudo instructions can be removed early. My solution here is to not insert them in the first place. The calculation of the reserved frame size is now done during call lowering.
1 parent 003740b commit 96c9c21

File tree

6 files changed

+15
-55
lines changed

6 files changed

+15
-55
lines changed

llvm/lib/Target/M88k/GISel/M88kCallLowering.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "llvm/CodeGen/MachineMemOperand.h"
3131
#include "llvm/CodeGen/Register.h"
3232
#include "llvm/CodeGen/TargetCallingConv.h"
33+
#include "llvm/CodeGen/TargetFrameLowering.h"
3334
#include "llvm/CodeGenTypes/LowLevelType.h"
3435
#include "llvm/Support/Alignment.h"
3536
#include <cassert>
@@ -423,9 +424,6 @@ bool M88kCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
423424

424425
// TODO Handle tail calls.
425426

426-
MachineInstrBuilder CallSeqStart;
427-
CallSeqStart = MIRBuilder.buildInstr(M88k::ADJCALLSTACKDOWN);
428-
429427
// Create a temporarily-floating call instruction so we can add the implicit
430428
// uses of arg registers.
431429
unsigned Opc = Info.Callee.isReg() ? M88k::JSR : M88k::BSR;
@@ -471,10 +469,19 @@ bool M88kCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
471469
return false;
472470
}
473471

474-
CallSeqStart.addImm(ArgAssigner.StackSize).addImm(0);
475-
MIRBuilder.buildInstr(M88k::ADJCALLSTACKUP)
476-
.addImm(ArgAssigner.StackSize)
477-
.addImm(0);
472+
MachineFrameInfo &MFI = MF.getFrameInfo();
473+
const TargetFrameLowering *TFL = MF.getSubtarget().getFrameLowering();
474+
assert(TFL->hasReservedCallFrame(MF) &&
475+
"ADJSTACKDOWN and ADJSTACKUP should be no-ops");
476+
// Set the MaxCallFrameSize value. There is no need to emit the
477+
// ADJCALLSTACKDOWN/ADJCALLSTACKUP instructions since it serves no further
478+
// purpose as the call frame is statically reserved in the prolog. Set
479+
// AdjustsStack as MI is *not* mapped as a frame instruction.
480+
unsigned AlignedCallFrameSize =
481+
alignTo(ArgAssigner.StackSize, TFL->getStackAlign());
482+
if (AlignedCallFrameSize > MFI.getMaxCallFrameSize())
483+
MFI.setMaxCallFrameSize(AlignedCallFrameSize);
484+
MFI.setAdjustsStack(true);
478485

479486
return true;
480487
}

llvm/lib/Target/M88k/M88kFrameLowering.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,6 @@ bool M88kFrameLowering::spillCalleeSavedRegisters(
212212
return true;
213213
}
214214

215-
void M88kFrameLowering::processFunctionBeforeFrameFinalized(
216-
MachineFunction &MF, RegScavenger *RS) const {
217-
MachineFrameInfo &MFI = MF.getFrameInfo();
218-
219-
// Make sure that the call frame size has stack alignment.
220-
// The same effect could also be reached by align the size of each call frame.
221-
assert(MFI.isMaxCallFrameSizeComputed() && "MaxCallFrame not computed");
222-
unsigned MaxCallFrameSize = MFI.getMaxCallFrameSize();
223-
MaxCallFrameSize = alignTo(MaxCallFrameSize, getStackAlign());
224-
MFI.setMaxCallFrameSize(MaxCallFrameSize);
225-
}
226-
227215
void M88kFrameLowering::emitPrologue(MachineFunction &MF,
228216
MachineBasicBlock &MBB) const {
229217
assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported");
@@ -286,13 +274,6 @@ void M88kFrameLowering::emitPrologue(MachineFunction &MF,
286274
}
287275
}
288276

289-
MachineBasicBlock::iterator M88kFrameLowering::eliminateCallFramePseudoInstr(
290-
MachineFunction &MF, MachineBasicBlock &MBB,
291-
MachineBasicBlock::iterator I) const {
292-
// Discard ADJCALLSTACKDOWN, ADJCALLSTACKUP instructions.
293-
return MBB.erase(I);
294-
}
295-
296277
void M88kFrameLowering::emitEpilogue(MachineFunction &MF,
297278
MachineBasicBlock &MBB) const {
298279
MachineFrameInfo &MFI = MF.getFrameInfo();

llvm/lib/Target/M88k/M88kFrameLowering.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,10 @@ class M88kFrameLowering : public TargetFrameLowering {
2929
public:
3030
M88kFrameLowering(const M88kSubtarget &Subtarget);
3131

32-
void processFunctionBeforeFrameFinalized(
33-
MachineFunction &MF, RegScavenger *RS = nullptr) const override;
3432
void processFunctionBeforeFrameIndicesReplaced(
3533
MachineFunction &MF, RegScavenger *RS = nullptr) const override;
3634
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
3735
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
38-
MachineBasicBlock::iterator
39-
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
40-
MachineBasicBlock::iterator MI) const override;
4136
bool hasFP(const MachineFunction &MF) const override;
4237
bool hasReservedCallFrame(const MachineFunction &MF) const override;
4338
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,

llvm/lib/Target/M88k/M88kInstrInfo.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ using namespace llvm;
5757
void M88kInstrInfo::anchor() {}
5858

5959
M88kInstrInfo::M88kInstrInfo(const M88kSubtarget &STI)
60-
: M88kGenInstrInfo(M88k::ADJCALLSTACKDOWN, M88k::ADJCALLSTACKUP), STI(STI),
61-
RI() {}
60+
: M88kGenInstrInfo(-1, -1), STI(STI), RI() {}
6261

6362
std::pair<unsigned, unsigned>
6463
M88kInstrInfo::decomposeMachineOperandsTargetFlags(unsigned TF) const {

llvm/lib/Target/M88k/M88kInstrInfo.td

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,6 @@ def invshmask32 : IntImmLeaf<i32, [{
306306
return isUInt<32>(Val) && isShiftedMask_64(~Val & 0xffffffff);
307307
}]>;
308308

309-
// ---------------------------------------------------------------------------//
310-
// Pseudo instructions.
311-
// ---------------------------------------------------------------------------//
312-
let hasSideEffects = 1 in {
313-
def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2), []>;
314-
def ADJCALLSTACKUP : Pseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2), []>;
315-
}
316-
317309
// ---------------------------------------------------------------------------//
318310
// Generic patterns.
319311
// ---------------------------------------------------------------------------//

llvm/test/CodeGen/M88k/GlobalISel/call-return.ll

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ define void @f1() {
1111
define void @callf1() {
1212
; CHECK-LABEL: name: callf1
1313
; CHECK: bb.1 (%ir-block.0):
14-
; CHECK-NEXT: ADJCALLSTACKDOWN 0, 0
1514
; CHECK-NEXT: BSR @f1, csr_m88k, implicit-def $r1
16-
; CHECK-NEXT: ADJCALLSTACKUP 0, 0
1715
; CHECK-NEXT: RET
1816
call void() @f1()
1917
ret void
@@ -33,10 +31,8 @@ define void @callf2() {
3331
; CHECK-LABEL: name: callf2
3432
; CHECK: bb.1 (%ir-block.0):
3533
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
36-
; CHECK-NEXT: ADJCALLSTACKDOWN 0, 0
3734
; CHECK-NEXT: $r2 = COPY [[C]](s32)
3835
; CHECK-NEXT: BSR @f2, csr_m88k, implicit-def $r1, implicit $r2
39-
; CHECK-NEXT: ADJCALLSTACKUP 0, 0
4036
; CHECK-NEXT: RET
4137
call void(i32) @f2(i32 1)
4238
ret void
@@ -57,11 +53,9 @@ define i32 @callf3() {
5753
; CHECK-LABEL: name: callf3
5854
; CHECK: bb.1 (%ir-block.0):
5955
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
60-
; CHECK-NEXT: ADJCALLSTACKDOWN 0, 0
6156
; CHECK-NEXT: $r2 = COPY [[C]](s32)
6257
; CHECK-NEXT: BSR @f3, csr_m88k, implicit-def $r1, implicit $r2, implicit-def $r2
6358
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $r2
64-
; CHECK-NEXT: ADJCALLSTACKUP 0, 0
6559
; CHECK-NEXT: $r2 = COPY [[COPY]](s32)
6660
; CHECK-NEXT: RET implicit $r2
6761
%res = call i32(i32) @f3(i32 1)
@@ -87,12 +81,10 @@ define i32 @callf4() {
8781
; CHECK: bb.1 (%ir-block.0):
8882
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
8983
; CHECK-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 2
90-
; CHECK-NEXT: ADJCALLSTACKDOWN 0, 0
9184
; CHECK-NEXT: $r2 = COPY [[C]](s32)
9285
; CHECK-NEXT: $r3 = COPY [[C1]](s32)
9386
; CHECK-NEXT: BSR @f4, csr_m88k, implicit-def $r1, implicit $r2, implicit $r3, implicit-def $r2
9487
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $r2
95-
; CHECK-NEXT: ADJCALLSTACKUP 0, 0
9688
; CHECK-NEXT: $r2 = COPY [[COPY]](s32)
9789
; CHECK-NEXT: RET implicit $r2
9890
%res = call i32(i32, i32) @f4(i32 1, i32 2)
@@ -171,12 +163,10 @@ define float @callf8() {
171163
; CHECK: bb.1 (%ir-block.0):
172164
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_FCONSTANT float 1.000000e+00
173165
; CHECK-NEXT: [[C1:%[0-9]+]]:_(s32) = G_FCONSTANT float 2.000000e+00
174-
; CHECK-NEXT: ADJCALLSTACKDOWN 0, 0
175166
; CHECK-NEXT: $r2 = COPY [[C]](s32)
176167
; CHECK-NEXT: $r3 = COPY [[C1]](s32)
177168
; CHECK-NEXT: BSR @f8, csr_m88k, implicit-def $r1, implicit $r2, implicit $r3, implicit-def $r2
178169
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $r2
179-
; CHECK-NEXT: ADJCALLSTACKUP 0, 0
180170
; CHECK-NEXT: $r2 = COPY [[COPY]](s32)
181171
; CHECK-NEXT: RET implicit $r2
182172
%res = call float(float, float) @f8(float 1.0, float 2.0)
@@ -208,7 +198,6 @@ define double @callf9() {
208198
; CHECK: bb.1 (%ir-block.0):
209199
; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_FCONSTANT double 1.000000e+00
210200
; CHECK-NEXT: [[C1:%[0-9]+]]:_(s64) = G_FCONSTANT double 2.000000e+00
211-
; CHECK-NEXT: ADJCALLSTACKDOWN 0, 0
212201
; CHECK-NEXT: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[C]](s64)
213202
; CHECK-NEXT: [[UV2:%[0-9]+]]:_(s32), [[UV3:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[C1]](s64)
214203
; CHECK-NEXT: $r3 = COPY [[UV]](s32)
@@ -219,7 +208,6 @@ define double @callf9() {
219208
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $r3
220209
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $r2
221210
; CHECK-NEXT: [[MV:%[0-9]+]]:_(s64) = G_MERGE_VALUES [[COPY]](s32), [[COPY1]](s32)
222-
; CHECK-NEXT: ADJCALLSTACKUP 0, 0
223211
; CHECK-NEXT: [[UV4:%[0-9]+]]:_(s32), [[UV5:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[MV]](s64)
224212
; CHECK-NEXT: $r3 = COPY [[UV4]](s32)
225213
; CHECK-NEXT: $r2 = COPY [[UV5]](s32)
@@ -263,7 +251,6 @@ define i32 @callf11() {
263251
; CHECK-NEXT: [[C7:%[0-9]+]]:_(s32) = G_CONSTANT i32 8
264252
; CHECK-NEXT: [[C8:%[0-9]+]]:_(s32) = G_CONSTANT i32 9
265253
; CHECK-NEXT: [[C9:%[0-9]+]]:_(s32) = G_CONSTANT i32 10
266-
; CHECK-NEXT: ADJCALLSTACKDOWN 8, 0
267254
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $r31
268255
; CHECK-NEXT: [[C10:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
269256
; CHECK-NEXT: [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY]], [[C10]](s32)
@@ -281,7 +268,6 @@ define i32 @callf11() {
281268
; CHECK-NEXT: $r9 = COPY [[C7]](s32)
282269
; CHECK-NEXT: BSR @f10, csr_m88k, implicit-def $r1, implicit $r2, implicit $r3, implicit $r4, implicit $r5, implicit $r6, implicit $r7, implicit $r8, implicit $r9, implicit-def $r2
283270
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $r2
284-
; CHECK-NEXT: ADJCALLSTACKUP 8, 0
285271
; CHECK-NEXT: $r2 = COPY [[COPY1]](s32)
286272
; CHECK-NEXT: RET implicit $r2
287273
%res = call i32(i32,i32,i32,i32,i32,i32,i32,i32,i32,i32) @f10(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10)

0 commit comments

Comments
 (0)