Skip to content

Commit

Permalink
- Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tgiphil committed Oct 20, 2023
1 parent 75464aa commit 769b1b5
Show file tree
Hide file tree
Showing 10 changed files with 625 additions and 527 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public static class LowerTo32Transforms
new Compare64x64RestInSSA(),
new Branch64(),

//new Phi64(),
new Phi64(),
};
}
4 changes: 2 additions & 2 deletions Source/Mosa.Compiler.Framework/Transforms/LowerTo32/Phi64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Mosa.Compiler.Framework.Transforms.LowerTo32;

public sealed class Phi64 : BaseLower32Transform
{
public Phi64() : base(IRInstruction.Phi64, TransformType.Manual | TransformType.Optimization)
public Phi64() : base(IRInstruction.Phi64, TransformType.Manual | TransformType.Optimization, true)
{
}

Expand Down Expand Up @@ -73,7 +73,7 @@ public override void Transform(Context context, TransformContext transform)

var value = operand.IsConstant
? Operand.CreateConstant32(operand.ConstantUnsigned64 >> 32)
: operand.Definitions[0].Operand1;
: operand.Definitions[0].Operand2;

ctx.SetOperand(i, value);
ctx.PhiBlocks.Add(context.PhiBlocks[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public static class ManualTransforms
new Special.Store64AddressOf(),
new Special.Load32AddressOf(),
new Special.Load64AddressOf(),
new Special.StoreLoadObject(),
new Special.StoreLoadManagedPointer(),
new Special.StoreLoad32(),
new Special.StoreLoad64(),
Expand Down Expand Up @@ -230,8 +231,6 @@ public static class ManualTransforms
new Memory.DoubleLoadParamR8(),
new Memory.DoubleLoadParamObject(), // Dup for MP

//new Special.Phi32Conditional(),

new Rewrite.Branch32GreaterOrEqualThanZero(),
new Rewrite.Branch32LessThanZero(),
new Rewrite.Branch32GreaterThanZero(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

namespace Mosa.Compiler.Framework.Transforms.Optimizations.Manual.Special;

public sealed class StoreLoadObject : BaseTransform
{
public StoreLoadObject() : base(IRInstruction.StoreObject, TransformType.Manual | TransformType.Optimization)
{
}

public override bool Match(Context context, TransformContext transform)
{
if (!context.Operand2.IsLocalStack)
return false;

if (!context.Operand1.IsCPURegister)
return false;

if (context.Operand1 != transform.StackFrame)
return false;

if (context.Operand2.Uses.Count != 2) // FUTURE: traverse all uses
return false;

if (!context.Operand3.IsDefinedOnce)
return false;

var load = context.Operand2.Uses[0] != context.Node
? context.Operand2.Uses[0]
: context.Operand2.Uses[1];

if (load.Instruction != IRInstruction.LoadManagedPointer)
return false;

if (!context.Operand3.IsDefinedOnce)
return false;

if (load.Operand1 != transform.StackFrame)
return false;

return true;
}

public override void Transform(Context context, TransformContext transform)
{
var load = context.Operand2.Uses[0] != context.Node
? context.Operand2.Uses[0]
: context.Operand2.Uses[1];

context.SetInstruction(IRInstruction.MoveObject, load.Result, context.Operand3);
load.SetNop();
}
}
Loading

0 comments on commit 769b1b5

Please sign in to comment.