[sledge] Add a flag to disable internalization

Summary:
By default all functions except those specified as entry points in the
config file are "internalized". Internal functions are removed if they
are not called. It is sometimes necessary to disable internalization,
e.g. to analyze the llvm tests.

Reviewed By: bennostein

Differential Revision: D17725614

fbshipit-source-id: 4b13501f5
master
Josh Berdine 6 years ago committed by Facebook Github Bot
parent 6ca09b14fd
commit ffeef16aae

@ -56,6 +56,8 @@ Analyze code in a buck target. This is a convenience wrapper for the sequence `s
[-margin <cols>] wrap debug tracing at <cols> columns
[-modules <file>] write list of bitcode files to <file>, or to standard
output if <file> is `-`
[-no-internalize] do not internalize all functions except the entry
points specified in the config file
[-no-models] do not add models for C/C++ runtime and standard
libraries
[-preanalyze-globals] pre-analyze global variables used by each function
@ -139,6 +141,8 @@ Analyze code in one or more LLVM bitcode files. This is a convenience wrapper fo
[-fuzzer] add a harness for libFuzzer targets
[-llair-output <file>] write generated LLAIR to <file>
[-margin <cols>] wrap debug tracing at <cols> columns
[-no-internalize] do not internalize all functions except the entry
points specified in the config file
[-no-models] do not add models for C/C++ runtime and standard
libraries
[-preanalyze-globals] pre-analyze global variables used by each function
@ -162,6 +166,8 @@ Translate one or more LLVM bitcode files to LLAIR. Each <input> filename may be
[-fuzzer] add a harness for libFuzzer targets
[-llair-output <file>] write generated LLAIR to <file>
[-margin <cols>] wrap debug tracing at <cols> columns
[-no-internalize] do not internalize all functions except the entry
points specified in the config file
[-no-models] do not add models for C/C++ runtime and standard
libraries
[-trace <spec>] enable debug tracing

@ -1309,12 +1309,13 @@ let xlate_function : x -> Llvm.llvalue -> Llair.func =
|>
[%Trace.retn fun {pf} -> pf "@\n%a" Llair.Func.pp]
let transform : Llvm.llmodule -> unit =
let transform ~internalize : Llvm.llmodule -> unit =
fun llmodule ->
let pm = Llvm.PassManager.create () in
let entry_points = Config.find_list "entry-points" in
Llvm_ipo.add_internalize_predicate pm (fun fn ->
List.exists entry_points ~f:(String.equal fn) ) ;
if internalize then
Llvm_ipo.add_internalize_predicate pm (fun fn ->
List.exists entry_points ~f:(String.equal fn) ) ;
Llvm_ipo.add_global_dce pm ;
Llvm_ipo.add_global_optimizer pm ;
Llvm_ipo.add_merge_functions pm ;
@ -1349,7 +1350,7 @@ let link_in : Llvm.llcontext -> Llvm.lllinker -> string -> unit =
fun llcontext link_ctx bc_file ->
Llvm_linker.link_in link_ctx (read_and_parse llcontext bc_file)
let translate ~models ~fuzzer : string list -> Llair.t =
let translate ~models ~fuzzer ~internalize : string list -> Llair.t =
fun inputs ->
[%Trace.call fun {pf} ->
pf "%a" (List.pp "@ " Format.pp_print_string) inputs]
@ -1371,7 +1372,7 @@ let translate ~models ~fuzzer : string list -> Llair.t =
assert (
Llvm_analysis.verify_module llmodule |> Option.for_all ~f:invalid_llvm
) ;
transform llmodule ;
transform ~internalize llmodule ;
scan_names_and_locs llmodule ;
let lldatalayout =
Llvm_target.DataLayout.of_string (Llvm.data_layout llmodule)

@ -9,6 +9,7 @@
exception Invalid_llvm of string
val translate : models:bool -> fuzzer:bool -> string list -> Llair.t
val translate :
models:bool -> fuzzer:bool -> internalize:bool -> string list -> Llair.t
(** Translate the compilation units in the named (llvm or bitcode) files to
LLAIR. Attempts to raise [Invalid_llvm] when the input is invalid LLVM. *)

@ -135,10 +135,16 @@ let translate =
~doc:"do not add models for C/C++ runtime and standard libraries"
and fuzzer =
flag "fuzzer" no_arg ~doc:"add a harness for libFuzzer targets"
and no_internalize =
flag "no-internalize" no_arg
~doc:
"do not internalize all functions except the entry points \
specified in the config file"
in
fun bitcode_inputs () ->
let program =
Frontend.translate ~models:(not no_models) ~fuzzer bitcode_inputs
Frontend.translate ~models:(not no_models) ~fuzzer
~internalize:(not no_internalize) bitcode_inputs
in
Option.iter ~f:(marshal program) llair_output ;
program

@ -28,7 +28,7 @@ default: test
# all analyze tests
translate:
@find -L llvm -name '*.ll' -or -name '*.bc' \
| parallel --bar $(SLEDGE) llvm translate -no-models $(SLEDGE_ARGS)
| parallel --bar $(SLEDGE) llvm translate -no-models -no-internalize $(SLEDGE_ARGS)
_translate-report-raw:
@find -L llvm -name '*.out' \

Loading…
Cancel
Save