diff options
Diffstat (limited to 'src/shader_recompiler/backend/glasm/reg_alloc.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glasm/reg_alloc.cpp | 71 |
1 files changed, 41 insertions, 30 deletions
diff --git a/src/shader_recompiler/backend/glasm/reg_alloc.cpp b/src/shader_recompiler/backend/glasm/reg_alloc.cpp index 1a65a5e7d..f556f3aee 100644 --- a/src/shader_recompiler/backend/glasm/reg_alloc.cpp +++ b/src/shader_recompiler/backend/glasm/reg_alloc.cpp | |||
| @@ -21,10 +21,40 @@ Register RegAlloc::LongDefine(IR::Inst& inst) { | |||
| 21 | return Define(inst, true); | 21 | return Define(inst, true); |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | Value RegAlloc::Peek(const IR::Value& value) { | ||
| 25 | return value.IsImmediate() ? MakeImm(value) : PeekInst(*value.InstRecursive()); | ||
| 26 | } | ||
| 27 | |||
| 24 | Value RegAlloc::Consume(const IR::Value& value) { | 28 | Value RegAlloc::Consume(const IR::Value& value) { |
| 25 | if (!value.IsImmediate()) { | 29 | return value.IsImmediate() ? MakeImm(value) : ConsumeInst(*value.InstRecursive()); |
| 26 | return Consume(*value.InstRecursive()); | 30 | } |
| 31 | |||
| 32 | void RegAlloc::Unref(IR::Inst& inst) { | ||
| 33 | inst.DestructiveRemoveUsage(); | ||
| 34 | if (!inst.HasUses()) { | ||
| 35 | Free(inst.Definition<Id>()); | ||
| 27 | } | 36 | } |
| 37 | } | ||
| 38 | |||
| 39 | Register RegAlloc::AllocReg() { | ||
| 40 | Register ret; | ||
| 41 | ret.type = Type::Register; | ||
| 42 | ret.id = Alloc(false); | ||
| 43 | return ret; | ||
| 44 | } | ||
| 45 | |||
| 46 | Register RegAlloc::AllocLongReg() { | ||
| 47 | Register ret; | ||
| 48 | ret.type = Type::Register; | ||
| 49 | ret.id = Alloc(true); | ||
| 50 | return ret; | ||
| 51 | } | ||
| 52 | |||
| 53 | void RegAlloc::FreeReg(Register reg) { | ||
| 54 | Free(reg.id); | ||
| 55 | } | ||
| 56 | |||
| 57 | Value RegAlloc::MakeImm(const IR::Value& value) { | ||
| 28 | Value ret; | 58 | Value ret; |
| 29 | switch (value.Type()) { | 59 | switch (value.Type()) { |
| 30 | case IR::Type::U1: | 60 | case IR::Type::U1: |
| @@ -53,43 +83,24 @@ Value RegAlloc::Consume(const IR::Value& value) { | |||
| 53 | return ret; | 83 | return ret; |
| 54 | } | 84 | } |
| 55 | 85 | ||
| 56 | Register RegAlloc::AllocReg() { | 86 | Register RegAlloc::Define(IR::Inst& inst, bool is_long) { |
| 57 | Register ret; | 87 | inst.SetDefinition<Id>(Alloc(is_long)); |
| 58 | ret.type = Type::Register; | 88 | return Register{PeekInst(inst)}; |
| 59 | ret.id = Alloc(false); | ||
| 60 | return ret; | ||
| 61 | } | ||
| 62 | |||
| 63 | Register RegAlloc::AllocLongReg() { | ||
| 64 | Register ret; | ||
| 65 | ret.type = Type::Register; | ||
| 66 | ret.id = Alloc(true); | ||
| 67 | return ret; | ||
| 68 | } | ||
| 69 | |||
| 70 | void RegAlloc::FreeReg(Register reg) { | ||
| 71 | Free(reg.id); | ||
| 72 | } | 89 | } |
| 73 | 90 | ||
| 74 | Register RegAlloc::Define(IR::Inst& inst, bool is_long) { | 91 | Value RegAlloc::PeekInst(IR::Inst& inst) { |
| 75 | const Id id{Alloc(is_long)}; | 92 | Value ret; |
| 76 | inst.SetDefinition<Id>(id); | ||
| 77 | Register ret; | ||
| 78 | ret.type = Type::Register; | 93 | ret.type = Type::Register; |
| 79 | ret.id = id; | 94 | ret.id = inst.Definition<Id>(); |
| 80 | return ret; | 95 | return ret; |
| 81 | } | 96 | } |
| 82 | 97 | ||
| 83 | Value RegAlloc::Consume(IR::Inst& inst) { | 98 | Value RegAlloc::ConsumeInst(IR::Inst& inst) { |
| 84 | const Id id{inst.Definition<Id>()}; | ||
| 85 | inst.DestructiveRemoveUsage(); | 99 | inst.DestructiveRemoveUsage(); |
| 86 | if (!inst.HasUses()) { | 100 | if (!inst.HasUses()) { |
| 87 | Free(id); | 101 | Free(inst.Definition<Id>()); |
| 88 | } | 102 | } |
| 89 | Value ret; | 103 | return PeekInst(inst); |
| 90 | ret.type = Type::Register; | ||
| 91 | ret.id = id; | ||
| 92 | return ret; | ||
| 93 | } | 104 | } |
| 94 | 105 | ||
| 95 | Id RegAlloc::Alloc(bool is_long) { | 106 | Id RegAlloc::Alloc(bool is_long) { |