1 //===-- DomPrinter.h - Dom printer external interface ------------*- 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 // This file defines external functions that can be called to explicitly 10 // instantiate the dominance tree printer. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_ANALYSIS_DOMPRINTER_H 15 #define LLVM_ANALYSIS_DOMPRINTER_H 16 17 #include "llvm/Analysis/DOTGraphTraitsPass.h" 18 #include "llvm/Analysis/PostDominators.h" 19 #include "llvm/IR/Dominators.h" 20 21 namespace llvm { 22 23 template <> 24 struct DOTGraphTraits<DomTreeNode *> : public DefaultDOTGraphTraits { 25 26 DOTGraphTraits(bool isSimple = false) : DefaultDOTGraphTraits(isSimple) {} 27 28 std::string getNodeLabel(DomTreeNode *Node, DomTreeNode *Graph) { 29 30 BasicBlock *BB = Node->getBlock(); 31 32 if (!BB) 33 return "Post dominance root node"; 34 35 if (isSimple()) 36 return DOTGraphTraits<DOTFuncInfo *>::getSimpleNodeLabel(BB, nullptr); 37 38 return DOTGraphTraits<DOTFuncInfo *>::getCompleteNodeLabel(BB, nullptr); 39 } 40 }; 41 42 template <> 43 struct DOTGraphTraits<DominatorTree *> 44 : public DOTGraphTraits<DomTreeNode *> { 45 46 DOTGraphTraits(bool isSimple = false) 47 : DOTGraphTraits<DomTreeNode *>(isSimple) {} 48 49 static std::string getGraphName(DominatorTree *DT) { 50 return "Dominator tree"; 51 } 52 53 std::string getNodeLabel(DomTreeNode *Node, DominatorTree *G) { 54 return DOTGraphTraits<DomTreeNode *>::getNodeLabel(Node, 55 G->getRootNode()); 56 } 57 }; 58 59 template<> 60 struct DOTGraphTraits<PostDominatorTree *> 61 : public DOTGraphTraits<DomTreeNode*> { 62 63 DOTGraphTraits (bool isSimple=false) 64 : DOTGraphTraits<DomTreeNode*>(isSimple) {} 65 66 static std::string getGraphName(PostDominatorTree *DT) { 67 return "Post dominator tree"; 68 } 69 70 std::string getNodeLabel(DomTreeNode *Node, 71 PostDominatorTree *G) { 72 return DOTGraphTraits<DomTreeNode*>::getNodeLabel(Node, G->getRootNode()); 73 } 74 }; 75 76 struct DomViewer final : DOTGraphTraitsViewer<DominatorTreeAnalysis, false> { 77 DomViewer() : DOTGraphTraitsViewer<DominatorTreeAnalysis, false>("dom") {} 78 }; 79 80 struct DomOnlyViewer final : DOTGraphTraitsViewer<DominatorTreeAnalysis, true> { 81 DomOnlyViewer() 82 : DOTGraphTraitsViewer<DominatorTreeAnalysis, true>("domonly") {} 83 }; 84 85 struct PostDomViewer final 86 : DOTGraphTraitsViewer<PostDominatorTreeAnalysis, false> { 87 PostDomViewer() 88 : DOTGraphTraitsViewer<PostDominatorTreeAnalysis, false>("postdom") {} 89 }; 90 91 struct PostDomOnlyViewer final 92 : DOTGraphTraitsViewer<PostDominatorTreeAnalysis, true> { 93 PostDomOnlyViewer() 94 : DOTGraphTraitsViewer<PostDominatorTreeAnalysis, true>("postdomonly") {} 95 }; 96 97 struct DomPrinter final : DOTGraphTraitsPrinter<DominatorTreeAnalysis, false> { 98 DomPrinter() : DOTGraphTraitsPrinter<DominatorTreeAnalysis, false>("dom") {} 99 }; 100 101 struct DomOnlyPrinter final 102 : DOTGraphTraitsPrinter<DominatorTreeAnalysis, true> { 103 DomOnlyPrinter() 104 : DOTGraphTraitsPrinter<DominatorTreeAnalysis, true>("domonly") {} 105 }; 106 107 struct PostDomPrinter final 108 : DOTGraphTraitsPrinter<PostDominatorTreeAnalysis, false> { 109 PostDomPrinter() 110 : DOTGraphTraitsPrinter<PostDominatorTreeAnalysis, false>("postdom") {} 111 }; 112 113 struct PostDomOnlyPrinter final 114 : DOTGraphTraitsPrinter<PostDominatorTreeAnalysis, true> { 115 PostDomOnlyPrinter() 116 : DOTGraphTraitsPrinter<PostDominatorTreeAnalysis, true>("postdomonly") {} 117 }; 118 } // namespace llvm 119 120 namespace llvm { 121 class FunctionPass; 122 FunctionPass *createDomPrinterWrapperPassPass(); 123 FunctionPass *createDomOnlyPrinterWrapperPassPass(); 124 FunctionPass *createDomViewerWrapperPassPass(); 125 FunctionPass *createDomOnlyViewerWrapperPassPass(); 126 FunctionPass *createPostDomPrinterWrapperPassPass(); 127 FunctionPass *createPostDomOnlyPrinterWrapperPassPass(); 128 FunctionPass *createPostDomViewerWrapperPassPass(); 129 FunctionPass *createPostDomOnlyViewerWrapperPassPass(); 130 } // End llvm namespace 131 132 #endif 133