Revert "[lldb][test] Remove compiler version check and use regex" (#124101)
[llvm-project.git] / mlir / unittests / IR / IRMapping.cpp
blobb88009d1e3c36114896fb6a4490b2aee761a692b
1 //===- IRMapping.cpp --------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "mlir/IR/IRMapping.h"
10 #include "mlir/IR/Builders.h"
11 #include "gtest/gtest.h"
13 #include "../../test/lib/Dialect/Test/TestDialect.h"
14 #include "../../test/lib/Dialect/Test/TestOps.h"
16 using namespace mlir;
18 TEST(IRMapping, TypedValue) {
19 MLIRContext context;
21 context.loadDialect<test::TestDialect>();
23 OpBuilder builder(&context);
24 Location loc = builder.getUnknownLoc();
26 Block block;
27 builder.setInsertionPointToEnd(&block);
29 Value i64Val = builder.create<test::TestOpConstant>(
30 loc, builder.getI64Type(), builder.getI64IntegerAttr(0));
31 Value f64Val = builder.create<test::TestOpConstant>(
32 loc, builder.getF64Type(), builder.getF64FloatAttr(0.0));
34 IRMapping mapping;
35 mapping.map(i64Val, f64Val);
36 auto typedI64Val = cast<TypedValue<IntegerType>>(i64Val);
37 EXPECT_EQ(mapping.lookup(typedI64Val), f64Val);
40 TEST(IRMapping, OperationClone) {
41 MLIRContext ctx;
42 ctx.allowUnregisteredDialects();
44 OperationState state(UnknownLoc::get(&ctx), "no_results");
45 Operation *noResultsOp = Operation::create(state);
47 OperationState owner(UnknownLoc::get(&ctx), "owner");
48 owner.addRegion()->emplaceBlock().push_back(noResultsOp);
49 OwningOpRef<Operation *> ownerOp = Operation::create(owner);
51 IRMapping irMap;
52 OwningOpRef<Operation *> clonedOwnerOp = (*ownerOp)->clone(irMap);
54 EXPECT_EQ(irMap.lookupOrNull(*ownerOp), *clonedOwnerOp);
55 EXPECT_EQ(irMap.lookupOrNull(noResultsOp),
56 &(*clonedOwnerOp)->getRegion(0).front().front());