[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / mlir / unittests / IR / IRMapping.cpp
blob83627975006ee83f8aeba70c53dc259d291d2f03
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"
15 using namespace mlir;
17 TEST(IRMapping, TypedValue) {
18 MLIRContext context;
20 context.loadDialect<test::TestDialect>();
22 OpBuilder builder(&context);
23 Location loc = builder.getUnknownLoc();
25 Block block;
26 builder.setInsertionPointToEnd(&block);
28 Value i64Val = builder.create<test::TestOpConstant>(
29 loc, builder.getI64Type(), builder.getI64IntegerAttr(0));
30 Value f64Val = builder.create<test::TestOpConstant>(
31 loc, builder.getF64Type(), builder.getF64FloatAttr(0.0));
33 IRMapping mapping;
34 mapping.map(i64Val, f64Val);
35 auto typedI64Val = cast<TypedValue<IntegerType>>(i64Val);
36 EXPECT_EQ(mapping.lookup(typedI64Val), f64Val);
39 TEST(IRMapping, OperationClone) {
40 MLIRContext ctx;
41 ctx.allowUnregisteredDialects();
43 OperationState state(UnknownLoc::get(&ctx), "no_results");
44 Operation *noResultsOp = Operation::create(state);
46 OperationState owner(UnknownLoc::get(&ctx), "owner");
47 owner.addRegion()->emplaceBlock().push_back(noResultsOp);
48 OwningOpRef<Operation *> ownerOp = Operation::create(owner);
50 IRMapping irMap;
51 OwningOpRef<Operation *> clonedOwnerOp = (*ownerOp)->clone(irMap);
53 EXPECT_EQ(irMap.lookupOrNull(*ownerOp), *clonedOwnerOp);
54 EXPECT_EQ(irMap.lookupOrNull(noResultsOp),
55 &(*clonedOwnerOp)->getRegion(0).front().front());