1 //===- ValueMapper.cpp - Unit tests for ValueMapper -----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/IR/LLVMContext.h"
11 #include "llvm/IR/Metadata.h"
12 #include "llvm/Transforms/Utils/ValueMapper.h"
13 #include "gtest/gtest.h"
19 TEST(ValueMapperTest, MapMetadataUnresolved) {
21 TempMDTuple T = MDTuple::getTemporary(Context, None);
24 EXPECT_EQ(T.get(), MapMetadata(T.get(), VM, RF_NoModuleLevelChanges));
27 TEST(ValueMapperTest, MapMetadataDistinct) {
29 auto *D = MDTuple::getDistinct(Context, None);
32 // The node should be cloned.
34 EXPECT_NE(D, MapMetadata(D, VM, RF_None));
37 // The node should be moved.
39 EXPECT_EQ(D, MapMetadata(D, VM, RF_MoveDistinctMDs));
43 TEST(ValueMapperTest, MapMetadataDistinctOperands) {
45 Metadata *Old = MDTuple::getDistinct(Context, None);
46 auto *D = MDTuple::getDistinct(Context, Old);
47 ASSERT_EQ(Old, D->getOperand(0));
49 Metadata *New = MDTuple::getDistinct(Context, None);
51 VM.MD()[Old].reset(New);
53 // Make sure operands are updated.
54 EXPECT_EQ(D, MapMetadata(D, VM, RF_MoveDistinctMDs));
55 EXPECT_EQ(New, D->getOperand(0));