[sledge] Update internalize to handle other mains

Summary:
Use the new LLVM bindings to handle internalization.

We would like to use global dead code elimination (gdce) to remove all the code not reachable from an entry point. However in normal compilation most functions aren't globally dead (they can be linked to). At the point of running sledge we won't be linking anymore, therefore we can internalize (make invisible outside of the compilation unit) all the symbols.  In that case the whole program is dead with respect to gdce, therefore we need to preserve the entry point as external.

Previously we could only preserve `main` as the entry point (through a boolean flag). This patch uses a newer API that lets us preserve functions that satisfy a given predicate function. This enables us to have arbitrary entry points (not just main). Currently only the 3 entry points from `src/control.ml` are used, but this patch makes it easy to change.

Reviewed By: ngorogiannis

Differential Revision: D15561461

fbshipit-source-id: 88e054411
master
Timotej Kapus 6 years ago committed by Facebook Github Bot
parent 8910c0a20c
commit cdd444b901

@ -1323,8 +1323,12 @@ let xlate_function : x -> Llvm.llvalue -> Llair.func =
let transform ~gdce : Llvm.llmodule -> unit =
fun llmodule ->
let pm = Llvm.PassManager.create () in
if gdce then Llvm_ipo.add_internalize pm ~all_but_main:true ;
Llvm_ipo.add_global_dce pm ;
if gdce then (
Llvm_ipo.add_internalize_predicate pm ~predicate:(fun fn ->
List.exists
["__llair_main"; "_Z12__llair_mainv"; "main"]
~f:(String.equal fn) ) ;
Llvm_ipo.add_global_dce pm ) ;
Llvm_scalar_opts.add_lower_atomic pm ;
Llvm_scalar_opts.add_scalar_repl_aggregation pm ;
Llvm_scalar_opts.add_scalarizer pm ;

Loading…
Cancel
Save