Skip to content

Commit

Permalink
- WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tgiphil committed Apr 27, 2024
1 parent 4e5f0ba commit ab33d66
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 7 deletions.
2 changes: 0 additions & 2 deletions Source/Mosa.Compiler.Framework/BaseInstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public abstract class BaseInstruction

public virtual string FamilyName => null;

public virtual string Modifier => null;

public virtual string FullName { get; private set; }

public virtual string OpcodeName { get; private set; }
Expand Down
74 changes: 74 additions & 0 deletions Source/Mosa.Compiler.Framework/InstructionTrace2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System.Text;
using Mosa.Compiler.Framework;
using Mosa.Compiler.MosaTypeSystem;

/// <summary>
/// Logs all instructions.
/// </summary>
public static class InstructionTrace2
{
public static TraceLog Run(string stage, MosaMethod method, BasicBlocks basicBlocks, int version, string section, int step)
{
var traceLog = new TraceLog(TraceType.MethodInstructions, method, stage, section, version, step);

traceLog?.Log($"M\t{method.FullName}\t{version}\t{stage}\t{step}");

var sb = new StringBuilder();

foreach (var block in basicBlocks)
{
traceLog?.Log($"S\t{block.Label:X5}\t{block.Sequence}\t{(block.IsHeadBlock ? "Header" : string.Empty)}\t{block.PreviousBlocks.Count}\t{GetTabBlocks(block.PreviousBlocks)}");

for (var node = block.First; !node.IsBlockEndInstruction; node = node.Next)
{
if (node.IsEmpty)
continue;

sb.Clear();

sb.Append($"I\t{block.Label:X5}\t{(node.IsMarked ? "*" : string.Empty)}\t{node.Instruction}\t");
sb.Append($"{(node.ConditionCode != ConditionCode.Undefined ? node.ConditionCode.GetConditionString() : string.Empty)}\t");

sb.Append($"{node.ResultCount}\t");
sb.Append($"{node.OperandCount}\t");
sb.Append($"{node.BranchTargetsCount}\t");
sb.Append($"{node.PhiBlocks}\t");

foreach (var operand in node.Results)
{
sb.Append($"{operand}\t");
}

foreach (var operand in node.Operands)
{
sb.Append($"{operand}\t");
}

sb.Append($"{GetTabBlocks(node.BranchTargets)}");
sb.Append($"{GetTabBlocks(node.PhiBlocks)}");

sb.Length--;

sb.AppendLine();
}

traceLog?.Log($"E\t{block.Label}\t{block.Sequence}\t{block.NextBlocks.Count}\t{GetTabBlocks(block.NextBlocks)}");
}

return traceLog;
}

private static string GetTabBlocks(IList<BasicBlock> blocks)
{
var sb = new StringBuilder();

foreach (var next in blocks)
{
sb.AppendFormat($"{next}\t");
}

return sb.ToString();
}
}
5 changes: 0 additions & 5 deletions Source/Mosa.Compiler.Framework/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -854,11 +854,6 @@ public override string ToString()
sb.Append($" [{ConditionCode.GetConditionString()}]");
}

if (Instruction.Modifier != null)
{
sb.Append($" [{Instruction.Modifier}]");
}

for (var i = 0; i < ResultCount; i++)
{
var op = GetResult(i);
Expand Down
6 changes: 6 additions & 0 deletions Source/Mosa.Tool.Explorer/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,12 @@ private void ExtendMethodCompilerPipeline(Pipeline<BaseMethodCompilerStage> pipe
pipeline.InsertAfterLast<InlineStage>(new GraphVizStage());
}

if (MosaSettings.SSA)
{
pipeline.InsertBefore<EnterSSAStage>(new GraphVizStage());
pipeline.InsertAfterLast<EnterSSAStage>(new GraphVizStage());
}

pipeline.InsertAfterLast<FastBlockOrderingStage>(new GraphVizStage());
pipeline.Add(new GraphVizStage());
}
Expand Down

0 comments on commit ab33d66

Please sign in to comment.