[llvm-commits] [llvm] r113557 - in /llvm/trunk: include/llvm/Bitcode/LLVMBitCodes.h lib/Bitcode/Reader/BitcodeReader.cpp lib/Bitcode/Writer/BitcodeWriter.cpp tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp

Dan Gohman gohman at apple.com
Thu Sep 9 16:12:39 PDT 2010


Author: djg
Date: Thu Sep  9 18:12:39 2010
New Revision: 113557

URL: http://llvm.org/viewvc/llvm-project?rev=113557&view=rev
Log:
Discard metadata produced by LLVM 2.7. The value enumeration it used
is different from what the code now uses in a two ways: NamedMDNodes
were considered Values and included in the numbering, and the
function-local metadata counter wasn't reset between functions.

The later problem breaks lazy deserialization, so instead of trying
to emulate the old numbering, just drop the old metadata. The only
in-tree use case is debug info with LTO, where the QOI loss is
considered acceptable.

Modified:
    llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
    llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp

Modified: llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h?rev=113557&r1=113556&r2=113557&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h (original)
+++ llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h Thu Sep  9 18:12:39 2010
@@ -110,12 +110,20 @@
 
   enum MetadataCodes {
     METADATA_STRING        = 1,   // MDSTRING:      [values]
-    METADATA_NODE          = 2,   // MDNODE:        [n x (type num, value num)]
-    METADATA_FN_NODE       = 3,   // FN_MDNODE:     [n x (type num, value num)]
+    // FIXME: Remove NODE in favor of NODE2 in LLVM 3.0
+    METADATA_NODE          = 2,   // NODE with potentially invalid metadata
+    // FIXME: Remove FN_NODE in favor of FN_NODE2 in LLVM 3.0
+    METADATA_FN_NODE       = 3,   // FN_NODE with potentially invalid metadata
     METADATA_NAME          = 4,   // STRING:        [values]
-    METADATA_NAMED_NODE    = 5,   // NAMEDMDNODE:   [n x mdnodes]
+    // FIXME: Remove NAMED_NODE in favor of NAMED_NODE2 in LLVM 3.0
+    METADATA_NAMED_NODE    = 5,   // NAMED_NODE with potentially invalid metadata
     METADATA_KIND          = 6,   // [n x [id, name]]
-    METADATA_ATTACHMENT    = 7    // [m x [value, [n x [id, mdnode]]]
+    // FIXME: Remove ATTACHMENT in favor of ATTACHMENT2 in LLVM 3.0
+    METADATA_ATTACHMENT    = 7,   // ATTACHMENT with potentially invalid metadata
+    METADATA_NODE2         = 8,   // NODE2:         [n x (type num, value num)]
+    METADATA_FN_NODE2      = 9,   // FN_NODE2:      [n x (type num, value num)]
+    METADATA_NAMED_NODE2   = 10,  // NAMED_NODE2:   [n x mdnodes]
+    METADATA_ATTACHMENT2   = 11   // [m x [value, [n x [id, mdnode]]]
   };
   // The constants block (CONSTANTS_BLOCK_ID) describes emission for each
   // constant and maintains an implicit current type value.
@@ -223,7 +231,8 @@
     FUNC_CODE_INST_LOAD        = 20, // LOAD:       [opty, op, align, vol]
     // FIXME: Remove STORE in favor of STORE2 in LLVM 3.0
     FUNC_CODE_INST_STORE       = 21, // STORE:      [valty,val,ptr, align, vol]
-    FUNC_CODE_INST_CALL        = 22, // CALL:       [attr, fnty, fnid, args...]
+    // FIXME: Remove CALL in favor of CALL2 in LLVM 3.0
+    FUNC_CODE_INST_CALL        = 22, // CALL with potentially invalid metadata
     FUNC_CODE_INST_VAARG       = 23, // VAARG:      [valistty, valist, instty]
     // This store code encodes the pointer type, rather than the value type
     // this is so information only available in the pointer type (e.g. address
@@ -241,8 +250,13 @@
     FUNC_CODE_INST_INBOUNDS_GEP= 30, // INBOUNDS_GEP: [n x operands]
     FUNC_CODE_INST_INDIRECTBR  = 31, // INDIRECTBR: [opty, op0, op1, ...]
     
-    FUNC_CODE_DEBUG_LOC        = 32, // DEBUG_LOC: [Line,Col,ScopeVal, IAVal]
-    FUNC_CODE_DEBUG_LOC_AGAIN  = 33  // DEBUG_LOC_AGAIN
+    // FIXME: Remove DEBUG_LOC in favor of DEBUG_LOC2 in LLVM 3.0
+    FUNC_CODE_DEBUG_LOC        = 32, // DEBUG_LOC with potentially invalid metadata
+    FUNC_CODE_DEBUG_LOC_AGAIN  = 33, // DEBUG_LOC_AGAIN
+
+    FUNC_CODE_INST_CALL2       = 34, // CALL2:      [attr, fnty, fnid, args...]
+
+    FUNC_CODE_DEBUG_LOC2       = 35  // DEBUG_LOC2: [Line,Col,ScopeVal, IAVal]
   };
 } // End bitc namespace
 } // End llvm namespace

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=113557&r1=113556&r2=113557&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Thu Sep  9 18:12:39 2010
@@ -786,8 +786,12 @@
       Record.clear();
       Code = Stream.ReadCode();
 
-      // METADATA_NAME is always followed by METADATA_NAMED_NODE.
-      if (Stream.ReadRecord(Code, Record) != bitc::METADATA_NAMED_NODE)
+      // METADATA_NAME is always followed by METADATA_NAMED_NODE2.
+      unsigned NextBitCode = Stream.ReadRecord(Code, Record);
+      // FIXME: LLVM 3.0: Remove this.
+      if (NextBitCode == bitc::METADATA_NAMED_NODE)
+        break;
+      if (NextBitCode != bitc::METADATA_NAMED_NODE2)
         assert ( 0 && "Inavlid Named Metadata record");
 
       // Read named metadata elements.
@@ -802,11 +806,19 @@
       break;
     }
     case bitc::METADATA_FN_NODE:
+      // FIXME: Legacy support for the old fn_node, where function-local
+      // metadata operands were bogus. Remove in LLVM 3.0.
+      break;
+    case bitc::METADATA_NODE:
+      // FIXME: Legacy support for the old node, where function-local
+      // metadata operands were bogus. Remove in LLVM 3.0.
+      break;
+    case bitc::METADATA_FN_NODE2:
       IsFunctionLocal = true;
       // fall-through
-    case bitc::METADATA_NODE: {
+    case bitc::METADATA_NODE2: {
       if (Record.size() % 2 == 1)
-        return Error("Invalid METADATA_NODE record");
+        return Error("Invalid METADATA_NODE2 record");
 
       unsigned Size = Record.size();
       SmallVector<Value*, 8> Elts;
@@ -1593,7 +1605,10 @@
     switch (Stream.ReadRecord(Code, Record)) {
     default:  // Default behavior: ignore.
       break;
-    case bitc::METADATA_ATTACHMENT: {
+    case bitc::METADATA_ATTACHMENT:
+      // LLVM 3.0: Remove this.
+      break;
+    case bitc::METADATA_ATTACHMENT2: {
       unsigned RecordLength = Record.size();
       if (Record.empty() || (RecordLength - 1) % 2 == 1)
         return Error ("Invalid METADATA_ATTACHMENT reader!");
@@ -1706,7 +1721,11 @@
       I = 0;
       continue;
         
-    case bitc::FUNC_CODE_DEBUG_LOC: {      // DEBUG_LOC: [line, col, scope, ia]
+    case bitc::FUNC_CODE_DEBUG_LOC:
+      // FIXME: Ignore. Remove this in LLVM 3.0.
+      continue;
+
+    case bitc::FUNC_CODE_DEBUG_LOC2: {      // DEBUG_LOC: [line, col, scope, ia]
       I = 0;     // Get the last instruction emitted.
       if (CurBB && !CurBB->empty())
         I = &CurBB->back();
@@ -2221,7 +2240,12 @@
       InstructionList.push_back(I);
       break;
     }
-    case bitc::FUNC_CODE_INST_CALL: {
+    case bitc::FUNC_CODE_INST_CALL:
+    case bitc::FUNC_CODE_INST_CALL2: {
+      // FIXME: Legacy support for the old call instruction, where function-local
+      // metadata operands were bogus. Remove in LLVM 3.0.
+      bool DropMetadata = BitCode == bitc::FUNC_CODE_INST_CALL;
+
       // CALL: [paramattrs, cc, fnty, fnid, arg0, arg1...]
       if (Record.size() < 3)
         return Error("Invalid CALL record");
@@ -2245,7 +2269,13 @@
       for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
         if (FTy->getParamType(i)->getTypeID()==Type::LabelTyID)
           Args.push_back(getBasicBlock(Record[OpNum]));
-        else
+        else if (DropMetadata &&
+                 FTy->getParamType(i)->getTypeID()==Type::MetadataTyID) {
+          // LLVM 2.7 compatibility: drop metadata arguments to null.
+          Value *Ops = 0;
+          Args.push_back(MDNode::get(Context, &Ops, 1));
+          continue;
+        } else
           Args.push_back(getFnValueByID(Record[OpNum], FTy->getParamType(i)));
         if (Args.back() == 0) return Error("Invalid CALL record");
       }

Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=113557&r1=113556&r2=113557&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Thu Sep  9 18:12:39 2010
@@ -485,8 +485,8 @@
       Record.push_back(0);
     }
   }
-  unsigned MDCode = N->isFunctionLocal() ? bitc::METADATA_FN_NODE :
-                                           bitc::METADATA_NODE;
+  unsigned MDCode = N->isFunctionLocal() ? bitc::METADATA_FN_NODE2 :
+                                           bitc::METADATA_NODE2;
   Stream.EmitRecord(MDCode, Record, 0);
   Record.clear();
 }
@@ -549,7 +549,7 @@
     // Write named metadata operands.
     for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
       Record.push_back(VE.getValueID(NMD->getOperand(i)));
-    Stream.EmitRecord(bitc::METADATA_NAMED_NODE, Record, 0);
+    Stream.EmitRecord(bitc::METADATA_NAMED_NODE2, Record, 0);
     Record.clear();
   }
 
@@ -585,7 +585,7 @@
   SmallVector<uint64_t, 64> Record;
 
   // Write metadata attachments
-  // METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]]
+  // METADATA_ATTACHMENT2 - [m x [value, [n x [id, mdnode]]]
   SmallVector<std::pair<unsigned, MDNode*>, 4> MDs;
   
   for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
@@ -603,7 +603,7 @@
         Record.push_back(MDs[i].first);
         Record.push_back(VE.getValueID(MDs[i].second));
       }
-      Stream.EmitRecord(bitc::METADATA_ATTACHMENT, Record, 0);
+      Stream.EmitRecord(bitc::METADATA_ATTACHMENT2, Record, 0);
       Record.clear();
     }
 
@@ -1111,7 +1111,7 @@
     const PointerType *PTy = cast<PointerType>(CI.getCalledValue()->getType());
     const FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
 
-    Code = bitc::FUNC_CODE_INST_CALL;
+    Code = bitc::FUNC_CODE_INST_CALL2;
 
     Vals.push_back(VE.getAttributeID(CI.getAttributes()));
     Vals.push_back((CI.getCallingConv() << 1) | unsigned(CI.isTailCall()));
@@ -1255,7 +1255,7 @@
         Vals.push_back(DL.getCol());
         Vals.push_back(Scope ? VE.getValueID(Scope)+1 : 0);
         Vals.push_back(IA ? VE.getValueID(IA)+1 : 0);
-        Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals);
+        Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC2, Vals);
         Vals.clear();
         
         LastDL = DL;

Modified: llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp?rev=113557&r1=113556&r2=113557&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp (original)
+++ llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp Thu Sep  9 18:12:39 2010
@@ -236,6 +236,8 @@
     case bitc::FUNC_CODE_INST_VSELECT:      return "INST_VSELECT";
     case bitc::FUNC_CODE_DEBUG_LOC:         return "DEBUG_LOC";
     case bitc::FUNC_CODE_DEBUG_LOC_AGAIN:   return "DEBUG_LOC_AGAIN";
+    case bitc::FUNC_CODE_INST_CALL2:        return "INST_CALL2";
+    case bitc::FUNC_CODE_DEBUG_LOC2:        return "DEBUG_LOC2";
     }
   case bitc::TYPE_SYMTAB_BLOCK_ID:
     switch (CodeID) {
@@ -263,6 +265,10 @@
     case bitc::METADATA_NAMED_NODE:  return "METADATA_NAMED_NODE";
     case bitc::METADATA_KIND:        return "METADATA_KIND";
     case bitc::METADATA_ATTACHMENT:  return "METADATA_ATTACHMENT";
+    case bitc::METADATA_NODE2:       return "METADATA_NODE2";
+    case bitc::METADATA_FN_NODE2:    return "METADATA_FN_NODE2";
+    case bitc::METADATA_NAMED_NODE2: return "METADATA_NAMED_NODE2";
+    case bitc::METADATA_ATTACHMENT2: return "METADATA_ATTACHMENT2";
     }
   }
 }





More information about the llvm-commits mailing list