diff --git a/flang/include/flang/Lower/ConvertVariable.h b/flang/include/flang/Lower/ConvertVariable.h index cdbf050e4a7b3..b13bb412f0f3e 100644 --- a/flang/include/flang/Lower/ConvertVariable.h +++ b/flang/include/flang/Lower/ConvertVariable.h @@ -139,9 +139,9 @@ translateSymbolAttributes(mlir::MLIRContext *mlirContext, /// Translate the CUDA Fortran attributes of \p sym into the FIR CUDA attribute /// representation. -fir::CUDAAttributeAttr -translateSymbolCUDAAttribute(mlir::MLIRContext *mlirContext, - const Fortran::semantics::Symbol &sym); +fir::CUDADataAttributeAttr +translateSymbolCUDADataAttribute(mlir::MLIRContext *mlirContext, + const Fortran::semantics::Symbol &sym); /// Map a symbol to a given fir::ExtendedValue. This will generate an /// hlfir.declare when lowering to HLFIR and map the hlfir.declare result to the diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h index f50dacd327a7c..39821f1036c63 100644 --- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h +++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h @@ -231,13 +231,13 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener { mlir::StringAttr linkage = {}, mlir::Attribute value = {}, bool isConst = false, bool isTarget = false, - fir::CUDAAttributeAttr cudaAttr = {}); + fir::CUDADataAttributeAttr cudaAttr = {}); fir::GlobalOp createGlobal(mlir::Location loc, mlir::Type type, llvm::StringRef name, bool isConst, bool isTarget, std::function bodyBuilder, mlir::StringAttr linkage = {}, - fir::CUDAAttributeAttr cudaAttr = {}); + fir::CUDADataAttributeAttr cudaAttr = {}); /// Create a global constant (read-only) value. fir::GlobalOp createGlobalConstant(mlir::Location loc, mlir::Type type, diff --git a/flang/include/flang/Optimizer/Builder/HLFIRTools.h b/flang/include/flang/Optimizer/Builder/HLFIRTools.h index fe69ffa27dc35..170e134baef61 100644 --- a/flang/include/flang/Optimizer/Builder/HLFIRTools.h +++ b/flang/include/flang/Optimizer/Builder/HLFIRTools.h @@ -237,7 +237,7 @@ fir::FortranVariableOpInterface genDeclare(mlir::Location loc, fir::FirOpBuilder &builder, const fir::ExtendedValue &exv, llvm::StringRef name, fir::FortranVariableFlagsAttr flags, - fir::CUDAAttributeAttr cudaAttr = {}); + fir::CUDADataAttributeAttr cudaAttr = {}); /// Generate an hlfir.associate to build a variable from an expression value. /// The type of the variable must be provided so that scalar logicals are diff --git a/flang/include/flang/Optimizer/Dialect/FIRAttr.td b/flang/include/flang/Optimizer/Dialect/FIRAttr.td index bc7312453896d..422ad531181ae 100644 --- a/flang/include/flang/Optimizer/Dialect/FIRAttr.td +++ b/flang/include/flang/Optimizer/Dialect/FIRAttr.td @@ -66,8 +66,8 @@ def CUDAshared : I32EnumAttrCase<"Shared", 4, "shared">; def CUDAunified : I32EnumAttrCase<"Unified", 5, "unified">; // Texture is omitted since it is obsolete and rejected by semantic. -def fir_CUDAAttribute : I32EnumAttr< - "CUDAAttribute", +def fir_CUDADataAttribute : I32EnumAttr< + "CUDADataAttribute", "CUDA Fortran variable attributes", [CUDAconstant, CUDAdevice, CUDAmanaged, CUDApinned, CUDAshared, CUDAunified]> { @@ -75,7 +75,8 @@ def fir_CUDAAttribute : I32EnumAttr< let cppNamespace = "::fir"; } -def fir_CUDAAttributeAttr : EnumAttr { +def fir_CUDADataAttributeAttr : + EnumAttr { let assemblyFormat = [{ ```<` $value `>` }]; } diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td index d505fedd6e641..9f198a4c9132e 100644 --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -2738,7 +2738,7 @@ def fir_GlobalOp : fir_Op<"global", [IsolatedFromAbove, Symbol]> { OptionalAttr:$constant, OptionalAttr:$target, OptionalAttr:$linkName, - OptionalAttr:$cuda_attr + OptionalAttr:$cuda_attr ); let regions = (region AtMostRegion<1>:$region); @@ -3029,7 +3029,7 @@ def fir_DeclareOp : fir_Op<"declare", [AttrSizedOperandSegments, Variadic:$typeparams, Builtin_StringAttr:$uniq_name, OptionalAttr:$fortran_attrs, - OptionalAttr:$cuda_attr + OptionalAttr:$cuda_attr ); let results = (outs AnyRefOrBox); diff --git a/flang/include/flang/Optimizer/HLFIR/HLFIROps.td b/flang/include/flang/Optimizer/HLFIR/HLFIROps.td index f22e9a740da34..c82eae154d31a 100644 --- a/flang/include/flang/Optimizer/HLFIR/HLFIROps.td +++ b/flang/include/flang/Optimizer/HLFIR/HLFIROps.td @@ -89,7 +89,7 @@ def hlfir_DeclareOp : hlfir_Op<"declare", [AttrSizedOperandSegments, Variadic:$typeparams, Builtin_StringAttr:$uniq_name, OptionalAttr:$fortran_attrs, - OptionalAttr:$cuda_attr + OptionalAttr:$cuda_attr ); let results = (outs AnyFortranVariable, AnyRefOrBoxLike); @@ -103,7 +103,7 @@ def hlfir_DeclareOp : hlfir_Op<"declare", [AttrSizedOperandSegments, OpBuilder<(ins "mlir::Value":$memref, "llvm::StringRef":$uniq_name, CArg<"mlir::Value", "{}">:$shape, CArg<"mlir::ValueRange", "{}">:$typeparams, CArg<"fir::FortranVariableFlagsAttr", "{}">:$fortran_attrs, - CArg<"fir::CUDAAttributeAttr", "{}">:$cuda_attr)>]; + CArg<"fir::CUDADataAttributeAttr", "{}">:$cuda_attr)>]; let extraClassDeclaration = [{ /// Get the variable original base (same as input). It lacks diff --git a/flang/include/flang/Optimizer/Support/Utils.h b/flang/include/flang/Optimizer/Support/Utils.h index 586701b4c54d1..84c550afc0777 100644 --- a/flang/include/flang/Optimizer/Support/Utils.h +++ b/flang/include/flang/Optimizer/Support/Utils.h @@ -273,32 +273,32 @@ inline void genMinMaxlocReductionLoop( builder.setInsertionPointAfter(ifMaskTrueOp); } -inline fir::CUDAAttributeAttr -getCUDAAttribute(mlir::MLIRContext *mlirContext, - std::optional cudaAttr) { +inline fir::CUDADataAttributeAttr +getCUDADataAttribute(mlir::MLIRContext *mlirContext, + std::optional cudaAttr) { if (cudaAttr) { - fir::CUDAAttribute attr; + fir::CUDADataAttribute attr; switch (*cudaAttr) { case Fortran::common::CUDADataAttr::Constant: - attr = fir::CUDAAttribute::Constant; + attr = fir::CUDADataAttribute::Constant; break; case Fortran::common::CUDADataAttr::Device: - attr = fir::CUDAAttribute::Device; + attr = fir::CUDADataAttribute::Device; break; case Fortran::common::CUDADataAttr::Managed: - attr = fir::CUDAAttribute::Managed; + attr = fir::CUDADataAttribute::Managed; break; case Fortran::common::CUDADataAttr::Pinned: - attr = fir::CUDAAttribute::Pinned; + attr = fir::CUDADataAttribute::Pinned; break; case Fortran::common::CUDADataAttr::Shared: - attr = fir::CUDAAttribute::Shared; + attr = fir::CUDADataAttribute::Shared; break; case Fortran::common::CUDADataAttr::Texture: // Obsolete attribute return {}; } - return fir::CUDAAttributeAttr::get(mlirContext, attr); + return fir::CUDADataAttributeAttr::get(mlirContext, attr); } return {}; } diff --git a/flang/lib/Lower/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp index f67ee880a2ff7..9c32b7100db25 100644 --- a/flang/lib/Lower/CallInterface.cpp +++ b/flang/lib/Lower/CallInterface.cpp @@ -972,7 +972,7 @@ class Fortran::lower::CallInterfaceImpl { if (obj.cudaDataAttr) attrs.emplace_back( mlir::StringAttr::get(&mlirContext, fir::getCUDAAttrName()), - fir::getCUDAAttribute(&mlirContext, obj.cudaDataAttr)); + fir::getCUDADataAttribute(&mlirContext, obj.cudaDataAttr)); // TODO: intents that require special care (e.g finalization) diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp index 2f23757f497ea..b2279a319fe92 100644 --- a/flang/lib/Lower/ConvertVariable.cpp +++ b/flang/lib/Lower/ConvertVariable.cpp @@ -139,7 +139,7 @@ static fir::GlobalOp defineGlobal(Fortran::lower::AbstractConverter &converter, const Fortran::lower::pft::Variable &var, llvm::StringRef globalName, mlir::StringAttr linkage, - fir::CUDAAttributeAttr cudaAttr = {}); + fir::CUDADataAttributeAttr cudaAttr = {}); static mlir::Location genLocation(Fortran::lower::AbstractConverter &converter, const Fortran::semantics::Symbol &sym) { @@ -464,7 +464,7 @@ static fir::GlobalOp defineGlobal(Fortran::lower::AbstractConverter &converter, const Fortran::lower::pft::Variable &var, llvm::StringRef globalName, mlir::StringAttr linkage, - fir::CUDAAttributeAttr cudaAttr) { + fir::CUDADataAttributeAttr cudaAttr) { fir::FirOpBuilder &builder = converter.getFirOpBuilder(); const Fortran::semantics::Symbol &sym = var.getSymbol(); mlir::Location loc = genLocation(converter, sym); @@ -1583,11 +1583,11 @@ fir::FortranVariableFlagsAttr Fortran::lower::translateSymbolAttributes( return fir::FortranVariableFlagsAttr::get(mlirContext, flags); } -fir::CUDAAttributeAttr Fortran::lower::translateSymbolCUDAAttribute( +fir::CUDADataAttributeAttr Fortran::lower::translateSymbolCUDADataAttribute( mlir::MLIRContext *mlirContext, const Fortran::semantics::Symbol &sym) { std::optional cudaAttr = Fortran::semantics::GetCUDADataAttr(&sym); - return fir::getCUDAAttribute(mlirContext, cudaAttr); + return fir::getCUDADataAttribute(mlirContext, cudaAttr); } /// Map a symbol to its FIR address and evaluated specification expressions. @@ -1629,8 +1629,9 @@ static void genDeclareSymbol(Fortran::lower::AbstractConverter &converter, auto name = converter.mangleName(sym); fir::FortranVariableFlagsAttr attributes = Fortran::lower::translateSymbolAttributes(builder.getContext(), sym); - fir::CUDAAttributeAttr cudaAttr = - Fortran::lower::translateSymbolCUDAAttribute(builder.getContext(), sym); + fir::CUDADataAttributeAttr cudaAttr = + Fortran::lower::translateSymbolCUDADataAttribute(builder.getContext(), + sym); if (isCrayPointee) { mlir::Type baseType = @@ -1722,9 +1723,9 @@ void Fortran::lower::genDeclareSymbol( fir::FortranVariableFlagsAttr attributes = Fortran::lower::translateSymbolAttributes( builder.getContext(), sym.GetUltimate(), extraFlags); - fir::CUDAAttributeAttr cudaAttr = - Fortran::lower::translateSymbolCUDAAttribute(builder.getContext(), - sym.GetUltimate()); + fir::CUDADataAttributeAttr cudaAttr = + Fortran::lower::translateSymbolCUDADataAttribute(builder.getContext(), + sym.GetUltimate()); auto name = converter.mangleName(sym); hlfir::EntityWithAttributes declare = hlfir::genDeclare(loc, builder, exv, name, attributes, cudaAttr); @@ -2222,8 +2223,8 @@ void Fortran::lower::defineModuleVariable( // Do nothing. Mapping will be done on user side. } else { std::string globalName = converter.mangleName(sym); - fir::CUDAAttributeAttr cudaAttr = - Fortran::lower::translateSymbolCUDAAttribute( + fir::CUDADataAttributeAttr cudaAttr = + Fortran::lower::translateSymbolCUDADataAttribute( converter.getFirOpBuilder().getContext(), sym); defineGlobal(converter, var, globalName, linkage, cudaAttr); } diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp index 68fe8de550bb0..3cce39f5b8c78 100644 --- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp +++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp @@ -274,7 +274,7 @@ mlir::Value fir::FirOpBuilder::createHeapTemporary( 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) { + bool isTarget, fir::CUDADataAttributeAttr cudaAttr) { auto module = getModule(); auto insertPt = saveInsertionPoint(); if (auto glob = module.lookupSymbol(name)) @@ -296,7 +296,7 @@ fir::GlobalOp fir::FirOpBuilder::createGlobal( fir::GlobalOp fir::FirOpBuilder::createGlobal( mlir::Location loc, mlir::Type type, llvm::StringRef name, bool isConst, bool isTarget, std::function bodyBuilder, - mlir::StringAttr linkage, fir::CUDAAttributeAttr cudaAttr) { + mlir::StringAttr linkage, fir::CUDADataAttributeAttr cudaAttr) { auto module = getModule(); auto insertPt = saveInsertionPoint(); if (auto glob = module.lookupSymbol(name)) diff --git a/flang/lib/Optimizer/Builder/HLFIRTools.cpp b/flang/lib/Optimizer/Builder/HLFIRTools.cpp index 61e53117da44d..4ffa303f27103 100644 --- a/flang/lib/Optimizer/Builder/HLFIRTools.cpp +++ b/flang/lib/Optimizer/Builder/HLFIRTools.cpp @@ -199,7 +199,7 @@ fir::FortranVariableOpInterface hlfir::genDeclare(mlir::Location loc, fir::FirOpBuilder &builder, const fir::ExtendedValue &exv, llvm::StringRef name, fir::FortranVariableFlagsAttr flags, - fir::CUDAAttributeAttr cudaAttr) { + fir::CUDADataAttributeAttr cudaAttr) { mlir::Value base = fir::getBase(exv); assert(fir::conformsWithPassByRef(base.getType()) && diff --git a/flang/lib/Optimizer/Dialect/FIRAttr.cpp b/flang/lib/Optimizer/Dialect/FIRAttr.cpp index 04431b6afdce2..218fa5028e748 100644 --- a/flang/lib/Optimizer/Dialect/FIRAttr.cpp +++ b/flang/lib/Optimizer/Dialect/FIRAttr.cpp @@ -298,5 +298,5 @@ void fir::printFirAttribute(FIROpsDialect *dialect, mlir::Attribute attr, void FIROpsDialect::registerAttributes() { addAttributes(); + UpperBoundAttr, CUDADataAttributeAttr>(); } diff --git a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp index 85644c14748fc..8bc92a991a69c 100644 --- a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp +++ b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp @@ -124,7 +124,7 @@ void hlfir::DeclareOp::build(mlir::OpBuilder &builder, llvm::StringRef uniq_name, mlir::Value shape, mlir::ValueRange typeparams, fir::FortranVariableFlagsAttr fortran_attrs, - fir::CUDAAttributeAttr cuda_attr) { + fir::CUDADataAttributeAttr cuda_attr) { auto nameAttr = builder.getStringAttr(uniq_name); mlir::Type inputType = memref.getType(); bool hasExplicitLbs = hasExplicitLowerBounds(shape); diff --git a/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp index b15fb59062015..cd534bae4ad2a 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp @@ -320,12 +320,12 @@ class DeclareOpConversion : public mlir::OpRewritePattern { mlir::Location loc = declareOp->getLoc(); mlir::Value memref = declareOp.getMemref(); fir::FortranVariableFlagsAttr fortranAttrs; - fir::CUDAAttributeAttr cudaAttr; + fir::CUDADataAttributeAttr cudaAttr; if (auto attrs = declareOp.getFortranAttrs()) fortranAttrs = fir::FortranVariableFlagsAttr::get(rewriter.getContext(), *attrs); if (auto attr = declareOp.getCudaAttr()) - cudaAttr = fir::CUDAAttributeAttr::get(rewriter.getContext(), *attr); + cudaAttr = fir::CUDADataAttributeAttr::get(rewriter.getContext(), *attr); auto firDeclareOp = rewriter.create( loc, memref.getType(), memref, declareOp.getShape(), declareOp.getTypeparams(), declareOp.getUniqName(), fortranAttrs, diff --git a/flang/unittests/Optimizer/FortranVariableTest.cpp b/flang/unittests/Optimizer/FortranVariableTest.cpp index 4b101ce61f93b..790f735a6cf29 100644 --- a/flang/unittests/Optimizer/FortranVariableTest.cpp +++ b/flang/unittests/Optimizer/FortranVariableTest.cpp @@ -50,7 +50,7 @@ TEST_F(FortranVariableTest, SimpleScalar) { auto declare = builder->create(loc, addr.getType(), addr, /*shape=*/mlir::Value{}, /*typeParams=*/std::nullopt, name, /*fortran_attrs=*/fir::FortranVariableFlagsAttr{}, - /*cuda_attr=*/fir::CUDAAttributeAttr{}); + /*cuda_attr=*/fir::CUDADataAttributeAttr{}); fir::FortranVariableOpInterface fortranVariable = declare; EXPECT_FALSE(fortranVariable.isArray()); @@ -76,7 +76,7 @@ TEST_F(FortranVariableTest, CharacterScalar) { auto declare = builder->create(loc, addr.getType(), addr, /*shape=*/mlir::Value{}, typeParams, name, /*fortran_attrs=*/fir::FortranVariableFlagsAttr{}, - /*cuda_attr=*/fir::CUDAAttributeAttr{}); + /*cuda_attr=*/fir::CUDADataAttributeAttr{}); fir::FortranVariableOpInterface fortranVariable = declare; EXPECT_FALSE(fortranVariable.isArray()); @@ -107,7 +107,7 @@ TEST_F(FortranVariableTest, SimpleArray) { auto declare = builder->create(loc, addr.getType(), addr, shape, /*typeParams*/ std::nullopt, name, /*fortran_attrs=*/fir::FortranVariableFlagsAttr{}, - /*cuda_attr=*/fir::CUDAAttributeAttr{}); + /*cuda_attr=*/fir::CUDADataAttributeAttr{}); fir::FortranVariableOpInterface fortranVariable = declare; EXPECT_TRUE(fortranVariable.isArray()); @@ -138,7 +138,7 @@ TEST_F(FortranVariableTest, CharacterArray) { auto declare = builder->create(loc, addr.getType(), addr, shape, typeParams, name, /*fortran_attrs=*/fir::FortranVariableFlagsAttr{}, - /*cuda_attr=*/fir::CUDAAttributeAttr{}); + /*cuda_attr=*/fir::CUDADataAttributeAttr{}); fir::FortranVariableOpInterface fortranVariable = declare; EXPECT_TRUE(fortranVariable.isArray());