本文整理汇总了C++中BinaryOperator::user_begin方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryOperator::user_begin方法的具体用法?C++ BinaryOperator::user_begin怎么用?C++ BinaryOperator::user_begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryOperator
的用法示例。
在下文中一共展示了BinaryOperator::user_begin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runOnFunction
bool HexagonOptimizeSZextends::runOnFunction(Function &F) {
unsigned Idx = 1;
// Try to optimize sign extends in formal parameters. It's relying on
// callee already sign extending the values. I'm not sure if our ABI
// requires callee to sign extend though.
for (auto &Arg : F.args()) {
if (F.getAttributes().hasAttribute(Idx, Attribute::SExt)) {
if (!isa<PointerType>(Arg.getType())) {
for (auto UI = Arg.use_begin(); UI != Arg.use_end();) {
if (isa<SExtInst>(*UI)) {
Instruction* Use = cast<Instruction>(*UI);
SExtInst* SI = new SExtInst(&Arg, Use->getType());
assert (EVT::getEVT(SI->getType()) ==
(EVT::getEVT(Use->getType())));
++UI;
Use->replaceAllUsesWith(SI);
Instruction* First = &F.getEntryBlock().front();
SI->insertBefore(First);
Use->eraseFromParent();
} else {
++UI;
}
}
}
}
++Idx;
}
// Try to remove redundant sext operations on Hexagon. The hardware
// already sign extends many 16 bit intrinsic operations to 32 bits.
// For example:
// %34 = tail call i32 @llvm.hexagon.A2.addh.l16.sat.ll(i32 %x, i32 %y)
// %sext233 = shl i32 %34, 16
// %conv52 = ashr exact i32 %sext233, 16
for (auto &B : F) {
for (auto &I : B) {
// Look for arithmetic shift right by 16.
BinaryOperator *Ashr = dyn_cast<BinaryOperator>(&I);
if (!(Ashr && Ashr->getOpcode() == Instruction::AShr))
continue;
Value *AshrOp1 = Ashr->getOperand(1);
ConstantInt *C = dyn_cast<ConstantInt>(AshrOp1);
// Right shifted by 16.
if (!(C && C->getSExtValue() == 16))
continue;
// The first operand of Ashr comes from logical shift left.
Instruction *Shl = dyn_cast<Instruction>(Ashr->getOperand(0));
if (!(Shl && Shl->getOpcode() == Instruction::Shl))
continue;
Value *Intr = Shl->getOperand(0);
Value *ShlOp1 = Shl->getOperand(1);
C = dyn_cast<ConstantInt>(ShlOp1);
// Left shifted by 16.
if (!(C && C->getSExtValue() == 16))
continue;
// The first operand of Shl comes from an intrinsic.
if (IntrinsicInst *I = dyn_cast<IntrinsicInst>(Intr)) {
if (!intrinsicAlreadySextended(I->getIntrinsicID()))
continue;
// All is well. Replace all uses of AShr with I.
for (auto UI = Ashr->user_begin(), UE = Ashr->user_end();
UI != UE; ++UI) {
const Use &TheUse = UI.getUse();
if (Instruction *J = dyn_cast<Instruction>(TheUse.getUser())) {
J->replaceUsesOfWith(Ashr, I);
}
}
}
}
}
return true;
}