Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:48:21

0001 //===- GraphPrinter.h - Create a DOT output describing the Scop. ----------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Create a DOT output describing the Scop.
0010 //
0011 // For each function a dot file is created that shows the control flow graph of
0012 // the function and highlights the detected Scops.
0013 //
0014 //===----------------------------------------------------------------------===//
0015 
0016 #ifndef POLLY_SCOP_GRAPH_PRINTER_H
0017 #define POLLY_SCOP_GRAPH_PRINTER_H
0018 
0019 #include "polly/ScopDetection.h"
0020 #include "polly/Support/ScopLocation.h"
0021 #include "llvm/Analysis/DOTGraphTraitsPass.h"
0022 #include "llvm/Analysis/RegionInfo.h"
0023 #include "llvm/Analysis/RegionIterator.h"
0024 #include "llvm/Analysis/RegionPrinter.h"
0025 #include "llvm/IR/PassManager.h"
0026 
0027 namespace llvm {
0028 
0029 template <>
0030 struct GraphTraits<polly::ScopDetection *> : GraphTraits<RegionInfo *> {
0031   static NodeRef getEntryNode(polly::ScopDetection *SD) {
0032     return GraphTraits<RegionInfo *>::getEntryNode(SD->getRI());
0033   }
0034   static nodes_iterator nodes_begin(polly::ScopDetection *SD) {
0035     return nodes_iterator::begin(getEntryNode(SD));
0036   }
0037   static nodes_iterator nodes_end(polly::ScopDetection *SD) {
0038     return nodes_iterator::end(getEntryNode(SD));
0039   }
0040 };
0041 
0042 template <>
0043 struct DOTGraphTraits<polly::ScopDetection *> : DOTGraphTraits<RegionNode *> {
0044   DOTGraphTraits(bool isSimple = false)
0045       : DOTGraphTraits<RegionNode *>(isSimple) {}
0046   static std::string getGraphName(polly::ScopDetection *SD) {
0047     return "Scop Graph";
0048   }
0049 
0050   std::string getEdgeAttributes(RegionNode *srcNode,
0051                                 GraphTraits<RegionInfo *>::ChildIteratorType CI,
0052                                 polly::ScopDetection *SD);
0053 
0054   std::string getNodeLabel(RegionNode *Node, polly::ScopDetection *SD) {
0055     return DOTGraphTraits<RegionNode *>::getNodeLabel(
0056         Node, reinterpret_cast<RegionNode *>(SD->getRI()->getTopLevelRegion()));
0057   }
0058 
0059   static std::string escapeString(llvm::StringRef String);
0060 
0061   /// Print the cluster of the subregions. This groups the single basic blocks
0062   /// and adds a different background color for each group.
0063   static void printRegionCluster(polly::ScopDetection *SD, const Region *R,
0064                                  raw_ostream &O, unsigned depth = 0);
0065 
0066   static void addCustomGraphFeatures(polly::ScopDetection *SD,
0067                                      GraphWriter<polly::ScopDetection *> &GW);
0068 };
0069 } // end namespace llvm
0070 
0071 namespace polly {
0072 
0073 struct ScopViewer final : llvm::DOTGraphTraitsViewer<ScopAnalysis, false> {
0074   ScopViewer() : llvm::DOTGraphTraitsViewer<ScopAnalysis, false>("scops") {}
0075 
0076   bool processFunction(Function &F, const ScopDetection &SD) override;
0077 };
0078 
0079 struct ScopOnlyViewer final : llvm::DOTGraphTraitsViewer<ScopAnalysis, false> {
0080   ScopOnlyViewer()
0081       : llvm::DOTGraphTraitsViewer<ScopAnalysis, false>("scops-only") {}
0082 };
0083 
0084 struct ScopPrinter final : llvm::DOTGraphTraitsPrinter<ScopAnalysis, false> {
0085   ScopPrinter() : llvm::DOTGraphTraitsPrinter<ScopAnalysis, false>("scops") {}
0086 };
0087 
0088 struct ScopOnlyPrinter final : llvm::DOTGraphTraitsPrinter<ScopAnalysis, true> {
0089   ScopOnlyPrinter()
0090       : llvm::DOTGraphTraitsPrinter<ScopAnalysis, true>("scopsonly") {}
0091 };
0092 
0093 } // end namespace polly
0094 
0095 #endif /* POLLY_SCOP_GRAPH_PRINTER_H */