diff options
author | Stephen Hines <srhines@google.com> | 2014-12-01 14:51:49 -0800 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2014-12-02 16:08:10 -0800 |
commit | 37ed9c199ca639565f6ce88105f9e39e898d82d0 (patch) | |
tree | 8fb36d3910e3ee4c4e1b7422f4f017108efc52f5 /bindings/ocaml | |
parent | d2327b22152ced7bc46dc629fc908959e8a52d03 (diff) | |
download | external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.zip external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.tar.gz external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.tar.bz2 |
Update aosp/master LLVM for rebase to r222494.
Change-Id: Ic787f5e0124df789bd26f3f24680f45e678eef2d
Diffstat (limited to 'bindings/ocaml')
49 files changed, 1322 insertions, 1376 deletions
diff --git a/bindings/ocaml/Makefile b/bindings/ocaml/Makefile index b0e1f09..2005367 100644 --- a/bindings/ocaml/Makefile +++ b/bindings/ocaml/Makefile @@ -1,10 +1,10 @@ ##===- bindings/ocaml/Makefile -----------------------------*- Makefile -*-===## -# +# # The LLVM Compiler Infrastructure # # This file is distributed under the University of Illinois Open Source # License. See LICENSE.TXT for details. -# +# ##===----------------------------------------------------------------------===## LEVEL := ../.. diff --git a/bindings/ocaml/Makefile.ocaml b/bindings/ocaml/Makefile.ocaml index 1b964ee..5e00cf5 100644 --- a/bindings/ocaml/Makefile.ocaml +++ b/bindings/ocaml/Makefile.ocaml @@ -1,27 +1,30 @@ ##===- bindings/ocaml/Makefile.ocaml -----------------------*- Makefile -*-===## -# +# # The LLVM Compiler Infrastructure # # This file is distributed under the University of Illinois Open Source # License. See LICENSE.TXT for details. -# +# ##===----------------------------------------------------------------------===## -# +# # An OCaml library is a unique project type in the context of LLVM, so rules are # here rather than in Makefile.rules. -# +# # Reference materials on installing OCaml libraries: -# +# # https://fedoraproject.org/wiki/Packaging/OCaml # http://pkg-ocaml-maint.alioth.debian.org/ocaml_packaging_policy.txt -# +# ##===----------------------------------------------------------------------===## include $(LEVEL)/Makefile.config +# We have our own rules for building static libraries. +NO_BUILD_ARCHIVE = 1 + # CFLAGS needs to be set before Makefile.rules is included. -CXX.Flags += -I"$(shell $(OCAMLC) -where)" -C.Flags += -I"$(shell $(OCAMLC) -where)" +CXX.Flags += -I"$(shell $(OCAMLFIND) c -where)" +C.Flags += -I"$(shell $(OCAMLFIND) c -where)" ifeq ($(ENABLE_SHARED),1) LINK_COMPONENTS := all @@ -50,64 +53,55 @@ endif # from toplevels. ifneq ($(ObjectsO),) ifeq ($(ENABLE_SHARED),1) -OCAMLSTUBS := 1 +OCAMLSTUBS := 1 +OCAMLSTUBFLAGS := $(patsubst %,-cclib %, $(LLVMLibsOptions) -l$(LIBRARYNAME)) +endif +endif + +# Avoid the need for LD_LIBRARY_PATH +ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW)) +ifneq ($(HOST_OS),Darwin) +OCAMLRPATH := $(RPATH) -Wl,'$$ORIGIN/../../lib' endif endif # Tools -OCAMLCFLAGS += -I $(ObjDir) -I $(OcamlDir) +OCAMLCFLAGS += -I $(OcamlDir) $(addprefix -package ,$(FindlibPackages)) + ifndef IS_CLEANING_TARGET ifneq ($(ObjectsO),) OCAMLAFLAGS += $(patsubst %,-cclib %, \ $(filter-out -L$(LibDir),-l$(LIBRARYNAME) \ $(shell $(LLVM_CONFIG) --ldflags)) \ - $(UsedLibs)) + $(UsedLibs) $(ExtraLibs)) else OCAMLAFLAGS += $(patsubst %,-cclib %, \ $(filter-out -L$(LibDir),$(shell $(LLVM_CONFIG) --ldflags)) \ - $(UsedLibs)) + $(UsedLibs) $(ExtraLibs)) endif endif - -# -g was introduced in 3.10.0. -#ifneq ($(ENABLE_OPTIMIZED),1) -# OCAMLDEBUGFLAG := -g -#endif - -Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o) -Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o) -Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o) -ifdef OCAMLSTUBS -# Avoid the need for LD_LIBRARY_PATH -ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW)) -ifneq ($(HOST_OS),Darwin) -OCAMLRPATH := $(RPATH) -Wl,'$(SharedLibDir)' -endif -endif +ifneq ($(DEBUG_SYMBOLS),1) + OCAMLDEBUGFLAG := -g endif -ifdef OCAMLSTUBS -Archive.CMA := $(strip $(OCAMLC) -a -dllib -l$(LIBRARYNAME) $(OCAMLDEBUGFLAG) \ - -o) -else -Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) \ - -o) -endif +Compile.CMI := $(strip $(OCAMLFIND) c -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o) +Compile.CMO := $(strip $(OCAMLFIND) c -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o) +Compile.CMX := $(strip $(OCAMLFIND) opt -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o) ifdef OCAMLSTUBS -Archive.CMXA := $(strip $(OCAMLOPT) -a $(patsubst %,-cclib %, \ - $(LLVMLibsOptions) -l$(LIBRARYNAME) \ - -L$(SharedLibDir) $(OCAMLRPATH)) \ - $(OCAMLDEBUGFLAG) -o) +# -dllib is engaged with ocamlc builds, $(OCAMLSTUBFLAGS) in ocamlc -custom builds. +Archive.CMA := $(strip $(OCAMLFIND) c -a -dllib -l$(LIBRARYNAME) $(OCAMLSTUBFLAGS) \ + $(OCAMLDEBUGFLAG) -o) else -Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) -o) +Archive.CMA := $(strip $(OCAMLFIND) c -a -custom $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) \ + -o) endif -ifdef OCAMLOPT -Archive.EXE := $(strip $(OCAMLOPT) -cc $(CXX) $(OCAMLCFLAGS) $(UsedOcamlLibs:%=%.cmxa) $(OCAMLDEBUGFLAG) -o) +ifdef OCAMLSTUBS +Archive.CMXA := $(strip $(OCAMLFIND) opt -a $(OCAMLSTUBFLAGS) $(OCAMLDEBUGFLAG) -o) else -Archive.EXE := $(strip $(OCAMLC) -cc $(CXX) $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG:%=%.cma) -o) +Archive.CMXA := $(strip $(OCAMLFIND) opt -a $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) -o) endif # Source files @@ -191,7 +185,7 @@ $(ObjectsCMI): $(UsedOcamlInterfaces:%=$(OcamlDir)/%.cmi) ifdef LIBRARYNAME $(ObjDir)/$(LIBRARYNAME).ocamldep: $(OcamlSources) $(OcamlHeaders) \ $(OcamlDir)/.dir $(ObjDir)/.dir - $(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeaders) > $@ + $(Verb) $(OCAMLFIND) dep $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeaders) > $@ -include $(ObjDir)/$(LIBRARYNAME).ocamldep endif @@ -199,7 +193,7 @@ endif ifdef TOOLNAME $(ObjDir)/$(TOOLNAME).ocamldep: $(OcamlSources) $(OcamlHeaders) \ $(OcamlDir)/.dir $(ObjDir)/.dir - $(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeaders) > $@ + $(Verb) $(OCAMLFIND) dep $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeaders) > $@ -include $(ObjDir)/$(TOOLNAME).ocamldep endif @@ -225,7 +219,7 @@ install-a:: $(LibraryA) $(Echo) "Installing $(BuildMode) $(DestA)" $(Verb) $(MKDIR) $(PROJ_libocamldir) $(Verb) $(INSTALL) $(LibraryA) $(DestA) - $(Verb) + $(Verb) uninstall-a:: $(Echo) "Uninstalling $(DestA)" @@ -368,8 +362,8 @@ endif ##===- Build optimized ocaml archive (.ml's -> .cmx's -> .cmxa, .a) -------===## # The ocamlopt compiler is supported on a set of targets disjoint from LLVM's. -# If unavailable, 'configure' will not define OCAMLOPT in Makefile.config. -ifdef OCAMLOPT +# If unavailable, 'configure' will set HAVE_OCAMLOPT to 0 in Makefile.config. +ifeq ($(HAVE_OCAMLOPT),1) $(OcamlDir)/%.cmx: $(ObjDir)/%.cmx $(Verb) $(CP) -f $< $@ @@ -419,31 +413,11 @@ uninstall-cmxa:: endif endif -##===- Build executables --------------------------------------------------===## - -ifdef TOOLNAME -all-local:: $(OutputEXE) -clean-local:: clean-exe - -$(OutputEXE): $(ToolEXE) $(OcamlDir)/.dir - $(Verb) $(CP) -f $< $@ - -ifndef OCAMLOPT -$(ToolEXE): $(ObjectsCMO) $(OcamlDir)/.dir - $(Echo) "Archiving $(notdir $@) for $(BuildMode) build" - $(Verb) $(Archive.EXE) $@ $(ObjectsCMO) -else -$(ToolEXE): $(ObjectsCMX) $(OcamlDir)/.dir - $(Echo) "Archiving $(notdir $@) for $(BuildMode) build" - $(Verb) $(Archive.EXE) $@ $(ObjectsCMX) -endif -endif - ##===- Generate documentation ---------------------------------------------===## $(ObjDir)/$(LIBRARYNAME).odoc: $(ObjectsCMI) $(Echo) "Documenting $(notdir $@)" - $(Verb) $(OCAMLDOC) -I $(ObjDir) -I $(OcamlDir) -dump $@ $(OcamlHeaders) + $(Verb) $(OCAMLFIND) doc -I $(ObjDir) -I $(OcamlDir) -dump $@ $(OcamlHeaders) ocamldoc: $(ObjDir)/$(LIBRARYNAME).odoc @@ -454,15 +428,17 @@ printcamlvars:: $(Echo) "LLVM_CONFIG : " '$(LLVM_CONFIG)' $(Echo) "OCAMLCFLAGS : " '$(OCAMLCFLAGS)' $(Echo) "OCAMLAFLAGS : " '$(OCAMLAFLAGS)' - $(Echo) "OCAMLC : " '$(OCAMLC)' - $(Echo) "OCAMLOPT : " '$(OCAMLOPT)' - $(Echo) "OCAMLDEP : " '$(OCAMLDEP)' + $(Echo) "OCAMLRPATH : " '$(OCAMLRPATH)' + $(Echo) "OCAMLSTUBS : " '$(OCAMLSTUBS)' + $(Echo) "OCAMLSTUBFLAGS : " '$(OCAMLSTUBFLAGS)' + $(Echo) "OCAMLFIND : " '$(OCAMLFIND)' $(Echo) "Compile.CMI : " '$(Compile.CMI)' $(Echo) "Compile.CMO : " '$(Compile.CMO)' $(Echo) "Archive.CMA : " '$(Archive.CMA)' $(Echo) "Compile.CMX : " '$(Compile.CMX)' $(Echo) "Archive.CMXA : " '$(Archive.CMXA)' $(Echo) "CAML_LIBDIR : " '$(CAML_LIBDIR)' + $(Echo) "LibraryA : " '$(LibraryA)' $(Echo) "LibraryCMA : " '$(LibraryCMA)' $(Echo) "LibraryCMXA : " '$(LibraryCMXA)' $(Echo) "SharedLib : " '$(SharedLib)' @@ -482,6 +458,7 @@ printcamlvars:: $(Echo) "DestSharedLib: " '$(DestSharedLib)' $(Echo) "UsedLibs : " '$(UsedLibs)' $(Echo) "UsedLibNames : " '$(UsedLibNames)' + $(Echo) "ExtraLibs : " '$(ExtraLibs)' .PHONY: printcamlvars build-cmis \ clean-a clean-cmis clean-cma clean-cmxa \ diff --git a/bindings/ocaml/all_backends/Makefile b/bindings/ocaml/all_backends/Makefile index a5ff290..f7c8cdb 100644 --- a/bindings/ocaml/all_backends/Makefile +++ b/bindings/ocaml/all_backends/Makefile @@ -1,4 +1,4 @@ -##===- bindings/ocaml/all_backends/Makefile ----------------------*- Makefile -*-===## +##===- bindings/ocaml/all_backends/Makefile ----------------*- Makefile -*-===## # # The LLVM Compiler Infrastructure # @@ -7,7 +7,7 @@ # ##===----------------------------------------------------------------------===## # -# This is the makefile for the Objective Caml Llvm_backends interface. +# This is the makefile for the Objective Caml Llvm_all_backends interface. # ##===----------------------------------------------------------------------===## diff --git a/bindings/ocaml/analysis/Makefile b/bindings/ocaml/analysis/Makefile index cbfcb24..daff061 100644 --- a/bindings/ocaml/analysis/Makefile +++ b/bindings/ocaml/analysis/Makefile @@ -1,14 +1,14 @@ ##===- bindings/ocaml/analysis/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_analysis interface. -# +# ##===----------------------------------------------------------------------===## LEVEL := ../../.. diff --git a/bindings/ocaml/analysis/analysis_ocaml.c b/bindings/ocaml/analysis/analysis_ocaml.c index 91be2d3..44e3197 100644 --- a/bindings/ocaml/analysis/analysis_ocaml.c +++ b/bindings/ocaml/analysis/analysis_ocaml.c @@ -20,15 +20,14 @@ #include "caml/mlvalues.h" #include "caml/memory.h" - /* Llvm.llmodule -> string option */ CAMLprim value llvm_verify_module(LLVMModuleRef M) { CAMLparam0(); CAMLlocal2(String, Option); - + char *Message; int Result = LLVMVerifyModule(M, LLVMReturnStatusAction, &Message); - + if (0 == Result) { Option = Val_int(0); } else { @@ -36,9 +35,9 @@ CAMLprim value llvm_verify_module(LLVMModuleRef M) { String = copy_string(Message); Store_field(Option, 0, String); } - + LLVMDisposeMessage(Message); - + CAMLreturn(Option); } diff --git a/bindings/ocaml/analysis/llvm_analysis.ml b/bindings/ocaml/analysis/llvm_analysis.ml index 21088ab..8c11a63 100644 --- a/bindings/ocaml/analysis/llvm_analysis.ml +++ b/bindings/ocaml/analysis/llvm_analysis.ml @@ -1,4 +1,4 @@ -(*===-- llvm_analysis.ml - LLVM OCaml Interface -----------------*- C++ -*-===* +(*===-- llvm_analysis.ml - LLVM OCaml Interface ---------------*- OCaml -*-===* * * The LLVM Compiler Infrastructure * diff --git a/bindings/ocaml/analysis/llvm_analysis.mli b/bindings/ocaml/analysis/llvm_analysis.mli index 1a0af02..03197cd 100644 --- a/bindings/ocaml/analysis/llvm_analysis.mli +++ b/bindings/ocaml/analysis/llvm_analysis.mli @@ -1,4 +1,4 @@ -(*===-- llvm_analysis.mli - LLVM OCaml Interface ----------------*- C++ -*-===* +(*===-- llvm_analysis.mli - LLVM OCaml Interface --------------*- OCaml -*-===* * * The LLVM Compiler Infrastructure * diff --git a/bindings/ocaml/backends/META.llvm_backend.in b/bindings/ocaml/backends/META.llvm_backend.in index 0d4a6d6..6c1e8c4 100644 --- a/bindings/ocaml/backends/META.llvm_backend.in +++ b/bindings/ocaml/backends/META.llvm_backend.in @@ -5,4 +5,3 @@ requires = "llvm" archive(byte) = "llvm_@TARGET@.cma" archive(native) = "llvm_@TARGET@.cmxa" directory = "." -linkopts = "-ccopt -lstdc++"
\ No newline at end of file diff --git a/bindings/ocaml/backends/backend_ocaml.c b/bindings/ocaml/backends/backend_ocaml.c index 2d4ba85..3e1a438 100644 --- a/bindings/ocaml/backends/backend_ocaml.c +++ b/bindings/ocaml/backends/backend_ocaml.c @@ -19,10 +19,11 @@ #include "caml/alloc.h" #include "caml/memory.h" -// TODO: Figure out how to call these only for targets which support them. -// LLVMInitialize ## target ## AsmPrinter(); -// LLVMInitialize ## target ## AsmParser(); -// LLVMInitialize ## target ## Disassembler(); +/* TODO: Figure out how to call these only for targets which support them. + * LLVMInitialize ## target ## AsmPrinter(); + * LLVMInitialize ## target ## AsmParser(); + * LLVMInitialize ## target ## Disassembler(); + */ #define INITIALIZER1(target) \ CAMLprim value llvm_initialize_ ## target(value Unit) { \ diff --git a/bindings/ocaml/bitreader/Makefile b/bindings/ocaml/bitreader/Makefile index a1c7de8..dad4e1d 100644 --- a/bindings/ocaml/bitreader/Makefile +++ b/bindings/ocaml/bitreader/Makefile @@ -1,14 +1,14 @@ ##===- bindings/ocaml/bitreader/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_bitreader interface. -# +# ##===----------------------------------------------------------------------===## LEVEL := ../../.. diff --git a/bindings/ocaml/bitreader/bitreader_ocaml.c b/bindings/ocaml/bitreader/bitreader_ocaml.c index 0264e73..15ebd5f 100644 --- a/bindings/ocaml/bitreader/bitreader_ocaml.c +++ b/bindings/ocaml/bitreader/bitreader_ocaml.c @@ -16,58 +16,28 @@ #include "caml/alloc.h" #include "caml/fail.h" #include "caml/memory.h" +#include "caml/callback.h" - -/* Can't use the recommended caml_named_value mechanism for backwards - compatibility reasons. This is largely equivalent. */ -static value llvm_bitreader_error_exn; - -CAMLprim value llvm_register_bitreader_exns(value Error) { - llvm_bitreader_error_exn = Field(Error, 0); - register_global_root(&llvm_bitreader_error_exn); - return Val_unit; -} - -static void llvm_raise(value Prototype, char *Message) { - CAMLparam1(Prototype); - CAMLlocal1(CamlMessage); - - CamlMessage = copy_string(Message); - LLVMDisposeMessage(Message); - - raise_with_arg(Prototype, CamlMessage); - abort(); /* NOTREACHED */ -#ifdef CAMLnoreturn - CAMLnoreturn; /* Silences warnings, but is missing in some versions. */ -#endif -} - - -/*===-- Modules -----------------------------------------------------------===*/ +void llvm_raise(value Prototype, char *Message); /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */ -CAMLprim value llvm_get_module(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) { - CAMLparam0(); - CAMLlocal2(Variant, MessageVal); - char *Message; - +CAMLprim LLVMModuleRef llvm_get_module(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) { LLVMModuleRef M; + char *Message; + if (LLVMGetBitcodeModuleInContext(C, MemBuf, &M, &Message)) - llvm_raise(llvm_bitreader_error_exn, Message); - - CAMLreturn((value) M); + llvm_raise(*caml_named_value("Llvm_bitreader.Error"), Message); + + return M; } /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */ -CAMLprim value llvm_parse_bitcode(LLVMContextRef C, - LLVMMemoryBufferRef MemBuf) { - CAMLparam0(); - CAMLlocal2(Variant, MessageVal); +CAMLprim LLVMModuleRef llvm_parse_bitcode(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) { LLVMModuleRef M; char *Message; - + if (LLVMParseBitcodeInContext(C, MemBuf, &M, &Message)) - llvm_raise(llvm_bitreader_error_exn, Message); - - CAMLreturn((value) M); + llvm_raise(*caml_named_value("Llvm_bitreader.Error"), Message); + + return M; } diff --git a/bindings/ocaml/bitreader/llvm_bitreader.ml b/bindings/ocaml/bitreader/llvm_bitreader.ml index 865208c..b26efdd 100644 --- a/bindings/ocaml/bitreader/llvm_bitreader.ml +++ b/bindings/ocaml/bitreader/llvm_bitreader.ml @@ -1,4 +1,4 @@ -(*===-- llvm_bitreader.ml - LLVM OCaml Interface ----------------*- C++ -*-===* +(*===-- llvm_bitreader.ml - LLVM OCaml Interface --------------*- OCaml -*-===* * * The LLVM Compiler Infrastructure * @@ -7,14 +7,13 @@ * *===----------------------------------------------------------------------===*) - exception Error of string -external register_exns : exn -> unit = "llvm_register_bitreader_exns" -let _ = register_exns (Error "") - -external get_module : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule - = "llvm_get_module" +let () = Callback.register_exception "Llvm_bitreader.Error" (Error "") -external parse_bitcode : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule - = "llvm_parse_bitcode" +external get_module + : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule + = "llvm_get_module" +external parse_bitcode + : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule + = "llvm_parse_bitcode" diff --git a/bindings/ocaml/bitreader/llvm_bitreader.mli b/bindings/ocaml/bitreader/llvm_bitreader.mli index ff377b9..4351343 100644 --- a/bindings/ocaml/bitreader/llvm_bitreader.mli +++ b/bindings/ocaml/bitreader/llvm_bitreader.mli @@ -1,4 +1,4 @@ -(*===-- llvm_bitreader.mli - LLVM OCaml Interface ---------------*- C++ -*-===* +(*===-- llvm_bitreader.mli - LLVM OCaml Interface -------------*- OCaml -*-===* * * The LLVM Compiler Infrastructure * @@ -20,7 +20,6 @@ exception Error of string encountered. See the function [llvm::getBitcodeModule]. *) val get_module : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule - (** [parse_bitcode context mb] parses the bitcode for a new module [m] from the memory buffer [mb] in the context [context]. Returns [m] if successful, or raises [Error msg] otherwise, where [msg] is a description of the error diff --git a/bindings/ocaml/bitwriter/Makefile b/bindings/ocaml/bitwriter/Makefile index cec0a59..9f0b2c8 100644 --- a/bindings/ocaml/bitwriter/Makefile +++ b/bindings/ocaml/bitwriter/Makefile @@ -1,14 +1,14 @@ ##===- bindings/ocaml/bitwriter/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_bitwriter interface. -# +# ##===----------------------------------------------------------------------===## LEVEL := ../../.. diff --git a/bindings/ocaml/bitwriter/bitwriter_ocaml.c b/bindings/ocaml/bitwriter/bitwriter_ocaml.c index a47f700..04fd619 100644 --- a/bindings/ocaml/bitwriter/bitwriter_ocaml.c +++ b/bindings/ocaml/bitwriter/bitwriter_ocaml.c @@ -21,25 +21,28 @@ #include "caml/mlvalues.h" #include "caml/memory.h" -/*===-- Modules -----------------------------------------------------------===*/ - /* Llvm.llmodule -> string -> bool */ -CAMLprim value llvm_write_bitcode_file(value M, value Path) { - int res = LLVMWriteBitcodeToFile((LLVMModuleRef) M, String_val(Path)); - return Val_bool(res == 0); +CAMLprim value llvm_write_bitcode_file(LLVMModuleRef M, value Path) { + int Result = LLVMWriteBitcodeToFile(M, String_val(Path)); + return Val_bool(Result == 0); } /* ?unbuffered:bool -> Llvm.llmodule -> Unix.file_descr -> bool */ -CAMLprim value llvm_write_bitcode_to_fd(value U, value M, value FD) { +CAMLprim value llvm_write_bitcode_to_fd(value U, LLVMModuleRef M, value FD) { int Unbuffered; - int res; + int Result; if (U == Val_int(0)) { Unbuffered = 0; } else { - Unbuffered = Bool_val(Field(U,0)); + Unbuffered = Bool_val(Field(U, 0)); } - res = LLVMWriteBitcodeToFD((LLVMModuleRef) M, Int_val(FD), 0, Unbuffered); - return Val_bool(res == 0); + Result = LLVMWriteBitcodeToFD(M, Int_val(FD), 0, Unbuffered); + return Val_bool(Result == 0); +} + +/* Llvm.llmodule -> Llvm.llmemorybuffer */ +CAMLprim LLVMMemoryBufferRef llvm_write_bitcode_to_memory_buffer(LLVMModuleRef M) { + return LLVMWriteBitcodeToMemoryBuffer(M); } diff --git a/bindings/ocaml/bitwriter/llvm_bitwriter.ml b/bindings/ocaml/bitwriter/llvm_bitwriter.ml index fac8553..fca6efa 100644 --- a/bindings/ocaml/bitwriter/llvm_bitwriter.ml +++ b/bindings/ocaml/bitwriter/llvm_bitwriter.ml @@ -1,4 +1,4 @@ -(*===-- llvm_bitwriter.ml - LLVM OCaml Interface ----------------*- C++ -*-===* +(*===-- llvm_bitwriter.ml - LLVM OCaml Interface --------------*- OCaml -*-===* * * The LLVM Compiler Infrastructure * @@ -12,14 +12,17 @@ * *===----------------------------------------------------------------------===*) +external write_bitcode_file + : Llvm.llmodule -> string -> bool + = "llvm_write_bitcode_file" -(* Writes the bitcode for module the given path. Returns true if successful. *) -external write_bitcode_file : Llvm.llmodule -> string -> bool - = "llvm_write_bitcode_file" +external write_bitcode_to_fd + : ?unbuffered:bool -> Llvm.llmodule -> Unix.file_descr -> bool + = "llvm_write_bitcode_to_fd" -external write_bitcode_to_fd : ?unbuffered:bool -> Llvm.llmodule - -> Unix.file_descr -> bool - = "llvm_write_bitcode_to_fd" +external write_bitcode_to_memory_buffer + : Llvm.llmodule -> Llvm.llmemorybuffer + = "llvm_write_bitcode_to_memory_buffer" let output_bitcode ?unbuffered channel m = write_bitcode_to_fd ?unbuffered m (Unix.descr_of_out_channel channel) diff --git a/bindings/ocaml/bitwriter/llvm_bitwriter.mli b/bindings/ocaml/bitwriter/llvm_bitwriter.mli index bb3e3b8..3d0f780 100644 --- a/bindings/ocaml/bitwriter/llvm_bitwriter.mli +++ b/bindings/ocaml/bitwriter/llvm_bitwriter.mli @@ -1,4 +1,4 @@ -(*===-- llvm_bitwriter.mli - LLVM OCaml Interface ---------------*- C++ -*-===* +(*===-- llvm_bitwriter.mli - LLVM OCaml Interface -------------*- OCaml -*-===* * * The LLVM Compiler Infrastructure * @@ -14,15 +14,22 @@ (** [write_bitcode_file m path] writes the bitcode for module [m] to the file at [path]. Returns [true] if successful, [false] otherwise. *) -external write_bitcode_file : Llvm.llmodule -> string -> bool - = "llvm_write_bitcode_file" +external write_bitcode_file + : Llvm.llmodule -> string -> bool + = "llvm_write_bitcode_file" (** [write_bitcode_to_fd ~unbuffered fd m] writes the bitcode for module [m] to the channel [c]. If [unbuffered] is [true], after every write the fd will be flushed. Returns [true] if successful, [false] otherwise. *) -external write_bitcode_to_fd : ?unbuffered:bool -> Llvm.llmodule - -> Unix.file_descr -> bool - = "llvm_write_bitcode_to_fd" +external write_bitcode_to_fd + : ?unbuffered:bool -> Llvm.llmodule -> Unix.file_descr -> bool + = "llvm_write_bitcode_to_fd" + +(** [write_bitcode_to_memory_buffer m] returns a memory buffer containing + the bitcode for module [m]. *) +external write_bitcode_to_memory_buffer + : Llvm.llmodule -> Llvm.llmemorybuffer + = "llvm_write_bitcode_to_memory_buffer" (** [output_bitcode ~unbuffered c m] writes the bitcode for module [m] to the channel [c]. If [unbuffered] is [true], after every write the fd diff --git a/bindings/ocaml/executionengine/Makefile b/bindings/ocaml/executionengine/Makefile index 5fa3f22..8b5d28f 100644 --- a/bindings/ocaml/executionengine/Makefile +++ b/bindings/ocaml/executionengine/Makefile @@ -1,19 +1,20 @@ -##===- bindings/ocaml/executionengine/Makefile --------------*- Makefile -*-===## -# +##===- bindings/ocaml/executionengine/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_executionengine interface. -# +# ##===----------------------------------------------------------------------===## LEVEL := ../../.. LIBRARYNAME := llvm_executionengine -UsedComponents := executionengine jit interpreter native +UsedComponents := executionengine mcjit native UsedOcamlInterfaces := llvm llvm_target +FindlibPackages := ctypes include ../Makefile.ocaml diff --git a/bindings/ocaml/executionengine/executionengine_ocaml.c b/bindings/ocaml/executionengine/executionengine_ocaml.c index 4b44a91..0557efc 100644 --- a/bindings/ocaml/executionengine/executionengine_ocaml.c +++ b/bindings/ocaml/executionengine/executionengine_ocaml.c @@ -15,189 +15,48 @@ |* *| \*===----------------------------------------------------------------------===*/ +#include <string.h> +#include <assert.h> #include "llvm-c/ExecutionEngine.h" #include "llvm-c/Target.h" #include "caml/alloc.h" #include "caml/custom.h" #include "caml/fail.h" #include "caml/memory.h" -#include <string.h> -#include <assert.h> +#include "caml/callback.h" -/* Force the LLVM interpreter and JIT to be linked in. */ -void llvm_initialize(void) { - LLVMLinkInInterpreter(); - LLVMLinkInJIT(); -} +void llvm_raise(value Prototype, char *Message); /* unit -> bool */ -CAMLprim value llvm_initialize_native_target(value Unit) { - return Val_bool(LLVMInitializeNativeTarget()); -} - -/* Can't use the recommended caml_named_value mechanism for backwards - compatibility reasons. This is largely equivalent. */ -static value llvm_ee_error_exn; - -CAMLprim value llvm_register_ee_exns(value Error) { - llvm_ee_error_exn = Field(Error, 0); - register_global_root(&llvm_ee_error_exn); - return Val_unit; -} +CAMLprim value llvm_ee_initialize(value Unit) { + LLVMLinkInMCJIT(); -static void llvm_raise(value Prototype, char *Message) { - CAMLparam1(Prototype); - CAMLlocal1(CamlMessage); - - CamlMessage = copy_string(Message); - LLVMDisposeMessage(Message); - - raise_with_arg(Prototype, CamlMessage); - abort(); /* NOTREACHED */ -#ifdef CAMLnoreturn - CAMLnoreturn; /* Silences warnings, but is missing in some versions. */ -#endif + return Val_bool(!LLVMInitializeNativeTarget() && + !LLVMInitializeNativeAsmParser() && + !LLVMInitializeNativeAsmPrinter()); } - -/*--... Operations on generic values .......................................--*/ - -#define Genericvalue_val(v) (*(LLVMGenericValueRef *)(Data_custom_val(v))) - -static void llvm_finalize_generic_value(value GenVal) { - LLVMDisposeGenericValue(Genericvalue_val(GenVal)); -} - -static struct custom_operations generic_value_ops = { - (char *) "LLVMGenericValue", - llvm_finalize_generic_value, - custom_compare_default, - custom_hash_default, - custom_serialize_default, - custom_deserialize_default -#ifdef custom_compare_ext_default - , custom_compare_ext_default -#endif -}; - -static value alloc_generic_value(LLVMGenericValueRef Ref) { - value Val = alloc_custom(&generic_value_ops, sizeof(LLVMGenericValueRef), 0, 1); - Genericvalue_val(Val) = Ref; - return Val; -} - -/* Llvm.lltype -> float -> t */ -CAMLprim value llvm_genericvalue_of_float(LLVMTypeRef Ty, value N) { - CAMLparam1(N); - CAMLreturn(alloc_generic_value( - LLVMCreateGenericValueOfFloat(Ty, Double_val(N)))); -} - -/* 'a -> t */ -CAMLprim value llvm_genericvalue_of_pointer(value V) { - CAMLparam1(V); - CAMLreturn(alloc_generic_value(LLVMCreateGenericValueOfPointer(Op_val(V)))); -} - -/* Llvm.lltype -> int -> t */ -CAMLprim value llvm_genericvalue_of_int(LLVMTypeRef Ty, value Int) { - return alloc_generic_value(LLVMCreateGenericValueOfInt(Ty, Int_val(Int), 1)); -} - -/* Llvm.lltype -> int32 -> t */ -CAMLprim value llvm_genericvalue_of_int32(LLVMTypeRef Ty, value Int32) { - CAMLparam1(Int32); - CAMLreturn(alloc_generic_value( - LLVMCreateGenericValueOfInt(Ty, Int32_val(Int32), 1))); -} - -/* Llvm.lltype -> nativeint -> t */ -CAMLprim value llvm_genericvalue_of_nativeint(LLVMTypeRef Ty, value NatInt) { - CAMLparam1(NatInt); - CAMLreturn(alloc_generic_value( - LLVMCreateGenericValueOfInt(Ty, Nativeint_val(NatInt), 1))); -} - -/* Llvm.lltype -> int64 -> t */ -CAMLprim value llvm_genericvalue_of_int64(LLVMTypeRef Ty, value Int64) { - CAMLparam1(Int64); - CAMLreturn(alloc_generic_value( - LLVMCreateGenericValueOfInt(Ty, Int64_val(Int64), 1))); -} - -/* Llvm.lltype -> t -> float */ -CAMLprim value llvm_genericvalue_as_float(LLVMTypeRef Ty, value GenVal) { - CAMLparam1(GenVal); - CAMLreturn(copy_double( - LLVMGenericValueToFloat(Ty, Genericvalue_val(GenVal)))); -} - -/* t -> 'a */ -CAMLprim value llvm_genericvalue_as_pointer(value GenVal) { - return Val_op(LLVMGenericValueToPointer(Genericvalue_val(GenVal))); -} - -/* t -> int */ -CAMLprim value llvm_genericvalue_as_int(value GenVal) { - assert(LLVMGenericValueIntWidth(Genericvalue_val(GenVal)) <= 8 * sizeof(value) - && "Generic value too wide to treat as an int!"); - return Val_int(LLVMGenericValueToInt(Genericvalue_val(GenVal), 1)); -} - -/* t -> int32 */ -CAMLprim value llvm_genericvalue_as_int32(value GenVal) { - CAMLparam1(GenVal); - assert(LLVMGenericValueIntWidth(Genericvalue_val(GenVal)) <= 32 - && "Generic value too wide to treat as an int32!"); - CAMLreturn(copy_int32(LLVMGenericValueToInt(Genericvalue_val(GenVal), 1))); -} - -/* t -> int64 */ -CAMLprim value llvm_genericvalue_as_int64(value GenVal) { - CAMLparam1(GenVal); - assert(LLVMGenericValueIntWidth(Genericvalue_val(GenVal)) <= 64 - && "Generic value too wide to treat as an int64!"); - CAMLreturn(copy_int64(LLVMGenericValueToInt(Genericvalue_val(GenVal), 1))); -} - -/* t -> nativeint */ -CAMLprim value llvm_genericvalue_as_nativeint(value GenVal) { - CAMLparam1(GenVal); - assert(LLVMGenericValueIntWidth(Genericvalue_val(GenVal)) <= 8 * sizeof(value) - && "Generic value too wide to treat as a nativeint!"); - CAMLreturn(copy_nativeint(LLVMGenericValueToInt(Genericvalue_val(GenVal),1))); -} - - -/*--... Operations on execution engines ....................................--*/ - -/* llmodule -> ExecutionEngine.t */ -CAMLprim LLVMExecutionEngineRef llvm_ee_create(LLVMModuleRef M) { - LLVMExecutionEngineRef Interp; - char *Error; - if (LLVMCreateExecutionEngineForModule(&Interp, M, &Error)) - llvm_raise(llvm_ee_error_exn, Error); - return Interp; -} - -/* llmodule -> ExecutionEngine.t */ -CAMLprim LLVMExecutionEngineRef -llvm_ee_create_interpreter(LLVMModuleRef M) { - LLVMExecutionEngineRef Interp; +/* llmodule -> llcompileroption -> ExecutionEngine.t */ +CAMLprim LLVMExecutionEngineRef llvm_ee_create(value OptRecordOpt, LLVMModuleRef M) { + value OptRecord; + LLVMExecutionEngineRef MCJIT; char *Error; - if (LLVMCreateInterpreterForModule(&Interp, M, &Error)) - llvm_raise(llvm_ee_error_exn, Error); - return Interp; -} + struct LLVMMCJITCompilerOptions Options; + + LLVMInitializeMCJITCompilerOptions(&Options, sizeof(Options)); + if (OptRecordOpt != Val_int(0)) { + OptRecord = Field(OptRecordOpt, 0); + Options.OptLevel = Int_val(Field(OptRecord, 0)); + Options.CodeModel = Int_val(Field(OptRecord, 1)); + Options.NoFramePointerElim = Int_val(Field(OptRecord, 2)); + Options.EnableFastISel = Int_val(Field(OptRecord, 3)); + Options.MCJMM = NULL; + } -/* llmodule -> int -> ExecutionEngine.t */ -CAMLprim LLVMExecutionEngineRef -llvm_ee_create_jit(LLVMModuleRef M, value OptLevel) { - LLVMExecutionEngineRef JIT; - char *Error; - if (LLVMCreateJITCompilerForModule(&JIT, M, Int_val(OptLevel), &Error)) - llvm_raise(llvm_ee_error_exn, Error); - return JIT; + if (LLVMCreateMCJITCompilerForModule(&MCJIT, M, &Options, + sizeof(Options), &Error)) + llvm_raise(*caml_named_value("Llvm_executionengine.Error"), Error); + return MCJIT; } /* ExecutionEngine.t -> unit */ @@ -213,43 +72,12 @@ CAMLprim value llvm_ee_add_module(LLVMModuleRef M, LLVMExecutionEngineRef EE) { } /* llmodule -> ExecutionEngine.t -> llmodule */ -CAMLprim LLVMModuleRef llvm_ee_remove_module(LLVMModuleRef M, - LLVMExecutionEngineRef EE) { +CAMLprim value llvm_ee_remove_module(LLVMModuleRef M, LLVMExecutionEngineRef EE) { LLVMModuleRef RemovedModule; char *Error; if (LLVMRemoveModule(EE, M, &RemovedModule, &Error)) - llvm_raise(llvm_ee_error_exn, Error); - return RemovedModule; -} - -/* string -> ExecutionEngine.t -> llvalue option */ -CAMLprim value llvm_ee_find_function(value Name, LLVMExecutionEngineRef EE) { - CAMLparam1(Name); - CAMLlocal1(Option); - LLVMValueRef Found; - if (LLVMFindFunction(EE, String_val(Name), &Found)) - CAMLreturn(Val_unit); - Option = alloc(1, 0); - Field(Option, 0) = Val_op(Found); - CAMLreturn(Option); -} - -/* llvalue -> GenericValue.t array -> ExecutionEngine.t -> GenericValue.t */ -CAMLprim value llvm_ee_run_function(LLVMValueRef F, value Args, - LLVMExecutionEngineRef EE) { - unsigned NumArgs; - LLVMGenericValueRef Result, *GVArgs; - unsigned I; - - NumArgs = Wosize_val(Args); - GVArgs = (LLVMGenericValueRef*) malloc(NumArgs * sizeof(LLVMGenericValueRef)); - for (I = 0; I != NumArgs; ++I) - GVArgs[I] = Genericvalue_val(Field(Args, I)); - - Result = LLVMRunFunction(EE, F, NumArgs, GVArgs); - - free(GVArgs); - return alloc_generic_value(Result); + llvm_raise(*caml_named_value("Llvm_executionengine.Error"), Error); + return Val_unit; } /* ExecutionEngine.t -> unit */ @@ -264,78 +92,31 @@ CAMLprim value llvm_ee_run_static_dtors(LLVMExecutionEngineRef EE) { return Val_unit; } -/* llvalue -> string array -> (string * string) array -> ExecutionEngine.t -> - int */ -CAMLprim value llvm_ee_run_function_as_main(LLVMValueRef F, - value Args, value Env, - LLVMExecutionEngineRef EE) { - CAMLparam2(Args, Env); - int I, NumArgs, NumEnv, EnvSize, Result; - const char **CArgs, **CEnv; - char *CEnvBuf, *Pos; - - NumArgs = Wosize_val(Args); - NumEnv = Wosize_val(Env); - - /* Build the environment. */ - CArgs = (const char **) malloc(NumArgs * sizeof(char*)); - for (I = 0; I != NumArgs; ++I) - CArgs[I] = String_val(Field(Args, I)); - - /* Compute the size of the environment string buffer. */ - for (I = 0, EnvSize = 0; I != NumEnv; ++I) { - EnvSize += strlen(String_val(Field(Field(Env, I), 0))) + 1; - EnvSize += strlen(String_val(Field(Field(Env, I), 1))) + 1; - } - - /* Build the environment. */ - CEnv = (const char **) malloc((NumEnv + 1) * sizeof(char*)); - CEnvBuf = (char*) malloc(EnvSize); - Pos = CEnvBuf; - for (I = 0; I != NumEnv; ++I) { - char *Name = String_val(Field(Field(Env, I), 0)), - *Value = String_val(Field(Field(Env, I), 1)); - int NameLen = strlen(Name), - ValueLen = strlen(Value); - - CEnv[I] = Pos; - memcpy(Pos, Name, NameLen); - Pos += NameLen; - *Pos++ = '='; - memcpy(Pos, Value, ValueLen); - Pos += ValueLen; - *Pos++ = '\0'; - } - CEnv[NumEnv] = NULL; - - Result = LLVMRunFunctionAsMain(EE, F, NumArgs, CArgs, CEnv); - - free(CArgs); - free(CEnv); - free(CEnvBuf); - - CAMLreturn(Val_int(Result)); -} - -/* llvalue -> ExecutionEngine.t -> unit */ -CAMLprim value llvm_ee_free_machine_code(LLVMValueRef F, - LLVMExecutionEngineRef EE) { - LLVMFreeMachineCodeForFunction(EE, F); - return Val_unit; -} - extern value llvm_alloc_data_layout(LLVMTargetDataRef TargetData); /* ExecutionEngine.t -> Llvm_target.DataLayout.t */ CAMLprim value llvm_ee_get_data_layout(LLVMExecutionEngineRef EE) { value DataLayout; LLVMTargetDataRef OrigDataLayout; - OrigDataLayout = LLVMGetExecutionEngineTargetData(EE); - char* TargetDataCStr; + + OrigDataLayout = LLVMGetExecutionEngineTargetData(EE); TargetDataCStr = LLVMCopyStringRepOfTargetData(OrigDataLayout); DataLayout = llvm_alloc_data_layout(LLVMCreateTargetData(TargetDataCStr)); LLVMDisposeMessage(TargetDataCStr); return DataLayout; } + +/* Llvm.llvalue -> int64 -> llexecutionengine -> unit */ +CAMLprim value llvm_ee_add_global_mapping(LLVMValueRef Global, value Ptr, + LLVMExecutionEngineRef EE) { + LLVMAddGlobalMapping(EE, Global, (void*) (Int64_val(Ptr))); + return Val_unit; +} + +/* Llvm.llvalue -> llexecutionengine -> int64 */ +CAMLprim value llvm_ee_get_pointer_to_global(LLVMValueRef Global, + LLVMExecutionEngineRef EE) { + return caml_copy_int64((int64_t) LLVMGetPointerToGlobal(EE, Global)); +} diff --git a/bindings/ocaml/executionengine/llvm_executionengine.ml b/bindings/ocaml/executionengine/llvm_executionengine.ml index a738df7..c0ff330 100644 --- a/bindings/ocaml/executionengine/llvm_executionengine.ml +++ b/bindings/ocaml/executionengine/llvm_executionengine.ml @@ -1,4 +1,4 @@ -(*===-- llvm_executionengine.ml - LLVM OCaml Interface ----------*- C++ -*-===* +(*===-- llvm_executionengine.ml - LLVM OCaml Interface --------*- OCaml -*-===* * * The LLVM Compiler Infrastructure * @@ -7,105 +7,54 @@ * *===----------------------------------------------------------------------===*) - exception Error of string -external register_exns: exn -> unit - = "llvm_register_ee_exns" - - -module GenericValue = struct - type t - - external of_float: Llvm.lltype -> float -> t - = "llvm_genericvalue_of_float" - external of_pointer: 'a -> t - = "llvm_genericvalue_of_pointer" - external of_int32: Llvm.lltype -> int32 -> t - = "llvm_genericvalue_of_int32" - external of_int: Llvm.lltype -> int -> t - = "llvm_genericvalue_of_int" - external of_nativeint: Llvm.lltype -> nativeint -> t - = "llvm_genericvalue_of_nativeint" - external of_int64: Llvm.lltype -> int64 -> t - = "llvm_genericvalue_of_int64" - - external as_float: Llvm.lltype -> t -> float - = "llvm_genericvalue_as_float" - external as_pointer: t -> 'a - = "llvm_genericvalue_as_pointer" - external as_int32: t -> int32 - = "llvm_genericvalue_as_int32" - external as_int: t -> int - = "llvm_genericvalue_as_int" - external as_nativeint: t -> nativeint - = "llvm_genericvalue_as_nativeint" - external as_int64: t -> int64 - = "llvm_genericvalue_as_int64" -end - - -module ExecutionEngine = struct - type t - - (* FIXME: Ocaml is not running this setup code unless we use 'val' in the - interface, which causes the emission of a stub for each function; - using 'external' in the module allows direct calls into - ocaml_executionengine.c. This is hardly fatal, but it is unnecessary - overhead on top of the two stubs that are already invoked for each - call into LLVM. *) - let _ = register_exns (Error "") - - external create: Llvm.llmodule -> t - = "llvm_ee_create" - external create_interpreter: Llvm.llmodule -> t - = "llvm_ee_create_interpreter" - external create_jit: Llvm.llmodule -> int -> t - = "llvm_ee_create_jit" - external dispose: t -> unit - = "llvm_ee_dispose" - external add_module: Llvm.llmodule -> t -> unit - = "llvm_ee_add_module" - external remove_module: Llvm.llmodule -> t -> Llvm.llmodule - = "llvm_ee_remove_module" - external find_function: string -> t -> Llvm.llvalue option - = "llvm_ee_find_function" - external run_function: Llvm.llvalue -> GenericValue.t array -> t -> - GenericValue.t - = "llvm_ee_run_function" - external run_static_ctors: t -> unit - = "llvm_ee_run_static_ctors" - external run_static_dtors: t -> unit - = "llvm_ee_run_static_dtors" - external run_function_as_main: Llvm.llvalue -> string array -> - (string * string) array -> t -> int - = "llvm_ee_run_function_as_main" - external free_machine_code: Llvm.llvalue -> t -> unit - = "llvm_ee_free_machine_code" - - external data_layout : t -> Llvm_target.DataLayout.t - = "llvm_ee_get_data_layout" - - (* The following are not bound. Patches are welcome. - - add_global_mapping: llvalue -> llgenericvalue -> t -> unit - clear_all_global_mappings: t -> unit - update_global_mapping: llvalue -> llgenericvalue -> t -> unit - get_pointer_to_global_if_available: llvalue -> t -> llgenericvalue - get_pointer_to_global: llvalue -> t -> llgenericvalue - get_pointer_to_function: llvalue -> t -> llgenericvalue - get_pointer_to_function_or_stub: llvalue -> t -> llgenericvalue - get_global_value_at_address: llgenericvalue -> t -> llvalue option - store_value_to_memory: llgenericvalue -> llgenericvalue -> lltype -> unit - initialize_memory: llvalue -> llgenericvalue -> t -> unit - recompile_and_relink_function: llvalue -> t -> llgenericvalue - get_or_emit_global_variable: llvalue -> t -> llgenericvalue - disable_lazy_compilation: t -> unit - lazy_compilation_enabled: t -> bool - install_lazy_function_creator: (string -> llgenericvalue) -> t -> unit - - *) -end - -external initialize_native_target : unit -> bool - = "llvm_initialize_native_target" +let () = Callback.register_exception "Llvm_executionengine.Error" (Error "") + +external initialize : unit -> bool + = "llvm_ee_initialize" + +type llexecutionengine + +type llcompileroptions = { + opt_level: int; + code_model: Llvm_target.CodeModel.t; + no_framepointer_elim: bool; + enable_fast_isel: bool; +} + +let default_compiler_options = { + opt_level = 0; + code_model = Llvm_target.CodeModel.JITDefault; + no_framepointer_elim = false; + enable_fast_isel = false } + +external create : ?options:llcompileroptions -> Llvm.llmodule -> llexecutionengine + = "llvm_ee_create" +external dispose : llexecutionengine -> unit + = "llvm_ee_dispose" +external add_module : Llvm.llmodule -> llexecutionengine -> unit + = "llvm_ee_add_module" +external remove_module : Llvm.llmodule -> llexecutionengine -> unit + = "llvm_ee_remove_module" +external run_static_ctors : llexecutionengine -> unit + = "llvm_ee_run_static_ctors" +external run_static_dtors : llexecutionengine -> unit + = "llvm_ee_run_static_dtors" +external data_layout : llexecutionengine -> Llvm_target.DataLayout.t + = "llvm_ee_get_data_layout" +external add_global_mapping_ : Llvm.llvalue -> int64 -> llexecutionengine -> unit + = "llvm_ee_add_global_mapping" +external get_pointer_to_global_ : Llvm.llvalue -> llexecutionengine -> int64 + = "llvm_ee_get_pointer_to_global" + +let add_global_mapping llval ptr ee = + add_global_mapping_ llval (Ctypes.raw_address_of_ptr (Ctypes.to_voidp ptr)) ee + +let get_pointer_to_global llval typ ee = + Ctypes.coerce (let open Ctypes in ptr void) typ + (Ctypes.ptr_of_raw_address (get_pointer_to_global_ llval ee)) + +(* The following are not bound. Patches are welcome. +target_machine : llexecutionengine -> Llvm_target.TargetMachine.t + *) diff --git a/bindings/ocaml/executionengine/llvm_executionengine.mli b/bindings/ocaml/executionengine/llvm_executionengine.mli index 74a6062..b07151d 100644 --- a/bindings/ocaml/executionengine/llvm_executionengine.mli +++ b/bindings/ocaml/executionengine/llvm_executionengine.mli @@ -1,4 +1,4 @@ -(*===-- llvm_executionengine.mli - LLVM OCaml Interface ---------*- C++ -*-===* +(*===-- llvm_executionengine.mli - LLVM OCaml Interface -------*- OCaml -*-===* * * The LLVM Compiler Infrastructure * @@ -10,147 +10,75 @@ (** JIT Interpreter. This interface provides an OCaml API for LLVM execution engine (JIT/ - interpreter), the classes in the ExecutionEngine library. *) + interpreter), the classes in the [ExecutionEngine] library. *) exception Error of string -module GenericValue: sig - (** [GenericValue.t] is a boxed union type used to portably pass arguments to - and receive values from the execution engine. It supports only a limited - selection of types; for more complex argument types, it is necessary to - generate a stub function by hand or to pass parameters by reference. - See the struct [llvm::GenericValue]. *) - type t - - (** [of_float fpty n] boxes the float [n] in a float-valued generic value - according to the floating point type [fpty]. See the fields - [llvm::GenericValue::DoubleVal] and [llvm::GenericValue::FloatVal]. *) - val of_float : Llvm.lltype -> float -> t - - (** [of_pointer v] boxes the pointer value [v] in a generic value. See the - field [llvm::GenericValue::PointerVal]. *) - val of_pointer : 'a -> t - - (** [of_int32 n w] boxes the int32 [i] in a generic value with the bitwidth - [w]. See the field [llvm::GenericValue::IntVal]. *) - val of_int32 : Llvm.lltype -> int32 -> t - - (** [of_int n w] boxes the int [i] in a generic value with the bitwidth - [w]. See the field [llvm::GenericValue::IntVal]. *) - val of_int : Llvm.lltype -> int -> t - - (** [of_natint n w] boxes the native int [i] in a generic value with the - bitwidth [w]. See the field [llvm::GenericValue::IntVal]. *) - val of_nativeint : Llvm.lltype -> nativeint -> t - - (** [of_int64 n w] boxes the int64 [i] in a generic value with the bitwidth - [w]. See the field [llvm::GenericValue::IntVal]. *) - val of_int64 : Llvm.lltype -> int64 -> t - - (** [as_float fpty gv] unboxes the floating point-valued generic value [gv] of - floating point type [fpty]. See the fields [llvm::GenericValue::DoubleVal] - and [llvm::GenericValue::FloatVal]. *) - val as_float : Llvm.lltype -> t -> float - - (** [as_pointer gv] unboxes the pointer-valued generic value [gv]. See the - field [llvm::GenericValue::PointerVal]. *) - val as_pointer : t -> 'a - - (** [as_int32 gv] unboxes the integer-valued generic value [gv] as an [int32]. - Is invalid if [gv] has a bitwidth greater than 32 bits. See the field - [llvm::GenericValue::IntVal]. *) - val as_int32 : t -> int32 - - (** [as_int gv] unboxes the integer-valued generic value [gv] as an [int]. - Is invalid if [gv] has a bitwidth greater than the host bit width (but the - most significant bit may be lost). See the field - [llvm::GenericValue::IntVal]. *) - val as_int : t -> int - - (** [as_natint gv] unboxes the integer-valued generic value [gv] as a - [nativeint]. Is invalid if [gv] has a bitwidth greater than - [nativeint]. See the field [llvm::GenericValue::IntVal]. *) - val as_nativeint : t -> nativeint - - (** [as_int64 gv] returns the integer-valued generic value [gv] as an [int64]. - Is invalid if [gv] has a bitwidth greater than [int64]. See the field - [llvm::GenericValue::IntVal]. *) - val as_int64 : t -> int64 -end - - -module ExecutionEngine: sig - (** An execution engine is either a JIT compiler or an interpreter, capable of - directly loading an LLVM module and executing its functions without first - invoking a static compiler and generating a native executable. *) - type t - - (** [create m] creates a new execution engine, taking ownership of the - module [m] if successful. Creates a JIT if possible, else falls back to an - interpreter. Raises [Error msg] if an error occurrs. The execution engine - is not garbage collected and must be destroyed with [dispose ee]. - See the function [llvm::EngineBuilder::create]. *) - val create : Llvm.llmodule -> t - - (** [create_interpreter m] creates a new interpreter, taking ownership of the - module [m] if successful. Raises [Error msg] if an error occurrs. The - execution engine is not garbage collected and must be destroyed with - [dispose ee]. - See the function [llvm::EngineBuilder::create]. *) - val create_interpreter : Llvm.llmodule -> t - - (** [create_jit m optlevel] creates a new JIT (just-in-time compiler), taking - ownership of the module [m] if successful with the desired optimization - level [optlevel]. Raises [Error msg] if an error occurrs. The execution - engine is not garbage collected and must be destroyed with [dispose ee]. - See the function [llvm::EngineBuilder::create]. *) - val create_jit : Llvm.llmodule -> int -> t - - (** [dispose ee] releases the memory used by the execution engine and must be - invoked to avoid memory leaks. *) - val dispose : t -> unit - - (** [add_module m ee] adds the module [m] to the execution engine [ee]. *) - val add_module : Llvm.llmodule -> t -> unit - - (** [remove_module m ee] removes the module [m] from the execution engine - [ee], disposing of [m] and the module referenced by [mp]. Raises - [Error msg] if an error occurs. *) - val remove_module : Llvm.llmodule -> t -> Llvm.llmodule - - (** [find_function n ee] finds the function named [n] defined in any of the - modules owned by the execution engine [ee]. Returns [None] if the function - is not found and [Some f] otherwise. *) - val find_function : string -> t -> Llvm.llvalue option - - (** [run_function f args ee] synchronously executes the function [f] with the - arguments [args], which must be compatible with the parameter types. *) - val run_function : Llvm.llvalue -> GenericValue.t array -> t -> - GenericValue.t - - (** [run_static_ctors ee] executes the static constructors of each module in - the execution engine [ee]. *) - val run_static_ctors : t -> unit - - (** [run_static_dtors ee] executes the static destructors of each module in - the execution engine [ee]. *) - val run_static_dtors : t -> unit - - (** [run_function_as_main f args env ee] executes the function [f] as a main - function, passing it [argv] and [argc] according to the string array - [args], and [envp] as specified by the array [env]. Returns the integer - return value of the function. *) - val run_function_as_main : Llvm.llvalue -> string array -> - (string * string) array -> t -> int - - (** [free_machine_code f ee] releases the memory in the execution engine [ee] - used to store the machine code for the function [f]. *) - val free_machine_code : Llvm.llvalue -> t -> unit - - (** [data_layout ee] is the data layout of the execution engine [ee]. *) - val data_layout : t -> Llvm_target.DataLayout.t -end - -(** [initialize_native_target ()] initializes the native target corresponding - to the host. Returns [true] if initialization is {b not} done. *) -val initialize_native_target : unit -> bool +(** [initialize ()] initializes the backend corresponding to the host. + Returns [true] if initialization is successful; [false] indicates + that there is no such backend or it is unable to emit object code + via MCJIT. *) +val initialize : unit -> bool + +(** An execution engine is either a JIT compiler or an interpreter, capable of + directly loading an LLVM module and executing its functions without first + invoking a static compiler and generating a native executable. *) +type llexecutionengine + +(** MCJIT compiler options. See [llvm::TargetOptions]. *) +type llcompileroptions = { + opt_level: int; + code_model: Llvm_target.CodeModel.t; + no_framepointer_elim: bool; + enable_fast_isel: bool; +} + +(** Default MCJIT compiler options: + [{ opt_level = 0; code_model = CodeModel.JIT_default; + no_framepointer_elim = false; enable_fast_isel = false }] *) +val default_compiler_options : llcompileroptions + +(** [create m optlevel] creates a new MCJIT just-in-time compiler, taking + ownership of the module [m] if successful with the desired optimization + level [optlevel]. Raises [Error msg] if an error occurrs. The execution + engine is not garbage collected and must be destroyed with [dispose ee]. + + Run {!initialize} before using this function. + + See the function [llvm::EngineBuilder::create]. *) +val create : ?options:llcompileroptions -> Llvm.llmodule -> llexecutionengine + +(** [dispose ee] releases the memory used by the execution engine and must be + invoked to avoid memory leaks. *) +val dispose : llexecutionengine -> unit + +(** [add_module m ee] adds the module [m] to the execution engine [ee]. *) +val add_module : Llvm.llmodule -> llexecutionengine -> unit + +(** [remove_module m ee] removes the module [m] from the execution engine + [ee]. Raises [Error msg] if an error occurs. *) +val remove_module : Llvm.llmodule -> llexecutionengine -> unit + +(** [run_static_ctors ee] executes the static constructors of each module in + the execution engine [ee]. *) +val run_static_ctors : llexecutionengine -> unit + +(** [run_static_dtors ee] executes the static destructors of each module in + the execution engine [ee]. *) +val run_static_dtors : llexecutionengine -> unit + +(** [data_layout ee] is the data layout of the execution engine [ee]. *) +val data_layout : llexecutionengine -> Llvm_target.DataLayout.t + +(** [add_global_mapping gv ptr ee] tells the execution engine [ee] that + the global [gv] is at the specified location [ptr], which must outlive + [gv] and [ee]. + All uses of [gv] in the compiled code will refer to [ptr]. *) +val add_global_mapping : Llvm.llvalue -> 'a Ctypes.ptr -> llexecutionengine -> unit + +(** [get_pointer_to_global gv typ ee] returns the value of the global + variable [gv] in the execution engine [ee] as type [typ], which may + be a pointer type (e.g. [int ptr typ]) for global variables or + a function (e.g. [(int -> int) typ]) type for functions, and which + will be live as long as [gv] and [ee] are. *) +val get_pointer_to_global : Llvm.llvalue -> 'a Ctypes.typ -> llexecutionengine -> 'a diff --git a/bindings/ocaml/irreader/irreader_ocaml.c b/bindings/ocaml/irreader/irreader_ocaml.c index 30c10c7..ce593db 100644 --- a/bindings/ocaml/irreader/irreader_ocaml.c +++ b/bindings/ocaml/irreader/irreader_ocaml.c @@ -16,33 +16,9 @@ #include "caml/alloc.h" #include "caml/fail.h" #include "caml/memory.h" +#include "caml/callback.h" -/* Can't use the recommended caml_named_value mechanism for backwards - compatibility reasons. This is largely equivalent. */ -static value llvm_irreader_error_exn; - -CAMLprim value llvm_register_irreader_exns(value Error) { - llvm_irreader_error_exn = Field(Error, 0); - register_global_root(&llvm_irreader_error_exn); - return Val_unit; -} - -static void llvm_raise(value Prototype, char *Message) { - CAMLparam1(Prototype); - CAMLlocal1(CamlMessage); - - CamlMessage = copy_string(Message); - LLVMDisposeMessage(Message); - - raise_with_arg(Prototype, CamlMessage); - abort(); /* NOTREACHED */ -#ifdef CAMLnoreturn - CAMLnoreturn; /* Silences warnings, but is missing in some versions. */ -#endif -} - - -/*===-- Modules -----------------------------------------------------------===*/ +void llvm_raise(value Prototype, char *Message); /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */ CAMLprim value llvm_parse_ir(LLVMContextRef C, @@ -53,7 +29,7 @@ CAMLprim value llvm_parse_ir(LLVMContextRef C, char *Message; if (LLVMParseIRInContext(C, MemBuf, &M, &Message)) - llvm_raise(llvm_irreader_error_exn, Message); + llvm_raise(*caml_named_value("Llvm_irreader.Error"), Message); CAMLreturn((value) M); } diff --git a/bindings/ocaml/irreader/llvm_irreader.ml b/bindings/ocaml/irreader/llvm_irreader.ml index 455b1fa..f757d62 100644 --- a/bindings/ocaml/irreader/llvm_irreader.ml +++ b/bindings/ocaml/irreader/llvm_irreader.ml @@ -10,8 +10,7 @@ exception Error of string -external register_exns : exn -> unit = "llvm_register_irreader_exns" -let _ = register_exns (Error "") +let _ = Callback.register_exception "Llvm_irreader.Error" (Error "") external parse_ir : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule = "llvm_parse_ir" diff --git a/bindings/ocaml/linker/linker_ocaml.c b/bindings/ocaml/linker/linker_ocaml.c index 2491e3b..ed37777 100644 --- a/bindings/ocaml/linker/linker_ocaml.c +++ b/bindings/ocaml/linker/linker_ocaml.c @@ -1,4 +1,4 @@ -/*===-- linker_ocaml.c - LLVM Ocaml Glue ------------------------*- C++ -*-===*\ +/*===-- linker_ocaml.c - LLVM OCaml Glue ------------------------*- C++ -*-===*\ |* *| |* The LLVM Compiler Infrastructure *| |* *| @@ -19,36 +19,16 @@ #include "caml/alloc.h" #include "caml/memory.h" #include "caml/fail.h" +#include "caml/callback.h" -static value llvm_linker_error_exn; +void llvm_raise(value Prototype, char *Message); -CAMLprim value llvm_register_linker_exns(value Error) { - llvm_linker_error_exn = Field(Error, 0); - register_global_root(&llvm_linker_error_exn); - return Val_unit; -} - -static void llvm_raise(value Prototype, char *Message) { - CAMLparam1(Prototype); - CAMLlocal1(CamlMessage); - - CamlMessage = copy_string(Message); - LLVMDisposeMessage(Message); - - raise_with_arg(Prototype, CamlMessage); - abort(); /* NOTREACHED */ -#ifdef CAMLnoreturn - CAMLnoreturn; /* Silences warnings, but is missing in some versions. */ -#endif -} - -/* llmodule -> llmodule -> Mode.t -> unit - raises Error msg on error */ +/* llmodule -> llmodule -> Mode.t -> unit */ CAMLprim value llvm_link_modules(LLVMModuleRef Dst, LLVMModuleRef Src, value Mode) { char* Message; if (LLVMLinkModules(Dst, Src, Int_val(Mode), &Message)) - llvm_raise(llvm_linker_error_exn, Message); + llvm_raise(*caml_named_value("Llvm_linker.Error"), Message); return Val_unit; } diff --git a/bindings/ocaml/linker/llvm_linker.ml b/bindings/ocaml/linker/llvm_linker.ml index 2b73e2e..5854d70 100644 --- a/bindings/ocaml/linker/llvm_linker.ml +++ b/bindings/ocaml/linker/llvm_linker.ml @@ -9,8 +9,7 @@ exception Error of string -external register_exns : exn -> unit = "llvm_register_linker_exns" -let _ = register_exns (Error "") +let () = Callback.register_exception "Llvm_linker.Error" (Error "") module Mode = struct type t = @@ -19,4 +18,4 @@ module Mode = struct end external link_modules : Llvm.llmodule -> Llvm.llmodule -> Mode.t -> unit - = "llvm_link_modules"
\ No newline at end of file + = "llvm_link_modules" diff --git a/bindings/ocaml/llvm/META.llvm.in b/bindings/ocaml/llvm/META.llvm.in index edb84e0..f9808c7 100644 --- a/bindings/ocaml/llvm/META.llvm.in +++ b/bindings/ocaml/llvm/META.llvm.in @@ -4,7 +4,6 @@ description = "LLVM OCaml bindings" archive(byte) = "llvm.cma" archive(native) = "llvm.cmxa" directory = "." -linkopts = "-ccopt -lstdc++" package "analysis" ( requires = "llvm" @@ -31,7 +30,7 @@ package "bitwriter" ( ) package "executionengine" ( - requires = "llvm,llvm.target" + requires = "llvm,llvm.target,ctypes.foreign" version = "@PACKAGE_VERSION@" description = "JIT and Interpreter for LLVM" archive(byte) = "llvm_executionengine.cma" diff --git a/bindings/ocaml/llvm/Makefile b/bindings/ocaml/llvm/Makefile index 850f564..fb682c7 100644 --- a/bindings/ocaml/llvm/Makefile +++ b/bindings/ocaml/llvm/Makefile @@ -1,20 +1,21 @@ ##===- bindings/ocaml/llvm/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 interface. -# +# ##===----------------------------------------------------------------------===## LEVEL := ../../.. LIBRARYNAME := llvm -UsedComponents := core +UsedComponents := core transformutils UsedOcamlLibs := llvm +ExtraLibs := -lstdc++ include ../Makefile.ocaml diff --git a/bindings/ocaml/llvm/llvm.ml b/bindings/ocaml/llvm/llvm.ml index 39875a5..0df4d40 100644 --- a/bindings/ocaml/llvm/llvm.ml +++ b/bindings/ocaml/llvm/llvm.ml @@ -1,4 +1,4 @@ -(*===-- llvm/llvm.ml - LLVM Ocaml Interface --------------------------------===* +(*===-- llvm/llvm.ml - LLVM OCaml Interface -------------------------------===* * * The LLVM Compiler Infrastructure * @@ -66,6 +66,13 @@ module Visibility = struct | Protected end +module DLLStorageClass = struct + type t = + | Default + | DLLImport + | DLLExport +end + module CallConv = struct let c = 0 let fast = 8 @@ -278,8 +285,7 @@ end exception IoError of string -external register_exns : exn -> unit = "llvm_register_core_exns" -let _ = register_exns (IoError "") +let () = Callback.register_exception "Llvm.IoError" (IoError "") external install_fatal_error_handler : (string -> unit) -> unit = "llvm_install_fatal_error_handler" @@ -287,6 +293,8 @@ external reset_fatal_error_handler : unit -> unit = "llvm_reset_fatal_error_handler" external enable_pretty_stacktrace : unit -> unit = "llvm_enable_pretty_stacktrace" +external parse_command_line_options : ?overview:string -> string array -> unit + = "llvm_parse_command_line_options" type ('a, 'b) llpos = | At_end of 'a @@ -305,6 +313,7 @@ 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 @@ -428,6 +437,7 @@ let fold_right_uses f v init = (*--... Operations on users ................................................--*) external operand : llvalue -> int -> llvalue = "llvm_operand" +external operand_use : llvalue -> int -> lluse = "llvm_operand_use" external set_operand : llvalue -> int -> llvalue -> unit = "llvm_set_operand" external num_operands : llvalue -> int = "llvm_num_operands" @@ -465,6 +475,8 @@ external int64_of_const : llvalue -> Int64.t option external const_int_of_string : lltype -> string -> int -> llvalue = "llvm_const_int_of_string" external const_float : lltype -> float -> llvalue = "llvm_const_float" +external float_of_const : llvalue -> float option + = "llvm_float_of_const" external const_float_of_string : lltype -> string -> llvalue = "llvm_const_float_of_string" @@ -479,6 +491,8 @@ external const_named_struct : lltype -> llvalue array -> llvalue external const_packed_struct : llcontext -> llvalue array -> llvalue = "llvm_const_packed_struct" external const_vector : llvalue array -> llvalue = "llvm_const_vector" +external string_of_const : llvalue -> string option = "llvm_string_of_const" +external const_element : llvalue -> int -> llvalue = "llvm_const_element" (*--... Constant expressions ...............................................--*) external align_of : lltype -> llvalue = "LLVMAlignOf" @@ -569,6 +583,8 @@ external section : llvalue -> string = "llvm_section" external set_section : string -> llvalue -> unit = "llvm_set_section" external visibility : llvalue -> Visibility.t = "llvm_visibility" external set_visibility : Visibility.t -> llvalue -> unit = "llvm_set_visibility" +external dll_storage_class : llvalue -> DLLStorageClass.t = "llvm_dll_storage_class" +external set_dll_storage_class : DLLStorageClass.t -> llvalue -> unit = "llvm_set_dll_storage_class" external alignment : llvalue -> int = "llvm_alignment" external set_alignment : int -> llvalue -> unit = "llvm_set_alignment" external is_global_constant : llvalue -> bool = "llvm_is_global_constant" @@ -952,6 +968,8 @@ external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos external instr_opcode : llvalue -> Opcode.t = "llvm_instr_get_opcode" external icmp_predicate : llvalue -> Icmp.t option = "llvm_instr_icmp_predicate" +external fcmp_predicate : llvalue -> Fcmp.t option = "llvm_instr_fcmp_predicate" +external instr_clone : llvalue -> llvalue = "llvm_instr_clone" let rec iter_instrs_range f i e = if i = e then () else @@ -1019,6 +1037,63 @@ external set_tail_call : bool -> llvalue -> unit = "llvm_set_tail_call" external is_volatile : llvalue -> bool = "llvm_is_volatile" external set_volatile : bool -> llvalue -> unit = "llvm_set_volatile" +(*--... Operations on terminators ..........................................--*) + +let is_terminator llv = + let open ValueKind in + let open Opcode in + match classify_value llv with + | Instruction (Br | IndirectBr | Invoke | Resume | Ret | Switch | Unreachable) + -> true + | _ -> false + +external successor : llvalue -> int -> llbasicblock = "llvm_successor" +external set_successor : llvalue -> int -> llbasicblock -> unit + = "llvm_set_successor" +external num_successors : llvalue -> int = "llvm_num_successors" + +let successors llv = + if not (is_terminator llv) then + raise (Invalid_argument "Llvm.successors can only be used on terminators") + else + Array.init (num_successors llv) (successor llv) + +let iter_successors f llv = + if not (is_terminator llv) then + raise (Invalid_argument "Llvm.iter_successors can only be used on terminators") + else + for i = 0 to num_successors llv - 1 do + f (successor llv i) + done + +let fold_successors f llv z = + if not (is_terminator llv) then + raise (Invalid_argument "Llvm.fold_successors can only be used on terminators") + else + let n = num_successors llv in + let rec aux i acc = + if i >= n then acc + else begin + let llb = successor llv i in + aux (i+1) (f llb acc) + end + in aux 0 z + + +(*--... Operations on branches .............................................--*) +external condition : llvalue -> llvalue = "llvm_condition" +external set_condition : llvalue -> llvalue -> unit + = "llvm_set_condition" +external is_conditional : llvalue -> bool = "llvm_is_conditional" + +let get_branch llv = + if classify_value llv <> ValueKind.Instruction Opcode.Br then + None + else if is_conditional llv then + Some (`Conditional (condition llv, successor llv 0, successor llv 1)) + else + Some (`Unconditional (successor llv 0)) + (*--... Operations on phi nodes ............................................--*) external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit = "llvm_add_incoming" diff --git a/bindings/ocaml/llvm/llvm.mli b/bindings/ocaml/llvm/llvm.mli index f5f5b53..e5e90c3 100644 --- a/bindings/ocaml/llvm/llvm.mli +++ b/bindings/ocaml/llvm/llvm.mli @@ -105,6 +105,15 @@ module Visibility : sig | Protected end +(** The DLL storage class of a global value, accessed with {!dll_storage_class} and + {!set_dll_storage_class}. See [llvm::GlobalValue::DLLStorageClassTypes]. *) +module DLLStorageClass : sig + type t = + | Default + | DLLImport + | DLLExport +end + (** The following calling convention values may be accessed with {!function_call_conv} and {!set_function_call_conv}. Calling conventions are open-ended. *) @@ -157,16 +166,16 @@ end See the [llvm::ICmpInst::Predicate] enumeration. *) module Icmp : sig type t = - | Eq (* Equal *) - | Ne (* Not equal *) - | Ugt (* Unsigned greater than *) - | Uge (* Unsigned greater or equal *) - | Ult (* Unsigned less than *) - | Ule (* Unsigned less or equal *) - | Sgt (* Signed greater than *) - | Sge (* Signed greater or equal *) - | Slt (* Signed less than *) - | Sle (* Signed less or equal *) + | Eq (** Equal *) + | Ne (** Not equal *) + | Ugt (** Unsigned greater than *) + | Uge (** Unsigned greater or equal *) + | Ult (** Unsigned less than *) + | Ule (** Unsigned less or equal *) + | Sgt (** Signed greater than *) + | Sge (** Signed greater or equal *) + | Slt (** Signed less than *) + | Sle (** Signed less or equal *) end (** The predicate for a floating-point comparison ([fcmp]) instruction. @@ -175,38 +184,38 @@ end See the [llvm::FCmpInst::Predicate] enumeration. *) module Fcmp : sig type t = - | False (* Always false *) - | Oeq (* Ordered and equal *) - | Ogt (* Ordered and greater than *) - | Oge (* Ordered and greater or equal *) - | Olt (* Ordered and less than *) - | Ole (* Ordered and less or equal *) - | One (* Ordered and not equal *) - | Ord (* Ordered (no operand is NaN) *) - | Uno (* Unordered (one operand at least is NaN) *) - | Ueq (* Unordered and equal *) - | Ugt (* Unordered and greater than *) - | Uge (* Unordered and greater or equal *) - | Ult (* Unordered and less than *) - | Ule (* Unordered and less or equal *) - | Une (* Unordered and not equal *) - | True (* Always true *) + | False (** Always false *) + | Oeq (** Ordered and equal *) + | Ogt (** Ordered and greater than *) + | Oge (** Ordered and greater or equal *) + | Olt (** Ordered and less than *) + | Ole (** Ordered and less or equal *) + | One (** Ordered and not equal *) + | Ord (** Ordered (no operand is NaN) *) + | Uno (** Unordered (one operand at least is NaN) *) + | Ueq (** Unordered and equal *) + | Ugt (** Unordered and greater than *) + | Uge (** Unordered and greater or equal *) + | Ult (** Unordered and less than *) + | Ule (** Unordered and less or equal *) + | Une (** Unordered and not equal *) + | True (** Always true *) end (** The opcodes for LLVM instructions and constant expressions. *) module Opcode : sig type t = - | Invalid (* not an instruction *) - (* Terminator Instructions *) - | Ret + | Invalid (** Not an instruction *) + + | Ret (** Terminator Instructions *) | Br | Switch | IndirectBr | Invoke | Invalid2 | Unreachable - (* Standard Binary Operators *) - | Add + + | Add (** Standard Binary Operators *) | FAdd | Sub | FSub @@ -218,20 +227,20 @@ module Opcode : sig | URem | SRem | FRem - (* Logical Operators *) - | Shl + + | Shl (** Logical Operators *) | LShr | AShr | And | Or | Xor - (* Memory Operators *) - | Alloca + + | Alloca (** Memory Operators *) | Load | Store | GetElementPtr - (* Cast Operators *) - | Trunc + + | Trunc (** Cast Operators *) | ZExt | SExt | FPToUI @@ -243,8 +252,8 @@ module Opcode : sig | PtrToInt | IntToPtr | BitCast - (* Other Operators *) - | ICmp + + | ICmp (** Other Operators *) | FCmp | PHI | Call @@ -291,7 +300,7 @@ module AtomicOrdering : sig | NotAtomic | Unordered | Monotonic - | Invalid (* removed due to API changes *) + | Invalid (** removed due to API changes *) | Acquire | Release | AcqiureRelease @@ -381,6 +390,14 @@ val install_fatal_error_handler : (string -> unit) -> unit (** [reset_fatal_error_handler ()] resets LLVM's fatal error handler. *) val reset_fatal_error_handler : unit -> unit +(** [parse_command_line_options ?overview args] parses [args] using + the LLVM command line parser. Note that the only stable thing about this + function is its signature; you cannot rely on any particular set of command + line arguments being interpreted the same way across LLVM versions. + + See the function [llvm::cl::ParseCommandLineOptions()]. *) +val parse_command_line_options : ?overview:string -> string array -> unit + (** {6 Contexts} *) (** [create_context ()] creates a context for storing the "global" state in @@ -414,6 +431,9 @@ 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 @@ -651,7 +671,7 @@ val x86_mmx_type : llcontext -> lltype val type_by_name : llmodule -> string -> lltype option -(* {6 Values} *) +(** {6 Values} *) (** [type_of v] returns the type of the value [v]. See the method [llvm::Value::getType]. *) @@ -682,7 +702,7 @@ val string_of_llvalue : llvalue -> string val replace_all_uses_with : llvalue -> llvalue -> unit -(* {6 Uses} *) +(** {6 Uses} *) (** [use_begin v] returns the first position in the use list for the value [v]. [use_begin] and [use_succ] can e used to iterate over the use list in order. @@ -714,12 +734,17 @@ val fold_left_uses : ('a -> lluse -> 'a) -> 'a -> llvalue -> 'a val fold_right_uses : (lluse -> 'a -> 'a) -> llvalue -> 'a -> 'a -(* {6 Users} *) +(** {6 Users} *) (** [operand v i] returns the operand at index [i] for the value [v]. See the method [llvm::User::getOperand]. *) val operand : llvalue -> int -> llvalue +(** [operand_use v i] returns the use of the operand at index [i] for the value [v]. See the + method [llvm::User::getOperandUse]. *) +val operand_use : llvalue -> int -> lluse + + (** [set_operand v i o] sets the operand of the value [v] at the index [i] to the value [o]. See the method [llvm::User::setOperand]. *) @@ -837,15 +862,19 @@ val const_int_of_string : lltype -> string -> int -> llvalue value [n]. See the method [llvm::ConstantFP::get]. *) val const_float : lltype -> float -> llvalue +(** [float_of_const c] returns the float value of the [c] constant float. + None is returned if this is not an float constant. + See the method [llvm::ConstantFP::getDoubleValue].*) +val float_of_const : llvalue -> float option + (** [const_float_of_string ty s] returns the floating point constant of type [ty] and value [n]. See the method [llvm::ConstantFP::get]. *) val const_float_of_string : lltype -> string -> llvalue - (** {7 Operations on composite constants} *) (** [const_string c s] returns the constant [i8] array with the values of the - characters in the string [s] in the context [c]. The array is not + characters in the string [s] in the context [c]. The array is not null-terminated (but see {!const_stringz}). This value can in turn be used as the initializer for a global variable. See the method [llvm::ConstantArray::get]. *) @@ -887,6 +916,14 @@ val const_packed_struct : llcontext -> llvalue array -> llvalue values [elts]. See the method [llvm::ConstantVector::get]. *) val const_vector : llvalue array -> llvalue +(** [string_of_const c] returns [Some str] if [c] is a string constant, + or [None] if this is not a string constant. *) +val string_of_const : llvalue -> string option + +(** [const_element c] returns a constant for a specified index's element. + See the method ConstantDataSequential::getElementAsConstant. *) +val const_element : llvalue -> int -> llvalue + (** {7 Constant expressions} *) @@ -1234,6 +1271,14 @@ val visibility : llvalue -> Visibility.t [v]. See the method [llvm::GlobalValue::setVisibility]. *) val set_visibility : Visibility.t -> llvalue -> unit +(** [dll_storage_class g] returns the DLL storage class of the global value [g]. + See the method [llvm::GlobalValue::getDLLStorageClass]. *) +val dll_storage_class : llvalue -> DLLStorageClass.t + +(** [set_dll_storage_class v g] sets the DLL storage class of the global value [g] to + [v]. See the method [llvm::GlobalValue::setDLLStorageClass]. *) +val set_dll_storage_class : DLLStorageClass.t -> llvalue -> unit + (** [alignment g] returns the required alignment of the global value [g]. See the method [llvm::GlobalValue::getAlignment]. *) val alignment : llvalue -> int @@ -1687,6 +1732,15 @@ val instr_opcode : llvalue -> Opcode.t instruction [i]. *) val icmp_predicate : llvalue -> Icmp.t option +(** [fcmp_predicate i] returns the [fcmp.t] corresponding to an [fcmp] + instruction [i]. *) +val fcmp_predicate : llvalue -> Fcmp.t option + +(** [inst_clone i] returns a copy of instruction [i], + The instruction has no parent, and no name. + See the method [llvm::Instruction::clone]. *) +val instr_clone : llvalue -> llvalue + (** {7 Operations on call sites} *) @@ -1741,6 +1795,52 @@ val is_volatile : llvalue -> bool [llvm::StoreInst::setVolatile]. *) val set_volatile : bool -> llvalue -> unit +(** {7 Operations on terminators} *) + +(** [is_terminator v] returns true if the instruction [v] is a terminator. *) +val is_terminator : llvalue -> bool + +(** [successor v i] returns the successor at index [i] for the value [v]. + See the method [llvm::TerminatorInst::getSuccessor]. *) +val successor : llvalue -> int -> llbasicblock + +(** [set_successor v i o] sets the successor of the value [v] at the index [i] to + the value [o]. + See the method [llvm::TerminatorInst::setSuccessor]. *) +val set_successor : llvalue -> int -> llbasicblock -> unit + +(** [num_successors v] returns the number of successors for the value [v]. + See the method [llvm::TerminatorInst::getNumSuccessors]. *) +val num_successors : llvalue -> int + +(** [successors v] returns the successors of [v]. *) +val successors : llvalue -> llbasicblock array + +(** [iter_successors f v] applies function f to each successor [v] in order. Tail recursive. *) +val iter_successors : (llbasicblock -> unit) -> llvalue -> unit + +(** [fold_successors f v init] is [f (... (f init vN) ...) v1] where [v1,...,vN] are the successors of [v]. Tail recursive. *) +val fold_successors : (llbasicblock -> 'a -> 'a) -> llvalue -> 'a -> 'a + +(** {7 Operations on branches} *) + +(** [is_conditional v] returns true if the branch instruction [v] is conditional. + See the method [llvm::BranchInst::isConditional]. *) +val is_conditional : llvalue -> bool + +(** [condition v] return the condition of the branch instruction [v]. + See the method [llvm::BranchInst::getCondition]. *) +val condition : llvalue -> llvalue + +(** [set_condition v c] sets the condition of the branch instruction [v] to the value [c]. + See the method [llvm::BranchInst::setCondition]. *) +val set_condition : llvalue -> llvalue -> unit + +(** [get_branch c] returns a description of the branch instruction [c]. *) +val get_branch : llvalue -> + [ `Conditional of llvalue * llbasicblock * llbasicblock + | `Unconditional of llbasicblock ] + option (** {7 Operations on phi nodes} *) @@ -2402,7 +2502,7 @@ module MemoryBuffer : sig path [p]. If the file could not be read, then [IoError msg] is raised. *) val of_file : string -> llmemorybuffer - + (** [of_stdin ()] is the memory buffer containing the contents of standard input. If standard input is empty, then [IoError msg] is raised. *) val of_stdin : unit -> llmemorybuffer @@ -2413,7 +2513,7 @@ module MemoryBuffer : sig (** [as_string mb] is the string containing the contents of memory buffer [mb]. *) val as_string : llmemorybuffer -> string - + (** Disposes of a memory buffer. *) val dispose : llmemorybuffer -> unit end @@ -2425,13 +2525,13 @@ module PassManager : sig (** *) type 'a t type any = [ `Module | `Function ] - + (** [PassManager.create ()] constructs a new whole-module pass pipeline. This type of pipeline is suitable for link-time optimization and whole-module transformations. See the constructor of [llvm::PassManager]. *) val create : unit -> [ `Module ] t - + (** [PassManager.create_function m] constructs a new function-by-function pass pipeline over the module [m]. It does not take ownership of [m]. This type of pipeline is suitable for code generation and JIT compilation @@ -2450,19 +2550,19 @@ module PassManager : sig the module, [false] otherwise. See the [llvm::FunctionPassManager::doInitialization] method. *) val initialize : [ `Function ] t -> bool - + (** [run_function f fpm] executes all of the function passes scheduled in the function pass manager [fpm] over the function [f]. Returns [true] if any of the passes modified [f], [false] otherwise. See the [llvm::FunctionPassManager::run] method. *) val run_function : llvalue -> [ `Function ] t -> bool - + (** [finalize fpm] finalizes all of the function passes scheduled in in the function pass manager [fpm]. Returns [true] if any of the passes modified the module, [false] otherwise. See the [llvm::FunctionPassManager::doFinalization] method. *) val finalize : [ `Function ] t -> bool - + (** Frees the memory of a pass pipeline. For function pipelines, does not free the module. See the destructor of [llvm::BasePassManager]. *) diff --git a/bindings/ocaml/llvm/llvm_ocaml.c b/bindings/ocaml/llvm/llvm_ocaml.c index d5ebdcd..63c235d 100644 --- a/bindings/ocaml/llvm/llvm_ocaml.c +++ b/bindings/ocaml/llvm/llvm_ocaml.c @@ -15,46 +15,33 @@ |* *| \*===----------------------------------------------------------------------===*/ +#include <assert.h> +#include <stdlib.h> +#include <string.h> #include "llvm-c/Core.h" #include "caml/alloc.h" #include "caml/custom.h" #include "caml/memory.h" #include "caml/fail.h" #include "caml/callback.h" -#include <assert.h> -#include <stdlib.h> -#include <string.h> - - -/* Can't use the recommended caml_named_value mechanism for backwards - compatibility reasons. This is largely equivalent. */ -static value llvm_ioerror_exn; -CAMLprim value llvm_register_core_exns(value IoError) { - llvm_ioerror_exn = Field(IoError, 0); - register_global_root(&llvm_ioerror_exn); +value llvm_string_of_message(char* Message) { + value String = caml_copy_string(Message); + LLVMDisposeMessage(Message); - return Val_unit; + return String; } -static void llvm_raise(value Prototype, char *Message) { +void llvm_raise(value Prototype, char *Message) { CAMLparam1(Prototype); - CAMLlocal1(CamlMessage); - - CamlMessage = copy_string(Message); - LLVMDisposeMessage(Message); - - raise_with_arg(Prototype, CamlMessage); - abort(); /* NOTREACHED */ -#ifdef CAMLnoreturn - CAMLnoreturn; /* Silences warnings, but is missing in some versions. */ -#endif + caml_raise_with_arg(Prototype, llvm_string_of_message(Message)); + CAMLnoreturn; } static value llvm_fatal_error_handler; static void llvm_fatal_error_trampoline(const char *Reason) { - callback(llvm_fatal_error_handler, copy_string(Reason)); + callback(llvm_fatal_error_handler, caml_copy_string(Reason)); } CAMLprim value llvm_install_fatal_error_handler(value Handler) { @@ -75,6 +62,17 @@ CAMLprim value llvm_enable_pretty_stacktrace(value Unit) { return Val_unit; } +CAMLprim value llvm_parse_command_line_options(value Overview, value Args) { + char *COverview; + if (Overview == Val_int(0)) { + COverview = NULL; + } else { + COverview = String_val(Field(Overview, 0)); + } + LLVMParseCommandLineOptions(Wosize_val(Args), (const char* const*) Op_val(Args), COverview); + return Val_unit; +} + static value alloc_variant(int tag, void *Value) { value Iter = alloc_small(1, tag); Field(Iter, 0) = Val_op(Value); @@ -157,7 +155,7 @@ CAMLprim value llvm_dispose_module(LLVMModuleRef M) { /* llmodule -> string */ CAMLprim value llvm_target_triple(LLVMModuleRef M) { - return copy_string(LLVMGetTarget(M)); + return caml_copy_string(LLVMGetTarget(M)); } /* string -> llmodule -> unit */ @@ -168,7 +166,7 @@ CAMLprim value llvm_set_target_triple(value Trip, LLVMModuleRef M) { /* llmodule -> string */ CAMLprim value llvm_data_layout(LLVMModuleRef M) { - return copy_string(LLVMGetDataLayout(M)); + return caml_copy_string(LLVMGetDataLayout(M)); } /* string -> llmodule -> unit */ @@ -186,22 +184,24 @@ CAMLprim value llvm_dump_module(LLVMModuleRef M) { /* string -> llmodule -> unit */ CAMLprim value llvm_print_module(value Filename, LLVMModuleRef M) { char* Message; - if(LLVMPrintModuleToFile(M, String_val(Filename), &Message)) { - llvm_raise(llvm_ioerror_exn, Message); - } + + if(LLVMPrintModuleToFile(M, String_val(Filename), &Message)) + llvm_raise(*caml_named_value("Llvm.IoError"), Message); return Val_unit; } /* llmodule -> string */ CAMLprim value llvm_string_of_llmodule(LLVMModuleRef M) { + CAMLparam0(); + CAMLlocal1(ModuleStr); char* ModuleCStr; - ModuleCStr = LLVMPrintModuleToString(M); - value ModuleStr = caml_copy_string(ModuleCStr); + ModuleCStr = LLVMPrintModuleToString(M); + ModuleStr = caml_copy_string(ModuleCStr); LLVMDisposeMessage(ModuleCStr); - return ModuleStr; + CAMLreturn(ModuleStr); } /* llmodule -> string -> unit */ @@ -234,13 +234,15 @@ CAMLprim value llvm_dump_type(LLVMTypeRef Val) { /* lltype -> string */ CAMLprim value llvm_string_of_lltype(LLVMTypeRef M) { + CAMLparam0(); + CAMLlocal1(TypeStr); char* TypeCStr; - TypeCStr = LLVMPrintTypeToString(M); - value TypeStr = caml_copy_string(TypeCStr); + TypeCStr = LLVMPrintTypeToString(M); + TypeStr = caml_copy_string(TypeCStr); LLVMDisposeMessage(TypeCStr); - return TypeStr; + CAMLreturn(TypeStr); } /*--... Operations on integer types ........................................--*/ @@ -537,7 +539,7 @@ CAMLprim value llvm_classify_value(LLVMValueRef Val) { /* llvalue -> string */ CAMLprim value llvm_value_name(LLVMValueRef Val) { - return copy_string(LLVMGetValueName(Val)); + return caml_copy_string(LLVMGetValueName(Val)); } /* string -> llvalue -> unit */ @@ -554,13 +556,15 @@ CAMLprim value llvm_dump_value(LLVMValueRef Val) { /* llvalue -> string */ CAMLprim value llvm_string_of_llvalue(LLVMValueRef M) { + CAMLparam0(); + CAMLlocal1(ValueStr); char* ValueCStr; - ValueCStr = LLVMPrintValueToString(M); - value ValueStr = caml_copy_string(ValueCStr); + ValueCStr = LLVMPrintValueToString(M); + ValueStr = caml_copy_string(ValueCStr); LLVMDisposeMessage(ValueCStr); - return ValueStr; + CAMLreturn(ValueStr); } /* llvalue -> llvalue -> unit */ @@ -577,6 +581,11 @@ CAMLprim LLVMValueRef llvm_operand(LLVMValueRef V, value I) { return LLVMGetOperand(V, Int_val(I)); } +/* llvalue -> int -> lluse */ +CAMLprim LLVMUseRef llvm_operand_use(LLVMValueRef V, value I) { + return LLVMGetOperandUse(V, Int_val(I)); +} + /* llvalue -> int -> llvalue -> unit */ CAMLprim value llvm_set_operand(LLVMValueRef U, value I, LLVMValueRef V) { LLVMSetOperand(U, Int_val(I), V); @@ -695,7 +704,7 @@ CAMLprim value llvm_append_namedmd(LLVMModuleRef M, value Name, LLVMValueRef Val /* lltype -> int -> llvalue */ CAMLprim LLVMValueRef llvm_const_int(LLVMTypeRef IntTy, value N) { - return LLVMConstInt(IntTy, (long long) Int_val(N), 1); + return LLVMConstInt(IntTy, (long long) Long_val(N), 1); } /* lltype -> Int64.t -> bool -> llvalue */ @@ -729,6 +738,28 @@ CAMLprim LLVMValueRef llvm_const_float(LLVMTypeRef RealTy, value N) { return LLVMConstReal(RealTy, Double_val(N)); } + +/* llvalue -> float */ +CAMLprim value llvm_float_of_const(LLVMValueRef Const) +{ + CAMLparam0(); + CAMLlocal1(Option); + LLVMBool LosesInfo; + double Result; + + if (LLVMIsAConstantFP(Const)) { + Result = LLVMConstRealGetDouble(Const, &LosesInfo); + if (LosesInfo) + CAMLreturn(Val_int(0)); + + Option = alloc(1, 0); + Field(Option, 0) = caml_copy_double(Result); + CAMLreturn(Option); + } + + CAMLreturn(Val_int(0)); +} + /* lltype -> string -> llvalue */ CAMLprim LLVMValueRef llvm_const_float_of_string(LLVMTypeRef RealTy, value S) { return LLVMConstRealOfStringAndSize(RealTy, String_val(S), @@ -782,6 +813,31 @@ CAMLprim LLVMValueRef llvm_const_vector(value ElementVals) { Wosize_val(ElementVals)); } +/* llvalue -> string option */ +CAMLprim value llvm_string_of_const(LLVMValueRef Const) { + const char *S; + size_t Len; + CAMLparam0(); + CAMLlocal2(Option, Str); + + if(LLVMIsAConstantDataSequential(Const) && LLVMIsConstantString(Const)) { + S = LLVMGetAsString(Const, &Len); + Str = caml_alloc_string(Len); + memcpy(String_val(Str), S, Len); + + Option = alloc(1, 0); + Field(Option, 0) = Str; + CAMLreturn(Option); + } else { + CAMLreturn(Val_int(0)); + } +} + +/* llvalue -> int -> llvalue */ +CAMLprim LLVMValueRef llvm_const_element(LLVMValueRef Const, value N) { + return LLVMGetElementAsConstant(Const, Int_val(N)); +} + /*--... Constant expressions ...............................................--*/ /* Icmp.t -> llvalue -> llvalue -> llvalue */ @@ -881,7 +937,7 @@ CAMLprim value llvm_set_linkage(value Linkage, LLVMValueRef Global) { /* llvalue -> string */ CAMLprim value llvm_section(LLVMValueRef Global) { - return copy_string(LLVMGetSection(Global)); + return caml_copy_string(LLVMGetSection(Global)); } /* string -> llvalue -> unit */ @@ -901,6 +957,17 @@ CAMLprim value llvm_set_visibility(value Viz, LLVMValueRef Global) { return Val_unit; } +/* llvalue -> DLLStorageClass.t */ +CAMLprim value llvm_dll_storage_class(LLVMValueRef Global) { + return Val_int(LLVMGetDLLStorageClass(Global)); +} + +/* DLLStorageClass.t -> llvalue -> unit */ +CAMLprim value llvm_set_dll_storage_class(value Viz, LLVMValueRef Global) { + LLVMSetDLLStorageClass(Global, Int_val(Viz)); + return Val_unit; +} + /* llvalue -> int */ CAMLprim value llvm_alignment(LLVMValueRef Global) { return Val_int(LLVMGetAlignment(Global)); @@ -1151,10 +1218,10 @@ CAMLprim value llvm_gc(LLVMValueRef Fn) { const char *GC; CAMLparam0(); CAMLlocal2(Name, Option); - + if ((GC = LLVMGetGC(Fn))) { - Name = copy_string(GC); - + Name = caml_copy_string(GC); + Option = alloc(1, 0); Field(Option, 0) = Name; CAMLreturn(Option); @@ -1328,6 +1395,25 @@ CAMLprim value llvm_instr_icmp_predicate(LLVMValueRef Val) { CAMLreturn(Val_int(0)); } +/* llvalue -> FCmp.t option */ +CAMLprim value llvm_instr_fcmp_predicate(LLVMValueRef Val) { + CAMLparam0(); + int x = LLVMGetFCmpPredicate(Val); + if (x) { + value Option = alloc(1, 0); + Field(Option, 0) = Val_int(x - LLVMRealPredicateFalse); + CAMLreturn(Option); + } + CAMLreturn(Val_int(0)); +} + +/* llvalue -> llvalue */ +CAMLprim LLVMValueRef llvm_instr_clone(LLVMValueRef Inst) { + if (!LLVMIsAInstruction(Inst)) + failwith("Not an instruction"); + return LLVMInstructionClone(Inst); +} + /*--... Operations on call sites ...........................................--*/ @@ -1386,6 +1472,43 @@ CAMLprim value llvm_set_volatile(value IsVolatile, return Val_unit; } + +/*--.. Operations on terminators ...........................................--*/ + +/* llvalue -> int -> llbasicblock */ +CAMLprim LLVMBasicBlockRef llvm_successor(LLVMValueRef V, value I) { + return LLVMGetSuccessor(V, Int_val(I)); +} + +/* llvalue -> int -> llvalue -> unit */ +CAMLprim value llvm_set_successor(LLVMValueRef U, value I, LLVMBasicBlockRef B) { + LLVMSetSuccessor(U, Int_val(I), B); + return Val_unit; +} + +/* llvalue -> int */ +CAMLprim value llvm_num_successors(LLVMValueRef V) { + return Val_int(LLVMGetNumSuccessors(V)); +} + +/*--.. Operations on branch ................................................--*/ + +/* llvalue -> llvalue */ +CAMLprim LLVMValueRef llvm_condition(LLVMValueRef V) { + return LLVMGetCondition(V); +} + +/* llvalue -> llvalue -> unit */ +CAMLprim value llvm_set_condition(LLVMValueRef B, LLVMValueRef C) { + LLVMSetCondition(B, C); + return Val_unit; +} + +/* llvalue -> bool */ +CAMLprim value llvm_is_conditional(LLVMValueRef V) { + return Val_bool(LLVMIsConditional(V)); +} + /*--... Operations on phi nodes ............................................--*/ /* (llvalue * llbasicblock) -> llvalue -> unit */ @@ -1402,20 +1525,20 @@ CAMLprim value llvm_incoming(LLVMValueRef PhiNode) { unsigned I; CAMLparam0(); CAMLlocal3(Hd, Tl, Tmp); - + /* Build a tuple list of them. */ Tl = Val_int(0); for (I = LLVMCountIncoming(PhiNode); I != 0; ) { Hd = alloc(2, 0); Store_field(Hd, 0, (value) LLVMGetIncomingValue(PhiNode, --I)); Store_field(Hd, 1, (value) LLVMGetIncomingBlock(PhiNode, I)); - + Tmp = alloc(2, 0); Store_field(Tmp, 0, Hd); Store_field(Tmp, 1, Tl); Tl = Tmp; } - + CAMLreturn(Tl); } @@ -1434,15 +1557,13 @@ static void llvm_finalize_builder(value B) { } static struct custom_operations builder_ops = { - (char *) "LLVMIRBuilder", + (char *) "Llvm.llbuilder", llvm_finalize_builder, custom_compare_default, custom_hash_default, custom_serialize_default, - custom_deserialize_default -#ifdef custom_compare_ext_default - , custom_compare_ext_default -#endif + custom_deserialize_default, + custom_compare_ext_default }; static value alloc_builder(LLVMBuilderRef B) { @@ -1472,7 +1593,7 @@ CAMLprim value llvm_position_builder(value Pos, value B) { CAMLprim LLVMBasicBlockRef llvm_insertion_block(value B) { LLVMBasicBlockRef InsertBlock = LLVMGetInsertBlock(Builder_val(B)); if (!InsertBlock) - raise_not_found(); + caml_raise_not_found(); return InsertBlock; } @@ -2048,9 +2169,9 @@ CAMLprim LLVMValueRef llvm_build_fcmp(value Pred, CAMLprim LLVMValueRef llvm_build_phi(value Incoming, value Name, value B) { value Hd, Tl; LLVMValueRef FirstValue, PhiNode; - + assert(Incoming != Val_int(0) && "Empty list passed to Llvm.build_phi!"); - + Hd = Field(Incoming, 0); FirstValue = (LLVMValueRef) Field(Hd, 0); PhiNode = LLVMBuildPhi(Builder_val(B), LLVMTypeOf(FirstValue), @@ -2061,7 +2182,7 @@ CAMLprim LLVMValueRef llvm_build_phi(value Incoming, value Name, value B) { LLVMAddIncoming(PhiNode, (LLVMValueRef*) &Field(Hd, 0), (LLVMBasicBlockRef*) &Field(Hd, 1), 1); } - + return PhiNode; } @@ -2097,7 +2218,7 @@ CAMLprim LLVMValueRef llvm_build_insertelement(LLVMValueRef Vec, LLVMValueRef Element, LLVMValueRef Idx, value Name, value B) { - return LLVMBuildInsertElement(Builder_val(B), Vec, Element, Idx, + return LLVMBuildInsertElement(Builder_val(B), Vec, Element, Idx, String_val(Name)); } @@ -2149,11 +2270,11 @@ CAMLprim value llvm_memorybuffer_of_file(value Path) { CAMLparam1(Path); char *Message; LLVMMemoryBufferRef MemBuf; - + if (LLVMCreateMemoryBufferWithContentsOfFile(String_val(Path), &MemBuf, &Message)) - llvm_raise(llvm_ioerror_exn, Message); - + llvm_raise(*caml_named_value("Llvm.IoError"), Message); + CAMLreturn((value) MemBuf); } @@ -2162,22 +2283,23 @@ CAMLprim value llvm_memorybuffer_of_file(value Path) { CAMLprim LLVMMemoryBufferRef llvm_memorybuffer_of_stdin(value Unit) { char *Message; LLVMMemoryBufferRef MemBuf; - + if (LLVMCreateMemoryBufferWithSTDIN(&MemBuf, &Message)) - llvm_raise(llvm_ioerror_exn, Message); - + llvm_raise(*caml_named_value("Llvm.IoError"), Message); + return MemBuf; } /* ?name:string -> string -> llmemorybuffer */ CAMLprim LLVMMemoryBufferRef llvm_memorybuffer_of_string(value Name, value String) { + LLVMMemoryBufferRef MemBuf; const char *NameCStr; + if(Name == Val_int(0)) NameCStr = ""; else NameCStr = String_val(Field(Name, 0)); - LLVMMemoryBufferRef MemBuf; MemBuf = LLVMCreateMemoryBufferWithMemoryRangeCopy( String_val(String), caml_string_length(String), NameCStr); diff --git a/bindings/ocaml/target/llvm_target.ml b/bindings/ocaml/target/llvm_target.ml index 974bd49..bd7388e 100644 --- a/bindings/ocaml/target/llvm_target.ml +++ b/bindings/ocaml/target/llvm_target.ml @@ -47,8 +47,7 @@ end exception Error of string -external register_exns : exn -> unit = "llvm_register_target_exns" -let _ = register_exns (Error "") +let () = Callback.register_exception "Llvm_target.Error" (Error "") module DataLayout = struct type t @@ -127,6 +126,8 @@ module TargetMachine = struct = "llvm_targetmachine_features" external data_layout : t -> DataLayout.t = "llvm_targetmachine_data_layout" + external add_analysis_passes : [< Llvm.PassManager.any ] Llvm.PassManager.t -> t -> unit + = "llvm_targetmachine_add_analysis_passes" external set_verbose_asm : bool -> t -> unit = "llvm_targetmachine_set_verbose_asm" external emit_to_file : Llvm.llmodule -> CodeGenFileType.t -> string -> diff --git a/bindings/ocaml/target/llvm_target.mli b/bindings/ocaml/target/llvm_target.mli index 4f5e717..676bc61 100644 --- a/bindings/ocaml/target/llvm_target.mli +++ b/bindings/ocaml/target/llvm_target.mli @@ -67,7 +67,7 @@ module DataLayout : sig See the method [llvm::DataLayout::getStringRepresentation]. *) val as_string : t -> string - (** [add_to_pass_manager dl pm] adds the target data [dl] to + (** [add_to_pass_manager pm dl] adds the data layout [dl] to the pass manager [pm]. See the method [llvm::PassManagerBase::add]. *) val add_to_pass_manager : [<Llvm.PassManager.any] Llvm.PassManager.t -> @@ -207,6 +207,10 @@ module TargetMachine : sig (** Returns the data layout of this target machine. *) val data_layout : t -> DataLayout.t + (** Adds the target-specific analysis passes to the pass manager. + See [llvm::TargetMachine::addAnalysisPasses]. *) + val add_analysis_passes : [< Llvm.PassManager.any ] Llvm.PassManager.t -> t -> unit + (** Sets the assembly verbosity of this target machine. See [llvm::TargetMachine::setAsmVerbosity]. *) val set_verbose_asm : bool -> t -> unit diff --git a/bindings/ocaml/target/target_ocaml.c b/bindings/ocaml/target/target_ocaml.c index 74e8185..8f77cb4 100644 --- a/bindings/ocaml/target/target_ocaml.c +++ b/bindings/ocaml/target/target_ocaml.c @@ -21,37 +21,10 @@ #include "caml/fail.h" #include "caml/memory.h" #include "caml/custom.h" +#include "caml/callback.h" -/*===---- Exceptions ------------------------------------------------------===*/ - -static value llvm_target_error_exn; - -CAMLprim value llvm_register_target_exns(value Error) { - llvm_target_error_exn = Field(Error, 0); - register_global_root(&llvm_target_error_exn); - return Val_unit; -} - -static void llvm_raise(value Prototype, char *Message) { - CAMLparam1(Prototype); - CAMLlocal1(CamlMessage); - - CamlMessage = copy_string(Message); - LLVMDisposeMessage(Message); - - raise_with_arg(Prototype, CamlMessage); - abort(); /* NOTREACHED */ -#ifdef CAMLnoreturn - CAMLnoreturn; /* Silences warnings, but is missing in some versions. */ -#endif -} - -static value llvm_string_of_message(char* Message) { - value String = caml_copy_string(Message); - LLVMDisposeMessage(Message); - - return String; -} +void llvm_raise(value Prototype, char *Message); +value llvm_string_of_message(char* Message); /*===---- Data Layout -----------------------------------------------------===*/ @@ -62,15 +35,13 @@ static void llvm_finalize_data_layout(value DataLayout) { } static struct custom_operations llvm_data_layout_ops = { - (char *) "LLVMDataLayout", + (char *) "Llvm_target.DataLayout.t", llvm_finalize_data_layout, custom_compare_default, custom_hash_default, custom_serialize_default, - custom_deserialize_default -#ifdef custom_compare_ext_default - , custom_compare_ext_default -#endif + custom_deserialize_default, + custom_compare_ext_default }; value llvm_alloc_data_layout(LLVMTargetDataRef DataLayout) { @@ -219,7 +190,7 @@ CAMLprim LLVMTargetRef llvm_target_by_triple(value Triple) { char *Error; if(LLVMGetTargetFromTriple(String_val(Triple), &T, &Error)) - llvm_raise(llvm_target_error_exn, Error); + llvm_raise(*caml_named_value("Llvm_target.Error"), Error); return T; } @@ -258,15 +229,13 @@ static void llvm_finalize_target_machine(value Machine) { } static struct custom_operations llvm_target_machine_ops = { - (char *) "LLVMTargetMachine", + (char *) "Llvm_target.TargetMachine.t", llvm_finalize_target_machine, custom_compare_default, custom_hash_default, custom_serialize_default, - custom_deserialize_default -#ifdef custom_compare_ext_default - , custom_compare_ext_default -#endif + custom_deserialize_default, + custom_compare_ext_default }; static value llvm_alloc_targetmachine(LLVMTargetMachineRef Machine) { @@ -337,6 +306,7 @@ CAMLprim value llvm_targetmachine_features(value Machine) { CAMLprim value llvm_targetmachine_data_layout(value Machine) { CAMLparam1(Machine); CAMLlocal1(DataLayout); + char *TargetDataCStr; /* LLVMGetTargetMachineData returns a pointer owned by the TargetMachine, so it is impossible to wrap it with llvm_alloc_target_data, which assumes @@ -344,7 +314,6 @@ CAMLprim value llvm_targetmachine_data_layout(value Machine) { LLVMTargetDataRef OrigDataLayout; OrigDataLayout = LLVMGetTargetMachineData(TargetMachine_val(Machine)); - char* TargetDataCStr; TargetDataCStr = LLVMCopyStringRepOfTargetData(OrigDataLayout); DataLayout = llvm_alloc_data_layout(LLVMCreateTargetData(TargetDataCStr)); LLVMDisposeMessage(TargetDataCStr); @@ -361,12 +330,12 @@ CAMLprim value llvm_targetmachine_set_verbose_asm(value Verb, value Machine) { /* Llvm.llmodule -> CodeGenFileType.t -> string -> TargetMachine.t -> unit */ CAMLprim value llvm_targetmachine_emit_to_file(LLVMModuleRef Module, value FileType, value FileName, value Machine) { - char* ErrorMessage; + char *ErrorMessage; if(LLVMTargetMachineEmitToFile(TargetMachine_val(Machine), Module, String_val(FileName), Int_val(FileType), &ErrorMessage)) { - llvm_raise(llvm_target_error_exn, ErrorMessage); + llvm_raise(*caml_named_value("Llvm_target.Error"), ErrorMessage); } return Val_unit; @@ -377,14 +346,21 @@ CAMLprim value llvm_targetmachine_emit_to_file(LLVMModuleRef Module, CAMLprim LLVMMemoryBufferRef llvm_targetmachine_emit_to_memory_buffer( LLVMModuleRef Module, value FileType, value Machine) { - char* ErrorMessage; + char *ErrorMessage; LLVMMemoryBufferRef Buffer; if(LLVMTargetMachineEmitToMemoryBuffer(TargetMachine_val(Machine), Module, Int_val(FileType), &ErrorMessage, &Buffer)) { - llvm_raise(llvm_target_error_exn, ErrorMessage); + llvm_raise(*caml_named_value("Llvm_target.Error"), ErrorMessage); } return Buffer; } + +/* TargetMachine.t -> Llvm.PassManager.t -> unit */ +CAMLprim value llvm_targetmachine_add_analysis_passes(LLVMPassManagerRef PM, + value Machine) { + LLVMAddAnalysisPasses(TargetMachine_val(Machine), PM); + return Val_unit; +} diff --git a/bindings/ocaml/transforms/Makefile b/bindings/ocaml/transforms/Makefile index 92c8396..f3637a6 100644 --- a/bindings/ocaml/transforms/Makefile +++ b/bindings/ocaml/transforms/Makefile @@ -8,7 +8,7 @@ ##===----------------------------------------------------------------------===## LEVEL := ../../.. -DIRS = scalar ipo vectorize passmgr_builder +DIRS = scalar_opts ipo vectorize passmgr_builder ocamldoc: $(Verb) for i in $(DIRS) ; do \ diff --git a/bindings/ocaml/transforms/ipo/Makefile b/bindings/ocaml/transforms/ipo/Makefile index ed67a7c..f54bc4e 100644 --- a/bindings/ocaml/transforms/ipo/Makefile +++ b/bindings/ocaml/transforms/ipo/Makefile @@ -1,4 +1,4 @@ -##===- bindings/ocaml/transforms/scalar/Makefile -----------*- Makefile -*-===## +##===- bindings/ocaml/transforms/ipo/Makefile --------------*- Makefile -*-===## # # The LLVM Compiler Infrastructure # @@ -7,7 +7,7 @@ # ##===----------------------------------------------------------------------===## # -# This is the makefile for the Objective Caml Llvm_scalar_opts interface. +# This is the makefile for the Objective Caml Llvm_ipo interface. # ##===----------------------------------------------------------------------===## diff --git a/bindings/ocaml/transforms/ipo/ipo_ocaml.c b/bindings/ocaml/transforms/ipo/ipo_ocaml.c index 4ad8afb..9d8fb1e 100644 --- a/bindings/ocaml/transforms/ipo/ipo_ocaml.c +++ b/bindings/ocaml/transforms/ipo/ipo_ocaml.c @@ -56,12 +56,6 @@ CAMLprim value llvm_add_always_inliner(LLVMPassManagerRef PM) { } /* [`Module] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_always_inliner_pass(LLVMPassManagerRef PM) { - LLVMAddAlwaysInlinerPass(PM); - return Val_unit; -} - -/* [`Module] Llvm.PassManager.t -> unit */ CAMLprim value llvm_add_global_dce(LLVMPassManagerRef PM) { LLVMAddGlobalDCEPass(PM); return Val_unit; @@ -74,7 +68,7 @@ CAMLprim value llvm_add_global_optimizer(LLVMPassManagerRef PM) { } /* [`Module] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_ipc_propagation(LLVMPassManagerRef PM) { +CAMLprim value llvm_add_ip_constant_propagation(LLVMPassManagerRef PM) { LLVMAddIPConstantPropagationPass(PM); return Val_unit; } @@ -91,7 +85,7 @@ CAMLprim value llvm_add_ipsccp(LLVMPassManagerRef PM) { return Val_unit; } -/* [`Module] Llvm.PassManager.t -> bool -> unit */ +/* [`Module] Llvm.PassManager.t -> all_but_main:bool -> unit */ CAMLprim value llvm_add_internalize(LLVMPassManagerRef PM, value AllButMain) { LLVMAddInternalizePass(PM, Bool_val(AllButMain)); return Val_unit; diff --git a/bindings/ocaml/transforms/ipo/llvm_ipo.ml b/bindings/ocaml/transforms/ipo/llvm_ipo.ml index 93f564a..1af7d67 100644 --- a/bindings/ocaml/transforms/ipo/llvm_ipo.ml +++ b/bindings/ocaml/transforms/ipo/llvm_ipo.ml @@ -7,31 +7,45 @@ * *===----------------------------------------------------------------------===*) -external add_argument_promotion : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_argument_promotion" -external add_constant_merge : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_constant_merge" -external add_dead_arg_elimination : - [ | `Module ] Llvm.PassManager.t -> unit = "llvm_add_dead_arg_elimination" -external add_function_attrs : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_function_attrs" -external add_function_inlining : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_function_inlining" -external add_always_inliner : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_always_inliner" -external add_global_dce : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_global_dce" -external add_global_optimizer : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_global_optimizer" -external add_ipc_propagation : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_ipc_propagation" -external add_prune_eh : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_prune_eh" -external add_ipsccp : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_ipsccp" -external add_internalize : [ | `Module ] Llvm.PassManager.t -> bool -> unit = - "llvm_add_internalize" -external add_strip_dead_prototypes : - [ | `Module ] Llvm.PassManager.t -> unit = "llvm_add_strip_dead_prototypes" -external add_strip_symbols : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_strip_symbols" +external add_argument_promotion + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_argument_promotion" +external add_constant_merge + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_constant_merge" +external add_dead_arg_elimination + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_dead_arg_elimination" +external add_function_attrs + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_function_attrs" +external add_function_inlining + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_function_inlining" +external add_always_inliner + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_always_inliner" +external add_global_dce + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_global_dce" +external add_global_optimizer + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_global_optimizer" +external add_ipc_propagation + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_ip_constant_propagation" +external add_prune_eh + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_prune_eh" +external add_ipsccp + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_ipsccp" +external add_internalize + : [ `Module ] Llvm.PassManager.t -> all_but_main:bool -> unit + = "llvm_add_internalize" +external add_strip_dead_prototypes + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_strip_dead_prototypes" +external add_strip_symbols + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_strip_symbols" diff --git a/bindings/ocaml/transforms/ipo/llvm_ipo.mli b/bindings/ocaml/transforms/ipo/llvm_ipo.mli index 1944c30..09a4860 100644 --- a/bindings/ocaml/transforms/ipo/llvm_ipo.mli +++ b/bindings/ocaml/transforms/ipo/llvm_ipo.mli @@ -12,58 +12,72 @@ This interface provides an OCaml API for LLVM interprocedural optimizations, the classes in the [LLVMIPO] library. *) -(** See llvm::createAddArgumentPromotionPass *) -external add_argument_promotion : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_argument_promotion" - -(** See llvm::createConstantMergePass function. *) -external add_constant_merge : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_constant_merge" - -(** See llvm::createDeadArgEliminationPass function. *) -external add_dead_arg_elimination : - [ | `Module ] Llvm.PassManager.t -> unit = "llvm_add_dead_arg_elimination" - -(** See llvm::createFunctionAttrsPass function. *) -external add_function_attrs : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_function_attrs" - -(** See llvm::createFunctionInliningPass function. *) -external add_function_inlining : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_function_inlining" - -(** See llvm::createAlwaysInlinerPass function. *) -external add_always_inliner : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_always_inliner" - -(** See llvm::createGlobalDCEPass function. *) -external add_global_dce : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_global_dce" - -(** See llvm::createGlobalOptimizerPass function. *) -external add_global_optimizer : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_global_optimizer" - -(** See llvm::createIPConstantPropagationPass function. *) -external add_ipc_propagation : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_ipc_propagation" - -(** See llvm::createPruneEHPass function. *) -external add_prune_eh : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_prune_eh" - -(** See llvm::createIPSCCPPass function. *) -external add_ipsccp : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_ipsccp" - -(** See llvm::createInternalizePass function. *) -external add_internalize : [ | `Module ] Llvm.PassManager.t -> bool -> unit = - "llvm_add_internalize" - -(** See llvm::createStripDeadPrototypesPass function. *) -external add_strip_dead_prototypes : - [ | `Module ] Llvm.PassManager.t -> unit = "llvm_add_strip_dead_prototypes" - -(** See llvm::createStripSymbolsPass function. *) -external add_strip_symbols : [ | `Module ] Llvm.PassManager.t -> unit = - "llvm_add_strip_symbols" +(** See the [llvm::createAddArgumentPromotionPass] function. *) +external add_argument_promotion + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_argument_promotion" + +(** See the [llvm::createConstantMergePass] function. *) +external add_constant_merge + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_constant_merge" + +(** See the [llvm::createDeadArgEliminationPass] function. *) +external add_dead_arg_elimination + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_dead_arg_elimination" + +(** See the [llvm::createFunctionAttrsPass] function. *) +external add_function_attrs + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_function_attrs" + +(** See the [llvm::createFunctionInliningPass] function. *) +external add_function_inlining + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_function_inlining" + +(** See the [llvm::createAlwaysInlinerPass] function. *) +external add_always_inliner + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_always_inliner" + +(** See the [llvm::createGlobalDCEPass] function. *) +external add_global_dce + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_global_dce" + +(** See the [llvm::createGlobalOptimizerPass] function. *) +external add_global_optimizer + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_global_optimizer" + +(** See the [llvm::createIPConstantPropagationPass] function. *) +external add_ipc_propagation + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_ip_constant_propagation" + +(** See the [llvm::createPruneEHPass] function. *) +external add_prune_eh + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_prune_eh" + +(** See the [llvm::createIPSCCPPass] function. *) +external add_ipsccp + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_ipsccp" + +(** See the [llvm::createInternalizePass] function. *) +external add_internalize + : [ `Module ] Llvm.PassManager.t -> all_but_main:bool -> unit + = "llvm_add_internalize" + +(** See the [llvm::createStripDeadPrototypesPass] function. *) +external add_strip_dead_prototypes + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_strip_dead_prototypes" + +(** See the [llvm::createStripSymbolsPass] function. *) +external add_strip_symbols + : [ `Module ] Llvm.PassManager.t -> unit + = "llvm_add_strip_symbols" diff --git a/bindings/ocaml/transforms/passmgr_builder/llvm_passmgr_builder.mli b/bindings/ocaml/transforms/passmgr_builder/llvm_passmgr_builder.mli index 66b0981..ce162b1 100644 --- a/bindings/ocaml/transforms/passmgr_builder/llvm_passmgr_builder.mli +++ b/bindings/ocaml/transforms/passmgr_builder/llvm_passmgr_builder.mli @@ -14,41 +14,41 @@ type t -(** See [llvm::PassManagerBuilder]. *) +(** See the [llvm::PassManagerBuilder] function. *) external create : unit -> t = "llvm_pmbuilder_create" -(** See [llvm::PassManagerBuilder::OptLevel]. *) +(** See the [llvm::PassManagerBuilder::OptLevel] function. *) external set_opt_level : int -> t -> unit = "llvm_pmbuilder_set_opt_level" -(** See [llvm::PassManagerBuilder::SizeLevel]. *) +(** See the [llvm::PassManagerBuilder::SizeLevel] function. *) external set_size_level : int -> t -> unit = "llvm_pmbuilder_set_size_level" -(** See [llvm::PassManagerBuilder::DisableUnitAtATime]. *) +(** See the [llvm::PassManagerBuilder::DisableUnitAtATime] function. *) external set_disable_unit_at_a_time : bool -> t -> unit = "llvm_pmbuilder_set_disable_unit_at_a_time" -(** See [llvm::PassManagerBuilder::DisableUnrollLoops]. *) +(** See the [llvm::PassManagerBuilder::DisableUnrollLoops] function. *) external set_disable_unroll_loops : bool -> t -> unit = "llvm_pmbuilder_set_disable_unroll_loops" -(** See [llvm::PassManagerBuilder::Inliner]. *) +(** See the [llvm::PassManagerBuilder::Inliner] function. *) external use_inliner_with_threshold : int -> t -> unit = "llvm_pmbuilder_use_inliner_with_threshold" -(** See [llvm::PassManagerBuilder::populateFunctionPassManager]. *) +(** See the [llvm::PassManagerBuilder::populateFunctionPassManager] function. *) external populate_function_pass_manager : [ `Function ] Llvm.PassManager.t -> t -> unit = "llvm_pmbuilder_populate_function_pass_manager" -(** See [llvm::PassManagerBuilder::populateModulePassManager]. *) +(** See the [llvm::PassManagerBuilder::populateModulePassManager] function. *) external populate_module_pass_manager : [ `Module ] Llvm.PassManager.t -> t -> unit = "llvm_pmbuilder_populate_module_pass_manager" -(** See [llvm::PassManagerBuilder::populateLTOPassManager]. *) +(** See the [llvm::PassManagerBuilder::populateLTOPassManager] function. *) external populate_lto_pass_manager : [ `Module ] Llvm.PassManager.t -> internalize:bool -> run_inliner:bool -> t -> unit - = "llvm_pmbuilder_populate_lto_pass_manager"
\ No newline at end of file + = "llvm_pmbuilder_populate_lto_pass_manager" diff --git a/bindings/ocaml/transforms/passmgr_builder/passmgr_builder_ocaml.c b/bindings/ocaml/transforms/passmgr_builder/passmgr_builder_ocaml.c index a707856..a43863c 100644 --- a/bindings/ocaml/transforms/passmgr_builder/passmgr_builder_ocaml.c +++ b/bindings/ocaml/transforms/passmgr_builder/passmgr_builder_ocaml.c @@ -27,15 +27,13 @@ static void llvm_finalize_pmbuilder(value PMB) { } static struct custom_operations pmbuilder_ops = { - (char *) "LLVMPassManagerBuilder", + (char *) "Llvm_passmgr_builder.t", llvm_finalize_pmbuilder, custom_compare_default, custom_hash_default, custom_serialize_default, - custom_deserialize_default -#ifdef custom_compare_ext_default - , custom_compare_ext_default -#endif + custom_deserialize_default, + custom_compare_ext_default }; static value alloc_pmbuilder(LLVMPassManagerBuilderRef Ref) { diff --git a/bindings/ocaml/transforms/scalar/llvm_scalar_opts.ml b/bindings/ocaml/transforms/scalar/llvm_scalar_opts.ml deleted file mode 100644 index 958939d..0000000 --- a/bindings/ocaml/transforms/scalar/llvm_scalar_opts.ml +++ /dev/null @@ -1,114 +0,0 @@ -(*===-- llvm_scalar_opts.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 add_constant_propagation : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_constant_propagation" -external add_sccp : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_sccp" -external add_dead_store_elimination : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_dead_store_elimination" -external add_aggressive_dce : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_aggressive_dce" -external -add_scalar_repl_aggregation : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_scalar_repl_aggregation" - -external -add_scalar_repl_aggregation_ssa : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_scalar_repl_aggregation_ssa" - -external -add_scalar_repl_aggregation_with_threshold : int -> [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_scalar_repl_aggregation_with_threshold" -external add_ind_var_simplification : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_ind_var_simplification" -external -add_instruction_combination : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_instruction_combination" -external add_licm : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_licm" -external add_loop_unswitch : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_loop_unswitch" -external add_loop_unroll : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_loop_unroll" -external add_loop_rotation : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_loop_rotation" -external -add_memory_to_register_promotion : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_memory_to_register_promotion" -external -add_memory_to_register_demotion : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_memory_to_register_demotion" -external add_reassociation : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_reassociation" -external add_jump_threading : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_jump_threading" -external add_cfg_simplification : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_cfg_simplification" -external -add_tail_call_elimination : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_tail_call_elimination" -external add_gvn : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_gvn" -external add_memcpy_opt : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_memcpy_opt" -external add_loop_deletion : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_loop_deletion" - -external add_loop_idiom : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_loop_idiom" - -external -add_lib_call_simplification : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_lib_call_simplification" - -external -add_verifier : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_verifier" - -external -add_correlated_value_propagation : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_correlated_value_propagation" - -external -add_early_cse : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_early_cse" - -external -add_lower_expect_intrinsic : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_lower_expect_intrinsic" - -external -add_type_based_alias_analysis : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_type_based_alias_analysis" - -external -add_basic_alias_analysis : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_basic_alias_analysis" - -external -add_partially_inline_lib_calls : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_partially_inline_lib_calls" diff --git a/bindings/ocaml/transforms/scalar/llvm_scalar_opts.mli b/bindings/ocaml/transforms/scalar/llvm_scalar_opts.mli deleted file mode 100644 index ab6fa4a..0000000 --- a/bindings/ocaml/transforms/scalar/llvm_scalar_opts.mli +++ /dev/null @@ -1,168 +0,0 @@ -(*===-- llvm_scalar_opts.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. - * - *===----------------------------------------------------------------------===*) - -(** Scalar Transforms. - - This interface provides an OCaml API for LLVM scalar transforms, the - classes in the [LLVMScalarOpts] library. *) - -(** See the [llvm::createConstantPropagationPass] function. *) -external add_constant_propagation : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_constant_propagation" - -(** See the [llvm::createSCCPPass] function. *) -external add_sccp : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_sccp" - -(** See [llvm::createDeadStoreEliminationPass] function. *) -external add_dead_store_elimination : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_dead_store_elimination" - -(** See The [llvm::createAggressiveDCEPass] function. *) -external add_aggressive_dce : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_aggressive_dce" - -(** See the [llvm::createScalarReplAggregatesPass] function. *) -external -add_scalar_repl_aggregation : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_scalar_repl_aggregation" - -(** See the [llvm::createScalarReplAggregatesPassSSA] function. *) -external -add_scalar_repl_aggregation_ssa : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_scalar_repl_aggregation_ssa" - -(** See the [llvm::createScalarReplAggregatesWithThreshold] function. *) -external -add_scalar_repl_aggregation_with_threshold : int -> [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_scalar_repl_aggregation_with_threshold" - -(** See the [llvm::createIndVarSimplifyPass] function. *) -external add_ind_var_simplification : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_ind_var_simplification" - -(** See the [llvm::createInstructionCombiningPass] function. *) -external -add_instruction_combination : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_instruction_combination" - -(** See the [llvm::createLICMPass] function. *) -external add_licm : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_licm" - -(** See the [llvm::createLoopUnswitchPass] function. *) -external add_loop_unswitch : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_loop_unswitch" - -(** See the [llvm::createLoopUnrollPass] function. *) -external add_loop_unroll : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_loop_unroll" - -(** See the [llvm::createLoopRotatePass] function. *) -external add_loop_rotation : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_loop_rotation" - -(** See the [llvm::createPromoteMemoryToRegisterPass] function. *) -external -add_memory_to_register_promotion : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_memory_to_register_promotion" - -(** See the [llvm::createDemoteMemoryToRegisterPass] function. *) -external -add_memory_to_register_demotion : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_memory_to_register_demotion" - -(** See the [llvm::createReassociatePass] function. *) -external add_reassociation : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_reassociation" - -(** See the [llvm::createJumpThreadingPass] function. *) -external add_jump_threading : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_jump_threading" - -(** See the [llvm::createCFGSimplificationPass] function. *) -external add_cfg_simplification : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_cfg_simplification" - -(** See the [llvm::createTailCallEliminationPass] function. *) -external -add_tail_call_elimination : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_tail_call_elimination" - -(** See the [llvm::createGVNPass] function. *) -external add_gvn : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_gvn" - -(** See the [llvm::createMemCpyOptPass] function. *) -external add_memcpy_opt : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_memcpy_opt" - -(** See the [llvm::createLoopDeletionPass] function. *) -external add_loop_deletion : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_loop_deletion" - -external add_loop_idiom : [<Llvm.PassManager.any] Llvm.PassManager.t - -> unit - = "llvm_add_loop_idiom" - -(** See the [llvm::createSimplifyLibCallsPass] function. *) -external -add_lib_call_simplification : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_lib_call_simplification" - -(** See the [llvm::createVerifierPass] function. *) -external -add_verifier : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_verifier" - -(** See the [llvm::createCorrelatedValuePropagationPass] function. *) -external -add_correlated_value_propagation : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_correlated_value_propagation" - -(** See the [llvm::createEarlyCSE] function. *) -external -add_early_cse : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_early_cse" - -(** See the [llvm::createLowerExpectIntrinsicPass] function. *) -external -add_lower_expect_intrinsic : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_lower_expect_intrinsic" - -(** See the [llvm::createTypeBasedAliasAnalysisPass] function. *) -external -add_type_based_alias_analysis : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_type_based_alias_analysis" - -(** See the [llvm::createBasicAliasAnalysisPass] function. *) -external -add_basic_alias_analysis : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_basic_alias_analysis" - -(** See the [llvm::createPartiallyInlineLibCallsPass] function. *) -external -add_partially_inline_lib_calls : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_partially_inline_lib_calls" diff --git a/bindings/ocaml/transforms/scalar/Makefile b/bindings/ocaml/transforms/scalar_opts/Makefile index 6e250f6..63d86a6 100644 --- a/bindings/ocaml/transforms/scalar/Makefile +++ b/bindings/ocaml/transforms/scalar_opts/Makefile @@ -1,4 +1,4 @@ -##===- bindings/ocaml/transforms/scalar/Makefile -----------*- Makefile -*-===## +##===- bindings/ocaml/transforms/scalar_opts/Makefile ------*- Makefile -*-===## # # The LLVM Compiler Infrastructure # diff --git a/bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.ml b/bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.ml new file mode 100644 index 0000000..b90d0ae --- /dev/null +++ b/bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.ml @@ -0,0 +1,120 @@ +(*===-- llvm_scalar_opts.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 add_aggressive_dce + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_aggressive_dce" +external add_alignment_from_assumptions + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_alignment_from_assumptions" +external add_cfg_simplification + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_cfg_simplification" +external add_dead_store_elimination + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_dead_store_elimination" +external add_scalarizer + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_scalarizer" +external add_merged_load_store_motion + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_merged_load_store_motion" +external add_gvn + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_gvn" +external add_ind_var_simplification + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_ind_var_simplify" +external add_instruction_combination + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_instruction_combining" +external add_jump_threading + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_jump_threading" +external add_licm + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_licm" +external add_loop_deletion + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_loop_deletion" +external add_loop_idiom + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_loop_idiom" +external add_loop_rotation + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_loop_rotate" +external add_loop_reroll + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_loop_reroll" +external add_loop_unroll + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_loop_unroll" +external add_loop_unswitch + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_loop_unswitch" +external add_memcpy_opt + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_memcpy_opt" +external add_partially_inline_lib_calls + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_partially_inline_lib_calls" +external add_lower_switch + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_lower_switch" +external add_memory_to_register_promotion + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_promote_memory_to_register" +external add_reassociation + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_reassociation" +external add_sccp + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_sccp" +external add_scalar_repl_aggregation + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_scalar_repl_aggregates" +external add_scalar_repl_aggregation_ssa + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_scalar_repl_aggregates_ssa" +external add_scalar_repl_aggregation_with_threshold + : int -> [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_scalar_repl_aggregates_with_threshold" +external add_lib_call_simplification + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_simplify_lib_calls" +external add_tail_call_elimination + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_tail_call_elimination" +external add_constant_propagation + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_constant_propagation" +external add_memory_to_register_demotion + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_demote_memory_to_register" +external add_verifier + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_verifier" +external add_correlated_value_propagation + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_correlated_value_propagation" +external add_early_cse + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_early_cse" +external add_lower_expect_intrinsic + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_lower_expect_intrinsic" +external add_type_based_alias_analysis + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_type_based_alias_analysis" +external add_scoped_no_alias_alias_analysis + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_scoped_no_alias_aa" +external add_basic_alias_analysis + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_basic_alias_analysis" diff --git a/bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.mli b/bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.mli new file mode 100644 index 0000000..b4cefed --- /dev/null +++ b/bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.mli @@ -0,0 +1,198 @@ +(*===-- llvm_scalar_opts.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. + * + *===----------------------------------------------------------------------===*) + +(** Scalar Transforms. + + This interface provides an OCaml API for LLVM scalar transforms, the + classes in the [LLVMScalarOpts] library. *) + +(** See the [llvm::createAggressiveDCEPass] function. *) +external add_aggressive_dce + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_aggressive_dce" + +(** See the [llvm::createAlignmentFromAssumptionsPass] function. *) +external add_alignment_from_assumptions + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_alignment_from_assumptions" + +(** See the [llvm::createCFGSimplificationPass] function. *) +external add_cfg_simplification + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_cfg_simplification" + +(** See [llvm::createDeadStoreEliminationPass] function. *) +external add_dead_store_elimination + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_dead_store_elimination" + +(** See [llvm::createScalarizerPass] function. *) +external add_scalarizer + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_scalarizer" + +(** See [llvm::createMergedLoadStoreMotionPass] function. *) +external add_merged_load_store_motion + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_merged_load_store_motion" + +(** See the [llvm::createGVNPass] function. *) +external add_gvn + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_gvn" + +(** See the [llvm::createIndVarSimplifyPass] function. *) +external add_ind_var_simplification + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_ind_var_simplify" + +(** See the [llvm::createInstructionCombiningPass] function. *) +external add_instruction_combination + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_instruction_combining" + +(** See the [llvm::createJumpThreadingPass] function. *) +external add_jump_threading + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_jump_threading" + +(** See the [llvm::createLICMPass] function. *) +external add_licm + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_licm" + +(** See the [llvm::createLoopDeletionPass] function. *) +external add_loop_deletion + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_loop_deletion" + +(** See the [llvm::createLoopIdiomPass] function. *) +external add_loop_idiom + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_loop_idiom" + +(** See the [llvm::createLoopRotatePass] function. *) +external add_loop_rotation + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_loop_rotate" + +(** See the [llvm::createLoopRerollPass] function. *) +external add_loop_reroll + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_loop_reroll" + +(** See the [llvm::createLoopUnrollPass] function. *) +external add_loop_unroll + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_loop_unroll" + +(** See the [llvm::createLoopUnswitchPass] function. *) +external add_loop_unswitch + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_loop_unswitch" + +(** See the [llvm::createMemCpyOptPass] function. *) +external add_memcpy_opt + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_memcpy_opt" + +(** See the [llvm::createPartiallyInlineLibCallsPass] function. *) +external add_partially_inline_lib_calls + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_partially_inline_lib_calls" + +(** See the [llvm::createLowerSwitchPass] function. *) +external add_lower_switch + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_lower_switch" + +(** See the [llvm::createPromoteMemoryToRegisterPass] function. *) +external add_memory_to_register_promotion + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_promote_memory_to_register" + +(** See the [llvm::createReassociatePass] function. *) +external add_reassociation + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_reassociation" + +(** See the [llvm::createSCCPPass] function. *) +external add_sccp + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_sccp" + +(** See the [llvm::createScalarReplAggregatesPass] function. *) +external add_scalar_repl_aggregation + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_scalar_repl_aggregates" + +(** See the [llvm::createScalarReplAggregatesPassSSA] function. *) +external add_scalar_repl_aggregation_ssa + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_scalar_repl_aggregates_ssa" + +(** See the [llvm::createScalarReplAggregatesWithThreshold] function. *) +external add_scalar_repl_aggregation_with_threshold + : int -> [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_scalar_repl_aggregates_with_threshold" + +(** See the [llvm::createSimplifyLibCallsPass] function. *) +external add_lib_call_simplification + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_simplify_lib_calls" + +(** See the [llvm::createTailCallEliminationPass] function. *) +external add_tail_call_elimination + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_tail_call_elimination" + +(** See the [llvm::createConstantPropagationPass] function. *) +external add_constant_propagation + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_constant_propagation" + +(** See the [llvm::createDemoteMemoryToRegisterPass] function. *) +external add_memory_to_register_demotion + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_demote_memory_to_register" + +(** See the [llvm::createVerifierPass] function. *) +external add_verifier + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_verifier" + +(** See the [llvm::createCorrelatedValuePropagationPass] function. *) +external add_correlated_value_propagation + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_correlated_value_propagation" + +(** See the [llvm::createEarlyCSE] function. *) +external add_early_cse + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_early_cse" + +(** See the [llvm::createLowerExpectIntrinsicPass] function. *) +external add_lower_expect_intrinsic + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_lower_expect_intrinsic" + +(** See the [llvm::createTypeBasedAliasAnalysisPass] function. *) +external add_type_based_alias_analysis + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_type_based_alias_analysis" + +(** See the [llvm::createScopedNoAliasAAPass] function. *) +external add_scoped_no_alias_alias_analysis + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_scoped_no_alias_aa" + +(** See the [llvm::createBasicAliasAnalysisPass] function. *) +external add_basic_alias_analysis + : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit + = "llvm_add_basic_alias_analysis" diff --git a/bindings/ocaml/transforms/scalar/scalar_opts_ocaml.c b/bindings/ocaml/transforms/scalar_opts/scalar_opts_ocaml.c index 0a71bd7..bae4e31 100644 --- a/bindings/ocaml/transforms/scalar/scalar_opts_ocaml.c +++ b/bindings/ocaml/transforms/scalar_opts/scalar_opts_ocaml.c @@ -20,69 +20,92 @@ #include "caml/misc.h" /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_constant_propagation(LLVMPassManagerRef PM) { - LLVMAddConstantPropagationPass(PM); +CAMLprim value llvm_add_aggressive_dce(LLVMPassManagerRef PM) { + LLVMAddAggressiveDCEPass(PM); return Val_unit; } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_sccp(LLVMPassManagerRef PM) { - LLVMAddSCCPPass(PM); +CAMLprim value llvm_add_alignment_from_assumptions(LLVMPassManagerRef PM) { + LLVMAddAlignmentFromAssumptionsPass(PM); return Val_unit; } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_dead_store_elimination(LLVMPassManagerRef PM) { - LLVMAddDeadStoreEliminationPass(PM); +CAMLprim value llvm_add_cfg_simplification(LLVMPassManagerRef PM) { + LLVMAddCFGSimplificationPass(PM); return Val_unit; } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_aggressive_dce(LLVMPassManagerRef PM) { - LLVMAddAggressiveDCEPass(PM); +CAMLprim value llvm_add_dead_store_elimination(LLVMPassManagerRef PM) { + LLVMAddDeadStoreEliminationPass(PM); return Val_unit; } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_scalar_repl_aggregation(LLVMPassManagerRef PM) { - LLVMAddScalarReplAggregatesPass(PM); +CAMLprim value llvm_add_scalarizer(LLVMPassManagerRef PM) { + LLVMAddScalarizerPass(PM); return Val_unit; } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_scalar_repl_aggregation_ssa(LLVMPassManagerRef PM) { - LLVMAddScalarReplAggregatesPassSSA(PM); +CAMLprim value llvm_add_merged_load_store_motion(LLVMPassManagerRef PM) { + LLVMAddMergedLoadStoreMotionPass(PM); return Val_unit; } -/* [<Llvm.PassManager.any] Llvm.PassManager.t -> int -> unit */ -CAMLprim value llvm_add_scalar_repl_aggregation_with_threshold(value threshold, - LLVMPassManagerRef PM) { - LLVMAddScalarReplAggregatesPassWithThreshold(PM, Int_val(threshold)); +/* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ +CAMLprim value llvm_add_gvn(LLVMPassManagerRef PM) { + LLVMAddGVNPass(PM); return Val_unit; } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_ind_var_simplification(LLVMPassManagerRef PM) { +CAMLprim value llvm_add_ind_var_simplify(LLVMPassManagerRef PM) { LLVMAddIndVarSimplifyPass(PM); return Val_unit; } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_instruction_combination(LLVMPassManagerRef PM) { +CAMLprim value llvm_add_instruction_combining(LLVMPassManagerRef PM) { LLVMAddInstructionCombiningPass(PM); return Val_unit; } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ +CAMLprim value llvm_add_jump_threading(LLVMPassManagerRef PM) { + LLVMAddJumpThreadingPass(PM); + return Val_unit; +} + +/* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ CAMLprim value llvm_add_licm(LLVMPassManagerRef PM) { LLVMAddLICMPass(PM); return Val_unit; } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_loop_unswitch(LLVMPassManagerRef PM) { - LLVMAddLoopUnswitchPass(PM); +CAMLprim value llvm_add_loop_deletion(LLVMPassManagerRef PM) { + LLVMAddLoopDeletionPass(PM); + return Val_unit; +} + +/* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ +CAMLprim value llvm_add_loop_idiom(LLVMPassManagerRef PM) { + LLVMAddLoopIdiomPass(PM); + return Val_unit; +} + +/* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ +CAMLprim value llvm_add_loop_rotate(LLVMPassManagerRef PM) { + LLVMAddLoopRotatePass(PM); + return Val_unit; +} + +/* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ +CAMLprim value llvm_add_loop_reroll(LLVMPassManagerRef PM) { + LLVMAddLoopRerollPass(PM); return Val_unit; } @@ -93,20 +116,32 @@ CAMLprim value llvm_add_loop_unroll(LLVMPassManagerRef PM) { } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_loop_rotation(LLVMPassManagerRef PM) { - LLVMAddLoopRotatePass(PM); +CAMLprim value llvm_add_loop_unswitch(LLVMPassManagerRef PM) { + LLVMAddLoopUnswitchPass(PM); return Val_unit; } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_memory_to_register_promotion(LLVMPassManagerRef PM) { - LLVMAddPromoteMemoryToRegisterPass(PM); +CAMLprim value llvm_add_memcpy_opt(LLVMPassManagerRef PM) { + LLVMAddMemCpyOptPass(PM); return Val_unit; } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_memory_to_register_demotion(LLVMPassManagerRef PM) { - LLVMAddDemoteMemoryToRegisterPass(PM); +CAMLprim value llvm_add_partially_inline_lib_calls(LLVMPassManagerRef PM) { + LLVMAddPartiallyInlineLibCallsPass(PM); + return Val_unit; +} + +/* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ +CAMLprim value llvm_add_lower_switch(LLVMPassManagerRef PM) { + LLVMAddLowerSwitchPass(PM); + return Val_unit; +} + +/* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ +CAMLprim value llvm_add_promote_memory_to_register(LLVMPassManagerRef PM) { + LLVMAddPromoteMemoryToRegisterPass(PM); return Val_unit; } @@ -117,50 +152,51 @@ CAMLprim value llvm_add_reassociation(LLVMPassManagerRef PM) { } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_jump_threading(LLVMPassManagerRef PM) { - LLVMAddJumpThreadingPass(PM); +CAMLprim value llvm_add_sccp(LLVMPassManagerRef PM) { + LLVMAddSCCPPass(PM); return Val_unit; } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_cfg_simplification(LLVMPassManagerRef PM) { - LLVMAddCFGSimplificationPass(PM); +CAMLprim value llvm_add_scalar_repl_aggregates(LLVMPassManagerRef PM) { + LLVMAddScalarReplAggregatesPass(PM); return Val_unit; } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_tail_call_elimination(LLVMPassManagerRef PM) { - LLVMAddTailCallEliminationPass(PM); +CAMLprim value llvm_add_scalar_repl_aggregates_ssa(LLVMPassManagerRef PM) { + LLVMAddScalarReplAggregatesPassSSA(PM); return Val_unit; } -/* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_gvn(LLVMPassManagerRef PM) { - LLVMAddGVNPass(PM); +/* int -> [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ +CAMLprim value llvm_add_scalar_repl_aggregates_with_threshold(value threshold, + LLVMPassManagerRef PM) { + LLVMAddScalarReplAggregatesPassWithThreshold(PM, Int_val(threshold)); return Val_unit; } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_memcpy_opt(LLVMPassManagerRef PM) { - LLVMAddMemCpyOptPass(PM); +CAMLprim value llvm_add_simplify_lib_calls(LLVMPassManagerRef PM) { + LLVMAddSimplifyLibCallsPass(PM); return Val_unit; } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_loop_deletion(LLVMPassManagerRef PM) { - LLVMAddLoopDeletionPass(PM); +CAMLprim value llvm_add_tail_call_elimination(LLVMPassManagerRef PM) { + LLVMAddTailCallEliminationPass(PM); return Val_unit; } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_loop_idiom(LLVMPassManagerRef PM) { - LLVMAddLoopIdiomPass(PM); +CAMLprim value llvm_add_constant_propagation(LLVMPassManagerRef PM) { + LLVMAddConstantPropagationPass(PM); return Val_unit; } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_lib_call_simplification(LLVMPassManagerRef PM) { - LLVMAddSimplifyLibCallsPass(PM); +CAMLprim value llvm_add_demote_memory_to_register(LLVMPassManagerRef PM) { + LLVMAddDemoteMemoryToRegisterPass(PM); return Val_unit; } @@ -195,13 +231,13 @@ CAMLprim value llvm_add_type_based_alias_analysis(LLVMPassManagerRef PM) { } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_basic_alias_analysis(LLVMPassManagerRef PM) { - LLVMAddBasicAliasAnalysisPass(PM); +CAMLprim value llvm_add_scoped_no_alias_aa(LLVMPassManagerRef PM) { + LLVMAddScopedNoAliasAAPass(PM); return Val_unit; } /* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */ -CAMLprim value llvm_add_partially_inline_lib_calls(LLVMPassManagerRef PM) { - LLVMAddPartiallyInlineLibCallsPass(PM); +CAMLprim value llvm_add_basic_alias_analysis(LLVMPassManagerRef PM) { + LLVMAddBasicAliasAnalysisPass(PM); return Val_unit; } diff --git a/bindings/ocaml/transforms/vectorize/Makefile b/bindings/ocaml/transforms/vectorize/Makefile index 5a854d1..64ac5c3 100644 --- a/bindings/ocaml/transforms/vectorize/Makefile +++ b/bindings/ocaml/transforms/vectorize/Makefile @@ -7,7 +7,7 @@ # ##===----------------------------------------------------------------------===## # -# This is the makefile for the Objective Caml Llvm_vectorize_opts interface. +# This is the makefile for the Objective Caml Llvm_vectorize interface. # ##===----------------------------------------------------------------------===## diff --git a/bindings/ocaml/transforms/vectorize/llvm_vectorize.ml b/bindings/ocaml/transforms/vectorize/llvm_vectorize.ml index 4fc53c6..88831da 100644 --- a/bindings/ocaml/transforms/vectorize/llvm_vectorize.ml +++ b/bindings/ocaml/transforms/vectorize/llvm_vectorize.ml @@ -7,9 +7,12 @@ * *===----------------------------------------------------------------------===*) -external add_bb_vectorize : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_bb_vectorize" -external add_loop_vectorize : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_loop_vectorize" -external add_slp_vectorize : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_slp_vectorize" +external add_bb_vectorize + : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit + = "llvm_add_bb_vectorize" +external add_loop_vectorize + : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit + = "llvm_add_loop_vectorize" +external add_slp_vectorize + : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit + = "llvm_add_slp_vectorize" diff --git a/bindings/ocaml/transforms/vectorize/llvm_vectorize.mli b/bindings/ocaml/transforms/vectorize/llvm_vectorize.mli index 0253039..23a68a2 100644 --- a/bindings/ocaml/transforms/vectorize/llvm_vectorize.mli +++ b/bindings/ocaml/transforms/vectorize/llvm_vectorize.mli @@ -13,13 +13,16 @@ classes in the [LLVMVectorize] library. *) (** See the [llvm::createBBVectorizePass] function. *) -external add_bb_vectorize : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_bb_vectorize" +external add_bb_vectorize + : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit + = "llvm_add_bb_vectorize" (** See the [llvm::createLoopVectorizePass] function. *) -external add_loop_vectorize : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_loop_vectorize" +external add_loop_vectorize + : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit + = "llvm_add_loop_vectorize" -(** See [llvm::createSLPVectorizerPass] function. *) -external add_slp_vectorize : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit - = "llvm_add_slp_vectorize" +(** See the [llvm::createSLPVectorizerPass] function. *) +external add_slp_vectorize + : [<Llvm.PassManager.any] Llvm.PassManager.t -> unit + = "llvm_add_slp_vectorize" |