shader: share direct and conditional branch classification

This commit is contained in:
nmzik
2026-09-09 18:56:56 +04:00
parent ae573f941a
commit 3902b42096
4 changed files with 26 additions and 52 deletions
@@ -25,19 +25,6 @@ bool HasLiteral(const Instruction& inst) {
inst.src3.kind == OperandKind::LiteralConstant;
}
bool IsControlFlowBranch(Opcode opcode) {
switch (opcode) {
case Opcode::S_BRANCH:
case Opcode::S_CBRANCH_SCC0:
case Opcode::S_CBRANCH_SCC1:
case Opcode::S_CBRANCH_VCCZ:
case Opcode::S_CBRANCH_VCCNZ:
case Opcode::S_CBRANCH_EXECZ:
case Opcode::S_CBRANCH_EXECNZ: return true;
default: return false;
}
}
void ApplyLiteral(Operand& operand, uint32_t literal) {
if (operand.kind == OperandKind::LiteralConstant) {
operand.value = literal;
@@ -198,6 +185,22 @@ std::string FormatExp(const Instruction& inst) {
} // namespace
bool IsConditionalBranch(Opcode opcode) {
switch (opcode) {
case Opcode::S_CBRANCH_SCC0:
case Opcode::S_CBRANCH_SCC1:
case Opcode::S_CBRANCH_VCCZ:
case Opcode::S_CBRANCH_VCCNZ:
case Opcode::S_CBRANCH_EXECZ:
case Opcode::S_CBRANCH_EXECNZ: return true;
default: return false;
}
}
bool IsDirectBranch(Opcode opcode) {
return opcode == Opcode::S_BRANCH || IsConditionalBranch(opcode);
}
const char* ImageDimensionToString(ImageDimension dimension) {
switch (dimension) {
case ImageDimension::Dim1D: return "1d";
@@ -389,7 +392,7 @@ void DecodeProgram(std::span<const uint32_t> code, Program& program) {
const auto& inst = program.instructions.back();
word_index += inst.word_count;
if (IsControlFlowBranch(inst.opcode)) {
if (IsDirectBranch(inst.opcode)) {
const auto target_index = inst.branch_target / sizeof(uint32_t);
if (branch_targets.empty()) {
branch_targets.resize(code.size());