Skip to content

Commit

Permalink
Merge pull request #604 from tgiphil/018-Performance
Browse files Browse the repository at this point in the history
Performance Testing
  • Loading branch information
tgiphil committed Mar 3, 2019
2 parents 3dd005c + c9d99fe commit f4eee93
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private static List<BaseMethodCompilerStage> GetDefaultMethodPipeline(CompilerOp
(compilerOptions.EnableLoopInvariantCodeMotion && compilerOptions.EnableSSA) ? new LoopInvariantCodeMotionStage() : null,
(compilerOptions.EnableSparseConditionalConstantPropagation && compilerOptions.EnableSSA) ? new SparseConditionalConstantPropagationStage() : null,
(compilerOptions.EnableIROptimizations) ? new IROptimizationStage() : null,
(compilerOptions.IRLongExpansion && compilerOptions.Architecture.NativePointerSize == 4) ? new IRLongDecompositionStage() : null,
(compilerOptions.EnableIRLongExpansion && compilerOptions.Architecture.NativePointerSize == 4) ? new IRLongDecompositionStage() : null,
new LowerIRStage(),
(compilerOptions.TwoPassOptimizations && compilerOptions.EnableValueNumbering && compilerOptions.EnableSSA) ? new ValueNumberingStage() : null,
(compilerOptions.TwoPassOptimizations && compilerOptions.EnableLoopInvariantCodeMotion && compilerOptions.EnableSSA) ? new LoopInvariantCodeMotionStage() : null,
Expand Down
4 changes: 2 additions & 2 deletions Source/Mosa.Compiler.Framework/CompilerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class CompilerOptions
/// <summary>
/// Gets or sets a value indicating whether [enable IR long operand conversion].
/// </summary>
public bool IRLongExpansion { get; set; }
public bool EnableIRLongExpansion { get; set; }

/// <summary>
/// Gets or sets a value indicating whether [enable platform optimizations].
Expand Down Expand Up @@ -323,7 +323,7 @@ public CompilerOptions()
EmitStaticRelocations = true;
TwoPassOptimizations = true;
EnableStatistics = true;
IRLongExpansion = true;
EnableIRLongExpansion = true;
EnableValueNumbering = true;
EnableLoopInvariantCodeMotion = true;
EnablePlatformOptimizations = true;
Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Tool.Explorer/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ private void SetCompilerOptions()
Compiler.CompilerOptions.EnableSparseConditionalConstantPropagation = cbEnableSparseConditionalConstantPropagation.Checked;
Compiler.CompilerOptions.EmitBinary = cbEnableBinaryCodeGeneration.Checked;
Compiler.CompilerOptions.EnableInlinedMethods = cbEnableInlinedMethods.Checked;
Compiler.CompilerOptions.IRLongExpansion = cbEnableIRLongExpansion.Checked;
Compiler.CompilerOptions.EnableIRLongExpansion = cbEnableIRLongExpansion.Checked;
Compiler.CompilerOptions.InlinedIRMaximum = 12;
Compiler.CompilerOptions.TwoPassOptimizations = cbEnableTwoPassOptimizations.Checked;
Compiler.CompilerOptions.TraceLevel = 100;
Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Utility.Launcher/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void Compile()
compiler.CompilerOptions.EnableSparseConditionalConstantPropagation = Options.EnableSparseConditionalConstantPropagation;
compiler.CompilerOptions.EnableInlinedMethods = Options.EnableInlinedMethods;
compiler.CompilerOptions.InlinedIRMaximum = Options.InlinedIRMaximum;
compiler.CompilerOptions.IRLongExpansion = Options.EnableIRLongExpansion;
compiler.CompilerOptions.EnableIRLongExpansion = Options.EnableIRLongExpansion;
compiler.CompilerOptions.TwoPassOptimizations = Options.TwoPassOptimizations;
compiler.CompilerOptions.EnableValueNumbering = Options.EnableValueNumbering;
compiler.CompilerOptions.OutputFile = CompiledFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Mosa.Compiler.Common\Mosa.Compiler.Common.csproj">
<Project>{0B1011A6-8FCD-4F9E-BBB8-8DB86E23D2E8}</Project>
<Name>Mosa.Compiler.Common</Name>
</ProjectReference>
<ProjectReference Include="..\Mosa.Compiler.Framework\Mosa.Compiler.Framework.csproj">
<Project>{75a12a8a-8c8f-4d1e-801b-689d8f781bf4}</Project>
<Name>Mosa.Compiler.Framework</Name>
Expand All @@ -61,6 +65,14 @@
<Project>{0FB92651-3EE8-441D-84F2-C4DFDA68E8A5}</Project>
<Name>Mosa.Platform.ARMv6</Name>
</ProjectReference>
<ProjectReference Include="..\Mosa.Platform.ESP32\Mosa.Platform.ESP32.csproj">
<Project>{5b45af28-3b67-4542-a0c9-947f3cdd9741}</Project>
<Name>Mosa.Platform.ESP32</Name>
</ProjectReference>
<ProjectReference Include="..\Mosa.Platform.x64\Mosa.Platform.x64.csproj">
<Project>{f445db8e-e25a-41ef-a158-c742f14e94e4}</Project>
<Name>Mosa.Platform.x64</Name>
</ProjectReference>
<ProjectReference Include="..\Mosa.Platform.x86\Mosa.Platform.x86.csproj">
<Project>{DE30CBE9-50F3-4A3E-BCC9-A8A36348530E}</Project>
<Name>Mosa.Platform.x86</Name>
Expand Down
100 changes: 100 additions & 0 deletions Source/Mosa.Workspace.Experiment.Debug/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,111 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Common.Exceptions;
using Mosa.Compiler.Framework;
using Mosa.Compiler.Framework.Linker;
using Mosa.Compiler.MosaTypeSystem;
using System;
using System.Diagnostics;

namespace Mosa.Workspace.Experiment.Debug
{
internal static class Program
{
private static void Main()
{
var platform = "x86";

var compilerOptions = new CompilerOptions()
{
EnableSSA = true,
EnableIROptimizations = true,
EnableSparseConditionalConstantPropagation = true,
EnableInlinedMethods = true,
EnableIRLongExpansion = true,
EnableValueNumbering = true,
TwoPassOptimizations = true,
EnableMethodScanner = false,

MultibootSpecification = MultibootSpecification.V1,
LinkerFormatType = LinkerFormatType.Elf32,
InlinedIRMaximum = 12,

BaseAddress = 0x00500000,
EmitStaticRelocations = false,
EmitAllSymbols = false,

EmitBinary = false
};

compilerOptions.Architecture = SelectArchitecture(platform);

compilerOptions.AddSourceFile($"Mosa.TestWorld.{platform}.exe");
compilerOptions.AddSourceFile("Mosa.Plug.Korlib.dll");
compilerOptions.AddSourceFile($"Mosa.Plug.Korlib.{platform}.dll");

var stopwatch = new Stopwatch();

var compiler = new MosaCompiler
{
CompilerOptions = compilerOptions
};

compiler.Load();

var method1 = GetMethod("Mosa.Kernel.x86.IDT::SetTableEntries", compiler.TypeSystem);
var method2 = GetMethod("System.Void Mosa.TestWorld.x86.Boot::Thread1", compiler.TypeSystem);

compiler.Initialize();
compiler.PreCompile();

stopwatch.Start();

for (int i = 0; i < 5; i++)
{
var start = stopwatch.ElapsedMilliseconds;

compiler.Schedule(method1);
compiler.Compile();

Console.WriteLine("Elapsed: " + (stopwatch.ElapsedMilliseconds - start).ToString("F2") + " ms");
}

for (int i = 0; i < 5; i++)
{
var start = stopwatch.ElapsedMilliseconds;

compiler.Schedule(method2);
compiler.Compile();

Console.WriteLine("Elapsed: " + (stopwatch.ElapsedMilliseconds - start).ToString("F2") + " ms");
}

return;
}

private static MosaMethod GetMethod(string partial, TypeSystem typeSystem)
{
foreach (var type in typeSystem.AllTypes)
{
foreach (var method in type.Methods)
{
if (method.FullName.Contains(partial))
return method;
}
}

return null;
}

private static BaseArchitecture SelectArchitecture(string architecture)
{
switch (architecture.ToLower())
{
case "x86": return Platform.x86.Architecture.CreateArchitecture(Platform.x86.ArchitectureFeatureFlags.AutoDetect);
case "x64": return Platform.x64.Architecture.CreateArchitecture(Platform.x64.ArchitectureFeatureFlags.AutoDetect);
case "armv6": return Platform.ARMv6.Architecture.CreateArchitecture(Platform.ARMv6.ArchitectureFeatureFlags.AutoDetect);
default: throw new NotImplementCompilerException(string.Format("Unknown or unsupported Architecture {0}.", architecture));
}
}
}
}

0 comments on commit f4eee93

Please sign in to comment.