aco: move some register demand helpers into aco_live_var_analysis.cpp
authorRhys Perry <pendingchaos02@gmail.com>
Fri, 21 Feb 2020 20:14:03 +0000 (20:14 +0000)
committerMarge Bot <eric+marge@anholt.net>
Mon, 16 Mar 2020 16:09:02 +0000 (16:09 +0000)
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3914>

src/amd/compiler/aco_ir.h
src/amd/compiler/aco_live_var_analysis.cpp
src/amd/compiler/aco_scheduler.cpp
src/amd/compiler/aco_spill.cpp

index 6e427b2b4cd4d13529b228fe8a2d3127bb5a5ceb..3a2a2186afe405e4944cb2bd82a313b57a63bd8e 100644 (file)
@@ -1265,6 +1265,11 @@ void perfwarn(bool cond, const char *msg, Instruction *instr=NULL);
 void aco_print_instr(Instruction *instr, FILE *output);
 void aco_print_program(Program *program, FILE *output);
 
+/* utilities for dealing with register demand */
+RegisterDemand get_live_changes(aco_ptr<Instruction>& instr);
+RegisterDemand get_temp_registers(aco_ptr<Instruction>& instr);
+RegisterDemand get_demand_before(RegisterDemand demand, aco_ptr<Instruction>& instr, aco_ptr<Instruction>& instr_before);
+
 /* number of sgprs that need to be allocated but might notbe addressable as s0-s105 */
 uint16_t get_extra_sgprs(Program *program);
 
index eb965e4e05c3c8b17063b568b924191e8e1b1f72..3c8e4472db12a49b0842ddbc167e363cd3a107a8 100644 (file)
 #include "vulkan/radv_shader.h"
 
 namespace aco {
-namespace {
+RegisterDemand get_live_changes(aco_ptr<Instruction>& instr)
+{
+   RegisterDemand changes;
+   for (const Definition& def : instr->definitions) {
+      if (!def.isTemp() || def.isKill())
+         continue;
+      changes += def.getTemp();
+   }
+
+   for (const Operand& op : instr->operands) {
+      if (!op.isTemp() || !op.isFirstKill())
+         continue;
+      changes -= op.getTemp();
+   }
+
+   return changes;
+}
+
+RegisterDemand get_temp_registers(aco_ptr<Instruction>& instr)
+{
+   RegisterDemand temp_registers;
+   for (Definition def : instr->definitions) {
+      if (!def.isTemp())
+         continue;
+      if (def.isKill())
+         temp_registers += def.getTemp();
+   }
+   return temp_registers;
+}
+
+RegisterDemand get_demand_before(RegisterDemand demand, aco_ptr<Instruction>& instr, aco_ptr<Instruction>& instr_before)
+{
+   demand -= get_live_changes(instr);
+   demand -= get_temp_registers(instr);
+   if (instr_before)
+      demand += get_temp_registers(instr_before);
+   return demand;
+}
 
+namespace {
 void process_live_temps_per_block(Program *program, live& lives, Block* block,
                                   std::set<unsigned>& worklist, std::vector<uint16_t>& phi_sgpr_ops)
 {
@@ -101,7 +139,6 @@ void process_live_temps_per_block(Program *program, live& lives, Block* block,
             new_demand -= temp;
             definition.setKill(false);
          } else {
-            register_demand[idx] += temp;
             definition.setKill(true);
          }
 
@@ -146,6 +183,8 @@ void process_live_temps_per_block(Program *program, live& lives, Block* block,
          }
       }
 
+      register_demand[idx] += get_temp_registers(block->instructions[idx]);
+
       block->register_demand.update(register_demand[idx]);
    }
 
index 146c1809577a93aa64e7092ffeb3cc642615252a..41ca32c862585772ded7837525b8d5af3d2c40ed 100644 (file)
@@ -113,35 +113,6 @@ void move_element(T begin_it, size_t idx, size_t before) {
     }
 }
 
-static RegisterDemand getLiveChanges(aco_ptr<Instruction>& instr)
-{
-   RegisterDemand changes;
-   for (const Definition& def : instr->definitions) {
-      if (!def.isTemp() || def.isKill())
-         continue;
-      changes += def.getTemp();
-   }
-
-   for (const Operand& op : instr->operands) {
-      if (!op.isTemp() || !op.isFirstKill())
-         continue;
-      changes -= op.getTemp();
-   }
-
-   return changes;
-}
-
-static RegisterDemand getTempRegisters(aco_ptr<Instruction>& instr)
-{
-   RegisterDemand temp_registers;
-   for (const Definition& def : instr->definitions) {
-      if (!def.isTemp() || !def.isKill())
-         continue;
-      temp_registers += def.getTemp();
-   }
-   return temp_registers;
-}
-
 void MoveState::downwards_advance_helper()
 {
    source_idx--;
@@ -207,11 +178,11 @@ MoveResult MoveState::downwards_move(bool clause)
    int dest_insert_idx = clause ? insert_idx_clause : insert_idx;
    RegisterDemand register_pressure = clause ? total_demand_clause : total_demand;
 
-   const RegisterDemand candidate_diff = getLiveChanges(instr);
-   const RegisterDemand temp = getTempRegisters(instr);
+   const RegisterDemand candidate_diff = get_live_changes(instr);
+   const RegisterDemand temp = get_temp_registers(instr);
    if (RegisterDemand(register_pressure - candidate_diff).exceeds(max_registers))
       return move_fail_pressure;
-   const RegisterDemand temp2 = getTempRegisters(block->instructions[dest_insert_idx - 1]);
+   const RegisterDemand temp2 = get_temp_registers(block->instructions[dest_insert_idx - 1]);
    const RegisterDemand new_demand = register_demand[dest_insert_idx - 1] - temp2 + temp;
    if (new_demand.exceeds(max_registers))
       return move_fail_pressure;
@@ -302,11 +273,11 @@ MoveResult MoveState::upwards_move()
    }
 
    /* check if register pressure is low enough: the diff is negative if register pressure is decreased */
-   const RegisterDemand candidate_diff = getLiveChanges(instr);
-   const RegisterDemand temp = getTempRegisters(instr);
+   const RegisterDemand candidate_diff = get_live_changes(instr);
+   const RegisterDemand temp = get_temp_registers(instr);
    if (RegisterDemand(total_demand + candidate_diff).exceeds(max_registers))
       return move_fail_pressure;
-   const RegisterDemand temp2 = getTempRegisters(block->instructions[insert_idx - 1]);
+   const RegisterDemand temp2 = get_temp_registers(block->instructions[insert_idx - 1]);
    const RegisterDemand new_demand = register_demand[insert_idx - 1] - temp2 + candidate_diff + temp;
    if (new_demand.exceeds(max_registers))
       return move_fail_pressure;
index f474685dbfe8f47ded3d3b0f0b6a90df59ecacd0..1b8824c61f88a471acaaafa2faa141a6cc5f7828 100644 (file)
@@ -660,15 +660,10 @@ RegisterDemand init_live_in_vars(spill_ctx& ctx, Block* block, unsigned block_id
 RegisterDemand get_demand_before(spill_ctx& ctx, unsigned block_idx, unsigned idx)
 {
    if (idx == 0) {
-      RegisterDemand demand_before = ctx.register_demand[block_idx][idx];
+      RegisterDemand demand = ctx.register_demand[block_idx][idx];
       aco_ptr<Instruction>& instr = ctx.program->blocks[block_idx].instructions[idx];
-      for (const Definition& def : instr->definitions)
-         demand_before -= def.getTemp();
-      for (const Operand& op : instr->operands) {
-         if (op.isFirstKill())
-            demand_before += op.getTemp();
-      }
-      return demand_before;
+      aco_ptr<Instruction> instr_before(nullptr);
+      return get_demand_before(demand, instr, instr_before);
    } else {
       return ctx.register_demand[block_idx][idx - 1];
    }