Index: mlir/include/mlir/IR/BlockAndValueMapping.h =================================================================== --- mlir/include/mlir/IR/BlockAndValueMapping.h +++ mlir/include/mlir/IR/BlockAndValueMapping.h @@ -63,12 +63,8 @@ /// Lookup a mapped value within the map. This asserts the provided value /// exists within the map. - template - T lookup(T from) const { - auto result = lookupOrNull(from); - assert(result && "expected 'from' to be contained within the map"); - return result; - } + 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(); } @@ -80,6 +76,13 @@ const DenseMap &getBlockMap() const { return blockMap; } private: + template + T lookupImpl(T from) const { + auto 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 { Index: mlir/unittests/IR/BlockAndValueMapping.cpp =================================================================== --- /dev/null +++ mlir/unittests/IR/BlockAndValueMapping.cpp @@ -0,0 +1,34 @@ +//===- 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 +// +//===----------------------------------------------------------------------===// + +#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/Builders.h" +#include "gtest/gtest.h" + +#include "../../test/lib/Dialect/Test/TestDialect.h" + +using namespace mlir; + +TEST(BlockAndValueMapping, TypedValue) { + mlir::MLIRContext context; + + context.loadDialect(); + + mlir::OpBuilder builder(&context); + mlir::Location loc = builder.getUnknownLoc(); + + mlir::Value i64Val = builder.create( + loc, builder.getI64Type(), builder.getI64IntegerAttr(0)); + mlir::Value f64Val = builder.create( + loc, builder.getF64Type(), builder.getF64FloatAttr(0.0)); + + mlir::BlockAndValueMapping mapping; + mapping.map(i64Val, f64Val); + TypedValue typedI64Val = i64Val; + mapping.lookup(typedI64Val); +} Index: mlir/unittests/IR/CMakeLists.txt =================================================================== --- mlir/unittests/IR/CMakeLists.txt +++ mlir/unittests/IR/CMakeLists.txt @@ -1,5 +1,6 @@ add_mlir_unittest(MLIRIRTests AttributeTest.cpp + BlockAndValueMapping.cpp DialectTest.cpp InterfaceTest.cpp InterfaceAttachmentTest.cpp