Skip to content

Commit f4d6b11

Browse files
authored
Merge pull request #1060 from czgdp1807/inline
Respect ``@inline`` decorator in LLVM backend
2 parents a03d6a5 + 85e4316 commit f4d6b11

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/libasr/pass/inline_function_calls.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class InlineFunctionCallVisitor : public PassUtils::PassVisitor<InlineFunctionCa
4545

4646
bool from_inline_function_call, inlining_function;
4747
bool fixed_duplicated_expr_stmt;
48+
bool is_fast;
4849

4950
// Stores the local variables corresponding to the ones
5051
// present in function symbol table.
@@ -66,10 +67,12 @@ class InlineFunctionCallVisitor : public PassUtils::PassVisitor<InlineFunctionCa
6667

6768
bool function_inlined;
6869

69-
InlineFunctionCallVisitor(Allocator &al_, const std::string& rl_path_, bool inline_external_symbol_calls_)
70+
InlineFunctionCallVisitor(Allocator &al_, const std::string& rl_path_,
71+
bool inline_external_symbol_calls_, bool is_fast_)
7072
: PassVisitor(al_, nullptr),
7173
rl_path(rl_path_), function_result_var(nullptr),
7274
from_inline_function_call(false), inlining_function(false), fixed_duplicated_expr_stmt(false),
75+
is_fast(is_fast_),
7376
current_routine(""), inline_external_symbol_calls(inline_external_symbol_calls_),
7477
node_duplicator(al_), current_routine_scope(nullptr),
7578
label_generator(ASRUtils::LabelGenerator::get_instance()),
@@ -211,6 +214,10 @@ class InlineFunctionCallVisitor : public PassUtils::PassVisitor<InlineFunctionCa
211214
return ;
212215
}
213216

217+
if( !is_fast && !func->m_inline ) {
218+
return ;
219+
}
220+
214221
current_routine_scope = func->m_symtab;
215222

216223
ASR::expr_t* return_var = nullptr;
@@ -448,7 +455,7 @@ void pass_inline_function_calls(Allocator &al, ASR::TranslationUnit_t &unit,
448455
const LCompilers::PassOptions& pass_options) {
449456
std::string rl_path = pass_options.runtime_library_dir;
450457
bool inline_external_symbol_calls = pass_options.inline_external_symbol_calls;
451-
InlineFunctionCallVisitor v(al, rl_path, inline_external_symbol_calls);
458+
InlineFunctionCallVisitor v(al, rl_path, inline_external_symbol_calls, pass_options.fast);
452459
v.configure_node_duplicator(false);
453460
v.visit_TranslationUnit(unit);
454461
v.configure_node_duplicator(true);

src/libasr/pass/pass_manager.h

+3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ namespace LCompilers {
101101
"do_loops",
102102
"forall",
103103
"select_case",
104+
"inline_function_calls",
104105
"unused_functions"
105106
};
106107

@@ -161,8 +162,10 @@ namespace LCompilers {
161162
void apply_passes(Allocator& al, LFortran::ASR::TranslationUnit_t* asr,
162163
PassOptions& pass_options) {
163164
if( !_user_defined_passes.empty() ) {
165+
pass_options.fast = true;
164166
_apply_passes(al, asr, _user_defined_passes, pass_options);
165167
} else if( apply_default_passes ) {
168+
pass_options.fast = is_fast;
166169
if( is_fast ) {
167170
_apply_passes(al, asr, _with_optimization_passes, pass_options);
168171
} else {

src/libasr/utils.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ namespace LCompilers {
5555
bool always_run; // for unused_functions pass
5656
bool inline_external_symbol_calls; // for inline_function_calls pass
5757
int64_t unroll_factor; // for loop_unroll pass
58+
bool fast; // is fast flag enabled.
5859

5960
PassOptions(): always_run(false), inline_external_symbol_calls(true),
60-
unroll_factor(32)
61+
unroll_factor(32), fast(false)
6162
{}
6263
};
6364

0 commit comments

Comments
 (0)