@@ -49,6 +49,59 @@ llvm::cl::opt<bool> EnableVerifyAfterInlining(
49
49
llvm::cl::desc(" Run sil verification after inlining all found callee apply "
50
50
" sites into a caller." ));
51
51
52
+ llvm::cl::opt<bool > SILPrintInliningCallee (
53
+ " sil-print-inlining-callee" , llvm::cl::init(false ),
54
+ llvm::cl::desc(" Print functions that are inlined into other functions." ));
55
+
56
+ llvm::cl::opt<bool > SILPrintInliningCallerBefore (
57
+ " sil-print-inlining-caller-before" , llvm::cl::init(false ),
58
+ llvm::cl::desc(
59
+ " Print functions into which another function is about to be inlined." ));
60
+
61
+ llvm::cl::opt<bool > SILPrintInliningCallerAfter (
62
+ " sil-print-inlining-caller-after" , llvm::cl::init(false ),
63
+ llvm::cl::desc(
64
+ " Print functions into which another function has been inlined." ));
65
+
66
+ // ===----------------------------------------------------------------------===//
67
+ // Printing Helpers
68
+ // ===----------------------------------------------------------------------===//
69
+
70
+ extern bool isFunctionSelectedForPrinting (SILFunction *F);
71
+
72
+ static void printInliningDetails (StringRef passName, SILFunction *caller,
73
+ SILFunction *callee, bool isCaller,
74
+ bool alreadyInlined) {
75
+ if (!isFunctionSelectedForPrinting (caller))
76
+ return ;
77
+ llvm::dbgs () << " " << passName
78
+ << (alreadyInlined ? " has inlined " : " will inline " )
79
+ << callee->getName () << " into " << caller->getName () << " .\n " ;
80
+ auto *printee = isCaller ? caller : callee;
81
+ printee->dump (caller->getModule ().getOptions ().EmitVerboseSIL );
82
+ llvm::dbgs () << ' \n ' ;
83
+ }
84
+
85
+ static void printInliningDetailsCallee (StringRef passName, SILFunction *caller,
86
+ SILFunction *callee) {
87
+ printInliningDetails (passName, caller, callee, /* isCaller=*/ false ,
88
+ /* alreadyInlined=*/ false );
89
+ }
90
+
91
+ static void printInliningDetailsCallerBefore (StringRef passName,
92
+ SILFunction *caller,
93
+ SILFunction *callee) {
94
+ printInliningDetails (passName, caller, callee, /* isCaller=*/ true ,
95
+ /* alreadyInlined=*/ false );
96
+ }
97
+
98
+ static void printInliningDetailsCallerAfter (StringRef passName,
99
+ SILFunction *caller,
100
+ SILFunction *callee) {
101
+ printInliningDetails (passName, caller, callee, /* isCaller=*/ true ,
102
+ /* alreadyInlined=*/ true );
103
+ }
104
+
52
105
// ===----------------------------------------------------------------------===//
53
106
// Performance Inliner
54
107
// ===----------------------------------------------------------------------===//
@@ -58,6 +111,7 @@ namespace {
58
111
using Weight = ShortestPathAnalysis::Weight;
59
112
60
113
class SILPerformanceInliner {
114
+ StringRef PassName;
61
115
SILOptFunctionBuilder &FuncBuilder;
62
116
63
117
// / Specifies which functions not to inline, based on @_semantics and
@@ -190,12 +244,13 @@ class SILPerformanceInliner {
190
244
SmallVectorImpl<FullApplySite> &Applies);
191
245
192
246
public:
193
- SILPerformanceInliner (SILOptFunctionBuilder &FuncBuilder,
194
- InlineSelection WhatToInline, DominanceAnalysis *DA,
247
+ SILPerformanceInliner (StringRef PassName, SILOptFunctionBuilder &FuncBuilder,
248
+ InlineSelection WhatToInline, DominanceAnalysis *DA,
195
249
SILLoopAnalysis *LA, SideEffectAnalysis *SEA,
196
250
OptimizationMode OptMode, OptRemark::Emitter &ORE)
197
- : FuncBuilder(FuncBuilder), WhatToInline(WhatToInline), DA(DA), LA(LA),
198
- SEA (SEA), CBI(DA), ORE(ORE), OptMode(OptMode) {}
251
+ : PassName(PassName), FuncBuilder(FuncBuilder),
252
+ WhatToInline (WhatToInline), DA(DA), LA(LA), SEA(SEA), CBI(DA), ORE(ORE),
253
+ OptMode(OptMode) {}
199
254
200
255
bool inlineCallsIntoFunction (SILFunction *F);
201
256
};
@@ -975,6 +1030,12 @@ bool SILPerformanceInliner::inlineCallsIntoFunction(SILFunction *Caller) {
975
1030
// will be deleted after inlining.
976
1031
invalidatedStackNesting |= SILInliner::invalidatesStackNesting (AI);
977
1032
1033
+ if (SILPrintInliningCallee) {
1034
+ printInliningDetailsCallee (PassName, Caller, Callee);
1035
+ }
1036
+ if (SILPrintInliningCallerBefore) {
1037
+ printInliningDetailsCallerBefore (PassName, Caller, Callee);
1038
+ }
978
1039
// We've already determined we should be able to inline this, so
979
1040
// unconditionally inline the function.
980
1041
//
@@ -983,6 +1044,9 @@ bool SILPerformanceInliner::inlineCallsIntoFunction(SILFunction *Caller) {
983
1044
SILInliner::inlineFullApply (AI, SILInliner::InlineKind::PerformanceInline,
984
1045
FuncBuilder, deleter);
985
1046
++NumFunctionsInlined;
1047
+ if (SILPrintInliningCallerAfter) {
1048
+ printInliningDetailsCallerAfter (PassName, Caller, Callee);
1049
+ }
986
1050
}
987
1051
deleter.cleanupDeadInstructions ();
988
1052
@@ -1056,8 +1120,9 @@ class SILPerformanceInlinerPass : public SILFunctionTransform {
1056
1120
auto OptMode = getFunction ()->getEffectiveOptimizationMode ();
1057
1121
1058
1122
SILOptFunctionBuilder FuncBuilder (*this );
1059
- SILPerformanceInliner Inliner (FuncBuilder, WhatToInline, DA, LA, SEA,
1060
- OptMode, ORE);
1123
+
1124
+ SILPerformanceInliner Inliner (getID (), FuncBuilder, WhatToInline, DA, LA,
1125
+ SEA, OptMode, ORE);
1061
1126
1062
1127
assert (getFunction ()->isDefinition () &&
1063
1128
" Expected only functions with bodies!" );
0 commit comments