2010-04-07 11:46:26 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2010 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2010-11-17 10:43:10 -08:00
|
|
|
* \file opt_function_inlining.cpp
|
2010-04-07 11:46:26 -07:00
|
|
|
*
|
|
|
|
|
* Replaces calls to functions with the body of the function.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ir.h"
|
|
|
|
|
#include "ir_visitor.h"
|
|
|
|
|
#include "ir_function_inlining.h"
|
2010-04-16 12:53:46 -07:00
|
|
|
#include "ir_expression_flattening.h"
|
2010-04-07 11:46:26 -07:00
|
|
|
#include "glsl_types.h"
|
2010-07-29 12:40:49 +03:00
|
|
|
#include "program/hash_table.h"
|
2010-04-07 11:46:26 -07:00
|
|
|
|
2010-08-06 00:21:12 -07:00
|
|
|
static void
|
2013-09-30 12:54:57 -07:00
|
|
|
do_variable_replacement(exec_list *instructions,
|
|
|
|
|
ir_variable *orig,
|
|
|
|
|
ir_dereference *repl);
|
2010-08-06 00:21:12 -07:00
|
|
|
|
2012-05-29 16:18:37 -07:00
|
|
|
namespace {
|
|
|
|
|
|
2010-05-26 18:58:27 -07:00
|
|
|
class ir_function_inlining_visitor : public ir_hierarchical_visitor {
|
2010-05-05 11:45:30 -07:00
|
|
|
public:
|
|
|
|
|
ir_function_inlining_visitor()
|
|
|
|
|
{
|
2010-05-26 18:58:27 -07:00
|
|
|
progress = false;
|
2010-05-05 11:45:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual ~ir_function_inlining_visitor()
|
|
|
|
|
{
|
|
|
|
|
/* empty */
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-26 18:58:27 -07:00
|
|
|
virtual ir_visitor_status visit_enter(ir_expression *);
|
|
|
|
|
virtual ir_visitor_status visit_enter(ir_call *);
|
|
|
|
|
virtual ir_visitor_status visit_enter(ir_return *);
|
2010-05-26 17:42:03 -07:00
|
|
|
virtual ir_visitor_status visit_enter(ir_texture *);
|
2010-05-26 18:58:27 -07:00
|
|
|
virtual ir_visitor_status visit_enter(ir_swizzle *);
|
|
|
|
|
|
|
|
|
|
bool progress;
|
2010-05-05 11:45:30 -07:00
|
|
|
};
|
|
|
|
|
|
2012-05-29 16:18:37 -07:00
|
|
|
} /* unnamed namespace */
|
2010-04-07 11:46:26 -07:00
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
do_function_inlining(exec_list *instructions)
|
|
|
|
|
{
|
2010-05-26 18:58:27 -07:00
|
|
|
ir_function_inlining_visitor v;
|
2010-04-07 11:46:26 -07:00
|
|
|
|
2010-05-26 18:58:27 -07:00
|
|
|
v.run(instructions);
|
2010-04-07 11:46:26 -07:00
|
|
|
|
2010-05-26 18:58:27 -07:00
|
|
|
return v.progress;
|
2010-04-07 11:46:26 -07:00
|
|
|
}
|
|
|
|
|
|
2010-06-24 08:59:57 -07:00
|
|
|
static void
|
|
|
|
|
replace_return_with_assignment(ir_instruction *ir, void *data)
|
|
|
|
|
{
|
2011-01-21 14:32:31 -08:00
|
|
|
void *ctx = ralloc_parent(ir);
|
glsl: Convert ir_call to be a statement rather than a value.
Aside from ir_call, our IR is cleanly split into two classes:
- Statements (typeless; used for side effects, control flow)
- Values (deeply nestable, pure, typed expression trees)
Unfortunately, ir_call confused all this:
- For void functions, we placed ir_call directly in the instruction
stream, treating it as an untyped statement. Yet, it was a subclass
of ir_rvalue, and no other ir_rvalue could be used in this way.
- For functions with a return value, ir_call could be placed in
arbitrary expression trees. While this fit naturally with the source
language, it meant that expressions might not be pure, making it
difficult to transform and optimize them. To combat this, we always
emitted ir_call directly in the RHS of an ir_assignment, only using
a temporary variable in expression trees. Many passes relied on this
assumption; the acos and atan built-ins violated it.
This patch makes ir_call a statement (ir_instruction) rather than a
value (ir_rvalue). Non-void calls now take a ir_dereference of a
variable, and store the return value there---effectively a call and
assignment rolled into one. They cannot be embedded in expressions.
All expression trees are now pure, without exception.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-03-20 15:56:37 -07:00
|
|
|
ir_dereference *orig_deref = (ir_dereference *) data;
|
2010-06-24 08:59:57 -07:00
|
|
|
ir_return *ret = ir->as_return();
|
|
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
|
if (ret->value) {
|
glsl: Convert ir_call to be a statement rather than a value.
Aside from ir_call, our IR is cleanly split into two classes:
- Statements (typeless; used for side effects, control flow)
- Values (deeply nestable, pure, typed expression trees)
Unfortunately, ir_call confused all this:
- For void functions, we placed ir_call directly in the instruction
stream, treating it as an untyped statement. Yet, it was a subclass
of ir_rvalue, and no other ir_rvalue could be used in this way.
- For functions with a return value, ir_call could be placed in
arbitrary expression trees. While this fit naturally with the source
language, it meant that expressions might not be pure, making it
difficult to transform and optimize them. To combat this, we always
emitted ir_call directly in the RHS of an ir_assignment, only using
a temporary variable in expression trees. Many passes relied on this
assumption; the acos and atan built-ins violated it.
This patch makes ir_call a statement (ir_instruction) rather than a
value (ir_rvalue). Non-void calls now take a ir_dereference of a
variable, and store the return value there---effectively a call and
assignment rolled into one. They cannot be embedded in expressions.
All expression trees are now pure, without exception.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-03-20 15:56:37 -07:00
|
|
|
ir_rvalue *lhs = orig_deref->clone(ctx, NULL);
|
2010-07-19 21:44:03 -07:00
|
|
|
ret->replace_with(new(ctx) ir_assignment(lhs, ret->value, NULL));
|
2010-06-24 08:59:57 -07:00
|
|
|
} else {
|
|
|
|
|
/* un-valued return has to be the last return, or we shouldn't
|
|
|
|
|
* have reached here. (see can_inline()).
|
|
|
|
|
*/
|
2010-08-06 00:21:12 -07:00
|
|
|
assert(ret->next->is_tail_sentinel());
|
2010-07-29 13:42:39 -07:00
|
|
|
ret->remove();
|
2010-06-24 08:59:57 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
glsl: Convert ir_call to be a statement rather than a value.
Aside from ir_call, our IR is cleanly split into two classes:
- Statements (typeless; used for side effects, control flow)
- Values (deeply nestable, pure, typed expression trees)
Unfortunately, ir_call confused all this:
- For void functions, we placed ir_call directly in the instruction
stream, treating it as an untyped statement. Yet, it was a subclass
of ir_rvalue, and no other ir_rvalue could be used in this way.
- For functions with a return value, ir_call could be placed in
arbitrary expression trees. While this fit naturally with the source
language, it meant that expressions might not be pure, making it
difficult to transform and optimize them. To combat this, we always
emitted ir_call directly in the RHS of an ir_assignment, only using
a temporary variable in expression trees. Many passes relied on this
assumption; the acos and atan built-ins violated it.
This patch makes ir_call a statement (ir_instruction) rather than a
value (ir_rvalue). Non-void calls now take a ir_dereference of a
variable, and store the return value there---effectively a call and
assignment rolled into one. They cannot be embedded in expressions.
All expression trees are now pure, without exception.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-03-20 15:56:37 -07:00
|
|
|
void
|
2010-04-07 11:46:26 -07:00
|
|
|
ir_call::generate_inline(ir_instruction *next_ir)
|
|
|
|
|
{
|
2011-01-21 14:32:31 -08:00
|
|
|
void *ctx = ralloc_parent(this);
|
2010-04-07 11:46:26 -07:00
|
|
|
ir_variable **parameters;
|
|
|
|
|
int num_parameters;
|
|
|
|
|
int i;
|
2010-06-23 11:37:12 -07:00
|
|
|
struct hash_table *ht;
|
|
|
|
|
|
2010-07-06 14:49:14 -07:00
|
|
|
ht = hash_table_ctor(0, hash_table_pointer_hash, hash_table_pointer_compare);
|
2010-04-07 11:46:26 -07:00
|
|
|
|
|
|
|
|
num_parameters = 0;
|
|
|
|
|
foreach_iter(exec_list_iterator, iter_sig, this->callee->parameters)
|
|
|
|
|
num_parameters++;
|
|
|
|
|
|
|
|
|
|
parameters = new ir_variable *[num_parameters];
|
|
|
|
|
|
|
|
|
|
/* Generate the declarations for the parameters to our inlined code,
|
|
|
|
|
* and set up the mapping of real function body variables to ours.
|
|
|
|
|
*/
|
|
|
|
|
i = 0;
|
|
|
|
|
exec_list_iterator sig_param_iter = this->callee->parameters.iterator();
|
|
|
|
|
exec_list_iterator param_iter = this->actual_parameters.iterator();
|
|
|
|
|
for (i = 0; i < num_parameters; i++) {
|
2010-07-22 13:52:41 -07:00
|
|
|
ir_variable *sig_param = (ir_variable *) sig_param_iter.get();
|
2010-04-07 11:46:26 -07:00
|
|
|
ir_rvalue *param = (ir_rvalue *) param_iter.get();
|
|
|
|
|
|
|
|
|
|
/* Generate a new variable for the parameter. */
|
2013-09-30 12:54:57 -07:00
|
|
|
if (sig_param->type->contains_opaque()) {
|
|
|
|
|
/* For opaque types, we want the inlined variable references
|
|
|
|
|
* referencing the passed in variable, since that will have
|
|
|
|
|
* the location information, which an assignment of an opaque
|
|
|
|
|
* variable wouldn't. Fix it up below.
|
2010-07-22 13:52:41 -07:00
|
|
|
*/
|
|
|
|
|
parameters[i] = NULL;
|
|
|
|
|
} else {
|
2010-08-04 12:34:56 -07:00
|
|
|
parameters[i] = sig_param->clone(ctx, ht);
|
2013-12-12 13:51:01 +02:00
|
|
|
parameters[i]->data.mode = ir_var_auto;
|
2010-10-08 14:29:11 -07:00
|
|
|
|
|
|
|
|
/* Remove the read-only decoration becuase we're going to write
|
|
|
|
|
* directly to this variable. If the cloned variable is left
|
|
|
|
|
* read-only and the inlined function is inside a loop, the loop
|
|
|
|
|
* analysis code will get confused.
|
|
|
|
|
*/
|
2013-12-12 12:57:57 +02:00
|
|
|
parameters[i]->data.read_only = false;
|
2010-07-22 13:52:41 -07:00
|
|
|
next_ir->insert_before(parameters[i]);
|
|
|
|
|
}
|
2010-04-07 11:46:26 -07:00
|
|
|
|
|
|
|
|
/* Move the actual param into our param variable if it's an 'in' type. */
|
2013-12-12 13:51:01 +02:00
|
|
|
if (parameters[i] && (sig_param->data.mode == ir_var_function_in ||
|
|
|
|
|
sig_param->data.mode == ir_var_const_in ||
|
|
|
|
|
sig_param->data.mode == ir_var_function_inout)) {
|
2010-04-07 11:46:26 -07:00
|
|
|
ir_assignment *assign;
|
|
|
|
|
|
2010-06-23 18:11:51 -07:00
|
|
|
assign = new(ctx) ir_assignment(new(ctx) ir_dereference_variable(parameters[i]),
|
|
|
|
|
param, NULL);
|
2010-04-07 11:46:26 -07:00
|
|
|
next_ir->insert_before(assign);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sig_param_iter.next();
|
|
|
|
|
param_iter.next();
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-06 00:21:12 -07:00
|
|
|
exec_list new_instructions;
|
|
|
|
|
|
|
|
|
|
/* Generate the inlined body of the function to a new list */
|
2010-04-07 11:46:26 -07:00
|
|
|
foreach_iter(exec_list_iterator, iter, callee->body) {
|
|
|
|
|
ir_instruction *ir = (ir_instruction *)iter.get();
|
2010-08-04 12:34:56 -07:00
|
|
|
ir_instruction *new_ir = ir->clone(ctx, ht);
|
2010-04-07 11:46:26 -07:00
|
|
|
|
2010-08-06 00:21:12 -07:00
|
|
|
new_instructions.push_tail(new_ir);
|
glsl: Convert ir_call to be a statement rather than a value.
Aside from ir_call, our IR is cleanly split into two classes:
- Statements (typeless; used for side effects, control flow)
- Values (deeply nestable, pure, typed expression trees)
Unfortunately, ir_call confused all this:
- For void functions, we placed ir_call directly in the instruction
stream, treating it as an untyped statement. Yet, it was a subclass
of ir_rvalue, and no other ir_rvalue could be used in this way.
- For functions with a return value, ir_call could be placed in
arbitrary expression trees. While this fit naturally with the source
language, it meant that expressions might not be pure, making it
difficult to transform and optimize them. To combat this, we always
emitted ir_call directly in the RHS of an ir_assignment, only using
a temporary variable in expression trees. Many passes relied on this
assumption; the acos and atan built-ins violated it.
This patch makes ir_call a statement (ir_instruction) rather than a
value (ir_rvalue). Non-void calls now take a ir_dereference of a
variable, and store the return value there---effectively a call and
assignment rolled into one. They cannot be embedded in expressions.
All expression trees are now pure, without exception.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-03-20 15:56:37 -07:00
|
|
|
visit_tree(new_ir, replace_return_with_assignment, this->return_deref);
|
2010-04-07 11:46:26 -07:00
|
|
|
}
|
|
|
|
|
|
2013-09-30 12:54:57 -07:00
|
|
|
/* If any opaque types were passed in, replace any deref of the
|
|
|
|
|
* opaque variable with a deref of the argument.
|
2010-08-06 00:21:12 -07:00
|
|
|
*/
|
|
|
|
|
param_iter = this->actual_parameters.iterator();
|
|
|
|
|
sig_param_iter = this->callee->parameters.iterator();
|
|
|
|
|
for (i = 0; i < num_parameters; i++) {
|
|
|
|
|
ir_instruction *const param = (ir_instruction *) param_iter.get();
|
|
|
|
|
ir_variable *sig_param = (ir_variable *) sig_param_iter.get();
|
|
|
|
|
|
2013-09-30 12:54:57 -07:00
|
|
|
if (sig_param->type->contains_opaque()) {
|
2010-08-06 00:21:12 -07:00
|
|
|
ir_dereference *deref = param->as_dereference();
|
|
|
|
|
|
|
|
|
|
assert(deref);
|
2013-09-30 12:54:57 -07:00
|
|
|
do_variable_replacement(&new_instructions, sig_param, deref);
|
2010-08-06 00:21:12 -07:00
|
|
|
}
|
2010-08-06 12:31:56 +02:00
|
|
|
param_iter.next();
|
|
|
|
|
sig_param_iter.next();
|
2010-08-06 00:21:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now push those new instructions in. */
|
2011-03-08 11:43:52 -08:00
|
|
|
next_ir->insert_before(&new_instructions);
|
2010-08-06 00:21:12 -07:00
|
|
|
|
2010-04-30 23:38:50 -07:00
|
|
|
/* Copy back the value of any 'out' parameters from the function body
|
|
|
|
|
* variables to our own.
|
2010-04-07 11:46:26 -07:00
|
|
|
*/
|
|
|
|
|
i = 0;
|
|
|
|
|
param_iter = this->actual_parameters.iterator();
|
2010-07-20 16:03:46 -07:00
|
|
|
sig_param_iter = this->callee->parameters.iterator();
|
2010-04-07 11:46:26 -07:00
|
|
|
for (i = 0; i < num_parameters; i++) {
|
|
|
|
|
ir_instruction *const param = (ir_instruction *) param_iter.get();
|
2010-07-20 16:03:46 -07:00
|
|
|
const ir_variable *const sig_param = (ir_variable *) sig_param_iter.get();
|
2010-04-07 11:46:26 -07:00
|
|
|
|
2010-04-30 23:38:50 -07:00
|
|
|
/* Move our param variable into the actual param if it's an 'out' type. */
|
2013-12-12 13:51:01 +02:00
|
|
|
if (parameters[i] && (sig_param->data.mode == ir_var_function_out ||
|
|
|
|
|
sig_param->data.mode == ir_var_function_inout)) {
|
2010-04-07 11:46:26 -07:00
|
|
|
ir_assignment *assign;
|
|
|
|
|
|
2010-08-04 12:34:56 -07:00
|
|
|
assign = new(ctx) ir_assignment(param->clone(ctx, NULL)->as_rvalue(),
|
2010-06-23 18:11:51 -07:00
|
|
|
new(ctx) ir_dereference_variable(parameters[i]),
|
|
|
|
|
NULL);
|
2010-04-07 11:46:26 -07:00
|
|
|
next_ir->insert_before(assign);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
param_iter.next();
|
2010-07-20 16:03:46 -07:00
|
|
|
sig_param_iter.next();
|
2010-04-07 11:46:26 -07:00
|
|
|
}
|
|
|
|
|
|
2010-06-09 11:00:00 -07:00
|
|
|
delete [] parameters;
|
2010-04-07 11:46:26 -07:00
|
|
|
|
2010-06-23 11:37:12 -07:00
|
|
|
hash_table_dtor(ht);
|
2010-04-07 11:46:26 -07:00
|
|
|
}
|
|
|
|
|
|
2010-05-26 18:58:27 -07:00
|
|
|
|
|
|
|
|
ir_visitor_status
|
|
|
|
|
ir_function_inlining_visitor::visit_enter(ir_expression *ir)
|
2010-04-07 11:46:26 -07:00
|
|
|
{
|
|
|
|
|
(void) ir;
|
2010-05-26 18:58:27 -07:00
|
|
|
return visit_continue_with_parent;
|
2010-04-07 11:46:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-05-26 18:58:27 -07:00
|
|
|
ir_visitor_status
|
|
|
|
|
ir_function_inlining_visitor::visit_enter(ir_return *ir)
|
2010-04-07 11:46:26 -07:00
|
|
|
{
|
|
|
|
|
(void) ir;
|
2010-05-26 18:58:27 -07:00
|
|
|
return visit_continue_with_parent;
|
2010-04-07 11:46:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-05-26 17:42:03 -07:00
|
|
|
ir_visitor_status
|
|
|
|
|
ir_function_inlining_visitor::visit_enter(ir_texture *ir)
|
|
|
|
|
{
|
|
|
|
|
(void) ir;
|
|
|
|
|
return visit_continue_with_parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-05-26 18:58:27 -07:00
|
|
|
ir_visitor_status
|
|
|
|
|
ir_function_inlining_visitor::visit_enter(ir_swizzle *ir)
|
2010-04-07 11:46:26 -07:00
|
|
|
{
|
2010-05-26 18:58:27 -07:00
|
|
|
(void) ir;
|
|
|
|
|
return visit_continue_with_parent;
|
2010-04-07 11:46:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-05-26 18:58:27 -07:00
|
|
|
ir_visitor_status
|
|
|
|
|
ir_function_inlining_visitor::visit_enter(ir_call *ir)
|
2010-04-07 11:46:26 -07:00
|
|
|
{
|
2010-05-26 18:58:27 -07:00
|
|
|
if (can_inline(ir)) {
|
glsl: Convert ir_call to be a statement rather than a value.
Aside from ir_call, our IR is cleanly split into two classes:
- Statements (typeless; used for side effects, control flow)
- Values (deeply nestable, pure, typed expression trees)
Unfortunately, ir_call confused all this:
- For void functions, we placed ir_call directly in the instruction
stream, treating it as an untyped statement. Yet, it was a subclass
of ir_rvalue, and no other ir_rvalue could be used in this way.
- For functions with a return value, ir_call could be placed in
arbitrary expression trees. While this fit naturally with the source
language, it meant that expressions might not be pure, making it
difficult to transform and optimize them. To combat this, we always
emitted ir_call directly in the RHS of an ir_assignment, only using
a temporary variable in expression trees. Many passes relied on this
assumption; the acos and atan built-ins violated it.
This patch makes ir_call a statement (ir_instruction) rather than a
value (ir_rvalue). Non-void calls now take a ir_dereference of a
variable, and store the return value there---effectively a call and
assignment rolled into one. They cannot be embedded in expressions.
All expression trees are now pure, without exception.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-03-20 15:56:37 -07:00
|
|
|
ir->generate_inline(ir);
|
2010-05-26 18:58:27 -07:00
|
|
|
ir->remove();
|
|
|
|
|
this->progress = true;
|
2010-04-21 12:30:22 -07:00
|
|
|
}
|
2010-04-07 11:46:26 -07:00
|
|
|
|
2010-05-26 18:58:27 -07:00
|
|
|
return visit_continue;
|
2010-04-07 11:46:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-08-06 00:21:12 -07:00
|
|
|
/**
|
2013-09-30 12:54:57 -07:00
|
|
|
* Replaces references to the "orig" variable with a clone of "repl."
|
2010-08-06 00:21:12 -07:00
|
|
|
*
|
2013-09-30 12:54:57 -07:00
|
|
|
* From the spec, opaque types can appear in the tree as function
|
2010-08-06 00:21:12 -07:00
|
|
|
* (non-out) parameters and as the result of array indexing and
|
|
|
|
|
* structure field selection. In our builtin implementation, they
|
|
|
|
|
* also appear in the sampler field of an ir_tex instruction.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-09-30 12:54:57 -07:00
|
|
|
class ir_variable_replacement_visitor : public ir_hierarchical_visitor {
|
2010-08-06 00:21:12 -07:00
|
|
|
public:
|
2013-09-30 12:54:57 -07:00
|
|
|
ir_variable_replacement_visitor(ir_variable *orig, ir_dereference *repl)
|
2010-08-06 00:21:12 -07:00
|
|
|
{
|
2013-09-30 12:54:57 -07:00
|
|
|
this->orig = orig;
|
|
|
|
|
this->repl = repl;
|
2010-08-06 00:21:12 -07:00
|
|
|
}
|
|
|
|
|
|
2013-09-30 12:54:57 -07:00
|
|
|
virtual ~ir_variable_replacement_visitor()
|
2010-08-06 00:21:12 -07:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual ir_visitor_status visit_leave(ir_call *);
|
|
|
|
|
virtual ir_visitor_status visit_leave(ir_dereference_array *);
|
|
|
|
|
virtual ir_visitor_status visit_leave(ir_dereference_record *);
|
|
|
|
|
virtual ir_visitor_status visit_leave(ir_texture *);
|
|
|
|
|
|
|
|
|
|
void replace_deref(ir_dereference **deref);
|
|
|
|
|
void replace_rvalue(ir_rvalue **rvalue);
|
|
|
|
|
|
2013-09-30 12:54:57 -07:00
|
|
|
ir_variable *orig;
|
|
|
|
|
ir_dereference *repl;
|
2010-08-06 00:21:12 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void
|
2013-09-30 12:54:57 -07:00
|
|
|
ir_variable_replacement_visitor::replace_deref(ir_dereference **deref)
|
2010-08-06 00:21:12 -07:00
|
|
|
{
|
|
|
|
|
ir_dereference_variable *deref_var = (*deref)->as_dereference_variable();
|
2013-09-30 12:54:57 -07:00
|
|
|
if (deref_var && deref_var->var == this->orig) {
|
|
|
|
|
*deref = this->repl->clone(ralloc_parent(*deref), NULL);
|
2010-08-06 00:21:12 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2013-09-30 12:54:57 -07:00
|
|
|
ir_variable_replacement_visitor::replace_rvalue(ir_rvalue **rvalue)
|
2010-08-06 00:21:12 -07:00
|
|
|
{
|
|
|
|
|
if (!*rvalue)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ir_dereference *deref = (*rvalue)->as_dereference();
|
|
|
|
|
|
|
|
|
|
if (!deref)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
replace_deref(&deref);
|
|
|
|
|
*rvalue = deref;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ir_visitor_status
|
2013-09-30 12:54:57 -07:00
|
|
|
ir_variable_replacement_visitor::visit_leave(ir_texture *ir)
|
2010-08-06 00:21:12 -07:00
|
|
|
{
|
|
|
|
|
replace_deref(&ir->sampler);
|
|
|
|
|
|
|
|
|
|
return visit_continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ir_visitor_status
|
2013-09-30 12:54:57 -07:00
|
|
|
ir_variable_replacement_visitor::visit_leave(ir_dereference_array *ir)
|
2010-08-06 00:21:12 -07:00
|
|
|
{
|
|
|
|
|
replace_rvalue(&ir->array);
|
|
|
|
|
return visit_continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ir_visitor_status
|
2013-09-30 12:54:57 -07:00
|
|
|
ir_variable_replacement_visitor::visit_leave(ir_dereference_record *ir)
|
2010-08-06 00:21:12 -07:00
|
|
|
{
|
|
|
|
|
replace_rvalue(&ir->record);
|
|
|
|
|
return visit_continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ir_visitor_status
|
2013-09-30 12:54:57 -07:00
|
|
|
ir_variable_replacement_visitor::visit_leave(ir_call *ir)
|
2010-08-06 00:21:12 -07:00
|
|
|
{
|
|
|
|
|
foreach_iter(exec_list_iterator, iter, *ir) {
|
|
|
|
|
ir_rvalue *param = (ir_rvalue *)iter.get();
|
|
|
|
|
ir_rvalue *new_param = param;
|
|
|
|
|
replace_rvalue(&new_param);
|
|
|
|
|
|
|
|
|
|
if (new_param != param) {
|
|
|
|
|
param->replace_with(new_param);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return visit_continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-30 12:54:57 -07:00
|
|
|
do_variable_replacement(exec_list *instructions,
|
|
|
|
|
ir_variable *orig,
|
|
|
|
|
ir_dereference *repl)
|
2010-08-06 00:21:12 -07:00
|
|
|
{
|
2013-09-30 12:54:57 -07:00
|
|
|
ir_variable_replacement_visitor v(orig, repl);
|
2010-08-06 00:21:12 -07:00
|
|
|
|
|
|
|
|
visit_list_elements(&v, instructions);
|
|
|
|
|
}
|