aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2009-09-16 18:09:00 +0000
committerDevang Patel <dpatel@apple.com>2009-09-16 18:09:00 +0000
commit4b1fad3ca2acec2db8d4c4545b8d5f74a2500b0f (patch)
treec3f48b5aa007a783cb08cae05de7bfd2bab735b8 /include
parent86776f75bfef82e33cbd7b9a63c1963b1dd1e7b8 (diff)
downloadexternal_llvm-4b1fad3ca2acec2db8d4c4545b8d5f74a2500b0f.zip
external_llvm-4b1fad3ca2acec2db8d4c4545b8d5f74a2500b0f.tar.gz
external_llvm-4b1fad3ca2acec2db8d4c4545b8d5f74a2500b0f.tar.bz2
Add llvm::Metadata to manage metadata used in a context.
This interface will be used to attach metadata with an instruction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82060 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/LLVMContext.h3
-rw-r--r--include/llvm/Metadata.h46
-rw-r--r--include/llvm/Value.h3
3 files changed, 51 insertions, 1 deletions
diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h
index 56a640e..5e8cd1a 100644
--- a/include/llvm/LLVMContext.h
+++ b/include/llvm/LLVMContext.h
@@ -18,7 +18,7 @@
namespace llvm {
class LLVMContextImpl;
-
+class Metadata;
/// 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
/// infrastructure, including the type and constant uniquing tables.
@@ -30,6 +30,7 @@ class LLVMContext {
void operator=(LLVMContext&);
public:
LLVMContextImpl* pImpl;
+ Metadata &getMetadata();
bool RemoveDeadMetadata();
LLVMContext();
~LLVMContext();
diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h
index 0844006..66a10a8 100644
--- a/include/llvm/Metadata.h
+++ b/include/llvm/Metadata.h
@@ -22,12 +22,16 @@
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/ilist_node.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ValueHandle.h"
namespace llvm {
class Constant;
+class Instruction;
class LLVMContext;
//===----------------------------------------------------------------------===//
@@ -300,6 +304,48 @@ public:
}
};
+//===----------------------------------------------------------------------===//
+/// Metadata -
+/// Metadata manages metadata used in a context.
+
+/// MDKindID - This id identifies metadata kind the metadata store. Valid
+/// ID values are 1 or higher. This ID is set by RegisterMDKind.
+typedef unsigned MDKindID;
+class Metadata {
+private:
+ typedef std::pair<MDKindID, WeakVH> MDPairTy;
+ typedef SmallVector<MDPairTy, 2> MDMapTy;
+ typedef DenseMap<const Instruction *, MDMapTy> MDStoreTy;
+
+ /// MetadataStore - Collection of metadata used in this context.
+ MDStoreTy MetadataStore;
+
+ /// MDHandlerNames - Map to hold metadata handler names.
+ StringMap<unsigned> MDHandlerNames;
+
+public:
+
+ /// RegisterMDKind - Register a new metadata kind and return its ID.
+ /// A metadata kind can be registered only once.
+ MDKindID RegisterMDKind(const char *Name);
+
+ /// getMDKind - Return metadata kind. If the requested metadata kind
+ /// is not registered then return 0.
+ MDKindID getMDKind(const char *Name);
+
+ /// getMD - Get the metadata of given kind attached with an Instruction.
+ /// If the metadata is not found then return 0.
+ MDNode *getMD(MDKindID Kind, const Instruction *Inst);
+
+ /// setMD - Attach the metadata of given kind with an Instruction.
+ void setMD(MDKindID Kind, MDNode *Node, Instruction *Inst);
+
+ /// ValueIsDeleted - This handler is used to update metadata store
+ /// when a value is deleted.
+ void ValueIsDeleted(Value *V) {}
+ void ValueIsDeleted(const Instruction *Inst);
+};
+
} // end llvm namespace
#endif
diff --git a/include/llvm/Value.h b/include/llvm/Value.h
index 5aa2ea0..87c4dc2 100644
--- a/include/llvm/Value.h
+++ b/include/llvm/Value.h
@@ -42,6 +42,7 @@ class raw_ostream;
class AssemblyAnnotationWriter;
class ValueHandleBase;
class LLVMContext;
+class Metadata;
//===----------------------------------------------------------------------===//
// Value Class
@@ -63,6 +64,7 @@ class LLVMContext;
class Value {
const unsigned char SubclassID; // Subclass identifier (for isa/dyn_cast)
unsigned char HasValueHandle : 1; // Has a ValueHandle pointing to this?
+ unsigned char HasMetadata : 1; // Has a metadata attached to this ?
protected:
/// SubclassOptionalData - This member is similar to SubclassData, however it
/// is for holding information which may be used to aid optimization, but
@@ -81,6 +83,7 @@ private:
friend class ValueSymbolTable; // Allow ValueSymbolTable to directly mod Name.
friend class SymbolTable; // Allow SymbolTable to directly poke Name.
friend class ValueHandleBase;
+ friend class Metadata;
friend class AbstractTypeUser;
ValueName *Name;