|
20 | 20 | #include "swift/SILOptimizer/Analysis/LoopRegionAnalysis.h"
|
21 | 21 | #include "swift/SILOptimizer/PassManager/Passes.h"
|
22 | 22 | #include "swift/SILOptimizer/PassManager/Transforms.h"
|
| 23 | +#include "llvm/Support/CommandLine.h" |
23 | 24 |
|
24 | 25 | using namespace swift;
|
25 | 26 |
|
| 27 | +static llvm::cl::opt<std::string> |
| 28 | + SILViewCFGOnlyFun("sil-loop-region-view-cfg-only-function", |
| 29 | + llvm::cl::init(""), |
| 30 | + llvm::cl::desc("Only produce a graphviz file for the " |
| 31 | + "loop region info of this function")); |
| 32 | + |
| 33 | +static llvm::cl::opt<std::string> |
| 34 | + SILViewCFGOnlyFuns("sil-loop-region-view-cfg-only-functions", |
| 35 | + llvm::cl::init(""), |
| 36 | + llvm::cl::desc("Only produce a graphviz file for the " |
| 37 | + "loop region info for the functions " |
| 38 | + "whose name contains this substring")); |
| 39 | + |
26 | 40 | namespace {
|
27 | 41 |
|
28 | 42 | class LoopRegionViewText : public SILModuleTransform {
|
29 | 43 | void run() override {
|
30 | 44 | invalidateAll();
|
31 |
| - LoopRegionAnalysis *LRA = PM->getAnalysis<LoopRegionAnalysis>(); |
32 |
| - for (auto &Fn : *getModule()) { |
33 |
| - if (Fn.isExternalDeclaration()) continue; |
| 45 | + auto *lra = PM->getAnalysis<LoopRegionAnalysis>(); |
| 46 | + |
| 47 | + for (auto &fn : *getModule()) { |
| 48 | + if (fn.isExternalDeclaration()) |
| 49 | + continue; |
| 50 | + if (!SILViewCFGOnlyFun.empty() && fn.getName() != SILViewCFGOnlyFun) |
| 51 | + continue; |
| 52 | + if (!SILViewCFGOnlyFuns.empty() && |
| 53 | + fn.getName().find(SILViewCFGOnlyFuns, 0) == StringRef::npos) |
| 54 | + continue; |
34 | 55 |
|
35 |
| - llvm::outs() << "@" << Fn.getName() << "@\n"; |
36 |
| - LRA->get(&Fn)->dump(); |
37 |
| - llvm::outs() << "\n"; |
| 56 | + // Ok, we are going to analyze this function. Invalidate all state |
| 57 | + // associated with it so we recompute the loop regions. |
| 58 | + llvm::outs() << "Start @" << fn.getName() << "@\n"; |
| 59 | + lra->get(&fn)->dump(); |
| 60 | + llvm::outs() << "End @" << fn.getName() << "@\n"; |
38 | 61 | llvm::outs().flush();
|
39 | 62 | }
|
40 | 63 | }
|
41 |
| - |
42 | 64 | };
|
43 | 65 |
|
44 | 66 | class LoopRegionViewCFG : public SILModuleTransform {
|
45 | 67 | void run() override {
|
| 68 | + invalidateAll(); |
| 69 | + auto *lra = PM->getAnalysis<LoopRegionAnalysis>(); |
46 | 70 |
|
47 |
| - LoopRegionAnalysis *LRA = PM->getAnalysis<LoopRegionAnalysis>(); |
48 |
| - |
49 |
| - auto *M = getModule(); |
50 |
| - for (auto &Fn : M->getFunctions()) { |
51 |
| - if (Fn.isExternalDeclaration()) |
| 71 | + for (auto &fn : *getModule()) { |
| 72 | + if (fn.isExternalDeclaration()) |
52 | 73 | continue;
|
53 |
| - LRA->get(&Fn)->viewLoopRegions(); |
| 74 | + if (!SILViewCFGOnlyFun.empty() && fn.getName() != SILViewCFGOnlyFun) |
| 75 | + continue; |
| 76 | + if (!SILViewCFGOnlyFuns.empty() && |
| 77 | + fn.getName().find(SILViewCFGOnlyFuns, 0) == StringRef::npos) |
| 78 | + continue; |
| 79 | + |
| 80 | + // Ok, we are going to analyze this function. Invalidate all state |
| 81 | + // associated with it so we recompute the loop regions. |
| 82 | + lra->get(&fn)->viewLoopRegions(); |
54 | 83 | }
|
55 | 84 | }
|
56 | 85 | };
|
|
0 commit comments