@@ -204,6 +204,44 @@ def RetCC_AArch64_WebKit_JS : CallingConv<[
204
204
[Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7]>>
205
205
]>;
206
206
207
+ //===----------------------------------------------------------------------===//
208
+ // ARM64 Calling Convention for GHC
209
+ //===----------------------------------------------------------------------===//
210
+
211
+ // This calling convention is specific to the Glasgow Haskell Compiler.
212
+ // The only documentation is the GHC source code, specifically the C header
213
+ // file:
214
+ //
215
+ // https://github.com/ghc/ghc/blob/master/includes/stg/MachRegs.h
216
+ //
217
+ // which defines the registers for the Spineless Tagless G-Machine (STG) that
218
+ // GHC uses to implement lazy evaluation. The generic STG machine has a set of
219
+ // registers which are mapped to appropriate set of architecture specific
220
+ // registers for each CPU architecture.
221
+ //
222
+ // The STG Machine is documented here:
223
+ //
224
+ // https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/GeneratedCode
225
+ //
226
+ // The AArch64 register mapping is under the heading "The ARMv8/AArch64 ABI
227
+ // register mapping".
228
+
229
+ def CC_AArch64_GHC : CallingConv<[
230
+ // Handle all vector types as either f64 or v2f64.
231
+ CCIfType<[v1i64, v2i32, v4i16, v8i8, v2f32], CCBitConvertToType<f64>>,
232
+ CCIfType<[v2i64, v4i32, v8i16, v16i8, v4f32, f128], CCBitConvertToType<v2f64>>,
233
+
234
+ CCIfType<[v2f64], CCAssignToReg<[Q4, Q5]>>,
235
+ CCIfType<[f32], CCAssignToReg<[S8, S9, S10, S11]>>,
236
+ CCIfType<[f64], CCAssignToReg<[D12, D13, D14, D15]>>,
237
+
238
+ // Promote i8/i16/i32 arguments to i64.
239
+ CCIfType<[i8, i16, i32], CCPromoteToType<i64>>,
240
+
241
+ // Pass in STG registers: Base, Sp, Hp, R1, R2, R3, R4, R5, R6, SpLim
242
+ CCIfType<[i64], CCAssignToReg<[X19, X20, X21, X22, X23, X24, X25, X26, X27, X28]>>
243
+ ]>;
244
+
207
245
// FIXME: LR is only callee-saved in the sense that *we* preserve it and are
208
246
// presumably a callee to someone. External functions may not do so, but this
209
247
// is currently safe since BL has LR as an implicit-def and what happens after a
@@ -249,3 +287,4 @@ def CSR_AArch64_AllRegs
249
287
(sequence "S%u", 0, 31), (sequence "D%u", 0, 31),
250
288
(sequence "Q%u", 0, 31))>;
251
289
290
+ def CSR_AArch64_NoRegs : CalleeSavedRegs<(add)>;
0 commit comments