Skip to content

Commit

Permalink
Refactoring (#1060)
Browse files Browse the repository at this point in the history
* - Refactoring
  • Loading branch information
tgiphil committed May 28, 2023
1 parent ab6272e commit 5eb79c2
Show file tree
Hide file tree
Showing 80 changed files with 276 additions and 158 deletions.
2 changes: 1 addition & 1 deletion Demos/Run-Demo.SVGAWorld.x86.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
cd ../bin
./Mosa.Tool.Launcher.Console -autostart -oMax -output-asm -output-debug -output-hash -vmdk -virtio-vga -include Include Mosa.Demo.SVGAWorld.x86.dll
./Mosa.Tool.Launcher.Console -autostart -oMax -output-asm -output-debug -output-hash -virtio-vga -include Include Mosa.Demo.SVGAWorld.x86.dll
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public override IEnumerable<int> GetOutputs(InstructionNode node)

public override IEnumerable<int> GetKills(InstructionNode node)
{
if (node.Instruction.FlowControl == FlowControl.Call || node.Instruction == IRInstruction.KillAll)
if (node.Instruction.IsCall || node.Instruction == IRInstruction.KillAll)
{
for (var reg = 0; reg < IndexCount; reg++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override IEnumerable<int> GetOutputs(InstructionNode node)

public override IEnumerable<int> GetKills(InstructionNode node)
{
if (node.Instruction.FlowControl == FlowControl.Call || node.Instruction == IRInstruction.KillAll)
if (node.Instruction.IsCall || node.Instruction == IRInstruction.KillAll)
{
for (var reg = 0; reg < PhysicalRegisterCount; reg++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ private bool ProcessInstruction(InstructionNode node)
{
CompareOperation(node);
}
else if (instruction.IsPhiInstruction)
else if (instruction.IsPhi)
{
Phi(node);
}
Expand Down
50 changes: 25 additions & 25 deletions Source/Mosa.Compiler.Framework/BaseInstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ public abstract class BaseInstruction
/// <value>The operand result count.</value>
public byte DefaultResultCount { get; protected set; }

/// <summary>
/// Determines flow behavior of this instruction.
/// </summary>
/// <remarks>
/// Knowledge of control flow is required for correct basic block
/// building. Any instruction that alters the control flow must override
/// this property and correctly identify its control flow modifications.
/// </remarks>
public virtual FlowControl FlowControl => FlowControl.Next;

public virtual bool VariableOperands => false;

public virtual string Name { get; private set; }

public virtual string AlternativeName => null;
Expand All @@ -55,13 +43,35 @@ public abstract class BaseInstruction

public virtual string OpcodeName { get; private set; }

public virtual bool IgnoreDuringCodeGeneration => false;

public virtual bool IgnoreInstructionBasicBlockTargets => false;

#endregion Properties

#region Is/Has Properties

public virtual bool IgnoreDuringCodeGeneration => false;
public virtual bool IsFlowNext => true;

public virtual bool IgnoreInstructionBasicBlockTargets => false;
public virtual bool IsPlatformInstruction => false;

public virtual bool IsPhi => false;

public virtual bool IsConditionalBranch => false;

public virtual bool IsUnconditionalBranch => false;

public virtual bool IsCall => false;

public virtual bool IsReturn => false;

public virtual bool IsIRInstruction => false;

public virtual bool IsBranch => false;

public virtual bool IsMove => false;

public virtual bool IsCompare => false;

public virtual bool HasUnspecifiedSideEffect => false;

Expand All @@ -77,17 +87,7 @@ public abstract class BaseInstruction

public virtual bool IsParameterStore => false;

public virtual bool IsPlatformInstruction => false;

public virtual bool IsIRInstruction => false;

public virtual bool IsPhiInstruction => false;

public virtual bool IsIRBranchInstruction => false;

public virtual bool IsIRMoveInstruction => false;

public virtual bool IsIRCompareInstruction => false;
public virtual bool HasVariableOperands => false;

#endregion Is/Has Properties

Expand Down
12 changes: 6 additions & 6 deletions Source/Mosa.Compiler.Framework/BaseMethodCompilerStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ protected static bool IsEmptyBlockWithSingleJump(BasicBlock block)
if (node.IsEmptyOrNop)
continue;

if (node.Instruction.FlowControl != FlowControl.UnconditionalBranch)
if (!node.Instruction.IsUnconditionalBranch)
return false;
}

Expand Down Expand Up @@ -481,7 +481,7 @@ public static void UpdatePhiBlock(BasicBlock phiBlock)
if (node.IsEmptyOrNop)
continue;

if (!node.Instruction.IsPhiInstruction)
if (!node.Instruction.IsPhi)
break;

UpdatePhi(node);
Expand Down Expand Up @@ -527,7 +527,7 @@ public static void RemoveBlockFromPhi(BasicBlock removedBlock, BasicBlock phiBlo
if (node.IsEmptyOrNop)
continue;

if (!node.Instruction.IsPhiInstruction)
if (!node.Instruction.IsPhi)
break;

var sourceBlocks = node.PhiBlocks;
Expand Down Expand Up @@ -566,7 +566,7 @@ public static void UpdatePhiTarget(BasicBlock phiBlock, BasicBlock source, Basic
if (node.IsEmptyOrNop)
continue;

if (!node.Instruction.IsPhiInstruction)
if (!node.Instruction.IsPhi)
break;

var index = node.PhiBlocks.IndexOf(source);
Expand All @@ -584,7 +584,7 @@ public static bool HasPhiInstruction(BasicBlock target)
if (node.IsEmptyOrNop)
continue;

if (node.Instruction.IsPhiInstruction)
if (node.Instruction.IsPhi)
return true;

return false;
Expand Down Expand Up @@ -807,7 +807,7 @@ protected bool CheckAllPhiInstructions()
if (node.IsEmptyOrNop)
continue;

if (!node.Instruction.IsPhiInstruction)
if (!node.Instruction.IsPhi)
break;

foreach (var phiblock in node.PhiBlocks)
Expand Down
10 changes: 5 additions & 5 deletions Source/Mosa.Compiler.Framework/BaseTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -799,19 +799,19 @@ public static TriState AreStatusFlagsUsed(InstructionNode node, bool checkZero,
|| at.Instruction == IRInstruction.Gen)
continue;

if (at.Instruction.FlowControl == FlowControl.Return)
if (at.Instruction.IsReturn)
return TriState.No;

if (at.Instruction == IRInstruction.Epilogue)
return TriState.No;

if (at.Instruction.FlowControl == FlowControl.UnconditionalBranch && at.Block.NextBlocks.Count == 1)
if (at.Instruction.IsUnconditionalBranch && at.Block.NextBlocks.Count == 1)
{
at = at.BranchTargets[0].First;
continue;
}

if (at.Instruction.FlowControl != FlowControl.Next)
if (!at.Instruction.IsFlowNext)
return TriState.Unknown; // Flow direction changed

var instruction = at.Instruction;
Expand Down Expand Up @@ -880,7 +880,7 @@ protected static InstructionNode GetPreviousNodeUntil(Context context, BaseInstr
|| previous.Instruction.IsMemoryWrite
|| previous.Instruction.IsIOOperation
|| previous.Instruction.HasUnspecifiedSideEffect
|| previous.Instruction.FlowControl != FlowControl.Next)
|| !previous.Instruction.IsFlowNext)
return null;

if (operand1 != null)
Expand Down Expand Up @@ -936,7 +936,7 @@ protected static InstructionNode GetNextNodeUntil(Context context, BaseInstructi
|| next.Instruction.IsMemoryWrite
|| next.Instruction.IsIOOperation
|| next.Instruction.HasUnspecifiedSideEffect
|| next.Instruction.FlowControl != FlowControl.Next)
|| !next.Instruction.IsFlowNext)
return null;

if (operand != null)
Expand Down
4 changes: 3 additions & 1 deletion Source/Mosa.Compiler.Framework/BasicBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ public InstructionNode BeforeBranch
var node = BeforeLast;

while (node.IsEmpty
|| node.Instruction.FlowControl is FlowControl.UnconditionalBranch or FlowControl.ConditionalBranch or FlowControl.Return)
|| node.Instruction.IsUnconditionalBranch
|| node.Instruction.IsConditionalBranch
|| node.Instruction.IsReturn)
{
node = node.Previous;
}
Expand Down
6 changes: 4 additions & 2 deletions Source/Mosa.Compiler.Framework/IR/Branch32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public Branch32()
{
}

public override FlowControl FlowControl => FlowControl.ConditionalBranch;
public override bool IsFlowNext => false;

public override bool IsIRBranchInstruction => true;
public override bool IsConditionalBranch => true;

public override bool IsBranch => true;
}
6 changes: 4 additions & 2 deletions Source/Mosa.Compiler.Framework/IR/Branch64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public Branch64()
{
}

public override FlowControl FlowControl => FlowControl.ConditionalBranch;
public override bool IsFlowNext => false;

public override bool IsIRBranchInstruction => true;
public override bool IsConditionalBranch => true;

public override bool IsBranch => true;
}
6 changes: 4 additions & 2 deletions Source/Mosa.Compiler.Framework/IR/BranchManagedPointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public BranchManagedPointer()
{
}

public override FlowControl FlowControl => FlowControl.ConditionalBranch;
public override bool IsFlowNext => false;

public override bool IsIRBranchInstruction => true;
public override bool IsConditionalBranch => true;

public override bool IsBranch => true;
}
6 changes: 4 additions & 2 deletions Source/Mosa.Compiler.Framework/IR/BranchObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public BranchObject()
{
}

public override FlowControl FlowControl => FlowControl.ConditionalBranch;
public override bool IsFlowNext => false;

public override bool IsIRBranchInstruction => true;
public override bool IsConditionalBranch => true;

public override bool IsBranch => true;
}
6 changes: 4 additions & 2 deletions Source/Mosa.Compiler.Framework/IR/Call.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public Call()
{
}

public override FlowControl FlowControl => FlowControl.Call;
public override bool IsFlowNext => false;

public override bool VariableOperands => true;
public override bool IsCall => true;

public override bool HasVariableOperands => true;
}
6 changes: 4 additions & 2 deletions Source/Mosa.Compiler.Framework/IR/CallDirect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public CallDirect()
{
}

public override FlowControl FlowControl => FlowControl.Call;
public override bool IsFlowNext => false;

public override bool VariableOperands => true;
public override bool IsCall => true;

public override bool HasVariableOperands => true;
}
6 changes: 4 additions & 2 deletions Source/Mosa.Compiler.Framework/IR/CallDynamic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public CallDynamic()
{
}

public override FlowControl FlowControl => FlowControl.Call;
public override bool IsFlowNext => false;

public override bool VariableOperands => true;
public override bool IsCall => true;

public override bool HasVariableOperands => true;
}
6 changes: 4 additions & 2 deletions Source/Mosa.Compiler.Framework/IR/CallInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public CallInterface()
{
}

public override FlowControl FlowControl => FlowControl.Call;
public override bool IsFlowNext => false;

public override bool VariableOperands => true;
public override bool IsCall => true;

public override bool HasVariableOperands => true;
}
6 changes: 4 additions & 2 deletions Source/Mosa.Compiler.Framework/IR/CallStatic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public CallStatic()
{
}

public override FlowControl FlowControl => FlowControl.Call;
public override bool IsFlowNext => false;

public override bool VariableOperands => true;
public override bool IsCall => true;

public override bool HasVariableOperands => true;
}
6 changes: 4 additions & 2 deletions Source/Mosa.Compiler.Framework/IR/CallVirtual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public CallVirtual()
{
}

public override FlowControl FlowControl => FlowControl.Call;
public override bool IsFlowNext => false;

public override bool VariableOperands => true;
public override bool IsCall => true;

public override bool HasVariableOperands => true;
}
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/IR/Compare32x32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public Compare32x32()
{
}

public override bool IsIRCompareInstruction => true;
public override bool IsCompare => true;
}
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/IR/Compare32x64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public Compare32x64()
{
}

public override bool IsIRCompareInstruction => true;
public override bool IsCompare => true;
}
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/IR/Compare64x32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public Compare64x32()
{
}

public override bool IsIRCompareInstruction => true;
public override bool IsCompare => true;
}
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/IR/Compare64x64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public Compare64x64()
{
}

public override bool IsIRCompareInstruction => true;
public override bool IsCompare => true;
}
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/IR/CompareManagedPointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public CompareManagedPointer()
{
}

public override bool IsIRCompareInstruction => true;
public override bool IsCompare => true;
}
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/IR/CompareObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public CompareObject()
{
}

public override bool IsIRCompareInstruction => true;
public override bool IsCompare => true;
}
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/IR/CompareR4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public CompareR4()
{
}

public override bool IsIRCompareInstruction => true;
public override bool IsCompare => true;
}
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/IR/CompareR8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public CompareR8()
{
}

public override bool IsIRCompareInstruction => true;
public override bool IsCompare => true;
}
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/IR/Gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public Gen()

public override bool IgnoreDuringCodeGeneration => true;

public override bool VariableOperands => true;
public override bool HasVariableOperands => true;
}

0 comments on commit 5eb79c2

Please sign in to comment.