Introduce MetadataBase, a base class for MDString and MDNode.
authorDevang Patel <dpatel@apple.com>
Wed, 22 Jul 2009 17:43:22 +0000 (17:43 +0000)
committerDevang Patel <dpatel@apple.com>
Wed, 22 Jul 2009 17:43:22 +0000 (17:43 +0000)
Derive MDString directly from MetadataBase.
Introduce new bitcode block to hold metadata.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76759 91177308-0d34-0410-b5e6-96231b3b80d8

16 files changed:
include/llvm/Bitcode/LLVMBitCodes.h
include/llvm/Constants.h
include/llvm/MDNode.h
include/llvm/Value.h
lib/AsmParser/LLParser.cpp
lib/AsmParser/LLParser.h
lib/Bitcode/Reader/BitcodeReader.cpp
lib/Bitcode/Reader/BitcodeReader.h
lib/Bitcode/Writer/BitcodeWriter.cpp
lib/Bitcode/Writer/ValueEnumerator.cpp
lib/VMCore/AsmWriter.cpp
lib/VMCore/Constants.cpp
lib/VMCore/Value.cpp
test/Feature/embeddedmetadata.ll
test/Feature/mdnode.ll
tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp

index 753d0ff44c2cfcbf4bb739243128ee410e4df353..6847ac9472bad353f942f0848b87fb2003757c9f 100644 (file)
@@ -33,7 +33,8 @@ namespace bitc {
     CONSTANTS_BLOCK_ID,
     FUNCTION_BLOCK_ID,
     TYPE_SYMTAB_BLOCK_ID,
-    VALUE_SYMTAB_BLOCK_ID
+    VALUE_SYMTAB_BLOCK_ID,
+    METADATA_BLOCK_ID
   };
 
 
@@ -106,6 +107,9 @@ namespace bitc {
     VST_CODE_BBENTRY = 2   // VST_BBENTRY: [bbid, namechar x N]
   };
 
+  enum MetadataCodes {
+    METADATA_STRING  = 1   // MDString:      [values]
+  };
   // The constants block (CONSTANTS_BLOCK_ID) describes emission for each
   // constant and maintains an implicit current type value.
   enum ConstantsCodes {
@@ -128,7 +132,6 @@ namespace bitc {
     CST_CODE_CE_CMP        = 17,  // CE_CMP:        [opty, opval, opval, pred]
     CST_CODE_INLINEASM     = 18,  // INLINEASM:     [sideeffect,asmstr,conststr]
     CST_CODE_CE_SHUFVEC_EX = 19,  // SHUFVEC_EX:    [opty, opval, opval, opval]
-    CST_CODE_MDSTRING      = 20,  // MDSTRING:      [values]
     CST_CODE_MDNODE        = 21   // MDNODE:        [n x (type num, value num)]
   };
 
index 3bf8b142abf3072892b8f72e80e6f9aa31cceeeb..a9a18d7930f3481bbc4e45268d86929ed36cc0e0 100644 (file)
@@ -715,58 +715,6 @@ public:
     return V->getValueID() == UndefValueVal;
   }
 };
-
-//===----------------------------------------------------------------------===//
-/// MDString - a single uniqued string.
-/// These are used to efficiently contain a byte sequence for metadata.
-///
-class MDString : public Constant {
-  MDString(const MDString &);            // DO NOT IMPLEMENT
-  void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
-  MDString(const char *begin, const char *end);
-
-  const char *StrBegin, *StrEnd;
-  friend class LLVMContextImpl;
-protected:
-  // allocate space for exactly zero operands
-  void *operator new(size_t s) {
-    return User::operator new(s, 0);
-  }
-public:
-  /// size() - The length of this string.
-  ///
-  intptr_t size() const { return StrEnd - StrBegin; }
-
-  /// begin() - Pointer to the first byte of the string.
-  ///
-  const char *begin() const { return StrBegin; }
-
-  /// end() - Pointer to one byte past the end of the string.
-  ///
-  const char *end() const { return StrEnd; }
-
-  /// getType() specialization - Type is always MetadataTy.
-  ///
-  inline const Type *getType() const {
-    return Type::MetadataTy;
-  }
-
-  /// isNullValue - Return true if this is the value that would be returned by
-  /// getNullValue.  This always returns false because getNullValue will never
-  /// produce metadata.
-  virtual bool isNullValue() const {
-    return false;
-  }
-
-  virtual void destroyConstant();
-
-  /// 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;
-  }
-};
-
 } // End llvm namespace
 
 #endif
index e3944365ee465e8e568c756d120f4042c808a72c..d3af74a804f998542d194ef18296fb075deab8bd 100644 (file)
 
 namespace llvm {
 
+//===----------------------------------------------------------------------===//
+// MetadataBase  - A base class for MDNode and MDString.
+class MetadataBase : public Value {
+public:
+  MetadataBase(const Type *Ty, unsigned scid)
+    : Value(Ty, scid) {}
+
+  /// getType() specialization - Type is always MetadataTy.
+  ///
+  inline const Type *getType() const {
+    return Type::MetadataTy;
+  }
+
+  /// isNullValue - Return true if this is the value that would be returned by
+  /// getNullValue.  This always returns false because getNullValue will never
+  /// produce metadata.
+  virtual bool isNullValue() const {
+    return false;
+  }
+
+  /// 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;
+  }
+};
+
+//===----------------------------------------------------------------------===//
+/// MDString - a single uniqued string.
+/// These are used to efficiently contain a byte sequence for metadata.
+///
+class MDString : public MetadataBase {
+  MDString(const MDString &);            // DO NOT IMPLEMENT
+
+  const char *StrBegin, *StrEnd;
+  friend class LLVMContextImpl;
+
+public:
+  MDString(const char *begin, const char *end)
+    : MetadataBase(Type::MetadataTy, Value::MDStringVal),
+      StrBegin(begin), StrEnd(end) {}
+
+  intptr_t size() const { return StrEnd - StrBegin; }
+
+  /// begin() - Pointer to the first byte of the string.
+  ///
+  const char *begin() const { return StrBegin; }
+
+  /// end() - Pointer to one byte past the end of the string.
+  ///
+  const char *end() const { return StrEnd; }
+
+  /// 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;
+  }
+};
+
 //===----------------------------------------------------------------------===//
 /// MDNode - a tuple of other values.
 /// These contain a list of the Constants that represent the metadata. The
index b220930c287409f8f6298c54bd73eb8f12af7d50..dd01cabb8cdb0a43a643fa0393751ee7f47faee8 100644 (file)
@@ -219,8 +219,8 @@ public:
     ConstantStructVal,        // This is an instance of ConstantStruct
     ConstantVectorVal,        // This is an instance of ConstantVector
     ConstantPointerNullVal,   // This is an instance of ConstantPointerNull
-    MDStringVal,              // This is an instance of MDString
     MDNodeVal,                // This is an instance of MDNode
+    MDStringVal,              // This is an instance of MDString
     InlineAsmVal,             // This is an instance of InlineAsm
     PseudoSourceValueVal,     // This is an instance of PseudoSourceValue
     InstructionVal,           // This is an instance of Instruction
index d461a8dcffd2b2ccc5a43d911142c9cdeb7ba066..9f708a860cf7cca502ac29e6a0943b57eef4ad1d 100644 (file)
@@ -42,7 +42,8 @@ namespace llvm {
       t_Null, t_Undef, t_Zero,    // No value.
       t_EmptyArray,               // No value:  []
       t_Constant,                 // Value in ConstantVal.
-      t_InlineAsm                 // Value in StrVal/StrVal2/UIntVal.
+      t_InlineAsm,                // Value in StrVal/StrVal2/UIntVal.
+      t_Metadata                  // Value in MetadataVal.
     } Kind;
     
     LLParser::LocTy Loc;
@@ -51,6 +52,7 @@ namespace llvm {
     APSInt APSIntVal;
     APFloat APFloatVal;
     Constant *ConstantVal;
+    MetadataBase *MetadataVal;
     ValID() : APFloatVal(0.0) {}
   };
 }
@@ -368,7 +370,7 @@ bool LLParser::ParseNamedGlobal() {
 
 // MDString:
 //   ::= '!' STRINGCONSTANT
-bool LLParser::ParseMDString(Constant *&MDS) {
+bool LLParser::ParseMDString(MetadataBase *&MDS) {
   std::string Str;
   if (ParseStringConstant(Str)) return true;
   MDS = Context.getMDString(Str.data(), Str.data() + Str.size());
@@ -1694,7 +1696,8 @@ bool LLParser::ParseValID(ValID &ID) {
 
     // MDString:
     //   ::= '!' STRINGCONSTANT
-    if (ParseMDString(ID.ConstantVal)) return true;
+    if (ParseMDString(ID.MetadataVal)) return true;
+    ID.Kind = ValID::t_Metadata;
     return false;
   }
   case lltok::APSInt:
@@ -2107,7 +2110,9 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID,
     return Error(ID.Loc, "functions are not values, refer to them as pointers");
   
   switch (ID.Kind) {
-  default: llvm_unreachable("Unknown ValID!");
+  default: llvm_unreachable("Unknown ValID!");    
+  case ValID::t_Metadata:
+    return Error(ID.Loc, "invalid use of metadata");
   case ValID::t_LocalID:
   case ValID::t_LocalName:
     return Error(ID.Loc, "invalid use of function-local name");
@@ -2224,6 +2229,8 @@ bool LLParser::ConvertValIDToValue(const Type *Ty, ValID &ID, Value *&V,
       return Error(ID.Loc, "invalid type for inline asm constraint string");
     V = InlineAsm::get(FTy, ID.StrVal, ID.StrVal2, ID.UIntVal);
     return false;
+  } else if (ID.Kind == ValID::t_Metadata) {
+    V = ID.MetadataVal;
   } else {
     Constant *C;
     if (ConvertGlobalValIDToValue(Ty, ID, C)) return true;
@@ -3451,9 +3458,23 @@ bool LLParser::ParseMDNodeVector(SmallVectorImpl<Value*> &Elts) {
       Lex.Lex();
       V = 0;
     } else {
-      Constant *C;
-      if (ParseGlobalTypeAndValue(C)) return true;
-      V = C;
+      PATypeHolder Ty(Type::VoidTy);
+      if (ParseType(Ty)) return true;
+      if (Lex.getKind() == lltok::Metadata) {
+        Lex.Lex();
+        Constant *Node = 0;
+        if (!ParseMDNode(Node))
+          V = Node;
+        else {
+          MetadataBase *MDS = 0;
+          if (ParseMDString(MDS)) return true;
+          V = MDS;
+        }
+      } else {
+        Constant *C;
+        if (ParseGlobalValue(Ty, C)) return true;
+        V = C;
+      }
     }
     Elts.push_back(V);
   } while (EatIfPresent(lltok::comma));
index 57a19061132beec25e738ef6072411649628cde1..1a0b6ccde9fc3291a75fb9440cab2eef46c45bc3 100644 (file)
@@ -28,6 +28,7 @@ namespace llvm {
   class Instruction;
   class Constant;
   class GlobalValue;
+  class MetadataBase;
   class MDString;
   class MDNode;
   struct ValID;
@@ -147,7 +148,7 @@ namespace llvm {
                      bool HasLinkage, unsigned Visibility);
     bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Visibility);
     bool ParseStandaloneMetadata();
-    bool ParseMDString(Constant *&S);
+    bool ParseMDString(MetadataBase *&S);
     bool ParseMDNode(Constant *&N);
 
     // Type Parsing.
index 95276b1aece9cb2cc76f5005f9b6c13507ce3755..d22d467476da5a2aec38c0c0e7c6372dc7838b31 100644 (file)
@@ -699,6 +699,56 @@ bool BitcodeReader::ParseValueSymbolTable() {
   }
 }
 
+bool BitcodeReader::ParseMetadata() {
+  unsigned NextValueNo = ValueList.size();
+
+  if (Stream.EnterSubBlock(bitc::METADATA_BLOCK_ID))
+    return Error("Malformed block record");
+  
+  SmallVector<uint64_t, 64> Record;
+  
+  // Read all the records.
+  while (1) {
+    unsigned Code = Stream.ReadCode();
+    if (Code == bitc::END_BLOCK) {
+      if (Stream.ReadBlockEnd())
+        return Error("Error at end of PARAMATTR block");
+      return false;
+    }
+    
+    if (Code == bitc::ENTER_SUBBLOCK) {
+      // No known subblocks, always skip them.
+      Stream.ReadSubBlockID();
+      if (Stream.SkipBlock())
+        return Error("Malformed block record");
+      continue;
+    }
+    
+    if (Code == bitc::DEFINE_ABBREV) {
+      Stream.ReadAbbrevRecord();
+      continue;
+    }
+    
+    // Read a record.
+    Record.clear();
+    switch (Stream.ReadRecord(Code, Record)) {
+    default:  // Default behavior: ignore.
+      break;
+    case bitc::METADATA_STRING: {
+      unsigned MDStringLength = Record.size();
+      SmallString<8> String;
+      String.resize(MDStringLength);
+      for (unsigned i = 0; i != MDStringLength; ++i)
+        String[i] = Record[i];
+      Value *V = 
+        Context.getMDString(String.c_str(), String.c_str() + MDStringLength);
+      ValueList.AssignValue(V, NextValueNo++);
+      break;
+    }
+    }
+  }
+}
+
 /// DecodeSignRotatedValue - Decode a signed value stored with the sign bit in
 /// the LSB for dense VBR encoding.
 static uint64_t DecodeSignRotatedValue(uint64_t V) {
@@ -1028,15 +1078,6 @@ bool BitcodeReader::ParseConstants() {
                          AsmStr, ConstrStr, HasSideEffects);
       break;
     }
-    case bitc::CST_CODE_MDSTRING: {
-      unsigned MDStringLength = Record.size();
-      SmallString<8> String;
-      String.resize(MDStringLength);
-      for (unsigned i = 0; i != MDStringLength; ++i)
-        String[i] = Record[i];
-      V = Context.getMDString(String.c_str(), String.c_str() + MDStringLength);
-      break;
-    }
     case bitc::CST_CODE_MDNODE: {
       if (Record.empty() || Record.size() % 2 == 1)
         return Error("Invalid CST_MDNODE record");
@@ -1171,6 +1212,10 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) {
         if (ParseConstants() || ResolveGlobalAndAliasInits())
           return true;
         break;
+      case bitc::METADATA_BLOCK_ID:
+        if (ParseMetadata())
+          return true;
+        break;
       case bitc::FUNCTION_BLOCK_ID:
         // If this is the first function body we've seen, reverse the
         // FunctionsWithBodies list.
index bbbe4ec43a206ff3b4bc8fa537a35a73a84d0998..77dabdee2dc5857340aaa725bfe7a4a8291211f8 100644 (file)
@@ -210,6 +210,7 @@ private:
   bool RememberAndSkipFunctionBody();
   bool ParseFunctionBody(Function *F);
   bool ResolveGlobalAndAliasInits();
+  bool ParseMetadata();
 };
   
 } // End llvm namespace
index d245e5bcb1fbfe6c9a7e1e6ebfdaee45974b2c7a..467762efe7c135cd125dbd65bfc99d0c2923670f 100644 (file)
@@ -473,6 +473,42 @@ static uint64_t GetOptimizationFlags(const Value *V) {
   return Flags;
 }
 
+ static void WriteModuleMetadata(const ValueEnumerator &VE,
+                                 BitstreamWriter &Stream) {
+   const ValueEnumerator::ValueList &Vals = VE.getValues();
+   bool StartedMetadataBlock = false;
+   unsigned MDSAbbrev = 0;
+   for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
+     if (const MDString *MDS = dyn_cast<MDString>(Vals[i].first)) {
+       if (!StartedMetadataBlock)  {
+        Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
+
+         // Abbrev for CST_CODE_STRING.
+         BitCodeAbbrev *Abbv = new BitCodeAbbrev();
+         Abbv->Add(BitCodeAbbrevOp(bitc::METADATA_STRING));
+        Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
+         Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));
+         MDSAbbrev = Stream.EmitAbbrev(Abbv);
+         StartedMetadataBlock = true;
+       }
+
+      SmallVector<unsigned, 64> StrVals;
+      StrVals.clear();
+       // Code: [strchar x N]
+       const char *StrBegin = MDS->begin();
+       for (unsigned i = 0, e = MDS->size(); i != e; ++i)
+        StrVals.push_back(StrBegin[i]);
+    
+       // Emit the finished record.
+      Stream.EmitRecord(bitc::METADATA_STRING, StrVals, MDSAbbrev);
+     }
+   }
+
+   if (StartedMetadataBlock)
+     Stream.ExitBlock();    
+}
+
+
 static void WriteConstants(unsigned FirstVal, unsigned LastVal,
                            const ValueEnumerator &VE,
                            BitstreamWriter &Stream, bool isGlobal) {
@@ -484,8 +520,6 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
   unsigned String8Abbrev = 0;
   unsigned CString7Abbrev = 0;
   unsigned CString6Abbrev = 0;
-  unsigned MDString8Abbrev = 0;
-  unsigned MDString6Abbrev = 0;
   // If this is a constant pool for the module, emit module-specific abbrevs.
   if (isGlobal) {
     // Abbrev for CST_CODE_AGGREGATE.
@@ -513,19 +547,6 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
     Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
     Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6));
     CString6Abbrev = Stream.EmitAbbrev(Abbv);
-
-    // Abbrev for CST_CODE_MDSTRING.
-    Abbv = new BitCodeAbbrev();
-    Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_MDSTRING));
-    Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
-    Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));
-    MDString8Abbrev = Stream.EmitAbbrev(Abbv);
-    // Abbrev for CST_CODE_MDSTRING.
-    Abbv = new BitCodeAbbrev();
-    Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_MDSTRING));
-    Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
-    Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6));
-    MDString6Abbrev = Stream.EmitAbbrev(Abbv);
   }  
   
   SmallVector<uint64_t, 64> Record;
@@ -534,6 +555,8 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
   const Type *LastTy = 0;
   for (unsigned i = FirstVal; i != LastVal; ++i) {
     const Value *V = Vals[i].first;
+    if (isa<MDString>(V))
+      continue;
     // If we need to switch types, do so now.
     if (V->getType() != LastTy) {
       LastTy = V->getType();
@@ -713,16 +736,6 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
         Record.push_back(CE->getPredicate());
         break;
       }
-    } else if (const MDString *S = dyn_cast<MDString>(C)) {
-      Code = bitc::CST_CODE_MDSTRING;
-      AbbrevToUse = MDString6Abbrev;
-      for (unsigned i = 0, e = S->size(); i != e; ++i) {
-        char V = S->begin()[i];
-        Record.push_back(V);
-
-        if (!BitCodeAbbrevOp::isChar6(V))
-          AbbrevToUse = MDString8Abbrev;
-      }
     } else if (const MDNode *N = dyn_cast<MDNode>(C)) {
       Code = bitc::CST_CODE_MDNODE;
       for (unsigned i = 0, e = N->getNumElements(); i != e; ++i) {
@@ -1328,7 +1341,10 @@ static void WriteModule(const Module *M, BitstreamWriter &Stream) {
   // Emit top-level description of module, including target triple, inline asm,
   // descriptors for global variables, and function prototype info.
   WriteModuleInfo(M, VE, Stream);
-  
+
+  // Emit metadata.
+  WriteModuleMetadata(VE, Stream);
+
   // Emit constants.
   WriteModuleConstants(VE, Stream);
   
index 32b2819762db59ef5956fc08a11aa4c07cff729b..a31a49277497ebf6b4b4a1f6b9e74716ffbbbf5d 100644 (file)
@@ -259,10 +259,14 @@ void ValueEnumerator::EnumerateOperandType(const Value *V) {
       EnumerateOperandType(C->getOperand(i));
 
     if (const MDNode *N = dyn_cast<MDNode>(V)) {
-      for (unsigned i = 0, e = N->getNumElements(); i != e; ++i)
-        EnumerateOperandType(N->getElement(i));
+      for (unsigned i = 0, e = N->getNumElements(); i != e; ++i) {
+        Value *Elem = N->getElement(i);
+        if (Elem)
+          EnumerateOperandType(Elem);
+      }
     }
-  }
+  } else if (const MDString *MDS = dyn_cast<MDString>(V))
+    EnumerateValue(V);
 }
 
 void ValueEnumerator::EnumerateAttributes(const AttrListPtr &PAL) {
index a091a935bac1aad4e167297c7a24771b2745e7f1..17d0478d59ccf82e737a9359bd5499631a266c60 100644 (file)
@@ -1063,13 +1063,6 @@ static void WriteConstantInt(raw_ostream &Out, const Constant *CV,
     return;
   }
   
-  if (const MDString *S = dyn_cast<MDString>(CV)) {
-    Out << "!\"";
-    PrintEscapedString(S->begin(), S->size(), Out);
-    Out << '"';
-    return;
-  }
-
   if (const MDNode *Node = dyn_cast<MDNode>(CV)) {
     Out << "!" << Machine->getMetadataSlot(Node);
     return;
@@ -1138,7 +1131,16 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
     Out << '"';
     return;
   }
-  
+
+  if (const MDString *MDS = dyn_cast<MDString>(V)) {
+    TypePrinter.print(MDS->getType(), Out);
+    Out << ' ';
+    Out << "!\"";
+    PrintEscapedString(MDS->begin(), MDS->size(), Out);
+    Out << '"';
+    return;
+  }
+
   char Prefix = '%';
   int Slot;
   if (Machine) {
@@ -1973,6 +1975,13 @@ void Value::print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const {
     SlotTracker SlotTable(GV->getParent());
     AssemblyWriter W(OS, SlotTable, GV->getParent(), AAW);
     W.write(GV);
+  } else if (const MDString *MDS = dyn_cast<MDString>(this)) {
+    TypePrinting TypePrinter;
+    TypePrinter.print(MDS->getType(), OS);
+    OS << ' ';
+    OS << "!\"";
+    PrintEscapedString(MDS->begin(), MDS->size(), OS);
+    OS << '"';
   } else if (const MDNode *N = dyn_cast<MDNode>(this)) {
     SlotTracker SlotTable(N);
     TypePrinting TypePrinter;
index 2eb73398c5ba85d59b4c5d8bfc567c0a630de2c8..db405927ff5956150a904840775a8086faf4a45b 100644 (file)
@@ -1323,18 +1323,6 @@ void UndefValue::destroyConstant() {
   destroyConstantImpl();
 }
 
-//---- MDString::get() implementation
-//
-
-MDString::MDString(const char *begin, const char *end)
-  : Constant(Type::MetadataTy, MDStringVal, 0, 0),
-    StrBegin(begin), StrEnd(end) {}
-
-void MDString::destroyConstant() {
-  getType()->getContext().erase(this);
-  destroyConstantImpl();
-}
-
 //---- MDNode::get() implementation
 //
 
index 07fbfc622fff78b721541035b3f8d09cfff4258d..b3c0692c0e5c6c8304439aa4e8ba274b8f5f61a8 100644 (file)
@@ -18,6 +18,7 @@
 #include "llvm/Instructions.h"
 #include "llvm/Operator.h"
 #include "llvm/Module.h"
+#include "llvm/MDNode.h"
 #include "llvm/ValueSymbolTable.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -140,7 +141,9 @@ static bool getSymTab(Value *V, ValueSymbolTable *&ST) {
   } else if (Argument *A = dyn_cast<Argument>(V)) {
     if (Function *P = A->getParent()) 
       ST = &P->getValueSymbolTable();
-  } else {
+  } else if (isa<MDString>(V))
+    return true;
+  else {
     assert(isa<Constant>(V) && "Unknown value type!");
     return true;  // no name is setable for this.
   }
index 75977c0a4882bf8c6d0611ce0a4f0f9c461c301f..65e0d4c2a4b0124ae8b28e5b1f1f5ee0b466b58a 100644 (file)
@@ -1,11 +1,13 @@
 ; RUN: llvm-as < %s | llvm-dis | not grep undef
 
-declare i8 @llvm.something(metadata %a)
+declare i8 @llvm.something(metadata %a, i32 %b, metadata %c)
 
-@llvm.foo = internal constant metadata !{i17 123, null, metadata !"foobar"}
+;; Simple MDNode
+!21 = metadata !{i17 123, null, metadata !"foobar"}
 
 define void @foo() {
-  %x = call i8 @llvm.something(metadata !{metadata !"f\00oa", i42 123})
+  ;; Intrinsic using MDNode and MDString
+  %x = call i8 @llvm.something(metadata !21, i32 42, metadata !"bar")
   ret void
 }
 
index d63b46e9b4383b16418230053520a45149d4317b..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,4 +0,0 @@
-; RUN: llvm-as < %s | llc -f -o /dev/null
-@llvm.foo =  constant metadata !{i17 123, null, metadata !"foobar"}
-@llvm.bar =  constant metadata !"barbar"
-
index bb39e07d9042206024fa34c9218eb9c2494775e4..4eaa60c7570468db4cfe5e785435e93d21606aa8 100644 (file)
@@ -98,6 +98,7 @@ static const char *GetBlockName(unsigned BlockID,
   case bitc::FUNCTION_BLOCK_ID:     return "FUNCTION_BLOCK";
   case bitc::TYPE_SYMTAB_BLOCK_ID:  return "TYPE_SYMTAB";
   case bitc::VALUE_SYMTAB_BLOCK_ID: return "VALUE_SYMTAB";
+  case bitc::METADATA_BLOCK_ID:     return "METADATA_BLOCK";
   }
 }
 
@@ -194,7 +195,6 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID,
     case bitc::CST_CODE_CE_CMP:        return "CE_CMP";
     case bitc::CST_CODE_INLINEASM:     return "INLINEASM";
     case bitc::CST_CODE_CE_SHUFVEC_EX: return "CE_SHUFVEC_EX";
-    case bitc::CST_CODE_MDSTRING:      return "MDSTRING";
     case bitc::CST_CODE_MDNODE:        return "MDNODE";
     }        
   case bitc::FUNCTION_BLOCK_ID:
@@ -244,6 +244,11 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID,
     case bitc::VST_CODE_ENTRY: return "ENTRY";
     case bitc::VST_CODE_BBENTRY: return "BBENTRY";
     }
+  case bitc::METADATA_BLOCK_ID:
+    switch(CodeID) {
+    default:return 0;
+    case bitc::METADATA_STRING:      return "MDSTRING";
+    }
   }
 }