本文整理汇总了C++中BinaryOperator::getNumUses方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryOperator::getNumUses方法的具体用法?C++ BinaryOperator::getNumUses怎么用?C++ BinaryOperator::getNumUses使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryOperator
的用法示例。
在下文中一共展示了BinaryOperator::getNumUses方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getNullValue
Value *ConstantOffsetExtractor::removeConstOffset(unsigned ChainIndex) {
if (ChainIndex == 0) {
assert(isa<ConstantInt>(UserChain[ChainIndex]));
return ConstantInt::getNullValue(UserChain[ChainIndex]->getType());
}
BinaryOperator *BO = cast<BinaryOperator>(UserChain[ChainIndex]);
unsigned OpNo = (BO->getOperand(0) == UserChain[ChainIndex - 1] ? 0 : 1);
assert(BO->getOperand(OpNo) == UserChain[ChainIndex - 1]);
Value *NextInChain = removeConstOffset(ChainIndex - 1);
Value *TheOther = BO->getOperand(1 - OpNo);
// If NextInChain is 0 and not the LHS of a sub, we can simplify the
// sub-expression to be just TheOther.
if (ConstantInt *CI = dyn_cast<ConstantInt>(NextInChain)) {
if (CI->isZero() && !(BO->getOpcode() == Instruction::Sub && OpNo == 0))
return TheOther;
}
if (BO->getOpcode() == Instruction::Or) {
// Rebuild "or" as "add", because "or" may be invalid for the new
// epxression.
//
// For instance, given
// a | (b + 5) where a and b + 5 have no common bits,
// we can extract 5 as the constant offset.
//
// However, reusing the "or" in the new index would give us
// (a | b) + 5
// which does not equal a | (b + 5).
//
// Replacing the "or" with "add" is fine, because
// a | (b + 5) = a + (b + 5) = (a + b) + 5
if (OpNo == 0) {
return BinaryOperator::CreateAdd(NextInChain, TheOther, BO->getName(),
IP);
} else {
return BinaryOperator::CreateAdd(TheOther, NextInChain, BO->getName(),
IP);
}
}
// We can reuse BO in this case, because the new expression shares the same
// instruction type and BO is used at most once.
assert(BO->getNumUses() <= 1 &&
"distributeExtsAndCloneChain clones each BinaryOperator in "
"UserChain, so no one should be used more than "
"once");
BO->setOperand(OpNo, NextInChain);
BO->setHasNoSignedWrap(false);
BO->setHasNoUnsignedWrap(false);
// Make sure it appears after all instructions we've inserted so far.
BO->moveBefore(IP);
return BO;
}
示例2: getNullValue
Value *ConstantOffsetExtractor::removeConstOffset(unsigned ChainIndex) {
if (ChainIndex == 0) {
assert(isa<ConstantInt>(UserChain[ChainIndex]));
return ConstantInt::getNullValue(UserChain[ChainIndex]->getType());
}
BinaryOperator *BO = cast<BinaryOperator>(UserChain[ChainIndex]);
assert(BO->getNumUses() <= 1 &&
"distributeExtsAndCloneChain clones each BinaryOperator in "
"UserChain, so no one should be used more than "
"once");
unsigned OpNo = (BO->getOperand(0) == UserChain[ChainIndex - 1] ? 0 : 1);
assert(BO->getOperand(OpNo) == UserChain[ChainIndex - 1]);
Value *NextInChain = removeConstOffset(ChainIndex - 1);
Value *TheOther = BO->getOperand(1 - OpNo);
// If NextInChain is 0 and not the LHS of a sub, we can simplify the
// sub-expression to be just TheOther.
if (ConstantInt *CI = dyn_cast<ConstantInt>(NextInChain)) {
if (CI->isZero() && !(BO->getOpcode() == Instruction::Sub && OpNo == 0))
return TheOther;
}
BinaryOperator::BinaryOps NewOp = BO->getOpcode();
if (BO->getOpcode() == Instruction::Or) {
// Rebuild "or" as "add", because "or" may be invalid for the new
// epxression.
//
// For instance, given
// a | (b + 5) where a and b + 5 have no common bits,
// we can extract 5 as the constant offset.
//
// However, reusing the "or" in the new index would give us
// (a | b) + 5
// which does not equal a | (b + 5).
//
// Replacing the "or" with "add" is fine, because
// a | (b + 5) = a + (b + 5) = (a + b) + 5
NewOp = Instruction::Add;
}
BinaryOperator *NewBO;
if (OpNo == 0) {
NewBO = BinaryOperator::Create(NewOp, NextInChain, TheOther, "", IP);
} else {
NewBO = BinaryOperator::Create(NewOp, TheOther, NextInChain, "", IP);
}
NewBO->takeName(BO);
return NewBO;
}