-
Notifications
You must be signed in to change notification settings - Fork 532
Get list of bb start/end eas for loops in extract.py
#1253
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -291,6 +291,7 @@ def extract_function_loop(f): | |
| parse if a function has a loop | ||
| """ | ||
| edges = [] | ||
| bb_by_va = {bb.va: bb for bb in f.basic_blocks} | ||
|
|
||
| for bb in f.basic_blocks: | ||
| if len(bb.instructions) > 0: | ||
|
|
@@ -313,8 +314,15 @@ def extract_function_loop(f): | |
| comps = strongly_connected_components(g) | ||
| for comp in comps: | ||
| if len(comp) >= 2: | ||
| # TODO get list of bb start/end eas | ||
| yield Loop(comp) | ||
| loop_bb_ranges = [] | ||
| for bb_va in sorted(comp): | ||
| bb = bb_by_va.get(bb_va) | ||
| if bb is None: | ||
| continue | ||
|
|
||
| loop_bb_ranges.append((bb.va, bb.va + bb.size)) | ||
|
|
||
| yield Loop(comp, bb_ranges=loop_bb_ranges) | ||
|
Comment on lines
315
to
+325
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implementing lazy initialization for bb_by_va = None
for comp in comps:
if len(comp) >= 2:
if bb_by_va is None:
bb_by_va = {bb.va: bb for bb in f.basic_blocks}
loop_bb_ranges = []
for bb_va in sorted(comp):
bb = bb_by_va.get(bb_va)
if bb is None:
continue
loop_bb_ranges.append((bb.va, bb.va + bb.size))
yield Loop(comp, bb_ranges=loop_bb_ranges) |
||
|
|
||
|
|
||
| FUNCTION_HANDLERS = ( | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert this please |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert this |
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.
The dictionary
bb_by_vais created for every function, even those without loops. Since most functions do not contain loops (SCCs of size >= 2), this is an unnecessary overhead. It is more efficient to initialize this dictionary lazily only when a loop is detected.