For PR950: Implement read/write of ICmp and FCmp constant expressions
authorReid Spencer <rspencer@reidspencer.com>
Mon, 4 Dec 2006 05:23:49 +0000 (05:23 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Mon, 4 Dec 2006 05:23:49 +0000 (05:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32172 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bytecode/Reader/Reader.cpp
lib/Bytecode/Writer/Writer.cpp

index 9286279216e39abddc5b5b58052aeb6dcb694e53..3cc3b1d362bf9328ccdb1b873461bc8759856c83 100644 (file)
@@ -1355,14 +1355,18 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) {
       return Result;
     } else if (Opcode == Instruction::ICmp) {
       if (ArgVec.size() != 2) 
-        error("Invalid ICmp constant expr arguments");
-      unsigned short pred = read_vbr_uint();
-      return ConstantExpr::getICmp(pred, ArgVec[0], ArgVec[1]);
+        error("Invalid ICmp constant expr arguments.");
+      unsigned predicate = read_vbr_uint();
+      Constant *Result = ConstantExpr::getICmp(predicate, ArgVec[0], ArgVec[1]);
+      if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result);
+      return Result;
     } else if (Opcode == Instruction::FCmp) {
       if (ArgVec.size() != 2) 
-        error("Invalid FCmp constant expr arguments");
-      unsigned short pred = read_vbr_uint();
-      return ConstantExpr::getFCmp(pred, ArgVec[0], ArgVec[1]);
+        error("Invalid FCmp constant expr arguments.");
+      unsigned predicate = read_vbr_uint();
+      Constant *Result = ConstantExpr::getFCmp(predicate, ArgVec[0], ArgVec[1]);
+      if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result);
+      return Result;
     } else {                            // All other 2-operand expressions
       Constant* Result = ConstantExpr::get(Opcode, ArgVec[0], ArgVec[1]);
       if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result);
index 127a3bac003ce06a54057c8fc82d75ac896e175c..fdd0f3ca427a5e673d904716a3859cd94f2e0ffb 100644 (file)
@@ -303,6 +303,8 @@ void BytecodeWriter::outputConstant(const Constant *CPV) {
       Slot = Table.getSlot((*OI)->getType());
       output_typeid((unsigned)Slot);
     }
+    if (CE->isCompare())
+      output_vbr((unsigned)CE->getPredicate());
     return;
   } else if (isa<UndefValue>(CPV)) {
     output_vbr(1U);       // 1 -> UndefValue constant.