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


C# Instruction.ConvertToNop方法代码示例

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


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

示例1: OptimizePredictableBranch

        /// <summary>
        /// This will eliminate or shortcut: 
        ///     (1) zero-comparisons to a just set const
        ///     (2) branch to a branch when the second branch zero-compares to a 
        ///         just set const before the first branch.
        //      (3) branch to a const immediatly followed by a zero-comparison
        //          to that same const.
        /// </summary>
        private bool OptimizePredictableBranch(Instruction ins, BasicBlock block, ControlFlowGraph2 cfg)
        {
            // (1) zero-comparisons to a just set const
            if (ins != block.Entry 
                && IsComparisonWithZero(ins.Code) && ins.Previous.Code == RCode.Const 
                && IsSameRegister(ins.Registers, ins.Previous.Registers))
            {
                if (WillTakeBranch(ins.Code, Convert.ToInt32(ins.Previous.Operand)))
                {
                    ins.Registers.Clear();
                    ins.Code = RCode.Goto;
                    return true;
                }
                else
                {
                    ins.ConvertToNop();
                    return true;
                }
            }

            // (2)  branch to a branch when the second branch zero-compares to a 
            //      just set const before the first branch.
            var target = (Instruction)ins.Operand;
            if (ins != block.Entry 
                && IsComparisonWithZero(target.Code) && ins.Previous.Code == RCode.Const 
                && IsSameRegister(target.Registers, ins.Previous.Registers))
            {
                if (WillTakeBranch(target.Code, Convert.ToInt32(ins.Previous.Operand)))
                    cfg.RerouteBranch(ins, (Instruction)target.Operand);
                else
                    cfg.RerouteBranch(ins, target.Next);
                return true;
            }

            // (3) branch to a const immediatly followed by a zero-comparison to that same const.
            //     We can only shortcut if the register is not read again after the branch.
            if (target.Code == RCode.Const && IsComparisonWithZero(target.Next.Code)
                && IsSameRegister(target.Registers, target.Next.Registers))
            {
                var secondBranch = target.Next;
                var secondBlock = cfg.GetBlockFromExit(secondBranch);

                var visited = new HashSet<BasicBlock> {secondBlock};
                    // we know the second block contains only two instructions. 
                if (!IsRegisterReadAgain(target.Registers[0], secondBlock.ExitBlocks, visited))
                {
                    if (WillTakeBranch(secondBranch.Code, Convert.ToInt32(target.Operand)))
                        cfg.RerouteBranch(ins, (Instruction)target.Next.Operand);
                    else
                        cfg.RerouteBranch(ins, target.Next.Next);
                    return true;
                }
            }

            return false;
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:64,代码来源:PredictableBranchOptimizer.cs


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