Joseph Reddington
2012-Sep-03 10:40 UTC
[LLVMdev] Selection DAG output as bare DAG, code review
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.
It's not going to be that helpful to just look at the edges, since the edges "come out of" and "go into" different parts of the nodes, and that is really important information. I've attached a simple example of what it looks like. I made that with Mathematica, with: g = Import["/tmp/llvm_Cnrx9F/dag.setit.dot", {"DOT", "EdgeRules"}]; Graph[Union[g], ImageSize -> {400, 400}] Note that this won't scale. That BB was trivial (I believe it was one assignment). Once you get into anything more complicated, it's just going to become a ball of spaghetti without the node info. If you realy want to, you take the dot files produced by `-view-dag-combine1-dags` and friends <http://llvm.org/docs/CodeGenerator.html#selectiondag-instruction-selection-process> and then do some postprocessing to get it into the form that you want. --Sean Silva On Mon, Sep 3, 2012 at 6:40 AM, Joseph Reddington <joseph at cs.rhul.ac.uk> wrote:> 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. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- A non-text attachment was scrubbed... Name: dag-no-nodes.png Type: image/png Size: 8991 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120904/6e77c4ba/attachment.png>
Apparently Analagous Threads
- [LLVMdev] SelectionDAGISel::CodeGenAndEmitDAG() confusion.
- [LLVMdev] Difficulty with reusing DAG nodes.
- [LLVMdev] [PATCH] Add new phase to legalization to handle vector operations
- [LLVMdev] [PATCH] Add new phase to legalization to handle vector operations
- [LLVMdev] [PATCH] dbgs() Use