Skip to content
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

Improve cmd options #2392

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 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,8 +119,8 @@ impl PassManager {
))
.into());
}
// Expand any aliases used in defining this alias.
let all_passes = 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) {
Expand All @@ -130,6 +132,7 @@ impl PassManager {
}
})
.collect();

self.aliases.insert(name, all_passes);
Ok(())
}
Expand Down Expand Up @@ -162,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<_>>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this change help with?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It allows printing the alias pass name instead of the fully expanded pass. So the help message at "all" will be "validate,pre-opt..." instead of the long chain of passes.

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 @@ -218,7 +221,7 @@ impl PassManager {

// Validate that names of passes in incl and excl sets are known
passes.iter().chain(excl_set.iter().chain(insertions.iter().flat_map(|(pass1, pass2)| vec![pass1, pass2]))).try_for_each(|pass| {
if !self.passes.contains_key(pass) {
if !self.passes.contains_key(pass) && !self.aliases.contains_key(pass) {
Err(Error::misc(format!(
"Unknown pass: {pass}. Run compiler with pass-help subcommand to view registered passes."
)))
Expand Down Expand Up @@ -272,6 +275,7 @@ impl PassManager {
) -> PassResult<()> {
let (passes, excl_set) = self.create_plan(incl, excl, insn)?;

// Expand all aliases in the list of passes.
for name in passes {
// Pass is known to exist because create_plan validates the
// names of passes.
Expand All @@ -284,6 +288,7 @@ impl PassManager {
let start = Instant::now();
pass(ctx)?;
if dump_ir {
println!("After pass: {}", name);
ir::Printer::write_context(
ctx,
true,
Expand Down
9 changes: 6 additions & 3 deletions src/cmdline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,22 @@ pub struct Opts {
#[argh(option, short = 'b', default = "BackendOpt::default()")]
pub backend: BackendOpt,

/// run this pass during execution
/// run a pass or passes during execution. You can supply multiple -p to specify the pass pipeline
/// and the passes will and executed in the order it passed in. i.e."-p p1 -p p2" and will run p1 then p2.
/// Accept alias. Default is "all"
#[argh(option, short = 'p')]
pub pass: Vec<String>,

/// disable pass during execution
#[argh(option, short = 'd', long = "disable-pass")]
pub disable_pass: Vec<String>,

/// extra options passed to the context
/// extra options passed to the context. The format is either -x pass:opt or -x pass:opt=val
#[argh(option, short = 'x', long = "extra-opt")]
pub extra_opts: Vec<String>,

/// establish a relative ordering of passes
/// establish a relative ordering of passes. "a:b" will move pass `b` after pass `a`.
/// Similar to the `-p` flag, you can supply multiple `-i` flags to specify multiple ordering constraints.
#[argh(option, short = 'i', long = "insert")]
pub insertions: Vec<String>,

Expand Down