This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Split BBs after throw instructions
ClosedPublic

Authored by aheejin on Nov 15 2018, 1:03 AM.

Details

Summary

throw instruction is a terminator in wasm, but BBs were not splitted
after throw instructions, causing machine instruction verifier to
fail.

This patch

  • Splits BBs after throw instructions in WasmEHPrepare and adding an unreachable instruction after throw, which will be deleted in LateEHPrepare pass
  • Refactors WasmEHPrepare into two member functions
  • Changes the semantics of eraseBBsAndChildren in LateEHPrepare pass to match that of WasmEHPrepare pass, which is newly added. Now eraseBBsAndChildren does not delete BBs with remaining predecessors.
  • Fixes style nits, making static function names conform to clang-tidy
  • Re-enables the test temporarily disabled by rL346840 && rL346845

Diff Detail

Repository
rL LLVM

Event Timeline

aheejin created this revision.Nov 15 2018, 1:03 AM
aheejin edited the summary of this revision. (Show Details)Nov 15 2018, 1:08 AM
aheejin added inline comments.Nov 15 2018, 1:35 AM
lib/CodeGen/WasmEHPrepare.cpp
236 ↗(On Diff #174166)

This part is just factored out and has not changed.

lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
90 ↗(On Diff #174166)

This now does not delete children with remaining predecessors because the purpose of this function was delete dead children. Predecessors of blocks in MBBs are removed before calling this function.

280 ↗(On Diff #174166)

Now eraseBBsAndChildren does not delete children with remaining successors, so we remote the successor relationship here before calling the function

test/MC/WebAssembly/event-section.ll
3 ↗(On Diff #174166)

-verify-machineinstrs is added to test/CodeGen/exception.ll instead.

Sorry for little offtopic at first.

WebAssembly folks, can you check this warning:

WebAssemblyDisassembler.cpp:125:11: warning: comparison is always false due to limited range of data type [-Wtype-limits]

if (Opc < 0)

GCC 8.2

Sorry for little offtopic at first.

WebAssembly folks, can you check this warning:

WebAssemblyDisassembler.cpp:125:11: warning: comparison is always false due to limited range of data type [-Wtype-limits]

if (Opc < 0)

GCC 8.2

Hmm, looks like that broke in https://reviews.llvm.org/D54138. @tlively ?

Sorry for little offtopic at first.

WebAssembly folks, can you check this warning:

WebAssemblyDisassembler.cpp:125:11: warning: comparison is always false due to limited range of data type [-Wtype-limits]

if (Opc < 0)

GCC 8.2

Hmm, looks like that broke in https://reviews.llvm.org/D54138. @tlively ?

This should be fixed in rL346979.

dschuff accepted this revision.Nov 15 2018, 1:33 PM

Otherwise LGTM

lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
90 ↗(On Diff #174166)

The name and description for this function is now the same as eraseBBsAndChildren above but the implementation is different. The code looks like it does the same thing, any reason it can't be identical?

This revision is now accepted and ready to land.Nov 15 2018, 1:33 PM
aheejin added inline comments.Nov 15 2018, 1:51 PM
lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
90 ↗(On Diff #174166)

One is for LLVM IR (BasicBlock and Instruction) and the other is for the backend IR (MachineFunction and MachineInstr). And for the LLVM IR version I used DeleteDeadBlock utility method. (I don't think there's a similar utility method for the backend IR)

dschuff added inline comments.Nov 15 2018, 3:14 PM
lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
90 ↗(On Diff #174166)

oh haha i totally missed that. Guess that means we have good abstractions or something ¯\_(ツ)_/¯

aheejin updated this revision to Diff 174297.Nov 15 2018, 4:11 PM
  • eraseBBsAndChildren -> eraseDeadBBsAndChildren to be clear
This revision was automatically updated to reflect the committed changes.