@@ -444,15 +444,21 @@ def RetCC_X86_64_OCaml : CallingConv<[
444
444
// Promote all types to i64
445
445
CCIfType<[i8, i16, i32], CCPromoteToType<i64>>,
446
446
447
- // Every function preserves the necessary function arguments
448
- CCIfType<[i64], CCAssignToReg<[R14, RAX, RBX, RDI, RSI, RDX, RCX, R8, R9, R12, R13]>>,
447
+ // Runtime registers (R14, R15) are threaded through function calls
448
+ // See the argument calling conventions for OCaml for more details
449
+ CCIfType<[i64], CCAssignToReg<[R14, R15, RAX, RBX, RDI, RSI, RDX, RCX, R8, R9, R12, R13]>>,
449
450
450
451
CCIfType<[f32, f64], CCAssignToReg<[
451
452
XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
452
453
XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15
453
454
]>>
454
455
]>;
455
456
457
+ def RetCC_X86_64_OCaml_C_Call : CallingConv<[
458
+ CCIfType<[i64], CCAssignToReg<[R14, R15]>>,
459
+
460
+ CCDelegateTo<RetCC_X86_64_C>
461
+ ]>;
456
462
457
463
defm X86_32_RegCall :
458
464
X86_RegCall_base<RC_X86_32_RegCall>;
@@ -509,6 +515,7 @@ def RetCC_X86_64 : CallingConv<[
509
515
510
516
// Handle OCaml calls
511
517
CCIfCC<"CallingConv::OCaml", CCDelegateTo<RetCC_X86_64_OCaml>>,
518
+ CCIfCC<"CallingConv::OCaml_C_Call", CCDelegateTo<RetCC_X86_64_OCaml_C_Call>>,
512
519
513
520
// Otherwise, drop to normal X86-64 CC
514
521
CCDelegateTo<RetCC_X86_64_C>
@@ -725,9 +732,8 @@ def CC_X86_64_OCaml : CallingConv<[
725
732
// (registers containing pointers to data structures maintained by the
726
733
// runtime) must be preserved through the run of the program. To ensure LLVM
727
734
// doesn't mess with them, they are explicitly threaded through function calls
728
- // and returns. These are R14 and R15. Note that R15 isn't listed since it is
729
- // not implemented yet.
730
- CCIfType<[i64], CCAssignToReg<[R14, RAX, RBX, RDI, RSI, RDX, RCX, R8, R9, R12, R13]>>,
735
+ // and returns. These are R14 and R15.
736
+ CCIfType<[i64], CCAssignToReg<[R14, R15, RAX, RBX, RDI, RSI, RDX, RCX, R8, R9, R12, R13]>>,
731
737
732
738
CCIfType<[f32, f64], CCAssignToReg<[
733
739
XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
@@ -738,7 +744,7 @@ def CC_X86_64_OCaml : CallingConv<[
738
744
def CC_X86_64_OCaml_C_Call : CallingConv<[
739
745
// OCaml wraps C calls with another function that transfers stack arguments.
740
746
// RAX contains the function address, and R12 contains the size of the stack arguments.
741
- CCIfType<[i64], CCAssignToReg<[RAX, R12]>>,
747
+ CCIfType<[i64], CCAssignToReg<[R14, R15, RAX, R12]>>,
742
748
743
749
// Follow C convention normally otherwise
744
750
CCDelegateTo<CC_X86_64_C>
@@ -1173,6 +1179,9 @@ def CSR_NoRegs : CalleeSavedRegs<(add)>;
1173
1179
def CSR_32 : CalleeSavedRegs<(add ESI, EDI, EBX, EBP)>;
1174
1180
def CSR_64 : CalleeSavedRegs<(add RBX, R12, R13, R14, R15, RBP)>;
1175
1181
1182
+ // R14 and R15 are used as return registers, so they aren't callee saved.
1183
+ def CSR_64_OCaml_C_Call : CalleeSavedRegs<(sub CSR_64, R14, R15)>;
1184
+
1176
1185
def CSR_64_SwiftError : CalleeSavedRegs<(sub CSR_64, R12)>;
1177
1186
def CSR_64_SwiftTail : CalleeSavedRegs<(sub CSR_64, R13, R14)>;
1178
1187
0 commit comments