Skip to content

Commit

Permalink
X86 Optimizations + Build Automation Update (#1024)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgiphil committed Feb 27, 2023
1 parent 7ec3412 commit 143e173
Show file tree
Hide file tree
Showing 41 changed files with 316 additions and 170 deletions.
48 changes: 40 additions & 8 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ jobs:
working-directory: Source
- name: Build
run: dotnet build Source/Mosa.sln /p:Version=${{ env.BUILD_VERSION }}
- name: Unit Tests - All Performance Optimizations
run: bin\Mosa.Utility.UnitTests.exe -oMax -s Emulator.Display=false
- name: Unit Tests - No Optimizations
run: bin\Mosa.Utility.UnitTests.exe -oNone -s Emulator.Display=false
- name: Unit Tests - Optimization Level 1
run: bin\Mosa.Utility.UnitTests.exe -o1 -s Emulator.Display=false
- name: Unit Tests - Optimization Level 2
run: bin\Mosa.Utility.UnitTests.exe -o2 -s Emulator.Display=false
- name: Unit Tests - Optimization Level 3
run: bin\Mosa.Utility.UnitTests.exe -o3 -s Emulator.Display=false
- name: Unit Tests - Optimization Level 4
run: bin\Mosa.Utility.UnitTests.exe -o4 -s Emulator.Display=false
- name: Unit Tests - Optimization Level 5
run: bin\Mosa.Utility.UnitTests.exe -o5 -s Emulator.Display=false
- name: Unit Tests - Optimization Level 6
run: bin\Mosa.Utility.UnitTests.exe -o6 -s Emulator.Display=false
- name: Unit Tests - Optimization Level 7
run: bin\Mosa.Utility.UnitTests.exe -o7 -s Emulator.Display=false
- name: Unit Tests - Optimization Level 8
run: bin\Mosa.Utility.UnitTests.exe -o8 -s Emulator.Display=false
# - name: Test Demo - Mosa.Demo.HelloWorld.x86
# run: bin\Mosa.Tool.Launcher.Console.exe bin\Mosa.Demo.HelloWorld.x86.dll -s Launcher.Test=true
# - name: Test Demo - Mosa.Demo.CoolWorld.x86
# run: bin\Mosa.Tool.Launcher.Console.exe bin\Mosa.Demo.CoolWorld.x86.dll -s Launcher.Test=true
- name: Create Installer
run: ISCC.exe /DMyAppVersion=${{ env.BUILD_VERSION }}.${{ github.run_number }} Source/Inno-Setup-Script/Mosa-Installer.iss
- name: Build Project - Mosa.Templates
Expand Down Expand Up @@ -64,14 +88,6 @@ jobs:
with:
name: Nuget Packages
path: bin\nupkg
- name: Unit Tests - All Performance Optimizations
run: bin\Mosa.Utility.UnitTests.exe -oMax -s Emulator.Display=false
- name: Unit Tests - No Optimizations
run: bin\Mosa.Utility.UnitTests.exe -oNone -s Emulator.Display=false
# - name: Test Demo - Mosa.Demo.HelloWorld.x86
# run: bin\Mosa.Tool.Launcher.Console.exe bin\Mosa.Demo.HelloWorld.x86.dll -s Launcher.Test=true
# - name: Test Demo - Mosa.Demo.CoolWorld.x86
# run: bin\Mosa.Tool.Launcher.Console.exe bin\Mosa.Demo.CoolWorld.x86.dll -s Launcher.Test=true
- name: Publish Package - Mosa.Templates
run: dotnet nuget push bin\nupkg\Mosa.Templates.${{ env.BUILD_VERSION }}.${{ github.run_number }}.nupkg -k ${{ secrets.NUGET_KEY }} -s https://api.nuget.org/v3/index.json
if: github.event_name == 'push' && github.repository == 'mosa/MOSA-Project' && github.ref == 'refs/heads/master'
Expand Down Expand Up @@ -124,3 +140,19 @@ jobs:
run: dotnet bin/Mosa.Utility.UnitTests.dll -oMax -s Emulator.Display=false
- name: Unit Tests - No Optimizations
run: dotnet bin/Mosa.Utility.UnitTests.dll -oNone -s Emulator.Display=false
- name: Unit Tests - Optimization Level - 1
run: dotnet bin/Mosa.Utility.UnitTests.dll -o1 -s Emulator.Display=false
- name: Unit Tests - Optimization Level 2
run: dotnet bin/Mosa.Utility.UnitTests.dll -o2 -s Emulator.Display=false
- name: Unit Tests - Optimization Level 3
run: dotnet bin/Mosa.Utility.UnitTests.dll -o3 -s Emulator.Display=false
- name: Unit Tests - Optimization Level 4
run: dotnet bin/Mosa.Utility.UnitTests.dll -o4 -s Emulator.Display=false
- name: Unit Tests - Optimization Level 5
run: dotnet bin/Mosa.Utility.UnitTests.dll -o5 -s Emulator.Display=false
- name: Unit Tests - Optimization Level 6
run: dotnet bin/Mosa.Utility.UnitTests.dll -o6 -s Emulator.Display=false
- name: Unit Tests - Optimization Level 7
run: dotnet bin/Mosa.Utility.UnitTests.dll -o7 -s Emulator.Display=false
- name: Unit Tests - Optimization Level 8
run: dotnet bin/Mosa.Utility.UnitTests.dll -o8 -s Emulator.Display=false
65 changes: 0 additions & 65 deletions .github/workflows/unittests.yml

This file was deleted.

11 changes: 11 additions & 0 deletions Source/Data/X64-Optimizations-Standard.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@
"Filter": "IsVirtualRegister(x) && !IsCarryFlagUsed(@)",
"Result": "(X64.Blsr## x)",
"Variations": "Yes"
},
{
"FamilyName": "X64",
"Type": "Simplication",
"Name": "SubFromZero",
"SubName": "",
"Expression": "X86.Sub## 0 x",
"Filter": "IsVirtualRegister(x)",
"Result": "(X86.Neg## x)",
"Variations": "No",
"Log": "No"
}
]
}
11 changes: 11 additions & 0 deletions Source/Data/X86-Optimizations-Standard.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@
"Filter": "IsVirtualRegister(x) && !IsCarryFlagUsed(@)",
"Result": "(X86.Blsr32 x)",
"Variations": "Yes"
},
{
"FamilyName": "x86",
"Type": "Simplication",
"Name": "SubFromZero",
"SubName": "",
"Expression": "X86.Sub32 0 x",
"Filter": "IsVirtualRegister(x)",
"Result": "(X86.Neg32 x)",
"Variations": "No",
"Log": "Yes"
}
]
}
2 changes: 0 additions & 2 deletions Source/Inno-Setup-Script/Mosa-Installer.iss
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ Source: "..\..\bin\Mosa.Utility.FileSystem.dll"; DestDir: "{app}\bin"; Flags: ig
Source: "..\..\bin\Mosa.Utility.Launcher.dll"; DestDir: "{app}\bin"; Flags: ignoreversion
Source: "..\..\bin\Mosa.Utility.RSP.dll"; DestDir: "{app}\bin"; Flags: ignoreversion
Source: "..\..\bin\Mosa.Utility.Disassembler.dll"; DestDir: "{app}\bin"; Flags: ignoreversion
;Source: "..\..\bin\System.Threading.Channels.dll"; DestDir: "{app}\bin"; Flags: ignoreversion
;Source: "..\..\bin\System.Threading.Tasks.Extensions.dll"; DestDir: "{app}\bin"; Flags: ignoreversion
Source: "..\..\bin\dnlib.dll"; DestDir: "{app}\bin"; Flags: ignoreversion
Source: "..\..\bin\PriorityQueue.dll"; DestDir: "{app}\bin"; Flags: ignoreversion
Source: "..\..\bin\WinFormsUI.dll"; DestDir: "{app}\bin"; Flags: ignoreversion
Expand Down
9 changes: 0 additions & 9 deletions Source/Mosa.Compiler.Framework/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,6 @@ public void SetNop()
Node.SetNop();
}

/// <summary>
/// Clones this instance.
/// </summary>
/// <returns>A new instance with the same instruction set, basic block and index.</returns>
public Context Clone()
{
return new Context(Node);
}

/// <summary>
/// Goes to the next instruction.
/// </summary>
Expand Down
76 changes: 55 additions & 21 deletions Source/Mosa.Compiler.Framework/InstructionNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -906,39 +906,73 @@ public void ReplaceInstruction(BaseInstruction instruction)
Instruction = instruction;
}

/// <summary>
/// Returns the 1st non empty node (including the current) by traversing the instructions forward
/// </summary>
/// <returns></returns>
public InstructionNode GoForwardToNonEmpty()
{
var node = this;
#endregion Methods

while (node.IsEmpty)
#region Navigation

public InstructionNode NextNonEmpty
{
get
{
node = node.Next;
}
var next = Next;

while (next.IsEmptyOrNop)
{
next = next.Next;
}

return node;
return next.IsBlockEndInstruction ? null : next;
}
}

/// <summary>
/// Returns the 1st non empty node (including the current) by traversing the instructions backwards
/// </summary>
/// <returns></returns>
public InstructionNode GoBackwardsToNonEmpty()
public InstructionNode PreviousNonEmpty
{
var node = this;
get
{
var previous = Previous;

while (previous.IsEmptyOrNop)
{
previous = previous.Previous;
}

while (node.IsEmpty)
return previous.IsBlockStartInstruction ? null : previous;
}
}

/// <summary>Returns the 1st non empty node (including the current) by traversing the instructions forward</summary>
public InstructionNode ForwardToNonEmpty
{
get
{
node = node.Previous;
var node = this;

while (node.IsEmpty)
{
node = node.Next;
}

return node;
}
}

/// <summary>Returns the 1st non empty node (including the current) by traversing the instructions backwards</summary>
public InstructionNode BackwardsToNonEmpty
{
get
{
var node = this;

return node;
while (node.IsEmpty)
{
node = node.Previous;
}

return node;
}
}

#endregion Methods
#endregion Navigation

#region Constructors

Expand Down
6 changes: 3 additions & 3 deletions Source/Mosa.Compiler.Framework/Stages/BaseTransformStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,9 @@ protected bool MergeBlocks()
UpdatePhiTargets(next.NextBlocks, next, block);
}

var insertPoint = block.BeforeLast.GoBackwardsToNonEmpty();
var insertPoint = block.BeforeLast.BackwardsToNonEmpty;

var beforeInsertPoint = insertPoint.Previous.GoBackwardsToNonEmpty();
var beforeInsertPoint = insertPoint.Previous.BackwardsToNonEmpty;

if (beforeInsertPoint.BranchTargetsCount != 0)
{
Expand All @@ -444,7 +444,7 @@ protected bool MergeBlocks()
}

insertPoint.Empty();
insertPoint.CutFrom(next.AfterFirst.GoForwardToNonEmpty(), next.Last.Previous.GoBackwardsToNonEmpty());
insertPoint.CutFrom(next.AfterFirst.ForwardToNonEmpty, next.Last.Previous.BackwardsToNonEmpty);
emptied++;
changed = true;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Mosa.Compiler.Framework/Stages/CILDecodingStageV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3091,9 +3091,8 @@ private bool Ldfld(Context context, Stack<StackEntry> stack, MosaInstruction ins

PushStack(stack, new StackEntry(stacktype, result));

switch (entry.StackType)
switch (stacktype)
{
case StackType.ManagedPointer:
case StackType.Object:
{
if (isPrimary)
Expand All @@ -3114,6 +3113,7 @@ private bool Ldfld(Context context, Stack<StackEntry> stack, MosaInstruction ins
}
}

case StackType.ManagedPointer:
case StackType.Int64:
case StackType.Int32:
case StackType.R4:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override void Run()
if (!from.NextBlocks.Contains(next))
continue;

var node = from.BeforeLast.GoBackwardsToNonEmpty();
var node = from.BeforeLast.BackwardsToNonEmpty;

//Debug.Assert(node.Instruction.FlowControl == FlowControl.UnconditionalBranch);
Debug.Assert(node.BranchTargetsCount != 0);
Expand All @@ -42,7 +42,7 @@ protected override void Run()

// reverse the condition and swap branch and jump target, and remove jump instruction
var jumpNode = node;
var branchNode = node.Previous.GoBackwardsToNonEmpty();
var branchNode = node.Previous.BackwardsToNonEmpty;

Debug.Assert(node.BranchTargetsCount == 1);

Expand Down
26 changes: 1 addition & 25 deletions Source/Mosa.Compiler.Framework/Transforms/BaseTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ public static TriState AreStatusFlagsUsed(InstructionNode node, bool checkZero,

#endregion Status Helpers

protected static void RemoveRestOfInstructions(Context context)
protected static void RemoveRemainingInstructionInBlock(Context context)
{
var node = context.Node.Next;

Expand All @@ -854,30 +854,6 @@ protected static void RemoveRestOfInstructions(Context context)
}
}

protected static InstructionNode GetPreviousNode(Context context)
{
var previous = context.Node.Previous;

while (previous.IsEmptyOrNop)
{
previous = previous.Previous;
}

return previous.IsBlockStartInstruction ? null : previous;
}

protected static InstructionNode GetNextNode(Context context)
{
var next = context.Node.Next;

while (next.IsEmptyOrNop)
{
next = next.Next;
}

return next.IsBlockEndInstruction ? null : next;
}

protected static InstructionNode GetPreviousNodeUntil(Context context, BaseInstruction untilInstruction, int window, Operand operand1 = null, Operand operand2 = null)
{
return GetPreviousNodeUntil(context, untilInstruction, window, out _, operand1, operand2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public override void Transform(Context context, TransformContext transform)

context.SetInstruction(IRInstruction.Jmp, target);

RemoveRestOfInstructions(context);
RemoveRemainingInstructionInBlock(context);

TransformContext.UpdatePhiBlock(phiBlock);
}
Expand Down

0 comments on commit 143e173

Please sign in to comment.