diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2016-04-08 18:49:36 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2016-04-08 18:49:36 +0000 |
commit | 69341e6abca92f7f118ee7bd99be0cdfc649386f (patch) | |
tree | 543c8c36236826e8d0a4eb9d8f7d2c8a08b8f1d1 /llvm/unittests/Transforms | |
parent | e05ff7c1a787cf2bf85e4c73947eea5df34ed8c3 (diff) | |
download | bcm5719-llvm-69341e6abca92f7f118ee7bd99be0cdfc649386f.tar.gz bcm5719-llvm-69341e6abca92f7f118ee7bd99be0cdfc649386f.zip |
ValueMapper: Don't memoize metadata when RF_NoModuleLevelChanges
Prevent the Metadata side-table in ValueMap from growing unnecessarily
when RF_NoModuleLevelChanges. As a drive-by, make ValueMap::hasMD,
which apparently had no users until I used it here for testing, actually
compile.
llvm-svn: 265828
Diffstat (limited to 'llvm/unittests/Transforms')
-rw-r--r-- | llvm/unittests/Transforms/Utils/ValueMapperTest.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp b/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp index 3bccd503c1b..5221ab705a3 100644 --- a/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp +++ b/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp @@ -155,6 +155,38 @@ TEST(ValueMapperTest, MapMetadataMDString) { EXPECT_EQ(S2, MapMetadata(S1, VM)); } +TEST(ValueMapperTest, MapMetadataGetMappedMD) { + LLVMContext C; + auto *N0 = MDTuple::get(C, None); + auto *N1 = MDTuple::get(C, N0); + + // 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_TRUE(VM.hasMD()); + ASSERT_NE(None, VM.getMappedMD(N0)); + ASSERT_NE(None, VM.getMappedMD(N1)); + EXPECT_EQ(N0, *VM.getMappedMD(N0)); + EXPECT_EQ(N1, *VM.getMappedMD(N1)); +} + +TEST(ValueMapperTest, MapMetadataNoModuleLevelChanges) { + LLVMContext C; + auto *N0 = MDTuple::get(C, None); + auto *N1 = MDTuple::get(C, N0); + + // 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_FALSE(VM.hasMD()); + EXPECT_EQ(None, VM.getMappedMD(N0)); + EXPECT_EQ(None, VM.getMappedMD(N1)); +} + TEST(ValueMapperTest, MapMetadataConstantAsMetadata) { LLVMContext C; FunctionType *FTy = |