[RISCV][NFC] Move static global variables into static variable in function.
authorKito Cheng <kito.cheng@sifive.com>
Thu, 30 Jun 2022 02:28:21 +0000 (10:28 +0800)
committerKito Cheng <kito.cheng@sifive.com>
Thu, 30 Jun 2022 02:30:01 +0000 (10:30 +0800)
It's violate coding guideline in LLVM coding standard[1], because the  the initialization order is nondeterministic and that might increase the launch time of programs.

However these variables are only used to cache query result, so we can move these variables into the function,, that which resolve both issue: 1. initialized in deterministic order, 2. Initialized that when the first time used.

[1] https://llvm.org/docs/CodingStandards.html#do-not-use-static-constructors

Reviewed By: MaskRay

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

clang/lib/Support/RISCVVIntrinsicUtils.cpp

index 0d7ca0e..d4d3f22 100644 (file)
@@ -31,10 +31,6 @@ const PrototypeDescriptor PrototypeDescriptor::VL =
 const PrototypeDescriptor PrototypeDescriptor::Vector =
     PrototypeDescriptor(BaseTypeModifier::Vector);
 
-// Concat BasicType, LMUL and Proto as key
-static std::unordered_map<uint64_t, RVVType> LegalTypes;
-static std::set<uint64_t> IllegalTypes;
-
 //===----------------------------------------------------------------------===//
 // Type implementation
 //===----------------------------------------------------------------------===//
@@ -822,6 +818,9 @@ static uint64_t computeRVVTypeHashValue(BasicType BT, int Log2LMUL,
 
 Optional<RVVTypePtr> RVVType::computeType(BasicType BT, int Log2LMUL,
                                           PrototypeDescriptor Proto) {
+  // Concat BasicType, LMUL and Proto as key
+  static std::unordered_map<uint64_t, RVVType> LegalTypes;
+  static std::set<uint64_t> IllegalTypes;
   uint64_t Idx = computeRVVTypeHashValue(BT, Log2LMUL, Proto);
   // Search first
   auto It = LegalTypes.find(Idx);