Beispiel #1
0
// Processes one node and its imediate edges for building the DAG.
void BallLarusDag::buildNode(BLBlockNodeMap& inDag, BLNodeStack& dfsStack) {
  BallLarusNode* currentNode = dfsStack.top();
  BasicBlock* currentBlock = currentNode->getBlock();

  if(currentNode->getColor() != BallLarusNode::WHITE) {
    // we have already visited this node
    dfsStack.pop();
    currentNode->setColor(BallLarusNode::BLACK);
  } else {
    // are there any external procedure calls?
    if( ProcessEarlyTermination ) {
      for( BasicBlock::iterator bbCurrent = currentNode->getBlock()->begin(),
             bbEnd = currentNode->getBlock()->end(); bbCurrent != bbEnd;
           bbCurrent++ ) {
        Instruction& instr = *bbCurrent;
        if( instr.getOpcode() == Instruction::Call ) {
          BallLarusEdge* callEdge = addEdge(currentNode, getExit(), 0);
          callEdge->setType(BallLarusEdge::CALLEDGE_PHONY);
          break;
        }
      }
    }

    TerminatorInst* terminator = currentNode->getBlock()->getTerminator();
    if(isa<ReturnInst>(terminator) || isa<UnreachableInst>(terminator)
       || isa<UnwindInst>(terminator))
      addEdge(currentNode, getExit(),0);

    currentNode->setColor(BallLarusNode::GRAY);
    inDag[currentBlock] = currentNode;

    BasicBlock* oldSuccessor = 0;
    unsigned duplicateNumber = 0;

    // iterate through this node's successors
    for(succ_iterator successor = succ_begin(currentBlock),
          succEnd = succ_end(currentBlock); successor != succEnd;
        oldSuccessor = *successor, ++successor ) {
      BasicBlock* succBB = *successor;

      // is this edge a duplicate?
      if (oldSuccessor == succBB)
        duplicateNumber++;
      else
        duplicateNumber = 0;

      buildEdge(inDag, dfsStack, currentNode, succBB, duplicateNumber);
    }
  }
}
Beispiel #2
0
BasicBlock* ProfilePath::getFirstBlockInPath() const {
    BallLarusNode* root = _ppi->_currentDag->getRoot();
    BallLarusEdge* edge = getNextEdge(root, _number);

    if( edge && (edge->getType() == BallLarusEdge::BACKEDGE_PHONY ||
                 edge->getType() == BallLarusEdge::SPLITEDGE_PHONY) )
        return edge->getTarget()->getBlock();

    return root->getBlock();
}
Beispiel #3
0
ProfilePathBlockVector* ProfilePath::getPathBlocks() const {
    BallLarusNode* currentNode = _ppi->_currentDag->getRoot ();
    unsigned int increment = _number;
    ProfilePathBlockVector* pbv = new ProfilePathBlockVector;

    while (currentNode != _ppi->_currentDag->getExit()) {
        BallLarusEdge* next = getNextEdge(currentNode, increment);
        increment -= next->getWeight();

        // add block to the block list if it is a real edge
        if( next->getType() == BallLarusEdge::NORMAL)
            pbv->push_back (currentNode->getBlock());
        // make the back edge the last edge since we are at the end
        else if( next->getTarget() == _ppi->_currentDag->getExit() ) {
            pbv->push_back (currentNode->getBlock());
            pbv->push_back (next->getRealEdge()->getTarget()->getBlock());
        }

        // set the new node
        currentNode = next->getTarget();
    }

    return pbv;
}