2009-07-28 21:49:47 +00:00
|
|
|
//===-- llvm/Metadata.h - Metadata definitions ------------------*- C++ -*-===//
|
2009-05-10 20:57:05 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// @file
|
2009-07-28 21:49:47 +00:00
|
|
|
/// This file contains the declarations for metadata subclasses.
|
|
|
|
/// They represent the different flavors of metadata that live in LLVM.
|
2009-05-10 20:57:05 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-10-20 11:44:38 +00:00
|
|
|
#ifndef LLVM_METADATA_H
|
|
|
|
#define LLVM_METADATA_H
|
2009-05-10 20:57:05 +00:00
|
|
|
|
2009-10-21 23:57:35 +00:00
|
|
|
#include "llvm/Value.h"
|
2009-09-03 01:39:20 +00:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2009-07-29 17:16:17 +00:00
|
|
|
#include "llvm/ADT/ilist_node.h"
|
2009-05-10 20:57:05 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2009-07-29 15:24:54 +00:00
|
|
|
class Constant;
|
2009-09-16 18:09:00 +00:00
|
|
|
class Instruction;
|
2009-08-11 17:45:13 +00:00
|
|
|
class LLVMContext;
|
2009-12-28 08:30:43 +00:00
|
|
|
class Module;
|
2009-10-22 19:36:54 +00:00
|
|
|
class MetadataContextImpl;
|
2009-12-28 08:26:43 +00:00
|
|
|
template <typename T> class SmallVectorImpl;
|
2009-05-10 20:57:05 +00:00
|
|
|
|
2009-07-22 17:43:22 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-07-29 00:33:07 +00:00
|
|
|
// MetadataBase - A base class for MDNode, MDString and NamedMDNode.
|
2009-10-21 23:57:35 +00:00
|
|
|
class MetadataBase : public Value {
|
2009-07-23 01:19:53 +00:00
|
|
|
protected:
|
2009-07-22 17:43:22 +00:00
|
|
|
MetadataBase(const Type *Ty, unsigned scid)
|
2009-10-21 23:57:35 +00:00
|
|
|
: Value(Ty, scid) {}
|
2009-07-22 17:43:22 +00:00
|
|
|
|
2009-07-23 01:19:53 +00:00
|
|
|
public:
|
2009-07-22 17:43:22 +00:00
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2009-07-30 18:45:09 +00:00
|
|
|
static inline bool classof(const MetadataBase *) { return true; }
|
2009-07-22 17:43:22 +00:00
|
|
|
static bool classof(const Value *V) {
|
2009-07-29 00:33:07 +00:00
|
|
|
return V->getValueID() == MDStringVal || V->getValueID() == MDNodeVal
|
|
|
|
|| V->getValueID() == NamedMDNodeVal;
|
2009-07-22 17:43:22 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// MDString - a single uniqued string.
|
|
|
|
/// These are used to efficiently contain a byte sequence for metadata.
|
2009-07-29 00:33:07 +00:00
|
|
|
/// MDString is always unnamd.
|
2009-07-22 17:43:22 +00:00
|
|
|
class MDString : public MetadataBase {
|
|
|
|
MDString(const MDString &); // DO NOT IMPLEMENT
|
|
|
|
|
2009-08-03 22:51:10 +00:00
|
|
|
StringRef Str;
|
2009-07-23 01:19:53 +00:00
|
|
|
protected:
|
2009-12-28 08:30:43 +00:00
|
|
|
explicit MDString(LLVMContext &C, StringRef S);
|
2009-07-22 17:43:22 +00:00
|
|
|
|
2009-07-23 01:19:53 +00:00
|
|
|
public:
|
2009-10-22 00:10:15 +00:00
|
|
|
static MDString *get(LLVMContext &Context, StringRef Str);
|
2009-11-12 00:50:58 +00:00
|
|
|
static MDString *get(LLVMContext &Context, const char *Str);
|
2009-07-31 21:35:40 +00:00
|
|
|
|
2009-07-25 23:55:21 +00:00
|
|
|
StringRef getString() const { return Str; }
|
|
|
|
|
2009-11-04 03:08:57 +00:00
|
|
|
unsigned getLength() const { return (unsigned)Str.size(); }
|
2009-07-22 17:43:22 +00:00
|
|
|
|
2009-10-19 07:10:59 +00:00
|
|
|
typedef StringRef::iterator iterator;
|
|
|
|
|
2009-07-22 17:43:22 +00:00
|
|
|
/// begin() - Pointer to the first byte of the string.
|
|
|
|
///
|
2009-10-19 07:10:59 +00:00
|
|
|
iterator begin() const { return Str.begin(); }
|
2009-07-22 17:43:22 +00:00
|
|
|
|
|
|
|
/// end() - Pointer to one byte past the end of the string.
|
|
|
|
///
|
2009-10-19 07:10:59 +00:00
|
|
|
iterator end() const { return Str.end(); }
|
2009-07-22 17:43:22 +00:00
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const MDString *) { return true; }
|
|
|
|
static bool classof(const Value *V) {
|
|
|
|
return V->getValueID() == MDStringVal;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-12-28 07:41:54 +00:00
|
|
|
|
|
|
|
class MDNodeElement;
|
|
|
|
|
2009-05-10 20:57:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// MDNode - a tuple of other values.
|
2009-07-23 01:07:34 +00:00
|
|
|
/// These contain a list of the values that represent the metadata.
|
2009-07-29 00:33:07 +00:00
|
|
|
/// MDNode is always unnamed.
|
2009-09-03 01:39:20 +00:00
|
|
|
class MDNode : public MetadataBase, public FoldingSetNode {
|
2009-08-03 22:51:10 +00:00
|
|
|
MDNode(const MDNode &); // DO NOT IMPLEMENT
|
2009-12-28 09:07:21 +00:00
|
|
|
void operator=(const MDNode &); // DO NOT IMPLEMENT
|
2009-12-28 07:41:54 +00:00
|
|
|
friend class MDNodeElement;
|
2009-12-28 09:07:21 +00:00
|
|
|
|
|
|
|
MDNodeElement *Operands;
|
|
|
|
unsigned NumOperands;
|
2009-12-18 20:09:14 +00:00
|
|
|
|
2009-12-28 09:07:21 +00:00
|
|
|
// Subclass data enums.
|
|
|
|
enum {
|
|
|
|
FunctionLocalBit = 1
|
|
|
|
};
|
2009-12-18 20:09:14 +00:00
|
|
|
|
2009-09-03 01:39:20 +00:00
|
|
|
// Replace each instance of F from the element list of this node with T.
|
2009-12-28 09:32:10 +00:00
|
|
|
void replaceElement(MDNodeElement *Op, Value *NewVal);
|
2009-09-03 01:39:20 +00:00
|
|
|
|
2009-05-10 20:57:05 +00:00
|
|
|
protected:
|
2009-12-16 02:52:09 +00:00
|
|
|
explicit MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals,
|
2009-12-18 20:09:14 +00:00
|
|
|
bool isFunctionLocal);
|
2009-05-10 20:57:05 +00:00
|
|
|
public:
|
2009-08-03 22:51:10 +00:00
|
|
|
// Constructors and destructors.
|
2009-12-18 20:09:14 +00:00
|
|
|
static MDNode *get(LLVMContext &Context, Value *const *Vals, unsigned NumVals,
|
|
|
|
bool isFunctionLocal = false);
|
2009-05-10 20:57:05 +00:00
|
|
|
|
2009-08-11 17:15:47 +00:00
|
|
|
/// ~MDNode - Destroy MDNode.
|
2009-08-03 22:51:10 +00:00
|
|
|
~MDNode();
|
|
|
|
|
|
|
|
/// getElement - Return specified element.
|
2009-12-28 07:41:54 +00:00
|
|
|
Value *getElement(unsigned i) const;
|
|
|
|
|
2009-08-03 22:51:10 +00:00
|
|
|
/// getNumElements - Return number of MDNode elements.
|
2009-12-28 08:48:12 +00:00
|
|
|
unsigned getNumElements() const { return NumOperands; }
|
2009-12-16 02:52:09 +00:00
|
|
|
|
|
|
|
/// isFunctionLocal - Return whether MDNode is local to a function.
|
2009-12-18 20:09:14 +00:00
|
|
|
/// Note: MDNodes are designated as function-local when created, and keep
|
|
|
|
/// that designation even if their operands are modified to no longer
|
|
|
|
/// refer to function-local IR.
|
|
|
|
bool isFunctionLocal() const { return SubclassData & FunctionLocalBit; }
|
|
|
|
|
2009-09-03 01:39:20 +00:00
|
|
|
/// Profile - calculate a unique identifier for this MDNode to collapse
|
|
|
|
/// duplicates
|
|
|
|
void Profile(FoldingSetNodeID &ID) const;
|
|
|
|
|
2009-05-10 20:57:05 +00:00
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const MDNode *) { return true; }
|
|
|
|
static bool classof(const Value *V) {
|
|
|
|
return V->getValueID() == MDNodeVal;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-07-29 00:33:07 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// NamedMDNode - a tuple of other metadata.
|
|
|
|
/// NamedMDNode is always named. All NamedMDNode element has a type of metadata.
|
2009-07-29 17:16:17 +00:00
|
|
|
template<typename ValueSubClass, typename ItemParentClass>
|
|
|
|
class SymbolTableListTraits;
|
|
|
|
|
|
|
|
class NamedMDNode : public MetadataBase, public ilist_node<NamedMDNode> {
|
|
|
|
friend class SymbolTableListTraits<NamedMDNode, Module>;
|
2009-08-11 17:45:13 +00:00
|
|
|
friend class LLVMContextImpl;
|
2009-07-29 00:33:07 +00:00
|
|
|
|
2009-08-03 22:51:10 +00:00
|
|
|
NamedMDNode(const NamedMDNode &); // DO NOT IMPLEMENT
|
|
|
|
|
2009-07-29 00:33:07 +00:00
|
|
|
Module *Parent;
|
2009-12-28 08:07:14 +00:00
|
|
|
void *Operands; // SmallVector<TrackingVH<MetadataBase>, 4>
|
2009-07-29 00:33:07 +00:00
|
|
|
|
2009-10-21 17:33:41 +00:00
|
|
|
void setParent(Module *M) { Parent = M; }
|
2009-07-29 00:33:07 +00:00
|
|
|
protected:
|
2009-10-19 07:10:59 +00:00
|
|
|
explicit NamedMDNode(LLVMContext &C, const Twine &N, MetadataBase*const *Vals,
|
2009-07-29 21:58:56 +00:00
|
|
|
unsigned NumVals, Module *M = 0);
|
2009-07-29 00:33:07 +00:00
|
|
|
public:
|
2009-08-13 21:58:54 +00:00
|
|
|
static NamedMDNode *Create(LLVMContext &C, const Twine &N,
|
2009-10-19 07:10:59 +00:00
|
|
|
MetadataBase *const *MDs,
|
2009-07-29 21:58:56 +00:00
|
|
|
unsigned NumMDs, Module *M = 0) {
|
2009-08-13 21:58:54 +00:00
|
|
|
return new NamedMDNode(C, N, MDs, NumMDs, M);
|
2009-07-29 00:33:07 +00:00
|
|
|
}
|
|
|
|
|
2009-08-11 18:01:24 +00:00
|
|
|
static NamedMDNode *Create(const NamedMDNode *NMD, Module *M = 0);
|
|
|
|
|
2009-08-03 06:19:01 +00:00
|
|
|
/// eraseFromParent - Drop all references and remove the node from parent
|
|
|
|
/// module.
|
|
|
|
void eraseFromParent();
|
|
|
|
|
|
|
|
/// dropAllReferences - Remove all uses and clear node vector.
|
|
|
|
void dropAllReferences();
|
|
|
|
|
2009-08-03 22:51:10 +00:00
|
|
|
/// ~NamedMDNode - Destroy NamedMDNode.
|
2009-08-03 06:19:01 +00:00
|
|
|
~NamedMDNode();
|
|
|
|
|
2009-07-29 00:33:07 +00:00
|
|
|
/// getParent - Get the module that holds this named metadata collection.
|
|
|
|
inline Module *getParent() { return Parent; }
|
|
|
|
inline const Module *getParent() const { return Parent; }
|
|
|
|
|
2009-08-03 22:51:10 +00:00
|
|
|
/// getElement - Return specified element.
|
2009-12-28 08:07:14 +00:00
|
|
|
MetadataBase *getElement(unsigned i) const;
|
|
|
|
|
2009-08-03 22:51:10 +00:00
|
|
|
/// getNumElements - Return number of NamedMDNode elements.
|
2009-12-28 08:07:14 +00:00
|
|
|
unsigned getNumElements() const;
|
2009-07-29 00:33:07 +00:00
|
|
|
|
2009-07-30 23:57:23 +00:00
|
|
|
/// addElement - Add metadata element.
|
2009-12-28 08:07:14 +00:00
|
|
|
void addElement(MetadataBase *M);
|
|
|
|
|
2009-07-29 00:33:07 +00:00
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const NamedMDNode *) { return true; }
|
|
|
|
static bool classof(const Value *V) {
|
|
|
|
return V->getValueID() == NamedMDNodeVal;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-09-16 18:09:00 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-12-28 20:45:51 +00:00
|
|
|
/// MetadataContext - MetadataContext handles uniquing and assignment of IDs for
|
|
|
|
/// custom metadata types.
|
|
|
|
///
|
2009-09-28 21:41:20 +00:00
|
|
|
class MetadataContext {
|
2009-12-28 20:45:51 +00:00
|
|
|
MetadataContext(MetadataContext&); // DO NOT IMPLEMENT
|
|
|
|
void operator=(MetadataContext&); // DO NOT IMPLEMENT
|
2009-09-16 18:09:00 +00:00
|
|
|
|
2009-10-22 19:36:54 +00:00
|
|
|
MetadataContextImpl *const pImpl;
|
2009-12-28 23:41:32 +00:00
|
|
|
friend class Instruction;
|
2009-09-16 18:09:00 +00:00
|
|
|
public:
|
2009-10-22 19:36:54 +00:00
|
|
|
MetadataContext();
|
|
|
|
~MetadataContext();
|
|
|
|
|
2009-12-28 20:45:51 +00:00
|
|
|
/// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
|
|
|
|
unsigned getMDKindID(StringRef Name) const;
|
2009-09-16 18:09:00 +00:00
|
|
|
|
2009-10-20 22:50:27 +00:00
|
|
|
/// isValidName - Return true if Name is a valid custom metadata handler name.
|
2009-10-22 00:10:15 +00:00
|
|
|
static bool isValidName(StringRef Name);
|
2009-09-29 00:01:14 +00:00
|
|
|
|
2009-10-14 17:02:49 +00:00
|
|
|
/// copyMD - If metadata is attached with Instruction In1 then attach
|
|
|
|
/// the same metadata to In2.
|
|
|
|
void copyMD(Instruction *In1, Instruction *In2);
|
|
|
|
|
2009-12-28 20:10:43 +00:00
|
|
|
/// 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;
|
2009-09-18 19:26:43 +00:00
|
|
|
|
2009-09-16 18:09:00 +00:00
|
|
|
/// ValueIsDeleted - This handler is used to update metadata store
|
|
|
|
/// when a value is deleted.
|
2009-10-14 20:28:33 +00:00
|
|
|
void ValueIsDeleted(const Value *) {}
|
2009-10-22 19:36:54 +00:00
|
|
|
void ValueIsDeleted(Instruction *Inst);
|
2009-10-13 17:00:54 +00:00
|
|
|
void ValueIsRAUWd(Value *V1, Value *V2);
|
2009-09-23 18:32:25 +00:00
|
|
|
|
|
|
|
/// ValueIsCloned - This handler is used to update metadata store
|
|
|
|
/// when In1 is cloned to create In2.
|
|
|
|
void ValueIsCloned(const Instruction *In1, Instruction *In2);
|
2009-09-16 18:09:00 +00:00
|
|
|
};
|
|
|
|
|
2009-05-10 20:57:05 +00:00
|
|
|
} // end llvm namespace
|
|
|
|
|
|
|
|
#endif
|