本文整理汇总了C++中SwitchInst::setTarget方法的典型用法代码示例。如果您正苦于以下问题:C++ SwitchInst::setTarget方法的具体用法?C++ SwitchInst::setTarget怎么用?C++ SwitchInst::setTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SwitchInst
的用法示例。
在下文中一共展示了SwitchInst::setTarget方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: genSwitchEdges
void CfgCodeSelector::genSwitchEdges(U_32 tailNodeId, U_32 numTargets,
U_32 *targets, double *probs,
U_32 defaultTarget)
{
//
// Switch structure:
//
// origBlock switchBlock
// =========== Fallthrough =============
// .... =======> .......
// if (switchVar >= numTargets) swTarget= jmp [switchVar + swTableBase]
// jmp defaultTarget
//
Node * origBlock = nodes[tailNodeId];
const Edges& outEdges=origBlock->getOutEdges();
assert(outEdges.size() == 1);
Node * switchBlock= outEdges.front()->getTargetNode();
assert(switchBlock->isBlockNode());
assert(((Inst*)switchBlock->getLastInst())->hasKind(Inst::Kind_SwitchInst));
SwitchInst * swInst = (SwitchInst *)switchBlock->getLastInst();
double defaultEdgeProb = 1.0;
defaultEdgeProb = 1.0;
for (U_32 i = 0; i < numTargets; i++) {
U_32 targetId = targets[i];
if ( targetId == defaultTarget) {
defaultEdgeProb = probs[i];
break;
}
if (std::find(targets, targets+i, targetId)!=targets+i) {
continue; //repeated target
}
if (probs[i] < 0) {
defaultEdgeProb = 0;
break;
}
defaultEdgeProb -= 1.0/(numTargets+1);
}
genTrueEdge(tailNodeId, defaultTarget, defaultEdgeProb);
// Fix probability of fallthrough edge
if (defaultEdgeProb!=0) {
origBlock->getOutEdges().front()->setEdgeProb(1.0 - defaultEdgeProb);
}
// Generate edges from switchBlock to switch targets
for (U_32 i = 0; i < numTargets; i++) {
Node * targetNode = nodes[targets[i]];
// Avoid generating duplicate edges. Jump table however needs all entries
if (! switchBlock->isConnectedTo(true, targetNode)) {
irManager.getFlowGraph()->addEdge(switchBlock, targetNode, probs[i]);
}
swInst->setTarget(i, targetNode);
}
}