summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend/ir
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/frontend/ir')
-rw-r--r--src/shader_recompiler/frontend/ir/basic_block.cpp4
-rw-r--r--src/shader_recompiler/frontend/ir/ir_emitter.cpp2
-rw-r--r--src/shader_recompiler/frontend/ir/microinstruction.cpp16
3 files changed, 13 insertions, 9 deletions
diff --git a/src/shader_recompiler/frontend/ir/basic_block.cpp b/src/shader_recompiler/frontend/ir/basic_block.cpp
index b5616f394..c97626712 100644
--- a/src/shader_recompiler/frontend/ir/basic_block.cpp
+++ b/src/shader_recompiler/frontend/ir/basic_block.cpp
@@ -113,7 +113,7 @@ static std::string ArgToIndex(const std::map<const Block*, size_t>& block_to_ind
113 if (arg.IsLabel()) { 113 if (arg.IsLabel()) {
114 return BlockToIndex(block_to_index, arg.Label()); 114 return BlockToIndex(block_to_index, arg.Label());
115 } 115 }
116 if (!arg.IsImmediate()) { 116 if (!arg.IsImmediate() || arg.IsIdentity()) {
117 return fmt::format("%{}", InstIndex(inst_to_index, inst_index, arg.Inst())); 117 return fmt::format("%{}", InstIndex(inst_to_index, inst_index, arg.Inst()));
118 } 118 }
119 switch (arg.Type()) { 119 switch (arg.Type()) {
@@ -166,7 +166,7 @@ std::string DumpBlock(const Block& block, const std::map<const Block*, size_t>&
166 const std::string arg_str{ArgToIndex(block_to_index, inst_to_index, inst_index, arg)}; 166 const std::string arg_str{ArgToIndex(block_to_index, inst_to_index, inst_index, arg)};
167 ret += arg_index != 0 ? ", " : " "; 167 ret += arg_index != 0 ? ", " : " ";
168 if (op == Opcode::Phi) { 168 if (op == Opcode::Phi) {
169 ret += fmt::format("[ {}, {} ]", arg_index, 169 ret += fmt::format("[ {}, {} ]", arg_str,
170 BlockToIndex(block_to_index, inst.PhiBlock(arg_index))); 170 BlockToIndex(block_to_index, inst.PhiBlock(arg_index)));
171 } else { 171 } else {
172 ret += arg_str; 172 ret += arg_str;
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.cpp b/src/shader_recompiler/frontend/ir/ir_emitter.cpp
index 30932043f..f42489d41 100644
--- a/src/shader_recompiler/frontend/ir/ir_emitter.cpp
+++ b/src/shader_recompiler/frontend/ir/ir_emitter.cpp
@@ -46,10 +46,12 @@ F64 IREmitter::Imm64(f64 value) const {
46 46
47void IREmitter::Branch(Block* label) { 47void IREmitter::Branch(Block* label) {
48 label->AddImmediatePredecessor(block); 48 label->AddImmediatePredecessor(block);
49 block->SetBranch(label);
49 Inst(Opcode::Branch, label); 50 Inst(Opcode::Branch, label);
50} 51}
51 52
52void IREmitter::BranchConditional(const U1& condition, Block* true_label, Block* false_label) { 53void IREmitter::BranchConditional(const U1& condition, Block* true_label, Block* false_label) {
54 block->SetBranches(IR::Condition{true}, true_label, false_label);
53 true_label->AddImmediatePredecessor(block); 55 true_label->AddImmediatePredecessor(block);
54 false_label->AddImmediatePredecessor(block); 56 false_label->AddImmediatePredecessor(block);
55 Inst(Opcode::BranchConditional, condition, true_label, false_label); 57 Inst(Opcode::BranchConditional, condition, true_label, false_label);
diff --git a/src/shader_recompiler/frontend/ir/microinstruction.cpp b/src/shader_recompiler/frontend/ir/microinstruction.cpp
index b4ae371bd..9279b9692 100644
--- a/src/shader_recompiler/frontend/ir/microinstruction.cpp
+++ b/src/shader_recompiler/frontend/ir/microinstruction.cpp
@@ -143,19 +143,21 @@ Value Inst::Arg(size_t index) const {
143} 143}
144 144
145void Inst::SetArg(size_t index, Value value) { 145void Inst::SetArg(size_t index, Value value) {
146 if (op == Opcode::Phi) { 146 if (index >= NumArgs()) {
147 throw LogicError("Setting argument on a phi instruction");
148 }
149 if (index >= NumArgsOf(op)) {
150 throw InvalidArgument("Out of bounds argument index {} in opcode {}", index, op); 147 throw InvalidArgument("Out of bounds argument index {} in opcode {}", index, op);
151 } 148 }
152 if (!args[index].IsImmediate()) { 149 const IR::Value arg{Arg(index)};
153 UndoUse(args[index]); 150 if (!arg.IsImmediate()) {
151 UndoUse(arg);
154 } 152 }
155 if (!value.IsImmediate()) { 153 if (!value.IsImmediate()) {
156 Use(value); 154 Use(value);
157 } 155 }
158 args[index] = value; 156 if (op == Opcode::Phi) {
157 phi_args[index].second = value;
158 } else {
159 args[index] = value;
160 }
159} 161}
160 162
161Block* Inst::PhiBlock(size_t index) const { 163Block* Inst::PhiBlock(size_t index) const {