[LLVMdev] DFG of machine functions

AbhishekR abhishekr1982 at gmail.com
Wed May 30 20:21:39 PDT 2012


Hi,
I am trying to generate the DFG of machine functions.

Initially, I added a pass to generate the DFG of LLVM IR functions. This
was based on the mail thread -
http://lists.cs.uiuc.edu/pipermail/llvmdev/2009-September/025582.html. This
pass worked fine and I was able to generate DFG of LLVM IR functions.

Later, I ported the DFG pass code for machine functions. I ported the
InstIterator.h (which was required to use inst_iterator in the *template <>
struct GraphTraits<DFG<Function*> >*) to MachineInstrIterator.h to iterate
over machine instructions in a machine function. But the build is throwing
the following error:

llvm[2]: Compiling MC_DFG.cpp for Debug+Asserts build
/home/abhi/work/llvm31/llvm/include/llvm/Support/GraphWriter.h: In member
function ‘void llvm::GraphWriter<GraphType>::writeNodes() [with GraphType =
llvm::MCDFGraph<llvm::MachineFunction*>]’:
/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*>]’
/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*>]’
/home/abhi/work/llvm31/llvm/lib/CodeGen/MC_DFG.cpp:249:   instantiated from
here
*/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&)’*
*/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*>]*
*/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*>]*
*/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*>]*
*/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&)’*
*/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*>]*
*/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*>]*
*/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*>]*
gmake[2]: ***
[/home/abhi/work/llvm31/llvm-build-new/lib/CodeGen/Debug+Asserts/MC_DFG.o]
Error 1
gmake[2]: Leaving directory
`/home/abhi/work/llvm31/llvm-build-new/lib/CodeGen'
gmake[1]: *** [CodeGen/.makeall] Error 2
gmake[1]: Leaving directory `/home/abhi/work/llvm31/llvm-build-new/lib'
gmake: *** [all] Error 1


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?

Here are some of the code snippets:

*//templates for DFG and specializations of GraphTraits*
  template <typename T>
  class MCDFGraph {
  private:
    T p;
  public:
    MCDFGraph(T t) : p(t) {}
    T operator*() { return p; }
  };

  template <> struct GraphTraits<MCDFGraph<MachineFunction*> > : public
  GraphTraits<Value*> {
    typedef mc_inst_iterator nodes_iterator;

    static nodes_iterator nodes_begin(MCDFGraph<MachineFunction *> F) {
      return mc_inst_begin(*F);
    }

    static nodes_iterator nodes_end(MCDFGraph<MachineFunction *> F) {
      return mc_inst_end(*F);
    }
  };

  template<>
  struct DOTGraphTraits<MCDFGraph<MachineFunction*> > : public
DefaultDOTGraphTraits {

    DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple)
{}

    static std::string getGraphName(MCDFGraph<MachineFunction *> F) {
      return "DFG for the function";
    }

    static std::string getSimpleNodeLabel(Value *Node,
                                          const MCDFGraph<MachineFunction
*> &F) {
      std::string Str;
      raw_string_ostream OS(Str);

      WriteAsOperand(OS, Node, false);
      return OS.str();
    }

    static std::string getCompleteNodeLabel(Value *Node,
                                            const MCDFGraph<MachineFunction
*> &F) {
      std::string Str;
      raw_string_ostream OS(Str);

      if (!Node->getName().empty()) {
        WriteAsOperand(OS, Node, false);
        OS << ":\n";
      }

      OS << *Node;
      std::string OutStr = OS.str();
      if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());

      // Process string output to make it nicer...
      for (unsigned i = 0; i != OutStr.length(); ++i)
        if (OutStr[i] == '\n') {                            // Left justify
          OutStr[i] = '\\';
          OutStr.insert(OutStr.begin()+i+1, 'l');
        } else if (OutStr[i] == ';') {                      // Delete
comments!
          unsigned Idx = OutStr.find('\n', i+1);            // Find end of
line
          OutStr.erase(OutStr.begin()+i, OutStr.begin()+Idx);
          --i;
        }

      return OutStr;
    }

    std::string getNodeLabel(Value *&Node,
                             const MCDFGraph<MachineFunction *> &Graph) {
      if (isSimple())
        return getSimpleNodeLabel(Node, Graph);
      else
        return getCompleteNodeLabel(Node, Graph);
    }

  };

*//Calls to ViewGraph and WriteGraph from the respective passes'
runOnMachineFunction*
    ViewGraph(MCDFGraph<MachineFunction*>(&F), "Function:" +
(F.getFunction())->getName());

          WriteGraph(File, (MCDFGraph<MachineFunction*>)&F);


The MachineInstrIterator.h is quite lengthy, please let me know if I need
to post it.

-- 
Regards,
Abhishek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120530/88babf4b/attachment.html>


More information about the llvm-dev mailing list