2019-09-17 13:22:17 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2019 Valve 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 "aco_builder.h"
|
2021-06-09 15:40:03 +02:00
|
|
|
#include "aco_ir.h"
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2021-06-09 15:40:03 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <vector>
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
namespace aco {
|
|
|
|
|
|
|
|
|
|
struct ssa_state {
|
2020-01-09 16:51:34 +00:00
|
|
|
bool checked_preds_for_uniform;
|
|
|
|
|
bool all_preds_uniform;
|
|
|
|
|
|
2020-01-06 15:46:28 +00:00
|
|
|
bool needs_init;
|
|
|
|
|
uint64_t cur_undef_operands;
|
|
|
|
|
|
|
|
|
|
unsigned phi_block_idx;
|
|
|
|
|
unsigned loop_nest_depth;
|
2021-06-24 22:11:20 +02:00
|
|
|
|
2021-06-09 20:10:51 +01:00
|
|
|
std::vector<bool> any_pred_defined;
|
2020-07-10 16:31:31 +01:00
|
|
|
std::vector<bool> visited;
|
2021-06-24 22:11:20 +02:00
|
|
|
std::vector<Operand> outputs; /* the output per block */
|
2019-09-17 13:22:17 +02:00
|
|
|
};
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
Operand
|
2021-06-24 22:11:20 +02:00
|
|
|
get_ssa(Program* program, unsigned block_idx, ssa_state* state, bool input)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
2021-06-24 22:11:20 +02:00
|
|
|
if (!input) {
|
2020-07-10 16:31:31 +01:00
|
|
|
if (state->visited[block_idx])
|
2021-06-24 22:11:20 +02:00
|
|
|
return state->outputs[block_idx];
|
|
|
|
|
|
|
|
|
|
/* otherwise, output == input */
|
|
|
|
|
Operand output = get_ssa(program, block_idx, state, true);
|
|
|
|
|
state->visited[block_idx] = true;
|
|
|
|
|
state->outputs[block_idx] = output;
|
|
|
|
|
return output;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-24 22:11:20 +02:00
|
|
|
/* retrieve the Operand by checking the predecessors */
|
|
|
|
|
if (!state->any_pred_defined[block_idx])
|
|
|
|
|
return Operand(program->lane_mask);
|
2020-07-10 16:31:31 +01:00
|
|
|
|
2020-01-06 15:46:28 +00:00
|
|
|
Block& block = program->blocks[block_idx];
|
|
|
|
|
size_t pred = block.linear_preds.size();
|
2021-06-24 22:11:20 +02:00
|
|
|
Operand op;
|
|
|
|
|
if (block.loop_nest_depth < state->loop_nest_depth) {
|
|
|
|
|
op = Operand(program->lane_mask);
|
|
|
|
|
} else if (block.loop_nest_depth > state->loop_nest_depth || pred == 1 ||
|
|
|
|
|
block.kind & block_kind_loop_exit) {
|
|
|
|
|
op = get_ssa(program, block.linear_preds[0], state, false);
|
2020-01-06 15:46:28 +00:00
|
|
|
} else {
|
2021-06-24 22:11:20 +02:00
|
|
|
assert(pred > 1);
|
|
|
|
|
bool previously_visited = state->visited[block_idx];
|
|
|
|
|
/* potential recursion: anchor at loop header */
|
|
|
|
|
if (block.kind & block_kind_loop_header) {
|
|
|
|
|
assert(!previously_visited);
|
|
|
|
|
previously_visited = true;
|
|
|
|
|
state->visited[block_idx] = true;
|
|
|
|
|
state->outputs[block_idx] = Operand(Temp(program->allocateTmp(program->lane_mask)));
|
|
|
|
|
}
|
2020-07-10 16:31:31 +01:00
|
|
|
|
2021-06-24 22:11:20 +02:00
|
|
|
/* collect predecessor output operands */
|
|
|
|
|
std::vector<Operand> ops(pred);
|
|
|
|
|
for (unsigned i = 0; i < pred; i++)
|
|
|
|
|
ops[i] = get_ssa(program, block.linear_preds[i], state, false);
|
|
|
|
|
|
2021-06-24 22:59:21 +02:00
|
|
|
/* check triviality */
|
|
|
|
|
if (std::all_of(ops.begin() + 1, ops.end(), [&](Operand same) { return same == ops[0]; }))
|
|
|
|
|
return ops[0];
|
|
|
|
|
|
2021-06-24 22:11:20 +02:00
|
|
|
/* Return if this was handled in a recursive call by a loop header phi */
|
|
|
|
|
if (!previously_visited && state->visited[block_idx])
|
|
|
|
|
return state->outputs[block_idx];
|
|
|
|
|
|
|
|
|
|
if (block.kind & block_kind_loop_header)
|
|
|
|
|
op = state->outputs[block_idx];
|
|
|
|
|
else
|
|
|
|
|
op = Operand(Temp(program->allocateTmp(program->lane_mask)));
|
|
|
|
|
|
|
|
|
|
/* create phi */
|
2021-06-09 10:14:54 +02:00
|
|
|
aco_ptr<Pseudo_instruction> phi{
|
|
|
|
|
create_instruction<Pseudo_instruction>(aco_opcode::p_linear_phi, Format::PSEUDO, pred, 1)};
|
2020-01-06 15:46:28 +00:00
|
|
|
for (unsigned i = 0; i < pred; i++)
|
2021-06-24 22:11:20 +02:00
|
|
|
phi->operands[i] = ops[i];
|
|
|
|
|
phi->definitions[0] = Definition(op.getTemp());
|
2020-01-06 15:46:28 +00:00
|
|
|
block.instructions.emplace(block.instructions.begin(), std::move(phi));
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
2021-06-24 22:11:20 +02:00
|
|
|
|
|
|
|
|
assert(op.size() == program->lane_mask.size());
|
|
|
|
|
return op;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
void
|
|
|
|
|
insert_before_logical_end(Block* block, aco_ptr<Instruction> instr)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
2021-06-09 10:14:54 +02:00
|
|
|
auto IsLogicalEnd = [](const aco_ptr<Instruction>& inst) -> bool
|
|
|
|
|
{ return inst->opcode == aco_opcode::p_logical_end; };
|
2019-08-12 20:40:37 +02:00
|
|
|
auto it = std::find_if(block->instructions.crbegin(), block->instructions.crend(), IsLogicalEnd);
|
|
|
|
|
|
|
|
|
|
if (it == block->instructions.crend()) {
|
2021-01-20 15:27:16 +00:00
|
|
|
assert(block->instructions.back()->isBranch());
|
2019-08-12 20:40:37 +02:00
|
|
|
block->instructions.insert(std::prev(block->instructions.end()), std::move(instr));
|
2020-01-06 16:50:41 +00:00
|
|
|
} else {
|
2019-08-12 20:40:37 +02:00
|
|
|
block->instructions.insert(std::prev(it.base()), std::move(instr));
|
2020-01-06 16:50:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
void
|
|
|
|
|
build_merge_code(Program* program, Block* block, Definition dst, Operand prev, Operand cur)
|
2020-01-06 16:50:41 +00:00
|
|
|
{
|
|
|
|
|
Builder bld(program);
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
auto IsLogicalEnd = [](const aco_ptr<Instruction>& instr) -> bool
|
|
|
|
|
{ return instr->opcode == aco_opcode::p_logical_end; };
|
2020-01-06 16:50:41 +00:00
|
|
|
auto it = std::find_if(block->instructions.rbegin(), block->instructions.rend(), IsLogicalEnd);
|
|
|
|
|
assert(it != block->instructions.rend());
|
|
|
|
|
bld.reset(&block->instructions, std::prev(it.base()));
|
|
|
|
|
|
|
|
|
|
if (prev.isUndefined()) {
|
2020-10-15 15:09:20 +01:00
|
|
|
bld.copy(dst, cur);
|
2020-01-06 16:50:41 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-03 11:05:16 +00:00
|
|
|
bool prev_is_constant = prev.isConstant() && prev.constantValue() + 1u < 2u;
|
|
|
|
|
bool cur_is_constant = cur.isConstant() && cur.constantValue() + 1u < 2u;
|
2020-01-06 16:50:41 +00:00
|
|
|
|
|
|
|
|
if (!prev_is_constant) {
|
|
|
|
|
if (!cur_is_constant) {
|
|
|
|
|
Temp tmp1 = bld.tmp(bld.lm), tmp2 = bld.tmp(bld.lm);
|
2021-06-09 10:14:54 +02:00
|
|
|
bld.sop2(Builder::s_andn2, Definition(tmp1), bld.def(s1, scc), prev,
|
|
|
|
|
Operand(exec, bld.lm));
|
2020-01-06 16:50:41 +00:00
|
|
|
bld.sop2(Builder::s_and, Definition(tmp2), bld.def(s1, scc), cur, Operand(exec, bld.lm));
|
|
|
|
|
bld.sop2(Builder::s_or, dst, bld.def(s1, scc), tmp1, tmp2);
|
2020-12-03 11:05:16 +00:00
|
|
|
} else if (cur.constantValue()) {
|
2020-01-06 16:50:41 +00:00
|
|
|
bld.sop2(Builder::s_or, dst, bld.def(s1, scc), prev, Operand(exec, bld.lm));
|
|
|
|
|
} else {
|
|
|
|
|
bld.sop2(Builder::s_andn2, dst, bld.def(s1, scc), prev, Operand(exec, bld.lm));
|
|
|
|
|
}
|
2020-12-03 11:05:16 +00:00
|
|
|
} else if (prev.constantValue()) {
|
2020-01-06 16:50:41 +00:00
|
|
|
if (!cur_is_constant)
|
|
|
|
|
bld.sop2(Builder::s_orn2, dst, bld.def(s1, scc), cur, Operand(exec, bld.lm));
|
2020-12-03 11:05:16 +00:00
|
|
|
else if (cur.constantValue())
|
2021-07-13 11:22:46 +02:00
|
|
|
bld.copy(dst, Operand::c32_or_c64(UINT32_MAX, bld.lm == s2));
|
2020-01-06 16:50:41 +00:00
|
|
|
else
|
|
|
|
|
bld.sop1(Builder::s_not, dst, bld.def(s1, scc), Operand(exec, bld.lm));
|
|
|
|
|
} else {
|
|
|
|
|
if (!cur_is_constant)
|
|
|
|
|
bld.sop2(Builder::s_and, dst, bld.def(s1, scc), cur, Operand(exec, bld.lm));
|
2020-12-03 11:05:16 +00:00
|
|
|
else if (cur.constantValue())
|
2020-10-15 15:09:20 +01:00
|
|
|
bld.copy(dst, Operand(exec, bld.lm));
|
2020-01-06 16:50:41 +00:00
|
|
|
else
|
2021-07-13 11:22:46 +02:00
|
|
|
bld.copy(dst, Operand::zero(bld.lm.bytes()));
|
2020-01-06 16:50:41 +00:00
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
void
|
|
|
|
|
init_any_pred_defined(Program* program, ssa_state* state, Block* block, aco_ptr<Instruction>& phi)
|
2021-06-09 20:10:51 +01:00
|
|
|
{
|
|
|
|
|
std::fill(state->any_pred_defined.begin(), state->any_pred_defined.end(), false);
|
|
|
|
|
for (unsigned i = 0; i < block->logical_preds.size(); i++) {
|
|
|
|
|
if (phi->operands[i].isUndefined())
|
|
|
|
|
continue;
|
|
|
|
|
for (unsigned succ : program->blocks[block->logical_preds[i]].linear_succs)
|
|
|
|
|
state->any_pred_defined[succ] = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned start = block->logical_preds[0];
|
2021-06-24 18:11:12 +02:00
|
|
|
unsigned end = block->index;
|
2021-06-09 20:10:51 +01:00
|
|
|
|
|
|
|
|
/* for loop exit phis, start at the loop header */
|
2021-06-24 18:11:12 +02:00
|
|
|
if (block->kind & block_kind_loop_exit) {
|
|
|
|
|
while (program->blocks[start - 1].loop_nest_depth >= state->loop_nest_depth)
|
|
|
|
|
start--;
|
|
|
|
|
/* If the loop-header has a back-edge, we need to insert a phi.
|
|
|
|
|
* This will contain a defined value */
|
|
|
|
|
if (program->blocks[start].linear_preds.size() > 1)
|
|
|
|
|
state->any_pred_defined[start] = true;
|
|
|
|
|
}
|
|
|
|
|
/* for loop header phis, end at the loop exit */
|
|
|
|
|
if (block->kind & block_kind_loop_header) {
|
|
|
|
|
while (program->blocks[end].loop_nest_depth >= state->loop_nest_depth)
|
|
|
|
|
end++;
|
|
|
|
|
/* don't propagate the incoming value */
|
|
|
|
|
state->any_pred_defined[block->index] = false;
|
2021-06-09 20:10:51 +01:00
|
|
|
}
|
2021-06-24 18:11:12 +02:00
|
|
|
|
|
|
|
|
for (unsigned j = start; j < end; j++) {
|
|
|
|
|
if (!state->any_pred_defined[j])
|
|
|
|
|
continue;
|
|
|
|
|
for (unsigned succ : program->blocks[j].linear_succs)
|
|
|
|
|
state->any_pred_defined[succ] = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
state->any_pred_defined[block->index] = false;
|
2021-06-09 20:10:51 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
void
|
|
|
|
|
lower_divergent_bool_phi(Program* program, ssa_state* state, Block* block,
|
|
|
|
|
aco_ptr<Instruction>& phi)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
|
|
|
|
Builder bld(program);
|
|
|
|
|
|
2020-01-09 16:51:34 +00:00
|
|
|
if (!state->checked_preds_for_uniform) {
|
2021-02-22 15:05:32 +00:00
|
|
|
state->all_preds_uniform = !(block->kind & block_kind_merge) &&
|
|
|
|
|
block->linear_preds.size() == block->logical_preds.size();
|
2020-01-09 16:51:34 +00:00
|
|
|
for (unsigned pred : block->logical_preds)
|
2021-06-09 10:14:54 +02:00
|
|
|
state->all_preds_uniform =
|
|
|
|
|
state->all_preds_uniform && (program->blocks[pred].kind & block_kind_uniform);
|
2020-01-09 16:51:34 +00:00
|
|
|
state->checked_preds_for_uniform = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state->all_preds_uniform) {
|
|
|
|
|
phi->opcode = aco_opcode::p_linear_phi;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-24 22:11:20 +02:00
|
|
|
/* do this here to avoid resizing in case of no boolean phis */
|
2020-07-10 16:31:31 +01:00
|
|
|
state->visited.resize(program->blocks.size());
|
2021-06-24 22:11:20 +02:00
|
|
|
state->outputs.resize(program->blocks.size());
|
2021-06-09 20:10:51 +01:00
|
|
|
state->any_pred_defined.resize(program->blocks.size());
|
2020-01-06 15:46:28 +00:00
|
|
|
|
|
|
|
|
uint64_t undef_operands = 0;
|
|
|
|
|
for (unsigned i = 0; i < phi->operands.size(); i++)
|
2021-06-10 11:23:56 +01:00
|
|
|
undef_operands |= (uint64_t)phi->operands[i].isUndefined() << i;
|
2020-01-06 15:46:28 +00:00
|
|
|
|
|
|
|
|
if (state->needs_init || undef_operands != state->cur_undef_operands ||
|
|
|
|
|
block->logical_preds.size() > 64) {
|
|
|
|
|
/* this only has to be done once per block unless the set of predecessors
|
|
|
|
|
* which are undefined changes */
|
|
|
|
|
state->cur_undef_operands = undef_operands;
|
|
|
|
|
state->phi_block_idx = block->index;
|
|
|
|
|
state->loop_nest_depth = block->loop_nest_depth;
|
|
|
|
|
if (block->kind & block_kind_loop_exit) {
|
|
|
|
|
state->loop_nest_depth += 1;
|
|
|
|
|
}
|
2021-06-09 20:10:51 +01:00
|
|
|
init_any_pred_defined(program, state, block, phi);
|
2020-01-06 15:46:28 +00:00
|
|
|
state->needs_init = false;
|
|
|
|
|
}
|
2020-07-10 16:31:31 +01:00
|
|
|
std::fill(state->visited.begin(), state->visited.end(), false);
|
2020-01-06 15:46:28 +00:00
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < phi->operands.size(); i++) {
|
2021-06-24 22:11:20 +02:00
|
|
|
unsigned pred = block->logical_preds[i];
|
|
|
|
|
if (state->any_pred_defined[pred]) {
|
|
|
|
|
state->outputs[pred] = Operand(bld.tmp(bld.lm));
|
|
|
|
|
} else {
|
|
|
|
|
state->outputs[pred] = phi->operands[i];
|
|
|
|
|
}
|
|
|
|
|
assert(state->outputs[pred].size() == bld.lm.size());
|
|
|
|
|
state->visited[pred] = true;
|
2020-01-06 15:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
for (unsigned i = 0; i < phi->operands.size(); i++) {
|
2021-06-24 22:11:20 +02:00
|
|
|
unsigned pred = block->logical_preds[i];
|
|
|
|
|
if (!state->any_pred_defined[pred])
|
2019-09-17 13:22:17 +02:00
|
|
|
continue;
|
2021-06-24 22:11:20 +02:00
|
|
|
Operand input = get_ssa(program, pred, state, true);
|
2020-01-06 16:50:41 +00:00
|
|
|
if (i == 1 && (block->kind & block_kind_merge) && phi->operands[0].isConstant())
|
2021-06-24 22:11:20 +02:00
|
|
|
input = phi->operands[0];
|
|
|
|
|
assert(state->outputs[pred].isTemp() && state->outputs[pred].regClass() == bld.lm);
|
|
|
|
|
Definition dst = Definition(state->outputs[pred].getTemp());
|
|
|
|
|
build_merge_code(program, &program->blocks[pred], dst, input, phi->operands[i]);
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2019-10-07 02:32:54 +02:00
|
|
|
unsigned num_preds = block->linear_preds.size();
|
|
|
|
|
if (phi->operands.size() != num_preds) {
|
2021-06-09 10:14:54 +02:00
|
|
|
Pseudo_instruction* new_phi{create_instruction<Pseudo_instruction>(
|
|
|
|
|
aco_opcode::p_linear_phi, Format::PSEUDO, num_preds, 1)};
|
2019-10-07 02:32:54 +02:00
|
|
|
new_phi->definitions[0] = phi->definitions[0];
|
|
|
|
|
phi.reset(new_phi);
|
|
|
|
|
} else {
|
|
|
|
|
phi->opcode = aco_opcode::p_linear_phi;
|
|
|
|
|
}
|
|
|
|
|
assert(phi->operands.size() == num_preds);
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < num_preds; i++)
|
2020-01-06 15:46:28 +00:00
|
|
|
phi->operands[i] = get_ssa(program, block->linear_preds[i], state, false);
|
2019-10-07 02:32:54 +02:00
|
|
|
|
|
|
|
|
return;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
void
|
|
|
|
|
lower_subdword_phis(Program* program, Block* block, aco_ptr<Instruction>& phi)
|
2020-04-07 12:16:57 +01:00
|
|
|
{
|
|
|
|
|
Builder bld(program);
|
|
|
|
|
for (unsigned i = 0; i < phi->operands.size(); i++) {
|
|
|
|
|
if (phi->operands[i].isUndefined())
|
|
|
|
|
continue;
|
|
|
|
|
if (phi->operands[i].regClass() == phi->definitions[0].regClass())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
assert(phi->operands[i].isTemp());
|
2021-06-09 10:14:54 +02:00
|
|
|
Block* pred = &program->blocks[block->logical_preds[i]];
|
2020-04-07 12:16:57 +01:00
|
|
|
Temp phi_src = phi->operands[i].getTemp();
|
|
|
|
|
|
|
|
|
|
assert(phi_src.regClass().type() == RegType::sgpr);
|
|
|
|
|
Temp tmp = bld.tmp(RegClass(RegType::vgpr, phi_src.size()));
|
2020-10-15 15:09:20 +01:00
|
|
|
insert_before_logical_end(pred, bld.copy(Definition(tmp), phi_src).get_ptr());
|
2020-04-07 12:16:57 +01:00
|
|
|
Temp new_phi_src = bld.tmp(phi->definitions[0].regClass());
|
2021-07-13 11:22:46 +02:00
|
|
|
insert_before_logical_end(pred, bld.pseudo(aco_opcode::p_extract_vector,
|
|
|
|
|
Definition(new_phi_src), tmp, Operand::zero())
|
|
|
|
|
.get_ptr());
|
2020-04-07 12:16:57 +01:00
|
|
|
|
|
|
|
|
phi->operands[i].setTemp(new_phi_src);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
void
|
|
|
|
|
lower_phis(Program* program)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
2020-01-06 15:46:28 +00:00
|
|
|
ssa_state state;
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
for (Block& block : program->blocks) {
|
2020-01-09 16:51:34 +00:00
|
|
|
state.checked_preds_for_uniform = false;
|
2020-01-06 15:46:28 +00:00
|
|
|
state.needs_init = true;
|
2019-10-07 02:52:55 +02:00
|
|
|
for (aco_ptr<Instruction>& phi : block.instructions) {
|
|
|
|
|
if (phi->opcode == aco_opcode::p_phi) {
|
2021-06-09 10:14:54 +02:00
|
|
|
assert(program->wave_size == 64 ? phi->definitions[0].regClass() != s1
|
|
|
|
|
: phi->definitions[0].regClass() != s2);
|
2019-11-27 11:04:47 +01:00
|
|
|
if (phi->definitions[0].regClass() == program->lane_mask)
|
2020-01-06 15:46:28 +00:00
|
|
|
lower_divergent_bool_phi(program, &state, &block, phi);
|
2020-04-07 12:16:57 +01:00
|
|
|
else if (phi->definitions[0].regClass().is_subdword())
|
|
|
|
|
lower_subdword_phis(program, &block, phi);
|
2019-11-21 12:31:14 +01:00
|
|
|
} else if (!is_phi(phi)) {
|
2019-10-07 02:52:55 +02:00
|
|
|
break;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
} // namespace aco
|