Skip to content

Commit 35361b7

Browse files
Add option to print entire function instead of just the loops for loop passes
1 parent 404d0e9 commit 35361b7

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

llvm/include/llvm/IR/PrintPasses.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ std::vector<std::string> printAfterPasses();
5151
// Returns true if we should always print the entire module.
5252
bool forcePrintModuleIR();
5353

54+
// Returns true if we should print the entire function for loop passes.
55+
bool forcePrintFuncIR();
56+
5457
// Return true if -filter-passes is empty or contains the pass name.
5558
bool isPassInPrintList(StringRef PassName);
5659
bool isFilterPassesEmpty();

llvm/lib/Analysis/LoopInfo.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,18 @@ void llvm::printLoop(Loop &L, raw_ostream &OS, const std::string &Banner) {
999999
return;
10001000
}
10011001

1002+
if (forcePrintFuncIR()) {
1003+
// handling -print-loop-func-scope.
1004+
// -print-module-scope overrides this.
1005+
OS << Banner << " (loop: ";
1006+
L.getHeader()->printAsOperand(OS, false);
1007+
OS << ")\n";
1008+
1009+
// printing whole function.
1010+
OS << *L.getHeader()->getParent();
1011+
return;
1012+
}
1013+
10021014
OS << Banner;
10031015

10041016
auto *PreHeader = L.getLoopPreheader();

llvm/lib/IR/PrintPasses.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ static cl::opt<bool>
8888
"always print a module IR"),
8989
cl::init(false), cl::Hidden);
9090

91+
static cl::opt<bool>
92+
LoopPrintFuncScope("print-loop-func-scope",
93+
cl::desc("When printing IR for print-[before|after]{-all} "
94+
"for a loop pass, always print function IR"),
95+
cl::init(false), cl::Hidden);
96+
9197
// See the description for -print-changed for an explanation of the use
9298
// of this option.
9399
static cl::list<std::string> FilterPasses(
@@ -141,6 +147,8 @@ std::vector<std::string> llvm::printAfterPasses() {
141147

142148
bool llvm::forcePrintModuleIR() { return PrintModuleScope; }
143149

150+
bool llvm::forcePrintFuncIR() { return LoopPrintFuncScope; }
151+
144152
bool llvm::isPassInPrintList(StringRef PassName) {
145153
static std::unordered_set<std::string> Set(FilterPasses.begin(),
146154
FilterPasses.end());

0 commit comments

Comments
 (0)