[Mesa-dev] [PATCH 02/11] mesa/st/glsl_to_tgsi: rename lifetime to register_live_range
Gert Wollny
gw.fossdev at gmail.com
Fri Feb 9 10:11:07 UTC 2018
On one hand "live range" is the term used in the literature, and on the
other hand a distinction is needed from the array live ranges that will
be introduced later.
Signed-off-by: Gert Wollny <gw.fossdev at gmail.com>
---
src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 16 ++---
.../state_tracker/st_glsl_to_tgsi_temprename.cpp | 78 +++++++++++-----------
.../state_tracker/st_glsl_to_tgsi_temprename.h | 36 +++++-----
src/mesa/state_tracker/tests/st_tests_common.cpp | 16 +++--
src/mesa/state_tracker/tests/st_tests_common.h | 13 ++--
.../tests/test_glsl_to_tgsi_lifetime.cpp | 10 +--
6 files changed, 88 insertions(+), 81 deletions(-)
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index f1482596f2..f1ecbcd433 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -5476,19 +5476,19 @@ glsl_to_tgsi_visitor::split_arrays(void)
void
glsl_to_tgsi_visitor::merge_registers(void)
{
- struct lifetime *lifetimes =
- rzalloc_array(mem_ctx, struct lifetime, this->next_temp);
+ struct register_live_range *reg_live_ranges =
+ rzalloc_array(mem_ctx, struct register_live_range, this->next_temp);
- if (get_temp_registers_required_lifetimes(mem_ctx, &this->instructions,
- this->next_temp, lifetimes)) {
+ if (get_temp_registers_required_live_ranges(reg_live_ranges, &this->instructions,
+ this->next_temp, reg_live_ranges)) {
struct rename_reg_pair *renames =
- rzalloc_array(mem_ctx, struct rename_reg_pair, this->next_temp);
- get_temp_registers_remapping(mem_ctx, this->next_temp, lifetimes, renames);
+ rzalloc_array(reg_live_ranges, struct rename_reg_pair, this->next_temp);
+ get_temp_registers_remapping(reg_live_ranges, this->next_temp,
+ reg_live_ranges, renames);
rename_temp_registers(renames);
ralloc_free(renames);
}
-
- ralloc_free(lifetimes);
+ ralloc_free(reg_live_ranges);
}
/* Reassign indices to temporary registers by reusing unused indices created
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp
index 6921a643b7..73f52cf2d8 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp
@@ -154,9 +154,9 @@ public:
void record_read(int line, prog_scope *scope);
void record_write(int line, prog_scope *scope);
- lifetime get_required_lifetime();
+ register_live_range get_required_live_range();
private:
- void propagate_lifetime_to_dominant_write_scope();
+ void propagate_live_range_to_dominant_write_scope();
bool conditional_ifelse_write_in_loop() const;
void record_ifelse_write(const prog_scope& scope);
@@ -230,7 +230,7 @@ public:
temp_access();
void record_read(int line, prog_scope *scope, int swizzle);
void record_write(int line, prog_scope *scope, int writemask);
- lifetime get_required_lifetime();
+ register_live_range get_required_live_range();
private:
void update_access_mask(int mask);
@@ -513,22 +513,22 @@ void temp_access::record_read(int line, prog_scope *scope, int swizzle)
comp[3].record_read(line, scope);
}
-inline static lifetime make_lifetime(int b, int e)
+inline static register_live_range make_live_range(int b, int e)
{
- lifetime lt;
+ register_live_range lt;
lt.begin = b;
lt.end = e;
return lt;
}
-lifetime temp_access::get_required_lifetime()
+register_live_range temp_access::get_required_live_range()
{
- lifetime result = make_lifetime(-1, -1);
+ register_live_range result = make_live_range(-1, -1);
unsigned mask = access_mask;
while (mask) {
unsigned chan = u_bit_scan(&mask);
- lifetime lt = comp[chan].get_required_lifetime();
+ register_live_range lt = comp[chan].get_required_live_range();
if (lt.begin >= 0) {
if ((result.begin < 0) || (result.begin > lt.begin))
@@ -766,7 +766,7 @@ bool temp_comp_access::conditional_ifelse_write_in_loop() const
return conditionality_in_loop_id <= conditionality_unresolved;
}
-void temp_comp_access::propagate_lifetime_to_dominant_write_scope()
+void temp_comp_access::propagate_live_range_to_dominant_write_scope()
{
first_write = first_write_scope->begin();
int lr = first_write_scope->end();
@@ -775,7 +775,7 @@ void temp_comp_access::propagate_lifetime_to_dominant_write_scope()
last_read = lr;
}
-lifetime temp_comp_access::get_required_lifetime()
+register_live_range temp_comp_access::get_required_live_range()
{
bool keep_for_full_loop = false;
@@ -785,7 +785,7 @@ lifetime temp_comp_access::get_required_lifetime()
* eliminating registers that are not written to.
*/
if (last_write < 0)
- return make_lifetime(-1, -1);
+ return make_live_range(-1, -1);
assert(first_write_scope);
@@ -793,7 +793,7 @@ lifetime temp_comp_access::get_required_lifetime()
* reused in the range it is used to write to
*/
if (!last_read_scope)
- return make_lifetime(first_write, last_write + 1);
+ return make_live_range(first_write, last_write + 1);
const prog_scope *enclosing_scope_first_read = first_read_scope;
const prog_scope *enclosing_scope_first_write = first_write_scope;
@@ -837,7 +837,7 @@ lifetime temp_comp_access::get_required_lifetime()
/* Propagate the last read scope to the target scope */
while (enclosing_scope->nesting_depth() < last_read_scope->nesting_depth()) {
/* If the read is in a loop and we have to move up the scope we need to
- * extend the life time to the end of this current loop because at this
+ * extend the live range to the end of this current loop because at this
* point we don't know whether the component was written before
* un-conditionally in the same loop.
*/
@@ -848,42 +848,42 @@ lifetime temp_comp_access::get_required_lifetime()
}
/* If the variable has to be kept for the whole loop, and we
- * are currently in a loop, then propagate the life time.
+ * are currently in a loop, then propagate the live range.
*/
if (keep_for_full_loop && first_write_scope->is_loop())
- propagate_lifetime_to_dominant_write_scope();
+ propagate_live_range_to_dominant_write_scope();
/* Propagate the first_dominant_write scope to the target scope */
while (enclosing_scope->nesting_depth() < first_write_scope->nesting_depth()) {
- /* Propagate lifetime if there was a break in a loop and the write was
+ /* Propagate live_range if there was a break in a loop and the write was
* after the break inside that loop. Note, that this is only needed if
* we move up in the scopes.
*/
if (first_write_scope->loop_break_line() < first_write) {
keep_for_full_loop = true;
- propagate_lifetime_to_dominant_write_scope();
+ propagate_live_range_to_dominant_write_scope();
}
first_write_scope = first_write_scope->parent();
- /* Propagte lifetime if we are now in a loop */
+ /* Propagte live_range if we are now in a loop */
if (keep_for_full_loop && first_write_scope->is_loop())
- propagate_lifetime_to_dominant_write_scope();
+ propagate_live_range_to_dominant_write_scope();
}
/* The last write past the last read is dead code, but we have to
* ensure that the component is not reused too early, hence extend the
- * lifetime past the last write.
+ * live_range past the last write.
*/
if (last_write >= last_read)
last_read = last_write + 1;
/* Here we are at the same scope, all is resolved */
- return make_lifetime(first_write, last_read);
+ return make_live_range(first_write, last_read);
}
/* Helper class for sorting and searching the registers based
- * on life times. */
+ * on live ranges. */
class access_record {
public:
int begin;
@@ -904,7 +904,7 @@ public:
void record_read(const st_src_reg& src, int line, prog_scope *scope);
void record_write(const st_dst_reg& src, int line, prog_scope *scope);
- void get_required_lifetimes(struct lifetime *lifetimes);
+ void get_required_live_ranges(register_live_range *live_ranges);
private:
int ntemps;
@@ -947,14 +947,14 @@ void access_recorder::record_write(const st_dst_reg& dst, int line,
record_read(*dst.reladdr2, line, scope);
}
-void access_recorder::get_required_lifetimes(struct lifetime *lifetimes)
+void access_recorder::get_required_live_ranges(struct register_live_range *live_ranges)
{
- RENAME_DEBUG(debug_log << "========= lifetimes ==============\n");
+ RENAME_DEBUG(debug_log << "=========live_ranges ==============\n");
for(int i = 0; i < ntemps; ++i) {
RENAME_DEBUG(debug_log<< setw(4) << i);
- lifetimes[i] = acc[i].get_required_lifetime();
- RENAME_DEBUG(debug_log << ": [" << lifetimes[i].begin << ", "
- << lifetimes[i].end << "]\n");
+ live_ranges[i] = acc[i].get_required_live_range();
+ RENAME_DEBUG(debug_log << ": [" <<live_ranges[i].begin << ", "
+ <<live_ranges[i].end << "]\n");
}
RENAME_DEBUG(debug_log << "==================================\n\n");
}
@@ -967,12 +967,12 @@ static void dump_instruction(ostream& os, int line, prog_scope *scope,
const glsl_to_tgsi_instruction& inst);
#endif
-/* Scan the program and estimate the required register life times.
- * The array lifetimes must be pre-allocated
+/* Scan the program and estimate the required register live ranges.
+ * live_ranges must be pre-allocated.
*/
bool
-get_temp_registers_required_lifetimes(void *mem_ctx, exec_list *instructions,
- int ntemps, struct lifetime *lifetimes)
+get_temp_registers_required_live_ranges(void *mem_ctx, exec_list *instructions,
+ int ntemps, struct register_live_range *live_ranges)
{
int line = 0;
int loop_id = 1;
@@ -1110,7 +1110,7 @@ get_temp_registers_required_lifetimes(void *mem_ctx, exec_list *instructions,
case TGSI_OPCODE_CAL:
case TGSI_OPCODE_RET:
/* These opcodes are not supported and if a subroutine would
- * be called in a shader, then the lifetime tracking would have
+ * be called in a shader, then the live_range tracking would have
* to follow that call to see which registers are used there.
* Since this is not done, we have to bail out here and signal
* that no register merge will take place.
@@ -1139,11 +1139,11 @@ get_temp_registers_required_lifetimes(void *mem_ctx, exec_list *instructions,
if (cur_scope->end() < 0)
cur_scope->set_end(line - 1);
- access.get_required_lifetimes(lifetimes);
+ access.get_required_live_ranges(live_ranges);
return true;
}
-/* Find the next register between [start, end) that has a life time starting
+/* Find the next register between [start, end) that has a live range starting
* at or after bound by using a binary search.
* start points at the beginning of the search range,
* end points at the element past the end of the search range, and
@@ -1181,16 +1181,16 @@ static int access_record_compare (const void *a, const void *b) {
/* This functions evaluates the register merges by using a binary
* search to find suitable merge candidates. */
void get_temp_registers_remapping(void *mem_ctx, int ntemps,
- const struct lifetime* lifetimes,
+ const struct register_live_range *live_ranges,
struct rename_reg_pair *result)
{
access_record *reg_access = ralloc_array(mem_ctx, access_record, ntemps);
int used_temps = 0;
for (int i = 0; i < ntemps; ++i) {
- if (lifetimes[i].begin >= 0) {
- reg_access[used_temps].begin = lifetimes[i].begin;
- reg_access[used_temps].end = lifetimes[i].end;
+ if (live_ranges[i].begin >= 0) {
+ reg_access[used_temps].begin =live_ranges[i].begin;
+ reg_access[used_temps].end =live_ranges[i].end;
reg_access[used_temps].reg = i;
reg_access[used_temps].erase = false;
++used_temps;
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.h b/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.h
index 3f21b1317a..375d5b88ec 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.h
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.h
@@ -26,46 +26,48 @@
#include "st_glsl_to_tgsi_private.h"
-/** Storage to record the required life time of a temporary register
+/** Storage to record the required live range of a temporary register
* begin == end == -1 indicates that the register can be reused without
* limitations. Otherwise, "begin" indicates the first instruction in which
* a write operation may target this temporary, and end indicates the
* last instruction in which a value can be read from this temporary.
* Hence, a register R2 can be merged with a register R1 if R1.end <= R2.begin.
*/
-struct lifetime {
+struct register_live_range {
int begin;
int end;
};
-/** Evaluates the required life times of temporary registers in a shader.
- * The life time estimation can only be run sucessfully if the shader doesn't
+/** Evaluates the required live ranges of temporary registers in a shader.
+ * The live range estimation can only be run sucessfully if the shader doesn't
* call a subroutine.
- * @param[in] mem_ctx a memory context that can be used with the ralloc_* functions
+ * @param[in] mem_ctx a memory context that can be used with the ralloc_*
+ * functions
* @param[in] instructions the shader to be anlzyed
* @param[in] ntemps number of temporaries reserved for this shader
- * @param[in,out] lifetimes memory location to store the estimated required
- * life times for each temporary register. The parameter must point to
- * allocated memory that can hold ntemps lifetime structures. On output
- * the life times contains the life times for the registers with the
- * exception of TEMP[0].
+ * @param[in,out] reg_live_ranges memory location to store the estimated
+ * required live ranges for each temporary register. The parameter must
+ * point to allocated memory that can hold ntemps register_live_range
+ * structures. On output the live ranges contains the live ranges for
+ * the registers with the exception of TEMP[0]
* @returns: true if the lifetimes were estimated, false if not (i.e. if a
* subroutine was called).
*/
bool
-get_temp_registers_required_lifetimes(void *mem_ctx, exec_list *instructions,
- int ntemps, struct lifetime *lifetimes);
+get_temp_registers_required_live_ranges(void *mem_ctx, exec_list *instructions,
+ int ntemps, struct register_live_range *live_ranges);
+
/** Estimate the merge remapping of the registers.
- * @param[in] mem_ctx a memory context that can be used with the ralloc_* functions
+ * @param[in] mem_ctx a memory context that can be used with the ralloc_*
+ * functions
* @param[in] ntemps number of temporaries reserved for this shader
- * @param[in] lifetimes required life time for each temporary register.
+ * @param[in] reg_live_ranges required live range for each temporary register.
* @param[in,out] result memory location to store the register remapping table.
* On input the parameter must point to allocated memory that can hold the
* renaming information for ntemps registers, on output the mapping is stored.
* Note that TEMP[0] is not considered for register renaming.
*/
void get_temp_registers_remapping(void *mem_ctx, int ntemps,
- const struct lifetime* lifetimes,
- struct rename_reg_pair *result);
-
+ const struct register_live_range* reg_live_ranges,
+ struct rename_reg_pair *result);
#endif
\ No newline at end of file
diff --git a/src/mesa/state_tracker/tests/st_tests_common.cpp b/src/mesa/state_tracker/tests/st_tests_common.cpp
index ea01ca5555..f1e4a83d2c 100644
--- a/src/mesa/state_tracker/tests/st_tests_common.cpp
+++ b/src/mesa/state_tracker/tests/st_tests_common.cpp
@@ -411,7 +411,7 @@ LifetimeEvaluatorTest::run(const vector<FakeCodeline>& code, bool& success)
lifetime_result result(shader.get_num_temps());
success =
- get_temp_registers_required_lifetimes(mem_ctx, shader.get_program(mem_ctx),
+ get_temp_registers_required_live_ranges(mem_ctx, shader.get_program(mem_ctx),
shader.get_num_temps(),
&result[0]);
@@ -422,8 +422,9 @@ void LifetimeEvaluatorTest::run(const vector<FakeCodeline>& code, const temp_lt_
{
FakeShader shader(code);
lifetime_result result(shader.get_num_temps());
+
bool success =
- get_temp_registers_required_lifetimes(mem_ctx, shader.get_program(mem_ctx),
+ get_temp_registers_required_live_ranges(mem_ctx, shader.get_program(mem_ctx),
shader.get_num_temps(),
&result[0]);
ASSERT_TRUE(success);
@@ -431,7 +432,7 @@ void LifetimeEvaluatorTest::run(const vector<FakeCodeline>& code, const temp_lt_
check(result, e);
}
-void LifetimeEvaluatorExactTest::check( const vector<lifetime>& lifetimes,
+void LifetimeEvaluatorExactTest::check( const vector<register_live_range>& lifetimes,
const temp_lt_expect& e)
{
for (unsigned i = 1; i < lifetimes.size(); ++i) {
@@ -440,7 +441,7 @@ void LifetimeEvaluatorExactTest::check( const vector<lifetime>& lifetimes,
}
}
-void LifetimeEvaluatorAtLeastTest::check( const vector<lifetime>& lifetimes,
+void LifetimeEvaluatorAtLeastTest::check( const vector<register_live_range>& lifetimes,
const temp_lt_expect& e)
{
for (unsigned i = 1; i < lifetimes.size(); ++i) {
@@ -449,7 +450,7 @@ void LifetimeEvaluatorAtLeastTest::check( const vector<lifetime>& lifetimes,
}
}
-void RegisterRemappingTest::run(const vector<lifetime>& lt,
+void RegisterRemappingTest::run(const vector<register_live_range>& lt,
const vector<int>& expect)
{
rename_reg_pair proto{false,0};
@@ -476,8 +477,9 @@ void RegisterLifetimeAndRemappingTest::run(const vector<FakeCodeline>& code,
const vector<int>& expect)
{
FakeShader shader(code);
- std::vector<lifetime> lt(shader.get_num_temps());
- get_temp_registers_required_lifetimes(mem_ctx, shader.get_program(mem_ctx),
+ std::vector<register_live_range> lt(shader.get_num_temps());
+
+ get_temp_registers_required_live_ranges(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
index 2e18832923..0fcec623fe 100644
--- a/src/mesa/state_tracker/tests/st_tests_common.h
+++ b/src/mesa/state_tracker/tests/st_tests_common.h
@@ -131,17 +131,19 @@ class LifetimeEvaluatorTest : public MesaTestWithMemCtx {
protected:
void run(const std::vector<FakeCodeline>& code, const temp_lt_expect& e);
private:
- using lifetime_result=std::vector<lifetime>;
+ using lifetime_result=std::vector<register_live_range>;
lifetime_result run(const std::vector<FakeCodeline>& code, bool& success);
- virtual void check(const std::vector<lifetime>& result, const temp_lt_expect& e) = 0;
+ virtual void check(const std::vector<register_live_range>& 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<lifetime>& result, const temp_lt_expect& e);
+ void check(const std::vector<register_live_range>& result,
+ const temp_lt_expect& e);
};
@@ -152,13 +154,14 @@ protected:
*/
class LifetimeEvaluatorAtLeastTest : public LifetimeEvaluatorTest {
protected:
- void check(const std::vector<lifetime>& result, const temp_lt_expect& e);
+ void check(const std::vector<register_live_range>& 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<lifetime>& lt, const std::vector<int> &expect);
+ void run(const std::vector<register_live_range>& lt,
+ const std::vector<int> &expect);
};
/* With this test class the combined lifetime estimation and renaming
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 acebfb8293..dbf74ccbd6 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
@@ -1684,7 +1684,7 @@ TEST_F(LifetimeEvaluatorExactTest, WriteIndirectReladdr2)
*/
TEST_F(RegisterRemappingTest, RegisterRemapping1)
{
- vector<lifetime> lt({{-1,-1},
+ vector<register_live_range> lt({{-1,-1},
{0,1},
{0,2},
{1,2},
@@ -1699,7 +1699,7 @@ TEST_F(RegisterRemappingTest, RegisterRemapping1)
TEST_F(RegisterRemappingTest, RegisterRemapping2)
{
- vector<lifetime> lt({{-1,-1},
+ vector<register_live_range> lt({{-1,-1},
{0,1},
{0,2},
{3,4},
@@ -1711,7 +1711,7 @@ TEST_F(RegisterRemappingTest, RegisterRemapping2)
TEST_F(RegisterRemappingTest, RegisterRemappingMergeAllToOne)
{
- vector<lifetime> lt({{-1,-1},
+ vector<register_live_range> lt({{-1,-1},
{0,1},
{1,2},
{2,3},
@@ -1723,7 +1723,7 @@ TEST_F(RegisterRemappingTest, RegisterRemappingMergeAllToOne)
TEST_F(RegisterRemappingTest, RegisterRemappingIgnoreUnused)
{
- vector<lifetime> lt({{-1,-1},
+ vector<register_live_range> lt({{-1,-1},
{0,1},
{1,2},
{2,3},
@@ -1736,7 +1736,7 @@ TEST_F(RegisterRemappingTest, RegisterRemappingIgnoreUnused)
TEST_F(RegisterRemappingTest, RegisterRemappingMergeZeroLifetimeRegisters)
{
- vector<lifetime> lt({{-1,-1},
+ vector<register_live_range> lt({{-1,-1},
{0,1},
{1,2},
{2,3},
--
2.13.6
More information about the mesa-dev
mailing list