diff --git a/flang/include/flang/Optimizer/Dialect/FIRDialect.h b/flang/include/flang/Optimizer/Dialect/FIRDialect.h index 5a69e3fa23a8f..29f8d437fc5a3 100644 --- a/flang/include/flang/Optimizer/Dialect/FIRDialect.h +++ b/flang/include/flang/Optimizer/Dialect/FIRDialect.h @@ -16,7 +16,7 @@ #include "mlir/IR/Dialect.h" namespace mlir { -class BlockAndValueMapping; +class IRMapping; } // namespace mlir namespace fir { @@ -56,7 +56,7 @@ class FIRCodeGenDialect final : public mlir::Dialect { /// Support for inlining on FIR. bool canLegallyInline(mlir::Operation *op, mlir::Region *reg, bool, - mlir::BlockAndValueMapping &map); + mlir::IRMapping &map); bool canLegallyInline(mlir::Operation *, mlir::Operation *, bool); } // namespace fir diff --git a/flang/include/flang/Optimizer/Transforms/Passes.h b/flang/include/flang/Optimizer/Transforms/Passes.h index 762ea9d90c40e..dee514bc444ac 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.h +++ b/flang/include/flang/Optimizer/Transforms/Passes.h @@ -15,7 +15,7 @@ #include namespace mlir { -class BlockAndValueMapping; +class IRMapping; class GreedyRewriteConfig; class Operation; class Pass; diff --git a/flang/lib/Optimizer/Builder/HLFIRTools.cpp b/flang/lib/Optimizer/Builder/HLFIRTools.cpp index 755e8d898b978..17bf90fff08bd 100644 --- a/flang/lib/Optimizer/Builder/HLFIRTools.cpp +++ b/flang/lib/Optimizer/Builder/HLFIRTools.cpp @@ -15,7 +15,7 @@ #include "flang/Optimizer/Builder/MutableBox.h" #include "flang/Optimizer/Builder/Todo.h" #include "flang/Optimizer/HLFIR/HLFIROps.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include // Return explicit extents. If the base is a fir.box, this won't read it to @@ -575,7 +575,7 @@ hlfir::inlineElementalOp(mlir::Location loc, fir::FirOpBuilder &builder, // hlfir.elemental region is a SizedRegion<1>. assert(elemental.getRegion().hasOneBlock() && "expect elemental region to have one block"); - mlir::BlockAndValueMapping mapper; + mlir::IRMapping mapper; mapper.map(elemental.getIndices(), oneBasedIndices); mlir::Operation *newOp; for (auto &op : elemental.getRegion().back().getOperations()) diff --git a/flang/lib/Optimizer/Dialect/FIRDialect.cpp b/flang/lib/Optimizer/Dialect/FIRDialect.cpp index 9a936aed7fda0..6082417e111a5 100644 --- a/flang/lib/Optimizer/Dialect/FIRDialect.cpp +++ b/flang/lib/Optimizer/Dialect/FIRDialect.cpp @@ -31,8 +31,7 @@ struct FIRInlinerInterface : public mlir::DialectInlinerInterface { /// This hook checks to see if the operation `op` is legal to inline into the /// given region `reg`. bool isLegalToInline(mlir::Operation *op, mlir::Region *reg, - bool wouldBeCloned, - mlir::BlockAndValueMapping &map) const final { + bool wouldBeCloned, mlir::IRMapping &map) const final { return fir::canLegallyInline(op, reg, wouldBeCloned, map); } diff --git a/flang/lib/Optimizer/Dialect/Inliner.cpp b/flang/lib/Optimizer/Dialect/Inliner.cpp index ffd7e3e075618..93da611ad5a79 100644 --- a/flang/lib/Optimizer/Dialect/Inliner.cpp +++ b/flang/lib/Optimizer/Dialect/Inliner.cpp @@ -16,7 +16,7 @@ static llvm::cl::opt /// Should we inline the callable `op` into region `reg`? bool fir::canLegallyInline(mlir::Operation *, mlir::Region *, bool, - mlir::BlockAndValueMapping &) { + mlir::IRMapping &) { return aggressivelyInline; } diff --git a/mlir/docs/Interfaces.md b/mlir/docs/Interfaces.md index 11e40cf30d216..b6007d04ad1da 100644 --- a/mlir/docs/Interfaces.md +++ b/mlir/docs/Interfaces.md @@ -53,7 +53,7 @@ public: /// This can be used to examine what values will replace entry arguments into /// the 'src' region, for example. virtual bool isLegalToInline(Region *dest, Region *src, - BlockAndValueMapping &valueMapping) const { + IRMapping &valueMapping) const { return false; } }; @@ -63,7 +63,7 @@ public: struct AffineInlinerInterface : public DialectInlinerInterface { /// Affine structures have specific inlining constraints. bool isLegalToInline(Region *dest, Region *src, - BlockAndValueMapping &valueMapping) const final { + IRMapping &valueMapping) const final { ... } }; @@ -99,7 +99,7 @@ class InlinerInterface : public /// with default implementations that call the hook on the interface for a /// given dialect. virtual bool isLegalToInline(Region *dest, Region *src, - BlockAndValueMapping &valueMapping) const { + IRMapping &valueMapping) const { auto *handler = getInterfaceFor(dest->getContainingOp()); return handler ? handler->isLegalToInline(dest, src, valueMapping) : false; } diff --git a/mlir/docs/Rationale/UsageOfConst.md b/mlir/docs/Rationale/UsageOfConst.md index b1de7309bb2c0..102b948a0eac1 100644 --- a/mlir/docs/Rationale/UsageOfConst.md +++ b/mlir/docs/Rationale/UsageOfConst.md @@ -186,7 +186,7 @@ Other parts of the code are just outright incorrect. For example, the operation cloning methods are defined on `Operation` like this: ```C++ -Operation *clone(BlockAndValueMapping &mapper, MLIRContext *context) const; +Operation *clone(IRMapping &mapper, MLIRContext *context) const; Operation *clone(MLIRContext *context) const; ``` @@ -270,4 +270,3 @@ MLIR. This implies the following changes to the codebase: 1. Types like `OpPointer` and `ConstOpPointer` that exist solely to propagate const can be entirely removed from the codebase. 1. We can close bugs complaining about const incorrectness in the IR. - diff --git a/mlir/docs/Tutorials/Toy/Ch-4.md b/mlir/docs/Tutorials/Toy/Ch-4.md index 9584a169f60e3..95cdca0c3fa32 100644 --- a/mlir/docs/Tutorials/Toy/Ch-4.md +++ b/mlir/docs/Tutorials/Toy/Ch-4.md @@ -73,7 +73,7 @@ struct ToyInlinerInterface : public DialectInlinerInterface { /// given region. For Toy this hook can simply return true, as all Toy /// operations are inlinable. bool isLegalToInline(Operation *, Region *, bool, - BlockAndValueMapping &) const final { + IRMapping &) const final { return true; } @@ -81,7 +81,7 @@ struct ToyInlinerInterface : public DialectInlinerInterface { /// region. The regions here are the bodies of the callable functions. For /// Toy, any function can be inlined, so we simply return true. bool isLegalToInline(Region *dest, Region *src, bool wouldBeCloned, - BlockAndValueMapping &valueMapping) const final { + IRMapping &valueMapping) const final { return true; } diff --git a/mlir/examples/toy/Ch4/mlir/Dialect.cpp b/mlir/examples/toy/Ch4/mlir/Dialect.cpp index 5db2f953e8b2f..c87e107f6f415 100644 --- a/mlir/examples/toy/Ch4/mlir/Dialect.cpp +++ b/mlir/examples/toy/Ch4/mlir/Dialect.cpp @@ -44,14 +44,12 @@ struct ToyInlinerInterface : public DialectInlinerInterface { } /// All operations within toy can be inlined. - bool isLegalToInline(Operation *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final { return true; } // All functions within toy can be inlined. - bool isLegalToInline(Region *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Region *, Region *, bool, IRMapping &) const final { return true; } diff --git a/mlir/examples/toy/Ch5/mlir/Dialect.cpp b/mlir/examples/toy/Ch5/mlir/Dialect.cpp index c2015eee1890e..04ae3149281f9 100644 --- a/mlir/examples/toy/Ch5/mlir/Dialect.cpp +++ b/mlir/examples/toy/Ch5/mlir/Dialect.cpp @@ -44,14 +44,12 @@ struct ToyInlinerInterface : public DialectInlinerInterface { } /// All operations within toy can be inlined. - bool isLegalToInline(Operation *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final { return true; } // All functions within toy can be inlined. - bool isLegalToInline(Region *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Region *, Region *, bool, IRMapping &) const final { return true; } diff --git a/mlir/examples/toy/Ch6/mlir/Dialect.cpp b/mlir/examples/toy/Ch6/mlir/Dialect.cpp index c2015eee1890e..04ae3149281f9 100644 --- a/mlir/examples/toy/Ch6/mlir/Dialect.cpp +++ b/mlir/examples/toy/Ch6/mlir/Dialect.cpp @@ -44,14 +44,12 @@ struct ToyInlinerInterface : public DialectInlinerInterface { } /// All operations within toy can be inlined. - bool isLegalToInline(Operation *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final { return true; } // All functions within toy can be inlined. - bool isLegalToInline(Region *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Region *, Region *, bool, IRMapping &) const final { return true; } diff --git a/mlir/examples/toy/Ch7/mlir/Dialect.cpp b/mlir/examples/toy/Ch7/mlir/Dialect.cpp index ffcdd7a76c992..3382cbcd3074a 100644 --- a/mlir/examples/toy/Ch7/mlir/Dialect.cpp +++ b/mlir/examples/toy/Ch7/mlir/Dialect.cpp @@ -45,14 +45,12 @@ struct ToyInlinerInterface : public DialectInlinerInterface { } /// All operations within toy can be inlined. - bool isLegalToInline(Operation *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final { return true; } // All functions within toy can be inlined. - bool isLegalToInline(Region *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Region *, Region *, bool, IRMapping &) const final { return true; } diff --git a/mlir/include/mlir/Dialect/Func/IR/FuncOps.td b/mlir/include/mlir/Dialect/Func/IR/FuncOps.td index 58a33a124042b..50c01cff57048 100644 --- a/mlir/include/mlir/Dialect/Func/IR/FuncOps.td +++ b/mlir/include/mlir/Dialect/Func/IR/FuncOps.td @@ -278,14 +278,14 @@ def FuncOp : Func_Op<"func", [ /// included in the new function. Replaces references to cloned sub-values /// with the corresponding value that is copied, and adds those mappings to /// the mapper. - FuncOp clone(BlockAndValueMapping &mapper); + FuncOp clone(IRMapping &mapper); FuncOp clone(); /// Clone the internal blocks and attributes from this function into dest. /// Any cloned blocks are appended to the back of dest. This function /// asserts that the attributes of the current function and dest are /// compatible. - void cloneInto(FuncOp dest, BlockAndValueMapping &mapper); + void cloneInto(FuncOp dest, IRMapping &mapper); //===------------------------------------------------------------------===// // CallableOpInterface diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h index 45d63d80f73bc..d8d59b5ce3a81 100644 --- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h +++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h @@ -15,8 +15,8 @@ #include "mlir/Dialect/Utils/StructuredOpsUtils.h" #include "mlir/IR/AffineMap.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/BuiltinTypes.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/ImplicitLocOpBuilder.h" #include "mlir/IR/OpDefinition.h" #include "mlir/Interfaces/DestinationStyleOpInterface.h" diff --git a/mlir/include/mlir/IR/BlockAndValueMapping.h b/mlir/include/mlir/IR/BlockAndValueMapping.h deleted file mode 100644 index 9776030282202..0000000000000 --- a/mlir/include/mlir/IR/BlockAndValueMapping.h +++ /dev/null @@ -1,103 +0,0 @@ -//===- BlockAndValueMapping.h -----------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file defines a utility class for maintaining a mapping for multiple -// value types. -// -//===----------------------------------------------------------------------===// - -#ifndef MLIR_IR_BLOCKANDVALUEMAPPING_H -#define MLIR_IR_BLOCKANDVALUEMAPPING_H - -#include "mlir/IR/Block.h" - -namespace mlir { -// This is a utility class for mapping one set of values to another. New -// mappings can be inserted via 'map'. Existing mappings can be -// found via the 'lookup*' functions. There are two variants that differ only in -// return value when an existing is not found for the provided key. -// 'lookupOrNull' returns nullptr where as 'lookupOrDefault' will return the -// lookup key. -class BlockAndValueMapping { -public: - /// Inserts a new mapping for 'from' to 'to'. If there is an existing mapping, - /// it is overwritten. - void map(Block *from, Block *to) { blockMap[from] = to; } - void map(Value from, Value to) { valueMap[from] = to; } - - template < - typename S, typename T, - std::enable_if_t::value && - !std::is_assignable::value> * = nullptr> - void map(S &&from, T &&to) { - for (auto pair : llvm::zip(from, to)) - map(std::get<0>(pair), std::get<1>(pair)); - } - - /// Erases a mapping for 'from'. - void erase(Block *from) { blockMap.erase(from); } - void erase(Value from) { valueMap.erase(from); } - - /// Checks to see if a mapping for 'from' exists. - bool contains(Block *from) const { return blockMap.count(from); } - bool contains(Value from) const { return valueMap.count(from); } - - /// Lookup a mapped value within the map. If a mapping for the provided value - /// does not exist then return nullptr. - Block *lookupOrNull(Block *from) const { - return lookupOrValue(from, (Block *)nullptr); - } - Value lookupOrNull(Value from) const { return lookupOrValue(from, Value()); } - - /// Lookup a mapped value within the map. If a mapping for the provided value - /// does not exist then return the provided value. - Block *lookupOrDefault(Block *from) const { - return lookupOrValue(from, from); - } - Value lookupOrDefault(Value from) const { return lookupOrValue(from, from); } - - /// Lookup a mapped value within the map. This asserts the provided value - /// exists within the map. - Block *lookup(Block *from) const { return lookupImpl(from); } - Value lookup(Value from) const { return lookupImpl(from); } - - /// Clears all mappings held by the mapper. - void clear() { valueMap.clear(); } - - /// Return the held value mapping. - const DenseMap &getValueMap() const { return valueMap; } - - /// Return the held block mapping. - const DenseMap &getBlockMap() const { return blockMap; } - -private: - template - T lookupImpl(T from) const { - T result = lookupOrNull(from); - assert(result && "expected 'from' to be contained within the map"); - return result; - } - - /// Utility lookupOrValue that looks up an existing key or returns the - /// provided value. - Block *lookupOrValue(Block *from, Block *value) const { - auto it = blockMap.find(from); - return it != blockMap.end() ? it->second : value; - } - Value lookupOrValue(Value from, Value value) const { - auto it = valueMap.find(from); - return it != valueMap.end() ? it->second : value; - } - - DenseMap valueMap; - DenseMap blockMap; -}; - -} // namespace mlir - -#endif // MLIR_IR_BLOCKANDVALUEMAPPING_H diff --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h index 834be92aeac08..66fa8264eb16f 100644 --- a/mlir/include/mlir/IR/Builders.h +++ b/mlir/include/mlir/IR/Builders.h @@ -15,7 +15,7 @@ namespace mlir { class AffineExpr; -class BlockAndValueMapping; +class IRMapping; class UnknownLoc; class FileLineColLoc; class Type; @@ -517,13 +517,13 @@ class OpBuilder : public Builder { /// ( leaving them alone if no entry is present). Replaces references to /// cloned sub-operations to the corresponding operation that is copied, /// and adds those mappings to the map. - Operation *clone(Operation &op, BlockAndValueMapping &mapper); + Operation *clone(Operation &op, IRMapping &mapper); Operation *clone(Operation &op); /// Creates a deep copy of this operation but keep the operation regions /// empty. Operands are remapped using `mapper` (if present), and `mapper` is /// updated to contain the results. - Operation *cloneWithoutRegions(Operation &op, BlockAndValueMapping &mapper) { + Operation *cloneWithoutRegions(Operation &op, IRMapping &mapper) { return insert(op.cloneWithoutRegions(mapper)); } Operation *cloneWithoutRegions(Operation &op) { diff --git a/mlir/include/mlir/IR/IRMapping.h b/mlir/include/mlir/IR/IRMapping.h new file mode 100644 index 0000000000000..bc4c2d82201ea --- /dev/null +++ b/mlir/include/mlir/IR/IRMapping.h @@ -0,0 +1,120 @@ +//===- IRMapping.h ----------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines a utility class for maintaining a mapping of SSA values, +// blocks, and operations. +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_IR_IRMAPPING_H +#define MLIR_IR_IRMAPPING_H + +#include "mlir/IR/Block.h" + +namespace mlir { +/// This is a utility class for mapping one set of IR entities to another. New +/// mappings can be inserted via 'map'. Existing mappings can be +/// found via the 'lookup*' functions. There are three variants that differ only +/// in return value when an existing is not found for the provided key: SSA +/// values, blocks, and operations. 'lookupOrNull' returns nullptr where as +/// 'lookupOrDefault' will return the lookup key. +class IRMapping { +public: + /// Inserts a new mapping for 'from' to 'to'. If there is an existing mapping, + /// it is overwritten. + void map(Value from, Value to) { valueMap[from] = to; } + void map(Block *from, Block *to) { blockMap[from] = to; } + void map(Operation *from, Operation *to) { operationMap[from] = to; } + + template && + !std::is_assignable_v && + !std::is_assignable_v> * = nullptr> + void map(S &&from, T &&to) { + for (auto [fromValue, toValue] : llvm::zip(from, to)) + map(fromValue, toValue); + } + + /// Erases a mapping for 'from'. + template + void erase(T from) { + getMap().erase(from); + } + + /// Checks to see if a mapping for 'from' exists. + template + bool contains(T from) const { + return getMap().count(from); + } + + /// Lookup a mapped value within the map. If a mapping for the provided value + /// does not exist then return nullptr. + template + auto lookupOrNull(T from) const { + return lookupOrValue(from, T(nullptr)); + } + + /// Lookup a mapped value within the map. If a mapping for the provided value + /// does not exist then return the provided value. + template + auto lookupOrDefault(T from) const { + return lookupOrValue(from, from); + } + + /// Lookup a mapped value within the map. This asserts the provided value + /// exists within the map. + template + auto lookup(T from) const { + auto result = lookupOrNull(from); + assert(result && "expected 'from' to be contained within the map"); + return result; + } + + /// Clears all mappings held by the mapper. + void clear() { valueMap.clear(); } + + /// Return the held value mapping. + const DenseMap &getValueMap() const { return valueMap; } + + /// Return the held block mapping. + const DenseMap &getBlockMap() const { return blockMap; } + + /// Return the held operation mapping. + const DenseMap &getOperationMap() const { + return operationMap; + } + +private: + /// Return the map for the given value type. + template + auto &getMap() const { + if constexpr (std::is_convertible_v) + return const_cast &>(valueMap); + else if constexpr (std::is_convertible_v) + return const_cast &>(blockMap); + else + return const_cast &>(operationMap); + } + + /// Utility lookupOrValue that looks up an existing key or returns the + /// provided value. + template + auto lookupOrValue(T from, T value) const { + auto &map = getMap(); + auto it = map.find(from); + return it != map.end() ? it->second : value; + } + + DenseMap valueMap; + DenseMap blockMap; + DenseMap operationMap; +}; + +} // namespace mlir + +#endif // MLIR_IR_IRMAPPING_H diff --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h index 61f1c028ba32a..18844000787c7 100644 --- a/mlir/include/mlir/IR/Operation.h +++ b/mlir/include/mlir/IR/Operation.h @@ -167,7 +167,7 @@ class alignas(8) Operation final /// as top level function operations, is therefore always safe. Using the /// mapper, it is possible to avoid adding uses to outside operands by /// remapping them to 'Value's owned by the caller thread. - Operation *clone(BlockAndValueMapping &mapper, + Operation *clone(IRMapping &mapper, CloneOptions options = CloneOptions::all()); Operation *clone(CloneOptions options = CloneOptions::all()); @@ -176,7 +176,7 @@ class alignas(8) Operation final /// original one, but they will be left empty. /// Operands are remapped using `mapper` (if present), and `mapper` is updated /// to contain the results. - Operation *cloneWithoutRegions(BlockAndValueMapping &mapper); + Operation *cloneWithoutRegions(IRMapping &mapper); /// Create a partial copy of this operation without traversing into attached /// regions. The new operation will have the same number of regions as the diff --git a/mlir/include/mlir/IR/PatternMatch.h b/mlir/include/mlir/IR/PatternMatch.h index 3ee533c89c537..9c6f1d4dd5480 100644 --- a/mlir/include/mlir/IR/PatternMatch.h +++ b/mlir/include/mlir/IR/PatternMatch.h @@ -410,8 +410,7 @@ class RewriterBase : public OpBuilder, public OpBuilder::Listener { /// responsible for creating or updating the operation transferring flow of /// control to the region and passing it the correct block arguments. virtual void cloneRegionBefore(Region ®ion, Region &parent, - Region::iterator before, - BlockAndValueMapping &mapping); + Region::iterator before, IRMapping &mapping); void cloneRegionBefore(Region ®ion, Region &parent, Region::iterator before); void cloneRegionBefore(Region ®ion, Block *before); diff --git a/mlir/include/mlir/IR/Region.h b/mlir/include/mlir/IR/Region.h index f5168138056a1..7b2927c6e080b 100644 --- a/mlir/include/mlir/IR/Region.h +++ b/mlir/include/mlir/IR/Region.h @@ -19,7 +19,7 @@ namespace mlir { class TypeRange; template class ValueTypeRange; -class BlockAndValueMapping; +class IRMapping; /// This class contains a list of basic blocks and a link to the parent /// operation it is attached to. @@ -232,10 +232,9 @@ class Region { /// process of cloning, no new uses of 'Value's from outside the region are /// created. Using the mapper, it is possible to avoid adding uses to outside /// operands by remapping them to 'Value's owned by the caller thread. - void cloneInto(Region *dest, BlockAndValueMapping &mapper); + void cloneInto(Region *dest, IRMapping &mapper); /// Clone this region into 'dest' before the given position in 'dest'. - void cloneInto(Region *dest, Region::iterator destPos, - BlockAndValueMapping &mapper); + void cloneInto(Region *dest, Region::iterator destPos, IRMapping &mapper); /// Takes body of another region (that region will have no body after this /// operation completes). The current body of this region is cleared. diff --git a/mlir/include/mlir/Interfaces/DestinationStyleOpInterface.h b/mlir/include/mlir/Interfaces/DestinationStyleOpInterface.h index fe8478e89cbe2..9ace95c6f3d3b 100644 --- a/mlir/include/mlir/Interfaces/DestinationStyleOpInterface.h +++ b/mlir/include/mlir/Interfaces/DestinationStyleOpInterface.h @@ -9,9 +9,9 @@ #ifndef MLIR_INTERFACES_DESTINATIONSTYLEOPINTERFACE_H_ #define MLIR_INTERFACES_DESTINATIONSTYLEOPINTERFACE_H_ -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinTypes.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/OpDefinition.h" #include "mlir/IR/Value.h" #include "llvm/ADT/SmallVector.h" diff --git a/mlir/include/mlir/Transforms/DialectConversion.h b/mlir/include/mlir/Transforms/DialectConversion.h index f024d80e59743..5c0d49295e75f 100644 --- a/mlir/include/mlir/Transforms/DialectConversion.h +++ b/mlir/include/mlir/Transforms/DialectConversion.h @@ -620,8 +620,7 @@ class ConversionPatternRewriter final : public PatternRewriter { /// yet, i.e. it must be within an operation that is either in the process of /// conversion, or has not yet been converted. void cloneRegionBefore(Region ®ion, Region &parent, - Region::iterator before, - BlockAndValueMapping &mapping) override; + Region::iterator before, IRMapping &mapping) override; using PatternRewriter::cloneRegionBefore; /// PatternRewriter hook for inserting a new operation. diff --git a/mlir/include/mlir/Transforms/InliningUtils.h b/mlir/include/mlir/Transforms/InliningUtils.h index 99891016e8d02..6c914d6c1d7ff 100644 --- a/mlir/include/mlir/Transforms/InliningUtils.h +++ b/mlir/include/mlir/Transforms/InliningUtils.h @@ -20,7 +20,7 @@ namespace mlir { class Block; -class BlockAndValueMapping; +class IRMapping; class CallableOpInterface; class CallOpInterface; class OpBuilder; @@ -67,7 +67,7 @@ class DialectInlinerInterface /// used to examine what values will replace entry arguments into the 'src' /// region for example. virtual bool isLegalToInline(Region *dest, Region *src, bool wouldBeCloned, - BlockAndValueMapping &valueMapping) const { + IRMapping &valueMapping) const { return false; } @@ -79,7 +79,7 @@ class DialectInlinerInterface /// remapped values from within the 'src' region. This can be used to examine /// what values may potentially replace the operands to 'op'. virtual bool isLegalToInline(Operation *op, Region *dest, bool wouldBeCloned, - BlockAndValueMapping &valueMapping) const { + IRMapping &valueMapping) const { return false; } @@ -170,9 +170,9 @@ class InlinerInterface virtual bool isLegalToInline(Operation *call, Operation *callable, bool wouldBeCloned) const; virtual bool isLegalToInline(Region *dest, Region *src, bool wouldBeCloned, - BlockAndValueMapping &valueMapping) const; + IRMapping &valueMapping) const; virtual bool isLegalToInline(Operation *op, Region *dest, bool wouldBeCloned, - BlockAndValueMapping &valueMapping) const; + IRMapping &valueMapping) const; virtual bool shouldAnalyzeRecursively(Operation *op) const; //===--------------------------------------------------------------------===// @@ -205,15 +205,14 @@ class InlinerInterface /// information. 'shouldCloneInlinedRegion' corresponds to whether the source /// region should be cloned into the 'inlinePoint' or spliced directly. LogicalResult inlineRegion(InlinerInterface &interface, Region *src, - Operation *inlinePoint, BlockAndValueMapping &mapper, + Operation *inlinePoint, IRMapping &mapper, ValueRange resultsToReplace, TypeRange regionResultTypes, Optional inlineLoc = std::nullopt, bool shouldCloneInlinedRegion = true); LogicalResult inlineRegion(InlinerInterface &interface, Region *src, Block *inlineBlock, Block::iterator inlinePoint, - BlockAndValueMapping &mapper, - ValueRange resultsToReplace, + IRMapping &mapper, ValueRange resultsToReplace, TypeRange regionResultTypes, Optional inlineLoc = std::nullopt, bool shouldCloneInlinedRegion = true); diff --git a/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp b/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp index f1a32fa8fde67..ebff3cc9a0c6f 100644 --- a/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp +++ b/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp @@ -18,7 +18,7 @@ #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/SCF/IR/SCF.h" #include "mlir/Dialect/Vector/IR/VectorOps.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/IntegerSet.h" #include "mlir/IR/MLIRContext.h" #include "mlir/Transforms/DialectConversion.h" diff --git a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp index 0cd024e4ae89b..c905fd567768e 100644 --- a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp +++ b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp @@ -26,11 +26,11 @@ #include "mlir/Dialect/LLVMIR/LLVMTypes.h" #include "mlir/Dialect/Utils/StaticValueUtils.h" #include "mlir/IR/Attributes.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinAttributeInterfaces.h" #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/BuiltinOps.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeUtilities.h" #include "mlir/Support/LogicalResult.h" diff --git a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp index 36ed389132cff..4d5af81757d03 100644 --- a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp +++ b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp @@ -19,7 +19,7 @@ #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/IR/AffineMap.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include "mlir/Pass/Pass.h" #include "llvm/ADT/SmallBitVector.h" #include @@ -557,7 +557,7 @@ struct GenericAtomicRMWOpLowering // Clone the GenericAtomicRMWOp region and extract the result. auto loopArgument = loopBlock->getArgument(0); - BlockAndValueMapping mapping; + IRMapping mapping; mapping.map(atomicOp.getCurrentValue(), loopArgument); Block &entryBlock = atomicOp.body().front(); for (auto &nestedOp : entryBlock.without_terminator()) { @@ -599,7 +599,7 @@ struct GenericAtomicRMWOpLowering void moveOpsRange(ValueRange oldResult, ValueRange newResult, Block::iterator start, Block::iterator end, ConversionPatternRewriter &rewriter) const { - BlockAndValueMapping mapping; + IRMapping mapping; mapping.map(oldResult, newResult); SmallVector opsToErase; for (auto it = start; it != end; ++it) { diff --git a/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp b/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp index c15832a8efad6..2f9ad2b7ad9ba 100644 --- a/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp +++ b/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp @@ -16,9 +16,9 @@ #include "mlir/Dialect/Arith/IR/Arith.h" #include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h" #include "mlir/Dialect/SCF/IR/SCF.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinOps.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/MLIRContext.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Transforms/DialectConversion.h" diff --git a/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp b/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp index 6be4a356e9671..c3084e503a806 100644 --- a/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp +++ b/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp @@ -22,8 +22,8 @@ #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/SCF/IR/SCF.h" #include "mlir/IR/AffineExpr.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" +#include "mlir/IR/IRMapping.h" #include "mlir/Interfaces/SideEffectInterfaces.h" #include "mlir/Pass/Pass.h" #include "mlir/Transforms/DialectConversion.h" @@ -403,8 +403,8 @@ static unsigned getLaunchOpArgumentNum(gpu::Processor processor) { /// worklist. This signals the processor of the worklist to pop the rewriter /// one scope-level up. static LogicalResult processParallelLoop( - ParallelOp parallelOp, gpu::LaunchOp launchOp, - BlockAndValueMapping &cloningMap, SmallVectorImpl &worklist, + ParallelOp parallelOp, gpu::LaunchOp launchOp, IRMapping &cloningMap, + SmallVectorImpl &worklist, DenseMap &bounds, PatternRewriter &rewriter) { // TODO: Verify that this is a valid GPU mapping. // processor ids: 0-2 block [x/y/z], 3-5 -> thread [x/y/z], 6-> sequential @@ -615,7 +615,7 @@ ParallelToGpuLaunchLowering::matchAndRewrite(ParallelOp parallelOp, rewriter.create(loc); rewriter.setInsertionPointToStart(&launchOp.getBody().front()); - BlockAndValueMapping cloningMap; + IRMapping cloningMap; llvm::DenseMap launchBounds; SmallVector worklist; if (failed(processParallelLoop(parallelOp, launchOp, cloningMap, worklist, diff --git a/mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp b/mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp index e641bb40982f8..4e746ea561cb8 100644 --- a/mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp +++ b/mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp @@ -13,7 +13,7 @@ #include "mlir/Dialect/SCF/IR/SCF.h" #include "mlir/Dialect/Shape/IR/Shape.h" #include "mlir/Dialect/Tensor/IR/Tensor.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/ImplicitLocOpBuilder.h" #include "mlir/Pass/Pass.h" #include "mlir/Transforms/DialectConversion.h" @@ -439,7 +439,7 @@ ReduceOpConverter::matchAndRewrite(shape::ReduceOp op, OpAdaptor adaptor, SmallVector mappedValues{iv, extent}; mappedValues.append(args.begin(), args.end()); - BlockAndValueMapping mapping; + IRMapping mapping; Block *reduceBody = op.getBody(); mapping.map(reduceBody->getArguments(), mappedValues); for (auto &nested : reduceBody->without_terminator()) diff --git a/mlir/lib/Conversion/TosaToSCF/TosaToSCF.cpp b/mlir/lib/Conversion/TosaToSCF/TosaToSCF.cpp index 3b261ffbb2de9..8f10497d99c32 100644 --- a/mlir/lib/Conversion/TosaToSCF/TosaToSCF.cpp +++ b/mlir/lib/Conversion/TosaToSCF/TosaToSCF.cpp @@ -14,7 +14,7 @@ #include "mlir/Dialect/SCF/IR/SCF.h" #include "mlir/Dialect/Tensor/IR/Tensor.h" #include "mlir/Dialect/Tosa/IR/TosaOps.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp index 401e91b75956c..3ac25b7f5d33c 100644 --- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp +++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp @@ -10,7 +10,7 @@ #include "mlir/Dialect/Affine/IR/AffineValueMap.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/IR/AffineExprVisitor.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/IntegerSet.h" #include "mlir/IR/Matchers.h" #include "mlir/IR/OpDefinition.h" @@ -46,7 +46,7 @@ bool mlir::isTopLevelValue(Value value, Region *region) { /// dimension or symbol. static bool remainsLegalAfterInline(Value value, Region *src, Region *dest, - const BlockAndValueMapping &mapping, + const IRMapping &mapping, function_ref legalityCheck) { // If the value is a valid dimension for any other reason than being // a top-level value, it will remain valid: constants get inlined @@ -75,7 +75,7 @@ remainsLegalAfterInline(Value value, Region *src, Region *dest, /// remain so if their respective users are inlined into `dest`. static bool remainsLegalAfterInline(ValueRange values, Region *src, Region *dest, - const BlockAndValueMapping &mapping, + const IRMapping &mapping, function_ref legalityCheck) { return llvm::all_of(values, [&](Value v) { return remainsLegalAfterInline(v, src, dest, mapping, legalityCheck); @@ -86,7 +86,7 @@ remainsLegalAfterInline(ValueRange values, Region *src, Region *dest, /// from `src` to `dest`. template static bool remainsLegalAfterInline(OpTy op, Region *src, Region *dest, - const BlockAndValueMapping &mapping) { + const IRMapping &mapping) { static_assert(llvm::is_one_of::value, "only ops with affine read/write interface are supported"); @@ -111,9 +111,9 @@ static bool remainsLegalAfterInline(OpTy op, Region *src, Region *dest, // Use "unused attribute" marker to silence clang-tidy warning stemming from // the inability to see through "llvm::TypeSwitch". template <> -bool LLVM_ATTRIBUTE_UNUSED -remainsLegalAfterInline(AffineApplyOp op, Region *src, Region *dest, - const BlockAndValueMapping &mapping) { +bool LLVM_ATTRIBUTE_UNUSED remainsLegalAfterInline(AffineApplyOp op, + Region *src, Region *dest, + const IRMapping &mapping) { // If it's a valid dimension, we need to check that it remains so. if (isValidDim(op.getResult(), src)) return remainsLegalAfterInline( @@ -145,7 +145,7 @@ struct AffineInlinerInterface : public DialectInlinerInterface { /// 'wouldBeCloned' is set if the region is cloned into its new location /// rather than moved, indicating there may be other users. bool isLegalToInline(Region *dest, Region *src, bool wouldBeCloned, - BlockAndValueMapping &valueMapping) const final { + IRMapping &valueMapping) const final { // We can inline into affine loops and conditionals if this doesn't break // affine value categorization rules. Operation *destOp = dest->getParentOp(); @@ -190,7 +190,7 @@ struct AffineInlinerInterface : public DialectInlinerInterface { /// Returns true if the given operation 'op', that is registered to this /// dialect, can be inlined into the given region, false otherwise. bool isLegalToInline(Operation *op, Region *region, bool wouldBeCloned, - BlockAndValueMapping &valueMapping) const final { + IRMapping &valueMapping) const final { // Always allow inlining affine operations into a region that is marked as // affine scope, or into affine loops and conditionals. There are some edge // cases when inlining *into* affine structures, but that is handled in the diff --git a/mlir/lib/Dialect/Affine/Transforms/LoopTiling.cpp b/mlir/lib/Dialect/Affine/Transforms/LoopTiling.cpp index 3b1b48e31aee6..b8591231b6931 100644 --- a/mlir/lib/Dialect/Affine/Transforms/LoopTiling.cpp +++ b/mlir/lib/Dialect/Affine/Transforms/LoopTiling.cpp @@ -21,8 +21,8 @@ #include "mlir/Dialect/Affine/LoopUtils.h" #include "mlir/Dialect/Affine/Utils.h" #include "mlir/Dialect/Func/IR/FuncOps.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" +#include "mlir/IR/IRMapping.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" diff --git a/mlir/lib/Dialect/Affine/Transforms/LoopUnrollAndJam.cpp b/mlir/lib/Dialect/Affine/Transforms/LoopUnrollAndJam.cpp index cad62c4a55caf..ec76320ffa4a8 100644 --- a/mlir/lib/Dialect/Affine/Transforms/LoopUnrollAndJam.cpp +++ b/mlir/lib/Dialect/Affine/Transforms/LoopUnrollAndJam.cpp @@ -42,8 +42,8 @@ #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/AffineExpr.h" #include "mlir/IR/AffineMap.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" +#include "mlir/IR/IRMapping.h" #include "llvm/ADT/DenseMap.h" #include "llvm/Support/CommandLine.h" diff --git a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp index 2bdbb8bb9f4b8..86ebf1b54a40b 100644 --- a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp +++ b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp @@ -23,7 +23,7 @@ #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/Vector/IR/VectorOps.h" #include "mlir/Dialect/Vector/Utils/VectorUtils.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include "mlir/Pass/Pass.h" #include "mlir/Support/LLVM.h" #include "llvm/ADT/STLExtras.h" @@ -747,10 +747,10 @@ struct VectorizationState { // Maps input scalar operations to their vector counterparts. DenseMap opVectorReplacement; // Maps input scalar values to their vector counterparts. - BlockAndValueMapping valueVectorReplacement; + IRMapping valueVectorReplacement; // Maps input scalar values to their new scalar counterparts in the vector // loop nest. - BlockAndValueMapping valueScalarReplacement; + IRMapping valueScalarReplacement; // Maps results of reduction loops to their new scalar counterparts. DenseMap loopResultScalarReplacement; diff --git a/mlir/lib/Dialect/Affine/Utils/LoopFusionUtils.cpp b/mlir/lib/Dialect/Affine/Utils/LoopFusionUtils.cpp index 50a31abac28bc..27b56054dee9b 100644 --- a/mlir/lib/Dialect/Affine/Utils/LoopFusionUtils.cpp +++ b/mlir/lib/Dialect/Affine/Utils/LoopFusionUtils.cpp @@ -17,7 +17,7 @@ #include "mlir/Dialect/Affine/Analysis/Utils.h" #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Affine/LoopUtils.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/Operation.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" @@ -422,7 +422,7 @@ void mlir::fuseLoops(AffineForOp srcForOp, AffineForOp dstForOp, bool isInnermostSiblingInsertion) { // Clone 'srcForOp' into 'dstForOp' at 'srcSlice->insertPoint'. OpBuilder b(srcSlice.insertPoint->getBlock(), srcSlice.insertPoint); - BlockAndValueMapping mapper; + IRMapping mapper; b.clone(*srcForOp, mapper); // Update 'sliceLoopNest' upper and lower bounds from computed 'srcSlice'. diff --git a/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp b/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp index 89859bbe3aa08..d92ab6ea0f78a 100644 --- a/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp +++ b/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp @@ -21,7 +21,7 @@ #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/SCF/IR/SCF.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/IntegerSet.h" #include "mlir/Support/MathExtras.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" @@ -193,7 +193,7 @@ static AffineForOp generateShiftedLoop( auto loopChunkIV = loopChunk.getInductionVar(); auto srcIV = srcForOp.getInductionVar(); - BlockAndValueMapping operandMap; + IRMapping operandMap; auto bodyBuilder = OpBuilder::atBlockTerminator(loopChunk.getBody()); for (const auto &it : llvm::drop_begin(opGroupQueue, offset)) { @@ -1017,7 +1017,7 @@ static void generateUnrolledLoop( SmallVector lastYielded(yieldedValues); for (unsigned i = 1; i < unrollFactor; i++) { - BlockAndValueMapping operandMap; + IRMapping operandMap; // Prepare operand map. operandMap.map(iterArgs, lastYielded); @@ -1265,7 +1265,7 @@ LogicalResult mlir::loopUnrollJamByFactor(AffineForOp forOp, // `operandMaps[i - 1]` carries old->new operand mapping for the ith unrolled // iteration. There are (`unrollJamFactor` - 1) iterations. - SmallVector operandMaps(unrollJamFactor - 1); + SmallVector operandMaps(unrollJamFactor - 1); // For any loop with iter_args, replace it with a new loop that has // `unrollJamFactor` copies of its iterOperands, iter_args and yield @@ -2777,7 +2777,7 @@ createFullTiles(MutableArrayRef inputNest, } // Add the body for the full tile loop nest. - BlockAndValueMapping operandMap; + IRMapping operandMap; for (const auto &loopEn : llvm::enumerate(inputNest)) operandMap.map(loopEn.value().getInductionVar(), fullTileLoops[loopEn.index()].getInductionVar()); diff --git a/mlir/lib/Dialect/Affine/Utils/Utils.cpp b/mlir/lib/Dialect/Affine/Utils/Utils.cpp index ece17badbba93..5c32c9e309350 100644 --- a/mlir/lib/Dialect/Affine/Utils/Utils.cpp +++ b/mlir/lib/Dialect/Affine/Utils/Utils.cpp @@ -21,8 +21,8 @@ #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/IR/AffineExprVisitor.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Dominance.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/IntegerSet.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" @@ -288,7 +288,7 @@ static AffineIfOp hoistAffineIfOp(AffineIfOp ifOp, Operation *hoistOverOp) { // branch while promoting its then block, and analogously drop the 'then' // block of the original 'if' from the 'else' branch while promoting its else // block. - BlockAndValueMapping operandMap; + IRMapping operandMap; OpBuilder b(hoistOverOp); auto hoistedIfOp = b.create(ifOp.getLoc(), ifOp.getIntegerSet(), ifOp.getOperands(), diff --git a/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp b/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp index b15f7f05b8531..0a7b2c4f0b561 100644 --- a/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp +++ b/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp @@ -27,8 +27,7 @@ struct ArithInlinerInterface : public DialectInlinerInterface { using DialectInlinerInterface::DialectInlinerInterface; /// All arithmetic dialect ops can be inlined. - bool isLegalToInline(Operation *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final { return true; } }; diff --git a/mlir/lib/Dialect/Async/IR/Async.cpp b/mlir/lib/Dialect/Async/IR/Async.cpp index db481f19fcd85..8ccec11b8e218 100644 --- a/mlir/lib/Dialect/Async/IR/Async.cpp +++ b/mlir/lib/Dialect/Async/IR/Async.cpp @@ -8,9 +8,9 @@ #include "mlir/Dialect/Async/IR/Async.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/DialectImplementation.h" #include "mlir/IR/FunctionImplementation.h" +#include "mlir/IR/IRMapping.h" #include "llvm/ADT/MapVector.h" #include "llvm/ADT/TypeSwitch.h" diff --git a/mlir/lib/Dialect/Async/Transforms/AsyncParallelFor.cpp b/mlir/lib/Dialect/Async/Transforms/AsyncParallelFor.cpp index 04977a98e6ba2..3cd4677c2cb8b 100644 --- a/mlir/lib/Dialect/Async/Transforms/AsyncParallelFor.cpp +++ b/mlir/lib/Dialect/Async/Transforms/AsyncParallelFor.cpp @@ -18,7 +18,7 @@ #include "mlir/Dialect/Async/Transforms.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/SCF/IR/SCF.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/ImplicitLocOpBuilder.h" #include "mlir/IR/Matchers.h" #include "mlir/IR/PatternMatch.h" @@ -425,7 +425,7 @@ static ParallelComputeFunction createParallelComputeFunction( } // Copy the body of the parallel op into the inner-most loop. - BlockAndValueMapping mapping; + IRMapping mapping; mapping.map(op.getInductionVars(), computeBlockInductionVars); mapping.map(computeFuncType.captures, captures); diff --git a/mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp b/mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp index df6f1d80d7d23..e2120ed644c34 100644 --- a/mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp +++ b/mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp @@ -22,7 +22,7 @@ #include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/SCF/IR/SCF.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/ImplicitLocOpBuilder.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Transforms/DialectConversion.h" @@ -319,7 +319,7 @@ outlineExecuteOp(SymbolTable &symbolTable, ExecuteOp execute) { // Map from function inputs defined above the execute op to the function // arguments. - BlockAndValueMapping valueMapping; + IRMapping valueMapping; valueMapping.map(functionInputs, func.getArguments()); valueMapping.map(execute.getBodyRegion().getArguments(), unwrappedOperands); diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp index 68990eaa0b697..af0d48a126af8 100644 --- a/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp +++ b/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp @@ -12,8 +12,8 @@ #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/Tensor/IR/Tensor.h" #include "mlir/IR/AsmState.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/BuiltinOps.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/Operation.h" #include "mlir/IR/TypeUtilities.h" #include "mlir/IR/Value.h" @@ -723,7 +723,7 @@ LogicalResult BufferizationOptions::createMemCpy(OpBuilder &b, Location loc, } //===----------------------------------------------------------------------===// -// Bufferization-specific BlockAndValueMapping support with debugging. +// Bufferization-specific IRMapping support with debugging. //===----------------------------------------------------------------------===// bool bufferization::isFunctionArgument(Value value) { diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp index a8e6d51940395..0052829e2dd43 100644 --- a/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp +++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp @@ -40,8 +40,7 @@ struct BufferizationInlinerInterface : public DialectInlinerInterface { using DialectInlinerInterface::DialectInlinerInterface; /// Operations in Bufferization dialect are always legal to inline. - bool isLegalToInline(Operation *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final { return true; } }; diff --git a/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp b/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp index 6230d67806556..659d1c883c877 100644 --- a/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp +++ b/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp @@ -12,10 +12,10 @@ #include "mlir/Dialect/CommonFolders.h" #include "mlir/IR/AffineExpr.h" #include "mlir/IR/AffineMap.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/BuiltinTypes.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/Matchers.h" #include "mlir/IR/OpImplementation.h" #include "mlir/IR/PatternMatch.h" @@ -49,8 +49,7 @@ struct ControlFlowInlinerInterface : public DialectInlinerInterface { bool wouldBeCloned) const final { return true; } - bool isLegalToInline(Operation *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final { return true; } diff --git a/mlir/lib/Dialect/Func/IR/FuncOps.cpp b/mlir/lib/Dialect/Func/IR/FuncOps.cpp index de96e46c5376f..7205a7eac18e2 100644 --- a/mlir/lib/Dialect/Func/IR/FuncOps.cpp +++ b/mlir/lib/Dialect/Func/IR/FuncOps.cpp @@ -9,11 +9,11 @@ #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/FunctionImplementation.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/Matchers.h" #include "mlir/IR/OpImplementation.h" #include "mlir/IR/PatternMatch.h" @@ -52,14 +52,12 @@ struct FuncInlinerInterface : public DialectInlinerInterface { } /// All operations can be inlined. - bool isLegalToInline(Operation *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final { return true; } /// All functions can be inlined. - bool isLegalToInline(Region *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Region *, Region *, bool, IRMapping &) const final { return true; } @@ -275,7 +273,7 @@ void FuncOp::print(OpAsmPrinter &p) { /// Clone the internal blocks from this function into dest and all attributes /// from this function to dest. -void FuncOp::cloneInto(FuncOp dest, BlockAndValueMapping &mapper) { +void FuncOp::cloneInto(FuncOp dest, IRMapping &mapper) { // Add the attributes of this function to dest. llvm::MapVector newAttrMap; for (const auto &attr : dest->getAttrs()) @@ -298,7 +296,7 @@ void FuncOp::cloneInto(FuncOp dest, BlockAndValueMapping &mapper) { /// provided (leaving them alone if no entry is present). Replaces references /// to cloned sub-values with the corresponding value that is copied, and adds /// those mappings to the mapper. -FuncOp FuncOp::clone(BlockAndValueMapping &mapper) { +FuncOp FuncOp::clone(IRMapping &mapper) { // Create the new function. FuncOp newFunc = cast(getOperation()->cloneWithoutRegions()); @@ -337,7 +335,7 @@ FuncOp FuncOp::clone(BlockAndValueMapping &mapper) { return newFunc; } FuncOp FuncOp::clone() { - BlockAndValueMapping mapper; + IRMapping mapper; return clone(mapper); } diff --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp index e55e9a60fa67d..031e0d92153e8 100644 --- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp +++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp @@ -122,8 +122,7 @@ struct GPUInlinerInterface : public DialectInlinerInterface { using DialectInlinerInterface::DialectInlinerInterface; /// All gpu dialect ops can be inlined. - bool isLegalToInline(Operation *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final { return true; } }; diff --git a/mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp b/mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp index 4dc80e84b18ca..6442523d624f0 100644 --- a/mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp +++ b/mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp @@ -17,7 +17,7 @@ #include "mlir/Dialect/Transform/IR/TransformDialect.h" #include "mlir/Dialect/Transform/IR/TransformInterfaces.h" #include "mlir/Dialect/Transform/IR/TransformUtils.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" using namespace mlir; using namespace mlir::gpu; @@ -225,7 +225,7 @@ DiagnosedSilenceableFailure mlir::transform::gpu::mapForeachToBlocksImpl( // induction variables to the newly created ops. SmallVector blockOps; blockIdGenerator(rewriter, foreachThreadOp, blockOps); - BlockAndValueMapping bvm; + IRMapping bvm; for (auto [blockIdx, blockDim] : llvm::zip(foreachThreadOp.getThreadIndices(), blockMapping)) { bvm.map(blockIdx, @@ -434,7 +434,7 @@ static DiagnosedSilenceableFailure rewriteOneForeachThreadToGpuThreads( rewriter.create(loc, indexType, Dimension::x), rewriter.create(loc, indexType, Dimension::y), rewriter.create(loc, indexType, Dimension::z)}; - BlockAndValueMapping bvm; + IRMapping bvm; for (auto [blockIdx, blockDim] : llvm::zip(foreachThreadOp.getThreadIndices(), threadMapping)) { bvm.map( diff --git a/mlir/lib/Dialect/GPU/Transforms/AllReduceLowering.cpp b/mlir/lib/Dialect/GPU/Transforms/AllReduceLowering.cpp index 96ca93f547a3b..894573b919efd 100644 --- a/mlir/lib/Dialect/GPU/Transforms/AllReduceLowering.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/AllReduceLowering.cpp @@ -16,8 +16,8 @@ #include "mlir/Dialect/GPU/IR/GPUDialect.h" #include "mlir/Dialect/GPU/Transforms/Passes.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Pass/Pass.h" @@ -186,7 +186,7 @@ struct GpuAllReduceRewriter { Block *split = rewriter.splitBlock(block, rewriter.getInsertionPoint()); // Insert accumulator body between split block. - BlockAndValueMapping mapping; + IRMapping mapping; mapping.map(body.getArgument(0), lhs); mapping.map(body.getArgument(1), rhs); rewriter.cloneRegionBefore(body, *split->getParent(), diff --git a/mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp b/mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp index c8a835ce35e83..cb3cebef79730 100644 --- a/mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp @@ -17,8 +17,8 @@ #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/GPU/IR/GPUDialect.h" #include "mlir/Dialect/GPU/Transforms/Utils.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/SymbolTable.h" #include "mlir/Interfaces/SideEffectInterfaces.h" @@ -116,7 +116,7 @@ struct GpuAsyncRegionPass::ThreadTokenCallback { op->getSuccessors(), op->getNumRegions()); // Clone regions into new op. - BlockAndValueMapping mapping; + IRMapping mapping; for (auto pair : llvm::zip_first(op->getRegions(), newOp->getRegions())) std::get<0>(pair).cloneInto(&std::get<1>(pair), mapping); @@ -170,7 +170,7 @@ async::ExecuteOp addExecuteResults(async::ExecuteOp executeOp, auto newOp = builder.create( executeOp.getLoc(), TypeRange{resultTypes}.drop_front() /*drop token*/, executeOp.getDependencies(), executeOp.getBodyOperands()); - BlockAndValueMapping mapper; + IRMapping mapper; newOp.getRegion().getBlocks().clear(); executeOp.getRegion().cloneInto(&newOp.getRegion(), mapper); diff --git a/mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp b/mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp index e8883ea7c8eb7..8abf75993a63d 100644 --- a/mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp @@ -20,9 +20,9 @@ #include "mlir/Dialect/GPU/IR/GPUDialect.h" #include "mlir/Dialect/GPU/Transforms/Utils.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinAttributes.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/Matchers.h" #include "mlir/IR/SymbolTable.h" #include "mlir/Support/LLVM.h" @@ -49,8 +49,7 @@ static void createForAllDimensions(OpBuilder &builder, Location loc, /// entry block of `launchOpBody`, to the corresponding result value of the /// added operations. static void injectGpuIndexOperations(Location loc, Region &launchFuncOpBody, - Region &launchOpBody, - BlockAndValueMapping &map) { + Region &launchOpBody, IRMapping &map) { OpBuilder builder(loc->getContext()); Block &firstBlock = launchOpBody.front(); builder.setInsertionPointToStart(&launchFuncOpBody.front()); @@ -137,7 +136,7 @@ LogicalResult mlir::sinkOperationsIntoLaunchOp( } // Insert operations so that the defs get cloned before uses. - BlockAndValueMapping map; + IRMapping map; OpBuilder builder(launchOpBody); for (Operation *op : toBeSunk) { Operation *clonedOp = builder.clone(*op, map); @@ -207,7 +206,7 @@ static gpu::GPUFuncOp outlineKernelFuncImpl(gpu::LaunchOp launchOp, outlinedFunc->setAttr(gpu::GPUFuncOp::getKnownGridSizeAttrName(), gridBounds); - BlockAndValueMapping map; + IRMapping map; // Map the arguments corresponding to the launch parameters like blockIdx, // threadIdx, etc. diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp index adab5fe66c6e1..4a6ed4c5c7fe5 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -2870,8 +2870,7 @@ struct LLVMInlinerInterface : public DialectInlinerInterface { using DialectInlinerInterface::DialectInlinerInterface; /// Conservative allowlist-based inlining of operations supported so far. - bool isLegalToInline(Operation *op, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Operation *op, Region *, bool, IRMapping &) const final { if (isPure(op)) return true; return llvm::TypeSwitch(op) diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp index 0c27575d3badd..bf663f458ace5 100644 --- a/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp @@ -44,12 +44,11 @@ struct LinalgInlinerInterface : public DialectInlinerInterface { // We don't have any special restrictions on what can be inlined into // destination regions (e.g. while/conditional bodies). Always allow it. bool isLegalToInline(Region *dest, Region *src, bool wouldBeCloned, - BlockAndValueMapping &valueMapping) const final { + IRMapping &valueMapping) const final { return true; } // Operations in Linalg dialect are always legal to inline. - bool isLegalToInline(Operation *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final { return true; } // Handle the given inlined terminator by replacing it with a new operation diff --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp index 509739691ab5e..7d2f6da935ae8 100644 --- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp +++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp @@ -384,7 +384,7 @@ static Operation *tileAndFuseFirstExtractUseThroughContainingOpBlockArgument( return nullptr; } - BlockAndValueMapping bvm; + IRMapping bvm; bvm.map(destinationTensors[resultNumber], bbArg); auto tileableProducerClone = cast(rewriter.clone(*tileableProducer, bvm)); diff --git a/mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp b/mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp index 8dc14ea507104..f122712b209bf 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp @@ -324,7 +324,7 @@ struct MoveInitOperandsToInput : public OpRewritePattern { Region ®ion = newOp.getRegion(); Block *block = new Block(); region.push_back(block); - BlockAndValueMapping mapper; + IRMapping mapper; OpBuilder::InsertionGuard guard(rewriter); rewriter.setInsertionPointToStart(block); for (auto bbarg : genericOp.getRegionInputArgs()) diff --git a/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp b/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp index 7f2b915731552..58216fee60303 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp @@ -157,7 +157,7 @@ static void generateFusedElementwiseOpRegion( Block &consumerBlock = consumer->getRegion(0).front(); Block *fusedBlock = new Block(); fusedOp.getRegion().push_back(fusedBlock); - BlockAndValueMapping mapper; + IRMapping mapper; OpBuilder::InsertionGuard guard(rewriter); rewriter.setInsertionPointToStart(fusedBlock); @@ -1684,7 +1684,7 @@ class FoldScalarOrSplatConstant : public OpRewritePattern { // scalar constant. Region ®ion = genericOp->getRegion(0); Block &entryBlock = *region.begin(); - BlockAndValueMapping mapping; + IRMapping mapping; mapping.map(entryBlock.getArgument(opOperand->getOperandNumber()), scalarConstant); Region &fusedRegion = fusedOp->getRegion(0); diff --git a/mlir/lib/Dialect/Linalg/Transforms/HoistPadding.cpp b/mlir/lib/Dialect/Linalg/Transforms/HoistPadding.cpp index a83305d013bcb..b8e4f4af17d68 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/HoistPadding.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/HoistPadding.cpp @@ -447,7 +447,7 @@ FailureOr mlir::linalg::hoistPaddingOnTensors( SmallVector clonedLoopIvs, leadingPackedTensorIndexings; clonedLoopIvs.reserve(nPackedLoops); leadingPackedTensorIndexings.reserve(nPackedLoops); - BlockAndValueMapping bvm; + IRMapping bvm; // Stack step 1. iteratively clone loops and push `packedTensor`. for (Operation *op : analysis.backwardSlice) { // Specifically sit out in the extract_slice(packedTensor) case: this is the diff --git a/mlir/lib/Dialect/Linalg/Transforms/Loops.cpp b/mlir/lib/Dialect/Linalg/Transforms/Loops.cpp index b8d0b09b0c90e..d2adaadf233d2 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/Loops.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Loops.cpp @@ -19,7 +19,7 @@ #include "mlir/Dialect/SCF/Utils/AffineCanonicalizationUtils.h" #include "mlir/IR/AffineExpr.h" #include "mlir/IR/AffineMap.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include "mlir/Support/LLVM.h" #include "mlir/Transforms/DialectConversion.h" #include "mlir/Transforms/FoldUtils.h" @@ -61,7 +61,7 @@ static void inlineRegionAndEmitStore(OpBuilder &b, Location loc, OpType op, ArrayRef> indexing, ArrayRef outputBuffers) { auto &block = op->getRegion(0).front(); - BlockAndValueMapping map; + IRMapping map; map.map(block.getArguments(), indexedValues); for (auto &op : block.without_terminator()) { auto *newOp = b.clone(op, map); diff --git a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp index 0c0e0d6e33970..c410b5d15a771 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp @@ -693,7 +693,7 @@ linalg::tileReductionUsingForeachThread(RewriterBase &b, } // 4.b. Clone the op and update init operands. - // We cannot use a BlockAndValueMapping here because it can replace + // We cannot use a IRMapping here because it can replace // different OpOperands with the same value. Operation *clonedOp = b.clone(*op.getOperation()); b.updateRootInPlace(clonedOp, [&]() { diff --git a/mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp b/mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp index 9fcee2b7e0aad..58c0a7b7e62b3 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp @@ -47,7 +47,7 @@ static SmallVector getIndicesForAccess(OpBuilder &b, Location loc, static LogicalResult inlinePayload(OpBuilder &b, LinalgOp linalgOp, ValueRange ivs, ValueRange argValues) { Block *body = linalgOp.getBlock(); - BlockAndValueMapping map; + IRMapping map; map.map(body->getArguments(), argValues); for (auto &op : body->without_terminator()) { if (auto indexOp = dyn_cast(&op)) { @@ -345,7 +345,7 @@ struct LinalgOpPartialReductionInterface auto genericOp = b.create(loc, TypeRange({out.getType()}), tiledOperands, ValueRange({out}), newMaps, newIteratorTypes); - BlockAndValueMapping mapping; + IRMapping mapping; op->getRegion(0).cloneInto(&genericOp.getRegion(), genericOp.getRegion().begin(), mapping); return genericOp.getOperation(); diff --git a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp index 20ee25955f394..9f374991aed3c 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp @@ -381,7 +381,7 @@ Value GeneralizePadOpPattern::createFillOrGenerateOp( auto generateOp = rewriter.create( padOp.getLoc(), padOp.getResultType(), dynSizes); // Copy region to new op. - BlockAndValueMapping bvm; + IRMapping bvm; padOp.getRegion().cloneInto(&generateOp.getRegion(), bvm); return generateOp; } diff --git a/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp b/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp index 58d746088ad91..4f3d55ffde2bc 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp @@ -511,10 +511,10 @@ using CustomVectorizationPrecondition = std::function; // Custom vectorization function type. Produce a vector form of Operation* -// assuming all its vectorized operands are already in the BlockAndValueMapping. +// assuming all its vectorized operands are already in the IRMapping. // Return nullptr if the Operation cannot be vectorized. -using CustomVectorizationHook = std::function; +using CustomVectorizationHook = + std::function; /// Helper function to vectorize the terminator of a `linalgOp`. New result /// vector values are appended to `newResults`. Return @@ -525,7 +525,7 @@ using CustomVectorizationHook = std::function &newResults) { auto yieldOp = dyn_cast(op); if (!yieldOp) @@ -615,7 +615,7 @@ tensorExtractVectorizationPrecondition(Operation *op, bool vectorizeNDExtract) { /// offset = ( ( 1 ) * 80 + 2 ) * 15 + 3 static Value calculateGatherOffset(OpBuilder &b, tensor::ExtractOp extractOp, - const BlockAndValueMapping &bvm, + const IRMapping &bvm, const SmallVectorImpl &targetShape) { // The vector of indices for GatherOp should be shaped as the output vector auto indexVecType = VectorType::get(targetShape, b.getIndexType()); @@ -648,9 +648,10 @@ calculateGatherOffset(OpBuilder &b, tensor::ExtractOp extractOp, /// VectorizationStatus::NewOp to signal the vectorization algorithm that it /// should map the produced operations. This function is meant to be used as a /// CustomVectorizationHook. -static VectorizationResult -vectorizeTensorExtract(RewriterBase &rewriter, Operation *op, LinalgOp linalgOp, - const BlockAndValueMapping &bvm) { +static VectorizationResult vectorizeTensorExtract(RewriterBase &rewriter, + Operation *op, + LinalgOp linalgOp, + const IRMapping &bvm) { tensor::ExtractOp extractOp = dyn_cast(op); if (!extractOp) return VectorizationResult{VectorizationStatus::Failure, nullptr}; @@ -688,10 +689,9 @@ vectorizeTensorExtract(RewriterBase &rewriter, Operation *op, LinalgOp linalgOp, /// that the result shape. // Note: this is a true builder that notifies the OpBuilder listener. // TODO: Consider moving as a static helper on the ReduceOp. -static Operation *reduceIfNeeded(OpBuilder &b, LinalgOp linalgOp, - Operation *op, Value reduceValue, - Value initialValue, - const BlockAndValueMapping &bvm) { +static Operation *reduceIfNeeded(OpBuilder &b, LinalgOp linalgOp, Operation *op, + Value reduceValue, Value initialValue, + const IRMapping &bvm) { Value reduceVec = bvm.lookup(reduceValue); Value outputVec = bvm.lookup(initialValue); auto reduceType = reduceVec.getType().dyn_cast(); @@ -726,7 +726,7 @@ static Operation *reduceIfNeeded(OpBuilder &b, LinalgOp linalgOp, /// instructs the caller what `bvm` update needs to occur. static VectorizationResult vectorizeOneOp(RewriterBase &rewriter, LinalgOp linalgOp, Operation *op, - const BlockAndValueMapping &bvm, + const IRMapping &bvm, ArrayRef customVectorizationHooks) { LDBG("vectorize op " << *op << "\n"); @@ -833,7 +833,7 @@ vectorizeAsLinalgGeneric(RewriterBase &rewriter, VectorizationState &state, // 2. Values defined above the region can only be broadcast for now. Make them // map to themselves. - BlockAndValueMapping bvm; + IRMapping bvm; SetVector valuesSet; mlir::getUsedValuesDefinedAbove(linalgOp->getRegion(0), valuesSet); bvm.map(valuesSet.getArrayRef(), valuesSet.getArrayRef()); @@ -911,24 +911,21 @@ vectorizeAsLinalgGeneric(RewriterBase &rewriter, VectorizationState &state, SmallVector hooks; // 4a. Register CustomVectorizationHook for yieldOp. CustomVectorizationHook vectorizeYield = - [&](Operation *op, - const BlockAndValueMapping &bvm) -> VectorizationResult { + [&](Operation *op, const IRMapping &bvm) -> VectorizationResult { return vectorizeLinalgYield(rewriter, op, bvm, state, linalgOp, newResults); }; hooks.push_back(vectorizeYield); // 4b. Register CustomVectorizationHook for indexOp. CustomVectorizationHook vectorizeIndex = - [&](Operation *op, - const BlockAndValueMapping &bvm) -> VectorizationResult { + [&](Operation *op, const IRMapping &bvm) -> VectorizationResult { return vectorizeLinalgIndex(rewriter, op, linalgOp); }; hooks.push_back(vectorizeIndex); // 4c. Register CustomVectorizationHook for extractOp. CustomVectorizationHook vectorizeExtract = - [&](Operation *op, - const BlockAndValueMapping &bvm) -> VectorizationResult { + [&](Operation *op, const IRMapping &bvm) -> VectorizationResult { return vectorizeTensorExtract(rewriter, op, linalgOp, bvm); }; hooks.push_back(vectorizeExtract); diff --git a/mlir/lib/Dialect/Math/IR/MathDialect.cpp b/mlir/lib/Dialect/Math/IR/MathDialect.cpp index 0f7307cd68b5e..54a8cc1d697b4 100644 --- a/mlir/lib/Dialect/Math/IR/MathDialect.cpp +++ b/mlir/lib/Dialect/Math/IR/MathDialect.cpp @@ -21,8 +21,7 @@ struct MathInlinerInterface : public DialectInlinerInterface { using DialectInlinerInterface::DialectInlinerInterface; /// All operations within math ops can be inlined. - bool isLegalToInline(Operation *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final { return true; } }; diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp index cb325ff179587..6dbcebb64165d 100644 --- a/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp +++ b/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp @@ -24,11 +24,11 @@ namespace { struct MemRefInlinerInterface : public DialectInlinerInterface { using DialectInlinerInterface::DialectInlinerInterface; bool isLegalToInline(Region *dest, Region *src, bool wouldBeCloned, - BlockAndValueMapping &valueMapping) const final { + IRMapping &valueMapping) const final { return true; } bool isLegalToInline(Operation *, Region *, bool wouldBeCloned, - BlockAndValueMapping &) const final { + IRMapping &) const final { return true; } }; diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp index b98f9df6ad987..a709d2c24b92d 100644 --- a/mlir/lib/Dialect/SCF/IR/SCF.cpp +++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp @@ -14,9 +14,9 @@ #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/SCF/IR/DeviceMappingInterface.h" #include "mlir/Dialect/Tensor/IR/Tensor.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/FunctionInterfaces.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/Matchers.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Support/MathExtras.h" @@ -38,13 +38,12 @@ struct SCFInlinerInterface : public DialectInlinerInterface { // We don't have any special restrictions on what can be inlined into // destination regions (e.g. while/conditional bodies). Always allow it. bool isLegalToInline(Region *dest, Region *src, bool wouldBeCloned, - BlockAndValueMapping &valueMapping) const final { + IRMapping &valueMapping) const final { return true; } // Operations in scf dialect are always legal to inline since they are // pure. - bool isLegalToInline(Operation *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final { return true; } // Handle the given inlined terminator by replacing it with a new operation @@ -621,7 +620,7 @@ struct ForOpIterArgsFolder : public OpRewritePattern { // An internal flat vector of block transfer // arguments `newBlockTransferArgs` keeps the 1-1 mapping of original to // transformed block argument mappings. This plays the role of a - // BlockAndValueMapping for the particular use case of calling into + // IRMapping for the particular use case of calling into // `mergeBlockBefore`. SmallVector keepMask; keepMask.reserve(yieldOp.getNumOperands()); @@ -2454,7 +2453,7 @@ struct CollapseSingleIterationLoops : public OpRewritePattern { LogicalResult matchAndRewrite(ParallelOp op, PatternRewriter &rewriter) const override { - BlockAndValueMapping mapping; + IRMapping mapping; // Compute new loop bounds that omit all single-iteration loop dimensions. SmallVector newLowerBounds; SmallVector newUpperBounds; @@ -2573,7 +2572,7 @@ struct MergeNestedParallelLoops : public OpRewritePattern { Block &innerBody = innerOp.getLoopBody().front(); assert(iterVals.size() == (outerBody.getNumArguments() + innerBody.getNumArguments())); - BlockAndValueMapping mapping; + IRMapping mapping; mapping.map(outerBody.getArguments(), iterVals.take_front(outerBody.getNumArguments())); mapping.map(innerBody.getArguments(), diff --git a/mlir/lib/Dialect/SCF/Transforms/LoopPipelining.cpp b/mlir/lib/Dialect/SCF/Transforms/LoopPipelining.cpp index 6d5cd3b33deb5..b9182f5a073ed 100644 --- a/mlir/lib/Dialect/SCF/Transforms/LoopPipelining.cpp +++ b/mlir/lib/Dialect/SCF/Transforms/LoopPipelining.cpp @@ -15,7 +15,7 @@ #include "mlir/Dialect/SCF/Transforms/Patterns.h" #include "mlir/Dialect/SCF/Transforms/Transforms.h" #include "mlir/Dialect/SCF/Utils/Utils.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Support/MathExtras.h" #include "mlir/Transforms/RegionUtils.h" @@ -320,7 +320,7 @@ static void updateInductionVariableUses(RewriterBase &rewriter, Location loc, /// If the value is a loop carried value coming from stage N + 1 remap, it will /// become a direct use. -static void updateIterArgUses(RewriterBase &rewriter, BlockAndValueMapping &bvm, +static void updateIterArgUses(RewriterBase &rewriter, IRMapping &bvm, Operation *newOp, ForOp oldForOp, ForOp newForOp, unsigned useStage, const DenseMap &stages) { @@ -344,9 +344,8 @@ static void updateIterArgUses(RewriterBase &rewriter, BlockAndValueMapping &bvm, /// correct region argument. We look for the right version of the Value based /// on the stage where it is used. static void updateCrossStageUses( - RewriterBase &rewriter, Operation *newOp, BlockAndValueMapping &bvm, - ForOp newForOp, unsigned useStage, - const DenseMap &stages, + RewriterBase &rewriter, Operation *newOp, IRMapping &bvm, ForOp newForOp, + unsigned useStage, const DenseMap &stages, const llvm::DenseMap, unsigned> &loopArgMap) { // Because we automatically cloned the sub-regions, there's no simple way // to walk the nested regions in pairs of (oldOps, newOps), so we just @@ -381,7 +380,7 @@ void LoopPipelinerInternal::createKernel( // Create the kernel, we clone instruction based on the order given by // user and remap operands coming from a previous stages. rewriter.setInsertionPoint(newForOp.getBody(), newForOp.getBody()->begin()); - BlockAndValueMapping mapping; + IRMapping mapping; mapping.map(forOp.getInductionVar(), newForOp.getInductionVar()); for (const auto &arg : llvm::enumerate(forOp.getRegionIterArgs())) { mapping.map(arg.value(), newForOp.getRegionIterArgs()[arg.index()]); diff --git a/mlir/lib/Dialect/SCF/Transforms/LoopRangeFolding.cpp b/mlir/lib/Dialect/SCF/Transforms/LoopRangeFolding.cpp index a2fe36e370474..9ca441f643183 100644 --- a/mlir/lib/Dialect/SCF/Transforms/LoopRangeFolding.cpp +++ b/mlir/lib/Dialect/SCF/Transforms/LoopRangeFolding.cpp @@ -16,7 +16,7 @@ #include "mlir/Dialect/SCF/IR/SCF.h" #include "mlir/Dialect/SCF/Transforms/Transforms.h" #include "mlir/Dialect/SCF/Utils/Utils.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" namespace mlir { #define GEN_PASS_DEF_SCFFORLOOPRANGEFOLDING @@ -57,11 +57,11 @@ void ForLoopRangeFolding::runOnOperation() { break; OpBuilder b(op); - BlockAndValueMapping lbMap; + IRMapping lbMap; lbMap.map(indVar, op.getLowerBound()); - BlockAndValueMapping ubMap; + IRMapping ubMap; ubMap.map(indVar, op.getUpperBound()); - BlockAndValueMapping stepMap; + IRMapping stepMap; stepMap.map(indVar, op.getStep()); if (isa(user)) { diff --git a/mlir/lib/Dialect/SCF/Transforms/LoopSpecialization.cpp b/mlir/lib/Dialect/SCF/Transforms/LoopSpecialization.cpp index 2a83b6dcba672..82c2223b6eec0 100644 --- a/mlir/lib/Dialect/SCF/Transforms/LoopSpecialization.cpp +++ b/mlir/lib/Dialect/SCF/Transforms/LoopSpecialization.cpp @@ -21,7 +21,7 @@ #include "mlir/Dialect/SCF/Utils/AffineCanonicalizationUtils.h" #include "mlir/Dialect/Utils/StaticValueUtils.h" #include "mlir/IR/AffineExpr.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "llvm/ADT/DenseMap.h" @@ -59,7 +59,7 @@ static void specializeParallelLoopForUnrolling(ParallelOp op) { } OpBuilder b(op); - BlockAndValueMapping map; + IRMapping map; Value cond; for (auto bound : llvm::zip(op.getUpperBound(), constantIndices)) { Value constant = @@ -93,7 +93,7 @@ static void specializeForLoopForUnrolling(ForOp op) { return; OpBuilder b(op); - BlockAndValueMapping map; + IRMapping map; Value constant = b.create(op.getLoc(), minConstant); Value cond = b.create(op.getLoc(), arith::CmpIPredicate::eq, bound, constant); diff --git a/mlir/lib/Dialect/SCF/Transforms/ParallelLoopFusion.cpp b/mlir/lib/Dialect/SCF/Transforms/ParallelLoopFusion.cpp index a525c059bf231..9a5db1b41b35a 100644 --- a/mlir/lib/Dialect/SCF/Transforms/ParallelLoopFusion.cpp +++ b/mlir/lib/Dialect/SCF/Transforms/ParallelLoopFusion.cpp @@ -15,8 +15,8 @@ #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/SCF/IR/SCF.h" #include "mlir/Dialect/SCF/Transforms/Transforms.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/OpDefinition.h" #include "mlir/Interfaces/SideEffectInterfaces.h" @@ -58,7 +58,7 @@ static bool equalIterationSpaces(ParallelOp firstPloop, /// loop reads. static bool haveNoReadsAfterWriteExceptSameIndex( ParallelOp firstPloop, ParallelOp secondPloop, - const BlockAndValueMapping &firstToSecondPloopIndices) { + const IRMapping &firstToSecondPloopIndices) { DenseMap> bufferStores; firstPloop.getBody()->walk([&](memref::StoreOp store) { bufferStores[store.getMemRef()].push_back(store.getIndices()); @@ -98,21 +98,20 @@ static bool haveNoReadsAfterWriteExceptSameIndex( /// write patterns. static LogicalResult verifyDependencies(ParallelOp firstPloop, ParallelOp secondPloop, - const BlockAndValueMapping &firstToSecondPloopIndices) { + const IRMapping &firstToSecondPloopIndices) { if (!haveNoReadsAfterWriteExceptSameIndex(firstPloop, secondPloop, firstToSecondPloopIndices)) return failure(); - BlockAndValueMapping secondToFirstPloopIndices; + IRMapping secondToFirstPloopIndices; secondToFirstPloopIndices.map(secondPloop.getBody()->getArguments(), firstPloop.getBody()->getArguments()); return success(haveNoReadsAfterWriteExceptSameIndex( secondPloop, firstPloop, secondToFirstPloopIndices)); } -static bool -isFusionLegal(ParallelOp firstPloop, ParallelOp secondPloop, - const BlockAndValueMapping &firstToSecondPloopIndices) { +static bool isFusionLegal(ParallelOp firstPloop, ParallelOp secondPloop, + const IRMapping &firstToSecondPloopIndices) { return !hasNestedParallelOp(firstPloop) && !hasNestedParallelOp(secondPloop) && equalIterationSpaces(firstPloop, secondPloop) && @@ -123,7 +122,7 @@ isFusionLegal(ParallelOp firstPloop, ParallelOp secondPloop, /// Prepends operations of firstPloop's body into secondPloop's body. static void fuseIfLegal(ParallelOp firstPloop, ParallelOp secondPloop, OpBuilder b) { - BlockAndValueMapping firstToSecondPloopIndices; + IRMapping firstToSecondPloopIndices; firstToSecondPloopIndices.map(firstPloop.getBody()->getArguments(), secondPloop.getBody()->getArguments()); diff --git a/mlir/lib/Dialect/SCF/Utils/Utils.cpp b/mlir/lib/Dialect/SCF/Utils/Utils.cpp index 2b9aa9d302746..b4c60b69849a0 100644 --- a/mlir/lib/Dialect/SCF/Utils/Utils.cpp +++ b/mlir/lib/Dialect/SCF/Utils/Utils.cpp @@ -15,8 +15,8 @@ #include "mlir/Dialect/Arith/IR/Arith.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/SCF/IR/SCF.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/BuiltinOps.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Interfaces/SideEffectInterfaces.h" #include "mlir/Support/MathExtras.h" @@ -260,7 +260,7 @@ FailureOr mlir::outlineSingleBlockRegion(RewriterBase &rewriter, // `originalTerminator` was moved to `outlinedFuncBody` and is still valid. // Clone `originalTerminator` to take the callOp results then erase it from // `outlinedFuncBody`. - BlockAndValueMapping bvm; + IRMapping bvm; bvm.map(originalTerminator->getOperands(), call->getResults()); rewriter.clone(*originalTerminator, bvm); rewriter.eraseOp(originalTerminator); @@ -276,7 +276,7 @@ FailureOr mlir::outlineSingleBlockRegion(RewriterBase &rewriter, OpBuilder::InsertionGuard g(rewriter); rewriter.setInsertionPointToStart(outlinedFuncBody); if (Operation *cst = orig.getDefiningOp()) { - BlockAndValueMapping bvm; + IRMapping bvm; repl = rewriter.clone(*cst, bvm)->getResult(0); } } @@ -430,7 +430,7 @@ static void generateUnrolledLoop( SmallVector lastYielded(yieldedValues); for (unsigned i = 1; i < unrollFactor; i++) { - BlockAndValueMapping operandMap; + IRMapping operandMap; // Prepare operand map. operandMap.map(iterArgs, lastYielded); diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp index fe722e90c9b6b..220e08f309b32 100644 --- a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp +++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp @@ -61,7 +61,7 @@ struct SPIRVInlinerInterface : public DialectInlinerInterface { /// Returns true if the given region 'src' can be inlined into the region /// 'dest' that is attached to an operation registered to the current dialect. bool isLegalToInline(Region *dest, Region *src, bool wouldBeCloned, - BlockAndValueMapping &) const final { + IRMapping &) const final { // Return true here when inlining into spirv.func, spirv.mlir.selection, and // spirv.mlir.loop operations. auto *op = dest->getParentOp(); @@ -72,7 +72,7 @@ struct SPIRVInlinerInterface : public DialectInlinerInterface { /// dialect, can be inlined into the region 'dest' that is attached to an /// operation registered to the current dialect. bool isLegalToInline(Operation *op, Region *dest, bool wouldBeCloned, - BlockAndValueMapping &) const final { + IRMapping &) const final { // TODO: Enable inlining structured control flows with return. if ((isa(op)) && containsReturn(op->getRegion(0))) diff --git a/mlir/lib/Dialect/Shape/IR/Shape.cpp b/mlir/lib/Dialect/Shape/IR/Shape.cpp index f28cbcae6bb37..7e4d1250ba2e1 100644 --- a/mlir/lib/Dialect/Shape/IR/Shape.cpp +++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp @@ -114,7 +114,7 @@ struct ShapeInlinerInterface : public DialectInlinerInterface { // Returns true if the given region 'src' can be inlined into the region // 'dest' that is attached to an operation registered to the current dialect. bool isLegalToInline(Region *dest, Region *src, bool wouldBeCloned, - BlockAndValueMapping &) const final { + IRMapping &) const final { return true; } @@ -122,7 +122,7 @@ struct ShapeInlinerInterface : public DialectInlinerInterface { // dialect, can be inlined into the region 'dest' that is attached to an // operation registered to the current dialect. bool isLegalToInline(Operation *op, Region *dest, bool wouldBeCloned, - BlockAndValueMapping &) const final { + IRMapping &) const final { return true; } }; diff --git a/mlir/lib/Dialect/Shape/Transforms/OutlineShapeComputation.cpp b/mlir/lib/Dialect/Shape/Transforms/OutlineShapeComputation.cpp index 5d598a6f88109..372ec80978c65 100644 --- a/mlir/lib/Dialect/Shape/Transforms/OutlineShapeComputation.cpp +++ b/mlir/lib/Dialect/Shape/Transforms/OutlineShapeComputation.cpp @@ -11,7 +11,7 @@ #include "mlir/Dialect/Shape/IR/Shape.h" #include "mlir/Dialect/Shape/Transforms/Passes.h" #include "mlir/Dialect/Tensor/IR/Tensor.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/Matchers.h" #include "mlir/Pass/Pass.h" #include "mlir/Transforms/DialectConversion.h" @@ -72,7 +72,7 @@ createFuncFromCluster(OpBuilder &b, const SmallVector &cluster, shape::FuncOp fnOp = b.create(loc, fnName, fnType); Block *block = fnOp.addEntryBlock(); b.setInsertionPoint(block, block->end()); - BlockAndValueMapping bvm; + IRMapping bvm; if (cluster.empty()) { bvm.map(shape, fnOp.getArgument(0)); } else { diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp index 5b8ebdb08acea..c88e163f9f5e0 100644 --- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp @@ -350,7 +350,7 @@ struct FuseSparseMultiplyOverAdd : public OpRewritePattern { /*doc=*/nullptr, /*library_call=*/nullptr); Block &prodBlock = prod.getRegion().front(); Block &consBlock = op.getRegion().front(); - BlockAndValueMapping mapper; + IRMapping mapper; Block *fusedBlock = new Block(); fusedOp.getRegion().push_back(fusedBlock); unsigned num = prodBlock.getNumArguments(); @@ -390,7 +390,7 @@ struct FuseSparseMultiplyOverAdd : public OpRewritePattern { private: // Helper to add argument and record the mapping. - static void addArg(BlockAndValueMapping &mapper, Block *b, BlockArgument a) { + static void addArg(IRMapping &mapper, Block *b, BlockArgument a) { mapper.map(a, b->addArgument(a.getType(), a.getLoc())); } }; diff --git a/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp b/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp index f82ff4452b647..748f564109fd0 100644 --- a/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp +++ b/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp @@ -1204,7 +1204,7 @@ static Value insertYieldOp(RewriterBase &rewriter, Location loc, Region ®ion, ValueRange vals) { // Make a clone of overlap region. Region tmpRegion; - BlockAndValueMapping mapper; + IRMapping mapper; region.cloneInto(&tmpRegion, tmpRegion.begin(), mapper); Block &clonedBlock = tmpRegion.front(); YieldOp clonedYield = cast(clonedBlock.getTerminator()); diff --git a/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp b/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp index c1d285c28c636..62032ff301bec 100644 --- a/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp +++ b/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp @@ -25,11 +25,11 @@ namespace { struct TensorInlinerInterface : public DialectInlinerInterface { using DialectInlinerInterface::DialectInlinerInterface; bool isLegalToInline(Region *dest, Region *src, bool wouldBeCloned, - BlockAndValueMapping &valueMapping) const final { + IRMapping &valueMapping) const final { return true; } bool isLegalToInline(Operation *, Region *, bool wouldBeCloned, - BlockAndValueMapping &) const final { + IRMapping &) const final { return true; } }; diff --git a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp index 5746b6eaffb54..2c17b4a38b13e 100644 --- a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp +++ b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp @@ -14,10 +14,10 @@ #include "mlir/Dialect/Utils/IndexingUtils.h" #include "mlir/Dialect/Utils/ReshapeOpsUtils.h" #include "mlir/Dialect/Utils/StaticValueUtils.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinAttributeInterfaces.h" #include "mlir/IR/BuiltinTypes.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/Matchers.h" #include "mlir/IR/OpDefinition.h" #include "mlir/IR/TypeUtilities.h" @@ -1148,7 +1148,7 @@ struct ExtractFromTensorGenerate : public OpRewritePattern { if (!tensorFromElements || !wouldOpBeTriviallyDead(tensorFromElements)) return failure(); - BlockAndValueMapping mapping; + IRMapping mapping; Block *body = &tensorFromElements.getBody().front(); mapping.map(body->getArguments(), extract.getIndices()); for (auto &op : body->without_terminator()) @@ -2639,7 +2639,7 @@ struct FoldSourceTensorCast : public OpRewritePattern { padTensorOp.getLow(), padTensorOp.getHigh(), padTensorOp.getStaticLow(), padTensorOp.getStaticHigh(), padTensorOp.getNofold()); - BlockAndValueMapping mapper; + IRMapping mapper; padTensorOp.getRegion().cloneInto(&newOp.getRegion(), mapper); rewriter.replaceOpWithNewOp( @@ -3228,7 +3228,7 @@ static LogicalResult commonVerifierPackAndUnPackOp(OpTy packOrUnPack) { return true; } return shape == constTileSize.value(); - + })) { return op->emitError("mismatch in inner tile sizes specified and shaped of " "tiled dimension in the packed type"); diff --git a/mlir/lib/Dialect/Tensor/IR/TensorTilingInterfaceImpl.cpp b/mlir/lib/Dialect/Tensor/IR/TensorTilingInterfaceImpl.cpp index 7eced90aac548..d84f10294d282 100644 --- a/mlir/lib/Dialect/Tensor/IR/TensorTilingInterfaceImpl.cpp +++ b/mlir/lib/Dialect/Tensor/IR/TensorTilingInterfaceImpl.cpp @@ -616,7 +616,7 @@ Operation *tensor::bubbleUpPadSlice(OpBuilder &b, tensor::PadOp padOp, staticNewHighs, newLows, newHighs); // Copy region to new PadOp. - BlockAndValueMapping bvm; + IRMapping bvm; padOp.getRegion().cloneInto(&newPadOp.getRegion(), bvm); // Cast result and return. diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp index 82f34f93cb3d1..338f5308e38be 100644 --- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp +++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp @@ -50,13 +50,13 @@ struct TosaInlinerInterface : public DialectInlinerInterface { /// All operations can be inlined by default. bool isLegalToInline(Operation *op, Region *region, bool wouldBeCloned, - BlockAndValueMapping &map) const final { + IRMapping &map) const final { return true; } /// All regions with If and While parent operators can be inlined. bool isLegalToInline(Region *dest, Region *src, bool wouldBeCloned, - BlockAndValueMapping &map) const final { + IRMapping &map) const final { return (isa(dest->getParentOp()) || isa(dest->getParentOp())); } diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaInferShapes.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaInferShapes.cpp index d588836ff1086..bd6069468d7f7 100644 --- a/mlir/lib/Dialect/Tosa/Transforms/TosaInferShapes.cpp +++ b/mlir/lib/Dialect/Tosa/Transforms/TosaInferShapes.cpp @@ -17,9 +17,9 @@ #include "mlir/Dialect/Tensor/IR/Tensor.h" #include "mlir/Dialect/Tosa/IR/TosaOps.h" #include "mlir/Dialect/Tosa/Utils/ShapeUtils.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinOps.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/Matchers.h" #include "mlir/Pass/Pass.h" #include "mlir/Transforms/DialectConversion.h" diff --git a/mlir/lib/Dialect/Utils/StructuredOpsUtils.cpp b/mlir/lib/Dialect/Utils/StructuredOpsUtils.cpp index 84aed89d12a3f..b22f42c09da59 100644 --- a/mlir/lib/Dialect/Utils/StructuredOpsUtils.cpp +++ b/mlir/lib/Dialect/Utils/StructuredOpsUtils.cpp @@ -8,9 +8,9 @@ #include "mlir/Dialect/Utils/StructuredOpsUtils.h" #include "mlir/IR/AffineMap.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinAttributes.h" +#include "mlir/IR/IRMapping.h" #include "mlir/Dialect/Utils/DialectUtilsEnums.cpp.inc" @@ -97,7 +97,7 @@ bool mlir::isRowMajorBatchMatmul(ArrayAttr indexingMaps) { Operation *mlir::clone(OpBuilder &b, Operation *op, TypeRange newResultTypes, ValueRange newOperands) { - BlockAndValueMapping bvm; + IRMapping bvm; OperationState state(op->getLoc(), op->getName(), newOperands, newResultTypes, op->getAttrs()); for (Region &r : op->getRegions()) diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp index 470b57b887735..d5975876cfb2e 100644 --- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp +++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp @@ -21,12 +21,12 @@ #include "mlir/Dialect/Utils/StructuredOpsUtils.h" #include "mlir/IR/AffineExpr.h" #include "mlir/IR/AffineMap.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/DialectImplementation.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/OpImplementation.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeUtilities.h" @@ -981,7 +981,7 @@ struct CanonicalizeContractAdd : public OpRewritePattern { contractionOp.getAcc().getDefiningOp())) { if (maybeZero.getValue() == rewriter.getZeroAttr(contractionOp.getAcc().getType())) { - BlockAndValueMapping bvm; + IRMapping bvm; bvm.map(contractionOp.getAcc(), otherOperand); auto newContraction = cast(rewriter.clone(*contractionOp, bvm)); diff --git a/mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp index 0cfbe396e3bb5..7567dc5944228 100644 --- a/mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp @@ -428,7 +428,7 @@ static void createFullPartialVectorTransferWrite(RewriterBase &b, auto notInBounds = b.create( loc, inBoundsCond, b.create(loc, true, 1)); b.create(loc, notInBounds, [&](OpBuilder &b, Location loc) { - BlockAndValueMapping mapping; + IRMapping mapping; Value load = b.create( loc, b.create( @@ -614,7 +614,7 @@ LogicalResult mlir::vector::splitFullAndPartialTransfer( // Do an in bounds write to either the output or the extra allocated buffer. // The operation is cloned to prevent deleting information needed for the // later IR creation. - BlockAndValueMapping mapping; + IRMapping mapping; mapping.map(xferWriteOp.getSource(), memrefAndIndices.front()); mapping.map(xferWriteOp.getIndices(), memrefAndIndices.drop_front()); auto *clone = b.clone(*xferWriteOp, mapping); diff --git a/mlir/lib/IR/Builders.cpp b/mlir/lib/IR/Builders.cpp index 2f4e07990a0d1..38f0501adfbf8 100644 --- a/mlir/lib/IR/Builders.cpp +++ b/mlir/lib/IR/Builders.cpp @@ -9,9 +9,9 @@ #include "mlir/IR/Builders.h" #include "mlir/IR/AffineExpr.h" #include "mlir/IR/AffineMap.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Dialect.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/IntegerSet.h" #include "mlir/IR/Matchers.h" #include "mlir/IR/SymbolTable.h" @@ -507,7 +507,7 @@ LogicalResult OpBuilder::tryFold(Operation *op, return success(); } -Operation *OpBuilder::clone(Operation &op, BlockAndValueMapping &mapper) { +Operation *OpBuilder::clone(Operation &op, IRMapping &mapper) { Operation *newOp = op.clone(mapper); // The `insert` call below handles the notification for inserting `newOp` // itself. But if `newOp` has any regions, we need to notify the listener @@ -523,6 +523,6 @@ Operation *OpBuilder::clone(Operation &op, BlockAndValueMapping &mapper) { } Operation *OpBuilder::clone(Operation &op) { - BlockAndValueMapping mapper; + IRMapping mapper; return clone(op, mapper); } diff --git a/mlir/lib/IR/BuiltinDialect.cpp b/mlir/lib/IR/BuiltinDialect.cpp index 0668459d622b1..2dd4e2234f0cb 100644 --- a/mlir/lib/IR/BuiltinDialect.cpp +++ b/mlir/lib/IR/BuiltinDialect.cpp @@ -13,11 +13,11 @@ #include "mlir/IR/BuiltinDialect.h" #include "BuiltinDialectBytecode.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/DialectResourceBlobManager.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/OpImplementation.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeRange.h" diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp index d44d0b199efcb..0c5869b49cc05 100644 --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// #include "mlir/IR/Operation.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Dialect.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/OpImplementation.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeUtilities.h" @@ -541,12 +541,12 @@ Operation::CloneOptions &Operation::CloneOptions::cloneOperands(bool enable) { /// Operands are remapped using `mapper` (if present), and `mapper` is updated /// to contain the results. The `mapResults` flag specifies whether the results /// of the cloned operation should be added to the map. -Operation *Operation::cloneWithoutRegions(BlockAndValueMapping &mapper) { +Operation *Operation::cloneWithoutRegions(IRMapping &mapper) { return clone(mapper, CloneOptions::all().cloneRegions(false)); } Operation *Operation::cloneWithoutRegions() { - BlockAndValueMapping mapper; + IRMapping mapper; return cloneWithoutRegions(mapper); } @@ -555,8 +555,7 @@ Operation *Operation::cloneWithoutRegions() { /// them alone if no entry is present). Replaces references to cloned /// sub-operations to the corresponding operation that is copied, and adds /// those mappings to the map. -Operation *Operation::clone(BlockAndValueMapping &mapper, - CloneOptions options) { +Operation *Operation::clone(IRMapping &mapper, CloneOptions options) { SmallVector operands; SmallVector successors; @@ -575,6 +574,7 @@ Operation *Operation::clone(BlockAndValueMapping &mapper, // Create the new operation. auto *newOp = create(getLoc(), getName(), getResultTypes(), operands, attrs, successors, getNumRegions()); + mapper.map(this, newOp); // Clone the regions. if (options.shouldCloneRegions()) { @@ -590,7 +590,7 @@ Operation *Operation::clone(BlockAndValueMapping &mapper, } Operation *Operation::clone(CloneOptions options) { - BlockAndValueMapping mapper; + IRMapping mapper; return clone(mapper, options); } diff --git a/mlir/lib/IR/PatternMatch.cpp b/mlir/lib/IR/PatternMatch.cpp index 1a2b234c3a19c..2f1ad0c469834 100644 --- a/mlir/lib/IR/PatternMatch.cpp +++ b/mlir/lib/IR/PatternMatch.cpp @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "mlir/IR/PatternMatch.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" using namespace mlir; @@ -386,12 +386,12 @@ void RewriterBase::inlineRegionBefore(Region ®ion, Block *before) { /// control to the region and passing it the correct block arguments. void RewriterBase::cloneRegionBefore(Region ®ion, Region &parent, Region::iterator before, - BlockAndValueMapping &mapping) { + IRMapping &mapping) { region.cloneInto(&parent, before, mapping); } void RewriterBase::cloneRegionBefore(Region ®ion, Region &parent, Region::iterator before) { - BlockAndValueMapping mapping; + IRMapping mapping; cloneRegionBefore(region, parent, before, mapping); } void RewriterBase::cloneRegionBefore(Region ®ion, Block *before) { diff --git a/mlir/lib/IR/Region.cpp b/mlir/lib/IR/Region.cpp index 1b98926ca0b0f..2b84a935371a9 100644 --- a/mlir/lib/IR/Region.cpp +++ b/mlir/lib/IR/Region.cpp @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "mlir/IR/Region.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/Operation.h" using namespace mlir; @@ -67,14 +67,14 @@ unsigned Region::getRegionNumber() { /// Clone the internal blocks from this region into `dest`. Any /// cloned blocks are appended to the back of dest. -void Region::cloneInto(Region *dest, BlockAndValueMapping &mapper) { +void Region::cloneInto(Region *dest, IRMapping &mapper) { assert(dest && "expected valid region to clone into"); cloneInto(dest, dest->end(), mapper); } /// Clone this region into 'dest' before the given position in 'dest'. void Region::cloneInto(Region *dest, Region::iterator destPos, - BlockAndValueMapping &mapper) { + IRMapping &mapper) { assert(dest && "expected valid region to clone into"); assert(this != dest && "cannot clone region into itself"); diff --git a/mlir/lib/Reducer/ReductionNode.cpp b/mlir/lib/Reducer/ReductionNode.cpp index 957ce1d21ad5a..7de17cc06e4b3 100644 --- a/mlir/lib/Reducer/ReductionNode.cpp +++ b/mlir/lib/Reducer/ReductionNode.cpp @@ -15,7 +15,7 @@ //===----------------------------------------------------------------------===// #include "mlir/Reducer/ReductionNode.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include "llvm/ADT/STLExtras.h" #include @@ -38,7 +38,7 @@ ReductionNode::ReductionNode( LogicalResult ReductionNode::initialize(ModuleOp parentModule, Region &targetRegion) { // Use the mapper help us find the corresponding region after module clone. - BlockAndValueMapping mapper; + IRMapping mapper; module = cast(parentModule->clone(mapper)); // Use the first block of targetRegion to locate the cloned region. Block *block = mapper.lookup(&*targetRegion.begin()); diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp index 96cd923e5108b..a6f881a637b88 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp @@ -12,7 +12,7 @@ //===----------------------------------------------------------------------===// #include "mlir/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.h" #include "mlir/Dialect/OpenMP/OpenMPDialect.h" -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/Operation.h" #include "mlir/Support/LLVM.h" #include "mlir/Target/LLVMIR/ModuleTranslation.h" diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp index f608637b6e738..642c22637fe19 100644 --- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp +++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp @@ -16,8 +16,8 @@ #include "mlir/Dialect/SPIRV/IR/SPIRVEnums.h" #include "mlir/Dialect/SPIRV/IR/SPIRVOps.h" #include "mlir/Dialect/SPIRV/IR/SPIRVTypes.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/Location.h" #include "mlir/Support/LogicalResult.h" #include "mlir/Target/SPIRV/SPIRVBinaryUtils.h" @@ -1750,7 +1750,7 @@ LogicalResult ControlFlowStructurizer::structurize() { return failure(); Region &body = op->getRegion(0); - BlockAndValueMapping mapper; + IRMapping mapper; // All references to the old merge block should be directed to the // selection/loop merge block in the SelectionOp/LoopOp's region. mapper.map(mergeBlock, &body.back()); diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp index 024c2f5e16e36..0213c63d7b0b1 100644 --- a/mlir/lib/Transforms/Utils/DialectConversion.cpp +++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp @@ -8,10 +8,10 @@ #include "mlir/Transforms/DialectConversion.h" #include "mlir/IR/Block.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/FunctionInterfaces.h" +#include "mlir/IR/IRMapping.h" #include "mlir/Rewrite/PatternApplicator.h" #include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/SetVector.h" @@ -104,7 +104,7 @@ static void logFailure(llvm::ScopedPrinter &os, StringRef fmt, Args &&...args) { //===----------------------------------------------------------------------===// namespace { -/// This class wraps a BlockAndValueMapping to provide recursive lookup +/// This class wraps a IRMapping to provide recursive lookup /// functionality, i.e. we will traverse if the mapped value also has a mapping. struct ConversionValueMapping { /// Lookup a mapped value within the map. If a mapping for the provided value @@ -145,7 +145,7 @@ struct ConversionValueMapping { private: /// Current value mappings. - BlockAndValueMapping mapping; + IRMapping mapping; }; } // namespace @@ -1620,9 +1620,10 @@ void ConversionPatternRewriter::inlineRegionBefore(Region ®ion, PatternRewriter::inlineRegionBefore(region, parent, before); } -void ConversionPatternRewriter::cloneRegionBefore( - Region ®ion, Region &parent, Region::iterator before, - BlockAndValueMapping &mapping) { +void ConversionPatternRewriter::cloneRegionBefore(Region ®ion, + Region &parent, + Region::iterator before, + IRMapping &mapping) { if (region.empty()) return; PatternRewriter::cloneRegionBefore(region, parent, before, mapping); diff --git a/mlir/lib/Transforms/Utils/InliningUtils.cpp b/mlir/lib/Transforms/Utils/InliningUtils.cpp index ae3e066cd1f28..6a34530532263 100644 --- a/mlir/lib/Transforms/Utils/InliningUtils.cpp +++ b/mlir/lib/Transforms/Utils/InliningUtils.cpp @@ -12,8 +12,8 @@ #include "mlir/Transforms/InliningUtils.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/Operation.h" #include "mlir/Interfaces/CallInterfaces.h" #include "llvm/ADT/MapVector.h" @@ -43,7 +43,7 @@ remapInlinedLocations(iterator_range inlinedBlocks, } static void remapInlinedOperands(iterator_range inlinedBlocks, - BlockAndValueMapping &mapper) { + IRMapping &mapper) { auto remapOperands = [&](Operation *op) { for (auto &operand : op->getOpOperands()) if (auto mappedOp = mapper.lookupOrNull(operand.get())) @@ -64,17 +64,17 @@ bool InlinerInterface::isLegalToInline(Operation *call, Operation *callable, return false; } -bool InlinerInterface::isLegalToInline( - Region *dest, Region *src, bool wouldBeCloned, - BlockAndValueMapping &valueMapping) const { +bool InlinerInterface::isLegalToInline(Region *dest, Region *src, + bool wouldBeCloned, + IRMapping &valueMapping) const { if (auto *handler = getInterfaceFor(dest->getParentOp())) return handler->isLegalToInline(dest, src, wouldBeCloned, valueMapping); return false; } -bool InlinerInterface::isLegalToInline( - Operation *op, Region *dest, bool wouldBeCloned, - BlockAndValueMapping &valueMapping) const { +bool InlinerInterface::isLegalToInline(Operation *op, Region *dest, + bool wouldBeCloned, + IRMapping &valueMapping) const { if (auto *handler = getInterfaceFor(op)) return handler->isLegalToInline(op, dest, wouldBeCloned, valueMapping); return false; @@ -112,7 +112,7 @@ void InlinerInterface::processInlinedCallBlocks( /// Utility to check that all of the operations within 'src' can be inlined. static bool isLegalToInline(InlinerInterface &interface, Region *src, Region *insertRegion, bool shouldCloneInlinedRegion, - BlockAndValueMapping &valueMapping) { + IRMapping &valueMapping) { for (auto &block : *src) { for (auto &op : block) { // Check this operation. @@ -142,7 +142,7 @@ static bool isLegalToInline(InlinerInterface &interface, Region *src, static LogicalResult inlineRegionImpl(InlinerInterface &interface, Region *src, Block *inlineBlock, - Block::iterator inlinePoint, BlockAndValueMapping &mapper, + Block::iterator inlinePoint, IRMapping &mapper, ValueRange resultsToReplace, TypeRange regionResultTypes, Optional inlineLoc, bool shouldCloneInlinedRegion, Operation *call = nullptr) { @@ -243,7 +243,7 @@ inlineRegionImpl(InlinerInterface &interface, Region *src, Block *inlineBlock, return failure(); // Map the provided call operands to the arguments of the region. - BlockAndValueMapping mapper; + IRMapping mapper; for (unsigned i = 0, e = inlinedOperands.size(); i != e; ++i) { // Verify that the types of the provided values match the function argument // types. @@ -260,8 +260,7 @@ inlineRegionImpl(InlinerInterface &interface, Region *src, Block *inlineBlock, } LogicalResult mlir::inlineRegion(InlinerInterface &interface, Region *src, - Operation *inlinePoint, - BlockAndValueMapping &mapper, + Operation *inlinePoint, IRMapping &mapper, ValueRange resultsToReplace, TypeRange regionResultTypes, Optional inlineLoc, @@ -270,12 +269,13 @@ LogicalResult mlir::inlineRegion(InlinerInterface &interface, Region *src, ++inlinePoint->getIterator(), mapper, resultsToReplace, regionResultTypes, inlineLoc, shouldCloneInlinedRegion); } -LogicalResult -mlir::inlineRegion(InlinerInterface &interface, Region *src, Block *inlineBlock, - Block::iterator inlinePoint, BlockAndValueMapping &mapper, - ValueRange resultsToReplace, TypeRange regionResultTypes, - Optional inlineLoc, - bool shouldCloneInlinedRegion) { +LogicalResult mlir::inlineRegion(InlinerInterface &interface, Region *src, + Block *inlineBlock, + Block::iterator inlinePoint, IRMapping &mapper, + ValueRange resultsToReplace, + TypeRange regionResultTypes, + Optional inlineLoc, + bool shouldCloneInlinedRegion) { return inlineRegionImpl(interface, src, inlineBlock, inlinePoint, mapper, resultsToReplace, regionResultTypes, inlineLoc, shouldCloneInlinedRegion); @@ -367,7 +367,7 @@ LogicalResult mlir::inlineCall(InlinerInterface &interface, const auto *callInterface = interface.getInterfaceFor(call->getDialect()); // Map the provided call operands to the arguments of the region. - BlockAndValueMapping mapper; + IRMapping mapper; for (unsigned i = 0, e = callOperands.size(); i != e; ++i) { BlockArgument regionArg = entryBlock->getArgument(i); Value operand = callOperands[i]; diff --git a/mlir/test/lib/Dialect/Test/TestDialect.cpp b/mlir/test/lib/Dialect/Test/TestDialect.cpp index 7f0ad3b69c5b9..6cbd53620cbde 100644 --- a/mlir/test/lib/Dialect/Test/TestDialect.cpp +++ b/mlir/test/lib/Dialect/Test/TestDialect.cpp @@ -194,13 +194,11 @@ struct TestInlinerInterface : public DialectInlinerInterface { // Don't allow inlining calls that are marked `noinline`. return !call->hasAttr("noinline"); } - bool isLegalToInline(Region *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Region *, Region *, bool, IRMapping &) const final { // Inlining into test dialect regions is legal. return true; } - bool isLegalToInline(Operation *, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final { return true; } diff --git a/mlir/test/lib/IR/TestClone.cpp b/mlir/test/lib/IR/TestClone.cpp index 5d80e9356f14f..70238608a67c2 100644 --- a/mlir/test/lib/IR/TestClone.cpp +++ b/mlir/test/lib/IR/TestClone.cpp @@ -41,7 +41,7 @@ struct ClonePass if (terminator->getNumOperands() != regionEntry.getNumArguments()) return; - BlockAndValueMapping map; + IRMapping map; for (auto tup : llvm::zip(terminator->getOperands(), regionEntry.getArguments())) { if (std::get<0>(tup).getType() != std::get<1>(tup).getType()) diff --git a/mlir/test/lib/IR/TestSlicing.cpp b/mlir/test/lib/IR/TestSlicing.cpp index 01335022fe011..78c8ff7d46015 100644 --- a/mlir/test/lib/IR/TestSlicing.cpp +++ b/mlir/test/lib/IR/TestSlicing.cpp @@ -13,8 +13,8 @@ #include "mlir/Analysis/SliceAnalysis.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/Linalg/IR/Linalg.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/BuiltinOps.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Pass/Pass.h" #include "mlir/Support/LLVM.h" @@ -31,7 +31,7 @@ static LogicalResult createBackwardSliceFunction(Operation *op, std::string clonedFuncOpName = parentFuncOp.getName().str() + suffix.str(); func::FuncOp clonedFuncOp = builder.create( loc, clonedFuncOpName, parentFuncOp.getFunctionType()); - BlockAndValueMapping mapper; + IRMapping mapper; builder.setInsertionPointToEnd(clonedFuncOp.addEntryBlock()); for (const auto &arg : enumerate(parentFuncOp.getArguments())) mapper.map(arg.value(), clonedFuncOp.getArgument(arg.index())); diff --git a/mlir/test/lib/Transforms/TestInlining.cpp b/mlir/test/lib/Transforms/TestInlining.cpp index 3fb70285cef45..9821179d05e89 100644 --- a/mlir/test/lib/Transforms/TestInlining.cpp +++ b/mlir/test/lib/Transforms/TestInlining.cpp @@ -14,8 +14,8 @@ #include "TestDialect.h" #include "mlir/Dialect/Func/IR/FuncOps.h" -#include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/BuiltinOps.h" +#include "mlir/IR/IRMapping.h" #include "mlir/Pass/Pass.h" #include "mlir/Transforms/InliningUtils.h" #include "llvm/ADT/StringSet.h" diff --git a/mlir/unittests/IR/CMakeLists.txt b/mlir/unittests/IR/CMakeLists.txt index 41964ab0d30af..9dcfb71744bee 100644 --- a/mlir/unittests/IR/CMakeLists.txt +++ b/mlir/unittests/IR/CMakeLists.txt @@ -1,9 +1,9 @@ add_mlir_unittest(MLIRIRTests AdaptorTest.cpp AttributeTest.cpp - BlockAndValueMapping.cpp DialectTest.cpp InterfaceTest.cpp + IRMapping.cpp InterfaceAttachmentTest.cpp OperationSupportTest.cpp PatternMatchTest.cpp diff --git a/mlir/unittests/IR/BlockAndValueMapping.cpp b/mlir/unittests/IR/IRMapping.cpp similarity index 53% rename from mlir/unittests/IR/BlockAndValueMapping.cpp rename to mlir/unittests/IR/IRMapping.cpp index ba66403eeac28..bf00e5eea2260 100644 --- a/mlir/unittests/IR/BlockAndValueMapping.cpp +++ b/mlir/unittests/IR/IRMapping.cpp @@ -1,4 +1,4 @@ -//===- BlockAndValueMapping.h -----------------------------------*- C++ -*-===// +//===- IRMapping.cpp --------------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/IRMapping.h" #include "mlir/IR/Builders.h" #include "gtest/gtest.h" @@ -14,7 +14,7 @@ using namespace mlir; -TEST(BlockAndValueMapping, TypedValue) { +TEST(IRMapping, TypedValue) { MLIRContext context; context.loadDialect(); @@ -30,8 +30,27 @@ TEST(BlockAndValueMapping, TypedValue) { Value f64Val = builder.create( loc, builder.getF64Type(), builder.getF64FloatAttr(0.0)); - BlockAndValueMapping mapping; + IRMapping mapping; mapping.map(i64Val, f64Val); TypedValue typedI64Val = i64Val; - mapping.lookup(typedI64Val); + EXPECT_EQ(mapping.lookup(typedI64Val), f64Val); +} + +TEST(IRMapping, OperationClone) { + MLIRContext ctx; + ctx.allowUnregisteredDialects(); + + OperationState state(UnknownLoc::get(&ctx), "no_results"); + Operation *noResultsOp = Operation::create(state); + + OperationState owner(UnknownLoc::get(&ctx), "owner"); + owner.addRegion()->emplaceBlock().push_back(noResultsOp); + OwningOpRef ownerOp = Operation::create(owner); + + IRMapping irMap; + OwningOpRef clonedOwnerOp = (*ownerOp)->clone(irMap); + + EXPECT_EQ(irMap.lookupOrNull(*ownerOp), *clonedOwnerOp); + EXPECT_EQ(irMap.lookupOrNull(noResultsOp), + &(*clonedOwnerOp)->getRegion(0).front().front()); }