[LLVMdev] Selection DAG output as bare DAG, code review

Joseph Reddington joseph at cs.rhul.ac.uk
Mon Sep 3 03:40:44 PDT 2012


Hello all,

I recently foudn myself wanting to view the basic blocks in the
selection DAG as pure DAGs - so just as a list of edges, with no other
information.  I added the below code to the start of the "
void SelectionDAGISel::CodeGenAndEmitDAG()" function.  It creates a
separate txt file for each basic block and gives a list of edges
between nodes.  The segment of code is below - I'm looking for any
feedback on how I might have done things differently (I'm a very basic
c++ programmer) or if is a much easier way of getting the same
information - or if there are any obvious omissions in the code that
might be affecting the results.

Thanking you all in advance.

Joe

CODE

void SelectionDAGISel::CodeGenAndEmitDAG() {
  std::string GroupName;
    std::cout<<"-Joe: we have entered a block"<<std::endl;
    static int numberOfBlocks=0;
    numberOfBlocks++;
    std::cout<<"-We are in Block:"<<numberOfBlocks<<std::endl;
    //FIRST OF ALL, LET US TRY NUMBERING THE NODES
    int in=0;
    for (SelectionDAG::allnodes_iterator I =
CurDAG->allnodes_begin(),E = CurDAG->allnodes_end(); I != E; ++I)
    {
        I->setNodeId(in++);
    }
    //END NUMBERING THE NODES.

    //LET'S TRY WRITING A FILE
    std::ofstream myfile;
    std::string filename="DDGBLOCK"+convertInt(numberOfBlocks)+".txt";
    myfile.open (filename.c_str());
    myfile << "{\n";
    for (SelectionDAG::allnodes_iterator I =
CurDAG->allnodes_begin(),E = CurDAG->allnodes_end(); I != E; ++I)
    {
        std::cout<<"-Operation "<<I->getOperationName(CurDAG)<<"has
number "<<I->getNodeId()<<std::endl;
        int operands =I->getNumOperands();
        std::cout<<"-  has "<<operands<<" operands"<<std::endl;
        for(int i=0;i<operands;i++)
        {
            std::cout<<"-
"<<I->getOperand(i)->getOperationName(CurDAG)<<"number:
"<<I->getOperand(i)->getNodeId()<<std::endl;
            myfile<<"( "<<I->getOperand(i)->getNodeId()<<"
"<<I->getNodeId()<<" )"<<std::endl;

        }
    }
    myfile<<"}"<<std::endl;
    myfile.close();
    //END WRITING A FILE

//rest of the  void SelectionDAGISel::CodeGenAndEmitDAG() method
continues as normal...

-- 
Dr Joseph Reddington
Computer Science, Royal Holloway
For 2012 I have a resolution to write all my email responses within
24-hours - no exceptions. If you've not had a response, there's been a
misunderstanding somewhere, and it's worth reminding me.



More information about the llvm-dev mailing list