Skip to content

Commit

Permalink
A better solution
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinChung2000 committed Jan 10, 2025
1 parent 7d1898a commit 4105d0a
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions calyx-opt/src/pass_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub struct PassManager {
passes: HashMap<String, PassClosure>,
/// Tracks alias for groups of passes that run together.
aliases: HashMap<String, Vec<String>>,
/// Tracks alias for groups of passes that run together before flatten.
aliases_cmd: HashMap<String, Vec<String>>,
// Track the help information for passes
help: HashMap<String, String>,
}
Expand Down Expand Up @@ -117,7 +119,21 @@ impl PassManager {
))
.into());
}
self.aliases.insert(name, passes);
self.aliases_cmd.insert(name.clone(), passes.clone());
let all_passes: Vec<String> = passes
.into_iter()
.flat_map(|pass| {
if self.aliases.contains_key(&pass) {
self.aliases[&pass].clone()
} else if self.passes.contains_key(&pass) {
vec![pass]
} else {
panic!("No pass or alias named: {}", pass)
}
})
.collect();

self.aliases.insert(name, all_passes);
Ok(())
}

Expand Down Expand Up @@ -149,7 +165,7 @@ impl PassManager {
});

// Push all aliases
let mut aliases = self.aliases.iter().collect::<Vec<_>>();
let mut aliases = self.aliases_cmd.iter().collect::<Vec<_>>();
aliases.sort_by(|kv1, kv2| kv1.0.cmp(kv2.0));
ret.push_str("\nAliases:\n");
aliases.iter().for_each(|(alias, passes)| {
Expand Down Expand Up @@ -258,23 +274,9 @@ impl PassManager {
dump_ir: bool,
) -> PassResult<()> {
let (passes, excl_set) = self.create_plan(incl, excl, insn)?;


// Expand all aliases in the list of passes.
let all_passes: Vec<String> = passes
.into_iter()
.flat_map(|pass| {
if self.aliases.contains_key(&pass) {
self.aliases[&pass].clone()
} else if self.passes.contains_key(&pass) {
vec![pass]
} else {
panic!("No pass or alias named: {}", pass)
}
})
.collect();

for name in all_passes {
for name in passes {
// Pass is known to exist because create_plan validates the
// names of passes.
let pass = &self.passes[&name];
Expand Down

0 comments on commit 4105d0a

Please sign in to comment.