llvm-project/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp

59 lines
1.5 KiB
C++

//===- ValueMapper.cpp - Unit tests for ValueMapper -----------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/Transforms/Utils/ValueMapper.h"
#include "gtest/gtest.h"
using namespace llvm;
namespace {
TEST(ValueMapperTest, MapMetadataUnresolved) {
LLVMContext Context;
TempMDTuple T = MDTuple::getTemporary(Context, None);
ValueToValueMapTy VM;
EXPECT_EQ(T.get(), MapMetadata(T.get(), VM, RF_NoModuleLevelChanges));
}
TEST(ValueMapperTest, MapMetadataDistinct) {
LLVMContext Context;
auto *D = MDTuple::getDistinct(Context, None);
{
// The node should be cloned.
ValueToValueMapTy VM;
EXPECT_NE(D, MapMetadata(D, VM, RF_None));
}
{
// The node should be moved.
ValueToValueMapTy VM;
EXPECT_EQ(D, MapMetadata(D, VM, RF_MoveDistinctMDs));
}
}
TEST(ValueMapperTest, MapMetadataDistinctOperands) {
LLVMContext Context;
Metadata *Old = MDTuple::getDistinct(Context, None);
auto *D = MDTuple::getDistinct(Context, Old);
ASSERT_EQ(Old, D->getOperand(0));
Metadata *New = MDTuple::getDistinct(Context, None);
ValueToValueMapTy VM;
VM.MD()[Old].reset(New);
// Make sure operands are updated.
EXPECT_EQ(D, MapMetadata(D, VM, RF_MoveDistinctMDs));
EXPECT_EQ(New, D->getOperand(0));
}
}