@@ -440,6 +440,19 @@ def RetCC_X86_64_HHVM: CallingConv<[
440
440
RAX, R10, R11, R13, R14, R15]>>
441
441
]>;
442
442
443
+ def RetCC_X86_64_OCaml : CallingConv<[
444
+ // Promote all types to i64
445
+ CCIfType<[i8, i16, i32], CCPromoteToType<i64>>,
446
+
447
+ // Every function preserves the necessary function arguments
448
+ CCIfType<[i64], CCAssignToReg<[R14, RAX, RBX, RDI, RSI, RDX, RCX, R8, R9, R12, R13]>>,
449
+
450
+ CCIfType<[f32, f64], CCAssignToReg<[
451
+ XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
452
+ XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15
453
+ ]>>
454
+ ]>;
455
+
443
456
444
457
defm X86_32_RegCall :
445
458
X86_RegCall_base<RC_X86_32_RegCall>;
@@ -494,6 +507,9 @@ def RetCC_X86_64 : CallingConv<[
494
507
// Mingw64 and native Win64 use Win64 CC
495
508
CCIfSubtarget<"isTargetWin64()", CCDelegateTo<RetCC_X86_Win64_C>>,
496
509
510
+ // Handle OCaml calls
511
+ CCIfCC<"CallingConv::OCaml", CCDelegateTo<RetCC_X86_64_OCaml>>,
512
+
497
513
// Otherwise, drop to normal X86-64 CC
498
514
CCDelegateTo<RetCC_X86_64_C>
499
515
]>;
@@ -700,6 +716,24 @@ def CC_X86_Win64_VectorCall : CallingConv<[
700
716
CCDelegateTo<CC_X86_Win64_C>
701
717
]>;
702
718
719
+ def CC_X86_64_OCaml : CallingConv<[
720
+ // Promote i8/i16/i32 arguments to i64.
721
+ CCIfType<[i8, i16, i32], CCPromoteToType<i64>>,
722
+
723
+ // See https://github.com/oxcaml/oxcaml/blob/main/backend/amd64/proc.ml#L34
724
+ // for further details on the registers and their meaning. Runtime registers
725
+ // (registers containing pointers to data structures maintained by the
726
+ // runtime) must be preserved through the run of the program. To ensure LLVM
727
+ // 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]>>,
731
+
732
+ CCIfType<[f32, f64], CCAssignToReg<[
733
+ XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
734
+ XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15
735
+ ]>>
736
+ ]>;
703
737
704
738
def CC_X86_64_GHC : CallingConv<[
705
739
// Promote i8/i16/i32 arguments to i64.
@@ -1103,6 +1137,7 @@ def CC_X86_64 : CallingConv<[
1103
1137
CCIfSubtarget<"isTargetWin64()", CCDelegateTo<CC_X86_Win64_RegCall>>>,
1104
1138
CCIfCC<"CallingConv::X86_RegCall", CCDelegateTo<CC_X86_SysV64_RegCall>>,
1105
1139
CCIfCC<"CallingConv::X86_INTR", CCCustom<"CC_X86_Intr">>,
1140
+ CCIfCC<"CallingConv::OCaml", CCDelegateTo<CC_X86_64_OCaml>>,
1106
1141
1107
1142
// Mingw64 and native Win64 use Win64 CC
1108
1143
CCIfSubtarget<"isTargetWin64()", CCDelegateTo<CC_X86_Win64_C>>,
0 commit comments