diff --git a/flang/include/flang/Optimizer/Dialect/FIRDialect.h b/flang/include/flang/Optimizer/Dialect/FIRDialect.h --- 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 @@ /// 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 --- 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 --- 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 @@ -547,7 +547,7 @@ // 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 --- a/flang/lib/Optimizer/Dialect/FIRDialect.cpp +++ b/flang/lib/Optimizer/Dialect/FIRDialect.cpp @@ -31,8 +31,7 @@ /// 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 --- a/flang/lib/Optimizer/Dialect/Inliner.cpp +++ b/flang/lib/Optimizer/Dialect/Inliner.cpp @@ -16,7 +16,7 @@ /// 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 --- a/mlir/docs/Interfaces.md +++ b/mlir/docs/Interfaces.md @@ -53,7 +53,7 @@ /// 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 @@ 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 @@ /// 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 --- a/mlir/docs/Rationale/UsageOfConst.md +++ b/mlir/docs/Rationale/UsageOfConst.md @@ -186,7 +186,7 @@ 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 @@ 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 --- a/mlir/docs/Tutorials/Toy/Ch-4.md +++ b/mlir/docs/Tutorials/Toy/Ch-4.md @@ -73,7 +73,7 @@ /// 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 @@ /// 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 --- a/mlir/examples/toy/Ch4/mlir/Dialect.cpp +++ b/mlir/examples/toy/Ch4/mlir/Dialect.cpp @@ -44,14 +44,12 @@ } /// 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 --- a/mlir/examples/toy/Ch5/mlir/Dialect.cpp +++ b/mlir/examples/toy/Ch5/mlir/Dialect.cpp @@ -44,14 +44,12 @@ } /// 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 --- a/mlir/examples/toy/Ch6/mlir/Dialect.cpp +++ b/mlir/examples/toy/Ch6/mlir/Dialect.cpp @@ -44,14 +44,12 @@ } /// 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 --- a/mlir/examples/toy/Ch7/mlir/Dialect.cpp +++ b/mlir/examples/toy/Ch7/mlir/Dialect.cpp @@ -45,14 +45,12 @@ } /// 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 --- a/mlir/include/mlir/Dialect/Func/IR/FuncOps.td +++ b/mlir/include/mlir/Dialect/Func/IR/FuncOps.td @@ -277,14 +277,14 @@ /// 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 --- 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 --- 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 --- 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 @@ /// ( 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 --- /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 --- a/mlir/include/mlir/IR/Operation.h +++ b/mlir/include/mlir/IR/Operation.h @@ -167,7 +167,7 @@ /// 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 @@ /// 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 --- a/mlir/include/mlir/IR/PatternMatch.h +++ b/mlir/include/mlir/IR/PatternMatch.h @@ -410,8 +410,7 @@ /// 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 --- a/mlir/include/mlir/IR/Region.h +++ b/mlir/include/mlir/IR/Region.h @@ -19,7 +19,7 @@ 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 @@ /// 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 --- 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 --- a/mlir/include/mlir/Transforms/DialectConversion.h +++ b/mlir/include/mlir/Transforms/DialectConversion.h @@ -620,8 +620,7 @@ /// 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 --- 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 @@ /// 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 @@ /// 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 @@ 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 @@ /// 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 --- 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 --- 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 --- 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 @@ // 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 @@ 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 --- 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 --- 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 @@ /// 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 @@ 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 --- 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 @@ 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 --- 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 --- 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 @@ /// 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 @@ /// 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 @@ /// 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 @@ // 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 @@ /// '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 @@ /// 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 --- 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 --- 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 --- 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 @@ // 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 --- 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 @@ 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 --- 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 @@ 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 @@ 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 @@ // `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 @@ } // 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 --- 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 @@ // 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 --- a/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp +++ b/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp @@ -27,8 +27,7 @@ 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 --- 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 --- 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 @@ } // 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 --- 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 @@ // 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 --- 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 @@ } //===----------------------------------------------------------------------===// -// 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 --- a/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp +++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp @@ -40,8 +40,7 @@ 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 --- 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 @@ 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 --- 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 @@ } /// 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; } @@ -276,7 +274,7 @@ /// 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()) @@ -299,7 +297,7 @@ /// 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()); @@ -338,7 +336,7 @@ 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 --- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp +++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp @@ -122,8 +122,7 @@ 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 --- 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 @@ // 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 @@ 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 --- 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 @@ 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 --- 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 @@ 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 @@ 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 --- 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 @@ /// 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 @@ } // 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 @@ 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 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -2824,8 +2824,7 @@ using DialectInlinerInterface::DialectInlinerInterface; /// Conservatively only allow inlining of pure ops. - bool isLegalToInline(Operation *op, Region *, bool, - BlockAndValueMapping &) const final { + bool isLegalToInline(Operation *op, Region *, bool, IRMapping &) const final { return isPure(op); } }; diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp --- a/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp @@ -44,12 +44,11 @@ // 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 --- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp +++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp @@ -384,7 +384,7 @@ 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 --- a/mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp @@ -324,7 +324,7 @@ 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 --- a/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp @@ -157,7 +157,7 @@ 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 @@ // 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 --- a/mlir/lib/Dialect/Linalg/Transforms/HoistPadding.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/HoistPadding.cpp @@ -447,7 +447,7 @@ 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 --- 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 @@ 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 --- a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp @@ -693,7 +693,7 @@ } // 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 --- a/mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp @@ -47,7 +47,7 @@ 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 @@ 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 --- a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp @@ -381,7 +381,7 @@ 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 --- a/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp @@ -511,10 +511,10 @@ 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 @@ /// CustomVectorizationHook. static VectorizationResult vectorizeLinalgYield(RewriterBase &rewriter, Operation *op, - const BlockAndValueMapping &bvm, VectorizationState &state, + const IRMapping &bvm, VectorizationState &state, LinalgOp linalgOp, SmallVectorImpl &newResults) { auto yieldOp = dyn_cast(op); if (!yieldOp) @@ -615,7 +615,7 @@ /// 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()); @@ -652,9 +652,10 @@ /// 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}; @@ -692,10 +693,9 @@ /// 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(); @@ -730,7 +730,7 @@ /// 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"); @@ -837,7 +837,7 @@ // 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()); @@ -915,24 +915,21 @@ 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 --- a/mlir/lib/Dialect/Math/IR/MathDialect.cpp +++ b/mlir/lib/Dialect/Math/IR/MathDialect.cpp @@ -21,8 +21,7 @@ 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 --- a/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp +++ b/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp @@ -24,11 +24,11 @@ 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 --- 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 @@ // 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 @@ // 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 @@ 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 @@ 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 --- 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 @@ /// 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 @@ /// 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 @@ // 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 --- 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 @@ 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 --- 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 @@ } OpBuilder b(op); - BlockAndValueMapping map; + IRMapping map; Value cond; for (auto bound : llvm::zip(op.getUpperBound(), constantIndices)) { Value constant = @@ -93,7 +93,7 @@ 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 --- 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 @@ /// 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 @@ /// 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 @@ /// 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 --- 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 @@ // `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 @@ 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 @@ 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 --- a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp +++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp @@ -61,7 +61,7 @@ /// 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 @@ /// 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 --- a/mlir/lib/Dialect/Shape/IR/Shape.cpp +++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp @@ -114,7 +114,7 @@ // 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 @@ // 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 --- 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 @@ 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 --- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp @@ -350,7 +350,7 @@ /*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 @@ 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 --- a/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp +++ b/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp @@ -1204,7 +1204,7 @@ 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 --- a/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp +++ b/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp @@ -25,11 +25,11 @@ 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 --- 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 @@ 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 @@ padTensorOp.getLow(), padTensorOp.getHigh(), padTensorOp.getStaticLow(), padTensorOp.getStaticHigh(), padTensorOp.getNofold()); - BlockAndValueMapping mapper; + IRMapping mapper; padTensorOp.getRegion().cloneInto(&newOp.getRegion(), mapper); rewriter.replaceOpWithNewOp( @@ -3190,7 +3190,7 @@ 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 --- a/mlir/lib/Dialect/Tensor/IR/TensorTilingInterfaceImpl.cpp +++ b/mlir/lib/Dialect/Tensor/IR/TensorTilingInterfaceImpl.cpp @@ -616,7 +616,7 @@ 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 --- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp +++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp @@ -50,13 +50,13 @@ /// 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 --- 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 --- 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 @@ 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 --- 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 @@ 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 --- a/mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp @@ -428,7 +428,7 @@ 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 @@ // 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 --- 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 @@ 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; + IRMapping mapper; return clone(op, mapper); } diff --git a/mlir/lib/IR/BuiltinDialect.cpp b/mlir/lib/IR/BuiltinDialect.cpp --- 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 --- 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 @@ /// 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 @@ /// 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 @@ // 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(CloneOptions options) { - BlockAndValueMapping mapper; + IRMapping mapper; return clone(mapper, options); } diff --git a/mlir/lib/IR/PatternMatch.cpp b/mlir/lib/IR/PatternMatch.cpp --- 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 @@ /// 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 --- 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 @@ /// 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 --- 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 @@ 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 --- 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 --- 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 @@ 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 --- 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 @@ //===----------------------------------------------------------------------===// 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 @@ private: /// Current value mappings. - BlockAndValueMapping mapping; + IRMapping mapping; }; } // namespace @@ -1620,9 +1620,10 @@ 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 --- 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 @@ } 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 @@ 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 @@ /// 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 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 @@ 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 @@ } 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 @@ ++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 @@ 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 --- a/mlir/test/lib/Dialect/Test/TestDialect.cpp +++ b/mlir/test/lib/Dialect/Test/TestDialect.cpp @@ -192,13 +192,11 @@ // 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 --- a/mlir/test/lib/IR/TestClone.cpp +++ b/mlir/test/lib/IR/TestClone.cpp @@ -41,7 +41,7 @@ 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 --- 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 @@ 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 --- 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 --- a/mlir/unittests/IR/CMakeLists.txt +++ b/mlir/unittests/IR/CMakeLists.txt @@ -1,8 +1,8 @@ add_mlir_unittest(MLIRIRTests 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 rename from mlir/unittests/IR/BlockAndValueMapping.cpp rename to mlir/unittests/IR/IRMapping.cpp --- 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 @@ 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()); }