This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Use SSAUpdaterBulk in LowerEmscriptenSjLj
ClosedPublic

Authored by aheejin on Aug 23 2021, 1:46 PM.

Details

Summary

We update SSA in two steps in Emscripten SjLj:

  1. Rewrite uses of setjmpTable and setjmpTableSize variables and place phis where necessary, which are updated where we call saveSetjmp.
  2. Do a whole function level SSA update for all variables, because we split BBs where setjmp is called and there are possibly variable uses that are not dominated by a def. (See https://github.com/llvm/llvm-project/blob/955b91c19c00ed4c917559a5d66d14c669dde2e3/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp#L1314-L1324)

We have been using SSAUpdater to do this, but SSAUpdaterBulk class
was added after this pass was first created, and for the step 2 it looks
like a better alternative with a possible performance benefit. Not sure
the author is aware of it, but SSAUpdaterBulk seems to have a
limitation: it cannot handle a use within the same BB as a def but
before it. For example:

... = %a + 1
%a = foo();

or

%a = %a + 1

The uses %a in RHS should be rewritten with another SSA variable of
%a, most likely one generated from a phi. But SSAUpdaterBulk
thinks all uses of %a are below the def of %a within the same BB.
(SSAUpdater has two different functions of rewriting because of this:
RewriteUse and RewriteUseAfterInsertions.) This doesn't affect our
usage in the step 2 because that deals with possibly non-dominated uses
by defs after block splitting. But it does in the step 1, which still
uses SSAUpdater.

But this CL also simplifies the step 1 by using make_early_inc_range,
removing the need to advance the iterator before rewriting a use.

This is NFC; the test changes are just the order of PHI nodes.

Diff Detail

Event Timeline

aheejin created this revision.Aug 23 2021, 1:46 PM
aheejin requested review of this revision.Aug 23 2021, 1:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2021, 1:46 PM
aheejin edited the summary of this revision. (Show Details)Aug 23 2021, 1:49 PM
aheejin added inline comments.
llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
225

This is just an order change of phi clauses and doesn't mean the number of clause has been increased from 1 to 2. Previously we were only checking the first clause.

dschuff accepted this revision.Aug 23 2021, 3:18 PM

looks like a nice simplification.
It might be worth ccing the author of SSAUpdaterBulk as an FYI

This revision is now accepted and ready to land.Aug 23 2021, 3:18 PM
aheejin added a subscriber: mzolotukhin.EditedAug 23 2021, 4:14 PM

@mzolotukhin I'm trying to use SSAUpdaterBulk class here, and I'm wondering if this limitation is intended, and if so there is a way to work around that restriction. I'll paste the relevant paragraph in the CL description:

Not sure
the author is aware of it, but SSAUpdaterBulk seems to have a
limitation: it cannot handle a use within the same BB as a def but
before it. For example:

... = %a + 1
%a = foo();

or

%a = %a + 1

The uses %a in RHS should be rewritten with another SSA variable of
%a, most likely one generated from a phi. But SSAUpdaterBulk
thinks all uses of %a are below the def of %a within the same BB.
(SSAUpdater has two different functions of rewriting because of this:
RewriteUse and RewriteUseAfterInsertions.)

This revision was landed with ongoing or failed builds.Aug 24 2021, 6:24 PM
This revision was automatically updated to reflect the committed changes.