コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultCallingConvention"/>.
 /// </summary>
 /// <param name="architecture">The architecture of the calling convention.</param>
 public DefaultCallingConvention(BaseArchitecture architecture)
     : base(architecture)
 {
     scratchRegister             = GeneralPurposeRegister.EDX;
     return32BitRegister         = GeneralPurposeRegister.EAX;
     return64BitRegister         = GeneralPurposeRegister.EDX;
     returnFloatingPointRegister = SSE2Register.XMM0;
 }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultCallingConvention"/>.
 /// </summary>
 /// <param name="architecture">The architecture of the calling convention.</param>
 public DefaultCallingConvention(BaseArchitecture architecture)
     : base(architecture)
 {
     // FIXME:
     scratchRegister             = GeneralPurposeRegister.R12;
     return32BitRegister         = GeneralPurposeRegister.R1;
     return64BitRegister         = GeneralPurposeRegister.R2;
     returnFloatingPointRegister = GeneralPurposeRegister.R1;
 }
コード例 #3
0
ファイル: GCEnvironment.cs プロジェクト: arakis/MOSA-Project
        public GCEnvironment(BasicBlocks basicBlocks, BaseArchitecture architecture, List <Operand> localStack)
        {
            BasicBlocks         = basicBlocks;
            StackLocalReference = new bool[localStack.Count];

            PhysicalRegisterCount = architecture.RegisterSet.Length;

            CollectReferenceStackObjects(localStack);

            IndexCount = PhysicalRegisterCount + stackLookup.Count;
        }
コード例 #4
0
ファイル: MoveResolver.cs プロジェクト: tea/MOSA-Project
        protected void CreateMemoryMoves(BaseArchitecture architecture, Context context)
        {
            for (int i = 0; i < moves.Count; i++)
            {
                var move = moves[i];

                if (!(move.Source.IsCPURegister || move.Destination.IsCPURegister))
                    continue;

                architecture.InsertMoveInstruction(context, move.Destination, move.Source);
            }
        }
コード例 #5
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();
        }
コード例 #6
0
        public void InsertResolvingMoves(BaseArchitecture architecture, Operand stackFrame)
        {
            if (Moves.Count == 0)
            {
                return;
            }

            var moves = GetResolveMoves();

            var context = new Context(Index);

            if (Before)
            {
                // TODO: Generalize XXXX
                context.GotoPrevious();

                // Note: This won't work for expanded switch statements... but we can't insert into the end of those blocks anyway
                while (context.IsEmpty ||
                       context.Instruction.FlowControl == FlowControl.UnconditionalBranch ||
                       context.Instruction.FlowControl == FlowControl.ConditionalBranch ||
                       context.Instruction.FlowControl == FlowControl.Return)
                {
                    context.GotoPrevious();
                }
            }

            foreach (var move in moves)
            {
                Debug.Assert(move.Destination.IsCPURegister);

                switch (move.Value)
                {
                case ResolvedMoveType.Move: architecture.InsertMoveInstruction(context, move.Destination, move.Source); break;

                case ResolvedMoveType.Exchange: architecture.InsertExchangeInstruction(context, move.Destination, move.Source); break;

                case ResolvedMoveType.Load: architecture.InsertLoadInstruction(context, move.Destination, stackFrame, move.Source); break;
                }

                context.Marked = true;
            }

            Debug.Assert(Moves.Count == 0);
        }
コード例 #7
0
        public void InsertResolvingMoves(BaseArchitecture architecture)
        {
            if (Moves.Count == 0)
            {
                return;
            }

            var moves = GetResolveMoves();

            var context = new Context(Index);

            if (Before)
            {
                context.GotoPrevious();

                // Note: This won't work for expanded switch statements... but we can't insert into the end of those blocks anyway
                while (context.IsEmpty || context.Instruction.FlowControl == FlowControl.UnconditionalBranch || context.Instruction.FlowControl == FlowControl.ConditionalBranch || context.Instruction.FlowControl == FlowControl.Return)
                {
                    context.GotoPrevious();
                }
            }

            foreach (var move in moves)
            {
                if (move.Value == ResolvedMoveType.Move)
                {
                    architecture.InsertMoveInstruction(context, move.Destination, move.Source);
                }
                else
                {
                    architecture.InsertExchangeInstruction(context, move.Destination, move.Source);
                }

                context.Marked = true;
            }

            Debug.Assert(Moves.Count == 0);
        }
コード例 #8
0
ファイル: MoveResolver.cs プロジェクト: tea/MOSA-Project
        public void InsertResolvingMoves(BaseArchitecture architecture, InstructionSet instructionSet)
        {
            if (moves.Count == 0)
                return;

            Context context = new Context(instructionSet, Source == Anchor ? Source.EndIndex : Destination.StartIndex);

            if (Source == Anchor)
            {
                context.GotoPrevious();

                // Note: This won't work for expanded switch statements... but we can't insert into the end of those blocks anyway
                while (context.IsEmpty || context.Instruction.FlowControl == FlowControl.UnconditionalBranch || context.Instruction.FlowControl == FlowControl.ConditionalBranch || context.Instruction.FlowControl == FlowControl.Return)
                {
                    context.GotoPrevious();
                }
            }

            TrySimpleMoves(architecture, context);
            TryExchange(architecture, context);
            CreateMemoryMoves(architecture, context);

            Debug.Assert(moves.Count == 0);
        }
コード例 #9
0
 public GreedyRegisterAllocator(BasicBlocks basicBlocks, VirtualRegisters virtualRegisters, BaseArchitecture architecture, AddStackLocalDelegate addStackLocal, Operand stackFrame, CreateTraceHandler createTrace)
     : base(basicBlocks, virtualRegisters, architecture, addStackLocal, stackFrame, createTrace)
 {
 }
コード例 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseCallingConvention32Bit"/>.
 /// </summary>
 /// <param name="architecture">The architecture of the calling convention.</param>
 public BaseCallingConvention32Bit(BaseArchitecture architecture)
     : base(architecture)
 {
 }
コード例 #11
0
 public GreedyRegisterAllocator(BasicBlocks basicBlocks, VirtualRegisters virtualRegisters, BaseArchitecture architecture, AddStackLocalDelegate addStackLocal, Operand stackFrame, ITraceFactory traceFactory)
     : base(basicBlocks, virtualRegisters, architecture, addStackLocal, stackFrame, traceFactory)
 {
 }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseCallingConvention32Bit"/>.
 /// </summary>
 /// <param name="architecture">The architecture of the calling convention.</param>
 public BaseCallingConvention32Bit(BaseArchitecture architecture)
     : base(architecture)
 {
 }
コード例 #13
0
 public RegisterAllocatorEnvironment(BasicBlocks basicBlocks, BaseArchitecture architecture)
 {
     BasicBlocks           = basicBlocks;
     PhysicalRegisterCount = architecture.RegisterSet.Length;
 }
コード例 #14
0
 public void Add(BaseArchitecture architecture)
 {
     Add(architecture.RegisterSet);
     Add(architecture.Instructions);
 }
コード例 #15
0
 public BasicRegisterAllocator(BasicBlocks basicBlocks, VirtualRegisters compilerVirtualRegisters, InstructionSet instructionSet, StackLayout stackLayout, BaseArchitecture architecture, SectionTrace trace)
     : base(basicBlocks, compilerVirtualRegisters, instructionSet, stackLayout, architecture, trace)
 {
 }
コード例 #16
0
ファイル: MoveResolver.cs プロジェクト: tea/MOSA-Project
        protected void TryExchange(BaseArchitecture architecture, Context context)
        {
            bool loop = true;

            while (loop)
            {
                loop = false;

                for (int i = 0; i < moves.Count; i++)
                {
                    var move = moves[i];

                    if (!(move.Source.IsCPURegister || move.Destination.IsCPURegister))
                        continue;

                    int other = FindIndex(move.Destination.Register, true);

                    if (other == -1)
                        continue;

                    architecture.InsertExchangeInstruction(context, moves[other].Source, move.Source);
                    context.Marked = true;
                    moves[other].Source = move.Source;
                    moves.RemoveAt(i);

                    if (other > i)
                        other--;

                    if (moves[other].Source.Register == moves[other].Destination.Register)
                        moves.RemoveAt(other);

                    loop = true;
                }
            }
        }
コード例 #17
0
 public BasicRegisterAllocator(BasicBlocks basicBlocks, VirtualRegisters compilerVirtualRegisters, StackLayout stackLayout, BaseArchitecture architecture, ITraceFactory traceFactory)
     : base(basicBlocks, compilerVirtualRegisters, stackLayout, architecture, traceFactory)
 {
 }
コード例 #18
0
 public BasicRegisterAllocator(BasicBlocks basicBlocks, VirtualRegisters compilerVirtualRegisters, StackLayout stackLayout, BaseArchitecture architecture, ITraceFactory traceFactory)
     : base(basicBlocks, compilerVirtualRegisters, stackLayout, architecture, traceFactory)
 {
 }
コード例 #19
0
 public BasicRegisterAllocator(BasicBlocks basicBlocks, VirtualRegisters virtualRegisters, BaseArchitecture architecture, AddStackLocalDelegate addStackLocal, Operand stackFrame, ITraceFactory traceFactory)
     : base(basicBlocks, virtualRegisters, architecture, addStackLocal, stackFrame, traceFactory)
 {
 }