[llvm] r223072 - [OCaml] Move Llvm.clone_module to its own Llvm_transform_utils module.
Peter Zotov
whitequark at whitequark.org
Mon Dec 1 11:50:40 PST 2014
Author: whitequark
Date: Mon Dec 1 13:50:39 2014
New Revision: 223072
URL: http://llvm.org/viewvc/llvm-project?rev=223072&view=rev
Log:
[OCaml] Move Llvm.clone_module to its own Llvm_transform_utils module.
This way most code won't link this (substantially large) library,
if compiled statically with LLVM.
Added:
llvm/trunk/bindings/ocaml/transforms/utils/
llvm/trunk/bindings/ocaml/transforms/utils/CMakeLists.txt
llvm/trunk/bindings/ocaml/transforms/utils/Makefile
llvm/trunk/bindings/ocaml/transforms/utils/llvm_transform_utils.ml
llvm/trunk/bindings/ocaml/transforms/utils/llvm_transform_utils.mli
llvm/trunk/bindings/ocaml/transforms/utils/transform_utils_ocaml.c
llvm/trunk/test/Bindings/OCaml/transform_utils.ml
Modified:
llvm/trunk/bindings/ocaml/llvm/CMakeLists.txt
llvm/trunk/bindings/ocaml/llvm/META.llvm.in
llvm/trunk/bindings/ocaml/llvm/Makefile
llvm/trunk/bindings/ocaml/llvm/llvm.ml
llvm/trunk/bindings/ocaml/llvm/llvm.mli
llvm/trunk/bindings/ocaml/transforms/CMakeLists.txt
llvm/trunk/bindings/ocaml/transforms/Makefile
llvm/trunk/docs/CMakeLists.txt
llvm/trunk/test/CMakeLists.txt
Modified: llvm/trunk/bindings/ocaml/llvm/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/CMakeLists.txt?rev=223072&r1=223071&r2=223072&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/CMakeLists.txt (original)
+++ llvm/trunk/bindings/ocaml/llvm/CMakeLists.txt Mon Dec 1 13:50:39 2014
@@ -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"
Modified: llvm/trunk/bindings/ocaml/llvm/META.llvm.in
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/META.llvm.in?rev=223072&r1=223071&r2=223072&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/META.llvm.in (original)
+++ llvm/trunk/bindings/ocaml/llvm/META.llvm.in Mon Dec 1 13:50:39 2014
@@ -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@"
Modified: llvm/trunk/bindings/ocaml/llvm/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/Makefile?rev=223072&r1=223071&r2=223072&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/Makefile (original)
+++ llvm/trunk/bindings/ocaml/llvm/Makefile Mon Dec 1 13:50:39 2014
@@ -13,7 +13,7 @@
LEVEL := ../../..
LIBRARYNAME := llvm
-UsedComponents := core transformutils
+UsedComponents := core
UsedOcamlLibs := llvm
ExtraLibs := -lstdc++
Modified: llvm/trunk/bindings/ocaml/llvm/llvm.ml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm.ml?rev=223072&r1=223071&r2=223072&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm.ml (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm.ml Mon Dec 1 13:50:39 2014
@@ -313,7 +313,6 @@ external mdkind_id : llcontext -> string
(*===-- 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
Modified: llvm/trunk/bindings/ocaml/llvm/llvm.mli
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm.mli?rev=223072&r1=223071&r2=223072&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm.mli (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm.mli Mon Dec 1 13:50:39 2014
@@ -431,9 +431,6 @@ val create_module : llcontext -> string
[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
Modified: llvm/trunk/bindings/ocaml/transforms/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/transforms/CMakeLists.txt?rev=223072&r1=223071&r2=223072&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/transforms/CMakeLists.txt (original)
+++ llvm/trunk/bindings/ocaml/transforms/CMakeLists.txt Mon Dec 1 13:50:39 2014
@@ -1,4 +1,5 @@
add_subdirectory(ipo)
add_subdirectory(passmgr_builder)
add_subdirectory(scalar_opts)
+add_subdirectory(utils)
add_subdirectory(vectorize)
Modified: llvm/trunk/bindings/ocaml/transforms/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/transforms/Makefile?rev=223072&r1=223071&r2=223072&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/transforms/Makefile (original)
+++ llvm/trunk/bindings/ocaml/transforms/Makefile Mon Dec 1 13:50:39 2014
@@ -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 \
Added: llvm/trunk/bindings/ocaml/transforms/utils/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/transforms/utils/CMakeLists.txt?rev=223072&view=auto
==============================================================================
--- llvm/trunk/bindings/ocaml/transforms/utils/CMakeLists.txt (added)
+++ llvm/trunk/bindings/ocaml/transforms/utils/CMakeLists.txt Mon Dec 1 13:50:39 2014
@@ -0,0 +1,5 @@
+add_ocaml_library(llvm_transform_utils
+ OCAML llvm_transform_utils
+ OCAMLDEP llvm
+ C transform_utils_ocaml
+ LLVM transformutils)
Added: llvm/trunk/bindings/ocaml/transforms/utils/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/transforms/utils/Makefile?rev=223072&view=auto
==============================================================================
--- llvm/trunk/bindings/ocaml/transforms/utils/Makefile (added)
+++ llvm/trunk/bindings/ocaml/transforms/utils/Makefile Mon Dec 1 13:50:39 2014
@@ -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
Added: llvm/trunk/bindings/ocaml/transforms/utils/llvm_transform_utils.ml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/transforms/utils/llvm_transform_utils.ml?rev=223072&view=auto
==============================================================================
--- llvm/trunk/bindings/ocaml/transforms/utils/llvm_transform_utils.ml (added)
+++ llvm/trunk/bindings/ocaml/transforms/utils/llvm_transform_utils.ml Mon Dec 1 13:50:39 2014
@@ -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"
Added: llvm/trunk/bindings/ocaml/transforms/utils/llvm_transform_utils.mli
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/transforms/utils/llvm_transform_utils.mli?rev=223072&view=auto
==============================================================================
--- llvm/trunk/bindings/ocaml/transforms/utils/llvm_transform_utils.mli (added)
+++ llvm/trunk/bindings/ocaml/transforms/utils/llvm_transform_utils.mli Mon Dec 1 13:50:39 2014
@@ -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"
Added: llvm/trunk/bindings/ocaml/transforms/utils/transform_utils_ocaml.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/transforms/utils/transform_utils_ocaml.c?rev=223072&view=auto
==============================================================================
--- llvm/trunk/bindings/ocaml/transforms/utils/transform_utils_ocaml.c (added)
+++ llvm/trunk/bindings/ocaml/transforms/utils/transform_utils_ocaml.c Mon Dec 1 13:50:39 2014
@@ -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);
+}
Modified: llvm/trunk/docs/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CMakeLists.txt?rev=223072&r1=223071&r2=223072&view=diff
==============================================================================
--- llvm/trunk/docs/CMakeLists.txt (original)
+++ llvm/trunk/docs/CMakeLists.txt Mon Dec 1 13:50:39 2014
@@ -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
)
Added: llvm/trunk/test/Bindings/OCaml/transform_utils.ml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bindings/OCaml/transform_utils.ml?rev=223072&view=auto
==============================================================================
--- llvm/trunk/test/Bindings/OCaml/transform_utils.ml (added)
+++ llvm/trunk/test/Bindings/OCaml/transform_utils.ml Mon Dec 1 13:50:39 2014
@@ -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 ()
Modified: llvm/trunk/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CMakeLists.txt?rev=223072&r1=223071&r2=223072&view=diff
==============================================================================
--- llvm/trunk/test/CMakeLists.txt (original)
+++ llvm/trunk/test/CMakeLists.txt Mon Dec 1 13:50:39 2014
@@ -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()
More information about the llvm-commits
mailing list