summaryrefslogtreecommitdiff
path: root/include/llvm/Instruction.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-12-28 23:41:32 +0000
committerChris Lattner <sabre@nondot.org>2009-12-28 23:41:32 +0000
commit3990b121cf4a0b280ed3e54cf13870cbf4259e78 (patch)
tree9d5ea8aa8a5f0b166334346e372f143b832b9d03 /include/llvm/Instruction.h
parentf309880ad86114cda05037538c46123f6cda1a7e (diff)
downloadllvm-3990b121cf4a0b280ed3e54cf13870cbf4259e78.tar.gz
llvm-3990b121cf4a0b280ed3e54cf13870cbf4259e78.tar.bz2
llvm-3990b121cf4a0b280ed3e54cf13870cbf4259e78.tar.xz
This is a major cleanup of the instruction metadata interfaces that
I asked Devang to do back on Sep 27. Instead of going through the MetadataContext class with methods like getMD() and getMDs(), just ask the instruction directly for its metadata with getMetadata() and getAllMetadata(). This includes a variety of other fixes and improvements: previously all Value*'s were bloated because the HasMetadata bit was thrown into value, adding a 9th bit to a byte. Now this is properly sunk down to the Instruction class (the only place where it makes sense) and it will be folded away somewhere soon. This also fixes some confusion in getMDs and its clients about whether the returned list is indexed by the MDID or densely packed. This is now returned sorted and densely packed and the comments make this clear. This introduces a number of fixme's which I'll follow up on. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92235 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Instruction.h')
-rw-r--r--include/llvm/Instruction.h67
1 files changed, 61 insertions, 6 deletions
diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h
index c4c746a49f..6cfe0a1ca7 100644
--- a/include/llvm/Instruction.h
+++ b/include/llvm/Instruction.h
@@ -21,6 +21,8 @@
namespace llvm {
class LLVMContext;
+class MDNode;
+class MetadataContextImpl;
template<typename ValueSubClass, typename ItemParentClass>
class SymbolTableListTraits;
@@ -30,6 +32,10 @@ class Instruction : public User, public ilist_node<Instruction> {
Instruction(const Instruction &); // Do not implement
BasicBlock *Parent;
+
+ // FIXME: Bitfieldize this.
+ bool HasMetadata;
+ friend class MetadataContextImpl;
friend class SymbolTableListTraits<Instruction, BasicBlock>;
void setParent(BasicBlock *P);
@@ -74,19 +80,19 @@ public:
/// MovePos.
void moveBefore(Instruction *MovePos);
- // ---------------------------------------------------------------------------
- /// Subclass classification... getOpcode() returns a member of
- /// one of the enums that is coming soon (down below)...
- ///
+ //===--------------------------------------------------------------------===//
+ // Subclass classification.
+ //===--------------------------------------------------------------------===//
+
+ /// getOpcode() returns a member of one of the enums like Instruction::Add.
unsigned getOpcode() const { return getValueID() - InstructionVal; }
+
const char *getOpcodeName() const { return getOpcodeName(getOpcode()); }
bool isTerminator() const { return isTerminator(getOpcode()); }
bool isBinaryOp() const { return isBinaryOp(getOpcode()); }
bool isShift() { return isShift(getOpcode()); }
bool isCast() const { return isCast(getOpcode()); }
-
-
static const char* getOpcodeName(unsigned OpCode);
static inline bool isTerminator(unsigned OpCode) {
@@ -118,6 +124,55 @@ public:
return OpCode >= CastOpsBegin && OpCode < CastOpsEnd;
}
+ //===--------------------------------------------------------------------===//
+ // Metadata manipulation.
+ //===--------------------------------------------------------------------===//
+
+ /// hasMetadata() - Return true if this instruction has any metadata attached
+ /// to it.
+ bool hasMetadata() const {
+ return HasMetadata;
+ }
+
+ /// getMetadata - Get the metadata of given kind attached to this Instruction.
+ /// If the metadata is not found then return null.
+ MDNode *getMetadata(unsigned KindID) const {
+ if (!hasMetadata()) return 0;
+ return getMetadataImpl(KindID);
+ }
+
+ /// getMetadata - Get the metadata of given kind attached to this Instruction.
+ /// If the metadata is not found then return null.
+ MDNode *getMetadata(const char *Kind) const {
+ if (!hasMetadata()) return 0;
+ return getMetadataImpl(Kind);
+ }
+
+ /// getAllMetadata - Get all metadata attached to this Instruction. The first
+ /// element of each pair returned is the KindID, the second element is the
+ /// metadata value. This list is returned sorted by the KindID.
+ void getAllMetadata(SmallVectorImpl<std::pair<unsigned, MDNode*> > &MDs)const{
+ if (hasMetadata())
+ getAllMetadataImpl(MDs);
+ }
+
+ /// 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 setMetadata(unsigned KindID, MDNode *Node);
+ void setMetadata(const char *Kind, MDNode *Node);
+
+private:
+ // These are all implemented in Metadata.cpp.
+ MDNode *getMetadataImpl(unsigned KindID) const;
+ MDNode *getMetadataImpl(const char *Kind) const;
+ void getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned,MDNode*> > &)const;
+public:
+ //===--------------------------------------------------------------------===//
+ // Predicates and helper methods.
+ //===--------------------------------------------------------------------===//
+
+
/// isAssociative - Return true if the instruction is associative:
///
/// Associative operators satisfy: x op (y op z) === (x op y) op z