Skip to content

Commit a4e8ec9

Browse files
authored
[flang][cuda][NFC] Add getDataAttr helper (#154586)
1 parent 45e2c50 commit a4e8ec9

File tree

2 files changed

+19
-9
lines changed
  • flang
    • include/flang/Optimizer/Dialect/CUF/Attributes
    • lib/Optimizer/Dialect/CUF/Attributes

2 files changed

+19
-9
lines changed

flang/include/flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ getProcAttribute(mlir::MLIRContext *mlirContext,
106106
return {};
107107
}
108108

109+
/// Returns the data attribute if the operation has one.
110+
cuf::DataAttributeAttr getDataAttr(mlir::Operation *op);
111+
109112
/// Returns true if the operation has a data attribute with the given value.
110113
bool hasDataAttr(mlir::Operation *op, cuf::DataAttribute value);
111114

flang/lib/Optimizer/Dialect/CUF/Attributes/CUFAttr.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,26 @@ void CUFDialect::registerAttributes() {
3030
LaunchBoundsAttr, ProcAttributeAttr>();
3131
}
3232

33-
bool hasDataAttr(mlir::Operation *op, cuf::DataAttribute value) {
33+
cuf::DataAttributeAttr getDataAttr(mlir::Operation *op) {
3434
if (!op)
35-
return false;
35+
return {};
36+
37+
if (auto dataAttr =
38+
op->getAttrOfType<cuf::DataAttributeAttr>(cuf::getDataAttrName()))
39+
return dataAttr;
3640

37-
cuf::DataAttributeAttr dataAttr =
38-
op->getAttrOfType<cuf::DataAttributeAttr>(cuf::getDataAttrName());
3941
// When the attribute is declared on the operation, it doesn't have a prefix.
40-
if (!dataAttr)
41-
dataAttr = op->getAttrOfType<cuf::DataAttributeAttr>(cuf::dataAttrName);
42-
if (!dataAttr)
43-
return false;
42+
if (auto dataAttr =
43+
op->getAttrOfType<cuf::DataAttributeAttr>(cuf::dataAttrName))
44+
return dataAttr;
4445

45-
return dataAttr.getValue() == value;
46+
return {};
47+
}
48+
49+
bool hasDataAttr(mlir::Operation *op, cuf::DataAttribute value) {
50+
if (auto dataAttr = getDataAttr(op))
51+
return dataAttr.getValue() == value;
52+
return false;
4653
}
4754

4855
} // namespace cuf

0 commit comments

Comments
 (0)