Skip to content

Commit

Permalink
Merge pull request #237 from tgiphil/master
Browse files Browse the repository at this point in the history
Merging inline optimizations work in progress
  • Loading branch information
tgiphil committed Aug 2, 2015
2 parents 4fc4023 + d8f8445 commit ff084c7
Show file tree
Hide file tree
Showing 14 changed files with 356 additions and 219 deletions.
7 changes: 7 additions & 0 deletions Source/Mosa.Compiler.Framework/MosaCompiler.cs
Expand Up @@ -110,6 +110,13 @@ public void PreCompile()

public void ScheduleAll()
{
//HACK - for debugging
// Mosa.Platform.Internal.x86.Runtime::GetProtectedRegionEntryByAddress
//var type = TypeSystem.GetTypeByName("Mosa.Platform.Internal.x86", "Runtime");
//var method = type.FindMethodByName("GetProtectedRegionEntryByAddress");
//CompilationScheduler.Schedule(method);
//ENDHACK

CompilationScheduler.ScheduleAll(TypeSystem);
}

Expand Down
12 changes: 12 additions & 0 deletions Source/Mosa.Compiler.Framework/Stages/CodeGenerationStage.cs
Expand Up @@ -191,6 +191,18 @@ protected virtual void BlockEnd(BasicBlock block)
/// </summary>
protected virtual void EndGenerate()
{
//HACK - for debugging
// Mosa.Platform.Internal.x86.Runtime::GetProtectedRegionEntryByAddress
//if (MethodCompiler.Method.FullName.Contains("Mosa.Platform.Internal.x86.Runtime::GetProtectedRegionEntryByAddress"))
//{
// codeStream.Position = codeStream.Length - 1;
// while (codeStream.Length < 1024)
// {
// codeStream.WriteByte(0);
// }
//}
//ENDHACK

codeEmitter.ResolvePatches();
}

Expand Down
7 changes: 2 additions & 5 deletions Source/Mosa.Compiler.Framework/Stages/IROptimizationStage.cs
Expand Up @@ -281,8 +281,8 @@ private bool ContainsAddressOf(Operand local)
private bool PromoteLocalVariable()
{
//HACK!!! HACK!!! HACK!!!
if (MethodCompiler.Method.FullName.Contains(" Mosa.Platform.Internal.x86.Runtime::GetProtectedRegionEntryByAddress"))
return false;
//if (MethodCompiler.Method.FullName.Contains(" Mosa.Platform.Internal.x86.Runtime::GetProtectedRegionEntryByAddress"))
// return false;

bool change = false;

Expand All @@ -306,9 +306,6 @@ private bool PromoteLocalVariable()
if (ContainsAddressOf(local))
continue;

//if (local.Definitions.Count == 0 || local.Uses.Count == 0)
// continue;

var v = MethodCompiler.CreateVirtualRegister(local.Type.GetStackType());

if (trace.Active) trace.Log("*** PromoteLocalVariable");
Expand Down
Expand Up @@ -17,8 +17,8 @@ public sealed class PromoteTempVariablesStage : PromoteLocalVariablesStage
protected override void Run()
{
//HACK!!! HACK!!! HACK!!!
if (MethodCompiler.Method.FullName.Contains(" Mosa.Platform.Internal.x86.Runtime::GetProtectedRegionEntryByAddress"))
return;
//if (MethodCompiler.Method.FullName.Contains(" Mosa.Platform.Internal.x86.Runtime::GetProtectedRegionEntryByAddress"))
// return;

if (!HasCode)
return;
Expand Down
23 changes: 6 additions & 17 deletions Source/Mosa.Platform.Internal.x86/Runtime.cs
Expand Up @@ -302,7 +302,7 @@ public static void DebugOutput(uint code)

public static void DebugOutput(string msg)
{
for(int i = 0; i < msg.Length; i++)
for (int i = 0; i < msg.Length; i++)
{
var c = msg[i];
Native.Out8(0xEC, (byte)c);
Expand Down Expand Up @@ -395,6 +395,7 @@ public static void Fault(uint code)
MetadataPRDefinitionStruct* protectedRegionDef = null;
uint currentStart = uint.MinValue;
uint currentEnd = uint.MaxValue;

while (entry < entries)
{
var prDef = MetadataPRTableStruct.GetProtectedRegionDefinitionAddress(protectedRegionTable, (uint)entry);
Expand All @@ -405,28 +406,16 @@ public static void Fault(uint code)
if ((offset >= start) && (offset < end) && (start >= currentStart) && (end < currentEnd))
{
var handlerType = prDef->HandlerType;

// If the handler is a Finally clause, accept without testing
if (handlerType == ExceptionHandlerType.Finally)
{
protectedRegionDef = prDef;
currentStart = start;
currentEnd = end;
entry++;
continue;
}

var exType = prDef->ExceptionType;

// If the handler is a Exception clause, accept if the exception Type
// is in the is within the inhertiance chain of the exception object
if (handlerType == ExceptionHandlerType.Exception && IsTypeInInheritanceChain(exType, exceptionType))
// If the handler is a finally clause, accept without testing
// If the handler is a exception clause, accept if the exception type is in the is within the inhertiance chain of the exception object
if ((handlerType == ExceptionHandlerType.Finally) ||
(handlerType == ExceptionHandlerType.Exception && IsTypeInInheritanceChain(exType, exceptionType)))
{
protectedRegionDef = prDef;
currentStart = start;
currentEnd = end;
entry++;
continue;
}
}

Expand Down
7 changes: 6 additions & 1 deletion Source/Mosa.Test.Collection/SpecificTests.cs
Expand Up @@ -11,6 +11,11 @@ namespace Mosa.Test.Collection
{
public static class SpecificTests
{
public unsafe static void RefPointer(ref int* ptr)
{
ptr++;
}

public static uint Test2(uint size)
{
uint first = 0xFFFFFFFF; // Marker
Expand Down Expand Up @@ -49,4 +54,4 @@ public static uint Test2(uint size)
// return Double.IsPositiveInfinity(Double.NegativeInfinity);
//}
}
}
}
4 changes: 2 additions & 2 deletions Source/Mosa.TinyCPUSimulator.Debug/Program.cs
Expand Up @@ -56,9 +56,9 @@ private static void Main(string[] args)
//Test4();
//Test12();

//Test13();
Test13();

Test14();
//Test14();
}
catch (Exception e)
{
Expand Down
22 changes: 18 additions & 4 deletions Source/Mosa.TinyCPUSimulator.TestSystem/TestCompiler.cs
Expand Up @@ -29,6 +29,8 @@ public class TestCompiler : ITraceListener

protected SimLinker linker;

protected const uint MaxTicks = 500000;

public TestCompiler(BaseTestPlatform platform)
{
this.platform = platform;
Expand Down Expand Up @@ -65,15 +67,27 @@ protected void CompileTestCode()

compiler.Load(TypeSystem.Load(moduleLoader.CreateMetadata()));

//compiler.Execute();
compiler.Execute(Environment.ProcessorCount);

linker = compiler.Linker as SimLinker;

//DumpSymbols();
//simAdapter.SimCPU.Monitor.DebugOutput = true; // DEBUG OPTION

Run<int>(string.Empty, "Default", "AssemblyInit", true);

//simAdapter.SimCPU.Monitor.DebugOutput = true; // DEBUG OPTION
simAdapter.SimCPU.Monitor.DebugOutput = true; // DEBUG OPTION
}

public void DumpSymbols()
{
var symbols = simAdapter.SimCPU.Symbols;

foreach (var symbol in symbols)
{
Debug.WriteLine(symbol.Value.ToString());
}
}

public T Run<T>(string ns, string type, string method, params object[] parameters)
Expand Down Expand Up @@ -107,12 +121,12 @@ protected T Run<T>(string ns, string type, string method, bool reset, params obj

platform.PrepareToExecuteMethod(simAdapter, address, parameters);

simAdapter.SimCPU.Monitor.BreakAtTick = simAdapter.SimCPU.Monitor.BreakAtTick + 500000; // nothing should take this long
simAdapter.SimCPU.Monitor.BreakAtTick = simAdapter.SimCPU.Monitor.BreakAtTick + MaxTicks; // nothing should take this long
simAdapter.SimCPU.Execute();

if (simAdapter.SimCPU.Monitor.BreakAtTick == simAdapter.SimCPU.Tick)
{
throw new Exception("Aborted. Method did not complete under 500000 ticks. " + simAdapter.SimCPU.Tick.ToString());
throw new Exception("Aborted. Method did not complete under " + MaxTicks.ToString() + " ticks. " + simAdapter.SimCPU.Tick.ToString());
}

if (runtimeMethod.Signature.ReturnType.IsVoid)
Expand Down Expand Up @@ -174,4 +188,4 @@ void ITraceListener.OnNewTraceLog(TraceLog traceLog)
{
}
}
}
}
6 changes: 3 additions & 3 deletions Source/Mosa.TinyCPUSimulator/SimSymbol.cs
Expand Up @@ -17,7 +17,7 @@ public class SimSymbol

public ulong Size { get; private set; }

public ulong EndAddress { get { return Address + Size; } }
public ulong EndAddress { get { return Size == 0 ? Address : Address + Size - 1; } }

public SimSymbol(string name, ulong address, ulong size)
{
Expand All @@ -28,7 +28,7 @@ public SimSymbol(string name, ulong address, ulong size)

public override string ToString()
{
return "0x" + Address.ToString("X") + " " + Name;
return "0x" + Address.ToString("X") + " - " + "0x" + EndAddress.ToString("X") + " " + Name + " (" + Size.ToString() + ")";
}
}
}
}
48 changes: 37 additions & 11 deletions Source/Mosa.Tool.Explorer/Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ff084c7

Please sign in to comment.