From 2663f35684efb79e08b26cdd359ff64c429ad2d3 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Tue, 19 Apr 2016 04:55:25 +0000 Subject: [PATCH] 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 --- include/llvm/IR/LLVMContext.h | 16 +++++++-------- lib/AsmParser/LLParser.cpp | 2 +- lib/Bitcode/Reader/BitcodeReader.cpp | 2 +- lib/IR/LLVMContext.cpp | 10 +++++----- lib/LTO/LTOCodeGenerator.cpp | 2 +- tools/gold/gold-plugin.cpp | 4 ++-- tools/llvm-link/llvm-link.cpp | 2 +- unittests/IR/LLVMContextTest.cpp | 30 ++++++++++++++-------------- 8 files changed, 34 insertions(+), 34 deletions(-) diff --git a/include/llvm/IR/LLVMContext.h b/include/llvm/IR/LLVMContext.h index 34541995c4c..2b0dfaf5598 100644 --- a/include/llvm/IR/LLVMContext.h +++ b/include/llvm/IR/LLVMContext.h @@ -115,22 +115,22 @@ public: /// especially in release mode. void setDiscardValueNames(bool Discard); - /// Whether there is a string map for uniquing debug info types with + /// Whether there is a string map for uniquing debug info /// identifiers across the context. Off by default. - bool hasDITypeMap() const; - void ensureDITypeMap(); - void destroyDITypeMap(); + bool isODRUniquingDebugTypes() const; + void enableDebugTypeODRUniquing(); + void disableDebugTypeODRUniquing(); /// Get or insert the DIType mapped to the given string. /// /// Returns the address of the current \a DIType pointer mapped to \c S, /// inserting a mapping to \c nullptr if \c S was not previously mapped. /// This method has no effect (and returns \c nullptr instead of a valid - /// address) if \a hasDITypeMap() is \c false. + /// address) if \a isODRUniquingDebugTypes() is \c false. /// - /// \post If \a hasDITypeMap(), \c S will have a (possibly null) mapping. - /// \note The returned address is only valid until the next call. - DIType **getOrInsertDITypeMapping(const MDString &S); + /// \post If \a isODRUniquingDebugTypes(), \c S will have a (possibly null) + /// mapping. \note The returned address is only valid until the next call. + DIType **getOrInsertODRUniquedType(const MDString &S); typedef void (*InlineAsmDiagHandlerTy)(const SMDiagnostic&, void *Context, unsigned LocCookie); diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 34f7ec4469b..987ab5de967 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -3843,7 +3843,7 @@ bool LLParser::ParseDICompositeType(MDNode *&Result, bool IsDistinct) { // type map in the context. DIType **MappedT = nullptr; if (!(flags.Val & DINode::FlagFwdDecl) && identifier.Val && - (MappedT = Context.getOrInsertDITypeMapping(*identifier.Val)) && + (MappedT = Context.getOrInsertODRUniquedType(*identifier.Val)) && *MappedT) { Result = *MappedT; return false; diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 18386ed0727..1a83359b6e8 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2194,7 +2194,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { auto *Identifier = getMDString(Record[15]); DIType **MappedT = nullptr; if (!(Flags & DINode::FlagFwdDecl) && Identifier) - MappedT = Context.getOrInsertDITypeMapping(*Identifier); + MappedT = Context.getOrInsertODRUniquedType(*Identifier); // Use the mapped type node, or create a new one if necessary. DIType *CT = MappedT ? *MappedT : nullptr; diff --git a/lib/IR/LLVMContext.cpp b/lib/IR/LLVMContext.cpp index 3fc79ed03c3..e166a551ade 100644 --- a/lib/IR/LLVMContext.cpp +++ b/lib/IR/LLVMContext.cpp @@ -311,19 +311,19 @@ bool LLVMContext::shouldDiscardValueNames() const { return pImpl->DiscardValueNames; } -bool LLVMContext::hasDITypeMap() const { return !!pImpl->DITypeMap; } +bool LLVMContext::isODRUniquingDebugTypes() const { return !!pImpl->DITypeMap; } -void LLVMContext::ensureDITypeMap() { +void LLVMContext::enableDebugTypeODRUniquing() { if (pImpl->DITypeMap) return; pImpl->DITypeMap = llvm::make_unique>(); } -void LLVMContext::destroyDITypeMap() { pImpl->DITypeMap.reset(); } +void LLVMContext::disableDebugTypeODRUniquing() { pImpl->DITypeMap.reset(); } -DIType **LLVMContext::getOrInsertDITypeMapping(const MDString &S) { - if (!hasDITypeMap()) +DIType **LLVMContext::getOrInsertODRUniquedType(const MDString &S) { + if (!isODRUniquingDebugTypes()) return nullptr; return &(*pImpl->DITypeMap)[&S]; } diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp index a1d4d7bd101..e06903ca37b 100644 --- a/lib/LTO/LTOCodeGenerator.cpp +++ b/lib/LTO/LTOCodeGenerator.cpp @@ -84,7 +84,7 @@ LTOCodeGenerator::LTOCodeGenerator(LLVMContext &Context) : Context(Context), MergedModule(new Module("ld-temp.o", Context)), TheLinker(new Linker(*MergedModule)) { Context.setDiscardValueNames(LTODiscardValueNames); - Context.ensureDITypeMap(); + Context.enableDebugTypeODRUniquing(); initializeLTOPasses(); } diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp index 9a78c56b96a..1c78d2fc745 100644 --- a/tools/gold/gold-plugin.cpp +++ b/tools/gold/gold-plugin.cpp @@ -1114,7 +1114,7 @@ static void thinLTOBackendTask(claimed_file &F, const void *View, raw_fd_ostream *OS, unsigned TaskID) { // Need to use a separate context for each task LLVMContext Context; - Context.ensureDITypeMap(); // Merge debug info types. + Context.enableDebugTypeODRUniquing(); // Merge debug info types. Context.setDiagnosticHandler(diagnosticHandlerForContext, nullptr, true); std::unique_ptr NewModule(new llvm::Module(File.name, Context)); @@ -1236,7 +1236,7 @@ static ld_plugin_status allSymbolsReadHook(raw_fd_ostream *ApiFile) { } LLVMContext Context; - Context.ensureDITypeMap(); // Merge debug info types. + Context.enableDebugTypeODRUniquing(); // Merge debug info types. Context.setDiagnosticHandler(diagnosticHandlerForContext, nullptr, true); std::unique_ptr Combined(new Module("ld-temp.o", Context)); diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp index 2dac8eabaee..73ac8727e71 100644 --- a/tools/llvm-link/llvm-link.cpp +++ b/tools/llvm-link/llvm-link.cpp @@ -342,7 +342,7 @@ int main(int argc, char **argv) { cl::ParseCommandLineOptions(argc, argv, "llvm linker\n"); if (!DisableDITypeMap) - Context.ensureDITypeMap(); + Context.enableDebugTypeODRUniquing(); auto Composite = make_unique("llvm-link", Context); Linker L(*Composite); diff --git a/unittests/IR/LLVMContextTest.cpp b/unittests/IR/LLVMContextTest.cpp index 16cf0745e09..f1eeb05b1cb 100644 --- a/unittests/IR/LLVMContextTest.cpp +++ b/unittests/IR/LLVMContextTest.cpp @@ -14,25 +14,25 @@ using namespace llvm; namespace { -TEST(LLVMContextTest, ensureDITypeMap) { +TEST(LLVMContextTest, enableDebugTypeODRUniquing) { LLVMContext Context; - EXPECT_FALSE(Context.hasDITypeMap()); - Context.ensureDITypeMap(); - EXPECT_TRUE(Context.hasDITypeMap()); - Context.destroyDITypeMap(); - EXPECT_FALSE(Context.hasDITypeMap()); + EXPECT_FALSE(Context.isODRUniquingDebugTypes()); + Context.enableDebugTypeODRUniquing(); + EXPECT_TRUE(Context.isODRUniquingDebugTypes()); + Context.disableDebugTypeODRUniquing(); + EXPECT_FALSE(Context.isODRUniquingDebugTypes()); } -TEST(LLVMContextTest, getOrInsertDITypeMapping) { +TEST(LLVMContextTest, getOrInsertODRUniquedType) { LLVMContext Context; const MDString &S = *MDString::get(Context, "string"); // Without a type map, this should return null. - EXPECT_FALSE(Context.getOrInsertDITypeMapping(S)); + EXPECT_FALSE(Context.getOrInsertODRUniquedType(S)); // Get the mapping. - Context.ensureDITypeMap(); - DIType **Mapping = Context.getOrInsertDITypeMapping(S); + Context.enableDebugTypeODRUniquing(); + DIType **Mapping = Context.getOrInsertODRUniquedType(S); ASSERT_TRUE(Mapping); // Create some type and add it to the mapping. @@ -41,17 +41,17 @@ TEST(LLVMContextTest, getOrInsertDITypeMapping) { *Mapping = &BT; // Check that we get it back. - Mapping = Context.getOrInsertDITypeMapping(S); + Mapping = Context.getOrInsertODRUniquedType(S); ASSERT_TRUE(Mapping); EXPECT_EQ(&BT, *Mapping); // Check that it's discarded with the type map. - Context.destroyDITypeMap(); - EXPECT_FALSE(Context.getOrInsertDITypeMapping(S)); + Context.disableDebugTypeODRUniquing(); + EXPECT_FALSE(Context.getOrInsertODRUniquedType(S)); // And it shouldn't magically reappear... - Context.ensureDITypeMap(); - EXPECT_FALSE(*Context.getOrInsertDITypeMapping(S)); + Context.enableDebugTypeODRUniquing(); + EXPECT_FALSE(*Context.getOrInsertODRUniquedType(S)); } } // end namespace