[PATCH] D48194: [X86] Initialize FMA3Info directly in its constructor instead of relying on std::call_once
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 14 13:24:24 PDT 2018
craig.topper created this revision.
craig.topper added reviewers: spatel, RKSimon, echristo.
FMA3Info only exists as a managed static. As far as I know the ManagedStatic construction proccess is thread safe. It doesn't look like we ever access the ManagedStatic object without immediately doing a query on it that would require the map to be populated. So I don't think we're ever deferring the calculation of the tables from the construction of the object.
So I think we should be able to just populate the FMA3Info map directly in the constructor and get rid of all of the initGroupsOnce stuff.
https://reviews.llvm.org/D48194
Files:
lib/Target/X86/X86InstrFMA3Info.cpp
lib/Target/X86/X86InstrFMA3Info.h
Index: lib/Target/X86/X86InstrFMA3Info.h
===================================================================
--- lib/Target/X86/X86InstrFMA3Info.h
+++ lib/Target/X86/X86InstrFMA3Info.h
@@ -171,16 +171,6 @@
/// from the group.
DenseMap<unsigned, const X86InstrFMA3Group *> OpcodeToGroup;
- /// Creates groups of FMA opcodes and initializes Opcode-to-Group map.
- /// This method can be called many times, but the actual initialization is
- /// called only once.
- static void initGroupsOnce();
-
- /// Creates groups of FMA opcodes and initializes Opcode-to-Group map.
- /// This method must be called ONLY from initGroupsOnce(). Otherwise, such
- /// call is not thread safe.
- void initGroupsOnceImpl();
-
/// Creates one group of FMA opcodes having the register opcodes
/// \p RegOpcodes and memory opcodes \p MemOpcodes. The parameter \p Attr
/// specifies the attributes describing the created group.
@@ -203,7 +193,7 @@
static X86InstrFMA3Info *getX86InstrFMA3Info();
/// Constructor. Just creates an object of the class.
- X86InstrFMA3Info() = default;
+ X86InstrFMA3Info();
/// Destructor. Deallocates the memory used for FMA3 Groups.
~X86InstrFMA3Info() {
@@ -222,9 +212,6 @@
/// \p Opcode is included. If the given \p Opcode is not recognized as FMA3
/// and not included into any FMA3 group, then nullptr is returned.
static const X86InstrFMA3Group *getFMA3Group(unsigned Opcode) {
- // Ensure that the groups of opcodes are initialized.
- initGroupsOnce();
-
// Find the group including the given opcode.
const X86InstrFMA3Info *FMA3Info = getX86InstrFMA3Info();
auto I = FMA3Info->OpcodeToGroup.find(Opcode);
@@ -292,7 +279,6 @@
/// Returns rm_iterator pointing to the first entry of OpcodeToGroup map
/// with a register FMA opcode having memory form opcode equivalent.
static rm_iterator rm_begin() {
- initGroupsOnce();
const X86InstrFMA3Info *FMA3Info = getX86InstrFMA3Info();
auto I = FMA3Info->OpcodeToGroup.begin();
auto E = FMA3Info->OpcodeToGroup.end();
@@ -308,7 +294,6 @@
/// Returns the last rm_iterator.
static rm_iterator rm_end() {
- initGroupsOnce();
return rm_iterator(getX86InstrFMA3Info()->OpcodeToGroup.end());
}
};
Index: lib/Target/X86/X86InstrFMA3Info.cpp
===================================================================
--- lib/Target/X86/X86InstrFMA3Info.cpp
+++ lib/Target/X86/X86InstrFMA3Info.cpp
@@ -21,10 +21,6 @@
using namespace llvm;
-/// This flag is used in the method llvm::call_once() used below to make the
-/// initialization of the map 'OpcodeToGroup' thread safe.
-static llvm::once_flag InitGroupsOnceFlag;
-
static ManagedStatic<X86InstrFMA3Info> X86InstrFMA3InfoObj;
X86InstrFMA3Info *X86InstrFMA3Info::getX86InstrFMA3Info() {
return &*X86InstrFMA3InfoObj;
@@ -264,7 +260,7 @@
FMA3_AVX512_VECTOR_GROUP(Name); \
FMA3_AVX512_SCALAR_GROUP(Name);
-void X86InstrFMA3Info::initGroupsOnceImpl() {
+X86InstrFMA3Info::X86InstrFMA3Info() {
FMA3_AVX2_FULL_GROUP(VFMADD);
FMA3_AVX2_FULL_GROUP(VFMSUB);
FMA3_AVX2_FULL_GROUP(VFNMADD);
@@ -281,8 +277,3 @@
FMA3_AVX512_VECTOR_GROUP(VFMADDSUB);
FMA3_AVX512_VECTOR_GROUP(VFMSUBADD);
}
-
-void X86InstrFMA3Info::initGroupsOnce() {
- llvm::call_once(InitGroupsOnceFlag,
- []() { getX86InstrFMA3Info()->initGroupsOnceImpl(); });
-}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48194.151412.patch
Type: text/x-patch
Size: 3435 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180614/0facf22b/attachment.bin>
More information about the llvm-commits
mailing list