当前位置: 首页>>代码示例>>C#>>正文


C# InstructionNode.SetInstruction方法代码示例

本文整理汇总了C#中InstructionNode.SetInstruction方法的典型用法代码示例。如果您正苦于以下问题:C# InstructionNode.SetInstruction方法的具体用法?C# InstructionNode.SetInstruction怎么用?C# InstructionNode.SetInstruction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在InstructionNode的用法示例。


在下文中一共展示了InstructionNode.SetInstruction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SimplifyExtendedMove

        /// <summary>
        /// Simplifies sign/zero extended move
        /// </summary>
        /// <param name="node">The node.</param>
        private void SimplifyExtendedMove(InstructionNode node)
        {
            if (node.IsEmpty)
                return;

            if (!(node.Instruction == IRInstruction.ZeroExtendedMove || node.Instruction == IRInstruction.SignExtendedMove))
                return;

            if (!node.Result.IsVirtualRegister || !node.Operand1.IsVirtualRegister)
                return;

            if (!((NativePointerSize == 4 && node.Result.IsInt && (node.Operand1.IsInt || node.Operand1.IsU || node.Operand1.IsI)) ||
                (NativePointerSize == 4 && node.Operand1.IsInt && (node.Result.IsInt || node.Result.IsU || node.Result.IsI)) ||
                (NativePointerSize == 8 && node.Result.IsLong && (node.Operand1.IsLong || node.Operand1.IsU || node.Operand1.IsI)) ||
                (NativePointerSize == 8 && node.Operand1.IsLong && (node.Result.IsLong || node.Result.IsU || node.Result.IsI))))
                return;

            AddOperandUsageToWorkList(node);
            if (trace.Active) trace.Log("*** SimplifyExtendedMove");
            if (trace.Active) trace.Log("BEFORE:\t" + node.ToString());
            node.SetInstruction(IRInstruction.Move, node.Result, node.Operand1);
            simplifyExtendedMoveCount++;
            if (trace.Active) trace.Log("AFTER: \t" + node.ToString());
            changeCount++;
        }
开发者ID:Profi-Concept,项目名称:MOSA-Project,代码行数:29,代码来源:IROptimizationStage.cs

示例2: ArithmeticSimplificationDivision

        /// <summary>
        /// Strength reduction for division when one of the constants is zero or one
        /// </summary>
        /// <param name="node">The node.</param>
        private void ArithmeticSimplificationDivision(InstructionNode node)
        {
            if (!(node.Instruction == IRInstruction.DivSigned || node.Instruction == IRInstruction.DivUnsigned))
                return;

            if (!node.Result.IsVirtualRegister)
                return;

            Operand result = node.Result;
            Operand op1 = node.Operand1;
            Operand op2 = node.Operand2;

            if (!op2.IsResolvedConstant || op2.IsConstantZero)
            {
                // Possible divide by zero
                return;
            }

            if (op1.IsResolvedConstant && op1.IsConstantZero)
            {
                AddOperandUsageToWorkList(node);
                if (trace.Active) trace.Log("*** ArithmeticSimplificationDivision");
                if (trace.Active) trace.Log("BEFORE:\t" + node.ToString());
                node.SetInstruction(IRInstruction.MoveInteger, result, ConstantZero);
                arithmeticSimplificationDivisionCount++;
                changeCount++;
                if (trace.Active) trace.Log("AFTER: \t" + node.ToString());
                return;
            }

            if (op2.IsResolvedConstant && op2.IsConstantOne)
            {
                AddOperandUsageToWorkList(node);
                if (trace.Active) trace.Log("*** ArithmeticSimplificationDivision");
                if (trace.Active) trace.Log("BEFORE:\t" + node.ToString());
                node.SetInstruction(IRInstruction.MoveInteger, result, op1);
                arithmeticSimplificationDivisionCount++;
                changeCount++;
                if (trace.Active) trace.Log("AFTER: \t" + node.ToString());
                return;
            }

            if (node.Instruction == IRInstruction.DivUnsigned && IsPowerOfTwo(op2.ConstantUnsignedLongInteger))
            {
                int shift = GetPowerOfTwo(op2.ConstantUnsignedLongInteger);

                if (shift < 32)
                {
                    AddOperandUsageToWorkList(node);
                    if (trace.Active) trace.Log("*** ArithmeticSimplificationDivision");
                    if (trace.Active) trace.Log("BEFORE:\t" + node.ToString());
                    node.SetInstruction(IRInstruction.ShiftRight, result, op1, Operand.CreateConstant(TypeSystem, (int)shift));
                    arithmeticSimplificationDivisionCount++;
                    changeCount++;
                    if (trace.Active) trace.Log("AFTER: \t" + node.ToString());
                    return;
                }
            }
        }
开发者ID:tgiphil,项目名称:MOSA-Project,代码行数:63,代码来源:IROptimizationStage.cs

示例3: SimpleForwardCopyPropagation

        /// <summary>
        /// Simple copy propagation.
        /// </summary>
        /// <param name="node">The node.</param>
        private void SimpleForwardCopyPropagation(InstructionNode node)
        {
            if (node.IsEmpty)
                return;

            if (node.Instruction != IRInstruction.Move)
                return;

            if (!node.Result.IsVirtualRegister)
                return;

            if (node.Result.Definitions.Count != 1)
                return;

            if (node.Operand1.Definitions.Count != 1)
                return;

            if (node.Operand1.IsConstant)
                return;

            if (!node.Operand1.IsVirtualRegister)
                return;

            // If the pointer or reference types are different, we can not copy propagation because type information would be lost.
            // Also if the operand sign is different, we cannot do it as it requires a signed/unsigned extended move, not a normal move
            if (!CanCopyPropagation(node.Result, node.Operand1))
                return;

            Operand destination = node.Result;
            Operand source = node.Operand1;

            if (ContainsAddressOf(destination))
                return;

            // for each statement T that uses operand, substituted c in statement T
            AddOperandUsageToWorkList(node);

            foreach (var useNode in destination.Uses.ToArray())
            {
                for (int i = 0; i < useNode.OperandCount; i++)
                {
                    var operand = useNode.GetOperand(i);

                    if (destination == operand)
                    {
                        if (trace.Active) trace.Log("*** SimpleForwardCopyPropagation");
                        if (trace.Active) trace.Log("BEFORE:\t" + useNode.ToString());
                        useNode.SetOperand(i, source);
                        simpleForwardCopyPropagationCount++;
                        changeCount++;
                        if (trace.Active) trace.Log("AFTER: \t" + useNode.ToString());
                    }
                }
            }

            Debug.Assert(destination.Uses.Count == 0);

            if (trace.Active) trace.Log("REMOVED:\t" + node.ToString());
            AddOperandUsageToWorkList(node);
            node.SetInstruction(IRInstruction.Nop);
            instructionsRemovedCount++;
            changeCount++;
        }
开发者ID:Profi-Concept,项目名称:MOSA-Project,代码行数:67,代码来源:IROptimizationStage.cs

示例4: ArithmeticSimplificationSubtraction

        /// <summary>
        /// Simplifies subtraction where both operands are the same
        /// </summary>
        /// <param name="node">The node.</param>
        private void ArithmeticSimplificationSubtraction(InstructionNode node)
        {
            if (node.IsEmpty)
                return;

            if (!(node.Instruction == IRInstruction.SubSigned || node.Instruction == IRInstruction.SubUnsigned))
                return;

            if (!node.Result.IsVirtualRegister)
                return;

            Operand result = node.Result;
            Operand op1 = node.Operand1;
            Operand op2 = node.Operand2;

            if (op1 != op2)
                return;

            AddOperandUsageToWorkList(node);
            if (trace.Active) trace.Log("*** ArithmeticSimplificationSubtraction");
            if (trace.Active) trace.Log("BEFORE:\t" + node.ToString());
            node.SetInstruction(IRInstruction.Move, result, Operand.CreateConstant(node.Result.Type, 0));
            arithmeticSimplificationSubtractionCount++;
            changeCount++;
        }
开发者ID:Profi-Concept,项目名称:MOSA-Project,代码行数:29,代码来源:IROptimizationStage.cs

示例5: ConstantFoldingIntegerOperations

        /// <summary>
        /// Folds an integer operation on constants
        /// </summary>
        /// <param name="node">The node.</param>
        private void ConstantFoldingIntegerOperations(InstructionNode node)
        {
            if (node.IsEmpty)
                return;

            if (!(node.Instruction == IRInstruction.AddSigned || node.Instruction == IRInstruction.AddUnsigned ||
                  node.Instruction == IRInstruction.SubSigned || node.Instruction == IRInstruction.SubUnsigned ||
                  node.Instruction == IRInstruction.LogicalAnd || node.Instruction == IRInstruction.LogicalOr ||
                  node.Instruction == IRInstruction.LogicalXor ||
                  node.Instruction == IRInstruction.MulSigned || node.Instruction == IRInstruction.MulUnsigned ||
                  node.Instruction == IRInstruction.DivSigned || node.Instruction == IRInstruction.DivUnsigned ||
                  node.Instruction == IRInstruction.ArithmeticShiftRight ||
                  node.Instruction == IRInstruction.ShiftLeft || node.Instruction == IRInstruction.ShiftRight))
                return;

            if (!node.Result.IsVirtualRegister)
                return;

            Operand result = node.Result;
            Operand op1 = node.Operand1;
            Operand op2 = node.Operand2;

            if (!op1.IsConstant || !op2.IsConstant)
                return;

            // Divide by zero!
            if ((node.Instruction == IRInstruction.DivSigned || node.Instruction == IRInstruction.DivUnsigned) && op2.IsConstant && op2.IsConstantZero)
                return;

            Operand constant = null;

            if (node.Instruction == IRInstruction.AddSigned || node.Instruction == IRInstruction.AddUnsigned)
            {
                constant = Operand.CreateConstant(result.Type, op1.ConstantUnsignedLongInteger + op2.ConstantUnsignedLongInteger);
            }
            else if (node.Instruction == IRInstruction.SubSigned || node.Instruction == IRInstruction.SubUnsigned)
            {
                constant = Operand.CreateConstant(result.Type, op1.ConstantUnsignedLongInteger - op2.ConstantUnsignedLongInteger);
            }
            else if (node.Instruction == IRInstruction.LogicalAnd)
            {
                constant = Operand.CreateConstant(result.Type, op1.ConstantUnsignedLongInteger & op2.ConstantUnsignedLongInteger);
            }
            else if (node.Instruction == IRInstruction.LogicalOr)
            {
                constant = Operand.CreateConstant(result.Type, op1.ConstantUnsignedLongInteger | op2.ConstantUnsignedLongInteger);
            }
            else if (node.Instruction == IRInstruction.LogicalXor)
            {
                constant = Operand.CreateConstant(result.Type, op1.ConstantUnsignedLongInteger ^ op2.ConstantUnsignedLongInteger);
            }
            else if (node.Instruction == IRInstruction.MulSigned || node.Instruction == IRInstruction.MulUnsigned)
            {
                constant = Operand.CreateConstant(result.Type, op1.ConstantUnsignedLongInteger * op2.ConstantUnsignedLongInteger);
            }
            else if (node.Instruction == IRInstruction.DivUnsigned)
            {
                constant = Operand.CreateConstant(result.Type, op1.ConstantUnsignedLongInteger / op2.ConstantUnsignedLongInteger);
            }
            else if (node.Instruction == IRInstruction.DivSigned)
            {
                constant = Operand.CreateConstant(result.Type, op1.ConstantSignedLongInteger / op2.ConstantSignedLongInteger);
            }
            else if (node.Instruction == IRInstruction.ArithmeticShiftRight)
            {
                constant = Operand.CreateConstant(result.Type, ((long)op1.ConstantUnsignedLongInteger) >> (int)op2.ConstantUnsignedLongInteger);
            }
            else if (node.Instruction == IRInstruction.ShiftRight)
            {
                constant = Operand.CreateConstant(result.Type, op1.ConstantUnsignedLongInteger >> (int)op2.ConstantUnsignedLongInteger);
            }
            else if (node.Instruction == IRInstruction.ShiftLeft)
            {
                constant = Operand.CreateConstant(result.Type, op1.ConstantUnsignedLongInteger << (int)op2.ConstantUnsignedLongInteger);
            }

            if (constant == null)
                return;

            AddOperandUsageToWorkList(node);
            if (trace.Active) trace.Log("*** ConstantFoldingIntegerOperations");
            if (trace.Active) trace.Log("BEFORE:\t" + node.ToString());
            node.SetInstruction(IRInstruction.Move, node.Result, constant);
            constantFoldingIntegerOperationsCount++;
            changeCount++;
            if (trace.Active) trace.Log("AFTER: \t" + node.ToString());
        }
开发者ID:Profi-Concept,项目名称:MOSA-Project,代码行数:91,代码来源:IROptimizationStage.cs

示例6: ArithmeticSimplificationAdditionAndSubstraction

        /// <summary>
        /// Strength reduction for integer addition when one of the constants is zero
        /// </summary>
        /// <param name="node">The node.</param>
        private void ArithmeticSimplificationAdditionAndSubstraction(InstructionNode node)
        {
            if (node.IsEmpty)
                return;

            if (!(node.Instruction == IRInstruction.AddSigned || node.Instruction == IRInstruction.AddUnsigned
                || node.Instruction == IRInstruction.SubSigned || node.Instruction == IRInstruction.SubUnsigned))
                return;

            if (!node.Result.IsVirtualRegister)
                return;

            Operand result = node.Result;
            Operand op1 = node.Operand1;
            Operand op2 = node.Operand2;

            if (op2.IsConstant && !op1.IsConstant && op2.IsConstantZero)
            {
                AddOperandUsageToWorkList(node);
                if (trace.Active) trace.Log("*** ArithmeticSimplificationAdditionAndSubstraction");
                if (trace.Active) trace.Log("BEFORE:\t" + node.ToString());
                node.SetInstruction(IRInstruction.Move, result, op1);
                if (trace.Active) trace.Log("AFTER: \t" + node.ToString());
                arithmeticSimplificationAdditionAndSubstractionCount++;
                changeCount++;
                return;
            }
        }
开发者ID:Profi-Concept,项目名称:MOSA-Project,代码行数:32,代码来源:IROptimizationStage.cs

示例7: ArithmeticSimplificationMultiplication

        /// <summary>
        /// Strength reduction for multiplication when one of the constants is zero or one
        /// </summary>
        /// <param name="node">The node.</param>
        private void ArithmeticSimplificationMultiplication(InstructionNode node)
        {
            if (node.IsEmpty)
                return;

            if (!(node.Instruction == IRInstruction.MulSigned || node.Instruction == IRInstruction.MulUnsigned))
                return;

            if (!node.Result.IsVirtualRegister)
                return;

            if (!node.Operand2.IsConstant)
                return;

            Operand result = node.Result;
            Operand op1 = node.Operand1;
            Operand op2 = node.Operand2;

            if (op2.IsConstantZero)
            {
                AddOperandUsageToWorkList(node);
                if (trace.Active) trace.Log("*** ArithmeticSimplificationMultiplication");
                if (trace.Active) trace.Log("BEFORE:\t" + node.ToString());
                node.SetInstruction(IRInstruction.Move, result, Operand.CreateConstant(node.Result.Type, 0));
                arithmeticSimplificationMultiplicationCount++;
                if (trace.Active) trace.Log("AFTER: \t" + node.ToString());
                changeCount++;
                return;
            }

            if (op2.IsConstantOne)
            {
                AddOperandUsageToWorkList(node);
                if (trace.Active) trace.Log("*** ArithmeticSimplificationMultiplication");
                if (trace.Active) trace.Log("BEFORE:\t" + node.ToString());
                node.SetInstruction(IRInstruction.Move, result, op1);
                arithmeticSimplificationMultiplicationCount++;
                if (trace.Active) trace.Log("AFTER: \t" + node.ToString());
                changeCount++;
                return;
            }

            if (IsPowerOfTwo(op2.ConstantUnsignedLongInteger))
            {
                uint shift = GetPowerOfTwo(op2.ConstantUnsignedLongInteger);

                if (shift < 32)
                {
                    AddOperandUsageToWorkList(node);
                    if (trace.Active) trace.Log("*** ArithmeticSimplificationMultiplication");
                    if (trace.Active) trace.Log("BEFORE:\t" + node.ToString());
                    node.SetInstruction(IRInstruction.ShiftLeft, result, op1, Operand.CreateConstant(TypeSystem, (int)shift));
                    arithmeticSimplificationMultiplicationCount++;
                    if (trace.Active) trace.Log("AFTER: \t" + node.ToString());
                    changeCount++;
                    return;
                }
            }
        }
开发者ID:Profi-Concept,项目名称:MOSA-Project,代码行数:63,代码来源:IROptimizationStage.cs

示例8: ConstantFoldingPhi

        /// <summary>
        /// Folds the constant phi instruction.
        /// </summary>
        /// <param name="node">The node.</param>
        private void ConstantFoldingPhi(InstructionNode node)
        {
            if (node.IsEmpty)
                return;

            if (node.Instruction != IRInstruction.Phi)
                return;

            if (node.Result.Definitions.Count != 1)
                return;

            if (!node.Result.IsInteger)
                return;

            Operand operand1 = node.Operand1;
            Operand result = node.Result;

            foreach (var operand in node.Operands)
            {
                if (!operand.IsConstant)
                    return;

                if (operand.ConstantUnsignedLongInteger != operand1.ConstantUnsignedLongInteger)
                    return;
            }

            if (trace.Active) trace.Log("*** FoldConstantPhiInstruction");
            if (trace.Active) trace.Log("BEFORE:\t" + node.ToString());
            AddOperandUsageToWorkList(node);
            node.SetInstruction(IRInstruction.Move, result, operand1);
            if (trace.Active) trace.Log("AFTER: \t" + node.ToString());
            constantFoldingPhiCount++;
            changeCount++;
        }
开发者ID:Profi-Concept,项目名称:MOSA-Project,代码行数:38,代码来源:IROptimizationStage.cs

示例9: DeadCodeElimination

        /// <summary>
        /// Removes the useless move and dead code
        /// </summary>
        /// <param name="node">The node.</param>
        private void DeadCodeElimination(InstructionNode node)
        {
            if (node.IsEmpty)
                return;

            if (node.ResultCount != 1)
                return;

            if (!node.Result.IsVirtualRegister)
                return;

            if (node.Result.Definitions.Count != 1)
                return;

            if (node.Instruction == IRInstruction.Call || node.Instruction == IRInstruction.IntrinsicMethodCall)
                return;

            if (node.Instruction == IRInstruction.Move && node.Operand1.IsVirtualRegister && node.Operand1 == node.Result)
            {
                if (trace.Active) trace.Log("*** DeadCodeElimination");
                if (trace.Active) trace.Log("REMOVED:\t" + node.ToString());
                AddOperandUsageToWorkList(node);
                node.SetInstruction(IRInstruction.Nop);
                instructionsRemovedCount++;
                deadCodeEliminationCount++;
                changeCount++;
                return;
            }

            if (node.Result.Uses.Count != 0)
                return;

            if (trace.Active) trace.Log("*** DeadCodeElimination");
            if (trace.Active) trace.Log("REMOVED:\t" + node.ToString());
            AddOperandUsageToWorkList(node);
            node.SetInstruction(IRInstruction.Nop);
            instructionsRemovedCount++;
            deadCodeEliminationCount++;
            changeCount++;
            return;
        }
开发者ID:Profi-Concept,项目名称:MOSA-Project,代码行数:45,代码来源:IROptimizationStage.cs

示例10: RemoveUselessPhi

        private void RemoveUselessPhi(InstructionNode node)
        {
            if (node.IsEmpty)
                return;

            if (node.Instruction != IRInstruction.Phi)
                return;

            if (node.Result.Definitions.Count != 1)
                return;

            var result = node.Result;

            foreach (var use in node.Result.Uses)
            {
                if (use != node)
                    return;
            }

            AddOperandUsageToWorkList(node);
            if (trace.Active) trace.Log("REMOVED:\t" + node.ToString());
            node.SetInstruction(IRInstruction.Nop);
            removeUselessPhiCount++;
        }
开发者ID:yonglehou,项目名称:MOSA-Project,代码行数:24,代码来源:IROptimizationStage.cs

示例11: Run

        protected override void Run()
        {
            // No CIL decoding if this is a linker generated method
            if (MethodCompiler.Method.IsLinkerGenerated)
                return;

            if (IsPlugged)
            {
                var plugMethod = MethodCompiler.Compiler.PlugSystem.GetPlugMethod(MethodCompiler.Method);

                Debug.Assert(plugMethod != null);

                var plugSymbol = Operand.CreateSymbolFromMethod(TypeSystem, plugMethod);
                var context = CreateNewBlockContext(-1);
                context.AppendInstruction(IRInstruction.Jmp, null, plugSymbol);
                BasicBlocks.AddHeadBlock(context.Block);
                return;
            }

            if (MethodCompiler.Method.Code.Count == 0)
            {
                if (DelegatePatcher.PatchDelegate(MethodCompiler))
                    return;

                MethodCompiler.Stop();
                return;
            }

            if (MethodCompiler.Compiler.CompilerOptions.EnableStatistics)
            {
                counts = new int[CILInstruction.MaxOpCodeValue];
            }

            MethodCompiler.SetLocalVariables(MethodCompiler.Method.LocalVariables);

            // Create the prologue block
            var prologue = CreateNewBlock(BasicBlock.PrologueLabel);
            BasicBlocks.AddHeadBlock(prologue);

            var jmpNode = new InstructionNode();
            jmpNode.Label = BasicBlock.PrologueLabel;
            jmpNode.Block = prologue;
            prologue.First.Insert(jmpNode);

            // Create starting block
            var startBlock = CreateNewBlock(0);

            jmpNode.SetInstruction(IRInstruction.Jmp, startBlock);

            DecodeInstructionTargets();

            DecodeProtectedRegionTargets();

            /* Decode the instructions */
            DecodeInstructions();

            foreach (var block in BasicBlocks)
            {
                if (!block.HasPreviousBlocks && !BasicBlocks.HeadBlocks.Contains(block))
                {
                    // block was targeted (probably by an leave instruction within a protected region)
                    BasicBlocks.AddHeadBlock(block);
                }
            }

            // This makes it easier to review --- it's not necessary
            BasicBlocks.OrderByLabel();
        }
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:68,代码来源:CILDecodingStage.cs

示例12: Inline

        protected void Inline(InstructionNode callNode, BasicBlocks blocks)
        {
            var mapBlocks = new Dictionary<BasicBlock, BasicBlock>(blocks.Count);
            var map = new Dictionary<Operand, Operand>();

            var nextBlock = Split(callNode);

            // create basic blocks
            foreach (var block in blocks)
            {
                var newBlock = CreateNewBlock();
                mapBlocks.Add(block, newBlock);
            }

            // copy instructions
            foreach (var block in blocks)
            {
                var newBlock = mapBlocks[block];

                for (var node = block.First.Next; !node.IsBlockEndInstruction; node = node.Next)
                {
                    if (node.IsEmpty)
                        continue;

                    if (node.Instruction == IRInstruction.Prologue)
                        continue;

                    if (node.Instruction == IRInstruction.Epilogue)
                        continue;

                    if (node.Instruction == IRInstruction.Return)
                    {
                        if (callNode.Result != null)
                        {
                            var newOp = Map(node.Operand1, map, callNode);
                            newBlock.BeforeLast.Insert(new InstructionNode(IRInstruction.Move, callNode.Result, newOp));
                        }
                        newBlock.BeforeLast.Insert(new InstructionNode(IRInstruction.Jmp, nextBlock));

                        continue;
                    }

                    var newNode = new InstructionNode(node.Instruction, node.OperandCount, node.ResultCount);
                    newNode.Size = node.Size;
                    newNode.ConditionCode = node.ConditionCode;

                    if (node.BranchTargets != null)
                    {
                        // copy targets
                        foreach (var target in node.BranchTargets)
                        {
                            newNode.AddBranchTarget(mapBlocks[target]);
                        }
                    }

                    // copy results
                    for (int i = 0; i < node.ResultCount; i++)
                    {
                        var op = node.GetResult(i);

                        var newOp = Map(op, map, callNode);

                        newNode.SetResult(i, newOp);
                    }

                    // copy operands
                    for (int i = 0; i < node.OperandCount; i++)
                    {
                        var op = node.GetOperand(i);

                        var newOp = Map(op, map, callNode);

                        newNode.SetOperand(i, newOp);
                    }

                    // copy other
                    if (node.MosaType != null)
                        newNode.MosaType = node.MosaType;
                    if (node.MosaField != null)
                        newNode.MosaField = node.MosaField;
                    if (node.InvokeMethod != null)
                        newNode.InvokeMethod = node.InvokeMethod;

                    newBlock.BeforeLast.Insert(newNode);
                }
            }

            callNode.SetInstruction(IRInstruction.Jmp, mapBlocks[blocks.PrologueBlock]);
        }
开发者ID:yonglehou,项目名称:MOSA-Project,代码行数:89,代码来源:InlineStage.cs

示例13: ArithmeticSimplificationRemUnsignedModulus

        /// <summary>
        /// Arithmetics the simplification rem unsigned modulus.
        /// </summary>
        /// <param name="node">The node.</param>
        private void ArithmeticSimplificationRemUnsignedModulus(InstructionNode node)
        {
            if (node.IsEmpty)
                return;

            if (!(node.Instruction == IRInstruction.RemUnsigned))
                return;

            if (!node.Result.IsVirtualRegister)
                return;

            if (!node.Operand2.IsConstant)
                return;

            if (node.Operand2.ConstantUnsignedLongInteger == 0)
                return;

            if (!IsPowerOfTwo(node.Operand2.ConstantUnsignedLongInteger))
                return;

            Operand result = node.Result;
            Operand op1 = node.Operand1;
            Operand op2 = node.Operand2;

            if (op2.ConstantUnsignedLongInteger == 0)
            {
                AddOperandUsageToWorkList(node);
                if (trace.Active) trace.Log("*** ArithmeticSimplificationRemUnsignedModulus");
                if (trace.Active) trace.Log("BEFORE:\t" + node.ToString());
                node.SetInstruction(IRInstruction.Move, result, Operand.CreateConstant(TypeSystem, 0));
                arithmeticSimplificationModulus++;
                changeCount++;
                if (trace.Active) trace.Log("AFTER: \t" + node.ToString());
                return;
            }

            int power = GetPowerOfTwo(op2.ConstantUnsignedLongInteger);

            var mask = (1 << power) - 1;

            var constant = Operand.CreateConstant(TypeSystem, mask);

            AddOperandUsageToWorkList(node);
            if (trace.Active) trace.Log("*** ArithmeticSimplificationRemUnsignedModulus");
            if (trace.Active) trace.Log("BEFORE:\t" + node.ToString());
            node.SetInstruction(IRInstruction.LogicalAnd, result, op1, constant);
            arithmeticSimplificationModulus++;
            changeCount++;
            if (trace.Active) trace.Log("AFTER: \t" + node.ToString());
            return;
        }
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:55,代码来源:IROptimizationStage.cs

示例14: ArithmeticSimplificationRemSignedModulus

        /// <summary>
        /// Arithmetics the simplification rem signed modulus.
        /// </summary>
        /// <param name="node">The node.</param>
        private void ArithmeticSimplificationRemSignedModulus(InstructionNode node)
        {
            if (node.IsEmpty)
                return;

            if (!(node.Instruction == IRInstruction.RemSigned))
                return;

            if (!node.Result.IsVirtualRegister)
                return;

            if (!node.Operand2.IsConstant)
                return;

            if (node.Operand2.ConstantUnsignedLongInteger != 1)
                return;

            Operand result = node.Result;
            Operand op1 = node.Operand1;
            Operand op2 = node.Operand2;

            AddOperandUsageToWorkList(node);
            if (trace.Active) trace.Log("*** ArithmeticSimplificationRemSignedModulus");
            if (trace.Active) trace.Log("BEFORE:\t" + node.ToString());
            node.SetInstruction(IRInstruction.Move, result, Operand.CreateConstant(TypeSystem, 0));
            arithmeticSimplificationModulus++;
            changeCount++;
            if (trace.Active) trace.Log("AFTER: \t" + node.ToString());
            return;
        }
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:34,代码来源:IROptimizationStage.cs

示例15: SimplifyExtendedMoveWithConstant

        /// <summary>
        /// Simplifies extended moves with a constant
        /// </summary>
        /// <param name="node">The node.</param>
        private void SimplifyExtendedMoveWithConstant(InstructionNode node)
        {
            if (node.IsEmpty)
                return;

            if (!(node.Instruction == IRInstruction.ZeroExtendedMove || node.Instruction == IRInstruction.SignExtendedMove))
                return;

            if (!node.Result.IsVirtualRegister)
                return;

            if (node.Result.Definitions.Count != 1)
                return;

            if (!node.Operand1.IsConstant)
                return;

            Operand result = node.Result;
            Operand op1 = node.Operand1;

            Operand newOperand;

            if (node.Instruction == IRInstruction.ZeroExtendedMove && result.IsUnsigned && op1.IsSigned)
            {
                var newConstant = Unsign(op1.Type, op1.ConstantSignedLongInteger);
                newOperand = Operand.CreateConstant(node.Result.Type, newConstant);
            }
            else
            {
                newOperand = Operand.CreateConstant(node.Result.Type, op1.ConstantUnsignedLongInteger);
            }

            AddOperandUsageToWorkList(node);
            if (trace.Active) trace.Log("*** SimplifyExtendedMoveWithConstant");
            if (trace.Active) trace.Log("BEFORE:\t" + node.ToString());
            node.SetInstruction(IRInstruction.Move, result, newOperand);
            simplifyExtendedMoveWithConstantCount++;
            changeCount++;
            if (trace.Active) trace.Log("AFTER: \t" + node.ToString());
        }
开发者ID:Profi-Concept,项目名称:MOSA-Project,代码行数:44,代码来源:IROptimizationStage.cs


注:本文中的InstructionNode.SetInstruction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。