//===- GraphPrinter.h - Create a DOT output describing the Scop. ----------===// // // 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 // //===----------------------------------------------------------------------===// // // Create a DOT output describing the Scop. // // For each function a dot file is created that shows the control flow graph of // the function and highlights the detected Scops. // //===----------------------------------------------------------------------===// #ifndef POLLY_SCOP_GRAPH_PRINTER_H #define POLLY_SCOP_GRAPH_PRINTER_H #include "polly/ScopDetection.h" #include "polly/Support/ScopLocation.h" #include "llvm/Analysis/DOTGraphTraitsPass.h" #include "llvm/Analysis/RegionInfo.h" #include "llvm/Analysis/RegionIterator.h" #include "llvm/Analysis/RegionPrinter.h" #include "llvm/IR/PassManager.h" namespace llvm { template <> struct GraphTraits : GraphTraits { static NodeRef getEntryNode(polly::ScopDetection *SD) { return GraphTraits::getEntryNode(SD->getRI()); } static nodes_iterator nodes_begin(polly::ScopDetection *SD) { return nodes_iterator::begin(getEntryNode(SD)); } static nodes_iterator nodes_end(polly::ScopDetection *SD) { return nodes_iterator::end(getEntryNode(SD)); } }; template <> struct DOTGraphTraits : DOTGraphTraits { DOTGraphTraits(bool isSimple = false) : DOTGraphTraits(isSimple) {} static std::string getGraphName(polly::ScopDetection *SD) { return "Scop Graph"; } std::string getEdgeAttributes(RegionNode *srcNode, GraphTraits::ChildIteratorType CI, polly::ScopDetection *SD); std::string getNodeLabel(RegionNode *Node, polly::ScopDetection *SD) { return DOTGraphTraits::getNodeLabel( Node, reinterpret_cast(SD->getRI()->getTopLevelRegion())); } static std::string escapeString(llvm::StringRef String); /// Print the cluster of the subregions. This groups the single basic blocks /// and adds a different background color for each group. static void printRegionCluster(polly::ScopDetection *SD, const Region *R, raw_ostream &O, unsigned depth = 0); static void addCustomGraphFeatures(polly::ScopDetection *SD, GraphWriter &GW); }; } // end namespace llvm namespace polly { struct ScopViewer final : llvm::DOTGraphTraitsViewer { ScopViewer() : llvm::DOTGraphTraitsViewer("scops") {} bool processFunction(Function &F, const ScopDetection &SD) override; }; struct ScopOnlyViewer final : llvm::DOTGraphTraitsViewer { ScopOnlyViewer() : llvm::DOTGraphTraitsViewer("scops-only") {} }; struct ScopPrinter final : llvm::DOTGraphTraitsPrinter { ScopPrinter() : llvm::DOTGraphTraitsPrinter("scops") {} }; struct ScopOnlyPrinter final : llvm::DOTGraphTraitsPrinter { ScopOnlyPrinter() : llvm::DOTGraphTraitsPrinter("scopsonly") {} }; } // end namespace polly #endif /* POLLY_SCOP_GRAPH_PRINTER_H */