Skip to content

Commit 586327a

Browse files
authored
Merge pull request #26698 from gottesmm/pr-251ac47676a7789236a438744e9fe9b38c45cbde
[loop-region-printer] A few small improvements
2 parents fc3d975 + 5d5bb8c commit 586327a

File tree

2 files changed

+100
-42
lines changed

2 files changed

+100
-42
lines changed

lib/SILOptimizer/UtilityPasses/LoopRegionPrinter.cpp

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,66 @@
2020
#include "swift/SILOptimizer/Analysis/LoopRegionAnalysis.h"
2121
#include "swift/SILOptimizer/PassManager/Passes.h"
2222
#include "swift/SILOptimizer/PassManager/Transforms.h"
23+
#include "llvm/Support/CommandLine.h"
2324

2425
using namespace swift;
2526

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+
2640
namespace {
2741

2842
class LoopRegionViewText : public SILModuleTransform {
2943
void run() override {
3044
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;
3455

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";
3861
llvm::outs().flush();
3962
}
4063
}
41-
4264
};
4365

4466
class LoopRegionViewCFG : public SILModuleTransform {
4567
void run() override {
68+
invalidateAll();
69+
auto *lra = PM->getAnalysis<LoopRegionAnalysis>();
4670

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())
5273
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();
5483
}
5584
}
5685
};

0 commit comments

Comments
 (0)