Skip to content

Commit 99f118f

Browse files
aheejinmemfrob
authored andcommitted
[WebAssembly] Fix JS code mentions in LowerEmscriptenEHSjLj
- Removes the mention of fastcomp, which is deprecated. - Some functions in Emscripten have moved from JS glue code to compiler-rt/emscripten_setjmp.c and compiler-rt/emscripten_exception_builtins.c. This fixes comments about that. Reviewed By: sbc100 Differential Revision: https://reviews.llvm.org/D101812
1 parent 76a2491 commit 99f118f

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@
1313
///
1414
/// To handle exceptions and setjmp/longjmps, this scheme relies on JavaScript's
1515
/// try and catch syntax and relevant exception-related libraries implemented
16-
/// in JavaScript glue code that will be produced by Emscripten. This is similar
17-
/// to the current Emscripten asm.js exception handling in fastcomp. For
18-
/// fastcomp's EH / SjLj scheme, see these files in fastcomp LLVM branch:
19-
/// (Location: https://github.com/kripken/emscripten-fastcomp)
20-
/// lib/Target/JSBackend/NaCl/LowerEmExceptionsPass.cpp
21-
/// lib/Target/JSBackend/NaCl/LowerEmSetjmp.cpp
22-
/// lib/Target/JSBackend/JSBackend.cpp
23-
/// lib/Target/JSBackend/CallHandlers.h
16+
/// in JavaScript glue code that will be produced by Emscripten.
2417
///
2518
/// * Exception handling
2619
/// This pass lowers invokes and landingpads into library functions in JS glue
@@ -50,9 +43,8 @@
5043
/// In detail, this pass does following things:
5144
///
5245
/// 1) Assumes the existence of global variables: __THREW__, __threwValue
53-
/// __THREW__ and __threwValue will be set in invoke wrappers
54-
/// in JS glue code. For what invoke wrappers are, refer to 3). These
55-
/// variables are used for both exceptions and setjmp/longjmps.
46+
/// __THREW__ and __threwValue are defined in compiler-rt in Emscripten.
47+
/// These variables are used for both exceptions and setjmp/longjmps.
5648
/// __THREW__ indicates whether an exception or a longjmp occurred or not. 0
5749
/// means nothing occurred, 1 means an exception occurred, and other numbers
5850
/// mean a longjmp occurred. In the case of longjmp, __threwValue variable
@@ -61,22 +53,16 @@
6153
/// * Exception handling
6254
///
6355
/// 2) We assume the existence of setThrew and setTempRet0/getTempRet0 functions
64-
/// at link time.
65-
/// The global variables in 1) will exist in wasm address space,
66-
/// but their values should be set in JS code, so these functions
67-
/// as interfaces to JS glue code. These functions are equivalent to the
68-
/// following JS functions, which actually exist in asm.js version of JS
69-
/// library.
56+
/// at link time. setThrew exists in Emscripten's compiler-rt:
7057
///
71-
/// function setThrew(threw, value) {
58+
/// void setThrew(int threw, int value) {
7259
/// if (__THREW__ == 0) {
7360
/// __THREW__ = threw;
7461
/// __threwValue = value;
7562
/// }
7663
/// }
7764
//
7865
/// setTempRet0 is called from __cxa_find_matching_catch() in JS glue code.
79-
///
8066
/// In exception handling, getTempRet0 indicates the type of an exception
8167
/// caught, and in setjmp/longjmp, it means the second argument to longjmp
8268
/// function.
@@ -105,7 +91,7 @@
10591
/// Module["dynCall_vi"](index,a1); // This calls original callee
10692
/// } catch(e) {
10793
/// if (typeof e !== 'number' && e !== 'longjmp') throw e;
108-
/// asm["setThrew"](1, 0); // setThrew is called here
94+
/// _setThrew(1, 0); // setThrew is called here
10995
/// }
11096
/// }
11197
/// If an exception is thrown, __THREW__ will be set to true in a wrapper,
@@ -149,8 +135,8 @@
149135
/// setjmpTableSize = 4;
150136
/// setjmpTable = (int *) malloc(40);
151137
/// setjmpTable[0] = 0;
152-
/// setjmpTable and setjmpTableSize are used in saveSetjmp() function in JS
153-
/// code.
138+
/// setjmpTable and setjmpTableSize are used to call saveSetjmp() function in
139+
/// Emscripten compiler-rt.
154140
///
155141
/// 3) Lower
156142
/// setjmp(buf)
@@ -160,11 +146,11 @@
160146
/// For each dynamic setjmp call, setjmpTable stores its ID (a number which
161147
/// is incrementally assigned from 0) and its label (a unique number that
162148
/// represents each callsite of setjmp). When we need more entries in
163-
/// setjmpTable, it is reallocated in saveSetjmp() in JS code and it will
164-
/// return the new table address, and assign the new table size in
165-
/// setTempRet0(). saveSetjmp also stores the setjmp's ID into the buffer
166-
/// buf. A BB with setjmp is split into two after setjmp call in order to
167-
/// make the post-setjmp BB the possible destination of longjmp BB.
149+
/// setjmpTable, it is reallocated in saveSetjmp() in Emscripten's
150+
/// compiler-rt and it will return the new table address, and assign the new
151+
/// table size in setTempRet0(). saveSetjmp also stores the setjmp's ID into
152+
/// the buffer buf. A BB with setjmp is split into two after setjmp call in
153+
/// order to make the post-setjmp BB the possible destination of longjmp BB.
168154
///
169155
///
170156
/// 4) Lower every call that might longjmp into
@@ -505,7 +491,7 @@ bool WebAssemblyLowerEmscriptenEHSjLj::canLongjmp(Module &M,
505491
if (CalleeName == "setjmp" || CalleeName == "malloc" || CalleeName == "free")
506492
return false;
507493

508-
// There are functions in JS glue code
494+
// There are functions in Emscripten's JS glue code or compiler-rt
509495
if (CalleeName == "__resumeException" || CalleeName == "llvm_eh_typeid_for" ||
510496
CalleeName == "saveSetjmp" || CalleeName == "testSetjmp" ||
511497
CalleeName == "getTempRet0" || CalleeName == "setTempRet0")

0 commit comments

Comments
 (0)