Permalink
Browse files

Better LLVM code is produced

  • Loading branch information...
1 parent bf85656 commit 821aa7875a74d7d7d48a70f500da36d97d5d61ef @colinbenner committed Dec 12, 2011
Showing with 386 additions and 297 deletions.
  1. +15 −14 src/asmcomp/asmgen.ml
  2. +15 −12 src/asmcomp/asmlink.ml
  3. +86 −84 src/asmcomp/llvmcompile.ml
  4. +259 −160 src/asmcomp/llvmemit.ml
  5. +5 −5 src/asmcomp/llvmemit.mli
  6. +0 −5 src/libocamlnat.clib
  7. +0 −15 src/ocamlnat.ml
  8. +6 −2 src/utils/config.mli
View
@@ -107,9 +107,7 @@ let compile_implementation ?toplevel prefixname ppf (size, lam) =
let oc = open_out asmfile in
begin try
Emitaux.output_channel := oc;
- if !use_llvm
- then Llvmemit.begin_assembly()
- else Emit.begin_assembly();
+ if !use_llvm then Llvmemit.begin_assembly() else Emit.begin_assembly();
Closure.intro size lam
++ Cmmgen.compunit size
++ List.map (fun x -> Llvmcompile.read_function x; x)
@@ -128,26 +126,29 @@ let compile_implementation ?toplevel prefixname ppf (size, lam) =
(List.map Primitive.native_name !Translmod.primitive_declarations))
);
- if !use_llvm then Llvmemit.end_assembly()
- else Emit.end_assembly();
+ if !use_llvm then Llvmemit.end_assembly() else Emit.end_assembly();
close_out oc
with x ->
close_out oc;
if !keep_asm_file then () else remove_file asmfile;
raise x
end;
- let tmpfile = prefixname ^ ".ll" ^ ext_asm in
- if !use_llvm then begin
- if Llvmemit.assemble_file asmfile tmpfile (prefixname ^ ext_obj) <> 0
+ let temp1 =
+ if !Clflags.keep_asm_file then prefixname ^ ".opt" ^ ext_llvm
+ else Filename.temp_file (prefixname ^ ".opt") ext_llvm
+ in
+ let temp2 =
+ if !Clflags.keep_asm_file then prefixname ^ ext_asm
+ else Filename.temp_file prefixname ext_asm
+ in
+ let assemble = if !use_llvm then Llvmemit.assemble_file temp1 temp2 else Proc.assemble_file in
+ if assemble asmfile (prefixname ^ ext_obj) <> 0
then raise(Error(Assembler_error asmfile));
- end else begin
- if Proc.assemble_file asmfile (prefixname ^ ext_obj) <> 0
- then raise(Error(Assembler_error asmfile))
- end;
if !keep_asm_file then ()
else begin
- if !use_llvm then remove_file tmpfile;
- remove_file asmfile
+ remove_file asmfile;
+ remove_file temp1;
+ remove_file temp2
end
(* Error report *)
@@ -203,8 +203,7 @@ let make_startup_file ppf filename units_list =
Emitaux.output_channel := oc;
Location.input_name := "caml_startup"; (* set name of "current" input *)
Compilenv.reset "_startup"; (* set the name of the "current" compunit *)
- if !Clflags.use_llvm then Llvmemit.begin_assembly()
- else Emit.begin_assembly();
+ if !Clflags.use_llvm then Llvmemit.begin_assembly() else Emit.begin_assembly();
let name_list =
List.flatten (List.map (fun (info,_,_) -> info.ui_defines) units_list) in
compile_phrase (Cmmgen.entry_point name_list);
@@ -230,8 +229,7 @@ let make_startup_file ppf filename units_list =
compile_phrase
(Cmmgen.frame_table("_startup" :: "_system" :: name_list));
- if !Clflags.use_llvm then Llvmemit.end_assembly()
- else Emit.end_assembly();
+ if !Clflags.use_llvm then Llvmemit.end_assembly() else Emit.end_assembly();
close_out oc
let make_shared_startup_file ppf units filename =
@@ -323,18 +321,23 @@ let link ppf objfiles output_name =
units_tolink;
Clflags.ccobjs := !Clflags.ccobjs @ !lib_ccobjs;
Clflags.ccopts := !lib_ccopts @ !Clflags.ccopts; (* put user's opts first *)
+ let suffix = if !Clflags.use_llvm then ext_llvm else ext_asm in
let startup =
- if !Clflags.keep_startup_file then output_name ^ ".startup" ^ ext_asm
- else Filename.temp_file "camlstartup" ext_asm in
+ if !Clflags.keep_startup_file then output_name ^ ".startup" ^ suffix
+ else Filename.temp_file "camlstartup" suffix in
make_startup_file ppf startup units_tolink;
let startup_obj = Filename.temp_file "camlstartup" ext_obj in
- let startup_asm =
- if !Clflags.keep_startup_file then output_name ^ ".startup.ll.s"
- else Filename.temp_file "camlstartup" ".ll.s" in
- let llvm_temp = Filename.temp_file "camlstartup" (".ll" ^ext_asm) in
+ let temp1 =
+ if !Clflags.keep_startup_file then output_name ^ ".startup.opt" ^ ext_llvm
+ else Filename.temp_file "camlstartup.opt" suffix
+ in
+ let temp2 =
+ if !Clflags.keep_startup_file then output_name ^ ".startup" ^ ext_asm
+ else Filename.temp_file "camlstartup" ext_asm
+ in
if !Clflags.use_llvm then begin
- if Llvmemit.assemble_file startup llvm_temp startup_obj <> 0 then
- raise(Error(Assembler_error startup_asm));
+ if Llvmemit.assemble_file temp1 temp2 startup startup_obj <> 0 then
+ raise(Error(Assembler_error startup));
end else
if Proc.assemble_file startup startup_obj <> 0
then raise(Error(Assembler_error startup));
Oops, something went wrong. Retry.

0 comments on commit 821aa78

Please sign in to comment.