mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-13 11:30:21 +00:00

Support seeding a ValueMap with nullptr for Metadata entries, a situation I didn't consider in the Metadata/Value split. I added a ValueMapper::getMappedMD accessor that returns an Optional<Metadata*> with the mapped (possibly null) metadata. IRMover needs to use this to avoid modifying the map when it's checking for unneeded subprograms. I updated a call from bugpoint since I find the new code clearer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265228 91177308-0d34-0410-b5e6-96231b3b80d8
85 lines
2.2 KiB
C++
85 lines
2.2 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));
|
|
}
|
|
|
|
TEST(ValueMapperTest, MapMetadataSeeded) {
|
|
LLVMContext Context;
|
|
auto *D = MDTuple::getDistinct(Context, None);
|
|
|
|
// The node should be moved.
|
|
ValueToValueMapTy VM;
|
|
EXPECT_EQ(None, VM.getMappedMD(D));
|
|
|
|
VM.MD().insert(std::make_pair(D, TrackingMDRef(D)));
|
|
EXPECT_EQ(D, *VM.getMappedMD(D));
|
|
EXPECT_EQ(D, MapMetadata(D, VM, RF_None));
|
|
}
|
|
|
|
TEST(ValueMapperTest, MapMetadataSeededWithNull) {
|
|
LLVMContext Context;
|
|
auto *D = MDTuple::getDistinct(Context, None);
|
|
|
|
// The node should be moved.
|
|
ValueToValueMapTy VM;
|
|
EXPECT_EQ(None, VM.getMappedMD(D));
|
|
|
|
VM.MD().insert(std::make_pair(D, TrackingMDRef()));
|
|
EXPECT_EQ(nullptr, *VM.getMappedMD(D));
|
|
EXPECT_EQ(nullptr, MapMetadata(D, VM, RF_None));
|
|
}
|
|
|
|
} // end namespace
|