Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Hercules
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
llvm
Hercules
Commits
44f49494
"...matmul/git@gitlab.engr.illinois.edu:llvm/hercules.git" did not exist on "8ee05f40278c5883ff4f89c353e24fce6f858656"
Commit
44f49494
authored
8 months ago
by
Ryan Ziegler
Browse files
Options
Downloads
Patches
Plain Diff
finalize
parent
d94294c4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!69
Dce dead calls
Pipeline
#200397
passed
8 months ago
Stage: build
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
hercules_opt/src/delete_uncalled.rs
+25
-11
25 additions, 11 deletions
hercules_opt/src/delete_uncalled.rs
hercules_opt/src/pass.rs
+48
-42
48 additions, 42 deletions
hercules_opt/src/pass.rs
juno_frontend/src/lib.rs
+2
-0
2 additions, 0 deletions
juno_frontend/src/lib.rs
with
75 additions
and
53 deletions
hercules_opt/src/delete_uncalled.rs
+
25
−
11
View file @
44f49494
extern
crate
bitvec
;
extern
crate
hercules_ir
;
use
self
::
bitvec
::
prelude
::
*
;
use
self
::
hercules_ir
::
callgraph
::
*
;
use
self
::
hercules_ir
::
ir
::
*
;
use
crate
::
*
;
pub
fn
delete_uncalled
(
editors
:
&
mut
Vec
<
FunctionEditor
>
,
callgraph
:
&
CallGraph
)
->
Vec
<
usize
>
{
/**
* First renumber functions by deleting all functions unreachable from any entry function.
* Then, updates all functions to use the new function numbering.
* Returns a vec where the element at index i is the new idx of the ith function (if it was not
* deleted).
*/
pub
fn
delete_uncalled
(
editors
:
&
mut
Vec
<
FunctionEditor
>
,
callgraph
:
&
CallGraph
,
)
->
Vec
<
Option
<
usize
>>
{
// Step 1. Identify which functions are not reachable from entry nodes using BFS.
let
mut
reachable
=
vec!
[
false
;
editors
.len
()];
let
mut
reachable
=
bit
vec!
[
u8
,
Lsb0
;
0
;
editors
.len
()];
let
mut
worklist
=
vec!
[];
for
(
idx
,
editor
)
in
editors
.iter
()
.enumerate
()
{
if
editor
.func
()
.entry
{
worklist
.push
(
idx
);
reachable
[
idx
]
=
true
;
reachable
.set
(
idx
,
true
)
;
}
}
while
let
Some
(
func_idx
)
=
worklist
.pop
()
{
for
callee
in
callgraph
.get_callees
(
FunctionID
::
new
(
func_idx
))
{
if
!
reachable
[
callee
.idx
()]
{
reachable
[
callee
.idx
()
]
=
true
;
reachable
.set
(
callee
.idx
()
,
true
)
;
worklist
.push
(
callee
.idx
());
}
}
...
...
@@ -27,19 +38,19 @@ pub fn delete_uncalled(editors: &mut Vec<FunctionEditor>, callgraph: &CallGraph)
// Step 2. Compute the new index of each function, which is obtained by
// deleteting all unreachable non-entry functions before it
let
mut
new_idx
=
vec!
[
std
::
usize
::
MAX
;
editors
.len
()];
let
mut
new_idx
=
vec!
[
None
;
editors
.len
()];
let
mut
deleted_count
=
0
;
for
idx
in
0
..
editors
.len
()
{
if
!
reachable
[
idx
]
{
deleted_count
+=
1
;
}
else
{
new_idx
[
idx
]
=
idx
-
deleted_count
;
new_idx
[
idx
]
=
Some
(
idx
-
deleted_count
)
;
}
}
// Step 3. Update all function callsites to use new indices. We
should
//
eventually handle the case where some edits fail, and just don't delete
//
functions that would cause the
fail
ure
s.
// Step 3. Update all function callsites to use new indices. We
assume
//
that all nodes in all functions will be mutable, so panic if any
//
edit
fails.
for
editor
in
editors
.iter_mut
()
{
let
callsites
:
Vec
<
_
>
=
editor
.node_ids
()
...
...
@@ -47,18 +58,21 @@ pub fn delete_uncalled(editors: &mut Vec<FunctionEditor>, callgraph: &CallGraph)
.collect
();
for
callsite
in
callsites
{
editor
.edit
(|
mut
edit
|
{
let
success
=
editor
.edit
(|
mut
edit
|
{
let
(
control
,
function
,
dynamic_constants
,
args
)
=
edit
.get_node
(
callsite
)
.try_call
()
.unwrap
();
let
new_node
=
edit
.add_node
(
Node
::
Call
{
control
,
function
:
FunctionID
::
new
(
new_idx
[
function
.idx
()]),
function
:
FunctionID
::
new
(
new_idx
[
function
.idx
()]
.unwrap
()
),
dynamic_constants
:
dynamic_constants
.clone
(),
args
:
args
.clone
(),
});
let
edit
=
edit
.delete_node
(
callsite
)
?
;
edit
.replace_all_uses
(
callsite
,
new_node
)
});
if
!
success
{
panic!
(
"Expected all delete_uncalled callsite edits to succeed!"
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
hercules_opt/src/pass.rs
+
48
−
42
View file @
44f49494
...
...
@@ -637,6 +637,50 @@ impl PassManager {
}
self
.clear_analyses
();
}
Pass
::
DeleteUncalled
=>
{
self
.make_def_uses
();
self
.make_callgraph
();
let
def_uses
=
self
.def_uses
.as_ref
()
.unwrap
();
let
callgraph
=
self
.callgraph
.as_ref
()
.unwrap
();
let
constants_ref
=
RefCell
::
new
(
std
::
mem
::
take
(
&
mut
self
.module.constants
));
let
dynamic_constants_ref
=
RefCell
::
new
(
std
::
mem
::
take
(
&
mut
self
.module.dynamic_constants
));
let
types_ref
=
RefCell
::
new
(
std
::
mem
::
take
(
&
mut
self
.module.types
));
// By default in an editor all nodes are mutable, which is desired in this case
// since we are only modifying the IDs of functions that we call.
let
mut
editors
:
Vec
<
_
>
=
zip
(
self
.module.functions
.iter_mut
(),
def_uses
.iter
())
.map
(|(
func
,
def_use
)|
{
FunctionEditor
::
new
(
func
,
&
constants_ref
,
&
dynamic_constants_ref
,
&
types_ref
,
def_use
,
)
})
.collect
();
let
new_idx
=
delete_uncalled
(
&
mut
editors
,
callgraph
);
self
.module.constants
=
constants_ref
.take
();
self
.module.dynamic_constants
=
dynamic_constants_ref
.take
();
self
.module.types
=
types_ref
.take
();
let
edits
:
Vec
<
_
>
=
editors
.into_iter
()
.map
(|
editor
|
editor
.edits
())
.collect
();
for
idx
in
0
..
edits
.len
()
{
if
let
Some
(
plans
)
=
self
.plans
.as_mut
()
{
repair_plan
(
&
mut
plans
[
idx
],
&
self
.module.functions
[
idx
],
&
edits
[
idx
]);
}
let
grave_mapping
=
self
.module.functions
[
idx
]
.delete_gravestones
();
if
let
Some
(
plans
)
=
self
.plans
.as_mut
()
{
plans
[
idx
]
.fix_gravestones
(
&
grave_mapping
);
}
}
self
.fix_deleted_functions
(
&
new_idx
);
self
.clear_analyses
();
}
Pass
::
Verify
=>
{
let
(
def_uses
,
...
...
@@ -787,46 +831,6 @@ impl PassManager {
file
.write_all
(
&
module_contents
)
.expect
(
"PANIC: Unable to write output module file contents."
);
}
Pass
::
DeleteUncalled
=>
{
self
.make_def_uses
();
self
.make_callgraph
();
let
def_uses
=
self
.def_uses
.as_ref
()
.unwrap
();
let
callgraph
=
self
.callgraph
.as_ref
()
.unwrap
();
let
constants_ref
=
RefCell
::
new
(
std
::
mem
::
take
(
&
mut
self
.module.constants
));
let
dynamic_constants_ref
=
RefCell
::
new
(
std
::
mem
::
take
(
&
mut
self
.module.dynamic_constants
));
let
types_ref
=
RefCell
::
new
(
std
::
mem
::
take
(
&
mut
self
.module.types
));
let
mut
editors
:
Vec
<
_
>
=
zip
(
self
.module.functions
.iter_mut
(),
def_uses
.iter
())
.map
(|(
func
,
def_use
)|
{
FunctionEditor
::
new
(
func
,
&
constants_ref
,
&
dynamic_constants_ref
,
&
types_ref
,
def_use
,
)
})
.collect
();
let
id_mapping
=
delete_uncalled
(
&
mut
editors
,
callgraph
);
self
.module.constants
=
constants_ref
.take
();
self
.module.dynamic_constants
=
dynamic_constants_ref
.take
();
self
.module.types
=
types_ref
.take
();
let
edits
:
Vec
<
_
>
=
editors
.into_iter
()
.map
(|
editor
|
editor
.edits
())
.collect
();
for
idx
in
0
..
edits
.len
()
{
if
let
Some
(
plans
)
=
self
.plans
.as_mut
()
{
repair_plan
(
&
mut
plans
[
idx
],
&
self
.module.functions
[
idx
],
&
edits
[
idx
]);
}
let
grave_mapping
=
self
.module.functions
[
idx
]
.delete_gravestones
();
if
let
Some
(
plans
)
=
self
.plans
.as_mut
()
{
plans
[
idx
]
.fix_gravestones
(
&
grave_mapping
);
}
}
self
.fix_deleted_functions
(
&
id_mapping
);
self
.clear_analyses
();
}
}
println!
(
"Ran pass: {:?}"
,
pass
);
}
...
...
@@ -872,12 +876,14 @@ impl PassManager {
self
.manifests
.unwrap
()
}
fn
fix_deleted_functions
(
&
mut
self
,
id_mapping
:
&
[
usize
])
{
fn
fix_deleted_functions
(
&
mut
self
,
id_mapping
:
&
[
Option
<
usize
>
])
{
let
mut
idx
=
0
;
// Rust does not like enumerate here, so use
// idx outside as a hack to make it happy.
self
.module.functions
.retain
(|
_
|
{
idx
+=
1
;
id_mapping
[
idx
-
1
]
<
std
::
usize
::
MAX
id_mapping
[
idx
-
1
]
.is_some
()
});
}
}
This diff is collapsed.
Click to expand it.
juno_frontend/src/lib.rs
+
2
−
0
View file @
44f49494
...
...
@@ -157,6 +157,8 @@ pub fn compile_ir(
if
x_dot
{
pm
.add_pass
(
hercules_opt
::
pass
::
Pass
::
Xdot
(
true
));
}
// Inlining may make some functions uncalled, so run this pass.
// In general, this should always be run after inlining.
add_pass!
(
pm
,
verify
,
DeleteUncalled
);
if
x_dot
{
pm
.add_pass
(
hercules_opt
::
pass
::
Pass
::
Xdot
(
true
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment