LLVM: lib/Analysis/RegionPrinter.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

18#ifndef NDEBUG

20#endif

21

22using namespace llvm;

23

24

25

28 cl::desc("Show only simple regions in the graphviz viewer"),

31

32std::string

35 if (Node->isSubRegion()) {

37

40 else

42 }

43

44 return "Not implemented";

45}

46

47template <>

50

53

55

60

65

67 return "";

68

69

72

73 Region *R = G->getRegionFor(destBB);

74

75 while (R && R->getParent())

76 if (R->getParent()->getEntry() == destBB)

77 R = R->getParent();

78 else

79 break;

80

81 if (R && R->getEntry() == destBB && R->contains(srcBB))

82 return "constraint=false";

83

84 return "";

85 }

86

87

88

90 unsigned depth = 0) {

92 O.indent(2 * depth) << "subgraph cluster_" << static_cast<const void*>(&R)

93 << " {\n";

94 O.indent(2 * (depth + 1)) << "label = \"\";\n";

95

97 O.indent(2 * (depth + 1)) << "style = filled;\n";

98 O.indent(2 * (depth + 1)) << "color = "

99 << ((R.getDepth() * 2 % 12) + 1) << "\n";

100

101 } else {

102 O.indent(2 * (depth + 1)) << "style = solid;\n";

103 O.indent(2 * (depth + 1)) << "color = "

104 << ((R.getDepth() * 2 % 12) + 2) << "\n";

105 }

106

107 for (const auto &RI : R)

109

111

112 for (auto *BB : R.blocks())

114 O.indent(2 * (depth + 1)) << "Node"

115 << static_cast<const void*>(RI.getTopLevelRegion()->getBBNode(BB))

116 << ";\n";

117

118 O.indent(2 * depth) << "}\n";

119 }

120

124 O << "\tcolorscheme = \"paired12\"\n";

126 }

127};

128

129namespace {

130

131struct RegionInfoPassGraphTraits {

134 }

135};

136

137struct RegionPrinter

138 : public DOTGraphTraitsPrinterWrapperPass<

139 RegionInfoPass, false, RegionInfo *, RegionInfoPassGraphTraits> {

140 static char ID;

141 RegionPrinter()

142 : DOTGraphTraitsPrinterWrapperPass<RegionInfoPass, false, RegionInfo *,

143 RegionInfoPassGraphTraits>("reg", ID) {

144 }

145};

146char RegionPrinter::ID = 0;

147

148struct RegionOnlyPrinter

149 : public DOTGraphTraitsPrinterWrapperPass<

150 RegionInfoPass, true, RegionInfo *, RegionInfoPassGraphTraits> {

151 static char ID;

152 RegionOnlyPrinter()

153 : DOTGraphTraitsPrinterWrapperPass<RegionInfoPass, true, RegionInfo *,

154 RegionInfoPassGraphTraits>("reg", ID) {

155 }

156};

157char RegionOnlyPrinter::ID = 0;

158

159struct RegionViewer

160 : public DOTGraphTraitsViewerWrapperPass<

161 RegionInfoPass, false, RegionInfo *, RegionInfoPassGraphTraits> {

162 static char ID;

163 RegionViewer()

164 : DOTGraphTraitsViewerWrapperPass<RegionInfoPass, false, RegionInfo *,

165 RegionInfoPassGraphTraits>("reg", ID) {}

166};

167char RegionViewer::ID = 0;

168

169struct RegionOnlyViewer

170 : public DOTGraphTraitsViewerWrapperPass<RegionInfoPass, true, RegionInfo *,

171 RegionInfoPassGraphTraits> {

172 static char ID;

173 RegionOnlyViewer()

174 : DOTGraphTraitsViewerWrapperPass<RegionInfoPass, true, RegionInfo *,

175 RegionInfoPassGraphTraits>("regonly",

176 ID) {}

177};

178char RegionOnlyViewer::ID = 0;

179

180}

181

183 "Print regions of function to 'dot' file", true, true)

184

186 RegionOnlyPrinter, "dot-regions-only",

187 "Print regions of function to 'dot' file (with no function bodies)", true,

189

190INITIALIZE_PASS(RegionViewer, "view-regions", "View regions of function",

192

194 "View regions of function (with no function bodies)",

196

198

200 return new RegionOnlyPrinter();

201}

202

204 return new RegionViewer();

205}

206

208 return new RegionOnlyViewer();

209}

210

211#ifndef NDEBUG

213 assert(RI && "Argument must be non-null");

214

217

219 Twine(GraphName) + " for '" + F->getName() + "' function");

220}

221

223 assert(F && "Argument must be non-null");

224 assert(F->isDeclaration() && "Function must have an implementation");

225

226

227

228 auto NonConstF = const_cast<Function *>(F);

229

231 FPM.add(ViewerPass);

233 FPM.run(*NonConstF);

235}

236

238

242

244

248#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

Function Alias Analysis false

#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)

static void viewRegionInfo(RegionInfo *RI, bool ShortNames)

Definition RegionPrinter.cpp:212

static cl::opt< bool > onlySimpleRegions("only-simple-regions", cl::desc("Show only simple regions in the graphviz viewer"), cl::Hidden, cl::init(false))

onlySimpleRegion - Show only the simple regions in the RegionViewer.

static void invokeFunctionPass(const Function *F, FunctionPass *ViewerPass)

Definition RegionPrinter.cpp:222

static bool isSimple(Instruction *I)

LLVM Basic Block Representation.

FunctionPass class - This class is used to implement most global optimizations.

raw_ostream & getOStream()

getOStream - Get the raw output stream into the graph file.

RegionT * getTopLevelRegion() const

RegionT * getRegionFor(BlockT *BB) const

Get the smallest region that contains a BasicBlock.

RegionInfo & getRegionInfo()

bool isSubRegion() const

Is this RegionNode a subregion?

BasicBlock * getNodeAs() const

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

FunctionPassManager manages FunctionPasses.

bool run(Function &F)

run - Execute all of the passes scheduled for execution.

void add(Pass *P) override

Add a pass to the queue of passes to run.

bool doInitialization()

doInitialization - Run all of the initializers for the function passes.

bool doFinalization()

doFinalization - Run all of the finalizers for the function passes.

This class implements an extremely fast bulk output stream that can only output to a stream.

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

initializer< Ty > init(const Ty &Val)

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI FunctionPass * createRegionOnlyViewerPass()

Definition RegionPrinter.cpp:207

LLVM_ABI FunctionPass * createRegionPrinterPass()

Definition RegionPrinter.cpp:197

LLVM_ABI FunctionPass * createRegionOnlyPrinterPass()

Definition RegionPrinter.cpp:199

void ViewGraph(const GraphType &G, const Twine &Name, bool ShortNames=false, const Twine &Title="", GraphProgram::Name Program=GraphProgram::DOT)

ViewGraph - Emit a dot graph, run 'dot', run gv on the postscript file, then cleanup.

LLVM_ABI FunctionPass * createRegionViewerPass()

Definition RegionPrinter.cpp:203

void viewRegion(llvm::RegionInfo *RI)

Open a viewer to display the GraphViz vizualization of the analysis result.

Definition RegionPrinter.cpp:237

void viewRegionOnly(llvm::RegionInfo *RI)

Open a viewer to display the GraphViz vizualization of the analysis result.

Definition RegionPrinter.cpp:243

static void addCustomGraphFeatures(const RegionInfo *G, GraphWriter< RegionInfo * > &GW)

Definition RegionPrinter.cpp:121

std::string getNodeLabel(RegionNode *Node, RegionInfo *G)

Definition RegionPrinter.cpp:56

DOTGraphTraits(bool isSimple=false)

Definition RegionPrinter.cpp:51

std::string getEdgeAttributes(RegionNode *srcNode, GraphTraits< RegionInfo * >::ChildIteratorType CI, RegionInfo *G)

Definition RegionPrinter.cpp:61

static void printRegionCluster(const Region &R, GraphWriter< RegionInfo * > &GW, unsigned depth=0)

Definition RegionPrinter.cpp:89

static std::string getGraphName(const RegionInfo *)

Definition RegionPrinter.cpp:54

DOTGraphTraits(bool isSimple=false)

DOTGraphTraits - Template class that can be specialized to customize how graphs are converted to 'dot...

std::string getNodeLabel(const void *, const GraphType &)

getNodeLabel - Given a node and a pointer to the top level graph, return the label to print in the no...