summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/DebugInfoMetadata.cpp14
-rw-r--r--llvm/lib/IR/LLVMContextImpl.cpp6
-rw-r--r--llvm/lib/IR/LLVMContextImpl.h64
-rw-r--r--llvm/lib/IR/Metadata.cpp20
-rw-r--r--llvm/lib/IR/MetadataImpl.h13
-rw-r--r--llvm/lib/IR/Verifier.cpp1
6 files changed, 41 insertions, 77 deletions
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp
index 4adda6fb293..89111f73ae2 100644
--- a/llvm/lib/IR/DebugInfoMetadata.cpp
+++ b/llvm/lib/IR/DebugInfoMetadata.cpp
@@ -317,20 +317,18 @@ DICompileUnit *DICompileUnit::getImpl(
Metadata *Subprograms, Metadata *GlobalVariables,
Metadata *ImportedEntities, uint64_t DWOId,
StorageType Storage, bool ShouldCreate) {
+ assert(Storage != Uniqued && "Cannot unique DICompileUnit");
assert(isCanonical(Producer) && "Expected canonical MDString");
assert(isCanonical(Flags) && "Expected canonical MDString");
assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
- DEFINE_GETIMPL_LOOKUP(
- DICompileUnit,
- (SourceLanguage, File, getString(Producer), IsOptimized, getString(Flags),
- RuntimeVersion, getString(SplitDebugFilename), EmissionKind, EnumTypes,
- RetainedTypes, Subprograms, GlobalVariables, ImportedEntities, DWOId));
+
Metadata *Ops[] = {File, Producer, Flags, SplitDebugFilename, EnumTypes,
RetainedTypes, Subprograms, GlobalVariables,
ImportedEntities};
- DEFINE_GETIMPL_STORE(
- DICompileUnit,
- (SourceLanguage, IsOptimized, RuntimeVersion, EmissionKind, DWOId), Ops);
+ return storeImpl(new (ArrayRef<Metadata *>(Ops).size()) DICompileUnit(
+ Context, Storage, SourceLanguage, IsOptimized,
+ RuntimeVersion, EmissionKind, DWOId, Ops),
+ Storage);
}
DISubprogram *DILocalScope::getSubprogram() const {
diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp
index 1e2080770fc..0ce28712339 100644
--- a/llvm/lib/IR/LLVMContextImpl.cpp
+++ b/llvm/lib/IR/LLVMContextImpl.cpp
@@ -78,7 +78,7 @@ LLVMContextImpl::~LLVMContextImpl() {
// unnecessary RAUW when nodes are still unresolved.
for (auto *I : DistinctMDNodes)
I->dropAllReferences();
-#define HANDLE_MDNODE_LEAF(CLASS) \
+#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
for (auto *I : CLASS##s) \
I->dropAllReferences();
#include "llvm/IR/Metadata.def"
@@ -92,8 +92,8 @@ LLVMContextImpl::~LLVMContextImpl() {
// Destroy MDNodes.
for (MDNode *I : DistinctMDNodes)
I->deleteAsSubclass();
-#define HANDLE_MDNODE_LEAF(CLASS) \
- for (CLASS *I : CLASS##s) \
+#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
+ for (CLASS * I : CLASS##s) \
delete I;
#include "llvm/IR/Metadata.def"
diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h
index 35897a93788..f514beabd0d 100644
--- a/llvm/lib/IR/LLVMContextImpl.h
+++ b/llvm/lib/IR/LLVMContextImpl.h
@@ -458,67 +458,6 @@ template <> struct MDNodeKeyImpl<DIFile> {
unsigned getHashValue() const { return hash_combine(Filename, Directory); }
};
-template <> struct MDNodeKeyImpl<DICompileUnit> {
- unsigned SourceLanguage;
- Metadata *File;
- StringRef Producer;
- bool IsOptimized;
- StringRef Flags;
- unsigned RuntimeVersion;
- StringRef SplitDebugFilename;
- unsigned EmissionKind;
- Metadata *EnumTypes;
- Metadata *RetainedTypes;
- Metadata *Subprograms;
- Metadata *GlobalVariables;
- Metadata *ImportedEntities;
- uint64_t DWOId;
-
- MDNodeKeyImpl(unsigned SourceLanguage, Metadata *File, StringRef Producer,
- bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
- StringRef SplitDebugFilename, unsigned EmissionKind,
- Metadata *EnumTypes, Metadata *RetainedTypes,
- Metadata *Subprograms, Metadata *GlobalVariables,
- Metadata *ImportedEntities, uint64_t DWOId)
- : SourceLanguage(SourceLanguage), File(File), Producer(Producer),
- IsOptimized(IsOptimized), Flags(Flags), RuntimeVersion(RuntimeVersion),
- SplitDebugFilename(SplitDebugFilename), EmissionKind(EmissionKind),
- EnumTypes(EnumTypes), RetainedTypes(RetainedTypes),
- Subprograms(Subprograms), GlobalVariables(GlobalVariables),
- ImportedEntities(ImportedEntities), DWOId(DWOId) {}
- MDNodeKeyImpl(const DICompileUnit *N)
- : SourceLanguage(N->getSourceLanguage()), File(N->getRawFile()),
- Producer(N->getProducer()), IsOptimized(N->isOptimized()),
- Flags(N->getFlags()), RuntimeVersion(N->getRuntimeVersion()),
- SplitDebugFilename(N->getSplitDebugFilename()),
- EmissionKind(N->getEmissionKind()), EnumTypes(N->getRawEnumTypes()),
- RetainedTypes(N->getRawRetainedTypes()),
- Subprograms(N->getRawSubprograms()),
- GlobalVariables(N->getRawGlobalVariables()),
- ImportedEntities(N->getRawImportedEntities()), DWOId(N->getDWOId()) {}
-
- bool isKeyOf(const DICompileUnit *RHS) const {
- return SourceLanguage == RHS->getSourceLanguage() &&
- File == RHS->getRawFile() && Producer == RHS->getProducer() &&
- IsOptimized == RHS->isOptimized() && Flags == RHS->getFlags() &&
- RuntimeVersion == RHS->getRuntimeVersion() &&
- SplitDebugFilename == RHS->getSplitDebugFilename() &&
- EmissionKind == RHS->getEmissionKind() &&
- EnumTypes == RHS->getRawEnumTypes() &&
- RetainedTypes == RHS->getRawRetainedTypes() &&
- Subprograms == RHS->getRawSubprograms() &&
- GlobalVariables == RHS->getRawGlobalVariables() &&
- ImportedEntities == RHS->getRawImportedEntities() &&
- DWOId == RHS->getDWOId();
- }
- unsigned getHashValue() const {
- return hash_combine(SourceLanguage, File, Producer, IsOptimized, Flags,
- RuntimeVersion, SplitDebugFilename, EmissionKind,
- EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
- ImportedEntities, DWOId);
- }
-};
-
template <> struct MDNodeKeyImpl<DISubprogram> {
Metadata *Scope;
StringRef Name;
@@ -952,7 +891,8 @@ public:
DenseMap<const Value*, ValueName*> ValueNames;
-#define HANDLE_MDNODE_LEAF(CLASS) DenseSet<CLASS *, CLASS##Info> CLASS##s;
+#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
+ DenseSet<CLASS *, CLASS##Info> CLASS##s;
#include "llvm/IR/Metadata.def"
// MDNodes may be uniqued or not uniqued. When they're not uniqued, they
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index 1abcf0d18c9..6ec4a25f51b 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -545,6 +545,18 @@ static bool hasSelfReference(MDNode *N) {
}
MDNode *MDNode::replaceWithPermanentImpl() {
+ switch (getMetadataID()) {
+ default:
+ // If this type isn't uniquable, replace with a distinct node.
+ return replaceWithDistinctImpl();
+
+#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
+ case CLASS##Kind: \
+ break;
+#include "llvm/IR/Metadata.def"
+ }
+
+ // Even if this type is uniquable, self-references have to be distinct.
if (hasSelfReference(this))
return replaceWithDistinctImpl();
return replaceWithUniquedImpl();
@@ -671,8 +683,8 @@ MDNode *MDNode::uniquify() {
// Try to insert into uniquing store.
switch (getMetadataID()) {
default:
- llvm_unreachable("Invalid subclass of MDNode");
-#define HANDLE_MDNODE_LEAF(CLASS) \
+ llvm_unreachable("Invalid or non-uniquable subclass of MDNode");
+#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
case CLASS##Kind: { \
CLASS *SubclassThis = cast<CLASS>(this); \
std::integral_constant<bool, HasCachedHash<CLASS>::value> \
@@ -687,8 +699,8 @@ MDNode *MDNode::uniquify() {
void MDNode::eraseFromStore() {
switch (getMetadataID()) {
default:
- llvm_unreachable("Invalid subclass of MDNode");
-#define HANDLE_MDNODE_LEAF(CLASS) \
+ llvm_unreachable("Invalid or non-uniquable subclass of MDNode");
+#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
case CLASS##Kind: \
getContext().pImpl->CLASS##s.erase(cast<CLASS>(this)); \
break;
diff --git a/llvm/lib/IR/MetadataImpl.h b/llvm/lib/IR/MetadataImpl.h
index 662a50eb1bd..b9137460bd2 100644
--- a/llvm/lib/IR/MetadataImpl.h
+++ b/llvm/lib/IR/MetadataImpl.h
@@ -26,6 +26,19 @@ static T *getUniqued(DenseSet<T *, InfoT> &Store,
return I == Store.end() ? nullptr : *I;
}
+template <class T> T *MDNode::storeImpl(T *N, StorageType Storage) {
+ switch (Storage) {
+ case Uniqued:
+ llvm_unreachable("Cannot unique without a uniquing-store");
+ case Distinct:
+ N->storeDistinctInContext();
+ break;
+ case Temporary:
+ break;
+ }
+ return N;
+}
+
template <class T, class StoreT>
T *MDNode::storeImpl(T *N, StorageType Storage, StoreT &Store) {
switch (Storage) {
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 05b7b607023..b680f6e62f3 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -887,6 +887,7 @@ void Verifier::visitDIFile(const DIFile &N) {
}
void Verifier::visitDICompileUnit(const DICompileUnit &N) {
+ Assert(N.isDistinct(), "compile units must be distinct", &N);
Assert(N.getTag() == dwarf::DW_TAG_compile_unit, "invalid tag", &N);
// Don't bother verifying the compilation directory or producer string
OpenPOWER on IntegriCloud