Skip to content

Commit ff084c7

Browse files
committed
Merge pull request #237 from tgiphil/master
Merging inline optimizations work in progress
2 parents 4fc4023 + d8f8445 commit ff084c7

File tree

14 files changed

+356
-219
lines changed

14 files changed

+356
-219
lines changed

Source/Mosa.Compiler.Framework/MosaCompiler.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ public void PreCompile()
110110

111111
public void ScheduleAll()
112112
{
113+
//HACK - for debugging
114+
// Mosa.Platform.Internal.x86.Runtime::GetProtectedRegionEntryByAddress
115+
//var type = TypeSystem.GetTypeByName("Mosa.Platform.Internal.x86", "Runtime");
116+
//var method = type.FindMethodByName("GetProtectedRegionEntryByAddress");
117+
//CompilationScheduler.Schedule(method);
118+
//ENDHACK
119+
113120
CompilationScheduler.ScheduleAll(TypeSystem);
114121
}
115122

Source/Mosa.Compiler.Framework/Stages/CodeGenerationStage.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,18 @@ protected virtual void BlockEnd(BasicBlock block)
191191
/// </summary>
192192
protected virtual void EndGenerate()
193193
{
194+
//HACK - for debugging
195+
// Mosa.Platform.Internal.x86.Runtime::GetProtectedRegionEntryByAddress
196+
//if (MethodCompiler.Method.FullName.Contains("Mosa.Platform.Internal.x86.Runtime::GetProtectedRegionEntryByAddress"))
197+
//{
198+
// codeStream.Position = codeStream.Length - 1;
199+
// while (codeStream.Length < 1024)
200+
// {
201+
// codeStream.WriteByte(0);
202+
// }
203+
//}
204+
//ENDHACK
205+
194206
codeEmitter.ResolvePatches();
195207
}
196208

Source/Mosa.Compiler.Framework/Stages/IROptimizationStage.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ private bool ContainsAddressOf(Operand local)
281281
private bool PromoteLocalVariable()
282282
{
283283
//HACK!!! HACK!!! HACK!!!
284-
if (MethodCompiler.Method.FullName.Contains(" Mosa.Platform.Internal.x86.Runtime::GetProtectedRegionEntryByAddress"))
285-
return false;
284+
//if (MethodCompiler.Method.FullName.Contains(" Mosa.Platform.Internal.x86.Runtime::GetProtectedRegionEntryByAddress"))
285+
// return false;
286286

287287
bool change = false;
288288

@@ -306,9 +306,6 @@ private bool PromoteLocalVariable()
306306
if (ContainsAddressOf(local))
307307
continue;
308308

309-
//if (local.Definitions.Count == 0 || local.Uses.Count == 0)
310-
// continue;
311-
312309
var v = MethodCompiler.CreateVirtualRegister(local.Type.GetStackType());
313310

314311
if (trace.Active) trace.Log("*** PromoteLocalVariable");

Source/Mosa.Compiler.Framework/Stages/PromoteTempVariablesStage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public sealed class PromoteTempVariablesStage : PromoteLocalVariablesStage
1717
protected override void Run()
1818
{
1919
//HACK!!! HACK!!! HACK!!!
20-
if (MethodCompiler.Method.FullName.Contains(" Mosa.Platform.Internal.x86.Runtime::GetProtectedRegionEntryByAddress"))
21-
return;
20+
//if (MethodCompiler.Method.FullName.Contains(" Mosa.Platform.Internal.x86.Runtime::GetProtectedRegionEntryByAddress"))
21+
// return;
2222

2323
if (!HasCode)
2424
return;

Source/Mosa.Platform.Internal.x86/Runtime.cs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public static void DebugOutput(uint code)
302302

303303
public static void DebugOutput(string msg)
304304
{
305-
for(int i = 0; i < msg.Length; i++)
305+
for (int i = 0; i < msg.Length; i++)
306306
{
307307
var c = msg[i];
308308
Native.Out8(0xEC, (byte)c);
@@ -395,6 +395,7 @@ public static void Fault(uint code)
395395
MetadataPRDefinitionStruct* protectedRegionDef = null;
396396
uint currentStart = uint.MinValue;
397397
uint currentEnd = uint.MaxValue;
398+
398399
while (entry < entries)
399400
{
400401
var prDef = MetadataPRTableStruct.GetProtectedRegionDefinitionAddress(protectedRegionTable, (uint)entry);
@@ -405,28 +406,16 @@ public static void Fault(uint code)
405406
if ((offset >= start) && (offset < end) && (start >= currentStart) && (end < currentEnd))
406407
{
407408
var handlerType = prDef->HandlerType;
408-
409-
// If the handler is a Finally clause, accept without testing
410-
if (handlerType == ExceptionHandlerType.Finally)
411-
{
412-
protectedRegionDef = prDef;
413-
currentStart = start;
414-
currentEnd = end;
415-
entry++;
416-
continue;
417-
}
418-
419409
var exType = prDef->ExceptionType;
420410

421-
// If the handler is a Exception clause, accept if the exception Type
422-
// is in the is within the inhertiance chain of the exception object
423-
if (handlerType == ExceptionHandlerType.Exception && IsTypeInInheritanceChain(exType, exceptionType))
411+
// If the handler is a finally clause, accept without testing
412+
// If the handler is a exception clause, accept if the exception type is in the is within the inhertiance chain of the exception object
413+
if ((handlerType == ExceptionHandlerType.Finally) ||
414+
(handlerType == ExceptionHandlerType.Exception && IsTypeInInheritanceChain(exType, exceptionType)))
424415
{
425416
protectedRegionDef = prDef;
426417
currentStart = start;
427418
currentEnd = end;
428-
entry++;
429-
continue;
430419
}
431420
}
432421

Source/Mosa.Test.Collection/SpecificTests.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ namespace Mosa.Test.Collection
1111
{
1212
public static class SpecificTests
1313
{
14+
public unsafe static void RefPointer(ref int* ptr)
15+
{
16+
ptr++;
17+
}
18+
1419
public static uint Test2(uint size)
1520
{
1621
uint first = 0xFFFFFFFF; // Marker
@@ -49,4 +54,4 @@ public static uint Test2(uint size)
4954
// return Double.IsPositiveInfinity(Double.NegativeInfinity);
5055
//}
5156
}
52-
}
57+
}

Source/Mosa.TinyCPUSimulator.Debug/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ private static void Main(string[] args)
5656
//Test4();
5757
//Test12();
5858

59-
//Test13();
59+
Test13();
6060

61-
Test14();
61+
//Test14();
6262
}
6363
catch (Exception e)
6464
{

Source/Mosa.TinyCPUSimulator.TestSystem/TestCompiler.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public class TestCompiler : ITraceListener
2929

3030
protected SimLinker linker;
3131

32+
protected const uint MaxTicks = 500000;
33+
3234
public TestCompiler(BaseTestPlatform platform)
3335
{
3436
this.platform = platform;
@@ -65,15 +67,27 @@ protected void CompileTestCode()
6567

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

70+
//compiler.Execute();
6871
compiler.Execute(Environment.ProcessorCount);
6972

7073
linker = compiler.Linker as SimLinker;
7174

75+
//DumpSymbols();
7276
//simAdapter.SimCPU.Monitor.DebugOutput = true; // DEBUG OPTION
7377

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

76-
//simAdapter.SimCPU.Monitor.DebugOutput = true; // DEBUG OPTION
80+
simAdapter.SimCPU.Monitor.DebugOutput = true; // DEBUG OPTION
81+
}
82+
83+
public void DumpSymbols()
84+
{
85+
var symbols = simAdapter.SimCPU.Symbols;
86+
87+
foreach (var symbol in symbols)
88+
{
89+
Debug.WriteLine(symbol.Value.ToString());
90+
}
7791
}
7892

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

108122
platform.PrepareToExecuteMethod(simAdapter, address, parameters);
109123

110-
simAdapter.SimCPU.Monitor.BreakAtTick = simAdapter.SimCPU.Monitor.BreakAtTick + 500000; // nothing should take this long
124+
simAdapter.SimCPU.Monitor.BreakAtTick = simAdapter.SimCPU.Monitor.BreakAtTick + MaxTicks; // nothing should take this long
111125
simAdapter.SimCPU.Execute();
112126

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

118132
if (runtimeMethod.Signature.ReturnType.IsVoid)
@@ -174,4 +188,4 @@ void ITraceListener.OnNewTraceLog(TraceLog traceLog)
174188
{
175189
}
176190
}
177-
}
191+
}

Source/Mosa.TinyCPUSimulator/SimSymbol.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class SimSymbol
1717

1818
public ulong Size { get; private set; }
1919

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

2222
public SimSymbol(string name, ulong address, ulong size)
2323
{
@@ -28,7 +28,7 @@ public SimSymbol(string name, ulong address, ulong size)
2828

2929
public override string ToString()
3030
{
31-
return "0x" + Address.ToString("X") + " " + Name;
31+
return "0x" + Address.ToString("X") + " - " + "0x" + EndAddress.ToString("X") + " " + Name + " (" + Size.ToString() + ")";
3232
}
3333
}
34-
}
34+
}

Source/Mosa.Tool.Explorer/Main.Designer.cs

Lines changed: 37 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)