Skip to content

Commit 775030a

Browse files
authored
[NFC] Inlining: Avoid wasteful non-nullable local fixups (#8147)
Mark the scanning and planning passes as not modifying the IR at all. Mark the doInlining and Inlining passes as not needing non-nullable fixups, as we apply those fixups when we inline (update the comment there to clarify that). This makes `--inlining` 8% faster on a Dart testcase I am looking at. That is the result of avoiding 87% of the scans for non-nullable fixups. The `--inlining-optimizing` pass, however, has a more modest speedup (since it optimizes after each inlining anyhow, which is even larger work): 10% fewer scans, and wall time is within noise. (Still, this does avoid some wasted work even there, and marking sub-passes that do not modify the IR as not doing so seems like a win for readability.)
1 parent 96f2976 commit 775030a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/passes/Inlining.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ struct FunctionInfoScanner
198198
: public WalkerPass<PostWalker<FunctionInfoScanner>> {
199199
bool isFunctionParallel() override { return true; }
200200

201+
bool modifiesBinaryenIR() override { return false; }
202+
201203
FunctionInfoScanner(NameInfoMap& infos) : infos(infos) {}
202204

203205
std::unique_ptr<Pass> create() override {
@@ -323,6 +325,8 @@ struct InliningState {
323325
struct Planner : public WalkerPass<TryDepthWalker<Planner>> {
324326
bool isFunctionParallel() override { return true; }
325327

328+
bool modifiesBinaryenIR() override { return false; }
329+
326330
Planner(InliningState* state) : state(state) {}
327331

328332
std::unique_ptr<Pass> create() override {
@@ -688,8 +692,9 @@ static void updateAfterInlining(Module* module, Function* into) {
688692
// Inlining unreachable contents can make things in the function we inlined
689693
// into unreachable.
690694
ReFinalize().walkFunctionInModule(into, module);
691-
// New locals we added may require fixups for nondefaultability.
692-
// FIXME Is this not done automatically?
695+
// New locals we added may require fixups for nondefaultability. We do this
696+
// here and not in the main pass (or its subpasses) so that we only do it
697+
// where needed.
693698
TypeUpdating::handleNonDefaultableLocals(into, *module);
694699
}
695700

@@ -710,6 +715,9 @@ using ChosenActions = std::unordered_map<Name, std::vector<InliningAction>>;
710715
struct DoInlining : public Pass {
711716
bool isFunctionParallel() override { return true; }
712717

718+
// We do this only where we inline, inside updateAfterInlining().
719+
bool requiresNonNullableLocalFixups() override { return false; }
720+
713721
std::unique_ptr<Pass> create() override {
714722
return std::make_unique<DoInlining>(chosenActions);
715723
}
@@ -1254,6 +1262,9 @@ struct Inlining : public Pass {
12541262
// FIXME DWARF updating does not handle local changes yet.
12551263
bool invalidatesDWARF() override { return true; }
12561264

1265+
// We do this only where we inline, inside updateAfterInlining().
1266+
bool requiresNonNullableLocalFixups() override { return false; }
1267+
12571268
// whether to optimize where we inline
12581269
bool optimize = false;
12591270

0 commit comments

Comments
 (0)