[llvm] r336055 - [X86] Move the X86InstrFMA3Info class into the cpp file. Expose only a getFMA3Group free function. NFCI

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 30 15:38:43 PDT 2018


Author: ctopper
Date: Sat Jun 30 15:38:42 2018
New Revision: 336055

URL: http://llvm.org/viewvc/llvm-project?rev=336055&view=rev
Log:
[X86] Move the X86InstrFMA3Info class into the cpp file. Expose only a getFMA3Group free function. NFCI

The class only exists to hold a DenseMap and is only created as a ManagedStatic. It used to expose a single static method that outside code was expected to use.

This patch moves that static function out of the class and moves it implementation into the cpp file. It can now access the ManagedStatic directly by name without the need for the other static method that accessed the ManagedStatic.

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

Modified: llvm/trunk/lib/Target/X86/X86InstrFMA3Info.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrFMA3Info.cpp?rev=336055&r1=336054&r2=336055&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86InstrFMA3Info.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86InstrFMA3Info.cpp Sat Jun 30 15:38:42 2018
@@ -21,11 +21,6 @@
 
 using namespace llvm;
 
-static ManagedStatic<X86InstrFMA3Info> X86InstrFMA3InfoObj;
-X86InstrFMA3Info *X86InstrFMA3Info::getX86InstrFMA3Info() {
-  return &*X86InstrFMA3InfoObj;
-}
-
 #define FMA3BASE(X132, X213, X231, Attrs)                                      \
   { { X132, X213, X231 }, Attrs },
 
@@ -230,10 +225,35 @@ static const X86InstrFMA3Group Groups[]
   FMA3_AVX512_VECTOR_GROUP(VFMSUBADD)
 };
 
-X86InstrFMA3Info::X86InstrFMA3Info() {
-  for (const X86InstrFMA3Group &G : Groups) {
-    OpcodeToGroup[G.Opcodes[0]] = &G;
-    OpcodeToGroup[G.Opcodes[1]] = &G;
-    OpcodeToGroup[G.Opcodes[2]] = &G;
+namespace {
+
+struct X86InstrFMA3Info {
+  /// A map that is used to find the group of FMA opcodes using any FMA opcode
+  /// from the group.
+  DenseMap<unsigned, const X86InstrFMA3Group *> OpcodeToGroup;
+
+  /// Constructor. Just creates an object of the class.
+  X86InstrFMA3Info() {
+    for (const X86InstrFMA3Group &G : Groups) {
+      OpcodeToGroup[G.Opcodes[0]] = &G;
+      OpcodeToGroup[G.Opcodes[1]] = &G;
+      OpcodeToGroup[G.Opcodes[2]] = &G;
+    }
   }
+};
+
+}
+
+static ManagedStatic<X86InstrFMA3Info> X86FMA3InfoObj;
+
+/// 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.
+const X86InstrFMA3Group *llvm::getFMA3Group(unsigned Opcode) {
+  auto &Map = X86FMA3InfoObj->OpcodeToGroup;
+  auto I = Map.find(Opcode);
+  if (I != Map.end())
+    return I->second;
+
+  return nullptr;
 }

Modified: llvm/trunk/lib/Target/X86/X86InstrFMA3Info.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrFMA3Info.h?rev=336055&r1=336054&r2=336055&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86InstrFMA3Info.h (original)
+++ llvm/trunk/lib/Target/X86/X86InstrFMA3Info.h Sat Jun 30 15:38:42 2018
@@ -88,40 +88,10 @@ struct X86InstrFMA3Group {
   }
 };
 
-/// This class provides information about all existing FMA3 opcodes
-///
-class X86InstrFMA3Info final {
-private:
-  /// A map that is used to find the group of FMA opcodes using any FMA opcode
-  /// from the group.
-  DenseMap<unsigned, const X86InstrFMA3Group *> OpcodeToGroup;
-
-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();
-
-  /// 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) {
-    // Find the group including the given opcode.
-    const X86InstrFMA3Info *FMA3Info = getX86InstrFMA3Info();
-    auto I = FMA3Info->OpcodeToGroup.find(Opcode);
-    if (I == FMA3Info->OpcodeToGroup.end())
-      return nullptr;
-
-    return I->second;
-  }
-
-  /// Returns true iff the given \p Opcode is recognized as FMA3 by this class.
-  static bool isFMA3(unsigned Opcode) {
-    return getFMA3Group(Opcode) != nullptr;
-  }
-};
+/// 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.
+const X86InstrFMA3Group *getFMA3Group(unsigned Opcode);
 
 } // end namespace llvm
 

Modified: llvm/trunk/lib/Target/X86/X86InstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrInfo.cpp?rev=336055&r1=336054&r2=336055&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86InstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86InstrInfo.cpp Sat Jun 30 15:38:42 2018
@@ -7243,8 +7243,7 @@ MachineInstr *X86InstrInfo::commuteInstr
                                                      OpIdx1, OpIdx2);
     }
 
-    const X86InstrFMA3Group *FMA3Group =
-        X86InstrFMA3Info::getFMA3Group(MI.getOpcode());
+    const X86InstrFMA3Group *FMA3Group = getFMA3Group(MI.getOpcode());
     if (FMA3Group) {
       unsigned Opc =
         getFMA3OpcodeToCommuteOperands(MI, OpIdx1, OpIdx2, *FMA3Group);
@@ -7478,8 +7477,7 @@ bool X86InstrInfo::findCommutedOpIndices
   }
 
   default:
-    const X86InstrFMA3Group *FMA3Group =
-        X86InstrFMA3Info::getFMA3Group(MI.getOpcode());
+    const X86InstrFMA3Group *FMA3Group = getFMA3Group(MI.getOpcode());
     if (FMA3Group)
       return findThreeSrcCommutedOpIndices(MI, SrcOpIdx1, SrcOpIdx2,
                                            FMA3Group->isIntrinsic());




More information about the llvm-commits mailing list