[clang] 1b8cde9 - [RISCV][NFC] Move static global variables into static variable in function.
Kito Cheng via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 29 19:30:07 PDT 2022
Author: Kito Cheng
Date: 2022-06-30T10:30:01+08:00
New Revision: 1b8cde9b633841c7199b345132423dd3d6bdf3e7
URL: https://github.com/llvm/llvm-project/commit/1b8cde9b633841c7199b345132423dd3d6bdf3e7
DIFF: https://github.com/llvm/llvm-project/commit/1b8cde9b633841c7199b345132423dd3d6bdf3e7.diff
LOG: [RISCV][NFC] Move static global variables into static variable in function.
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
Added:
Modified:
clang/lib/Support/RISCVVIntrinsicUtils.cpp
Removed:
################################################################################
diff --git a/clang/lib/Support/RISCVVIntrinsicUtils.cpp b/clang/lib/Support/RISCVVIntrinsicUtils.cpp
index 0d7ca0ed0f1fa..d4d3f22c93279 100644
--- a/clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ b/clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -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);
More information about the cfe-commits
mailing list