[Mlir-commits] [mlir] [mlir][nvvm]Add support for grid_constant attribute on LLVM function arguments (PR #78228)

Oleksandr Alex Zinenko llvmlistbot at llvm.org
Thu Jan 18 04:51:01 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;
+  }();
----------------
ftynse wrote:

No, here the lambda is called immediately and will be executed as part of static initialization IIUC. We could have something like

```cpp
Mapping &getMapping() {
  static std::optional<Mapping> mapping;
  if (!mapping) {
    // initializaiton;
  }
  return *mapping;
}
```

that will perform initialization when the getter function is first called.

https://github.com/llvm/llvm-project/pull/78228


More information about the Mlir-commits mailing list