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

32namespace llvm {

33

36 if (!Node->isSubRegion()) {

38

41 else

43 }

44

45 return "Not implemented";

46}

47

48template <>

50

53

55

58 Node, reinterpret_cast<RegionNode *>(G->getTopLevelRegion()));

59 }

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)

108 printRegionCluster(*RI, GW, depth + 1);

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";

125 printRegionCluster(*G->getTopLevelRegion(), GW, 4);

126 }

127};

128}

129

130namespace {

131

132struct RegionInfoPassGraphTraits {

135 }

136};

137

138struct RegionPrinter

140 RegionInfoPass, false, RegionInfo *, RegionInfoPassGraphTraits> {

141 static char ID;

142 RegionPrinter()

144 RegionInfoPassGraphTraits>("reg", ID) {

146 }

147};

148char RegionPrinter::ID = 0;

149

150struct RegionOnlyPrinter

152 RegionInfoPass, true, RegionInfo *, RegionInfoPassGraphTraits> {

153 static char ID;

154 RegionOnlyPrinter()

156 RegionInfoPassGraphTraits>("reg", ID) {

158 }

159};

160char RegionOnlyPrinter::ID = 0;

161

162struct RegionViewer

164 RegionInfoPass, false, RegionInfo *, RegionInfoPassGraphTraits> {

165 static char ID;

166 RegionViewer()

168 RegionInfoPassGraphTraits>("reg", ID) {

170 }

171};

172char RegionViewer::ID = 0;

173

174struct RegionOnlyViewer

176 RegionInfoPassGraphTraits> {

177 static char ID;

178 RegionOnlyViewer()

180 RegionInfoPassGraphTraits>("regonly",

181 ID) {

183 }

184};

185char RegionOnlyViewer::ID = 0;

186

187}

188

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

191

196

199

203

205

207 return new RegionOnlyPrinter();

208}

209

211 return new RegionViewer();

212}

213

215 return new RegionOnlyViewer();

216}

217

218#ifndef NDEBUG

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

221

224

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

227}

228

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

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

232

233

234

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

236

238 FPM.add(ViewerPass);

240 FPM.run(*NonConstF);

242}

243

245

248}

249

251

254}

255#endif

Performs the initial survey of the specified function

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

static void viewRegionInfo(RegionInfo *RI, bool ShortNames)

dot regions Print regions of function to dot file(with no function bodies)"

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)

dot regions Print regions of function to dot true

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

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.

static PassRegistry * getPassRegistry()

getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...

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?

T * getNodeAs() const

Get the content of this RegionNode.

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.

void initializeRegionViewerPass(PassRegistry &)

FunctionPass * createRegionOnlyViewerPass()

FunctionPass * createRegionPrinterPass()

void initializeRegionOnlyPrinterPass(PassRegistry &)

void initializeRegionOnlyViewerPass(PassRegistry &)

FunctionPass * createRegionOnlyPrinterPass()

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.

FunctionPass * createRegionViewerPass()

void viewRegion(llvm::RegionInfo *RI)

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

void initializeRegionPrinterPass(PassRegistry &)

void viewRegionOnly(llvm::RegionInfo *RI)

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

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

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

DOTGraphTraits(bool isSimple=false)

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

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

static std::string getGraphName(const RegionInfo *)

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...