[flang-commits] [flang] [flang][cuda] Lower attribute for module variables (PR #81226)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Thu Feb 8 21:32:33 PST 2024


================
@@ -271,27 +271,29 @@ mlir::Value fir::FirOpBuilder::createHeapTemporary(
 
 /// Create a global variable in the (read-only) data section. A global variable
 /// must have a unique name to identify and reference it.
-fir::GlobalOp fir::FirOpBuilder::createGlobal(mlir::Location loc,
-                                              mlir::Type type,
-                                              llvm::StringRef name,
-                                              mlir::StringAttr linkage,
-                                              mlir::Attribute value,
-                                              bool isConst, bool isTarget) {
+fir::GlobalOp fir::FirOpBuilder::createGlobal(
+    mlir::Location loc, mlir::Type type, llvm::StringRef name,
+    mlir::StringAttr linkage, mlir::Attribute value, bool isConst,
+    bool isTarget, fir::CUDAAttributeAttr cudaAttr) {
   auto module = getModule();
   auto insertPt = saveInsertionPoint();
   if (auto glob = module.lookupSymbol<fir::GlobalOp>(name))
     return glob;
   setInsertionPoint(module.getBody(), module.getBody()->end());
-  auto glob =
-      create<fir::GlobalOp>(loc, name, isConst, isTarget, type, value, linkage);
+  llvm::SmallVector<mlir::NamedAttribute> attrs;
+  if (cudaAttr)
+    attrs.push_back(mlir::NamedAttribute(
+        mlir::StringAttr::get(module.getContext(), "cuda_attr"), cudaAttr));
----------------
clementval wrote:

I updated it but unfortunately we cannot use the generated getter without an object. So I added a getter in the extra declaration part. This is has been an issue for long time and we should maybe try to fix it in MLIR tablegen at some point. This is the reason we have constexpr getter all over the extra declaration of our FIR operations. 

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


More information about the flang-commits mailing list