summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/frontend')
-rw-r--r--src/shader_recompiler/frontend/ir/ir_emitter.cpp18
-rw-r--r--src/shader_recompiler/frontend/ir/ir_emitter.h4
-rw-r--r--src/shader_recompiler/frontend/ir/microinstruction.cpp3
-rw-r--r--src/shader_recompiler/frontend/ir/opcodes.inc3
-rw-r--r--src/shader_recompiler/frontend/ir/value.h4
-rw-r--r--src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp6
6 files changed, 28 insertions, 10 deletions
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.cpp b/src/shader_recompiler/frontend/ir/ir_emitter.cpp
index eb45aa477..def29143e 100644
--- a/src/shader_recompiler/frontend/ir/ir_emitter.cpp
+++ b/src/shader_recompiler/frontend/ir/ir_emitter.cpp
@@ -61,6 +61,14 @@ F64 IREmitter::Imm64(f64 value) const {
61 return F64{Value{value}}; 61 return F64{Value{value}};
62} 62}
63 63
64void IREmitter::DummyReference(const Value& value) {
65 Inst(Opcode::DummyReference, value);
66}
67
68void IREmitter::PhiMove(IR::Inst& phi, const Value& value) {
69 Inst(Opcode::PhiMove, Value{&phi}, value);
70}
71
64void IREmitter::Prologue() { 72void IREmitter::Prologue() {
65 Inst(Opcode::Prologue); 73 Inst(Opcode::Prologue);
66} 74}
@@ -69,10 +77,6 @@ void IREmitter::Epilogue() {
69 Inst(Opcode::Epilogue); 77 Inst(Opcode::Epilogue);
70} 78}
71 79
72void IREmitter::BranchConditionRef(const U1& cond) {
73 Inst(Opcode::BranchConditionRef, cond);
74}
75
76void IREmitter::DemoteToHelperInvocation() { 80void IREmitter::DemoteToHelperInvocation() {
77 Inst(Opcode::DemoteToHelperInvocation); 81 Inst(Opcode::DemoteToHelperInvocation);
78} 82}
@@ -106,6 +110,9 @@ void IREmitter::SetReg(IR::Reg reg, const U32& value) {
106} 110}
107 111
108U1 IREmitter::GetPred(IR::Pred pred, bool is_negated) { 112U1 IREmitter::GetPred(IR::Pred pred, bool is_negated) {
113 if (pred == Pred::PT) {
114 return Imm1(!is_negated);
115 }
109 const U1 value{Inst<U1>(Opcode::GetPred, pred)}; 116 const U1 value{Inst<U1>(Opcode::GetPred, pred)};
110 if (is_negated) { 117 if (is_negated) {
111 return Inst<U1>(Opcode::LogicalNot, value); 118 return Inst<U1>(Opcode::LogicalNot, value);
@@ -264,6 +271,9 @@ static U1 GetFlowTest(IREmitter& ir, FlowTest flow_test) {
264U1 IREmitter::Condition(IR::Condition cond) { 271U1 IREmitter::Condition(IR::Condition cond) {
265 const FlowTest flow_test{cond.GetFlowTest()}; 272 const FlowTest flow_test{cond.GetFlowTest()};
266 const auto [pred, is_negated]{cond.GetPred()}; 273 const auto [pred, is_negated]{cond.GetPred()};
274 if (flow_test == FlowTest::T) {
275 return GetPred(pred, is_negated);
276 }
267 return LogicalAnd(GetPred(pred, is_negated), GetFlowTest(*this, flow_test)); 277 return LogicalAnd(GetPred(pred, is_negated), GetFlowTest(*this, flow_test));
268} 278}
269 279
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.h b/src/shader_recompiler/frontend/ir/ir_emitter.h
index 7a83c33d3..4f7c820fe 100644
--- a/src/shader_recompiler/frontend/ir/ir_emitter.h
+++ b/src/shader_recompiler/frontend/ir/ir_emitter.h
@@ -32,9 +32,11 @@ public:
32 [[nodiscard]] U64 Imm64(s64 value) const; 32 [[nodiscard]] U64 Imm64(s64 value) const;
33 [[nodiscard]] F64 Imm64(f64 value) const; 33 [[nodiscard]] F64 Imm64(f64 value) const;
34 34
35 void DummyReference(const Value& value);
36 void PhiMove(IR::Inst& phi, const Value& value);
37
35 void Prologue(); 38 void Prologue();
36 void Epilogue(); 39 void Epilogue();
37 void BranchConditionRef(const U1& cond);
38 void DemoteToHelperInvocation(); 40 void DemoteToHelperInvocation();
39 void EmitVertex(const U32& stream); 41 void EmitVertex(const U32& stream);
40 void EndPrimitive(const U32& stream); 42 void EndPrimitive(const U32& stream);
diff --git a/src/shader_recompiler/frontend/ir/microinstruction.cpp b/src/shader_recompiler/frontend/ir/microinstruction.cpp
index 364574240..267aebc61 100644
--- a/src/shader_recompiler/frontend/ir/microinstruction.cpp
+++ b/src/shader_recompiler/frontend/ir/microinstruction.cpp
@@ -56,9 +56,10 @@ Inst::~Inst() {
56 56
57bool Inst::MayHaveSideEffects() const noexcept { 57bool Inst::MayHaveSideEffects() const noexcept {
58 switch (op) { 58 switch (op) {
59 case Opcode::DummyReference:
60 case Opcode::PhiMove:
59 case Opcode::Prologue: 61 case Opcode::Prologue:
60 case Opcode::Epilogue: 62 case Opcode::Epilogue:
61 case Opcode::BranchConditionRef:
62 case Opcode::Join: 63 case Opcode::Join:
63 case Opcode::DemoteToHelperInvocation: 64 case Opcode::DemoteToHelperInvocation:
64 case Opcode::Barrier: 65 case Opcode::Barrier:
diff --git a/src/shader_recompiler/frontend/ir/opcodes.inc b/src/shader_recompiler/frontend/ir/opcodes.inc
index 75ddb6b6f..6196b867d 100644
--- a/src/shader_recompiler/frontend/ir/opcodes.inc
+++ b/src/shader_recompiler/frontend/ir/opcodes.inc
@@ -6,11 +6,12 @@
6OPCODE(Phi, Opaque, ) 6OPCODE(Phi, Opaque, )
7OPCODE(Identity, Opaque, Opaque, ) 7OPCODE(Identity, Opaque, Opaque, )
8OPCODE(Void, Void, ) 8OPCODE(Void, Void, )
9OPCODE(DummyReference, Void, Opaque, )
10OPCODE(PhiMove, Void, Opaque, Opaque, )
9 11
10// Special operations 12// Special operations
11OPCODE(Prologue, Void, ) 13OPCODE(Prologue, Void, )
12OPCODE(Epilogue, Void, ) 14OPCODE(Epilogue, Void, )
13OPCODE(BranchConditionRef, Void, U1, )
14OPCODE(Join, Void, ) 15OPCODE(Join, Void, )
15OPCODE(DemoteToHelperInvocation, Void, ) 16OPCODE(DemoteToHelperInvocation, Void, )
16OPCODE(EmitVertex, Void, U32, ) 17OPCODE(EmitVertex, Void, U32, )
diff --git a/src/shader_recompiler/frontend/ir/value.h b/src/shader_recompiler/frontend/ir/value.h
index 2ce49f953..0c6bf684d 100644
--- a/src/shader_recompiler/frontend/ir/value.h
+++ b/src/shader_recompiler/frontend/ir/value.h
@@ -391,4 +391,8 @@ inline f64 Value::F64() const {
391 return imm_f64; 391 return imm_f64;
392} 392}
393 393
394[[nodiscard]] inline bool IsPhi(const Inst& inst) {
395 return inst.GetOpcode() == Opcode::Phi;
396}
397
394} // namespace Shader::IR 398} // namespace Shader::IR
diff --git a/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp b/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp
index e7e2e9c82..836d4b8aa 100644
--- a/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp
+++ b/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp
@@ -704,7 +704,7 @@ private:
704 // Implement if header block 704 // Implement if header block
705 IR::IREmitter ir{*current_block}; 705 IR::IREmitter ir{*current_block};
706 const IR::U1 cond{VisitExpr(ir, *stmt.cond)}; 706 const IR::U1 cond{VisitExpr(ir, *stmt.cond)};
707 ir.BranchConditionRef(cond); 707 ir.DummyReference(cond);
708 708
709 const size_t if_node_index{syntax_list.size()}; 709 const size_t if_node_index{syntax_list.size()};
710 syntax_list.emplace_back(); 710 syntax_list.emplace_back();
@@ -755,7 +755,7 @@ private:
755 // The continue block is located at the end of the loop 755 // The continue block is located at the end of the loop
756 IR::IREmitter ir{*continue_block}; 756 IR::IREmitter ir{*continue_block};
757 const IR::U1 cond{VisitExpr(ir, *stmt.cond)}; 757 const IR::U1 cond{VisitExpr(ir, *stmt.cond)};
758 ir.BranchConditionRef(cond); 758 ir.DummyReference(cond);
759 759
760 IR::Block* const body_block{syntax_list.at(body_block_index).block}; 760 IR::Block* const body_block{syntax_list.at(body_block_index).block};
761 loop_header_block->AddBranch(body_block); 761 loop_header_block->AddBranch(body_block);
@@ -792,7 +792,7 @@ private:
792 792
793 IR::IREmitter ir{*current_block}; 793 IR::IREmitter ir{*current_block};
794 const IR::U1 cond{VisitExpr(ir, *stmt.cond)}; 794 const IR::U1 cond{VisitExpr(ir, *stmt.cond)};
795 ir.BranchConditionRef(cond); 795 ir.DummyReference(cond);
796 current_block->AddBranch(break_block); 796 current_block->AddBranch(break_block);
797 current_block->AddBranch(skip_block); 797 current_block->AddBranch(skip_block);
798 current_block = skip_block; 798 current_block = skip_block;