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 | 81361659c523e6cef9cd66046334fe46619b9c00 (patch) | |
tree | fd95936ab17d9a7c65f27b811066a40813198146 /unittests/Transforms | |
parent | ae29a03172bff733617791323f5a6c01b7695ba0 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265828 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Transforms')
-rw-r--r-- | unittests/Transforms/Utils/ValueMapperTest.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/unittests/Transforms/Utils/ValueMapperTest.cpp b/unittests/Transforms/Utils/ValueMapperTest.cpp index 3bccd503c1b..5221ab705a3 100644 --- a/unittests/Transforms/Utils/ValueMapperTest.cpp +++ b/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 = |