From: David Blaikie Date: Tue, 5 Feb 2019 23:38:55 +0000 (+0000) Subject: Orc: Simplify RPC naming system by using function-local statics X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eae2f5e5e0c3757c421bd53e9a32751cac3df98e;p=llvm Orc: Simplify RPC naming system by using function-local statics The existing scheme of class template static members for Name and NameMutex is a bit verbose, involves global ctors (even if they're cheap for string and mutex, still not entirely free), and (importantly/my immediate motivation here) trips over a bug in LLVM's modules implementation that's a bit involved (hmm, sounds like Mr. Smith has a fix for the modules thing - but I'm still inclined to commit this patch as general goodness). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353241 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ExecutionEngine/Orc/RPCSerialization.h b/include/llvm/ExecutionEngine/Orc/RPCSerialization.h index 9c18f3609ca..07c7471afc6 100644 --- a/include/llvm/ExecutionEngine/Orc/RPCSerialization.h +++ b/include/llvm/ExecutionEngine/Orc/RPCSerialization.h @@ -127,123 +127,85 @@ template class RPCTypeName> { public: static const char* getName() { - std::lock_guard Lock(NameMutex); - if (Name.empty()) + static std::string Name = [] { + std::string Name; raw_string_ostream(Name) << "Expected<" << RPCTypeNameSequence() << ">"; + return Name; + }(); return Name.data(); } - -private: - static std::mutex NameMutex; - static std::string Name; }; -template -std::mutex RPCTypeName>::NameMutex; - -template -std::string RPCTypeName>::Name; - template class RPCTypeName> { public: static const char* getName() { - std::lock_guard Lock(NameMutex); - if (Name.empty()) + static std::string Name = [] { + std::string Name; raw_string_ostream(Name) << "std::pair<" << RPCTypeNameSequence() << ">"; + return Name; + }(); return Name.data(); } -private: - static std::mutex NameMutex; - static std::string Name; }; -template -std::mutex RPCTypeName>::NameMutex; -template -std::string RPCTypeName>::Name; - template class RPCTypeName> { public: static const char* getName() { - std::lock_guard Lock(NameMutex); - if (Name.empty()) + static std::string Name = [] { + std::string Name; raw_string_ostream(Name) << "std::tuple<" << RPCTypeNameSequence() << ">"; + return Name; + }(); return Name.data(); } -private: - static std::mutex NameMutex; - static std::string Name; }; -template -std::mutex RPCTypeName>::NameMutex; -template -std::string RPCTypeName>::Name; - template class RPCTypeName> { public: static const char*getName() { - std::lock_guard Lock(NameMutex); - if (Name.empty()) + static std::string Name = [] { + std::string Name; raw_string_ostream(Name) << "std::vector<" << RPCTypeName::getName() << ">"; + return Name; + }(); return Name.data(); } - -private: - static std::mutex NameMutex; - static std::string Name; }; -template -std::mutex RPCTypeName>::NameMutex; -template -std::string RPCTypeName>::Name; - template class RPCTypeName> { public: static const char *getName() { - std::lock_guard Lock(NameMutex); - if (Name.empty()) + static std::string Name = [] { + std::string Name; raw_string_ostream(Name) << "std::set<" << RPCTypeName::getName() << ">"; + return Name; + }(); return Name.data(); } - -private: - static std::mutex NameMutex; - static std::string Name; }; -template std::mutex RPCTypeName>::NameMutex; -template std::string RPCTypeName>::Name; - template class RPCTypeName> { public: static const char *getName() { - std::lock_guard Lock(NameMutex); - if (Name.empty()) + static std::string Name = [] { + std::string Name; raw_string_ostream(Name) << "std::map<" << RPCTypeNameSequence() << ">"; + return Name; + }(); return Name.data(); } - -private: - static std::mutex NameMutex; - static std::string Name; }; -template -std::mutex RPCTypeName>::NameMutex; -template std::string RPCTypeName>::Name; - /// The SerializationTraits class describes how to serialize and /// deserialize an instance of type T to/from an abstract channel of type /// ChannelT. It also provides a representation of the type's name via the diff --git a/include/llvm/ExecutionEngine/Orc/RPCUtils.h b/include/llvm/ExecutionEngine/Orc/RPCUtils.h index 4f38fbc5ecd..a2b12dbb5a6 100644 --- a/include/llvm/ExecutionEngine/Orc/RPCUtils.h +++ b/include/llvm/ExecutionEngine/Orc/RPCUtils.h @@ -151,25 +151,17 @@ public: /// Returns the full function prototype as a string. static const char *getPrototype() { - std::lock_guard Lock(NameMutex); - if (Name.empty()) + static std::string Name = [] { + std::string Name; raw_string_ostream(Name) << RPCTypeName::getName() << " " << DerivedFunc::getName() << "(" << llvm::orc::rpc::RPCTypeNameSequence() << ")"; + return Name; + }(); return Name.data(); } - -private: - static std::mutex NameMutex; - static std::string Name; }; -template -std::mutex Function::NameMutex; - -template -std::string Function::Name; - /// Allocates RPC function ids during autonegotiation. /// Specializations of this class must provide four members: ///