llvm.org GIT mirror llvm / 8136165
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 Duncan P. N. Exon Smith 4 years ago
3 changed file(s) with 34 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
102102 explicit ValueMap(const ExtraData &Data, unsigned NumInitBuckets = 64)
103103 : Map(NumInitBuckets), Data(Data) {}
104104
105 bool hasMD() const { return MDMap; }
105 bool hasMD() const { return bool(MDMap); }
106106 MDMapT &MD() {
107107 if (!MDMap)
108108 MDMap.reset(new MDMapT);
657657 // This is a module-level metadata. If nothing at the module level is
658658 // changing, use an identity mapping.
659659 if ((Flags & RF_NoModuleLevelChanges))
660 return mapToSelf(MD);
660 return const_cast(MD);
661661
662662 if (auto *CMD = dyn_cast(MD)) {
663663 // Disallow recursion into metadata mapping through mapValue.
152152 auto *S2 = MDString::get(C, "S2");
153153 VM.MD()[S1].reset(S2);
154154 EXPECT_EQ(S2, MapMetadata(S1, VM));
155 }
156
157 TEST(ValueMapperTest, MapMetadataGetMappedMD) {
158 LLVMContext C;
159 auto *N0 = MDTuple::get(C, None);
160 auto *N1 = MDTuple::get(C, N0);
161
162 // Make sure hasMD and getMappedMD work correctly.
163 ValueToValueMapTy VM;
164 EXPECT_FALSE(VM.hasMD());
165 EXPECT_EQ(N0, MapMetadata(N0, VM));
166 EXPECT_EQ(N1, MapMetadata(N1, VM));
167 EXPECT_TRUE(VM.hasMD());
168 ASSERT_NE(None, VM.getMappedMD(N0));
169 ASSERT_NE(None, VM.getMappedMD(N1));
170 EXPECT_EQ(N0, *VM.getMappedMD(N0));
171 EXPECT_EQ(N1, *VM.getMappedMD(N1));
172 }
173
174 TEST(ValueMapperTest, MapMetadataNoModuleLevelChanges) {
175 LLVMContext C;
176 auto *N0 = MDTuple::get(C, None);
177 auto *N1 = MDTuple::get(C, N0);
178
179 // Nothing should be memoized when RF_NoModuleLevelChanges.
180 ValueToValueMapTy VM;
181 EXPECT_FALSE(VM.hasMD());
182 EXPECT_EQ(N0, MapMetadata(N0, VM, RF_NoModuleLevelChanges));
183 EXPECT_EQ(N1, MapMetadata(N1, VM, RF_NoModuleLevelChanges));
184 EXPECT_FALSE(VM.hasMD());
185 EXPECT_EQ(None, VM.getMappedMD(N0));
186 EXPECT_EQ(None, VM.getMappedMD(N1));
155187 }
156188
157189 TEST(ValueMapperTest, MapMetadataConstantAsMetadata) {