Skip to content

Commit

Permalink
Revert "ManagedStatic: remove many straightforward uses in llvm"
Browse files Browse the repository at this point in the history
This reverts commit e6f1f06.

Reverting due to a failure on the fuchsia-x86_64-linux buildbot.
  • Loading branch information
nhaehnle committed Jul 10, 2022
1 parent e6f1f06 commit e9ce1a5
Show file tree
Hide file tree
Showing 34 changed files with 162 additions and 164 deletions.
4 changes: 2 additions & 2 deletions llvm/include/llvm/IR/OptBisect.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define LLVM_IR_OPTBISECT_H

#include "llvm/ADT/StringRef.h"
#include "llvm/Support/ManagedStatic.h"
#include <limits>

namespace llvm {
Expand Down Expand Up @@ -89,8 +90,7 @@ class OptBisect : public OptPassGate {

/// Singleton instance of the OptBisect class, so multiple pass managers don't
/// need to coordinate their uses of OptBisect.
OptBisect &getOptBisector();

extern ManagedStatic<OptBisect> OptBisector;
} // end namespace llvm

#endif // LLVM_IR_OPTBISECT_H
11 changes: 7 additions & 4 deletions llvm/lib/Analysis/TFUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/JSON.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -48,17 +49,19 @@ using TFStatusPtr = std::unique_ptr<TF_Status, decltype(&TF_DeleteStatus)>;

struct TFInitializer {
TFInitializer() {
assert(!IsInitialized && "TFInitialized should be called only once");
int Argc = 1;
const char *Name = "";
const char **NamePtr = &Name;
TF_InitMain(Name, &Argc, const_cast<char ***>(&NamePtr));
IsInitialized = true;
}
bool IsInitialized = false;
};

bool ensureInitTF() {
static TFInitializer TFLibInitializer;
return true;
}
llvm::ManagedStatic<TFInitializer> TFLibInitializer;

bool ensureInitTF() { return TFLibInitializer->IsInitialized; }

TFGraphPtr createTFGraph() {
return TFGraphPtr(TF_NewGraph(), &TF_DeleteGraph);
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -7445,9 +7446,10 @@ class BitcodeErrorCategoryType : public std::error_category {

} // end anonymous namespace

static ManagedStatic<BitcodeErrorCategoryType> ErrorCategory;

const std::error_category &llvm::BitcodeErrorCategory() {
static BitcodeErrorCategoryType ErrorCategory;
return ErrorCategory;
return *ErrorCategory;
}

static Expected<StringRef> readBlobInRecord(BitstreamCursor &Stream,
Expand Down
15 changes: 8 additions & 7 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/MachineValueType.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -10753,19 +10754,19 @@ namespace {

} // end anonymous namespace

static ManagedStatic<std::set<EVT, EVT::compareRawBits>> EVTs;
static ManagedStatic<EVTArray> SimpleVTArray;
static ManagedStatic<sys::SmartMutex<true>> VTMutex;

/// getValueTypeList - Return a pointer to the specified value type.
///
const EVT *SDNode::getValueTypeList(EVT VT) {
static std::set<EVT, EVT::compareRawBits> EVTs;
static EVTArray SimpleVTArray;
static sys::SmartMutex<true> VTMutex;

if (VT.isExtended()) {
sys::SmartScopedLock<true> Lock(VTMutex);
return &(*EVTs.insert(VT).first);
sys::SmartScopedLock<true> Lock(*VTMutex);
return &(*EVTs->insert(VT).first);
}
assert(VT.getSimpleVT() < MVT::VALUETYPE_SIZE && "Value type out of range!");
return &SimpleVTArray.VTs[VT.getSimpleVT().SimpleTy];
return &SimpleVTArray->VTs[VT.getSimpleVT().SimpleTy];
}

/// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/DebugInfo/CodeView/CodeViewError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "llvm/DebugInfo/CodeView/CodeViewError.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"
#include <string>

using namespace llvm;
Expand Down Expand Up @@ -41,9 +42,9 @@ class CodeViewErrorCategory : public std::error_category {
};
} // namespace

static llvm::ManagedStatic<CodeViewErrorCategory> CodeViewErrCategory;
const std::error_category &llvm::codeview::CVErrorCategory() {
static CodeViewErrorCategory CodeViewErrCategory;
return CodeViewErrCategory;
return *CodeViewErrCategory;
}

char CodeViewError::ID;
7 changes: 3 additions & 4 deletions llvm/lib/DebugInfo/MSF/MSFError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "llvm/DebugInfo/MSF/MSFError.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"
#include <string>

using namespace llvm;
Expand Down Expand Up @@ -49,9 +50,7 @@ class MSFErrorCategory : public std::error_category {
};
} // namespace

const std::error_category &llvm::msf::MSFErrCategory() {
static MSFErrorCategory MSFCategory;
return MSFCategory;
}
static llvm::ManagedStatic<MSFErrorCategory> MSFCategory;
const std::error_category &llvm::msf::MSFErrCategory() { return *MSFCategory; }

char MSFError::ID;
7 changes: 3 additions & 4 deletions llvm/lib/DebugInfo/PDB/DIA/DIAError.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "llvm/DebugInfo/PDB/DIA/DIAError.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"

using namespace llvm;
using namespace llvm::pdb;
Expand Down Expand Up @@ -30,9 +31,7 @@ class DIAErrorCategory : public std::error_category {
}
};

const std::error_category &llvm::pdb::DIAErrCategory() {
static DIAErrorCategory DIACategory;
return DIACategory;
}
static llvm::ManagedStatic<DIAErrorCategory> DIACategory;
const std::error_category &llvm::pdb::DIAErrCategory() { return *DIACategory; }

char DIAError::ID;
7 changes: 3 additions & 4 deletions llvm/lib/DebugInfo/PDB/GenericError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "llvm/DebugInfo/PDB/GenericError.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"

using namespace llvm;
using namespace llvm::pdb;
Expand Down Expand Up @@ -41,9 +42,7 @@ class PDBErrorCategory : public std::error_category {
};
} // namespace

const std::error_category &llvm::pdb::PDBErrCategory() {
static PDBErrorCategory PDBCategory;
return PDBCategory;
}
static llvm::ManagedStatic<PDBErrorCategory> PDBCategory;
const std::error_category &llvm::pdb::PDBErrCategory() { return *PDBCategory; }

char PDBError::ID;
7 changes: 3 additions & 4 deletions llvm/lib/DebugInfo/PDB/Native/RawError.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "llvm/DebugInfo/PDB/Native/RawError.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"

using namespace llvm;
using namespace llvm::pdb;
Expand Down Expand Up @@ -46,9 +47,7 @@ class RawErrorCategory : public std::error_category {
};
} // namespace

const std::error_category &llvm::pdb::RawErrCategory() {
static RawErrorCategory RawCategory;
return RawCategory;
}
static llvm::ManagedStatic<RawErrorCategory> RawCategory;
const std::error_category &llvm::pdb::RawErrCategory() { return *RawCategory; }

char RawError::ID;
17 changes: 8 additions & 9 deletions llvm/lib/ExecutionEngine/GDBRegistrationListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Mutex.h"
#include <mutex>
Expand Down Expand Up @@ -122,10 +123,7 @@ class GDBJITRegistrationListener : public JITEventListener {

/// Lock used to serialize all jit registration events, since they
/// modify global variables.
sys::Mutex &getJITDebugLock() {
static sys::Mutex JITDebugLock;
return JITDebugLock;
}
ManagedStatic<sys::Mutex> JITDebugLock;

/// Do the registration.
void NotifyDebugger(jit_code_entry* JITCodeEntry) {
Expand All @@ -145,7 +143,7 @@ void NotifyDebugger(jit_code_entry* JITCodeEntry) {

GDBJITRegistrationListener::~GDBJITRegistrationListener() {
// Free all registered object files.
std::lock_guard<llvm::sys::Mutex> locked(getJITDebugLock());
std::lock_guard<llvm::sys::Mutex> locked(*JITDebugLock);
for (RegisteredObjectBufferMap::iterator I = ObjectBufferMap.begin(),
E = ObjectBufferMap.end();
I != E; ++I) {
Expand All @@ -169,7 +167,7 @@ void GDBJITRegistrationListener::notifyObjectLoaded(
const char *Buffer = DebugObj.getBinary()->getMemoryBufferRef().getBufferStart();
size_t Size = DebugObj.getBinary()->getMemoryBufferRef().getBufferSize();

std::lock_guard<llvm::sys::Mutex> locked(getJITDebugLock());
std::lock_guard<llvm::sys::Mutex> locked(*JITDebugLock);
assert(ObjectBufferMap.find(K) == ObjectBufferMap.end() &&
"Second attempt to perform debug registration.");
jit_code_entry* JITCodeEntry = new jit_code_entry();
Expand All @@ -188,7 +186,7 @@ void GDBJITRegistrationListener::notifyObjectLoaded(
}

void GDBJITRegistrationListener::notifyFreeingObject(ObjectKey K) {
std::lock_guard<llvm::sys::Mutex> locked(getJITDebugLock());
std::lock_guard<llvm::sys::Mutex> locked(*JITDebugLock);
RegisteredObjectBufferMap::iterator I = ObjectBufferMap.find(K);

if (I != ObjectBufferMap.end()) {
Expand Down Expand Up @@ -230,13 +228,14 @@ void GDBJITRegistrationListener::deregisterObjectInternal(
JITCodeEntry = nullptr;
}

llvm::ManagedStatic<GDBJITRegistrationListener> GDBRegListener;

} // end namespace

namespace llvm {

JITEventListener* JITEventListener::createGDBRegistrationListener() {
static GDBJITRegistrationListener GDBRegListener;
return &GDBRegListener;
return &*GDBRegListener;
}

} // namespace llvm
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "llvm/ExecutionEngine/JITLink/ELF.h"
#include "llvm/ExecutionEngine/JITLink/MachO.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"

Expand Down Expand Up @@ -40,6 +41,8 @@ class JITLinkerErrorCategory : public std::error_category {
}
};

static ManagedStatic<JITLinkerErrorCategory> JITLinkerErrorCategory;

} // namespace

namespace llvm {
Expand All @@ -50,8 +53,7 @@ char JITLinkError::ID = 0;
void JITLinkError::log(raw_ostream &OS) const { OS << ErrMsg; }

std::error_code JITLinkError::convertToErrorCode() const {
static JITLinkerErrorCategory TheJITLinkerErrorCategory;
return std::error_code(GenericJITLinkError, TheJITLinkerErrorCategory);
return std::error_code(GenericJITLinkError, *JITLinkerErrorCategory);
}

const char *getGenericEdgeKindName(Edge::Kind K) {
Expand Down
10 changes: 4 additions & 6 deletions llvm/lib/ExecutionEngine/Orc/Shared/OrcError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "llvm/ExecutionEngine/Orc/Shared/OrcError.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"

#include <type_traits>

Expand Down Expand Up @@ -69,10 +70,7 @@ class OrcErrorCategory : public std::error_category {
}
};

OrcErrorCategory &getOrcErrCat() {
static OrcErrorCategory OrcErrCat;
return OrcErrCat;
}
static ManagedStatic<OrcErrorCategory> OrcErrCat;
} // namespace

namespace llvm {
Expand All @@ -83,7 +81,7 @@ char JITSymbolNotFound::ID = 0;

std::error_code orcError(OrcErrorCode ErrCode) {
typedef std::underlying_type<OrcErrorCode>::type UT;
return std::error_code(static_cast<UT>(ErrCode), getOrcErrCat());
return std::error_code(static_cast<UT>(ErrCode), *OrcErrCat);
}

DuplicateDefinition::DuplicateDefinition(std::string SymbolName)
Expand All @@ -107,7 +105,7 @@ JITSymbolNotFound::JITSymbolNotFound(std::string SymbolName)
std::error_code JITSymbolNotFound::convertToErrorCode() const {
typedef std::underlying_type<OrcErrorCode>::type UT;
return std::error_code(static_cast<UT>(OrcErrorCode::JITSymbolNotFound),
getOrcErrCat());
*OrcErrCat);
}

void JITSymbolNotFound::log(raw_ostream &OS) const {
Expand Down
8 changes: 5 additions & 3 deletions llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/Support/BinaryStreamReader.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/ManagedStatic.h"

#include <cstdint>
#include <mutex>
Expand Down Expand Up @@ -66,6 +67,9 @@ LLVM_ATTRIBUTE_NOINLINE void __jit_debug_register_code() {
using namespace llvm;
using namespace llvm::orc;

// Serialize rendezvous with the debugger as well as access to shared data.
ManagedStatic<std::mutex> JITDebugLock;

// Register debug object, return error message or null for success.
static void registerJITLoaderGDBImpl(const char *ObjAddr, size_t Size) {
LLVM_DEBUG({
Expand All @@ -81,9 +85,7 @@ static void registerJITLoaderGDBImpl(const char *ObjAddr, size_t Size) {
E->symfile_size = Size;
E->prev_entry = nullptr;

// Serialize rendezvous with the debugger as well as access to shared data.
static std::mutex JITDebugLock;
std::lock_guard<std::mutex> Lock(JITDebugLock);
std::lock_guard<std::mutex> Lock(*JITDebugLock);

// Insert this entry at the head of the list.
jit_code_entry *NextEntry = __jit_debug_descriptor.first_entry;
Expand Down
10 changes: 6 additions & 4 deletions llvm/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/Errno.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/Path.h"
Expand Down Expand Up @@ -487,14 +488,15 @@ void PerfJITEventListener::NotifyDebug(uint64_t CodeAddr,
}
}

// There should be only a single event listener per process, otherwise perf gets
// confused.
llvm::ManagedStatic<PerfJITEventListener> PerfListener;

} // end anonymous namespace

namespace llvm {
JITEventListener *JITEventListener::createPerfJITEventListener() {
// There should be only a single event listener per process, otherwise perf
// gets confused.
static PerfJITEventListener PerfListener;
return &PerfListener;
return &*PerfListener;
}

} // namespace llvm
Expand Down
Loading

0 comments on commit e9ce1a5

Please sign in to comment.