diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -2700,7 +2700,7 @@ p.printAttributeWithoutType(getAttr(symbolAttrName())); if (auto val = getValueOrNull()) p << '(' << val << ')'; - if (getAttr(constantAttrName())) + if ((*this)->getAttr(constantAttrName())) p << " constant"; p << " : "; p.printType(getType()); diff --git a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h --- a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h +++ b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h @@ -107,7 +107,7 @@ /// Returns the affine map used to access the src memref. AffineMap getSrcMap() { return getSrcMapAttr().getValue(); } AffineMapAttr getSrcMapAttr() { - return getAttr(getSrcMapAttrName()).cast(); + return (*this)->getAttr(getSrcMapAttrName()).cast(); } /// Returns the source memref affine map indices for this DMA operation. @@ -146,7 +146,7 @@ /// Returns the affine map used to access the dst memref. AffineMap getDstMap() { return getDstMapAttr().getValue(); } AffineMapAttr getDstMapAttr() { - return getAttr(getDstMapAttrName()).cast(); + return (*this)->getAttr(getDstMapAttrName()).cast(); } /// Returns the destination memref indices for this DMA operation. @@ -175,7 +175,7 @@ /// Returns the affine map used to access the tag memref. AffineMap getTagMap() { return getTagMapAttr().getValue(); } AffineMapAttr getTagMapAttr() { - return getAttr(getTagMapAttrName()).cast(); + return (*this)->getAttr(getTagMapAttrName()).cast(); } /// Returns the tag memref indices for this DMA operation. @@ -289,7 +289,7 @@ /// Returns the affine map used to access the tag memref. AffineMap getTagMap() { return getTagMapAttr().getValue(); } AffineMapAttr getTagMapAttr() { - return getAttr(getTagMapAttrName()).cast(); + return (*this)->getAttr(getTagMapAttrName()).cast(); } // Returns the tag memref index for this DMA operation. diff --git a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td --- a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td +++ b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td @@ -258,18 +258,18 @@ /// Returns loop step. int64_t getStep() { - return getAttr(getStepAttrName()).cast().getInt(); + return (*this)->getAttr(getStepAttrName()).cast().getInt(); } /// Returns affine map for the lower bound. AffineMap getLowerBoundMap() { return getLowerBoundMapAttr().getValue(); } AffineMapAttr getLowerBoundMapAttr() { - return getAttr(getLowerBoundAttrName()).cast(); + return (*this)->getAttr(getLowerBoundAttrName()).cast(); } /// Returns affine map for the upper bound. The upper bound is exclusive. AffineMap getUpperBoundMap() { return getUpperBoundMapAttr().getValue(); } AffineMapAttr getUpperBoundMapAttr() { - return getAttr(getUpperBoundAttrName()).cast(); + return (*this)->getAttr(getUpperBoundAttrName()).cast(); } /// Set lower bound. The new bound must have the same number of operands as @@ -289,8 +289,8 @@ void setStep(int64_t step) { assert(step > 0 && "step has to be a positive integer constant"); auto *context = getLowerBoundMap().getContext(); - setAttr(Identifier::get(getStepAttrName(), context), - IntegerAttr::get(IndexType::get(context), step)); + (*this)->setAttr(Identifier::get(getStepAttrName(), context), + IntegerAttr::get(IndexType::get(context), step)); } /// Returns number of region arguments for loop-carried values. @@ -471,7 +471,7 @@ /// Returns the affine map used to index the memref for this operation. AffineMapAttr getAffineMapAttr() { - return getAttr(getMapAttrName()).cast(); + return (*this)->getAttr(getMapAttrName()).cast(); } static StringRef getMapAttrName() { return "map"; } @@ -749,7 +749,7 @@ /// Returns the affine map used to index the memref for this operation. AffineMap getAffineMap() { return getAffineMapAttr().getValue(); } AffineMapAttr getAffineMapAttr() { - return getAttr(getMapAttrName()).cast(); + return (*this)->getAttr(getMapAttrName()).cast(); } /// Returns the AffineMapAttr associated with 'memref'. @@ -789,7 +789,7 @@ /// Returns the affine map used to index the memref for this operation. AffineMapAttr getAffineMapAttr() { - return getAttr(getMapAttrName()).cast(); + return (*this)->getAttr(getMapAttrName()).cast(); } /// Returns the AffineMapAttr associated with 'memref'. diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterface.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterface.td --- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterface.td +++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterface.td @@ -748,7 +748,7 @@ /*args=*/(ins), /*methodBody=*/"", /*defaultImplementation=*/[{ - return $_op.getAttr(getSparseAttrName()).template dyn_cast_or_null() != nullptr; + return $_op->getAttr(getSparseAttrName()).template dyn_cast_or_null() != nullptr; }] >, InterfaceMethod< @@ -849,7 +849,7 @@ [{ BlockAndValueMapping map; unsigned numRegions = $_op->getNumRegions(); - Operation *res = create(b, loc, resultTypes, operands, $_op.getAttrs()); + Operation *res = create(b, loc, resultTypes, operands, $_op->getAttrs()); assert(res->getNumRegions() == numRegions && "inconsistent # regions"); for (unsigned ridx = 0; ridx < numRegions; ++ridx) $_op->getRegion(ridx).cloneInto( @@ -908,7 +908,7 @@ private: void setOperandSegmentAt(unsigned idx, unsigned val) { - auto attr = getOperation()->getAttr("operand_segment_sizes") + auto attr = (*this)->getAttr("operand_segment_sizes") .cast(); unsigned i = 0; auto newAttr = attr.mapValues(IntegerType::get(32, getContext()), diff --git a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td --- a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td +++ b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td @@ -1388,7 +1388,7 @@ [{ build($_builder, $_state, value.getType(), value); }]>]; let extraClassDeclaration = [{ - Attribute getValue() { return getAttr("value"); } + Attribute getValue() { return (*this)->getAttr("value"); } /// Returns true if a constant operation can be built with the given value /// and result type. diff --git a/mlir/include/mlir/IR/FunctionSupport.h b/mlir/include/mlir/IR/FunctionSupport.h --- a/mlir/include/mlir/IR/FunctionSupport.h +++ b/mlir/include/mlir/IR/FunctionSupport.h @@ -549,7 +549,7 @@ concreteOp->removeAttr(getArgAttrName(i, nameBuf)); for (int i = newType.getNumResults(), e = oldType.getNumResults(); i < e; i++) concreteOp->removeAttr(getResultAttrName(i, nameBuf)); - concreteOp->setAttr(getTypeAttrName(), TypeAttr::get(newType)); + (*concreteOp)->setAttr(getTypeAttrName(), TypeAttr::get(newType)); } //===----------------------------------------------------------------------===// diff --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h --- a/mlir/include/mlir/IR/Operation.h +++ b/mlir/include/mlir/IR/Operation.h @@ -318,6 +318,7 @@ /// Using a MutableDictionaryAttr is more efficient as it does not require new /// uniquing in the MLIRContext. void setAttrs(MutableDictionaryAttr newAttrs) { attrs = newAttrs; } + void setAttrs(ArrayRef newAttrs) { attrs = newAttrs; } /// Return the specified attribute if present, null otherwise. Attribute getAttr(Identifier name) { return attrs.get(name); } diff --git a/mlir/include/mlir/IR/SymbolInterfaces.td b/mlir/include/mlir/IR/SymbolInterfaces.td --- a/mlir/include/mlir/IR/SymbolInterfaces.td +++ b/mlir/include/mlir/IR/SymbolInterfaces.td @@ -164,7 +164,7 @@ // If this is an optional symbol, bail out early if possible. auto concreteOp = cast($_op); if (concreteOp.isOptionalSymbol()) { - if(!concreteOp.getAttr(::mlir::SymbolTable::getSymbolAttrName())) + if(!concreteOp->getAttr(::mlir::SymbolTable::getSymbolAttrName())) return success(); } if (::mlir::failed(::mlir::detail::verifySymbol($_op))) diff --git a/mlir/lib/Analysis/Utils.cpp b/mlir/lib/Analysis/Utils.cpp --- a/mlir/lib/Analysis/Utils.cpp +++ b/mlir/lib/Analysis/Utils.cpp @@ -829,7 +829,7 @@ for (unsigned i = 0; i < numSliceLoopIVs; ++i) { Value iv = getSliceLoop(i).getInductionVar(); if (sequentialLoops.count(iv) == 0 && - getSliceLoop(i).getAttr(kSliceFusionBarrierAttrName) == nullptr) + getSliceLoop(i)->getAttr(kSliceFusionBarrierAttrName) == nullptr) continue; for (unsigned j = i; j < numSliceLoopIVs; ++j) { sliceState->lbs[j] = AffineMap(); diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp --- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp +++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp @@ -1672,7 +1672,7 @@ newOperands.append(iterOperands.begin(), iterOperands.end()); (*this)->setOperands(newOperands); - setAttr(getLowerBoundAttrName(), AffineMapAttr::get(map)); + (*this)->setAttr(getLowerBoundAttrName(), AffineMapAttr::get(map)); } void AffineForOp::setUpperBound(ValueRange ubOperands, AffineMap map) { @@ -1685,7 +1685,7 @@ newOperands.append(iterOperands.begin(), iterOperands.end()); (*this)->setOperands(newOperands); - setAttr(getUpperBoundAttrName(), AffineMapAttr::get(map)); + (*this)->setAttr(getUpperBoundAttrName(), AffineMapAttr::get(map)); } void AffineForOp::setLowerBoundMap(AffineMap map) { @@ -1694,7 +1694,7 @@ lbMap.getNumSymbols() == map.getNumSymbols()); assert(map.getNumResults() >= 1 && "bound map has at least one result"); (void)lbMap; - setAttr(getLowerBoundAttrName(), AffineMapAttr::get(map)); + (*this)->setAttr(getLowerBoundAttrName(), AffineMapAttr::get(map)); } void AffineForOp::setUpperBoundMap(AffineMap map) { @@ -1703,7 +1703,7 @@ ubMap.getNumSymbols() == map.getNumSymbols()); assert(map.getNumResults() >= 1 && "bound map has at least one result"); (void)ubMap; - setAttr(getUpperBoundAttrName(), AffineMapAttr::get(map)); + (*this)->setAttr(getUpperBoundAttrName(), AffineMapAttr::get(map)); } bool AffineForOp::hasConstantLowerBound() { @@ -2004,7 +2004,7 @@ .getValue(); } void AffineIfOp::setIntegerSet(IntegerSet newSet) { - setAttr(getConditionAttrName(), IntegerSetAttr::get(newSet)); + (*this)->setAttr(getConditionAttrName(), IntegerSetAttr::get(newSet)); } void AffineIfOp::setConditional(IntegerSet set, ValueRange operands) { @@ -2288,7 +2288,7 @@ template static void printAffineMinMaxOp(OpAsmPrinter &p, T op) { - p << op.getOperationName() << ' ' << op.getAttr(T::getMapAttrName()); + p << op.getOperationName() << ' ' << op->getAttr(T::getMapAttrName()); auto operands = op.getOperands(); unsigned numDims = op.map().getNumDims(); p << '(' << operands.take_front(numDims) << ')'; @@ -2337,7 +2337,7 @@ // If the map is the same, report that folding did not happen. if (foldedMap == op.map()) return {}; - op.setAttr("map", AffineMapAttr::get(foldedMap)); + op->setAttr("map", AffineMapAttr::get(foldedMap)); return op.getResult(); } @@ -2549,8 +2549,8 @@ result.addOperands(lbArgs); result.addOperands(ubArgs); // Create a region and a block for the body. - auto bodyRegion = result.addRegion(); - auto body = new Block(); + auto *bodyRegion = result.addRegion(); + auto *body = new Block(); // Add all the block arguments. for (unsigned i = 0; i < numDims; ++i) body->addArgument(IndexType::get(builder.getContext())); diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -1738,8 +1738,8 @@ static void printFenceOp(OpAsmPrinter &p, FenceOp &op) { StringRef syncscopeKeyword = "syncscope"; p << op.getOperationName() << ' '; - if (!op.getAttr(syncscopeKeyword).cast().getValue().empty()) - p << "syncscope(" << op.getAttr(syncscopeKeyword) << ") "; + if (!op->getAttr(syncscopeKeyword).cast().getValue().empty()) + p << "syncscope(" << op->getAttr(syncscopeKeyword) << ") "; p << stringifyAtomicOrdering(op.ordering()); } diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td --- a/mlir/test/lib/Dialect/Test/TestOps.td +++ b/mlir/test/lib/Dialect/Test/TestOps.td @@ -822,7 +822,7 @@ let arguments = (ins AnyAttr:$value); let results = (outs AnyType); let extraClassDeclaration = [{ - Attribute getValue() { return getAttr("value"); } + Attribute getValue() { return (*this)->getAttr("value"); } }]; let hasFolder = 1; diff --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td --- a/mlir/test/mlir-tblgen/op-attribute.td +++ b/mlir/test/mlir-tblgen/op-attribute.td @@ -48,13 +48,13 @@ // --- // DEF: some-attr-kind AOp::aAttrAttr() -// DEF-NEXT: this->getAttr("aAttr").cast() +// DEF-NEXT: (*this)->getAttr("aAttr").cast() // DEF: some-return-type AOp::aAttr() { // DEF-NEXT: auto attr = aAttrAttr() // DEF-NEXT: return attr.some-convert-from-storage(); // DEF: some-attr-kind AOp::bAttrAttr() -// DEF-NEXT: return this->getAttr("bAttr").dyn_cast_or_null() +// DEF-NEXT: return (*this)->getAttr("bAttr").dyn_cast_or_null() // DEF: some-return-type AOp::bAttr() { // DEF-NEXT: auto attr = bAttrAttr(); // DEF-NEXT: if (!attr) @@ -62,7 +62,7 @@ // DEF-NEXT: return attr.some-convert-from-storage(); // DEF: some-attr-kind AOp::cAttrAttr() -// DEF-NEXT: return this->getAttr("cAttr").dyn_cast_or_null() +// DEF-NEXT: return (*this)->getAttr("cAttr").dyn_cast_or_null() // DEF: ::llvm::Optional AOp::cAttr() { // DEF-NEXT: auto attr = cAttrAttr() // DEF-NEXT: return attr ? ::llvm::Optional(attr.some-convert-from-storage()) : (::llvm::None); diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -479,7 +479,7 @@ void OpEmitter::genAttrGetters() { FmtContext fctx; - fctx.withBuilder("::mlir::Builder(this->getContext())"); + fctx.withBuilder("::mlir::Builder((*this)->getContext())"); Dialect opDialect = op.getDialect(); // Emit the derived attribute body. @@ -521,7 +521,7 @@ if (!method) return; auto &body = method->body(); - body << " return this->getAttr(\"" << name << "\")."; + body << " return (*this)->getAttr(\"" << name << "\")."; if (attr.isOptional() || attr.hasDefaultValue()) body << "dyn_cast_or_null<"; else @@ -837,13 +837,13 @@ if (region.isVariadic()) { auto *m = opClass.addMethodAndPrune("::mlir::MutableArrayRef", region.name); - m->body() << formatv( - " return this->getOperation()->getRegions().drop_front({0});", i); + m->body() << formatv(" return (*this)->getRegions().drop_front({0});", + i); continue; } auto *m = opClass.addMethodAndPrune("::mlir::Region &", region.name); - m->body() << formatv(" return this->getOperation()->getRegion({0});", i); + m->body() << formatv(" return (*this)->getRegion({0});", i); } } @@ -859,15 +859,14 @@ auto *m = opClass.addMethodAndPrune("::mlir::SuccessorRange", successor.name); m->body() << formatv( - " return {std::next(this->getOperation()->successor_begin(), {0}), " - "this->getOperation()->successor_end()};", + " return {std::next((*this)->successor_begin(), {0}), " + "(*this)->successor_end()};", i); continue; } auto *m = opClass.addMethodAndPrune("::mlir::Block *", successor.name); - m->body() << formatv(" return this->getOperation()->getSuccessor({0});", - i); + m->body() << formatv(" return (*this)->getSuccessor({0});", i); } } @@ -1826,16 +1825,16 @@ auto *method = opClass.addMethodAndPrune("::mlir::LogicalResult", "verify"); auto &body = method->body(); body << " if (failed(" << op.getAdaptorName() - << "(*this).verify(this->getLoc()))) " + << "(*this).verify((*this)->getLoc()))) " << "return ::mlir::failure();\n"; auto *valueInit = def.getValueInit("verifier"); StringInit *stringInit = dyn_cast(valueInit); bool hasCustomVerify = stringInit && !stringInit->getValue().empty(); - populateSubstitutions(op, "this->getAttr", "this->getODSOperands", + populateSubstitutions(op, "(*this)->getAttr", "this->getODSOperands", "this->getODSResults", verifyCtx); - genAttributeVerifier(op, "this->getAttr", "emitOpError(", + genAttributeVerifier(op, "(*this)->getAttr", "emitOpError(", /*emitVerificationRequiringOp=*/true, verifyCtx, body); genOperandResultVerifier(body, op.getOperands(), "operand"); genOperandResultVerifier(body, op.getResults(), "result"); @@ -1932,8 +1931,8 @@ body << " for (::mlir::Region ®ion : "; body << formatv(region.isVariadic() ? "{0}()" - : "::mlir::MutableArrayRef<::mlir::Region>(this->" - "getOperation()->getRegion({1}))", + : "::mlir::MutableArrayRef<::mlir::Region>((*this)" + "->getRegion({1}))", region.name, i); body << ") {\n"; auto constraint = tgfmt(region.constraint.getConditionTemplate(), diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp --- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp +++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp @@ -1640,7 +1640,7 @@ body << " if (!" << var->name << "().empty()) {\n"; } else { - body << " if (getAttr(\"" + body << " if ((*this)->getAttr(\"" << cast(anchor)->getVar()->name << "\")) {\n"; }