llvm.org GIT mirror llvm / 5864ac7
[RegionInfo] Add debug-time region viewer functions Summary: Analogously to Function::viewCFG(), RegionInfo::view() and RegionInfo::viewOnly() are meant to be called in debugging sessions. They open a viewer to show how RegionInfo currently understands the region hierarchy. The functions viewRegion(Function*) and viewRegionOnly(Function*) invoke a fresh region analysis of the function in contrast to viewRegion(RegionInfo*) and viewRegionOnly(RegionInfo*) which show the current analysis result. Reviewers: grosser Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D11875 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244444 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Kruse 4 years ago
4 changed file(s) with 108 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
845845
846846 void recalculate(Function &F, DominatorTree *DT, PostDominatorTree *PDT,
847847 DominanceFrontier *DF);
848
849 #ifndef NDEBUG
850 /// @brief Opens a viewer to show the GraphViz visualization of the regions.
851 ///
852 /// Useful during debugging as an alternative to dump().
853 void view();
854
855 /// @brief Opens a viewer to show the GraphViz visalization of this region
856 /// without instructions in the BasicBlocks.
857 ///
858 /// Useful during debugging as an alternative to dump().
859 void viewOnly();
860 #endif
848861 };
849862
850863 class RegionInfoPass : public FunctionPass {
1616
1717 namespace llvm {
1818 class FunctionPass;
19 class Function;
20 class RegionInfo;
21
1922 FunctionPass *createRegionViewerPass();
2023 FunctionPass *createRegionOnlyViewerPass();
2124 FunctionPass *createRegionPrinterPass();
2225 FunctionPass *createRegionOnlyPrinterPass();
26
27 #ifndef NDEBUG
28 /// @brief Open a viewer to display the GraphViz vizualization of the analysis
29 /// result.
30 ///
31 /// Practical to call in the debugger.
32 /// Includes the instructions in each BasicBlock.
33 ///
34 /// @param RI The analysis to display.
35 void viewRegion(llvm::RegionInfo *RI);
36
37 /// @brief Analyze the regions of a function and open its GraphViz
38 /// visualization in a viewer.
39 ///
40 /// Useful to call in the debugger.
41 /// Includes the instructions in each BasicBlock.
42 /// The result of a new analysis may differ from the RegionInfo the pass
43 /// manager currently holds.
44 ///
45 /// @param F Function to analyze.
46 void viewRegion(const llvm::Function *F);
47
48 /// @brief Open a viewer to display the GraphViz vizualization of the analysis
49 /// result.
50 ///
51 /// Useful to call in the debugger.
52 /// Shows only the BasicBlock names without their instructions.
53 ///
54 /// @param RI The analysis to display.
55 void viewRegionOnly(llvm::RegionInfo *RI);
56
57 /// @brief Analyze the regions of a function and open its GraphViz
58 /// visualization in a viewer.
59 ///
60 /// Useful to call in the debugger.
61 /// Shows only the BasicBlock names without their instructions.
62 /// The result of a new analysis may differ from the RegionInfo the pass
63 /// manager currently holds.
64 ///
65 /// @param F Function to analyze.
66 void viewRegionOnly(const llvm::Function *F);
67 #endif
2368 } // End llvm namespace
2469
2570 #endif
2020 #include
2121 #include
2222 #include
23 #ifndef NDEBUG
24 #include "llvm/Analysis/RegionPrinter.h"
25 #endif
2326
2427 using namespace llvm;
2528
102105 calculate(F);
103106 }
104107
108 #ifndef NDEBUG
109 void RegionInfo::view() { viewRegion(this); }
110
111 void RegionInfo::viewOnly() { viewRegionOnly(this); }
112 #endif
113
105114 //===----------------------------------------------------------------------===//
106115 // RegionInfoPass implementation
107116 //
1919 #include "llvm/Support/CommandLine.h"
2020 #include "llvm/Support/Debug.h"
2121 #include "llvm/Support/raw_ostream.h"
22 #ifndef NDEBUG
23 #include "llvm/IR/LegacyPassManager.h"
24 #endif
2225
2326 using namespace llvm;
2427
223226 return new RegionOnlyViewer();
224227 }
225228
229 #ifndef NDEBUG
230 static void viewRegionInfo(RegionInfo *RI, bool ShortNames) {
231 assert(RI && "Argument must be non-null");
232
233 llvm::Function *F = RI->getTopLevelRegion()->getEntry()->getParent();
234 std::string GraphName = DOTGraphTraits::getGraphName(RI);
235
236 llvm::ViewGraph(RI, "reg", ShortNames,
237 Twine(GraphName) + " for '" + F->getName() + "' function");
238 }
239
240 static void invokeFunctionPass(const Function *F, FunctionPass *ViewerPass) {
241 assert(F && "Argument must be non-null");
242 assert(!F->isDeclaration() && "Function must have an implementation");
243
244 // The viewer and analysis passes do not modify anything, so we can safely
245 // remove the const qualifier
246 auto NonConstF = const_cast(F);
247
248 llvm::legacy::FunctionPassManager FPM(NonConstF->getParent());
249 FPM.add(ViewerPass);
250 FPM.doInitialization();
251 FPM.run(*NonConstF);
252 FPM.doFinalization();
253 }
254
255 void llvm::viewRegion(RegionInfo *RI) { viewRegionInfo(RI, false); }
256
257 void llvm::viewRegion(const Function *F) {
258 invokeFunctionPass(F, createRegionViewerPass());
259 }
260
261 void llvm::viewRegionOnly(RegionInfo *RI) { viewRegionInfo(RI, true); }
262
263 void llvm::viewRegionOnly(const Function *F) {
264 invokeFunctionPass(F, createRegionOnlyViewerPass());
265 }
266 #endif