本文整理汇总了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;
}