[X86] Create X86InstrFMA3Group objects fully in a static table instead of on the...
authorCraig Topper <craig.topper@intel.com>
Mon, 18 Jun 2018 06:32:22 +0000 (06:32 +0000)
committerCraig Topper <craig.topper@intel.com>
Mon, 18 Jun 2018 06:32:22 +0000 (06:32 +0000)
Previously we heap allocated the X86InstrFMA3Group objects which were created by passing them small register/memory opcode arrays that existed as individual static tables.

Rather than a bunch of small static arrays we now have one large static table of X86InstrFMA3Group objects. Rather than storing a pointer to the opcode arrays in the X86InstrFMA3Group object, we now store have a register and memory array as part of the object. If a group doesn't have memory or register opcodes, the array entries will be 0.

This greatly simplifies the destruction of the X86InstrFMA3Info object. We no longer need to delete the X86InstrFMA3Group objects as we destruct the DenseMap. And we don't need to keep track of which ones we already deleted.

This reduces the llc binary size on my local machine by ~50k. I can only assume that's really due to the fact that we had something like 512 small static arrays that we passed to the init functions either one at a time or in pairs. So there were between 256 and 512 distinct calls to the init functions in the initOnceImpl method.

llvm-svn: 334925

llvm/lib/Target/X86/X86InstrFMA3Info.cpp
llvm/lib/Target/X86/X86InstrFMA3Info.h

index 00ef65c..376aab7 100644 (file)
@@ -30,256 +30,224 @@ X86InstrFMA3Info *X86InstrFMA3Info::getX86InstrFMA3Info() {
   return &*X86InstrFMA3InfoObj;
 }
 
-void X86InstrFMA3Info::initRMGroup(const uint16_t *RegOpcodes,
-                                   const uint16_t *MemOpcodes, unsigned Attr) {
-  // Create a new instance of this class that would hold a group of FMA opcodes.
-  X86InstrFMA3Group *G = new X86InstrFMA3Group(RegOpcodes, MemOpcodes, Attr);
+#define FMA3BASE(R132, R213, R231, M132, M213, M231, Attrs)                    \
+  { { R132, R213, R231 }, { M132, M213, M231 }, Attrs },
 
-  // Add the references from indvidual opcodes to the group holding them.
-  assert((!OpcodeToGroup[RegOpcodes[0]] && !OpcodeToGroup[RegOpcodes[1]] &&
-          !OpcodeToGroup[RegOpcodes[2]] && !OpcodeToGroup[MemOpcodes[0]] &&
-          !OpcodeToGroup[MemOpcodes[1]] && !OpcodeToGroup[MemOpcodes[2]]) &&
-         "Duplication or rewrite of elements in OpcodeToGroup.");
-  OpcodeToGroup[RegOpcodes[0]] = G;
-  OpcodeToGroup[RegOpcodes[1]] = G;
-  OpcodeToGroup[RegOpcodes[2]] = G;
-  OpcodeToGroup[MemOpcodes[0]] = G;
-  OpcodeToGroup[MemOpcodes[1]] = G;
-  OpcodeToGroup[MemOpcodes[2]] = G;
-}
-
-void X86InstrFMA3Info::initRGroup(const uint16_t *RegOpcodes, unsigned Attr) {
-  // Create a new instance of this class that would hold a group of FMA opcodes.
-  X86InstrFMA3Group *G = new X86InstrFMA3Group(RegOpcodes, nullptr, Attr);
-
-  // Add the references from indvidual opcodes to the group holding them.
-  assert((!OpcodeToGroup[RegOpcodes[0]] && !OpcodeToGroup[RegOpcodes[1]] &&
-          !OpcodeToGroup[RegOpcodes[2]]) &&
-         "Duplication or rewrite of elements in OpcodeToGroup.");
-  OpcodeToGroup[RegOpcodes[0]] = G;
-  OpcodeToGroup[RegOpcodes[1]] = G;
-  OpcodeToGroup[RegOpcodes[2]] = G;
-}
-
-void X86InstrFMA3Info::initMGroup(const uint16_t *MemOpcodes, unsigned Attr) {
-  // Create a new instance of this class that would hold a group of FMA opcodes.
-  X86InstrFMA3Group *G = new X86InstrFMA3Group(nullptr, MemOpcodes, Attr);
-
-  // Add the references from indvidual opcodes to the group holding them.
-  assert((!OpcodeToGroup[MemOpcodes[0]] && !OpcodeToGroup[MemOpcodes[1]] &&
-          !OpcodeToGroup[MemOpcodes[2]]) &&
-         "Duplication or rewrite of elements in OpcodeToGroup.");
-  OpcodeToGroup[MemOpcodes[0]] = G;
-  OpcodeToGroup[MemOpcodes[1]] = G;
-  OpcodeToGroup[MemOpcodes[2]] = G;
-}
+#define FMA3RMA(R132, R213, R231, M132, M213, M231, Attrs)                     \
+  FMA3BASE(X86::R132, X86::R213, X86::R231, X86::M132, X86::M213, X86::M231, Attrs)
 
 #define FMA3RM(R132, R213, R231, M132, M213, M231)                             \
-  static const uint16_t Reg##R132[3] = {X86::R132, X86::R213, X86::R231};      \
-  static const uint16_t Mem##R132[3] = {X86::M132, X86::M213, X86::M231};      \
-  initRMGroup(Reg##R132, Mem##R132);
+  FMA3RMA(R132, R213, R231, M132, M213, M231, 0)
 
-#define FMA3RMA(R132, R213, R231, M132, M213, M231, Attrs)                     \
-  static const uint16_t Reg##R132[3] = {X86::R132, X86::R213, X86::R231};      \
-  static const uint16_t Mem##R132[3] = {X86::M132, X86::M213, X86::M231};      \
-  initRMGroup(Reg##R132, Mem##R132, (Attrs));
+#define FMA3RA(R132, R213, R231, Attrs)                                        \
+  FMA3BASE(X86::R132, X86::R213, X86::R231, 0, 0, 0, Attrs)
 
 #define FMA3R(R132, R213, R231)                                                \
-  static const uint16_t Reg##R132[3] = {X86::R132, X86::R213, X86::R231};      \
-  initRGroup(Reg##R132);
+  FMA3RA(R132, R213, R231, 0)
 
-#define FMA3RA(R132, R213, R231, Attrs)                                        \
-  static const uint16_t Reg##R132[3] = {X86::R132, X86::R213, X86::R231};      \
-  initRGroup(Reg##R132, (Attrs));
+#define FMA3MA(M132, M213, M231, Attrs)                                        \
+  FMA3BASE(0, 0, 0, X86::M132, X86::M213, X86::M231, Attrs)
 
 #define FMA3M(M132, M213, M231)                                                \
-  static const uint16_t Mem##M132[3] = {X86::M132, X86::M213, X86::M231};      \
-  initMGroup(Mem##M132);
-
-#define FMA3MA(M132, M213, M231, Attrs)                                        \
-  static const uint16_t Mem##M132[3] = {X86::M132, X86::M213, X86::M231};      \
-  initMGroup(Mem##M132, (Attrs));
+  FMA3MA(M132, M213, M231, 0)
 
 #define FMA3_AVX2_VECTOR_GROUP(Name)                                           \
   FMA3RM(Name##132PSr, Name##213PSr, Name##231PSr,                             \
-         Name##132PSm, Name##213PSm, Name##231PSm);                            \
+         Name##132PSm, Name##213PSm, Name##231PSm)                             \
   FMA3RM(Name##132PDr, Name##213PDr, Name##231PDr,                             \
-         Name##132PDm, Name##213PDm, Name##231PDm);                            \
+         Name##132PDm, Name##213PDm, Name##231PDm)                             \
   FMA3RM(Name##132PSYr, Name##213PSYr, Name##231PSYr,                          \
-         Name##132PSYm, Name##213PSYm, Name##231PSYm);                         \
+         Name##132PSYm, Name##213PSYm, Name##231PSYm)                          \
   FMA3RM(Name##132PDYr, Name##213PDYr, Name##231PDYr,                          \
-         Name##132PDYm, Name##213PDYm, Name##231PDYm);
+         Name##132PDYm, Name##213PDYm, Name##231PDYm)
 
 #define FMA3_AVX2_SCALAR_GROUP(Name)                                           \
   FMA3RM(Name##132SSr, Name##213SSr, Name##231SSr,                             \
-         Name##132SSm, Name##213SSm, Name##231SSm);                            \
+         Name##132SSm, Name##213SSm, Name##231SSm)                             \
   FMA3RM(Name##132SDr, Name##213SDr, Name##231SDr,                             \
-         Name##132SDm, Name##213SDm, Name##231SDm);                            \
+         Name##132SDm, Name##213SDm, Name##231SDm)                             \
   FMA3RMA(Name##132SSr_Int, Name##213SSr_Int, Name##231SSr_Int,                \
           Name##132SSm_Int, Name##213SSm_Int, Name##231SSm_Int,                \
-          X86InstrFMA3Group::X86FMA3Intrinsic);                                \
+          X86InstrFMA3Group::X86FMA3Intrinsic)                                 \
   FMA3RMA(Name##132SDr_Int, Name##213SDr_Int, Name##231SDr_Int,                \
           Name##132SDm_Int, Name##213SDm_Int, Name##231SDm_Int,                \
-          X86InstrFMA3Group::X86FMA3Intrinsic);
+          X86InstrFMA3Group::X86FMA3Intrinsic)
 
 #define FMA3_AVX2_FULL_GROUP(Name)                                             \
-  FMA3_AVX2_VECTOR_GROUP(Name);                                                \
-  FMA3_AVX2_SCALAR_GROUP(Name);
+  FMA3_AVX2_VECTOR_GROUP(Name)                                                 \
+  FMA3_AVX2_SCALAR_GROUP(Name)
 
 #define FMA3_AVX512_VECTOR_GROUP(Name)                                         \
   FMA3RM(Name##132PSZ128r, Name##213PSZ128r, Name##231PSZ128r,                 \
-         Name##132PSZ128m, Name##213PSZ128m, Name##231PSZ128m);                \
+         Name##132PSZ128m, Name##213PSZ128m, Name##231PSZ128m)                 \
   FMA3RM(Name##132PDZ128r, Name##213PDZ128r, Name##231PDZ128r,                 \
-         Name##132PDZ128m, Name##213PDZ128m, Name##231PDZ128m);                \
+         Name##132PDZ128m, Name##213PDZ128m, Name##231PDZ128m)                 \
   FMA3RM(Name##132PSZ256r, Name##213PSZ256r, Name##231PSZ256r,                 \
-         Name##132PSZ256m, Name##213PSZ256m, Name##231PSZ256m);                \
+         Name##132PSZ256m, Name##213PSZ256m, Name##231PSZ256m)                 \
   FMA3RM(Name##132PDZ256r, Name##213PDZ256r, Name##231PDZ256r,                 \
-         Name##132PDZ256m, Name##213PDZ256m, Name##231PDZ256m);                \
+         Name##132PDZ256m, Name##213PDZ256m, Name##231PDZ256m)                 \
   FMA3RM(Name##132PSZr,    Name##213PSZr,    Name##231PSZr,                    \
-         Name##132PSZm,    Name##213PSZm,    Name##231PSZm);                   \
+         Name##132PSZm,    Name##213PSZm,    Name##231PSZm)                    \
   FMA3RM(Name##132PDZr,    Name##213PDZr,    Name##231PDZr,                    \
-         Name##132PDZm,    Name##213PDZm,    Name##231PDZm);                   \
+         Name##132PDZm,    Name##213PDZm,    Name##231PDZm)                    \
   FMA3RMA(Name##132PSZ128rk, Name##213PSZ128rk, Name##231PSZ128rk,             \
           Name##132PSZ128mk, Name##213PSZ128mk, Name##231PSZ128mk,             \
-          X86InstrFMA3Group::X86FMA3KMergeMasked);                             \
+          X86InstrFMA3Group::X86FMA3KMergeMasked)                              \
   FMA3RMA(Name##132PDZ128rk, Name##213PDZ128rk, Name##231PDZ128rk,             \
           Name##132PDZ128mk, Name##213PDZ128mk, Name##231PDZ128mk,             \
-          X86InstrFMA3Group::X86FMA3KMergeMasked);                             \
+          X86InstrFMA3Group::X86FMA3KMergeMasked)                              \
   FMA3RMA(Name##132PSZ256rk, Name##213PSZ256rk, Name##231PSZ256rk,             \
           Name##132PSZ256mk, Name##213PSZ256mk, Name##231PSZ256mk,             \
-          X86InstrFMA3Group::X86FMA3KMergeMasked);                             \
+          X86InstrFMA3Group::X86FMA3KMergeMasked)                              \
   FMA3RMA(Name##132PDZ256rk, Name##213PDZ256rk, Name##231PDZ256rk,             \
           Name##132PDZ256mk, Name##213PDZ256mk, Name##231PDZ256mk,             \
-          X86InstrFMA3Group::X86FMA3KMergeMasked);                             \
+          X86InstrFMA3Group::X86FMA3KMergeMasked)                              \
   FMA3RMA(Name##132PSZrk,    Name##213PSZrk,    Name##231PSZrk,                \
           Name##132PSZmk,    Name##213PSZmk,    Name##231PSZmk,                \
-          X86InstrFMA3Group::X86FMA3KMergeMasked);                             \
+          X86InstrFMA3Group::X86FMA3KMergeMasked)                              \
   FMA3RMA(Name##132PDZrk,    Name##213PDZrk,    Name##231PDZrk,                \
           Name##132PDZmk,    Name##213PDZmk,    Name##231PDZmk,                \
-          X86InstrFMA3Group::X86FMA3KMergeMasked);                             \
+          X86InstrFMA3Group::X86FMA3KMergeMasked)                              \
   FMA3RMA(Name##132PSZ128rkz, Name##213PSZ128rkz, Name##231PSZ128rkz,          \
           Name##132PSZ128mkz, Name##213PSZ128mkz, Name##231PSZ128mkz,          \
-          X86InstrFMA3Group::X86FMA3KZeroMasked);                              \
+          X86InstrFMA3Group::X86FMA3KZeroMasked)                               \
   FMA3RMA(Name##132PDZ128rkz, Name##213PDZ128rkz, Name##231PDZ128rkz,          \
           Name##132PDZ128mkz, Name##213PDZ128mkz, Name##231PDZ128mkz,          \
-          X86InstrFMA3Group::X86FMA3KZeroMasked);                              \
+          X86InstrFMA3Group::X86FMA3KZeroMasked)                               \
   FMA3RMA(Name##132PSZ256rkz, Name##213PSZ256rkz, Name##231PSZ256rkz,          \
           Name##132PSZ256mkz, Name##213PSZ256mkz, Name##231PSZ256mkz,          \
-          X86InstrFMA3Group::X86FMA3KZeroMasked);                              \
+          X86InstrFMA3Group::X86FMA3KZeroMasked)                               \
   FMA3RMA(Name##132PDZ256rkz, Name##213PDZ256rkz, Name##231PDZ256rkz,          \
           Name##132PDZ256mkz, Name##213PDZ256mkz, Name##231PDZ256mkz,          \
-          X86InstrFMA3Group::X86FMA3KZeroMasked);                              \
+          X86InstrFMA3Group::X86FMA3KZeroMasked)                               \
   FMA3RMA(Name##132PSZrkz,    Name##213PSZrkz,    Name##231PSZrkz,             \
           Name##132PSZmkz,    Name##213PSZmkz,    Name##231PSZmkz,             \
-          X86InstrFMA3Group::X86FMA3KZeroMasked);                              \
+          X86InstrFMA3Group::X86FMA3KZeroMasked)                               \
   FMA3RMA(Name##132PDZrkz,    Name##213PDZrkz,    Name##231PDZrkz,             \
           Name##132PDZmkz,    Name##213PDZmkz,    Name##231PDZmkz,             \
-          X86InstrFMA3Group::X86FMA3KZeroMasked);                              \
-  FMA3R(Name##132PSZrb, Name##213PSZrb, Name##231PSZrb);                       \
-  FMA3R(Name##132PDZrb, Name##213PDZrb, Name##231PDZrb);                       \
+          X86InstrFMA3Group::X86FMA3KZeroMasked)                               \
+  FMA3R(Name##132PSZrb, Name##213PSZrb, Name##231PSZrb)                        \
+  FMA3R(Name##132PDZrb, Name##213PDZrb, Name##231PDZrb)                        \
   FMA3RA(Name##132PSZrbk, Name##213PSZrbk, Name##231PSZrbk,                    \
-         X86InstrFMA3Group::X86FMA3KMergeMasked);                              \
+         X86InstrFMA3Group::X86FMA3KMergeMasked)                               \
   FMA3RA(Name##132PDZrbk, Name##213PDZrbk, Name##231PDZrbk,                    \
-         X86InstrFMA3Group::X86FMA3KMergeMasked);                              \
+         X86InstrFMA3Group::X86FMA3KMergeMasked)                               \
   FMA3RA(Name##132PSZrbkz, Name##213PSZrbkz, Name##231PSZrbkz,                 \
-         X86InstrFMA3Group::X86FMA3KZeroMasked);                               \
+         X86InstrFMA3Group::X86FMA3KZeroMasked)                                \
   FMA3RA(Name##132PDZrbkz, Name##213PDZrbkz, Name##231PDZrbkz,                 \
-         X86InstrFMA3Group::X86FMA3KZeroMasked);                               \
-  FMA3M(Name##132PSZ128mb, Name##213PSZ128mb, Name##231PSZ128mb);              \
-  FMA3M(Name##132PDZ128mb, Name##213PDZ128mb, Name##231PDZ128mb);              \
-  FMA3M(Name##132PSZ256mb, Name##213PSZ256mb, Name##231PSZ256mb);              \
-  FMA3M(Name##132PDZ256mb, Name##213PDZ256mb, Name##231PDZ256mb);              \
-  FMA3M(Name##132PSZmb, Name##213PSZmb, Name##231PSZmb);                       \
-  FMA3M(Name##132PDZmb, Name##213PDZmb, Name##231PDZmb);                       \
+         X86InstrFMA3Group::X86FMA3KZeroMasked)                                \
+  FMA3M(Name##132PSZ128mb, Name##213PSZ128mb, Name##231PSZ128mb)               \
+  FMA3M(Name##132PDZ128mb, Name##213PDZ128mb, Name##231PDZ128mb)               \
+  FMA3M(Name##132PSZ256mb, Name##213PSZ256mb, Name##231PSZ256mb)               \
+  FMA3M(Name##132PDZ256mb, Name##213PDZ256mb, Name##231PDZ256mb)               \
+  FMA3M(Name##132PSZmb, Name##213PSZmb, Name##231PSZmb)                        \
+  FMA3M(Name##132PDZmb, Name##213PDZmb, Name##231PDZmb)                        \
   FMA3MA(Name##132PSZ128mbk, Name##213PSZ128mbk, Name##231PSZ128mbk,           \
-         X86InstrFMA3Group::X86FMA3KMergeMasked);                              \
+         X86InstrFMA3Group::X86FMA3KMergeMasked)                               \
   FMA3MA(Name##132PDZ128mbk, Name##213PDZ128mbk, Name##231PDZ128mbk,           \
-         X86InstrFMA3Group::X86FMA3KMergeMasked);                              \
+         X86InstrFMA3Group::X86FMA3KMergeMasked)                               \
   FMA3MA(Name##132PSZ256mbk, Name##213PSZ256mbk, Name##231PSZ256mbk,           \
-         X86InstrFMA3Group::X86FMA3KMergeMasked);                              \
+         X86InstrFMA3Group::X86FMA3KMergeMasked)                               \
   FMA3MA(Name##132PDZ256mbk, Name##213PDZ256mbk, Name##231PDZ256mbk,           \
-         X86InstrFMA3Group::X86FMA3KMergeMasked);                              \
+         X86InstrFMA3Group::X86FMA3KMergeMasked)                               \
   FMA3MA(Name##132PSZmbk,    Name##213PSZmbk,    Name##231PSZmbk,              \
-         X86InstrFMA3Group::X86FMA3KMergeMasked);                              \
+         X86InstrFMA3Group::X86FMA3KMergeMasked)                               \
   FMA3MA(Name##132PDZmbk,    Name##213PDZmbk,    Name##231PDZmbk,              \
-         X86InstrFMA3Group::X86FMA3KMergeMasked);                              \
+         X86InstrFMA3Group::X86FMA3KMergeMasked)                               \
   FMA3MA(Name##132PSZ128mbkz, Name##213PSZ128mbkz, Name##231PSZ128mbkz,        \
-         X86InstrFMA3Group::X86FMA3KZeroMasked);                               \
+         X86InstrFMA3Group::X86FMA3KZeroMasked)                                \
   FMA3MA(Name##132PDZ128mbkz, Name##213PDZ128mbkz, Name##231PDZ128mbkz,        \
-         X86InstrFMA3Group::X86FMA3KZeroMasked);                               \
+         X86InstrFMA3Group::X86FMA3KZeroMasked)                                \
   FMA3MA(Name##132PSZ256mbkz, Name##213PSZ256mbkz, Name##231PSZ256mbkz,        \
-         X86InstrFMA3Group::X86FMA3KZeroMasked);                               \
+         X86InstrFMA3Group::X86FMA3KZeroMasked)                                \
   FMA3MA(Name##132PDZ256mbkz, Name##213PDZ256mbkz, Name##231PDZ256mbkz,        \
-         X86InstrFMA3Group::X86FMA3KZeroMasked);                               \
+         X86InstrFMA3Group::X86FMA3KZeroMasked)                                \
   FMA3MA(Name##132PSZmbkz, Name##213PSZmbkz, Name##231PSZmbkz,                 \
-         X86InstrFMA3Group::X86FMA3KZeroMasked);                               \
+         X86InstrFMA3Group::X86FMA3KZeroMasked)                                \
   FMA3MA(Name##132PDZmbkz, Name##213PDZmbkz, Name##231PDZmbkz,                 \
-         X86InstrFMA3Group::X86FMA3KZeroMasked);
+         X86InstrFMA3Group::X86FMA3KZeroMasked)
 
 #define FMA3_AVX512_SCALAR_GROUP(Name)                                         \
   FMA3RM(Name##132SSZr,      Name##213SSZr,     Name##231SSZr,                 \
-         Name##132SSZm,      Name##213SSZm,     Name##231SSZm);                \
+         Name##132SSZm,      Name##213SSZm,     Name##231SSZm)                 \
   FMA3RM(Name##132SDZr,      Name##213SDZr,     Name##231SDZr,                 \
-         Name##132SDZm,      Name##213SDZm,     Name##231SDZm);                \
+         Name##132SDZm,      Name##213SDZm,     Name##231SDZm)                 \
   FMA3RMA(Name##132SSZr_Int, Name##213SSZr_Int, Name##231SSZr_Int,             \
           Name##132SSZm_Int, Name##213SSZm_Int, Name##231SSZm_Int,             \
-          X86InstrFMA3Group::X86FMA3Intrinsic);                                \
+          X86InstrFMA3Group::X86FMA3Intrinsic)                                 \
   FMA3RMA(Name##132SDZr_Int, Name##213SDZr_Int, Name##231SDZr_Int,             \
           Name##132SDZm_Int, Name##213SDZm_Int, Name##231SDZm_Int,             \
-          X86InstrFMA3Group::X86FMA3Intrinsic);                                \
+          X86InstrFMA3Group::X86FMA3Intrinsic)                                 \
   FMA3RMA(Name##132SSZr_Intk, Name##213SSZr_Intk, Name##231SSZr_Intk,          \
           Name##132SSZm_Intk, Name##213SSZm_Intk, Name##231SSZm_Intk,          \
           X86InstrFMA3Group::X86FMA3Intrinsic |                                \
-              X86InstrFMA3Group::X86FMA3KMergeMasked);                         \
+              X86InstrFMA3Group::X86FMA3KMergeMasked)                          \
   FMA3RMA(Name##132SDZr_Intk, Name##213SDZr_Intk, Name##231SDZr_Intk,          \
           Name##132SDZm_Intk, Name##213SDZm_Intk, Name##231SDZm_Intk,          \
           X86InstrFMA3Group::X86FMA3Intrinsic |                                \
-              X86InstrFMA3Group::X86FMA3KMergeMasked);                         \
+              X86InstrFMA3Group::X86FMA3KMergeMasked)                          \
   FMA3RMA(Name##132SSZr_Intkz, Name##213SSZr_Intkz, Name##231SSZr_Intkz,       \
           Name##132SSZm_Intkz, Name##213SSZm_Intkz, Name##231SSZm_Intkz,       \
           X86InstrFMA3Group::X86FMA3Intrinsic |                                \
-              X86InstrFMA3Group::X86FMA3KZeroMasked);                          \
+              X86InstrFMA3Group::X86FMA3KZeroMasked)                           \
   FMA3RMA(Name##132SDZr_Intkz, Name##213SDZr_Intkz, Name##231SDZr_Intkz,       \
           Name##132SDZm_Intkz, Name##213SDZm_Intkz, Name##231SDZm_Intkz,       \
           X86InstrFMA3Group::X86FMA3Intrinsic |                                \
-              X86InstrFMA3Group::X86FMA3KZeroMasked);                          \
+              X86InstrFMA3Group::X86FMA3KZeroMasked)                           \
   FMA3RA(Name##132SSZrb_Int, Name##213SSZrb_Int, Name##231SSZrb_Int,           \
-         X86InstrFMA3Group::X86FMA3Intrinsic);                                 \
+         X86InstrFMA3Group::X86FMA3Intrinsic)                                  \
   FMA3RA(Name##132SDZrb_Int, Name##213SDZrb_Int, Name##231SDZrb_Int,           \
-         X86InstrFMA3Group::X86FMA3Intrinsic);                                 \
+         X86InstrFMA3Group::X86FMA3Intrinsic)                                  \
   FMA3RA(Name##132SSZrb_Intk, Name##213SSZrb_Intk, Name##231SSZrb_Intk,        \
          X86InstrFMA3Group::X86FMA3Intrinsic |                                 \
-             X86InstrFMA3Group::X86FMA3KMergeMasked);                          \
+             X86InstrFMA3Group::X86FMA3KMergeMasked)                           \
   FMA3RA(Name##132SDZrb_Intk, Name##213SDZrb_Intk, Name##231SDZrb_Intk,        \
          X86InstrFMA3Group::X86FMA3Intrinsic |                                 \
-             X86InstrFMA3Group::X86FMA3KMergeMasked);                          \
+             X86InstrFMA3Group::X86FMA3KMergeMasked)                           \
   FMA3RA(Name##132SSZrb_Intkz, Name##213SSZrb_Intkz, Name##231SSZrb_Intkz,     \
          X86InstrFMA3Group::X86FMA3Intrinsic |                                 \
-             X86InstrFMA3Group::X86FMA3KZeroMasked);                           \
+             X86InstrFMA3Group::X86FMA3KZeroMasked)                            \
   FMA3RA(Name##132SDZrb_Intkz, Name##213SDZrb_Intkz, Name##231SDZrb_Intkz,     \
          X86InstrFMA3Group::X86FMA3Intrinsic |                                 \
-             X86InstrFMA3Group::X86FMA3KZeroMasked);
+             X86InstrFMA3Group::X86FMA3KZeroMasked)
 
 #define FMA3_AVX512_FULL_GROUP(Name)                                           \
-  FMA3_AVX512_VECTOR_GROUP(Name);                                              \
-  FMA3_AVX512_SCALAR_GROUP(Name);
+  FMA3_AVX512_VECTOR_GROUP(Name)                                               \
+  FMA3_AVX512_SCALAR_GROUP(Name)
 
-void X86InstrFMA3Info::initGroupsOnceImpl() {
-  FMA3_AVX2_FULL_GROUP(VFMADD);
-  FMA3_AVX2_FULL_GROUP(VFMSUB);
-  FMA3_AVX2_FULL_GROUP(VFNMADD);
-  FMA3_AVX2_FULL_GROUP(VFNMSUB);
+static const X86InstrFMA3Group Groups[] = {
+  FMA3_AVX2_FULL_GROUP(VFMADD)
+  FMA3_AVX2_FULL_GROUP(VFMSUB)
+  FMA3_AVX2_FULL_GROUP(VFNMADD)
+  FMA3_AVX2_FULL_GROUP(VFNMSUB)
 
-  FMA3_AVX2_VECTOR_GROUP(VFMADDSUB);
-  FMA3_AVX2_VECTOR_GROUP(VFMSUBADD);
+  FMA3_AVX2_VECTOR_GROUP(VFMADDSUB)
+  FMA3_AVX2_VECTOR_GROUP(VFMSUBADD)
 
-  FMA3_AVX512_FULL_GROUP(VFMADD);
-  FMA3_AVX512_FULL_GROUP(VFMSUB);
-  FMA3_AVX512_FULL_GROUP(VFNMADD);
-  FMA3_AVX512_FULL_GROUP(VFNMSUB);
+  FMA3_AVX512_FULL_GROUP(VFMADD)
+  FMA3_AVX512_FULL_GROUP(VFMSUB)
+  FMA3_AVX512_FULL_GROUP(VFNMADD)
+  FMA3_AVX512_FULL_GROUP(VFNMSUB)
 
-  FMA3_AVX512_VECTOR_GROUP(VFMADDSUB);
-  FMA3_AVX512_VECTOR_GROUP(VFMSUBADD);
+  FMA3_AVX512_VECTOR_GROUP(VFMADDSUB)
+  FMA3_AVX512_VECTOR_GROUP(VFMSUBADD)
+};
+
+void X86InstrFMA3Info::initGroupsOnceImpl() {
+  for (const X86InstrFMA3Group &G : Groups) {
+    if (G.RegOpcodes[0])
+      OpcodeToGroup[G.RegOpcodes[0]] = &G;
+    if (G.RegOpcodes[1])
+      OpcodeToGroup[G.RegOpcodes[1]] = &G;
+    if (G.RegOpcodes[2])
+      OpcodeToGroup[G.RegOpcodes[2]] = &G;
+    if (G.MemOpcodes[0])
+      OpcodeToGroup[G.MemOpcodes[0]] = &G;
+    if (G.MemOpcodes[1])
+      OpcodeToGroup[G.MemOpcodes[1]] = &G;
+    if (G.MemOpcodes[2])
+      OpcodeToGroup[G.MemOpcodes[2]] = &G;
+  }
 }
 
 void X86InstrFMA3Info::initGroupsOnce() {
index 8846632..3f8be85 100644 (file)
@@ -27,61 +27,45 @@ namespace llvm {
 /// Each of the groups has either 3 register opcodes, 3 memory opcodes,
 /// or 6 register and memory opcodes. Also, each group has an attrubutes field
 /// describing it.
-class X86InstrFMA3Group {
-private:
-  /// Reference to an array holding 3 forms of register FMA opcodes.
-  /// It may be set to nullptr if the group of FMA opcodes does not have
-  /// any register form opcodes.
-  const uint16_t *RegOpcodes;
+struct X86InstrFMA3Group {
+  /// An array holding 3 forms of register FMA opcodes.
+  /// Entries will be 0 if there are no register opcodes in the group.
+  uint16_t RegOpcodes[3];
 
-  /// Reference to an array holding 3 forms of memory FMA opcodes.
-  /// It may be set to nullptr if the group of FMA opcodes does not have
-  /// any register form opcodes.
-  const uint16_t *MemOpcodes;
+  /// An array holding 3 forms of memory FMA opcodes.
+  /// Entries will be 0 if there are no register opcodes in the group.
+  uint16_t MemOpcodes[3];
 
   /// This bitfield specifies the attributes associated with the created
   /// FMA groups of opcodes.
-  unsigned Attributes;
-
-  static const unsigned Form132 = 0;
-  static const unsigned Form213 = 1;
-  static const unsigned Form231 = 2;
-
-public:
-  /// This bit must be set in the 'Attributes' field of FMA group if such
-  /// group of FMA opcodes consists of FMA intrinsic opcodes.
-  static const unsigned X86FMA3Intrinsic = 0x1;
-
-  /// This bit must be set in the 'Attributes' field of FMA group if such
-  /// group of FMA opcodes consists of AVX512 opcodes accepting a k-mask and
-  /// passing the elements from the 1st operand to the result of the operation
-  /// when the correpondings bits in the k-mask are unset.
-  static const unsigned X86FMA3KMergeMasked = 0x2;
-
-  /// This bit must be set in the 'Attributes' field of FMA group if such
-  /// group of FMA opcodes consists of AVX512 opcodes accepting a k-zeromask.
-  static const unsigned X86FMA3KZeroMasked = 0x4;
-
-  /// Constructor. Creates a new group of FMA opcodes with three register form
-  /// FMA opcodes \p RegOpcodes and three memory form FMA opcodes \p MemOpcodes.
-  /// The parameters \p RegOpcodes and \p MemOpcodes may be set to nullptr,
-  /// which means that the created group of FMA opcodes does not have the
-  /// corresponding (register or memory) opcodes.
-  /// The parameter \p Attr specifies the attributes describing the created
-  /// group.
-  X86InstrFMA3Group(const uint16_t *RegOpcodes, const uint16_t *MemOpcodes,
-                    unsigned Attr)
-      : RegOpcodes(RegOpcodes), MemOpcodes(MemOpcodes), Attributes(Attr) {
-    assert((RegOpcodes || MemOpcodes) &&
-           "Cannot create a group not having any opcodes.");
-  }
+  uint16_t Attributes;
+
+  enum {
+    Form132,
+    Form213,
+    Form231,
+  };
+
+  enum : uint16_t {
+    /// This bit must be set in the 'Attributes' field of FMA group if such
+    /// group of FMA opcodes consists of FMA intrinsic opcodes.
+    X86FMA3Intrinsic = 0x1,
+
+    /// This bit must be set in the 'Attributes' field of FMA group if such
+    /// group of FMA opcodes consists of AVX512 opcodes accepting a k-mask and
+    /// passing the elements from the 1st operand to the result of the operation
+    /// when the correpondings bits in the k-mask are unset.
+    X86FMA3KMergeMasked = 0x2,
+
+    /// This bit must be set in the 'Attributes' field of FMA group if such
+    /// group of FMA opcodes consists of AVX512 opcodes accepting a k-zeromask.
+    X86FMA3KZeroMasked = 0x4,
+  };
 
   /// Returns a memory form opcode that is the equivalent of the given register
   /// form opcode \p RegOpcode. 0 is returned if the group does not have
   /// either register of memory opcodes.
   unsigned getMemOpcode(unsigned RegOpcode) const {
-    if (!RegOpcodes || !MemOpcodes)
-      return 0;
     for (unsigned Form = 0; Form < 3; Form++)
       if (RegOpcodes[Form] == RegOpcode)
         return MemOpcodes[Form];
@@ -90,37 +74,37 @@ public:
 
   /// Returns the 132 form of FMA register opcode.
   unsigned getReg132Opcode() const {
-    assert(RegOpcodes && "The group does not have register opcodes.");
+    assert(RegOpcodes[Form132] && "The group does not have register opcodes.");
     return RegOpcodes[Form132];
   }
 
   /// Returns the 213 form of FMA register opcode.
   unsigned getReg213Opcode() const {
-    assert(RegOpcodes && "The group does not have register opcodes.");
+    assert(RegOpcodes[Form213] && "The group does not have register opcodes.");
     return RegOpcodes[Form213];
   }
 
   /// Returns the 231 form of FMA register opcode.
   unsigned getReg231Opcode() const {
-    assert(RegOpcodes && "The group does not have register opcodes.");
+    assert(RegOpcodes[Form231] && "The group does not have register opcodes.");
     return RegOpcodes[Form231];
   }
 
   /// Returns the 132 form of FMA memory opcode.
   unsigned getMem132Opcode() const {
-    assert(MemOpcodes && "The group does not have memory opcodes.");
+    assert(MemOpcodes[Form132] && "The group does not have memory opcodes.");
     return MemOpcodes[Form132];
   }
 
   /// Returns the 213 form of FMA memory opcode.
   unsigned getMem213Opcode() const {
-    assert(MemOpcodes && "The group does not have memory opcodes.");
+    assert(MemOpcodes[Form213] && "The group does not have memory opcodes.");
     return MemOpcodes[Form213];
   }
 
   /// Returns the 231 form of FMA memory opcode.
   unsigned getMem231Opcode() const {
-    assert(MemOpcodes && "The group does not have memory opcodes.");
+    assert(MemOpcodes[Form231] && "The group does not have memory opcodes.");
     return MemOpcodes[Form231];
   }
 
@@ -143,8 +127,6 @@ public:
   /// Returns true iff the given \p Opcode is a register opcode from the
   /// groups of FMA opcodes.
   bool isRegOpcodeFromGroup(unsigned Opcode) const {
-    if (!RegOpcodes)
-      return false;
     for (unsigned Form = 0; Form < 3; Form++)
       if (Opcode == RegOpcodes[Form])
         return true;
@@ -154,8 +136,6 @@ public:
   /// Returns true iff the given \p Opcode is a memory opcode from the
   /// groups of FMA opcodes.
   bool isMemOpcodeFromGroup(unsigned Opcode) const {
-    if (!MemOpcodes)
-      return false;
     for (unsigned Form = 0; Form < 3; Form++)
       if (Opcode == MemOpcodes[Form])
         return true;
@@ -165,7 +145,7 @@ public:
 
 /// This class provides information about all existing FMA3 opcodes
 ///
-class X86InstrFMA3Info {
+class X86InstrFMA3Info final {
 private:
   /// A map that is used to find the group of FMA opcodes using any FMA opcode
   /// from the group.
@@ -181,22 +161,6 @@ private:
   /// 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.
-  void initRMGroup(const uint16_t *RegOpcodes,
-                   const uint16_t *MemOpcodes, unsigned Attr = 0);
-
-  /// Creates one group of FMA opcodes having only the register opcodes
-  /// \p RegOpcodes. The parameter \p Attr specifies the attributes describing
-  /// the created group.
-  void initRGroup(const uint16_t *RegOpcodes, unsigned Attr = 0);
-
-  /// Creates one group of FMA opcodes having only the memory opcodes
-  /// \p MemOpcodes. The parameter \p Attr specifies the attributes describing
-  /// the created group.
-  void initMGroup(const uint16_t *MemOpcodes, unsigned Attr = 0);
-
 public:
   /// Returns the reference to an object of this class. It is assumed that
   /// only one object may exist.
@@ -205,19 +169,6 @@ public:
   /// Constructor. Just creates an object of the class.
   X86InstrFMA3Info() = default;
 
-  /// Destructor. Deallocates the memory used for FMA3 Groups.
-  ~X86InstrFMA3Info() {
-    std::set<const X86InstrFMA3Group *> DeletedGroups;
-    auto E = OpcodeToGroup.end();
-    for (auto I = OpcodeToGroup.begin(); I != E; I++) {
-      const X86InstrFMA3Group *G = I->second;
-      if (DeletedGroups.find(G) == DeletedGroups.end()) {
-        DeletedGroups.insert(G);
-        delete G;
-      }
-    }
-  }
-
   /// 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.