This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Fix reverse mapping in WasmEHFuncInfo
ClosedPublic

Authored by aheejin on Feb 26 2021, 2:47 PM.

Details

Summary

D97247 added the reverse mapping from unwind destination to their
source, but it had a critical bug; sources can be multiple, because
multiple BBs can have a single BB as their unwind destination.

This changes WasmEHFuncInfo::getUnwindSrc to getUnwindSrcs and makes
it return a vector rather than a single BB. It does not return the const
reference to the existing vector but creates a new vector because
WasmEHFuncInfo stores not BasicBlock* or MachineBasicBlock* but
PointerUnion of them. Also I hoped to unify those methods for
BasicBlock and MachineBasicBlock into one using templates to reduce
duplication, but failed because various usages require BasicBlock* to
be const but it's hard to make it const for MachineBasicBlock
usages.

Fixes https://github.com/emscripten-core/emscripten/issues/13514.
(More precisely, fixes
https://github.com/emscripten-core/emscripten/issues/13514#issuecomment-784708744)

Diff Detail

Event Timeline

aheejin created this revision.Feb 26 2021, 2:47 PM
aheejin requested review of this revision.Feb 26 2021, 2:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 26 2021, 2:47 PM
aheejin edited the summary of this revision. (Show Details)Feb 26 2021, 2:57 PM
aheejin updated this revision to Diff 326815.EditedFeb 26 2021, 3:04 PM

include "llvm/ADT/SmallPtrSet.h"

aheejin edited the summary of this revision. (Show Details)Feb 26 2021, 3:38 PM
dschuff accepted this revision.Feb 26 2021, 3:39 PM

LGTM. since the data structure is a SmallPtrSet now, it probably makes sense to update the description and maybe the var names to reflect that.

llvm/include/llvm/CodeGen/WasmEHFuncInfo.h
45

I guess Vec could be named Set now since it's a set rather than a vector.

llvm/lib/Target/WebAssembly/WebAssemblyCFGSort.cpp
266–267

what's the significance of the iteration order here?

This revision is now accepted and ready to land.Feb 26 2021, 3:39 PM
tlively accepted this revision.Feb 26 2021, 3:48 PM
aheejin marked an inline comment as done.Feb 26 2021, 5:06 PM
aheejin added inline comments.
llvm/include/llvm/CodeGen/WasmEHFuncInfo.h
45

Yeah I made it as a vector first and then changed it to a set, which resulted in this.. Fixed.

llvm/lib/Target/WebAssembly/WebAssemblyCFGSort.cpp
266–267

Now we shouldn't do a reverse traversal because Succ has to be added to Deferred list of the outermost SortRegion. For example, if exception A contains exception B, and both A's header and B's header's unwind destination is Succ, Entries will be like [..., exception A, ..., exception B, ...], and Succ has to be deferred until all blocks in the exception A are scheduled.

Before when I incorrectly assumed the unwind source is a single BB, it was correct traverse Entries either way. I did it backwards just because I thought it would more likely to hit the target first.

aheejin updated this revision to Diff 326850.Feb 26 2021, 5:11 PM
aheejin marked an inline comment as done.

Vec -> Set

This revision was landed with ongoing or failed builds.Feb 26 2021, 5:13 PM
This revision was automatically updated to reflect the committed changes.