Skip to content

Commit 32685ce

Browse files
committed
[Inliner] Add per-inlining verification.
Previously, there was an -Xllvm option to verify after all inlining to a particlar caller. That makes it a chore to track down which apply's inlining resulted in invalid code. Here, a new option is added that verifies after each run of the inliner.
1 parent 3dae89e commit 32685ce

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/SILOptimizer/Mandatory/MandatoryInlining.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ extern llvm::cl::opt<bool> SILPrintInliningCallerBefore;
5050

5151
extern llvm::cl::opt<bool> SILPrintInliningCallerAfter;
5252

53+
extern llvm::cl::opt<bool> EnableVerifyAfterEachInlining;
54+
5355
extern void printInliningDetailsCallee(StringRef passName, SILFunction *caller,
5456
SILFunction *callee);
5557

@@ -972,6 +974,16 @@ runOnFunctionRecursively(SILOptFunctionBuilder &FuncBuilder, SILFunction *F,
972974
// later.
973975
changedFunctions.insert(F);
974976

977+
if (EnableVerifyAfterEachInlining) {
978+
if (invalidatedStackNesting) {
979+
StackNesting::fixNesting(F);
980+
changedFunctions.insert(F);
981+
invalidatedStackNesting = false;
982+
}
983+
984+
F->verify();
985+
}
986+
975987
// Resume inlining within nextBB, which contains only the inlined
976988
// instructions and possibly instructions in the original call block that
977989
// have not yet been visited.

lib/SILOptimizer/Transforms/PerformanceInliner.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ llvm::cl::opt<bool> SILPrintInliningCallerAfter(
6363
llvm::cl::desc(
6464
"Print functions into which another function has been inlined."));
6565

66+
llvm::cl::opt<bool> EnableVerifyAfterEachInlining(
67+
"sil-inline-verify-after-each-inline", llvm::cl::init(false),
68+
llvm::cl::desc(
69+
"Run sil verification after inlining each found callee apply "
70+
"site into a caller."));
71+
6672
//===----------------------------------------------------------------------===//
6773
// Printing Helpers
6874
//===----------------------------------------------------------------------===//
@@ -1038,6 +1044,20 @@ bool SILPerformanceInliner::inlineCallsIntoFunction(SILFunction *Caller) {
10381044
if (SILPrintInliningCallerAfter) {
10391045
printInliningDetailsCallerAfter(PassName, Caller, Callee);
10401046
}
1047+
if (EnableVerifyAfterEachInlining) {
1048+
deleter.cleanupDeadInstructions();
1049+
1050+
// The inliner splits blocks at call sites. Re-merge trivial branches to
1051+
// reestablish a canonical CFG.
1052+
mergeBasicBlocks(Caller);
1053+
1054+
if (invalidatedStackNesting) {
1055+
StackNesting::fixNesting(Caller);
1056+
invalidatedStackNesting = false;
1057+
}
1058+
1059+
Caller->verify();
1060+
}
10411061
}
10421062
deleter.cleanupDeadInstructions();
10431063

0 commit comments

Comments
 (0)