本文整理汇总了C#中InstructionNode.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# InstructionNode.ToString方法的具体用法?C# InstructionNode.ToString怎么用?C# InstructionNode.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InstructionNode
的用法示例。
在下文中一共展示了InstructionNode.ToString方法的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++;
}
示例2: 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());
}
示例3: ConstantFoldingDivision
private void ConstantFoldingDivision(InstructionNode node)
{
if (!(node.Instruction == IRInstruction.DivSigned || node.Instruction == IRInstruction.DivUnsigned))
return;
if (!node.Result.IsVirtualRegister)
return;
if (node.Result.Definitions.Count != 1)
return;
if (!node.Operand2.IsResolvedConstant)
return;
if (node.Result.Uses.Count != 1)
return;
var node2 = node.Result.Uses[0];
if (!(node2.Instruction == IRInstruction.DivSigned || node2.Instruction == IRInstruction.DivUnsigned))
return;
if (!node2.Result.IsVirtualRegister)
return;
if (!node2.Operand2.IsResolvedConstant)
return;
Debug.Assert(node2.Result.Definitions.Count == 1);
ulong r = (node2.Instruction == IRInstruction.DivSigned) ?
(ulong)(node.Operand2.ConstantSignedLongInteger / node2.Operand2.ConstantSignedLongInteger) :
node.Operand2.ConstantUnsignedLongInteger / node2.Operand2.ConstantUnsignedLongInteger;
if (trace.Active) trace.Log("*** ConstantFoldingDivision");
AddOperandUsageToWorkList(node2);
AddOperandUsageToWorkList(node);
if (trace.Active) trace.Log("BEFORE:\t" + node2.ToString());
node2.SetInstruction(IRInstruction.MoveInteger, node2.Result, node.Result);
if (trace.Active) trace.Log("AFTER: \t" + node2.ToString());
if (trace.Active) trace.Log("BEFORE:\t" + node.ToString());
node.Operand2 = Operand.CreateConstant(node.Operand2.Type, r);
if (trace.Active) trace.Log("AFTER: \t" + node.ToString());
constantFoldingDivisionCount++;
changeCount++;
}
示例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++;
}
示例5: ConstantFoldingAdditionAndSubstraction
private void ConstantFoldingAdditionAndSubstraction(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;
if (node.Result.Definitions.Count != 1)
return;
if (!node.Operand2.IsConstant)
return;
if (node.Result.Uses.Count != 1)
return;
var node2 = node.Result.Uses[0];
if (!(node2.Instruction == IRInstruction.AddSigned || node2.Instruction == IRInstruction.AddUnsigned
|| node2.Instruction == IRInstruction.SubSigned || node2.Instruction == IRInstruction.SubUnsigned))
return;
if (!node2.Result.IsVirtualRegister)
return;
if (!node2.Operand2.IsConstant)
return;
Debug.Assert(node2.Result.Definitions.Count == 1);
bool add = true;
if ((node.Instruction == IRInstruction.AddSigned || node.Instruction == IRInstruction.AddUnsigned) &&
(node2.Instruction == IRInstruction.SubSigned || node2.Instruction == IRInstruction.SubUnsigned))
{
add = false;
}
else if ((node.Instruction == IRInstruction.SubSigned || node.Instruction == IRInstruction.SubUnsigned) &&
(node2.Instruction == IRInstruction.AddSigned || node2.Instruction == IRInstruction.AddUnsigned))
{
add = false;
}
ulong r = add ? node.Operand2.ConstantUnsignedLongInteger + node2.Operand2.ConstantUnsignedLongInteger :
node.Operand2.ConstantUnsignedLongInteger - node2.Operand2.ConstantUnsignedLongInteger;
Debug.Assert(node2.Result.Definitions.Count == 1);
if (trace.Active) trace.Log("*** ConstantFoldingAdditionAndSubstraction");
AddOperandUsageToWorkList(node2);
AddOperandUsageToWorkList(node);
if (trace.Active) trace.Log("BEFORE:\t" + node2.ToString());
node2.SetInstruction(IRInstruction.Move, node2.Result, node.Result);
if (trace.Active) trace.Log("AFTER: \t" + node2.ToString());
if (trace.Active) trace.Log("BEFORE:\t" + node.ToString());
node.Operand2 = Operand.CreateConstant(node.Operand2.Type, r);
if (trace.Active) trace.Log("AFTER: \t" + node.ToString());
constantFoldingAdditionAndSubstractionCount++;
changeCount++;
}
示例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;
}
}
示例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;
}
}
}
示例8: 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;
}
示例9: DeadCodeEliminationPhi
private void DeadCodeEliminationPhi(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 result.Uses)
{
if (use != node)
return;
}
AddOperandUsageToWorkList(node);
if (trace.Active) trace.Log("*** DeadCodeEliminationPhi");
if (trace.Active) trace.Log("REMOVED:\t" + node.ToString());
node.SetInstruction(IRInstruction.Nop);
deadCodeEliminationPhi++;
changeCount++;
}
示例10: 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++;
}
示例11: ConstantMoveToRight
private void ConstantMoveToRight(InstructionNode node)
{
if (node.IsEmpty)
return;
if (!(node.Instruction == IRInstruction.AddSigned || node.Instruction == IRInstruction.AddUnsigned
|| node.Instruction == IRInstruction.MulSigned || node.Instruction == IRInstruction.MulUnsigned
|| node.Instruction == IRInstruction.LogicalAnd || node.Instruction == IRInstruction.LogicalOr
|| node.Instruction == IRInstruction.LogicalXor))
return;
if (node.Operand2.IsConstant)
return;
if (!node.Operand1.IsConstant)
return;
AddOperandUsageToWorkList(node);
if (trace.Active) trace.Log("*** ConstantMoveToRight");
if (trace.Active) trace.Log("BEFORE:\t" + node.ToString());
var op1 = node.Operand1;
node.Operand1 = node.Operand2;
node.Operand2 = op1;
if (trace.Active) trace.Log("AFTER: \t" + node.ToString());
constantMoveToRightCount++;
changeCount++;
}
示例12: 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++;
}
示例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;
}
示例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;
}
示例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());
}