xref: /netbsd-src/external/apache2/llvm/dist/llvm/tools/opt/GraphPrinters.cpp (revision 7330f729ccf0bd976a06f95fad452fe774fc7fd1)
1 //===- GraphPrinters.cpp - DOT printers for various graph types -----------===//
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 // This file defines several printers for various different types of graphs used
10 // by the LLVM infrastructure.  It uses the generic graph interface to convert
11 // the graph into a .dot graph.  These graphs can then be processed with the
12 // "dot" tool to convert them to postscript or some other suitable format.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #include "llvm/IR/Dominators.h"
17 #include "llvm/Pass.h"
18 
19 using namespace llvm;
20 
21 //===----------------------------------------------------------------------===//
22 //                            DomInfoPrinter Pass
23 //===----------------------------------------------------------------------===//
24 
25 namespace {
26   class DomInfoPrinter : public FunctionPass {
27   public:
28     static char ID; // Pass identification, replacement for typeid
DomInfoPrinter()29     DomInfoPrinter() : FunctionPass(ID) {}
30 
getAnalysisUsage(AnalysisUsage & AU) const31     void getAnalysisUsage(AnalysisUsage &AU) const override {
32       AU.setPreservesAll();
33       AU.addRequired<DominatorTreeWrapperPass>();
34     }
35 
runOnFunction(Function & F)36     bool runOnFunction(Function &F) override {
37       getAnalysis<DominatorTreeWrapperPass>().print(dbgs());
38       return false;
39     }
40   };
41 }
42 
43 char DomInfoPrinter::ID = 0;
44 static RegisterPass<DomInfoPrinter>
45 DIP("print-dom-info", "Dominator Info Printer", true, true);
46