llvm.org GIT mirror llvm / 2663f35
IR: Rename API for enabling ODR uniquing of DITypes, NFC As per David's review, rename everything in the new API for ODR type uniquing of debug info. ensureDITypeMap => enableDebugTypeODRUniquing destroyDITypeMap => disableDebugTypeODRUniquing hasDITypeMap => isODRUniquingDebugTypes git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266713 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 3 years ago
8 changed file(s) with 37 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
114114 /// especially in release mode.
115115 void setDiscardValueNames(bool Discard);
116116
117 /// Whether there is a string map for uniquing debug info types with
117 /// Whether there is a string map for uniquing debug info
118118 /// identifiers across the context. Off by default.
119 bool hasDITypeMap() const;
120 void ensureDITypeMap();
121 void destroyDITypeMap();
119 bool isODRUniquingDebugTypes() const;
120 void enableDebugTypeODRUniquing();
121 void disableDebugTypeODRUniquing();
122122
123123 /// Get or insert the DIType mapped to the given string.
124124 ///
125125 /// Returns the address of the current \a DIType pointer mapped to \c S,
126126 /// inserting a mapping to \c nullptr if \c S was not previously mapped.
127127 /// This method has no effect (and returns \c nullptr instead of a valid
128 /// address) if \a hasDITypeMap() is \c false.
129 ///
130 /// \post If \a hasDITypeMap(), \c S will have a (possibly null) mapping.
131 /// \note The returned address is only valid until the next call.
132 DIType **getOrInsertDITypeMapping(const MDString &S);
128 /// address) if \a isODRUniquingDebugTypes() is \c false.
129 ///
130 /// \post If \a isODRUniquingDebugTypes(), \c S will have a (possibly null)
131 /// mapping. \note The returned address is only valid until the next call.
132 DIType **getOrInsertODRUniquedType(const MDString &S);
133133
134134 typedef void (*InlineAsmDiagHandlerTy)(const SMDiagnostic&, void *Context,
135135 unsigned LocCookie);
38423842 // type map in the context.
38433843 DIType **MappedT = nullptr;
38443844 if (!(flags.Val & DINode::FlagFwdDecl) && identifier.Val &&
3845 (MappedT = Context.getOrInsertDITypeMapping(*identifier.Val)) &&
3845 (MappedT = Context.getOrInsertODRUniquedType(*identifier.Val)) &&
38463846 *MappedT) {
38473847 Result = *MappedT;
38483848 return false;
21932193 auto *Identifier = getMDString(Record[15]);
21942194 DIType **MappedT = nullptr;
21952195 if (!(Flags & DINode::FlagFwdDecl) && Identifier)
2196 MappedT = Context.getOrInsertDITypeMapping(*Identifier);
2196 MappedT = Context.getOrInsertODRUniquedType(*Identifier);
21972197
21982198 // Use the mapped type node, or create a new one if necessary.
21992199 DIType *CT = MappedT ? *MappedT : nullptr;
310310 return pImpl->DiscardValueNames;
311311 }
312312
313 bool LLVMContext::hasDITypeMap() const { return !!pImpl->DITypeMap; }
314
315 void LLVMContext::ensureDITypeMap() {
313 bool LLVMContext::isODRUniquingDebugTypes() const { return !!pImpl->DITypeMap; }
314
315 void LLVMContext::enableDebugTypeODRUniquing() {
316316 if (pImpl->DITypeMap)
317317 return;
318318
319319 pImpl->DITypeMap = llvm::make_unique>();
320320 }
321321
322 void LLVMContext::destroyDITypeMap() { pImpl->DITypeMap.reset(); }
323
324 DIType **LLVMContext::getOrInsertDITypeMapping(const MDString &S) {
325 if (!hasDITypeMap())
322 void LLVMContext::disableDebugTypeODRUniquing() { pImpl->DITypeMap.reset(); }
323
324 DIType **LLVMContext::getOrInsertODRUniquedType(const MDString &S) {
325 if (!isODRUniquingDebugTypes())
326326 return nullptr;
327327 return &(*pImpl->DITypeMap)[&S];
328328 }
8383 : Context(Context), MergedModule(new Module("ld-temp.o", Context)),
8484 TheLinker(new Linker(*MergedModule)) {
8585 Context.setDiscardValueNames(LTODiscardValueNames);
86 Context.ensureDITypeMap();
86 Context.enableDebugTypeODRUniquing();
8787 initializeLTOPasses();
8888 }
8989
11131113 raw_fd_ostream *OS, unsigned TaskID) {
11141114 // Need to use a separate context for each task
11151115 LLVMContext Context;
1116 Context.ensureDITypeMap(); // Merge debug info types.
1116 Context.enableDebugTypeODRUniquing(); // Merge debug info types.
11171117 Context.setDiagnosticHandler(diagnosticHandlerForContext, nullptr, true);
11181118
11191119 std::unique_ptr NewModule(new llvm::Module(File.name, Context));
12351235 }
12361236
12371237 LLVMContext Context;
1238 Context.ensureDITypeMap(); // Merge debug info types.
1238 Context.enableDebugTypeODRUniquing(); // Merge debug info types.
12391239 Context.setDiagnosticHandler(diagnosticHandlerForContext, nullptr, true);
12401240
12411241 std::unique_ptr Combined(new Module("ld-temp.o", Context));
341341 cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
342342
343343 if (!DisableDITypeMap)
344 Context.ensureDITypeMap();
344 Context.enableDebugTypeODRUniquing();
345345
346346 auto Composite = make_unique("llvm-link", Context);
347347 Linker L(*Composite);
1313
1414 namespace {
1515
16 TEST(LLVMContextTest, ensureDITypeMap) {
16 TEST(LLVMContextTest, enableDebugTypeODRUniquing) {
1717 LLVMContext Context;
18 EXPECT_FALSE(Context.hasDITypeMap());
19 Context.ensureDITypeMap();
20 EXPECT_TRUE(Context.hasDITypeMap());
21 Context.destroyDITypeMap();
22 EXPECT_FALSE(Context.hasDITypeMap());
18 EXPECT_FALSE(Context.isODRUniquingDebugTypes());
19 Context.enableDebugTypeODRUniquing();
20 EXPECT_TRUE(Context.isODRUniquingDebugTypes());
21 Context.disableDebugTypeODRUniquing();
22 EXPECT_FALSE(Context.isODRUniquingDebugTypes());
2323 }
2424
25 TEST(LLVMContextTest, getOrInsertDITypeMapping) {
25 TEST(LLVMContextTest, getOrInsertODRUniquedType) {
2626 LLVMContext Context;
2727 const MDString &S = *MDString::get(Context, "string");
2828
2929 // Without a type map, this should return null.
30 EXPECT_FALSE(Context.getOrInsertDITypeMapping(S));
30 EXPECT_FALSE(Context.getOrInsertODRUniquedType(S));
3131
3232 // Get the mapping.
33 Context.ensureDITypeMap();
34 DIType **Mapping = Context.getOrInsertDITypeMapping(S);
33 Context.enableDebugTypeODRUniquing();
34 DIType **Mapping = Context.getOrInsertODRUniquedType(S);
3535 ASSERT_TRUE(Mapping);
3636
3737 // Create some type and add it to the mapping.
4040 *Mapping = &BT;
4141
4242 // Check that we get it back.
43 Mapping = Context.getOrInsertDITypeMapping(S);
43 Mapping = Context.getOrInsertODRUniquedType(S);
4444 ASSERT_TRUE(Mapping);
4545 EXPECT_EQ(&BT, *Mapping);
4646
4747 // Check that it's discarded with the type map.
48 Context.destroyDITypeMap();
49 EXPECT_FALSE(Context.getOrInsertDITypeMapping(S));
48 Context.disableDebugTypeODRUniquing();
49 EXPECT_FALSE(Context.getOrInsertODRUniquedType(S));
5050
5151 // And it shouldn't magically reappear...
52 Context.ensureDITypeMap();
53 EXPECT_FALSE(*Context.getOrInsertDITypeMapping(S));
52 Context.enableDebugTypeODRUniquing();
53 EXPECT_FALSE(*Context.getOrInsertODRUniquedType(S));
5454 }
5555
5656 } // end namespace