[Hexagon] Replace a static member variable in HexagonCVIResource (NFC)
authorTobias Edler von Koch <tobias@codeaurora.org>
Fri, 8 Jan 2016 22:07:25 +0000 (22:07 +0000)
committerTobias Edler von Koch <tobias@codeaurora.org>
Fri, 8 Jan 2016 22:07:25 +0000 (22:07 +0000)
This creates one instance of TUL per HexagonShuffler, which avoids thread-safety
issues with future changes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257215 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.cpp
lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.h

index 6ceb848ba20c6c91ee4aab249a8c4ef53d874f6c..4e1cce3bd7d16b32e4d22fc7ac116d0fc0a18f3a 100644 (file)
@@ -95,14 +95,7 @@ unsigned HexagonResource::setWeight(unsigned s) {
   return (Weight);
 }
 
-HexagonCVIResource::TypeUnitsAndLanes *HexagonCVIResource::TUL;
-
-bool HexagonCVIResource::SetUp = HexagonCVIResource::setup();
-
-bool HexagonCVIResource::setup() {
-  assert(!TUL);
-  TUL = new (TypeUnitsAndLanes);
-
+void HexagonCVIResource::SetupTUL(TypeUnitsAndLanes *TUL, StringRef CPU) {
   (*TUL)[HexagonII::TypeCVI_VA] =
       UnitsAndLanes(CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1, 1);
   (*TUL)[HexagonII::TypeCVI_VA_DV] = UnitsAndLanes(CVI_XLANE | CVI_MPY0, 2);
@@ -123,13 +116,12 @@ bool HexagonCVIResource::setup() {
   (*TUL)[HexagonII::TypeCVI_VM_NEW_ST] = UnitsAndLanes(CVI_NONE, 0);
   (*TUL)[HexagonII::TypeCVI_VM_STU] = UnitsAndLanes(CVI_XLANE, 1);
   (*TUL)[HexagonII::TypeCVI_HIST] = UnitsAndLanes(CVI_XLANE, 4);
-
-  return true;
 }
 
-HexagonCVIResource::HexagonCVIResource(MCInstrInfo const &MCII, unsigned s,
+HexagonCVIResource::HexagonCVIResource(TypeUnitsAndLanes *TUL,
+                                       MCInstrInfo const &MCII, unsigned s,
                                        MCInst const *id)
-    : HexagonResource(s) {
+    : HexagonResource(s), TUL(TUL) {
   unsigned T = HexagonMCInstrInfo::getType(MCII, *id);
 
   if (TUL->count(T)) {
@@ -153,6 +145,7 @@ HexagonShuffler::HexagonShuffler(MCInstrInfo const &MCII,
                                  MCSubtargetInfo const &STI)
     : MCII(MCII), STI(STI) {
   reset();
+  HexagonCVIResource::SetupTUL(&TUL, STI.getCPU());
 }
 
 void HexagonShuffler::reset() {
@@ -163,7 +156,7 @@ void HexagonShuffler::reset() {
 
 void HexagonShuffler::append(MCInst const *ID, MCInst const *Extender,
                              unsigned S, bool X) {
-  HexagonInstr PI(MCII, ID, Extender, S, X);
+  HexagonInstr PI(&TUL, MCII, ID, Extender, S, X);
 
   Packet.push_back(PI);
 }
index 174f10fb2580bd528e680bbe769468e0a7c1aa29..a093f85451323f228f0fbcc772e90e4efabc87f1 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/MC/MCInstrInfo.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 
 using namespace llvm;
 
@@ -53,9 +54,11 @@ public:
 
 // HVX insn resources.
 class HexagonCVIResource : public HexagonResource {
+public:
   typedef std::pair<unsigned, unsigned> UnitsAndLanes;
   typedef llvm::DenseMap<unsigned, UnitsAndLanes> TypeUnitsAndLanes;
 
+private:
   // Available HVX slots.
   enum {
     CVI_NONE = 0,
@@ -65,9 +68,7 @@ class HexagonCVIResource : public HexagonResource {
     CVI_MPY1 = 1 << 3
   };
 
-  static bool SetUp;
-  static bool setup();
-  static TypeUnitsAndLanes *TUL;
+  TypeUnitsAndLanes *TUL;
 
   // Count of adjacent slots that the insn requires to be executed.
   unsigned Lanes;
@@ -81,7 +82,9 @@ class HexagonCVIResource : public HexagonResource {
   void setStore(bool f = true) { Store = f; };
 
 public:
-  HexagonCVIResource(MCInstrInfo const &MCII, unsigned s, MCInst const *id);
+  HexagonCVIResource(TypeUnitsAndLanes *TUL, MCInstrInfo const &MCII,
+                     unsigned s, MCInst const *id);
+  static void SetupTUL(TypeUnitsAndLanes *TUL, StringRef CPU);
 
   bool isValid() const { return (Valid); };
   unsigned getLanes() const { return (Lanes); };
@@ -100,10 +103,11 @@ class HexagonInstr {
   bool SoloException;
 
 public:
-  HexagonInstr(MCInstrInfo const &MCII, MCInst const *id,
+  HexagonInstr(HexagonCVIResource::TypeUnitsAndLanes *T,
+               MCInstrInfo const &MCII, MCInst const *id,
                MCInst const *Extender, unsigned s, bool x = false)
-      : ID(id), Extender(Extender), Core(s), CVI(MCII, s, id),
-        SoloException(x){};
+      : ID(id), Extender(Extender), Core(s), CVI(T, MCII, s, id),
+        SoloException(x) {};
 
   MCInst const *getDesc() const { return (ID); };
 
@@ -136,6 +140,8 @@ class HexagonShuffler {
   // Shuffling error code.
   unsigned Error;
 
+  HexagonCVIResource::TypeUnitsAndLanes TUL;
+
 protected:
   int64_t BundleFlags;
   MCInstrInfo const &MCII;