[llvm-commits] [llvm] r53887 - in /llvm/trunk: include/llvm/Bitcode/LLVMBitCodes.h lib/Bitcode/Reader/BitcodeReader.cpp lib/Bitcode/Writer/BitcodeWriter.cpp lib/VMCore/Constants.cpp

Dan Gohman gohman at apple.com
Mon Jul 21 16:30:30 PDT 2008


Author: djg
Date: Mon Jul 21 18:30:30 2008
New Revision: 53887

URL: http://llvm.org/viewvc/llvm-project?rev=53887&view=rev
Log:
InsertValue and ExtractValue constant expressions are always
folded. Remove code that handled the case where they aren't
folded, and remove bitcode reader/writer support for them.

Modified:
    llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
    llvm/trunk/lib/VMCore/Constants.cpp

Modified: llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h?rev=53887&r1=53886&r2=53887&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h (original)
+++ llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h Mon Jul 21 18:30:30 2008
@@ -125,9 +125,7 @@
     CST_CODE_CE_INSERTELT  = 15,  // CE_INSERTELT:  [opval, opval, opval]
     CST_CODE_CE_SHUFFLEVEC = 16,  // CE_SHUFFLEVEC: [opval, opval, opval]
     CST_CODE_CE_CMP        = 17,  // CE_CMP:        [opty, opval, opval, pred]
-    CST_CODE_INLINEASM     = 18,  // INLINEASM:     [sideeffect,asmstr,conststr]
-    CST_CODE_CE_EXTRACTVAL = 19,  // CE_EXTRACTVAL: [n x operands]
-    CST_CODE_CE_INSERTVAL  = 20   // CE_INSERTVAL:  [n x operands]
+    CST_CODE_INLINEASM     = 18   // INLINEASM:     [sideeffect,asmstr,conststr]
   };
   
   /// CastOpcodes - These are values used in the bitcode files to encode which

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=53887&r1=53886&r2=53887&view=diff

==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Mon Jul 21 18:30:30 2008
@@ -770,47 +770,6 @@
       V = ConstantExpr::getGetElementPtr(Elts[0], &Elts[1], Elts.size()-1);
       break;
     }
-    case bitc::CST_CODE_CE_EXTRACTVAL: {
-                                    // CE_EXTRACTVAL: [opty, opval, n x indices]
-      const Type *AggTy = getTypeByID(Record[0]);
-      if (!AggTy || !AggTy->isAggregateType())
-        return Error("Invalid CE_EXTRACTVAL record");
-      Constant *Agg = ValueList.getConstantFwdRef(Record[1], AggTy);
-      SmallVector<unsigned, 4> Indices;
-      for (unsigned i = 2, e = Record.size(); i != e; ++i) {
-        uint64_t Index = Record[i];
-        if ((unsigned)Index != Index)
-          return Error("Invalid CE_EXTRACTVAL record");
-        Indices.push_back((unsigned)Index);
-      }
-      if (!ExtractValueInst::getIndexedType(AggTy,
-                                            Indices.begin(), Indices.end()))
-        return Error("Invalid CE_EXTRACTVAL record");
-      V = ConstantExpr::getExtractValue(Agg, &Indices[0], Indices.size());
-      break;
-    }
-    case bitc::CST_CODE_CE_INSERTVAL: {
-                        // CE_INSERTVAL: [opty, opval, opty, opval, n x indices]
-      const Type *AggTy = getTypeByID(Record[0]);
-      if (!AggTy || !AggTy->isAggregateType())
-        return Error("Invalid CE_INSERTVAL record");
-      Constant *Agg = ValueList.getConstantFwdRef(Record[1], AggTy);
-      const Type *ValTy = getTypeByID(Record[2]);
-      Constant *Val = ValueList.getConstantFwdRef(Record[3], ValTy);
-      SmallVector<unsigned, 4> Indices;
-      for (unsigned i = 4, e = Record.size(); i != e; ++i) {
-        uint64_t Index = Record[i];
-        if ((unsigned)Index != Index)
-          return Error("Invalid CE_INSERTVAL record");
-        Indices.push_back((unsigned)Index);
-      }
-      if (ExtractValueInst::getIndexedType(AggTy,
-                                           Indices.begin(),
-                                           Indices.end()) != ValTy)
-        return Error("Invalid CE_INSERTVAL record");
-      V = ConstantExpr::getInsertValue(Agg, Val, &Indices[0], Indices.size());
-      break;
-    }
     case bitc::CST_CODE_CE_SELECT:  // CE_SELECT: [opval#, opval#, opval#]
       if (Record.size() < 3) return Error("Invalid CE_SELECT record");
       V = ConstantExpr::getSelect(ValueList.getConstantFwdRef(Record[0],

Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=53887&r1=53886&r2=53887&view=diff

==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Mon Jul 21 18:30:30 2008
@@ -611,26 +611,6 @@
           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)));

Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=53887&r1=53886&r2=53887&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Mon Jul 21 18:30:30 2008
@@ -857,19 +857,6 @@
     Op1 = (OpNo == 1) ? Op : getOperand(1);
     Op2 = (OpNo == 2) ? Op : getOperand(2);
     return ConstantExpr::getShuffleVector(Op0, Op1, Op2);
-  case Instruction::InsertValue: {
-    const SmallVector<unsigned, 4> &Indices = getIndices();
-    Op0 = (OpNo == 0) ? Op : getOperand(0);
-    Op1 = (OpNo == 1) ? Op : getOperand(1);
-    return ConstantExpr::getInsertValue(Op0, Op1,
-                                        &Indices[0], Indices.size());
-  }
-  case Instruction::ExtractValue: {
-    assert(OpNo == 0 && "ExtractaValue has only one operand!");
-    const SmallVector<unsigned, 4> &Indices = getIndices();
-    return
-      ConstantExpr::getExtractValue(Op, &Indices[0], Indices.size());
-  }
   case Instruction::GetElementPtr: {
     SmallVector<Constant*, 8> Ops;
     Ops.resize(getNumOperands()-1);
@@ -925,16 +912,6 @@
     return ConstantExpr::getExtractElement(Ops[0], Ops[1]);
   case Instruction::ShuffleVector:
     return ConstantExpr::getShuffleVector(Ops[0], Ops[1], Ops[2]);
-  case Instruction::InsertValue: {
-    const SmallVector<unsigned, 4> &Indices = getIndices();
-    return ConstantExpr::getInsertValue(Ops[0], Ops[1],
-                                        &Indices[0], Indices.size());
-  }
-  case Instruction::ExtractValue: {
-    const SmallVector<unsigned, 4> &Indices = getIndices();
-    return ConstantExpr::getExtractValue(Ops[0],
-                                         &Indices[0], Indices.size());
-  }
   case Instruction::GetElementPtr:
     return ConstantExpr::getGetElementPtr(Ops[0], &Ops[1], Ops.size()-1);
   case Instruction::ICmp:
@@ -2365,15 +2342,9 @@
          "insertvalue type invalid!");
   assert(Agg->getType()->isFirstClassType() &&
          "Non-first-class type for constant InsertValue expression");
-  if (Constant *FC = ConstantFoldInsertValueInstruction(Agg, Val, Idxs, NumIdx))
-    return FC;          // Fold a few common cases...
-  // Look up the constant in the table first to ensure uniqueness
-  std::vector<Constant*> ArgVec;
-  ArgVec.push_back(Agg);
-  ArgVec.push_back(Val);
-  SmallVector<unsigned, 4> Indices(Idxs, Idxs + NumIdx);
-  const ExprMapKeyType Key(Instruction::InsertValue, ArgVec, 0, Indices);
-  return ExprConstants->getOrCreate(ReqTy, Key);
+  Constant *FC = ConstantFoldInsertValueInstruction(Agg, Val, Idxs, NumIdx);
+  assert(FC && "InsertValue constant expr couldn't be folded!");
+  return FC;
 }
 
 Constant *ConstantExpr::getInsertValue(Constant *Agg, Constant *Val,
@@ -2395,14 +2366,9 @@
          "extractvalue indices invalid!");
   assert(Agg->getType()->isFirstClassType() &&
          "Non-first-class type for constant extractvalue expression");
-  if (Constant *FC = ConstantFoldExtractValueInstruction(Agg, Idxs, NumIdx))
-    return FC;          // Fold a few common cases...
-  // Look up the constant in the table first to ensure uniqueness
-  std::vector<Constant*> ArgVec;
-  ArgVec.push_back(Agg);
-  SmallVector<unsigned, 4> Indices(Idxs, Idxs + NumIdx);
-  const ExprMapKeyType Key(Instruction::ExtractValue, ArgVec, 0, Indices);
-  return ExprConstants->getOrCreate(ReqTy, Key);
+  Constant *FC = ConstantFoldExtractValueInstruction(Agg, Idxs, NumIdx);
+  assert(FC && "ExtractValue constant expr couldn't be folded!");
+  return FC;
 }
 
 Constant *ConstantExpr::getExtractValue(Constant *Agg,





More information about the llvm-commits mailing list