From 16815e99bbac1ba34e041ab1cb137db9aca89c78 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sat, 30 Jun 2018 22:38:42 +0000 Subject: [PATCH] [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336055 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86InstrFMA3Info.cpp | 40 +++++++++++++++++++++++++++---------- lib/Target/X86/X86InstrFMA3Info.h | 38 ++++------------------------------- lib/Target/X86/X86InstrInfo.cpp | 6 ++---- 3 files changed, 36 insertions(+), 48 deletions(-) diff --git a/lib/Target/X86/X86InstrFMA3Info.cpp b/lib/Target/X86/X86InstrFMA3Info.cpp index 9d37d06e0c8..d107a9b46c1 100644 --- a/lib/Target/X86/X86InstrFMA3Info.cpp +++ b/lib/Target/X86/X86InstrFMA3Info.cpp @@ -21,11 +21,6 @@ using namespace llvm; -static ManagedStatic 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 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 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; } diff --git a/lib/Target/X86/X86InstrFMA3Info.h b/lib/Target/X86/X86InstrFMA3Info.h index 91e5d2a177b..6709a53072f 100644 --- a/lib/Target/X86/X86InstrFMA3Info.h +++ b/lib/Target/X86/X86InstrFMA3Info.h @@ -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 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 diff --git a/lib/Target/X86/X86InstrInfo.cpp b/lib/Target/X86/X86InstrInfo.cpp index 9cd42a59d2b..10415237dd2 100644 --- a/lib/Target/X86/X86InstrInfo.cpp +++ b/lib/Target/X86/X86InstrInfo.cpp @@ -7243,8 +7243,7 @@ MachineInstr *X86InstrInfo::commuteInstructionImpl(MachineInstr &MI, bool NewMI, 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(MachineInstr &MI, unsigned &SrcOpIdx1, } default: - const X86InstrFMA3Group *FMA3Group = - X86InstrFMA3Info::getFMA3Group(MI.getOpcode()); + const X86InstrFMA3Group *FMA3Group = getFMA3Group(MI.getOpcode()); if (FMA3Group) return findThreeSrcCommutedOpIndices(MI, SrcOpIdx1, SrcOpIdx2, FMA3Group->isIntrinsic()); -- 2.11.0