LLVM  17.0.0git
MachineCFGPrinter.h
Go to the documentation of this file.
1 //===-- MachineCFGPrinter.h -------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 //===----------------------------------------------------------------------===//
10 
16 
17 namespace llvm {
18 
19 template <class GraphType> struct GraphTraits;
21 private:
22  const MachineFunction *F;
23 
24 public:
26 
27  const MachineFunction *getFunction() const { return this->F; }
28 };
29 
30 template <>
34  return &(CFGInfo->getFunction()->front());
35  }
36 
37  // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
39 
41  return nodes_iterator(CFGInfo->getFunction()->begin());
42  }
43 
45  return nodes_iterator(CFGInfo->getFunction()->end());
46  }
47 
48  static size_t size(DOTMachineFuncInfo *CFGInfo) {
49  return CFGInfo->getFunction()->size();
50  }
51 };
52 
53 template <>
55 
57 
58  static void eraseComment(std::string &OutStr, unsigned &I, unsigned Idx) {
59  OutStr.erase(OutStr.begin() + I, OutStr.begin() + Idx);
60  --I;
61  }
62 
63  static std::string getSimpleNodeLabel(const MachineBasicBlock *Node,
66  }
67 
68  static std::string getCompleteNodeLabel(
71  HandleBasicBlock =
72  [](raw_string_ostream &OS,
73  const MachineBasicBlock &Node) -> void { OS << Node; },
74  function_ref<void(std::string &, unsigned &, unsigned)>
75  HandleComment = eraseComment) {
76  return CompleteNodeLabelString(Node, HandleBasicBlock, HandleComment);
77  }
78 
79  std::string getNodeLabel(const MachineBasicBlock *Node,
80  DOTMachineFuncInfo *CFGInfo) {
81  if (isSimple())
82  return getSimpleNodeLabel(Node, CFGInfo);
83 
84  return getCompleteNodeLabel(Node, CFGInfo);
85  }
86 
87  static std::string getGraphName(DOTMachineFuncInfo *CFGInfo) {
88  return "Machine CFG for '" + CFGInfo->getFunction()->getName().str() +
89  "' function";
90  }
91 };
92 } // namespace llvm
MachineInstr.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::DOTMachineFuncInfo::DOTMachineFuncInfo
DOTMachineFuncInfo(const MachineFunction *F)
Definition: MachineCFGPrinter.h:25
llvm::DOTGraphTraits< DOTMachineFuncInfo * >::getGraphName
static std::string getGraphName(DOTMachineFuncInfo *CFGInfo)
Definition: MachineCFGPrinter.h:87
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:642
llvm::MachineFunction::end
iterator end()
Definition: MachineFunction.h:872
MachineBasicBlock.h
llvm::DOTGraphTraits< DOTMachineFuncInfo * >::getSimpleNodeLabel
static std::string getSimpleNodeLabel(const MachineBasicBlock *Node, DOTMachineFuncInfo *)
Definition: MachineCFGPrinter.h:63
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::MachineFunction::front
const MachineBasicBlock & front() const
Definition: MachineFunction.h:882
llvm::MachineFunction::size
unsigned size() const
Definition: MachineFunction.h:880
llvm::DOTMachineFuncInfo::getFunction
const MachineFunction * getFunction() const
Definition: MachineCFGPrinter.h:27
llvm::MachineFunction::begin
iterator begin()
Definition: MachineFunction.h:870
llvm::GraphTraits< DOTMachineFuncInfo * >::getEntryNode
static NodeRef getEntryNode(DOTMachineFuncInfo *CFGInfo)
Definition: MachineCFGPrinter.h:33
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:94
llvm::DOTGraphTraits
DOTGraphTraits - Template class that can be specialized to customize how graphs are converted to 'dot...
Definition: DOTGraphTraits.h:166
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
llvm::pointer_iterator
Definition: iterator.h:344
CFGPrinter.h
llvm::GraphTraits< DOTMachineFuncInfo * >::nodes_end
static nodes_iterator nodes_end(DOTMachineFuncInfo *CFGInfo)
Definition: MachineCFGPrinter.h:44
llvm::GraphTraits< DOTMachineFuncInfo * >::size
static size_t size(DOTMachineFuncInfo *CFGInfo)
Definition: MachineCFGPrinter.h:48
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::GraphTraits< const MachineBasicBlock * >
Definition: MachineBasicBlock.h:1225
llvm::MachineFunction::getName
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Definition: MachineFunction.cpp:582
llvm::DOTMachineFuncInfo
Definition: MachineCFGPrinter.h:20
llvm::MachineFunction
Definition: MachineFunction.h:258
Node
Definition: ItaniumDemangle.h:156
llvm::DOTGraphTraits< DOTMachineFuncInfo * >::getCompleteNodeLabel
static std::string getCompleteNodeLabel(const MachineBasicBlock *Node, DOTMachineFuncInfo *, function_ref< void(raw_string_ostream &, const MachineBasicBlock &)> HandleBasicBlock=[](raw_string_ostream &OS, const MachineBasicBlock &Node) -> void { OS<< Node;}, function_ref< void(std::string &, unsigned &, unsigned)> HandleComment=eraseComment)
Definition: MachineCFGPrinter.h:68
DOTGraphTraits.h
isSimple
static bool isSimple(Instruction *I)
Definition: SLPVectorizer.cpp:821
llvm::CompleteNodeLabelString
std::string CompleteNodeLabelString(const BasicBlockT *Node, function_ref< void(raw_string_ostream &, const BasicBlockT &)> HandleBasicBlock, function_ref< void(std::string &, unsigned &, unsigned)> HandleComment)
Definition: CFGPrinter.h:136
llvm::GraphTraits< DOTMachineFuncInfo * >::nodes_begin
static nodes_iterator nodes_begin(DOTMachineFuncInfo *CFGInfo)
Definition: MachineCFGPrinter.h:40
llvm::DOTGraphTraits< DOTMachineFuncInfo * >::DOTGraphTraits
DOTGraphTraits(bool isSimple=false)
Definition: MachineCFGPrinter.h:56
llvm::DOTGraphTraits< DOTMachineFuncInfo * >::eraseComment
static void eraseComment(std::string &OutStr, unsigned &I, unsigned Idx)
Definition: MachineCFGPrinter.h:58
llvm::DefaultDOTGraphTraits
DefaultDOTGraphTraits - This class provides the default implementations of all of the DOTGraphTraits ...
Definition: DOTGraphTraits.h:28
llvm::StringRef::str
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:222
llvm::DOTGraphTraits< DOTMachineFuncInfo * >::getNodeLabel
std::string getNodeLabel(const MachineBasicBlock *Node, DOTMachineFuncInfo *CFGInfo)
Definition: MachineCFGPrinter.h:79
llvm::GraphTraits
Definition: GraphTraits.h:37
llvm::SimpleNodeLabelString
std::string SimpleNodeLabelString(const BasicBlockT *Node)
Definition: CFGPrinter.h:124
MachineFunction.h