mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 03:33:20 +01:00
Incorporate various suggestions Chris gave during metadata review.
- i < getNumElements() instead of getNumElements() > i - Make setParent() private - Fix use of resizeOperands - Reset HasMetadata bit after removing all metadata attached to an instruction - Efficient use of iterators llvm-svn: 84765
This commit is contained in:
parent
9e78b53be3
commit
7137e5f065
@ -145,7 +145,7 @@ public:
|
|||||||
|
|
||||||
/// getElement - Return specified element.
|
/// getElement - Return specified element.
|
||||||
Value *getElement(unsigned i) const {
|
Value *getElement(unsigned i) const {
|
||||||
assert(getNumElements() > i && "Invalid element number!");
|
assert(i < getNumElements() && "Invalid element number!");
|
||||||
return Node[i];
|
return Node[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,6 +211,7 @@ class NamedMDNode : public MetadataBase, public ilist_node<NamedMDNode> {
|
|||||||
SmallVector<WeakMetadataVH, 4> Node;
|
SmallVector<WeakMetadataVH, 4> Node;
|
||||||
typedef SmallVectorImpl<WeakMetadataVH>::iterator elem_iterator;
|
typedef SmallVectorImpl<WeakMetadataVH>::iterator elem_iterator;
|
||||||
|
|
||||||
|
void setParent(Module *M) { Parent = M; }
|
||||||
protected:
|
protected:
|
||||||
explicit NamedMDNode(LLVMContext &C, const Twine &N, MetadataBase*const *Vals,
|
explicit NamedMDNode(LLVMContext &C, const Twine &N, MetadataBase*const *Vals,
|
||||||
unsigned NumVals, Module *M = 0);
|
unsigned NumVals, Module *M = 0);
|
||||||
@ -240,11 +241,10 @@ public:
|
|||||||
/// getParent - Get the module that holds this named metadata collection.
|
/// getParent - Get the module that holds this named metadata collection.
|
||||||
inline Module *getParent() { return Parent; }
|
inline Module *getParent() { return Parent; }
|
||||||
inline const Module *getParent() const { return Parent; }
|
inline const Module *getParent() const { return Parent; }
|
||||||
void setParent(Module *M) { Parent = M; }
|
|
||||||
|
|
||||||
/// getElement - Return specified element.
|
/// getElement - Return specified element.
|
||||||
MetadataBase *getElement(unsigned i) const {
|
MetadataBase *getElement(unsigned i) const {
|
||||||
assert(getNumElements() > i && "Invalid element number!");
|
assert(i < getNumElements() && "Invalid element number!");
|
||||||
return Node[i];
|
return Node[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +255,7 @@ public:
|
|||||||
|
|
||||||
/// addElement - Add metadata element.
|
/// addElement - Add metadata element.
|
||||||
void addElement(MetadataBase *M) {
|
void addElement(MetadataBase *M) {
|
||||||
resizeOperands(0);
|
resizeOperands(NumOperands + 1);
|
||||||
OperandList[NumOperands++] = M;
|
OperandList[NumOperands++] = M;
|
||||||
Node.push_back(WeakMetadataVH(M));
|
Node.push_back(WeakMetadataVH(M));
|
||||||
}
|
}
|
||||||
@ -319,8 +319,8 @@ public:
|
|||||||
/// removeMD - Remove metadata of given kind attached with an instuction.
|
/// removeMD - Remove metadata of given kind attached with an instuction.
|
||||||
void removeMD(unsigned Kind, Instruction *Inst);
|
void removeMD(unsigned Kind, Instruction *Inst);
|
||||||
|
|
||||||
/// removeMDs - Remove all metadata attached with an instruction.
|
/// removeAllMetadata - Remove all metadata attached with an instruction.
|
||||||
void removeMDs(const Instruction *Inst);
|
void removeAllMetadata(Instruction *Inst);
|
||||||
|
|
||||||
/// copyMD - If metadata is attached with Instruction In1 then attach
|
/// copyMD - If metadata is attached with Instruction In1 then attach
|
||||||
/// the same metadata to In2.
|
/// the same metadata to In2.
|
||||||
@ -333,8 +333,8 @@ public:
|
|||||||
/// ValueIsDeleted - This handler is used to update metadata store
|
/// ValueIsDeleted - This handler is used to update metadata store
|
||||||
/// when a value is deleted.
|
/// when a value is deleted.
|
||||||
void ValueIsDeleted(const Value *) {}
|
void ValueIsDeleted(const Value *) {}
|
||||||
void ValueIsDeleted(const Instruction *Inst) {
|
void ValueIsDeleted(Instruction *Inst) {
|
||||||
removeMDs(Inst);
|
removeAllMetadata(Inst);
|
||||||
}
|
}
|
||||||
void ValueIsRAUWd(Value *V1, Value *V2);
|
void ValueIsRAUWd(Value *V1, Value *V2);
|
||||||
|
|
||||||
|
@ -250,10 +250,8 @@ NamedMDNode::~NamedMDNode() {
|
|||||||
unsigned MetadataContext::registerMDKind(const char *Name) {
|
unsigned MetadataContext::registerMDKind(const char *Name) {
|
||||||
assert(isValidName(Name) && "Invalid custome metadata name!");
|
assert(isValidName(Name) && "Invalid custome metadata name!");
|
||||||
unsigned Count = MDHandlerNames.size();
|
unsigned Count = MDHandlerNames.size();
|
||||||
assert(MDHandlerNames.find(Name) == MDHandlerNames.end()
|
assert(MDHandlerNames.count(Name) == 0 && "Already registered MDKind!");
|
||||||
&& "Already registered MDKind!");
|
return MDHandlerNames[Name] = Count + 1;
|
||||||
MDHandlerNames[Name] = Count + 1;
|
|
||||||
return Count + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// isValidName - Return true if Name is a valid custom metadata handler name.
|
/// isValidName - Return true if Name is a valid custom metadata handler name.
|
||||||
@ -280,10 +278,11 @@ bool MetadataContext::isValidName(const char *Name) {
|
|||||||
/// getMDKind - Return metadata kind. If the requested metadata kind
|
/// getMDKind - Return metadata kind. If the requested metadata kind
|
||||||
/// is not registered then return 0.
|
/// is not registered then return 0.
|
||||||
unsigned MetadataContext::getMDKind(const char *Name) {
|
unsigned MetadataContext::getMDKind(const char *Name) {
|
||||||
assert(isValidName(Name) && "Invalid custome metadata name!");
|
|
||||||
StringMap<unsigned>::iterator I = MDHandlerNames.find(Name);
|
StringMap<unsigned>::iterator I = MDHandlerNames.find(Name);
|
||||||
if (I == MDHandlerNames.end())
|
if (I == MDHandlerNames.end()) {
|
||||||
|
assert(isValidName(Name) && "Invalid custome metadata name!");
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return I->getValue();
|
return I->getValue();
|
||||||
}
|
}
|
||||||
@ -292,15 +291,13 @@ unsigned MetadataContext::getMDKind(const char *Name) {
|
|||||||
void MetadataContext::addMD(unsigned MDKind, MDNode *Node, Instruction *Inst) {
|
void MetadataContext::addMD(unsigned MDKind, MDNode *Node, Instruction *Inst) {
|
||||||
assert(Node && "Invalid null MDNode");
|
assert(Node && "Invalid null MDNode");
|
||||||
Inst->HasMetadata = true;
|
Inst->HasMetadata = true;
|
||||||
MDStoreTy::iterator I = MetadataStore.find(Inst);
|
MDMapTy &Info = MetadataStore[Inst];
|
||||||
if (I == MetadataStore.end()) {
|
if (Info.empty()) {
|
||||||
MDMapTy Info;
|
|
||||||
Info.push_back(std::make_pair(MDKind, Node));
|
Info.push_back(std::make_pair(MDKind, Node));
|
||||||
MetadataStore.insert(std::make_pair(Inst, Info));
|
MetadataStore.insert(std::make_pair(Inst, Info));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MDMapTy &Info = I->second;
|
|
||||||
// If there is an entry for this MDKind then replace it.
|
// If there is an entry for this MDKind then replace it.
|
||||||
for (unsigned i = 0, e = Info.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Info.size(); i != e; ++i) {
|
||||||
MDPairTy &P = Info[i];
|
MDPairTy &P = Info[i];
|
||||||
@ -333,30 +330,20 @@ void MetadataContext::removeMD(unsigned Kind, Instruction *Inst) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// removeMDs - Remove all metadata attached with an instruction.
|
/// removeAllMetadata - Remove all metadata attached with an instruction.
|
||||||
void MetadataContext::removeMDs(const Instruction *Inst) {
|
void MetadataContext::removeAllMetadata(Instruction *Inst) {
|
||||||
// Find Metadata handles for this instruction.
|
MetadataStore.erase(Inst);
|
||||||
MDStoreTy::iterator I = MetadataStore.find(Inst);
|
Inst->HasMetadata = false;
|
||||||
assert(I != MetadataStore.end() && "Invalid custom metadata info!");
|
|
||||||
MDMapTy &Info = I->second;
|
|
||||||
|
|
||||||
// FIXME : Give all metadata handlers a chance to adjust.
|
|
||||||
|
|
||||||
// Remove the entries for this instruction.
|
|
||||||
Info.clear();
|
|
||||||
MetadataStore.erase(I);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// copyMD - If metadata is attached with Instruction In1 then attach
|
/// copyMD - If metadata is attached with Instruction In1 then attach
|
||||||
/// the same metadata to In2.
|
/// the same metadata to In2.
|
||||||
void MetadataContext::copyMD(Instruction *In1, Instruction *In2) {
|
void MetadataContext::copyMD(Instruction *In1, Instruction *In2) {
|
||||||
assert(In1 && In2 && "Invalid instruction!");
|
assert(In1 && In2 && "Invalid instruction!");
|
||||||
MDStoreTy::iterator I = MetadataStore.find(In1);
|
MDMapTy &In1Info = MetadataStore[In1];
|
||||||
if (I == MetadataStore.end())
|
if (In1Info.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MDMapTy &In1Info = I->second;
|
|
||||||
MDMapTy In2Info;
|
|
||||||
for (MDMapTy::iterator I = In1Info.begin(), E = In1Info.end(); I != E; ++I)
|
for (MDMapTy::iterator I = In1Info.begin(), E = In1Info.end(); I != E; ++I)
|
||||||
if (MDNode *MD = dyn_cast_or_null<MDNode>(I->second))
|
if (MDNode *MD = dyn_cast_or_null<MDNode>(I->second))
|
||||||
addMD(I->first, MD, In2);
|
addMD(I->first, MD, In2);
|
||||||
@ -365,11 +352,10 @@ void MetadataContext::copyMD(Instruction *In1, Instruction *In2) {
|
|||||||
/// getMD - Get the metadata of given kind attached to an Instruction.
|
/// getMD - Get the metadata of given kind attached to an Instruction.
|
||||||
/// If the metadata is not found then return 0.
|
/// If the metadata is not found then return 0.
|
||||||
MDNode *MetadataContext::getMD(unsigned MDKind, const Instruction *Inst) {
|
MDNode *MetadataContext::getMD(unsigned MDKind, const Instruction *Inst) {
|
||||||
MDStoreTy::iterator I = MetadataStore.find(Inst);
|
MDMapTy &Info = MetadataStore[Inst];
|
||||||
if (I == MetadataStore.end())
|
if (Info.empty())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
MDMapTy &Info = I->second;
|
|
||||||
for (MDMapTy::iterator I = Info.begin(), E = Info.end(); I != E; ++I)
|
for (MDMapTy::iterator I = Info.begin(), E = Info.end(); I != E; ++I)
|
||||||
if (I->first == MDKind)
|
if (I->first == MDKind)
|
||||||
return dyn_cast_or_null<MDNode>(I->second);
|
return dyn_cast_or_null<MDNode>(I->second);
|
||||||
|
Loading…
Reference in New Issue
Block a user