Skip to content

Commit c3529a5

Browse files
committed
[mlir] Mark methods from mlir::OpState that just forward to mlir::Operation as deprecated.
The functions will be removed by January 20th. All call sites within MLIR have been converted in previous changes. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D94191
1 parent f448524 commit c3529a5

File tree

2 files changed

+79
-28
lines changed

2 files changed

+79
-28
lines changed

mlir/include/mlir/IR/OpDefinition.h

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -105,26 +105,32 @@ class OpState {
105105
Operation *getOperation() { return state; }
106106

107107
/// Return the dialect that this refers to.
108-
Dialect *getDialect() { return getOperation()->getDialect(); }
108+
LLVM_ATTRIBUTE_DEPRECATED(
109+
Dialect *getDialect(),
110+
"Use Operation::getDialect() instead (replace '.' with '->').");
109111

110112
/// Return the parent Region of this operation.
111-
Region *getParentRegion() { return getOperation()->getParentRegion(); }
113+
LLVM_ATTRIBUTE_DEPRECATED(
114+
Region *getParentRegion(),
115+
"Use Operation::getParentRegion() instead (replace '.' with '->').");
112116

113117
/// Returns the closest surrounding operation that contains this operation
114118
/// or nullptr if this is a top-level operation.
115-
Operation *getParentOp() { return getOperation()->getParentOp(); }
119+
LLVM_ATTRIBUTE_DEPRECATED(
120+
Operation *getParentOp(),
121+
"Use Operation::getParentOp() instead (replace '.' with '->').");
116122

117123
/// Return the closest surrounding parent operation that is of type 'OpTy'.
118124
template <typename OpTy>
119-
OpTy getParentOfType() {
120-
return getOperation()->getParentOfType<OpTy>();
121-
}
125+
LLVM_ATTRIBUTE_DEPRECATED(
126+
OpTy getParentOfType(),
127+
"Use Operation::getParentOfType() instead (replace '.' with '->').");
122128

123129
/// Returns the closest surrounding parent operation with trait `Trait`.
124130
template <template <typename T> class Trait>
125-
Operation *getParentWithTrait() {
126-
return getOperation()->getParentWithTrait<Trait>();
127-
}
131+
LLVM_ATTRIBUTE_DEPRECATED(
132+
Operation *getParentWithTrait(),
133+
"Use Operation::getParentWithTrait() instead (replace '.' with '->').");
128134

129135
/// Return the context this operation belongs to.
130136
MLIRContext *getContext() { return getOperation()->getContext(); }
@@ -153,35 +159,43 @@ class OpState {
153159
using dialect_attr_range = Operation::dialect_attr_range;
154160

155161
/// Return a range corresponding to the dialect attributes for this operation.
156-
dialect_attr_range getDialectAttrs() { return state->getDialectAttrs(); }
157-
dialect_attr_iterator dialect_attr_begin() {
158-
return state->dialect_attr_begin();
159-
}
160-
dialect_attr_iterator dialect_attr_end() { return state->dialect_attr_end(); }
162+
LLVM_ATTRIBUTE_DEPRECATED(
163+
dialect_attr_range getDialectAttrs(),
164+
"Use Operation::getDialectAttrs() instead (replace '.' with '->').");
165+
LLVM_ATTRIBUTE_DEPRECATED(
166+
dialect_attr_iterator dialect_attr_begin(),
167+
"Use Operation::dialect_attr_begin() instead (replace '.' with '->').");
168+
LLVM_ATTRIBUTE_DEPRECATED(
169+
dialect_attr_iterator dialect_attr_end(),
170+
"Use Operation::dialect_attr_end() instead (replace '.' with '->').");
161171

162172
/// Return an attribute with the specified name.
163-
Attribute getAttr(StringRef name) { return state->getAttr(name); }
173+
LLVM_ATTRIBUTE_DEPRECATED(
174+
Attribute getAttr(StringRef name),
175+
"Use Operation::getAttr() instead (replace '.' with '->').");
164176

165177
/// If the operation has an attribute of the specified type, return it.
166178
template <typename AttrClass>
167-
AttrClass getAttrOfType(StringRef name) {
168-
return getAttr(name).dyn_cast_or_null<AttrClass>();
169-
}
179+
LLVM_ATTRIBUTE_DEPRECATED(
180+
AttrClass getAttrOfType(StringRef name),
181+
"Use Operation::getAttrOfType() instead (replace '.' with '->').");
170182

171183
/// If the an attribute exists with the specified name, change it to the new
172184
/// value. Otherwise, add a new attribute with the specified name/value.
173-
void setAttr(Identifier name, Attribute value) {
174-
state->setAttr(name, value);
175-
}
176-
void setAttr(StringRef name, Attribute value) {
177-
setAttr(Identifier::get(name, getContext()), value);
178-
}
185+
LLVM_ATTRIBUTE_DEPRECATED(
186+
void setAttr(Identifier name, Attribute value),
187+
"Use Operation::setAttr() instead (replace '.' with '->').");
188+
LLVM_ATTRIBUTE_DEPRECATED(
189+
void setAttr(StringRef name, Attribute value),
190+
"Use Operation::setAttr() instead (replace '.' with '->').");
179191

180192
/// Set the attributes held by this operation.
181-
void setAttrs(ArrayRef<NamedAttribute> attributes) {
182-
state->setAttrs(DictionaryAttr::get(attributes, getContext()));
183-
}
184-
void setAttrs(DictionaryAttr newAttrs) { state->setAttrs(newAttrs); }
193+
LLVM_ATTRIBUTE_DEPRECATED(
194+
void setAttrs(ArrayRef<NamedAttribute> attributes),
195+
"Use Operation::setAttrs() instead (replace '.' with '->').");
196+
LLVM_ATTRIBUTE_DEPRECATED(
197+
void setAttrs(DictionaryAttr newAttrs),
198+
"Use Operation::setAttrs() instead (replace '.' with '->').");
185199

186200
/// Set the dialect attributes for this operation, and preserve all dependent.
187201
template <typename DialectAttrs>
@@ -258,6 +272,19 @@ class OpState {
258272
friend AbstractOperation;
259273
};
260274

275+
template <typename OpTy>
276+
OpTy OpState::getParentOfType() {
277+
return getOperation()->getParentOfType<OpTy>();
278+
}
279+
template <template <typename T> class Trait>
280+
Operation *OpState::getParentWithTrait() {
281+
return getOperation()->getParentWithTrait<Trait>();
282+
}
283+
template <typename AttrClass>
284+
AttrClass OpState::getAttrOfType(StringRef name) {
285+
return getAttr(name).dyn_cast_or_null<AttrClass>();
286+
}
287+
261288
// Allow comparing operators.
262289
inline bool operator==(OpState lhs, OpState rhs) {
263290
return lhs.getOperation() == rhs.getOperation();

mlir/lib/IR/Operation.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,30 @@ InFlightDiagnostic OpState::emitRemark(const Twine &message) {
692692
return getOperation()->emitRemark(message);
693693
}
694694

695+
Dialect *OpState::getDialect() { return getOperation()->getDialect(); }
696+
Region *OpState::getParentRegion() { return getOperation()->getParentRegion(); }
697+
Operation *OpState::getParentOp() { return getOperation()->getParentOp(); }
698+
OpState::dialect_attr_range OpState::getDialectAttrs() {
699+
return state->getDialectAttrs();
700+
}
701+
OpState::dialect_attr_iterator OpState::dialect_attr_begin() {
702+
return state->dialect_attr_begin();
703+
}
704+
OpState::dialect_attr_iterator OpState::dialect_attr_end() {
705+
return state->dialect_attr_end();
706+
}
707+
Attribute OpState::getAttr(StringRef name) { return state->getAttr(name); }
708+
void OpState::setAttr(Identifier name, Attribute value) {
709+
state->setAttr(name, value);
710+
}
711+
void OpState::setAttr(StringRef name, Attribute value) {
712+
setAttr(Identifier::get(name, getContext()), value);
713+
}
714+
void OpState::setAttrs(ArrayRef<NamedAttribute> attributes) {
715+
state->setAttrs(DictionaryAttr::get(attributes, getContext()));
716+
}
717+
void OpState::setAttrs(DictionaryAttr newAttrs) { state->setAttrs(newAttrs); }
718+
695719
//===----------------------------------------------------------------------===//
696720
// Op Trait implementations
697721
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)