From 57448283d1e45f864add9b63886d641503be3aa9 Mon Sep 17 00:00:00 2001 From: redbopo Date: Wed, 31 Aug 2022 20:02:21 +0800 Subject: [PATCH 1/2] Add an option to skip pass in default pipeline --- src/bin/lpython.cpp | 4 +++- src/libasr/pass/pass_manager.h | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bin/lpython.cpp b/src/bin/lpython.cpp index d7a04f2229..0b89ea792c 100644 --- a/src/bin/lpython.cpp +++ b/src/bin/lpython.cpp @@ -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; @@ -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"); @@ -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); } diff --git a/src/libasr/pass/pass_manager.h b/src/libasr/pass/pass_manager.h index c342e8ca81..1a6ea630ea 100644 --- a/src/libasr/pass/pass_manager.h +++ b/src/libasr/pass/pass_manager.h @@ -86,6 +86,7 @@ namespace LCompilers { bool is_fast; bool apply_default_passes; + std::string skip_pass; void _apply_passes(Allocator& al, LFortran::ASR::TranslationUnit_t* asr, std::vector& passes, PassOptions &pass_options, @@ -159,8 +160,9 @@ namespace LCompilers { _user_defined_passes.clear(); } - void parse_pass_arg(std::string& arg_pass) { + void parse_pass_arg(std::string& arg_pass, std::string& s_pass) { _user_defined_passes.clear(); + skip_pass = s_pass; if (arg_pass == "") { return ; } From 6525a765d4b981ff40ecae0fb136e9ddcb34668b Mon Sep 17 00:00:00 2001 From: Smit-create Date: Mon, 9 Jan 2023 09:51:44 +0530 Subject: [PATCH 2/2] Enable skip multi passes. Also change option to --skip-pass, format like other options. --- src/bin/lpython.cpp | 2 +- src/libasr/pass/pass_manager.h | 60 +++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/bin/lpython.cpp b/src/bin/lpython.cpp index 0b89ea792c..7545ef5a16 100644 --- a/src/bin/lpython.cpp +++ b/src/bin/lpython.cpp @@ -1364,7 +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_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"); diff --git a/src/libasr/pass/pass_manager.h b/src/libasr/pass/pass_manager.h index 1a6ea630ea..acb57084d8 100644 --- a/src/libasr/pass/pass_manager.h +++ b/src/libasr/pass/pass_manager.h @@ -45,6 +45,7 @@ #include #include +#include namespace LCompilers { @@ -57,6 +58,7 @@ namespace LCompilers { std::vector _passes; std::vector _with_optimization_passes; std::vector _user_defined_passes; + std::vector _skip_passes; std::map _passes_db = { {"do_loops", &LFortran::pass_replace_do_loops}, {"global_stmts", &LFortran::pass_wrap_global_stmts_into_function}, @@ -86,7 +88,6 @@ namespace LCompilers { bool is_fast; bool apply_default_passes; - std::string skip_pass; void _apply_passes(Allocator& al, LFortran::ASR::TranslationUnit_t* asr, std::vector& passes, PassOptions &pass_options, @@ -98,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)) { @@ -108,6 +111,31 @@ namespace LCompilers { } } + void _parse_pass_arg(std::string& arg, std::vector& 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:- "<