[llvm] r335064 - [X86] Initialize FMA3Info directly in its constructor instead of relying on std::call_once

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 19 11:06:52 PDT 2018


Author: ctopper
Date: Tue Jun 19 11:06:52 2018
New Revision: 335064

URL: http://llvm.org/viewvc/llvm-project?rev=335064&view=rev
Log:
[X86] Initialize FMA3Info directly in its constructor instead of relying on std::call_once

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.

Differential Revision: https://reviews.llvm.org/D48194

Modified:
    llvm/trunk/lib/Target/X86/X86InstrFMA3Info.cpp
    llvm/trunk/lib/Target/X86/X86InstrFMA3Info.h

Modified: llvm/trunk/lib/Target/X86/X86InstrFMA3Info.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrFMA3Info.cpp?rev=335064&r1=335063&r2=335064&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86InstrFMA3Info.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86InstrFMA3Info.cpp Tue Jun 19 11:06:52 2018
@@ -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;
@@ -233,7 +229,7 @@ static const X86InstrFMA3Group Groups[]
   FMA3_AVX512_VECTOR_GROUP(VFMSUBADD)
 };
 
-void X86InstrFMA3Info::initGroupsOnceImpl() {
+X86InstrFMA3Info::X86InstrFMA3Info() {
   for (const X86InstrFMA3Group &G : Groups) {
     if (G.RegOpcodes[0])
       OpcodeToGroup[G.RegOpcodes[0]] = &G;
@@ -249,8 +245,3 @@ void X86InstrFMA3Info::initGroupsOnceImp
       OpcodeToGroup[G.MemOpcodes[2]] = &G;
   }
 }
-
-void X86InstrFMA3Info::initGroupsOnce() {
-  llvm::call_once(InitGroupsOnceFlag,
-                  []() { getX86InstrFMA3Info()->initGroupsOnceImpl(); });
-}

Modified: llvm/trunk/lib/Target/X86/X86InstrFMA3Info.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrFMA3Info.h?rev=335064&r1=335063&r2=335064&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86InstrFMA3Info.h (original)
+++ llvm/trunk/lib/Target/X86/X86InstrFMA3Info.h Tue Jun 19 11:06:52 2018
@@ -151,31 +151,18 @@ private:
   /// 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();
-
 public:
   /// Returns the reference to an object of this class. It is assumed that
   /// only one object may exist.
   static X86InstrFMA3Info *getX86InstrFMA3Info();
 
   /// Constructor. Just creates an object of the class.
-  X86InstrFMA3Info() = default;
+  X86InstrFMA3Info();
 
   /// Returns a reference to a group of FMA3 opcodes to where the given
   /// \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);
@@ -189,9 +176,6 @@ public:
   static bool isFMA3(unsigned Opcode) {
     return getFMA3Group(Opcode) != nullptr;
   }
-
-  /// Iterator that is used to walk on FMA register opcodes having memory
-  /// form equivalents.
 };
 
 } // end namespace llvm




More information about the llvm-commits mailing list