Skip to content

Commit

Permalink
WIP (#691)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgiphil committed Sep 7, 2019
1 parent 5c13541 commit 0e61982
Show file tree
Hide file tree
Showing 191 changed files with 4,818 additions and 2,252 deletions.
1,246 changes: 0 additions & 1,246 deletions Source/Data/ARMv6-Instructions.json

This file was deleted.

239 changes: 239 additions & 0 deletions Source/Data/IR-Optimizations.json
@@ -0,0 +1,239 @@
{
"Optimizations": [
{
"FamilyName": "IR2",
"Type": "ConstantFolding",
"Name": "Add32",
"SubName": "",
"Expression": "IR.Add32 a b",
"Filter": "IsResolvedConstant(a) & IsResolvedConstant(b)",
"Result": "[Add32(a,b)]"
},
{
"FamilyName": "IR2",
"Type": "ConstantFolding",
"Name": "Add64",
"SubName": "",
"Expression": "IR.Add64 a b",
"Filter": "IsResolvedConstant(a) & IsResolvedConstant(b)",
"Result": "[Add64(a,b)]"
},
{
"FamilyName": "IR2",
"Type": "StrengthReduction",
"Name": "Add32",
"SubName": "Right",
"Expression": "IR.Add32 a 0",
"Filter": "",
"Result": "a"
},
{
"FamilyName": "IR2",
"Type": "StrengthReduction",
"Name": "Add32",
"SubName": "Left",
"Expression": "IR.Add32 0 a",
"Filter": "",
"Result": "a"
},
{
"FamilyName": "IR2",
"Type": "StrengthReduction",
"Name": "Add64",
"SubName": "Right",
"Expression": "IR.Add64 a 0",
"Filter": "",
"Result": "a"
},
{
"FamilyName": "IR2",
"Type": "StrengthReduction",
"Name": "Add64",
"SubName": "Left",
"Expression": "IR.Add64 0 a",
"Filter": "",
"Result": "a"
},
{
"FamilyName": "IR2",
"Type": "StrengthReduction",
"Name": "ShiftRight32",
"SubName": "ZeroValue",
"Expression": "IR.ShiftRight32 0 a",
"Filter": "",
"Result": "0"
},
{
"FamilyName": "IR2",
"Type": "StrengthReduction",
"Name": "ShiftRight32",
"SubName": "ByZero",
"Expression": "IR.ShiftRight32 a 0",
"Filter": "",
"Result": "a"
},
{
"FamilyName": "IR2",
"Type": "StrengthReduction",
"Name": "ShiftRight64",
"SubName": "ZeroValue",
"Expression": "IR.ShiftRight64 0 a",
"Filter": "",
"Result": "0"
},
{
"FamilyName": "IR2",
"Type": "StrengthReduction",
"Name": "ShiftRight64",
"SubName": "ByZero",
"Expression": "IR.ShiftRight64 a 0",
"Filter": "",
"Result": "a"
},
{
"FamilyName": "IR2",
"Type": "StrengthReduction",
"Name": "ShiftLeft32",
"SubName": "ByZero",
"Expression": "IR.ShiftLeft32 a 0",
"Filter": "",
"Result": "a"
},
{
"FamilyName": "IR2",
"Type": "StrengthReduction",
"Name": "ShiftLeft32",
"SubName": "ByZero",
"Expression": "IR.ShiftLeft32 a 0",
"Filter": "",
"Result": "a"
},
{
"FamilyName": "IR2",
"Type": "StrengthReduction",
"Name": "ShiftLeft64",
"SubName": "ByZero",
"Expression": "IR.ShiftLeft64 a 0",
"Filter": "",
"Result": "a"
},
{
"FamilyName": "IR2",
"Type": "StrengthReduction",
"Name": "ShiftLeft64",
"SubName": "ByZero",
"Expression": "IR.ShiftLeft64 a 0",
"Filter": "",
"Result": "a"
},

{
"FamilyName": "IR2",
"Type": "StrengthReduction",
"Name": "Sub32",
"SubName": "ByZero",
"Expression": "IR.Sub32 a 0",
"Filter": "",
"Result": "a"
},
{
"FamilyName": "IR2",
"Type": "StrengthReduction",
"Name": "Sub64",
"SubName": "ByZero",
"Expression": "IR.Sub64 a 0",
"Filter": "",
"Result": "a"
},
{
"FamilyName": "IR2",
"Type": "StrengthReduction",
"Name": "Sub32",
"SubName": "BySame",
"Expression": "IR.Sub32 a a",
"Filter": "",
"Result": "0"
},
{
"FamilyName": "IR2",
"Type": "StrengthReduction",
"Name": "Sub64",
"SubName": "BySame",
"Expression": "IR.Sub64 a a",
"Filter": "",
"Result": "0"
},
{
"FamilyName": "IR2",
"Type": "Simplification",
"Name": "LogicalNot32",
"SubName": "Twice",
"Expression": "IR.LogicalNot32 (IR.LogicalNot32 x)",
"Filter": "",
"Result": "x"
},
{
"FamilyName": "IR2",
"Type": "Simplification",
"Name": "LogicalNot64",
"SubName": "Twice",
"Expression": "IR.LogicalNot64 (IR.LogicalNot64 x)",
"Filter": "",
"Result": "x"
},
{
"FamilyName": "IR2",
"Type": "Rewrite",
"Name": "Add32",
"SubName": "MultipleWithCommon",
"Expression": "IR.Add32 (IR.MulUnsigned32 x y) (IR.MulUnsigned32 x z)",
"Filter": "",
"Result": "(IR.MulUnsigned32 x (IR.Add32 y z))"
},
{
"FamilyName": "IR2",
"Type": "Rewrite",
"Name": "Add64",
"SubName": "MultipleWithCommon",
"Expression": "IR.Add64 (IR.MulUnsigned64 x y) (IR.MulUnsigned64 x z)",
"Filter": "",
"Result": "(IR.MulUnsigned64 x (IR.Add64 y z))"
},
{
"FamilyName": "IR2",
"Type": "Rewrite",
"Name": "Sub32",
"SubName": "MultipleWithCommon",
"Expression": "IR.Add32 (IR.MulUnsigned32 x y) (IR.MulUnsigned32 x z)",
"Filter": "",
"Result": "(IR.MulUnsigned32 x (IR.Sub32 y z))"
},
{
"FamilyName": "IR2",
"Type": "Rewrite",
"Name": "Sub64",
"SubName": "MultipleWithCommon",
"Expression": "IR.Add64 (IR.MulUnsigned64 x y) (IR.MulUnsigned64 x z)",
"Filter": "",
"Result": "(IR.MulUnsigned64 x (IR.Sub64 y z))"
},
{
"FamilyName": "IR2",
"Type": "StrengthReduction",
"Name": "MulUnsigned32",
"SubName": "ByPowerOfTwo",
"Expression": "IR.MulUnsigned32 x c",
"Filter": "IsPowerOfTwo32(c)",
"Result": "(IR.ShiftLeft32 x [GetPowerOfTwo(c)])"
},
{
"FamilyName": "IR2",
"Type": "StrengthReduction",
"Name": "MulUnsigned64",
"SubName": "ByPowerOfTwo",
"Expression": "IR.MulUnsigned64 x c",
"Filter": "IsPowerOfTwo64(c)",
"Result": "(IR.ShiftLeft64 x [GetPowerOfTwo(c)])"
}
]
}
4 changes: 2 additions & 2 deletions Source/Mosa.Compiler.Common/BitTwiddling.cs
Expand Up @@ -11,9 +11,9 @@ public static bool IsPowerOfTwo(ulong n)
return (n & (n - 1)) == 0;
}

public static int GetPowerOfTwo(ulong n)
public static uint GetPowerOfTwo(ulong n)
{
int bits = 0;
uint bits = 0;
while (n != 0)
{
bits++;
Expand Down
Expand Up @@ -120,7 +120,7 @@ public override IEnumerable<int> GetKills(InstructionNode node)

public bool ContainsReference(Operand operand)
{
if (operand.Type.IsReferenceType || operand.Type.IsManagedPointer)
if (operand.IsReferenceType || operand.IsManagedPointer)
return true;

if (!operand.IsValueType)
Expand Down
Expand Up @@ -94,11 +94,11 @@ private void TraceNumberInstructions()
if (node.IsEmpty)
continue;

string log = node.Offset.ToString() + " = " + node;
string log = $"{node.Offset} = {node}";

if (node.IsBlockStartInstruction)
{
log = log + " # " + block;
log = $"{log} # {block}";
}

numberTrace.Log(log);
Expand Down
Expand Up @@ -47,7 +47,7 @@ public bool Contains(int index)

public override string ToString()
{
return "[" + Start + ", " + End + "]";
return $"[{Start}, {End}]";
}
}
}
Expand Up @@ -60,10 +60,10 @@ public SimpleFastDominance(BasicBlocks basicBlocks, BasicBlock entryBlock)
children = new List<BasicBlock>[blockCount];
blockToPostorderIndex = new int[blockCount];

// Blocks in reverse post order topology
reversePostOrder = BasicBlocks.ReversePostOrder(entryBlock);
// Blocks in reverse postorder
reversePostOrder = basicBlocks.ReversePostorder(entryBlock);

// Map block to reverse post order index
// Map block to reverse postorder index
int i = reversePostOrder.Count;
foreach (var block in reversePostOrder)
{
Expand Down
Expand Up @@ -110,7 +110,7 @@ public VariableState(Operand operand)
}
else if (operand.IsConstant && operand.IsInteger)
{
AddConstant(operand.ConstantUnsignedLongInteger);
AddConstant(operand.ConstantUnsigned64);
}
else if (operand.IsNull)
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Mosa.Compiler.Framework/BaseMethodCompilerStage.cs
Expand Up @@ -223,7 +223,7 @@ public void Setup(MethodCompiler methodCompiler, int position)

traceLogs = new List<TraceLog>();

FormattedStageName = "[" + position.ToString("00") + "] " + Name;
FormattedStageName = $"[{position.ToString("00")}] {Name}";

Setup();
}
Expand All @@ -247,7 +247,7 @@ public void Execute()
catch (Exception ex)
{
MethodCompiler.Stop();
PostCompilerTraceEvent(CompilerEvent.Exception, "Method: " + Method + " -> " + ex);
PostCompilerTraceEvent(CompilerEvent.Exception, $"Method: {Method} -> {ex}");
MethodCompiler.Compiler.Stop();
}

Expand Down
20 changes: 13 additions & 7 deletions Source/Mosa.Compiler.Framework/BasicBlocks.cs
Expand Up @@ -311,21 +311,27 @@ public BasicBlock GetExitBlock(BasicBlock start)
return null;
}

public static List<BasicBlock> ReversePostOrder(BasicBlock head)
public List<BasicBlock> ReversePostorder(BasicBlock head)
{
var array = new BitArray(Count, false);
var result = new List<BasicBlock>();
var workList = new Queue<BasicBlock>();
var worklist = new Queue<BasicBlock>();

workList.Enqueue(head);
worklist.Enqueue(head);

while (workList.Count != 0)
while (worklist.Count != 0)
{
var current = workList.Dequeue();
if (!result.Contains(current))
var current = worklist.Dequeue();

if (!array.Get(current.Sequence))
{
result.Add(current);
array.Set(current.Sequence, true);

foreach (var next in current.NextBlocks)
workList.Enqueue(next);
{
worklist.Enqueue(next);
}
}
}

Expand Down

0 comments on commit 0e61982

Please sign in to comment.