mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-12 17:32:19 +00:00
[OCaml] Implement Llvm_vectorize bindings
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193950 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6ca1789ac6
commit
1185582dfd
@ -54,6 +54,14 @@ package "scalar_opts" (
|
|||||||
archive(native) = "llvm_scalar_opts.cmxa"
|
archive(native) = "llvm_scalar_opts.cmxa"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
package "vectorize" (
|
||||||
|
requires = "llvm"
|
||||||
|
version = "@PACKAGE_VERSION@"
|
||||||
|
description = "Vector Transforms for LLVM"
|
||||||
|
archive(byte) = "llvm_vectorize.cma"
|
||||||
|
archive(native) = "llvm_vectorize.cmxa"
|
||||||
|
)
|
||||||
|
|
||||||
package "target" (
|
package "target" (
|
||||||
requires = "llvm"
|
requires = "llvm"
|
||||||
version = "@PACKAGE_VERSION@"
|
version = "@PACKAGE_VERSION@"
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
##===----------------------------------------------------------------------===##
|
##===----------------------------------------------------------------------===##
|
||||||
|
|
||||||
LEVEL := ../../..
|
LEVEL := ../../..
|
||||||
DIRS = scalar ipo
|
DIRS = scalar ipo vectorize
|
||||||
|
|
||||||
ocamldoc:
|
ocamldoc:
|
||||||
$(Verb) for i in $(DIRS) ; do \
|
$(Verb) for i in $(DIRS) ; do \
|
||||||
|
19
bindings/ocaml/transforms/vectorize/Makefile
Normal file
19
bindings/ocaml/transforms/vectorize/Makefile
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
##===- bindings/ocaml/transforms/vectorize/Makefile --------*- Makefile -*-===##
|
||||||
|
#
|
||||||
|
# The LLVM Compiler Infrastructure
|
||||||
|
#
|
||||||
|
# This file is distributed under the University of Illinois Open Source
|
||||||
|
# License. See LICENSE.TXT for details.
|
||||||
|
#
|
||||||
|
##===----------------------------------------------------------------------===##
|
||||||
|
#
|
||||||
|
# This is the makefile for the Objective Caml Llvm_vectorize_opts interface.
|
||||||
|
#
|
||||||
|
##===----------------------------------------------------------------------===##
|
||||||
|
|
||||||
|
LEVEL := ../../../..
|
||||||
|
LIBRARYNAME := llvm_vectorize
|
||||||
|
UsedComponents := vectorize
|
||||||
|
UsedOcamlInterfaces := llvm
|
||||||
|
|
||||||
|
include ../../Makefile.ocaml
|
15
bindings/ocaml/transforms/vectorize/llvm_vectorize.ml
Normal file
15
bindings/ocaml/transforms/vectorize/llvm_vectorize.ml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
(*===-- llvm_vectorize.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_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"
|
25
bindings/ocaml/transforms/vectorize/llvm_vectorize.mli
Normal file
25
bindings/ocaml/transforms/vectorize/llvm_vectorize.mli
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
(*===-- llvm_vectorize.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.
|
||||||
|
*
|
||||||
|
*===----------------------------------------------------------------------===*)
|
||||||
|
|
||||||
|
(** Vectorize Transforms.
|
||||||
|
|
||||||
|
This interface provides an OCaml API for LLVM vectorize transforms, the
|
||||||
|
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"
|
||||||
|
|
||||||
|
(** See the [llvm::createLoopVectorizePass] function. *)
|
||||||
|
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"
|
38
bindings/ocaml/transforms/vectorize/vectorize_ocaml.c
Normal file
38
bindings/ocaml/transforms/vectorize/vectorize_ocaml.c
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*===-- vectorize_ocaml.c - LLVM OCaml Glue ---------------------*- C++ -*-===*\
|
||||||
|
|* *|
|
||||||
|
|* The LLVM Compiler Infrastructure *|
|
||||||
|
|* *|
|
||||||
|
|* This file is distributed under the University of Illinois Open Source *|
|
||||||
|
|* License. See LICENSE.TXT for details. *|
|
||||||
|
|* *|
|
||||||
|
|*===----------------------------------------------------------------------===*|
|
||||||
|
|* *|
|
||||||
|
|* This file glues LLVM's OCaml interface to its C interface. These functions *|
|
||||||
|
|* are by and large transparent wrappers to the corresponding C functions. *|
|
||||||
|
|* *|
|
||||||
|
|* Note that these functions intentionally take liberties with the CAMLparamX *|
|
||||||
|
|* macros, since most of the parameters are not GC heap objects. *|
|
||||||
|
|* *|
|
||||||
|
\*===----------------------------------------------------------------------===*/
|
||||||
|
|
||||||
|
#include "llvm-c/Transforms/Vectorize.h"
|
||||||
|
#include "caml/mlvalues.h"
|
||||||
|
#include "caml/misc.h"
|
||||||
|
|
||||||
|
/* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
|
||||||
|
CAMLprim value llvm_add_bb_vectorize(LLVMPassManagerRef PM) {
|
||||||
|
LLVMAddBBVectorizePass(PM);
|
||||||
|
return Val_unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
|
||||||
|
CAMLprim value llvm_add_loop_vectorize(LLVMPassManagerRef PM) {
|
||||||
|
LLVMAddLoopVectorizePass(PM);
|
||||||
|
return Val_unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
|
||||||
|
CAMLprim value llvm_add_slp_vectorize(LLVMPassManagerRef PM) {
|
||||||
|
LLVMAddSLPVectorizePass(PM);
|
||||||
|
return Val_unit;
|
||||||
|
}
|
61
test/Bindings/Ocaml/vectorize_opts.ml
Normal file
61
test/Bindings/Ocaml/vectorize_opts.ml
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
(* RUN: rm -rf %t.builddir
|
||||||
|
* RUN: mkdir -p %t.builddir
|
||||||
|
* RUN: cp %s %t.builddir
|
||||||
|
* RUN: %ocamlopt -warn-error A llvm.cmxa llvm_vectorize.cmxa llvm_target.cmxa %t.builddir/vectorize_opts.ml -o %t
|
||||||
|
* RUN: %t %t.bc
|
||||||
|
* XFAIL: vg_leak
|
||||||
|
*)
|
||||||
|
|
||||||
|
(* Note: It takes several seconds for ocamlopt to link an executable with
|
||||||
|
libLLVMCore.a, so it's better to write a big test than a bunch of
|
||||||
|
little ones. *)
|
||||||
|
|
||||||
|
open Llvm
|
||||||
|
open Llvm_vectorize
|
||||||
|
open Llvm_target
|
||||||
|
|
||||||
|
let context = global_context ()
|
||||||
|
let void_type = Llvm.void_type context
|
||||||
|
|
||||||
|
(* Tiny unit test framework - really just to help find which line is busted *)
|
||||||
|
let print_checkpoints = false
|
||||||
|
|
||||||
|
let suite name f =
|
||||||
|
if print_checkpoints then
|
||||||
|
prerr_endline (name ^ ":");
|
||||||
|
f ()
|
||||||
|
|
||||||
|
|
||||||
|
(*===-- Fixture -----------------------------------------------------------===*)
|
||||||
|
|
||||||
|
let filename = Sys.argv.(1)
|
||||||
|
let m = create_module context filename
|
||||||
|
|
||||||
|
|
||||||
|
(*===-- Transforms --------------------------------------------------------===*)
|
||||||
|
|
||||||
|
let test_transforms () =
|
||||||
|
let (++) x f = ignore (f x); x in
|
||||||
|
|
||||||
|
let fty = function_type void_type [| |] in
|
||||||
|
let fn = define_function "fn" fty m in
|
||||||
|
ignore (build_ret_void (builder_at_end context (entry_block fn)));
|
||||||
|
|
||||||
|
let td = DataLayout.create (target_triple m) in
|
||||||
|
|
||||||
|
ignore (PassManager.create ()
|
||||||
|
++ DataLayout.add td
|
||||||
|
++ add_bb_vectorize
|
||||||
|
++ add_loop_vectorize
|
||||||
|
++ add_slp_vectorize
|
||||||
|
++ PassManager.run_module m
|
||||||
|
++ PassManager.dispose);
|
||||||
|
|
||||||
|
DataLayout.dispose td
|
||||||
|
|
||||||
|
|
||||||
|
(*===-- Driver ------------------------------------------------------------===*)
|
||||||
|
|
||||||
|
let _ =
|
||||||
|
suite "transforms" test_transforms;
|
||||||
|
dispose_module m
|
Loading…
x
Reference in New Issue
Block a user