compiler/mapper/DFG.cpp
// This is necessary to handle the control flow.
// Each one would have their own implementation about control
// flow handling. We simply connect 'br' to the entry ('phi')
// of the corresponding basic blocks (w/o including additional
// DFG nodes).
This is necessary to handle the control flow.
Each one would have their own implementation about control
flow handling. We simply connect 'br' to the entry ('phi')
of the corresponding basic blocks (w/o including additional
DFG nodes).
This is necessary to handle the control flow . Each one would have their own implementation about control flow handling . We simply connect ' br ' to the entry ( ' phi ' ) of the corresponding basic blocks ( w / o including additional DFG nodes ) .
void DFG::tuneForBranch() {
  list<DFGNode*> processedDFGBrNodes;
  list<DFGEdge*> replaceDFGEdges;
  list<DFGEdge*> newBrDFGEdges;
  int newDFGEdgeID = m_DFGEdges.size();
  for (DFGEdge* dfgEdge: m_ctrlEdges) {
    DFGNode* left = dfgEdge->getSrc();
    DFGNode* right = dfgEdge->getDst();
    assert(left->isBranch());
    assert(right->isPhi());
    if (find(processedDFGBrNodes.begin(), processedDFGBrNodes.end(), left) ==
        processedDFGBrNodes.end()) {
      processedDFGBrNodes.push_back(left);
    } else {
      DFGNode* newDFGBrNode = new DFGNode(nodes.size(), left->getInst(),
          getValueName(left->getInst()));
      for (DFGNode* predDFGNode: *(left->getPredNodes())) {
        DFGEdge* newDFGBrEdge = new DFGEdge(newDFGEdgeID++,
            predDFGNode, newDFGBrNode);
        m_DFGEdges.push_back(newDFGBrEdge);
      }
      nodes.push_back(newDFGBrNode);
      left = newDFGBrNode;
    }
    list<DFGNode*>* predNodes = right->getPredNodes();
    for (DFGNode* predNode: *predNodes) {
      DFGEdge* replaceDFGEdge = getDFGEdge(predNode, right);
      DFGEdge* brDataDFGEdge = new DFGEdge(replaceDFGEdge->getID(), predNode, left);
      DFGEdge* brCtrlDFGEdge = new DFGEdge(newDFGEdgeID++, left, right);
      replaceDFGEdges.push_back(replaceDFGEdge);
      newBrDFGEdges.push_back(brDataDFGEdge);
      newBrDFGEdges.push_back(brCtrlDFGEdge);
      break;
    }
  }
  for (DFGEdge* dfgEdge: replaceDFGEdges) {
    m_DFGEdges.remove(dfgEdge);
  }
  for (DFGEdge* dfgEdge: newBrDFGEdges) {
    m_DFGEdges.push_back(dfgEdge);
  }
  connectDFGNodes();
}
void DFG :: tuneForBranch ( ) { list < DFGNode * > processedDFGBrNodes ; list < DFGEdge * > replaceDFGEdges ; list < DFGEdge * > newBrDFGEdges ; int newDFGEdgeID = m_DFGEdges . size ( ) ; for ( DFGEdge * dfgEdge : m_ctrlEdges ) { DFGNode * left = dfgEdge -> getSrc ( ) ; DFGNode * right = dfgEdge -> getDst ( ) ; assert ( left -> isBranch ( ) ) ; assert ( right -> isPhi ( ) ) ; if ( find ( processedDFGBrNodes . begin ( ) , processedDFGBrNodes . end ( ) , left ) == processedDFGBrNodes . end ( ) ) { processedDFGBrNodes . push_back ( left ) ; } else { DFGNode * newDFGBrNode = new DFGNode ( nodes . size ( ) , left -> getInst ( ) , getValueName ( left -> getInst ( ) ) ) ; for ( DFGNode * predDFGNode : * ( left -> getPredNodes ( ) ) ) { DFGEdge * newDFGBrEdge = new DFGEdge ( newDFGEdgeID ++ , predDFGNode , newDFGBrNode ) ; m_DFGEdges . push_back ( newDFGBrEdge ) ; } nodes . push_back ( newDFGBrNode ) ; left = newDFGBrNode ; } list < DFGNode * > * predNodes = right -> getPredNodes ( ) ; for ( DFGNode * predNode : * predNodes ) { DFGEdge * replaceDFGEdge = getDFGEdge ( predNode , right ) ; DFGEdge * brDataDFGEdge = new DFGEdge ( replaceDFGEdge -> getID ( ) , predNode , left ) ; DFGEdge * brCtrlDFGEdge = new DFGEdge ( newDFGEdgeID ++ , left , right ) ; replaceDFGEdges . push_back ( replaceDFGEdge ) ; newBrDFGEdges . push_back ( brDataDFGEdge ) ; newBrDFGEdges . push_back ( brCtrlDFGEdge ) ; break ; } } for ( DFGEdge * dfgEdge : replaceDFGEdges ) { m_DFGEdges . remove ( dfgEdge ) ; } for ( DFGEdge * dfgEdge : newBrDFGEdges ) { m_DFGEdges . push_back ( dfgEdge ) ; } connectDFGNodes ( ) ; }
This is necessary to handle the control flow.
This is necessary to handle the control flow .
// FIXME: Only consider one predecessor for 'phi' node for now. //        Need to care about true/false and make proper connection. //    DFGEdge* brCtrlDFGEdge = new DFGEdge(m_DFGEdges.size(), left, right); //    DFGEdge* replaceDFGEdge; //    for (list<DFGNode*>::iterator predNodeItr=predNodes->begin(); //        predNodeItr!=predNodes->end(); ++predNodeItr) { //      DFGNode* predNode = *predNodeItr; //      list<DFGNode*>* visitedNodes = new list<DFGNode*>(); //      // Found one predNode is one the same control/data path as the 'br'. //      if (searchDFS(left, predNode, visitedNodes)) { //        replaceDFGEdge = getDFGEdge(predNode, right); //        DFGEdge* brDataDFGEdge = new DFGEdge(replaceDFGEdge->getID(), predNode, left); //        m_DFGEdges.remove(replaceDFGEdge); //        m_DFGEdges.push_back(brDataDFGEdge); //        break; //      } //    } //    m_DFGEdges.push_back(brCtrlDFGEdge); //  }