summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-12-29 09:01:33 +0000
committerChris Lattner <sabre@nondot.org>2009-12-29 09:01:33 +0000
commit081134741b40b342fb2f85722c9cea5d412489a8 (patch)
tree73cd43fda7814ed745c3c31de92ff8c7bbf93721 /lib
parente3e38ea9fb70cbd8cc33111589c92c0a61674679 (diff)
downloadllvm-081134741b40b342fb2f85722c9cea5d412489a8.tar.gz
llvm-081134741b40b342fb2f85722c9cea5d412489a8.tar.bz2
llvm-081134741b40b342fb2f85722c9cea5d412489a8.tar.xz
Final step in the metadata API restructuring: move the
getMDKindID/getMDKindNames methods to LLVMContext (and add convenience methods to Module), eliminating MetadataContext. Move the state that it maintains out to LLVMContext. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92259 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Analysis/DebugInfo.cpp3
-rw-r--r--lib/AsmParser/LLParser.cpp5
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp3
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.h2
-rw-r--r--lib/Bitcode/Writer/BitcodeWriter.cpp5
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp6
-rw-r--r--lib/Transforms/IPO/StripSymbols.cpp6
-rw-r--r--lib/Transforms/Utils/CloneFunction.cpp3
-rw-r--r--lib/VMCore/AsmWriter.cpp3
-rw-r--r--lib/VMCore/IRBuilder.cpp3
-rw-r--r--lib/VMCore/LLVMContext.cpp5
-rw-r--r--lib/VMCore/LLVMContextImpl.h16
-rw-r--r--lib/VMCore/Metadata.cpp220
-rw-r--r--lib/VMCore/Module.cpp14
14 files changed, 112 insertions, 182 deletions
diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp
index 256a7d1c36..32554a6a78 100644
--- a/lib/Analysis/DebugInfo.cpp
+++ b/lib/Analysis/DebugInfo.cpp
@@ -18,7 +18,6 @@
#include "llvm/Intrinsics.h"
#include "llvm/IntrinsicInst.h"
#include "llvm/Instructions.h"
-#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/ADT/SmallPtrSet.h"
@@ -1117,7 +1116,7 @@ Instruction *DIFactory::InsertDbgValueIntrinsic(Value *V, Value *Offset,
/// processModule - Process entire module and collect debug info.
void DebugInfoFinder::processModule(Module &M) {
- unsigned MDDbgKind = M.getContext().getMetadata().getMDKindID("dbg");
+ unsigned MDDbgKind = M.getMDKindID("dbg");
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
for (Function::iterator FI = (*I).begin(), FE = (*I).end(); FI != FE; ++FI)
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
index d9d2a4b2ad..351245d8e8 100644
--- a/lib/AsmParser/LLParser.cpp
+++ b/lib/AsmParser/LLParser.cpp
@@ -18,8 +18,6 @@
#include "llvm/DerivedTypes.h"
#include "llvm/InlineAsm.h"
#include "llvm/Instructions.h"
-#include "llvm/LLVMContext.h"
-#include "llvm/Metadata.h"
#include "llvm/Module.h"
#include "llvm/Operator.h"
#include "llvm/ValueSymbolTable.h"
@@ -1122,8 +1120,7 @@ bool LLParser::ParseOptionalCustomMetadata() {
MetadataBase *Node;
if (ParseMDNode(Node)) return true;
- MetadataContext &TheMetadata = M->getContext().getMetadata();
- unsigned MDK = TheMetadata.getMDKindID(Name.c_str());
+ unsigned MDK = M->getMDKindID(Name.c_str());
MDsOnInst.push_back(std::make_pair(MDK, cast<MDNode>(Node)));
return false;
}
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index 568968d927..7dffafa831 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -17,7 +17,6 @@
#include "llvm/DerivedTypes.h"
#include "llvm/InlineAsm.h"
#include "llvm/IntrinsicInst.h"
-#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Operator.h"
#include "llvm/AutoUpgrade.h"
@@ -840,7 +839,7 @@ bool BitcodeReader::ParseMetadata() {
for (unsigned i = 1; i != RecordLength; ++i)
Name[i-1] = Record[i];
- unsigned NewKind = Context.getMetadata().getMDKindID(Name.str());
+ unsigned NewKind = TheModule->getMDKindID(Name.str());
assert(Kind == NewKind &&
"FIXME: Unable to handle custom metadata mismatch!");(void)NewKind;
break;
diff --git a/lib/Bitcode/Reader/BitcodeReader.h b/lib/Bitcode/Reader/BitcodeReader.h
index 7b3a1ae893..bb3961a086 100644
--- a/lib/Bitcode/Reader/BitcodeReader.h
+++ b/lib/Bitcode/Reader/BitcodeReader.h
@@ -170,7 +170,7 @@ class BitcodeReader : public ModuleProvider {
DenseMap<Function*, std::vector<BlockAddrRefTy> > BlockAddrFwdRefs;
public:
- explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext& C)
+ explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C)
: Context(C), Buffer(buffer), ErrorString(0), ValueList(C), MDValueList(C) {
HasReversedFunctionsWithBodies = false;
}
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp
index 21548cd18d..8454e54f65 100644
--- a/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -19,8 +19,6 @@
#include "llvm/DerivedTypes.h"
#include "llvm/InlineAsm.h"
#include "llvm/Instructions.h"
-#include "llvm/LLVMContext.h"
-#include "llvm/Metadata.h"
#include "llvm/Module.h"
#include "llvm/Operator.h"
#include "llvm/TypeSymbolTable.h"
@@ -595,9 +593,8 @@ static void WriteModuleMetadataStore(const Module *M, BitstreamWriter &Stream) {
// Write metadata kinds
// METADATA_KIND - [n x [id, name]]
- MetadataContext &TheMetadata = M->getContext().getMetadata();
SmallVector<StringRef, 4> Names;
- TheMetadata.getMDKindNames(Names);
+ M->getMDKindNames(Names);
assert(Names[0] == "" && "MDKind #0 is invalid");
if (Names.size() == 1) return;
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index a46aad7e48..05669c0ec9 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -395,8 +395,7 @@ void SelectionDAGISel::SelectBasicBlock(BasicBlock *LLVMBB,
BasicBlock::iterator End,
bool &HadTailCall) {
SDB->setCurrentBasicBlock(BB);
- MetadataContext &TheMetadata =LLVMBB->getParent()->getContext().getMetadata();
- unsigned MDDbgKind = TheMetadata.getMDKindID("dbg");
+ unsigned MDDbgKind = LLVMBB->getContext().getMDKindID("dbg");
// Lower all of the non-terminator instructions. If a call is emitted
// as a tail call, cease emitting nodes for this block.
@@ -676,8 +675,7 @@ void SelectionDAGISel::SelectAllBasicBlocks(Function &Fn,
#endif
);
- MetadataContext &TheMetadata = Fn.getContext().getMetadata();
- unsigned MDDbgKind = TheMetadata.getMDKindID("dbg");
+ unsigned MDDbgKind = Fn.getContext().getMDKindID("dbg");
// Iterate over all basic blocks in the function.
for (Function::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) {
diff --git a/lib/Transforms/IPO/StripSymbols.cpp b/lib/Transforms/IPO/StripSymbols.cpp
index 0d756267cf..ae88d9ecd0 100644
--- a/lib/Transforms/IPO/StripSymbols.cpp
+++ b/lib/Transforms/IPO/StripSymbols.cpp
@@ -24,7 +24,6 @@
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Instructions.h"
-#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Pass.h"
#include "llvm/Analysis/DebugInfo.h"
@@ -220,9 +219,8 @@ static bool StripDebugInfo(Module &M) {
Changed = true;
NMD->eraseFromParent();
}
- MetadataContext &TheMetadata = M.getContext().getMetadata();
- unsigned MDDbgKind = TheMetadata.getMDKindID("dbg");
-
+
+ unsigned MDDbgKind = M.getMDKindID("dbg");
for (Module::iterator MI = M.begin(), ME = M.end(); MI != ME; ++MI)
for (Function::iterator FI = MI->begin(), FE = MI->end(); FI != FE;
++FI)
diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp
index 09af8ae925..038e7ba08a 100644
--- a/lib/Transforms/Utils/CloneFunction.cpp
+++ b/lib/Transforms/Utils/CloneFunction.cpp
@@ -420,8 +420,7 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
//
BasicBlock::iterator I = NewBB->begin();
- // FIXME: Only use of context.
- unsigned DbgKind = OldFunc->getContext().getMetadata().getMDKindID("dbg");
+ unsigned DbgKind = OldFunc->getContext().getMDKindID("dbg");
MDNode *TheCallMD = NULL;
SmallVector<Value *, 4> MDVs;
if (TheCall && TheCall->hasMetadata())
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index e82b3d9562..a95a5498c1 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -22,7 +22,6 @@
#include "llvm/DerivedTypes.h"
#include "llvm/InlineAsm.h"
#include "llvm/IntrinsicInst.h"
-#include "llvm/LLVMContext.h"
#include "llvm/Operator.h"
#include "llvm/Module.h"
#include "llvm/ValueSymbolTable.h"
@@ -1338,7 +1337,7 @@ public:
AddModuleTypesToPrinter(TypePrinter, NumberedTypes, M);
// FIXME: Provide MDPrinter
if (M)
- M->getContext().getMetadata().getMDKindNames(MDNames);
+ M->getMDKindNames(MDNames);
}
void write(const Module *M) { printModule(M); }
diff --git a/lib/VMCore/IRBuilder.cpp b/lib/VMCore/IRBuilder.cpp
index 4c0299c6fc..699bf0f653 100644
--- a/lib/VMCore/IRBuilder.cpp
+++ b/lib/VMCore/IRBuilder.cpp
@@ -15,7 +15,6 @@
#include "llvm/Support/IRBuilder.h"
#include "llvm/GlobalVariable.h"
#include "llvm/Function.h"
-#include "llvm/Metadata.h"
#include "llvm/LLVMContext.h"
using namespace llvm;
@@ -37,7 +36,7 @@ Value *IRBuilderBase::CreateGlobalString(const char *Str, const Twine &Name) {
/// information.
void IRBuilderBase::SetCurrentDebugLocation(MDNode *L) {
if (DbgMDKind == 0)
- DbgMDKind = Context.getMetadata().getMDKindID("dbg");
+ DbgMDKind = Context.getMDKindID("dbg");
CurDbgLocation = L;
}
diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp
index 3e326050fc..5a8ea5cf6d 100644
--- a/lib/VMCore/LLVMContext.cpp
+++ b/lib/VMCore/LLVMContext.cpp
@@ -17,9 +17,7 @@
#include "llvm/Constants.h"
#include "llvm/Instruction.h"
#include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/ValueHandle.h"
#include "LLVMContextImpl.h"
-
using namespace llvm;
static ManagedStatic<LLVMContext> GlobalContext;
@@ -44,6 +42,3 @@ GetElementPtrConstantExpr::GetElementPtrConstantExpr
OperandList[i+1] = IdxList[i];
}
-MetadataContext &LLVMContext::getMetadata() {
- return pImpl->TheMetadata;
-}
diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h
index 2ea2d5e910..ccca789209 100644
--- a/lib/VMCore/LLVMContextImpl.h
+++ b/lib/VMCore/LLVMContextImpl.h
@@ -23,6 +23,7 @@
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Assembly/Writer.h"
+#include "llvm/Support/ValueHandle.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/DenseMap.h"
@@ -171,7 +172,17 @@ public:
typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy;
ValueHandlesTy ValueHandles;
- MetadataContext TheMetadata;
+ /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
+ StringMap<unsigned> CustomMDKindNames;
+
+ typedef std::pair<unsigned, TrackingVH<MDNode> > MDPairTy;
+ typedef SmallVector<MDPairTy, 2> MDMapTy;
+
+ /// MetadataStore - Collection of per-instruction metadata used in this
+ /// context.
+ DenseMap<const Instruction *, MDMapTy> MetadataStore;
+
+
LLVMContextImpl(LLVMContext &C) : TheTrueVal(0), TheFalseVal(0),
VoidTy(C, Type::VoidTyID),
LabelTy(C, Type::LabelTyID),
@@ -187,8 +198,7 @@ public:
Int32Ty(C, 32),
Int64Ty(C, 64) { }
- ~LLVMContextImpl()
- {
+ ~LLVMContextImpl() {
ExprConstants.freeConstants();
ArrayConstants.freeConstants();
StructConstants.freeConstants();
diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp
index 216d8a20af..d5c1dba2d7 100644
--- a/lib/VMCore/Metadata.cpp
+++ b/lib/VMCore/Metadata.cpp
@@ -243,131 +243,103 @@ void NamedMDNode::dropAllReferences() {
//===----------------------------------------------------------------------===//
-// MetadataContextImpl implementation.
+// MetadataContext implementation.
//
-namespace llvm {
-class MetadataContextImpl {
-public:
- typedef std::pair<unsigned, TrackingVH<MDNode> > MDPairTy;
- typedef SmallVector<MDPairTy, 2> MDMapTy;
- typedef DenseMap<const Instruction *, MDMapTy> MDStoreTy;
- friend class BitcodeReader;
-private:
-
- /// MetadataStore - Collection of metadata used in this context.
- MDStoreTy MetadataStore;
- /// MDHandlerNames - Map to hold metadata handler names.
- StringMap<unsigned> MDHandlerNames;
-
-public:
- // Name <-> ID mapping methods.
- unsigned getMDKindID(StringRef Name);
- void getMDKindNames(SmallVectorImpl<StringRef> &) const;
-
-
- // Instruction metadata methods.
- MDNode *getMetadata(const Instruction *Inst, unsigned Kind);
- void getAllMetadata(const Instruction *Inst,
- SmallVectorImpl<std::pair<unsigned, MDNode*> > &MDs)const;
+#ifndef NDEBUG
+/// isValidName - Return true if Name is a valid custom metadata handler name.
+static bool isValidName(StringRef MDName) {
+ if (MDName.empty())
+ return false;
- void setMetadata(Instruction *Inst, unsigned Kind, MDNode *Node);
+ if (!isalpha(MDName[0]))
+ return false;
- /// removeAllMetadata - Remove all metadata attached to an instruction.
- void removeAllMetadata(Instruction *Inst);
-};
+ for (StringRef::iterator I = MDName.begin() + 1, E = MDName.end(); I != E;
+ ++I) {
+ if (!isalnum(*I) && *I != '_' && *I != '-' && *I != '.')
+ return false;
+ }
+ return true;
}
+#endif
/// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
-unsigned MetadataContextImpl::getMDKindID(StringRef Name) {
- unsigned &Entry = MDHandlerNames[Name];
-
+unsigned LLVMContext::getMDKindID(StringRef Name) const {
+ assert(isValidName(Name) && "Invalid MDNode name");
+
+ unsigned &Entry = pImpl->CustomMDKindNames[Name];
+
// If this is new, assign it its ID.
- if (Entry == 0) Entry = MDHandlerNames.size();
+ if (Entry == 0) Entry = pImpl->CustomMDKindNames.size();
return Entry;
}
/// getHandlerNames - Populate client supplied smallvector using custome
/// metadata name and ID.
-void MetadataContextImpl::
-getMDKindNames(SmallVectorImpl<StringRef> &Names) const {
- Names.resize(MDHandlerNames.size()+1);
+void LLVMContext::getMDKindNames(SmallVectorImpl<StringRef> &Names) const {
+ Names.resize(pImpl->CustomMDKindNames.size()+1);
Names[0] = "";
- for (StringMap<unsigned>::const_iterator I = MDHandlerNames.begin(),
- E = MDHandlerNames.end(); I != E; ++I)
+ for (StringMap<unsigned>::const_iterator I = pImpl->CustomMDKindNames.begin(),
+ E = pImpl->CustomMDKindNames.end(); I != E; ++I)
// MD Handlers are numbered from 1.
Names[I->second] = I->first();
}
+//===----------------------------------------------------------------------===//
+// Instruction Metadata method implementations.
+//
-/// getMetadata - Get the metadata of given kind attached to an Instruction.
-/// If the metadata is not found then return 0.
-MDNode *MetadataContextImpl::
-getMetadata(const Instruction *Inst, unsigned MDKind) {
- MDMapTy &Info = MetadataStore[Inst];
- assert(Inst->hasMetadata() && !Info.empty() && "Shouldn't have called this");
-
- for (MDMapTy::iterator I = Info.begin(), E = Info.end(); I != E; ++I)
- if (I->first == MDKind)
- return I->second;
- return 0;
+void Instruction::setMetadata(const char *Kind, MDNode *Node) {
+ if (Node == 0 && !hasMetadata()) return;
+ setMetadata(getContext().getMDKindID(Kind), Node);
}
-/// getAllMetadata - Get all of the metadata attached to an Instruction.
-void MetadataContextImpl::
-getAllMetadata(const Instruction *Inst,
- SmallVectorImpl<std::pair<unsigned, MDNode*> > &Result) const {
- assert(Inst->hasMetadata() && MetadataStore.find(Inst) != MetadataStore.end()
- && "Shouldn't have called this");
- const MDMapTy &Info = MetadataStore.find(Inst)->second;
- assert(!Info.empty() && "Shouldn't have called this");
-
- Result.clear();
- Result.append(Info.begin(), Info.end());
-
- // Sort the resulting array so it is stable.
- if (Result.size() > 1)
- array_pod_sort(Result.begin(), Result.end());
+MDNode *Instruction::getMetadataImpl(const char *Kind) const {
+ return getMetadataImpl(getContext().getMDKindID(Kind));
}
-
-void MetadataContextImpl::setMetadata(Instruction *Inst, unsigned Kind,
- MDNode *Node) {
+/// setMetadata - Set the metadata of of the specified kind to the specified
+/// node. This updates/replaces metadata if already present, or removes it if
+/// Node is null.
+void Instruction::setMetadata(unsigned KindID, MDNode *Node) {
+ if (Node == 0 && !hasMetadata()) return;
+
// Handle the case when we're adding/updating metadata on an instruction.
if (Node) {
- MDMapTy &Info = MetadataStore[Inst];
- assert(!Info.empty() == Inst->hasMetadata() && "HasMetadata bit is wonked");
+ LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
+ assert(!Info.empty() == hasMetadata() && "HasMetadata bit is wonked");
if (Info.empty()) {
- Inst->setHasMetadata(true);
+ setHasMetadata(true);
} else {
// Handle replacement of an existing value.
for (unsigned i = 0, e = Info.size(); i != e; ++i)
- if (Info[i].first == Kind) {
+ if (Info[i].first == KindID) {
Info[i].second = Node;
return;
}
}
// No replacement, just add it to the list.
- Info.push_back(std::make_pair(Kind, Node));
+ Info.push_back(std::make_pair(KindID, Node));
return;
}
// Otherwise, we're removing metadata from an instruction.
- assert(Inst->hasMetadata() && MetadataStore.count(Inst) &&
+ assert(hasMetadata() && getContext().pImpl->MetadataStore.count(this) &&
"HasMetadata bit out of date!");
- MDMapTy &Info = MetadataStore[Inst];
-
+ LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
+
// Common case is removing the only entry.
- if (Info.size() == 1 && Info[0].first == Kind) {
- MetadataStore.erase(Inst);
- Inst->setHasMetadata(false);
+ if (Info.size() == 1 && Info[0].first == KindID) {
+ getContext().pImpl->MetadataStore.erase(this);
+ setHasMetadata(false);
return;
}
// Handle replacement of an existing value.
for (unsigned i = 0, e = Info.size(); i != e; ++i)
- if (Info[i].first == Kind) {
+ if (Info[i].first == KindID) {
Info[i] = Info.back();
Info.pop_back();
assert(!Info.empty() && "Removing last entry should be handled above");
@@ -376,83 +348,37 @@ void MetadataContextImpl::setMetadata(Instruction *Inst, unsigned Kind,
// Otherwise, removing an entry that doesn't exist on the instruction.
}
-/// removeAllMetadata - Remove all metadata attached with an instruction.
-void MetadataContextImpl::removeAllMetadata(Instruction *Inst) {
- MetadataStore.erase(Inst);
- Inst->setHasMetadata(false);
-}
-
-
-//===----------------------------------------------------------------------===//
-// MetadataContext implementation.
-//
-MetadataContext::MetadataContext() : pImpl(new MetadataContextImpl()) { }
-MetadataContext::~MetadataContext() { delete pImpl; }
-
-#ifndef NDEBUG
-/// isValidName - Return true if Name is a valid custom metadata handler name.
-static bool isValidName(StringRef MDName) {
- if (MDName.empty())
- return false;
-
- if (!isalpha(MDName[0]))
- return false;
-
- for (StringRef::iterator I = MDName.begin() + 1, E = MDName.end(); I != E;
- ++I) {
- if (!isalnum(*I) && *I != '_' && *I != '-' && *I != '.')
- return false;
- }
- return true;
-}
-#endif
-
-/// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
-unsigned MetadataContext::getMDKindID(StringRef Name) const {
- assert(isValidName(Name) && "Invalid MDNode name");
- return pImpl->getMDKindID(Name);
-}
-
-/// getHandlerNames - Populate client supplied smallvector using custome
-/// metadata name and ID.
-void MetadataContext::getMDKindNames(SmallVectorImpl<StringRef> &N) const {
- pImpl->getMDKindNames(N);
-}
-
-//===----------------------------------------------------------------------===//
-// Instruction Metadata method implementations.
-//
-
-void Instruction::setMetadata(const char *Kind, MDNode *Node) {
- if (Node == 0 && !hasMetadata()) return;
- setMetadata(getContext().getMetadata().getMDKindID(Kind), Node);
-}
-
-MDNode *Instruction::getMetadataImpl(const char *Kind) const {
- return getMetadataImpl(getContext().getMetadata().getMDKindID(Kind));
-}
-
-/// setMetadata - Set the metadata of of the specified kind to the specified
-/// node. This updates/replaces metadata if already present, or removes it if
-/// Node is null.
-void Instruction::setMetadata(unsigned KindID, MDNode *Node) {
- if (Node == 0 && !hasMetadata()) return;
-
- getContext().getMetadata().pImpl->setMetadata(this, KindID, Node);
-}
-
MDNode *Instruction::getMetadataImpl(unsigned KindID) const {
- return getContext().getMetadata().pImpl->getMetadata(this, KindID);
+ LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
+ assert(hasMetadata() && !Info.empty() && "Shouldn't have called this");
+
+ for (LLVMContextImpl::MDMapTy::iterator I = Info.begin(), E = Info.end();
+ I != E; ++I)
+ if (I->first == KindID)
+ return I->second;
+ return 0;
}
void Instruction::getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned,
MDNode*> > &Result)const {
- getContext().getMetadata().pImpl->getAllMetadata(this, Result);
+ assert(hasMetadata() && getContext().pImpl->MetadataStore.count(this) &&
+ "Shouldn't have called this");
+ const LLVMContextImpl::MDMapTy &Info =
+ getContext().pImpl->MetadataStore.find(this)->second;
+ assert(!Info.empty() && "Shouldn't have called this");
+
+ Result.clear();
+ Result.append(Info.begin(), Info.end());
+
+ // Sort the resulting array so it is stable.
+ if (Result.size() > 1)
+ array_pod_sort(Result.begin(), Result.end());
}
/// removeAllMetadata - Remove all metadata from this instruction.
void Instruction::removeAllMetadata() {
assert(hasMetadata() && "Caller should check");
- getContext().getMetadata().pImpl->removeAllMetadata(this);
+ getContext().pImpl->MetadataStore.erase(this);
+ setHasMetadata(false);
}
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp
index ce281eb549..a7f503bacb 100644
--- a/lib/VMCore/Module.cpp
+++ b/lib/VMCore/Module.cpp
@@ -118,6 +118,20 @@ GlobalValue *Module::getNamedValue(StringRef Name) const {
return cast_or_null<GlobalValue>(getValueSymbolTable().lookup(Name));
}
+/// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
+/// This ID is uniqued across modules in the current LLVMContext.
+unsigned Module::getMDKindID(StringRef Name) const {
+ return Context.getMDKindID(Name);
+}
+
+/// getMDKindNames - Populate client supplied SmallVector with the name for
+/// custom metadata IDs registered in this LLVMContext. ID #0 is not used,
+/// so it is filled in as an empty string.
+void Module::getMDKindNames(SmallVectorImpl<StringRef> &Result) const {
+ return Context.getMDKindNames(Result);
+}
+
+
//===----------------------------------------------------------------------===//
// Methods for easy access to the functions in the module.
//