2010-07-30 17:04:49 -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_tree_grafting.cpp
|
2010-07-30 17:04:49 -07:00
|
|
|
*
|
|
|
|
|
* Takes assignments to variables that are dereferenced only once and
|
|
|
|
|
* pastes the RHS expression into where the variable is dereferenced.
|
|
|
|
|
*
|
|
|
|
|
* In the process of various operations like function inlining and
|
|
|
|
|
* tertiary op handling, we'll end up with our expression trees having
|
|
|
|
|
* been chopped up into a series of assignments of short expressions
|
|
|
|
|
* to temps. Other passes like ir_algebraic.cpp would prefer to see
|
|
|
|
|
* the deepest expression trees they can to try to optimize them.
|
|
|
|
|
*
|
|
|
|
|
* This is a lot like copy propagaton. In comparison, copy
|
|
|
|
|
* propagation only acts on plain copies, not arbitrary expressions on
|
|
|
|
|
* the RHS. Generally, we wouldn't want to go pasting some
|
|
|
|
|
* complicated expression everywhere it got used, though, so we don't
|
|
|
|
|
* handle expressions in that pass.
|
|
|
|
|
*
|
|
|
|
|
* The hard part is making sure we don't move an expression across
|
|
|
|
|
* some other assignments that would change the value of the
|
|
|
|
|
* expression. So we split this into two passes: First, find the
|
|
|
|
|
* variables in our scope which are written to once and read once, and
|
|
|
|
|
* then go through basic blocks seeing if we find an opportunity to
|
|
|
|
|
* move those expressions safely.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ir.h"
|
|
|
|
|
#include "ir_visitor.h"
|
|
|
|
|
#include "ir_variable_refcount.h"
|
|
|
|
|
#include "ir_basic_block.h"
|
|
|
|
|
#include "ir_optimization.h"
|
2016-01-18 11:35:29 +02:00
|
|
|
#include "compiler/glsl_types.h"
|
2010-07-30 17:04:49 -07:00
|
|
|
|
2012-05-29 16:18:37 -07:00
|
|
|
namespace {
|
|
|
|
|
|
2010-07-30 17:04:49 -07:00
|
|
|
static bool debug = false;
|
|
|
|
|
|
|
|
|
|
class ir_tree_grafting_visitor : public ir_hierarchical_visitor {
|
|
|
|
|
public:
|
|
|
|
|
ir_tree_grafting_visitor(ir_assignment *graft_assign,
|
|
|
|
|
ir_variable *graft_var)
|
|
|
|
|
{
|
|
|
|
|
this->progress = false;
|
|
|
|
|
this->graft_assign = graft_assign;
|
|
|
|
|
this->graft_var = graft_var;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual ir_visitor_status visit_leave(class ir_assignment *);
|
|
|
|
|
virtual ir_visitor_status visit_enter(class ir_call *);
|
|
|
|
|
virtual ir_visitor_status visit_enter(class ir_expression *);
|
|
|
|
|
virtual ir_visitor_status visit_enter(class ir_function *);
|
|
|
|
|
virtual ir_visitor_status visit_enter(class ir_function_signature *);
|
|
|
|
|
virtual ir_visitor_status visit_enter(class ir_if *);
|
|
|
|
|
virtual ir_visitor_status visit_enter(class ir_loop *);
|
|
|
|
|
virtual ir_visitor_status visit_enter(class ir_swizzle *);
|
|
|
|
|
virtual ir_visitor_status visit_enter(class ir_texture *);
|
|
|
|
|
|
2011-09-22 15:04:56 -07:00
|
|
|
ir_visitor_status check_graft(ir_instruction *ir, ir_variable *var);
|
|
|
|
|
|
2010-07-30 17:04:49 -07:00
|
|
|
bool do_graft(ir_rvalue **rvalue);
|
|
|
|
|
|
|
|
|
|
bool progress;
|
|
|
|
|
ir_variable *graft_var;
|
|
|
|
|
ir_assignment *graft_assign;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct find_deref_info {
|
|
|
|
|
ir_variable *var;
|
|
|
|
|
bool found;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
dereferences_variable_callback(ir_instruction *ir, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct find_deref_info *info = (struct find_deref_info *)data;
|
2010-08-05 12:52:29 -07:00
|
|
|
ir_dereference_variable *deref = ir->as_dereference_variable();
|
2010-07-30 17:04:49 -07:00
|
|
|
|
2010-08-05 12:52:29 -07:00
|
|
|
if (deref && deref->var == info->var)
|
2010-07-30 17:04:49 -07:00
|
|
|
info->found = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
dereferences_variable(ir_instruction *ir, ir_variable *var)
|
|
|
|
|
{
|
|
|
|
|
struct find_deref_info info;
|
|
|
|
|
|
|
|
|
|
info.var = var;
|
|
|
|
|
info.found = false;
|
|
|
|
|
|
|
|
|
|
visit_tree(ir, dereferences_variable_callback, &info);
|
|
|
|
|
|
|
|
|
|
return info.found;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
ir_tree_grafting_visitor::do_graft(ir_rvalue **rvalue)
|
|
|
|
|
{
|
|
|
|
|
if (!*rvalue)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
ir_dereference_variable *deref = (*rvalue)->as_dereference_variable();
|
|
|
|
|
|
|
|
|
|
if (!deref || deref->var != this->graft_var)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (debug) {
|
2014-03-25 12:28:57 -07:00
|
|
|
fprintf(stderr, "GRAFTING:\n");
|
|
|
|
|
this->graft_assign->fprint(stderr);
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
fprintf(stderr, "TO:\n");
|
|
|
|
|
(*rvalue)->fprint(stderr);
|
|
|
|
|
fprintf(stderr, "\n");
|
2010-07-30 17:04:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->graft_assign->remove();
|
|
|
|
|
*rvalue = this->graft_assign->rhs;
|
|
|
|
|
|
|
|
|
|
this->progress = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ir_visitor_status
|
|
|
|
|
ir_tree_grafting_visitor::visit_enter(ir_loop *ir)
|
|
|
|
|
{
|
|
|
|
|
(void)ir;
|
|
|
|
|
/* Do not traverse into the body of the loop since that is a
|
|
|
|
|
* different basic block.
|
|
|
|
|
*/
|
|
|
|
|
return visit_stop;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-22 15:04:56 -07:00
|
|
|
/**
|
|
|
|
|
* Check if we can continue grafting after writing to a variable. If the
|
|
|
|
|
* expression we're trying to graft references the variable, we must stop.
|
|
|
|
|
*
|
|
|
|
|
* \param ir An instruction that writes to a variable.
|
|
|
|
|
* \param var The variable being updated.
|
|
|
|
|
*/
|
2010-07-30 17:04:49 -07:00
|
|
|
ir_visitor_status
|
2011-09-22 15:04:56 -07:00
|
|
|
ir_tree_grafting_visitor::check_graft(ir_instruction *ir, ir_variable *var)
|
2010-07-30 17:04:49 -07:00
|
|
|
{
|
2011-09-22 15:04:56 -07:00
|
|
|
if (dereferences_variable(this->graft_assign->rhs, var)) {
|
2010-07-30 17:04:49 -07:00
|
|
|
if (debug) {
|
2014-03-25 12:28:57 -07:00
|
|
|
fprintf(stderr, "graft killed by: ");
|
|
|
|
|
ir->fprint(stderr);
|
|
|
|
|
fprintf(stderr, "\n");
|
2010-07-30 17:04:49 -07:00
|
|
|
}
|
|
|
|
|
return visit_stop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return visit_continue;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-22 15:04:56 -07:00
|
|
|
ir_visitor_status
|
|
|
|
|
ir_tree_grafting_visitor::visit_leave(ir_assignment *ir)
|
|
|
|
|
{
|
|
|
|
|
if (do_graft(&ir->rhs) ||
|
|
|
|
|
do_graft(&ir->condition))
|
|
|
|
|
return visit_stop;
|
|
|
|
|
|
|
|
|
|
/* If this assignment updates a variable used in the assignment
|
|
|
|
|
* we're trying to graft, then we're done.
|
|
|
|
|
*/
|
|
|
|
|
return check_graft(ir, ir->lhs->variable_referenced());
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-30 17:04:49 -07:00
|
|
|
ir_visitor_status
|
|
|
|
|
ir_tree_grafting_visitor::visit_enter(ir_function *ir)
|
|
|
|
|
{
|
|
|
|
|
(void) ir;
|
|
|
|
|
return visit_continue_with_parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ir_visitor_status
|
|
|
|
|
ir_tree_grafting_visitor::visit_enter(ir_function_signature *ir)
|
|
|
|
|
{
|
|
|
|
|
(void)ir;
|
|
|
|
|
return visit_continue_with_parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ir_visitor_status
|
|
|
|
|
ir_tree_grafting_visitor::visit_enter(ir_call *ir)
|
|
|
|
|
{
|
glsl: Use a new foreach_two_lists macro for walking two lists at once.
When handling function calls, we often want to walk through the list of
formal parameters and list of actual parameters at the same time.
(Both are guaranteed to be the same length.)
Previously, we used a pattern of:
exec_list_iterator 1st_iter = <1st list>.iterator();
foreach_iter(exec_list_iterator, 2nd_iter, <2nd list>) {
...
1st_iter.next();
}
This was awkward, since you had to manually iterate through one of
the two lists.
This patch introduces a foreach_two_lists macro which safely walks
through two lists at the same time, so you can simply do:
foreach_two_lists(1st_node, <1st list>, 2nd_node, <2nd list>) {
...
}
v2: Rename macro from foreach_list2 to foreach_two_lists, as suggested
by Ian Romanick.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2014-01-10 16:39:17 -08:00
|
|
|
foreach_two_lists(formal_node, &ir->callee->parameters,
|
|
|
|
|
actual_node, &ir->actual_parameters) {
|
|
|
|
|
ir_variable *sig_param = (ir_variable *) formal_node;
|
|
|
|
|
ir_rvalue *ir = (ir_rvalue *) actual_node;
|
2010-07-30 17:04:49 -07:00
|
|
|
ir_rvalue *new_ir = ir;
|
|
|
|
|
|
2013-12-12 13:51:01 +02:00
|
|
|
if (sig_param->data.mode != ir_var_function_in
|
|
|
|
|
&& sig_param->data.mode != ir_var_const_in) {
|
2011-09-22 15:04:56 -07:00
|
|
|
if (check_graft(ir, sig_param) == visit_stop)
|
|
|
|
|
return visit_stop;
|
2010-08-22 18:25:55 -07:00
|
|
|
continue;
|
2011-09-22 15:04:56 -07:00
|
|
|
}
|
2010-08-22 18:25:55 -07:00
|
|
|
|
2010-07-30 17:04:49 -07:00
|
|
|
if (do_graft(&new_ir)) {
|
|
|
|
|
ir->replace_with(new_ir);
|
|
|
|
|
return visit_stop;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
if (ir->return_deref && check_graft(ir, ir->return_deref->var) == visit_stop)
|
|
|
|
|
return visit_stop;
|
|
|
|
|
|
2010-07-30 17:04:49 -07:00
|
|
|
return visit_continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ir_visitor_status
|
|
|
|
|
ir_tree_grafting_visitor::visit_enter(ir_expression *ir)
|
|
|
|
|
{
|
|
|
|
|
for (unsigned int i = 0; i < ir->get_num_operands(); i++) {
|
|
|
|
|
if (do_graft(&ir->operands[i]))
|
|
|
|
|
return visit_stop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return visit_continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ir_visitor_status
|
|
|
|
|
ir_tree_grafting_visitor::visit_enter(ir_if *ir)
|
|
|
|
|
{
|
|
|
|
|
if (do_graft(&ir->condition))
|
|
|
|
|
return visit_stop;
|
|
|
|
|
|
|
|
|
|
/* Do not traverse into the body of the if-statement since that is a
|
|
|
|
|
* different basic block.
|
|
|
|
|
*/
|
|
|
|
|
return visit_continue_with_parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ir_visitor_status
|
|
|
|
|
ir_tree_grafting_visitor::visit_enter(ir_swizzle *ir)
|
|
|
|
|
{
|
|
|
|
|
if (do_graft(&ir->val))
|
|
|
|
|
return visit_stop;
|
|
|
|
|
|
|
|
|
|
return visit_continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ir_visitor_status
|
|
|
|
|
ir_tree_grafting_visitor::visit_enter(ir_texture *ir)
|
|
|
|
|
{
|
|
|
|
|
if (do_graft(&ir->coordinate) ||
|
|
|
|
|
do_graft(&ir->projector) ||
|
2011-01-08 23:49:23 -08:00
|
|
|
do_graft(&ir->offset) ||
|
2010-07-30 17:04:49 -07:00
|
|
|
do_graft(&ir->shadow_comparitor))
|
|
|
|
|
return visit_stop;
|
|
|
|
|
|
|
|
|
|
switch (ir->op) {
|
|
|
|
|
case ir_tex:
|
2012-09-23 19:50:41 +10:00
|
|
|
case ir_lod:
|
2013-09-26 19:37:30 +12:00
|
|
|
case ir_query_levels:
|
2015-08-27 23:03:46 -04:00
|
|
|
case ir_texture_samples:
|
2015-11-17 16:54:31 -08:00
|
|
|
case ir_samples_identical:
|
2010-07-30 17:04:49 -07:00
|
|
|
break;
|
|
|
|
|
case ir_txb:
|
|
|
|
|
if (do_graft(&ir->lod_info.bias))
|
|
|
|
|
return visit_stop;
|
|
|
|
|
break;
|
|
|
|
|
case ir_txf:
|
|
|
|
|
case ir_txl:
|
2011-02-25 14:45:33 -08:00
|
|
|
case ir_txs:
|
2010-07-30 17:04:49 -07:00
|
|
|
if (do_graft(&ir->lod_info.lod))
|
|
|
|
|
return visit_stop;
|
|
|
|
|
break;
|
2012-12-21 21:33:37 +13:00
|
|
|
case ir_txf_ms:
|
|
|
|
|
if (do_graft(&ir->lod_info.sample_index))
|
|
|
|
|
return visit_stop;
|
|
|
|
|
break;
|
2010-07-30 17:04:49 -07:00
|
|
|
case ir_txd:
|
|
|
|
|
if (do_graft(&ir->lod_info.grad.dPdx) ||
|
|
|
|
|
do_graft(&ir->lod_info.grad.dPdy))
|
|
|
|
|
return visit_stop;
|
|
|
|
|
break;
|
2013-10-05 18:26:56 +13:00
|
|
|
case ir_tg4:
|
|
|
|
|
if (do_graft(&ir->lod_info.component))
|
|
|
|
|
return visit_stop;
|
|
|
|
|
break;
|
2010-07-30 17:04:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return visit_continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct tree_grafting_info {
|
|
|
|
|
ir_variable_refcount_visitor *refs;
|
|
|
|
|
bool progress;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
try_tree_grafting(ir_assignment *start,
|
|
|
|
|
ir_variable *lhs_var,
|
|
|
|
|
ir_instruction *bb_last)
|
|
|
|
|
{
|
|
|
|
|
ir_tree_grafting_visitor v(start, lhs_var);
|
|
|
|
|
|
|
|
|
|
if (debug) {
|
2014-03-25 12:28:57 -07:00
|
|
|
fprintf(stderr, "trying to graft: ");
|
|
|
|
|
lhs_var->fprint(stderr);
|
|
|
|
|
fprintf(stderr, "\n");
|
2010-07-30 17:04:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (ir_instruction *ir = (ir_instruction *)start->next;
|
|
|
|
|
ir != bb_last->next;
|
|
|
|
|
ir = (ir_instruction *)ir->next) {
|
|
|
|
|
|
|
|
|
|
if (debug) {
|
2014-03-25 12:28:57 -07:00
|
|
|
fprintf(stderr, "- ");
|
|
|
|
|
ir->fprint(stderr);
|
|
|
|
|
fprintf(stderr, "\n");
|
2010-07-30 17:04:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ir_visitor_status s = ir->accept(&v);
|
|
|
|
|
if (s == visit_stop)
|
|
|
|
|
return v.progress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tree_grafting_basic_block(ir_instruction *bb_first,
|
|
|
|
|
ir_instruction *bb_last,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
struct tree_grafting_info *info = (struct tree_grafting_info *)data;
|
|
|
|
|
ir_instruction *ir, *next;
|
|
|
|
|
|
|
|
|
|
for (ir = bb_first, next = (ir_instruction *)ir->next;
|
|
|
|
|
ir != bb_last->next;
|
|
|
|
|
ir = next, next = (ir_instruction *)ir->next) {
|
|
|
|
|
ir_assignment *assign = ir->as_assignment();
|
|
|
|
|
|
|
|
|
|
if (!assign)
|
|
|
|
|
continue;
|
|
|
|
|
|
2010-08-02 18:48:25 -07:00
|
|
|
ir_variable *lhs_var = assign->whole_variable_written();
|
2010-07-30 17:04:49 -07:00
|
|
|
if (!lhs_var)
|
|
|
|
|
continue;
|
|
|
|
|
|
2016-01-19 23:27:22 -08:00
|
|
|
if (lhs_var->data.mode == ir_var_function_out ||
|
|
|
|
|
lhs_var->data.mode == ir_var_function_inout ||
|
|
|
|
|
lhs_var->data.mode == ir_var_shader_out ||
|
|
|
|
|
lhs_var->data.mode == ir_var_shader_storage ||
|
|
|
|
|
lhs_var->data.mode == ir_var_shader_shared)
|
|
|
|
|
continue;
|
2010-08-05 12:24:36 -07:00
|
|
|
|
2016-04-03 02:02:12 -07:00
|
|
|
if (lhs_var->data.precise)
|
|
|
|
|
continue;
|
|
|
|
|
|
2012-01-28 16:58:37 -08:00
|
|
|
ir_variable_refcount_entry *entry = info->refs->get_variable_entry(lhs_var);
|
2010-07-30 17:04:49 -07:00
|
|
|
|
|
|
|
|
if (!entry->declaration ||
|
|
|
|
|
entry->assigned_count != 1 ||
|
|
|
|
|
entry->referenced_count != 2)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* Found a possibly graftable assignment. Now, walk through the
|
|
|
|
|
* rest of the BB seeing if the deref is here, and if nothing interfered with
|
|
|
|
|
* pasting its expression's values in between.
|
|
|
|
|
*/
|
|
|
|
|
info->progress |= try_tree_grafting(assign, lhs_var, bb_last);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-29 16:18:37 -07:00
|
|
|
} /* unnamed namespace */
|
|
|
|
|
|
2010-07-30 17:04:49 -07:00
|
|
|
/**
|
|
|
|
|
* Does a copy propagation pass on the code present in the instruction stream.
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
do_tree_grafting(exec_list *instructions)
|
|
|
|
|
{
|
|
|
|
|
ir_variable_refcount_visitor refs;
|
|
|
|
|
struct tree_grafting_info info;
|
|
|
|
|
|
|
|
|
|
info.progress = false;
|
|
|
|
|
info.refs = &refs;
|
|
|
|
|
|
|
|
|
|
visit_list_elements(info.refs, instructions);
|
|
|
|
|
|
|
|
|
|
call_for_basic_blocks(instructions, tree_grafting_basic_block, &info);
|
|
|
|
|
|
|
|
|
|
return info.progress;
|
|
|
|
|
}
|