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

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Fri Feb 9 08:20:30 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));
----------------
vzakhari wrote:

Thank you, Valentin!

We could use something like this: https://github.com/llvm/llvm-project/pull/79301/files#diff-aa56bf8cfc0c7b570e4e825e0a9e375a930085bc6837ca4854557d0c4c0ab977R58

I am okay with the way it is now.

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


More information about the flang-commits mailing list