StringMapEntry<MDString *> &Entry =
pImpl->MDStringCache.GetOrCreateValue(Str);
MDString *&S = Entry.getValue();
- if (S) return S;
-
- return S =
- new MDString(Context, Entry.getKey());
+ if (!S) S = new MDString(Context, Entry.getKey());
+ return S;
+}
+
+MDString *MDString::get(LLVMContext &Context, const char *Str) {
+ LLVMContextImpl *pImpl = Context.pImpl;
+ StringMapEntry<MDString *> &Entry =
+ pImpl->MDStringCache.GetOrCreateValue(Str ? StringRef(Str) : StringRef());
+ MDString *&S = Entry.getValue();
+ if (!S) S = new MDString(Context, Entry.getKey());
+ return S;
}
//===----------------------------------------------------------------------===//
// MDNode implementation.
//
-MDNode::MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals)
+MDNode::MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals,
+ Function *LocalFunc)
: MetadataBase(Type::getMetadataTy(C), Value::MDNodeVal) {
NodeSize = NumVals;
Node = new ElementVH[NodeSize];
ElementVH *Ptr = Node;
for (unsigned i = 0; i != NumVals; ++i)
*Ptr++ = ElementVH(Vals[i], this);
+ LocalFunction = LocalFunc;
}
void MDNode::Profile(FoldingSetNodeID &ID) const {
ID.AddPointer(getElement(i));
}
-MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals) {
+MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals,
+ Function *LocalFunction) {
LLVMContextImpl *pImpl = Context.pImpl;
FoldingSetNodeID ID;
for (unsigned i = 0; i != NumVals; ++i)
ID.AddPointer(Vals[i]);
+ if (LocalFunction)
+ ID.AddPointer(LocalFunction);
void *InsertPoint;
- MDNode *N;
- {
- N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
- }
- if (N) return N;
-
- N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
+ MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
if (!N) {
// InsertPoint will have been set by the FindNodeOrInsertPos call.
- N = new MDNode(Context, Vals, NumVals);
+ N = new MDNode(Context, Vals, NumVals, LocalFunction);
pImpl->MDNodeSet.InsertNode(N, InsertPoint);
}
-
return N;
}
/// ~MDNode - Destroy MDNode.
MDNode::~MDNode() {
- {
- LLVMContextImpl *pImpl = getType()->getContext().pImpl;
- pImpl->MDNodeSet.RemoveNode(this);
- }
+ LLVMContextImpl *pImpl = getType()->getContext().pImpl;
+ pImpl->MDNodeSet.RemoveNode(this);
delete [] Node;
Node = NULL;
}
/// addMD - Attach the metadata of given kind to an Instruction.
void addMD(unsigned Kind, MDNode *Node, Instruction *Inst);
- /// removeMD - Remove metadata of given kind attached with an instuction.
+ /// removeMD - Remove metadata of given kind attached with an instruction.
void removeMD(unsigned Kind, Instruction *Inst);
/// removeAllMetadata - Remove all metadata attached with an instruction.
/// the same metadata to In2.
void copyMD(Instruction *In1, Instruction *In2);
- /// getHandlerNames - Populate client supplied smallvector using custome
+ /// getHandlerNames - Populate client-supplied smallvector using custom
/// metadata name and ID.
void getHandlerNames(SmallVectorImpl<std::pair<unsigned, StringRef> >&) const;
Info.push_back(std::make_pair(MDKind, Node));
}
-/// removeMD - Remove metadata of given kind attached with an instuction.
+/// removeMD - Remove metadata of given kind attached with an instruction.
void MetadataContextImpl::removeMD(unsigned Kind, Instruction *Inst) {
MDStoreTy::iterator I = MetadataStore.find(Inst);
if (I == MetadataStore.end())
}
}
}
-
+
/// removeAllMetadata - Remove all metadata attached with an instruction.
void MetadataContextImpl::removeAllMetadata(Instruction *Inst) {
MetadataStore.erase(Inst);
void MetadataContext::addMD(unsigned Kind, MDNode *Node, Instruction *Inst) {
pImpl->addMD(Kind, Node, Inst);
}
-
-/// removeMD - Remove metadata of given kind attached with an instuction.
+
+/// removeMD - Remove metadata of given kind attached with an instruction.
void MetadataContext::removeMD(unsigned Kind, Instruction *Inst) {
pImpl->removeMD(Kind, Inst);
}
-
+
/// removeAllMetadata - Remove all metadata attached with an instruction.
void MetadataContext::removeAllMetadata(Instruction *Inst) {
pImpl->removeAllMetadata(Inst);