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
getContext().getWasmSection(Name, Kind, Group,
MCContext::GenericSectionID);
- if (TM.Options.ThreadModel != ThreadModel::Single)
- Section->setPassive();
-
return Section;
}
(*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(
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.
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<WebAssemblySubtarget>(TargetTriple, CPU, FS, *this);
+ UsedFeatures |= I->getFeatureBits();
+ }
+ return I.get();
+}
+
const WebAssemblySubtarget *
WebAssemblyTargetMachine::getSubtargetImpl(const Function &F) const {
Attribute CPUAttr = F.getFnAttribute("target-cpu");
? 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<WebAssemblySubtarget>(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 {
//===----------------------------------------------------------------------===//
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<WebAssemblyTargetMachine *>(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
class WebAssemblyTargetMachine final : public LLVMTargetMachine {
std::unique_ptr<TargetLoweringObjectFile> TLOF;
mutable StringMap<std::unique_ptr<WebAssemblySubtarget>> SubtargetMap;
+ mutable FeatureBitset UsedFeatures;
public:
WebAssemblyTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
bool JIT);
~WebAssemblyTargetMachine() override;
+
+ const WebAssemblySubtarget *getSubtargetImpl(std::string CPU,
+ std::string FS) const;
const WebAssemblySubtarget *
getSubtargetImpl(const Function &F) const override;
return TLOF.get();
}
+ FeatureBitset getUsedFeatures() const { return UsedFeatures; }
+
TargetTransformInfo getTargetTransformInfo(const Function &F) override;
bool usesPhysRegsForPEI() const override { return false; }
-; 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
-; 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.
-; 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.
; 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:
; 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:
-; 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"
-; 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.
;
-; 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"
-; 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"
-; 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
-; 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"
-; 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"
-; 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"
-; 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"
+++ /dev/null
-; 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
-; 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"
-; 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"
-; 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
-; 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
-; 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