[Mlir-commits] [mlir] [mlir][nvvm]Add support for grid_constant attribute on LLVM function arguments (PR #78228)
Mehdi Amini
llvmlistbot at llvm.org
Thu Jan 18 08:24:21 PST 2024
================
@@ -59,6 +59,19 @@ getAttrKindToNameMapping() {
return kindNamePairs;
}
+static llvm::DenseMap<llvm::StringRef, llvm::Attribute::AttrKind>
+getAttrNameToKindMapping() {
+ static auto attrNameToKindMapping = []() {
+ static llvm::DenseMap<llvm::StringRef, llvm::Attribute::AttrKind>
+ nameKindMap;
+ for (auto kindNamePair : getAttrKindToNameMapping()) {
+ nameKindMap.insert({kindNamePair.second, kindNamePair.first});
+ }
+ return nameKindMap;
+ }();
----------------
joker-eph wrote:
Actually the static initializer inside the function runs only on the first call to the function.
It is the idiom recommended for lazy-initialization in a thread-safe way: https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use
(I'm using this pattern frequently in MLIR actually :))
Note that the code pattern you suggested would not be thread-safe: I even sometimes have "unused" static value in a function just to run an initializer once (and benefit from the thread-safety).
https://github.com/llvm/llvm-project/pull/78228
More information about the Mlir-commits
mailing list