Skip to content

Commit dd5a694

Browse files
authored
Merge pull request #2112 from certik/asr_pass
Initial pass infrastructure
2 parents de44dbf + 4562866 commit dd5a694

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+202
-133
lines changed

src/libasr/codegen/asr_to_x86.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ Result<int> asr_to_x86(ASR::TranslationUnit_t &asr, Allocator &al,
577577

578578
{
579579
auto t1 = std::chrono::high_resolution_clock::now();
580-
pass_wrap_global_stmts_into_function(al, asr, pass_options);
580+
pass_wrap_global_stmts(al, asr, pass_options);
581581
auto t2 = std::chrono::high_resolution_clock::now();
582582
time_pass_global = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count();
583583
}

src/libasr/gen_pass.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
passes = [
2+
# name, optional prefix (pass_PREFIX_name())
3+
("arr_slice", "replace"),
4+
("array_op", "replace"),
5+
("class_constructor", "replace"),
6+
("dead_code_removal", ""),
7+
("div_to_mul", "replace"),
8+
("do_loops", "replace"),
9+
("flip_sign", "replace"),
10+
("fma", "replace"),
11+
("for_all", "replace"),
12+
("global_stmts", "wrap"),
13+
("global_stmts_program", "wrap"),
14+
("global_symbols", "wrap"),
15+
("implied_do_loops", "replace"),
16+
("init_expr", "replace"),
17+
("inline_function_calls", ""),
18+
("instantiate_template", ""),
19+
("intrinsic_function", "replace"),
20+
("loop_unroll", ""),
21+
("loop_vectorise", ""),
22+
("nested_vars", ""),
23+
("param_to_const", "replace"),
24+
("pass_array_by_data", ""),
25+
("pass_compare", ""),
26+
("pass_list_expr", ""),
27+
("print_arr", "replace"),
28+
("print_list_tuple", "replace"),
29+
("print_struct_type", "replace"),
30+
("select_case", "replace"),
31+
("sign_from_value", "replace"),
32+
("subroutine_from_function", "create"),
33+
("transform_optional_argument_functions", ""),
34+
("unused_functions", ""),
35+
("update_array_dim_intrinsic_calls", ""),
36+
("where", "replace"),
37+
]
38+
39+
40+
41+
for pass_name, prefix in passes:
42+
print(f"Processing: {pass_name}")
43+
name = pass_name
44+
if name.startswith("pass"):
45+
name = name[5:]
46+
name_up = name.upper()
47+
if prefix != "":
48+
prefix += "_"
49+
arguments = r"""Allocator &al, ASR::TranslationUnit_t &unit,
50+
const PassOptions &pass_options"""
51+
return_type = "void"
52+
if pass_name == "instantiate_template":
53+
arguments = r"""Allocator &al,
54+
std::map<std::string, ASR::ttype_t*> subs, std::map<std::string, ASR::symbol_t*> rt_subs,
55+
SymbolTable *current_scope, std::string new_func_name, ASR::symbol_t *sym"""
56+
return_type = "ASR::symbol_t*"
57+
58+
59+
60+
header = rf"""#ifndef LIBASR_PASS_{name_up}_H
61+
#define LIBASR_PASS_{name_up}_H
62+
63+
#include <libasr/asr.h>
64+
#include <libasr/utils.h>
65+
66+
namespace LCompilers {{
67+
68+
{return_type} pass_{prefix}{name}({arguments});
69+
70+
}} // namespace LCompilers
71+
72+
#endif // LIBASR_PASS_{name_up}_H
73+
"""
74+
header_filename = f"pass/{pass_name}.h"
75+
f = open(header_filename, "w")
76+
f.write(header)

src/libasr/pass/arr_slice.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
#ifndef LFORTRAN_PASS_ARR_SLICE_H
2-
#define LFORTRAN_PASS_ARR_SLICE_H
1+
#ifndef LIBASR_PASS_ARR_SLICE_H
2+
#define LIBASR_PASS_ARR_SLICE_H
33

44
#include <libasr/asr.h>
55
#include <libasr/utils.h>
66

77
namespace LCompilers {
88

99
void pass_replace_arr_slice(Allocator &al, ASR::TranslationUnit_t &unit,
10-
const LCompilers::PassOptions& pass_options);
10+
const PassOptions &pass_options);
1111

1212
} // namespace LCompilers
1313

14-
#endif // LFORTRAN_PASS_ARR_SLICE_H
14+
#endif // LIBASR_PASS_ARR_SLICE_H

src/libasr/pass/array_op.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
#ifndef LFORTRAN_PASS_ARRAY_OP_H
2-
#define LFORTRAN_PASS_ARRAY_OP_H
1+
#ifndef LIBASR_PASS_ARRAY_OP_H
2+
#define LIBASR_PASS_ARRAY_OP_H
33

44
#include <libasr/asr.h>
55
#include <libasr/utils.h>
66

77
namespace LCompilers {
88

99
void pass_replace_array_op(Allocator &al, ASR::TranslationUnit_t &unit,
10-
const LCompilers::PassOptions& pass_options);
10+
const PassOptions &pass_options);
1111

1212
} // namespace LCompilers
1313

14-
#endif // LFORTRAN_PASS_ARRAY_OP_H
14+
#endif // LIBASR_PASS_ARRAY_OP_H
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
#ifndef LFORTRAN_PASS_CLASS_CONSTRUCTOR_H
2-
#define LFORTRAN_PASS_CLASS_CONSTRUCTOR_H
1+
#ifndef LIBASR_PASS_CLASS_CONSTRUCTOR_H
2+
#define LIBASR_PASS_CLASS_CONSTRUCTOR_H
33

44
#include <libasr/asr.h>
55
#include <libasr/utils.h>
66

77
namespace LCompilers {
88

99
void pass_replace_class_constructor(Allocator &al, ASR::TranslationUnit_t &unit,
10-
const LCompilers::PassOptions& pass_options);
10+
const PassOptions &pass_options);
1111

1212
} // namespace LCompilers
1313

14-
#endif // LFORTRAN_PASS_CLASS_CONSTRUCTOR_H
14+
#endif // LIBASR_PASS_CLASS_CONSTRUCTOR_H

src/libasr/pass/dead_code_removal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
namespace LCompilers {
88

99
void pass_dead_code_removal(Allocator &al, ASR::TranslationUnit_t &unit,
10-
const LCompilers::PassOptions& pass_options);
10+
const PassOptions &pass_options);
1111

1212
} // namespace LCompilers
1313

14-
#endif
14+
#endif // LIBASR_PASS_DEAD_CODE_REMOVAL_H

src/libasr/pass/div_to_mul.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace LCompilers {
88

99
void pass_replace_div_to_mul(Allocator &al, ASR::TranslationUnit_t &unit,
10-
const LCompilers::PassOptions& pass_options);
10+
const PassOptions &pass_options);
1111

1212
} // namespace LCompilers
1313

src/libasr/pass/do_loops.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
#ifndef LFORTRAN_PASS_DO_LOOPS_H
2-
#define LFORTRAN_PASS_DO_LOOPS_H
1+
#ifndef LIBASR_PASS_DO_LOOPS_H
2+
#define LIBASR_PASS_DO_LOOPS_H
33

44
#include <libasr/asr.h>
55
#include <libasr/utils.h>
66

77
namespace LCompilers {
88

99
void pass_replace_do_loops(Allocator &al, ASR::TranslationUnit_t &unit,
10-
const LCompilers::PassOptions& pass_options);
10+
const PassOptions &pass_options);
1111

1212
} // namespace LCompilers
1313

14-
#endif // LFORTRAN_PASS_DO_LOOPS_H
14+
#endif // LIBASR_PASS_DO_LOOPS_H

src/libasr/pass/flip_sign.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace LCompilers {
88

99
void pass_replace_flip_sign(Allocator &al, ASR::TranslationUnit_t &unit,
10-
const LCompilers::PassOptions& pass_options);
10+
const PassOptions &pass_options);
1111

1212
} // namespace LCompilers
1313

src/libasr/pass/fma.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace LCompilers {
88

99
void pass_replace_fma(Allocator &al, ASR::TranslationUnit_t &unit,
10-
const LCompilers::PassOptions& pass_options);
10+
const PassOptions &pass_options);
1111

1212
} // namespace LCompilers
1313

0 commit comments

Comments
 (0)