diff options
author | Thomas Lively <tlively@google.com> | 2020-09-25 11:45:16 -0700 |
---|---|---|
committer | Thomas Lively <tlively@google.com> | 2020-09-25 11:45:16 -0700 |
commit | 89fe083c197951a1380ee70e9e36e2aa95659da5 (patch) | |
tree | 1b693e4b33b4ba3adfb84bb1457bc23c69a2eb8f /llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp | |
parent | d2166076b882e38becf3657ea830ffd2b6a5695e (diff) | |
download | llvm-89fe083c197951a1380ee70e9e36e2aa95659da5.zip llvm-89fe083c197951a1380ee70e9e36e2aa95659da5.tar.gz llvm-89fe083c197951a1380ee70e9e36e2aa95659da5.tar.bz2 |
[WebAssembly] Check features before making SjLj vars thread-local
1c5a3c4d3823 updated the variables inserted by Emscripten SjLj lowering to be
thread-local, depending on the CoalesceFeaturesAndStripAtomics pass to downgrade
them to normal globals if the target features did not support TLS. However, this
had the unintended side effect of preventing all non-TLS-supporting objects from
being linked into modules with shared memory, because stripping TLS marks an
object as thread-unsafe. This patch fixes the problem by only making the SjLj
lowering variables thread-local if the target machine supports TLS so that it
never introduces new usage of TLS that will be stripped. Since SjLj lowering
works on Modules instead of Functions, this required that the
WebAssemblyTargetMachine have its feature string updated to reflect the
coalesced features collected from all the functions so that a
WebAssemblySubtarget can be created without using any particular function.
Differential Revision: https://reviews.llvm.org/D88323
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp index 60a7dee..97d9e00 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -145,6 +145,11 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine( WebAssemblyTargetMachine::~WebAssemblyTargetMachine() = default; // anchor. +const WebAssemblySubtarget *WebAssemblyTargetMachine::getSubtargetImpl() const { + return getSubtargetImpl(std::string(getTargetCPU()), + std::string(getTargetFeatureString())); +} + const WebAssemblySubtarget * WebAssemblyTargetMachine::getSubtargetImpl(std::string CPU, std::string FS) const { @@ -191,6 +196,7 @@ public: FeatureBitset Features = coalesceFeatures(M); std::string FeatureStr = getFeatureString(Features); + WasmTM->setTargetFeatureString(FeatureStr); for (auto &F : M) replaceFeatures(F, FeatureStr); @@ -348,6 +354,12 @@ FunctionPass *WebAssemblyPassConfig::createTargetRegisterAllocator(bool) { //===----------------------------------------------------------------------===// void WebAssemblyPassConfig::addIRPasses() { + // Lower atomics and TLS if necessary + addPass(new CoalesceFeaturesAndStripAtomics(&getWebAssemblyTargetMachine())); + + // This is a no-op if atomics are not used in the module + addPass(createAtomicExpandPass()); + // Add signatures to prototype-less function declarations addPass(createWebAssemblyAddMissingPrototypes()); @@ -383,12 +395,6 @@ void WebAssemblyPassConfig::addIRPasses() { // Expand indirectbr instructions to switches. addPass(createIndirectBrExpandPass()); - // Lower atomics and TLS if necessary - addPass(new CoalesceFeaturesAndStripAtomics(&getWebAssemblyTargetMachine())); - - // This is a no-op if atomics are not used in the module - addPass(createAtomicExpandPass()); - TargetPassConfig::addIRPasses(); } |