当前位置: 首页>>代码示例>>C++>>正文


C++ ControlFlowGraph::createBlockNode方法代码示例

本文整理汇总了C++中ControlFlowGraph::createBlockNode方法的典型用法代码示例。如果您正苦于以下问题:C++ ControlFlowGraph::createBlockNode方法的具体用法?C++ ControlFlowGraph::createBlockNode怎么用?C++ ControlFlowGraph::createBlockNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ControlFlowGraph的用法示例。


在下文中一共展示了ControlFlowGraph::createBlockNode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fixNodeInfo

void CfgCodeSelector::fixNodeInfo() 
{
    MemoryManager tmpMM("Ia32CS:fixNodeInfoMM");
    ControlFlowGraph* fg = irManager.getFlowGraph();
    Nodes nodes(tmpMM);
    fg->getNodes(nodes); //copy nodes -> loop creates new ones, so we can't use reference to cfg->getNodes()
    for (Nodes::const_iterator it = nodes.begin(), end = nodes.end(); it!=end; ++it) {
        Node* node = *it;
        // connect throw nodes added during inst code selection to corresponding dispatch or unwind nodes
        if (node->isBlockNode()){
            Inst * lastInst = (Inst*)node->getLastInst();
            if (lastInst) {
                Inst * prevInst = lastInst->getPrevInst();
                if(prevInst && prevInst->getKind() == Inst::Kind_BranchInst) {
                    Edge * ftEdge = node->getFalseEdge();
                    Edge * dbEdge = node->getTrueEdge();
                    assert(ftEdge && dbEdge);

                    Node* newBB =  fg->createBlockNode();
                    Node* nextFT =  ftEdge->getTargetNode();
                    Node* nextDB = dbEdge->getTargetNode();

                    fg->removeEdge(ftEdge);
                    fg->removeEdge(dbEdge);

                    newBB->appendInst(irManager.newBranchInst(lastInst->getMnemonic(), nextDB, nextFT));
                    lastInst->unlink();

                    //now fix prev branch successors
                    BranchInst* prevBranch = (BranchInst*)prevInst;
                    assert(prevBranch->getTrueTarget() == NULL && prevBranch->getFalseTarget() == NULL);
                    prevBranch->setTrueTarget(lastInst->getMnemonic() == Mnemonic_JZ? nextFT : nextDB);
                    prevBranch->setFalseTarget(newBB);
              
                    
                    fg->addEdge(node, lastInst->getMnemonic() == Mnemonic_JZ? nextFT : nextDB, 0);
                    fg->addEdge(node, newBB, 0);
                    fg->addEdge(newBB, nextDB, 0); 
                    fg->addEdge(newBB, nextFT, 0);
                }
            }
            if (node->getOutDegree() == 0){ // throw node
                assert(node->getInDegree()==1);
                Node* bbIn = node->getInEdges().front()->getSourceNode();
                assert(bbIn!=NULL);
                Node * target=bbIn->getExceptionEdgeTarget();
                assert(target!=NULL);
                fg->addEdge(node, target, 1.0);
            }
            // fixup empty catch blocks otherwise respective catchEdges will be lost
            // There is no [catchBlock]-->[catchHandler] edge. Catch block will be removed
            // as an empty one and exception handling will be incorrect
            if (node->isCatchBlock() && node->isEmpty()) {
                assert(node->getInDegree()==1);
                Edge* catchEdge = node->getInEdges().front();
                assert(catchEdge->getSourceNode()->isDispatchNode());
                assert(node->getOutDegree()==1);
                Node* succ = node->getUnconditionalEdgeTarget();
                while( succ->isEmpty() && (succ->getOutDegree() == 1) ) {
                    succ = succ->getUnconditionalEdgeTarget();
                }
                assert(succ && ((Inst*)succ->getFirstInst())->hasKind(Inst::Kind_CatchPseudoInst));
                fg->replaceEdgeTarget(catchEdge,succ,true/*keepOldBody*/);
            }
        }
    }
}
开发者ID:,项目名称:,代码行数:67,代码来源:


注:本文中的ControlFlowGraph::createBlockNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。