-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implements deadcode-elimination pass optimization #857
Merged
gitoleg
merged 18 commits into
BinaryAnalysisPlatform:master
from
gitoleg:update-dead-code
Aug 30, 2018
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6a9e668
improves dead-code-elimination
gitoleg 1cda10f
Merge remote-tracking branch 'upstream/master' into update-dead-code
gitoleg 075ad6e
bug fixed
gitoleg d925218
bug fixed again
gitoleg ab074a4
updated after review
gitoleg 5fd6436
refactoring and bug fixing
gitoleg 32c1e62
const propagation in ssa form
gitoleg 2512d01
adds a level of optimization
gitoleg 87bf62b
refactored and reduced memory usage
gitoleg 1b8806b
added attribute for updated terms
gitoleg f7ad7f9
refactoring
gitoleg f1fac20
fixed a bug in sub's digest
gitoleg c7f3a75
renamed dead-code-elimination to optimization
gitoleg f071c7d
updated testsuite
gitoleg e5afe93
bug fixed
gitoleg 79c2476
feqw updates after review
gitoleg 3c48e3a
edited doc
gitoleg 11006f4
issue a warning on --no-dead-code-elimination
gitoleg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
added attribute for updated terms
commit 1b8806b7ebe9592c593d673958f9492ab981fc7e
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
open Core_kernel | ||
open Bap.Std | ||
open Regular.Std | ||
|
||
type jmp_update = { | ||
cond : exp; | ||
kind : jmp_kind; | ||
} | ||
|
||
type update = Rhs of exp | Jmp of jmp_update | ||
|
||
type t = { | ||
deads : Tid.Set.t; | ||
updates : update Tid.Map.t; | ||
} | ||
|
||
let updated_term = Value.Tag.register (module Unit) | ||
~name:"updated-term" | ||
~uuid:"d21d76fa-12dd-470f-902e-f0e890e382d3" | ||
|
||
let mark_updated t = Term.set_attr t updated_term () | ||
let is_updated t = Option.is_some (Term.get_attr t updated_term) | ||
|
||
let drop_index = (object | ||
inherit Exp.mapper | ||
method! map_sym var = Var.base var | ||
end)#map_exp | ||
|
||
let updates_of_sub sub = | ||
let fold t cls init ~f = Seq.fold (Term.enum cls t) ~init ~f in | ||
let update_rhs updates d = | ||
let rhs = drop_index (Def.rhs d) in | ||
Map.add updates (Term.tid d) (Rhs rhs) in | ||
let update_jmp updates j = | ||
let j = Jmp.map_exp ~f:drop_index j in | ||
let data = Jmp {cond = Jmp.cond j; kind = Jmp.kind j} in | ||
Map.add updates (Term.tid j) data in | ||
let add_if add updates t = | ||
if is_updated t then add updates t else updates in | ||
fold sub blk_t Tid.Map.empty ~f:(fun updates b -> | ||
fold b def_t updates ~f:(add_if update_rhs) |> | ||
fold b jmp_t ~f:(add_if update_jmp)) | ||
|
||
let create ~deads sub = {deads; updates = updates_of_sub sub} | ||
|
||
let apply sub {deads; updates} = | ||
let apply_to_def d = | ||
if Set.mem deads (Term.tid d) then None | ||
else | ||
match Map.find updates (Term.tid d) with | ||
| None -> Some d | ||
| Some (Rhs e) -> Some (Def.with_rhs d e) | ||
| _ -> assert false in | ||
let apply_to_jmp j = | ||
match Map.find updates (Term.tid j) with | ||
| None -> j | ||
| Some (Jmp {cond; kind}) -> | ||
let j = Jmp.with_cond j cond in | ||
Jmp.with_kind j kind | ||
| _ -> assert false in | ||
Term.map blk_t sub ~f:(fun b -> | ||
Term.filter_map def_t b ~f:apply_to_def |> | ||
Term.map jmp_t ~f:apply_to_jmp) | ||
|
||
include Data.Make(struct | ||
type nonrec t = t | ||
let version = "0.1" | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.