From 5e0f8e873857ce3ca3f532aff0936beb28e412c8 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Tue, 10 Jan 2023 19:16:59 -0300 Subject: Implement JIT Arm64 backend (#4114) * Implement JIT Arm64 backend * PPTC version bump * Address some feedback from Arm64 JIT PR * Address even more PR feedback * Remove unused IsPageAligned function * Sync Qc flag before calls * Fix comment and remove unused enum * Address riperiperi PR feedback * Delete Breakpoint IR instruction that was only implemented for Arm64 --- .../CodeGen/Optimizations/ConstantFolding.cs | 41 ++++++++++++++++++++++ ARMeilleure/CodeGen/Optimizations/Optimizer.cs | 28 ++++----------- 2 files changed, 48 insertions(+), 21 deletions(-) (limited to 'ARMeilleure/CodeGen/Optimizations') diff --git a/ARMeilleure/CodeGen/Optimizations/ConstantFolding.cs b/ARMeilleure/CodeGen/Optimizations/ConstantFolding.cs index 0423c255..c5a22a53 100644 --- a/ARMeilleure/CodeGen/Optimizations/ConstantFolding.cs +++ b/ARMeilleure/CodeGen/Optimizations/ConstantFolding.cs @@ -90,6 +90,47 @@ namespace ARMeilleure.CodeGen.Optimizations } break; + case Instruction.Compare: + if (type == OperandType.I32 && + operation.GetSource(0).Type == type && + operation.GetSource(1).Type == type) + { + switch ((Comparison)operation.GetSource(2).Value) + { + case Comparison.Equal: + EvaluateBinaryI32(operation, (x, y) => x == y ? 1 : 0); + break; + case Comparison.NotEqual: + EvaluateBinaryI32(operation, (x, y) => x != y ? 1 : 0); + break; + case Comparison.Greater: + EvaluateBinaryI32(operation, (x, y) => x > y ? 1 : 0); + break; + case Comparison.LessOrEqual: + EvaluateBinaryI32(operation, (x, y) => x <= y ? 1 : 0); + break; + case Comparison.GreaterUI: + EvaluateBinaryI32(operation, (x, y) => (uint)x > (uint)y ? 1 : 0); + break; + case Comparison.LessOrEqualUI: + EvaluateBinaryI32(operation, (x, y) => (uint)x <= (uint)y ? 1 : 0); + break; + case Comparison.GreaterOrEqual: + EvaluateBinaryI32(operation, (x, y) => x >= y ? 1 : 0); + break; + case Comparison.Less: + EvaluateBinaryI32(operation, (x, y) => x < y ? 1 : 0); + break; + case Comparison.GreaterOrEqualUI: + EvaluateBinaryI32(operation, (x, y) => (uint)x >= (uint)y ? 1 : 0); + break; + case Comparison.LessUI: + EvaluateBinaryI32(operation, (x, y) => (uint)x < (uint)y ? 1 : 0); + break; + } + } + break; + case Instruction.Copy: if (type == OperandType.I32) { diff --git a/ARMeilleure/CodeGen/Optimizations/Optimizer.cs b/ARMeilleure/CodeGen/Optimizations/Optimizer.cs index 919e996b..a45bb455 100644 --- a/ARMeilleure/CodeGen/Optimizations/Optimizer.cs +++ b/ARMeilleure/CodeGen/Optimizations/Optimizer.cs @@ -44,8 +44,8 @@ namespace ARMeilleure.CodeGen.Optimizations ConstantFolding.RunPass(node); Simplification.RunPass(node); - if (DestIsLocalVar(node)) - { + if (DestIsSingleLocalVar(node)) + { if (IsPropagableCompare(node)) { modified |= PropagateCompare(ref buffer, node); @@ -99,20 +99,6 @@ namespace ARMeilleure.CodeGen.Optimizations while (modified); } - private static Span GetUses(ref Span buffer, Operand operand) - { - ReadOnlySpan uses = operand.Uses; - - if (buffer.Length < uses.Length) - { - buffer = Allocators.Default.AllocateSpan((uint)uses.Length); - } - - uses.CopyTo(buffer); - - return buffer.Slice(0, uses.Length); - } - private static bool PropagateCompare(ref Span buffer, Operation compOp) { // Try to propagate Compare operations into their BranchIf uses, when these BranchIf uses are in the form @@ -160,7 +146,7 @@ namespace ARMeilleure.CodeGen.Optimizations Comparison compType = (Comparison)comp.AsInt32(); - Span uses = GetUses(ref buffer, dest); + Span uses = dest.GetUses(ref buffer); foreach (Operation use in uses) { @@ -199,7 +185,7 @@ namespace ARMeilleure.CodeGen.Optimizations Operand dest = copyOp.Destination; Operand source = copyOp.GetSource(0); - Span uses = GetUses(ref buffer, dest); + Span uses = dest.GetUses(ref buffer); foreach (Operation use in uses) { @@ -231,12 +217,12 @@ namespace ARMeilleure.CodeGen.Optimizations private static bool IsUnused(Operation node) { - return DestIsLocalVar(node) && node.Destination.UsesCount == 0 && !HasSideEffects(node); + return DestIsSingleLocalVar(node) && node.Destination.UsesCount == 0 && !HasSideEffects(node); } - private static bool DestIsLocalVar(Operation node) + private static bool DestIsSingleLocalVar(Operation node) { - return node.Destination != default && node.Destination.Kind == OperandKind.LocalVariable; + return node.DestinationsCount == 1 && node.Destination.Kind == OperandKind.LocalVariable; } private static bool HasSideEffects(Operation node) -- cgit v1.2.3