17
17
// copy and modified from third_party/binaryen/src/passes/Inlining.cpp
18
18
19
19
#include < atomic>
20
+ #include < cassert>
20
21
#include < cstdint>
21
22
#include < memory>
22
23
37
38
#include " pass.h"
38
39
#include " passes/pass-utils.h"
39
40
#include " support/name.h"
41
+ #include " warpo/common/OptLevel.hpp"
40
42
#include " warpo/support/Debug.hpp"
41
43
#include " warpo/support/Opt.hpp"
42
44
#include " wasm-builder.h"
@@ -101,7 +103,14 @@ struct FunctionInfo {
101
103
budget += functionCost;
102
104
}
103
105
// calculate delta for each call
104
- float delta = inlinedCost - getOpcodeCost (Opcode::CALL);
106
+ float const sizeCostDelta = inlinedCost - getOpcodeSizeCost (Opcode::CALL);
107
+ float const performanceCostDelta = 0 .0f - getOpcodePerformanceCost (Opcode::CALL) - getFunctionPerformanceCost ();
108
+
109
+ float const optimizationLevel = static_cast <float >(common::getOptimizationLevel ()) + 0.0001 ;
110
+ float const shrinkLevel = static_cast <float >(common::getShrinkLevel ()) + 0.0001 ;
111
+ float const optRatio = optimizationLevel / (optimizationLevel + shrinkLevel);
112
+ float const shrinkRatio = shrinkLevel / (optimizationLevel + shrinkLevel);
113
+ float const delta = performanceCostDelta * optRatio + sizeCostDelta * shrinkRatio;
105
114
106
115
budget -= refs * delta;
107
116
@@ -110,8 +119,8 @@ struct FunctionInfo {
110
119
111
120
bool const shouldInline = budget >= 0 .0f ;
112
121
if (support::isDebug (PASS_NAME, funcName.str )) {
113
- fmt::println (" [" PASS_NAME " ] {} '{}', func_cost={}, refs ={}, budget ={}" , shouldInline ? " inline " : " not inline " ,
114
- funcName.str , functionCost, refs.load (), budget);
122
+ fmt::println (" [" PASS_NAME " ] {} '{}', func_cost={}, delta ={}, refs ={}, budget={} " ,
123
+ shouldInline ? " inline " : " not inline " , funcName.str , functionCost, delta , refs.load (), budget);
115
124
}
116
125
return shouldInline;
117
126
}
@@ -157,8 +166,8 @@ struct FunctionInfoScanner : public WalkerPass<PostWalker<FunctionInfoScanner>>
157
166
info.inliningMode = InliningMode::Uninlineble;
158
167
}
159
168
160
- float const bodyCost = measureCost (curr->body );
161
- info.functionCost = bodyCost + getFunctionCost ();
169
+ float const bodyCost = measureSizeCost (curr->body );
170
+ info.functionCost = bodyCost + getFunctionSizeCost ();
162
171
info.inlinedCost = bodyCost;
163
172
}
164
173
0 commit comments