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/Conversion/GPUCommon/ConvertKernelFuncToBlob.cpp b/mlir/lib/Conversion/GPUCommon/ConvertKernelFuncToBlob.cpp --- a/mlir/lib/Conversion/GPUCommon/ConvertKernelFuncToBlob.cpp +++ b/mlir/lib/Conversion/GPUCommon/ConvertKernelFuncToBlob.cpp @@ -70,7 +70,7 @@ // attribute to the module. if (auto blobAttr = translateGPUModuleToBinaryAnnotation( *llvmModule, module.getLoc(), module.getName())) - module.setAttr(blobAnnotation, blobAttr); + module->setAttr(blobAnnotation, blobAttr); else signalPassFailure(); } diff --git a/mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRV.cpp b/mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRV.cpp --- a/mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRV.cpp +++ b/mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRV.cpp @@ -197,7 +197,7 @@ if (namedAttr.first == impl::getTypeAttrName() || namedAttr.first == SymbolTable::getSymbolAttrName()) continue; - newFuncOp.setAttr(namedAttr.first, namedAttr.second); + newFuncOp->setAttr(namedAttr.first, namedAttr.second); } rewriter.inlineRegionBefore(funcOp.getBody(), newFuncOp.getBody(), diff --git a/mlir/lib/Conversion/GPUToVulkan/ConvertGPULaunchFuncToVulkanLaunchFunc.cpp b/mlir/lib/Conversion/GPUToVulkan/ConvertGPULaunchFuncToVulkanLaunchFunc.cpp --- a/mlir/lib/Conversion/GPUToVulkan/ConvertGPULaunchFuncToVulkanLaunchFunc.cpp +++ b/mlir/lib/Conversion/GPUToVulkan/ConvertGPULaunchFuncToVulkanLaunchFunc.cpp @@ -175,12 +175,12 @@ vulkanLaunchOperands); // Set SPIR-V binary shader data as an attribute. - vulkanLaunchCallOp.setAttr( + vulkanLaunchCallOp->setAttr( kSPIRVBlobAttrName, StringAttr::get({binary.data(), binary.size()}, loc->getContext())); // Set entry point name as an attribute. - vulkanLaunchCallOp.setAttr( + vulkanLaunchCallOp->setAttr( kSPIRVEntryPointAttrName, StringAttr::get(launchOp.getKernelName(), loc->getContext())); diff --git a/mlir/lib/Conversion/LinalgToStandard/LinalgToStandard.cpp b/mlir/lib/Conversion/LinalgToStandard/LinalgToStandard.cpp --- a/mlir/lib/Conversion/LinalgToStandard/LinalgToStandard.cpp +++ b/mlir/lib/Conversion/LinalgToStandard/LinalgToStandard.cpp @@ -76,7 +76,7 @@ // Insert a function attribute that will trigger the emission of the // corresponding `_mlir_ciface_xxx` interface so that external libraries see // a normalized ABI. This interface is added during std to llvm conversion. - funcOp.setAttr("llvm.emit_c_interface", UnitAttr::get(op->getContext())); + funcOp->setAttr("llvm.emit_c_interface", UnitAttr::get(op->getContext())); funcOp.setPrivate(); return fnNameAttr; } diff --git a/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp b/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp --- a/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp +++ b/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp @@ -524,7 +524,7 @@ if (namedAttr.first == gpu::getMappingAttrName() || namedAttr.first == ParallelOp::getOperandSegmentSizeAttr()) continue; - launchOp.setAttr(namedAttr.first, namedAttr.second); + launchOp->setAttr(namedAttr.first, namedAttr.second); } Block *body = parallelOp.getBody(); @@ -648,6 +648,6 @@ void mlir::configureParallelLoopToGPULegality(ConversionTarget &target) { target.addDynamicallyLegalOp([](scf::ParallelOp parallelOp) { - return !parallelOp.getAttr(gpu::getMappingAttrName()); + return !parallelOp->getAttr(gpu::getMappingAttrName()); }); } diff --git a/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp b/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp --- a/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp +++ b/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp @@ -1302,17 +1302,17 @@ switch (funcOp.function_control()) { #define DISPATCH(functionControl, llvmAttr) \ case functionControl: \ - newFuncOp.setAttr("passthrough", ArrayAttr::get({llvmAttr}, context)); \ + newFuncOp->setAttr("passthrough", ArrayAttr::get({llvmAttr}, context)); \ break; - DISPATCH(spirv::FunctionControl::Inline, - StringAttr::get("alwaysinline", context)); - DISPATCH(spirv::FunctionControl::DontInline, - StringAttr::get("noinline", context)); - DISPATCH(spirv::FunctionControl::Pure, - StringAttr::get("readonly", context)); - DISPATCH(spirv::FunctionControl::Const, - StringAttr::get("readnone", context)); + DISPATCH(spirv::FunctionControl::Inline, + StringAttr::get("alwaysinline", context)); + DISPATCH(spirv::FunctionControl::DontInline, + StringAttr::get("noinline", context)); + DISPATCH(spirv::FunctionControl::Pure, + StringAttr::get("readonly", context)); + DISPATCH(spirv::FunctionControl::Const, + StringAttr::get("readnone", context)); #undef DISPATCH diff --git a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp --- a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp +++ b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp @@ -4154,8 +4154,8 @@ LLVMConversionTarget target(getContext()); if (failed(applyPartialConversion(m, target, std::move(patterns)))) signalPassFailure(); - m.setAttr(LLVM::LLVMDialect::getDataLayoutAttrName(), - StringAttr::get(this->dataLayout, m.getContext())); + m->setAttr(LLVM::LLVMDialect::getDataLayoutAttrName(), + StringAttr::get(this->dataLayout, m.getContext())); } }; } // end namespace 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 @@ -1796,7 +1796,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) { @@ -1809,7 +1809,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) { @@ -1818,7 +1818,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) { @@ -1827,7 +1827,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() { @@ -2128,7 +2128,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) { @@ -2412,7 +2412,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) << ')'; @@ -2461,7 +2461,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(); } @@ -2673,8 +2673,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/Affine/Utils/Utils.cpp b/mlir/lib/Dialect/Affine/Utils/Utils.cpp --- a/mlir/lib/Dialect/Affine/Utils/Utils.cpp +++ b/mlir/lib/Dialect/Affine/Utils/Utils.cpp @@ -92,7 +92,7 @@ operandMap.clear(); b.setInsertionPointAfter(hoistOverOp); // We'll set an attribute to identify this op in a clone of this sub-tree. - ifOp.setAttr(idForIfOp, b.getBoolAttr(true)); + ifOp->setAttr(idForIfOp, b.getBoolAttr(true)); hoistOverOpClone = b.clone(*hoistOverOp, operandMap); // Promote the 'then' block of the original affine.if in the then version. @@ -107,7 +107,7 @@ // Find the clone of the original affine.if op in the else version. AffineIfOp ifCloneInElse; hoistOverOpClone->walk([&](AffineIfOp ifClone) { - if (!ifClone.getAttr(idForIfOp)) + if (!ifClone->getAttr(idForIfOp)) return WalkResult::advance(); ifCloneInElse = ifClone; return WalkResult::interrupt(); diff --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp --- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp +++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp @@ -524,7 +524,8 @@ BlockArgument GPUFuncOp::addWorkgroupAttribution(Type type) { auto attrName = getNumWorkgroupAttributionsAttrName(); auto attr = (*this)->getAttrOfType(attrName); - setAttr(attrName, IntegerAttr::get(attr.getType(), attr.getValue() + 1)); + (*this)->setAttr(attrName, + IntegerAttr::get(attr.getType(), attr.getValue() + 1)); return getBody().insertArgument(getType().getNumInputs() + attr.getInt(), type); } @@ -701,7 +702,7 @@ for (int i = newType.getNumInputs(), e = oldType.getNumInputs(); i < e; i++) removeAttr(getArgAttrName(i, nameBuf)); - setAttr(getTypeAttrName(), TypeAttr::get(newType)); + (*this)->setAttr(getTypeAttrName(), TypeAttr::get(newType)); } /// Hook for FunctionLike verifier. diff --git a/mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp b/mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp --- a/mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp @@ -157,8 +157,8 @@ FunctionType type = FunctionType::get(kernelOperandTypes, {}, launchOp.getContext()); auto outlinedFunc = builder.create(loc, kernelFnName, type); - outlinedFunc.setAttr(gpu::GPUDialect::getKernelFuncAttrName(), - builder.getUnitAttr()); + outlinedFunc->setAttr(gpu::GPUDialect::getKernelFuncAttrName(), + builder.getUnitAttr()); BlockAndValueMapping map; // Map the arguments corresponding to the launch parameters like blockIdx, @@ -269,8 +269,8 @@ // If any new module was inserted in this module, annotate this module as // a container module. if (modified) - getOperation().setAttr(gpu::GPUDialect::getContainerModuleAttrName(), - UnitAttr::get(&getContext())); + getOperation()->setAttr(gpu::GPUDialect::getContainerModuleAttrName(), + UnitAttr::get(&getContext())); } private: diff --git a/mlir/lib/Dialect/GPU/Transforms/ParallelLoopMapper.cpp b/mlir/lib/Dialect/GPU/Transforms/ParallelLoopMapper.cpp --- a/mlir/lib/Dialect/GPU/Transforms/ParallelLoopMapper.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/ParallelLoopMapper.cpp @@ -52,8 +52,8 @@ "invalid mapping multiple loops to same processor"); } ArrayRef mappingAsAttrs(mapping.data(), mapping.size()); - ploopOp.setAttr(getMappingAttrName(), - ArrayAttr::get(mappingAsAttrs, ploopOp.getContext())); + ploopOp->setAttr(getMappingAttrName(), + ArrayAttr::get(mappingAsAttrs, ploopOp.getContext())); return success(); } } // namespace gpu @@ -122,7 +122,7 @@ static void mapParallelOp(ParallelOp parallelOp, MappingLevel mappingLevel = MapGrid) { // Do not try to add a mapping to already mapped loops or nested loops. - if (parallelOp.getAttr(getMappingAttrName()) || + if (parallelOp->getAttr(getMappingAttrName()) || ((mappingLevel == MapGrid) && parallelOp->getParentOfType())) return; 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/lib/Dialect/Linalg/Transforms/Interchange.cpp b/mlir/lib/Dialect/Linalg/Transforms/Interchange.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/Interchange.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Interchange.cpp @@ -76,10 +76,10 @@ itTypesVector.push_back(itTypes[i]); applyPermutationToVector(itTypesVector, interchangeVector); - op.setAttr(getIndexingMapsAttrName(), - ArrayAttr::get(newIndexingMaps, context)); - op.setAttr(getIteratorTypesAttrName(), - ArrayAttr::get(itTypesVector, context)); + op->setAttr(getIndexingMapsAttrName(), + ArrayAttr::get(newIndexingMaps, context)); + op->setAttr(getIteratorTypesAttrName(), + ArrayAttr::get(itTypesVector, context)); return op; } diff --git a/mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp b/mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp --- a/mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp +++ b/mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp @@ -496,7 +496,7 @@ for (const auto &namedAttr : funcOp.getAttrs()) { if (namedAttr.first != impl::getTypeAttrName() && namedAttr.first != SymbolTable::getSymbolAttrName()) - newFuncOp.setAttr(namedAttr.first, namedAttr.second); + newFuncOp->setAttr(namedAttr.first, namedAttr.second); } rewriter.inlineRegionBefore(funcOp.getBody(), newFuncOp.getBody(), @@ -656,7 +656,7 @@ for (auto argIndex : llvm::seq(0, argABIInfo.size())) { funcOp.setArgAttr(argIndex, argABIAttrName, argABIInfo[argIndex]); } - funcOp.setAttr(spirv::getEntryPointABIAttrName(), entryPointInfo); + funcOp->setAttr(spirv::getEntryPointABIAttrName(), entryPointInfo); return success(); } diff --git a/mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp b/mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp --- a/mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp +++ b/mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp @@ -721,19 +721,20 @@ } void Deserializer::attachVCETriple() { - module->setAttr(spirv::ModuleOp::getVCETripleAttrName(), - spirv::VerCapExtAttr::get(version, capabilities.getArrayRef(), - extensions.getArrayRef(), context)); + (*module)->setAttr( + spirv::ModuleOp::getVCETripleAttrName(), + spirv::VerCapExtAttr::get(version, capabilities.getArrayRef(), + extensions.getArrayRef(), context)); } LogicalResult Deserializer::processMemoryModel(ArrayRef operands) { if (operands.size() != 2) return emitError(unknownLoc, "OpMemoryModel must have two operands"); - module->setAttr( + (*module)->setAttr( "addressing_model", opBuilder.getI32IntegerAttr(llvm::bit_cast(operands.front()))); - module->setAttr( + (*module)->setAttr( "memory_model", opBuilder.getI32IntegerAttr(llvm::bit_cast(operands.back()))); @@ -1035,7 +1036,7 @@ defaultValue); if (decorations.count(resultID)) { for (auto attr : decorations[resultID].getAttrs()) - op.setAttr(attr.first, attr.second); + op->setAttr(attr.first, attr.second); } specConstMap[resultID] = op; return op; @@ -1105,7 +1106,7 @@ // Decorations. if (decorations.count(variableID)) { for (auto attr : decorations[variableID].getAttrs()) { - varOp.setAttr(attr.first, attr.second); + varOp->setAttr(attr.first, attr.second); } } globalVariableMap[variableID] = varOp; diff --git a/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp b/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp --- a/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp +++ b/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp @@ -915,7 +915,7 @@ resultID = getNextID(); valueIDMap[op.getResult()] = resultID; operands.push_back(resultID); - auto attr = op.getAttr(spirv::attributeName()); + auto attr = op->getAttr(spirv::attributeName()); if (attr) { operands.push_back(static_cast( attr.cast().getValue().getZExtValue())); @@ -930,7 +930,7 @@ } emitDebugLine(functionHeader, op.getLoc()); encodeInstructionInto(functionHeader, spirv::Opcode::OpVariable, operands); - for (auto attr : op.getAttrs()) { + for (auto attr : op->getAttrs()) { if (llvm::any_of(elidedAttrs, [&](StringRef elided) { return attr.first == elided; })) { continue; @@ -999,7 +999,7 @@ } // Encode decorations. - for (auto attr : varOp.getAttrs()) { + for (auto attr : varOp->getAttrs()) { if (llvm::any_of(elidedAttrs, [&](StringRef elided) { return attr.first == elided; })) { continue; @@ -2071,28 +2071,28 @@ operands.push_back(id); } - if (auto attr = op.getAttr("memory_access")) { + if (auto attr = op->getAttr("memory_access")) { operands.push_back(static_cast( attr.cast().getValue().getZExtValue())); } elidedAttrs.push_back("memory_access"); - if (auto attr = op.getAttr("alignment")) { + if (auto attr = op->getAttr("alignment")) { operands.push_back(static_cast( attr.cast().getValue().getZExtValue())); } elidedAttrs.push_back("alignment"); - if (auto attr = op.getAttr("source_memory_access")) { + if (auto attr = op->getAttr("source_memory_access")) { operands.push_back(static_cast( attr.cast().getValue().getZExtValue())); } elidedAttrs.push_back("source_memory_access"); - if (auto attr = op.getAttr("source_alignment")) { + if (auto attr = op->getAttr("source_alignment")) { operands.push_back(static_cast( attr.cast().getValue().getZExtValue())); } diff --git a/mlir/lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp b/mlir/lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp --- a/mlir/lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp +++ b/mlir/lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp @@ -169,7 +169,7 @@ auto triple = spirv::VerCapExtAttr::get( deducedVersion, deducedCapabilities.getArrayRef(), deducedExtensions.getArrayRef(), &getContext()); - module.setAttr(spirv::ModuleOp::getVCETripleAttrName(), triple); + module->setAttr(spirv::ModuleOp::getVCETripleAttrName(), triple); } std::unique_ptr> diff --git a/mlir/lib/Dialect/Vector/VectorOps.cpp b/mlir/lib/Dialect/Vector/VectorOps.cpp --- a/mlir/lib/Dialect/Vector/VectorOps.cpp +++ b/mlir/lib/Dialect/Vector/VectorOps.cpp @@ -666,8 +666,8 @@ // OpBuilder is only used as a helper to build an I64ArrayAttr. OpBuilder b(extractOp.getContext()); std::reverse(globalPosition.begin(), globalPosition.end()); - extractOp.setAttr(ExtractOp::getPositionAttrName(), - b.getI64ArrayAttr(globalPosition)); + extractOp->setAttr(ExtractOp::getPositionAttrName(), + b.getI64ArrayAttr(globalPosition)); return success(); } @@ -722,8 +722,8 @@ inversePermutation(permutationMap).compose(extractedPos); // OpBuilder is only used as a helper to build an I64ArrayAttr. OpBuilder b(extractOp.getContext()); - extractOp.setAttr(ExtractOp::getPositionAttrName(), - b.getI64ArrayAttr(newExtractedPos)); + extractOp->setAttr(ExtractOp::getPositionAttrName(), + b.getI64ArrayAttr(newExtractedPos)); return success(); } @@ -832,8 +832,8 @@ extractOp.setOperand(broadcastOp.source()); // OpBuilder is only used as a helper to build an I64ArrayAttr. OpBuilder b(extractOp.getContext()); - extractOp.setAttr(ExtractOp::getPositionAttrName(), - b.getI64ArrayAttr(extractPos)); + extractOp->setAttr(ExtractOp::getPositionAttrName(), + b.getI64ArrayAttr(extractPos)); return extractOp.getResult(); } // TODO: In case the rank of the broadcast source is greater than the rank of @@ -895,8 +895,8 @@ SmallVector newPosition = delinearize(newStrides, position); // OpBuilder is only used as a helper to build an I64ArrayAttr. OpBuilder b(extractOp.getContext()); - extractOp.setAttr(ExtractOp::getPositionAttrName(), - b.getI64ArrayAttr(newPosition)); + extractOp->setAttr(ExtractOp::getPositionAttrName(), + b.getI64ArrayAttr(newPosition)); extractOp.setOperand(shapeCastOp.source()); return extractOp.getResult(); } @@ -1737,8 +1737,8 @@ op.setOperand(insertOp.source()); // OpBuilder is only used as a helper to build an I64ArrayAttr. OpBuilder b(op.getContext()); - op.setAttr(ExtractStridedSliceOp::getOffsetsAttrName(), - b.getI64ArrayAttr(offsetDiffs)); + op->setAttr(ExtractStridedSliceOp::getOffsetsAttrName(), + b.getI64ArrayAttr(offsetDiffs)); return success(); } // If the chunk extracted is disjoint from the chunk inserted, keep looking @@ -2135,7 +2135,7 @@ return failure(); // OpBuilder is only used as a helper to build an I64ArrayAttr. OpBuilder b(op.getContext()); - op.setAttr(TransferOp::getMaskedAttrName(), b.getBoolArrayAttr(isMasked)); + op->setAttr(TransferOp::getMaskedAttrName(), b.getBoolArrayAttr(isMasked)); return success(); } diff --git a/mlir/lib/Dialect/Vector/VectorTransforms.cpp b/mlir/lib/Dialect/Vector/VectorTransforms.cpp --- a/mlir/lib/Dialect/Vector/VectorTransforms.cpp +++ b/mlir/lib/Dialect/Vector/VectorTransforms.cpp @@ -2391,7 +2391,7 @@ SmallVector bools(xferOp.getTransferRank(), false); auto unmaskedAttr = b.getBoolArrayAttr(bools); if (options.vectorTransferSplit == VectorTransferSplit::ForceUnmasked) { - xferOp.setAttr(vector::TransferReadOp::getMaskedAttrName(), unmaskedAttr); + xferOp->setAttr(vector::TransferReadOp::getMaskedAttrName(), unmaskedAttr); return success(); } @@ -2447,7 +2447,7 @@ // Unmask the existing read op, it always reads from a full buffer. for (unsigned i = 0, e = returnTypes.size(); i != e; ++i) xferReadOp.setOperand(i, fullPartialIfOp.getResult(i)); - xferOp.setAttr(vector::TransferReadOp::getMaskedAttrName(), unmaskedAttr); + xferOp->setAttr(vector::TransferReadOp::getMaskedAttrName(), unmaskedAttr); return success(); } diff --git a/mlir/test/lib/Dialect/SPIRV/TestEntryPointAbi.cpp b/mlir/test/lib/Dialect/SPIRV/TestEntryPointAbi.cpp --- a/mlir/test/lib/Dialect/SPIRV/TestEntryPointAbi.cpp +++ b/mlir/test/lib/Dialect/SPIRV/TestEntryPointAbi.cpp @@ -44,13 +44,13 @@ MLIRContext *context = &getContext(); StringRef attrName = spirv::getEntryPointABIAttrName(); for (gpu::GPUFuncOp gpuFunc : gpuModule.getOps()) { - if (!gpu::GPUDialect::isKernel(gpuFunc) || gpuFunc.getAttr(attrName)) + if (!gpu::GPUDialect::isKernel(gpuFunc) || gpuFunc->getAttr(attrName)) continue; SmallVector workgroupSizeVec(workgroupSize.begin(), workgroupSize.end()); workgroupSizeVec.resize(3, 1); - gpuFunc.setAttr(attrName, - spirv::getEntryPointABIAttr(workgroupSizeVec, context)); + gpuFunc->setAttr(attrName, + spirv::getEntryPointABIAttr(workgroupSizeVec, context)); } } diff --git a/mlir/test/lib/Dialect/Test/TestDialect.cpp b/mlir/test/lib/Dialect/Test/TestDialect.cpp --- a/mlir/test/lib/Dialect/Test/TestDialect.cpp +++ b/mlir/test/lib/Dialect/Test/TestDialect.cpp @@ -674,7 +674,7 @@ OpFoldResult TestOpInPlaceFold::fold(ArrayRef operands) { assert(operands.size() == 1); if (operands.front()) { - setAttr("attr", operands.front()); + (*this)->setAttr("attr", operands.front()); return getResult(); } return {}; 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/lib/Dialect/Test/TestPatterns.cpp b/mlir/test/lib/Dialect/Test/TestPatterns.cpp --- a/mlir/test/lib/Dialect/Test/TestPatterns.cpp +++ b/mlir/test/lib/Dialect/Test/TestPatterns.cpp @@ -467,7 +467,7 @@ PatternRewriter &rewriter) const final { // Decrement the depth of the op in-place. rewriter.updateRootInPlace(op, [&] { - op.setAttr("depth", rewriter.getI64IntegerAttr(op.depth() - 1)); + op->setAttr("depth", rewriter.getI64IntegerAttr(op.depth() - 1)); }); return success(); } diff --git a/mlir/test/lib/Transforms/TestCallGraph.cpp b/mlir/test/lib/Transforms/TestCallGraph.cpp --- a/mlir/test/lib/Transforms/TestCallGraph.cpp +++ b/mlir/test/lib/Transforms/TestCallGraph.cpp @@ -20,7 +20,8 @@ struct TestCallGraphPass : public PassWrapper> { void runOnOperation() override { - llvm::errs() << "Testing : " << getOperation().getAttr("test.name") << "\n"; + llvm::errs() << "Testing : " << getOperation()->getAttr("test.name") + << "\n"; getAnalysis().print(llvm::errs()); } }; 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,21 +48,21 @@ // --- // 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) -// DEF-NEXT: return some-const-builder-call(::mlir::Builder(this->getContext()), 4.2).some-convert-from-storage(); +// DEF-NEXT: return some-const-builder-call(::mlir::Builder((*this)->getContext()), 4.2).some-convert-from-storage(); // 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); @@ -164,11 +164,11 @@ } // DEF-LABEL: COp definitions -// DEF: ::mlir::Builder(this->getContext()).getI32ArrayAttr({1, 2}) -// DEF: ::mlir::Builder(this->getContext()).getI64ArrayAttr({3, 4}) -// DEF: ::mlir::Builder(this->getContext()).getF32ArrayAttr({5.f, 6.f}) -// DEF: ::mlir::Builder(this->getContext()).getF64ArrayAttr({7., 8.}) -// DEF: ::mlir::Builder(this->getContext()).getStrArrayAttr({"a", "b"}) +// DEF: ::mlir::Builder((*this)->getContext()).getI32ArrayAttr({1, 2}) +// DEF: ::mlir::Builder((*this)->getContext()).getI64ArrayAttr({3, 4}) +// DEF: ::mlir::Builder((*this)->getContext()).getF32ArrayAttr({5.f, 6.f}) +// DEF: ::mlir::Builder((*this)->getContext()).getF64ArrayAttr({7., 8.}) +// DEF: ::mlir::Builder((*this)->getContext()).getStrArrayAttr({"a", "b"}) // Test builder method which takes unwrapped values for attributes 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"; } diff --git a/mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp b/mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp --- a/mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp +++ b/mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp @@ -491,7 +491,7 @@ StringRef opVar, StringRef operandList, StringRef attrName, raw_ostream &os) { os << tabs - << formatv("if (auto attr = {0}.getAttr(\"{1}\")) {{\n", opVar, attrName); + << formatv("if (auto attr = {0}->getAttr(\"{1}\")) {{\n", opVar, attrName); if (attr.getAttrDefName() == "SPV_ScopeAttr" || attr.getAttrDefName() == "SPV_MemorySemanticsAttr") { os << tabs @@ -645,7 +645,7 @@ StringRef resultID, raw_ostream &os) { if (op.getNumResults() == 1) { // All non-argument attributes translated into OpDecorate instruction - os << tabs << formatv("for (auto attr : {0}.getAttrs()) {{\n", opVar); + os << tabs << formatv("for (auto attr : {0}->getAttrs()) {{\n", opVar); os << tabs << formatv(" if (llvm::any_of({0}, [&](StringRef elided)", elidedAttrs); os << " {return attr.first == elided;})) {\n";