/// <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.º 2
0
        public GreedyRegisterAllocator(BasicBlocks basicBlocks, VirtualRegisters compilerVirtualRegisters, InstructionSet instructionSet, StackLayout stackLayout, BaseArchitecture architecture, CompilerTrace trace)
        {
            this.trace = trace;

            this.basicBlocks = basicBlocks;
            this.instructionSet = instructionSet;
            this.stackLayout = stackLayout;
            this.architecture = architecture;

            this.virtualRegisterCount = compilerVirtualRegisters.Count;
            this.physicalRegisterCount = architecture.RegisterSet.Length;
            this.registerCount = virtualRegisterCount + physicalRegisterCount;

            this.liveIntervalTracks = new List<LiveIntervalTrack>(physicalRegisterCount);
            this.virtualRegisters = new List<VirtualRegister>(registerCount);
            this.extendedBlocks = new List<ExtendedBlock>(basicBlocks.Count);

            stackFrameRegister = architecture.StackFrameRegister;
            stackPointerRegister = architecture.StackPointerRegister;
            programCounter = architecture.ProgramCounter;

            // Setup extended physical registers
            foreach (var physicalRegister in architecture.RegisterSet)
            {
                Debug.Assert(physicalRegister.Index == virtualRegisters.Count);
                Debug.Assert(physicalRegister.Index == liveIntervalTracks.Count);

                bool reserved = (physicalRegister == stackFrameRegister
                    || physicalRegister == stackPointerRegister
                    || (programCounter != null && physicalRegister == programCounter));

                this.virtualRegisters.Add(new VirtualRegister(physicalRegister, reserved));
                this.liveIntervalTracks.Add(new LiveIntervalTrack(physicalRegister, reserved));
            }

            // Setup extended virtual registers
            foreach (var virtualRegister in compilerVirtualRegisters)
            {
                Debug.Assert(virtualRegister.Index == virtualRegisters.Count - physicalRegisterCount + 1);

                this.virtualRegisters.Add(new VirtualRegister(virtualRegister));
            }

            priorityQueue = new SimpleKeyPriorityQueue<LiveInterval>();
            spilledIntervals = new List<LiveInterval>();

            callSlots = new List<SlotIndex>();

            moveHints = new Dictionary<SlotIndex, MoveHint>();

            Start();
        }
Ejemplo n.º 3
0
        public TransformContext(MethodCompiler methodCompiler, TraceLog traceLog = null)
        {
            MethodCompiler = methodCompiler;
            TraceLog       = traceLog;

            VirtualRegisters = MethodCompiler.VirtualRegisters;

            I4 = TypeSystem.BuiltIn.I4;
            I8 = TypeSystem.BuiltIn.I8;
            R4 = TypeSystem.BuiltIn.R4;
            R8 = TypeSystem.BuiltIn.R8;
            O  = TypeSystem.BuiltIn.Object;
        }
 public BasicRegisterAllocator(BasicBlocks basicBlocks, VirtualRegisters compilerVirtualRegisters, StackLayout stackLayout, BaseArchitecture architecture, ITraceFactory traceFactory)
     : base(basicBlocks, compilerVirtualRegisters, stackLayout, architecture, traceFactory)
 {
 }
Ejemplo n.º 5
0
 public Operand AllocateVirtualRegisterObject()
 {
     return(VirtualRegisters.Allocate(O));
 }
Ejemplo n.º 6
0
 public Operand AllocateVirtualRegisterR8()
 {
     return(VirtualRegisters.Allocate(R8));
 }
Ejemplo n.º 7
0
 public Operand AllocateVirtualRegister64()
 {
     return(VirtualRegisters.Allocate(I8));
 }
Ejemplo n.º 8
0
 public Operand AllocateVirtualRegister32()
 {
     return(VirtualRegisters.Allocate(I4));
 }
Ejemplo n.º 9
0
 public Operand AllocateVirtualRegister(MosaType type)
 {
     return(VirtualRegisters.Allocate(type));
 }
 public GreedyRegisterAllocator(BasicBlocks basicBlocks, VirtualRegisters virtualRegisters, BaseArchitecture architecture, AddStackLocalDelegate addStackLocal, Operand stackFrame, ITraceFactory traceFactory)
     : base(basicBlocks, virtualRegisters, architecture, addStackLocal, stackFrame, traceFactory)
 {
 }
Ejemplo n.º 11
0
 public GreedyRegisterAllocator(BasicBlocks basicBlocks, VirtualRegisters virtualRegisters, BaseArchitecture architecture, AddStackLocalDelegate addStackLocal, Operand stackFrame, CreateTraceHandler createTrace)
     : base(basicBlocks, virtualRegisters, architecture, addStackLocal, stackFrame, createTrace)
 {
 }
Ejemplo n.º 12
0
 public BasicRegisterAllocator(BasicBlocks basicBlocks, VirtualRegisters virtualRegisters, BaseArchitecture architecture, AddStackLocalDelegate addStackLocal, Operand stackFrame, ITraceFactory traceFactory)
     : base(basicBlocks, virtualRegisters, architecture, addStackLocal, stackFrame, traceFactory)
 {
 }
Ejemplo n.º 13
0
 public BasicRegisterAllocator(BasicBlocks basicBlocks, VirtualRegisters compilerVirtualRegisters, StackLayout stackLayout, BaseArchitecture architecture, ITraceFactory traceFactory)
     : base(basicBlocks, compilerVirtualRegisters, stackLayout, architecture, traceFactory)
 {
 }
 public BasicRegisterAllocator(BasicBlocks basicBlocks, VirtualRegisters compilerVirtualRegisters, InstructionSet instructionSet, StackLayout stackLayout, BaseArchitecture architecture, SectionTrace trace)
     : base(basicBlocks, compilerVirtualRegisters, instructionSet, stackLayout, architecture, trace)
 {
 }