[sledge] Add LLVM passes that reduce bitcode size

Summary:
:
This patch adds several passes that reduce the amount of bitcode
making sledge's job easier, more info:

https://llvm.org/docs/Passes.html

`-mergefunc`
This pass merges functions that do the same thing, this can be because of
templating or casts (ie. same functionality but on 32bit and 64bit ints,
which is the same in machine code). More details at
http://llvm.org/docs/MergeFunctions.html

Note that this pass is currently not available through C/OCaml API.

`-constmerge`
This merges constants that have the same value, this is possible to do
when the constants are internalized.

`-argpromotion`
```
This pass promotes “by reference” arguments to be “by value” arguments.
In practice, this means looking for internal functions that have pointer
arguments. If it can prove, through the use of alias analysis, that an
argument is only loaded, then it can pass the value into the function
instead of the address of the value. This can cause recursive
simplification of code and lead to the elimination of allocas
(especially in C++ template code like the STL).
```

`-ipsccp`
```
Sparse conditional constant propagation and merging, which can be
summarized as:

Assumes values are constant unless proven otherwise
Assumes BasicBlocks are dead unless proven otherwise
Proves values to be constant, and replaces them with constants
Proves conditional branches to be unconditional
```

`-deadargelim`
Removes dead arguments of internal functions, good to run after other inter-procedural
passes. Seems to crash llvm if run directly after `ipsccp`.

Note that while this might look like doing full link-time optimisation,
we are actually picking relatively cheap optimisations that mostly look
at globals and walk their use chains. The main reason link-time
optimisations are expensive is due to inlining and then running the full
optimisation again from there.

Reviewed By: jberdine

Differential Revision: D15851408

fbshipit-source-id: be7191683
master
Timotej Kapus 6 years ago committed by Facebook Github Bot
parent 512b42ece7
commit a75a50215b

@ -1362,6 +1362,12 @@ let transform : Llvm.llmodule -> unit =
List.exists entry_points ~f:(String.equal fn) ) ;
Llvm_ipo.add_global_dce pm ;
Llvm_ipo.add_global_optimizer pm ;
Llvm_ipo.add_constant_merge pm ;
Llvm_ipo.add_argument_promotion pm ;
Llvm_ipo.add_ipsccp pm ;
Llvm_scalar_opts.add_memory_to_register_promotion pm ;
Llvm_ipo.add_global_dce pm ;
Llvm_ipo.add_dead_arg_elimination pm ;
Llvm_scalar_opts.add_lower_atomic pm ;
Llvm_scalar_opts.add_scalar_repl_aggregation pm ;
Llvm_scalar_opts.add_scalarizer pm ;

@ -146,7 +146,9 @@ let llvm_link_opt ~lib_fuzzer_harness ~output modules =
:: "-o=-" :: modules )
|- run
(Lazy.force llvm_bin ^ "opt")
["-o=" ^ output; "-globaldce"; "-globalopt"] )
[ "-o=" ^ output; "-globaldce"; "-globalopt"; "-mergefunc"
; "-constmerge"; "-argpromotion"; "-ipsccp"; "-mem2reg"; "-dce"
; "-globaldce"; "-deadargelim" ] )
(** command line interface *)

Loading…
Cancel
Save