mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-25 21:18:26 +02:00
glsl: Refactor logic for determining whether to lower return statements.
Previously, do_lower_jumps.cpp determined whether to lower return
statements in ir_lower_jumps_visitor::should_lower_jumps(). Moved
this logic to ir_lower_jumps_visitor::visit(ir_function_signature *),
so that it can be used in determining whether to lower a return
statement at the end of a function.
(cherry picked from commit dbaa2e627e)
This commit is contained in:
parent
934c7a0661
commit
d1786cea1c
1 changed files with 12 additions and 7 deletions
|
|
@ -146,16 +146,17 @@ struct function_record
|
|||
ir_function_signature* signature;
|
||||
ir_variable* return_flag; /* used to break out of all loops and then jump to the return instruction */
|
||||
ir_variable* return_value;
|
||||
bool is_main;
|
||||
bool lower_return;
|
||||
unsigned nesting_depth;
|
||||
|
||||
function_record(ir_function_signature* p_signature = 0)
|
||||
function_record(ir_function_signature* p_signature = 0,
|
||||
bool lower_return = false)
|
||||
{
|
||||
this->signature = p_signature;
|
||||
this->return_flag = 0;
|
||||
this->return_value = 0;
|
||||
this->nesting_depth = 0;
|
||||
this->is_main = this->signature && (strcmp(this->signature->function_name(), "main") == 0);
|
||||
this->lower_return = lower_return;
|
||||
}
|
||||
|
||||
ir_variable* get_return_flag()
|
||||
|
|
@ -274,10 +275,8 @@ struct ir_lower_jumps_visitor : public ir_control_flow_visitor {
|
|||
/* never lower return at the end of a this->function */
|
||||
if(this->function.nesting_depth == 0 && ir->get_next()->is_tail_sentinel())
|
||||
lower = false;
|
||||
else if (this->function.is_main)
|
||||
lower = lower_main_return;
|
||||
else
|
||||
lower = lower_sub_return;
|
||||
lower = this->function.lower_return;
|
||||
break;
|
||||
}
|
||||
return lower;
|
||||
|
|
@ -530,9 +529,15 @@ lower_continue:
|
|||
assert(!this->function.signature);
|
||||
assert(!this->loop.loop);
|
||||
|
||||
bool lower_return;
|
||||
if (strcmp(ir->function_name(), "main") == 0)
|
||||
lower_return = lower_main_return;
|
||||
else
|
||||
lower_return = lower_sub_return;
|
||||
|
||||
function_record saved_function = this->function;
|
||||
loop_record saved_loop = this->loop;
|
||||
this->function = function_record(ir);
|
||||
this->function = function_record(ir, lower_return);
|
||||
this->loop = loop_record(ir);
|
||||
|
||||
assert(!this->loop.loop);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue