mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-27 06:54:30 +00:00
IR: Require DICompositeType for ODR uniquing type map
Tighten up the API for debug info ODR type uniquing in LLVMContext. The only reason to allow other DIType subclasses is to make the unit tests prettier :/. llvm-svn: 266737
This commit is contained in:
parent
2006c6eadb
commit
74624754a7
@ -26,7 +26,7 @@ class Twine;
|
|||||||
class Instruction;
|
class Instruction;
|
||||||
class Module;
|
class Module;
|
||||||
class MDString;
|
class MDString;
|
||||||
class DIType;
|
class DICompositeType;
|
||||||
class SMDiagnostic;
|
class SMDiagnostic;
|
||||||
class DiagnosticInfo;
|
class DiagnosticInfo;
|
||||||
template <typename T> class SmallVectorImpl;
|
template <typename T> class SmallVectorImpl;
|
||||||
@ -121,16 +121,16 @@ public:
|
|||||||
void enableDebugTypeODRUniquing();
|
void enableDebugTypeODRUniquing();
|
||||||
void disableDebugTypeODRUniquing();
|
void disableDebugTypeODRUniquing();
|
||||||
|
|
||||||
/// Get or insert the DIType mapped to the given string.
|
/// Get or insert the DICompositeType mapped to the given string.
|
||||||
///
|
///
|
||||||
/// Returns the address of the current \a DIType pointer mapped to \c S,
|
/// Returns the address of the current \a DICompositeType pointer mapped to
|
||||||
/// inserting a mapping to \c nullptr if \c S was not previously mapped.
|
/// \c S, inserting a mapping to \c nullptr if \c S was not previously
|
||||||
/// This method has no effect (and returns \c nullptr instead of a valid
|
/// mapped. This method has no effect (and returns \c nullptr instead of a
|
||||||
/// address) if \a isODRUniquingDebugTypes() is \c false.
|
/// valid address) if \a isODRUniquingDebugTypes() is \c false.
|
||||||
///
|
///
|
||||||
/// \post If \a isODRUniquingDebugTypes(), \c S will have a (possibly null)
|
/// \post If \a isODRUniquingDebugTypes(), \c S will have a (possibly null)
|
||||||
/// mapping. \note The returned address is only valid until the next call.
|
/// mapping. \note The returned address is only valid until the next call.
|
||||||
DIType **getOrInsertODRUniquedType(const MDString &S);
|
DICompositeType **getOrInsertODRUniquedType(const MDString &S);
|
||||||
|
|
||||||
typedef void (*InlineAsmDiagHandlerTy)(const SMDiagnostic&, void *Context,
|
typedef void (*InlineAsmDiagHandlerTy)(const SMDiagnostic&, void *Context,
|
||||||
unsigned LocCookie);
|
unsigned LocCookie);
|
||||||
|
@ -3841,7 +3841,7 @@ bool LLParser::ParseDICompositeType(MDNode *&Result, bool IsDistinct) {
|
|||||||
|
|
||||||
// If this isn't a forward declaration and it has a UUID, check for it in the
|
// If this isn't a forward declaration and it has a UUID, check for it in the
|
||||||
// type map in the context.
|
// type map in the context.
|
||||||
DIType **MappedT = nullptr;
|
DICompositeType **MappedT = nullptr;
|
||||||
if (!(flags.Val & DINode::FlagFwdDecl) && identifier.Val &&
|
if (!(flags.Val & DINode::FlagFwdDecl) && identifier.Val &&
|
||||||
(MappedT = Context.getOrInsertODRUniquedType(*identifier.Val)) &&
|
(MappedT = Context.getOrInsertODRUniquedType(*identifier.Val)) &&
|
||||||
*MappedT) {
|
*MappedT) {
|
||||||
@ -3857,7 +3857,7 @@ bool LLParser::ParseDICompositeType(MDNode *&Result, bool IsDistinct) {
|
|||||||
size.Val, align.Val, offset.Val, flags.Val, elements.Val,
|
size.Val, align.Val, offset.Val, flags.Val, elements.Val,
|
||||||
runtimeLang.Val, vtableHolder.Val, templateParams.Val, identifier.Val));
|
runtimeLang.Val, vtableHolder.Val, templateParams.Val, identifier.Val));
|
||||||
if (MappedT)
|
if (MappedT)
|
||||||
*MappedT = cast<DIType>(Result);
|
*MappedT = cast<DICompositeType>(Result);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2192,12 +2192,12 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
|
|||||||
// mapping.
|
// mapping.
|
||||||
unsigned Flags = Record[10];
|
unsigned Flags = Record[10];
|
||||||
auto *Identifier = getMDString(Record[15]);
|
auto *Identifier = getMDString(Record[15]);
|
||||||
DIType **MappedT = nullptr;
|
DICompositeType **MappedT = nullptr;
|
||||||
if (!(Flags & DINode::FlagFwdDecl) && Identifier)
|
if (!(Flags & DINode::FlagFwdDecl) && Identifier)
|
||||||
MappedT = Context.getOrInsertODRUniquedType(*Identifier);
|
MappedT = Context.getOrInsertODRUniquedType(*Identifier);
|
||||||
|
|
||||||
// Use the mapped type node, or create a new one if necessary.
|
// Use the mapped type node, or create a new one if necessary.
|
||||||
DIType *CT = MappedT ? *MappedT : nullptr;
|
DICompositeType *CT = MappedT ? *MappedT : nullptr;
|
||||||
if (!CT) {
|
if (!CT) {
|
||||||
CT = GET_OR_DISTINCT(
|
CT = GET_OR_DISTINCT(
|
||||||
DICompositeType, Record[0],
|
DICompositeType, Record[0],
|
||||||
|
@ -317,12 +317,13 @@ void LLVMContext::enableDebugTypeODRUniquing() {
|
|||||||
if (pImpl->DITypeMap)
|
if (pImpl->DITypeMap)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pImpl->DITypeMap = llvm::make_unique<DenseMap<const MDString *, DIType *>>();
|
pImpl->DITypeMap =
|
||||||
|
llvm::make_unique<DenseMap<const MDString *, DICompositeType *>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LLVMContext::disableDebugTypeODRUniquing() { pImpl->DITypeMap.reset(); }
|
void LLVMContext::disableDebugTypeODRUniquing() { pImpl->DITypeMap.reset(); }
|
||||||
|
|
||||||
DIType **LLVMContext::getOrInsertODRUniquedType(const MDString &S) {
|
DICompositeType **LLVMContext::getOrInsertODRUniquedType(const MDString &S) {
|
||||||
if (!isODRUniquingDebugTypes())
|
if (!isODRUniquingDebugTypes())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return &(*pImpl->DITypeMap)[&S];
|
return &(*pImpl->DITypeMap)[&S];
|
||||||
|
@ -1022,7 +1022,7 @@ public:
|
|||||||
#include "llvm/IR/Metadata.def"
|
#include "llvm/IR/Metadata.def"
|
||||||
|
|
||||||
// Optional map for looking up composite types by identifier.
|
// Optional map for looking up composite types by identifier.
|
||||||
std::unique_ptr<DenseMap<const MDString *, DIType *>> DITypeMap;
|
std::unique_ptr<DenseMap<const MDString *, DICompositeType *>> DITypeMap;
|
||||||
|
|
||||||
// MDNodes may be uniqued or not uniqued. When they're not uniqued, they
|
// MDNodes may be uniqued or not uniqued. When they're not uniqued, they
|
||||||
// aren't in the MDNodeSet, but they're still shared between objects, so no
|
// aren't in the MDNodeSet, but they're still shared between objects, so no
|
||||||
|
@ -32,18 +32,20 @@ TEST(LLVMContextTest, getOrInsertODRUniquedType) {
|
|||||||
|
|
||||||
// Get the mapping.
|
// Get the mapping.
|
||||||
Context.enableDebugTypeODRUniquing();
|
Context.enableDebugTypeODRUniquing();
|
||||||
DIType **Mapping = Context.getOrInsertODRUniquedType(S);
|
DICompositeType **Mapping = Context.getOrInsertODRUniquedType(S);
|
||||||
ASSERT_TRUE(Mapping);
|
ASSERT_TRUE(Mapping);
|
||||||
|
|
||||||
// Create some type and add it to the mapping.
|
// Create some type and add it to the mapping.
|
||||||
auto &BT =
|
auto &CT = *DICompositeType::get(Context, dwarf::DW_TAG_class_type, "name",
|
||||||
*DIBasicType::get(Context, dwarf::DW_TAG_unspecified_type, S.getString());
|
nullptr, 0, nullptr, nullptr, 0, 0, 0, 0,
|
||||||
*Mapping = &BT;
|
nullptr, 0, nullptr, nullptr, S.getString());
|
||||||
|
ASSERT_EQ(S.getString(), CT.getIdentifier());
|
||||||
|
*Mapping = &CT;
|
||||||
|
|
||||||
// Check that we get it back.
|
// Check that we get it back.
|
||||||
Mapping = Context.getOrInsertODRUniquedType(S);
|
Mapping = Context.getOrInsertODRUniquedType(S);
|
||||||
ASSERT_TRUE(Mapping);
|
ASSERT_TRUE(Mapping);
|
||||||
EXPECT_EQ(&BT, *Mapping);
|
EXPECT_EQ(&CT, *Mapping);
|
||||||
|
|
||||||
// Check that it's discarded with the type map.
|
// Check that it's discarded with the type map.
|
||||||
Context.disableDebugTypeODRUniquing();
|
Context.disableDebugTypeODRUniquing();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user