Advertisement
Guest User

mcjit patch

a guest
Oct 25th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.80 KB | None | 0 0
  1. diff --git a/bindings/ocaml/executionengine/executionengine_ocaml.c b/bindings/ocaml/executionengine/executionengine_ocaml.c
  2. index 4b44a91..7463810 100644
  3. --- a/bindings/ocaml/executionengine/executionengine_ocaml.c
  4. +++ b/bindings/ocaml/executionengine/executionengine_ocaml.c
  5. @@ -200,6 +200,24 @@ llvm_ee_create_jit(LLVMModuleRef M, value OptLevel) {
  6.    return JIT;
  7.  }
  8.  
  9. +/* llmodule -> llcompileroption -> ExecutionEngine.t */
  10. +CAMLprim LLVMExecutionEngineRef
  11. +llvm_ee_create_mcjit(LLVMModuleRef M, value OptRecord) {
  12. +  LLVMExecutionEngineRef MCJIT;
  13. +  char *Error;
  14. +  struct LLVMMCJITCompilerOptions Options = {
  15. +     .OptLevel = Int_val(Field(OptRecord, 0)),
  16. +     .CodeModel = Int_val(Field(OptRecord, 1)),
  17. +     .NoFramePointerElim = Int_val(Field(OptRecord, 2)),
  18. +     .EnableFastISel = Int_val(Field(OptRecord, 3)),
  19. +     .MCJMM = NULL
  20. +  };
  21. +  if (LLVMCreateMCJITCompilerForModule(&MCJIT, M, &Options,
  22. +                      sizeof(Options), &Error))
  23. +    llvm_raise(llvm_ee_error_exn, Error);
  24. +  return MCJIT;
  25. +}
  26. +
  27.  /* ExecutionEngine.t -> unit */
  28.  CAMLprim value llvm_ee_dispose(LLVMExecutionEngineRef EE) {
  29.    LLVMDisposeExecutionEngine(EE);
  30. diff --git a/bindings/ocaml/executionengine/llvm_executionengine.ml b/bindings/ocaml/executionengine/llvm_executionengine.ml
  31. index a738df7..64d21bc 100644
  32. --- a/bindings/ocaml/executionengine/llvm_executionengine.ml
  33. +++ b/bindings/ocaml/executionengine/llvm_executionengine.ml
  34. @@ -14,6 +14,25 @@ external register_exns: exn -> unit
  35.    = "llvm_register_ee_exns"
  36.  
  37.  
  38. +module CodeModel = struct
  39. +  type t =
  40. +    | Default
  41. +    | JIT_default
  42. +    | Small
  43. +    | Kernel
  44. +    | Medium
  45. +    | Large
  46. +end
  47. +
  48. +
  49. +type mcjitcompileroptions =
  50. +    { opt_level: int;
  51. +      code_model: CodeModel.t;
  52. +      no_framepointer_elim: bool;
  53. +      enable_fast_isel: bool;
  54. +    }
  55. +
  56. +
  57.  module GenericValue = struct
  58.    type t
  59.    
  60. @@ -62,6 +81,8 @@ module ExecutionEngine = struct
  61.      = "llvm_ee_create_interpreter"
  62.    external create_jit: Llvm.llmodule -> int -> t
  63.      = "llvm_ee_create_jit"
  64. +  external create_mcjit: Llvm.llmodule -> mcjitcompileroptions -> t
  65. +    = "llvm_ee_create_mcjit"
  66.    external dispose: t -> unit
  67.      = "llvm_ee_dispose"
  68.    external add_module: Llvm.llmodule -> t -> unit
  69. diff --git a/test/Bindings/Ocaml/executionengine.ml b/test/Bindings/Ocaml/executionengine.ml
  70. index 8e24949..be8b53c 100644
  71. --- a/test/Bindings/Ocaml/executionengine.ml
  72. +++ b/test/Bindings/Ocaml/executionengine.ml
  73. @@ -18,6 +18,9 @@ let i8_type = Llvm.i8_type context
  74.  let i32_type = Llvm.i32_type context
  75.  let i64_type = Llvm.i64_type context
  76.  let double_type = Llvm.double_type context
  77. +type ee_engine = Interpreter
  78. +               | JIT
  79. +               | MCJIT
  80.  
  81.  let bomb msg =
  82.    prerr_endline msg;
  83. @@ -60,7 +63,7 @@ let test_genericvalue () =
  84.    let i64gv = GenericValue.of_int64 i64_type (Int64.of_int 6) in
  85.    assert ((Int64.of_int 6) = GenericValue.as_int64 i64gv)
  86.  
  87. -let test_executionengine () =
  88. +let test_executionengine ?(engine = Interpreter) () =
  89.    (* create *)
  90.    let m = create_module (global_context ()) "test_module" in
  91.    let main = define_main_fn m 42 in
  92. @@ -68,7 +71,13 @@ let test_executionengine () =
  93.    let m2 = create_module (global_context ()) "test_module2" in
  94.    define_plus m2;
  95.    
  96. -  let ee = ExecutionEngine.create m in
  97. +  let ee =
  98. +    if engine = Interpreter then
  99. +      ExecutionEngine.create_interpreter m
  100. +    else if engine = JIT then
  101. +      ExecutionEngine.create_jit m
  102. +    else
  103. +      ExecutionEngine.create_mcjit m in
  104.    ExecutionEngine.add_module m2 ee;
  105.    
  106.    (* run_static_ctors *)
  107. @@ -115,4 +124,6 @@ let test_executionengine () =
  108.  
  109.  let _ =
  110.    test_genericvalue ();
  111. -  test_executionengine ()
  112. +  test_executionengine ~engine:Interpreter ()
  113. +  test_executionengine ~engine:JIT ()
  114. +  test_executionengine ~engine:MCJIT ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement