<span style>I tried debugging it and the issue seems to be in the implementation of MachineInstrIterator.h and the way it interacts with GraphWriter.h functions. I found this by replacing the ( template <> struct GraphTraits<MCDFGraph<</span><span style>MachineFunction*> >) with a similar MCDFGraph based template of CFG similar to the one in MachineFunction.h (similarly replacing the DOTGraphTraits with the one for CFG) and it works and pops up the GraphViz window with the CFG for the machine function.</span><div>
<font color="#222222" face="arial, sans-serif"><br></font></div><div><span style>I am attaching the MachineInstrIterator.h file.</span><font color="#222222" face="arial, sans-serif"><br></font><div><font color="#222222" face="arial, sans-serif"><br>
</font></div><div><font color="#222222" face="arial, sans-serif">Also, I wrote a pass using the mc_inst_iterator (defined in the MachineInstrIterator.h - the direct iterator over MachineInstr in a MachineFunction) to iterate through the machine instructions in a machine function and it works.</font></div>
<div><font color="#222222" face="arial, sans-serif"><br></font></div><div><font color="#222222" face="arial, sans-serif">I tried building LLVM 3.1 using clang in order to get a better idea of the error. Here is the build error output:</font></div>
<div><font color="#222222" face="arial, sans-serif"><br></font></div><div><font color="#222222" face="arial, sans-serif"><div>/home/arhishee/work/llvm-3.1.src/include/llvm/Support/GraphWriter.h:143:8: note: candidate function not viable: no known conversion from</div>
<div> 'IIty' (aka 'llvm::MachineInstr') to 'NodeType &' (aka 'llvm::Value &') for 1st argument;</div><div> bool isNodeHidden(NodeType &Node) {</div><div> ^</div><div>
/home/arhishee/work/llvm-3.1.src/include/llvm/Support/GraphWriter.h:147:8: note: candidate function not viable: no known conversion from</div><div> 'IIty' (aka 'llvm::MachineInstr') to 'NodeType *const *' (aka 'llvm::Value *const *') for 1st argument;</div>
<div> bool isNodeHidden(NodeType *const *Node) {</div><div> ^</div><div>/home/arhishee/work/llvm-3.1.src/include/llvm/Support/GraphWriter.h:151:8: note: candidate function not viable: no known conversion from</div>
<div> 'IIty' (aka 'llvm::MachineInstr') to 'NodeType *' (aka 'llvm::Value *') for 1st argument;</div><div> bool isNodeHidden(NodeType *Node) {</div><div><br></div></font></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif">This seems to be a clear type mismatch between the argument expected by isNodeHidden in GraphWriter.h (either of 3 types - </span><span style="color:rgb(34,34,34);font-family:arial,sans-serif">NodeType &Node, </span><span style="color:rgb(34,34,34);font-family:arial,sans-serif">NodeType *const *Node, </span><span style="color:rgb(34,34,34);font-family:arial,sans-serif">NodeType *Node, where NodeType corresponds to llvm::Value</span><span style="color:rgb(34,34,34);font-family:arial,sans-serif">) and the llvm::MachineInstr type passed through the mc_inst_iterator template. But I am not sure how to fix it. Can someone provide some debug pointers?</span></div>
<div><span style="color:rgb(34,34,34);font-family:arial,sans-serif"><br></span></div><div><br><div class="gmail_quote">On Wed, May 30, 2012 at 8:21 PM, AbhishekR <span dir="ltr"><<a href="mailto:abhishekr1982@gmail.com" target="_blank">abhishekr1982@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<div>I am trying to generate the DFG of machine functions.</div><div><br></div><div>Initially, I added a pass to generate the DFG of LLVM IR functions. This was based on the mail thread -
<a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2009-September/025582.html" target="_blank">http://lists.cs.uiuc.edu/pipermail/llvmdev/2009-September/025582.html</a>. This pass worked fine and I was able to generate DFG of LLVM IR functions.</div>
<div><br></div><div>Later, I ported the DFG pass code for machine functions. I ported the InstIterator.h (which was required to use inst_iterator in the <i>template <> struct GraphTraits<DFG<Function*> ></i>) to MachineInstrIterator.h to iterate over machine instructions in a machine function. But the build is throwing the following error:</div>
<div><br></div><div><div>llvm[2]: Compiling MC_DFG.cpp for Debug+Asserts build</div><div>/home/abhi/work/llvm31/llvm/include/llvm/Support/GraphWriter.h: In member function ‘void llvm::GraphWriter<GraphType>::writeNodes() [with GraphType = llvm::MCDFGraph<llvm::MachineFunction*>]’:</div>
<div>/home/abhi/work/llvm31/llvm/include/llvm/Support/GraphWriter.h:100: instantiated from ‘void llvm::GraphWriter<GraphType>::writeGraph(const std::string&) [with GraphType = llvm::MCDFGraph<llvm::MachineFunction*>]’</div>
<div>/home/abhi/work/llvm31/llvm/include/llvm/Support/GraphWriter.h:304: instantiated from ‘llvm::raw_ostream& llvm::WriteGraph(llvm::raw_ostream&, const GraphType&, bool, const llvm::Twine&) [with GraphType = llvm::MCDFGraph<llvm::MachineFunction*>]’</div>
<div>/home/abhi/work/llvm31/llvm/lib/CodeGen/MC_DFG.cpp:249: instantiated from here</div><div><b>/home/abhi/work/llvm31/llvm/include/llvm/Support/GraphWriter.h:139: error: no matching function for call to ‘llvm::GraphWriter<llvm::MCDFGraph<llvm::MachineFunction*> >::isNodeHidden(llvm::MachineInstr&)’</b></div>
<div><b>/home/abhi/work/llvm31/llvm/include/llvm/Support/GraphWriter.h:143: note: candidates are: bool llvm::GraphWriter<GraphType>::isNodeHidden(typename llvm::GraphTraits<T>::NodeType&) [with GraphType = llvm::MCDFGraph<llvm::MachineFunction*>]</b></div>
<div><b>/home/abhi/work/llvm31/llvm/include/llvm/Support/GraphWriter.h:147: note: bool llvm::GraphWriter<GraphType>::isNodeHidden(typename llvm::GraphTraits<T>::NodeType* const*) [with GraphType = llvm::MCDFGraph<llvm::MachineFunction*>]</b></div>
<div><b>/home/abhi/work/llvm31/llvm/include/llvm/Support/GraphWriter.h:151: note: bool llvm::GraphWriter<GraphType>::isNodeHidden(typename llvm::GraphTraits<T>::NodeType*) [with GraphType = llvm::MCDFGraph<llvm::MachineFunction*>]</b></div>
<div><b>/home/abhi/work/llvm31/llvm/include/llvm/Support/GraphWriter.h:140: error: no matching function for call to ‘llvm::GraphWriter<llvm::MCDFGraph<llvm::MachineFunction*> >::writeNode(llvm::MachineInstr&)’</b></div>
<div><b>/home/abhi/work/llvm31/llvm/include/llvm/Support/GraphWriter.h:155: note: candidates are: void llvm::GraphWriter<GraphType>::writeNode(typename llvm::GraphTraits<T>::NodeType&) [with GraphType = llvm::MCDFGraph<llvm::MachineFunction*>]</b></div>
<div><b>/home/abhi/work/llvm31/llvm/include/llvm/Support/GraphWriter.h:159: note: void llvm::GraphWriter<GraphType>::writeNode(typename llvm::GraphTraits<T>::NodeType* const*) [with GraphType = llvm::MCDFGraph<llvm::MachineFunction*>]</b></div>
<div><b>/home/abhi/work/llvm31/llvm/include/llvm/Support/GraphWriter.h:163: note: void llvm::GraphWriter<GraphType>::writeNode(typename llvm::GraphTraits<T>::NodeType*) [with GraphType = llvm::MCDFGraph<llvm::MachineFunction*>]</b></div>
<div>gmake[2]: *** [/home/abhi/work/llvm31/llvm-build-new/lib/CodeGen/Debug+Asserts/MC_DFG.o] Error 1</div><div>gmake[2]: Leaving directory `/home/abhi/work/llvm31/llvm-build-new/lib/CodeGen'</div><div>gmake[1]: *** [CodeGen/.makeall] Error 2</div>
<div>gmake[1]: Leaving directory `/home/abhi/work/llvm31/llvm-build-new/lib'</div><div>gmake: *** [all] Error 1</div></div><div><br></div><div><div><br></div><div>The error seems to be a mismatch between types of the argument passed to the isNodeHidden and writeNode function in the GraphWriter.h file. But I am not sure where this type mismatch is originating from or how to fix it. Any idea what could be the issue here?</div>
<div><br></div><div>Here are some of the code snippets:</div><div><br></div><div><b>//templates for DFG and specializations of GraphTraits</b></div><div><div> template <typename T></div><div> class MCDFGraph {</div>
<div> private:</div><div> T p;</div><div> public:</div><div> MCDFGraph(T t) : p(t) {}</div><div> T operator*() { return p; }</div><div> };</div><div><br></div><div> template <> struct GraphTraits<MCDFGraph<MachineFunction*> > : public</div>
<div> GraphTraits<Value*> {</div><div> typedef mc_inst_iterator nodes_iterator;</div><div><br></div><div> static nodes_iterator nodes_begin(MCDFGraph<MachineFunction *> F) {</div><div> return mc_inst_begin(*F);</div>
<div> }</div><div><br></div><div> static nodes_iterator nodes_end(MCDFGraph<MachineFunction *> F) {</div><div> return mc_inst_end(*F);</div><div> }</div><div> };</div><div><br></div><div> template<></div>
<div> struct DOTGraphTraits<MCDFGraph<MachineFunction*> > : public DefaultDOTGraphTraits {</div><div> </div><div> DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}</div><div> </div>
<div> static std::string getGraphName(MCDFGraph<MachineFunction *> F) {</div><div> return "DFG for the function";</div><div> }</div><div><br></div><div> static std::string getSimpleNodeLabel(Value *Node,</div>
<div> const MCDFGraph<MachineFunction *> &F) {</div><div> std::string Str;</div><div> raw_string_ostream OS(Str);</div><div> </div><div> WriteAsOperand(OS, Node, false);</div>
<div> return OS.str();</div><div> }</div><div> </div><div> static std::string getCompleteNodeLabel(Value *Node, </div><div> const MCDFGraph<MachineFunction *> &F) {</div>
<div> std::string Str;</div><div> raw_string_ostream OS(Str);</div><div><br></div><div> if (!Node->getName().empty()) {</div><div> WriteAsOperand(OS, Node, false);</div><div> OS << ":\n";</div>
<div> }</div><div><br></div><div> OS << *Node;</div><div> std::string OutStr = OS.str();</div><div> if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());</div><div> </div><div> // Process string output to make it nicer...</div>
<div> for (unsigned i = 0; i != OutStr.length(); ++i)</div><div> if (OutStr[i] == '\n') { // Left justify</div><div> OutStr[i] = '\\';</div><div> OutStr.insert(OutStr.begin()+i+1, 'l');</div>
<div> } else if (OutStr[i] == ';') { // Delete comments!</div><div> unsigned Idx = OutStr.find('\n', i+1); // Find end of line</div><div> OutStr.erase(OutStr.begin()+i, OutStr.begin()+Idx);</div>
<div> --i;</div><div> }</div><div> </div><div> return OutStr;</div><div> }</div><div><br></div><div> std::string getNodeLabel(Value *&Node,</div><div> const MCDFGraph<MachineFunction *> &Graph) {</div>
<div> if (isSimple())</div><div> return getSimpleNodeLabel(Node, Graph);</div><div> else</div><div> return getCompleteNodeLabel(Node, Graph);</div><div> }</div><div><br></div><div> };</div><div>
<br></div></div><div><b>//Calls to ViewGraph and WriteGraph from the respective passes' runOnMachineFunction</b></div><div><div> ViewGraph(MCDFGraph<MachineFunction*>(&F), "Function:" + (F.getFunction())->getName());</div>
</div><div><br></div><div><div> WriteGraph(File, (MCDFGraph<MachineFunction*>)&F);</div></div><div><br></div><div><br></div><div>The MachineInstrIterator.h is quite lengthy, please let me know if I need to post it.</div>
<span class="HOEnZb"><font color="#888888">
<div><br></div>-- <br>Regards,<br>Abhishek<br>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Regards,<br>Abhishek<br>
</div></div>