ValueMapper: Use API from r266503 in unit tests, NFC

I'm not in a hurry to migrate all the users, but the unit tests at least
should use the new API.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266505 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2016-04-16 01:40:24 +00:00
parent d83a5e8fc6
commit 90cac21151

View File

@ -19,16 +19,16 @@ using namespace llvm;
namespace {
TEST(ValueMapperTest, MapMetadata) {
TEST(ValueMapperTest, mapMDNode) {
LLVMContext Context;
auto *U = MDTuple::get(Context, None);
// The node should be unchanged.
ValueToValueMapTy VM;
EXPECT_EQ(U, MapMetadata(U, VM, RF_None));
EXPECT_EQ(U, ValueMapper(VM).mapMDNode(*U));
}
TEST(ValueMapperTest, MapMetadataCycle) {
TEST(ValueMapperTest, mapMDNodeCycle) {
LLVMContext Context;
MDNode *U0;
MDNode *U1;
@ -52,19 +52,19 @@ TEST(ValueMapperTest, MapMetadataCycle) {
// Cycles shouldn't be duplicated.
{
ValueToValueMapTy VM;
EXPECT_EQ(U0, MapMetadata(U0, VM, RF_None));
EXPECT_EQ(U1, MapMetadata(U1, VM, RF_None));
EXPECT_EQ(U0, ValueMapper(VM).mapMDNode(*U0));
EXPECT_EQ(U1, ValueMapper(VM).mapMDNode(*U1));
}
// Check the other order.
{
ValueToValueMapTy VM;
EXPECT_EQ(U1, MapMetadata(U1, VM, RF_None));
EXPECT_EQ(U0, MapMetadata(U0, VM, RF_None));
EXPECT_EQ(U1, ValueMapper(VM).mapMDNode(*U1));
EXPECT_EQ(U0, ValueMapper(VM).mapMDNode(*U0));
}
}
TEST(ValueMapperTest, MapMetadataDuplicatedCycle) {
TEST(ValueMapperTest, mapMDNodeDuplicatedCycle) {
LLVMContext Context;
auto *PtrTy = Type::getInt8Ty(Context)->getPointerTo();
std::unique_ptr<GlobalVariable> G0 = llvm::make_unique<GlobalVariable>(
@ -94,8 +94,8 @@ TEST(ValueMapperTest, MapMetadataDuplicatedCycle) {
// have new nodes that reference G1 (instead of G0).
ValueToValueMapTy VM;
VM[G0.get()] = G1.get();
MDNode *MappedN0 = MapMetadata(N0, VM);
MDNode *MappedN1 = MapMetadata(N1, VM);
MDNode *MappedN0 = ValueMapper(VM).mapMDNode(*N0);
MDNode *MappedN1 = ValueMapper(VM).mapMDNode(*N1);
EXPECT_NE(N0, MappedN0);
EXPECT_NE(N1, MappedN1);
EXPECT_EQ(ConstantAsMetadata::get(G1.get()), MappedN1->getOperand(1));
@ -105,31 +105,31 @@ TEST(ValueMapperTest, MapMetadataDuplicatedCycle) {
EXPECT_TRUE(MappedN1->isResolved());
}
TEST(ValueMapperTest, MapMetadataUnresolved) {
TEST(ValueMapperTest, mapMDNodeUnresolved) {
LLVMContext Context;
TempMDTuple T = MDTuple::getTemporary(Context, None);
ValueToValueMapTy VM;
EXPECT_EQ(T.get(), MapMetadata(T.get(), VM, RF_NoModuleLevelChanges));
EXPECT_EQ(T.get(), ValueMapper(VM, RF_NoModuleLevelChanges).mapMDNode(*T));
}
TEST(ValueMapperTest, MapMetadataDistinct) {
TEST(ValueMapperTest, mapMDNodeDistinct) {
LLVMContext Context;
auto *D = MDTuple::getDistinct(Context, None);
{
// The node should be cloned.
ValueToValueMapTy VM;
EXPECT_NE(D, MapMetadata(D, VM, RF_None));
EXPECT_NE(D, ValueMapper(VM).mapMDNode(*D));
}
{
// The node should be moved.
ValueToValueMapTy VM;
EXPECT_EQ(D, MapMetadata(D, VM, RF_MoveDistinctMDs));
EXPECT_EQ(D, ValueMapper(VM, RF_MoveDistinctMDs).mapMDNode(*D));
}
}
TEST(ValueMapperTest, MapMetadataDistinctOperands) {
TEST(ValueMapperTest, mapMDNodeDistinctOperands) {
LLVMContext Context;
Metadata *Old = MDTuple::getDistinct(Context, None);
auto *D = MDTuple::getDistinct(Context, Old);
@ -140,11 +140,11 @@ TEST(ValueMapperTest, MapMetadataDistinctOperands) {
VM.MD()[Old].reset(New);
// Make sure operands are updated.
EXPECT_EQ(D, MapMetadata(D, VM, RF_MoveDistinctMDs));
EXPECT_EQ(D, ValueMapper(VM, RF_MoveDistinctMDs).mapMDNode(*D));
EXPECT_EQ(New, D->getOperand(0));
}
TEST(ValueMapperTest, MapMetadataSeeded) {
TEST(ValueMapperTest, mapMDNodeSeeded) {
LLVMContext Context;
auto *D = MDTuple::getDistinct(Context, None);
@ -154,10 +154,10 @@ TEST(ValueMapperTest, MapMetadataSeeded) {
VM.MD().insert(std::make_pair(D, TrackingMDRef(D)));
EXPECT_EQ(D, *VM.getMappedMD(D));
EXPECT_EQ(D, MapMetadata(D, VM, RF_None));
EXPECT_EQ(D, ValueMapper(VM).mapMDNode(*D));
}
TEST(ValueMapperTest, MapMetadataSeededWithNull) {
TEST(ValueMapperTest, mapMDNodeSeededWithNull) {
LLVMContext Context;
auto *D = MDTuple::getDistinct(Context, None);
@ -167,10 +167,10 @@ TEST(ValueMapperTest, MapMetadataSeededWithNull) {
VM.MD().insert(std::make_pair(D, TrackingMDRef()));
EXPECT_EQ(nullptr, *VM.getMappedMD(D));
EXPECT_EQ(nullptr, MapMetadata(D, VM, RF_None));
EXPECT_EQ(nullptr, ValueMapper(VM).mapMDNode(*D));
}
TEST(ValueMapperTest, MapMetadataNullMapGlobalWithIgnoreMissingLocals) {
TEST(ValueMapperTest, mapMetadataNullMapGlobalWithIgnoreMissingLocals) {
LLVMContext C;
FunctionType *FTy =
FunctionType::get(Type::getVoidTy(C), Type::getInt8Ty(C), false);
@ -179,25 +179,25 @@ TEST(ValueMapperTest, MapMetadataNullMapGlobalWithIgnoreMissingLocals) {
ValueToValueMapTy VM;
RemapFlags Flags = RF_IgnoreMissingLocals | RF_NullMapMissingGlobalValues;
EXPECT_EQ(nullptr, MapValue(F.get(), VM, Flags));
EXPECT_EQ(nullptr, ValueMapper(VM, Flags).mapValue(*F));
}
TEST(ValueMapperTest, MapMetadataMDString) {
TEST(ValueMapperTest, mapMetadataMDString) {
LLVMContext C;
auto *S1 = MDString::get(C, "S1");
ValueToValueMapTy VM;
// Make sure S1 maps to itself, but isn't memoized.
EXPECT_EQ(S1, MapMetadata(S1, VM));
EXPECT_EQ(S1, ValueMapper(VM).mapMetadata(*S1));
EXPECT_EQ(None, VM.getMappedMD(S1));
// We still expect VM.MD() to be respected.
auto *S2 = MDString::get(C, "S2");
VM.MD()[S1].reset(S2);
EXPECT_EQ(S2, MapMetadata(S1, VM));
EXPECT_EQ(S2, ValueMapper(VM).mapMetadata(*S1));
}
TEST(ValueMapperTest, MapMetadataGetMappedMD) {
TEST(ValueMapperTest, mapMetadataGetMappedMD) {
LLVMContext C;
auto *N0 = MDTuple::get(C, None);
auto *N1 = MDTuple::get(C, N0);
@ -205,8 +205,8 @@ TEST(ValueMapperTest, MapMetadataGetMappedMD) {
// Make sure hasMD and getMappedMD work correctly.
ValueToValueMapTy VM;
EXPECT_FALSE(VM.hasMD());
EXPECT_EQ(N0, MapMetadata(N0, VM));
EXPECT_EQ(N1, MapMetadata(N1, VM));
EXPECT_EQ(N0, ValueMapper(VM).mapMetadata(*N0));
EXPECT_EQ(N1, ValueMapper(VM).mapMetadata(*N1));
EXPECT_TRUE(VM.hasMD());
ASSERT_NE(None, VM.getMappedMD(N0));
ASSERT_NE(None, VM.getMappedMD(N1));
@ -214,7 +214,7 @@ TEST(ValueMapperTest, MapMetadataGetMappedMD) {
EXPECT_EQ(N1, *VM.getMappedMD(N1));
}
TEST(ValueMapperTest, MapMetadataNoModuleLevelChanges) {
TEST(ValueMapperTest, mapMetadataNoModuleLevelChanges) {
LLVMContext C;
auto *N0 = MDTuple::get(C, None);
auto *N1 = MDTuple::get(C, N0);
@ -222,14 +222,14 @@ TEST(ValueMapperTest, MapMetadataNoModuleLevelChanges) {
// Nothing should be memoized when RF_NoModuleLevelChanges.
ValueToValueMapTy VM;
EXPECT_FALSE(VM.hasMD());
EXPECT_EQ(N0, MapMetadata(N0, VM, RF_NoModuleLevelChanges));
EXPECT_EQ(N1, MapMetadata(N1, VM, RF_NoModuleLevelChanges));
EXPECT_EQ(N0, ValueMapper(VM, RF_NoModuleLevelChanges).mapMetadata(*N0));
EXPECT_EQ(N1, ValueMapper(VM, RF_NoModuleLevelChanges).mapMetadata(*N1));
EXPECT_FALSE(VM.hasMD());
EXPECT_EQ(None, VM.getMappedMD(N0));
EXPECT_EQ(None, VM.getMappedMD(N1));
}
TEST(ValueMapperTest, MapMetadataConstantAsMetadata) {
TEST(ValueMapperTest, mapMetadataConstantAsMetadata) {
LLVMContext C;
FunctionType *FTy =
FunctionType::get(Type::getVoidTy(C), Type::getInt8Ty(C), false);
@ -239,23 +239,23 @@ TEST(ValueMapperTest, MapMetadataConstantAsMetadata) {
auto *CAM = ConstantAsMetadata::get(F.get());
{
ValueToValueMapTy VM;
EXPECT_EQ(CAM, MapMetadata(CAM, VM));
EXPECT_EQ(CAM, ValueMapper(VM).mapMetadata(*CAM));
EXPECT_TRUE(VM.MD().count(CAM));
VM.MD().erase(CAM);
EXPECT_EQ(CAM, MapMetadata(CAM, VM, RF_IgnoreMissingLocals));
EXPECT_EQ(CAM, ValueMapper(VM, RF_IgnoreMissingLocals).mapMetadata(*CAM));
EXPECT_TRUE(VM.MD().count(CAM));
auto *N = MDTuple::get(C, None);
VM.MD()[CAM].reset(N);
EXPECT_EQ(N, MapMetadata(CAM, VM));
EXPECT_EQ(N, MapMetadata(CAM, VM, RF_IgnoreMissingLocals));
EXPECT_EQ(N, ValueMapper(VM).mapMetadata(*CAM));
EXPECT_EQ(N, ValueMapper(VM, RF_IgnoreMissingLocals).mapMetadata(*CAM));
}
std::unique_ptr<Function> F2(
Function::Create(FTy, GlobalValue::ExternalLinkage, "F2"));
ValueToValueMapTy VM;
VM[F.get()] = F2.get();
auto *F2MD = MapMetadata(CAM, VM);
auto *F2MD = ValueMapper(VM).mapMetadata(*CAM);
EXPECT_TRUE(VM.MD().count(CAM));
EXPECT_TRUE(F2MD);
EXPECT_EQ(F2.get(), cast<ConstantAsMetadata>(F2MD)->getValue());
@ -263,7 +263,7 @@ TEST(ValueMapperTest, MapMetadataConstantAsMetadata) {
#ifdef GTEST_HAS_DEATH_TEST
#ifndef NDEBUG
TEST(ValueMapperTest, MapMetadataLocalAsMetadata) {
TEST(ValueMapperTest, mapMetadataLocalAsMetadata) {
LLVMContext C;
FunctionType *FTy =
FunctionType::get(Type::getVoidTy(C), Type::getInt8Ty(C), false);
@ -271,18 +271,18 @@ TEST(ValueMapperTest, MapMetadataLocalAsMetadata) {
Function::Create(FTy, GlobalValue::ExternalLinkage, "F"));
Argument &A = *F->arg_begin();
// MapMetadata doesn't support LocalAsMetadata. The only valid container for
// mapMetadata doesn't support LocalAsMetadata. The only valid container for
// LocalAsMetadata is a MetadataAsValue instance, so use it directly.
auto *LAM = LocalAsMetadata::get(&A);
ValueToValueMapTy VM;
EXPECT_DEATH(MapMetadata(LAM, VM), "Unexpected local metadata");
EXPECT_DEATH(MapMetadata(LAM, VM, RF_IgnoreMissingLocals),
EXPECT_DEATH(ValueMapper(VM).mapMetadata(*LAM), "Unexpected local metadata");
EXPECT_DEATH(ValueMapper(VM, RF_IgnoreMissingLocals).mapMetadata(*LAM),
"Unexpected local metadata");
}
#endif
#endif
TEST(ValueMapperTest, MapValueLocalAsMetadata) {
TEST(ValueMapperTest, mapValueLocalAsMetadata) {
LLVMContext C;
FunctionType *FTy =
FunctionType::get(Type::getVoidTy(C), Type::getInt8Ty(C), false);
@ -305,26 +305,26 @@ TEST(ValueMapperTest, MapValueLocalAsMetadata) {
auto *N0 = MDTuple::get(C, None);
auto *N0AV = MetadataAsValue::get(C, N0);
ValueToValueMapTy VM;
EXPECT_EQ(N0AV, MapValue(MAV, VM));
EXPECT_EQ(nullptr, MapValue(MAV, VM, RF_IgnoreMissingLocals));
EXPECT_EQ(N0AV, ValueMapper(VM).mapValue(*MAV));
EXPECT_EQ(nullptr, ValueMapper(VM, RF_IgnoreMissingLocals).mapValue(*MAV));
EXPECT_FALSE(VM.count(MAV));
EXPECT_FALSE(VM.count(&A));
EXPECT_EQ(None, VM.getMappedMD(LAM));
VM[MAV] = MAV;
EXPECT_EQ(MAV, MapValue(MAV, VM));
EXPECT_EQ(MAV, MapValue(MAV, VM, RF_IgnoreMissingLocals));
EXPECT_EQ(MAV, ValueMapper(VM).mapValue(*MAV));
EXPECT_EQ(MAV, ValueMapper(VM, RF_IgnoreMissingLocals).mapValue(*MAV));
EXPECT_TRUE(VM.count(MAV));
EXPECT_FALSE(VM.count(&A));
VM[MAV] = &A;
EXPECT_EQ(&A, MapValue(MAV, VM));
EXPECT_EQ(&A, MapValue(MAV, VM, RF_IgnoreMissingLocals));
EXPECT_EQ(&A, ValueMapper(VM).mapValue(*MAV));
EXPECT_EQ(&A, ValueMapper(VM, RF_IgnoreMissingLocals).mapValue(*MAV));
EXPECT_TRUE(VM.count(MAV));
EXPECT_FALSE(VM.count(&A));
}
TEST(ValueMapperTest, MapValueLocalAsMetadataToConstant) {
TEST(ValueMapperTest, mapValueLocalAsMetadataToConstant) {
LLVMContext Context;
auto *Int8 = Type::getInt8Ty(Context);
FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), Int8, false);
@ -342,8 +342,8 @@ TEST(ValueMapperTest, MapValueLocalAsMetadataToConstant) {
auto *MDC = MetadataAsValue::get(Context, ValueAsMetadata::get(&C));
EXPECT_TRUE(isa<LocalAsMetadata>(MDA->getMetadata()));
EXPECT_TRUE(isa<ConstantAsMetadata>(MDC->getMetadata()));
EXPECT_EQ(&C, MapValue(&A, VM));
EXPECT_EQ(MDC, MapValue(MDA, VM));
EXPECT_EQ(&C, ValueMapper(VM).mapValue(A));
EXPECT_EQ(MDC, ValueMapper(VM).mapValue(*MDA));
}
} // end namespace