diff --git a/mlir/include/mlir/Analysis/NestedMatcher.h b/mlir/include/mlir/Analysis/NestedMatcher.h --- a/mlir/include/mlir/Analysis/NestedMatcher.h +++ b/mlir/include/mlir/Analysis/NestedMatcher.h @@ -180,15 +180,15 @@ namespace matcher { // Syntactic sugar NestedPattern builder functions. NestedPattern Op(FilterFunctionType filter = defaultFilterFunction); -NestedPattern If(NestedPattern child); -NestedPattern If(FilterFunctionType filter, NestedPattern child); +NestedPattern If(const NestedPattern &child); +NestedPattern If(const FilterFunctionType &filter, const NestedPattern &child); NestedPattern If(ArrayRef nested = {}); -NestedPattern If(FilterFunctionType filter, +NestedPattern If(const FilterFunctionType &filter, ArrayRef nested = {}); -NestedPattern For(NestedPattern child); -NestedPattern For(FilterFunctionType filter, NestedPattern child); +NestedPattern For(const NestedPattern &child); +NestedPattern For(const FilterFunctionType &filter, const NestedPattern &child); NestedPattern For(ArrayRef nested = {}); -NestedPattern For(FilterFunctionType filter, +NestedPattern For(const FilterFunctionType &filter, ArrayRef nested = {}); bool isParallelLoop(Operation &op); diff --git a/mlir/include/mlir/Dialect/Async/Transforms.h b/mlir/include/mlir/Dialect/Async/Transforms.h --- a/mlir/include/mlir/Dialect/Async/Transforms.h +++ b/mlir/include/mlir/Dialect/Async/Transforms.h @@ -32,7 +32,7 @@ /// operations. void populateAsyncParallelForPatterns( RewritePatternSet &patterns, bool asyncDispatch, int32_t numWorkerThreads, - AsyncMinTaskSizeComputationFunction computeMinTaskSize); + const AsyncMinTaskSizeComputationFunction &computeMinTaskSize); } // namespace async } // namespace mlir diff --git a/mlir/include/mlir/Dialect/Linalg/ComprehensiveBufferize/BufferizableOpInterface.h b/mlir/include/mlir/Dialect/Linalg/ComprehensiveBufferize/BufferizableOpInterface.h --- a/mlir/include/mlir/Dialect/Linalg/ComprehensiveBufferize/BufferizableOpInterface.h +++ b/mlir/include/mlir/Dialect/Linalg/ComprehensiveBufferize/BufferizableOpInterface.h @@ -352,7 +352,7 @@ /// { 2, 7, 8, 5 } llvm::SetVector findValueInReverseUseDefChain(Value value, - std::function condition); + const std::function &condition); /// Find the Value of the last preceding write of a given Value. /// diff --git a/mlir/include/mlir/Dialect/Linalg/Passes.h b/mlir/include/mlir/Dialect/Linalg/Passes.h --- a/mlir/include/mlir/Dialect/Linalg/Passes.h +++ b/mlir/include/mlir/Dialect/Linalg/Passes.h @@ -82,70 +82,70 @@ //===----------------------------------------------------------------------===// /// Create a LinalgStrategyTileAndFusePass. std::unique_ptr> createLinalgStrategyTileAndFusePass( - StringRef opName = "", linalg::LinalgTilingAndFusionOptions opt = {}, - linalg::LinalgTransformationFilter filter = + StringRef opName = "", const linalg::LinalgTilingAndFusionOptions &opt = {}, + const linalg::LinalgTransformationFilter &filter = linalg::LinalgTransformationFilter()); /// Create a LinalgStrategyTilePass. std::unique_ptr> createLinalgStrategyTilePass( StringRef opName = "", - linalg::LinalgTilingOptions opt = linalg::LinalgTilingOptions(), - linalg::LinalgTransformationFilter filter = + const linalg::LinalgTilingOptions &opt = linalg::LinalgTilingOptions(), + const linalg::LinalgTransformationFilter &filter = linalg::LinalgTransformationFilter()); /// Create a LinalgStrategyPadPass. std::unique_ptr> createLinalgStrategyPadPass( StringRef opName = "", - linalg::LinalgPaddingOptions opt = linalg::LinalgPaddingOptions(), - linalg::LinalgTransformationFilter filter = + const linalg::LinalgPaddingOptions &opt = linalg::LinalgPaddingOptions(), + const linalg::LinalgTransformationFilter &filter = linalg::LinalgTransformationFilter()); /// Create a LinalgStrategyPromotePass. std::unique_ptr> createLinalgStrategyPromotePass( StringRef opName = "", - linalg::LinalgPromotionOptions opt = linalg::LinalgPromotionOptions(), - linalg::LinalgTransformationFilter filter = + const linalg::LinalgPromotionOptions &opt = + linalg::LinalgPromotionOptions(), + const linalg::LinalgTransformationFilter &filter = linalg::LinalgTransformationFilter()); /// Create a LinalgStrategyGeneralizePass. -std::unique_ptr> -createLinalgStrategyGeneralizePass(StringRef opName = "", - linalg::LinalgTransformationFilter filter = - linalg::LinalgTransformationFilter()); +std::unique_ptr> createLinalgStrategyGeneralizePass( + StringRef opName = "", const linalg::LinalgTransformationFilter &filter = + linalg::LinalgTransformationFilter()); /// Create a LinalgStrategyDecomposePass. // TODO: if/when we need finer control add an `opName` parameter. -std::unique_ptr> -createLinalgStrategyDecomposePass(linalg::LinalgTransformationFilter filter = - linalg::LinalgTransformationFilter()); +std::unique_ptr> createLinalgStrategyDecomposePass( + const linalg::LinalgTransformationFilter &filter = + linalg::LinalgTransformationFilter()); /// Create a LinalgStrategyInterchangePass. -std::unique_ptr> -createLinalgStrategyInterchangePass(ArrayRef iteratorInterchange = {}, - linalg::LinalgTransformationFilter filter = - linalg::LinalgTransformationFilter()); +std::unique_ptr> createLinalgStrategyInterchangePass( + ArrayRef iteratorInterchange = {}, + const linalg::LinalgTransformationFilter &filter = + linalg::LinalgTransformationFilter()); /// Create a LinalgStrategyVectorizePass. -std::unique_ptr> -createLinalgStrategyVectorizePass(StringRef opName = "", - linalg::LinalgVectorizationOptions opt = - linalg::LinalgVectorizationOptions(), - linalg::LinalgTransformationFilter filter = - linalg::LinalgTransformationFilter(), - bool padVectorize = false); +std::unique_ptr> createLinalgStrategyVectorizePass( + StringRef opName = "", + linalg::LinalgVectorizationOptions opt = + linalg::LinalgVectorizationOptions(), + const linalg::LinalgTransformationFilter &filter = + linalg::LinalgTransformationFilter(), + bool padVectorize = false); /// Create a LinalgStrategyEnablePass. std::unique_ptr> createLinalgStrategyEnablePass( linalg::LinalgEnablingOptions opt = linalg::LinalgEnablingOptions(), - linalg::LinalgTransformationFilter filter = + const linalg::LinalgTransformationFilter &filter = linalg::LinalgTransformationFilter()); /// Create a LinalgStrategyLowerVectorsPass. -std::unique_ptr> -createLinalgStrategyLowerVectorsPass(linalg::LinalgVectorLoweringOptions opt = - linalg::LinalgVectorLoweringOptions(), - linalg::LinalgTransformationFilter filter = - linalg::LinalgTransformationFilter()); +std::unique_ptr> createLinalgStrategyLowerVectorsPass( + linalg::LinalgVectorLoweringOptions opt = + linalg::LinalgVectorLoweringOptions(), + const linalg::LinalgTransformationFilter &filter = + linalg::LinalgTransformationFilter()); /// Create a LinalgStrategyRemoveMarkersPass. std::unique_ptr> createLinalgStrategyRemoveMarkersPass(); diff --git a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h --- a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h +++ b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h @@ -70,7 +70,8 @@ /// loop in the generic op. void populateFoldReshapeOpsByExpansionPatterns( RewritePatternSet &patterns, - ControlElementwiseOpsFusionFn controlFoldingReshapes = skipUnitDimReshape); + const ControlElementwiseOpsFusionFn &controlFoldingReshapes = + skipUnitDimReshape); /// Patterns to fold a collapsing (expanding) tensor_reshape operation with its /// producer (consumer) generic operation by linearizing the indexing map used @@ -356,7 +357,7 @@ }; FailureOr promoteSubviewAsNewBuffer(OpBuilder &b, Location loc, memref::SubViewOp subView, - AllocBufferCallbackFn allocationFn, + const AllocBufferCallbackFn &allocationFn, DataLayout &layout); /// Promotes the `subViews` into a new buffer allocated at the insertion point @@ -370,7 +371,7 @@ /// Returns the modified linalg op (the modification happens in place) as well /// as all the copy ops created. FailureOr promoteSubViews(OpBuilder &b, LinalgOp op, - LinalgPromotionOptions options); + const LinalgPromotionOptions &options); /// Emit a suitable vector form for a Linalg op with fully static shape. LogicalResult vectorizeLinalgOp(OpBuilder &builder, Operation *op, @@ -437,7 +438,7 @@ Optional replacement = None); explicit LinalgTransformationFilter( - FilterFunction f, ArrayRef matchDisjunction = {}, + const FilterFunction &f, ArrayRef matchDisjunction = {}, Optional replacement = None); LinalgTransformationFilter(LinalgTransformationFilter &&) = default; @@ -1180,7 +1181,7 @@ /// linalg.generic ops. void populateLinalgNamedOpsGeneralizationPatterns( RewritePatternSet &patterns, - LinalgTransformationFilter filter = LinalgTransformationFilter()); + const LinalgTransformationFilter &filter = LinalgTransformationFilter()); /// Linalg decompose convolutions patterns @@ -1189,7 +1190,7 @@ /// vectorize the low-D convolution ops. void populateDecomposeConvolutionPatterns( RewritePatternSet &patterns, - LinalgTransformationFilter filter = LinalgTransformationFilter(), + const LinalgTransformationFilter &filter = LinalgTransformationFilter(), PatternBenefit benefit = 1); /// Linalg distribution patterns diff --git a/mlir/include/mlir/IR/AffineMap.h b/mlir/include/mlir/IR/AffineMap.h --- a/mlir/include/mlir/IR/AffineMap.h +++ b/mlir/include/mlir/IR/AffineMap.h @@ -182,7 +182,7 @@ /// Walk all of the AffineExpr's in this mapping. Each node in an expression /// tree is visited in postorder. - void walkExprs(std::function callback) const; + void walkExprs(const std::function &callback) const; /// This method substitutes any uses of dimensions and symbols (e.g. /// dim#0 with dimReplacements[0]) in subexpressions and returns the modified diff --git a/mlir/include/mlir/IR/Dialect.h b/mlir/include/mlir/IR/Dialect.h --- a/mlir/include/mlir/IR/Dialect.h +++ b/mlir/include/mlir/IR/Dialect.h @@ -317,7 +317,8 @@ /// Add a new dialect constructor to the registry. The constructor must be /// calling MLIRContext::getOrLoadDialect in order for the context to take /// ownership of the dialect and for delayed interface registration to happen. - void insert(TypeID typeID, StringRef name, DialectAllocatorFunction ctor); + void insert(TypeID typeID, StringRef name, + const DialectAllocatorFunction &ctor); /// Return an allocation function for constructing the dialect identified by /// its namespace, or nullptr if the namespace is not in this registry. @@ -397,13 +398,13 @@ /// Add an interface constructed with the given allocation function to the /// dialect identified by its namespace. void addDialectInterface(StringRef dialectName, TypeID interfaceTypeID, - DialectInterfaceAllocatorFunction allocator); + const DialectInterfaceAllocatorFunction &allocator); /// Add an attribute/operation/type interface constructible with the given /// allocation function to the dialect identified by its namespace. void addObjectInterface(StringRef dialectName, TypeID objectID, TypeID interfaceTypeID, - ObjectInterfaceAllocatorFunction allocator); + const ObjectInterfaceAllocatorFunction &allocator); /// Add an external model for an attribute/type interface to the dialect /// identified by its namespace. diff --git a/mlir/include/mlir/Reducer/ReductionNode.h b/mlir/include/mlir/Reducer/ReductionNode.h --- a/mlir/include/mlir/Reducer/ReductionNode.h +++ b/mlir/include/mlir/Reducer/ReductionNode.h @@ -48,7 +48,7 @@ using Range = std::pair; - ReductionNode(ReductionNode *parent, std::vector range, + ReductionNode(ReductionNode *parent, const std::vector &range, llvm::SpecificBumpPtrAllocator &allocator); ReductionNode *getParent() const { return parent; } diff --git a/mlir/include/mlir/TableGen/GenInfo.h b/mlir/include/mlir/TableGen/GenInfo.h --- a/mlir/include/mlir/TableGen/GenInfo.h +++ b/mlir/include/mlir/TableGen/GenInfo.h @@ -64,7 +64,8 @@ /// // At namespace scope. /// static GenRegistration Print("print", "Print records", [](...){...}); struct GenRegistration { - GenRegistration(StringRef arg, StringRef description, GenFunction function); + GenRegistration(StringRef arg, StringRef description, + const GenFunction &function); }; } // namespace mlir diff --git a/mlir/include/mlir/TableGen/Pattern.h b/mlir/include/mlir/TableGen/Pattern.h --- a/mlir/include/mlir/TableGen/Pattern.h +++ b/mlir/include/mlir/TableGen/Pattern.h @@ -398,7 +398,8 @@ // with index `argIndex` for operator `op`. const_iterator findBoundSymbol(StringRef key, DagNode node, const Operator &op, int argIndex) const; - const_iterator findBoundSymbol(StringRef key, SymbolInfo symbolInfo) const; + const_iterator findBoundSymbol(StringRef key, + const SymbolInfo &symbolInfo) const; // Returns the bounds of a range that includes all the elements which // bind to the `key`. diff --git a/mlir/include/mlir/Translation.h b/mlir/include/mlir/Translation.h --- a/mlir/include/mlir/Translation.h +++ b/mlir/include/mlir/Translation.h @@ -78,7 +78,7 @@ struct TranslateFromMLIRRegistration { TranslateFromMLIRRegistration( llvm::StringRef name, const TranslateFromMLIRFunction &function, - std::function dialectRegistration = + const std::function &dialectRegistration = [](DialectRegistry &) {}); }; struct TranslateRegistration { diff --git a/mlir/lib/Analysis/LoopAnalysis.cpp b/mlir/lib/Analysis/LoopAnalysis.cpp --- a/mlir/lib/Analysis/LoopAnalysis.cpp +++ b/mlir/lib/Analysis/LoopAnalysis.cpp @@ -264,7 +264,7 @@ static bool isVectorizableLoopBodyWithOpCond(AffineForOp loop, - VectorizableOpFun isVectorizableOp, + const VectorizableOpFun &isVectorizableOp, NestedPattern &vectorTransferMatcher) { auto *forOp = loop.getOperation(); diff --git a/mlir/lib/Analysis/NestedMatcher.cpp b/mlir/lib/Analysis/NestedMatcher.cpp --- a/mlir/lib/Analysis/NestedMatcher.cpp +++ b/mlir/lib/Analysis/NestedMatcher.cpp @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +#include + #include "mlir/Analysis/NestedMatcher.h" #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/StandardOps/IR/Ops.h" @@ -55,7 +57,7 @@ NestedPattern::NestedPattern(ArrayRef nested, FilterFunctionType filter) - : nestedPatterns(), filter(filter), skip(nullptr) { + : nestedPatterns(), filter(std::move(filter)), skip(nullptr) { copyNestedToThis(nested); } @@ -132,13 +134,13 @@ namespace matcher { NestedPattern Op(FilterFunctionType filter) { - return NestedPattern({}, filter); + return NestedPattern({}, std::move(filter)); } -NestedPattern If(NestedPattern child) { +NestedPattern If(const NestedPattern &child) { return NestedPattern(child, isAffineIfOp); } -NestedPattern If(FilterFunctionType filter, NestedPattern child) { +NestedPattern If(const FilterFunctionType &filter, const NestedPattern &child) { return NestedPattern(child, [filter](Operation &op) { return isAffineIfOp(op) && filter(op); }); @@ -146,23 +148,26 @@ NestedPattern If(ArrayRef nested) { return NestedPattern(nested, isAffineIfOp); } -NestedPattern If(FilterFunctionType filter, ArrayRef nested) { +NestedPattern If(const FilterFunctionType &filter, + ArrayRef nested) { return NestedPattern(nested, [filter](Operation &op) { return isAffineIfOp(op) && filter(op); }); } -NestedPattern For(NestedPattern child) { +NestedPattern For(const NestedPattern &child) { return NestedPattern(child, isAffineForOp); } -NestedPattern For(FilterFunctionType filter, NestedPattern child) { +NestedPattern For(const FilterFunctionType &filter, + const NestedPattern &child) { return NestedPattern( child, [=](Operation &op) { return isAffineForOp(op) && filter(op); }); } NestedPattern For(ArrayRef nested) { return NestedPattern(nested, isAffineForOp); } -NestedPattern For(FilterFunctionType filter, ArrayRef nested) { +NestedPattern For(const FilterFunctionType &filter, + ArrayRef nested) { return NestedPattern( nested, [=](Operation &op) { return isAffineForOp(op) && filter(op); }); } diff --git a/mlir/lib/Bindings/Python/DialectSparseTensor.cpp b/mlir/lib/Bindings/Python/DialectSparseTensor.cpp --- a/mlir/lib/Bindings/Python/DialectSparseTensor.cpp +++ b/mlir/lib/Bindings/Python/DialectSparseTensor.cpp @@ -17,7 +17,7 @@ using namespace mlir::python::adaptors; void mlir::python::populateDialectSparseTensorSubmodule( - py::module m, const py::module &irModule) { + const py::module &m, const py::module &irModule) { auto attributeClass = irModule.attr("Attribute"); py::enum_(m, "DimLevelType", py::module_local()) diff --git a/mlir/lib/Bindings/Python/Dialects.h b/mlir/lib/Bindings/Python/Dialects.h --- a/mlir/lib/Bindings/Python/Dialects.h +++ b/mlir/lib/Bindings/Python/Dialects.h @@ -15,7 +15,7 @@ namespace python { void populateDialectLinalgSubmodule(pybind11::module m); -void populateDialectSparseTensorSubmodule(pybind11::module m, +void populateDialectSparseTensorSubmodule(const pybind11::module &m, const pybind11::module &irModule); } // namespace python diff --git a/mlir/lib/Bindings/Python/ExecutionEngineModule.cpp b/mlir/lib/Bindings/Python/ExecutionEngineModule.cpp --- a/mlir/lib/Bindings/Python/ExecutionEngineModule.cpp +++ b/mlir/lib/Bindings/Python/ExecutionEngineModule.cpp @@ -42,7 +42,7 @@ // Add an object to the list of referenced objects whose lifetime must exceed // those of the ExecutionEngine. - void addReferencedObject(pybind11::object obj) { + void addReferencedObject(const pybind11::object &obj) { referencedObjects.push_back(obj); } diff --git a/mlir/lib/Bindings/Python/IRAffine.cpp b/mlir/lib/Bindings/Python/IRAffine.cpp --- a/mlir/lib/Bindings/Python/IRAffine.cpp +++ b/mlir/lib/Bindings/Python/IRAffine.cpp @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +#include + #include "IRModule.h" #include "PybindUtils.h" @@ -30,7 +32,8 @@ /// Throws errors in case of failure, using "action" to describe what the caller /// was attempting to do. template -static void pyListToVector(py::list list, llvm::SmallVectorImpl &result, +static void pyListToVector(const py::list &list, + llvm::SmallVectorImpl &result, StringRef action) { result.reserve(py::len(list)); for (py::handle item : list) { @@ -203,7 +206,7 @@ static constexpr const char *pyClassName = "AffineAddExpr"; using PyConcreteAffineExpr::PyConcreteAffineExpr; - static PyAffineAddExpr get(PyAffineExpr lhs, PyAffineExpr rhs) { + static PyAffineAddExpr get(PyAffineExpr lhs, const PyAffineExpr &rhs) { MlirAffineExpr expr = mlirAffineAddExprGet(lhs, rhs); return PyAffineAddExpr(lhs.getContext(), expr); } @@ -232,7 +235,7 @@ static constexpr const char *pyClassName = "AffineMulExpr"; using PyConcreteAffineExpr::PyConcreteAffineExpr; - static PyAffineMulExpr get(PyAffineExpr lhs, PyAffineExpr rhs) { + static PyAffineMulExpr get(PyAffineExpr lhs, const PyAffineExpr &rhs) { MlirAffineExpr expr = mlirAffineMulExprGet(lhs, rhs); return PyAffineMulExpr(lhs.getContext(), expr); } @@ -261,7 +264,7 @@ static constexpr const char *pyClassName = "AffineModExpr"; using PyConcreteAffineExpr::PyConcreteAffineExpr; - static PyAffineModExpr get(PyAffineExpr lhs, PyAffineExpr rhs) { + static PyAffineModExpr get(PyAffineExpr lhs, const PyAffineExpr &rhs) { MlirAffineExpr expr = mlirAffineModExprGet(lhs, rhs); return PyAffineModExpr(lhs.getContext(), expr); } @@ -290,7 +293,7 @@ static constexpr const char *pyClassName = "AffineFloorDivExpr"; using PyConcreteAffineExpr::PyConcreteAffineExpr; - static PyAffineFloorDivExpr get(PyAffineExpr lhs, PyAffineExpr rhs) { + static PyAffineFloorDivExpr get(PyAffineExpr lhs, const PyAffineExpr &rhs) { MlirAffineExpr expr = mlirAffineFloorDivExprGet(lhs, rhs); return PyAffineFloorDivExpr(lhs.getContext(), expr); } @@ -319,7 +322,7 @@ static constexpr const char *pyClassName = "AffineCeilDivExpr"; using PyConcreteAffineExpr::PyConcreteAffineExpr; - static PyAffineCeilDivExpr get(PyAffineExpr lhs, PyAffineExpr rhs) { + static PyAffineCeilDivExpr get(PyAffineExpr lhs, const PyAffineExpr &rhs) { MlirAffineExpr expr = mlirAffineCeilDivExprGet(lhs, rhs); return PyAffineCeilDivExpr(lhs.getContext(), expr); } @@ -375,7 +378,7 @@ public: static constexpr const char *pyClassName = "AffineExprList"; - PyAffineMapExprList(PyAffineMap map, intptr_t startIndex = 0, + PyAffineMapExprList(const PyAffineMap &map, intptr_t startIndex = 0, intptr_t length = -1, intptr_t step = 1) : Sliceable(startIndex, length == -1 ? mlirAffineMapGetNumResults(map) : length, @@ -423,7 +426,8 @@ class PyIntegerSetConstraint { public: - PyIntegerSetConstraint(PyIntegerSet set, intptr_t pos) : set(set), pos(pos) {} + PyIntegerSetConstraint(PyIntegerSet set, intptr_t pos) + : set(std::move(set)), pos(pos) {} PyAffineExpr getExpr() { return PyAffineExpr(set.getContext(), @@ -449,7 +453,7 @@ public: static constexpr const char *pyClassName = "IntegerSetConstraintList"; - PyIntegerSetConstraintList(PyIntegerSet set, intptr_t startIndex = 0, + PyIntegerSetConstraintList(const PyIntegerSet &set, intptr_t startIndex = 0, intptr_t length = -1, intptr_t step = 1) : Sliceable(startIndex, length == -1 ? mlirIntegerSetGetNumConstraints(set) : length, @@ -693,7 +697,8 @@ DefaultingPyMlirContext context) { SmallVector affineExprs; pyListToVector( - exprs, affineExprs, "attempting to create an AffineMap"); + std::move(exprs), affineExprs, + "attempting to create an AffineMap"); MlirAffineMap map = mlirAffineMapGet(context->get(), dimCount, symbolCount, affineExprs.size(), affineExprs.data()); diff --git a/mlir/lib/Bindings/Python/IRAttributes.cpp b/mlir/lib/Bindings/Python/IRAttributes.cpp --- a/mlir/lib/Bindings/Python/IRAttributes.cpp +++ b/mlir/lib/Bindings/Python/IRAttributes.cpp @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +#include + #include "IRModule.h" #include "PybindUtils.h" @@ -116,7 +118,7 @@ class PyArrayAttributeIterator { public: - PyArrayAttributeIterator(PyAttribute attr) : attr(attr) {} + PyArrayAttributeIterator(PyAttribute attr) : attr(std::move(attr)) {} PyArrayAttributeIterator &dunderIter() { return *this; } @@ -459,7 +461,7 @@ arrayInfo.format); } - static PyDenseElementsAttribute getSplat(PyType shapedType, + static PyDenseElementsAttribute getSplat(const PyType &shapedType, PyAttribute &elementAttr) { auto contextWrapper = PyMlirContext::forContext(mlirTypeGetContext(shapedType)); diff --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp --- a/mlir/lib/Bindings/Python/IRCore.cpp +++ b/mlir/lib/Bindings/Python/IRCore.cpp @@ -21,6 +21,8 @@ #include "llvm/ADT/SmallVector.h" #include +#include + namespace py = pybind11; using namespace mlir; using namespace mlir::python; @@ -178,7 +180,7 @@ mlirEnableGlobalDebug(enable); } - static bool get(py::object) { return mlirIsGlobalDebugEnabled(); } + static bool get(const py::object &) { return mlirIsGlobalDebugEnabled(); } static void bind(py::module &m) { // Debug flags. @@ -322,7 +324,7 @@ throw SetPyError(PyExc_IndexError, "attempt to access out of bounds block"); } - PyBlock appendBlock(py::args pyArgTypes) { + PyBlock appendBlock(const py::args &pyArgTypes) { operation->checkValid(); llvm::SmallVector argTypes; argTypes.reserve(pyArgTypes.size()); @@ -505,9 +507,9 @@ return PyThreadContextEntry::pushContext(*this); } -void PyMlirContext::contextExit(pybind11::object /*excType*/, - pybind11::object /*excVal*/, - pybind11::object /*excTb*/) { +void PyMlirContext::contextExit(const pybind11::object & /*excType*/, + const pybind11::object & /*excVal*/, + const pybind11::object & /*excTb*/) { PyThreadContextEntry::popContext(*this); } @@ -691,8 +693,9 @@ return PyThreadContextEntry::pushLocation(*this); } -void PyLocation::contextExit(py::object /*excType*/, py::object /*excVal*/, - py::object /*excTb*/) { +void PyLocation::contextExit(const py::object & /*excType*/, + const py::object & /*excVal*/, + const py::object & /*excTb*/) { PyThreadContextEntry::popLocation(*this); } @@ -947,11 +950,11 @@ } py::object PyOperation::create( - std::string name, llvm::Optional> results, + const std::string &name, llvm::Optional> results, llvm::Optional> operands, llvm::Optional attributes, llvm::Optional> successors, int regions, - DefaultingPyLocation location, py::object maybeIp) { + DefaultingPyLocation location, const py::object &maybeIp) { llvm::SmallVector mlirOperands; llvm::SmallVector mlirResults; llvm::SmallVector mlirSuccessors; @@ -1107,7 +1110,7 @@ //------------------------------------------------------------------------------ py::object -PyOpView::buildGeneric(py::object cls, py::list resultTypeList, +PyOpView::buildGeneric(const py::object &cls, py::list resultTypeList, py::list operandList, llvm::Optional attributes, llvm::Optional> successors, @@ -1361,16 +1364,17 @@ /*operands=*/std::move(operands), /*attributes=*/std::move(attributes), /*successors=*/std::move(successors), - /*regions=*/*regions, location, maybeIp); + /*regions=*/*regions, location, + std::move(maybeIp)); } -PyOpView::PyOpView(py::object operationObject) +PyOpView::PyOpView(const py::object &operationObject) // Casting through the PyOperationBase base-class and then back to the // Operation lets us accept any PyOperationBase subclass. : operation(py::cast(operationObject).getOperation()), operationObject(operation.getRef().getObject()) {} -py::object PyOpView::createRawSubclass(py::object userClass) { +py::object PyOpView::createRawSubclass(const py::object &userClass) { // This is... a little gross. The typical pattern is to have a pure python // class that extends OpView like: // class AddFOp(_cext.ir.OpView): @@ -1467,9 +1471,9 @@ return PyThreadContextEntry::pushInsertionPoint(*this); } -void PyInsertionPoint::contextExit(pybind11::object /*excType*/, - pybind11::object /*excVal*/, - pybind11::object /*excTb*/) { +void PyInsertionPoint::contextExit(const pybind11::object & /*excType*/, + const pybind11::object & /*excVal*/, + const pybind11::object & /*excTb*/) { PyThreadContextEntry::popInsertionPoint(*this); } @@ -1956,7 +1960,8 @@ /// attributes, or by index, producing named attributes. class PyOpAttributeMap { public: - PyOpAttributeMap(PyOperationRef operation) : operation(operation) {} + PyOpAttributeMap(PyOperationRef operation) + : operation(std::move(operation)) {} PyAttribute dunderGetItemNamed(const std::string &name) { MlirAttribute attr = mlirOperationGetAttributeByName(operation->get(), @@ -1981,7 +1986,7 @@ mlirIdentifierStr(namedAttr.name).length)); } - void dunderSetItem(const std::string &name, PyAttribute attr) { + void dunderSetItem(const std::string &name, const PyAttribute &attr) { mlirOperationSetAttributeByName(operation->get(), toMlirStringRef(name), attr); } diff --git a/mlir/lib/Bindings/Python/IRInterfaces.cpp b/mlir/lib/Bindings/Python/IRInterfaces.cpp --- a/mlir/lib/Bindings/Python/IRInterfaces.cpp +++ b/mlir/lib/Bindings/Python/IRInterfaces.cpp @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +#include + #include "IRModule.h" #include "mlir-c/BuiltinAttributes.h" #include "mlir-c/Interfaces.h" @@ -58,7 +60,7 @@ /// operation or a subclass of OpView. In the latter case, only the static /// methods of the interface are accessible to the caller. PyConcreteOpInterface(py::object object, DefaultingPyMlirContext context) - : obj(object) { + : obj(std::move(object)) { try { operation = &py::cast(obj); } catch (py::cast_error &err) { diff --git a/mlir/lib/Bindings/Python/IRModule.h b/mlir/lib/Bindings/Python/IRModule.h --- a/mlir/lib/Bindings/Python/IRModule.h +++ b/mlir/lib/Bindings/Python/IRModule.h @@ -203,8 +203,9 @@ /// Enter and exit the context manager. pybind11::object contextEnter(); - void contextExit(pybind11::object excType, pybind11::object excVal, - pybind11::object excTb); + void contextExit(const pybind11::object &excType, + const pybind11::object &excVal, + const pybind11::object &excTb); private: PyMlirContext(MlirContext context); @@ -316,8 +317,9 @@ /// Enter and exit the context manager. pybind11::object contextEnter(); - void contextExit(pybind11::object excType, pybind11::object excVal, - pybind11::object excTb); + void contextExit(const pybind11::object &excType, + const pybind11::object &excVal, + const pybind11::object &excTb); /// Gets a capsule wrapping the void* within the MlirLocation. pybind11::object getCapsule(); @@ -482,11 +484,11 @@ /// Creates an operation. See corresponding python docstring. static pybind11::object - create(std::string name, llvm::Optional> results, + create(const std::string &name, llvm::Optional> results, llvm::Optional> operands, llvm::Optional attributes, llvm::Optional> successors, int regions, - DefaultingPyLocation location, pybind11::object ip); + DefaultingPyLocation location, const pybind11::object &ip); /// Creates an OpView suitable for this operation. pybind11::object createOpView(); @@ -524,15 +526,15 @@ /// python types. class PyOpView : public PyOperationBase { public: - PyOpView(pybind11::object operationObject); + PyOpView(const pybind11::object &operationObject); PyOperation &getOperation() override { return operation; } - static pybind11::object createRawSubclass(pybind11::object userClass); + static pybind11::object createRawSubclass(const pybind11::object &userClass); pybind11::object getOperationObject() { return operationObject; } static pybind11::object - buildGeneric(pybind11::object cls, pybind11::list resultTypeList, + buildGeneric(const pybind11::object &cls, pybind11::list resultTypeList, pybind11::list operandList, llvm::Optional attributes, llvm::Optional> successors, @@ -607,8 +609,9 @@ /// Enter and exit the context manager. pybind11::object contextEnter(); - void contextExit(pybind11::object excType, pybind11::object excVal, - pybind11::object excTb); + void contextExit(const pybind11::object &excType, + const pybind11::object &excVal, + const pybind11::object &excTb); PyBlock &getBlock() { return block; } diff --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp --- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp +++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp @@ -34,7 +34,7 @@ template static arith::ConstantOp -createConstFromIntAttribute(Operation *op, std::string attrName, +createConstFromIntAttribute(Operation *op, const std::string &attrName, Type requiredAttrType, OpBuilder &rewriter) { auto castedN = static_cast( op->getAttr(attrName).cast().getValue().getSExtValue()); @@ -92,7 +92,7 @@ .result(); } -static SmallVector filterDynamicDims(SmallVector dynDims) { +static SmallVector filterDynamicDims(const SmallVector &dynDims) { SmallVector filteredDims; for (auto dim : dynDims) if (dim) diff --git a/mlir/lib/Dialect/Arithmetic/IR/ArithmeticOps.cpp b/mlir/lib/Dialect/Arithmetic/IR/ArithmeticOps.cpp --- a/mlir/lib/Dialect/Arithmetic/IR/ArithmeticOps.cpp +++ b/mlir/lib/Dialect/Arithmetic/IR/ArithmeticOps.cpp @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +#include + #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h" #include "mlir/Dialect/CommonFolders.h" #include "mlir/IR/Builders.h" @@ -190,8 +192,8 @@ if (matchPattern(getRhs(), m_Zero())) return getLhs(); - return constFoldBinaryOp(operands, - [](APInt a, APInt b) { return a + b; }); + return constFoldBinaryOp( + operands, [](APInt a, const APInt &b) { return std::move(a) + b; }); } void arith::AddIOp::getCanonicalizationPatterns( @@ -212,8 +214,8 @@ if (matchPattern(getRhs(), m_Zero())) return getLhs(); - return constFoldBinaryOp(operands, - [](APInt a, APInt b) { return a - b; }); + return constFoldBinaryOp( + operands, [](APInt a, const APInt &b) { return std::move(a) - b; }); } void arith::SubIOp::getCanonicalizationPatterns( @@ -237,8 +239,8 @@ // TODO: Handle the overflow case. // default folder - return constFoldBinaryOp(operands, - [](APInt a, APInt b) { return a * b; }); + return constFoldBinaryOp( + operands, [](const APInt &a, const APInt &b) { return a * b; }); } //===----------------------------------------------------------------------===// @@ -248,13 +250,14 @@ OpFoldResult arith::DivUIOp::fold(ArrayRef operands) { // Don't fold if it would require a division by zero. bool div0 = false; - auto result = constFoldBinaryOp(operands, [&](APInt a, APInt b) { - if (div0 || !b) { - div0 = true; - return a; - } - return a.udiv(b); - }); + auto result = + constFoldBinaryOp(operands, [&](APInt a, const APInt &b) { + if (div0 || !b) { + div0 = true; + return a; + } + return a.udiv(b); + }); // Fold out division by one. Assumes all tensors of all ones are splats. if (auto rhs = operands[1].dyn_cast_or_null()) { @@ -275,13 +278,14 @@ OpFoldResult arith::DivSIOp::fold(ArrayRef operands) { // Don't fold if it would overflow or if it requires a division by zero. bool overflowOrDiv0 = false; - auto result = constFoldBinaryOp(operands, [&](APInt a, APInt b) { - if (overflowOrDiv0 || !b) { - overflowOrDiv0 = true; - return a; - } - return a.sdiv_ov(b, overflowOrDiv0); - }); + auto result = + constFoldBinaryOp(operands, [&](APInt a, const APInt &b) { + if (overflowOrDiv0 || !b) { + overflowOrDiv0 = true; + return a; + } + return a.sdiv_ov(b, overflowOrDiv0); + }); // Fold out division by one. Assumes all tensors of all ones are splats. if (auto rhs = operands[1].dyn_cast_or_null()) { @@ -299,7 +303,8 @@ // Ceil and floor division folding helpers //===----------------------------------------------------------------------===// -static APInt signedCeilNonnegInputs(APInt a, APInt b, bool &overflow) { +static APInt signedCeilNonnegInputs(const APInt &a, const APInt &b, + bool &overflow) { // Returns (a-1)/b + 1 APInt one(a.getBitWidth(), 1, true); // Signed value 1. APInt val = a.ssub_ov(one, overflow).sdiv_ov(b, overflow); @@ -312,17 +317,18 @@ OpFoldResult arith::CeilDivUIOp::fold(ArrayRef operands) { bool overflowOrDiv0 = false; - auto result = constFoldBinaryOp(operands, [&](APInt a, APInt b) { - if (overflowOrDiv0 || !b) { - overflowOrDiv0 = true; - return a; - } - APInt quotient = a.udiv(b); - if (!a.urem(b)) - return quotient; - APInt one(a.getBitWidth(), 1, true); - return quotient.uadd_ov(one, overflowOrDiv0); - }); + auto result = + constFoldBinaryOp(operands, [&](APInt a, const APInt &b) { + if (overflowOrDiv0 || !b) { + overflowOrDiv0 = true; + return a; + } + APInt quotient = a.udiv(b); + if (!a.urem(b)) + return quotient; + APInt one(a.getBitWidth(), 1, true); + return quotient.uadd_ov(one, overflowOrDiv0); + }); // Fold out ceil division by one. Assumes all tensors of all ones are // splats. if (auto rhs = operands[1].dyn_cast_or_null()) { @@ -343,34 +349,35 @@ OpFoldResult arith::CeilDivSIOp::fold(ArrayRef operands) { // Don't fold if it would overflow or if it requires a division by zero. bool overflowOrDiv0 = false; - auto result = constFoldBinaryOp(operands, [&](APInt a, APInt b) { - if (overflowOrDiv0 || !b) { - overflowOrDiv0 = true; - return a; - } - unsigned bits = a.getBitWidth(); - APInt zero = APInt::getZero(bits); - if (a.sgt(zero) && b.sgt(zero)) { - // Both positive, return ceil(a, b). - return signedCeilNonnegInputs(a, b, overflowOrDiv0); - } - if (a.slt(zero) && b.slt(zero)) { - // Both negative, return ceil(-a, -b). - APInt posA = zero.ssub_ov(a, overflowOrDiv0); - APInt posB = zero.ssub_ov(b, overflowOrDiv0); - return signedCeilNonnegInputs(posA, posB, overflowOrDiv0); - } - if (a.slt(zero) && b.sgt(zero)) { - // A is negative, b is positive, return - ( -a / b). - APInt posA = zero.ssub_ov(a, overflowOrDiv0); - APInt div = posA.sdiv_ov(b, overflowOrDiv0); - return zero.ssub_ov(div, overflowOrDiv0); - } - // A is positive (or zero), b is negative, return - (a / -b). - APInt posB = zero.ssub_ov(b, overflowOrDiv0); - APInt div = a.sdiv_ov(posB, overflowOrDiv0); - return zero.ssub_ov(div, overflowOrDiv0); - }); + auto result = + constFoldBinaryOp(operands, [&](APInt a, const APInt &b) { + if (overflowOrDiv0 || !b) { + overflowOrDiv0 = true; + return a; + } + unsigned bits = a.getBitWidth(); + APInt zero = APInt::getZero(bits); + if (a.sgt(zero) && b.sgt(zero)) { + // Both positive, return ceil(a, b). + return signedCeilNonnegInputs(a, b, overflowOrDiv0); + } + if (a.slt(zero) && b.slt(zero)) { + // Both negative, return ceil(-a, -b). + APInt posA = zero.ssub_ov(a, overflowOrDiv0); + APInt posB = zero.ssub_ov(b, overflowOrDiv0); + return signedCeilNonnegInputs(posA, posB, overflowOrDiv0); + } + if (a.slt(zero) && b.sgt(zero)) { + // A is negative, b is positive, return - ( -a / b). + APInt posA = zero.ssub_ov(a, overflowOrDiv0); + APInt div = posA.sdiv_ov(b, overflowOrDiv0); + return zero.ssub_ov(div, overflowOrDiv0); + } + // A is positive (or zero), b is negative, return - (a / -b). + APInt posB = zero.ssub_ov(b, overflowOrDiv0); + APInt div = a.sdiv_ov(posB, overflowOrDiv0); + return zero.ssub_ov(div, overflowOrDiv0); + }); // Fold out ceil division by one. Assumes all tensors of all ones are // splats. @@ -392,34 +399,35 @@ OpFoldResult arith::FloorDivSIOp::fold(ArrayRef operands) { // Don't fold if it would overflow or if it requires a division by zero. bool overflowOrDiv0 = false; - auto result = constFoldBinaryOp(operands, [&](APInt a, APInt b) { - if (overflowOrDiv0 || !b) { - overflowOrDiv0 = true; - return a; - } - unsigned bits = a.getBitWidth(); - APInt zero = APInt::getZero(bits); - if (a.sge(zero) && b.sgt(zero)) { - // Both positive (or a is zero), return a / b. - return a.sdiv_ov(b, overflowOrDiv0); - } - if (a.sle(zero) && b.slt(zero)) { - // Both negative (or a is zero), return -a / -b. - APInt posA = zero.ssub_ov(a, overflowOrDiv0); - APInt posB = zero.ssub_ov(b, overflowOrDiv0); - return posA.sdiv_ov(posB, overflowOrDiv0); - } - if (a.slt(zero) && b.sgt(zero)) { - // A is negative, b is positive, return - ceil(-a, b). - APInt posA = zero.ssub_ov(a, overflowOrDiv0); - APInt ceil = signedCeilNonnegInputs(posA, b, overflowOrDiv0); - return zero.ssub_ov(ceil, overflowOrDiv0); - } - // A is positive, b is negative, return - ceil(a, -b). - APInt posB = zero.ssub_ov(b, overflowOrDiv0); - APInt ceil = signedCeilNonnegInputs(a, posB, overflowOrDiv0); - return zero.ssub_ov(ceil, overflowOrDiv0); - }); + auto result = + constFoldBinaryOp(operands, [&](APInt a, const APInt &b) { + if (overflowOrDiv0 || !b) { + overflowOrDiv0 = true; + return a; + } + unsigned bits = a.getBitWidth(); + APInt zero = APInt::getZero(bits); + if (a.sge(zero) && b.sgt(zero)) { + // Both positive (or a is zero), return a / b. + return a.sdiv_ov(b, overflowOrDiv0); + } + if (a.sle(zero) && b.slt(zero)) { + // Both negative (or a is zero), return -a / -b. + APInt posA = zero.ssub_ov(a, overflowOrDiv0); + APInt posB = zero.ssub_ov(b, overflowOrDiv0); + return posA.sdiv_ov(posB, overflowOrDiv0); + } + if (a.slt(zero) && b.sgt(zero)) { + // A is negative, b is positive, return - ceil(-a, b). + APInt posA = zero.ssub_ov(a, overflowOrDiv0); + APInt ceil = signedCeilNonnegInputs(posA, b, overflowOrDiv0); + return zero.ssub_ov(ceil, overflowOrDiv0); + } + // A is positive, b is negative, return - ceil(a, -b). + APInt posB = zero.ssub_ov(b, overflowOrDiv0); + APInt ceil = signedCeilNonnegInputs(a, posB, overflowOrDiv0); + return zero.ssub_ov(ceil, overflowOrDiv0); + }); // Fold out floor division by one. Assumes all tensors of all ones are // splats. @@ -495,8 +503,8 @@ if (matchPattern(getRhs(), m_ConstantInt(&intValue)) && intValue.isAllOnes()) return getLhs(); - return constFoldBinaryOp(operands, - [](APInt a, APInt b) { return a & b; }); + return constFoldBinaryOp( + operands, [](APInt a, const APInt &b) { return std::move(a) & b; }); } //===----------------------------------------------------------------------===// @@ -512,8 +520,8 @@ if (rhsAttr.getValue().isAllOnes()) return rhsAttr; - return constFoldBinaryOp(operands, - [](APInt a, APInt b) { return a | b; }); + return constFoldBinaryOp( + operands, [](APInt a, const APInt &b) { return std::move(a) | b; }); } //===----------------------------------------------------------------------===// @@ -528,8 +536,8 @@ if (getLhs() == getRhs()) return Builder(getContext()).getZeroAttr(getType()); - return constFoldBinaryOp(operands, - [](APInt a, APInt b) { return a ^ b; }); + return constFoldBinaryOp( + operands, [](APInt a, const APInt &b) { return std::move(a) ^ b; }); } void arith::XOrIOp::getCanonicalizationPatterns( @@ -543,7 +551,7 @@ OpFoldResult arith::AddFOp::fold(ArrayRef operands) { return constFoldBinaryOp( - operands, [](APFloat a, APFloat b) { return a + b; }); + operands, [](const APFloat &a, const APFloat &b) { return a + b; }); } //===----------------------------------------------------------------------===// @@ -552,7 +560,7 @@ OpFoldResult arith::SubFOp::fold(ArrayRef operands) { return constFoldBinaryOp( - operands, [](APFloat a, APFloat b) { return a - b; }); + operands, [](const APFloat &a, const APFloat &b) { return a - b; }); } //===----------------------------------------------------------------------===// @@ -577,8 +585,10 @@ intValue.isMinSignedValue()) return getLhs(); - return constFoldBinaryOp( - operands, [](APInt a, APInt b) { return llvm::APIntOps::smax(a, b); }); + return constFoldBinaryOp(operands, + [](const APInt &a, const APInt &b) { + return llvm::APIntOps::smax(a, b); + }); } //===----------------------------------------------------------------------===// @@ -601,8 +611,10 @@ if (matchPattern(getRhs(), m_ConstantInt(&intValue)) && intValue.isMinValue()) return getLhs(); - return constFoldBinaryOp( - operands, [](APInt a, APInt b) { return llvm::APIntOps::umax(a, b); }); + return constFoldBinaryOp(operands, + [](const APInt &a, const APInt &b) { + return llvm::APIntOps::umax(a, b); + }); } //===----------------------------------------------------------------------===// @@ -627,8 +639,10 @@ intValue.isMaxSignedValue()) return getLhs(); - return constFoldBinaryOp( - operands, [](APInt a, APInt b) { return llvm::APIntOps::smin(a, b); }); + return constFoldBinaryOp(operands, + [](const APInt &a, const APInt &b) { + return llvm::APIntOps::smin(a, b); + }); } //===----------------------------------------------------------------------===// @@ -651,8 +665,10 @@ if (matchPattern(getRhs(), m_ConstantInt(&intValue)) && intValue.isMaxValue()) return getLhs(); - return constFoldBinaryOp( - operands, [](APInt a, APInt b) { return llvm::APIntOps::umin(a, b); }); + return constFoldBinaryOp(operands, + [](const APInt &a, const APInt &b) { + return llvm::APIntOps::umin(a, b); + }); } //===----------------------------------------------------------------------===// @@ -661,7 +677,7 @@ OpFoldResult arith::MulFOp::fold(ArrayRef operands) { return constFoldBinaryOp( - operands, [](APFloat a, APFloat b) { return a * b; }); + operands, [](const APFloat &a, const APFloat &b) { return a * b; }); } //===----------------------------------------------------------------------===// @@ -670,7 +686,7 @@ OpFoldResult arith::DivFOp::fold(ArrayRef operands) { return constFoldBinaryOp( - operands, [](APFloat a, APFloat b) { return a / b; }); + operands, [](const APFloat &a, const APFloat &b) { return a / b; }); } //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Dialect/Async/Transforms/AsyncParallelFor.cpp b/mlir/lib/Dialect/Async/Transforms/AsyncParallelFor.cpp --- a/mlir/lib/Dialect/Async/Transforms/AsyncParallelFor.cpp +++ b/mlir/lib/Dialect/Async/Transforms/AsyncParallelFor.cpp @@ -10,6 +10,8 @@ // //===----------------------------------------------------------------------===// +#include + #include "PassDetail.h" #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h" #include "mlir/Dialect/Async/IR/Async.h" @@ -111,7 +113,7 @@ AsyncMinTaskSizeComputationFunction computeMinTaskSize) : OpRewritePattern(ctx), asyncDispatch(asyncDispatch), numWorkerThreads(numWorkerThreads), - computeMinTaskSize(computeMinTaskSize) {} + computeMinTaskSize(std::move(computeMinTaskSize)) {} LogicalResult matchAndRewrite(scf::ParallelOp op, PatternRewriter &rewriter) const override; @@ -244,7 +246,7 @@ // Create a parallel compute fuction from the parallel operation. static ParallelComputeFunction createParallelComputeFunction( - scf::ParallelOp op, ParallelComputeFunctionBounds bounds, + scf::ParallelOp op, const ParallelComputeFunctionBounds &bounds, unsigned numBlockAlignedInnerLoops, PatternRewriter &rewriter) { OpBuilder::InsertionGuard guard(rewriter); ImplicitLocOpBuilder b(op.getLoc(), rewriter); @@ -904,7 +906,7 @@ void mlir::async::populateAsyncParallelForPatterns( RewritePatternSet &patterns, bool asyncDispatch, int32_t numWorkerThreads, - AsyncMinTaskSizeComputationFunction computeMinTaskSize) { + const AsyncMinTaskSizeComputationFunction &computeMinTaskSize) { MLIRContext *ctx = patterns.getContext(); patterns.add(ctx, asyncDispatch, numWorkerThreads, computeMinTaskSize); diff --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp b/mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp --- a/mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp +++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp @@ -64,7 +64,7 @@ /// Walks over all immediate return-like terminators in the given region. static LogicalResult walkReturnOperations(Region *region, - std::function func) { + const std::function &func) { for (Block &block : *region) { Operation *terminator = block.getTerminator(); // Skip non region-return-like terminators. 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 @@ -78,7 +78,8 @@ /// is updated with results that will be available after sinking the identified /// ops. static bool -extractBeneficiaryOps(Operation *op, SetVector existingDependencies, +extractBeneficiaryOps(Operation *op, + const SetVector &existingDependencies, SetVector &beneficiaryOps, llvm::SmallPtrSetImpl &availableValues) { if (beneficiaryOps.count(op)) 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 @@ -313,7 +313,7 @@ ElementsAttr caseValues, SuccessorRange caseDestinations, OperandRangeRange caseOperands, - TypeRangeRange caseOperandTypes) { + const TypeRangeRange &caseOperandTypes) { if (!caseValues) return; @@ -361,7 +361,8 @@ LogicalResult verifySymbolAttribute( Operation *op, StringRef attributeName, - std::function verifySymbolType) { + const std::function + &verifySymbolType) { if (Attribute attribute = op->getAttr(attributeName)) { // The attribute is already verified to be a symbol ref array attribute via // a constraint in the operation definition. diff --git a/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/BufferizableOpInterface.cpp b/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/BufferizableOpInterface.cpp --- a/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/BufferizableOpInterface.cpp +++ b/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/BufferizableOpInterface.cpp @@ -285,7 +285,7 @@ llvm::SetVector mlir::linalg::comprehensive_bufferize::BufferizationState:: findValueInReverseUseDefChain(Value value, - std::function condition) { + const std::function &condition) { llvm::SetVector result, workingSet; workingSet.insert(value); diff --git a/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/SCFInterfaceImpl.cpp b/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/SCFInterfaceImpl.cpp --- a/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/SCFInterfaceImpl.cpp +++ b/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/SCFInterfaceImpl.cpp @@ -297,7 +297,7 @@ // Given a range of values, apply `func` to those marked in `indices`. // Otherwise, store the unmodified value in the result vector. auto convert = [&](ValueRange values, - std::function func) { + const std::function &func) { SmallVector result; for (const auto &it : llvm::enumerate(values)) { size_t idx = it.index(); diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp --- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp @@ -50,7 +50,7 @@ static void fillStructuredOpRegion( OpBuilder &opBuilder, Region ®ion, TypeRange inputTypes, TypeRange outputTypes, - std::function errorHandler = nullptr); + const std::function &errorHandler = nullptr); /// Generic entry point to create both the region and the block of a LinalgOp. template @@ -323,7 +323,7 @@ builder.create(first.getLoc(), values); } - Value constant(std::string value) { + Value constant(const std::string &value) { OpBuilder builder = getBuilder(); Location loc = builder.getUnknownLoc(); Attribute valueAttr = parseAttribute(value, builder.getContext()); @@ -2407,10 +2407,10 @@ /// to the elemental types of `inputTypes` and `outputTypes`, which are asserted /// to be ShapedType. template -static void -fillStructuredOpRegion(OpBuilder &opBuilder, Region ®ion, - TypeRange inputTypes, TypeRange outputTypes, - std::function errorHandler) { +static void fillStructuredOpRegion( + OpBuilder &opBuilder, Region ®ion, TypeRange inputTypes, + TypeRange outputTypes, + const std::function &errorHandler) { assert(llvm::all_of(outputTypes, [](Type t) { return t.isa(); })); // TODO: atm all operands go through getElementTypeOrSelf, diff --git a/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp b/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp @@ -16,6 +16,7 @@ #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include #include +#include using namespace mlir; using namespace mlir::linalg; @@ -97,7 +98,7 @@ : ConversionPattern(converter, MatchTraitOpTypeTag(), TypeID::get(), /*benefit=*/1, ctx), - blockArgsToDetensor(blockArgsToDetensor) {} + blockArgsToDetensor(std::move(blockArgsToDetensor)) {} LogicalResult matchAndRewrite(Operation *op, ArrayRef /*operands*/, diff --git a/mlir/lib/Dialect/Linalg/Transforms/Distribution.cpp b/mlir/lib/Dialect/Linalg/Transforms/Distribution.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/Distribution.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Distribution.cpp @@ -11,6 +11,8 @@ // //===----------------------------------------------------------------------===// // +#include + #include "mlir/Dialect/Linalg/Transforms/Transforms.h" #include "mlir/Dialect/Linalg/Utils/Utils.h" #include "mlir/IR/MLIRContext.h" @@ -31,8 +33,8 @@ DistributeTiledLoopPattern(MLIRContext *context, LinalgLoopDistributionOptions options, LinalgTransformationFilter marker) - : OpRewritePattern(context), options(options), - marker(marker) {} + : OpRewritePattern(context), + options(std::move(options)), marker(std::move(marker)) {} LogicalResult matchAndRewrite(linalg::TiledLoopOp op, PatternRewriter &rewriter) const override { if (failed(marker.checkAndNotify(rewriter, op))) diff --git a/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp b/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp @@ -9,6 +9,8 @@ // This file implements the linalg dialect Fusion on tensors operations pass. // //===----------------------------------------------------------------------===// +#include + #include "PassDetail.h" #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Linalg/IR/Linalg.h" @@ -1078,7 +1080,7 @@ MLIRContext *context, ControlElementwiseOpsFusionFn foldReshapes, PatternBenefit benefit = 1) : OpRewritePattern(context, benefit), - controlFoldingReshapes(foldReshapes) {} + controlFoldingReshapes(std::move(foldReshapes)) {} LogicalResult matchAndRewrite(GenericOp genericOp, PatternRewriter &rewriter) const override { @@ -1181,7 +1183,7 @@ MLIRContext *context, ControlElementwiseOpsFusionFn foldReshapes, PatternBenefit benefit = 1) : OpRewritePattern(context, benefit), - controlFoldingReshapes(foldReshapes) {} + controlFoldingReshapes(std::move(foldReshapes)) {} LogicalResult matchAndRewrite(tensor::ExpandShapeOp reshapeOp, PatternRewriter &rewriter) const override { @@ -1755,7 +1757,7 @@ void mlir::linalg::populateFoldReshapeOpsByExpansionPatterns( RewritePatternSet &patterns, - ControlElementwiseOpsFusionFn controlFoldingReshapes) { + const ControlElementwiseOpsFusionFn &controlFoldingReshapes) { patterns.add(patterns.getContext(), controlFoldingReshapes); patterns.add(patterns.getContext(), diff --git a/mlir/lib/Dialect/Linalg/Transforms/Generalization.cpp b/mlir/lib/Dialect/Linalg/Transforms/Generalization.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/Generalization.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Generalization.cpp @@ -78,7 +78,7 @@ } void mlir::linalg::populateLinalgNamedOpsGeneralizationPatterns( - RewritePatternSet &patterns, LinalgTransformationFilter marker) { + RewritePatternSet &patterns, const LinalgTransformationFilter &marker) { patterns.add(patterns.getContext(), marker); } diff --git a/mlir/lib/Dialect/Linalg/Transforms/LinalgStrategyPasses.cpp b/mlir/lib/Dialect/Linalg/Transforms/LinalgStrategyPasses.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/LinalgStrategyPasses.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/LinalgStrategyPasses.cpp @@ -11,6 +11,8 @@ // //===----------------------------------------------------------------------===// +#include + #include "PassDetail.h" #include "mlir/Analysis/SliceAnalysis.h" #include "mlir/Dialect/Affine/IR/AffineOps.h" @@ -46,7 +48,7 @@ LinalgStrategyTileAndFusePass(StringRef opName, LinalgTilingAndFusionOptions opt, LinalgTransformationFilter filt) - : options(opt), filter(filt) { + : options(std::move(opt)), filter(std::move(filt)) { this->anchorOpName.setValue(opName.str()); } @@ -82,7 +84,7 @@ LinalgStrategyTilePass(StringRef opName, LinalgTilingOptions opt, LinalgTransformationFilter filt) - : options(opt), filter(filt) { + : options(std::move(opt)), filter(std::move(filt)) { this->anchorOpName.setValue(opName.str()); } @@ -114,7 +116,7 @@ LinalgStrategyPadPass(StringRef opName, LinalgPaddingOptions opt, LinalgTransformationFilter filt) - : options(opt), filter(filt) { + : options(std::move(opt)), filter(std::move(filt)) { this->anchorOpName.setValue(opName.str()); } @@ -146,7 +148,7 @@ LinalgStrategyGeneralizePass(StringRef opName, LinalgTransformationFilter filter) - : filter(filter) { + : filter(std::move(filter)) { this->anchorOpName.setValue(opName.str()); } @@ -179,7 +181,7 @@ LinalgStrategyDecomposePass() = default; LinalgStrategyDecomposePass(LinalgTransformationFilter filter) - : filter(filter) {} + : filter(std::move(filter)) {} void runOnFunction() override { auto funcOp = getFunction(); @@ -205,7 +207,7 @@ LinalgTransformationFilter filter) : iteratorInterchange(iteratorInterchange.begin(), iteratorInterchange.end()), - filter(filter) {} + filter(std::move(filter)) {} void runOnFunction() override { auto funcOp = getFunction(); @@ -234,7 +236,7 @@ LinalgStrategyPromotePass(StringRef opName, LinalgPromotionOptions opt, LinalgTransformationFilter filt) - : options(opt), filter(filt) { + : options(std::move(opt)), filter(std::move(filt)) { this->anchorOpName.setValue(opName.str()); } @@ -267,7 +269,7 @@ LinalgStrategyVectorizePass(StringRef opName, LinalgVectorizationOptions opt, LinalgTransformationFilter filt, bool padVectorize = false) - : options(opt), filter(filt) { + : options(opt), filter(std::move(filt)) { this->anchorOpName.setValue(opName.str()); this->vectorizePadding.setValue(padVectorize); } @@ -320,7 +322,7 @@ LinalgStrategyEnablePass(LinalgEnablingOptions opt, LinalgTransformationFilter filt) - : options(opt), filter(filt) {} + : options(opt), filter(std::move(filt)) {} void runOnFunction() override { auto funcOp = getFunction(); @@ -370,7 +372,7 @@ LinalgStrategyLowerVectorsPass(LinalgVectorLoweringOptions opt, LinalgTransformationFilter filt) - : options(opt), filter(filt) {} + : options(opt), filter(std::move(filt)) {} void runOnFunction() override { auto funcOp = getFunction(); @@ -446,53 +448,54 @@ /// Create a LinalgStrategyTileAndFusePass. std::unique_ptr> -mlir::createLinalgStrategyTileAndFusePass(StringRef opName, - LinalgTilingAndFusionOptions options, - LinalgTransformationFilter filter) { +mlir::createLinalgStrategyTileAndFusePass( + StringRef opName, const LinalgTilingAndFusionOptions &options, + const LinalgTransformationFilter &filter) { return std::make_unique(opName, options, filter); } /// Create a LinalgStrategyTilePass. std::unique_ptr> -mlir::createLinalgStrategyTilePass(StringRef opName, LinalgTilingOptions opt, - LinalgTransformationFilter filter) { +mlir::createLinalgStrategyTilePass(StringRef opName, + const LinalgTilingOptions &opt, + const LinalgTransformationFilter &filter) { return std::make_unique(opName, opt, filter); } /// Create a LinalgStrategyPadPass. std::unique_ptr> -mlir::createLinalgStrategyPadPass(StringRef opName, LinalgPaddingOptions opt, - LinalgTransformationFilter filter) { +mlir::createLinalgStrategyPadPass(StringRef opName, + const LinalgPaddingOptions &opt, + const LinalgTransformationFilter &filter) { return std::make_unique(opName, opt, filter); } /// Create a LinalgStrategyPromotePass. -std::unique_ptr> -mlir::createLinalgStrategyPromotePass(StringRef opName, - LinalgPromotionOptions opt, - LinalgTransformationFilter filter) { +std::unique_ptr> mlir::createLinalgStrategyPromotePass( + StringRef opName, const LinalgPromotionOptions &opt, + const LinalgTransformationFilter &filter) { return std::make_unique(opName, opt, filter); } /// Create a LinalgStrategyGeneralizePass. -std::unique_ptr> -mlir::createLinalgStrategyGeneralizePass(StringRef opName, - LinalgTransformationFilter filter) { +std::unique_ptr> mlir::createLinalgStrategyGeneralizePass( + StringRef opName, const LinalgTransformationFilter &filter) { return std::make_unique(opName, filter); } /// Create a LinalgStrategyDecomposePass. // TODO: if/when we need finer control add an `opName` parameter. -std::unique_ptr> -mlir::createLinalgStrategyDecomposePass(LinalgTransformationFilter filter) { +std::unique_ptr> mlir::createLinalgStrategyDecomposePass( + const LinalgTransformationFilter &filter) { return std::make_unique(filter); } /// Create a LinalgStrategyInterchangePass. std::unique_ptr> -mlir::createLinalgStrategyInterchangePass(ArrayRef iteratorInterchange, - LinalgTransformationFilter filter) { +mlir::createLinalgStrategyInterchangePass( + ArrayRef iteratorInterchange, + const LinalgTransformationFilter &filter) { return std::make_unique(iteratorInterchange, filter); } @@ -500,7 +503,7 @@ /// Create a LinalgStrategyVectorizePass. std::unique_ptr> mlir::createLinalgStrategyVectorizePass( StringRef opName, LinalgVectorizationOptions opt, - LinalgTransformationFilter filter, bool padVectorize) { + const LinalgTransformationFilter &filter, bool padVectorize) { return std::make_unique(opName, opt, filter, padVectorize); } @@ -508,14 +511,14 @@ /// Create a LinalgStrategyEnablePass. std::unique_ptr> mlir::createLinalgStrategyEnablePass(LinalgEnablingOptions opt, - LinalgTransformationFilter filter) { + const LinalgTransformationFilter &filter) { return std::make_unique(opt, filter); } /// Create a LinalgStrategyLowerVectorsPass. std::unique_ptr> -mlir::createLinalgStrategyLowerVectorsPass(LinalgVectorLoweringOptions opt, - LinalgTransformationFilter filter) { +mlir::createLinalgStrategyLowerVectorsPass( + LinalgVectorLoweringOptions opt, const LinalgTransformationFilter &filter) { return std::make_unique(opt, filter); } diff --git a/mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp b/mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp @@ -212,7 +212,7 @@ // by a partial `copy` op. FailureOr mlir::linalg::promoteSubviewAsNewBuffer( OpBuilder &b, Location loc, memref::SubViewOp subView, - AllocBufferCallbackFn allocationFn, DataLayout &layout) { + const AllocBufferCallbackFn &allocationFn, DataLayout &layout) { auto viewType = subView.getType(); auto rank = viewType.getRank(); SmallVector fullSizes; @@ -379,7 +379,7 @@ FailureOr mlir::linalg::promoteSubViews(OpBuilder &builder, LinalgOp linalgOp, - LinalgPromotionOptions options) { + const LinalgPromotionOptions &options) { LinalgOpInstancePromotionOptions linalgOptions(linalgOp, options); auto layout = DataLayout::closest(linalgOp); ImplicitLocOpBuilder b(linalgOp.getLoc(), builder); diff --git a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp @@ -10,6 +10,8 @@ // //===----------------------------------------------------------------------===// +#include + #include "PassDetail.h" #include "mlir/Dialect/Linalg/IR/Linalg.h" #include "mlir/Dialect/Linalg/Passes.h" @@ -392,7 +394,7 @@ namespace { struct PadTensorOpTilingPattern : public OpRewritePattern { PadTensorOpTilingPattern(MLIRContext *ctx, LinalgTilingOptions opt) - : OpRewritePattern(ctx), options(opt) {} + : OpRewritePattern(ctx), options(std::move(opt)) {} LogicalResult matchAndRewrite(PadTensorOp op, PatternRewriter &rewriter) const override { diff --git a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp @@ -33,6 +33,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" #include +#include #define DEBUG_TYPE "linalg-transforms" @@ -54,7 +55,7 @@ replacement(replacement), matchByDefault(false) {} mlir::linalg::LinalgTransformationFilter::LinalgTransformationFilter( - FilterFunction f, ArrayRef matchDisjunction, + const FilterFunction &f, ArrayRef matchDisjunction, Optional replacement) : filters(), matchDisjunction(matchDisjunction.begin(), matchDisjunction.end()), @@ -287,14 +288,14 @@ mlir::linalg::LinalgBaseTilingPattern::LinalgBaseTilingPattern( StringRef opName, MLIRContext *context, LinalgTilingOptions options, LinalgTransformationFilter filter, PatternBenefit benefit) - : RewritePattern(opName, benefit, context), filter(filter), - options(options) {} + : RewritePattern(opName, benefit, context), filter(std::move(filter)), + options(std::move(options)) {} mlir::linalg::LinalgBaseTilingPattern::LinalgBaseTilingPattern( MLIRContext *context, LinalgTilingOptions options, LinalgTransformationFilter filter, PatternBenefit benefit) - : RewritePattern(MatchAnyOpTypeTag(), benefit, context), filter(filter), - options(options) {} + : RewritePattern(MatchAnyOpTypeTag(), benefit, context), + filter(std::move(filter)), options(std::move(options)) {} /// Try to peel a loop `op` and return the new result. // TODO: Add support for scf.parallel and affine.for loops. @@ -393,9 +394,10 @@ LinalgTransformationFilter filter, LinalgTransformationFilter fusedOpMarker, LinalgTransformationFilter originalOpMarker, PatternBenefit benefit) : RewritePattern(opName, benefit, context, {}), - dependenceGraph(dependenceGraph), tilingOptions(tilingOptions), - fusionOptions(fusionOptions), filter(filter), - fusedOpMarker(fusedOpMarker), originalOpMarker(originalOpMarker) {} + dependenceGraph(dependenceGraph), tilingOptions(std::move(tilingOptions)), + fusionOptions(std::move(fusionOptions)), filter(std::move(filter)), + fusedOpMarker(std::move(fusedOpMarker)), + originalOpMarker(std::move(originalOpMarker)) {} LogicalResult mlir::linalg::LinalgBaseTileAndFusePattern::matchAndRewrite( Operation *op, PatternRewriter &rewriter) const { @@ -487,14 +489,14 @@ mlir::linalg::LinalgPaddingPattern::LinalgPaddingPattern( MLIRContext *context, LinalgPaddingOptions options, LinalgTransformationFilter filter, PatternBenefit benefit) - : RewritePattern(MatchAnyOpTypeTag(), benefit, context), filter(filter), - options(options) {} + : RewritePattern(MatchAnyOpTypeTag(), benefit, context), + filter(std::move(filter)), options(std::move(options)) {} mlir::linalg::LinalgPaddingPattern::LinalgPaddingPattern( StringRef opName, MLIRContext *context, LinalgPaddingOptions options, LinalgTransformationFilter filter, PatternBenefit benefit) - : RewritePattern(opName, benefit, context, {}), filter(filter), - options(options) {} + : RewritePattern(opName, benefit, context, {}), filter(std::move(filter)), + options(std::move(options)) {} LogicalResult mlir::linalg::LinalgPaddingPattern::matchAndRewrite( Operation *op, PatternRewriter &rewriter) const { @@ -547,16 +549,16 @@ LinalgTilingAndFusionOptions options, LinalgTransformationFilter filter, PatternBenefit benefit) - : RewritePattern(MatchAnyOpTypeTag(), benefit, context), filter(filter), - options(options) {} + : RewritePattern(MatchAnyOpTypeTag(), benefit, context), + filter(std::move(filter)), options(std::move(options)) {} mlir::linalg::LinalgTileAndFuseTensorOpsPattern:: LinalgTileAndFuseTensorOpsPattern(StringRef opName, MLIRContext *context, LinalgTilingAndFusionOptions options, LinalgTransformationFilter filter, PatternBenefit benefit) - : RewritePattern(opName, benefit, context), filter(filter), - options(options) {} + : RewritePattern(opName, benefit, context), filter(std::move(filter)), + options(std::move(options)) {} LogicalResult mlir::linalg::LinalgTileAndFuseTensorOpsPattern::matchAndRewrite( Operation *op, PatternRewriter &rewriter) const { @@ -614,7 +616,7 @@ mlir::linalg::GenericOpInterchangePattern::GenericOpInterchangePattern( MLIRContext *context, ArrayRef interchangeVector, LinalgTransformationFilter filter, PatternBenefit benefit) - : OpRewritePattern(context, benefit), filter(filter), + : OpRewritePattern(context, benefit), filter(std::move(filter)), interchangeVector(interchangeVector.begin(), interchangeVector.end()) {} LogicalResult mlir::linalg::GenericOpInterchangePattern::matchAndRewrite( @@ -638,12 +640,13 @@ mlir::linalg::LinalgGeneralizationPattern::LinalgGeneralizationPattern( MLIRContext *context, LinalgTransformationFilter filter, PatternBenefit benefit) - : RewritePattern(MatchAnyOpTypeTag(), benefit, context), filter(filter) {} + : RewritePattern(MatchAnyOpTypeTag(), benefit, context), + filter(std::move(filter)) {} mlir::linalg::LinalgGeneralizationPattern::LinalgGeneralizationPattern( StringRef opName, MLIRContext *context, LinalgTransformationFilter filter, PatternBenefit benefit) - : RewritePattern(opName, benefit, context, {}), filter(filter) {} + : RewritePattern(opName, benefit, context, {}), filter(std::move(filter)) {} LogicalResult mlir::linalg::LinalgGeneralizationPattern::matchAndRewrite( Operation *op, PatternRewriter &rewriter) const { @@ -661,14 +664,14 @@ mlir::linalg::LinalgBasePromotionPattern::LinalgBasePromotionPattern( MLIRContext *context, LinalgTransformationFilter filter, LinalgPromotionOptions options, PatternBenefit benefit) - : RewritePattern(MatchAnyOpTypeTag(), benefit, context), filter(filter), - options(options) {} + : RewritePattern(MatchAnyOpTypeTag(), benefit, context), + filter(std::move(filter)), options(std::move(options)) {} mlir::linalg::LinalgBasePromotionPattern::LinalgBasePromotionPattern( StringRef opName, MLIRContext *context, LinalgPromotionOptions options, LinalgTransformationFilter filter, PatternBenefit benefit) - : RewritePattern(opName, benefit, context, {}), filter(filter), - options(options) {} + : RewritePattern(opName, benefit, context, {}), filter(std::move(filter)), + options(std::move(options)) {} LogicalResult mlir::linalg::LinalgBasePromotionPattern::matchAndRewrite( Operation *op, PatternRewriter &rewriter) const { @@ -695,12 +698,13 @@ mlir::linalg::LinalgBaseVectorizationPattern::LinalgBaseVectorizationPattern( MLIRContext *context, LinalgTransformationFilter filter, PatternBenefit benefit) - : RewritePattern(MatchAnyOpTypeTag(), benefit, context), filter(filter) {} + : RewritePattern(MatchAnyOpTypeTag(), benefit, context), + filter(std::move(filter)) {} mlir::linalg::LinalgBaseVectorizationPattern::LinalgBaseVectorizationPattern( StringRef opName, MLIRContext *context, LinalgTransformationFilter filter, PatternBenefit benefit) - : RewritePattern(opName, benefit, context, {}), filter(filter) {} + : RewritePattern(opName, benefit, context, {}), filter(std::move(filter)) {} LogicalResult mlir::linalg::LinalgBaseVectorizationPattern::matchAndRewrite( Operation *op, PatternRewriter &rewriter) const { @@ -942,7 +946,8 @@ MLIRContext *context, LinalgTransformationFilter filter = LinalgTransformationFilter(), PatternBenefit benefit = 1) - : OpRewritePattern(context, benefit), filter(filter) {} + : OpRewritePattern(context, benefit), + filter(std::move(filter)) {} LogicalResult matchAndRewrite(linalg::Conv2DNhwcHwcfOp convOp, PatternRewriter &rewriter) const override { @@ -1028,7 +1033,7 @@ LinalgTransformationFilter filter = LinalgTransformationFilter(), PatternBenefit benefit = 1) : OpRewritePattern(context, benefit), - filter(filter) {} + filter(std::move(filter)) {} LogicalResult matchAndRewrite(DepthwiseConv2DNhwcHwcOp convOp, PatternRewriter &rewriter) const override { @@ -1108,7 +1113,7 @@ } // namespace void linalg::populateDecomposeConvolutionPatterns( - RewritePatternSet &patterns, LinalgTransformationFilter filter, + RewritePatternSet &patterns, const LinalgTransformationFilter &filter, PatternBenefit benefit) { patterns.add(patterns.getContext(), filter, diff --git a/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp b/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp --- a/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp +++ b/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp @@ -83,7 +83,7 @@ static Value handleMultidimensionalVectors(ImplicitLocOpBuilder &builder, ValueRange operands, int64_t vectorWidth, - std::function compute) { + const std::function &compute) { assert(!operands.empty() && "operands must be not empty"); assert(vectorWidth > 0 && "vector width must be larger than 0"); diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp --- a/mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp +++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp @@ -10,6 +10,8 @@ // //===----------------------------------------------------------------------===// +#include + #include "mlir/Dialect/SPIRV/IR/SPIRVOps.h" #include "mlir/Dialect/CommonFolders.h" @@ -161,8 +163,8 @@ // The resulting value will equal the low-order N bits of the correct result // R, where N is the component width and R is computed with enough precision // to avoid overflow and underflow. - return constFoldBinaryOp(operands, - [](APInt a, APInt b) { return a + b; }); + return constFoldBinaryOp( + operands, [](APInt a, const APInt &b) { return std::move(a) + b; }); } //===----------------------------------------------------------------------===// @@ -183,8 +185,8 @@ // The resulting value will equal the low-order N bits of the correct result // R, where N is the component width and R is computed with enough precision // to avoid overflow and underflow. - return constFoldBinaryOp(operands, - [](APInt a, APInt b) { return a * b; }); + return constFoldBinaryOp( + operands, [](const APInt &a, const APInt &b) { return a * b; }); } //===----------------------------------------------------------------------===// @@ -201,8 +203,8 @@ // The resulting value will equal the low-order N bits of the correct result // R, where N is the component width and R is computed with enough precision // to avoid overflow and underflow. - return constFoldBinaryOp(operands, - [](APInt a, APInt b) { return a - b; }); + return constFoldBinaryOp( + operands, [](APInt a, const APInt &b) { return std::move(a) - b; }); } //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Dialect/Shape/IR/Shape.cpp b/mlir/lib/Dialect/Shape/IR/Shape.cpp --- a/mlir/lib/Dialect/Shape/IR/Shape.cpp +++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +#include + #include "mlir/Dialect/Shape/IR/Shape.h" #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h" @@ -446,8 +448,8 @@ if (matchPattern(getRhs(), m_Zero())) return getLhs(); - return constFoldBinaryOp(operands, - [](APInt a, APInt b) { return a + b; }); + return constFoldBinaryOp( + operands, [](APInt a, const APInt &b) { return std::move(a) + b; }); } //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp --- a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp +++ b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp @@ -1163,7 +1163,7 @@ OpAsmPrinter &p, SwitchOp op, Type flagType, Block *defaultDestination, OperandRange defaultOperands, TypeRange defaultOperandTypes, DenseIntElementsAttr caseValues, SuccessorRange caseDestinations, - OperandRangeRange caseOperands, TypeRangeRange caseOperandTypes) { + OperandRangeRange caseOperands, const TypeRangeRange &caseOperandTypes) { p << " default: "; p.printSuccessorAndUseList(defaultDestination, defaultOperands); @@ -1289,7 +1289,7 @@ /// ] /// -> br ^bb2 static void foldSwitch(SwitchOp op, PatternRewriter &rewriter, - APInt caseValue) { + const APInt &caseValue) { auto caseValues = op.getCaseValues(); for (const auto &it : llvm::enumerate(caseValues->getValues())) { if (it.value() == caseValue) { diff --git a/mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp b/mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp --- a/mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp +++ b/mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp @@ -215,7 +215,7 @@ OpBuilder &b, ArrayRef reassociation) { SmallVector reassociationAttr = llvm::to_vector<4>(llvm::map_range( - reassociation, [&](ReassociationIndices indices) -> Attribute { + reassociation, [&](const ReassociationIndices &indices) -> Attribute { return b.getI64ArrayAttr(indices).cast(); })); return b.getArrayAttr(reassociationAttr); diff --git a/mlir/lib/Dialect/Vector/VectorMultiDimReductionTransforms.cpp b/mlir/lib/Dialect/Vector/VectorMultiDimReductionTransforms.cpp --- a/mlir/lib/Dialect/Vector/VectorMultiDimReductionTransforms.cpp +++ b/mlir/lib/Dialect/Vector/VectorMultiDimReductionTransforms.cpp @@ -46,7 +46,7 @@ auto reductionDimsRange = multiReductionOp.reduction_dims().getAsValueRange(); auto reductionDims = llvm::to_vector<4>(llvm::map_range( - reductionDimsRange, [](APInt a) { return a.getZExtValue(); })); + reductionDimsRange, [](const APInt &a) { return a.getZExtValue(); })); llvm::SmallDenseSet reductionDimsSet(reductionDims.begin(), reductionDims.end()); int64_t reductionSize = reductionDims.size(); diff --git a/mlir/lib/IR/AffineExpr.cpp b/mlir/lib/IR/AffineExpr.cpp --- a/mlir/lib/IR/AffineExpr.cpp +++ b/mlir/lib/IR/AffineExpr.cpp @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +#include + #include "mlir/IR/AffineExpr.h" #include "AffineExprDetail.h" #include "mlir/IR/AffineExprVisitor.h" @@ -28,7 +30,7 @@ std::function callback; AffineExprWalker(std::function callback) - : callback(callback) {} + : callback(std::move(callback)) {} void visitAffineBinaryOpExpr(AffineBinaryOpExpr expr) { callback(expr); } void visitConstantExpr(AffineConstantExpr expr) { callback(expr); } @@ -36,7 +38,7 @@ void visitSymbolExpr(AffineSymbolExpr expr) { callback(expr); } }; - AffineExprWalker(callback).walkPostOrder(*this); + AffineExprWalker(std::move(callback)).walkPostOrder(*this); } // Dispatch affine expression construction based on kind. diff --git a/mlir/lib/IR/AffineMap.cpp b/mlir/lib/IR/AffineMap.cpp --- a/mlir/lib/IR/AffineMap.cpp +++ b/mlir/lib/IR/AffineMap.cpp @@ -384,7 +384,8 @@ /// Walk all of the AffineExpr's in this mapping. Each node in an expression /// tree is visited in postorder. -void AffineMap::walkExprs(std::function callback) const { +void AffineMap::walkExprs( + const std::function &callback) const { for (auto expr : getResults()) expr.walk(callback); } diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp --- a/mlir/lib/IR/Diagnostics.cpp +++ b/mlir/lib/IR/Diagnostics.cpp @@ -875,7 +875,7 @@ } /// Utility method to emit any held diagnostics. - void emitDiagnostics(std::function emitFn) const { + void emitDiagnostics(const std::function &emitFn) const { // Stable sort all of the diagnostics that were emitted. This creates a // deterministic ordering for the diagnostics based upon which order id they // were emitted for. diff --git a/mlir/lib/IR/Dialect.cpp b/mlir/lib/IR/Dialect.cpp --- a/mlir/lib/IR/Dialect.cpp +++ b/mlir/lib/IR/Dialect.cpp @@ -32,7 +32,7 @@ void DialectRegistry::addDialectInterface( StringRef dialectName, TypeID interfaceTypeID, - DialectInterfaceAllocatorFunction allocator) { + const DialectInterfaceAllocatorFunction &allocator) { assert(allocator && "unexpected null interface allocation function"); auto it = registry.find(dialectName.str()); assert(it != registry.end() && @@ -57,7 +57,7 @@ void DialectRegistry::addObjectInterface( StringRef dialectName, TypeID objectID, TypeID interfaceTypeID, - ObjectInterfaceAllocatorFunction allocator) { + const ObjectInterfaceAllocatorFunction &allocator) { assert(allocator && "unexpected null interface allocation function"); auto it = registry.find(dialectName.str()); @@ -88,7 +88,7 @@ } void DialectRegistry::insert(TypeID typeID, StringRef name, - DialectAllocatorFunction ctor) { + const DialectAllocatorFunction &ctor) { auto inserted = registry.insert( std::make_pair(std::string(name), std::make_pair(typeID, ctor))); if (!inserted.second && inserted.first->second.first != typeID) { diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -995,7 +995,7 @@ size_t totalCount = std::accumulate( sizeAttr.begin(), sizeAttr.end(), 0, - [](unsigned all, APInt one) { return all + one.getZExtValue(); }); + [](unsigned all, const APInt &one) { return all + one.getZExtValue(); }); if (totalCount != expectedCount) return op->emitOpError() diff --git a/mlir/lib/Pass/IRPrinting.cpp b/mlir/lib/Pass/IRPrinting.cpp --- a/mlir/lib/Pass/IRPrinting.cpp +++ b/mlir/lib/Pass/IRPrinting.cpp @@ -216,8 +216,8 @@ /// Simple wrapper config that allows for the simpler interface defined above. struct BasicIRPrinterConfig : public PassManager::IRPrinterConfig { BasicIRPrinterConfig( - std::function shouldPrintBeforePass, - std::function shouldPrintAfterPass, + const std::function &shouldPrintBeforePass, + const std::function &shouldPrintAfterPass, bool printModuleScope, bool printAfterOnlyOnChange, bool printAfterOnlyOnFailure, OpPrintingFlags opPrintingFlags, raw_ostream &out) diff --git a/mlir/lib/Pass/PassRegistry.cpp b/mlir/lib/Pass/PassRegistry.cpp --- a/mlir/lib/Pass/PassRegistry.cpp +++ b/mlir/lib/Pass/PassRegistry.cpp @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +#include + #include "mlir/Pass/PassRegistry.h" #include "mlir/Pass/Pass.h" #include "mlir/Pass/PassManager.h" @@ -87,7 +89,8 @@ void mlir::registerPassPipeline( StringRef arg, StringRef description, const PassRegistryFunction &function, std::function)> optHandler) { - PassPipelineInfo pipelineInfo(arg, description, function, optHandler); + PassPipelineInfo pipelineInfo(arg, description, function, + std::move(optHandler)); bool inserted = passPipelineRegistry->try_emplace(arg, pipelineInfo).second; assert(inserted && "Pass pipeline registered multiple times"); (void)inserted; diff --git a/mlir/lib/Reducer/ReductionNode.cpp b/mlir/lib/Reducer/ReductionNode.cpp --- a/mlir/lib/Reducer/ReductionNode.cpp +++ b/mlir/lib/Reducer/ReductionNode.cpp @@ -24,7 +24,7 @@ using namespace mlir; ReductionNode::ReductionNode( - ReductionNode *parentNode, std::vector ranges, + ReductionNode *parentNode, const std::vector &ranges, llvm::SpecificBumpPtrAllocator &allocator) /// Root node will have the parent pointer point to themselves. : parent(parentNode == nullptr ? this : parentNode), diff --git a/mlir/lib/TableGen/Pattern.cpp b/mlir/lib/TableGen/Pattern.cpp --- a/mlir/lib/TableGen/Pattern.cpp +++ b/mlir/lib/TableGen/Pattern.cpp @@ -11,6 +11,8 @@ // //===----------------------------------------------------------------------===// +#include + #include "mlir/TableGen/Pattern.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" @@ -217,7 +219,7 @@ SymbolInfoMap::SymbolInfo::SymbolInfo(const Operator *op, SymbolInfo::Kind kind, Optional dagAndConstant) - : op(op), kind(kind), dagAndConstant(dagAndConstant) {} + : op(op), kind(kind), dagAndConstant(std::move(dagAndConstant)) {} int SymbolInfoMap::SymbolInfo::getStaticValueCount() const { switch (kind) { @@ -502,7 +504,8 @@ } SymbolInfoMap::const_iterator -SymbolInfoMap::findBoundSymbol(StringRef key, SymbolInfo symbolInfo) const { +SymbolInfoMap::findBoundSymbol(StringRef key, + const SymbolInfo &symbolInfo) const { std::string name = getValuePackName(key).str(); auto range = symbolInfoMap.equal_range(name); diff --git a/mlir/lib/TableGen/Predicate.cpp b/mlir/lib/TableGen/Predicate.cpp --- a/mlir/lib/TableGen/Predicate.cpp +++ b/mlir/lib/TableGen/Predicate.cpp @@ -286,7 +286,8 @@ // Combine a list of predicate expressions using a binary combiner. If a list // is empty, return "init". static std::string combineBinary(ArrayRef children, - std::string combiner, std::string init) { + const std::string &combiner, + std::string init) { if (children.empty()) return init; diff --git a/mlir/lib/Target/Cpp/TranslateToCpp.cpp b/mlir/lib/Target/Cpp/TranslateToCpp.cpp --- a/mlir/lib/Target/Cpp/TranslateToCpp.cpp +++ b/mlir/lib/Target/Cpp/TranslateToCpp.cpp @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +#include + #include "mlir/Dialect/EmitC/IR/EmitC.h" #include "mlir/Dialect/SCF/SCF.h" #include "mlir/Dialect/StandardOps/IR/Ops.h" @@ -689,7 +691,7 @@ } LogicalResult CppEmitter::emitAttribute(Location loc, Attribute attr) { - auto printInt = [&](APInt val, bool isUnsigned) { + auto printInt = [&](const APInt &val, bool isUnsigned) { if (val.getBitWidth() == 1) { if (val.getBoolValue()) os << "true"; @@ -702,7 +704,7 @@ } }; - auto printFloat = [&](APFloat val) { + auto printFloat = [&](const APFloat &val) { if (val.isFinite()) { SmallString<128> strValue; // Use default values of toString except don't truncate zeros. @@ -734,7 +736,8 @@ } if (auto dense = attr.dyn_cast()) { os << '{'; - interleaveComma(dense, os, [&](APFloat val) { printFloat(val); }); + interleaveComma(dense, os, + [&](APFloat val) { printFloat(std::move(val)); }); os << '}'; return success(); } @@ -757,7 +760,7 @@ .dyn_cast()) { os << '{'; interleaveComma(dense, os, [&](APInt val) { - printInt(val, shouldMapToUnsigned(iType.getSignedness())); + printInt(std::move(val), shouldMapToUnsigned(iType.getSignedness())); }); os << '}'; return success(); @@ -767,7 +770,8 @@ .getElementType() .dyn_cast()) { os << '{'; - interleaveComma(dense, os, [&](APInt val) { printInt(val, false); }); + interleaveComma(dense, os, + [&](APInt val) { printInt(std::move(val), false); }); os << '}'; return success(); } diff --git a/mlir/lib/Tools/mlir-lsp-server/lsp/Transport.cpp b/mlir/lib/Tools/mlir-lsp-server/lsp/Transport.cpp --- a/mlir/lib/Tools/mlir-lsp-server/lsp/Transport.cpp +++ b/mlir/lib/Tools/mlir-lsp-server/lsp/Transport.cpp @@ -13,6 +13,7 @@ #include "llvm/Support/Errno.h" #include "llvm/Support/Error.h" #include +#include using namespace mlir; using namespace mlir::lsp; @@ -87,7 +88,7 @@ } else { auto it = notificationHandlers.find(method); if (it != notificationHandlers.end()) - it->second(value); + it->second(std::move(value)); } return true; } @@ -100,7 +101,7 @@ auto it = methodHandlers.find(method); if (it != methodHandlers.end()) { - it->second(params, std::move(reply)); + it->second(std::move(params), std::move(reply)); } else { reply(llvm::make_error("method not found: " + method.str(), ErrorCode::MethodNotFound)); diff --git a/mlir/lib/Transforms/Inliner.cpp b/mlir/lib/Transforms/Inliner.cpp --- a/mlir/lib/Transforms/Inliner.cpp +++ b/mlir/lib/Transforms/Inliner.cpp @@ -514,7 +514,7 @@ public: InlinerPass(); InlinerPass(const InlinerPass &) = default; - InlinerPass(std::function defaultPipeline); + InlinerPass(const std::function &defaultPipeline); InlinerPass(std::function defaultPipeline, llvm::StringMap opPipelines); void runOnOperation() override; @@ -562,7 +562,8 @@ } // namespace InlinerPass::InlinerPass() : InlinerPass(defaultInlinerOptPipeline) {} -InlinerPass::InlinerPass(std::function defaultPipeline) +InlinerPass::InlinerPass( + const std::function &defaultPipeline) : defaultPipeline(defaultPipeline) { opPipelines.push_back({}); diff --git a/mlir/lib/Transforms/ViewOpGraph.cpp b/mlir/lib/Transforms/ViewOpGraph.cpp --- a/mlir/lib/Transforms/ViewOpGraph.cpp +++ b/mlir/lib/Transforms/ViewOpGraph.cpp @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +#include + #include "mlir/Transforms/ViewOpGraph.h" #include "PassDetail.h" #include "mlir/IR/Block.h" @@ -43,7 +45,9 @@ } /// Put quotation marks around a given string. -static std::string quoteString(std::string str) { return "\"" + str + "\""; } +static std::string quoteString(const std::string &str) { + return "\"" + str + "\""; +} using AttributeMap = llvm::StringMap; @@ -104,7 +108,8 @@ os.indent(); // Emit invisible anchor node from/to which arrows can be drawn. Node anchorNode = emitNodeStmt(" ", kShapeNone); - os << attrStmt("label", quoteString(escapeString(label))) << ";\n"; + os << attrStmt("label", quoteString(escapeString(std::move(label)))) + << ";\n"; builder(); os.unindent(); os << "}\n"; @@ -167,7 +172,7 @@ // clipped at the boundary, but labels are not. This can lead to labels // floating around without any edge next to them. if (!n1.clusterId && !n2.clusterId) - attrs["label"] = quoteString(escapeString(label)); + attrs["label"] = quoteString(escapeString(std::move(label))); // Use `ltail` and `lhead` to draw edges between clusters. if (n1.clusterId) attrs["ltail"] = "cluster_" + std::to_string(*n1.clusterId); @@ -195,7 +200,7 @@ Node emitNodeStmt(std::string label, StringRef shape = kShapeNode) { int nodeId = ++counter; AttributeMap attrs; - attrs["label"] = quoteString(escapeString(label)); + attrs["label"] = quoteString(escapeString(std::move(label))); attrs["shape"] = shape.str(); os << llvm::format("v%i ", nodeId); emitAttrList(os, attrs); diff --git a/mlir/lib/Translation/Translation.cpp b/mlir/lib/Translation/Translation.cpp --- a/mlir/lib/Translation/Translation.cpp +++ b/mlir/lib/Translation/Translation.cpp @@ -94,7 +94,7 @@ TranslateFromMLIRRegistration::TranslateFromMLIRRegistration( StringRef name, const TranslateFromMLIRFunction &function, - std::function dialectRegistration) { + const std::function &dialectRegistration) { registerTranslation(name, [function, dialectRegistration]( llvm::SourceMgr &sourceMgr, raw_ostream &output, MLIRContext *context) { diff --git a/mlir/test/lib/Dialect/Linalg/TestLinalgCodegenStrategy.cpp b/mlir/test/lib/Dialect/Linalg/TestLinalgCodegenStrategy.cpp --- a/mlir/test/lib/Dialect/Linalg/TestLinalgCodegenStrategy.cpp +++ b/mlir/test/lib/Dialect/Linalg/TestLinalgCodegenStrategy.cpp @@ -10,6 +10,8 @@ // //===----------------------------------------------------------------------===// +#include + #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/GPU/GPUDialect.h" #include "mlir/Dialect/Linalg/IR/Linalg.h" @@ -175,19 +177,20 @@ CodegenStrategy strategy; strategy .tileAndFuseIf(fuse && !tileSizes.empty(), anchorOpName, - tilingAndFusionOptions) - .tileIf(!fuse && !tileSizes.empty(), anchorOpName, tilingOptions) + std::move(tilingAndFusionOptions)) + .tileIf(!fuse && !tileSizes.empty(), anchorOpName, + std::move(tilingOptions)) .promoteIf(!fuse && promote, anchorOpName, LinalgPromotionOptions() .setAlignment(16) .setUseFullTileBuffersByDefault(promoteFullTile)) .tileIf(!fuse && !registerTileSizes.empty(), anchorOpName, - registerTilingOptions) + std::move(registerTilingOptions)) .promoteIf(!fuse && registerPromote, anchorOpName, LinalgPromotionOptions() .setAlignment(16) .setUseFullTileBuffersByDefault(registerPromoteFullTile)) - .padIf(pad, "", paddingOptions) + .padIf(pad, "", std::move(paddingOptions)) .decomposeIf(decompose) .generalizeIf(generalize, "") .interchangeIf(!iteratorInterchange.empty(), iteratorInterchange) diff --git a/mlir/test/lib/Dialect/Linalg/TestLinalgTransforms.cpp b/mlir/test/lib/Dialect/Linalg/TestLinalgTransforms.cpp --- a/mlir/test/lib/Dialect/Linalg/TestLinalgTransforms.cpp +++ b/mlir/test/lib/Dialect/Linalg/TestLinalgTransforms.cpp @@ -567,7 +567,7 @@ (void)applyPatternsAndFoldGreedily(funcOp, std::move(patterns)); } -static void applyTilePattern(FuncOp funcOp, std::string loopType, +static void applyTilePattern(FuncOp funcOp, const std::string &loopType, ArrayRef tileSizes, ArrayRef peeledLoops, bool scalarizeDynamicDims) { diff --git a/mlir/tools/mlir-tblgen/DialectGen.cpp b/mlir/tools/mlir-tblgen/DialectGen.cpp --- a/mlir/tools/mlir-tblgen/DialectGen.cpp +++ b/mlir/tools/mlir-tblgen/DialectGen.cpp @@ -185,10 +185,11 @@ )"; /// Generate the declaration for the given dialect class. -static void emitDialectDecl(Dialect &dialect, - iterator_range dialectAttrs, - iterator_range dialectTypes, - raw_ostream &os) { +static void +emitDialectDecl(Dialect &dialect, + const iterator_range &dialectAttrs, + const iterator_range &dialectTypes, + raw_ostream &os) { /// Build the list of dependent dialects std::string dependentDialectRegistrations; { diff --git a/mlir/tools/mlir-tblgen/OpDocGen.cpp b/mlir/tools/mlir-tblgen/OpDocGen.cpp --- a/mlir/tools/mlir-tblgen/OpDocGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDocGen.cpp @@ -88,7 +88,7 @@ os << "```\n\n"; } -static void emitOpTraitsDoc(Operator op, raw_ostream &os) { +static void emitOpTraitsDoc(const Operator &op, raw_ostream &os) { // TODO: We should link to the trait/documentation of it. That also means we // should add descriptions to traits that can be queried. // Collect using set to sort effects, interfaces & traits. 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 @@ -2217,7 +2217,7 @@ /// attribute. void handleTypesMatchConstraint( llvm::StringMap &variableTyResolver, - llvm::Record def); + const llvm::Record &def); /// Returns an argument or attribute with the given name that has been seen /// within the format. @@ -2621,7 +2621,7 @@ void FormatParser::handleTypesMatchConstraint( llvm::StringMap &variableTyResolver, - llvm::Record def) { + const llvm::Record &def) { StringRef lhsName = def.getValueAsString("lhs"); StringRef rhsName = def.getValueAsString("rhs"); StringRef transformer = def.getValueAsString("transformer"); diff --git a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp --- a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp +++ b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp @@ -154,7 +154,7 @@ // GEN: Interface definitions //===----------------------------------------------------------------------===// -static void emitInterfaceDef(Interface interface, StringRef valueType, +static void emitInterfaceDef(const Interface &interface, StringRef valueType, raw_ostream &os) { StringRef interfaceName = interface.getName(); StringRef cppNamespace = interface.getCppNamespace(); diff --git a/mlir/tools/mlir-tblgen/mlir-tblgen.cpp b/mlir/tools/mlir-tblgen/mlir-tblgen.cpp --- a/mlir/tools/mlir-tblgen/mlir-tblgen.cpp +++ b/mlir/tools/mlir-tblgen/mlir-tblgen.cpp @@ -29,7 +29,7 @@ static llvm::ManagedStatic> generatorRegistry; mlir::GenRegistration::GenRegistration(StringRef arg, StringRef description, - GenFunction function) { + const GenFunction &function) { generatorRegistry->emplace_back(arg, description, function); } diff --git a/mlir/unittests/Analysis/AffineStructuresParserTest.cpp b/mlir/unittests/Analysis/AffineStructuresParserTest.cpp --- a/mlir/unittests/Analysis/AffineStructuresParserTest.cpp +++ b/mlir/unittests/Analysis/AffineStructuresParserTest.cpp @@ -73,7 +73,7 @@ /// Parses and compares the `str` to the `ex`. The equality check is performed /// by using PresburgerSet::isEqual -static bool parseAndCompare(StringRef str, FlatAffineConstraints ex, +static bool parseAndCompare(StringRef str, const FlatAffineConstraints &ex, MLIRContext *context) { FailureOr fac = parseIntegerSetToFAC(str, context); diff --git a/mlir/unittests/Analysis/Presburger/SimplexTest.cpp b/mlir/unittests/Analysis/Presburger/SimplexTest.cpp --- a/mlir/unittests/Analysis/Presburger/SimplexTest.cpp +++ b/mlir/unittests/Analysis/Presburger/SimplexTest.cpp @@ -92,9 +92,10 @@ } } -Simplex simplexFromConstraints(unsigned nDim, - SmallVector, 8> ineqs, - SmallVector, 8> eqs) { +Simplex +simplexFromConstraints(unsigned nDim, + const SmallVector, 8> &ineqs, + const SmallVector, 8> &eqs) { Simplex simplex(nDim); for (const auto &ineq : ineqs) simplex.addInequality(ineq); diff --git a/mlir/unittests/Analysis/PresburgerSetTest.cpp b/mlir/unittests/Analysis/PresburgerSetTest.cpp --- a/mlir/unittests/Analysis/PresburgerSetTest.cpp +++ b/mlir/unittests/Analysis/PresburgerSetTest.cpp @@ -48,7 +48,7 @@ /// Compute the union of s and t, and check that each of the given points /// belongs to the union iff it belongs to at least one of s and t. -static void testUnionAtPoints(PresburgerSet s, PresburgerSet t, +static void testUnionAtPoints(const PresburgerSet &s, const PresburgerSet &t, ArrayRef> points) { PresburgerSet unionSet = s.unionSet(t); for (const SmallVector &point : points) { @@ -61,7 +61,8 @@ /// Compute the intersection of s and t, and check that each of the given points /// belongs to the intersection iff it belongs to both s and t. -static void testIntersectAtPoints(PresburgerSet s, PresburgerSet t, +static void testIntersectAtPoints(const PresburgerSet &s, + const PresburgerSet &t, ArrayRef> points) { PresburgerSet intersection = s.intersect(t); for (const SmallVector &point : points) { @@ -74,7 +75,7 @@ /// Compute the set difference s \ t, and check that each of the given points /// belongs to the difference iff it belongs to s and does not belong to t. -static void testSubtractAtPoints(PresburgerSet s, PresburgerSet t, +static void testSubtractAtPoints(const PresburgerSet &s, const PresburgerSet &t, ArrayRef> points) { PresburgerSet diff = s.subtract(t); for (const SmallVector &point : points) { @@ -90,7 +91,7 @@ /// Compute the complement of s, and check that each of the given points /// belongs to the complement iff it does not belong to s. -static void testComplementAtPoints(PresburgerSet s, +static void testComplementAtPoints(const PresburgerSet &s, ArrayRef> points) { PresburgerSet complement = s.complement(); complement.complement(); @@ -473,7 +474,7 @@ EXPECT_TRUE(s.isEqual(t)); } -void expectEmpty(PresburgerSet s) { EXPECT_TRUE(s.isIntegerEmpty()); } +void expectEmpty(const PresburgerSet &s) { EXPECT_TRUE(s.isIntegerEmpty()); } TEST(SetTest, divisions) { MLIRContext context; @@ -511,7 +512,7 @@ /// Coalesce `set` and check that the `newSet` is equal to `set and that /// `expectedNumFACs` matches the number of FACs in the coalesced set. /// If one of the two -void expectCoalesce(size_t expectedNumFACs, const PresburgerSet set) { +void expectCoalesce(size_t expectedNumFACs, const PresburgerSet &set) { PresburgerSet newSet = set.coalesce(); EXPECT_TRUE(set.isEqual(newSet)); EXPECT_TRUE(expectedNumFACs == newSet.getNumFACs()); diff --git a/mlir/unittests/Conversion/PDLToPDLInterp/RootOrderingTest.cpp b/mlir/unittests/Conversion/PDLToPDLInterp/RootOrderingTest.cpp --- a/mlir/unittests/Conversion/PDLToPDLInterp/RootOrderingTest.cpp +++ b/mlir/unittests/Conversion/PDLToPDLInterp/RootOrderingTest.cpp @@ -46,7 +46,7 @@ /// Checks that optimal branching on graph has the given cost and /// its preorder traversal results in the specified edges. - void check(unsigned cost, OptimalBranching::EdgeList edges) { + void check(unsigned cost, const OptimalBranching::EdgeList &edges) { OptimalBranching opt(graph, v[0]); EXPECT_EQ(opt.solve(), cost); EXPECT_EQ(opt.preOrderTraversal({v, v + edges.size()}), edges); diff --git a/mlir/unittests/Dialect/SparseTensor/MergerTest.cpp b/mlir/unittests/Dialect/SparseTensor/MergerTest.cpp --- a/mlir/unittests/Dialect/SparseTensor/MergerTest.cpp +++ b/mlir/unittests/Dialect/SparseTensor/MergerTest.cpp @@ -22,7 +22,8 @@ /// Rather than using these, please use the readable helper constructor /// functions below to make tests more readable. Pattern(unsigned tensorNum) : kind(Kind::kTensor), tensorNum(tensorNum) {} - Pattern(Kind kind, std::shared_ptr e0, std::shared_ptr e1) + Pattern(Kind kind, const std::shared_ptr &e0, + const std::shared_ptr &e1) : kind(kind), e0(e0), e1(e1) { assert(kind >= Kind::kMulF); assert(e0 && e1); @@ -38,13 +39,15 @@ return std::make_shared(tensorNum); } -static std::shared_ptr addfPattern(std::shared_ptr e0, - std::shared_ptr e1) { +static std::shared_ptr +addfPattern(const std::shared_ptr &e0, + const std::shared_ptr &e1) { return std::make_shared(Kind::kAddF, e0, e1); } -static std::shared_ptr mulfPattern(std::shared_ptr e0, - std::shared_ptr e1) { +static std::shared_ptr +mulfPattern(const std::shared_ptr &e0, + const std::shared_ptr &e1) { return std::make_shared(Kind::kMulF, e0, e1); } @@ -84,8 +87,8 @@ /// groups of lattice points should be ordered with respect to other groups, /// but there is no required ordering within groups. bool latPointWithinRange(unsigned s, unsigned p, unsigned n, - std::shared_ptr pattern, - llvm::BitVector bits) { + const std::shared_ptr &pattern, + const llvm::BitVector &bits) { for (unsigned i = p; i < p + n; ++i) { if (compareExpression(merger.lat(merger.set(s)[i]).exp, pattern) && compareBits(s, i, bits)) @@ -110,7 +113,7 @@ /// Converts a vector of (loop, tensor) pairs to a bitvector with the /// corresponding bits set. llvm::BitVector - loopsToBits(std::vector> loops) { + loopsToBits(const std::vector> &loops) { llvm::BitVector testBits = llvm::BitVector(numTensors + 1, false); for (auto l : loops) { auto loop = std::get<0>(l); @@ -121,7 +124,7 @@ } /// Returns true if the bits of lattice point p in set s match the given bits. - bool compareBits(unsigned s, unsigned p, llvm::BitVector bits) { + bool compareBits(unsigned s, unsigned p, const llvm::BitVector &bits) { return merger.lat(merger.set(s)[p]).bits == bits; } @@ -136,7 +139,7 @@ /// children are equal. /// - Expressions with Kind invariant or tensor are equal if they have the /// same expression id. - bool compareExpression(unsigned e, std::shared_ptr pattern) { + bool compareExpression(unsigned e, const std::shared_ptr &pattern) { auto tensorExp = merger.exp(e); if (tensorExp.kind != pattern->kind) return false;