Beispiel #1
0
        public bool Optimize(ref List <Instruction> src)
        {
            int pushidx;

            if (CurrentIndex == -1)
            {
                return(false);
            }

            Mov OldMov = (Mov)src[CurrentIndex];

            if (OldMov.DestinationIsIndirect && OldMov.SourceIsIndirect)
            {
                return(false);
            }
            // check for same operands
            if (OptimizeUtils.SameOperands(OldMov))
            {
                src[CurrentIndex].Emit = false;
                Optimizer.Optimizations++;
                Optimizer.OptimizationsSize += 3;
                SameMov++;
                return(true);
            }
            return(true);
        }
Beispiel #2
0
        public bool Optimize(ref List <Instruction> src)
        {
            int pushidx;

            if (CurrentIndex == -1)
            {
                return(false);
            }

            Push OldPush = (Push)src[CurrentIndex];

            pushidx = -1;
            Pop OldPop = OptimizeUtils.GetLastPop(src, CurrentIndex - 1, ref pushidx);

            if (OldPop == null)
            {
                return(false);
            }

            // check for same operands
            if (OptimizeUtils.SameOperands(OldPop, OldPush))
            {
                src[CurrentIndex].Emit = false;
                src[pushidx].Emit      = false;
                SamePushPop++;
                Optimizer.OptimizationsSize += 3;
                Optimizer.Optimizations++;
                return(true);
            }



            return(true);
        }
Beispiel #3
0
        public bool Optimize(ref List <Instruction> src)
        {
            int pushidx;

            if (CurrentIndex == -1)
            {
                return(false);
            }

            Pop OldPop = (Pop)src[CurrentIndex];

            pushidx = -1;
            Push OldPush = OptimizeUtils.GetLastPush(src, CurrentIndex - 1, ref pushidx);

            if (OldPush == null)
            {
                return(false);
            }



            // check for same operands
            if (OptimizeUtils.SameOperands(OldPop, OldPush))
            {
                src[CurrentIndex].Emit = false;
                src[pushidx].Emit      = false;
                SamePushPop++;
                Optimizer.OptimizationsSize += 6;
                Optimizer.Optimizations++;
                return(true);
            }
            if (OldPop.DestinationIsIndirect && OldPush.DestinationIsIndirect)
            {
                return(false);
            }


            // Transfer to mov dst,src
            if (OptimizeUtils.CanTransfer(OldPush, OldPop))
            {
                src[CurrentIndex].Emit = false;
                src[pushidx].Emit      = false;

                InstructionWithDestinationAndSourceAndSize mv = new Mov();
                OptimizeUtils.CopyDestination((InstructionWithDestinationAndSize)OldPush, ref mv, true);
                OptimizeUtils.CopyDestination((InstructionWithDestinationAndSize)OldPop, ref mv, false);
                src[CurrentIndex] = mv;
                src[pushidx]      = null;

                PushPopCount++;
                Optimizer.OptimizationsSize += 3;
                Optimizer.Optimizations++;
            }

            return(true);
        }
Beispiel #4
0
        public bool Optimize(ref List <Instruction> src)
        {
            if (CurrentIndex < 1)
            {
                return(false);
            }
            if (!(src[CurrentIndex] is InstructionWithDestinationAndSourceAndSize))
            {
                return(false);
            }
            InstructionWithDestinationAndSourceAndSize Operator = src[CurrentIndex] as InstructionWithDestinationAndSourceAndSize;


            Move       = OptimizeUtils.GetLastMove(src, CurrentIndex - 1, ref MoveIdx);
            SecondMove = OptimizeUtils.GetLastMove(src, MoveIdx - 1, ref SecondMoveIdx);

            if (Move != null && SecondMove == null) // just a single mov
            {
                // optimize
                src[MoveIdx].Emit = false;           // eliminate mov
                OptimizeUtils.CopySource(Move, ref Operator, true);

                Optimizer.Optimizations     += 1;
                Optimizer.OptimizationsSize += 3;
                Optimizations++;
            }
            else if (Move != null && !OptimizeUtils.BothIndirect(Move, SecondMove, true) && !OptimizeUtils.IsImmediate(SecondMove, true)) // just a single mov (s
            {
                // optimize
                src[MoveIdx].Emit       = false; // eliminate mov
                src[SecondMoveIdx].Emit = false; // eliminate mov

                OptimizeUtils.CopySource(Move, ref Operator, true);
                OptimizeUtils.CopySource(SecondMove, ref Operator, false);

                Optimizer.Optimizations     += 2;
                Optimizer.OptimizationsSize += 6;
                Optimizations++;
            }
            else
            {
                return(false);
            }


            return(true);
        }
Beispiel #5
0
        public bool Optimize(ref List <Instruction> src)
        {
            if (CurrentIndex == -1)
            {
                return(false);
            }

            LeftPopIdx = CurrentIndex;
            LeftPop    = src[CurrentIndex] as Pop;
            if (LeftPop != null)
            {
                RightPop = OptimizeUtils.GetLastPop(src, CurrentIndex - 1, ref RightPopIdx);
                if (RightPop != null)
                {
                    Right = OptimizeUtils.GetLastPush(src, RightPopIdx - 1, ref RightIdx);
                    if (Right != null)
                    {
                        Left = OptimizeUtils.GetLastPush(src, RightIdx - 1, ref LeftIdx);
                        if (Left != null)
                        {
                            if ((RightPop.DestinationIsIndirect && Right.DestinationIsIndirect) || (LeftPop.DestinationIsIndirect && Left.DestinationIsIndirect))
                            {
                                return(false);
                            }
                            if (OptimizeUtils.CrossUsage(Left, RightPop) || OptimizeUtils.CrossUsage(Right, LeftPop))
                            {
                                return(false);
                            }
                            if (OptimizeUtils.IsSegment(Left) || OptimizeUtils.IsSegment(LeftPop) || OptimizeUtils.IsSegment(Right) || OptimizeUtils.IsSegment(RightPop))
                            {
                                return(false);
                            }
                            // optimize
                            src[LeftIdx].Emit  = false;
                            src[RightIdx].Emit = false;

                            InstructionWithDestinationAndSourceAndSize mv = new Mov();
                            OptimizeUtils.CopyDestination((InstructionWithDestinationAndSize)Right, ref mv, true);
                            OptimizeUtils.CopyDestination((InstructionWithDestinationAndSize)RightPop, ref mv, false);
                            src[RightPopIdx] = mv;

                            mv = new Mov();
                            OptimizeUtils.CopyDestination((InstructionWithDestinationAndSize)Left, ref mv, true);
                            OptimizeUtils.CopyDestination((InstructionWithDestinationAndSize)LeftPop, ref mv, false);
                            src[LeftPopIdx] = mv;

                            Optimizer.Optimizations += 2;
                            Optimizations++;
                            Optimizer.OptimizationsSize += 6;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }