diff options
author | Alon Zakai <azakai@google.com> | 2023-05-05 10:19:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-05 17:19:58 +0000 |
commit | a2fca965807a62f6c84739df88bcffbb7c7b74e4 (patch) | |
tree | c7246f9e401f6f65327f1b0027d72a316490832a /src/passes | |
parent | 515690c397c772f6eb0f9747c51fab69046c606b (diff) | |
download | binaryen-a2fca965807a62f6c84739df88bcffbb7c7b74e4.tar.gz binaryen-a2fca965807a62f6c84739df88bcffbb7c7b74e4.tar.bz2 binaryen-a2fca965807a62f6c84739df88bcffbb7c7b74e4.zip |
Generate unique block names when inlining (#5697)
Each time we inline we put the contents in a block. Before we used the same name
each time we inlined the same method, and as a result had many conflicts if a
function was inlined many times. With this PR we emit a different name each
time.
This is not 100% NFC as it does change block names, which is observable in the IR
(as can be seen in the test updates).
This helps #5696 in speeding up UniqueNameManner.
Diffstat (limited to 'src/passes')
-rw-r--r-- | src/passes/Inlining.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/passes/Inlining.cpp b/src/passes/Inlining.cpp index 112c31036..28083f4d0 100644 --- a/src/passes/Inlining.cpp +++ b/src/passes/Inlining.cpp @@ -329,17 +329,27 @@ struct Updater : public PostWalker<Updater> { // Core inlining logic. Modifies the outside function (adding locals as // needed), and returns the inlined code. +// +// An optional name hint can be provided, which will then be used in the name of +// the block we put the inlined code in. Using a unique name hint in each call +// of this function can reduce the risk of name overlaps (which cause fixup work +// in UniqueNameMapper::uniquify). static Expression* doInlining(Module* module, Function* into, const InliningAction& action, - PassOptions& options) { + PassOptions& options, + Index nameHint = 0) { Function* from = action.contents; auto* call = (*action.callSite)->cast<Call>(); // Works for return_call, too Type retType = module->getFunction(call->target)->getResults(); Builder builder(*module); auto* block = builder.makeBlock(); - block->name = Name(std::string("__inlined_func$") + from->name.toString()); + auto name = std::string("__inlined_func$") + from->name.toString(); + if (nameHint) { + name += '$' + std::to_string(nameHint); + } + block->name = Name(name); // In the unlikely event that the function already has a branch target with // this name, fix that up, as otherwise we can get unexpected capture of our // branches, that is, we could end up with this: @@ -1084,7 +1094,7 @@ struct Inlining : public Pass { action.contents = getActuallyInlinedFunction(action.contents); // Perform the inlining and update counts. - doInlining(module, func, action, getPassOptions()); + doInlining(module, func, action, getPassOptions(), inlinedNameHint++); inlinedUses[inlinedName]++; inlinedInto.insert(func); assert(inlinedUses[inlinedName] <= infos[inlinedName].refs); @@ -1102,6 +1112,9 @@ struct Inlining : public Pass { }); } + // See explanation in doInlining() for the parameter nameHint. + Index inlinedNameHint = 0; + InliningMode getInliningMode(Name name) { auto& info = infos[name]; |