forked from mosa/MOSA-Project
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
624 additions
and
75 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
Source/Mosa.Compiler.Common/Exceptions/InvalidOperationCompilerException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) MOSA Project. Licensed under the New BSD License. | ||
|
||
using System.Diagnostics; | ||
|
||
namespace Mosa.Compiler.Common.Exceptions; | ||
|
||
[Serializable] | ||
public class InvalidOperationCompilerException : CompilerException | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="InvalidOperationCompilerException"/> class. | ||
/// </summary> | ||
public InvalidOperationCompilerException() : base() | ||
{ | ||
var callStack = new StackFrame(1, true); | ||
var method = callStack.GetMethod(); | ||
|
||
BaseMessage = $"Invalid Operation: {method.DeclaringType.Name}.{method.Name} at line {callStack.GetFileLineNumber}"; | ||
} | ||
|
||
public InvalidOperationCompilerException(string message, bool includeMethod = true) : base(message) | ||
{ | ||
if (includeMethod) | ||
{ | ||
var callStack = new StackFrame(1, true); | ||
var method = callStack.GetMethod(); | ||
|
||
BaseMessage = $"{message}: {method.DeclaringType.Name}.{method.Name} at line {callStack.GetFileLineNumber}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...a.Compiler.Framework/Transforms/Optimizations/Manual/ConstantMove/BranchManagedPointer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) MOSA Project. Licensed under the New BSD License. | ||
|
||
namespace Mosa.Compiler.Framework.Transforms.Optimizations.Manual.ConstantMove; | ||
|
||
public sealed class BranchManagedPointer : BaseTransform | ||
{ | ||
public BranchManagedPointer() : base(IRInstruction.BranchManagedPointer, TransformType.Manual | TransformType.Optimization) | ||
{ | ||
} | ||
|
||
public override bool Match(Context context, TransformContext transform) | ||
{ | ||
if (IsConstant(context.Operand2)) | ||
return false; | ||
|
||
if (!IsConstant(context.Operand1)) | ||
return false; | ||
|
||
if (context.Block.NextBlocks.Count == 1) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
public override void Transform(Context context, TransformContext transform) | ||
{ | ||
context.SetInstruction(IRInstruction.BranchManagedPointer, context.ConditionCode.GetReverse(), context.Result, context.Operand2, context.Operand1, context.BranchTargets[0]); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/ConstantMove/BranchObject.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) MOSA Project. Licensed under the New BSD License. | ||
|
||
namespace Mosa.Compiler.Framework.Transforms.Optimizations.Manual.ConstantMove; | ||
|
||
public sealed class BranchObject : BaseTransform | ||
{ | ||
public BranchObject() : base(IRInstruction.BranchObject, TransformType.Manual | TransformType.Optimization) | ||
{ | ||
} | ||
|
||
public override bool Match(Context context, TransformContext transform) | ||
{ | ||
if (IsConstant(context.Operand2)) | ||
return false; | ||
|
||
if (!IsConstant(context.Operand1)) | ||
return false; | ||
|
||
if (context.Block.NextBlocks.Count == 1) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
public override void Transform(Context context, TransformContext transform) | ||
{ | ||
context.SetInstruction(IRInstruction.BranchObject, context.ConditionCode.GetReverse(), context.Result, context.Operand2, context.Operand1, context.BranchTargets[0]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/PHI/BasePhiTransform.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) MOSA Project. Licensed under the New BSD License. | ||
|
||
namespace Mosa.Compiler.Framework.Transforms.Optimizations.Manual.Phi | ||
{ | ||
public abstract class BasePhiTransform : BaseTransform | ||
{ | ||
public BasePhiTransform(BaseInstruction instruction, TransformType type, bool log = false) | ||
: base(instruction, type, log) | ||
{ } | ||
|
||
#region Helpers | ||
|
||
protected static void ReplaceBranchTarget(BasicBlock source, BasicBlock oldTarget, BasicBlock newTarget) | ||
{ | ||
for (var node = source.BeforeLast; !node.IsBlockStartInstruction; node = node.Previous) | ||
{ | ||
if (node.IsEmptyOrNop) | ||
continue; | ||
|
||
if (node.Instruction.IsConditionalBranch || node.Instruction.IsUnconditionalBranch) | ||
{ | ||
if (node.BranchTargets[0] == oldTarget) | ||
{ | ||
node.UpdateBranchTarget(0, newTarget); | ||
} | ||
continue; | ||
} | ||
|
||
break; | ||
} | ||
} | ||
|
||
#endregion Helpers | ||
|
||
#region Phi Helpers | ||
|
||
public static void UpdatePhiTarget(BasicBlock target, BasicBlock source, BasicBlock newSource) | ||
{ | ||
PhiHelper.UpdatePhiTarget(target, source, newSource); | ||
} | ||
|
||
public static void UpdatePhiTargets(List<BasicBlock> targets, BasicBlock source, BasicBlock newSource) | ||
{ | ||
PhiHelper.UpdatePhiTargets(targets, source, newSource); | ||
} | ||
|
||
public static void UpdatePhiBlocks(List<BasicBlock> phiBlocks) | ||
{ | ||
PhiHelper.UpdatePhiBlocks(phiBlocks); | ||
} | ||
|
||
public static void UpdatePhiBlock(BasicBlock phiBlock) | ||
{ | ||
PhiHelper.UpdatePhiBlock(phiBlock); | ||
} | ||
|
||
public static void UpdatePhi(InstructionNode node) | ||
{ | ||
PhiHelper.UpdatePhi(node); | ||
} | ||
|
||
#endregion Phi Helpers | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.