Skip to content

Commit 468ff6d

Browse files
committed
Skip passes that are re-writes and handled in C
1 parent a166236 commit 468ff6d

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/bin/lpython.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ int emit_c(const std::string &infile,
296296

297297
// Apply ASR passes
298298
LCompilers::PassOptions pass_options;
299-
pass_manager.use_default_passes();
299+
pass_manager.use_default_passes(true);
300300
pass_options.run_fun = "f";
301301
pass_options.always_run = true;
302302
pass_manager.apply_passes(al, asr, pass_options, diagnostics);
@@ -347,7 +347,7 @@ int emit_c_to_file(const std::string &infile, const std::string &outfile,
347347

348348
// Apply ASR passes
349349
LCompilers::PassOptions pass_options;
350-
pass_manager.use_default_passes();
350+
pass_manager.use_default_passes(true);
351351
pass_options.run_fun = "f";
352352
pass_options.always_run = true;
353353
pass_manager.apply_passes(al, asr, pass_options, diagnostics);

src/libasr/pass/pass_manager.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace LCompilers {
5959
std::vector<std::string> _passes;
6060
std::vector<std::string> _with_optimization_passes;
6161
std::vector<std::string> _user_defined_passes;
62-
std::vector<std::string> _skip_passes;
62+
std::vector<std::string> _skip_passes, _c_skip_passes;
6363
std::map<std::string, pass_function> _passes_db = {
6464
{"do_loops", &pass_replace_do_loops},
6565
{"global_stmts", &pass_wrap_global_stmts_into_function},
@@ -90,6 +90,7 @@ namespace LCompilers {
9090

9191
bool is_fast;
9292
bool apply_default_passes;
93+
bool c_skip_pass; // This will contain the passes that are to be skipped in C
9394

9495
void _apply_passes(Allocator& al, ASR::TranslationUnit_t* asr,
9596
std::vector<std::string>& passes, PassOptions &pass_options,
@@ -103,6 +104,9 @@ namespace LCompilers {
103104
if (rtlib && passes[i] == "unused_functions") continue;
104105
if( std::find(_skip_passes.begin(), _skip_passes.end(), passes[i]) != _skip_passes.end())
105106
continue;
107+
if (c_skip_pass && std::find(_c_skip_passes.begin(),
108+
_c_skip_passes.end(), passes[i]) != _c_skip_passes.end())
109+
continue;
106110
_passes_db[passes[i]](al, *asr, pass_options);
107111
#if defined(WITH_LFORTRAN_ASSERT)
108112
if (!asr_verify(*asr, true, diagnostics)) {
@@ -142,7 +146,8 @@ namespace LCompilers {
142146
}
143147
}
144148

145-
PassManager(): is_fast{false}, apply_default_passes{false} {
149+
PassManager(): is_fast{false}, apply_default_passes{false},
150+
c_skip_pass{false} {
146151
_passes = {
147152
"global_stmts",
148153
"init_expr",
@@ -191,6 +196,12 @@ namespace LCompilers {
191196
"inline_function_calls"
192197
};
193198

199+
// These are well re-write passes which are already handled
200+
// appropriately in C backend.
201+
_c_skip_passes = {
202+
"pass_list_expr",
203+
"print_list_tuple"
204+
};
194205
_user_defined_passes.clear();
195206
}
196207

@@ -227,8 +238,9 @@ namespace LCompilers {
227238
is_fast = false;
228239
}
229240

230-
void use_default_passes() {
241+
void use_default_passes(bool _c_skip_pass=false) {
231242
apply_default_passes = true;
243+
c_skip_pass = _c_skip_pass;
232244
}
233245

234246
void do_not_use_default_passes() {

0 commit comments

Comments
 (0)