Index: bolt/include/bolt/Core/BinaryContext.h =================================================================== --- bolt/include/bolt/Core/BinaryContext.h +++ bolt/include/bolt/Core/BinaryContext.h @@ -37,12 +37,12 @@ #include "llvm/MC/MCSymbol.h" #include "llvm/MC/TargetRegistry.h" #include "llvm/Support/ErrorOr.h" +#include "llvm/Support/RWMutex.h" #include "llvm/Support/raw_ostream.h" #include #include #include #include -#include #include #include #include @@ -190,7 +190,7 @@ std::map BinaryFunctions; /// A mutex that is used to control parallel accesses to BinaryFunctions - mutable std::shared_timed_mutex BinaryFunctionsMutex; + mutable llvm::sys::RWMutex BinaryFunctionsMutex; /// Functions injected by BOLT std::vector InjectedBinaryFunctions; @@ -420,7 +420,7 @@ std::unordered_map SymbolToFunctionMap; /// A mutex that is used to control parallel accesses to SymbolToFunctionMap - mutable std::shared_timed_mutex SymbolToFunctionMapMutex; + mutable llvm::sys::RWMutex SymbolToFunctionMapMutex; /// Look up the symbol entry that contains the given \p Address (based on /// the start address and size for each symbol). Returns a pointer to @@ -556,9 +556,9 @@ std::unique_ptr Ctx; /// A mutex that is used to control parallel accesses to Ctx - mutable std::shared_timed_mutex CtxMutex; - std::unique_lock scopeLock() const { - return std::unique_lock(CtxMutex); + mutable llvm::sys::RWMutex CtxMutex; + std::unique_lock scopeLock() const { + return std::unique_lock(CtxMutex); } std::unique_ptr DwCtx; Index: bolt/include/bolt/Core/BinaryFunction.h =================================================================== --- bolt/include/bolt/Core/BinaryFunction.h +++ bolt/include/bolt/Core/BinaryFunction.h @@ -45,6 +45,7 @@ #include "llvm/MC/MCInst.h" #include "llvm/MC/MCSymbol.h" #include "llvm/Object/ObjectFile.h" +#include "llvm/Support/RWMutex.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -1166,7 +1167,7 @@ MCSymbol *&FunctionEndLabel = FunctionEndLabels[LabelIndex]; if (!FunctionEndLabel) { - std::unique_lock Lock(BC.CtxMutex); + std::unique_lock Lock(BC.CtxMutex); if (Fragment == FragmentNum::main()) FunctionEndLabel = BC.Ctx->createNamedTempSymbol("func_end"); else @@ -1490,7 +1491,7 @@ std::unique_ptr createBasicBlock(MCSymbol *Label = nullptr) { if (!Label) { - std::unique_lock Lock(BC.CtxMutex); + std::unique_lock Lock(BC.CtxMutex); Label = BC.Ctx->createNamedTempSymbol("BB"); } auto BB = Index: bolt/include/bolt/Passes/Aligner.h =================================================================== --- bolt/include/bolt/Passes/Aligner.h +++ bolt/include/bolt/Passes/Aligner.h @@ -16,6 +16,7 @@ #define BOLT_PASSES_ALIGNER_H #include "bolt/Passes/BinaryPasses.h" +#include "llvm/Support/RWMutex.h" namespace llvm { namespace bolt { @@ -24,7 +25,7 @@ private: /// Stats for usage of max bytes for basic block alignment. std::vector AlignHistogram; - std::shared_timed_mutex AlignHistogramMtx; + llvm::sys::RWMutex AlignHistogramMtx; /// Stats: execution count of blocks that were aligned. std::atomic AlignedBlocksCount{0}; Index: bolt/include/bolt/Passes/Instrumentation.h =================================================================== --- bolt/include/bolt/Passes/Instrumentation.h +++ bolt/include/bolt/Passes/Instrumentation.h @@ -19,6 +19,7 @@ #include "bolt/Passes/BinaryPasses.h" #include "bolt/Passes/InstrumentationSummary.h" +#include "llvm/Support/RWMutex.h" namespace llvm { namespace bolt { @@ -109,7 +110,7 @@ /// strtab indices in StringTable for each function name std::unordered_map FuncToStringIdx; - mutable std::shared_timed_mutex FDMutex; + mutable llvm::sys::RWMutex FDMutex; /// The data generated during Instrumentation pass that needs to /// be passed to the Instrument runtime library. Index: bolt/lib/Core/BinaryBasicBlock.cpp =================================================================== --- bolt/lib/Core/BinaryBasicBlock.cpp +++ bolt/lib/Core/BinaryBasicBlock.cpp @@ -491,7 +491,7 @@ assert(isSuccessor(Successor)); BinaryContext &BC = Function->getBinaryContext(); MCInst NewInst; - std::unique_lock Lock(BC.CtxMutex); + std::unique_lock Lock(BC.CtxMutex); BC.MIB->createUncondBranch(NewInst, Successor->getLabel(), BC.Ctx.get()); Instructions.emplace_back(std::move(NewInst)); } Index: bolt/lib/Core/BinaryContext.cpp =================================================================== --- bolt/lib/Core/BinaryContext.cpp +++ bolt/lib/Core/BinaryContext.cpp @@ -1316,9 +1316,8 @@ assert(!ChildBF.isMultiEntry() && !ParentBF.isMultiEntry() && "cannot merge functions with multiple entry points"); - std::unique_lock WriteCtxLock(CtxMutex, - std::defer_lock); - std::unique_lock WriteSymbolMapLock( + std::unique_lock WriteCtxLock(CtxMutex, std::defer_lock); + std::unique_lock WriteSymbolMapLock( SymbolToFunctionMapMutex, std::defer_lock); const StringRef ChildName = ChildBF.getOneName(); @@ -1343,10 +1342,10 @@ // continue to exist and either one can be executed. ChildBF.mergeProfileDataInto(ParentBF); - std::shared_lock ReadBfsLock(BinaryFunctionsMutex, - std::defer_lock); - std::unique_lock WriteBfsLock(BinaryFunctionsMutex, - std::defer_lock); + std::shared_lock ReadBfsLock(BinaryFunctionsMutex, + std::defer_lock); + std::unique_lock WriteBfsLock(BinaryFunctionsMutex, + std::defer_lock); // Remove ChildBF from the global set of functions in relocs mode. ReadBfsLock.lock(); auto FI = BinaryFunctions.find(ChildBF.getAddress()); @@ -2157,7 +2156,7 @@ BinaryFunction *BinaryContext::getFunctionForSymbol(const MCSymbol *Symbol, uint64_t *EntryDesc) { - std::shared_lock Lock(SymbolToFunctionMapMutex); + std::shared_lock Lock(SymbolToFunctionMapMutex); auto BFI = SymbolToFunctionMap.find(Symbol); if (BFI == SymbolToFunctionMap.end()) return nullptr; Index: bolt/lib/Core/Exceptions.cpp =================================================================== --- bolt/lib/Core/Exceptions.cpp +++ bolt/lib/Core/Exceptions.cpp @@ -406,7 +406,7 @@ const MCSymbol *EHSymbol; MCInst EHLabel; { - std::unique_lock Lock(BC.CtxMutex); + std::unique_lock Lock(BC.CtxMutex); EHSymbol = BC.Ctx->createNamedTempSymbol("EH"); BC.MIB->createEHLabel(EHLabel, EHSymbol, BC.Ctx.get()); } Index: bolt/lib/Core/ParallelUtilities.cpp =================================================================== --- bolt/lib/Core/ParallelUtilities.cpp +++ bolt/lib/Core/ParallelUtilities.cpp @@ -13,10 +13,10 @@ #include "bolt/Core/ParallelUtilities.h" #include "bolt/Core/BinaryContext.h" #include "bolt/Core/BinaryFunction.h" +#include "llvm/Support/RWMutex.h" #include "llvm/Support/ThreadPool.h" #include "llvm/Support/Timer.h" #include -#include #define DEBUG_TYPE "par-utils" @@ -170,13 +170,13 @@ if (BC.getBinaryFunctions().size() == 0) return; - std::shared_timed_mutex MainLock; + llvm::sys::RWMutex MainLock; auto runBlock = [&](std::map::iterator BlockBegin, std::map::iterator BlockEnd, MCPlusBuilder::AllocatorIdTy AllocId) { Timer T(LogName, LogName); LLVM_DEBUG(T.startTimer()); - std::shared_lock Lock(MainLock); + std::shared_lock Lock(MainLock); for (auto It = BlockBegin; It != BlockEnd; ++It) { BinaryFunction &BF = It->second; if (SkipPredicate && SkipPredicate(BF)) @@ -192,7 +192,7 @@ return; } // This lock is used to postpone task execution - std::unique_lock Lock(MainLock); + std::unique_lock Lock(MainLock); // Estimate the overall runtime cost using the scheduling policy const unsigned TotalCost = estimateTotalCost(BC, SkipPredicate, SchedPolicy); Index: bolt/lib/Passes/Aligner.cpp =================================================================== --- bolt/lib/Passes/Aligner.cpp +++ bolt/lib/Passes/Aligner.cpp @@ -143,7 +143,7 @@ // Update stats. LLVM_DEBUG( - std::unique_lock Lock(AlignHistogramMtx); + std::unique_lock Lock(AlignHistogramMtx); AlignHistogram[BytesToUse]++; AlignedBlocksCount += BB->getKnownExecutionCount(); ); Index: bolt/lib/Passes/Instrumentation.cpp =================================================================== --- bolt/lib/Passes/Instrumentation.cpp +++ bolt/lib/Passes/Instrumentation.cpp @@ -15,6 +15,7 @@ #include "bolt/RuntimeLibs/InstrumentationRuntimeLibrary.h" #include "bolt/Utils/Utils.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/RWMutex.h" #include #define DEBUG_TYPE "bolt-instrumentation" @@ -298,7 +299,7 @@ FunctionDescription *FuncDesc = nullptr; { - std::unique_lock L(FDMutex); + std::unique_lock L(FDMutex); Summary->FunctionDescriptions.emplace_back(); FuncDesc = &Summary->FunctionDescriptions.back(); }