[PATCH] D141349: Remove the ThreadLocal template from LLVM.

2023-01-10 Thread Owen Anderson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe4e0f9330798: Remove the ThreadLocal template from LLVM. 
(authored by resistor).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141349/new/

https://reviews.llvm.org/D141349

Files:
  clang-tools-extra/clangd/support/ThreadCrashReporter.cpp
  llvm/include/llvm/Support/ThreadLocal.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/CrashRecoveryContext.cpp
  llvm/lib/Support/ThreadLocal.cpp
  llvm/lib/Support/Unix/ThreadLocal.inc
  llvm/lib/Support/Windows/ThreadLocal.inc
  llvm/unittests/Support/CMakeLists.txt
  llvm/unittests/Support/ThreadLocalTest.cpp
  mlir/include/mlir/Support/ThreadLocalCache.h

Index: mlir/include/mlir/Support/ThreadLocalCache.h
===
--- mlir/include/mlir/Support/ThreadLocalCache.h
+++ mlir/include/mlir/Support/ThreadLocalCache.h
@@ -18,7 +18,6 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Mutex.h"
-#include "llvm/Support/ThreadLocal.h"
 
 namespace mlir {
 /// This class provides support for defining a thread local object with non
Index: llvm/unittests/Support/ThreadLocalTest.cpp
===
--- llvm/unittests/Support/ThreadLocalTest.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-//===- llvm/unittest/Support/ThreadLocalTest.cpp - ThreadLocal tests --===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "llvm/Support/ThreadLocal.h"
-#include "gtest/gtest.h"
-#include 
-
-using namespace llvm;
-using namespace sys;
-
-namespace {
-
-class ThreadLocalTest : public ::testing::Test {
-};
-
-struct S {
-  int i;
-};
-
-TEST_F(ThreadLocalTest, Basics) {
-  ThreadLocal x;
-
-  static_assert(std::is_const_v>,
-"ThreadLocal::get didn't return a pointer to const object");
-
-  EXPECT_EQ(nullptr, x.get());
-
-  S s;
-  x.set();
-  EXPECT_EQ(, x.get());
-
-  x.erase();
-  EXPECT_EQ(nullptr, x.get());
-
-  ThreadLocal y;
-
-  static_assert(!std::is_const_v>,
-"ThreadLocal::get returned a pointer to const object");
-
-  EXPECT_EQ(nullptr, y.get());
-
-  y.set();
-  EXPECT_EQ(, y.get());
-
-  y.erase();
-  EXPECT_EQ(nullptr, y.get());
-}
-
-}
Index: llvm/unittests/Support/CMakeLists.txt
===
--- llvm/unittests/Support/CMakeLists.txt
+++ llvm/unittests/Support/CMakeLists.txt
@@ -80,7 +80,6 @@
   SymbolRemappingReaderTest.cpp
   TarWriterTest.cpp
   TaskQueueTest.cpp
-  ThreadLocalTest.cpp
   ThreadPool.cpp
   Threading.cpp
   TimerTest.cpp
Index: llvm/lib/Support/Windows/ThreadLocal.inc
===
--- llvm/lib/Support/Windows/ThreadLocal.inc
+++ /dev/null
@@ -1,50 +0,0 @@
-//= llvm/Support/Win32/ThreadLocal.inc - Win32 Thread Local Data -*- C++
-//-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-//
-// This file implements the Win32 specific (non-pthread) ThreadLocal class.
-//
-//===--===//
-
-//===--===//
-//=== WARNING: Implementation here must contain only generic Win32 code that
-//===  is guaranteed to work on *all* Win32 variants.
-//===--===//
-
-#include "llvm/Support/ThreadLocal.h"
-#include "llvm/Support/Windows/WindowsSupport.h"
-
-namespace llvm {
-
-sys::ThreadLocalImpl::ThreadLocalImpl() : data() {
-  static_assert(sizeof(DWORD) <= sizeof(data), "size too big");
-  DWORD *tls = reinterpret_cast();
-  *tls = TlsAlloc();
-  assert(*tls != TLS_OUT_OF_INDEXES);
-}
-
-sys::ThreadLocalImpl::~ThreadLocalImpl() {
-  DWORD *tls = reinterpret_cast();
-  TlsFree(*tls);
-}
-
-void *sys::ThreadLocalImpl::getInstance() {
-  DWORD *tls = reinterpret_cast();
-  return TlsGetValue(*tls);
-}
-
-void sys::ThreadLocalImpl::setInstance(const void *d) {
-  DWORD *tls = reinterpret_cast();
-  int errorcode = TlsSetValue(*tls, const_cast(d));
-  assert(errorcode != 0);
-  (void)errorcode;
-}
-
-void sys::ThreadLocalImpl::removeInstance() { setInstance(0); }
-
-} // namespace llvm
Index: llvm/lib/Support/Unix/ThreadLocal.inc

[PATCH] D141349: Remove the ThreadLocal template from LLVM.

2023-01-10 Thread Nikita Popov via Phabricator via cfe-commits
nikic accepted this revision.
nikic added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: StephenFan.

LGTM

> As a precaution, use LLVM_THREAD_LOCAL which provides even greater
> backwards compatibility, allowing this to function even pre-C++11
> versions of GCC.

I don't think backwards compatibility is still relevant given our minimum 
version requirements. We can probably drop the `__thread` fallback. What 
LLVM_THREAD_LOCAL does though is fall back to a normal variable if 
`!LLVM_ENABLE_THREADS`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141349/new/

https://reviews.llvm.org/D141349

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141349: Remove the ThreadLocal template from LLVM.

2023-01-09 Thread Owen Anderson via Phabricator via cfe-commits
resistor added a comment.

Incorporated build fixes for GCC. Waiting for buildbots to complete.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141349/new/

https://reviews.llvm.org/D141349

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141349: Remove the ThreadLocal template from LLVM.

2023-01-09 Thread Owen Anderson via Phabricator via cfe-commits
resistor created this revision.
Herald added subscribers: Moerafaat, zero9178, bzcheeseman, sdasgup3, 
wenzhicui, wrengr, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, 
Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, 
antiagainst, shauheen, rriddle, mehdi_amini, kadircet, arphaman, hiraditya.
Herald added a project: All.
resistor requested review of this revision.
Herald added subscribers: cfe-commits, llvm-commits, stephenneuendorffer, 
nicolasvasilache.
Herald added projects: MLIR, LLVM, clang-tools-extra.

This has been obsoleted by C++ thread_local for a long time.
As far as I know, Xcode was the last supported toolchain to add
support for C++ thread_local in 2016.

As a precaution, use LLVM_THREAD_LOCAL which provides even greater
backwards compatibility, allowing this to function even pre-C++11
versions of GCC.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141349

Files:
  clang-tools-extra/clangd/support/ThreadCrashReporter.cpp
  llvm/include/llvm/Support/ThreadLocal.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/CrashRecoveryContext.cpp
  llvm/lib/Support/ThreadLocal.cpp
  llvm/lib/Support/Unix/ThreadLocal.inc
  llvm/lib/Support/Windows/ThreadLocal.inc
  llvm/unittests/Support/CMakeLists.txt
  llvm/unittests/Support/ThreadLocalTest.cpp
  mlir/include/mlir/Support/ThreadLocalCache.h

Index: mlir/include/mlir/Support/ThreadLocalCache.h
===
--- mlir/include/mlir/Support/ThreadLocalCache.h
+++ mlir/include/mlir/Support/ThreadLocalCache.h
@@ -18,7 +18,6 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Mutex.h"
-#include "llvm/Support/ThreadLocal.h"
 
 namespace mlir {
 /// This class provides support for defining a thread local object with non
Index: llvm/unittests/Support/ThreadLocalTest.cpp
===
--- llvm/unittests/Support/ThreadLocalTest.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-//===- llvm/unittest/Support/ThreadLocalTest.cpp - ThreadLocal tests --===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "llvm/Support/ThreadLocal.h"
-#include "gtest/gtest.h"
-#include 
-
-using namespace llvm;
-using namespace sys;
-
-namespace {
-
-class ThreadLocalTest : public ::testing::Test {
-};
-
-struct S {
-  int i;
-};
-
-TEST_F(ThreadLocalTest, Basics) {
-  ThreadLocal x;
-
-  static_assert(std::is_const_v>,
-"ThreadLocal::get didn't return a pointer to const object");
-
-  EXPECT_EQ(nullptr, x.get());
-
-  S s;
-  x.set();
-  EXPECT_EQ(, x.get());
-
-  x.erase();
-  EXPECT_EQ(nullptr, x.get());
-
-  ThreadLocal y;
-
-  static_assert(!std::is_const_v>,
-"ThreadLocal::get returned a pointer to const object");
-
-  EXPECT_EQ(nullptr, y.get());
-
-  y.set();
-  EXPECT_EQ(, y.get());
-
-  y.erase();
-  EXPECT_EQ(nullptr, y.get());
-}
-
-}
Index: llvm/unittests/Support/CMakeLists.txt
===
--- llvm/unittests/Support/CMakeLists.txt
+++ llvm/unittests/Support/CMakeLists.txt
@@ -80,7 +80,6 @@
   SymbolRemappingReaderTest.cpp
   TarWriterTest.cpp
   TaskQueueTest.cpp
-  ThreadLocalTest.cpp
   ThreadPool.cpp
   Threading.cpp
   TimerTest.cpp
Index: llvm/lib/Support/Windows/ThreadLocal.inc
===
--- llvm/lib/Support/Windows/ThreadLocal.inc
+++ /dev/null
@@ -1,50 +0,0 @@
-//= llvm/Support/Win32/ThreadLocal.inc - Win32 Thread Local Data -*- C++
-//-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-//
-// This file implements the Win32 specific (non-pthread) ThreadLocal class.
-//
-//===--===//
-
-//===--===//
-//=== WARNING: Implementation here must contain only generic Win32 code that
-//===  is guaranteed to work on *all* Win32 variants.
-//===--===//
-
-#include "llvm/Support/ThreadLocal.h"
-#include "llvm/Support/Windows/WindowsSupport.h"
-
-namespace llvm {
-
-sys::ThreadLocalImpl::ThreadLocalImpl() : data() {
-  static_assert(sizeof(DWORD) <= sizeof(data), "size too big");
-  DWORD *tls = reinterpret_cast();
-  *tls = TlsAlloc();
-  assert(*tls != TLS_OUT_OF_INDEXES);
-}
-
-sys::ThreadLocalImpl::~ThreadLocalImpl() {
-