Skip to content

Commit

Permalink
Improvements (#1062)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgiphil committed Jun 4, 2023
1 parent afd61df commit 5a5dce2
Show file tree
Hide file tree
Showing 643 changed files with 3,278 additions and 3,219 deletions.
40 changes: 20 additions & 20 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@ jobs:
- 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
run: bin\Mosa.Utility.UnitTests.exe -oMax -display-off
- name: Unit Tests - No Optimizations
run: bin\Mosa.Utility.UnitTests.exe -oNone -s Emulator.Display=false
run: bin\Mosa.Utility.UnitTests.exe -oNone -display-off
- name: Unit Tests - Optimization Level 1
run: bin\Mosa.Utility.UnitTests.exe -o1 -s Emulator.Display=false
run: bin\Mosa.Utility.UnitTests.exe -o1 -display-off
- name: Unit Tests - Optimization Level 2
run: bin\Mosa.Utility.UnitTests.exe -o2 -s Emulator.Display=false
run: bin\Mosa.Utility.UnitTests.exe -o2 -display-off
- name: Unit Tests - Optimization Level 3
run: bin\Mosa.Utility.UnitTests.exe -o3 -s Emulator.Display=false
run: bin\Mosa.Utility.UnitTests.exe -o3 -display-off
- name: Unit Tests - Optimization Level 4
run: bin\Mosa.Utility.UnitTests.exe -o4 -s Emulator.Display=false
run: bin\Mosa.Utility.UnitTests.exe -o4 -display-off
- name: Unit Tests - Optimization Level 5
run: bin\Mosa.Utility.UnitTests.exe -o5 -s Emulator.Display=false
run: bin\Mosa.Utility.UnitTests.exe -o5 -display-off
- name: Unit Tests - Optimization Level 6
run: bin\Mosa.Utility.UnitTests.exe -o6 -s Emulator.Display=false
run: bin\Mosa.Utility.UnitTests.exe -o6 -display-off
- name: Unit Tests - Optimization Level 7
run: bin\Mosa.Utility.UnitTests.exe -o7 -s Emulator.Display=false
run: bin\Mosa.Utility.UnitTests.exe -o7 -display-off
- name: Unit Tests - Optimization Level 8
run: bin\Mosa.Utility.UnitTests.exe -o8 -s Emulator.Display=false
run: bin\Mosa.Utility.UnitTests.exe -o8 -display-off
# - 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
Expand Down Expand Up @@ -130,25 +130,25 @@ jobs:
- name: Install Qemu and Dependencies
run: sudo apt-get install -y qemu qemu-system qemu-system-x86 libsdl2-image-2.0-0 libvirglrenderer1 libpixman-1-0 libepoxy0 libdw1 libpng16-16 zlib1g libjpeg8 libudev1 libusb-1.0-0 liblzo2-2 libgio-cil libglib2.0-0 libzstd1 libncursesw6 libgbm1 libgtk-3-0 libgdk3.0-cil libcairo2 libgdk-pixbuf-2.0-0 libx11-6 libasound2 libpulse0 libsndio7.0 libbz2-1.0 libc6 libgcc-s1
- name: Unit Tests - All Performance Optimizations
run: dotnet bin/Mosa.Utility.UnitTests.dll -oMax -s Emulator.Display=false
run: dotnet bin/Mosa.Utility.UnitTests.dll -oMax -display-off
- name: Unit Tests - No Optimizations
run: dotnet bin/Mosa.Utility.UnitTests.dll -oNone -s Emulator.Display=false
run: dotnet bin/Mosa.Utility.UnitTests.dll -oNone -display-off
- name: Unit Tests - Optimization Level 1
run: dotnet bin/Mosa.Utility.UnitTests.dll -o1 -s Emulator.Display=false
run: dotnet bin/Mosa.Utility.UnitTests.dll -o1 -display-off
- name: Unit Tests - Optimization Level 2
run: dotnet bin/Mosa.Utility.UnitTests.dll -o2 -s Emulator.Display=false
run: dotnet bin/Mosa.Utility.UnitTests.dll -o2 -display-off
- name: Unit Tests - Optimization Level 3
run: dotnet bin/Mosa.Utility.UnitTests.dll -o3 -s Emulator.Display=false
run: dotnet bin/Mosa.Utility.UnitTests.dll -o3 -display-off
- name: Unit Tests - Optimization Level 4
run: dotnet bin/Mosa.Utility.UnitTests.dll -o4 -s Emulator.Display=false
run: dotnet bin/Mosa.Utility.UnitTests.dll -o4 -display-off
- name: Unit Tests - Optimization Level 5
run: dotnet bin/Mosa.Utility.UnitTests.dll -o5 -s Emulator.Display=false
run: dotnet bin/Mosa.Utility.UnitTests.dll -o5 -display-off
- name: Unit Tests - Optimization Level 6
run: dotnet bin/Mosa.Utility.UnitTests.dll -o6 -s Emulator.Display=false
run: dotnet bin/Mosa.Utility.UnitTests.dll -o6 -display-off
- name: Unit Tests - Optimization Level 7
run: dotnet bin/Mosa.Utility.UnitTests.dll -o7 -s Emulator.Display=false
run: dotnet bin/Mosa.Utility.UnitTests.dll -o7 -display-off
- name: Unit Tests - Optimization Level 8
run: dotnet bin/Mosa.Utility.UnitTests.dll -o8 -s Emulator.Display=false
run: dotnet bin/Mosa.Utility.UnitTests.dll -o8 -display-off

generate-docs:
name: Generate documentation
Expand Down
2 changes: 1 addition & 1 deletion Source/Docs/command-line-arguments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Below are the command line arguments available:
-launch-off,Launcher.Launch,false

Launcher - Emulator:
-emulator,Emulator,
-emulator,Emulator,qemu|vmware|bochs
-qemu,Emulator,qemu
-vmware,Emulator,vmware
-bochs,Emulator,bochs
Expand Down
16 changes: 16 additions & 0 deletions Source/Mosa.Compiler.Common/DictionaryExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System.Collections.Generic;

namespace Mosa.Compiler.Common;

public static class DictionaryExtension
{
public static void AddIfNew<X, Y>(this Dictionary<X, Y> list, X key, Y item)
{
if (list.ContainsKey(key))
return;

list.Add(key, item);
}
}
10 changes: 1 addition & 9 deletions Source/Mosa.Compiler.Common/Exceptions/AssemblyLoadException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class AssemblyLoadException : CompilerException
/// <summary>
/// Initializes a new instance of the <see cref="AssemblyLoadException"/> class.
/// </summary>
public AssemblyLoadException() : base()
public AssemblyLoadException() : base("Assembly Load Exception")
{
}

Expand All @@ -20,12 +20,4 @@ public AssemblyLoadException() : base()
/// <param name="message">The message that describes the error.</param>
public AssemblyLoadException(string message) : base(message)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="AssemblyLoadException"/> class.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param>
public AssemblyLoadException(string message, Exception innerException) : base(message, innerException)
{ }
}
43 changes: 34 additions & 9 deletions Source/Mosa.Compiler.Common/Exceptions/CompilerException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,49 @@ namespace Mosa.Compiler.Common.Exceptions;
[Serializable]
public class CompilerException : Exception
{
public string Stage { get; set; }

public string Method { get; set; }

public string BaseMessage { get; private set; }

/// <summary>
/// Initializes a new instance of the <see cref="CompilerException" /> class.
/// </summary>
public CompilerException() : base()
{ }
{
BaseMessage = "Exception";
}

/// <summary>
/// Initializes a new instance of the <see cref="CompilerException" /> class.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public CompilerException(string message) : base(message)
{ }
{
BaseMessage = message;
}

/// <summary>
/// Initializes a new instance of the <see cref="CompilerException"/> class.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param>
public CompilerException(string message, Exception innerException) : base(message, innerException)
{ }
public CompilerException(string stage, string method, string message)
{
Stage = stage;
Method = method;
BaseMessage = message;
}

public override string Message => BuildMessage();

protected string BuildMessage()
{
if (Stage != null && Method != null)
return $"Stage: {Stage} - Method: {Method} -> {BaseMessage}";

if (Method != null)
return $"Method: {Method} -> {BaseMessage}";

if (Stage != null)
return $"Stage: {Stage} -> {BaseMessage}";

return BaseMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class InvalidMetadataException : CompilerException
/// <summary>
/// Initializes a new instance of the <see cref="InvalidMetadataException"/> class.
/// </summary>
public InvalidMetadataException()
public InvalidMetadataException() : base("Invalid Metadata Exception")
{ }

/// <summary>
Expand All @@ -19,12 +19,4 @@ public InvalidMetadataException()
/// <param name="message">The message that describes the error.</param>
public InvalidMetadataException(string message) : base(message)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="InvalidMetadataException"/> class.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param>
public InvalidMetadataException(string message, Exception innerException) : base(message, innerException)
{ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class NotImplementCompilerException : CompilerException
/// <summary>
/// Initializes a new instance of the <see cref="NotImplementCompilerException" /> class.
/// </summary>
public NotImplementCompilerException() : base()
public NotImplementCompilerException() : base("Not Implement Exception")
{ }

/// <summary>
Expand All @@ -19,12 +19,4 @@ public NotImplementCompilerException() : base()
/// <param name="message">The message that describes the error.</param>
public NotImplementCompilerException(string message) : base(message)
{ }

/// <summary>
/// Initializes a new instance of the <see cref="NotImplementCompilerException"/> class.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param>
public NotImplementCompilerException(string message, Exception innerException) : base(message, innerException)
{ }
}
2 changes: 0 additions & 2 deletions Source/Mosa.Compiler.Framework/BaseCompilerStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ public void ExecuteInitialization(Compiler compiler)
public void ExecuteSetup()
{
if (Compiler.IsStopped)
{
return;
}

Setup();
}
Expand Down
2 changes: 0 additions & 2 deletions Source/Mosa.Compiler.Framework/BaseInstruction.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.MosaTypeSystem;

namespace Mosa.Compiler.Framework;

/// <summary>
Expand Down
52 changes: 44 additions & 8 deletions Source/Mosa.Compiler.Framework/BaseMethodCompilerStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ public void Execute()
Finish();

UpdateRegisterCounters();
}

public void CleanUp()
{
MethodCompiler = null;
traceLogs = null;
}
Expand Down Expand Up @@ -791,30 +794,63 @@ protected void ReplaceWithCall(Context context, string fullName, string methodNa

#endregion Helper Methods

public void AllStopWithException(string exception)
public bool FullCheck(bool full = true)
{
MethodCompiler.Stop();
MethodCompiler.Compiler.Stop();
throw new CompilerException(exception);
return CheckVirtualRegisters(full) || CheckAllPhiInstructions() || CheckAllInstructions();
}

protected bool CheckAllPhiInstructions()
protected bool CheckVirtualRegisters(bool full)
{
foreach (var operand in MethodCompiler.VirtualRegisters)
{
if ((full && operand.IsUsed && !operand.IsDefined)
|| (!full && operand.IsUsed && !operand.IsDefined && !operand.HasParent && !operand.IsParent))
{
throw new CompilerException($"CHECK-FAILED: Virtual register used by not defined: {operand}");
}
}

return true;
}

protected bool CheckAllInstructions()
{
foreach (var block in BasicBlocks)
{
for (var node = block.AfterFirst; !node.IsBlockEndInstruction; node = node.Next)
{
if (node.IsEmptyOrNop)
if (node.IsEmptyOrNop || node.Instruction.HasVariableOperands)
continue;

if (!node.Instruction.IsPhi)
if (node.Instruction.DefaultResultCount != node.ResultCount)
{
throw new CompilerException($"CHECK-FAILED: Too many results: {block} at {node}");
}

if (node.Instruction.DefaultOperandCount != node.OperandCount)
{
throw new CompilerException($"CHECK-FAILED: Too many operands: {block} at {node}");
}
}
}

return true;
}

protected bool CheckAllPhiInstructions()
{
foreach (var block in BasicBlocks)
{
for (var node = block.AfterFirst; !node.IsBlockEndInstruction; node = node.Next)
{
if (node.IsEmptyOrNop || !node.Instruction.IsPhi)
break;

foreach (var phiblock in node.PhiBlocks)
{
if (!block.PreviousBlocks.Contains(phiblock))
{
throw new CompilerException($"{FormattedStageName}:CheckAllPhiInstructions() failed in block: {block} at {node}!");
throw new CompilerException($"CHECK-FAILED: PHI consistency: {block} at {node}");
}
}
}
Expand Down
10 changes: 0 additions & 10 deletions Source/Mosa.Compiler.Framework/BaseTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ int IComparable<BaseTransform>.CompareTo(BaseTransform other)

#region Filter Methods

protected static bool IsSSAForm(Operand operand)
{
return operand.Definitions.Count == 1;
}

protected static bool IsSSAFormOrConstant(Operand operand)
{
return operand.IsConstant || operand.Definitions.Count == 1;
}

protected static bool AreSame(Operand operand1, Operand operand2)
{
if (operand1 == operand2)
Expand Down

0 comments on commit 5a5dce2

Please sign in to comment.