mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-13 19:24:21 +00:00
IR: Clarify ownership of ConstantDataSequentials, NFC
Change `ConstantDataSequential::Next` to a `unique_ptr<ConstantDataSequential>` and update `CDSConstants` to a `StringMap<unique_ptr<ConstantDataSequential>>`, making the ownership more obvious. Differential Revision: https://reviews.llvm.org/D90083
This commit is contained in:
parent
db4863ffd1
commit
b2b7cf39d5
@ -592,14 +592,13 @@ class ConstantDataSequential : public ConstantData {
|
|||||||
/// the same value but different type. For example, 0,0,0,1 could be a 4
|
/// the same value but different type. For example, 0,0,0,1 could be a 4
|
||||||
/// element array of i8, or a 1-element array of i32. They'll both end up in
|
/// element array of i8, or a 1-element array of i32. They'll both end up in
|
||||||
/// the same StringMap bucket, linked up.
|
/// the same StringMap bucket, linked up.
|
||||||
ConstantDataSequential *Next;
|
std::unique_ptr<ConstantDataSequential> Next;
|
||||||
|
|
||||||
void destroyConstantImpl();
|
void destroyConstantImpl();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit ConstantDataSequential(Type *ty, ValueTy VT, const char *Data)
|
explicit ConstantDataSequential(Type *ty, ValueTy VT, const char *Data)
|
||||||
: ConstantData(ty, VT), DataElements(Data), Next(nullptr) {}
|
: ConstantData(ty, VT), DataElements(Data) {}
|
||||||
~ConstantDataSequential() { delete Next; }
|
|
||||||
|
|
||||||
static Constant *getImpl(StringRef Bytes, Type *Ty);
|
static Constant *getImpl(StringRef Bytes, Type *Ty);
|
||||||
|
|
||||||
|
@ -2783,56 +2783,55 @@ Constant *ConstantDataSequential::getImpl(StringRef Elements, Type *Ty) {
|
|||||||
// body but different types. For example, 0,0,0,1 could be a 4 element array
|
// body but different types. For example, 0,0,0,1 could be a 4 element array
|
||||||
// of i8, or a 1-element array of i32. They'll both end up in the same
|
// of i8, or a 1-element array of i32. They'll both end up in the same
|
||||||
/// StringMap bucket, linked up by their Next pointers. Walk the list.
|
/// StringMap bucket, linked up by their Next pointers. Walk the list.
|
||||||
ConstantDataSequential **Entry = &Slot.second;
|
std::unique_ptr<ConstantDataSequential> *Entry = &Slot.second;
|
||||||
for (ConstantDataSequential *Node = *Entry; Node;
|
for (ConstantDataSequential *Node = Entry->get(); Node;
|
||||||
Entry = &Node->Next, Node = *Entry)
|
Entry = &Node->Next, Node = Entry->get())
|
||||||
if (Node->getType() == Ty)
|
if (Node->getType() == Ty)
|
||||||
return Node;
|
return Node;
|
||||||
|
|
||||||
// Okay, we didn't get a hit. Create a node of the right class, link it in,
|
// Okay, we didn't get a hit. Create a node of the right class, link it in,
|
||||||
// and return it.
|
// and return it.
|
||||||
if (isa<ArrayType>(Ty))
|
if (isa<ArrayType>(Ty)) {
|
||||||
return *Entry = new ConstantDataArray(Ty, Slot.first().data());
|
Entry->reset(new ConstantDataArray(Ty, Slot.first().data()));
|
||||||
|
return Entry->get();
|
||||||
|
}
|
||||||
|
|
||||||
assert(isa<VectorType>(Ty));
|
assert(isa<VectorType>(Ty));
|
||||||
return *Entry = new ConstantDataVector(Ty, Slot.first().data());
|
Entry->reset(new ConstantDataVector(Ty, Slot.first().data()));
|
||||||
|
return Entry->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConstantDataSequential::destroyConstantImpl() {
|
void ConstantDataSequential::destroyConstantImpl() {
|
||||||
// Remove the constant from the StringMap.
|
// Remove the constant from the StringMap.
|
||||||
StringMap<ConstantDataSequential*> &CDSConstants =
|
StringMap<std::unique_ptr<ConstantDataSequential>> &CDSConstants =
|
||||||
getType()->getContext().pImpl->CDSConstants;
|
getType()->getContext().pImpl->CDSConstants;
|
||||||
|
|
||||||
StringMap<ConstantDataSequential*>::iterator Slot =
|
auto Slot = CDSConstants.find(getRawDataValues());
|
||||||
CDSConstants.find(getRawDataValues());
|
|
||||||
|
|
||||||
assert(Slot != CDSConstants.end() && "CDS not found in uniquing table");
|
assert(Slot != CDSConstants.end() && "CDS not found in uniquing table");
|
||||||
|
|
||||||
ConstantDataSequential **Entry = &Slot->getValue();
|
std::unique_ptr<ConstantDataSequential> *Entry = &Slot->getValue();
|
||||||
|
|
||||||
// Remove the entry from the hash table.
|
// Remove the entry from the hash table.
|
||||||
if (!(*Entry)->Next) {
|
if (!(*Entry)->Next) {
|
||||||
// If there is only one value in the bucket (common case) it must be this
|
// If there is only one value in the bucket (common case) it must be this
|
||||||
// entry, and removing the entry should remove the bucket completely.
|
// entry, and removing the entry should remove the bucket completely.
|
||||||
assert((*Entry) == this && "Hash mismatch in ConstantDataSequential");
|
assert(Entry->get() == this && "Hash mismatch in ConstantDataSequential");
|
||||||
getContext().pImpl->CDSConstants.erase(Slot);
|
getContext().pImpl->CDSConstants.erase(Slot);
|
||||||
} else {
|
return;
|
||||||
// Otherwise, there are multiple entries linked off the bucket, unlink the
|
|
||||||
// node we care about but keep the bucket around.
|
|
||||||
for (ConstantDataSequential *Node = *Entry; ;
|
|
||||||
Entry = &Node->Next, Node = *Entry) {
|
|
||||||
assert(Node && "Didn't find entry in its uniquing hash table!");
|
|
||||||
// If we found our entry, unlink it from the list and we're done.
|
|
||||||
if (Node == this) {
|
|
||||||
*Entry = Node->Next;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we were part of a list, make sure that we don't delete the list that is
|
// Otherwise, there are multiple entries linked off the bucket, unlink the
|
||||||
// still owned by the uniquing map.
|
// node we care about but keep the bucket around.
|
||||||
Next = nullptr;
|
for (ConstantDataSequential *Node = Entry->get();;
|
||||||
|
Entry = &Node->Next, Node = Entry->get()) {
|
||||||
|
assert(Node && "Didn't find entry in its uniquing hash table!");
|
||||||
|
// If we found our entry, unlink it from the list and we're done.
|
||||||
|
if (Node == this) {
|
||||||
|
*Entry = std::move(Node->Next);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getFP() constructors - Return a constant of array type with a float
|
/// getFP() constructors - Return a constant of array type with a float
|
||||||
|
@ -99,9 +99,6 @@ LLVMContextImpl::~LLVMContextImpl() {
|
|||||||
UVConstants.clear();
|
UVConstants.clear();
|
||||||
IntConstants.clear();
|
IntConstants.clear();
|
||||||
FPConstants.clear();
|
FPConstants.clear();
|
||||||
|
|
||||||
for (auto &CDSConstant : CDSConstants)
|
|
||||||
delete CDSConstant.second;
|
|
||||||
CDSConstants.clear();
|
CDSConstants.clear();
|
||||||
|
|
||||||
// Destroy attribute node lists.
|
// Destroy attribute node lists.
|
||||||
|
@ -1346,7 +1346,7 @@ public:
|
|||||||
|
|
||||||
DenseMap<Type *, std::unique_ptr<UndefValue>> UVConstants;
|
DenseMap<Type *, std::unique_ptr<UndefValue>> UVConstants;
|
||||||
|
|
||||||
StringMap<ConstantDataSequential*> CDSConstants;
|
StringMap<std::unique_ptr<ConstantDataSequential>> CDSConstants;
|
||||||
|
|
||||||
DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
|
DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
|
||||||
BlockAddresses;
|
BlockAddresses;
|
||||||
|
Loading…
Reference in New Issue
Block a user