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
c63b72a6
Commit
c63b72a6
authored
2 months ago
by
Russel Arbore
Browse files
Options
Downloads
Patches
Plain Diff
cleanup fork_guard_elim
parent
0bad572f
No related branches found
No related tags found
1 merge request
!103
Forkify + Loop Canonicalization + Initial Fork Fission
Pipeline
#201251
passed
2 months ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hercules_opt/src/fork_concat_split.rs
+2
-1
2 additions, 1 deletion
hercules_opt/src/fork_concat_split.rs
hercules_opt/src/fork_guard_elim.rs
+22
-31
22 additions, 31 deletions
hercules_opt/src/fork_guard_elim.rs
with
24 additions
and
32 deletions
hercules_opt/src/fork_concat_split.rs
+
2
−
1
View file @
c63b72a6
...
@@ -7,7 +7,8 @@ use crate::*;
...
@@ -7,7 +7,8 @@ use crate::*;
/*
/*
* Split multi-dimensional fork-joins into separate one-dimensional fork-joins.
* Split multi-dimensional fork-joins into separate one-dimensional fork-joins.
* Useful for code generation.
* Useful for code generation. A single iteration of `fork_split` only splits
* at most one fork-join, it must be called repeatedly to split all fork-joins.
*/
*/
pub
fn
fork_split
(
pub
fn
fork_split
(
editor
:
&
mut
FunctionEditor
,
editor
:
&
mut
FunctionEditor
,
...
...
This diff is collapsed.
Click to expand it.
hercules_opt/src/fork_guard_elim.rs
+
22
−
31
View file @
c63b72a6
use
std
::
collections
::{
HashMap
,
HashSet
};
use
std
::
collections
::{
HashMap
,
HashSet
};
use
either
::
Either
;
use
either
::
Either
;
use
hercules_ir
::
get_uses_mut
;
use
hercules_ir
::
ir
::
*
;
use
hercules_ir
::
ImmutableDefUseMap
;
use
crate
::
FunctionEditor
;
use
hercules_ir
::
*
;
use
crate
::
*
;
/*
/*
* This is a Hercules IR transformation that:
* This is a Hercules IR transformation that:
...
@@ -20,20 +19,6 @@ use crate::FunctionEditor;
...
@@ -20,20 +19,6 @@ use crate::FunctionEditor;
* guard remains and in these cases the guard is no longer needed.
* guard remains and in these cases the guard is no longer needed.
*/
*/
/* Given a node index and the node itself, return None if the node is not
* a guarded fork where we can eliminate the guard.
* If the node is a fork with a guard we can eliminate returns a tuple of
* - This node's NodeID
* - The replication factor of the fork
* - The ID of the if of the guard
* - The ID of the projections of the if
* - The guard's predecessor
* - A map of NodeIDs for the phi nodes to the reduce they should be replaced
* with, and also the region that joins the guard's branches mapping to the
* fork's join NodeID
* - If the replication factor is a max that can be eliminated.
*/
// Simplify factors through max
// Simplify factors through max
enum
Factor
{
enum
Factor
{
Max
(
usize
,
DynamicConstantID
),
Max
(
usize
,
DynamicConstantID
),
...
@@ -61,6 +46,19 @@ struct GuardedFork {
...
@@ -61,6 +46,19 @@ struct GuardedFork {
factor
:
Factor
,
// The factor that matches the guard
factor
:
Factor
,
// The factor that matches the guard
}
}
/* Given a node index and the node itself, return None if the node is not
* a guarded fork where we can eliminate the guard.
* If the node is a fork with a guard we can eliminate returns a tuple of
* - This node's NodeID
* - The replication factor of the fork
* - The ID of the if of the guard
* - The ID of the projections of the if
* - The guard's predecessor
* - A map of NodeIDs for the phi nodes to the reduce they should be replaced
* with, and also the region that joins the guard's branches mapping to the
* fork's join NodeID
* - If the replication factor is a max that can be eliminated.
*/
fn
guarded_fork
(
fn
guarded_fork
(
editor
:
&
mut
FunctionEditor
,
editor
:
&
mut
FunctionEditor
,
fork_join_map
:
&
HashMap
<
NodeID
,
NodeID
>
,
fork_join_map
:
&
HashMap
<
NodeID
,
NodeID
>
,
...
@@ -73,8 +71,7 @@ fn guarded_fork(
...
@@ -73,8 +71,7 @@ fn guarded_fork(
return
None
;
return
None
;
};
};
let
factors
=
factors
.iter
()
.enumerate
()
.map
(|(
idx
,
dc
)|
{
let
mut
factors
=
factors
.iter
()
.enumerate
()
.map
(|(
idx
,
dc
)|
{
// FIXME: Can we hide .idx() in an impl Index or something so we don't index Vec<Nodes> iwht DynamicConstantId.idx()
let
DynamicConstant
::
Max
(
l
,
r
)
=
*
editor
.get_dynamic_constant
(
*
dc
)
else
{
let
DynamicConstant
::
Max
(
l
,
r
)
=
*
editor
.get_dynamic_constant
(
*
dc
)
else
{
return
Factor
::
Normal
(
idx
,
*
dc
);
return
Factor
::
Normal
(
idx
,
*
dc
);
};
};
...
@@ -140,24 +137,22 @@ fn guarded_fork(
...
@@ -140,24 +137,22 @@ fn guarded_fork(
}
}
// Match Factor
// Match Factor
let
factor
=
factors
.clone
()
.find
(|
factor
|
{
let
factor
=
factors
.find
(|
factor
|
{
// This clone on the dc is painful.
match
(
match
(
&
function
.nodes
[
pattern_factor
.idx
()],
&
function
.nodes
[
pattern_factor
.idx
()],
editor
.get_dynamic_constant
(
factor
.get_id
())
.clone
()
,
&*
editor
.get_dynamic_constant
(
factor
.get_id
()),
)
{
)
{
(
Node
::
Constant
{
id
},
DynamicConstant
::
Constant
(
v
))
=>
{
(
Node
::
Constant
{
id
},
DynamicConstant
::
Constant
(
v
))
=>
{
let
Constant
::
UnsignedInteger64
(
pattern_v
)
=
*
editor
.get_constant
(
*
id
)
let
Constant
::
UnsignedInteger64
(
pattern_v
)
=
*
editor
.get_constant
(
*
id
)
else
{
else
{
return
false
;
return
false
;
};
};
pattern_v
==
(
v
as
u64
)
pattern_v
==
(
*
v
as
u64
)
}
}
(
Node
::
DynamicConstant
{
id
},
_
)
=>
*
id
==
factor
.get_id
(),
(
Node
::
DynamicConstant
{
id
},
_
)
=>
*
id
==
factor
.get_id
(),
_
=>
false
,
_
=>
false
,
}
}
});
});
// return Factor
factor
factor
})
})
}
}
...
@@ -184,12 +179,10 @@ fn guarded_fork(
...
@@ -184,12 +179,10 @@ fn guarded_fork(
}
}
// Match Factor
// Match Factor
// FIXME: Implement dc / constant matching as in case where branch_idx == 1
let
factor
=
factors
.find
(|
factor
|
{
let
factor
=
factors
.clone
()
.find
(|
factor
|
{
function
.nodes
[
pattern_factor
.idx
()]
.try_dynamic_constant
()
function
.nodes
[
pattern_factor
.idx
()]
.try_dynamic_constant
()
==
Some
(
factor
.get_id
())
==
Some
(
factor
.get_id
())
});
});
// return Factor
factor
factor
})
})
}
else
{
}
else
{
...
@@ -229,7 +222,7 @@ fn guarded_fork(
...
@@ -229,7 +222,7 @@ fn guarded_fork(
}
else
{
}
else
{
return
None
;
return
None
;
};
};
// Other predecessor needs to be the other
read
from the guard's if
// Other predecessor needs to be the other
projection
from the guard's if
let
Node
::
Projection
{
let
Node
::
Projection
{
control
:
if_node2
,
control
:
if_node2
,
ref
selection
,
ref
selection
,
...
@@ -317,8 +310,6 @@ fn guarded_fork(
...
@@ -317,8 +310,6 @@ fn guarded_fork(
/*
/*
* Top level function to run fork guard elimination, as described above.
* Top level function to run fork guard elimination, as described above.
* Deletes nodes by setting nodes to gravestones. Works with a function already
* containing gravestones.
*/
*/
pub
fn
fork_guard_elim
(
editor
:
&
mut
FunctionEditor
,
fork_join_map
:
&
HashMap
<
NodeID
,
NodeID
>
)
{
pub
fn
fork_guard_elim
(
editor
:
&
mut
FunctionEditor
,
fork_join_map
:
&
HashMap
<
NodeID
,
NodeID
>
)
{
let
guard_info
=
editor
let
guard_info
=
editor
...
...
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