aboutsummaryrefslogtreecommitdiffstats
path: root/include
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
parentf309880ad86114cda05037538c46123f6cda1a7e (diff)
downloadexternal_llvm-3990b121cf4a0b280ed3e54cf13870cbf4259e78.zip
external_llvm-3990b121cf4a0b280ed3e54cf13870cbf4259e78.tar.gz
external_llvm-3990b121cf4a0b280ed3e54cf13870cbf4259e78.tar.bz2
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')
-rw-r--r--include/llvm/Instruction.h67
-rw-r--r--include/llvm/Metadata.h20
-rw-r--r--include/llvm/Value.h6
3 files changed, 62 insertions, 31 deletions
diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h
index c4c746a..6cfe0a1 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
diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h
index a6e2d81..6f3017d 100644
--- a/include/llvm/Metadata.h
+++ b/include/llvm/Metadata.h
@@ -205,6 +205,7 @@ class MetadataContext {
void operator=(MetadataContext&); // DO NOT IMPLEMENT
MetadataContextImpl *const pImpl;
+ friend class Instruction;
public:
MetadataContext();
~MetadataContext();
@@ -215,25 +216,6 @@ public:
/// isValidName - Return true if Name is a valid custom metadata handler name.
static bool isValidName(StringRef Name);
-#if 1
- /// getMD - Get the metadata of given kind attached to an Instruction.
- /// If the metadata is not found then return 0.
- MDNode *getMD(unsigned Kind, const Instruction *Inst);
-
- /// getMDs - Get the metadata attached to an Instruction.
- void getMDs(const Instruction *Inst,
- SmallVectorImpl<std::pair<unsigned, MDNode*> > &MDs) const;
-
- /// addMD - Attach the metadata of given kind to an Instruction.
- void addMD(unsigned Kind, MDNode *Node, Instruction *Inst);
-
- /// removeMD - Remove metadata of given kind attached with an instuction.
- void removeMD(unsigned Kind, Instruction *Inst);
-
- /// removeAllMetadata - Remove all metadata attached with an instruction.
- void removeAllMetadata(Instruction *Inst);
-#endif
-
/// copyMD - If metadata is attached with Instruction In1 then attach
/// the same metadata to In2.
void copyMD(Instruction *In1, Instruction *In2);
diff --git a/include/llvm/Value.h b/include/llvm/Value.h
index 0960346..f2fa36d 100644
--- a/include/llvm/Value.h
+++ b/include/llvm/Value.h
@@ -64,7 +64,6 @@ class MetadataContextImpl;
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,9 +80,7 @@ private:
Use *UseList;
friend class ValueSymbolTable; // Allow ValueSymbolTable to directly mod Name.
- friend class SymbolTable; // Allow SymbolTable to directly poke Name.
friend class ValueHandleBase;
- friend class MetadataContextImpl;
friend class AbstractTypeUser;
ValueName *Name;
@@ -303,9 +300,6 @@ public:
const BasicBlock *PredBB) const{
return const_cast<Value*>(this)->DoPHITranslation(CurBB, PredBB);
}
-
- /// hasMetadata - Return true if metadata is attached with this value.
- bool hasMetadata() const { return HasMetadata; }
};
inline raw_ostream &operator<<(raw_ostream &OS, const Value &V) {