From 6569b33b6eed94aa8722287344f9f06a9390e0e5 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Wed, 11 Oct 2017 19:56:46 +0200 Subject: [PATCH] mesa/st/tests: unify MockCodeLine* classes * Merge the classes MockCodeLine and MockCodelineWithSwizzle into one, and refactor tests accordingly. * Change memory allocations to use ralloc* interface. v2: * move the test classes into a conveniance library * rename the Mock* classes to Fake* since they are not really Mocks * Base assertion of correct number of src and dst registers in tests on what the operatand actually expects * Fix number of destinations in one test v6: * fix local includes using "..." insteadof <...> Reviewed-by: Brian Paul Signed-off-by: Gert Wollny --- src/mesa/state_tracker/tests/Makefile.am | 6 + .../state_tracker/tests/st_tests_common.cpp | 394 ++++++++++ .../state_tracker/tests/st_tests_common.h | 163 ++++ .../tests/test_glsl_to_tgsi_lifetime.cpp | 719 +++++------------- 4 files changed, 735 insertions(+), 547 deletions(-) create mode 100644 src/mesa/state_tracker/tests/st_tests_common.cpp create mode 100644 src/mesa/state_tracker/tests/st_tests_common.h diff --git a/src/mesa/state_tracker/tests/Makefile.am b/src/mesa/state_tracker/tests/Makefile.am index 6c58d367694..0350c64bf3d 100644 --- a/src/mesa/state_tracker/tests/Makefile.am +++ b/src/mesa/state_tracker/tests/Makefile.am @@ -18,8 +18,13 @@ AM_CPPFLAGS = \ if HAVE_STD_CXX11 TESTS = st-renumerate-test check_PROGRAMS = st-renumerate-test + +noinst_LIBRARIES = libmesa-st-tests-common.a endif +libmesa_st_tests_common_a_SOURCES = \ + st_tests_common.cpp + st_renumerate_test_SOURCES = \ test_glsl_to_tgsi_lifetime.cpp @@ -27,6 +32,7 @@ st_renumerate_test_LDFLAGS = \ $(LLVM_LDFLAGS) st_renumerate_test_LDADD = \ + libmesa-st-tests-common.a \ $(top_builddir)/src/mesa/libmesagallium.la \ $(top_builddir)/src/mapi/shared-glapi/libglapi.la \ $(top_builddir)/src/gallium/auxiliary/libgallium.la \ diff --git a/src/mesa/state_tracker/tests/st_tests_common.cpp b/src/mesa/state_tracker/tests/st_tests_common.cpp new file mode 100644 index 00000000000..03d664dd4bb --- /dev/null +++ b/src/mesa/state_tracker/tests/st_tests_common.cpp @@ -0,0 +1,394 @@ +/* + * Copyright © 2017 Gert Wollny + * + * 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 "st_tests_common.h" + +#include "mesa/program/prog_instruction.h" +#include "tgsi/tgsi_info.h" +#include "tgsi/tgsi_ureg.h" +#include "compiler/glsl/list.h" +#include "gtest/gtest.h" + +#include +#include + +using std::vector; +using std::pair; +using std::make_pair; +using std::transform; +using std::copy; +using std::tuple; + + +/* Implementation of helper and test classes */ +void *FakeCodeline::mem_ctx = nullptr; + +FakeCodeline::FakeCodeline(unsigned _op, const vector& _dst, + const vector& _src, const vector&_to): + op(_op), + max_temp_id(0) +{ + transform(_dst.begin(), _dst.end(), std::back_inserter(dst), + [this](int i) { return create_dst_register(i);}); + + transform(_src.begin(), _src.end(), std::back_inserter(src), + [this](int i) { return create_src_register(i);}); + + transform(_to.begin(), _to.end(), std::back_inserter(tex_offsets), + [this](int i) { return create_src_register(i);}); + +} + +FakeCodeline::FakeCodeline(unsigned _op, const vector>& _dst, + const vector>& _src, + const vector>&_to, + SWZ with_swizzle): + op(_op), + max_temp_id(0) +{ + (void)with_swizzle; + + transform(_dst.begin(), _dst.end(), std::back_inserter(dst), + [this](pair r) { + return create_dst_register(r.first, r.second); + }); + + transform(_src.begin(), _src.end(), std::back_inserter(src), + [this](const pair& r) { + return create_src_register(r.first, r.second); + }); + + transform(_to.begin(), _to.end(), std::back_inserter(tex_offsets), + [this](const pair& r) { + return create_src_register(r.first, r.second); + }); +} + +FakeCodeline::FakeCodeline(const glsl_to_tgsi_instruction& instr): + op(instr.op), + max_temp_id(0) +{ + int nsrc = num_inst_src_regs(&instr); + int ndst = num_inst_dst_regs(&instr); + + copy(instr.src, instr.src + nsrc, std::back_inserter(src)); + copy(instr.dst, instr.dst + ndst, std::back_inserter(dst)); + + for (auto& s: src) + read_reg(s); + + for (auto& d: dst) + read_reg(d); + +} + +template +void FakeCodeline::read_reg(const st_reg& s) +{ + if (s.file == PROGRAM_TEMPORARY) { + if (s.index > max_temp_id) + max_temp_id = s.index; + } +} + +void FakeCodeline::print(std::ostream& os) const +{ + const struct tgsi_opcode_info *info = tgsi_get_opcode_info(op); + os << tgsi_get_opcode_name(info->opcode) << " "; + + for (auto d: dst) { + os << d << " "; + } + os << " <- "; + for (auto s: src) { + os << s << " "; + } + os << "\n"; +} + +bool operator == (const FakeCodeline& lhs, const FakeCodeline& rhs) +{ + if ((lhs.op != rhs.op) || + (lhs.src.size() != rhs.src.size()) || + (lhs.dst.size() != rhs.dst.size())) + return false; + + return std::equal(lhs.src.begin(), lhs.src.end(), rhs.src.begin()) && + std::equal(lhs.dst.begin(), lhs.dst.end(), rhs.dst.begin()); +} + +st_src_reg FakeCodeline::create_src_register(int src_idx) +{ + return create_src_register(src_idx, + src_idx < 0 ? PROGRAM_INPUT : PROGRAM_TEMPORARY); +} + +static int swizzle_from_char(const char *sw) +{ + int swizzle = 0; + if (!sw || sw[0] == 0) + return SWIZZLE_XYZW; + + const char *isw = sw; + for (int i = 0; i < 4; ++i) { + switch (*isw) { + case 'x': break; /* is zero */ + case 'y': swizzle |= SWIZZLE_Y << 3 * i; break; + case 'z': swizzle |= SWIZZLE_Z << 3 * i; break; + case 'w': swizzle |= SWIZZLE_W << 3 * i; break; + default: + assert(!"This test uses an unknown swizzle character"); + } + if (isw[1] != 0) + ++isw; + } + return swizzle; +} + +st_src_reg FakeCodeline::create_src_register(int src_idx, const char *sw) +{ + st_src_reg result = create_src_register(src_idx); + result.swizzle = swizzle_from_char(sw); + return result; +} + +st_src_reg FakeCodeline::create_src_register(int src_idx, gl_register_file file) +{ + st_src_reg retval; + retval.file = file; + retval.index = src_idx >= 0 ? src_idx : 1 - src_idx; + + if (file == PROGRAM_TEMPORARY) { + if (max_temp_id < src_idx) + max_temp_id = src_idx; + } else if (file == PROGRAM_ARRAY) { + retval.array_id = 1; + } + retval.swizzle = SWIZZLE_XYZW; + retval.type = GLSL_TYPE_INT; + + return retval; +} + +st_dst_reg FakeCodeline::create_dst_register(int dst_idx) +{ + return create_dst_register(dst_idx, dst_idx < 0 ? + PROGRAM_OUTPUT : PROGRAM_TEMPORARY); +} + +st_dst_reg FakeCodeline::create_dst_register(int dst_idx,int writemask) +{ + gl_register_file file; + int idx = 0; + if (dst_idx >= 0) { + file = PROGRAM_TEMPORARY; + idx = dst_idx; + if (max_temp_id < idx) + max_temp_id = idx; + } else { + file = PROGRAM_OUTPUT; + idx = 1 - dst_idx; + } + return st_dst_reg(file, writemask, GLSL_TYPE_INT, idx); +} + +st_dst_reg FakeCodeline::create_dst_register(int dst_idx, gl_register_file file) +{ + st_dst_reg retval; + retval.file = file; + retval.index = dst_idx >= 0 ? dst_idx : 1 - dst_idx; + + if (file == PROGRAM_TEMPORARY) { + if (max_temp_id < dst_idx) + max_temp_id = dst_idx; + } else if (file == PROGRAM_ARRAY) { + retval.array_id = 1; + } + retval.writemask = 0xF; + retval.type = GLSL_TYPE_INT; + + return retval; +} + +glsl_to_tgsi_instruction *FakeCodeline::get_codeline() const +{ + glsl_to_tgsi_instruction *next_instr = new(mem_ctx) glsl_to_tgsi_instruction(); + next_instr->op = op; + next_instr->info = tgsi_get_opcode_info(op); + + assert(src.size() == num_inst_src_regs(next_instr)); + assert(dst.size() == num_inst_dst_regs(next_instr)); + assert(tex_offsets.size() < 3); + + copy(src.begin(), src.end(), next_instr->src); + copy(dst.begin(), dst.end(), next_instr->dst); + + next_instr->tex_offset_num_offset = tex_offsets.size(); + + if (next_instr->tex_offset_num_offset > 0) { + next_instr->tex_offsets = ralloc_array(mem_ctx, st_src_reg, tex_offsets.size()); + copy(tex_offsets.begin(), tex_offsets.end(), next_instr->tex_offsets); + } else { + next_instr->tex_offsets = nullptr; + } + return next_instr; +} + +void FakeCodeline::set_mem_ctx(void *ctx) +{ + mem_ctx = ctx; +} + +FakeShader::FakeShader(const vector& source): + program(source), + num_temps(0) +{ + for (const FakeCodeline& i: source) { + int t = i.get_max_reg_id(); + if (t > num_temps) + num_temps = t; + } + ++num_temps; +} + +FakeShader::FakeShader(exec_list *tgsi_prog): + num_temps(0) +{ + FakeCodeline nop(TGSI_OPCODE_NOP); + FakeCodeline& last = nop; + + foreach_in_list(glsl_to_tgsi_instruction, inst, tgsi_prog) { + program.push_back(last = FakeCodeline(*inst)); + if (num_temps < last.get_max_reg_id()) + num_temps = last.get_max_reg_id(); + } + ++num_temps; +} + +int FakeShader::get_num_temps() const +{ + return num_temps; +} + +exec_list* FakeShader::get_program(void *ctx) const +{ + exec_list *prog = new(ctx) exec_list(); + + for (const FakeCodeline& i: program) { + prog->push_tail(i.get_codeline()); + } + + return prog; +} + +void MesaTestWithMemCtx::SetUp() +{ + mem_ctx = ralloc_context(nullptr); + FakeCodeline::set_mem_ctx(mem_ctx); +} + +void MesaTestWithMemCtx::TearDown() +{ + ralloc_free(mem_ctx); + FakeCodeline::set_mem_ctx(nullptr); + mem_ctx = nullptr; +} + + +LifetimeEvaluatorTest::lifetime_result +LifetimeEvaluatorTest::run(const vector& code, bool& success) +{ + FakeShader shader(code); + lifetime_result result(shader.get_num_temps()); + + success = + get_temp_registers_required_lifetimes(mem_ctx, shader.get_program(mem_ctx), + shader.get_num_temps(), + &result[0]); + + return result; +} + +void LifetimeEvaluatorTest::run(const vector& code, const temp_lt_expect& e) +{ + FakeShader shader(code); + lifetime_result result(shader.get_num_temps()); + bool success = + get_temp_registers_required_lifetimes(mem_ctx, shader.get_program(mem_ctx), + shader.get_num_temps(), + &result[0]); + ASSERT_TRUE(success); + ASSERT_EQ(result.size(), e.size()); + check(result, e); +} + +void LifetimeEvaluatorExactTest::check( const vector& lifetimes, + const temp_lt_expect& e) +{ + for (unsigned i = 1; i < lifetimes.size(); ++i) { + EXPECT_EQ(lifetimes[i].begin, e[i][0]); + EXPECT_EQ(lifetimes[i].end, e[i][1]); + } +} + +void LifetimeEvaluatorAtLeastTest::check( const vector& lifetimes, + const temp_lt_expect& e) +{ + for (unsigned i = 1; i < lifetimes.size(); ++i) { + EXPECT_LE(lifetimes[i].begin, e[i][0]); + EXPECT_GE(lifetimes[i].end, e[i][1]); + } +} + +void RegisterRemappingTest::run(const vector& lt, + const vector& expect) +{ + rename_reg_pair proto{false,0}; + vector result(lt.size(), proto); + + get_temp_registers_remapping(mem_ctx, lt.size(), <[0], &result[0]); + + vector remap(lt.size()); + for (unsigned i = 0; i < lt.size(); ++i) { + remap[i] = result[i].valid ? result[i].new_reg : i; + } + + std::transform(remap.begin(), remap.end(), result.begin(), remap.begin(), + [](int x, const rename_reg_pair& rn) { + return rn.valid ? rn.new_reg : x; + }); + + for(unsigned i = 1; i < remap.size(); ++i) { + EXPECT_EQ(remap[i], expect[i]); + } +} + +void RegisterLifetimeAndRemappingTest::run(const vector& code, + const vector& expect) +{ + FakeShader shader(code); + std::vector lt(shader.get_num_temps()); + get_temp_registers_required_lifetimes(mem_ctx, shader.get_program(mem_ctx), + shader.get_num_temps(), <[0]); + this->run(lt, expect); +} diff --git a/src/mesa/state_tracker/tests/st_tests_common.h b/src/mesa/state_tracker/tests/st_tests_common.h new file mode 100644 index 00000000000..cea8a5ce08e --- /dev/null +++ b/src/mesa/state_tracker/tests/st_tests_common.h @@ -0,0 +1,163 @@ +/* + * Copyright © 2017 Gert Wollny + * + * 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 mesa_st_tests_h +#define mesa_st_tests_h + +#include +#include +#include + +#define MP(X, W) std::make_pair(X, W) +#define MT(X,Y,Z) std::make_tuple(X,Y,Z) + + +/* Use this to make the compiler pick the swizzle constructor below */ +struct SWZ {}; + +/* A line to describe a TGSI instruction for building mock shaders. */ +struct FakeCodeline { + FakeCodeline(unsigned _op): op(_op), max_temp_id(0){} + FakeCodeline(unsigned _op, const std::vector& _dst, const std::vector& _src, + const std::vector&_to); + + FakeCodeline(unsigned _op, const std::vector>& _dst, + const std::vector>& _src, + const std::vector>&_to, SWZ with_swizzle); + + FakeCodeline(const glsl_to_tgsi_instruction& inst); + + int get_max_reg_id() const { return max_temp_id;} + + glsl_to_tgsi_instruction *get_codeline() const; + + static void set_mem_ctx(void *ctx); + + friend bool operator == (const FakeCodeline& lsh, const FakeCodeline& rhs); + + void print(std::ostream& os) const; +private: + st_src_reg create_src_register(int src_idx); + st_src_reg create_src_register(int src_idx, const char *swizzle); + st_src_reg create_src_register(int src_idx, gl_register_file file); + + st_dst_reg create_dst_register(int dst_idx); + st_dst_reg create_dst_register(int dst_idx, int writemask); + st_dst_reg create_dst_register(int dst_idx, gl_register_file file); + + template + void read_reg(const st_reg& s); + + unsigned op; + std::vector dst; + std::vector src; + std::vector tex_offsets; + + int max_temp_id; + static void *mem_ctx; +}; + +inline std::ostream& operator << (std::ostream& os, const FakeCodeline& line) +{ + line.print(os); + return os; +} + +/* A few constants that will not be tracked as temporary registers + by the fake shader. + */ +const int in0 = -1; +const int in1 = -2; +const int in2 = -3; + +const int out0 = -1; +const int out1 = -2; +const int out2 = -3; + +class FakeShader { +public: + FakeShader(const std::vector& source); + FakeShader(exec_list *tgsi_prog); + + exec_list* get_program(void *ctx) const; + int get_num_temps() const; + +private: + + std::vector program; + int num_temps; +}; + +using temp_lt_expect = std::vector>; + +class MesaTestWithMemCtx : public testing::Test { + void SetUp(); + void TearDown(); +protected: + void *mem_ctx; +}; + +class LifetimeEvaluatorTest : public MesaTestWithMemCtx { +protected: + void run(const std::vector& code, const temp_lt_expect& e); +private: + using lifetime_result=std::vector; + lifetime_result run(const std::vector& code, bool& success); + + virtual void check(const std::vector& result, const temp_lt_expect& e) = 0; +}; + +/* This is a test class to check the exact life times of + * registers. */ +class LifetimeEvaluatorExactTest : public LifetimeEvaluatorTest { +protected: + void check(const std::vector& result, const temp_lt_expect& e); + +}; + +/* This test class checks that the life time covers at least + * in the expected range. It is used for cases where we know that + * a the implementation could be improved on estimating the minimal + * life time. + */ +class LifetimeEvaluatorAtLeastTest : public LifetimeEvaluatorTest { +protected: + void check(const std::vector& result, const temp_lt_expect& e); +}; + +/* With this test class the renaming mapping estimation is tested */ +class RegisterRemappingTest : public MesaTestWithMemCtx { +protected: + void run(const std::vector& lt, const std::vector &expect); +}; + +/* With this test class the combined lifetime estimation and renaming + * mepping estimation is tested + */ +class RegisterLifetimeAndRemappingTest : public RegisterRemappingTest { +protected: + using RegisterRemappingTest::run; + void run(const std::vector& code, const std::vector &expect); +}; + +#endif diff --git a/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp b/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp index 1c8b9acfa4f..4f226429aff 100644 --- a/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp +++ b/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp @@ -21,155 +21,43 @@ * DEALINGS IN THE SOFTWARE. */ -#include #include #include -#include #include -#include #include +#include +#include +#include + +#include "st_tests_common.h" using std::vector; using std::pair; using std::make_pair; +using std::transform; +using std::copy; -/* A line to describe a TGSI instruction for building mock shaders. */ -struct MockCodeline { - MockCodeline(unsigned _op): op(_op) {} - MockCodeline(unsigned _op, const vector& _dst, const vector& _src, const vector&_to): - op(_op), dst(_dst), src(_src), tex_offsets(_to){} - unsigned op; - vector dst; - vector src; - vector tex_offsets; -}; - -/* A line to describe a TGSI instruction with swizzeling and write makss - * for building mock shaders. - */ -struct MockCodelineWithSwizzle { - MockCodelineWithSwizzle(unsigned _op): op(_op) {} - MockCodelineWithSwizzle(unsigned _op, const vector>& _dst, - const vector>& _src, - const vector>&_to): - op(_op), dst(_dst), src(_src), tex_offsets(_to){} - unsigned op; - vector> dst; - vector> src; - vector> tex_offsets; -}; - -/* A few constants that will notbe tracked as temporary registers by the - * mock shader. - */ -const int in0 = -1; -const int in1 = -2; -const int in2 = -3; - -const int out0 = -1; -const int out1 = -2; - -class MockShader { -public: - MockShader(const vector& source); - MockShader(const vector& source); - ~MockShader(); - - void free(); - - exec_list* get_program() const; - int get_num_temps() const; -private: - st_src_reg create_src_register(int src_idx); - st_dst_reg create_dst_register(int dst_idx); - st_src_reg create_src_register(int src_idx, const char *swizzle); - st_dst_reg create_dst_register(int dst_idx,int writemask); - exec_list* program; - int num_temps; - void *mem_ctx; -}; - -using expectation = vector>; - -class MesaTestWithMemCtx : public testing::Test { - void SetUp(); - void TearDown(); -protected: - void *mem_ctx; -}; - -class LifetimeEvaluatorTest : public MesaTestWithMemCtx { -protected: - void run(const vector& code, const expectation& e); - void run(const vector& code, const expectation& e); -private: - virtual void check(const vector& result, const expectation& e) = 0; -}; - -/* This is a test class to check the exact life times of - * registers. */ -class LifetimeEvaluatorExactTest : public LifetimeEvaluatorTest { -protected: - void check(const vector& result, const expectation& e); -}; - -/* This test class checks that the life time covers at least - * in the expected range. It is used for cases where we know that - * a the implementation could be improved on estimating the minimal - * life time. - */ -class LifetimeEvaluatorAtLeastTest : public LifetimeEvaluatorTest { -protected: - void check(const vector& result, const expectation& e); -}; - -/* With this test class the renaming mapping estimation is tested */ -class RegisterRemappingTest : public MesaTestWithMemCtx { -protected: - void run(const vector& lt, const vector& expect); -}; - -/* With this test class the combined lifetime estimation and renaming - * mepping estimation is tested - */ -class RegisterLifetimeAndRemappingTest : public RegisterRemappingTest { -protected: - using RegisterRemappingTest::run; - template - void run(const vector& code, const vector& expect); -}; - -template -void RegisterLifetimeAndRemappingTest::run(const vector& code, - const vector& expect) -{ - MockShader shader(code); - std::vector lt(shader.get_num_temps()); - get_temp_registers_required_lifetimes(mem_ctx, shader.get_program(), - shader.get_num_temps(), <[0]); - this->run(lt, expect); -} TEST_F(LifetimeEvaluatorExactTest, SimpleMoveAdd) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_UADD, {out0}, {1,in0}, {}}, { TGSI_OPCODE_END} }; - run(code, expectation({{-1,-1}, {0,1}})); + run(code, temp_lt_expect({{-1,-1}, {0,1}})); } TEST_F(LifetimeEvaluatorExactTest, SimpleMoveAddMove) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_UADD, {2}, {1,in0}, {}}, { TGSI_OPCODE_MOV, {out0}, {2}, {}}, { TGSI_OPCODE_END} }; - run(code, expectation({{-1, -1}, {0,1}, {1,2}})); + run(code, temp_lt_expect({{-1, -1}, {0,1}, {1,2}})); } /* Test whether the texoffst are actually visited by the @@ -180,13 +68,13 @@ TEST_F(LifetimeEvaluatorExactTest, SimpleMoveAddMove) */ TEST_F(LifetimeEvaluatorExactTest, SimpleOpWithTexoffset) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_MOV, {2}, {in1}, {}}, { TGSI_OPCODE_TEX, {out0}, {in0}, {1,2}}, { TGSI_OPCODE_END} }; - run(code, expectation({{-1, -1}, {0,2}, {1,2}})); + run(code, temp_lt_expect({{-1, -1}, {0,2}, {1,2}})); } /* Simple register access involving a loop @@ -196,7 +84,7 @@ TEST_F(LifetimeEvaluatorExactTest, SimpleOpWithTexoffset) */ TEST_F(LifetimeEvaluatorExactTest, SimpleMoveInLoop) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_UADD, {2}, {1,in0}, {}}, @@ -206,7 +94,7 @@ TEST_F(LifetimeEvaluatorExactTest, SimpleMoveInLoop) { TGSI_OPCODE_MOV, {out0}, {3}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,5}, {2,3}, {3,6}})); + run (code, temp_lt_expect({{-1,-1}, {0,5}, {2,3}, {3,6}})); } /* In loop if/else value written only in one path, and read later @@ -214,7 +102,7 @@ TEST_F(LifetimeEvaluatorExactTest, SimpleMoveInLoop) */ TEST_F(LifetimeEvaluatorExactTest, MoveInIfInLoop) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_IF, {}, {in1}, {}}, @@ -226,7 +114,7 @@ TEST_F(LifetimeEvaluatorExactTest, MoveInIfInLoop) { TGSI_OPCODE_MOV, {out0}, {3}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,7}, {1,7}, {5,8}})); + run (code, temp_lt_expect({{-1,-1}, {0,7}, {1,7}, {5,8}})); } /* A non-dominant write within an IF can be ignored (if it is read @@ -234,7 +122,7 @@ TEST_F(LifetimeEvaluatorExactTest, MoveInIfInLoop) */ TEST_F(LifetimeEvaluatorExactTest, NonDominantWriteinIfInLoop) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_IF, {}, {in1}, {}}, @@ -248,7 +136,7 @@ TEST_F(LifetimeEvaluatorExactTest, NonDominantWriteinIfInLoop) { TGSI_OPCODE_MOV, {out0}, {2}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {1,5}, {5,10}})); + run (code, temp_lt_expect({{-1,-1}, {1,5}, {5,10}})); } /* In Nested loop if/else value written only in one path, and read later @@ -256,7 +144,7 @@ TEST_F(LifetimeEvaluatorExactTest, NonDominantWriteinIfInLoop) */ TEST_F(LifetimeEvaluatorExactTest, MoveInIfInNestedLoop) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_BGNLOOP }, @@ -269,7 +157,7 @@ TEST_F(LifetimeEvaluatorExactTest, MoveInIfInNestedLoop) { TGSI_OPCODE_MOV, {out0}, {3}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,8}, {1,8}, {6,9}})); + run (code, temp_lt_expect({{-1,-1}, {0,8}, {1,8}, {6,9}})); } /* In loop if/else value written in both path, and read later @@ -278,7 +166,7 @@ TEST_F(LifetimeEvaluatorExactTest, MoveInIfInNestedLoop) */ TEST_F(LifetimeEvaluatorAtLeastTest, WriteInIfAndElseInLoop) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_IF, {}, {1}, {}}, @@ -292,7 +180,7 @@ TEST_F(LifetimeEvaluatorAtLeastTest, WriteInIfAndElseInLoop) { TGSI_OPCODE_MOV, {out0}, {3}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,9}, {3,7}, {7,10}})); + run (code, temp_lt_expect({{-1,-1}, {0,9}, {3,7}, {7,10}})); } /* In loop if/else value written in both path, read in else path @@ -301,7 +189,7 @@ TEST_F(LifetimeEvaluatorAtLeastTest, WriteInIfAndElseInLoop) */ TEST_F(LifetimeEvaluatorExactTest, WriteInIfAndElseReadInElseInLoop) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_IF, {}, {1}, {}}, @@ -315,7 +203,7 @@ TEST_F(LifetimeEvaluatorExactTest, WriteInIfAndElseReadInElseInLoop) { TGSI_OPCODE_MOV, {out0}, {3}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,9}, {1,9}, {7,10}})); + run (code, temp_lt_expect({{-1,-1}, {0,9}, {1,9}, {7,10}})); } /* In loop if/else read in one path before written in the same loop @@ -323,7 +211,7 @@ TEST_F(LifetimeEvaluatorExactTest, WriteInIfAndElseReadInElseInLoop) */ TEST_F(LifetimeEvaluatorExactTest, ReadInIfInLoopBeforeWrite) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_IF, {}, {in0}, {}}, @@ -335,7 +223,7 @@ TEST_F(LifetimeEvaluatorExactTest, ReadInIfInLoopBeforeWrite) { TGSI_OPCODE_MOV, {out0}, {3}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,7}, {1,7}, {1,8}})); + run (code, temp_lt_expect({{-1,-1}, {0,7}, {1,7}, {1,8}})); } /* In loop if/else read in one path before written in the same loop @@ -344,7 +232,7 @@ TEST_F(LifetimeEvaluatorExactTest, ReadInIfInLoopBeforeWrite) */ TEST_F(LifetimeEvaluatorExactTest, ReadInLoopInIfBeforeWriteAndLifeToTheEnd) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_IF, {}, {in0}, {}}, { TGSI_OPCODE_MUL, {1}, {1,in1}, {}}, @@ -354,7 +242,7 @@ TEST_F(LifetimeEvaluatorExactTest, ReadInLoopInIfBeforeWriteAndLifeToTheEnd) { TGSI_OPCODE_MOV, {out0}, {1}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,6}})); + run (code, temp_lt_expect({{-1,-1}, {0,6}})); } /* In loop if/else read in one path before written in the same loop @@ -363,7 +251,7 @@ TEST_F(LifetimeEvaluatorExactTest, ReadInLoopInIfBeforeWriteAndLifeToTheEnd) */ TEST_F(LifetimeEvaluatorExactTest, ReadInLoopBeforeWriteAndLifeToTheEnd) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_MUL, {1}, {1,in1}, {}}, { TGSI_OPCODE_UADD, {1}, {1,in1}, {}}, @@ -371,7 +259,7 @@ TEST_F(LifetimeEvaluatorExactTest, ReadInLoopBeforeWriteAndLifeToTheEnd) { TGSI_OPCODE_MOV, {out0}, {1}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,4}})); + run (code, temp_lt_expect({{-1,-1}, {0,4}})); } @@ -381,7 +269,7 @@ TEST_F(LifetimeEvaluatorExactTest, ReadInLoopBeforeWriteAndLifeToTheEnd) */ TEST_F(LifetimeEvaluatorAtLeastTest, NestedIfInLoopAlwaysWriteButNotPropagated) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_IF, {}, {in0}, {}}, { TGSI_OPCODE_IF, {}, {in0}, {}}, @@ -400,7 +288,7 @@ TEST_F(LifetimeEvaluatorAtLeastTest, NestedIfInLoopAlwaysWriteButNotPropagated) { TGSI_OPCODE_ENDLOOP }, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {3,14}})); + run (code, temp_lt_expect({{-1,-1}, {3,14}})); } /* The value is written in a loop and in a nested if, but @@ -408,7 +296,7 @@ TEST_F(LifetimeEvaluatorAtLeastTest, NestedIfInLoopAlwaysWriteButNotPropagated) */ TEST_F(LifetimeEvaluatorExactTest, NestedIfInLoopWriteNotAlways) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_IF, {}, {in0}, {}}, { TGSI_OPCODE_IF, {}, {in0}, {}}, @@ -425,13 +313,13 @@ TEST_F(LifetimeEvaluatorExactTest, NestedIfInLoopWriteNotAlways) { TGSI_OPCODE_ENDLOOP }, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,13}})); + run (code, temp_lt_expect({{-1,-1}, {0,13}})); } /* A continue in the loop is not relevant */ TEST_F(LifetimeEvaluatorExactTest, LoopWithWriteAfterContinue) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_IF, {}, {in0}, {}}, { TGSI_OPCODE_CONT}, @@ -441,7 +329,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithWriteAfterContinue) { TGSI_OPCODE_MOV, {out0}, {1}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {4,6}})); + run (code, temp_lt_expect({{-1,-1}, {4,6}})); } /* Temporary used to in case must live up to the case @@ -451,7 +339,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithWriteAfterContinue) */ TEST_F(LifetimeEvaluatorExactTest, UseSwitchCase) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_MOV, {2}, {in1}, {}}, { TGSI_OPCODE_MOV, {3}, {in2}, {}}, @@ -463,7 +351,7 @@ TEST_F(LifetimeEvaluatorExactTest, UseSwitchCase) { TGSI_OPCODE_ENDSWITCH}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,5}, {1,4}, {2,3}})); + run (code, temp_lt_expect({{-1,-1}, {0,5}, {1,4}, {2,3}})); } /* With two destinations, if one result is thrown away, the @@ -471,14 +359,14 @@ TEST_F(LifetimeEvaluatorExactTest, UseSwitchCase) */ TEST_F(LifetimeEvaluatorExactTest, WriteTwoOnlyUseOne) { - const vector code = { + const vector code = { { TGSI_OPCODE_DFRACEXP , {1,2}, {in0}, {}}, { TGSI_OPCODE_ADD , {3}, {2,in0}, {}}, { TGSI_OPCODE_MOV, {out1}, {3}, {}}, { TGSI_OPCODE_END}, }; - run (code, expectation({{-1,-1}, {0,1}, {0,1}, {1,2}})); + run (code, temp_lt_expect({{-1,-1}, {0,1}, {0,1}, {1,2}})); } /* If a break is in the loop, all variables written after the @@ -487,7 +375,7 @@ TEST_F(LifetimeEvaluatorExactTest, WriteTwoOnlyUseOne) */ TEST_F(LifetimeEvaluatorExactTest, LoopWithWriteAfterBreak) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_IF, {}, {in0}, {}}, { TGSI_OPCODE_BRK}, @@ -497,7 +385,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithWriteAfterBreak) { TGSI_OPCODE_MOV, {out0}, {1}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,6}})); + run (code, temp_lt_expect({{-1,-1}, {0,6}})); } /* If a break is in the loop, all variables written after the @@ -506,7 +394,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithWriteAfterBreak) */ TEST_F(LifetimeEvaluatorExactTest, LoopWithWriteAfterBreak2Breaks) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_IF, {}, {in0}, {}}, { TGSI_OPCODE_BRK}, @@ -517,7 +405,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithWriteAfterBreak2Breaks) { TGSI_OPCODE_MOV, {out0}, {1}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,7}})); + run (code, temp_lt_expect({{-1,-1}, {0,7}})); } /* Loop with a break at the beginning and read/write in the post @@ -529,7 +417,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithWriteAfterBreak2Breaks) */ TEST_F(LifetimeEvaluatorExactTest, LoopWithWriteAndReadAfterBreak) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_IF, {}, {in0}, {}}, { TGSI_OPCODE_BRK}, @@ -540,7 +428,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithWriteAndReadAfterBreak) { TGSI_OPCODE_MOV, {out0}, {2}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {4,5}, {0,7}})); + run (code, temp_lt_expect({{-1,-1}, {4,5}, {0,7}})); } /* Same as above, just make sure that the life time of the local variable @@ -548,7 +436,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithWriteAndReadAfterBreak) */ TEST_F(LifetimeEvaluatorExactTest, NestedLoopWithWriteAndReadAfterBreak) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_IF, {}, {in1}, {}}, { TGSI_OPCODE_BRK}, @@ -566,7 +454,7 @@ TEST_F(LifetimeEvaluatorExactTest, NestedLoopWithWriteAndReadAfterBreak) { TGSI_OPCODE_MOV, {out0}, {4}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {8,9}, {0,13}, {11,12}, {0,14}})); + run (code, temp_lt_expect({{-1,-1}, {8,9}, {0,13}, {11,12}, {0,14}})); } /* If a break is in the loop inside a switch case, make sure it is @@ -575,7 +463,7 @@ TEST_F(LifetimeEvaluatorExactTest, NestedLoopWithWriteAndReadAfterBreak) */ TEST_F(LifetimeEvaluatorExactTest, LoopWithWriteAfterBreakInSwitchInLoop) { - const vector code = { + const vector code = { { TGSI_OPCODE_SWITCH, {}, {in1}, {}}, { TGSI_OPCODE_CASE, {}, {in1}, {}}, { TGSI_OPCODE_BGNLOOP }, @@ -589,7 +477,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithWriteAfterBreakInSwitchInLoop) { TGSI_OPCODE_MOV, {out0}, {1}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {2,10}})); + run (code, temp_lt_expect({{-1,-1}, {2,10}})); } /* Value written conditionally in one loop and read in another loop, @@ -598,7 +486,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithWriteAfterBreakInSwitchInLoop) */ TEST_F(LifetimeEvaluatorExactTest, LoopsWithDifferntScopesConditionalWrite) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_IF, {}, {in0}, {}}, { TGSI_OPCODE_MOV, {1}, {in0}, {}}, @@ -609,7 +497,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopsWithDifferntScopesConditionalWrite) { TGSI_OPCODE_ENDLOOP }, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,7}})); + run (code, temp_lt_expect({{-1,-1}, {0,7}})); } /* Value written and read in one loop and last read in another loop, @@ -617,7 +505,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopsWithDifferntScopesConditionalWrite) */ TEST_F(LifetimeEvaluatorExactTest, LoopsWithDifferntScopesFirstReadBeforeWrite) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_MUL, {1}, {1,in0}, {}}, { TGSI_OPCODE_ENDLOOP }, @@ -626,7 +514,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopsWithDifferntScopesFirstReadBeforeWrite) { TGSI_OPCODE_ENDLOOP }, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,5}})); + run (code, temp_lt_expect({{-1,-1}, {0,5}})); } @@ -635,7 +523,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopsWithDifferntScopesFirstReadBeforeWrite) */ TEST_F(LifetimeEvaluatorExactTest, LoopWithWriteInSwitch) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_SWITCH, {}, {in0}, {} }, { TGSI_OPCODE_CASE, {}, {in0}, {} }, @@ -648,7 +536,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithWriteInSwitch) { TGSI_OPCODE_ENDLOOP }, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,9}})); + run (code, temp_lt_expect({{-1,-1}, {0,9}})); } /* Value written in one case, and read in other,in loop @@ -656,7 +544,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithWriteInSwitch) */ TEST_F(LifetimeEvaluatorExactTest, LoopWithReadWriteInSwitchDifferentCase) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_SWITCH, {}, {in0}, {} }, { TGSI_OPCODE_CASE, {}, {in0}, {} }, @@ -669,7 +557,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithReadWriteInSwitchDifferentCase) { TGSI_OPCODE_ENDLOOP }, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,9}})); + run (code, temp_lt_expect({{-1,-1}, {0,9}})); } /* Value written in one case, and read in other,in loop @@ -677,7 +565,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithReadWriteInSwitchDifferentCase) */ TEST_F(LifetimeEvaluatorExactTest, LoopWithReadWriteInSwitchDifferentCaseFallThrough) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_SWITCH, {}, {in0}, {} }, { TGSI_OPCODE_CASE, {}, {in0}, {} }, @@ -689,7 +577,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithReadWriteInSwitchDifferentCaseFallThr { TGSI_OPCODE_ENDLOOP }, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,8}})); + run (code, temp_lt_expect({{-1,-1}, {0,8}})); } @@ -699,7 +587,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithReadWriteInSwitchDifferentCaseFallThr */ TEST_F(LifetimeEvaluatorExactTest, WriteSelectFromSelf) { - const vector code = { + const vector code = { {TGSI_OPCODE_USEQ, {5}, {in0,in1}, {}}, {TGSI_OPCODE_UCMP, {1}, {5,in1,1}, {}}, {TGSI_OPCODE_UCMP, {1}, {5,in1,1}, {}}, @@ -716,7 +604,7 @@ TEST_F(LifetimeEvaluatorExactTest, WriteSelectFromSelf) {TGSI_OPCODE_MOV, {out1}, {3}, {}}, {TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {1,5}, {5,6}, {7,13}, {9,11}, {0,4}})); + run (code, temp_lt_expect({{-1,-1}, {1,5}, {5,6}, {7,13}, {9,11}, {0,4}})); } /* This test checks wheter the ENDSWITCH is handled properly if the @@ -724,7 +612,7 @@ TEST_F(LifetimeEvaluatorExactTest, WriteSelectFromSelf) */ TEST_F(LifetimeEvaluatorExactTest, LoopRWInSwitchCaseLastCaseWithoutBreak) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_SWITCH, {}, {in0}, {} }, { TGSI_OPCODE_CASE, {}, {in0}, {} }, @@ -736,13 +624,13 @@ TEST_F(LifetimeEvaluatorExactTest, LoopRWInSwitchCaseLastCaseWithoutBreak) { TGSI_OPCODE_ENDLOOP }, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,8}})); + run (code, temp_lt_expect({{-1,-1}, {0,8}})); } /* Value read/write in same case, stays there */ TEST_F(LifetimeEvaluatorExactTest, LoopWithReadWriteInSwitchSameCase) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_SWITCH, {}, {in0}, {} }, { TGSI_OPCODE_CASE, {}, {in0}, {} }, @@ -755,7 +643,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithReadWriteInSwitchSameCase) { TGSI_OPCODE_ENDLOOP }, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {3,4}})); + run (code, temp_lt_expect({{-1,-1}, {3,4}})); } /* Value read/write in all cases, should only live from first @@ -763,7 +651,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithReadWriteInSwitchSameCase) */ TEST_F(LifetimeEvaluatorAtLeastTest, LoopWithReadWriteInSwitchSameCase) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_SWITCH, {}, {in0}, {}}, { TGSI_OPCODE_CASE, {}, {in0}, {} }, @@ -777,13 +665,13 @@ TEST_F(LifetimeEvaluatorAtLeastTest, LoopWithReadWriteInSwitchSameCase) { TGSI_OPCODE_ENDLOOP }, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {3,9}})); + run (code, temp_lt_expect({{-1,-1}, {3,9}})); } /* First read before first write with nested loops */ TEST_F(LifetimeEvaluatorExactTest, LoopsWithDifferentScopesCondReadBeforeWrite) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_IF, {}, {in0}, {}}, @@ -796,7 +684,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopsWithDifferentScopesCondReadBeforeWrite) { TGSI_OPCODE_ENDLOOP }, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,9}})); + run (code, temp_lt_expect({{-1,-1}, {0,9}})); } /* First read before first write wiredness with nested loops. @@ -805,7 +693,7 @@ TEST_F(LifetimeEvaluatorExactTest, LoopsWithDifferentScopesCondReadBeforeWrite) */ TEST_F(LifetimeEvaluatorExactTest, FirstWriteAtferReadInNestedLoop) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_BGNLOOP }, @@ -817,7 +705,7 @@ TEST_F(LifetimeEvaluatorExactTest, FirstWriteAtferReadInNestedLoop) { TGSI_OPCODE_MOV, {out0}, {3}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,7}, {1,7}, {4,8}})); + run (code, temp_lt_expect({{-1,-1}, {0,7}, {1,7}, {4,8}})); } @@ -831,82 +719,83 @@ TEST_F(LifetimeEvaluatorExactTest, FirstWriteAtferReadInNestedLoop) */ TEST_F(LifetimeEvaluatorExactTest, LoopWithConditionalComponentWrite_X) { - const vector code = { - MockCodelineWithSwizzle(TGSI_OPCODE_BGNLOOP), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(1, WRITEMASK_Y), SRC(in1, "x"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_IF, {}, SRC(in0, "xxxx"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(1, WRITEMASK_X), SRC(in1, "y"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_ENDIF), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(2, WRITEMASK_XY), SRC(1, "xy"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_ENDLOOP), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(out0, WRITEMASK_XYZW), SRC(2, "xyxy"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_END) + const vector code = { + { TGSI_OPCODE_BGNLOOP}, + { TGSI_OPCODE_MOV, DST(1, WRITEMASK_Y), SRC(in1, "x"), {}, SWZ()}, + { TGSI_OPCODE_IF, {}, SRC(in0, "xxxx"), {}, SWZ()}, + { TGSI_OPCODE_MOV, DST(1, WRITEMASK_X), SRC(in1, "y"), {}, SWZ()}, + { TGSI_OPCODE_ENDIF}, + { TGSI_OPCODE_MOV, DST(2, WRITEMASK_XY), SRC(1, "xy"), {}, SWZ()}, + { TGSI_OPCODE_ENDLOOP}, + { TGSI_OPCODE_MOV, DST(out0, WRITEMASK_XYZW), SRC(2, "xyxy"), {}, SWZ()}, + { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,6}, {5,7}})); + run (code, temp_lt_expect({{-1,-1}, {0,6}, {5,7}})); } TEST_F(LifetimeEvaluatorExactTest, LoopWithConditionalComponentWrite_Y) { - const vector code = { - MockCodelineWithSwizzle(TGSI_OPCODE_BGNLOOP), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(1, WRITEMASK_X), SRC(in1, "x"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_IF, {}, SRC(in0, "xxxx"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(1, WRITEMASK_Y), SRC(in1, "y"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_ENDIF), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(2, WRITEMASK_XY), SRC(1, "xy"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_ENDLOOP), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(out0, WRITEMASK_XYZW), SRC(2, "xyxy"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_END) + const vector code = { + { TGSI_OPCODE_BGNLOOP}, + { TGSI_OPCODE_MOV, DST(1, WRITEMASK_X), SRC(in1, "x"), {}, SWZ()}, + { TGSI_OPCODE_IF, {}, SRC(in0, "xxxx"), {}, SWZ()}, + { TGSI_OPCODE_MOV, DST(1, WRITEMASK_Y), SRC(in1, "y"), {}, SWZ()}, + { TGSI_OPCODE_ENDIF}, + { TGSI_OPCODE_MOV, DST(2, WRITEMASK_XY), SRC(1, "xy"), {}, SWZ()}, + { TGSI_OPCODE_ENDLOOP}, + { TGSI_OPCODE_MOV, DST(out0, WRITEMASK_XYZW), SRC(2, "xyxy"), {}, SWZ()}, + { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,6}, {5,7}})); + run (code, temp_lt_expect({{-1,-1}, {0,6}, {5,7}})); } TEST_F(LifetimeEvaluatorExactTest, LoopWithConditionalComponentWrite_Z) { - const vector code = { - MockCodelineWithSwizzle(TGSI_OPCODE_BGNLOOP), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(1, WRITEMASK_X), SRC(in1, "x"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_IF, {}, SRC(in0, "xxxx"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(1, WRITEMASK_Z), SRC(in1, "y"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_ENDIF), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(2, WRITEMASK_XY), SRC(1, "xz"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_ENDLOOP), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(out0, WRITEMASK_XYZW), SRC(2, "xyxy"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_END) + const vector code = { + { TGSI_OPCODE_BGNLOOP}, + { TGSI_OPCODE_MOV, DST(1, WRITEMASK_X), SRC(in1, "x"), {}, SWZ()}, + { TGSI_OPCODE_IF, {}, SRC(in0, "xxxx"), {}, SWZ()}, + { TGSI_OPCODE_MOV, DST(1, WRITEMASK_Z), SRC(in1, "y"), {}, SWZ()}, + { TGSI_OPCODE_ENDIF}, + { TGSI_OPCODE_MOV, DST(2, WRITEMASK_XY), SRC(1, "xz"), {}, SWZ()}, + { TGSI_OPCODE_ENDLOOP}, + { TGSI_OPCODE_MOV, DST(out0, WRITEMASK_XYZW), SRC(2, "xyxy"), {}, SWZ()}, + { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,6}, {5,7}})); + run (code, temp_lt_expect({{-1,-1}, {0,6}, {5,7}})); } TEST_F(LifetimeEvaluatorExactTest, LoopWithConditionalComponentWrite_W) { - const vector code = { - MockCodelineWithSwizzle(TGSI_OPCODE_BGNLOOP), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(1, WRITEMASK_X), SRC(in1, "x"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_IF, {}, SRC(in0, "xxxx"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(1, WRITEMASK_W), SRC(in1, "y"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_ENDIF), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(2, WRITEMASK_XY), SRC(1, "xw"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_ENDLOOP), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(out0, WRITEMASK_XYZW), SRC(2, "xyxy"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_END) + const vector code = { + { TGSI_OPCODE_BGNLOOP}, + { TGSI_OPCODE_MOV, DST(1, WRITEMASK_X), SRC(in1, "x"), {}, SWZ()}, + { TGSI_OPCODE_IF, {}, SRC(in0, "xxxx"), {}, SWZ()}, + { TGSI_OPCODE_MOV, DST(1, WRITEMASK_W), SRC(in1, "y"), {}, SWZ()}, + { TGSI_OPCODE_ENDIF}, + { TGSI_OPCODE_MOV, DST(2, WRITEMASK_XY), SRC(1, "xw"), {}, SWZ()}, + { TGSI_OPCODE_ENDLOOP}, + { TGSI_OPCODE_MOV, DST(out0, WRITEMASK_XYZW), SRC(2, "xyxy"), {}, SWZ()}, + { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,6}, {5,7}})); + run (code, temp_lt_expect({{-1,-1}, {0,6}, {5,7}})); } TEST_F(LifetimeEvaluatorExactTest, LoopWithConditionalComponentWrite_X_Read_Y_Before) { - const vector code = { - MockCodelineWithSwizzle(TGSI_OPCODE_BGNLOOP), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(1, WRITEMASK_X), SRC(in1, "x"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_IF, {}, SRC(in0, "xxxx"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(2, WRITEMASK_XYZW), SRC(1, "yyyy"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_ENDIF), - MockCodelineWithSwizzle(TGSI_OPCODE_MOV, DST(1, WRITEMASK_YZW), SRC(2, "yyzw"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_ENDLOOP), - MockCodelineWithSwizzle(TGSI_OPCODE_ADD, DST(out0, WRITEMASK_XYZW), SRC2(2, "yyzw", 1, "xyxy"), {}), - MockCodelineWithSwizzle(TGSI_OPCODE_END) + const vector code = { + { TGSI_OPCODE_BGNLOOP}, + { TGSI_OPCODE_MOV, DST(1, WRITEMASK_X), SRC(in1, "x"), {}, SWZ()}, + { TGSI_OPCODE_IF, {}, SRC(in0, "xxxx"), {}, SWZ()}, + { TGSI_OPCODE_MOV, DST(2, WRITEMASK_XYZW), SRC(1, "yyyy"), {}, SWZ()}, + { TGSI_OPCODE_ENDIF}, + { TGSI_OPCODE_MOV, DST(1, WRITEMASK_YZW), SRC(2, "yyzw"), {}, SWZ()}, + { TGSI_OPCODE_ENDLOOP}, + { TGSI_OPCODE_ADD, DST(out0, WRITEMASK_XYZW), + SRC2(2, "yyzw", 1, "xyxy"), {}, SWZ()}, + { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,7}, {0,7}})); + run (code, temp_lt_expect({{-1,-1}, {0,7}, {0,7}})); } /* The variable is conditionally read before first written, so @@ -914,10 +803,10 @@ TEST_F(LifetimeEvaluatorExactTest, LoopWithConditionalComponentWrite_X_Read_Y_Be */ TEST_F(LifetimeEvaluatorExactTest, FRaWSameInstructionInLoopAndCondition) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_BGNLOOP }, - { TGSI_OPCODE_IF, {0}, {in0}, {} }, + { TGSI_OPCODE_IF, {}, {in0}, {} }, { TGSI_OPCODE_ADD, {1}, {1,in0}, {}}, { TGSI_OPCODE_ENDIF}, { TGSI_OPCODE_MOV, {1}, {in1}, {}}, @@ -926,7 +815,7 @@ TEST_F(LifetimeEvaluatorExactTest, FRaWSameInstructionInLoopAndCondition) { TGSI_OPCODE_END}, }; - run (code, expectation({{-1,-1}, {0,7}})); + run (code, temp_lt_expect({{-1,-1}, {0,7}})); } /* If unconditionally first written and read in the same @@ -935,12 +824,12 @@ TEST_F(LifetimeEvaluatorExactTest, FRaWSameInstructionInLoopAndCondition) */ TEST_F(LifetimeEvaluatorExactTest, FRaWSameInstruction) { - const vector code = { + const vector code = { { TGSI_OPCODE_ADD, {1}, {1,in0}, {}}, { TGSI_OPCODE_END}, }; - run (code, expectation({{-1,-1}, {0,1}})); + run (code, temp_lt_expect({{-1,-1}, {0,1}})); } /* If unconditionally written and read in the same @@ -949,14 +838,14 @@ TEST_F(LifetimeEvaluatorExactTest, FRaWSameInstruction) */ TEST_F(LifetimeEvaluatorExactTest, FRaWSameInstructionMoreThenOnce) { - const vector code = { + const vector code = { { TGSI_OPCODE_ADD, {1}, {1,in0}, {}}, { TGSI_OPCODE_ADD, {1}, {1,in0}, {}}, { TGSI_OPCODE_MOV, {out0}, {in0}, {}}, { TGSI_OPCODE_END}, }; - run (code, expectation({{-1,-1}, {0,2}})); + run (code, temp_lt_expect({{-1,-1}, {0,2}})); } /* Register is only written. This should not happen, @@ -965,52 +854,51 @@ TEST_F(LifetimeEvaluatorExactTest, FRaWSameInstructionMoreThenOnce) */ TEST_F(LifetimeEvaluatorExactTest, WriteOnly) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,1}})); + run (code, temp_lt_expect({{-1,-1}, {0,1}})); } /* Register is read in IF. */ TEST_F(LifetimeEvaluatorExactTest, SimpleReadForIf) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_ADD, {out0}, {in0,in1}, {}}, { TGSI_OPCODE_IF, {}, {1}, {}}, { TGSI_OPCODE_ENDIF} }; - run (code, expectation({{-1,-1}, {0,2}})); + run (code, temp_lt_expect({{-1,-1}, {0,2}})); } TEST_F(LifetimeEvaluatorExactTest, WriteTwoReadOne) { - const vector code = { + const vector code = { { TGSI_OPCODE_DFRACEXP , {1,2}, {in0}, {}}, { TGSI_OPCODE_ADD , {3}, {2,in0}, {}}, { TGSI_OPCODE_MOV, {out1}, {3}, {}}, { TGSI_OPCODE_END}, }; - run (code, expectation({{-1,-1}, {0,1}, {0,1}, {1,2}})); + run (code, temp_lt_expect({{-1,-1}, {0,1}, {0,1}, {1,2}})); } TEST_F(LifetimeEvaluatorExactTest, ReadOnly) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {out0}, {1}, {}}, { TGSI_OPCODE_END}, }; - run (code, expectation({{-1,-1}, {-1,-1}})); + run (code, temp_lt_expect({{-1,-1}, {-1,-1}})); } - /* Test handling of missing END marker */ TEST_F(LifetimeEvaluatorExactTest, SomeScopesAndNoEndProgramId) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_IF, {}, {1}, {}}, { TGSI_OPCODE_MOV, {2}, {1}, {}}, @@ -1019,30 +907,30 @@ TEST_F(LifetimeEvaluatorExactTest, SomeScopesAndNoEndProgramId) { TGSI_OPCODE_MOV, {out0}, {2}, {}}, { TGSI_OPCODE_ENDIF}, }; - run (code, expectation({{-1,-1}, {0,4}, {2,5}})); + run (code, temp_lt_expect({{-1,-1}, {0,4}, {2,5}})); } TEST_F(LifetimeEvaluatorExactTest, SerialReadWrite) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_MOV, {2}, {1}, {}}, { TGSI_OPCODE_MOV, {3}, {2}, {}}, { TGSI_OPCODE_MOV, {out0}, {3}, {}}, { TGSI_OPCODE_END}, }; - run (code, expectation({{-1,-1}, {0,1}, {1,2}, {2,3}})); + run (code, temp_lt_expect({{-1,-1}, {0,1}, {1,2}, {2,3}})); } /* Check that two destination registers are used */ TEST_F(LifetimeEvaluatorExactTest, TwoDestRegisters) { - const vector code = { + const vector code = { { TGSI_OPCODE_DFRACEXP , {1,2}, {in0}, {}}, { TGSI_OPCODE_ADD, {out0}, {1,2}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,1}, {0,1}})); + run (code, temp_lt_expect({{-1,-1}, {0,1}, {0,1}})); } /* Check that writing within a loop in a conditional is propagated @@ -1050,7 +938,7 @@ TEST_F(LifetimeEvaluatorExactTest, TwoDestRegisters) */ TEST_F(LifetimeEvaluatorExactTest, WriteInLoopInConditionalReadOutside) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP}, { TGSI_OPCODE_IF, {}, {in0}, {}}, { TGSI_OPCODE_BGNLOOP}, @@ -1062,7 +950,7 @@ TEST_F(LifetimeEvaluatorExactTest, WriteInLoopInConditionalReadOutside) { TGSI_OPCODE_MOV, {out0}, {2}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,7}, {6,8}})); + run (code, temp_lt_expect({{-1,-1}, {0,7}, {6,8}})); } /* Check that a register written in a loop that is inside a conditional @@ -1071,7 +959,7 @@ TEST_F(LifetimeEvaluatorExactTest, WriteInLoopInConditionalReadOutside) */ TEST_F(LifetimeEvaluatorExactTest, WriteInLoopInCondReadInCondOutsideLoop) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP}, { TGSI_OPCODE_IF, {}, {in0}, {}}, { TGSI_OPCODE_BGNLOOP}, @@ -1083,7 +971,7 @@ TEST_F(LifetimeEvaluatorExactTest, WriteInLoopInCondReadInCondOutsideLoop) { TGSI_OPCODE_MOV, {out0}, {2}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {3,5}, {0,8}})); + run (code, temp_lt_expect({{-1,-1}, {3,5}, {0,8}})); } /* Check that a register read before written in a loop that is @@ -1091,7 +979,7 @@ TEST_F(LifetimeEvaluatorExactTest, WriteInLoopInCondReadInCondOutsideLoop) */ TEST_F(LifetimeEvaluatorExactTest, ReadWriteInLoopInCondReadInCondOutsideLoop) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP}, { TGSI_OPCODE_IF, {}, {in0}, {}}, { TGSI_OPCODE_BGNLOOP}, @@ -1103,7 +991,7 @@ TEST_F(LifetimeEvaluatorExactTest, ReadWriteInLoopInCondReadInCondOutsideLoop) { TGSI_OPCODE_MOV, {out0}, {2}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,7}, {0,8}})); + run (code, temp_lt_expect({{-1,-1}, {0,7}, {0,8}})); } /* With two destinations if one value is thrown away, we must @@ -1114,7 +1002,7 @@ TEST_F(LifetimeEvaluatorExactTest, ReadWriteInLoopInCondReadInCondOutsideLoop) */ TEST_F(LifetimeEvaluatorExactTest, WritePastLastRead2) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_MOV, {2}, {in0}, {}}, { TGSI_OPCODE_ADD, {3}, {1,2}, {}}, @@ -1122,30 +1010,30 @@ TEST_F(LifetimeEvaluatorExactTest, WritePastLastRead2) { TGSI_OPCODE_MOV, {out1}, {4}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,2}, {1,4}, {2,3}, {3,4}})); + run (code, temp_lt_expect({{-1,-1}, {0,2}, {1,4}, {2,3}, {3,4}})); } /* Check that three source registers are used */ TEST_F(LifetimeEvaluatorExactTest, ThreeSourceRegisters) { - const vector code = { + const vector code = { { TGSI_OPCODE_DFRACEXP , {1,2}, {in0}, {}}, { TGSI_OPCODE_ADD , {3}, {in0,in1}, {}}, { TGSI_OPCODE_MAD, {out0}, {1,2,3}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,2}, {0,2}, {1,2}})); + run (code, temp_lt_expect({{-1,-1}, {0,2}, {0,2}, {1,2}})); } /* Check minimal lifetime for registers only written to */ TEST_F(LifetimeEvaluatorExactTest, OverwriteWrittenOnlyTemps) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV , {1}, {in0}, {}}, { TGSI_OPCODE_MOV , {2}, {in1}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,1}, {1,2}})); + run (code, temp_lt_expect({{-1,-1}, {0,1}, {1,2}})); } /* Same register is only written twice. This should not happen, @@ -1154,12 +1042,12 @@ TEST_F(LifetimeEvaluatorExactTest, OverwriteWrittenOnlyTemps) */ TEST_F(LifetimeEvaluatorExactTest, WriteOnlyTwiceSame) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,2}})); + run (code, temp_lt_expect({{-1,-1}, {0,2}})); } /* Dead code elimination should catch and remove the case @@ -1171,14 +1059,14 @@ TEST_F(LifetimeEvaluatorExactTest, WriteOnlyTwiceSame) */ TEST_F(LifetimeEvaluatorExactTest, WritePastLastRead) { - const vector code = { + const vector code = { { TGSI_OPCODE_MOV, {1}, {in0}, {}}, { TGSI_OPCODE_MOV, {2}, {1}, {}}, { TGSI_OPCODE_MOV, {1}, {2}, {}}, { TGSI_OPCODE_END}, }; - run (code, expectation({{-1,-1}, {0,3}, {1,2}})); + run (code, temp_lt_expect({{-1,-1}, {0,3}, {1,2}})); } /* If a break is in the loop, all variables written after the @@ -1187,7 +1075,7 @@ TEST_F(LifetimeEvaluatorExactTest, WritePastLastRead) */ TEST_F(LifetimeEvaluatorExactTest, NestedLoopWithWriteAfterBreak) { - const vector code = { + const vector code = { { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_BGNLOOP }, { TGSI_OPCODE_IF, {}, {in0}, {}}, @@ -1199,7 +1087,7 @@ TEST_F(LifetimeEvaluatorExactTest, NestedLoopWithWriteAfterBreak) { TGSI_OPCODE_ENDLOOP }, { TGSI_OPCODE_END} }; - run (code, expectation({{-1,-1}, {0,8}})); + run (code, temp_lt_expect({{-1,-1}, {0,8}})); } /* Test remapping table of registers. The tests don't assume @@ -1273,7 +1161,7 @@ TEST_F(RegisterRemappingTest, RegisterRemappingMergeZeroLifetimeRegisters) TEST_F(RegisterLifetimeAndRemappingTest, LifetimeAndRemapping) { - const vector code = { + const vector code = { {TGSI_OPCODE_USEQ, {5}, {in0,in1}, {}}, {TGSI_OPCODE_UCMP, {1}, {5,in1,1}, {}}, {TGSI_OPCODE_UCMP, {1}, {5,in1,1}, {}}, @@ -1295,7 +1183,7 @@ TEST_F(RegisterLifetimeAndRemappingTest, LifetimeAndRemapping) TEST_F(RegisterLifetimeAndRemappingTest, LifetimeAndRemappingWithUnusedReadOnlyIgnored) { - const vector code = { + const vector code = { {TGSI_OPCODE_USEQ, {1}, {in0,in1}, {}}, {TGSI_OPCODE_UCMP, {2}, {1,in1,2}, {}}, {TGSI_OPCODE_UCMP, {4}, {2,in1,1}, {}}, @@ -1312,7 +1200,7 @@ TEST_F(RegisterLifetimeAndRemappingTest, LifetimeAndRemappingWithUnusedReadOnlyI TEST_F(RegisterLifetimeAndRemappingTest, LifetimeAndRemappingWithUnusedReadOnlyRemappedTo) { - const vector code = { + const vector code = { {TGSI_OPCODE_USEQ, {1}, {in0,in1}, {}}, {TGSI_OPCODE_UIF, {}, {7}, {}}, { TGSI_OPCODE_UCMP, {2}, {1,in1,2}, {}}, @@ -1329,7 +1217,7 @@ TEST_F(RegisterLifetimeAndRemappingTest, LifetimeAndRemappingWithUnusedReadOnlyR TEST_F(RegisterLifetimeAndRemappingTest, LifetimeAndRemappingWithUnusedReadOnlyRemapped) { - const vector code = { + const vector code = { {TGSI_OPCODE_USEQ, {0}, {in0,in1}, {}}, {TGSI_OPCODE_UCMP, {2}, {0,in1,2}, {}}, {TGSI_OPCODE_UCMP, {4}, {2,in1,0}, {}}, @@ -1343,266 +1231,3 @@ TEST_F(RegisterLifetimeAndRemappingTest, LifetimeAndRemappingWithUnusedReadOnlyR /* lt: 0: 0-2 1: u 2: 1-2 3: u 4: 2-5 5: 4-5 6: u 7:ro 8: 5-7 */ run (code, vector({0,1,2,3,0,2,6,7,0})); } - -/* Implementation of helper and test classes */ -MockShader::~MockShader() -{ - free(); - ralloc_free(mem_ctx); -} - -MockShader::MockShader(const vector& source): - num_temps(0) -{ - mem_ctx = ralloc_context(NULL); - - program = new(mem_ctx) exec_list(); - - for (MockCodelineWithSwizzle i: source) { - glsl_to_tgsi_instruction *next_instr = new(mem_ctx) glsl_to_tgsi_instruction(); - next_instr->op = i.op; - next_instr->info = tgsi_get_opcode_info(i.op); - - assert(i.src.size() < 4); - assert(i.dst.size() < 3); - assert(i.tex_offsets.size() < 3); - - for (unsigned k = 0; k < i.src.size(); ++k) { - next_instr->src[k] = create_src_register(i.src[k].first, i.src[k].second); - } - for (unsigned k = 0; k < i.dst.size(); ++k) { - next_instr->dst[k] = create_dst_register(i.dst[k].first, i.dst[k].second); - } - next_instr->tex_offset_num_offset = i.tex_offsets.size(); - if (next_instr->tex_offset_num_offset > 0) { - next_instr->tex_offsets = new st_src_reg[i.tex_offsets.size()]; - for (unsigned k = 0; k < i.tex_offsets.size(); ++k) { - next_instr->tex_offsets[k] = create_src_register(i.tex_offsets[k].first, - i.tex_offsets[k].second); - } - } else { - next_instr->tex_offsets = nullptr; - } - program->push_tail(next_instr); - } - ++num_temps; -} - -MockShader::MockShader(const vector& source): - num_temps(0) -{ - mem_ctx = ralloc_context(NULL); - - program = new(mem_ctx) exec_list(); - - for (MockCodeline i: source) { - glsl_to_tgsi_instruction *next_instr = new(mem_ctx) glsl_to_tgsi_instruction(); - next_instr->op = i.op; - next_instr->info = tgsi_get_opcode_info(i.op); - - assert(i.src.size() < 4); - assert(i.dst.size() < 3); - assert(i.tex_offsets.size() < 3); - - for (unsigned k = 0; k < i.src.size(); ++k) { - next_instr->src[k] = create_src_register(i.src[k]); - } - for (unsigned k = 0; k < i.dst.size(); ++k) { - next_instr->dst[k] = create_dst_register(i.dst[k]); - } - next_instr->tex_offset_num_offset = i.tex_offsets.size(); - if (next_instr->tex_offset_num_offset > 0) { - next_instr->tex_offsets = new st_src_reg[i.tex_offsets.size()]; - for (unsigned k = 0; k < i.tex_offsets.size(); ++k) { - next_instr->tex_offsets[k] = create_src_register(i.tex_offsets[k]); - } - } else { - next_instr->tex_offsets = nullptr; - } - program->push_tail(next_instr); - } - ++num_temps; -} - -int MockShader::get_num_temps() const -{ - return num_temps; -} - - -exec_list* MockShader::get_program() const -{ - return program; -} - -void MockShader::free() -{ - /* The list is not fully initialized, so - * tearing it down also must be done manually. */ - exec_node *p; - while ((p = program->pop_head())) { - glsl_to_tgsi_instruction * instr = static_cast(p); - if (instr->tex_offset_num_offset > 0) - delete[] instr->tex_offsets; - delete p; - } - program = 0; - num_temps = 0; -} - -st_src_reg MockShader::create_src_register(int src_idx) -{ - gl_register_file file; - int idx = 0; - if (src_idx >= 0) { - file = PROGRAM_TEMPORARY; - idx = src_idx; - if (num_temps < idx) - num_temps = idx; - } else { - file = PROGRAM_INPUT; - idx = 1 - src_idx; - } - return st_src_reg(file, idx, GLSL_TYPE_INT); -} - -st_src_reg MockShader::create_src_register(int src_idx, const char *sw) -{ - uint16_t swizzle = 0; - for (int i = 0; i < 4; ++i) { - switch (sw[i]) { - case 'x': break; /* is zero */ - case 'y': swizzle |= SWIZZLE_Y << 3 * i; break; - case 'z': swizzle |= SWIZZLE_Z << 3 * i; break; - case 'w': swizzle |= SWIZZLE_W << 3 * i; break; - } - } - - gl_register_file file; - int idx = 0; - if (src_idx >= 0) { - file = PROGRAM_TEMPORARY; - idx = src_idx; - if (num_temps < idx) - num_temps = idx; - } else { - file = PROGRAM_INPUT; - idx = 1 - src_idx; - } - st_src_reg result(file, idx, GLSL_TYPE_INT); - result.swizzle = swizzle; - return result; -} - -st_dst_reg MockShader::create_dst_register(int dst_idx,int writemask) -{ - gl_register_file file; - int idx = 0; - if (dst_idx >= 0) { - file = PROGRAM_TEMPORARY; - idx = dst_idx; - if (num_temps < idx) - num_temps = idx; - } else { - file = PROGRAM_OUTPUT; - idx = 1 - dst_idx; - } - return st_dst_reg(file, writemask, GLSL_TYPE_INT, idx); -} - -st_dst_reg MockShader::create_dst_register(int dst_idx) -{ - gl_register_file file; - int idx = 0; - if (dst_idx >= 0) { - file = PROGRAM_TEMPORARY; - idx = dst_idx; - if (num_temps < idx) - num_temps = idx; - } else { - file = PROGRAM_OUTPUT; - idx = 1 - dst_idx; - } - return st_dst_reg(file,0xF, GLSL_TYPE_INT, idx); -} - - -void MesaTestWithMemCtx::SetUp() -{ - mem_ctx = ralloc_context(nullptr); -} - -void MesaTestWithMemCtx::TearDown() -{ - ralloc_free(mem_ctx); - mem_ctx = nullptr; -} - -void LifetimeEvaluatorTest::run(const vector& code, const expectation& e) -{ - MockShader shader(code); - std::vector result(shader.get_num_temps()); - - bool success = - get_temp_registers_required_lifetimes(mem_ctx, shader.get_program(), - shader.get_num_temps(), &result[0]); - - ASSERT_TRUE(success); - ASSERT_EQ(result.size(), e.size()); - check(result, e); -} - -void LifetimeEvaluatorTest::run(const vector& code, - const expectation& e) -{ - MockShader shader(code); - std::vector result(shader.get_num_temps()); - - bool success = - get_temp_registers_required_lifetimes(mem_ctx, shader.get_program(), - shader.get_num_temps(), &result[0]); - ASSERT_TRUE(success); - ASSERT_EQ(result.size(), e.size()); - check(result, e); -} - -void LifetimeEvaluatorExactTest::check( const vector& lifetimes, - const expectation& e) -{ - for (unsigned i = 1; i < lifetimes.size(); ++i) { - EXPECT_EQ(lifetimes[i].begin, e[i][0]); - EXPECT_EQ(lifetimes[i].end, e[i][1]); - } -} - -void LifetimeEvaluatorAtLeastTest::check( const vector& lifetimes, - const expectation& e) -{ - for (unsigned i = 1; i < lifetimes.size(); ++i) { - EXPECT_LE(lifetimes[i].begin, e[i][0]); - EXPECT_GE(lifetimes[i].end, e[i][1]); - } -} - -void RegisterRemappingTest::run(const vector& lt, - const vector& expect) -{ - rename_reg_pair proto{false,0}; - vector result(lt.size(), proto); - - get_temp_registers_remapping(mem_ctx, lt.size(), <[0], &result[0]); - - vector remap(lt.size()); - for (unsigned i = 0; i < lt.size(); ++i) { - remap[i] = result[i].valid ? result[i].new_reg : i; - } - - std::transform(remap.begin(), remap.end(), result.begin(), remap.begin(), - [](int x, const rename_reg_pair& rn) { - return rn.valid ? rn.new_reg : x; - }); - - for(unsigned i = 1; i < remap.size(); ++i) { - EXPECT_EQ(remap[i], expect[i]); - } -} -- 2.30.2