[llvm-commits] [llvm] r92259 - in /llvm/trunk: include/llvm/ lib/Analysis/ lib/AsmParser/ lib/Bitcode/Reader/ lib/Bitcode/Writer/ lib/CodeGen/SelectionDAG/ lib/Transforms/IPO/ lib/Transforms/Utils/ lib/VMCore/
Chris Lattner
sabre at nondot.org
Tue Dec 29 01:01:38 PST 2009
Author: lattner
Date: Tue Dec 29 03:01:33 2009
New Revision: 92259
URL: http://llvm.org/viewvc/llvm-project?rev=92259&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/Instruction.h
llvm/trunk/include/llvm/LLVMContext.h
llvm/trunk/include/llvm/Metadata.h
llvm/trunk/include/llvm/Module.h
llvm/trunk/include/llvm/Value.h
llvm/trunk/lib/Analysis/DebugInfo.cpp
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h
llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp
llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp
llvm/trunk/lib/VMCore/AsmWriter.cpp
llvm/trunk/lib/VMCore/IRBuilder.cpp
llvm/trunk/lib/VMCore/LLVMContext.cpp
llvm/trunk/lib/VMCore/LLVMContextImpl.h
llvm/trunk/lib/VMCore/Metadata.cpp
llvm/trunk/lib/VMCore/Module.cpp
Modified: llvm/trunk/include/llvm/Instruction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Instruction.h?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Instruction.h (original)
+++ llvm/trunk/include/llvm/Instruction.h Tue Dec 29 03:01:33 2009
@@ -22,7 +22,6 @@
class LLVMContext;
class MDNode;
-class MetadataContextImpl;
template<typename ValueSubClass, typename ItemParentClass>
class SymbolTableListTraits;
@@ -316,7 +315,6 @@
return Value::getSubclassDataFromValue();
}
- friend class MetadataContextImpl;
void setHasMetadata(bool V) {
setValueSubclassData((getSubclassDataFromValue() & ~HasMetadataBit) |
(V ? HasMetadataBit : 0));
Modified: llvm/trunk/include/llvm/LLVMContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LLVMContext.h?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LLVMContext.h (original)
+++ llvm/trunk/include/llvm/LLVMContext.h Tue Dec 29 03:01:33 2009
@@ -18,7 +18,8 @@
namespace llvm {
class LLVMContextImpl;
-class MetadataContext;
+class StringRef;
+template <typename T> class SmallVectorImpl;
/// This is an important class for using LLVM in a threaded context. It
/// (opaquely) owns and manages the core "global" data of LLVM's core
@@ -31,14 +32,23 @@
void operator=(LLVMContext&);
public:
- LLVMContextImpl* const pImpl;
- MetadataContext &getMetadata();
+ LLVMContextImpl *const pImpl;
LLVMContext();
~LLVMContext();
+
+ /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
+ /// This ID is uniqued across modules in the current LLVMContext.
+ unsigned getMDKindID(StringRef Name) const;
+
+ /// 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 getMDKindNames(SmallVectorImpl<StringRef> &Result) const;
};
-/// FOR BACKWARDS COMPATIBILITY - Returns a global context.
-extern LLVMContext& getGlobalContext();
+/// getGlobalContext - Returns a global context. This is for LLVM clients that
+/// only care about operating on a single thread.
+extern LLVMContext &getGlobalContext();
}
Modified: llvm/trunk/include/llvm/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Metadata.h?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Metadata.h (original)
+++ llvm/trunk/include/llvm/Metadata.h Tue Dec 29 03:01:33 2009
@@ -25,7 +25,6 @@
class Instruction;
class LLVMContext;
class Module;
-class MetadataContextImpl;
template <typename T> class SmallVectorImpl;
//===----------------------------------------------------------------------===//
@@ -204,28 +203,6 @@
}
};
-//===----------------------------------------------------------------------===//
-/// MetadataContext - MetadataContext handles uniquing and assignment of IDs for
-/// custom metadata types.
-///
-class MetadataContext {
- MetadataContext(MetadataContext&); // DO NOT IMPLEMENT
- void operator=(MetadataContext&); // DO NOT IMPLEMENT
-
- MetadataContextImpl *const pImpl;
- friend class Instruction;
-public:
- MetadataContext();
- ~MetadataContext();
-
- /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
- unsigned getMDKindID(StringRef Name) const;
-
- /// getMDKindNames - Populate client supplied SmallVector with the name for
- /// each custom metadata ID. ID #0 is not used, so it is filled in as empty.
- void getMDKindNames(SmallVectorImpl<StringRef> &) const;
-};
-
} // end llvm namespace
#endif
Modified: llvm/trunk/include/llvm/Module.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Module.h?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Module.h (original)
+++ llvm/trunk/include/llvm/Module.h Tue Dec 29 03:01:33 2009
@@ -184,7 +184,7 @@
/// Get the global data context.
/// @returns LLVMContext - a container for LLVM's global information
- LLVMContext& getContext() const { return Context; }
+ LLVMContext &getContext() const { return Context; }
/// Get any module-scope inline assembly blocks.
/// @returns a string containing the module-scope inline assembly blocks.
@@ -222,6 +222,15 @@
/// if a global with the specified name is not found.
GlobalValue *getNamedValue(StringRef Name) const;
+ /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
+ /// This ID is uniqued across modules in the current LLVMContext.
+ unsigned getMDKindID(StringRef Name) const;
+
+ /// 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 getMDKindNames(SmallVectorImpl<StringRef> &Result) const;
+
/// @}
/// @name Function Accessors
/// @{
Modified: llvm/trunk/include/llvm/Value.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Value.h?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Value.h (original)
+++ llvm/trunk/include/llvm/Value.h Tue Dec 29 03:01:33 2009
@@ -41,7 +41,6 @@
class AssemblyAnnotationWriter;
class ValueHandleBase;
class LLVMContext;
-class MetadataContextImpl;
class Twine;
//===----------------------------------------------------------------------===//
Modified: llvm/trunk/lib/Analysis/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DebugInfo.cpp?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/DebugInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/DebugInfo.cpp Tue Dec 29 03:01:33 2009
@@ -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 @@
/// 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)
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Tue Dec 29 03:01:33 2009
@@ -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 @@
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;
}
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Tue Dec 29 03:01:33 2009
@@ -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 @@
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;
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h Tue Dec 29 03:01:33 2009
@@ -170,7 +170,7 @@
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;
}
Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Tue Dec 29 03:01:33 2009
@@ -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 @@
// 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;
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Tue Dec 29 03:01:33 2009
@@ -395,8 +395,7 @@
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 @@
#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) {
Modified: llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp Tue Dec 29 03:01:33 2009
@@ -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 @@
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)
Modified: llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp Tue Dec 29 03:01:33 2009
@@ -420,8 +420,7 @@
//
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())
Modified: llvm/trunk/lib/VMCore/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AsmWriter.cpp?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/AsmWriter.cpp (original)
+++ llvm/trunk/lib/VMCore/AsmWriter.cpp Tue Dec 29 03:01:33 2009
@@ -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 @@
AddModuleTypesToPrinter(TypePrinter, NumberedTypes, M);
// FIXME: Provide MDPrinter
if (M)
- M->getContext().getMetadata().getMDKindNames(MDNames);
+ M->getMDKindNames(MDNames);
}
void write(const Module *M) { printModule(M); }
Modified: llvm/trunk/lib/VMCore/IRBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/IRBuilder.cpp?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/IRBuilder.cpp (original)
+++ llvm/trunk/lib/VMCore/IRBuilder.cpp Tue Dec 29 03:01:33 2009
@@ -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 @@
/// information.
void IRBuilderBase::SetCurrentDebugLocation(MDNode *L) {
if (DbgMDKind == 0)
- DbgMDKind = Context.getMetadata().getMDKindID("dbg");
+ DbgMDKind = Context.getMDKindID("dbg");
CurDbgLocation = L;
}
Modified: llvm/trunk/lib/VMCore/LLVMContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContext.cpp?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContext.cpp (original)
+++ llvm/trunk/lib/VMCore/LLVMContext.cpp Tue Dec 29 03:01:33 2009
@@ -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 @@
OperandList[i+1] = IdxList[i];
}
-MetadataContext &LLVMContext::getMetadata() {
- return pImpl->TheMetadata;
-}
Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.h?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.h (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.h Tue Dec 29 03:01:33 2009
@@ -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 @@
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 @@
Int32Ty(C, 32),
Int64Ty(C, 64) { }
- ~LLVMContextImpl()
- {
+ ~LLVMContextImpl() {
ExprConstants.freeConstants();
ArrayConstants.freeConstants();
StructConstants.freeConstants();
Modified: llvm/trunk/lib/VMCore/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Metadata.cpp?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Metadata.cpp (original)
+++ llvm/trunk/lib/VMCore/Metadata.cpp Tue Dec 29 03:01:33 2009
@@ -243,131 +243,103 @@
//===----------------------------------------------------------------------===//
-// 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;
-
- void setMetadata(Instruction *Inst, unsigned Kind, MDNode *Node);
-
- /// removeAllMetadata - Remove all metadata attached to an instruction.
- void removeAllMetadata(Instruction *Inst);
-};
+
+#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 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 @@
// 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);
}
Modified: llvm/trunk/lib/VMCore/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Module.cpp?rev=92259&r1=92258&r2=92259&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Module.cpp (original)
+++ llvm/trunk/lib/VMCore/Module.cpp Tue Dec 29 03:01:33 2009
@@ -118,6 +118,20 @@
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.
//
More information about the llvm-commits
mailing list