llvm.org GIT mirror llvm / 25ad1cc
Twinify GraphWriter a little bit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@144647 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 8 years ago
7 changed file(s) with 20 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
1717
1818 #include "llvm/ADT/ArrayRef.h"
1919 #include "llvm/ADT/IntEqClasses.h"
20 #include "llvm/ADT/Twine.h"
2021 #include "llvm/CodeGen/MachineFunctionPass.h"
2122
2223 namespace llvm {
6061 /// Specialize WriteGraph, the standard implementation won't work.
6162 raw_ostream &WriteGraph(raw_ostream &O, const EdgeBundles &G,
6263 bool ShortNames = false,
63 const std::string &Title = "");
64 const Twine &Title = "");
6465
6566 } // end namespace llvm
6667
295295 template
296296 raw_ostream &WriteGraph(raw_ostream &O, const GraphType &G,
297297 bool ShortNames = false,
298 const std::string &Title = "") {
298 const Twine &Title = "") {
299299 // Start the graph emission process...
300300 GraphWriter W(O, G, ShortNames);
301301
302302 // Emit the graph.
303 W.writeGraph(Title);
303 W.writeGraph(Title.str());
304304
305305 return O;
306306 }
307307
308308 template
309 sys::Path WriteGraph(const GraphType &G, const std::string &Name,
310 bool ShortNames = false, const std::string &Title = "") {
309 sys::Path WriteGraph(const GraphType &G, const Twine &Name,
310 bool ShortNames = false, const Twine &Title = "") {
311311 std::string ErrMsg;
312312 sys::Path Filename = sys::Path::GetTemporaryDirectory(&ErrMsg);
313313 if (Filename.isEmpty()) {
314314 errs() << "Error: " << ErrMsg << "\n";
315315 return Filename;
316316 }
317 Filename.appendComponent(Name + ".dot");
317 Filename.appendComponent((Name + ".dot").str());
318318 if (Filename.makeUnique(true,&ErrMsg)) {
319319 errs() << "Error: " << ErrMsg << "\n";
320320 return sys::Path();
340340 /// then cleanup. For use from the debugger.
341341 ///
342342 template
343 void ViewGraph(const GraphType &G, const std::string &Name,
344 bool ShortNames = false, const std::string &Title = "",
343 void ViewGraph(const GraphType &G, const Twine &Name,
344 bool ShortNames = false, const Twine &Title = "",
345345 GraphProgram::Name Program = GraphProgram::DOT) {
346346 sys::Path Filename = llvm::WriteGraph(G, Name, ShortNames, Title);
347347
142142 /// being a 'dot' and 'gv' program in your path.
143143 ///
144144 void Function::viewCFG() const {
145 ViewGraph(this, "cfg" + getNameStr());
145 ViewGraph(this, "cfg" + getName());
146146 }
147147
148148 /// viewCFGOnly - This function is meant for use from the debugger. It works
151151 /// his can make the graph smaller.
152152 ///
153153 void Function::viewCFGOnly() const {
154 ViewGraph(this, "cfg" + getNameStr(), true);
154 ViewGraph(this, "cfg" + getName(), true);
155155 }
156156
157157 FunctionPass *llvm::createCFGPrinterPass () {
7676 /// Specialize WriteGraph, the standard implementation won't work.
7777 raw_ostream &llvm::WriteGraph(raw_ostream &O, const EdgeBundles &G,
7878 bool ShortNames,
79 const std::string &Title) {
79 const Twine &Title) {
8080 const MachineFunction *MF = G.getMachineFunction();
8181
8282 O << "digraph {\n";
367367 void MachineFunction::viewCFG() const
368368 {
369369 #ifndef NDEBUG
370 ViewGraph(this, "mf" + getFunction()->getNameStr());
370 ViewGraph(this, "mf" + getFunction()->getName());
371371 #else
372372 errs() << "MachineFunction::viewCFG is only available in debug builds on "
373373 << "systems with Graphviz or gv!\n";
377377 void MachineFunction::viewCFGOnly() const
378378 {
379379 #ifndef NDEBUG
380 ViewGraph(this, "mf" + getFunction()->getNameStr(), true);
380 ViewGraph(this, "mf" + getFunction()->getName(), true);
381381 #else
382382 errs() << "MachineFunction::viewCFGOnly is only available in debug builds on "
383383 << "systems with Graphviz or gv!\n";
8585 // This code is only for debugging!
8686 #ifndef NDEBUG
8787 if (BB->getBasicBlock())
88 ViewGraph(this, "dag." + MF.getFunction()->getNameStr(), false,
89 "Scheduling-Units Graph for " + MF.getFunction()->getNameStr() +
90 ":" + BB->getBasicBlock()->getNameStr());
88 ViewGraph(this, "dag." + MF.getFunction()->getName(), false,
89 "Scheduling-Units Graph for " + MF.getFunction()->getName() +
90 ":" + BB->getBasicBlock()->getName());
9191 else
92 ViewGraph(this, "dag." + MF.getFunction()->getNameStr(), false,
93 "Scheduling-Units Graph for " + MF.getFunction()->getNameStr());
92 ViewGraph(this, "dag." + MF.getFunction()->getName(), false,
93 "Scheduling-Units Graph for " + MF.getFunction()->getName());
9494 #else
9595 errs() << "ScheduleDAG::viewGraph is only available in debug builds on "
9696 << "systems with Graphviz or gv!\n";
146146 void SelectionDAG::viewGraph(const std::string &Title) {
147147 // This code is only for debugging!
148148 #ifndef NDEBUG
149 ViewGraph(this, "dag." + getMachineFunction().getFunction()->getNameStr(),
149 ViewGraph(this, "dag." + getMachineFunction().getFunction()->getName(),
150150 false, Title);
151151 #else
152152 errs() << "SelectionDAG::viewGraph is only available in debug builds on "