diff options
| author | FICTURE7 <FICTURE7@gmail.com> | 2021-05-17 03:54:53 +0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-17 01:54:53 +0200 |
| commit | c805542b29975b0d9bf3ea324526f62cfe4331bf (patch) | |
| tree | 7c29106997c8f08b9335f7de856518f103e7f42c /ARMeilleure/CodeGen | |
| parent | 212e472c9fac8253456d710e0b071579da330c0a (diff) | |
Allow `LocalVariable` to be assigned more than once (#2288)
* Allow `LocalVariable` to be assigned more than once
This allows us to write flow controls like loops and if-elses with
LocalVariables participating in phi nodes.
* Add `GetLocalNumber` to operand
Diffstat (limited to 'ARMeilleure/CodeGen')
| -rw-r--r-- | ARMeilleure/CodeGen/RegisterAllocators/HybridAllocator.cs | 19 | ||||
| -rw-r--r-- | ARMeilleure/CodeGen/RegisterAllocators/LinearScanAllocator.cs | 2 |
2 files changed, 11 insertions, 10 deletions
diff --git a/ARMeilleure/CodeGen/RegisterAllocators/HybridAllocator.cs b/ARMeilleure/CodeGen/RegisterAllocators/HybridAllocator.cs index aa10aea0..2f68c43f 100644 --- a/ARMeilleure/CodeGen/RegisterAllocators/HybridAllocator.cs +++ b/ARMeilleure/CodeGen/RegisterAllocators/HybridAllocator.cs @@ -83,9 +83,10 @@ namespace ARMeilleure.CodeGen.RegisterAllocators int intFreeRegisters = regMasks.IntAvailableRegisters; int vecFreeRegisters = regMasks.VecAvailableRegisters; - BlockInfo[] blockInfo = new BlockInfo[cfg.Blocks.Count]; + var blockInfo = new BlockInfo[cfg.Blocks.Count]; - List<LocalInfo> locInfo = new List<LocalInfo>(); + var locInfo = new List<LocalInfo>(); + var locVisited = new HashSet<Operand>(); for (int index = cfg.PostOrderBlocks.Length - 1; index >= 0; index--) { @@ -109,7 +110,7 @@ namespace ARMeilleure.CodeGen.RegisterAllocators if (source.Kind == OperandKind.LocalVariable) { - locInfo[source.AsInt32() - 1].SetBlockIndex(block.Index); + locInfo[source.GetLocalNumber() - 1].SetBlockIndex(block.Index); } else if (source.Kind == OperandKind.Memory) { @@ -117,12 +118,12 @@ namespace ARMeilleure.CodeGen.RegisterAllocators if (memOp.BaseAddress != null) { - locInfo[memOp.BaseAddress.AsInt32() - 1].SetBlockIndex(block.Index); + locInfo[memOp.BaseAddress.GetLocalNumber() - 1].SetBlockIndex(block.Index); } if (memOp.Index != null) { - locInfo[memOp.Index.AsInt32() - 1].SetBlockIndex(block.Index); + locInfo[memOp.Index.GetLocalNumber() - 1].SetBlockIndex(block.Index); } } } @@ -135,9 +136,9 @@ namespace ARMeilleure.CodeGen.RegisterAllocators { LocalInfo info; - if (dest.Value != 0) + if (!locVisited.Add(dest)) { - info = locInfo[dest.AsInt32() - 1]; + info = locInfo[dest.GetLocalNumber() - 1]; } else { @@ -198,7 +199,7 @@ namespace ARMeilleure.CodeGen.RegisterAllocators void AllocateRegister(Operand source, MemoryOperand memOp, int srcIndex) { - LocalInfo info = locInfo[source.AsInt32() - 1]; + LocalInfo info = locInfo[source.GetLocalNumber() - 1]; info.UseCount++; @@ -317,7 +318,7 @@ namespace ARMeilleure.CodeGen.RegisterAllocators continue; } - LocalInfo info = locInfo[dest.AsInt32() - 1]; + LocalInfo info = locInfo[dest.GetLocalNumber() - 1]; if (info.UseCount == 0 && !info.PreAllocated) { diff --git a/ARMeilleure/CodeGen/RegisterAllocators/LinearScanAllocator.cs b/ARMeilleure/CodeGen/RegisterAllocators/LinearScanAllocator.cs index cd36bdc0..88adeeb0 100644 --- a/ARMeilleure/CodeGen/RegisterAllocators/LinearScanAllocator.cs +++ b/ARMeilleure/CodeGen/RegisterAllocators/LinearScanAllocator.cs @@ -976,7 +976,7 @@ namespace ARMeilleure.CodeGen.RegisterAllocators { if (operand.Kind == OperandKind.LocalVariable) { - return operand.AsInt32(); + return operand.GetLocalNumber(); } else if (operand.Kind == OperandKind.Register) { |
