本文整理汇总了C++中BranchInst::getOperand方法的典型用法代码示例。如果您正苦于以下问题:C++ BranchInst::getOperand方法的具体用法?C++ BranchInst::getOperand怎么用?C++ BranchInst::getOperand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BranchInst
的用法示例。
在下文中一共展示了BranchInst::getOperand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processOneIterationLoop
/// processOneIterationLoop -- Eliminate loop if loop body is executed
/// only once. For example,
/// for (i = 0; i < N; ++i) {
/// if ( i == X) {
/// ...
/// }
/// }
///
bool LoopIndexSplit::processOneIterationLoop() {
SplitCondition = NULL;
BasicBlock *Latch = L->getLoopLatch();
BasicBlock *Header = L->getHeader();
BranchInst *BR = dyn_cast<BranchInst>(Header->getTerminator());
if (!BR) return false;
if (!isa<BranchInst>(Latch->getTerminator())) return false;
if (BR->isUnconditional()) return false;
SplitCondition = dyn_cast<ICmpInst>(BR->getCondition());
if (!SplitCondition) return false;
if (SplitCondition == ExitCondition) return false;
if (SplitCondition->getPredicate() != ICmpInst::ICMP_EQ) return false;
if (BR->getOperand(1) != Latch) return false;
if (!IVBasedValues.count(SplitCondition->getOperand(0))
&& !IVBasedValues.count(SplitCondition->getOperand(1)))
return false;
// If IV is used outside the loop then this loop traversal is required.
// FIXME: Calculate and use last IV value.
if (isUsedOutsideLoop(IVIncrement, L))
return false;
// If BR operands are not IV or not loop invariants then skip this loop.
Value *OPV = SplitCondition->getOperand(0);
Value *SplitValue = SplitCondition->getOperand(1);
if (!L->isLoopInvariant(SplitValue))
std::swap(OPV, SplitValue);
if (!L->isLoopInvariant(SplitValue))
return false;
Instruction *OPI = dyn_cast<Instruction>(OPV);
if (!OPI)
return false;
if (OPI->getParent() != Header || isUsedOutsideLoop(OPI, L))
return false;
Value *StartValue = IVStartValue;
Value *ExitValue = IVExitValue;;
if (OPV != IndVar) {
// If BR operand is IV based then use this operand to calculate
// effective conditions for loop body.
BinaryOperator *BOPV = dyn_cast<BinaryOperator>(OPV);
if (!BOPV)
return false;
if (BOPV->getOpcode() != Instruction::Add)
return false;
StartValue = BinaryOperator::CreateAdd(OPV, StartValue, "" , BR);
ExitValue = BinaryOperator::CreateAdd(OPV, ExitValue, "" , BR);
}
if (!cleanBlock(Header))
return false;
if (!cleanBlock(Latch))
return false;
// If the merge point for BR is not loop latch then skip this loop.
if (BR->getSuccessor(0) != Latch) {
DominanceFrontier::iterator DF0 = DF->find(BR->getSuccessor(0));
assert (DF0 != DF->end() && "Unable to find dominance frontier");
if (!DF0->second.count(Latch))
return false;
}
if (BR->getSuccessor(1) != Latch) {
DominanceFrontier::iterator DF1 = DF->find(BR->getSuccessor(1));
assert (DF1 != DF->end() && "Unable to find dominance frontier");
if (!DF1->second.count(Latch))
return false;
}
// Now, Current loop L contains compare instruction
// that compares induction variable, IndVar, against loop invariant. And
// entire (i.e. meaningful) loop body is dominated by this compare
// instruction. In such case eliminate
// loop structure surrounding this loop body. For example,
// for (int i = start; i < end; ++i) {
// if ( i == somevalue) {
// loop_body
// }
// }
// can be transformed into
// if (somevalue >= start && somevalue < end) {
// i = somevalue;
// loop_body
// }
// Replace index variable with split value in loop body. Loop body is executed
// only when index variable is equal to split value.
IndVar->replaceAllUsesWith(SplitValue);
// Replace split condition in header.
// Transform
//.........这里部分代码省略.........