Permalink
Browse files

Merge pull request #499 from tgiphil/Improvements-1

General Improvements
  • Loading branch information...
tgiphil committed Sep 24, 2018
2 parents ce554b8 + ebc228a commit fdd699e5db4b099cf10fae4f83eb07f69e9bcd4f
Showing with 570 additions and 919 deletions.
  1. +1 −3 Source/Mosa.Compiler.Framework/BaseCodeTransformationStage.cs
  2. +1 −3 Source/Mosa.Compiler.Framework/BaseCodeTransformationStageLegacy.cs
  3. +24 −6 Source/Mosa.Compiler.Framework/BaseMethodCompilerStage.cs
  4. +19 −0 Source/Mosa.Compiler.Framework/Basics/Loop.cs
  5. +61 −0 Source/Mosa.Compiler.Framework/Basics/QuickBlockSetLookup.cs
  6. +41 −0 Source/Mosa.Compiler.Framework/Counter.cs
  7. +0 −18 Source/Mosa.Compiler.Framework/LoadStore.cs
  8. +4 −0 Source/Mosa.Compiler.Framework/Mosa.Compiler.Framework.csproj
  9. +2 −5 Source/Mosa.Compiler.Framework/Stages/CILDecodingStage.cs
  10. +0 −2 Source/Mosa.Compiler.Framework/Stages/CILProtectedRegionStage.cs
  11. +0 −2 Source/Mosa.Compiler.Framework/Stages/CallStage.cs
  12. +8 −15 Source/Mosa.Compiler.Framework/Stages/CodeGenerationStage.cs
  13. +10 −9 Source/Mosa.Compiler.Framework/Stages/DevirtualizeCallStage.cs
  14. +5 −7 Source/Mosa.Compiler.Framework/Stages/EnterSSAStage.cs
  15. +0 −2 Source/Mosa.Compiler.Framework/Stages/ExceptionPrologueStage.cs
  16. +0 −6 Source/Mosa.Compiler.Framework/Stages/ExceptionStage.cs
  17. +0 −2 Source/Mosa.Compiler.Framework/Stages/IRLongDecompositionStage.cs
  18. +135 −180 Source/Mosa.Compiler.Framework/Stages/IROptimizationStage.cs
  19. +11 −5 Source/Mosa.Compiler.Framework/Stages/InlineEvaluationStage.cs
  20. +11 −2 Source/Mosa.Compiler.Framework/Stages/InlineStage.cs
  21. +4 −7 Source/Mosa.Compiler.Framework/Stages/LeaveSSAStage.cs
  22. +72 −0 Source/Mosa.Compiler.Framework/Stages/LoopInvariantCodeMotionStage.cs
  23. +0 −6 Source/Mosa.Compiler.Framework/Stages/OperandAssignmentStage.cs
  24. +0 −13 Source/Mosa.Compiler.Framework/Stages/OptimizationRulesStage.cs
  25. +0 −2 Source/Mosa.Compiler.Framework/Stages/PlugStage.cs
  26. +0 −2 Source/Mosa.Compiler.Framework/Stages/PreciseGCStage.cs
  27. +7 −8 Source/Mosa.Compiler.Framework/Stages/PromoteTemporaryVariables.cs
  28. +0 −2 Source/Mosa.Compiler.Framework/Stages/ProtectedRegionLayoutStage.cs
  29. +17 −15 Source/Mosa.Compiler.Framework/Stages/SparseConditionalConstantPropagationStage.cs
  30. +2 −11 Source/Mosa.Compiler.Framework/Stages/UnboxValueTypeStage.cs
  31. +20 −30 Source/Mosa.Compiler.Framework/Stages/ValueNumberingStage.cs
  32. +1 −3 Source/Mosa.Platform.x86/Stages/LongOperandStage.cs
  33. +9 −9 Source/Mosa.Platform.x86/Stages/SimpleDeadCodeRemovalStage.cs
  34. +0 −3 Source/Mosa.Tool.Bootstrap/Mosa.Tool.Bootstrap.csproj
  35. +38 −7 Source/Mosa.Tools.Package/Mosa.Tools.Package.csproj
  36. +18 −0 Source/Mosa.Tools.Package/packages.config
  37. +21 −0 Source/Mosa.UnitTests/CharTests.cs
  38. +14 −0 Source/Mosa.UnitTests/OptimizationTests.cs
  39. +14 −8 Source/Mosa.Utility.UnitTests/Numbers/Series2.cs
  40. +0 −526 Source/Mosa.Utility.UnitTests/UnitTestEngineV2.cs
@@ -21,8 +21,6 @@ public abstract class BaseCodeTransformationStage : BaseMethodCompilerStage
protected override void Initialize()
{
base.Initialize();
visitationContexts = new ContextVisitationDelegate[MaxInstructions];
visitationNodes = new NodeVisitationDelegate[MaxInstructions];
@@ -40,7 +38,7 @@ protected override void Run()
if (node.IsEmpty)
continue;
instructionCount++;
//instructionCount++;
if (node.Instruction.ID == 0)
continue; // no mapping
@@ -21,8 +21,6 @@ public abstract class BaseCodeTransformationStageLegacy : BaseMethodCompilerStag
protected override void Initialize()
{
base.Initialize();
visitationDictionary = new Dictionary<BaseInstruction, Tuple<ContextVisitationDelegate, NodeVisitationDelegate>>();
PopulateVisitationDictionary();
@@ -42,7 +40,7 @@ protected override void Run()
if (node.IsEmpty)
continue;
instructionCount++;
//instructionCount++;
if (visitationDictionary.TryGetValue(node.Instruction, out Tuple<ContextVisitationDelegate, NodeVisitationDelegate> visitationMethod))
{
@@ -18,7 +18,7 @@ public abstract class BaseMethodCompilerStage : ITraceFactory
{
#region Data Members
protected int instructionCount = 0;
//protected int instructionCount = 0;
protected string formattedStageName;
@@ -169,6 +169,11 @@ public abstract class BaseMethodCompilerStage : ITraceFactory
/// </summary>
protected bool HasCode { get { return BasicBlocks.HeadBlocks.Count != 0; } }
/// <summary>
/// The counters
/// </summary>
private List<Counter> Counters = new List<Counter>();
#endregion Method Properties
#region Methods
@@ -211,8 +216,18 @@ public void Setup(MethodCompiler methodCompiler, int position)
Setup();
}
protected void Register(Counter counter)
{
Counters.Add(counter);
}
public void Execute()
{
foreach (var counter in Counters)
{
counter.Reset();
}
//Run();
try
@@ -230,6 +245,11 @@ public void Execute()
Finish();
foreach (var counter in Counters)
{
UpdateCounter(counter);
}
//if (!MethodCompiler.IsStopped)
//{
// Debug.Assert(BasicBlocks.RuntimeValidation());
@@ -268,7 +288,6 @@ protected virtual void Initialize()
protected virtual void Setup()
{
instructionCount = 0;
}
protected virtual void Run()
@@ -704,11 +723,10 @@ protected void NewCompilerTraceEvent(CompilerEvent compileEvent, string message)
/// <summary>
/// Updates the counter.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="count">The count.</param>
public void UpdateCounter(string name, int count)
/// <param name="counter">The counter.</param>
public void UpdateCounter(Counter counter)
{
MethodData.Counters.UpdateNoLock(name, count);
MethodData.Counters.UpdateNoLock(counter.Name, counter.Count);
}
#region Helpers
@@ -0,0 +1,19 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.
using System.Collections.Generic;
namespace Mosa.Compiler.Framework.Basics
{
public sealed class Loop
{
public BasicBlock Header { get; set; }
public readonly List<BasicBlock> Backedges = new List<BasicBlock>();
public readonly List<BasicBlock> nodes = new List<BasicBlock>();
public Loop(BasicBlock header, BasicBlock backedge)
{
Header = header;
Backedges.Add(backedge);
}
}
}
@@ -0,0 +1,61 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.
using System.Collections;
using System.Collections.Generic;
namespace Mosa.Compiler.Framework.Basics
{
public class QuickBlockSetLookup
{
private BitArray array;
public QuickBlockSetLookup(BasicBlocks basicBlocks)
{
array = new BitArray(basicBlocks.Count, false);
}
public QuickBlockSetLookup(BasicBlocks basicBlocks, List<BasicBlock> blocks)
{
array = new BitArray(basicBlocks.Count, false);
if (blocks != null)
{
Add(blocks);
}
}
public void Add(List<BasicBlock> blocks)
{
foreach (var block in blocks)
{
array.Set(block.Sequence, true);
}
}
public bool Contains(BasicBlock block)
{
return array.Get(block.Sequence);
}
public void Add(BasicBlock block)
{
array.Set(block.Sequence, true);
}
public void Remove(BasicBlock block)
{
array.Set(block.Sequence, false);
}
public IEnumerable<BasicBlock> GetBlocks(BasicBlocks basicBlocks)
{
for (int i = 0; i < array.Count; i++)
{
if (array.Get(i))
{
yield return basicBlocks[i];
}
}
}
}
}
@@ -0,0 +1,41 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.
namespace Mosa.Compiler.Framework
{
public class Counter
{
public readonly string Name;
public int Count = 0;
public Counter(string name)
{
Name = name;
}
public void Increment()
{
Count++;
}
public void Reset()
{
Count = 0;
}
public void Set(int count)
{
Count = count;
}
public void Set(bool condition, int truevalue = 1, int falsevalue = 0)
{
Count = condition ? truevalue : falsevalue;
}
public static Counter operator ++(Counter counter)
{
counter.Count++;
return counter;
}
}
}
@@ -42,23 +42,5 @@ public static void OrderStoreOperands(InstructionNode node, MethodCompiler metho
node.Operand1 = operand2;
}
}
//public static void OrderStoreOperands(InstructionNode node, BaseMethodCompiler methodCompiler)
//{
// if (node.Operand2.IsResolvedConstant && node.Operand3.IsResolvedConstant)
// {
// node.Operand2 = Operand.CreateConstant(node.Operand2.ConstantUnsignedLongInteger + node.Operand3.ConstantUnsignedLongInteger, methodCompiler.TypeSystem);
// node.Operand3 = methodCompiler.ConstantZero;
// }
// if (node.Operand2.IsConstant && !node.Operand3.IsConstant)
// {
// var operand2 = node.Operand2;
// var operand3 = node.Operand3;
// node.Operand3 = operand2;
// node.Operand2 = operand3;
// }
//}
}
}
@@ -92,6 +92,7 @@
<Compile Include="BaseCodeTransformationStage.cs" />
<Compile Include="BaseCompilerExtension.cs" />
<Compile Include="CIL\IRInstructions.cs" />
<Compile Include="Counter.cs" />
<Compile Include="Expression\Rule.cs" />
<Compile Include="Expression\NodeParser.cs" />
<Compile Include="Expression\SymbolDictionary.cs" />
@@ -370,6 +371,7 @@
<Compile Include="Platform\OpcodeEncoder.cs" />
<Compile Include="PlugSystem.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Basics\QuickBlockSetLookup.cs" />
<Compile Include="RegisterAllocator\BasicRegisterAllocator.cs" />
<Compile Include="RegisterAllocator\MoveExtended.cs" />
<Compile Include="RegisterAllocator\Move.cs" />
@@ -393,6 +395,7 @@
<Compile Include="RegisterAllocator\GreedyRegisterAllocator.cs" />
<Compile Include="CompilerStages\DebugFileGenerationStage.cs" />
<Compile Include="Stages\DominanceOutputStage.cs" />
<Compile Include="Basics\Loop.cs" />
<Compile Include="Stages\OptimizationRulesStage.cs" />
<Compile Include="Stages\PlugStage.cs" />
<Compile Include="Stages\DevirtualizeCallStage.cs" />
@@ -408,6 +411,7 @@
<Compile Include="Stages\InlineStage.cs" />
<Compile Include="Stages\InlineEvaluationStage.cs" />
<Compile Include="Stages\IRCleanupStage.cs" />
<Compile Include="Stages\LoopInvariantCodeMotionStage.cs" />
<Compile Include="Stages\ValueNumberingStage.cs" />
<Compile Include="Stages\SparseConditionalConstantPropagationStage.cs" />
<Compile Include="CompilerStages\MethodExceptionLookupTableStage.cs" />
@@ -40,8 +40,6 @@ public sealed class CILDecodingStage : BaseMethodCompilerStage, IInstructionDeco
protected override void Setup()
{
base.Setup();
instruction = null;
block = null;
counts = null;
@@ -120,8 +118,6 @@ protected override void Run()
protected override void Finish()
{
base.Finish();
if (counts == null)
return;
@@ -234,7 +230,8 @@ private void DecodeInstructions()
cil.Decode(node, this);
prefix = (cil is PrefixInstruction);
instructionCount++;
//instructionCount++;
const bool addjmp = false;
@@ -15,8 +15,6 @@ public class CILProtectedRegionStage : BaseMethodCompilerStage
protected override void Initialize()
{
base.Initialize();
exceptionType = TypeSystem.GetTypeByName("System", "Exception");
}
@@ -19,8 +19,6 @@ public sealed class CallStage : BaseCodeTransformationStage
protected override void Setup()
{
base.Setup();
loadInstruction = Select(IRInstruction.LoadInt32, IRInstruction.LoadInt64);
moveInstruction = Select(IRInstruction.MoveInt32, IRInstruction.MoveInt64);
}
Oops, something went wrong.

0 comments on commit fdd699e

Please sign in to comment.