diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2020-03-09 19:29:34 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-10 09:29:34 +1100 |
| commit | 61d79facd1740264dadb6c62a0af21179bf6672b (patch) | |
| tree | 4e5769fb13b3dea1be5b5977c7fdad3a9d8db01f /ARMeilleure/CodeGen/RegisterAllocators | |
| parent | e2bb5e8091125ec626fca0f1f7213463b68b54e6 (diff) | |
Optimize x64 loads and stores using complex addressing modes (#972)
* Optimize x64 loads and stores using complex addressing modes
* This was meant to be used for testing
Diffstat (limited to 'ARMeilleure/CodeGen/RegisterAllocators')
| -rw-r--r-- | ARMeilleure/CodeGen/RegisterAllocators/HybridAllocator.cs | 83 | ||||
| -rw-r--r-- | ARMeilleure/CodeGen/RegisterAllocators/LinearScanAllocator.cs | 28 |
2 files changed, 100 insertions, 11 deletions
diff --git a/ARMeilleure/CodeGen/RegisterAllocators/HybridAllocator.cs b/ARMeilleure/CodeGen/RegisterAllocators/HybridAllocator.cs index ed0e1ae1..ce7936f9 100644 --- a/ARMeilleure/CodeGen/RegisterAllocators/HybridAllocator.cs +++ b/ARMeilleure/CodeGen/RegisterAllocators/HybridAllocator.cs @@ -110,6 +110,20 @@ namespace ARMeilleure.CodeGen.RegisterAllocators { locInfo[source.AsInt32() - 1].SetBlockIndex(block.Index); } + else if (source.Kind == OperandKind.Memory) + { + MemoryOperand memOp = (MemoryOperand)source; + + if (memOp.BaseAddress != null) + { + locInfo[memOp.BaseAddress.AsInt32() - 1].SetBlockIndex(block.Index); + } + + if (memOp.Index != null) + { + locInfo[memOp.Index.AsInt32() - 1].SetBlockIndex(block.Index); + } + } } for (int dstIndex = 0; dstIndex < node.DestinationsCount; dstIndex++) @@ -181,15 +195,8 @@ namespace ARMeilleure.CodeGen.RegisterAllocators int intLocalUse = 0; int vecLocalUse = 0; - for (int srcIndex = 0; srcIndex < node.SourcesCount; srcIndex++) + void AllocateRegister(Operand source, MemoryOperand memOp, int srcIndex) { - Operand source = node.GetSource(srcIndex); - - if (source.Kind != OperandKind.LocalVariable) - { - continue; - } - LocalInfo info = locInfo[source.AsInt32() - 1]; info.UseCount++; @@ -198,7 +205,23 @@ namespace ARMeilleure.CodeGen.RegisterAllocators if (info.Register != -1) { - node.SetSource(srcIndex, Register(info.Register, source.Type.ToRegisterType(), source.Type)); + Operand reg = Register(info.Register, source.Type.ToRegisterType(), source.Type); + + if (memOp != null) + { + if (srcIndex == 0) + { + memOp.BaseAddress = reg; + } + else /* if (srcIndex == 1) */ + { + memOp.Index = reg; + } + } + else + { + node.SetSource(srcIndex, reg); + } if (info.UseCount == info.Uses && !info.PreAllocated) { @@ -223,10 +246,24 @@ namespace ARMeilleure.CodeGen.RegisterAllocators : GetSpillTemp(source, vecSpillTempRegisters, ref vecLocalUse); info.Sequence = sequence; - info.Temp = temp; + info.Temp = temp; } - node.SetSource(srcIndex, temp); + if (memOp != null) + { + if (srcIndex == 0) + { + memOp.BaseAddress = temp; + } + else /* if (srcIndex == 1) */ + { + memOp.Index = temp; + } + } + else + { + node.SetSource(srcIndex, temp); + } Operation fillOp = new Operation(Instruction.Fill, temp, Const(info.SpillOffset)); @@ -234,6 +271,30 @@ namespace ARMeilleure.CodeGen.RegisterAllocators } } + for (int srcIndex = 0; srcIndex < node.SourcesCount; srcIndex++) + { + Operand source = node.GetSource(srcIndex); + + if (source.Kind == OperandKind.LocalVariable) + { + AllocateRegister(source, null, srcIndex); + } + else if (source.Kind == OperandKind.Memory) + { + MemoryOperand memOp = (MemoryOperand)source; + + if (memOp.BaseAddress != null) + { + AllocateRegister(memOp.BaseAddress, memOp, 0); + } + + if (memOp.Index != null) + { + AllocateRegister(memOp.Index, memOp, 1); + } + } + } + int intLocalAsg = 0; int vecLocalAsg = 0; diff --git a/ARMeilleure/CodeGen/RegisterAllocators/LinearScanAllocator.cs b/ARMeilleure/CodeGen/RegisterAllocators/LinearScanAllocator.cs index 1127ccd5..1dc6ad73 100644 --- a/ARMeilleure/CodeGen/RegisterAllocators/LinearScanAllocator.cs +++ b/ARMeilleure/CodeGen/RegisterAllocators/LinearScanAllocator.cs @@ -711,6 +711,20 @@ namespace ARMeilleure.CodeGen.RegisterAllocators { operation.SetSource(index, register); } + else if (source.Kind == OperandKind.Memory) + { + MemoryOperand memOp = (MemoryOperand)source; + + if (memOp.BaseAddress == current.Local) + { + memOp.BaseAddress = register; + } + + if (memOp.Index == current.Local) + { + memOp.Index = register; + } + } } for (int index = 0; index < operation.DestinationsCount; index++) @@ -1011,6 +1025,20 @@ namespace ARMeilleure.CodeGen.RegisterAllocators { yield return source; } + else if (source.Kind == OperandKind.Memory) + { + MemoryOperand memOp = (MemoryOperand)source; + + if (memOp.BaseAddress != null) + { + yield return memOp.BaseAddress; + } + + if (memOp.Index != null) + { + yield return memOp.Index; + } + } } } |
