From ed6d2eb63249368c2c77e0ce17ee54f74a32ccb5 Mon Sep 17 00:00:00 2001 From: Phil Date: Sat, 28 Oct 2023 10:14:53 -0700 Subject: [PATCH] - WIP (working) --- Source/Mosa.Compiler.Framework/Compiler.cs | 52 +++++-------------- .../Intrinsics/GetExceptionRegister.cs | 2 +- .../Intrinsics/GetStackFrame.cs | 2 +- .../Intrinsics/GetStackPointer.cs | 2 +- .../BaseRegisterAllocator.cs | 2 +- Source/Mosa.Compiler.Framework/Transform.cs | 16 +++--- .../Transforms/Call/BaseCallTransform.cs | 14 ++--- .../Transforms/Call/SetReturn32.cs | 2 +- .../Transforms/Call/SetReturn64.cs | 6 +-- .../Call/SetReturnManagedPointer.cs | 2 +- .../Transforms/Call/SetReturnObject.cs | 2 +- .../Transforms/Call/SetReturnR4.cs | 2 +- .../Transforms/Call/SetReturnR8.cs | 2 +- .../CompilerStages/MultibootStage.cs | 33 ++++++------ .../Intrinsic/AllocateStackSpace.cs | 2 +- .../Intrinsic/CmpXChgLoad64.cs | 2 +- .../Mosa.Compiler.x64/Intrinsic/CpuIdRAX.cs | 8 +-- .../Mosa.Compiler.x64/Intrinsic/CpuIdRBX.cs | 8 +-- .../Mosa.Compiler.x64/Intrinsic/CpuIdRCX.cs | 8 +-- .../Mosa.Compiler.x64/Intrinsic/CpuIdRDX.cs | 8 +-- .../Intrinsic/FrameCallRetR8.cs | 6 +-- .../Intrinsic/FrameCallRetU8.cs | 4 +- .../Mosa.Compiler.x64/Intrinsic/FrameJump.cs | 12 ++--- Source/Mosa.Compiler.x64/Intrinsic/GetCR0.cs | 2 +- Source/Mosa.Compiler.x64/Intrinsic/GetCR2.cs | 2 +- Source/Mosa.Compiler.x64/Intrinsic/GetCR3.cs | 2 +- Source/Mosa.Compiler.x64/Intrinsic/GetCR4.cs | 2 +- Source/Mosa.Compiler.x64/Intrinsic/GetCS.cs | 2 +- Source/Mosa.Compiler.x64/Intrinsic/GetFS.cs | 2 +- Source/Mosa.Compiler.x64/Intrinsic/IRQs.cs | 2 +- .../Intrinsic/InterruptReturn.cs | 2 +- .../Mosa.Compiler.x64/Intrinsic/Memclr256.cs | 2 +- Source/Mosa.Compiler.x64/Intrinsic/RdMSR.cs | 6 +-- Source/Mosa.Compiler.x64/Intrinsic/SetCR0.cs | 4 +- Source/Mosa.Compiler.x64/Intrinsic/SetCR2.cs | 4 +- Source/Mosa.Compiler.x64/Intrinsic/SetCR3.cs | 4 +- Source/Mosa.Compiler.x64/Intrinsic/SetCR4.cs | 4 +- Source/Mosa.Compiler.x64/Intrinsic/SetFS.cs | 2 +- .../Intrinsic/SetSegments.cs | 10 ++-- .../Transforms/FixedRegisters/Cdq32.cs | 4 +- .../Transforms/FixedRegisters/Cdq64.cs | 4 +- .../Transforms/FixedRegisters/Div32.cs | 4 +- .../Transforms/FixedRegisters/Div64.cs | 4 +- .../Transforms/FixedRegisters/IDiv32.cs | 4 +- .../Transforms/FixedRegisters/IDiv64.cs | 4 +- .../Transforms/FixedRegisters/In16.cs | 4 +- .../Transforms/FixedRegisters/In32.cs | 4 +- .../Transforms/FixedRegisters/In8.cs | 4 +- .../Transforms/FixedRegisters/Mul32.cs | 4 +- .../Transforms/FixedRegisters/Mul64.cs | 4 +- .../Transforms/FixedRegisters/Out16.cs | 4 +- .../Transforms/FixedRegisters/Out32.cs | 4 +- .../Transforms/FixedRegisters/Out8.cs | 4 +- .../Transforms/FixedRegisters/Rcr32.cs | 2 +- .../Transforms/FixedRegisters/Rcr64.cs | 2 +- .../Transforms/FixedRegisters/RdMSR.cs | 6 +-- .../Transforms/FixedRegisters/Sar32.cs | 2 +- .../Transforms/FixedRegisters/Sar64.cs | 2 +- .../Transforms/FixedRegisters/Shl32.cs | 2 +- .../Transforms/FixedRegisters/Shl64.cs | 2 +- .../Transforms/FixedRegisters/Shld32.cs | 2 +- .../Transforms/FixedRegisters/Shld64.cs | 2 +- .../Transforms/FixedRegisters/Shr32.cs | 2 +- .../Transforms/FixedRegisters/Shr64.cs | 2 +- .../Transforms/FixedRegisters/Shrd32.cs | 2 +- .../Transforms/FixedRegisters/Shrd64.cs | 2 +- .../Transforms/FixedRegisters/WrMSR.cs | 6 +-- .../Transforms/Tweak/MovStore16.cs | 8 +-- .../Transforms/Tweak/MovStore8.cs | 8 +-- .../Transforms/Tweak/Setcc.cs | 2 +- .../CompilerStages/MultibootStage.cs | 35 +++++++------ .../Intrinsic/AllocateStackSpace.cs | 2 +- .../Intrinsic/CmpXChgLoad32.cs | 2 +- .../Mosa.Compiler.x86/Intrinsic/CpuIdEax.cs | 8 +-- .../Mosa.Compiler.x86/Intrinsic/CpuIdEbx.cs | 8 +-- .../Mosa.Compiler.x86/Intrinsic/CpuIdEcx.cs | 8 +-- .../Mosa.Compiler.x86/Intrinsic/CpuIdEdx.cs | 8 +-- .../Intrinsic/FrameCallRetR8.cs | 6 +-- .../Intrinsic/FrameCallRetU4.cs | 2 +- .../Intrinsic/FrameCallRetU8.cs | 4 +- .../Mosa.Compiler.x86/Intrinsic/FrameJump.cs | 12 ++--- Source/Mosa.Compiler.x86/Intrinsic/GetCR0.cs | 2 +- Source/Mosa.Compiler.x86/Intrinsic/GetCR2.cs | 2 +- Source/Mosa.Compiler.x86/Intrinsic/GetCR3.cs | 2 +- Source/Mosa.Compiler.x86/Intrinsic/GetCR4.cs | 2 +- Source/Mosa.Compiler.x86/Intrinsic/GetCS.cs | 2 +- Source/Mosa.Compiler.x86/Intrinsic/GetFS.cs | 2 +- Source/Mosa.Compiler.x86/Intrinsic/IRQs.cs | 2 +- .../Intrinsic/InterruptReturn.cs | 2 +- .../Mosa.Compiler.x86/Intrinsic/Memclr256.cs | 2 +- Source/Mosa.Compiler.x86/Intrinsic/RdMSR.cs | 6 +-- Source/Mosa.Compiler.x86/Intrinsic/SetCR0.cs | 4 +- Source/Mosa.Compiler.x86/Intrinsic/SetCR2.cs | 4 +- Source/Mosa.Compiler.x86/Intrinsic/SetCR3.cs | 4 +- Source/Mosa.Compiler.x86/Intrinsic/SetCR4.cs | 4 +- Source/Mosa.Compiler.x86/Intrinsic/SetFS.cs | 2 +- .../Intrinsic/SetSegments.cs | 10 ++-- .../Transforms/FixedRegisters/Cdq32.cs | 4 +- .../Transforms/FixedRegisters/Div32.cs | 4 +- .../Transforms/FixedRegisters/IDiv32.cs | 4 +- .../Transforms/FixedRegisters/IMul32o1.cs | 4 +- .../Transforms/FixedRegisters/In16.cs | 4 +- .../Transforms/FixedRegisters/In32.cs | 4 +- .../Transforms/FixedRegisters/In8.cs | 4 +- .../Transforms/FixedRegisters/Mul32.cs | 4 +- .../Transforms/FixedRegisters/Out16.cs | 4 +- .../Transforms/FixedRegisters/Out32.cs | 4 +- .../Transforms/FixedRegisters/Out8.cs | 4 +- .../Transforms/FixedRegisters/Rcr32.cs | 2 +- .../Transforms/FixedRegisters/RdMSR.cs | 6 +-- .../Transforms/FixedRegisters/Sar32.cs | 2 +- .../Transforms/FixedRegisters/Shl32.cs | 2 +- .../Transforms/FixedRegisters/Shld32.cs | 2 +- .../Transforms/FixedRegisters/Shr32.cs | 2 +- .../Transforms/FixedRegisters/Shrd32.cs | 2 +- .../Transforms/FixedRegisters/WrMSR.cs | 6 +-- .../Transforms/IR/ShiftRight64.cs | 2 +- .../Transforms/Tweak/MovStore16.cs | 8 +-- .../Transforms/Tweak/MovStore8.cs | 8 +-- .../Transforms/Tweak/Movsx16To32.cs | 2 +- .../Transforms/Tweak/Movsx8To32.cs | 2 +- .../Transforms/Tweak/Setcc.cs | 2 +- 122 files changed, 292 insertions(+), 306 deletions(-) diff --git a/Source/Mosa.Compiler.Framework/Compiler.cs b/Source/Mosa.Compiler.Framework/Compiler.cs index 92c22fdd98..7fbaf99d19 100644 --- a/Source/Mosa.Compiler.Framework/Compiler.cs +++ b/Source/Mosa.Compiler.Framework/Compiler.cs @@ -101,36 +101,6 @@ public sealed class Compiler /// public bool IsStopped { get; private set; } - /// - /// The stack frame - /// - public Operand StackFrame { get; } - - /// - /// The stack frame - /// - public Operand StackPointer { get; } - - /// - /// The program counter - /// - internal Operand ProgramCounter { get; } - - /// - /// The link register - /// - internal Operand LinkRegister { get; } - - /// - /// The exception register - /// - public Operand ExceptionRegister { get; } - - /// - /// The ;eave target register - /// - public Operand LeaveTargetRegister { get; } - public CompilerHooks CompilerHooks { get; } public int TraceLevel { get; } @@ -245,14 +215,6 @@ public Compiler(MosaCompiler mosaCompiler) ObjectHeaderSize = Architecture.NativePointerSize + 4 + 4; // Hash Value (32-bit) + Lock & Status (32-bit) + Method Table - StackFrame = Operand.CreateCPURegisterNativeInteger(Architecture.StackFrameRegister, Architecture.Is32BitPlatform); - StackPointer = Operand.CreateCPURegisterNativeInteger(Architecture.StackPointerRegister, Architecture.Is32BitPlatform); - ExceptionRegister = Operand.CreateCPURegisterObject(Architecture.ExceptionRegister); - LeaveTargetRegister = Operand.CreateCPURegisterNativeInteger(Architecture.LeaveTargetRegister, Architecture.Is32BitPlatform); - - LinkRegister = Architecture.LinkRegister == null ? null : Operand.CreateCPURegisterNativeInteger(Architecture.LinkRegister, Architecture.Is32BitPlatform); - ProgramCounter = Architecture.ProgramCounter == null ? null : Operand.CreateCPURegisterNativeInteger(Architecture.ProgramCounter, Architecture.Is32BitPlatform); - MethodStagePipelines = new Pipeline[MaxThreads]; MethodScheduler = new MethodScheduler(this); @@ -335,6 +297,20 @@ public void CompileMethod(MosaMethod method, BasicBlocks basicBlocks, int thread CompilerHooks.NotifyMethodCompiled?.Invoke(method); } + public void CompileMethod(Transform transform) + { + PostEvent(CompilerEvent.MethodCompileStart, transform.Method.FullName, transform.MethodCompiler.ThreadID); + + var pipeline = GetOrCreateMethodStagePipeline(transform.MethodCompiler.ThreadID); + + transform.MethodCompiler.Pipeline = pipeline; + transform.MethodCompiler.Compile(); + + PostEvent(CompilerEvent.MethodCompileEnd, transform.Method.FullName, transform.MethodCompiler.ThreadID); + + CompilerHooks.NotifyMethodCompiled?.Invoke(transform.Method); + } + private Pipeline GetOrCreateMethodStagePipeline(int threadID) { var pipeline = MethodStagePipelines[threadID]; diff --git a/Source/Mosa.Compiler.Framework/Intrinsics/GetExceptionRegister.cs b/Source/Mosa.Compiler.Framework/Intrinsics/GetExceptionRegister.cs index 50c4900e8d..1e67e01d73 100644 --- a/Source/Mosa.Compiler.Framework/Intrinsics/GetExceptionRegister.cs +++ b/Source/Mosa.Compiler.Framework/Intrinsics/GetExceptionRegister.cs @@ -10,6 +10,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Runtime.Intrinsic::GetExceptionRegister")] private static void GetExceptionRegister(Context context, Transform transform) { - context.SetInstruction(transform.MoveInstruction, context.Result, transform.Compiler.ExceptionRegister); + context.SetInstruction(transform.MoveInstruction, context.Result, transform.ExceptionRegister); } } diff --git a/Source/Mosa.Compiler.Framework/Intrinsics/GetStackFrame.cs b/Source/Mosa.Compiler.Framework/Intrinsics/GetStackFrame.cs index da8525e402..3efc69a90b 100644 --- a/Source/Mosa.Compiler.Framework/Intrinsics/GetStackFrame.cs +++ b/Source/Mosa.Compiler.Framework/Intrinsics/GetStackFrame.cs @@ -10,6 +10,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Runtime.Intrinsic::GetStackFrame")] private static void GetStackFrame(Context context, Transform transform) { - context.SetInstruction(transform.MoveInstruction, context.Result, transform.Compiler.StackFrame); + context.SetInstruction(transform.MoveInstruction, context.Result, transform.StackFrame); } } diff --git a/Source/Mosa.Compiler.Framework/Intrinsics/GetStackPointer.cs b/Source/Mosa.Compiler.Framework/Intrinsics/GetStackPointer.cs index 1df309ba2b..5ae1591010 100644 --- a/Source/Mosa.Compiler.Framework/Intrinsics/GetStackPointer.cs +++ b/Source/Mosa.Compiler.Framework/Intrinsics/GetStackPointer.cs @@ -10,6 +10,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Runtime.Intrinsic::GetStackPointer")] private static void GetStackPointer(Context context, Transform transform) { - context.SetInstruction(transform.MoveInstruction, context.Result, transform.Compiler.StackPointer); + context.SetInstruction(transform.MoveInstruction, context.Result, transform.StackPointer); } } diff --git a/Source/Mosa.Compiler.Framework/RegisterAllocator/BaseRegisterAllocator.cs b/Source/Mosa.Compiler.Framework/RegisterAllocator/BaseRegisterAllocator.cs index fcec15ada9..9bd8293b83 100644 --- a/Source/Mosa.Compiler.Framework/RegisterAllocator/BaseRegisterAllocator.cs +++ b/Source/Mosa.Compiler.Framework/RegisterAllocator/BaseRegisterAllocator.cs @@ -1420,7 +1420,7 @@ protected void CreatePhysicalRegisterOperands() if (liveInterval.AssignedPhysicalRegister == null) continue; - liveInterval.AssignedPhysicalOperand = Operand.CreateCPURegister(liveInterval.Register.RegisterOperand, liveInterval.AssignedPhysicalRegister); + liveInterval.AssignedPhysicalOperand = Transform.PhysicalRegisters.Allocate(liveInterval.Register.RegisterOperand, liveInterval.AssignedPhysicalRegister); } } } diff --git a/Source/Mosa.Compiler.Framework/Transform.cs b/Source/Mosa.Compiler.Framework/Transform.cs index edf46de4a0..3c1f6407a7 100644 --- a/Source/Mosa.Compiler.Framework/Transform.cs +++ b/Source/Mosa.Compiler.Framework/Transform.cs @@ -26,6 +26,8 @@ public sealed class Transform public VirtualRegisters VirtualRegisters { get; private set; } + public PhysicalRegisters PhysicalRegisters { get; private set; } + public LocalStack LocalStack { get; set; } public BasicBlocks BasicBlocks { get; set; } @@ -68,29 +70,29 @@ public sealed class Transform #region Properties - Registers - public Operand StackFrame => MethodCompiler.Compiler.StackFrame; + public Operand StackFrame => MethodCompiler.StackFrame; - public Operand StackPointer => MethodCompiler.Compiler.StackPointer; + public Operand StackPointer => MethodCompiler.StackPointer; /// /// Gets the link register. /// - public Operand LinkRegister => MethodCompiler.Compiler.LinkRegister; + public Operand LinkRegister => MethodCompiler.LinkRegister; /// /// Gets the program counter /// - public Operand ProgramCounter => MethodCompiler.Compiler.ProgramCounter; + public Operand ProgramCounter => MethodCompiler.ProgramCounter; /// /// Gets the exception register. /// - public Operand ExceptionRegister => MethodCompiler.Compiler.ExceptionRegister; + public Operand ExceptionRegister => MethodCompiler.ExceptionRegister; /// /// Gets the leave target register. /// - public Operand LeaveTargetRegister => MethodCompiler.Compiler.LeaveTargetRegister; + public Operand LeaveTargetRegister => MethodCompiler.LeaveTargetRegister; #endregion Properties - Registers @@ -149,6 +151,7 @@ public void SetCompiler(Compiler compiler) // clear - just in case MethodCompiler = null; VirtualRegisters = null; + PhysicalRegisters = null; LocalStack = null; BasicBlocks = null; } @@ -157,6 +160,7 @@ public void SetMethodCompiler(MethodCompiler methodCompiler) { MethodCompiler = methodCompiler; VirtualRegisters = methodCompiler.VirtualRegisters; + PhysicalRegisters = methodCompiler.PhysicalRegisters; LocalStack = methodCompiler.LocalStack; BasicBlocks = methodCompiler.BasicBlocks; AreCPURegistersAllocated = methodCompiler.AreCPURegistersAllocated; diff --git a/Source/Mosa.Compiler.Framework/Transforms/Call/BaseCallTransform.cs b/Source/Mosa.Compiler.Framework/Transforms/Call/BaseCallTransform.cs index 87282916f1..a45613974c 100644 --- a/Source/Mosa.Compiler.Framework/Transforms/Call/BaseCallTransform.cs +++ b/Source/Mosa.Compiler.Framework/Transforms/Call/BaseCallTransform.cs @@ -106,14 +106,14 @@ private static void GetReturnValue(Transform transform, Context context, Operand if (result.IsObject) { - var returnLow = Operand.CreateCPURegisterObject(transform.Architecture.ReturnRegister); + var returnLow = transform.PhysicalRegisters.AllocateObject(transform.Architecture.ReturnRegister); context.AppendInstruction(IRInstruction.Gen, returnLow); context.AppendInstruction(IRInstruction.MoveObject, result, returnLow); } else if (result.IsInt64 && transform.Is32BitPlatform) { - var returnLow = Operand.CreateCPURegister32(transform.Architecture.ReturnRegister); - var returnHigh = Operand.CreateCPURegister32(transform.Architecture.ReturnHighRegister); + var returnLow = transform.PhysicalRegisters.Allocate32(transform.Architecture.ReturnRegister); + var returnHigh = transform.PhysicalRegisters.Allocate32(transform.Architecture.ReturnHighRegister); context.AppendInstruction(IRInstruction.Gen, returnLow); context.AppendInstruction(IRInstruction.Gen, returnHigh); @@ -121,19 +121,19 @@ private static void GetReturnValue(Transform transform, Context context, Operand } else if (result.IsInteger) { - var returnLow = Operand.CreateCPURegister(result, transform.Architecture.ReturnRegister); + var returnLow = transform.PhysicalRegisters.Allocate(result, transform.Architecture.ReturnRegister); context.AppendInstruction(IRInstruction.Gen, returnLow); context.AppendInstruction(transform.MoveInstruction, result, returnLow); } else if (result.IsR4) { - var returnFP = Operand.CreateCPURegisterR4(transform.Architecture.ReturnFloatingPointRegister); + var returnFP = transform.PhysicalRegisters.AllocateR4(transform.Architecture.ReturnFloatingPointRegister); context.AppendInstruction(IRInstruction.Gen, returnFP); context.AppendInstruction(IRInstruction.MoveR4, result, returnFP); } else if (result.IsR8) { - var returnFP = Operand.CreateCPURegisterR8(transform.Architecture.ReturnFloatingPointRegister); + var returnFP = transform.PhysicalRegisters.AllocateR8(transform.Architecture.ReturnFloatingPointRegister); context.AppendInstruction(IRInstruction.Gen, returnFP); context.AppendInstruction(IRInstruction.MoveR8, result, returnFP); } @@ -143,7 +143,7 @@ private static void GetReturnValue(Transform transform, Context context, Operand } else { - var returnLow = Operand.CreateCPURegister(result, transform.Architecture.ReturnRegister); + var returnLow = transform.PhysicalRegisters.Allocate(result, transform.Architecture.ReturnRegister); context.AppendInstruction(IRInstruction.Gen, returnLow); context.AppendInstruction(transform.MoveInstruction, result, returnLow); } diff --git a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturn32.cs b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturn32.cs index 2202931518..e81b4a2570 100644 --- a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturn32.cs +++ b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturn32.cs @@ -18,6 +18,6 @@ public override bool Match(Context context, Transform transform) public override void Transform(Context context, Transform transform) { - context.SetInstruction(IRInstruction.Move32, Operand.CreateCPURegister32(transform.Architecture.ReturnRegister), context.Operand1); + context.SetInstruction(IRInstruction.Move32, transform.PhysicalRegisters.Allocate32(transform.Architecture.ReturnRegister), context.Operand1); } } diff --git a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturn64.cs b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturn64.cs index a9027d5b6f..e9f6304b00 100644 --- a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturn64.cs +++ b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturn64.cs @@ -22,12 +22,12 @@ public override void Transform(Context context, Transform transform) if (transform.Is32BitPlatform) { - context.SetInstruction(IRInstruction.GetLow32, Operand.CreateCPURegister32(transform.Architecture.ReturnRegister), operand); - context.AppendInstruction(IRInstruction.GetHigh32, Operand.CreateCPURegister32(transform.Architecture.ReturnHighRegister), operand); + context.SetInstruction(IRInstruction.GetLow32, transform.PhysicalRegisters.Allocate32(transform.Architecture.ReturnRegister), operand); + context.AppendInstruction(IRInstruction.GetHigh32, transform.PhysicalRegisters.Allocate32(transform.Architecture.ReturnHighRegister), operand); } else { - context.SetInstruction(IRInstruction.Move64, Operand.CreateCPURegister64(transform.Architecture.ReturnRegister), context.Operand1); + context.SetInstruction(IRInstruction.Move64, transform.PhysicalRegisters.Allocate64(transform.Architecture.ReturnRegister), context.Operand1); } } } diff --git a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnManagedPointer.cs b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnManagedPointer.cs index f43c86b5d5..a1336702d8 100644 --- a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnManagedPointer.cs +++ b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnManagedPointer.cs @@ -18,6 +18,6 @@ public override bool Match(Context context, Transform transform) public override void Transform(Context context, Transform transform) { - context.SetInstruction(IRInstruction.MoveManagedPointer, Operand.CreateCPURegisterObject(transform.Architecture.ReturnRegister), context.Operand1); + context.SetInstruction(IRInstruction.MoveManagedPointer, transform.PhysicalRegisters.AllocateObject(transform.Architecture.ReturnRegister), context.Operand1); } } diff --git a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnObject.cs b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnObject.cs index 885e56cc3f..c610a23f75 100644 --- a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnObject.cs +++ b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnObject.cs @@ -18,6 +18,6 @@ public override bool Match(Context context, Transform transform) public override void Transform(Context context, Transform transform) { - context.SetInstruction(IRInstruction.MoveObject, Operand.CreateCPURegisterObject(transform.Architecture.ReturnRegister), context.Operand1); + context.SetInstruction(IRInstruction.MoveObject, transform.PhysicalRegisters.AllocateObject(transform.Architecture.ReturnRegister), context.Operand1); } } diff --git a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnR4.cs b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnR4.cs index 95fb272e19..ae6c328419 100644 --- a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnR4.cs +++ b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnR4.cs @@ -18,6 +18,6 @@ public override bool Match(Context context, Transform transform) public override void Transform(Context context, Transform transform) { - context.SetInstruction(IRInstruction.MoveR4, Operand.CreateCPURegisterR4(transform.Architecture.ReturnFloatingPointRegister), context.Operand1); + context.SetInstruction(IRInstruction.MoveR4, transform.PhysicalRegisters.AllocateR4(transform.Architecture.ReturnFloatingPointRegister), context.Operand1); } } diff --git a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnR8.cs b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnR8.cs index 849540e517..e7fa699e58 100644 --- a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnR8.cs +++ b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnR8.cs @@ -18,6 +18,6 @@ public override bool Match(Context context, Transform transform) public override void Transform(Context context, Transform transform) { - context.SetInstruction(IRInstruction.MoveR8, Operand.CreateCPURegisterR8(transform.Architecture.ReturnFloatingPointRegister), context.Operand1); + context.SetInstruction(IRInstruction.MoveR8, transform.PhysicalRegisters.AllocateR8(transform.Architecture.ReturnFloatingPointRegister), context.Operand1); } } diff --git a/Source/Mosa.Compiler.x64/CompilerStages/MultibootStage.cs b/Source/Mosa.Compiler.x64/CompilerStages/MultibootStage.cs index 9747a88c17..d9b7087bbf 100644 --- a/Source/Mosa.Compiler.x64/CompilerStages/MultibootStage.cs +++ b/Source/Mosa.Compiler.x64/CompilerStages/MultibootStage.cs @@ -15,27 +15,30 @@ protected override void Finalization() private void CreateMultibootMethod() { + var basicBlocks = new BasicBlocks(); + + var methodCompiler = new MethodCompiler(Compiler, multibootMethod, basicBlocks, 0); + methodCompiler.MethodData.DoNotInline = true; + + var transform = new Transform(); + transform.SetCompiler(Compiler); + transform.SetMethodCompiler(methodCompiler); + var startUpType = TypeSystem.GetTypeByName("Mosa.Runtime.StartUp"); var initializeMethod = startUpType.FindMethodByName("Initialize"); - Compiler.GetMethodData(initializeMethod).DoNotInline = true; - var entryPoint = Operand.CreateLabel(initializeMethod, Architecture.Is32BitPlatform); - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rbx = Operand.CreateCPURegister64(CPURegister.RBX); - var rbp = Operand.CreateCPURegister64(CPURegister.RBP); - var rsp = Operand.CreateCPURegister64(CPURegister.RSP); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rbx = transform.PhysicalRegisters.Allocate64(CPURegister.RBX); + var rbp = transform.PhysicalRegisters.Allocate64(CPURegister.RBP); + var rsp = transform.PhysicalRegisters.Allocate64(CPURegister.RSP); var multibootEAX = Operand.CreateLabel(MultibootEAX, Architecture.Is32BitPlatform); var multibootEBX = Operand.CreateLabel(MultibootEBX, Architecture.Is32BitPlatform); var stackBottom = Operand.CreateLabel(MultibootInitialStack, Architecture.Is32BitPlatform); - var stackTopOffset = CreateConstant(StackSize - 8); - var zero = CreateConstant(0); - var offset = CreateConstant(8); - - var basicBlocks = new BasicBlocks(); + var stackTopOffset = CreateConstant(StackSize - 16); var prologueBlock = basicBlocks.CreatePrologueBlock(); @@ -46,12 +49,12 @@ private void CreateMultibootMethod() context.AppendInstruction(X64.Add64, rsp, rsp, stackTopOffset); context.AppendInstruction(X64.Mov64, rbp, stackBottom); context.AppendInstruction(X64.Add64, rbp, rbp, stackTopOffset); - context.AppendInstruction(X64.MovStore64, null, rsp, zero, zero); - context.AppendInstruction(X64.MovStore64, null, rsp, offset, zero); + context.AppendInstruction(X64.MovStore64, null, rsp, Operand.Constant64_0, Operand.Constant64_0); + context.AppendInstruction(X64.MovStore64, null, rsp, Operand.Constant64_16, Operand.Constant64_0); // Place the multiboot address into a static field - context.AppendInstruction(X64.MovStore64, null, multibootEAX, zero, rax); - context.AppendInstruction(X64.MovStore64, null, multibootEBX, zero, rbx); + context.AppendInstruction(X64.MovStore64, null, multibootEAX, Operand.Constant64_0, rax); + context.AppendInstruction(X64.MovStore64, null, multibootEBX, Operand.Constant64_0, rbx); context.AppendInstruction(X64.Call, null, entryPoint); context.AppendInstruction(X64.Ret); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/AllocateStackSpace.cs b/Source/Mosa.Compiler.x64/Intrinsic/AllocateStackSpace.cs index 1660fefa1b..989d9fb47f 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/AllocateStackSpace.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/AllocateStackSpace.cs @@ -15,7 +15,7 @@ private static void AllocateStackSpace(Context context, Transform transform) Operand result = context.Result; Operand size = context.Operand1; - Operand esp = Operand.CreateCPURegister64(CPURegister.RSP); + Operand esp = transform.PhysicalRegisters.Allocate64(CPURegister.RSP); context.SetInstruction(X64.Sub64, esp, esp, size); context.AppendInstruction(X64.Mov64, result, esp); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/CmpXChgLoad64.cs b/Source/Mosa.Compiler.x64/Intrinsic/CmpXChgLoad64.cs index 8accf835fd..ff3566fc9d 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/CmpXChgLoad64.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/CmpXChgLoad64.cs @@ -17,7 +17,7 @@ private static void CmpXChgLoad64(Context context, Transform transform) var comparand = context.Operand3; var result = context.Result; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); var v1 = transform.VirtualRegisters.Allocate64(); context.SetInstruction(X64.Mov64, rax, comparand); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRAX.cs b/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRAX.cs index f3b5d5b675..8491ed5865 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRAX.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRAX.cs @@ -16,10 +16,10 @@ private static void CpuIdRAX(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rbx = Operand.CreateCPURegister64(CPURegister.RBX); - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rbx = transform.PhysicalRegisters.Allocate64(CPURegister.RBX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); context.SetInstruction(X64.Mov64, rax, operand1); context.AppendInstruction(X64.Mov64, rcx, operand2); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRBX.cs b/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRBX.cs index 92515f0eb0..b23068fe45 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRBX.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRBX.cs @@ -16,10 +16,10 @@ private static void CpuIdRBX(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rbx = Operand.CreateCPURegister64(CPURegister.RBX); - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rbx = transform.PhysicalRegisters.Allocate64(CPURegister.RBX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); context.SetInstruction(X64.Mov64, rax, operand1); context.AppendInstruction(X64.Mov64, rcx, operand2); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRCX.cs b/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRCX.cs index a1eb6ee983..68f8979728 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRCX.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRCX.cs @@ -16,10 +16,10 @@ private static void CpuIdRCX(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rbx = Operand.CreateCPURegister64(CPURegister.RBX); - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rbx = transform.PhysicalRegisters.Allocate64(CPURegister.RBX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); context.SetInstruction(X64.Mov64, rax, operand1); context.AppendInstruction(X64.Mov64, rcx, operand2); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRDX.cs b/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRDX.cs index 439cf29bdb..992fd4a3e6 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRDX.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRDX.cs @@ -16,10 +16,10 @@ private static void CpuIdRDX(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rbx = Operand.CreateCPURegister64(CPURegister.RBX); - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rbx = transform.PhysicalRegisters.Allocate64(CPURegister.RBX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); context.SetInstruction(X64.Mov64, rax, operand1); context.AppendInstruction(X64.Mov64, rcx, operand2); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/FrameCallRetR8.cs b/Source/Mosa.Compiler.x64/Intrinsic/FrameCallRetR8.cs index 3888b99f4c..c5c56e345f 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/FrameCallRetR8.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/FrameCallRetR8.cs @@ -15,9 +15,9 @@ private static void FrameCallRetR8(Context context, Transform transform) var result = context.Result; var methodAddress = context.Operand1; - var eax = Operand.CreateCPURegister64(CPURegister.RAX); - var edx = Operand.CreateCPURegister64(CPURegister.RDX); - var xmm0 = Operand.CreateCPURegister64(CPURegister.XMM0); + var eax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var edx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); + var xmm0 = transform.PhysicalRegisters.Allocate64(CPURegister.XMM0); transform.SplitOperand(result, out Operand op0L, out Operand op0H); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/FrameCallRetU8.cs b/Source/Mosa.Compiler.x64/Intrinsic/FrameCallRetU8.cs index c9d75d0050..9754923934 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/FrameCallRetU8.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/FrameCallRetU8.cs @@ -15,8 +15,8 @@ private static void FrameCallRetU8(Context context, Transform transform) var result = context.Result; var methodAddress = context.Operand1; - var eax = Operand.CreateCPURegister64(CPURegister.RAX); - var edx = Operand.CreateCPURegister64(CPURegister.RDX); + var eax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var edx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); transform.SplitOperand(result, out Operand op0L, out Operand op0H); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/FrameJump.cs b/Source/Mosa.Compiler.x64/Intrinsic/FrameJump.cs index af30ffdbf9..67c25ec59a 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/FrameJump.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/FrameJump.cs @@ -17,18 +17,18 @@ private static void FrameJump(Context context, Transform transform) var v2 = context.Operand3; var v3 = context.Operand4; - var rsp = Operand.CreateCPURegister64(CPURegister.RSP); - var rbp = Operand.CreateCPURegister64(CPURegister.RBP); + var rsp = transform.PhysicalRegisters.Allocate64(CPURegister.RSP); + var rbp = transform.PhysicalRegisters.Allocate64(CPURegister.RBP); - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rbx = Operand.CreateCPURegister64(CPURegister.RBX); - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rbx = transform.PhysicalRegisters.Allocate64(CPURegister.RBX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); // Move all virtual registers into physical registers - necessary since stack frame pointer will change context.SetInstruction(X64.Mov64, rax, v0); context.AppendInstruction(X64.Mov64, rbx, v1); context.AppendInstruction(X64.Mov64, rcx, v2); - context.AppendInstruction(X64.Mov64, transform.Compiler.ExceptionRegister, v3); + context.AppendInstruction(X64.Mov64, transform.ExceptionRegister, v3); // Update the frame and stack registers context.AppendInstruction(X64.Mov64, rbp, rcx); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/GetCR0.cs b/Source/Mosa.Compiler.x64/Intrinsic/GetCR0.cs index f520dbc1f2..00a53317f7 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/GetCR0.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/GetCR0.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x64.Intrinsic::GetCR0")] private static void GetCR0(Context context, Transform transform) { - context.SetInstruction(X64.MovCRLoad64, context.Result, Operand.CreateCPURegister64(CPURegister.CR0)); + context.SetInstruction(X64.MovCRLoad64, context.Result, transform.PhysicalRegisters.Allocate64(CPURegister.CR0)); } } diff --git a/Source/Mosa.Compiler.x64/Intrinsic/GetCR2.cs b/Source/Mosa.Compiler.x64/Intrinsic/GetCR2.cs index 0dfe76361b..3026e4a169 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/GetCR2.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/GetCR2.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x64.Intrinsic::GetCR2")] private static void GetCR2(Context context, Transform transform) { - context.SetInstruction(X64.MovCRLoad64, context.Result, Operand.CreateCPURegister64(CPURegister.CR2)); + context.SetInstruction(X64.MovCRLoad64, context.Result, transform.PhysicalRegisters.Allocate64(CPURegister.CR2)); } } diff --git a/Source/Mosa.Compiler.x64/Intrinsic/GetCR3.cs b/Source/Mosa.Compiler.x64/Intrinsic/GetCR3.cs index 069e2f78a1..22a2686ff7 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/GetCR3.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/GetCR3.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x64.Intrinsic::GetCR3")] private static void GetCR3(Context context, Transform transform) { - context.SetInstruction(X64.MovCRLoad64, context.Result, Operand.CreateCPURegister64(CPURegister.CR3)); + context.SetInstruction(X64.MovCRLoad64, context.Result, transform.PhysicalRegisters.Allocate64(CPURegister.CR3)); } } diff --git a/Source/Mosa.Compiler.x64/Intrinsic/GetCR4.cs b/Source/Mosa.Compiler.x64/Intrinsic/GetCR4.cs index 0843f5eed8..8b8f8efafb 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/GetCR4.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/GetCR4.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x64.Intrinsic::GetCR4")] private static void GetCR4(Context context, Transform transform) { - context.SetInstruction(X64.MovCRLoad64, context.Result, Operand.CreateCPURegister64(CPURegister.CR4)); + context.SetInstruction(X64.MovCRLoad64, context.Result, transform.PhysicalRegisters.Allocate64(CPURegister.CR4)); } } diff --git a/Source/Mosa.Compiler.x64/Intrinsic/GetCS.cs b/Source/Mosa.Compiler.x64/Intrinsic/GetCS.cs index adb190cab5..55a3781305 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/GetCS.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/GetCS.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x64.Intrinsic::GetCS")] private static void GetCS(Context context, Transform transform) { - context.SetInstruction(X64.MovLoadSeg64, context.Result, Operand.CreateCPURegister64(CPURegister.CS)); + context.SetInstruction(X64.MovLoadSeg64, context.Result, transform.PhysicalRegisters.Allocate64(CPURegister.CS)); } } diff --git a/Source/Mosa.Compiler.x64/Intrinsic/GetFS.cs b/Source/Mosa.Compiler.x64/Intrinsic/GetFS.cs index df0df7d063..efc79c3130 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/GetFS.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/GetFS.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x64.Intrinsic::GetFS")] private static void GetFS(Context context, Transform transform) { - context.SetInstruction(X64.MovLoadSeg64, context.Result, Operand.CreateCPURegister64(CPURegister.FS)); + context.SetInstruction(X64.MovLoadSeg64, context.Result, transform.PhysicalRegisters.Allocate64(CPURegister.FS)); } } diff --git a/Source/Mosa.Compiler.x64/Intrinsic/IRQs.cs b/Source/Mosa.Compiler.x64/Intrinsic/IRQs.cs index 84e8e25f1d..3d877dd568 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/IRQs.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/IRQs.cs @@ -42,7 +42,7 @@ private static void InsertIRQ(int irq, Context context, Transform transform) var interrupt = Operand.CreateLabel(method, transform.Is32BitPlatform); - var esp = Operand.CreateCPURegister32(CPURegister.RSP); + var esp = transform.PhysicalRegisters.Allocate32(CPURegister.RSP); context.SetInstruction(X64.Cli); if (irq <= 7 || irq >= 16 | irq == 9) // For IRQ 8, 10, 11, 12, 13, 14 the cpu will automatically pushed the error code diff --git a/Source/Mosa.Compiler.x64/Intrinsic/InterruptReturn.cs b/Source/Mosa.Compiler.x64/Intrinsic/InterruptReturn.cs index 58cd08f8bc..c568e46ab3 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/InterruptReturn.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/InterruptReturn.cs @@ -14,7 +14,7 @@ private static void InterruptReturn(Context context, Transform transform) { Operand v0 = context.Operand1; - Operand esp = Operand.CreateCPURegister64(CPURegister.RSP); + Operand esp = transform.PhysicalRegisters.Allocate64(CPURegister.RSP); context.SetInstruction(X64.Mov64, esp, v0); context.AppendInstruction(X64.Popad); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/Memclr256.cs b/Source/Mosa.Compiler.x64/Intrinsic/Memclr256.cs index 76c4d703f4..8fd481e650 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/Memclr256.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/Memclr256.cs @@ -14,7 +14,7 @@ private static void Memclr256(Context context, Transform transform) { var dest = context.Operand1; - var v0 = Operand.CreateCPURegisterR8(CPURegister.XMM0); + var v0 = transform.PhysicalRegisters.AllocateR8(CPURegister.XMM0); var offset16 = Operand.Constant64_16; context.SetInstruction(X64.PXor, v0, v0, v0); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/RdMSR.cs b/Source/Mosa.Compiler.x64/Intrinsic/RdMSR.cs index ed00f94a68..787e255dff 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/RdMSR.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/RdMSR.cs @@ -17,9 +17,9 @@ private static void RdMSR(Context context, Transform transform) transform.SplitOperand(result, out Operand resultLow, out Operand resultHigh); - var EAX = Operand.CreateCPURegister64(CPURegister.RAX); - var EDX = Operand.CreateCPURegister64(CPURegister.RDX); - var ECX = Operand.CreateCPURegister64(CPURegister.RAX); + var EAX = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var EDX = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); + var ECX = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); context.SetInstruction(X64.Mov64, ECX, operand1); context.AppendInstruction2(X64.RdMSR, EAX, EDX, ECX); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/SetCR0.cs b/Source/Mosa.Compiler.x64/Intrinsic/SetCR0.cs index 37cb377759..40d96c6813 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/SetCR0.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/SetCR0.cs @@ -14,8 +14,8 @@ private static void SetCR0(Context context, Transform transform) { Operand operand1 = context.Operand1; - Operand eax = Operand.CreateCPURegister32(CPURegister.RAX); - Operand cr = Operand.CreateCPURegister32(CPURegister.CR0); + Operand eax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + Operand cr = transform.PhysicalRegisters.Allocate32(CPURegister.CR0); context.SetInstruction(X64.Mov64, eax, operand1); context.AppendInstruction(X64.MovCRStore64, null, cr, eax); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/SetCR2.cs b/Source/Mosa.Compiler.x64/Intrinsic/SetCR2.cs index 770b57f39e..c330c4d722 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/SetCR2.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/SetCR2.cs @@ -14,8 +14,8 @@ private static void SetCR2(Context context, Transform transform) { Operand operand1 = context.Operand1; - Operand eax = Operand.CreateCPURegister32(CPURegister.RAX); - Operand cr = Operand.CreateCPURegister32(CPURegister.CR2); + Operand eax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + Operand cr = transform.PhysicalRegisters.Allocate32(CPURegister.CR2); context.SetInstruction(X64.Mov64, eax, operand1); context.AppendInstruction(X64.MovCRStore64, null, cr, eax); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/SetCR3.cs b/Source/Mosa.Compiler.x64/Intrinsic/SetCR3.cs index 8b38536108..70adc8faeb 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/SetCR3.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/SetCR3.cs @@ -14,8 +14,8 @@ private static void SetCR3(Context context, Transform transform) { Operand operand1 = context.Operand1; - Operand eax = Operand.CreateCPURegister32(CPURegister.RAX); - Operand cr = Operand.CreateCPURegister32(CPURegister.CR3); + Operand eax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + Operand cr = transform.PhysicalRegisters.Allocate32(CPURegister.CR3); context.SetInstruction(X64.Mov64, eax, operand1); context.AppendInstruction(X64.MovCRStore64, null, cr, eax); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/SetCR4.cs b/Source/Mosa.Compiler.x64/Intrinsic/SetCR4.cs index 60cf80f5c0..177dfa53f3 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/SetCR4.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/SetCR4.cs @@ -14,8 +14,8 @@ private static void SetCR4(Context context, Transform transform) { Operand operand1 = context.Operand1; - Operand eax = Operand.CreateCPURegister32(CPURegister.RAX); - Operand cr = Operand.CreateCPURegister32(CPURegister.CR4); + Operand eax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + Operand cr = transform.PhysicalRegisters.Allocate32(CPURegister.CR4); context.SetInstruction(X64.Mov64, eax, operand1); context.AppendInstruction(X64.MovCRStore64, null, cr, eax); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/SetFS.cs b/Source/Mosa.Compiler.x64/Intrinsic/SetFS.cs index c9326d09b5..382af3e9ed 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/SetFS.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/SetFS.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x64.Intrinsic::SetFS")] private static void SetFS(Context context, Transform transform) { - context.SetInstruction(X64.MovStoreSeg64, Operand.CreateCPURegister64(CPURegister.FS), context.Operand1); + context.SetInstruction(X64.MovStoreSeg64, transform.PhysicalRegisters.Allocate64(CPURegister.FS), context.Operand1); } } diff --git a/Source/Mosa.Compiler.x64/Intrinsic/SetSegments.cs b/Source/Mosa.Compiler.x64/Intrinsic/SetSegments.cs index 24c9b69056..b51de8c012 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/SetSegments.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/SetSegments.cs @@ -18,11 +18,11 @@ private static void SetSegments(Context context, Transform transform) var operand4 = context.Operand4; var operand5 = context.Operand5; - var ds = Operand.CreateCPURegister64(CPURegister.DS); - var es = Operand.CreateCPURegister64(CPURegister.ES); - var fs = Operand.CreateCPURegister64(CPURegister.FS); - var gs = Operand.CreateCPURegister64(CPURegister.GS); - var ss = Operand.CreateCPURegister64(CPURegister.SS); + var ds = transform.PhysicalRegisters.Allocate64(CPURegister.DS); + var es = transform.PhysicalRegisters.Allocate64(CPURegister.ES); + var fs = transform.PhysicalRegisters.Allocate64(CPURegister.FS); + var gs = transform.PhysicalRegisters.Allocate64(CPURegister.GS); + var ss = transform.PhysicalRegisters.Allocate64(CPURegister.SS); context.SetInstruction(X64.MovStoreSeg64, ds, operand1); context.AppendInstruction(X64.MovStoreSeg64, es, operand2); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Cdq32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Cdq32.cs index 2bfc01c19b..7602868439 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Cdq32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Cdq32.cs @@ -30,8 +30,8 @@ public override void Transform(Context context, Transform transform) var operand1 = context.Operand1; var result = context.Result; - var rax = Operand.CreateCPURegister32(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rax, operand1); context.AppendInstruction(X64.Cdq32, rdx, rax); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Cdq64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Cdq64.cs index ec81b06a07..7148185701 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Cdq64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Cdq64.cs @@ -30,8 +30,8 @@ public override void Transform(Context context, Transform transform) var operand1 = context.Operand1; var result = context.Result; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); context.SetInstruction(X64.Mov64, rax, operand1); context.AppendInstruction(X64.Cdq64, rdx, rax); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Div32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Div32.cs index e639cf56ab..9d7ad43f44 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Div32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Div32.cs @@ -36,8 +36,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var rax = Operand.CreateCPURegister32(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.Mov64, rax, operand2); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Div64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Div64.cs index 27cc30fc21..7979b2d366 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Div64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Div64.cs @@ -36,8 +36,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.Mov64, rax, operand2); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/IDiv32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/IDiv32.cs index 0174a4719f..41b2caec70 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/IDiv32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/IDiv32.cs @@ -37,8 +37,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var rax = Operand.CreateCPURegister32(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.Mov64, rax, operand2); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/IDiv64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/IDiv64.cs index 3e5d036a3f..d27e668b07 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/IDiv64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/IDiv64.cs @@ -37,8 +37,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.Mov64, rax, operand2); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In16.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In16.cs index 11b4231444..3189cd73ce 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In16.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In16.cs @@ -27,8 +27,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var operand1 = context.Operand1; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.In16, rax, rdx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In32.cs index cf01e8597d..5962a660b7 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In32.cs @@ -27,8 +27,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var operand1 = context.Operand1; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.In32, rax, rdx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In8.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In8.cs index c90275ffa5..f4cd9aad9d 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In8.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In8.cs @@ -27,8 +27,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var operand1 = context.Operand1; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.In8, rax, rdx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Mul32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Mul32.cs index c7107f778f..a10922ab70 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Mul32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Mul32.cs @@ -36,8 +36,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var rax = Operand.CreateCPURegister32(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rax, operand1); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Mul64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Mul64.cs index f0c2e504a3..0b5f3f3e76 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Mul64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Mul64.cs @@ -36,8 +36,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); context.SetInstruction(X64.Mov64, rax, operand1); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out16.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out16.cs index 954fde667a..2ef8c37a4c 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out16.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out16.cs @@ -29,8 +29,8 @@ public override void Transform(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var rax = Operand.CreateCPURegister32(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.Mov64, rax, operand2); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out32.cs index aa38c26042..9705aeccaf 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out32.cs @@ -29,8 +29,8 @@ public override void Transform(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var rax = Operand.CreateCPURegister32(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.Mov64, rax, operand2); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out8.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out8.cs index 6234fcf1da..e045bee02c 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out8.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out8.cs @@ -29,8 +29,8 @@ public override void Transform(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var rax = Operand.CreateCPURegister32(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.Mov64, rax, operand2); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Rcr32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Rcr32.cs index 93a907a49d..d125a5453b 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Rcr32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Rcr32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand2); context.AppendInstruction(X64.Rcr32, result, operand1, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Rcr64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Rcr64.cs index 6c608736aa..1004b484db 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Rcr64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Rcr64.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand2); context.AppendInstruction(X64.Rcr64, result, operand1, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/RdMSR.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/RdMSR.cs index 8d4391cf59..bb7e5c7005 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/RdMSR.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/RdMSR.cs @@ -30,9 +30,9 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand1); context.AppendInstruction2(X64.RdMSR, rax, rdx, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Sar32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Sar32.cs index cd907700c0..1f83c19e8d 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Sar32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Sar32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var rcx = Operand.CreateCPURegister32(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate32(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand2); context.AppendInstruction(X64.Sar32, result, operand1, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Sar64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Sar64.cs index 56d21ac69e..c8a8f5d1cc 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Sar64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Sar64.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand2); context.AppendInstruction(X64.Sar64, result, operand1, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shl32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shl32.cs index 3022947b86..4150a0dd2e 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shl32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shl32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand2); context.AppendInstruction(X64.Shl32, result, operand1, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shl64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shl64.cs index edb3a1b622..5d240d2fef 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shl64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shl64.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand2); context.AppendInstruction(X64.Shl64, result, operand1, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shld32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shld32.cs index e2ef8d4f6d..36e161ad07 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shld32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shld32.cs @@ -32,7 +32,7 @@ public override void Transform(Context context, Transform transform) var operand3 = context.Operand3; var result = context.Result; - var rcx = Operand.CreateCPURegister32(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate32(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand3); context.AppendInstruction(X64.Shld32, result, operand1, operand2, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shld64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shld64.cs index 7902eae411..5bf22e486e 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shld64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shld64.cs @@ -32,7 +32,7 @@ public override void Transform(Context context, Transform transform) var operand3 = context.Operand3; var result = context.Result; - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand3); context.AppendInstruction(X64.Shld64, result, operand1, operand2, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shr32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shr32.cs index 1cb8f38ef9..86048eb161 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shr32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shr32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var rcx = Operand.CreateCPURegister32(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate32(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand2); context.AppendInstruction(X64.Shr32, result, operand1, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shr64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shr64.cs index 18829cdfa4..bf4bf780f4 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shr64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shr64.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand2); context.AppendInstruction(X64.Shr64, result, operand1, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shrd32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shrd32.cs index ace16ead9e..11274449bc 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shrd32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shrd32.cs @@ -32,7 +32,7 @@ public override void Transform(Context context, Transform transform) var operand3 = context.Operand3; var result = context.Result; - var rcx = Operand.CreateCPURegister32(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate32(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand3); context.AppendInstruction(X64.Shrd32, result, operand1, operand2, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shrd64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shrd64.cs index dd1e926df6..afe662e46e 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shrd64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shrd64.cs @@ -32,7 +32,7 @@ public override void Transform(Context context, Transform transform) var operand3 = context.Operand3; var result = context.Result; - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand3); context.AppendInstruction(X64.Shrd64, result, operand1, operand2, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/WrMSR.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/WrMSR.cs index 2714f0b8de..cf59530397 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/WrMSR.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/WrMSR.cs @@ -30,9 +30,9 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rax, operand1); context.AppendInstruction(X64.Mov64, rdx, operand2); diff --git a/Source/Mosa.Compiler.x64/Transforms/Tweak/MovStore16.cs b/Source/Mosa.Compiler.x64/Transforms/Tweak/MovStore16.cs index e0f77b3505..c0d98eb161 100644 --- a/Source/Mosa.Compiler.x64/Transforms/Tweak/MovStore16.cs +++ b/Source/Mosa.Compiler.x64/Transforms/Tweak/MovStore16.cs @@ -29,19 +29,19 @@ public override void Transform(Context context, Transform transform) if (dest.Register != CPURegister.RAX && offset.Register != CPURegister.RAX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.RAX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); } else if (dest.Register != CPURegister.RBX && offset.Register != CPURegister.RBX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.RBX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.RBX); } else if (dest.Register != CPURegister.RAX && offset.Register != CPURegister.RAX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.RAX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); } else { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.RAX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); } context.SetInstruction2(X64.XChg64, temporaryRegister, value, value, temporaryRegister); diff --git a/Source/Mosa.Compiler.x64/Transforms/Tweak/MovStore8.cs b/Source/Mosa.Compiler.x64/Transforms/Tweak/MovStore8.cs index a35c8d1ddf..1d1dbd74b1 100644 --- a/Source/Mosa.Compiler.x64/Transforms/Tweak/MovStore8.cs +++ b/Source/Mosa.Compiler.x64/Transforms/Tweak/MovStore8.cs @@ -29,19 +29,19 @@ public override void Transform(Context context, Transform transform) if (dest.Register != CPURegister.RAX && offset.Register != CPURegister.RAX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.RAX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); } else if (dest.Register != CPURegister.RBX && offset.Register != CPURegister.RBX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.RBX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.RBX); } else if (dest.Register != CPURegister.RAX && offset.Register != CPURegister.RAX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.RAX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); } else { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.RDX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); } context.SetInstruction2(X64.XChg64, temporaryRegister, value, value, temporaryRegister); diff --git a/Source/Mosa.Compiler.x64/Transforms/Tweak/Setcc.cs b/Source/Mosa.Compiler.x64/Transforms/Tweak/Setcc.cs index c4b93448e6..1f1e807f9f 100644 --- a/Source/Mosa.Compiler.x64/Transforms/Tweak/Setcc.cs +++ b/Source/Mosa.Compiler.x64/Transforms/Tweak/Setcc.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) // SETcc can not use with RSI or RDI registers - var rax = Operand.CreateCPURegister32(CPURegister.RAX); + var rax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); context.SetInstruction2(X64.XChg64, rax, result, result, rax); context.AppendInstruction(instruction, condition, rax); diff --git a/Source/Mosa.Compiler.x86/CompilerStages/MultibootStage.cs b/Source/Mosa.Compiler.x86/CompilerStages/MultibootStage.cs index 15c3b5cef2..acf35d7cc6 100644 --- a/Source/Mosa.Compiler.x86/CompilerStages/MultibootStage.cs +++ b/Source/Mosa.Compiler.x86/CompilerStages/MultibootStage.cs @@ -15,27 +15,30 @@ protected override void Finalization() private void CreateMultibootMethod() { + var basicBlocks = new BasicBlocks(); + + var methodCompiler = new MethodCompiler(Compiler, multibootMethod, basicBlocks, 0); + methodCompiler.MethodData.DoNotInline = true; + + var transform = new Transform(); + transform.SetCompiler(Compiler); + transform.SetMethodCompiler(methodCompiler); + var startUpType = TypeSystem.GetTypeByName("Mosa.Runtime.StartUp"); var initializeMethod = startUpType.FindMethodByName("Initialize"); - Compiler.GetMethodData(initializeMethod).DoNotInline = true; - var entryPoint = Operand.CreateLabel(initializeMethod, Architecture.Is32BitPlatform); - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var ebx = Operand.CreateCPURegister32(CPURegister.EBX); - var ebp = Operand.CreateCPURegister32(CPURegister.EBP); - var esp = Operand.CreateCPURegister32(CPURegister.ESP); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var ebx = transform.PhysicalRegisters.Allocate32(CPURegister.EBX); + var ebp = transform.PhysicalRegisters.Allocate32(CPURegister.EBP); + var esp = transform.PhysicalRegisters.Allocate32(CPURegister.ESP); var multibootEAX = Operand.CreateLabel(MultibootEAX, Architecture.Is32BitPlatform); var multibootEBX = Operand.CreateLabel(MultibootEBX, Architecture.Is32BitPlatform); var stackBottom = Operand.CreateLabel(MultibootInitialStack, Architecture.Is32BitPlatform); var stackTopOffset = CreateConstant(StackSize - 8); - var zero = CreateConstant(0); - var offset = CreateConstant(4); - - var basicBlocks = new BasicBlocks(); var prologueBlock = basicBlocks.CreatePrologueBlock(); @@ -46,16 +49,16 @@ private void CreateMultibootMethod() context.AppendInstruction(X86.Add32, esp, esp, stackTopOffset); context.AppendInstruction(X86.Mov32, ebp, stackBottom); context.AppendInstruction(X86.Add32, ebp, ebp, stackTopOffset); - context.AppendInstruction(X86.MovStore32, null, esp, zero, zero); - context.AppendInstruction(X86.MovStore32, null, esp, offset, zero); + context.AppendInstruction(X86.MovStore32, null, esp, Operand.Constant32_0, Operand.Constant32_0); + context.AppendInstruction(X86.MovStore32, null, esp, Operand.Constant32_8, Operand.Constant32_0); // Place the multiboot address into a static field - context.AppendInstruction(X86.MovStore32, null, multibootEAX, zero, eax); - context.AppendInstruction(X86.MovStore32, null, multibootEBX, zero, ebx); + context.AppendInstruction(X86.MovStore32, null, multibootEAX, Operand.Constant32_0, eax); + context.AppendInstruction(X86.MovStore32, null, multibootEBX, Operand.Constant32_0, ebx); - context.AppendInstruction(X86.Call, null, entryPoint); // FUTURE: Remove line (SetupStage) + context.AppendInstruction(X86.Call, null, entryPoint); context.AppendInstruction(X86.Ret); - Compiler.CompileMethod(multibootMethod, basicBlocks); + Compiler.CompileMethod(transform); } } diff --git a/Source/Mosa.Compiler.x86/Intrinsic/AllocateStackSpace.cs b/Source/Mosa.Compiler.x86/Intrinsic/AllocateStackSpace.cs index e1c3653f58..ba2447f2cd 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/AllocateStackSpace.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/AllocateStackSpace.cs @@ -15,7 +15,7 @@ private static void AllocateStackSpace(Context context, Transform transform) Operand result = context.Result; Operand size = context.Operand1; - Operand esp = Operand.CreateCPURegister32(CPURegister.ESP); + Operand esp = transform.PhysicalRegisters.Allocate32(CPURegister.ESP); context.SetInstruction(X86.Sub32, esp, esp, size); context.AppendInstruction(X86.Mov32, result, esp); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/CmpXChgLoad32.cs b/Source/Mosa.Compiler.x86/Intrinsic/CmpXChgLoad32.cs index df17c6aa4c..3847293f87 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/CmpXChgLoad32.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/CmpXChgLoad32.cs @@ -17,7 +17,7 @@ private static void CmpXChgLoad32(Context context, Transform transform) var comparand = context.Operand3; var result = context.Result; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); var v1 = transform.VirtualRegisters.Allocate32(); context.SetInstruction(X86.Mov32, eax, comparand); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEax.cs b/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEax.cs index 9c8cb40d48..da4d7ee3a5 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEax.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEax.cs @@ -16,10 +16,10 @@ private static void CpuIdEAX(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var ebx = Operand.CreateCPURegister32(CPURegister.EBX); - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var ebx = transform.PhysicalRegisters.Allocate32(CPURegister.EBX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, eax, operand1); context.AppendInstruction(X86.Mov32, ecx, operand2); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEbx.cs b/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEbx.cs index 904021cafb..213a2d5dfc 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEbx.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEbx.cs @@ -16,10 +16,10 @@ private static void CpuIdEBX(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var ebx = Operand.CreateCPURegister32(CPURegister.EBX); - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var ebx = transform.PhysicalRegisters.Allocate32(CPURegister.EBX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, eax, operand1); context.AppendInstruction(X86.Mov32, ecx, operand2); context.AppendInstruction(X86.Mov32, ecx, Operand.Constant32_0); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEcx.cs b/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEcx.cs index 7261d783cc..13a20eb9db 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEcx.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEcx.cs @@ -16,10 +16,10 @@ private static void CpuIdECX(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var ebx = Operand.CreateCPURegister32(CPURegister.EBX); - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var ebx = transform.PhysicalRegisters.Allocate32(CPURegister.EBX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, eax, operand1); context.AppendInstruction(X86.Mov32, ecx, operand2); context.AppendInstruction(X86.Mov32, ecx, Operand.Constant32_0); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEdx.cs b/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEdx.cs index 99df0686c5..7e562dec97 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEdx.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEdx.cs @@ -16,10 +16,10 @@ private static void CpuIdEDX(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var ebx = Operand.CreateCPURegister32(CPURegister.EBX); - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var ebx = transform.PhysicalRegisters.Allocate32(CPURegister.EBX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, eax, operand1); context.AppendInstruction(X86.Mov32, ecx, operand2); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetR8.cs b/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetR8.cs index ccf65ed07d..245eca4f81 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetR8.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetR8.cs @@ -15,9 +15,9 @@ private static void FrameCallRetR8(Context context, Transform transform) var result = context.Result; var methodAddress = context.Operand1; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); - var xmm0 = Operand.CreateCPURegister32(CPURegister.XMM0); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); + var xmm0 = transform.PhysicalRegisters.Allocate32(CPURegister.XMM0); context.SetInstruction(X86.Call, null, methodAddress); context.AppendInstruction(IRInstruction.Gen, xmm0); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetU4.cs b/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetU4.cs index 53100380e7..2faefb2556 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetU4.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetU4.cs @@ -15,7 +15,7 @@ private static void FrameCallRetU4(Context context, Transform transform) var result = context.Result; var methodAddress = context.Operand1; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); context.SetInstruction(X86.Call, null, methodAddress); context.AppendInstruction(IRInstruction.Gen, eax); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetU8.cs b/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetU8.cs index e09921f751..474d4a5583 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetU8.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetU8.cs @@ -15,8 +15,8 @@ private static void FrameCallRetU8(Context context, Transform transform) var result = context.Result; var methodAddress = context.Operand1; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Call, null, methodAddress); context.AppendInstruction(IRInstruction.Gen, eax); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/FrameJump.cs b/Source/Mosa.Compiler.x86/Intrinsic/FrameJump.cs index 5954990f9b..1592e57a13 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/FrameJump.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/FrameJump.cs @@ -17,18 +17,18 @@ private static void FrameJump(Context context, Transform transform) var v2 = context.Operand3; var v3 = context.Operand4; - var esp = Operand.CreateCPURegister32(CPURegister.ESP); - var ebp = Operand.CreateCPURegister32(CPURegister.EBP); + var esp = transform.PhysicalRegisters.Allocate32(CPURegister.ESP); + var ebp = transform.PhysicalRegisters.Allocate32(CPURegister.EBP); - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var ebx = Operand.CreateCPURegister32(CPURegister.EBX); - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var ebx = transform.PhysicalRegisters.Allocate32(CPURegister.EBX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); // Move all virtual registers into physical registers - necessary since stack frame pointer will change context.SetInstruction(X86.Mov32, eax, v0); context.AppendInstruction(X86.Mov32, ebx, v1); context.AppendInstruction(X86.Mov32, ecx, v2); - context.AppendInstruction(X86.Mov32, transform.Compiler.ExceptionRegister, v3); + context.AppendInstruction(X86.Mov32, transform.ExceptionRegister, v3); // Update the frame and stack registers context.AppendInstruction(X86.Mov32, ebp, ecx); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/GetCR0.cs b/Source/Mosa.Compiler.x86/Intrinsic/GetCR0.cs index 1f1482cc65..8f409abb4d 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/GetCR0.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/GetCR0.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x86.Intrinsic::GetCR0")] private static void GetCR0(Context context, Transform transform) { - context.SetInstruction(X86.MovCRLoad32, context.Result, Operand.CreateCPURegister32(CPURegister.CR0)); + context.SetInstruction(X86.MovCRLoad32, context.Result, transform.PhysicalRegisters.Allocate32(CPURegister.CR0)); } } diff --git a/Source/Mosa.Compiler.x86/Intrinsic/GetCR2.cs b/Source/Mosa.Compiler.x86/Intrinsic/GetCR2.cs index cb38cb6f1e..3c7635deb5 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/GetCR2.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/GetCR2.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x86.Intrinsic::GetCR2")] private static void GetCR2(Context context, Transform transform) { - context.SetInstruction(X86.MovCRLoad32, context.Result, Operand.CreateCPURegister32(CPURegister.CR2)); + context.SetInstruction(X86.MovCRLoad32, context.Result, transform.PhysicalRegisters.Allocate32(CPURegister.CR2)); } } diff --git a/Source/Mosa.Compiler.x86/Intrinsic/GetCR3.cs b/Source/Mosa.Compiler.x86/Intrinsic/GetCR3.cs index 7f9f208814..8228d38358 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/GetCR3.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/GetCR3.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x86.Intrinsic::GetCR3")] private static void GetCR3(Context context, Transform transform) { - context.SetInstruction(X86.MovCRLoad32, context.Result, Operand.CreateCPURegister32(CPURegister.CR3)); + context.SetInstruction(X86.MovCRLoad32, context.Result, transform.PhysicalRegisters.Allocate32(CPURegister.CR3)); } } diff --git a/Source/Mosa.Compiler.x86/Intrinsic/GetCR4.cs b/Source/Mosa.Compiler.x86/Intrinsic/GetCR4.cs index 1bfdf99bf0..d92b47a688 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/GetCR4.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/GetCR4.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x86.Intrinsic::GetCR4")] private static void GetCR4(Context context, Transform transform) { - context.SetInstruction(X86.MovCRLoad32, context.Result, Operand.CreateCPURegister32(CPURegister.CR4)); + context.SetInstruction(X86.MovCRLoad32, context.Result, transform.PhysicalRegisters.Allocate32(CPURegister.CR4)); } } diff --git a/Source/Mosa.Compiler.x86/Intrinsic/GetCS.cs b/Source/Mosa.Compiler.x86/Intrinsic/GetCS.cs index f856ee421f..868d324842 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/GetCS.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/GetCS.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x86.Intrinsic::GetCS")] private static void GetCS(Context context, Transform transform) { - context.SetInstruction(X86.MovLoadSeg32, context.Result, Operand.CreateCPURegister32(CPURegister.CS)); + context.SetInstruction(X86.MovLoadSeg32, context.Result, transform.PhysicalRegisters.Allocate32(CPURegister.CS)); } } diff --git a/Source/Mosa.Compiler.x86/Intrinsic/GetFS.cs b/Source/Mosa.Compiler.x86/Intrinsic/GetFS.cs index 7fa950d65d..b32bb9813a 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/GetFS.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/GetFS.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x86.Intrinsic::GetFS")] private static void GetFS(Context context, Transform transform) { - context.SetInstruction(X86.MovLoadSeg32, context.Result, Operand.CreateCPURegister32(CPURegister.FS)); + context.SetInstruction(X86.MovLoadSeg32, context.Result, transform.PhysicalRegisters.Allocate32(CPURegister.FS)); } } diff --git a/Source/Mosa.Compiler.x86/Intrinsic/IRQs.cs b/Source/Mosa.Compiler.x86/Intrinsic/IRQs.cs index c99c102cf0..07d9ccc536 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/IRQs.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/IRQs.cs @@ -52,7 +52,7 @@ private static void InsertIRQ(int irq, Context context, Transform transform) var interrupt = Operand.CreateLabel(method, transform.Is32BitPlatform); - var esp = Operand.CreateCPURegister32(CPURegister.ESP); + var esp = transform.PhysicalRegisters.Allocate32(CPURegister.ESP); context.SetInstruction(X86.Cli); if (irq <= 7 || irq >= 16 | irq == 9) // For IRQ 8, 10, 11, 12, 13, 14 the cpu will automatically pushed the error code diff --git a/Source/Mosa.Compiler.x86/Intrinsic/InterruptReturn.cs b/Source/Mosa.Compiler.x86/Intrinsic/InterruptReturn.cs index 71c508196b..df1f7caa01 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/InterruptReturn.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/InterruptReturn.cs @@ -14,7 +14,7 @@ private static void InterruptReturn(Context context, Transform transform) { Operand v0 = context.Operand1; - Operand esp = Operand.CreateCPURegister32(CPURegister.ESP); + Operand esp = transform.PhysicalRegisters.Allocate32(CPURegister.ESP); context.SetInstruction(X86.Mov32, esp, v0); context.AppendInstruction(X86.Popad); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/Memclr256.cs b/Source/Mosa.Compiler.x86/Intrinsic/Memclr256.cs index f91bae5586..f9c22fe298 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/Memclr256.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/Memclr256.cs @@ -14,7 +14,7 @@ private static void Memclr256(Context context, Transform transform) { var dest = context.Operand1; - var v0 = Operand.CreateCPURegisterNativeInteger(CPURegister.XMM0, transform.Is32BitPlatform); + var v0 = transform.PhysicalRegisters.AllocateR8(CPURegister.XMM0); var offset16 = Operand.Constant32_16; context.SetInstruction(X86.PXor, v0, v0, v0); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/RdMSR.cs b/Source/Mosa.Compiler.x86/Intrinsic/RdMSR.cs index e8f0a630ba..24133e8594 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/RdMSR.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/RdMSR.cs @@ -17,9 +17,9 @@ private static void RdMSR(Context context, Transform transform) //transform.SplitOperand(result, out Operand resultLow, out Operand resultHigh); - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ecx, operand1); context.AppendInstruction2(X86.RdMSR, eax, edx, ecx); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/SetCR0.cs b/Source/Mosa.Compiler.x86/Intrinsic/SetCR0.cs index 2ed06b9c5e..5dd0d5e4e5 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/SetCR0.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/SetCR0.cs @@ -14,8 +14,8 @@ private static void SetCR0(Context context, Transform transform) { Operand operand1 = context.Operand1; - Operand eax = Operand.CreateCPURegister32(CPURegister.EAX); - Operand cr = Operand.CreateCPURegister32(CPURegister.CR0); + Operand eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + Operand cr = transform.PhysicalRegisters.Allocate32(CPURegister.CR0); context.SetInstruction(X86.Mov32, eax, operand1); context.AppendInstruction(X86.MovCRStore32, null, cr, eax); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/SetCR2.cs b/Source/Mosa.Compiler.x86/Intrinsic/SetCR2.cs index f6e8a1cdcf..2a4d47f4da 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/SetCR2.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/SetCR2.cs @@ -14,8 +14,8 @@ private static void SetCR2(Context context, Transform transform) { Operand operand1 = context.Operand1; - Operand eax = Operand.CreateCPURegister32(CPURegister.EAX); - Operand cr = Operand.CreateCPURegister32(CPURegister.CR2); + Operand eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + Operand cr = transform.PhysicalRegisters.Allocate32(CPURegister.CR2); context.SetInstruction(X86.Mov32, eax, operand1); context.AppendInstruction(X86.MovCRStore32, null, cr, eax); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/SetCR3.cs b/Source/Mosa.Compiler.x86/Intrinsic/SetCR3.cs index 0cde29ee65..ac12e98c04 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/SetCR3.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/SetCR3.cs @@ -14,8 +14,8 @@ private static void SetCR3(Context context, Transform transform) { Operand operand1 = context.Operand1; - Operand eax = Operand.CreateCPURegister32(CPURegister.EAX); - Operand cr = Operand.CreateCPURegister32(CPURegister.CR3); + Operand eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + Operand cr = transform.PhysicalRegisters.Allocate32(CPURegister.CR3); context.SetInstruction(X86.Mov32, eax, operand1); context.AppendInstruction(X86.MovCRStore32, null, cr, eax); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/SetCR4.cs b/Source/Mosa.Compiler.x86/Intrinsic/SetCR4.cs index b4b68c779a..eb6d00e590 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/SetCR4.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/SetCR4.cs @@ -14,8 +14,8 @@ private static void SetCR4(Context context, Transform transform) { Operand operand1 = context.Operand1; - Operand eax = Operand.CreateCPURegister32(CPURegister.EAX); - Operand cr = Operand.CreateCPURegister32(CPURegister.CR4); + Operand eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + Operand cr = transform.PhysicalRegisters.Allocate32(CPURegister.CR4); context.SetInstruction(X86.Mov32, eax, operand1); context.AppendInstruction(X86.MovCRStore32, null, cr, eax); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/SetFS.cs b/Source/Mosa.Compiler.x86/Intrinsic/SetFS.cs index c740a25355..8f3f71170d 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/SetFS.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/SetFS.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x86.Intrinsic::SetFS")] private static void SetFS(Context context, Transform transform) { - context.SetInstruction(X86.MovStoreSeg32, Operand.CreateCPURegister32(CPURegister.FS), context.Operand1); + context.SetInstruction(X86.MovStoreSeg32, transform.PhysicalRegisters.Allocate32(CPURegister.FS), context.Operand1); } } diff --git a/Source/Mosa.Compiler.x86/Intrinsic/SetSegments.cs b/Source/Mosa.Compiler.x86/Intrinsic/SetSegments.cs index e256ecc19c..5ee1622c43 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/SetSegments.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/SetSegments.cs @@ -18,11 +18,11 @@ private static void SetSegments(Context context, Transform transform) var operand4 = context.Operand4; var operand5 = context.Operand5; - var ds = Operand.CreateCPURegister32(CPURegister.DS); - var es = Operand.CreateCPURegister32(CPURegister.ES); - var fs = Operand.CreateCPURegister32(CPURegister.FS); - var gs = Operand.CreateCPURegister32(CPURegister.GS); - var ss = Operand.CreateCPURegister32(CPURegister.SS); + var ds = transform.PhysicalRegisters.Allocate32(CPURegister.DS); + var es = transform.PhysicalRegisters.Allocate32(CPURegister.ES); + var fs = transform.PhysicalRegisters.Allocate32(CPURegister.FS); + var gs = transform.PhysicalRegisters.Allocate32(CPURegister.GS); + var ss = transform.PhysicalRegisters.Allocate32(CPURegister.SS); context.SetInstruction(X86.MovStoreSeg32, ds, operand1); context.AppendInstruction(X86.MovStoreSeg32, es, operand2); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Cdq32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Cdq32.cs index 06e62a02e9..ef4276a0de 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Cdq32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Cdq32.cs @@ -30,8 +30,8 @@ public override void Transform(Context context, Transform transform) var operand1 = context.Operand1; var result = context.Result; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, eax, operand1); context.AppendInstruction(X86.Cdq32, edx, eax); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Div32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Div32.cs index de03bb4f8e..810335f221 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Div32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Div32.cs @@ -36,8 +36,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, edx, operand1); context.AppendInstruction(X86.Mov32, eax, operand2); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/IDiv32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/IDiv32.cs index 496b02a8dd..4fd1dabf19 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/IDiv32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/IDiv32.cs @@ -37,8 +37,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, edx, operand1); context.AppendInstruction(X86.Mov32, eax, operand2); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/IMul32o1.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/IMul32o1.cs index a8718aa17d..e08440f871 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/IMul32o1.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/IMul32o1.cs @@ -36,8 +36,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, eax, operand1); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In16.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In16.cs index ebd9a3c22a..2e5697316c 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In16.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In16.cs @@ -30,8 +30,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var operand1 = context.Operand1; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, edx, operand1); context.AppendInstruction(X86.In16, eax, edx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In32.cs index bec5b8ad00..ff46b848b1 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In32.cs @@ -30,8 +30,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var operand1 = context.Operand1; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, edx, operand1); context.AppendInstruction(X86.In32, eax, edx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In8.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In8.cs index 140ff043ff..fd9ee8fac3 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In8.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In8.cs @@ -30,8 +30,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var operand1 = context.Operand1; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, edx, operand1); context.AppendInstruction(X86.In8, eax, edx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Mul32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Mul32.cs index b6896cdc7c..e9f686c7f8 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Mul32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Mul32.cs @@ -36,8 +36,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, eax, operand1); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out16.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out16.cs index 5d17a3e5d2..525ece62c1 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out16.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out16.cs @@ -30,8 +30,8 @@ public override void Transform(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, edx, operand1); context.AppendInstruction(X86.Mov32, eax, operand2); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out32.cs index c5a090f9da..fc79599962 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out32.cs @@ -30,8 +30,8 @@ public override void Transform(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, edx, operand1); context.AppendInstruction(X86.Mov32, eax, operand2); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out8.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out8.cs index c529010979..8602d394c5 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out8.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out8.cs @@ -30,8 +30,8 @@ public override void Transform(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, edx, operand1); context.AppendInstruction(X86.Mov32, eax, operand2); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Rcr32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Rcr32.cs index 05d4bfd522..abe35da976 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Rcr32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Rcr32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ecx, operand2); context.AppendInstruction(X86.Rcr32, result, operand1, ecx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/RdMSR.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/RdMSR.cs index 297ab2b20c..37e0e081f2 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/RdMSR.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/RdMSR.cs @@ -33,9 +33,9 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ecx, operand1); context.AppendInstruction2(X86.RdMSR, eax, edx, ecx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Sar32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Sar32.cs index 86ac666c39..8acbc461b7 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Sar32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Sar32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ecx, operand2); context.AppendInstruction(X86.Sar32, result, operand1, ecx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shl32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shl32.cs index 7464e954eb..856d65bf6a 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shl32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shl32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ecx, operand2); context.AppendInstruction(X86.Shl32, result, operand1, ecx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shld32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shld32.cs index 5b98c048ee..f4f0a4c826 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shld32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shld32.cs @@ -32,7 +32,7 @@ public override void Transform(Context context, Transform transform) var operand3 = context.Operand3; var result = context.Result; - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ecx, operand3); context.AppendInstruction(X86.Shld32, result, operand1, operand2, ecx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shr32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shr32.cs index 896bd09bcc..3424230235 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shr32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shr32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ecx, operand2); context.AppendInstruction(X86.Shr32, result, operand1, ecx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shrd32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shrd32.cs index d90d3a572d..e5a4be44eb 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shrd32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shrd32.cs @@ -32,7 +32,7 @@ public override void Transform(Context context, Transform transform) var operand3 = context.Operand3; var result = context.Result; - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ecx, operand3); context.AppendInstruction(X86.Shrd32, result, operand1, operand2, ecx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/WrMSR.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/WrMSR.cs index 1b9577d424..b276774fcd 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/WrMSR.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/WrMSR.cs @@ -33,9 +33,9 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var operand3 = context.Operand3; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ecx, operand1); context.AppendInstruction(X86.Mov32, eax, operand2); diff --git a/Source/Mosa.Compiler.x86/Transforms/IR/ShiftRight64.cs b/Source/Mosa.Compiler.x86/Transforms/IR/ShiftRight64.cs index 90bab82241..a1fce49891 100644 --- a/Source/Mosa.Compiler.x86/Transforms/IR/ShiftRight64.cs +++ b/Source/Mosa.Compiler.x86/Transforms/IR/ShiftRight64.cs @@ -53,7 +53,7 @@ public override void Transform(Context context, Transform transform) var newBlocks = transform.CreateNewBlockContexts(1, context.Label); var nextBlock = transform.Split(context); - var ECX = Operand.CreateCPURegister32(CPURegister.ECX); + var ECX = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ECX, count); context.AppendInstruction(X86.Shrd32, resultLow, op1L, op1H, ECX); diff --git a/Source/Mosa.Compiler.x86/Transforms/Tweak/MovStore16.cs b/Source/Mosa.Compiler.x86/Transforms/Tweak/MovStore16.cs index a074198042..48595636e4 100644 --- a/Source/Mosa.Compiler.x86/Transforms/Tweak/MovStore16.cs +++ b/Source/Mosa.Compiler.x86/Transforms/Tweak/MovStore16.cs @@ -29,19 +29,19 @@ public override void Transform(Context context, Transform transform) if (dest.Register != CPURegister.EAX && offset.Register != CPURegister.EAX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.EAX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); } else if (dest.Register != CPURegister.EBX && offset.Register != CPURegister.EBX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.EBX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.EBX); } else if (dest.Register != CPURegister.ECX && offset.Register != CPURegister.ECX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.ECX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); } else { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.EDX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); } context.SetInstruction2(X86.XChg32, temporaryRegister, value, value, temporaryRegister); diff --git a/Source/Mosa.Compiler.x86/Transforms/Tweak/MovStore8.cs b/Source/Mosa.Compiler.x86/Transforms/Tweak/MovStore8.cs index db8d2bf0d1..aeb1069de6 100644 --- a/Source/Mosa.Compiler.x86/Transforms/Tweak/MovStore8.cs +++ b/Source/Mosa.Compiler.x86/Transforms/Tweak/MovStore8.cs @@ -29,19 +29,19 @@ public override void Transform(Context context, Transform transform) if (dest.Register != CPURegister.EAX && offset.Register != CPURegister.EAX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.EAX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); } else if (dest.Register != CPURegister.EBX && offset.Register != CPURegister.EBX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.EBX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.EBX); } else if (dest.Register != CPURegister.ECX && offset.Register != CPURegister.ECX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.ECX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); } else { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.EDX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); } context.SetInstruction2(X86.XChg32, temporaryRegister, value, value, temporaryRegister); diff --git a/Source/Mosa.Compiler.x86/Transforms/Tweak/Movsx16To32.cs b/Source/Mosa.Compiler.x86/Transforms/Tweak/Movsx16To32.cs index 3615b44f9a..062a644b1d 100644 --- a/Source/Mosa.Compiler.x86/Transforms/Tweak/Movsx16To32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/Tweak/Movsx16To32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var source = context.Operand1; // Movsx16To32 can not use with ESI or EDI registers as source registers - var eax = Operand.CreateCPURegister32(CPURegister.EAX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); if (source.Register == result.Register) { diff --git a/Source/Mosa.Compiler.x86/Transforms/Tweak/Movsx8To32.cs b/Source/Mosa.Compiler.x86/Transforms/Tweak/Movsx8To32.cs index a07b1df0c7..78dd340bac 100644 --- a/Source/Mosa.Compiler.x86/Transforms/Tweak/Movsx8To32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/Tweak/Movsx8To32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var source = context.Operand1; // Movsx8To32 can not use with ESI or EDI registers as source registers - var eax = Operand.CreateCPURegister32(CPURegister.EAX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); if (source.Register == result.Register) { diff --git a/Source/Mosa.Compiler.x86/Transforms/Tweak/Setcc.cs b/Source/Mosa.Compiler.x86/Transforms/Tweak/Setcc.cs index cfa24759ff..95c38c11e3 100644 --- a/Source/Mosa.Compiler.x86/Transforms/Tweak/Setcc.cs +++ b/Source/Mosa.Compiler.x86/Transforms/Tweak/Setcc.cs @@ -34,7 +34,7 @@ public override void Transform(Context context, Transform transform) // SETcc can not use with ESI or EDI registers as source registers var condition = context.ConditionCode; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); context.SetInstruction2(X86.XChg32, eax, result, result, eax); context.AppendInstruction(instruction, condition, eax);