Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- Cleanup

  • Loading branch information...
commit 7a30a4a8534305828b96482ab7a98df07d4059cd 1 parent 1ad8474
@tgiphil tgiphil authored
View
29 Source/Mosa.Compiler.Framework/BasicBlocks.cs
@@ -35,6 +35,15 @@ public sealed class BasicBlocks : IEnumerable<BasicBlock>
/// </summary>
private readonly List<BasicBlock> headBlocks = new List<BasicBlock>();
+ /// <summary>
+ ///
+ /// </summary>
+ private BasicBlock prologueBlock = null;
+ /// <summary>
+ ///
+ /// </summary>
+ private BasicBlock epilogueBlock = null;
+
#endregion
#region Construction
@@ -91,12 +100,28 @@ IEnumerator IEnumerable.GetEnumerator()
/// <summary>
/// Gets the prologue block.
/// </summary>
- public BasicBlock PrologueBlock { get { return this.GetByLabel(BasicBlock.PrologueLabel); } }
+ public BasicBlock PrologueBlock
+ {
+ get
+ {
+ if (prologueBlock == null)
+ prologueBlock = GetByLabel(BasicBlock.PrologueLabel);
+ return prologueBlock;
+ }
+ }
/// <summary>
/// Gets the epilogue block.
/// </summary>
- public BasicBlock EpilogueBlock { get { return this.GetByLabel(BasicBlock.EpilogueLabel); } }
+ public BasicBlock EpilogueBlock
+ {
+ get
+ {
+ if (epilogueBlock == null)
+ epilogueBlock = GetByLabel(BasicBlock.EpilogueLabel);
+ return epilogueBlock;
+ }
+ }
#endregion
View
4 Source/Mosa.Compiler.Framework/Stages/ConstantFoldingStage.cs
@@ -20,10 +20,6 @@ public sealed class ConstantFoldingStage : BaseMethodCompilerStage, IMethodCompi
/// </summary>
void IMethodCompilerStage.Run()
{
- foreach (var block in this.basicBlocks)
- if (block.NextBlocks.Count == 0 && block.PreviousBlocks.Count == 0)
- return;
-
foreach (var block in basicBlocks)
{
for (var context = new Context(instructionSet, block); !context.EndOfInstruction; context.GotoNext())
View
42 Source/Mosa.Compiler.Framework/Stages/ConstantPropagationStage.cs
@@ -46,11 +46,7 @@ public enum PropagationStage
/// <summary>
///
/// </summary>
- private PropagationStage stage = PropagationStage.PreFolding;
- /// <summary>
- ///
- /// </summary>
- private HashSet<int> propagated = new HashSet<int>();
+ private PropagationStage stage;
/// <summary>
/// Initializes a new instance of the <see cref="ConstantPropagationStage"/> class.
@@ -82,23 +78,11 @@ public ConstantPropagationStage(PropagationStage stage)
/// </summary>
void IMethodCompilerStage.Run()
{
- foreach (var block in basicBlocks)
- if (block.NextBlocks.Count == 0 && block.PreviousBlocks.Count == 0)
- return;
-
- bool remove = false;
-
foreach (BasicBlock block in basicBlocks)
{
- if (block == basicBlocks.PrologueBlock || block == basicBlocks.EpilogueBlock)
- continue;
-
for (Context ctx = new Context(instructionSet, block); !ctx.EndOfInstruction; ctx.GotoNext())
{
- //if (this.propagated.Contains(ctx.Index))
- // continue;
-
- if (!(ctx.Instruction is IR.Move || ctx.Instruction is CIL.StlocInstruction))
+ if (!(ctx.Instruction is IR.Move))
continue;
if (!(ctx.Operand1 is ConstantOperand))
@@ -108,11 +92,11 @@ void IMethodCompilerStage.Run()
if (sop == null || !(sop.Operand is StackOperand))
continue;
- if (!CheckResultsAreBuiltin(sop))
+ if (!CheckResultsAreBuiltIn(sop))
continue;
ReplaceUses(sop, ctx.Operand1 as ConstantOperand);
- ctx.SetInstruction(IRInstruction.Nop);
+ ctx.Remove();
}
}
}
@@ -121,13 +105,10 @@ void IMethodCompilerStage.Run()
/// Checks for by ref.
/// </summary>
/// <param name="sop">The sop.</param>
- private bool CheckResultsAreBuiltin(SsaOperand sop)
+ private bool CheckResultsAreBuiltIn(SsaOperand sop)
{
foreach (BasicBlock block in basicBlocks)
{
- if (block == basicBlocks.GetByLabel(BasicBlock.PrologueLabel) || block == basicBlocks.EpilogueBlock)
- continue;
-
for (Context ctx = new Context(instructionSet, block); !ctx.EndOfInstruction; ctx.GotoNext())
{
if (!InstructionUsesOperand(ctx, sop))
@@ -174,11 +155,12 @@ private bool InstructionUsesOperand(Context context, SsaOperand sop)
{
foreach (var operand in context.Operands)
{
- if (!(operand is SsaOperand))
- continue;
var ssaOp = operand as SsaOperand;
- return sop.Operand == ssaOp.Operand && sop.SsaVersion == ssaOp.SsaVersion;
+
+ if (ssaOp != null)
+ return sop.Operand == ssaOp.Operand && sop.SsaVersion == ssaOp.SsaVersion;
}
+
return false;
}
@@ -191,20 +173,18 @@ private void ReplaceUses(SsaOperand sop, ConstantOperand constantOperand)
{
foreach (BasicBlock block in basicBlocks)
{
- if (block == basicBlocks.PrologueBlock || block == basicBlocks.EpilogueBlock)
- continue;
-
for (Context ctx = new Context(instructionSet, block); !ctx.EndOfInstruction; ctx.GotoNext())
{
for (var i = 0; i < ctx.OperandCount; ++i)
{
var op = ctx.GetOperand(i) as SsaOperand;
+
if (op == null)
continue;
+
if (op.Operand == sop.Operand && op.SsaVersion == sop.SsaVersion)
{
ctx.SetOperand(i, constantOperand);
- propagated.Add(ctx.Index);
}
}
}
View
4 Source/Mosa.Compiler.Framework/Stages/LeaveSSAStage.cs
@@ -88,8 +88,8 @@ private void InsertCopyStatement(BasicBlock predecessor, Operand result, Operand
Debug.Assert(!(source is SsaOperand));
Debug.Assert(!(destination is SsaOperand));
- //if (destination != source)
- context.SetInstruction(IR.IRInstruction.Move, destination, source);
+ if (destination != source)
+ context.SetInstruction(IR.IRInstruction.Move, destination, source);
}
/// <summary>
Please sign in to comment.
Something went wrong with that request. Please try again.