From: Thomas Lively Date: Thu, 28 Feb 2019 18:39:08 +0000 (+0000) Subject: [WebAssembly] Remove uses of ThreadModel X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f71ec6c9f145548357caaed4da9a806c5c2c2b11;p=llvm [WebAssembly] Remove uses of ThreadModel Summary: In the clang UI, replaces -mthread-model posix with -matomics as the source of truth on threading. In the backend, replaces -thread-model=posix with the atomics target feature, which is now collected on the WebAssemblyTargetMachine along with all other used features. These collected features will also be used to emit the target features section in the future. The default configuration for the backend is thread-model=posix and no atomics, which was previously an invalid configuration. This change makes the default valid because the thread model is ignored. A side effect of this change is that objects are never emitted with passive segments. It will instead be up to the linker to decide whether sections should be active or passive based on whether atomics are used in the final link. Reviewers: aheejin, sbc100, dschuff Subscribers: mehdi_amini, jgravelle-google, hiraditya, sunfish, steven_wu, dexonsmith, rupprecht, jfb, jdoerfert, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D58742 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355112 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index c50c6476ec5..436076f33b9 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1697,9 +1697,6 @@ MCSection *TargetLoweringObjectFileWasm::getExplicitSectionGlobal( getContext().getWasmSection(Name, Kind, Group, MCContext::GenericSectionID); - if (TM.Options.ThreadModel != ThreadModel::Single) - Section->setPassive(); - return Section; } @@ -1730,11 +1727,7 @@ static MCSectionWasm *selectWasmSectionForGlobal( (*NextUniqueID)++; } - MCSectionWasm* Section = Ctx.getWasmSection(Name, Kind, Group, UniqueID); - if (Section->isWasmData() && TM.Options.ThreadModel != ThreadModel::Single) - Section->setPassive(); - - return Section; + return Ctx.getWasmSection(Name, Kind, Group, UniqueID); } MCSection *TargetLoweringObjectFileWasm::SelectSectionForGlobal( diff --git a/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp index 8e8b4878c52..768ab7a099c 100644 --- a/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ b/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -115,6 +115,10 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine( initAsmInfo(); + // Create a subtarget using the unmodified target machine features to + // initialize the used feature set with explicitly enabled features. + getSubtargetImpl(getTargetCPU(), getTargetFeatureString()); + // Note that we don't use setRequiresStructuredCFG(true). It disables // optimizations than we're ok with, and want, such as critical edge // splitting and tail merging. @@ -122,6 +126,17 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine( WebAssemblyTargetMachine::~WebAssemblyTargetMachine() = default; // anchor. +const WebAssemblySubtarget * +WebAssemblyTargetMachine::getSubtargetImpl(std::string CPU, + std::string FS) const { + auto &I = SubtargetMap[CPU + FS]; + if (!I) { + I = llvm::make_unique(TargetTriple, CPU, FS, *this); + UsedFeatures |= I->getFeatureBits(); + } + return I.get(); +} + const WebAssemblySubtarget * WebAssemblyTargetMachine::getSubtargetImpl(const Function &F) const { Attribute CPUAttr = F.getFnAttribute("target-cpu"); @@ -134,15 +149,12 @@ WebAssemblyTargetMachine::getSubtargetImpl(const Function &F) const { ? FSAttr.getValueAsString().str() : TargetFS; - auto &I = SubtargetMap[CPU + FS]; - if (!I) { - // This needs to be done before we create a new subtarget since any - // creation will depend on the TM and the code generation flags on the - // function that reside in TargetOptions. - resetTargetOptions(F); - I = llvm::make_unique(TargetTriple, CPU, FS, *this); - } - return I.get(); + // This needs to be done before we create a new subtarget since any + // creation will depend on the TM and the code generation flags on the + // function that reside in TargetOptions. + resetTargetOptions(F); + + return getSubtargetImpl(CPU, FS); } namespace { @@ -202,14 +214,15 @@ FunctionPass *WebAssemblyPassConfig::createTargetRegisterAllocator(bool) { //===----------------------------------------------------------------------===// void WebAssemblyPassConfig::addIRPasses() { - if (TM->Options.ThreadModel == ThreadModel::Single) { - // In "single" mode, atomics get lowered to non-atomics. - addPass(createLowerAtomicPass()); - addPass(new StripThreadLocal()); - } else { + if (static_cast(TM) + ->getUsedFeatures()[WebAssembly::FeatureAtomics]) { // Expand some atomic operations. WebAssemblyTargetLowering has hooks which // control specifically what gets lowered. addPass(createAtomicExpandPass()); + } else { + // If atomics are not enabled, they get lowered to non-atomics. + addPass(createLowerAtomicPass()); + addPass(new StripThreadLocal()); } // Add signatures to prototype-less function declarations diff --git a/lib/Target/WebAssembly/WebAssemblyTargetMachine.h b/lib/Target/WebAssembly/WebAssemblyTargetMachine.h index e13ad7d4eac..0630797fe81 100644 --- a/lib/Target/WebAssembly/WebAssemblyTargetMachine.h +++ b/lib/Target/WebAssembly/WebAssemblyTargetMachine.h @@ -23,6 +23,7 @@ namespace llvm { class WebAssemblyTargetMachine final : public LLVMTargetMachine { std::unique_ptr TLOF; mutable StringMap> SubtargetMap; + mutable FeatureBitset UsedFeatures; public: WebAssemblyTargetMachine(const Target &T, const Triple &TT, StringRef CPU, @@ -32,6 +33,9 @@ public: bool JIT); ~WebAssemblyTargetMachine() override; + + const WebAssemblySubtarget *getSubtargetImpl(std::string CPU, + std::string FS) const; const WebAssemblySubtarget * getSubtargetImpl(const Function &F) const override; @@ -42,6 +46,8 @@ public: return TLOF.get(); } + FeatureBitset getUsedFeatures() const { return UsedFeatures; } + TargetTransformInfo getTargetTransformInfo(const Function &F) override; bool usesPhysRegsForPEI() const override { return false; } diff --git a/test/CodeGen/WebAssembly/atomic-mem-consistency.ll b/test/CodeGen/WebAssembly/atomic-mem-consistency.ll index 3a714370d84..c2cb02acc1e 100644 --- a/test/CodeGen/WebAssembly/atomic-mem-consistency.ll +++ b/test/CodeGen/WebAssembly/atomic-mem-consistency.ll @@ -1,4 +1,4 @@ -; RUN: not llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt +; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+atomics,+sign-ext | FileCheck %s ; Currently all wasm atomic memory access instructions are sequentially diff --git a/test/CodeGen/WebAssembly/atomic-rmw.ll b/test/CodeGen/WebAssembly/atomic-rmw.ll index 27b3be09943..34f505b7d6b 100644 --- a/test/CodeGen/WebAssembly/atomic-rmw.ll +++ b/test/CodeGen/WebAssembly/atomic-rmw.ll @@ -1,4 +1,4 @@ -; RUN: not llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers +; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+atomics,+sign-ext | FileCheck %s ; Test atomic RMW (read-modify-write) instructions are assembled properly. diff --git a/test/CodeGen/WebAssembly/global.ll b/test/CodeGen/WebAssembly/global.ll index d341ebc8f36..12f4db43f38 100644 --- a/test/CodeGen/WebAssembly/global.ll +++ b/test/CodeGen/WebAssembly/global.ll @@ -1,5 +1,5 @@ -; RUN: llc < %s -thread-model=single -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefixes=CHECK,SINGLE -; RUN: llc < %s -thread-model=posix -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefixes=CHECK,THREADS +; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=-atomics | FileCheck %s +; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+atomics | FileCheck %s ; Test that globals assemble as expected. @@ -192,8 +192,7 @@ define i8* @call_memcpy(i8* %p, i8* nocapture readonly %q, i32 %n) { ; Constant global. ; CHECK: .type rom,@object{{$}} -; SINGLE: .section .rodata.rom,"" -; THREADS: .section .rodata.rom,"passive" +; CHECK: .section .rodata.rom,"" ; CHECK: .globl rom{{$}} ; CHECK: .p2align 4{{$}} ; CHECK: rom: @@ -206,8 +205,7 @@ define i8* @call_memcpy(i8* %p, i8* nocapture readonly %q, i32 %n) { ; CHECK-NEXT: .skip 8 ; CHECK-NEXT: .size array, 8 ; CHECK: .type pointer_to_array,@object -; SINGLE-NEXT: .section .rodata.pointer_to_array,"" -; THREADS-NEXT: .section .rodata.pointer_to_array,"passive" +; CHECK-NEXT: .section .rodata.pointer_to_array,"" ; CHECK-NEXT: .globl pointer_to_array ; CHECK-NEXT: .p2align 2 ; CHECK-NEXT: pointer_to_array: diff --git a/test/CodeGen/WebAssembly/tls.ll b/test/CodeGen/WebAssembly/tls.ll index 6843aa0f9be..21e84f9fa97 100644 --- a/test/CodeGen/WebAssembly/tls.ll +++ b/test/CodeGen/WebAssembly/tls.ll @@ -1,4 +1,4 @@ -; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -thread-model=single | FileCheck --check-prefix=SINGLE %s +; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck --check-prefix=SINGLE %s target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" target triple = "wasm32-unknown-unknown" diff --git a/test/CodeGen/WebAssembly/vtable.ll b/test/CodeGen/WebAssembly/vtable.ll index 5a6d89d4e54..6a0d902254d 100644 --- a/test/CodeGen/WebAssembly/vtable.ll +++ b/test/CodeGen/WebAssembly/vtable.ll @@ -1,6 +1,6 @@ -; RUN: llc < %s -asm-verbose=false -thread-model=single -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefix=TYPEINFONAME -; RUN: llc < %s -asm-verbose=false -thread-model=single -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefix=VTABLE -; RUN: llc < %s -asm-verbose=false -thread-model=single -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefix=TYPEINFO +; RUN: llc < %s -asm-verbose=false -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefix=TYPEINFONAME +; RUN: llc < %s -asm-verbose=false -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefix=VTABLE +; RUN: llc < %s -asm-verbose=false -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefix=TYPEINFO ; Test that simple vtables assemble as expected. ; diff --git a/test/MC/WebAssembly/bss.ll b/test/MC/WebAssembly/bss.ll index a274982ed5b..36785caa3ba 100644 --- a/test/MC/WebAssembly/bss.ll +++ b/test/MC/WebAssembly/bss.ll @@ -1,4 +1,4 @@ -; RUN: llc -filetype=obj -thread-model=single %s -o - | obj2yaml | FileCheck %s +; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s target triple = "wasm32-unknown-unknown" diff --git a/test/MC/WebAssembly/comdat.ll b/test/MC/WebAssembly/comdat.ll index 9b1ac501dbf..95b77b9da61 100644 --- a/test/MC/WebAssembly/comdat.ll +++ b/test/MC/WebAssembly/comdat.ll @@ -1,4 +1,4 @@ -; RUN: llc -filetype=obj -thread-model=single %s -o - | obj2yaml | FileCheck %s +; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s target triple = "wasm32-unknown-unknown" diff --git a/test/MC/WebAssembly/debug-info.ll b/test/MC/WebAssembly/debug-info.ll index 374f5b3528b..fe4a4cf6983 100644 --- a/test/MC/WebAssembly/debug-info.ll +++ b/test/MC/WebAssembly/debug-info.ll @@ -1,4 +1,4 @@ -; RUN: llc -filetype=obj -thread-model=single %s -o - | llvm-readobj -r -s -symbols | FileCheck %s +; RUN: llc -filetype=obj %s -o - | llvm-readobj -r -s -symbols | FileCheck %s ; CHECK: Format: WASM ; CHECK-NEXT:Arch: wasm32 diff --git a/test/MC/WebAssembly/explicit-sections.ll b/test/MC/WebAssembly/explicit-sections.ll index 7fa6d4b6017..f6e9cae2868 100644 --- a/test/MC/WebAssembly/explicit-sections.ll +++ b/test/MC/WebAssembly/explicit-sections.ll @@ -1,4 +1,4 @@ -; RUN: llc -filetype=obj -thread-model=single %s -o - | obj2yaml | FileCheck %s +; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s target triple = "wasm32-unknown-unknown" diff --git a/test/MC/WebAssembly/external-data.ll b/test/MC/WebAssembly/external-data.ll index 7598c920903..c1ebca69c37 100644 --- a/test/MC/WebAssembly/external-data.ll +++ b/test/MC/WebAssembly/external-data.ll @@ -1,4 +1,4 @@ -; RUN: llc -filetype=obj -thread-model=single %s -o - | obj2yaml | FileCheck %s +; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s target triple = "wasm32-unknown-unknown" diff --git a/test/MC/WebAssembly/external-func-address.ll b/test/MC/WebAssembly/external-func-address.ll index 7ad4faa2701..95e679ab65d 100644 --- a/test/MC/WebAssembly/external-func-address.ll +++ b/test/MC/WebAssembly/external-func-address.ll @@ -1,4 +1,4 @@ -; RUN: llc -filetype=obj -thread-model=single %s -o - | obj2yaml | FileCheck %s +; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s target triple = "wasm32-unknown-unknown" diff --git a/test/MC/WebAssembly/global-ctor-dtor.ll b/test/MC/WebAssembly/global-ctor-dtor.ll index 1405803dd8f..d7e9bc9676b 100644 --- a/test/MC/WebAssembly/global-ctor-dtor.ll +++ b/test/MC/WebAssembly/global-ctor-dtor.ll @@ -1,4 +1,4 @@ -; RUN: llc -filetype=obj -thread-model=single %s -o - | obj2yaml | FileCheck %s +; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s target triple = "wasm32-unknown-unknown" diff --git a/test/MC/WebAssembly/init-flags.ll b/test/MC/WebAssembly/init-flags.ll deleted file mode 100644 index a5d2662436e..00000000000 --- a/test/MC/WebAssembly/init-flags.ll +++ /dev/null @@ -1,25 +0,0 @@ -; RUN: llc -filetype=obj %s -thread-model=single -o - | obj2yaml | FileCheck %s --check-prefix=SINGLE -; RUN: llc -filetype=obj %s -thread-model=posix -o - | obj2yaml | FileCheck %s --check-prefix=THREADS - -; Test that setting thread-model=posix causes data segments to be -; emitted as passive segments (i.e. have InitFlags set to 1). - -target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -target triple = "wasm32-unknown-unknown" - -@str = private unnamed_addr constant [7 x i8] c"Hello!\00", align 1 - -; SINGLE: - Type: DATA -; SINGLE-NEXT: Segments: -; SINGLE-NEXT: - SectionOffset: 6 -; SINGLE-NEXT: InitFlags: 0 -; SINGLE-NEXT: Offset: -; SINGLE-NEXT: Opcode: I32_CONST -; SINGLE-NEXT: Value: 0 -; SINGLE-NEXT: Content: 48656C6C6F2100 - -; THREADS: - Type: DATA -; THREADS-NEXT: Segments: -; THREADS-NEXT: - SectionOffset: 3 -; THREADS-NEXT: InitFlags: 1 -; THREADS-NEXT: Content: 48656C6C6F2100 diff --git a/test/MC/WebAssembly/reloc-data.ll b/test/MC/WebAssembly/reloc-data.ll index c812939711f..2c4b206fe9f 100644 --- a/test/MC/WebAssembly/reloc-data.ll +++ b/test/MC/WebAssembly/reloc-data.ll @@ -1,4 +1,4 @@ -; RUN: llc -O0 -filetype=obj -thread-model=single %s -o - | llvm-readobj -r -expand-relocs | FileCheck %s +; RUN: llc -O0 -filetype=obj %s -o - | llvm-readobj -r -expand-relocs | FileCheck %s target triple = "wasm32-unknown-unknown" diff --git a/test/MC/WebAssembly/unnamed-data.ll b/test/MC/WebAssembly/unnamed-data.ll index 2eb30c71f4a..3b3b414dbf7 100644 --- a/test/MC/WebAssembly/unnamed-data.ll +++ b/test/MC/WebAssembly/unnamed-data.ll @@ -1,4 +1,4 @@ -; RUN: llc -filetype=obj -thread-model=single %s -o - | obj2yaml | FileCheck %s +; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s target triple = "wasm32-unknown-unknown" diff --git a/test/MC/WebAssembly/weak-alias.ll b/test/MC/WebAssembly/weak-alias.ll index fe8112ddacb..7abdc79b569 100644 --- a/test/MC/WebAssembly/weak-alias.ll +++ b/test/MC/WebAssembly/weak-alias.ll @@ -1,4 +1,4 @@ -; RUN: llc -filetype=obj -thread-model=single -wasm-keep-registers %s -o %t.o +; RUN: llc -filetype=obj -wasm-keep-registers %s -o %t.o ; RUN: obj2yaml %t.o | FileCheck %s ; RUN: llvm-objdump -t %t.o | FileCheck --check-prefix=CHECK-SYMS %s diff --git a/test/tools/llvm-nm/wasm/local-symbols.ll b/test/tools/llvm-nm/wasm/local-symbols.ll index cc64f2e7f47..f7c0e837cc9 100644 --- a/test/tools/llvm-nm/wasm/local-symbols.ll +++ b/test/tools/llvm-nm/wasm/local-symbols.ll @@ -1,4 +1,4 @@ -; RUN: llc -filetype=obj -thread-model=single -mtriple=wasm32-unknown-unknown -o %t.o %s +; RUN: llc -filetype=obj -mtriple=wasm32-unknown-unknown -o %t.o %s ; RUN: llvm-nm %t.o | FileCheck %s @foo = internal global i32 1, align 4 diff --git a/test/tools/llvm-objdump/WebAssembly/relocations.test b/test/tools/llvm-objdump/WebAssembly/relocations.test index d86e9392651..acf276e7ba7 100644 --- a/test/tools/llvm-objdump/WebAssembly/relocations.test +++ b/test/tools/llvm-objdump/WebAssembly/relocations.test @@ -1,4 +1,4 @@ -; RUN: llc -thread-model=single -mtriple=wasm32-unknown-unknown -filetype=obj %s -o - | llvm-objdump -r - | FileCheck %s +; RUN: llc -mtriple=wasm32-unknown-unknown -filetype=obj %s -o - | llvm-objdump -r - | FileCheck %s @foo = external global i32, align 4 @bar = global i32* @foo, align 4