mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
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:
parent
00a658dcdc
commit
518025f8a1
@ -855,31 +855,36 @@ class MDTuple : public UniquableMDNode {
|
|||||||
friend class LLVMContextImpl;
|
friend class LLVMContextImpl;
|
||||||
friend class UniquableMDNode;
|
friend class UniquableMDNode;
|
||||||
|
|
||||||
MDTuple(LLVMContext &C, StorageType Storage, ArrayRef<Metadata *> Vals)
|
MDTuple(LLVMContext &C, StorageType Storage, unsigned Hash,
|
||||||
: UniquableMDNode(C, MDTupleKind, Storage, Vals) {}
|
ArrayRef<Metadata *> Vals)
|
||||||
|
: UniquableMDNode(C, MDTupleKind, Storage, Vals) {
|
||||||
|
setHash(Hash);
|
||||||
|
}
|
||||||
~MDTuple() { dropAllReferences(); }
|
~MDTuple() { dropAllReferences(); }
|
||||||
|
|
||||||
void setHash(unsigned Hash) { MDNodeSubclassData = Hash; }
|
void setHash(unsigned Hash) { MDNodeSubclassData = Hash; }
|
||||||
void recalculateHash();
|
void recalculateHash();
|
||||||
|
|
||||||
static MDTuple *getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
|
static MDTuple *getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
|
||||||
bool ShouldCreate);
|
StorageType Storage, bool ShouldCreate = true);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// \brief Get the hash, if any.
|
/// \brief Get the hash, if any.
|
||||||
unsigned getHash() const { return MDNodeSubclassData; }
|
unsigned getHash() const { return MDNodeSubclassData; }
|
||||||
|
|
||||||
static MDTuple *get(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
|
static MDTuple *get(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
|
||||||
return getImpl(Context, MDs, /* ShouldCreate */ true);
|
return getImpl(Context, MDs, Uniqued);
|
||||||
}
|
}
|
||||||
static MDTuple *getIfExists(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
|
static MDTuple *getIfExists(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
|
||||||
return getImpl(Context, MDs, /* ShouldCreate */ false);
|
return getImpl(Context, MDs, Uniqued, /* ShouldCreate */ false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Return a distinct node.
|
/// \brief Return a distinct node.
|
||||||
///
|
///
|
||||||
/// Return a distinct node -- i.e., a node that is not uniqued.
|
/// Return a distinct node -- i.e., a node that is not uniqued.
|
||||||
static MDTuple *getDistinct(LLVMContext &Context, ArrayRef<Metadata *> MDs);
|
static MDTuple *getDistinct(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
|
||||||
|
return getImpl(Context, MDs, Distinct);
|
||||||
|
}
|
||||||
|
|
||||||
static bool classof(const Metadata *MD) {
|
static bool classof(const Metadata *MD) {
|
||||||
return MD->getMetadataID() == MDTupleKind;
|
return MD->getMetadataID() == MDTupleKind;
|
||||||
@ -911,13 +916,10 @@ class MDLocation : public UniquableMDNode {
|
|||||||
unsigned Column, ArrayRef<Metadata *> MDs);
|
unsigned Column, ArrayRef<Metadata *> MDs);
|
||||||
~MDLocation() { dropAllReferences(); }
|
~MDLocation() { dropAllReferences(); }
|
||||||
|
|
||||||
static MDLocation *constructHelper(LLVMContext &Context, StorageType Storage,
|
|
||||||
unsigned Line, unsigned Column,
|
|
||||||
Metadata *Scope, Metadata *InlinedAt);
|
|
||||||
|
|
||||||
static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
|
static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
|
||||||
unsigned Column, Metadata *Scope,
|
unsigned Column, Metadata *Scope,
|
||||||
Metadata *InlinedAt, bool ShouldCreate);
|
Metadata *InlinedAt, StorageType Storage,
|
||||||
|
bool ShouldCreate = true);
|
||||||
|
|
||||||
// Disallow replacing operands.
|
// Disallow replacing operands.
|
||||||
void replaceOperandWith(unsigned I, Metadata *New) LLVM_DELETED_FUNCTION;
|
void replaceOperandWith(unsigned I, Metadata *New) LLVM_DELETED_FUNCTION;
|
||||||
@ -925,18 +927,19 @@ class MDLocation : public UniquableMDNode {
|
|||||||
public:
|
public:
|
||||||
static MDLocation *get(LLVMContext &Context, unsigned Line, unsigned Column,
|
static MDLocation *get(LLVMContext &Context, unsigned Line, unsigned Column,
|
||||||
Metadata *Scope, Metadata *InlinedAt = nullptr) {
|
Metadata *Scope, Metadata *InlinedAt = nullptr) {
|
||||||
return getImpl(Context, Line, Column, Scope, InlinedAt,
|
return getImpl(Context, Line, Column, Scope, InlinedAt, Uniqued);
|
||||||
/* ShouldCreate */ true);
|
|
||||||
}
|
}
|
||||||
static MDLocation *getIfExists(LLVMContext &Context, unsigned Line,
|
static MDLocation *getIfExists(LLVMContext &Context, unsigned Line,
|
||||||
unsigned Column, Metadata *Scope,
|
unsigned Column, Metadata *Scope,
|
||||||
Metadata *InlinedAt = nullptr) {
|
Metadata *InlinedAt = nullptr) {
|
||||||
return getImpl(Context, Line, Column, Scope, InlinedAt,
|
return getImpl(Context, Line, Column, Scope, InlinedAt, Uniqued,
|
||||||
/* ShouldCreate */ false);
|
/* ShouldCreate */ false);
|
||||||
}
|
}
|
||||||
static MDLocation *getDistinct(LLVMContext &Context, unsigned Line,
|
static MDLocation *getDistinct(LLVMContext &Context, unsigned Line,
|
||||||
unsigned Column, Metadata *Scope,
|
unsigned Column, Metadata *Scope,
|
||||||
Metadata *InlinedAt = nullptr);
|
Metadata *InlinedAt = nullptr) {
|
||||||
|
return getImpl(Context, Line, Column, Scope, InlinedAt, Distinct);
|
||||||
|
}
|
||||||
|
|
||||||
unsigned getLine() const { return MDNodeSubclassData; }
|
unsigned getLine() const { return MDNodeSubclassData; }
|
||||||
unsigned getColumn() const { return SubclassData16; }
|
unsigned getColumn() const { return SubclassData16; }
|
||||||
|
@ -605,26 +605,35 @@ void UniquableMDNode::eraseFromStore() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MDTuple *MDTuple::getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
|
MDTuple *MDTuple::getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
|
||||||
bool ShouldCreate) {
|
StorageType Storage, bool ShouldCreate) {
|
||||||
MDTupleInfo::KeyTy Key(MDs);
|
unsigned Hash = 0;
|
||||||
|
if (Storage == Uniqued) {
|
||||||
|
MDTupleInfo::KeyTy Key(MDs);
|
||||||
|
Hash = Key.Hash;
|
||||||
|
|
||||||
auto &Store = Context.pImpl->MDTuples;
|
auto &Store = Context.pImpl->MDTuples;
|
||||||
auto I = Store.find_as(Key);
|
auto I = Store.find_as(Key);
|
||||||
if (I != Store.end())
|
if (I != Store.end())
|
||||||
return *I;
|
return *I;
|
||||||
if (!ShouldCreate)
|
if (!ShouldCreate)
|
||||||
return nullptr;
|
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, Storage, Hash, MDs);
|
||||||
auto *N = new (MDs.size()) MDTuple(Context, Uniqued, MDs);
|
|
||||||
N->setHash(Key.Hash);
|
switch (Storage) {
|
||||||
Store.insert(N);
|
case Uniqued:
|
||||||
return N;
|
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;
|
return N;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -657,17 +666,6 @@ MDLocation::MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
|
|||||||
SubclassData16 = Column;
|
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) {
|
static void adjustLine(unsigned &Line) {
|
||||||
// Set to unknown on overflow. Still use 24 bits for now.
|
// Set to unknown on overflow. Still use 24 bits for now.
|
||||||
if (Line >= (1u << 24))
|
if (Line >= (1u << 24))
|
||||||
@ -682,34 +680,42 @@ static void adjustColumn(unsigned &Column) {
|
|||||||
|
|
||||||
MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line,
|
MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line,
|
||||||
unsigned Column, Metadata *Scope,
|
unsigned Column, Metadata *Scope,
|
||||||
Metadata *InlinedAt, bool ShouldCreate) {
|
Metadata *InlinedAt, StorageType Storage,
|
||||||
|
bool ShouldCreate) {
|
||||||
// Fixup line/column.
|
// Fixup line/column.
|
||||||
adjustLine(Line);
|
adjustLine(Line);
|
||||||
adjustColumn(Column);
|
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 &Store = Context.pImpl->MDLocations;
|
||||||
auto I = Store.find_as(Key);
|
auto I = Store.find_as(Key);
|
||||||
if (I != Store.end())
|
if (I != Store.end())
|
||||||
return *I;
|
return *I;
|
||||||
if (!ShouldCreate)
|
if (!ShouldCreate)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
} else {
|
||||||
|
assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
|
||||||
|
}
|
||||||
|
|
||||||
auto *N = constructHelper(Context, Uniqued, Line, Column, Scope, InlinedAt);
|
SmallVector<Metadata *, 2> Ops;
|
||||||
Store.insert(N);
|
Ops.push_back(Scope);
|
||||||
return N;
|
if (InlinedAt)
|
||||||
}
|
Ops.push_back(InlinedAt);
|
||||||
|
auto *N = new (Ops.size()) MDLocation(Context, Storage, Line, Column, Ops);
|
||||||
|
|
||||||
MDLocation *MDLocation::getDistinct(LLVMContext &Context, unsigned Line,
|
switch (Storage) {
|
||||||
unsigned Column, Metadata *Scope,
|
case Uniqued:
|
||||||
Metadata *InlinedAt) {
|
Context.pImpl->MDLocations.insert(N);
|
||||||
// Fixup line/column.
|
break;
|
||||||
adjustLine(Line);
|
case Distinct:
|
||||||
adjustColumn(Column);
|
N->storeDistinctInContext();
|
||||||
|
break;
|
||||||
|
case Temporary:
|
||||||
|
llvm_unreachable("Unexpected temporary node");
|
||||||
|
}
|
||||||
|
|
||||||
auto *N = constructHelper(Context, Distinct, Line, Column, Scope, InlinedAt);
|
|
||||||
N->storeDistinctInContext();
|
|
||||||
return N;
|
return N;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user