Skip to content

Commit b332236

Browse files
committed
Add support for the ARM GHC calling convention, this patch was in 3.0,
but somehow managed to be dropped later. Patch by Karel Gardas. llvm-svn: 161226
1 parent 0567de8 commit b332236

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,20 @@ ARMBaseRegisterInfo::ARMBaseRegisterInfo(const ARMBaseInstrInfo &tii,
6262

6363
const uint16_t*
6464
ARMBaseRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
65+
bool ghcCall = false;
66+
67+
if (MF) {
68+
const Function *F = MF->getFunction();
69+
ghcCall = (F ? F->getCallingConv() == CallingConv::GHC : false);
70+
}
71+
72+
if (ghcCall) {
73+
return CSR_GHC_SaveList;
74+
}
75+
else {
6576
return (STI.isTargetIOS() && !STI.isAAPCS_ABI())
6677
? CSR_iOS_SaveList : CSR_AAPCS_SaveList;
78+
}
6779
}
6880

6981
const uint32_t*

llvm/lib/Target/ARM/ARMCallingConv.td

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,25 @@ def RetFastCC_ARM_APCS : CallingConv<[
7979
CCDelegateTo<RetCC_ARM_APCS>
8080
]>;
8181

82+
//===----------------------------------------------------------------------===//
83+
// ARM APCS Calling Convention for GHC
84+
//===----------------------------------------------------------------------===//
85+
86+
def CC_ARM_APCS_GHC : CallingConv<[
87+
// Handle all vector types as either f64 or v2f64.
88+
CCIfType<[v1i64, v2i32, v4i16, v8i8, v2f32], CCBitConvertToType<f64>>,
89+
CCIfType<[v2i64, v4i32, v8i16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
90+
91+
CCIfType<[v2f64], CCAssignToReg<[Q4, Q5]>>,
92+
CCIfType<[f64], CCAssignToReg<[D8, D9, D10, D11]>>,
93+
CCIfType<[f32], CCAssignToReg<[S16, S17, S18, S19, S20, S21, S22, S23]>>,
94+
95+
// Promote i8/i16 arguments to i32.
96+
CCIfType<[i8, i16], CCPromoteToType<i32>>,
97+
98+
// Pass in STG registers: Base, Sp, Hp, R1, R2, R3, R4, SpLim
99+
CCIfType<[i32], CCAssignToReg<[R4, R5, R6, R7, R8, R9, R10, R11]>>
100+
]>;
82101

83102
//===----------------------------------------------------------------------===//
84103
// ARM AAPCS (EABI) Calling Convention, common parts
@@ -171,3 +190,9 @@ def CSR_AAPCS : CalleeSavedRegs<(add LR, R11, R10, R9, R8, R7, R6, R5, R4,
171190
// iOS ABI deviates from ARM standard ABI. R9 is not a callee-saved register.
172191
// Also save R7-R4 first to match the stack frame fixed spill areas.
173192
def CSR_iOS : CalleeSavedRegs<(add LR, R7, R6, R5, R4, (sub CSR_AAPCS, R9))>;
193+
194+
// GHC set of callee saved regs is empty as all those regs are
195+
// used for passing STG regs around
196+
// add is a workaround for not being able to compile empty list:
197+
// def CSR_GHC : CalleeSavedRegs<()>;
198+
def CSR_GHC : CalleeSavedRegs<(add)>;

llvm/lib/Target/ARM/ARMFastISel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,11 @@ CCAssignFn *ARMFastISel::CCAssignFnForCall(CallingConv::ID CC,
18421842
return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS);
18431843
case CallingConv::ARM_APCS:
18441844
return (Return ? RetCC_ARM_APCS: CC_ARM_APCS);
1845+
case CallingConv::GHC:
1846+
if (Return)
1847+
llvm_unreachable("Can't return in GHC call convention");
1848+
else
1849+
return CC_ARM_APCS_GHC;
18451850
}
18461851
}
18471852

llvm/lib/Target/ARM/ARMFrameLowering.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "ARMBaseInstrInfo.h"
1616
#include "ARMBaseRegisterInfo.h"
1717
#include "ARMMachineFunctionInfo.h"
18+
#include "llvm/CallingConv.h"
19+
#include "llvm/Function.h"
1820
#include "MCTargetDesc/ARMAddressingModes.h"
1921
#include "llvm/Function.h"
2022
#include "llvm/CodeGen/MachineFrameInfo.h"
@@ -151,6 +153,10 @@ void ARMFrameLowering::emitPrologue(MachineFunction &MF) const {
151153
int FramePtrSpillFI = 0;
152154
int D8SpillFI = 0;
153155

156+
// All calls are tail calls in GHC calling conv, and functions have no prologue/epilogue.
157+
if (MF.getFunction()->getCallingConv() == CallingConv::GHC)
158+
return;
159+
154160
// Allocate the vararg register save area. This is not counted in NumBytes.
155161
if (VARegSaveSize)
156162
emitSPUpdate(isARM, MBB, MBBI, dl, TII, -VARegSaveSize,
@@ -354,6 +360,10 @@ void ARMFrameLowering::emitEpilogue(MachineFunction &MF,
354360
int NumBytes = (int)MFI->getStackSize();
355361
unsigned FramePtr = RegInfo->getFrameRegister(MF);
356362

363+
// All calls are tail calls in GHC calling conv, and functions have no prologue/epilogue.
364+
if (MF.getFunction()->getCallingConv() == CallingConv::GHC)
365+
return;
366+
357367
if (!AFI->hasStackFrame()) {
358368
if (NumBytes != 0)
359369
emitSPUpdate(isARM, MBB, MBBI, dl, TII, NumBytes);

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,8 @@ CCAssignFn *ARMTargetLowering::CCAssignFnForNode(CallingConv::ID CC,
11711171
return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS);
11721172
case CallingConv::ARM_APCS:
11731173
return (Return ? RetCC_ARM_APCS : CC_ARM_APCS);
1174+
case CallingConv::GHC:
1175+
return (Return ? RetCC_ARM_APCS : CC_ARM_APCS_GHC);
11741176
}
11751177
}
11761178

0 commit comments

Comments
 (0)