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">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>
<div><br></div>-- <br>Regards,<br>Abhishek<br>
</div>