//===-- DomPrinter.h - Dom printer external interface ------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file defines external functions that can be called to explicitly // instantiate the dominance tree printer. // //===----------------------------------------------------------------------===// #ifndef LLVM_ANALYSIS_DOMPRINTER_H #define LLVM_ANALYSIS_DOMPRINTER_H #include "llvm/Analysis/DOTGraphTraitsPass.h" #include "llvm/Analysis/PostDominators.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/PassManager.h" namespace llvm { template <> struct DOTGraphTraits : public DefaultDOTGraphTraits { DOTGraphTraits(bool isSimple = false) : DefaultDOTGraphTraits(isSimple) {} std::string getNodeLabel(DomTreeNode *Node, DomTreeNode *Graph) { BasicBlock *BB = Node->getBlock(); if (!BB) return "Post dominance root node"; if (isSimple()) return DOTGraphTraits::getSimpleNodeLabel(BB, nullptr); return DOTGraphTraits::getCompleteNodeLabel(BB, nullptr); } }; template <> struct DOTGraphTraits : public DOTGraphTraits { DOTGraphTraits(bool isSimple = false) : DOTGraphTraits(isSimple) {} static std::string getGraphName(DominatorTree *DT) { return "Dominator tree"; } std::string getNodeLabel(DomTreeNode *Node, DominatorTree *G) { return DOTGraphTraits::getNodeLabel(Node, G->getRootNode()); } }; template<> struct DOTGraphTraits : public DOTGraphTraits { DOTGraphTraits (bool isSimple=false) : DOTGraphTraits(isSimple) {} static std::string getGraphName(PostDominatorTree *DT) { return "Post dominator tree"; } std::string getNodeLabel(DomTreeNode *Node, PostDominatorTree *G) { return DOTGraphTraits::getNodeLabel(Node, G->getRootNode()); } }; struct DomViewer final : DOTGraphTraitsViewer { DomViewer() : DOTGraphTraitsViewer("dom") {} }; struct DomOnlyViewer final : DOTGraphTraitsViewer { DomOnlyViewer() : DOTGraphTraitsViewer("domonly") {} }; struct PostDomViewer final : DOTGraphTraitsViewer { PostDomViewer() : DOTGraphTraitsViewer("postdom") {} }; struct PostDomOnlyViewer final : DOTGraphTraitsViewer { PostDomOnlyViewer() : DOTGraphTraitsViewer("postdomonly") {} }; struct DomPrinter final : DOTGraphTraitsPrinter { DomPrinter() : DOTGraphTraitsPrinter("dom") {} }; struct DomOnlyPrinter final : DOTGraphTraitsPrinter { DomOnlyPrinter() : DOTGraphTraitsPrinter("domonly") {} }; struct PostDomPrinter final : DOTGraphTraitsPrinter { PostDomPrinter() : DOTGraphTraitsPrinter("postdom") {} }; struct PostDomOnlyPrinter final : DOTGraphTraitsPrinter { PostDomOnlyPrinter() : DOTGraphTraitsPrinter("postdomonly") {} }; } // namespace llvm namespace llvm { class FunctionPass; FunctionPass *createDomPrinterWrapperPassPass(); FunctionPass *createDomOnlyPrinterWrapperPassPass(); FunctionPass *createDomViewerWrapperPassPass(); FunctionPass *createDomOnlyViewerWrapperPassPass(); FunctionPass *createPostDomPrinterWrapperPassPass(); FunctionPass *createPostDomOnlyPrinterWrapperPassPass(); FunctionPass *createPostDomViewerWrapperPassPass(); FunctionPass *createPostDomOnlyViewerWrapperPassPass(); } // End llvm namespace #endif