Encoding calling conv info in call/invoke instrs, tree add now round trips completely
[oota-llvm.git] / lib / Bitcode / Writer / BitcodeWriter.cpp
index f4ebeeaffdcda7b85c0e066629543ee4f6297e1c..6dcc37296c11ab5479cc75aeef988406013b8652 100644 (file)
@@ -507,7 +507,6 @@ static void WriteInstruction(const Instruction &I, ValueEnumerator &VE,
 
   case Instruction::GetElementPtr:
     Code = bitc::FUNC_CODE_INST_GEP;
-    Vals.push_back(I.getNumOperands());
     for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) {
       Vals.push_back(VE.getTypeID(I.getOperand(i)->getType()));
       Vals.push_back(VE.getValueID(I.getOperand(i)));
@@ -567,13 +566,12 @@ static void WriteInstruction(const Instruction &I, ValueEnumerator &VE,
   case Instruction::Switch:
     Code = bitc::FUNC_CODE_INST_SWITCH;
     Vals.push_back(VE.getTypeID(I.getOperand(0)->getType()));
-    Vals.push_back(I.getNumOperands());
     for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i)
       Vals.push_back(VE.getValueID(I.getOperand(i)));
     break;
   case Instruction::Invoke: {
     Code = bitc::FUNC_CODE_INST_INVOKE;
-    // FIXME: param attrs
+    Vals.push_back(cast<InvokeInst>(I).getCallingConv());
     Vals.push_back(VE.getTypeID(I.getOperand(0)->getType()));
     Vals.push_back(VE.getValueID(I.getOperand(0)));  // callee
     Vals.push_back(VE.getValueID(I.getOperand(1)));  // normal
@@ -649,7 +647,8 @@ static void WriteInstruction(const Instruction &I, ValueEnumerator &VE,
     break;
   case Instruction::Call: {
     Code = bitc::FUNC_CODE_INST_CALL;
-    // FIXME: param attrs
+    Vals.push_back((cast<CallInst>(I).getCallingConv() << 1) |
+                   cast<CallInst>(I).isTailCall());
     Vals.push_back(VE.getTypeID(I.getOperand(0)->getType()));
     Vals.push_back(VE.getValueID(I.getOperand(0)));  // callee
     
@@ -662,7 +661,6 @@ static void WriteInstruction(const Instruction &I, ValueEnumerator &VE,
     // Emit type/value pairs for varargs params.
     if (FTy->isVarArg()) {
       unsigned NumVarargs = I.getNumOperands()-1-FTy->getNumParams();
-      Vals.push_back(NumVarargs);
       for (unsigned i = I.getNumOperands()-NumVarargs, e = I.getNumOperands();
            i != e; ++i) {
         Vals.push_back(VE.getTypeID(I.getOperand(i)->getType()));
@@ -671,7 +669,6 @@ static void WriteInstruction(const Instruction &I, ValueEnumerator &VE,
     }
     break;
   }
-    
   case Instruction::VAArg:
     Code = bitc::FUNC_CODE_INST_VAARG;
     Vals.push_back(VE.getTypeID(I.getOperand(0)->getType()));   // valistty
@@ -699,16 +696,23 @@ static void WriteValueSymbolTable(const ValueSymbolTable &VST,
        SI != SE; ++SI) {
     unsigned AbbrevToUse = 0;
     
-    // VST_ENTRY: [valueid, namelen, namechar x N]
-    NameVals.push_back(VE.getValueID(SI->getValue()));
+    // VST_ENTRY:   [valueid, namelen, namechar x N]
+    // VST_BBENTRY: [bbid, namelen, namechar x N]
+    unsigned Code;
+    if (isa<BasicBlock>(SI->getValue())) {
+      Code = bitc::VST_CODE_BBENTRY;
+    } else {
+      Code = bitc::VST_CODE_ENTRY;
+    }
     
+    NameVals.push_back(VE.getValueID(SI->getValue()));
     NameVals.push_back(SI->getKeyLength());
     for (const char *P = SI->getKeyData(),
          *E = SI->getKeyData()+SI->getKeyLength(); P != E; ++P)
       NameVals.push_back((unsigned char)*P);
     
     // Emit the finished record.
-    Stream.EmitRecord(bitc::VST_CODE_ENTRY, NameVals, AbbrevToUse);
+    Stream.EmitRecord(Code, NameVals, AbbrevToUse);
     NameVals.clear();
   }
   Stream.ExitBlock();