Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MethodCompiler" /> class.
        /// </summary>
        /// <param name="compiler">The assembly compiler.</param>
        /// <param name="method">The method to compile by this instance.</param>
        /// <param name="basicBlocks">The basic blocks.</param>
        /// <param name="threadID">The thread identifier.</param>
        public MethodCompiler(Compiler compiler, MosaMethod method, BasicBlocks basicBlocks, int threadID)
        {
            Stopwatch = Stopwatch.StartNew();

            Compiler        = compiler;
            Method          = method;
            MethodScheduler = compiler.MethodScheduler;
            Architecture    = compiler.Architecture;
            TypeSystem      = compiler.TypeSystem;
            TypeLayout      = compiler.TypeLayout;
            Trace           = compiler.CompilerTrace;
            Linker          = compiler.Linker;
            MethodScanner   = compiler.MethodScanner;

            BasicBlocks      = basicBlocks ?? new BasicBlocks();
            LocalStack       = new List <Operand>();
            VirtualRegisters = new VirtualRegisters();

            Parameters = new Operand[method.Signature.Parameters.Count + (method.HasThis || method.HasExplicitThis ? 1 : 0)];

            ConstantZero32 = CreateConstant((uint)0);
            ConstantZero64 = CreateConstant((ulong)0);
            ConstantZeroR4 = CreateConstant(0.0f);
            ConstantZeroR8 = CreateConstant(0.0d);

            ConstantZero = Architecture.Is32BitPlatform ? ConstantZero32 : ConstantZero64;

            LocalVariables = emptyOperandList;
            ThreadID       = threadID;

            IsStopped            = false;
            IsExecutePipeline    = true;
            IsCILDecodeRequired  = true;
            IsStackFrameRequired = true;
            IsMethodInlined      = false;
            HasProtectedRegions  = Method.ExceptionHandlers.Count != 0;

            MethodData = Compiler.GetMethodData(Method);
            MethodData.Counters.Reset();

            MethodData.Version++;
            MethodData.IsMethodImplementationReplaced = IsMethodPlugged;

            if (Symbol == null)
            {
                Symbol            = Linker.DefineSymbol(Method.FullName, SectionKind.Text, 0, 0);
                Symbol.MethodData = MethodData;             // for debugging
                Symbol.MosaMethod = Method;                 // for debugging
            }
            else
            {
                Symbol.RemovePatches();
            }

            EvaluateParameterOperands();

            CalculateMethodParameterSize();

            MethodData.Counters.NewCountSkipLock("ExecutionTime.Setup.Ticks", (int)Stopwatch.ElapsedTicks);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MethodCompiler" /> class.
        /// </summary>
        /// <param name="compiler">The assembly compiler.</param>
        /// <param name="method">The method to compile by this instance.</param>
        /// <param name="basicBlocks">The basic blocks.</param>
        /// <param name="threadID">The thread identifier.</param>
        public MethodCompiler(Compiler compiler, MosaMethod method, BasicBlocks basicBlocks, int threadID)
        {
            Compiler     = compiler;
            Method       = method;
            Type         = method.DeclaringType;
            Scheduler    = compiler.CompilationScheduler;
            Architecture = compiler.Architecture;
            TypeSystem   = compiler.TypeSystem;
            TypeLayout   = compiler.TypeLayout;
            Trace        = compiler.CompilerTrace;
            Linker       = compiler.Linker;

            BasicBlocks      = basicBlocks ?? new BasicBlocks();
            LocalStack       = new List <Operand>();
            VirtualRegisters = new VirtualRegisters();

            StackFrame   = Operand.CreateCPURegister(TypeSystem.BuiltIn.Pointer, Architecture.StackFrameRegister);
            StackPointer = Operand.CreateCPURegister(TypeSystem.BuiltIn.Pointer, Architecture.StackPointerRegister);
            Parameters   = new Operand[method.Signature.Parameters.Count + (method.HasThis || method.HasExplicitThis ? 1 : 0)];
            ConstantZero = Architecture.Is32BitPlatform ? CreateConstant((uint)0) : CreateConstant((ulong)0);

            LocalVariables = emptyOperandList;
            ThreadID       = threadID;
            PluggedMethod  = compiler.PlugSystem.GetReplacement(Method);

            IsStopped   = false;
            IsInSSAForm = false;

            MethodData = compiler.CompilerData.GetCompilerMethodData(Method);
            MethodData.Counters.Reset();

            EvaluateParameterOperands();

            CalculateMethodParameterSize();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseMethodCompiler" /> class.
        /// </summary>
        /// <param name="compiler">The assembly compiler.</param>
        /// <param name="method">The method to compile by this instance.</param>
        /// <param name="basicBlocks">The basic blocks.</param>
        /// <param name="threadID">The thread identifier.</param>
        protected BaseMethodCompiler(BaseCompiler compiler, MosaMethod method, BasicBlocks basicBlocks, int threadID)
        {
            Compiler          = compiler;
            Method            = method;
            Type              = method.DeclaringType;
            Scheduler         = compiler.CompilationScheduler;
            Architecture      = compiler.Architecture;
            TypeSystem        = compiler.TypeSystem;
            TypeLayout        = compiler.TypeLayout;
            Trace             = compiler.CompilerTrace;
            Linker            = compiler.Linker;
            BasicBlocks       = basicBlocks ?? new BasicBlocks();
            Pipeline          = new CompilerPipeline();
            StackLayout       = new StackLayout(Architecture, method.Signature.Parameters.Count + (method.HasThis || method.HasExplicitThis ? 1 : 0));
            VirtualRegisters  = new VirtualRegisters(Architecture);
            LocalVariables    = emptyOperandList;
            ThreadID          = threadID;
            DominanceAnalysis = new Dominance(Compiler.CompilerOptions.DominanceAnalysisFactory, BasicBlocks);
            PluggedMethod     = compiler.PlugSystem.GetPlugMethod(Method);
            stop              = false;

            MethodData = compiler.CompilerData.GetCompilerMethodData(Method);
            MethodData.Counters.Clear();

            EvaluateParameterOperands();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseMethodCompiler" /> class.
        /// </summary>
        /// <param name="compiler">The assembly compiler.</param>
        /// <param name="method">The method to compile by this instance.</param>
        /// <param name="basicBlocks">The basic blocks.</param>
        /// <param name="threadID">The thread identifier.</param>
        protected BaseMethodCompiler(BaseCompiler compiler, MosaMethod method, BasicBlocks basicBlocks, int threadID)
        {
            Compiler     = compiler;
            Method       = method;
            Type         = method.DeclaringType;
            Scheduler    = compiler.CompilationScheduler;
            Architecture = compiler.Architecture;
            TypeSystem   = compiler.TypeSystem;
            TypeLayout   = compiler.TypeLayout;
            Trace        = compiler.CompilerTrace;
            Linker       = compiler.Linker;
            BasicBlocks  = basicBlocks ?? new BasicBlocks();
            Pipeline     = new CompilerPipeline();
            LocalStack   = new List <Operand>();

            ConstantZero     = Operand.CreateConstant(0, TypeSystem);
            StackFrame       = Operand.CreateCPURegister(TypeSystem.BuiltIn.Pointer, Architecture.StackFrameRegister);
            StackPointer     = Operand.CreateCPURegister(TypeSystem.BuiltIn.Pointer, Architecture.StackPointerRegister);
            Parameters       = new Operand[method.Signature.Parameters.Count + (method.HasThis || method.HasExplicitThis ? 1 : 0)];
            VirtualRegisters = new VirtualRegisters();
            LocalVariables   = emptyOperandList;
            ThreadID         = threadID;
            PluggedMethod    = compiler.PlugSystem.GetPlugMethod(Method);
            stop             = false;

            MethodData = compiler.CompilerData.GetCompilerMethodData(Method);
            MethodData.Counters.Clear();

            EvaluateParameterOperands();

            CalculateMethodParameterSize();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MethodCompiler" /> class.
        /// </summary>
        /// <param name="compiler">The assembly compiler.</param>
        /// <param name="method">The method to compile by this instance.</param>
        /// <param name="basicBlocks">The basic blocks.</param>
        /// <param name="threadID">The thread identifier.</param>
        public MethodCompiler(Compiler compiler, MosaMethod method, BasicBlocks basicBlocks, int threadID)
        {
            Stopwatch = Stopwatch.StartNew();

            Compiler        = compiler;
            Method          = method;
            MethodScheduler = compiler.MethodScheduler;
            Architecture    = compiler.Architecture;
            TypeSystem      = compiler.TypeSystem;
            TypeLayout      = compiler.TypeLayout;
            Trace           = compiler.CompilerTrace;
            Linker          = compiler.Linker;
            MethodScanner   = compiler.MethodScanner;

            BasicBlocks      = basicBlocks ?? new BasicBlocks();
            LocalStack       = new List <Operand>();
            VirtualRegisters = new VirtualRegisters();

            StackFrame   = Operand.CreateCPURegister(TypeSystem.BuiltIn.Pointer, Architecture.StackFrameRegister);
            StackPointer = Operand.CreateCPURegister(TypeSystem.BuiltIn.Pointer, Architecture.StackPointerRegister);
            Parameters   = new Operand[method.Signature.Parameters.Count + (method.HasThis || method.HasExplicitThis ? 1 : 0)];

            ConstantZero32 = CreateConstant((uint)0);
            ConstantZero64 = CreateConstant((ulong)0);
            ConstantZero   = Architecture.Is32BitPlatform ? ConstantZero32 : ConstantZero64;

            LocalVariables = emptyOperandList;
            ThreadID       = threadID;

            IsStopped            = false;
            IsExecutePipeline    = true;
            IsCILDecodeRequired  = true;
            IsStackFrameRequired = true;
            IsMethodInlined      = false;

            MethodData = compiler.CompilerData.GetMethodData(Method);

            MethodData.Counters.Reset();

            // Both defines the symbol and also clears the data
            Symbol = Linker.DefineSymbol(Method.FullName, SectionKind.Text, 0, 0);

            EvaluateParameterOperands();

            CalculateMethodParameterSize();

            MethodData.Counters.NewCountSkipLock("ExecutionTime.Setup.Ticks", (int)Stopwatch.ElapsedTicks);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Allocates the local variable virtual registers.
        /// </summary>
        /// <param name="locals">The locals.</param>
        public void SetLocalVariables(IList <MosaLocal> locals)
        {
            LocalVariables = new Operand[locals.Count];

            for (int index = 0; index < locals.Count; index++)
            {
                var     local = locals[index];
                Operand operand;

                if (local.Type.IsValueType || local.Type.IsPointer)
                {
                    operand = StackLayout.AddStackLocal(local.Type);
                }
                else
                {
                    var stacktype = local.Type.GetStackType();
                    operand = VirtualRegisters.Allocate(stacktype);
                }

                LocalVariables[index] = operand;
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Splits the long operand.
 /// </summary>
 /// <param name="longOperand">The long operand.</param>
 public void SplitLongOperand(Operand longOperand)
 {
     VirtualRegisters.SplitLongOperand(TypeSystem, longOperand);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates a new virtual register operand.
 /// </summary>
 /// <param name="type">The signature type of the virtual register.</param>
 /// <returns>
 /// An operand, which represents the virtual register.
 /// </returns>
 public Operand CreateVirtualRegister(MosaType type)
 {
     return(VirtualRegisters.Allocate(type));
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MethodCompiler" /> class.
        /// </summary>
        /// <param name="compiler">The assembly compiler.</param>
        /// <param name="method">The method to compile by this instance.</param>
        /// <param name="basicBlocks">The basic blocks.</param>
        /// <param name="threadID">The thread identifier.</param>
        public MethodCompiler(Compiler compiler, MosaMethod method, BasicBlocks basicBlocks, int threadID)
        {
            Stopwatch = Stopwatch.StartNew();

            Compiler        = compiler;
            Method          = method;
            MethodScheduler = compiler.MethodScheduler;
            Architecture    = compiler.Architecture;
            TypeSystem      = compiler.TypeSystem;
            TypeLayout      = compiler.TypeLayout;
            Linker          = compiler.Linker;
            MethodScanner   = compiler.MethodScanner;
            CompilerHooks   = compiler.CompilerHooks;

            NotifyTraceLogHandler = GetMethodInstructionTraceHandler();
            Statistics            = compiler.Statistics;
            IsInSSAForm           = false;

            BasicBlocks      = basicBlocks ?? new BasicBlocks();
            LocalStack       = new List <Operand>();
            VirtualRegisters = new VirtualRegisters();

            Parameters = new Operand[method.Signature.Parameters.Count + (method.HasThis || method.HasExplicitThis ? 1 : 0)];

            ConstantZero32 = CreateConstant((uint)0);
            ConstantZero64 = CreateConstant((ulong)0);
            ConstantZeroR4 = CreateConstant(0.0f);
            ConstantZeroR8 = CreateConstant(0.0d);

            ConstantZero = Architecture.Is32BitPlatform ? ConstantZero32 : ConstantZero64;              // FUTURE: This could just be Constant64 or Constant32 once the caling stage uses the method signature intead of the operand types

            LocalVariables = emptyOperandList;
            ThreadID       = threadID;

            IsStopped           = false;
            IsExecutePipeline   = true;
            IsMethodInlined     = false;
            IsCILStream         = !Method.IsCompilerGenerated;
            HasProtectedRegions = Method.ExceptionHandlers.Count != 0;

            MethodData = Compiler.GetMethodData(Method);

            MethodData.Counters.Reset();
            MethodData.HasCode = false;
            MethodData.Version++;
            MethodData.IsMethodImplementationReplaced = IsMethodPlugged;

            IsStackFrameRequired = MethodData.StackFrameRequired;

            if (Symbol == null)
            {
                Symbol            = Linker.DefineSymbol(Method.FullName, SectionKind.Text, 0, 0);
                Symbol.MethodData = MethodData;             // for debugging
                Symbol.MosaMethod = Method;                 // for debugging
            }
            else
            {
                Symbol.RemovePatches();
            }

            var methodInfo = TypeLayout.__GetMethodInfo(Method);

            MethodData.ParameterSizes     = methodInfo.ParameterSizes;
            MethodData.ParameterOffsets   = methodInfo.ParameterOffsets;
            MethodData.ParameterStackSize = methodInfo.ParameterStackSize;
            MethodData.ReturnSize         = methodInfo.ReturnSize;
            MethodData.ReturnInRegister   = methodInfo.ReturnInRegister;

            EvaluateParameterOperands();

            MethodData.Counters.NewCountSkipLock("ExecutionTime.Setup.Ticks", (int)Stopwatch.ElapsedTicks);
        }