]> granicus.if.org Git - llvm/commitdiff
[WebAssembly] Remove uses of ThreadModel
authorThomas Lively <tlively@google.com>
Thu, 28 Feb 2019 18:39:08 +0000 (18:39 +0000)
committerThomas Lively <tlively@google.com>
Thu, 28 Feb 2019 18:39:08 +0000 (18:39 +0000)
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

21 files changed:
lib/CodeGen/TargetLoweringObjectFileImpl.cpp
lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
lib/Target/WebAssembly/WebAssemblyTargetMachine.h
test/CodeGen/WebAssembly/atomic-mem-consistency.ll
test/CodeGen/WebAssembly/atomic-rmw.ll
test/CodeGen/WebAssembly/global.ll
test/CodeGen/WebAssembly/tls.ll
test/CodeGen/WebAssembly/vtable.ll
test/MC/WebAssembly/bss.ll
test/MC/WebAssembly/comdat.ll
test/MC/WebAssembly/debug-info.ll
test/MC/WebAssembly/explicit-sections.ll
test/MC/WebAssembly/external-data.ll
test/MC/WebAssembly/external-func-address.ll
test/MC/WebAssembly/global-ctor-dtor.ll
test/MC/WebAssembly/init-flags.ll [deleted file]
test/MC/WebAssembly/reloc-data.ll
test/MC/WebAssembly/unnamed-data.ll
test/MC/WebAssembly/weak-alias.ll
test/tools/llvm-nm/wasm/local-symbols.ll
test/tools/llvm-objdump/WebAssembly/relocations.test

index c50c6476ec5308101ce23d3a5738627e203a7703..436076f33b91849d3866fb3d668d5ccda51421cf 100644 (file)
@@ -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(
index 8e8b4878c52c1cb36ff22566b8bbdce8ce9b3374..768ab7a099c96bbe84de8f6d7d1ed0a3de1403f1 100644 (file)
@@ -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<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");
@@ -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<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 {
@@ -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<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
index e13ad7d4eacbfec89d01062eacb497877c102d74..0630797fe8143f5bc429ff6e4f2ceed7414d9e3f 100644 (file)
@@ -23,6 +23,7 @@ namespace llvm {
 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,
@@ -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; }
index 3a714370d84cf019eb047712d0208eeeffda6b97..c2cb02acc1ee569a14b4de36091347e89c374978 100644 (file)
@@ -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
index 27b3be09943df6822e7a5fbb7bcd02a2ae6bed06..34f505b7d6b4738766bcf46b76d06daf462bf7c4 100644 (file)
@@ -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.
index d341ebc8f369341302b9fa72f87f54d1f9dd2786..12f4db43f38a12591af4c7260842e02f670a1a4d 100644 (file)
@@ -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:
index 6843aa0f9be300520fcf2c7edee882b609371257..21e84f9fa9799ef8a599793c742433447df8f633 100644 (file)
@@ -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"
 
index 5a6d89d4e54cf024a8372191699f10db0cd6e8a6..6a0d902254dd6b19eb1cec1945cbe585ef533789 100644 (file)
@@ -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.
 ;
index a274982ed5b5844cd950ab1cb17b8c4c1b6a8d65..36785caa3bace3f2296e8ada3c38fe7aae0cd0bf 100644 (file)
@@ -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"
 
index 9b1ac501dbf22e482dbd0da26dc9ed20118d8bef..95b77b9da61bd914bc00b28f2094d11ecdd363c6 100644 (file)
@@ -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"
 
index 374f5b3528b57d8cbd0b2d3257881da2e5d32e6d..fe4a4cf698319773543f31baaf27101ced305ff0 100644 (file)
@@ -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
index 7fa6d4b6017e3d35c41e03a5fd44d0106b2447f7..f6e9cae286840a689cc1651d5c2ccd965e48dfc3 100644 (file)
@@ -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"
 
index 7598c920903f2832fe3650ca74c6413a8388b11d..c1ebca69c37f1591b95a4cdb358b5098360e797c 100644 (file)
@@ -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"
 
index 7ad4faa27017d59da08dfa4be3778d67c4f1fc64..95e679ab65d1cd6136bd67d2f0869cdae605a77f 100644 (file)
@@ -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"
 
index 1405803dd8f7d1e4b66c554c807ce6d43bd4cd64..d7e9bc9676be8ae69a4c95738769bdfc114a52d2 100644 (file)
@@ -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 (file)
index a5d2662..0000000
+++ /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
index c812939711f2b7506f6e8b36883c5ea881369ef9..2c4b206fe9f55527031dbe835db61e6f8ecc1405 100644 (file)
@@ -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"
 
index 2eb30c71f4a6dc488f34e2a731c6196759a1cd2a..3b3b414dbf7837d0fd5aa214e3d60255e9ce1ec7 100644 (file)
@@ -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"
 
index fe8112ddacb9aecc58cbd284871a20c4281f73ad..7abdc79b5691b68cd388e43b0def7b041d953900 100644 (file)
@@ -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
 
index cc64f2e7f47044a41994373f4baa4f7f0bae39bd..f7c0e837cc9f87c143a99b74c602a4a54de56fea 100644 (file)
@@ -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
index d86e9392651f885b943c530ba9284844800244fd..acf276e7ba76aad28f039334f0bf7086bb51e5f8 100644 (file)
@@ -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