IR: Reuse getImpl() for getDistinct(), NFC

Merge `getDistinct()`'s implementation with those of `get()` and
`getIfExists()` for both `MDTuple` and `MDLocation`.  This will make it
easier to scale to supporting temporaries.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226497 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2015-01-19 20:14:15 +00:00
parent 00a658dcdc
commit 518025f8a1
2 changed files with 72 additions and 63 deletions
+54 -48
View File
@@ -605,26 +605,35 @@ void UniquableMDNode::eraseFromStore() {
}
MDTuple *MDTuple::getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
bool ShouldCreate) {
MDTupleInfo::KeyTy Key(MDs);
StorageType Storage, bool ShouldCreate) {
unsigned Hash = 0;
if (Storage == Uniqued) {
MDTupleInfo::KeyTy Key(MDs);
Hash = Key.Hash;
auto &Store = Context.pImpl->MDTuples;
auto I = Store.find_as(Key);
if (I != Store.end())
return *I;
if (!ShouldCreate)
return nullptr;
auto &Store = Context.pImpl->MDTuples;
auto I = Store.find_as(Key);
if (I != Store.end())
return *I;
if (!ShouldCreate)
return nullptr;
} else {
assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
}
// Coallocate space for the node and Operands together, then placement new.
auto *N = new (MDs.size()) MDTuple(Context, Uniqued, MDs);
N->setHash(Key.Hash);
Store.insert(N);
return N;
}
auto *N = new (MDs.size()) MDTuple(Context, Storage, Hash, MDs);
switch (Storage) {
case Uniqued:
Context.pImpl->MDTuples.insert(N);
break;
case Distinct:
N->storeDistinctInContext();
break;
case Temporary:
llvm_unreachable("Unexpected temporary node");
}
MDTuple *MDTuple::getDistinct(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
auto *N = new (MDs.size()) MDTuple(Context, Distinct, MDs);
N->storeDistinctInContext();
return N;
}
@@ -657,17 +666,6 @@ MDLocation::MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
SubclassData16 = Column;
}
MDLocation *MDLocation::constructHelper(LLVMContext &Context,
StorageType Storage, unsigned Line,
unsigned Column, Metadata *Scope,
Metadata *InlinedAt) {
SmallVector<Metadata *, 2> Ops;
Ops.push_back(Scope);
if (InlinedAt)
Ops.push_back(InlinedAt);
return new (Ops.size()) MDLocation(Context, Storage, Line, Column, Ops);
}
static void adjustLine(unsigned &Line) {
// Set to unknown on overflow. Still use 24 bits for now.
if (Line >= (1u << 24))
@@ -682,34 +680,42 @@ static void adjustColumn(unsigned &Column) {
MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line,
unsigned Column, Metadata *Scope,
Metadata *InlinedAt, bool ShouldCreate) {
Metadata *InlinedAt, StorageType Storage,
bool ShouldCreate) {
// Fixup line/column.
adjustLine(Line);
adjustColumn(Column);
MDLocationInfo::KeyTy Key(Line, Column, Scope, InlinedAt);
if (Storage == Uniqued) {
MDLocationInfo::KeyTy Key(Line, Column, Scope, InlinedAt);
auto &Store = Context.pImpl->MDLocations;
auto I = Store.find_as(Key);
if (I != Store.end())
return *I;
if (!ShouldCreate)
return nullptr;
auto &Store = Context.pImpl->MDLocations;
auto I = Store.find_as(Key);
if (I != Store.end())
return *I;
if (!ShouldCreate)
return nullptr;
} else {
assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
}
auto *N = constructHelper(Context, Uniqued, Line, Column, Scope, InlinedAt);
Store.insert(N);
return N;
}
SmallVector<Metadata *, 2> Ops;
Ops.push_back(Scope);
if (InlinedAt)
Ops.push_back(InlinedAt);
auto *N = new (Ops.size()) MDLocation(Context, Storage, Line, Column, Ops);
MDLocation *MDLocation::getDistinct(LLVMContext &Context, unsigned Line,
unsigned Column, Metadata *Scope,
Metadata *InlinedAt) {
// Fixup line/column.
adjustLine(Line);
adjustColumn(Column);
switch (Storage) {
case Uniqued:
Context.pImpl->MDLocations.insert(N);
break;
case Distinct:
N->storeDistinctInContext();
break;
case Temporary:
llvm_unreachable("Unexpected temporary node");
}
auto *N = constructHelper(Context, Distinct, Line, Column, Scope, InlinedAt);
N->storeDistinctInContext();
return N;
}