Skip to content

Commit

Permalink
[flang][cuda][NFC] Rename CUDAAttribute to CUDADataAttribute (llvm#81323
Browse files Browse the repository at this point in the history
)

The newly introduced `CUDAAttribute` is meant for CUDA attributes
associated with variable. In order to not clash with the future
attribute for function/subroutine, rename `CUDAAttribute` to
`CUDADataAttribute`.
  • Loading branch information
clementval authored Feb 9, 2024
1 parent c7a0db1 commit 7ff4887
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 46 deletions.
6 changes: 3 additions & 3 deletions flang/include/flang/Lower/ConvertVariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions flang/include/flang/Optimizer/Builder/FIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(FirOpBuilder &)> 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,
Expand Down
2 changes: 1 addition & 1 deletion flang/include/flang/Optimizer/Builder/HLFIRTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions flang/include/flang/Optimizer/Dialect/FIRAttr.td
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,17 @@ 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]> {
let genSpecializedAttr = 0;
let cppNamespace = "::fir";
}

def fir_CUDAAttributeAttr : EnumAttr<fir_Dialect, fir_CUDAAttribute, "cuda"> {
def fir_CUDADataAttributeAttr :
EnumAttr<fir_Dialect, fir_CUDADataAttribute, "cuda"> {
let assemblyFormat = [{ ```<` $value `>` }];
}

Expand Down
4 changes: 2 additions & 2 deletions flang/include/flang/Optimizer/Dialect/FIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -2738,7 +2738,7 @@ def fir_GlobalOp : fir_Op<"global", [IsolatedFromAbove, Symbol]> {
OptionalAttr<UnitAttr>:$constant,
OptionalAttr<UnitAttr>:$target,
OptionalAttr<StrAttr>:$linkName,
OptionalAttr<fir_CUDAAttributeAttr>:$cuda_attr
OptionalAttr<fir_CUDADataAttributeAttr>:$cuda_attr
);

let regions = (region AtMostRegion<1>:$region);
Expand Down Expand Up @@ -3029,7 +3029,7 @@ def fir_DeclareOp : fir_Op<"declare", [AttrSizedOperandSegments,
Variadic<AnyIntegerType>:$typeparams,
Builtin_StringAttr:$uniq_name,
OptionalAttr<fir_FortranVariableFlagsAttr>:$fortran_attrs,
OptionalAttr<fir_CUDAAttributeAttr>:$cuda_attr
OptionalAttr<fir_CUDADataAttributeAttr>:$cuda_attr
);

let results = (outs AnyRefOrBox);
Expand Down
4 changes: 2 additions & 2 deletions flang/include/flang/Optimizer/HLFIR/HLFIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def hlfir_DeclareOp : hlfir_Op<"declare", [AttrSizedOperandSegments,
Variadic<AnyIntegerType>:$typeparams,
Builtin_StringAttr:$uniq_name,
OptionalAttr<fir_FortranVariableFlagsAttr>:$fortran_attrs,
OptionalAttr<fir_CUDAAttributeAttr>:$cuda_attr
OptionalAttr<fir_CUDADataAttributeAttr>:$cuda_attr
);

let results = (outs AnyFortranVariable, AnyRefOrBoxLike);
Expand All @@ -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
Expand Down
20 changes: 10 additions & 10 deletions flang/include/flang/Optimizer/Support/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,32 +273,32 @@ inline void genMinMaxlocReductionLoop(
builder.setInsertionPointAfter(ifMaskTrueOp);
}

inline fir::CUDAAttributeAttr
getCUDAAttribute(mlir::MLIRContext *mlirContext,
std::optional<Fortran::common::CUDADataAttr> cudaAttr) {
inline fir::CUDADataAttributeAttr
getCUDADataAttribute(mlir::MLIRContext *mlirContext,
std::optional<Fortran::common::CUDADataAttr> 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 {};
}
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Lower/CallInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
23 changes: 12 additions & 11 deletions flang/lib/Lower/ConvertVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<Fortran::common::CUDADataAttr> 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.
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions flang/lib/Optimizer/Builder/FIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<fir::GlobalOp>(name))
Expand All @@ -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<void(FirOpBuilder &)> bodyBuilder,
mlir::StringAttr linkage, fir::CUDAAttributeAttr cudaAttr) {
mlir::StringAttr linkage, fir::CUDADataAttributeAttr cudaAttr) {
auto module = getModule();
auto insertPt = saveInsertionPoint();
if (auto glob = module.lookupSymbol<fir::GlobalOp>(name))
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Optimizer/Builder/HLFIRTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) &&
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Optimizer/Dialect/FIRAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,5 +298,5 @@ void fir::printFirAttribute(FIROpsDialect *dialect, mlir::Attribute attr,
void FIROpsDialect::registerAttributes() {
addAttributes<ClosedIntervalAttr, ExactTypeAttr, FortranVariableFlagsAttr,
LowerBoundAttr, PointIntervalAttr, RealAttr, SubclassAttr,
UpperBoundAttr, CUDAAttributeAttr>();
UpperBoundAttr, CUDADataAttributeAttr>();
}
2 changes: 1 addition & 1 deletion flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,12 @@ class DeclareOpConversion : public mlir::OpRewritePattern<hlfir::DeclareOp> {
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<fir::DeclareOp>(
loc, memref.getType(), memref, declareOp.getShape(),
declareOp.getTypeparams(), declareOp.getUniqName(), fortranAttrs,
Expand Down
8 changes: 4 additions & 4 deletions flang/unittests/Optimizer/FortranVariableTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ TEST_F(FortranVariableTest, SimpleScalar) {
auto declare = builder->create<fir::DeclareOp>(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());
Expand All @@ -76,7 +76,7 @@ TEST_F(FortranVariableTest, CharacterScalar) {
auto declare = builder->create<fir::DeclareOp>(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());
Expand Down Expand Up @@ -107,7 +107,7 @@ TEST_F(FortranVariableTest, SimpleArray) {
auto declare = builder->create<fir::DeclareOp>(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());
Expand Down Expand Up @@ -138,7 +138,7 @@ TEST_F(FortranVariableTest, CharacterArray) {
auto declare = builder->create<fir::DeclareOp>(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());
Expand Down

0 comments on commit 7ff4887

Please sign in to comment.