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
This commit is contained in:
Duncan P. N. Exon Smith 2016-04-19 04:55:25 +00:00
parent 4576e07c30
commit 2663f35684
8 changed files with 34 additions and 34 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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<DenseMap<const MDString *, DIType *>>();
}
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];
}

View File

@ -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();
}

View File

@ -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<llvm::Module> 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<Module> Combined(new Module("ld-temp.o", Context));

View File

@ -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<Module>("llvm-link", Context);
Linker L(*Composite);

View File

@ -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