Skip to content

Add an option to skip pass in default pipeline #1069

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

Merged
merged 2 commits into from
Jan 10, 2023
Merged
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
4 changes: 3 additions & 1 deletion src/bin/lpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,7 @@ int main(int argc, char *argv[])
bool show_errors = false;
bool with_intrinsic_modules = false;
std::string arg_pass;
std::string skip_pass;
bool arg_no_color = false;
bool show_llvm = false;
bool show_asm = false;
Expand Down Expand Up @@ -1363,6 +1364,7 @@ int main(int argc, char *argv[])
app.add_flag("--indent", compiler_options.indent, "Indented print ASR/AST");
app.add_flag("--tree", compiler_options.tree, "Tree structure print ASR/AST");
app.add_option("--pass", arg_pass, "Apply the ASR pass and show ASR (implies --show-asr)");
app.add_option("--skip-pass", skip_pass, "Skip an ASR pass in default pipeline");
app.add_flag("--disable-main", compiler_options.disable_main, "Do not generate any code for the `main` function");
app.add_flag("--symtab-only", compiler_options.symtab_only, "Only create symbol tables in ASR (skip executable stmt)");
app.add_flag("--time-report", time_report, "Show compilation time report");
Expand Down Expand Up @@ -1539,7 +1541,7 @@ int main(int argc, char *argv[])
// return emit_c_preprocessor(arg_file, compiler_options);
// }

lpython_pass_manager.parse_pass_arg(arg_pass);
lpython_pass_manager.parse_pass_arg(arg_pass, skip_pass);
if (show_tokens) {
return emit_tokens(arg_file, true, compiler_options);
}
Expand Down
58 changes: 34 additions & 24 deletions src/libasr/pass/pass_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

#include <map>
#include <vector>
#include <algorithm>

namespace LCompilers {

Expand All @@ -57,6 +58,7 @@ namespace LCompilers {
std::vector<std::string> _passes;
std::vector<std::string> _with_optimization_passes;
std::vector<std::string> _user_defined_passes;
std::vector<std::string> _skip_passes;
std::map<std::string, pass_function> _passes_db = {
{"do_loops", &LFortran::pass_replace_do_loops},
{"global_stmts", &LFortran::pass_wrap_global_stmts_into_function},
Expand Down Expand Up @@ -97,6 +99,8 @@ namespace LCompilers {
// Note: this is not enough for rtlib, we also need to include
// it
if (rtlib && passes[i] == "unused_functions") continue;
if( std::find(_skip_passes.begin(), _skip_passes.end(), passes[i]) != _skip_passes.end())
continue;
_passes_db[passes[i]](al, *asr, pass_options);
#if defined(WITH_LFORTRAN_ASSERT)
if (!LFortran::asr_verify(*asr, true, diagnostics)) {
Expand All @@ -107,6 +111,31 @@ namespace LCompilers {
}
}

void _parse_pass_arg(std::string& arg, std::vector<std::string>& passes) {
if (arg == "") return;

std::string current_pass = "";
for( size_t i = 0; i < arg.size(); i++ ) {
char ch = arg[i];
if (ch != ' ' && ch != ',') {
current_pass.push_back(ch);
}
if (ch == ',' || i == arg.size() - 1) {
current_pass = LFortran::to_lower(current_pass);
if( _passes_db.find(current_pass) == _passes_db.end() ) {
std::cerr << current_pass << " isn't supported yet.";
std::cerr << " Only the following passes are supported:- "<<std::endl;
for( auto it: _passes_db ) {
std::cerr << it.first << std::endl;
}
exit(1);
}
passes.push_back(current_pass);
current_pass.clear();
}
}
}

public:

bool rtlib=false;
Expand Down Expand Up @@ -157,34 +186,15 @@ namespace LCompilers {
};

_user_defined_passes.clear();
_skip_passes.clear();
}

void parse_pass_arg(std::string& arg_pass) {
void parse_pass_arg(std::string& arg_pass, std::string& skip_pass) {
_user_defined_passes.clear();
if (arg_pass == "") {
return ;
}
_skip_passes.clear();

std::string current_pass = "";
for( size_t i = 0; i < arg_pass.size(); i++ ) {
char ch = arg_pass[i];
if (ch != ' ' && ch != ',') {
current_pass.push_back(ch);
}
if (ch == ',' || i == arg_pass.size() - 1) {
current_pass = LFortran::to_lower(current_pass);
if( _passes_db.find(current_pass) == _passes_db.end() ) {
std::cerr << current_pass << " isn't supported yet.";
std::cerr << " Only the following passes are supported:- "<<std::endl;
for( auto it: _passes_db ) {
std::cerr << it.first << std::endl;
}
exit(1);
}
_user_defined_passes.push_back(current_pass);
current_pass.clear();
}
}
_parse_pass_arg(arg_pass, _user_defined_passes);
_parse_pass_arg(skip_pass, _skip_passes);
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍🏻.

}

void apply_passes(Allocator& al, LFortran::ASR::TranslationUnit_t* asr,
Expand Down