Imported Upstream version 5.18.0.161

Former-commit-id: 4db48158d3a35497b8f118ab21b5f08ac3d86d98
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-10-19 08:34:24 +00:00
parent 37fbf886a3
commit e19d552987
28702 changed files with 3868076 additions and 803 deletions

View File

@@ -0,0 +1,3 @@
; RUN: llvm-go test llvm.org/llvm/bindings/go/llvm
; REQUIRES: shell, not_ubsan, not_msan

View File

@@ -0,0 +1,60 @@
import os
import pipes
import shlex
import sys
if not 'go' in config.root.llvm_bindings:
config.unsupported = True
if not config.root.include_go_tests:
config.unsupported = True
def find_executable(executable, path=None):
if path is None:
path = os.environ['PATH']
paths = path.split(os.pathsep)
base, ext = os.path.splitext(executable)
if (sys.platform == 'win32' or os.name == 'os2') and (ext != '.exe'):
executable = executable + '.exe'
if not os.path.isfile(executable):
for p in paths:
f = os.path.join(p, executable)
if os.path.isfile(f):
return f
return None
else:
return executable
# Resolve certain symlinks in the first word of compiler.
#
# This is a Go-specific hack. cgo and other Go tools check $CC and $CXX for the
# substring 'clang' to determine if the compiler is Clang. This won't work if
# $CC is cc and cc is a symlink pointing to clang, as it is on Darwin.
#
# Go tools also have problems with ccache, so we disable it.
def fixup_compiler_path(compiler):
args = shlex.split(compiler)
if args[0].endswith('ccache'):
args = args[1:]
path = find_executable(args[0])
try:
if path.endswith('/cc') and os.readlink(path) == 'clang':
args[0] = path[:len(path)-2] + 'clang'
except (AttributeError, OSError):
pass
try:
if path.endswith('/c++') and os.readlink(path) == 'clang++':
args[0] = path[:len(path)-3] + 'clang++'
except (AttributeError, OSError):
pass
return ' '.join([pipes.quote(arg) for arg in args])
config.environment['CC'] = fixup_compiler_path(config.host_cc)
config.environment['CXX'] = fixup_compiler_path(config.host_cxx)
config.environment['CGO_LDFLAGS'] = config.host_ldflags

View File

@@ -0,0 +1,54 @@
(* RUN: rm -rf %t && mkdir -p %t && cp %s %t/analysis.ml
* RUN: %ocamlc -g -w +A -package llvm.analysis -linkpkg %t/analysis.ml -o %t/executable
* RUN: %t/executable
* RUN: %ocamlopt -g -w +A -package llvm.analysis -linkpkg %t/analysis.ml -o %t/executable
* RUN: %t/executable
* XFAIL: vg_leak
*)
open Llvm
open Llvm_analysis
(* Note that this takes a moment to link, so it's best to keep the number of
individual tests low. *)
let context = global_context ()
let test x = if not x then exit 1 else ()
let bomb msg =
prerr_endline msg;
exit 2
let _ =
let fty = function_type (void_type context) [| |] in
let m = create_module context "valid_m" in
let fn = define_function "valid_fn" fty m in
let at_entry = builder_at_end context (entry_block fn) in
ignore (build_ret_void at_entry);
(* Test that valid constructs verify. *)
begin match verify_module m with
Some msg -> bomb "valid module failed verification!"
| None -> ()
end;
if not (verify_function fn) then bomb "valid function failed verification!";
(* Test that invalid constructs do not verify.
A basic block can contain only one terminator instruction. *)
ignore (build_ret_void at_entry);
begin match verify_module m with
Some msg -> ()
| None -> bomb "invalid module passed verification!"
end;
if verify_function fn then bomb "invalid function passed verification!";
dispose_module m
(* Don't bother to test assert_valid_{module,function}. *)

View File

@@ -0,0 +1,83 @@
(* RUN: rm -rf %t && mkdir -p %t && cp %s %t/bitreader.ml
* RUN: %ocamlc -g -w +A -package llvm.bitreader -package llvm.bitwriter -linkpkg %t/bitreader.ml -o %t/executable
* RUN: %t/executable %t/bitcode.bc
* RUN: %ocamlopt -g -w +A -package llvm.bitreader -package llvm.bitwriter -linkpkg %t/bitreader.ml -o %t/executable
* RUN: %t/executable %t/bitcode.bc
* RUN: llvm-dis < %t/bitcode.bc
* XFAIL: vg_leak
*)
(* Note that this takes a moment to link, so it's best to keep the number of
individual tests low. *)
let context = Llvm.global_context ()
let diagnostic_handler _ = ()
let test x = if not x then exit 1 else ()
let _ =
Llvm.set_diagnostic_handler context (Some diagnostic_handler);
let fn = Sys.argv.(1) in
let m = Llvm.create_module context "ocaml_test_module" in
test (Llvm_bitwriter.write_bitcode_file m fn);
Llvm.dispose_module m;
(* parse_bitcode *)
begin
let mb = Llvm.MemoryBuffer.of_file fn in
begin try
let m = Llvm_bitreader.parse_bitcode context mb in
Llvm.dispose_module m
with x ->
Llvm.MemoryBuffer.dispose mb;
raise x
end
end;
(* MemoryBuffer.of_file *)
test begin try
let mb = Llvm.MemoryBuffer.of_file (fn ^ ".bogus") in
Llvm.MemoryBuffer.dispose mb;
false
with Llvm.IoError _ ->
true
end;
(* get_module *)
begin
let mb = Llvm.MemoryBuffer.of_file fn in
let m = begin try
Llvm_bitreader.get_module context mb
with x ->
Llvm.MemoryBuffer.dispose mb;
raise x
end in
Llvm.dispose_module m
end;
(* corrupt the bitcode *)
let fn = fn ^ ".txt" in
begin let oc = open_out fn in
output_string oc "not a bitcode file\n";
close_out oc
end;
(* test get_module exceptions *)
test begin
try
let mb = Llvm.MemoryBuffer.of_file fn in
let m = begin try
Llvm_bitreader.get_module context mb
with x ->
Llvm.MemoryBuffer.dispose mb;
raise x
end in
Llvm.dispose_module m;
false
with Llvm_bitreader.Error _ ->
true
end

View File

@@ -0,0 +1,49 @@
(* RUN: rm -rf %t && mkdir -p %t && cp %s %t/bitwriter.ml
* RUN: %ocamlc -g -w -3 -w +A -package llvm.bitreader -package llvm.bitwriter -linkpkg %t/bitwriter.ml -o %t/executable
* RUN: %t/executable %t/bitcode.bc
* RUN: %ocamlopt -g -w -3 -w +A -package llvm.bitreader -package llvm.bitwriter -linkpkg %t/bitwriter.ml -o %t/executable
* RUN: %t/executable %t/bitcode.bc
* RUN: llvm-dis < %t/bitcode.bc
* XFAIL: vg_leak
*)
(* Note that this takes a moment to link, so it's best to keep the number of
individual tests low. *)
let context = Llvm.global_context ()
let test x = if not x then exit 1 else ()
let read_file name =
let ic = open_in_bin name in
let len = in_channel_length ic in
let buf = String.create len in
test ((input ic buf 0 len) = len);
close_in ic;
buf
let temp_bitcode ?unbuffered m =
let temp_name, temp_oc = Filename.open_temp_file ~mode:[Open_binary] "" "" in
test (Llvm_bitwriter.output_bitcode ?unbuffered temp_oc m);
flush temp_oc;
let temp_buf = read_file temp_name in
close_out temp_oc;
temp_buf
let _ =
let m = Llvm.create_module context "ocaml_test_module" in
test (Llvm_bitwriter.write_bitcode_file m Sys.argv.(1));
let file_buf = read_file Sys.argv.(1) in
test (file_buf = temp_bitcode m);
test (file_buf = temp_bitcode ~unbuffered:false m);
test (file_buf = temp_bitcode ~unbuffered:true m);
test (file_buf = Llvm.MemoryBuffer.as_string (Llvm_bitwriter.write_bitcode_to_memory_buffer m))

1564
external/llvm/test/Bindings/OCaml/core.ml vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,48 @@
(* RUN: rm -rf %t && mkdir -p %t && cp %s %t/diagnostic_handler.ml
* RUN: %ocamlc -g -w +A -package llvm.bitreader -linkpkg %t/diagnostic_handler.ml -o %t/executable
* RUN: %t/executable %t/bitcode.bc | FileCheck %s
* RUN: %ocamlopt -g -w +A -package llvm.bitreader -linkpkg %t/diagnostic_handler.ml -o %t/executable
* RUN: %t/executable %t/bitcode.bc | FileCheck %s
* XFAIL: vg_leak
*)
let context = Llvm.global_context ()
let diagnostic_handler d =
Printf.printf
"Diagnostic handler called: %s\n" (Llvm.Diagnostic.description d);
match Llvm.Diagnostic.severity d with
| Error -> Printf.printf "Diagnostic severity is Error\n"
| Warning -> Printf.printf "Diagnostic severity is Warning\n"
| Remark -> Printf.printf "Diagnostic severity is Remark\n"
| Note -> Printf.printf "Diagnostic severity is Note\n"
let test x = if not x then exit 1 else ()
let _ =
Llvm.set_diagnostic_handler context (Some diagnostic_handler);
(* corrupt the bitcode *)
let fn = Sys.argv.(1) ^ ".txt" in
begin let oc = open_out fn in
output_string oc "not a bitcode file\n";
close_out oc
end;
test begin
try
let mb = Llvm.MemoryBuffer.of_file fn in
let m = begin try
(* CHECK: Diagnostic handler called: Invalid bitcode signature
* CHECK: Diagnostic severity is Error
*)
Llvm_bitreader.get_module context mb
with x ->
Llvm.MemoryBuffer.dispose mb;
raise x
end in
Llvm.dispose_module m;
false
with Llvm_bitreader.Error _ ->
true
end

View File

@@ -0,0 +1,112 @@
(* RUN: rm -rf %t && mkdir -p %t && cp %s %t/executionengine.ml
* RUN: %ocamlc -g -w +A -package llvm.executionengine -linkpkg %t/executionengine.ml -o %t/executable
* RUN: %t/executable
* RUN: %ocamlopt -g -w +A -package llvm.executionengine -linkpkg %t/executionengine.ml -o %t/executable
* RUN: %t/executable
* REQUIRES: native, object-emission
* XFAIL: vg_leak
*)
open Llvm
open Llvm_executionengine
open Llvm_target
(* Note that this takes a moment to link, so it's best to keep the number of
individual tests low. *)
let context = global_context ()
let i8_type = Llvm.i8_type context
let i32_type = Llvm.i32_type context
let i64_type = Llvm.i64_type context
let double_type = Llvm.double_type context
let () =
assert (Llvm_executionengine.initialize ())
let bomb msg =
prerr_endline msg;
exit 2
let define_getglobal m pg =
let fn = define_function "getglobal" (function_type i32_type [||]) m in
let b = builder_at_end (global_context ()) (entry_block fn) in
let g = build_call pg [||] "" b in
ignore (build_ret g b);
fn
let define_plus m =
let fn = define_function "plus" (function_type i32_type [| i32_type;
i32_type |]) m in
let b = builder_at_end (global_context ()) (entry_block fn) in
let add = build_add (param fn 0) (param fn 1) "sum" b in
ignore (build_ret add b);
fn
let test_executionengine () =
let open Ctypes in
(* create *)
let m = create_module (global_context ()) "test_module" in
let ee = create m in
(* add plus *)
ignore (define_plus m);
(* declare global variable *)
ignore (define_global "globvar" (const_int i32_type 23) m);
(* add module *)
let m2 = create_module (global_context ()) "test_module2" in
add_module m2 ee;
(* add global mapping *)
(* BROKEN: see PR20656 *)
(* let g = declare_function "g" (function_type i32_type [||]) m2 in
let cg = coerce (Foreign.funptr (void @-> returning int32_t)) (ptr void)
(fun () -> 42l) in
add_global_mapping g cg ee;
(* check g *)
let cg' = get_pointer_to_global g (ptr void) ee in
if 0 <> ptr_compare cg cg' then bomb "int pointers to g differ";
(* add getglobal *)
let getglobal = define_getglobal m2 g in*)
(* run_static_ctors *)
run_static_ctors ee;
(* get a handle on globvar *)
let varh = get_global_value_address "globvar" int32_t ee in
if 23l <> varh then bomb "get_global_value_address didn't work";
(* call plus *)
let cplusty = Foreign.funptr (int32_t @-> int32_t @-> returning int32_t) in
let cplus = get_function_address "plus" cplusty ee in
if 4l <> cplus 2l 2l then bomb "plus didn't work";
(* call getglobal *)
(* let cgetglobalty = Foreign.funptr (void @-> returning int32_t) in
let cgetglobal = get_pointer_to_global getglobal cgetglobalty ee in
if 42l <> cgetglobal () then bomb "getglobal didn't work"; *)
(* remove_module *)
remove_module m2 ee;
dispose_module m2;
(* run_static_dtors *)
run_static_dtors ee;
(* Show that the data layout binding links and runs.*)
let dl = data_layout ee in
(* Demonstrate that a garbage pointer wasn't returned. *)
let ty = DataLayout.intptr_type context dl in
if ty != i32_type && ty != i64_type then bomb "target_data did not work";
(* dispose *)
dispose ee
let () =
test_executionengine ();
Gc.compact ()

View File

@@ -0,0 +1,25 @@
(* RUN: rm -rf %t && mkdir -p %t && cp %s %t/ext_exc.ml
* RUN: %ocamlc -g -w +A -package llvm.bitreader -linkpkg %t/ext_exc.ml -o %t/executable
* RUN: %t/executable
* RUN: %ocamlopt -g -w +A -package llvm.bitreader -linkpkg %t/ext_exc.ml -o %t/executable
* RUN: %t/executable
* XFAIL: vg_leak
*)
let context = Llvm.global_context ()
let diagnostic_handler _ = ()
(* This used to crash, we must not use 'external' in .mli files, but 'val' if we
* want the let _ bindings executed, see http://caml.inria.fr/mantis/view.php?id=4166 *)
let _ =
Llvm.set_diagnostic_handler context (Some diagnostic_handler);
try
ignore (Llvm_bitreader.get_module context (Llvm.MemoryBuffer.of_stdin ()))
with
Llvm_bitreader.Error _ -> ();;
let _ =
try
ignore (Llvm.MemoryBuffer.of_file "/path/to/nonexistent/file")
with
Llvm.IoError _ -> ();;

View File

@@ -0,0 +1,72 @@
(* RUN: rm -rf %t && mkdir -p %t && cp %s %t/ipo_opts.ml
* RUN: %ocamlc -g -w +A -package llvm.ipo -linkpkg %t/ipo_opts.ml -o %t/executable
* RUN: %t/executable %t/bitcode.bc
* RUN: %ocamlopt -g -w +A -package llvm.ipo -linkpkg %t/ipo_opts.ml -o %t/executable
* RUN: %t/executable %t/bitcode.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_ipo
open Llvm_target
let context = global_context ()
let void_type = Llvm.void_type context
let i8_type = Llvm.i8_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 = f x; x in
let fty = function_type i8_type [| |] in
let fn = define_function "fn" fty m in
let fn2 = define_function "fn2" fty m in begin
ignore (build_ret (const_int i8_type 4) (builder_at_end context (entry_block fn)));
let b = builder_at_end context (entry_block fn2) in
ignore (build_ret (build_call fn [| |] "" b) b);
end;
ignore (PassManager.create ()
++ add_argument_promotion
++ add_constant_merge
++ add_dead_arg_elimination
++ add_function_attrs
++ add_function_inlining
++ add_always_inliner
++ add_global_dce
++ add_global_optimizer
++ add_ipc_propagation
++ add_prune_eh
++ add_ipsccp
++ add_internalize ~all_but_main:true
++ add_strip_dead_prototypes
++ add_strip_symbols
++ PassManager.run_module m
++ PassManager.dispose)
(*===-- Driver ------------------------------------------------------------===*)
let _ =
suite "transforms" test_transforms;
dispose_module m

View File

@@ -0,0 +1,59 @@
(* RUN: rm -rf %t && mkdir -p %t && cp %s %t/irreader.ml
* RUN: %ocamlc -g -w +A -package llvm.irreader -linkpkg %t/irreader.ml -o %t/executable
* RUN: %t/executable
* RUN: %ocamlopt -g -w +A -package llvm.irreader -linkpkg %t/irreader.ml -o %t/executable
* RUN: %t/executable
* 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_irreader
let context = global_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 ()
let _ =
Printexc.record_backtrace true
let insist cond =
if not cond then failwith "insist"
(*===-- IR Reader ---------------------------------------------------------===*)
let test_irreader () =
begin
let buf = MemoryBuffer.of_string "@foo = global i32 42" in
let m = parse_ir context buf in
match lookup_global "foo" m with
| Some foo ->
insist ((global_initializer foo) = (const_int (i32_type context) 42))
| None ->
failwith "global"
end;
begin
let buf = MemoryBuffer.of_string "@foo = global garble" in
try
ignore (parse_ir context buf);
failwith "parsed"
with Llvm_irreader.Error _ ->
()
end
(*===-- Driver ------------------------------------------------------------===*)
let _ =
suite "irreader" test_irreader

View File

@@ -0,0 +1,65 @@
(* RUN: rm -rf %t && mkdir -p %t && cp %s %t/linker.ml
* RUN: %ocamlc -g -w +A -package llvm.linker -linkpkg %t/linker.ml -o %t/executable
* RUN: %t/executable
* RUN: %ocamlopt -g -w +A -package llvm.linker -linkpkg %t/linker.ml -o %t/executable
* RUN: %t/executable
* 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_linker
let context = global_context ()
let void_type = Llvm.void_type context
let diagnostic_handler _ = ()
(* 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 ()
(*===-- Linker -----------------------------------------------------------===*)
let test_linker () =
set_diagnostic_handler context (Some diagnostic_handler);
let fty = function_type void_type [| |] in
let make_module name =
let m = create_module context name in
let fn = define_function ("fn_" ^ name) fty m in
ignore (build_ret_void (builder_at_end context (entry_block fn)));
m
in
let m1 = make_module "one"
and m2 = make_module "two" in
link_modules' m1 m2;
dispose_module m1;
let m1 = make_module "one"
and m2 = make_module "two" in
link_modules' m1 m2;
dispose_module m1;
let m1 = make_module "one"
and m2 = make_module "one" in
try
link_modules' m1 m2;
failwith "must raise"
with Error _ ->
dispose_module m1
(*===-- Driver ------------------------------------------------------------===*)
let _ =
suite "linker" test_linker

View File

@@ -0,0 +1,7 @@
config.suffixes = ['.ml']
if not 'ocaml' in config.root.llvm_bindings:
config.unsupported = True
if not config.root.have_ocaml_ounit:
config.unsupported = True

View File

@@ -0,0 +1,64 @@
(* RUN: rm -rf %t && mkdir -p %t && cp %s %t/passmgr_builder.ml
* RUN: %ocamlc -g -w +A -package llvm.passmgr_builder -linkpkg %t/passmgr_builder.ml -o %t/executable
* RUN: %t/executable %t/bitcode.bc
* RUN: %ocamlopt -g -w +A -package llvm.passmgr_builder -linkpkg %t/passmgr_builder.ml -o %t/executable
* RUN: %t/executable %t/bitcode.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_passmgr_builder
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
(*===-- Pass Manager Builder ----------------------------------------------===*)
let test_pmbuilder () =
let (++) x f = ignore (f x); x in
let module_passmgr = PassManager.create () in
let func_passmgr = PassManager.create_function m in
let lto_passmgr = PassManager.create () in
ignore (Llvm_passmgr_builder.create ()
++ set_opt_level 3
++ set_size_level 1
++ set_disable_unit_at_a_time false
++ set_disable_unroll_loops false
++ use_inliner_with_threshold 10
++ populate_function_pass_manager func_passmgr
++ populate_module_pass_manager module_passmgr
++ populate_lto_pass_manager lto_passmgr
~internalize:false ~run_inliner:false);
Gc.compact ();
PassManager.dispose module_passmgr;
PassManager.dispose func_passmgr;
PassManager.dispose lto_passmgr
(*===-- Driver ------------------------------------------------------------===*)
let _ =
suite "pass manager builder" test_pmbuilder;
dispose_module m

View File

@@ -0,0 +1,92 @@
(* RUN: rm -rf %t && mkdir -p %t && cp %s %t/scalar_opts.ml
* RUN: %ocamlc -g -w +A -package llvm.scalar_opts -linkpkg %t/scalar_opts.ml -o %t/executable
* RUN: %t/executable %t/bitcode.bc
* RUN: %ocamlopt -g -w +A -package llvm.scalar_opts -linkpkg %t/scalar_opts.ml -o %t/executable
* RUN: %t/executable %t/bitcode.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_scalar_opts
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 = 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)));
ignore (PassManager.create_function m
++ add_aggressive_dce
++ add_alignment_from_assumptions
++ add_cfg_simplification
++ add_dead_store_elimination
++ add_scalarizer
++ add_merged_load_store_motion
++ add_gvn
++ add_ind_var_simplification
++ add_instruction_combination
++ add_jump_threading
++ add_licm
++ add_loop_deletion
++ add_loop_idiom
++ add_loop_rotation
++ add_loop_reroll
++ add_loop_unroll
++ add_loop_unswitch
++ add_memcpy_opt
++ add_partially_inline_lib_calls
++ add_lower_switch
++ add_memory_to_register_promotion
++ add_reassociation
++ add_sccp
++ add_scalar_repl_aggregation
++ add_scalar_repl_aggregation_ssa
++ add_scalar_repl_aggregation_with_threshold 4
++ add_lib_call_simplification
++ add_tail_call_elimination
++ add_constant_propagation
++ add_memory_to_register_demotion
++ add_verifier
++ add_correlated_value_propagation
++ add_early_cse
++ add_lower_expect_intrinsic
++ add_type_based_alias_analysis
++ add_scoped_no_alias_alias_analysis
++ add_basic_alias_analysis
++ PassManager.initialize
++ PassManager.run_function fn
++ PassManager.finalize
++ PassManager.dispose)
(*===-- Driver ------------------------------------------------------------===*)
let _ =
suite "transforms" test_transforms;
dispose_module m

View File

@@ -0,0 +1,113 @@
(* RUN: rm -rf %t && mkdir -p %t && cp %s %t/target.ml
* RUN: %ocamlc -g -w +A -package llvm.target -package llvm.all_backends -linkpkg %t/target.ml -o %t/executable
* RUN: %ocamlopt -g -w +A -package llvm.target -package llvm.all_backends -linkpkg %t/target.ml -o %t/executable
* RUN: %t/executable %t/bitcode.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_target
let () = Llvm_all_backends.initialize ()
let context = global_context ()
let i32_type = Llvm.i32_type context
let i64_type = Llvm.i64_type context
(* Tiny unit test framework - really just to help find which line is busted *)
let print_checkpoints = false
let _ =
Printexc.record_backtrace true
let assert_equal a b =
if a <> b then failwith "assert_equal"
(*===-- Fixture -----------------------------------------------------------===*)
let filename = Sys.argv.(1)
let m = create_module context filename
let target = Target.by_triple (Target.default_triple ())
let machine = TargetMachine.create (Target.default_triple ()) target
(*===-- Data Layout -------------------------------------------------------===*)
let test_target_data () =
let module DL = DataLayout in
let layout = "e-p:32:32-f64:32:64-v64:32:64-v128:32:128-n32-S32" in
let dl = DL.of_string layout in
let sty = struct_type context [| i32_type; i64_type |] in
assert_equal (DL.as_string dl) layout;
assert_equal (DL.byte_order dl) Endian.Little;
assert_equal (DL.pointer_size dl) 4;
assert_equal (DL.intptr_type context dl) i32_type;
assert_equal (DL.qualified_pointer_size 0 dl) 4;
assert_equal (DL.qualified_intptr_type context 0 dl) i32_type;
assert_equal (DL.size_in_bits sty dl) (Int64.of_int 96);
assert_equal (DL.store_size sty dl) (Int64.of_int 12);
assert_equal (DL.abi_size sty dl) (Int64.of_int 12);
assert_equal (DL.stack_align sty dl) 4;
assert_equal (DL.preferred_align sty dl) 8;
assert_equal (DL.preferred_align_of_global (declare_global sty "g" m) dl) 8;
assert_equal (DL.element_at_offset sty (Int64.of_int 1) dl) 0;
assert_equal (DL.offset_of_element sty 1 dl) (Int64.of_int 4)
(*===-- Target ------------------------------------------------------------===*)
let test_target () =
let module T = Target in
ignore (T.succ target);
ignore (T.name target);
ignore (T.description target);
ignore (T.has_jit target);
ignore (T.has_target_machine target);
ignore (T.has_asm_backend target)
(*===-- Target Machine ----------------------------------------------------===*)
let test_target_machine () =
let module TM = TargetMachine in
assert_equal (TM.target machine) target;
assert_equal (TM.triple machine) (Target.default_triple ());
assert_equal (TM.cpu machine) "";
assert_equal (TM.features machine) "";
ignore (TM.data_layout machine);
TM.set_verbose_asm true machine;
let pm = PassManager.create () in
TM.add_analysis_passes pm machine
(*===-- Code Emission -----------------------------------------------------===*)
let test_code_emission () =
TargetMachine.emit_to_file m CodeGenFileType.ObjectFile filename machine;
try
TargetMachine.emit_to_file m CodeGenFileType.ObjectFile
"/nonexistent/file" machine;
failwith "must raise"
with Llvm_target.Error _ ->
();
let buf = TargetMachine.emit_to_memory_buffer m CodeGenFileType.ObjectFile
machine in
Llvm.MemoryBuffer.dispose buf
(*===-- Driver ------------------------------------------------------------===*)
let _ =
test_target_data ();
test_target ();
test_target_machine ();
test_code_emission ();
dispose_module m

View File

@@ -0,0 +1,21 @@
(* RUN: rm -rf %t && mkdir -p %t && cp %s %t/transform_utils.ml
* RUN: %ocamlc -g -w +A -package llvm.transform_utils -linkpkg %t/transform_utils.ml -o %t/executable
* RUN: %t/executable
* RUN: %ocamlopt -g -w +A -package llvm.transform_utils -linkpkg %t/transform_utils.ml -o %t/executable
* RUN: %t/executable
* XFAIL: vg_leak
*)
open Llvm
open Llvm_transform_utils
let context = global_context ()
let test_clone_module () =
let m = create_module context "mod" in
let m' = clone_module m in
if m == m' then failwith "m == m'";
if string_of_llmodule m <> string_of_llmodule m' then failwith "string_of m <> m'"
let () =
test_clone_module ()

View File

@@ -0,0 +1,56 @@
(* RUN: rm -rf %t && mkdir -p %t && cp %s %t/vectorize_opts.ml
* RUN: %ocamlc -g -w +A -package llvm.vectorize -linkpkg %t/vectorize_opts.ml -o %t/executable
* RUN: %t/executable %t/bitcode.bc
* RUN: %ocamlopt -g -w +A -package llvm.vectorize -linkpkg %t/vectorize_opts.ml -o %t/executable
* RUN: %t/executable %t/bitcode.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 = 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)));
ignore (PassManager.create ()
++ add_bb_vectorize
++ add_loop_vectorize
++ add_slp_vectorize
++ PassManager.run_module m
++ PassManager.dispose)
(*===-- Driver ------------------------------------------------------------===*)
let _ =
suite "transforms" test_transforms;
dispose_module m

View File

@@ -0,0 +1,21 @@
; RUN: llvm-c-test --disassemble < %s | FileCheck %s
armv8-linux-gnu +crypto 02 00 81 e0 02 03 b0 f3
;CHECK: triple: armv8-linux-gnu, features: +crypto
;CHECK: 02 00 81 e0 add r0, r1, r2
;CHECK: 02 03 b0 f3 aese.8 q0, q1
armv8-linux-gnu -crypto 02 00 81 e0 02 03 b0 f3
;CHECK: triple: armv8-linux-gnu, features: -crypto
;CHECK: 02 00 81 e0 add r0, r1, r2
;CHECK: 02 ???
;CHECK: 03 ???
;CHECK: b0 ???
;CHECK: f3 ???
arm-linux-android NULL 44 26 1f e5 0c 10 4b e2 02 20 81 e0
;CHECK: triple: arm-linux-android, features: NULL
;CHECK: ldr r2, [pc, #-1604]
;CHECK: sub r1, r11, #12
;CHECK: 02 20 81 e0
;CHECK: add r2, r1, r2

View File

@@ -0,0 +1,2 @@
if not "ARM" in config.root.targets:
config.unsupported = True

Some files were not shown because too many files have changed in this diff Show More