Use parameter attribute store (soon to be renamed) for
[oota-llvm.git] / lib / Bitcode / Writer / BitcodeWriter.cpp
index 9794fac009c25c2ca0e8414ce8ea92bb705364fd..931e944a410d1dc13f9abe128a4b5b95771cfb2f 100644 (file)
@@ -23,6 +23,7 @@
 #include "llvm/TypeSymbolTable.h"
 #include "llvm/ValueSymbolTable.h"
 #include "llvm/Support/MathExtras.h"
+#include "llvm/Support/Streams.h"
 #include "llvm/System/Program.h"
 using namespace llvm;
 
@@ -303,10 +304,10 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
     WriteStringRecord(bitc::MODULE_CODE_ASM, M->getModuleInlineAsm(),
                       0/*TODO*/, Stream);
 
-  // Emit information about sections and collectors, computing how many there
-  // are.  Also compute the maximum alignment value.
+  // Emit information about sections and GC, computing how many there are. Also
+  // compute the maximum alignment value.
   std::map<std::string, unsigned> SectionMap;
-  std::map<std::string, unsigned> CollectorMap;
+  std::map<std::string, unsigned> GCMap;
   unsigned MaxAlignment = 0;
   unsigned MaxGlobalType = 0;
   for (Module::const_global_iterator GV = M->global_begin(),E = M->global_end();
@@ -333,13 +334,13 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
         Entry = SectionMap.size();
       }
     }
-    if (F->hasCollector()) {
-      // Same for collector names.
-      unsigned &Entry = CollectorMap[F->getCollector()];
+    if (F->hasGC()) {
+      // Same for GC names.
+      unsigned &Entry = GCMap[F->getGC()];
       if (!Entry) {
-        WriteStringRecord(bitc::MODULE_CODE_COLLECTORNAME, F->getCollector(),
+        WriteStringRecord(bitc::MODULE_CODE_GCNAME, F->getGC(),
                           0/*TODO*/, Stream);
-        Entry = CollectorMap.size();
+        Entry = GCMap.size();
       }
     }
   }
@@ -401,7 +402,7 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
   // Emit the function proto information.
   for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) {
     // FUNCTION:  [type, callingconv, isproto, paramattr,
-    //             linkage, alignment, section, visibility, collector]
+    //             linkage, alignment, section, visibility, gc]
     Vals.push_back(VE.getTypeID(F->getType()));
     Vals.push_back(F->getCallingConv());
     Vals.push_back(F->isDeclaration());
@@ -410,7 +411,7 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
     Vals.push_back(Log2_32(F->getAlignment())+1);
     Vals.push_back(F->hasSection() ? SectionMap[F->getSection()] : 0);
     Vals.push_back(getEncodedVisibility(F));
-    Vals.push_back(F->hasCollector() ? CollectorMap[F->getCollector()] : 0);
+    Vals.push_back(F->hasGC() ? GCMap[F->getGC()] : 0);
     
     unsigned AbbrevToUse = 0;
     Stream.EmitRecord(bitc::MODULE_CODE_FUNCTION, Vals, AbbrevToUse);
@@ -611,26 +612,6 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
           Record.push_back(VE.getValueID(C->getOperand(i)));
         }
         break;
-      case Instruction::ExtractValue: {
-        Code = bitc::CST_CODE_CE_EXTRACTVAL;
-        Record.push_back(VE.getTypeID(C->getOperand(0)->getType()));
-        Record.push_back(VE.getValueID(C->getOperand(0)));
-        const SmallVector<unsigned, 4> &Indices = CE->getIndices();
-        for (unsigned i = 0, e = Indices.size(); i != e; ++i)
-          Record.push_back(Indices[i]);
-        break;
-      }
-      case Instruction::InsertValue: {
-        Code = bitc::CST_CODE_CE_INSERTVAL;
-        Record.push_back(VE.getTypeID(C->getOperand(0)->getType()));
-        Record.push_back(VE.getValueID(C->getOperand(0)));
-        Record.push_back(VE.getTypeID(C->getOperand(1)->getType()));
-        Record.push_back(VE.getValueID(C->getOperand(1)));
-        const SmallVector<unsigned, 4> &Indices = CE->getIndices();
-        for (unsigned i = 0, e = Indices.size(); i != e; ++i)
-          Record.push_back(Indices[i]);
-        break;
-      }
       case Instruction::Select:
         Code = bitc::CST_CODE_CE_SELECT;
         Record.push_back(VE.getValueID(C->getOperand(0)));
@@ -659,7 +640,14 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
       case Instruction::FCmp:
       case Instruction::VICmp:
       case Instruction::VFCmp:
-        Code = bitc::CST_CODE_CE_CMP;
+        if (isa<VectorType>(C->getOperand(0)->getType())
+            && (CE->getOpcode() == Instruction::ICmp
+                || CE->getOpcode() == Instruction::FCmp)) {
+          // compare returning vector of Int1Ty
+          assert(0 && "Unsupported constant!");
+        } else {
+          Code = bitc::CST_CODE_CE_CMP;
+        }
         Record.push_back(VE.getTypeID(C->getOperand(0)->getType()));
         Record.push_back(VE.getValueID(C->getOperand(0)));
         Record.push_back(VE.getValueID(C->getOperand(1)));
@@ -757,10 +745,10 @@ static void WriteInstruction(const Instruction &I, unsigned InstID,
     break;
   }
   case Instruction::Select:
-    Code = bitc::FUNC_CODE_INST_SELECT;
+    Code = bitc::FUNC_CODE_INST_VSELECT;
     PushValueAndType(I.getOperand(1), InstID, Vals, VE);
     Vals.push_back(VE.getValueID(I.getOperand(2)));
-    Vals.push_back(VE.getValueID(I.getOperand(0)));
+    PushValueAndType(I.getOperand(0), InstID, Vals, VE);
     break;
   case Instruction::ExtractElement:
     Code = bitc::FUNC_CODE_INST_EXTRACTELT;
@@ -783,16 +771,17 @@ static void WriteInstruction(const Instruction &I, unsigned InstID,
   case Instruction::FCmp:
   case Instruction::VICmp:
   case Instruction::VFCmp:
-    Code = bitc::FUNC_CODE_INST_CMP;
+    if (I.getOpcode() == Instruction::ICmp
+        || I.getOpcode() == Instruction::FCmp) {
+      // compare returning Int1Ty or vector of Int1Ty
+      Code = bitc::FUNC_CODE_INST_CMP2;
+    } else {
+      Code = bitc::FUNC_CODE_INST_CMP;
+    }
     PushValueAndType(I.getOperand(0), InstID, Vals, VE);
     Vals.push_back(VE.getValueID(I.getOperand(1)));
     Vals.push_back(cast<CmpInst>(I).getPredicate());
     break;
-  case Instruction::GetResult:
-    Code = bitc::FUNC_CODE_INST_GETRESULT;
-    PushValueAndType(I.getOperand(0), InstID, Vals, VE);
-    Vals.push_back(cast<GetResultInst>(I).getIndex());
-    break;
 
   case Instruction::Ret: 
     {