[OCaml] Move Llvm.clone_module to its own Llvm_transform_utils module.
authorPeter Zotov <whitequark@whitequark.org>
Mon, 1 Dec 2014 19:50:39 +0000 (19:50 +0000)
committerPeter Zotov <whitequark@whitequark.org>
Mon, 1 Dec 2014 19:50:39 +0000 (19:50 +0000)
This way most code won't link this (substantially large) library,
if compiled statically with LLVM.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223072 91177308-0d34-0410-b5e6-96231b3b80d8

15 files changed:
bindings/ocaml/llvm/CMakeLists.txt
bindings/ocaml/llvm/META.llvm.in
bindings/ocaml/llvm/Makefile
bindings/ocaml/llvm/llvm.ml
bindings/ocaml/llvm/llvm.mli
bindings/ocaml/transforms/CMakeLists.txt
bindings/ocaml/transforms/Makefile
bindings/ocaml/transforms/utils/CMakeLists.txt [new file with mode: 0644]
bindings/ocaml/transforms/utils/Makefile [new file with mode: 0644]
bindings/ocaml/transforms/utils/llvm_transform_utils.ml [new file with mode: 0644]
bindings/ocaml/transforms/utils/llvm_transform_utils.mli [new file with mode: 0644]
bindings/ocaml/transforms/utils/transform_utils_ocaml.c [new file with mode: 0644]
docs/CMakeLists.txt
test/Bindings/OCaml/transform_utils.ml [new file with mode: 0644]
test/CMakeLists.txt

index 0d0fe3bd083bcf6ec8f76ab345ad9a97bbc2f044..d1c4ae52736964960285dd4e36a646c0653c5921 100644 (file)
@@ -1,7 +1,7 @@
 add_ocaml_library(llvm
   OCAML llvm
   C     llvm_ocaml
-  LLVM  core transformutils support)
+  LLVM  core support)
 
 configure_file(
   "${CMAKE_CURRENT_SOURCE_DIR}/META.llvm.in"
index f9808c73eb9afc639590f038dae41b166e0288ff..92896e387a6cc1da3460698c5b34f75a1ddf3032 100644 (file)
@@ -61,6 +61,14 @@ package "scalar_opts" (
     archive(native) = "llvm_scalar_opts.cmxa"
 )
 
+package "transform_utils" (
+    requires = "llvm"
+    version = "@PACKAGE_VERSION@"
+    description = "Transform utilities for LLVM"
+    archive(byte) = "llvm_transform_utils.cma"
+    archive(native) = "llvm_transform_utils.cmxa"
+)
+
 package "vectorize" (
     requires = "llvm"
     version = "@PACKAGE_VERSION@"
index fb682c731b4ca515c923fac925832ad897c33e5e..c0785a154d2220ad1a2a30fc27fe4c28869e2fad 100644 (file)
@@ -13,7 +13,7 @@
 
 LEVEL := ../../..
 LIBRARYNAME := llvm
-UsedComponents := core transformutils
+UsedComponents := core
 UsedOcamlLibs := llvm
 ExtraLibs := -lstdc++
 
index 0df4d40c0a2e5636b970e74d1a2908f2359e4777..8df34378b79d595db7b271f80a96997926a80984 100644 (file)
@@ -313,7 +313,6 @@ external mdkind_id : llcontext -> string -> llmdkind = "llvm_mdkind_id"
 (*===-- Modules -----------------------------------------------------------===*)
 external create_module : llcontext -> string -> llmodule = "llvm_create_module"
 external dispose_module : llmodule -> unit = "llvm_dispose_module"
-external clone_module : llmodule -> llmodule = "LLVMCloneModule"
 external target_triple: llmodule -> string
                       = "llvm_target_triple"
 external set_target_triple: string -> llmodule -> unit
index e5e90c33f4aa28ad978bf2996c277e6aeab44012..e6514327128f43a2ca72d61fd22e97ba3574c290 100644 (file)
@@ -431,9 +431,6 @@ val create_module : llcontext -> string -> llmodule
     [llvm::Module::~Module]. *)
 val dispose_module : llmodule -> unit
 
-(** [clone_module m] returns an exact copy of module [m]. *)
-val clone_module : llmodule -> llmodule
-
 (** [target_triple m] is the target specifier for the module [m], something like
     [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. *)
 val target_triple: llmodule -> string
index 8693ffb6ae21773e8f3b460085e37804fa3f661d..beb8694019b7a87c065d5eb5c1bad3844a3fb2b2 100644 (file)
@@ -1,4 +1,5 @@
 add_subdirectory(ipo)
 add_subdirectory(passmgr_builder)
 add_subdirectory(scalar_opts)
+add_subdirectory(utils)
 add_subdirectory(vectorize)
index f3637a6717cd2c8a3029ba9f87df24e9eb48171d..15bffb406890084ed818d7ab91f5d0d98766343f 100644 (file)
@@ -8,7 +8,7 @@
 ##===----------------------------------------------------------------------===##
 
 LEVEL := ../../..
-DIRS = scalar_opts ipo vectorize passmgr_builder
+DIRS = ipo passmgr_builder scalar_opts utils vectorize
 
 ocamldoc:
        $(Verb) for i in $(DIRS) ; do \
diff --git a/bindings/ocaml/transforms/utils/CMakeLists.txt b/bindings/ocaml/transforms/utils/CMakeLists.txt
new file mode 100644 (file)
index 0000000..37f3eb7
--- /dev/null
@@ -0,0 +1,5 @@
+add_ocaml_library(llvm_transform_utils
+  OCAML    llvm_transform_utils
+  OCAMLDEP llvm
+  C        transform_utils_ocaml
+  LLVM     transformutils)
diff --git a/bindings/ocaml/transforms/utils/Makefile b/bindings/ocaml/transforms/utils/Makefile
new file mode 100644 (file)
index 0000000..76a6f0b
--- /dev/null
@@ -0,0 +1,19 @@
+##===- bindings/ocaml/transforms/utils/Makefile ------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+#
+# This is the makefile for the Objective Caml Llvm_vectorize interface.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL := ../../../..
+LIBRARYNAME := llvm_transform_utils
+UsedComponents := transformutils
+UsedOcamlInterfaces := llvm
+
+include ../../Makefile.ocaml
diff --git a/bindings/ocaml/transforms/utils/llvm_transform_utils.ml b/bindings/ocaml/transforms/utils/llvm_transform_utils.ml
new file mode 100644 (file)
index 0000000..135efe2
--- /dev/null
@@ -0,0 +1,10 @@
+(*===-- llvm_transform_utils.ml - LLVM OCaml Interface --------*- OCaml -*-===*
+ *
+ *                     The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ *===----------------------------------------------------------------------===*)
+
+external clone_module : Llvm.llmodule -> Llvm.llmodule = "llvm_clone_module"
diff --git a/bindings/ocaml/transforms/utils/llvm_transform_utils.mli b/bindings/ocaml/transforms/utils/llvm_transform_utils.mli
new file mode 100644 (file)
index 0000000..1c2b07c
--- /dev/null
@@ -0,0 +1,17 @@
+(*===-- llvm_transform_utils.mli - LLVM OCaml Interface -------*- OCaml -*-===*
+ *
+ *                     The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ *===----------------------------------------------------------------------===*)
+
+(** Transform Utilities.
+
+    This interface provides an OCaml API for LLVM transform utilities, the
+    classes in the [LLVMTransformUtils] library. *)
+
+(** [clone_module m] returns an exact copy of module [m].
+    See the [llvm::CloneModule] function. *)
+external clone_module : Llvm.llmodule -> Llvm.llmodule = "llvm_clone_module"
diff --git a/bindings/ocaml/transforms/utils/transform_utils_ocaml.c b/bindings/ocaml/transforms/utils/transform_utils_ocaml.c
new file mode 100644 (file)
index 0000000..75b2052
--- /dev/null
@@ -0,0 +1,31 @@
+/*===-- vectorize_ocaml.c - LLVM OCaml Glue ---------------------*- C++ -*-===*\
+|*                                                                            *|
+|*                     The LLVM Compiler Infrastructure                       *|
+|*                                                                            *|
+|* This file is distributed under the University of Illinois Open Source      *|
+|* License. See LICENSE.TXT for details.                                      *|
+|*                                                                            *|
+|*===----------------------------------------------------------------------===*|
+|*                                                                            *|
+|* This file glues LLVM's OCaml interface to its C interface. These functions *|
+|* are by and large transparent wrappers to the corresponding C functions.    *|
+|*                                                                            *|
+|* Note that these functions intentionally take liberties with the CAMLparamX *|
+|* macros, since most of the parameters are not GC heap objects.              *|
+|*                                                                            *|
+\*===----------------------------------------------------------------------===*/
+
+#include "llvm-c/Core.h"
+#include "caml/mlvalues.h"
+#include "caml/misc.h"
+
+/*
+ * Do not move directly into external. This function is here to pull in
+ * -lLLVMTransformUtils, which would otherwise be not linked on static builds,
+ * as ld can't see the reference from OCaml code.
+ */
+
+/* llmodule -> llmodule */
+CAMLprim LLVMModuleRef llvm_clone_module(LLVMModuleRef M) {
+  return LLVMCloneModule(M);
+}
index c6986d0863771c12d5d82b072806ac3c891efcd1..da27627f07e9be8e4138a6dc9afa64440c11745f 100644 (file)
@@ -120,6 +120,7 @@ if( NOT uses_ocaml LESS 0 )
         ocaml_llvm_ipo
         ocaml_llvm_passmgr_builder
         ocaml_llvm_scalar_opts
+        ocaml_llvm_transform_utils
         ocaml_llvm_vectorize
       )
 
diff --git a/test/Bindings/OCaml/transform_utils.ml b/test/Bindings/OCaml/transform_utils.ml
new file mode 100644 (file)
index 0000000..6b46df1
--- /dev/null
@@ -0,0 +1,21 @@
+(* RUN: cp %s %T/transform_utils.ml
+ * RUN: %ocamlc -g -warn-error A -package llvm.transform_utils -linkpkg %T/transform_utils.ml -o %t
+ * RUN: %t
+ * RUN: %ocamlopt -g -warn-error A -package llvm.transform_utils -linkpkg %T/transform_utils.ml -o %t
+ * RUN: %t
+ * XFAIL: vg_leak
+ *)
+
+open Llvm
+open Llvm_transform_utils
+
+let context = global_context ()
+
+let test_clone_module () =
+  let m  = create_module context "mod" in
+  let m' = clone_module m in
+  if m == m' then failwith "m == m'";
+  if string_of_llmodule m <> string_of_llmodule m' then failwith "string_of m <> m'"
+
+let () =
+  test_clone_module ()
index 69c9cf6ab10c7b659834f41231ebc58e890eeef8..dabe5f1d66005a2f9ee119919ba24ed6a494efe9 100644 (file)
@@ -82,6 +82,7 @@ if(TARGET ocaml_llvm)
           ocaml_llvm_ipo
           ocaml_llvm_passmgr_builder
           ocaml_llvm_scalar_opts
+          ocaml_llvm_transform_utils
           ocaml_llvm_vectorize
         )
 endif()