glsl: drop glsl ir optimisation from the standalone compiler
There are no more users of the glsl ir at this point in the standalone compiler anymore for these optimisations. Later patches will also switch the standalone compiler to the nir linker. Acked-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29991>
This commit is contained in:

committed by
Marge Bot

parent
063d62f142
commit
a71ce0a6d6
@@ -208,7 +208,6 @@ files_libglsl = files(
|
||||
)
|
||||
|
||||
files_libglsl_standalone = files(
|
||||
'opt_add_neg_to_sub.h',
|
||||
'standalone_scaffolding.cpp',
|
||||
'standalone_scaffolding.h',
|
||||
'standalone.cpp',
|
||||
|
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2016 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.
|
||||
*/
|
||||
|
||||
#ifndef OPT_ADD_NEG_TO_SUB_H
|
||||
#define OPT_ADD_NEG_TO_SUB_H
|
||||
|
||||
#include "ir.h"
|
||||
#include "ir_hierarchical_visitor.h"
|
||||
|
||||
class add_neg_to_sub_visitor : public ir_hierarchical_visitor {
|
||||
public:
|
||||
add_neg_to_sub_visitor()
|
||||
{
|
||||
/* empty */
|
||||
}
|
||||
|
||||
ir_visitor_status visit_leave(ir_expression *ir)
|
||||
{
|
||||
if (ir->operation != ir_binop_add)
|
||||
return visit_continue;
|
||||
|
||||
for (unsigned i = 0; i < 2; i++) {
|
||||
ir_expression *const op = ir->operands[i]->as_expression();
|
||||
|
||||
if (op != NULL && op->operation == ir_unop_neg) {
|
||||
ir->operation = ir_binop_sub;
|
||||
|
||||
/* This ensures that -a + b becomes b - a. */
|
||||
if (i == 0)
|
||||
ir->operands[0] = ir->operands[1];
|
||||
|
||||
ir->operands[1] = op->operands[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return visit_continue;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* OPT_ADD_NEG_TO_SUB_H */
|
@@ -39,62 +39,9 @@
|
||||
#include "linker.h"
|
||||
#include "glsl_parser_extras.h"
|
||||
#include "builtin_functions.h"
|
||||
#include "opt_add_neg_to_sub.h"
|
||||
#include "main/mtypes.h"
|
||||
#include "program/program.h"
|
||||
|
||||
class dead_variable_visitor : public ir_hierarchical_visitor {
|
||||
public:
|
||||
dead_variable_visitor()
|
||||
{
|
||||
variables = _mesa_pointer_set_create(NULL);
|
||||
}
|
||||
|
||||
virtual ~dead_variable_visitor()
|
||||
{
|
||||
_mesa_set_destroy(variables, NULL);
|
||||
}
|
||||
|
||||
virtual ir_visitor_status visit(ir_variable *ir)
|
||||
{
|
||||
/* If the variable is auto or temp, add it to the set of variables that
|
||||
* are candidates for removal.
|
||||
*/
|
||||
if (ir->data.mode != ir_var_auto && ir->data.mode != ir_var_temporary)
|
||||
return visit_continue;
|
||||
|
||||
_mesa_set_add(variables, ir);
|
||||
|
||||
return visit_continue;
|
||||
}
|
||||
|
||||
virtual ir_visitor_status visit(ir_dereference_variable *ir)
|
||||
{
|
||||
struct set_entry *entry = _mesa_set_search(variables, ir->var);
|
||||
|
||||
/* If a variable is dereferenced at all, remove it from the set of
|
||||
* variables that are candidates for removal.
|
||||
*/
|
||||
if (entry != NULL)
|
||||
_mesa_set_remove(variables, entry);
|
||||
|
||||
return visit_continue;
|
||||
}
|
||||
|
||||
void remove_dead_variables()
|
||||
{
|
||||
set_foreach(variables, entry) {
|
||||
ir_variable *ir = (ir_variable *) entry->key;
|
||||
|
||||
assert(ir->ir_type == ir_type_variable);
|
||||
ir->remove();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
set *variables;
|
||||
};
|
||||
|
||||
static const struct standalone_options *options;
|
||||
|
||||
static void
|
||||
@@ -486,20 +433,6 @@ standalone_compile_shader(const struct standalone_options *_options,
|
||||
if (!options->just_log)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
|
||||
struct gl_linked_shader *shader = whole_program->_LinkedShaders[i];
|
||||
|
||||
if (!shader)
|
||||
continue;
|
||||
|
||||
add_neg_to_sub_visitor v;
|
||||
visit_list_elements(&v, shader->ir);
|
||||
|
||||
dead_variable_visitor dv;
|
||||
visit_list_elements(&dv, shader->ir);
|
||||
dv.remove_dead_variables();
|
||||
}
|
||||
}
|
||||
|
||||
return whole_program;
|
||||
|
@@ -5,7 +5,6 @@ general_ir_test_files = files(
|
||||
'array_refcount_test.cpp',
|
||||
'builtin_variable_test.cpp',
|
||||
'general_ir_test.cpp',
|
||||
'opt_add_neg_to_sub_test.cpp',
|
||||
)
|
||||
general_ir_test_files += ir_expression_operation_h
|
||||
|
||||
|
@@ -1,214 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2016 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.
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
#include "ir.h"
|
||||
#include "ir_builder.h"
|
||||
#include "opt_add_neg_to_sub.h"
|
||||
|
||||
using namespace ir_builder;
|
||||
|
||||
class add_neg_to_sub : public ::testing::Test {
|
||||
public:
|
||||
virtual void SetUp();
|
||||
virtual void TearDown();
|
||||
|
||||
exec_list instructions;
|
||||
ir_factory *body;
|
||||
void *mem_ctx;
|
||||
ir_variable *var_a;
|
||||
ir_variable *var_b;
|
||||
ir_variable *var_c;
|
||||
add_neg_to_sub_visitor v;
|
||||
};
|
||||
|
||||
void
|
||||
add_neg_to_sub::SetUp()
|
||||
{
|
||||
glsl_type_singleton_init_or_ref();
|
||||
|
||||
mem_ctx = ralloc_context(NULL);
|
||||
|
||||
instructions.make_empty();
|
||||
body = new ir_factory(&instructions, mem_ctx);
|
||||
|
||||
var_a = new(mem_ctx) ir_variable(&glsl_type_builtin_float,
|
||||
"a",
|
||||
ir_var_temporary);
|
||||
|
||||
var_b = new(mem_ctx) ir_variable(&glsl_type_builtin_float,
|
||||
"b",
|
||||
ir_var_temporary);
|
||||
|
||||
var_c = new(mem_ctx) ir_variable(&glsl_type_builtin_float,
|
||||
"c",
|
||||
ir_var_temporary);
|
||||
}
|
||||
|
||||
void
|
||||
add_neg_to_sub::TearDown()
|
||||
{
|
||||
delete body;
|
||||
body = NULL;
|
||||
|
||||
ralloc_free(mem_ctx);
|
||||
mem_ctx = NULL;
|
||||
|
||||
glsl_type_singleton_decref();
|
||||
}
|
||||
|
||||
TEST_F(add_neg_to_sub, a_plus_b)
|
||||
{
|
||||
body->emit(assign(var_c, add(var_a, var_b)));
|
||||
|
||||
visit_list_elements(&v, &instructions);
|
||||
|
||||
ASSERT_FALSE(instructions.is_empty());
|
||||
|
||||
ir_instruction *const ir = (ir_instruction *) instructions.pop_head();
|
||||
|
||||
EXPECT_TRUE(instructions.is_empty());
|
||||
|
||||
/* The resulting instruction should be 'c = a + b'. */
|
||||
ir_assignment *const assign = ir->as_assignment();
|
||||
ASSERT_NE((void *)0, assign);
|
||||
|
||||
EXPECT_EQ(var_c, assign->lhs->variable_referenced());
|
||||
|
||||
ir_expression *const expr = assign->rhs->as_expression();
|
||||
ASSERT_NE((void *)0, expr);
|
||||
EXPECT_EQ(ir_binop_add, expr->operation);
|
||||
|
||||
ir_dereference_variable *const deref_a =
|
||||
expr->operands[0]->as_dereference_variable();
|
||||
ir_dereference_variable *const deref_b =
|
||||
expr->operands[1]->as_dereference_variable();
|
||||
|
||||
ASSERT_NE((void *)0, deref_a);
|
||||
EXPECT_EQ(var_a, deref_a->var);
|
||||
ASSERT_NE((void *)0, deref_b);
|
||||
EXPECT_EQ(var_b, deref_b->var);
|
||||
}
|
||||
|
||||
TEST_F(add_neg_to_sub, a_plus_neg_b)
|
||||
{
|
||||
body->emit(assign(var_c, add(var_a, neg(var_b))));
|
||||
|
||||
visit_list_elements(&v, &instructions);
|
||||
|
||||
ASSERT_FALSE(instructions.is_empty());
|
||||
|
||||
ir_instruction *const ir = (ir_instruction *) instructions.pop_head();
|
||||
|
||||
EXPECT_TRUE(instructions.is_empty());
|
||||
|
||||
/* The resulting instruction should be 'c = a - b'. */
|
||||
ir_assignment *const assign = ir->as_assignment();
|
||||
ASSERT_NE((void *)0, assign);
|
||||
|
||||
EXPECT_EQ(var_c, assign->lhs->variable_referenced());
|
||||
|
||||
ir_expression *const expr = assign->rhs->as_expression();
|
||||
ASSERT_NE((void *)0, expr);
|
||||
EXPECT_EQ(ir_binop_sub, expr->operation);
|
||||
|
||||
ir_dereference_variable *const deref_a =
|
||||
expr->operands[0]->as_dereference_variable();
|
||||
ir_dereference_variable *const deref_b =
|
||||
expr->operands[1]->as_dereference_variable();
|
||||
|
||||
ASSERT_NE((void *)0, deref_a);
|
||||
EXPECT_EQ(var_a, deref_a->var);
|
||||
ASSERT_NE((void *)0, deref_b);
|
||||
EXPECT_EQ(var_b, deref_b->var);
|
||||
}
|
||||
|
||||
TEST_F(add_neg_to_sub, neg_a_plus_b)
|
||||
{
|
||||
body->emit(assign(var_c, add(neg(var_a), var_b)));
|
||||
|
||||
visit_list_elements(&v, &instructions);
|
||||
|
||||
ASSERT_FALSE(instructions.is_empty());
|
||||
|
||||
ir_instruction *const ir = (ir_instruction *) instructions.pop_head();
|
||||
|
||||
EXPECT_TRUE(instructions.is_empty());
|
||||
|
||||
/* The resulting instruction should be 'c = b - a'. */
|
||||
ir_assignment *const assign = ir->as_assignment();
|
||||
ASSERT_NE((void *)0, assign);
|
||||
|
||||
EXPECT_EQ(var_c, assign->lhs->variable_referenced());
|
||||
|
||||
ir_expression *const expr = assign->rhs->as_expression();
|
||||
ASSERT_NE((void *)0, expr);
|
||||
EXPECT_EQ(ir_binop_sub, expr->operation);
|
||||
|
||||
ir_dereference_variable *const deref_b =
|
||||
expr->operands[0]->as_dereference_variable();
|
||||
ir_dereference_variable *const deref_a =
|
||||
expr->operands[1]->as_dereference_variable();
|
||||
|
||||
ASSERT_NE((void *)0, deref_a);
|
||||
EXPECT_EQ(var_a, deref_a->var);
|
||||
ASSERT_NE((void *)0, deref_b);
|
||||
EXPECT_EQ(var_b, deref_b->var);
|
||||
}
|
||||
|
||||
TEST_F(add_neg_to_sub, neg_a_plus_neg_b)
|
||||
{
|
||||
body->emit(assign(var_c, add(neg(var_a), neg(var_b))));
|
||||
|
||||
visit_list_elements(&v, &instructions);
|
||||
|
||||
ASSERT_FALSE(instructions.is_empty());
|
||||
|
||||
ir_instruction *const ir = (ir_instruction *) instructions.pop_head();
|
||||
|
||||
EXPECT_TRUE(instructions.is_empty());
|
||||
|
||||
/* The resulting instruction should be 'c = -b - a'. */
|
||||
ir_assignment *const assign = ir->as_assignment();
|
||||
ASSERT_NE((void *)0, assign);
|
||||
|
||||
EXPECT_EQ(var_c, assign->lhs->variable_referenced());
|
||||
|
||||
ir_expression *const expr = assign->rhs->as_expression();
|
||||
ASSERT_NE((void *)0, expr);
|
||||
EXPECT_EQ(ir_binop_sub, expr->operation);
|
||||
|
||||
ir_expression *const neg_b = expr->operands[0]->as_expression();
|
||||
ir_dereference_variable *const deref_a =
|
||||
expr->operands[1]->as_dereference_variable();
|
||||
|
||||
ASSERT_NE((void *)0, deref_a);
|
||||
EXPECT_EQ(var_a, deref_a->var);
|
||||
|
||||
ASSERT_NE((void *)0, neg_b);
|
||||
|
||||
ir_dereference_variable *const deref_b =
|
||||
neg_b->operands[0]->as_dereference_variable();
|
||||
|
||||
ASSERT_NE((void *)0, deref_b);
|
||||
EXPECT_EQ(var_b, deref_b->var);
|
||||
}
|
Reference in New Issue
Block a user