This makes three thread local variables (__THREW__, __threwValue,
and __wasm_lpad_context) unconditionally thread local. If the target
doesn't support TLS, they will be downgraded to normal variables in
stripThreadLocals. This makes the object not linkable with other
objects using shared memory, which is what we intend here; these
variables should be thread local when used with shared memory. This is
what we initially tried in D88262.
But D88323 changed this: It only created these variables when threads
were supported, because __THREW__ and __threwValue were always
generated even if Emscripten EH/SjLj was not used, making all objects
built without threads not linkable with shared memory, which was too
restrictive. But sometimes this is not safe. If we build an object using
variables such as __THREW__ without threads, it can be linked to other
objects using shared memory, because the original object's __THREW__
was not created thread local to begin with.
So this CL basically reverts D88323 with some additional improvements:
- This checks each of the functions and global variables created within LowerEmscriptenEHSjLj pass and removes it if it's not used at the end of the pass. So only modules using those variables will be affected.
- Moves CoalesceFeaturesAndStripAtomics and AtomicExpand passes after all other IR pasess that can create thread local variables. It is not sufficient to move them to the end of addIRPasses, because __wasm_lpad_context is created in WasmEHPrepare, which runs inside addPassesToHandleExceptions, which runs before addISelPrepare. So we override addISelPrepare and move atomic/TLS stripping and expanding passes there.
This also removes merges TLS and NO-TLS FileCheck lines into one
CHECK line, because in the bitcode level we always create them as
thread local. Also some function declarations are deleted CHECK lines
because they are unused.
I was expecting to see LPadContextGV->setThreadLocalMode(GlobalValue::GeneralDynamicTLSModel); here...