File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
include/flang/Optimizer/Dialect/CUF/Attributes
lib/Optimizer/Dialect/CUF/Attributes Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,10 @@ namespace llvm {
2020class StringRef ;
2121}
2222
23+ namespace mlir {
24+ class Operation ;
25+ }
26+
2327#include " flang/Optimizer/Dialect/CUF/Attributes/CUFEnumAttr.h.inc"
2428
2529#define GET_ATTRDEF_CLASSES
@@ -28,6 +32,7 @@ class StringRef;
2832namespace cuf {
2933
3034// / Attribute to mark Fortran entities with the CUDA attribute.
35+ static constexpr llvm::StringRef dataAttrName = " data_attr" ;
3136static constexpr llvm::StringRef getDataAttrName () { return " cuf.data_attr" ; }
3237static constexpr llvm::StringRef getProcAttrName () { return " cuf.proc_attr" ; }
3338
@@ -101,6 +106,9 @@ getProcAttribute(mlir::MLIRContext *mlirContext,
101106 return {};
102107}
103108
109+ // / Returns true if the operation has a data attribute with the given value.
110+ bool hasDataAttr (mlir::Operation *op);
111+
104112} // namespace cuf
105113
106114#endif // FORTRAN_OPTIMIZER_DIALECT_CUF_CUFATTR_H
Original file line number Diff line number Diff line change 1616#include " mlir/IR/BuiltinTypes.h"
1717#include " mlir/IR/DialectImplementation.h"
1818#include " mlir/IR/OpDefinition.h"
19+ #include " mlir/IR/Operation.h"
1920#include " llvm/ADT/TypeSwitch.h"
2021
2122#include " flang/Optimizer/Dialect/CUF/Attributes/CUFEnumAttr.cpp.inc"
@@ -29,4 +30,19 @@ void CUFDialect::registerAttributes() {
2930 LaunchBoundsAttr, ProcAttributeAttr>();
3031}
3132
33+ bool hasDataAttr (mlir::Operation *op, cuf::DataAttribute value) {
34+ if (!op)
35+ return false ;
36+
37+ cuf::DataAttributeAttr dataAttr =
38+ op->getAttrOfType <cuf::DataAttributeAttr>(cuf::getDataAttrName ());
39+ // 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 ;
44+
45+ return dataAttr.getValue () == value;
46+ }
47+
3248} // namespace cuf
You can’t perform that action at this time.
0 commit comments