Dump the old va_arg and va_next upgrade support. No need to keep track of
[oota-llvm.git] / lib / AsmParser / llvmAsmParser.y
index f9a090a1634ddc83c14082e068d2b2d57bc9c86b..51fe7c9cc5c707af04549bba38ae1003124a48d5 100644 (file)
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
 #include "llvm/SymbolTable.h"
-#include "llvm/Assembly/AutoUpgrade.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/MathExtras.h"
+#include "llvm/Support/Streams.h"
 #include <algorithm>
-#include <iostream>
 #include <list>
 #include <utility>
 
@@ -58,16 +57,14 @@ static Module *ParserResult;
 //
 //#define DEBUG_UPREFS 1
 #ifdef DEBUG_UPREFS
-#define UR_OUT(X) std::cerr << X
+#define UR_OUT(X) llvm_cerr << X
 #else
 #define UR_OUT(X)
 #endif
 
 #define YYERROR_VERBOSE 1
 
-static bool ObsoleteVarArgs;
 static bool NewVarArgs;
-static BasicBlock *CurBB;
 static GlobalVariable *CurGV;
 
 
@@ -124,11 +121,6 @@ static struct PerModuleInfo {
       return;
     }
 
-    // Look for intrinsic functions and CallInst that need to be upgraded
-    for (Module::iterator FI = CurrentModule->begin(),
-         FE = CurrentModule->end(); FI != FE; )
-      UpgradeCallsToIntrinsic(FI++);
-
     Values.clear();         // Clear out function local definitions
     Types.clear();
     CurrentModule = 0;
@@ -813,78 +805,10 @@ static PATypeHolder HandleUpRefs(const Type *ty) {
   return Ty;
 }
 
-/// This function is used to obtain the correct opcode for an instruction when 
-/// an obsolete opcode is encountered. The OI parameter (OpcodeInfo) has both 
-/// an opcode and an "obsolete" flag. These are generated by the lexer and 
-/// the "obsolete" member will be true when the lexer encounters the token for
-/// an obsolete opcode. For example, "div" was replaced by [usf]div but we need
-/// to maintain backwards compatibility for asm files that still have the "div"
-/// instruction. This function handles converting div -> [usf]div appropriately.
-/// @brief Convert obsolete BinaryOps opcodes to new values
-static void 
-sanitizeOpCode(OpcodeInfo<Instruction::BinaryOps> &OI, const PATypeHolder& PATy)
-{
-  // If its not obsolete, don't do anything
-  if (!OI.obsolete) 
-    return;
-
-  // If its a packed type we want to use the element type
-  const Type* Ty = PATy;
-  if (const PackedType* PTy = dyn_cast<PackedType>(Ty))
-    Ty = PTy->getElementType();
-
-  // Depending on the opcode ..
-  switch (OI.opcode) {
-    default:
-      GenerateError("Invalid obsolete opCode (check Lexer.l)");
-      break;
-    case Instruction::UDiv:
-      // Handle cases where the opcode needs to change
-      if (Ty->isFloatingPoint()) 
-        OI.opcode = Instruction::FDiv;
-      else if (Ty->isSigned())
-        OI.opcode = Instruction::SDiv;
-      break;
-    case Instruction::URem:
-      if (Ty->isFloatingPoint()) 
-        OI.opcode = Instruction::FRem;
-      else if (Ty->isSigned())
-        OI.opcode = Instruction::SRem;
-      break;
-  }
-  // Its not obsolete any more, we fixed it.
-  OI.obsolete = false;
-}
-
-/// This function is similar to the previous overload of sanitizeOpCode but
-/// operates on Instruction::OtherOps instead of Instruction::BinaryOps.
-/// @brief Convert obsolete OtherOps opcodes to new values
-static void 
-sanitizeOpCode(OpcodeInfo<Instruction::OtherOps> &OI, const PATypeHolder& PATy)
-{
-  // If its not obsolete, don't do anything
-  if (!OI.obsolete) 
-    return;
-
-  const Type* Ty = PATy; // type conversion
-  switch (OI.opcode) {
-  default:
-    GenerateError("Invalid obsolete opcode (check Lexer.l)");
-    break;
-  case Instruction::LShr:
-    if (Ty->isSigned())
-      OI.opcode = Instruction::AShr;
-    break;
-  }
-  // Its not obsolete any more, we fixed it.
-  OI.obsolete = false;
-}
-
 // common code from the two 'RunVMAsmParser' functions
 static Module* RunParser(Module * M) {
 
   llvmAsmlineno = 1;      // Reset the current line number...
-  ObsoleteVarArgs = false;
   NewVarArgs = false;
   CurModule.CurrentModule = M;
 
@@ -903,113 +827,6 @@ static Module* RunParser(Module * M) {
   Module *Result = ParserResult;
   ParserResult = 0;
 
-  //Not all functions use vaarg, so make a second check for ObsoleteVarArgs
-  {
-    Function* F;
-    if ((F = Result->getNamedFunction("llvm.va_start"))
-        && F->getFunctionType()->getNumParams() == 0)
-      ObsoleteVarArgs = true;
-    if((F = Result->getNamedFunction("llvm.va_copy"))
-       && F->getFunctionType()->getNumParams() == 1)
-      ObsoleteVarArgs = true;
-  }
-
-  if (ObsoleteVarArgs && NewVarArgs) {
-    GenerateError(
-      "This file is corrupt: it uses both new and old style varargs");
-    return 0;
-  }
-
-  if(ObsoleteVarArgs) {
-    if(Function* F = Result->getNamedFunction("llvm.va_start")) {
-      if (F->arg_size() != 0) {
-        GenerateError("Obsolete va_start takes 0 argument!");
-        return 0;
-      }
-      
-      //foo = va_start()
-      // ->
-      //bar = alloca typeof(foo)
-      //va_start(bar)
-      //foo = load bar
-
-      const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
-      const Type* ArgTy = F->getFunctionType()->getReturnType();
-      const Type* ArgTyPtr = PointerType::get(ArgTy);
-      Function* NF = Result->getOrInsertFunction("llvm.va_start", 
-                                                 RetTy, ArgTyPtr, (Type *)0);
-
-      while (!F->use_empty()) {
-        CallInst* CI = cast<CallInst>(F->use_back());
-        AllocaInst* bar = new AllocaInst(ArgTy, 0, "vastart.fix.1", CI);
-        new CallInst(NF, bar, "", CI);
-        Value* foo = new LoadInst(bar, "vastart.fix.2", CI);
-        CI->replaceAllUsesWith(foo);
-        CI->getParent()->getInstList().erase(CI);
-      }
-      Result->getFunctionList().erase(F);
-    }
-    
-    if(Function* F = Result->getNamedFunction("llvm.va_end")) {
-      if(F->arg_size() != 1) {
-        GenerateError("Obsolete va_end takes 1 argument!");
-        return 0;
-      }
-
-      //vaend foo
-      // ->
-      //bar = alloca 1 of typeof(foo)
-      //vaend bar
-      const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
-      const Type* ArgTy = F->getFunctionType()->getParamType(0);
-      const Type* ArgTyPtr = PointerType::get(ArgTy);
-      Function* NF = Result->getOrInsertFunction("llvm.va_end", 
-                                                 RetTy, ArgTyPtr, (Type *)0);
-
-      while (!F->use_empty()) {
-        CallInst* CI = cast<CallInst>(F->use_back());
-        AllocaInst* bar = new AllocaInst(ArgTy, 0, "vaend.fix.1", CI);
-        new StoreInst(CI->getOperand(1), bar, CI);
-        new CallInst(NF, bar, "", CI);
-        CI->getParent()->getInstList().erase(CI);
-      }
-      Result->getFunctionList().erase(F);
-    }
-
-    if(Function* F = Result->getNamedFunction("llvm.va_copy")) {
-      if(F->arg_size() != 1) {
-        GenerateError("Obsolete va_copy takes 1 argument!");
-        return 0;
-      }
-      //foo = vacopy(bar)
-      // ->
-      //a = alloca 1 of typeof(foo)
-      //b = alloca 1 of typeof(foo)
-      //store bar -> b
-      //vacopy(a, b)
-      //foo = load a
-      
-      const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
-      const Type* ArgTy = F->getFunctionType()->getReturnType();
-      const Type* ArgTyPtr = PointerType::get(ArgTy);
-      Function* NF = Result->getOrInsertFunction("llvm.va_copy", 
-                                                 RetTy, ArgTyPtr, ArgTyPtr,
-                                                 (Type *)0);
-
-      while (!F->use_empty()) {
-        CallInst* CI = cast<CallInst>(F->use_back());
-        AllocaInst* a = new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI);
-        AllocaInst* b = new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI);
-        new StoreInst(CI->getOperand(1), b, CI);
-        new CallInst(NF, a, b, "", CI);
-        Value* foo = new LoadInst(a, "vacopy.fix.3", CI);
-        CI->replaceAllUsesWith(foo);
-        CI->getParent()->getInstList().erase(CI);
-      }
-      Result->getFunctionList().erase(F);
-    }
-  }
-
   return Result;
 }
 
@@ -1070,11 +887,14 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
   char                             *StrVal;   // This memory is strdup'd!
   llvm::ValID                       ValIDVal; // strdup'd memory maybe!
 
-  BinaryOpInfo                      BinaryOpVal;
-  TermOpInfo                        TermOpVal;
-  MemOpInfo                         MemOpVal;
-  OtherOpInfo                       OtherOpVal;
+  llvm::Instruction::BinaryOps      BinaryOpVal;
+  llvm::Instruction::TermOps        TermOpVal;
+  llvm::Instruction::MemoryOps      MemOpVal;
+  llvm::Instruction::CastOps        CastOpVal;
+  llvm::Instruction::OtherOps       OtherOpVal;
   llvm::Module::Endianness          Endianness;
+  llvm::ICmpInst::Predicate         IPredicate;
+  llvm::FCmpInst::Predicate         FPredicate;
 }
 
 %type <ModuleVal>     Module FunctionList
@@ -1144,15 +964,24 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
 %type  <BinaryOpVal> ArithmeticOps LogicalOps SetCondOps // Binops Subcatagories
 %token <BinaryOpVal> ADD SUB MUL UDIV SDIV FDIV UREM SREM FREM AND OR XOR
 %token <BinaryOpVal> SETLE SETGE SETLT SETGT SETEQ SETNE  // Binary Comparators
+%token <OtherOpVal> ICMP FCMP
+%type  <IPredicate> IPredicates
+%type  <FPredicate> FPredicates
+%token  EQ NE SLT SGT SLE SGE ULT UGT ULE UGE 
+%token  OEQ ONE OLT OGT OLE OGE ORD UNO UEQ UNE
 
 // Memory Instructions
 %token <MemOpVal> MALLOC ALLOCA FREE LOAD STORE GETELEMENTPTR
 
+// Cast Operators
+%type <CastOpVal> CastOps
+%token <CastOpVal> TRUNC ZEXT SEXT FPTRUNC FPEXT BITCAST
+%token <CastOpVal> UITOFP SITOFP FPTOUI FPTOSI INTTOPTR PTRTOINT
+
 // Other Operators
 %type  <OtherOpVal> ShiftOps
-%token <OtherOpVal> PHI_TOK CAST SELECT SHL LSHR ASHR VAARG
+%token <OtherOpVal> PHI_TOK SELECT SHL LSHR ASHR VAARG
 %token <OtherOpVal> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
-%token VAARG_old VANEXT_old //OBSOLETE
 
 
 %start Module
@@ -1183,8 +1012,28 @@ EINT64VAL : EUINT64VAL {
 ArithmeticOps: ADD | SUB | MUL | UDIV | SDIV | FDIV | UREM | SREM | FREM;
 LogicalOps   : AND | OR | XOR;
 SetCondOps   : SETLE | SETGE | SETLT | SETGT | SETEQ | SETNE;
-
-ShiftOps  : SHL | LSHR | ASHR;
+CastOps      : TRUNC | ZEXT | SEXT | FPTRUNC | FPEXT | BITCAST | 
+               UITOFP | SITOFP | FPTOUI | FPTOSI | INTTOPTR | PTRTOINT;
+ShiftOps     : SHL | LSHR | ASHR;
+IPredicates  
+  : EQ   { $$ = ICmpInst::ICMP_EQ; }  | NE   { $$ = ICmpInst::ICMP_NE; }
+  | SLT  { $$ = ICmpInst::ICMP_SLT; } | SGT  { $$ = ICmpInst::ICMP_SGT; }
+  | SLE  { $$ = ICmpInst::ICMP_SLE; } | SGE  { $$ = ICmpInst::ICMP_SGE; }
+  | ULT  { $$ = ICmpInst::ICMP_ULT; } | UGT  { $$ = ICmpInst::ICMP_UGT; }
+  | ULE  { $$ = ICmpInst::ICMP_ULE; } | UGE  { $$ = ICmpInst::ICMP_UGE; } 
+  ;
+
+FPredicates  
+  : OEQ  { $$ = FCmpInst::FCMP_OEQ; } | ONE  { $$ = FCmpInst::FCMP_ONE; }
+  | OLT  { $$ = FCmpInst::FCMP_OLT; } | OGT  { $$ = FCmpInst::FCMP_OGT; }
+  | OLE  { $$ = FCmpInst::FCMP_OLE; } | OGE  { $$ = FCmpInst::FCMP_OGE; }
+  | ORD  { $$ = FCmpInst::FCMP_ORD; } | UNO  { $$ = FCmpInst::FCMP_UNO; }
+  | UEQ  { $$ = FCmpInst::FCMP_UEQ; } | UNE  { $$ = FCmpInst::FCMP_UNE; }
+  | ULT  { $$ = FCmpInst::FCMP_ULT; } | UGT  { $$ = FCmpInst::FCMP_UGT; }
+  | ULE  { $$ = FCmpInst::FCMP_ULE; } | UGE  { $$ = FCmpInst::FCMP_UGE; }
+  | TRUETOK { $$ = FCmpInst::FCMP_TRUE; }
+  | FALSETOK { $$ = FCmpInst::FCMP_FALSE; }
+  ;
 
 // These are some types that allow classification if we only want a particular 
 // thing... for example, only a signed, unsigned, or integral type.
@@ -1624,9 +1473,8 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
     $$ = Constant::getNullValue(Ty);
     delete $1;
     CHECK_FOR_ERROR
-  };
-
-ConstVal : SIntType EINT64VAL {      // integral constants
+  }
+  | SIntType EINT64VAL {      // integral constants
     if (!ConstantInt::isValueValidForType($1, $2))
       GEN_ERROR("Constant value doesn't fit in type!");
     $$ = ConstantInt::get($1, $2);
@@ -1654,32 +1502,22 @@ ConstVal : SIntType EINT64VAL {      // integral constants
   };
 
 
-ConstExpr: CAST '(' ConstVal TO Types ')' {
-    if (!$3->getType()->isFirstClassType())
+ConstExpr: CastOps '(' ConstVal TO Types ')' {
+    Constant *Val = $3;
+    const Type *Ty = $5->get();
+    if (!Val->getType()->isFirstClassType())
       GEN_ERROR("cast constant expression from a non-primitive type: '" +
-                     $3->getType()->getDescription() + "'!");
-    if (!$5->get()->isFirstClassType())
+                     Val->getType()->getDescription() + "'!");
+    if (!Ty->isFirstClassType())
       GEN_ERROR("cast constant expression to a non-primitive type: '" +
-                     $5->get()->getDescription() + "'!");
-    $$ = ConstantExpr::getCast($3, $5->get());
+                Ty->getDescription() + "'!");
+    $$ = ConstantExpr::getCast($1, $3, $5->get());
     delete $5;
-    CHECK_FOR_ERROR
   }
   | GETELEMENTPTR '(' ConstVal IndexList ')' {
     if (!isa<PointerType>($3->getType()))
       GEN_ERROR("GetElementPtr requires a pointer operand!");
 
-    // LLVM 1.2 and earlier used ubyte struct indices.  Convert any ubyte struct
-    // indices to uint struct indices for compatibility.
-    generic_gep_type_iterator<std::vector<Value*>::iterator>
-      GTI = gep_type_begin($3->getType(), $4->begin(), $4->end()),
-      GTE = gep_type_end($3->getType(), $4->begin(), $4->end());
-    for (unsigned i = 0, e = $4->size(); i != e && GTI != GTE; ++i, ++GTI)
-      if (isa<StructType>(*GTI))        // Only change struct indices
-        if (ConstantInt *CUI = dyn_cast<ConstantInt>((*$4)[i]))
-          if (CUI->getType() == Type::UByteTy)
-            (*$4)[i] = ConstantExpr::getCast(CUI, Type::UIntTy);
-
     const Type *IdxTy =
       GetElementPtrInst::getIndexedType($3->getType(), *$4, true);
     if (!IdxTy)
@@ -1708,29 +1546,8 @@ ConstExpr: CAST '(' ConstVal TO Types ')' {
   | ArithmeticOps '(' ConstVal ',' ConstVal ')' {
     if ($3->getType() != $5->getType())
       GEN_ERROR("Binary operator types must match!");
-    // First, make sure we're dealing with the right opcode by upgrading from
-    // obsolete versions.
-    sanitizeOpCode($1,$3->getType());
     CHECK_FOR_ERROR;
-
-    // HACK: llvm 1.3 and earlier used to emit invalid pointer constant exprs.
-    // To retain backward compatibility with these early compilers, we emit a
-    // cast to the appropriate integer type automatically if we are in the
-    // broken case.  See PR424 for more information.
-    if (!isa<PointerType>($3->getType())) {
-      $$ = ConstantExpr::get($1.opcode, $3, $5);
-    } else {
-      const Type *IntPtrTy = 0;
-      switch (CurModule.CurrentModule->getPointerSize()) {
-      case Module::Pointer32: IntPtrTy = Type::IntTy; break;
-      case Module::Pointer64: IntPtrTy = Type::LongTy; break;
-      default: GEN_ERROR("invalid pointer binary constant expr!");
-      }
-      $$ = ConstantExpr::get($1.opcode, ConstantExpr::getCast($3, IntPtrTy),
-                             ConstantExpr::getCast($5, IntPtrTy));
-      $$ = ConstantExpr::getCast($$, $3->getType());
-    }
-    CHECK_FOR_ERROR
+    $$ = ConstantExpr::get($1, $3, $5);
   }
   | LogicalOps '(' ConstVal ',' ConstVal ')' {
     if ($3->getType() != $5->getType())
@@ -1740,24 +1557,32 @@ ConstExpr: CAST '(' ConstVal TO Types ')' {
           !cast<PackedType>($3->getType())->getElementType()->isIntegral())
         GEN_ERROR("Logical operator requires integral operands!");
     }
-    $$ = ConstantExpr::get($1.opcode, $3, $5);
+    $$ = ConstantExpr::get($1, $3, $5);
     CHECK_FOR_ERROR
   }
   | SetCondOps '(' ConstVal ',' ConstVal ')' {
     if ($3->getType() != $5->getType())
       GEN_ERROR("setcc operand types must match!");
-    $$ = ConstantExpr::get($1.opcode, $3, $5);
+    $$ = ConstantExpr::get($1, $3, $5);
     CHECK_FOR_ERROR
   }
+  | ICMP IPredicates '(' ConstVal ',' ConstVal ')' {
+    if ($4->getType() != $6->getType())
+      GEN_ERROR("icmp operand types must match!");
+    $$ = ConstantExpr::getICmp($2, $4, $6);
+  }
+  | FCMP FPredicates '(' ConstVal ',' ConstVal ')' {
+    if ($4->getType() != $6->getType())
+      GEN_ERROR("fcmp operand types must match!");
+    $$ = ConstantExpr::getFCmp($2, $4, $6);
+  }
   | ShiftOps '(' ConstVal ',' ConstVal ')' {
     if ($5->getType() != Type::UByteTy)
       GEN_ERROR("Shift count for shift constant must be unsigned byte!");
     if (!$3->getType()->isInteger())
       GEN_ERROR("Shift constant expression requires integer operand!");
-    // Handle opcode upgrade situations
-    sanitizeOpCode($1, $3->getType());
     CHECK_FOR_ERROR;
-    $$ = ConstantExpr::get($1.opcode, $3, $5);
+    $$ = ConstantExpr::get($1, $3, $5);
     CHECK_FOR_ERROR
   }
   | EXTRACTELEMENT '(' ConstVal ',' ConstVal ')' {
@@ -2130,7 +1955,7 @@ Function : BasicBlockList END {
 
 FnDeclareLinkage: /*default*/ |
                   DLLIMPORT   { CurFun.Linkage = GlobalValue::DLLImportLinkage; } |
-                  EXTERN_WEAK { CurFun.Linkage = GlobalValue::DLLImportLinkage; };
+                  EXTERN_WEAK { CurFun.Linkage = GlobalValue::ExternalWeakLinkage; };
   
 FunctionProto : DECLARE { CurFun.isDeclare = true; } FnDeclareLinkage FunctionHeaderH {
     $$ = CurFun.CurrentFunction;
@@ -2272,12 +2097,16 @@ BasicBlock : InstructionList OptAssign BBTerminatorInst  {
   };
 
 InstructionList : InstructionList Inst {
+    if (CastInst *CI1 = dyn_cast<CastInst>($2))
+      if (CastInst *CI2 = dyn_cast<CastInst>(CI1->getOperand(0)))
+        if (CI2->getParent() == 0)
+          $1->getInstList().push_back(CI2);
     $1->getInstList().push_back($2);
     $$ = $1;
     CHECK_FOR_ERROR
   }
   | /* empty */ {
-    $$ = CurBB = getBBVal(ValID::create((int)CurFun.NextBBNum++), true);
+    $$ = getBBVal(ValID::create((int)CurFun.NextBBNum++), true);
     CHECK_FOR_ERROR
 
     // Make sure to move the basic block to the correct location in the
@@ -2289,7 +2118,7 @@ InstructionList : InstructionList Inst {
     CHECK_FOR_ERROR
   }
   | LABELSTR {
-    $$ = CurBB = getBBVal(ValID::create($1), true);
+    $$ = getBBVal(ValID::create($1), true);
     CHECK_FOR_ERROR
 
     // Make sure to move the basic block to the correct location in the
@@ -2498,18 +2327,15 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
       GEN_ERROR(
         "Arithmetic operator requires integer, FP, or packed operands!");
     if (isa<PackedType>((*$2).get()) && 
-        ($1.opcode == Instruction::URem || 
-         $1.opcode == Instruction::SRem ||
-         $1.opcode == Instruction::FRem))
+        ($1 == Instruction::URem || 
+         $1 == Instruction::SRem ||
+         $1 == Instruction::FRem))
       GEN_ERROR("U/S/FRem not supported on packed types!");
-    // Upgrade the opcode from obsolete versions before we do anything with it.
-    sanitizeOpCode($1,*$2);
-    CHECK_FOR_ERROR;
     Value* val1 = getVal(*$2, $3); 
     CHECK_FOR_ERROR
     Value* val2 = getVal(*$2, $5);
     CHECK_FOR_ERROR
-    $$ = BinaryOperator::create($1.opcode, val1, val2);
+    $$ = BinaryOperator::create($1, val1, val2);
     if ($$ == 0)
       GEN_ERROR("binary operator returned null!");
     delete $2;
@@ -2524,7 +2350,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
     CHECK_FOR_ERROR
     Value* tmpVal2 = getVal(*$2, $5);
     CHECK_FOR_ERROR
-    $$ = BinaryOperator::create($1.opcode, tmpVal1, tmpVal2);
+    $$ = BinaryOperator::create($1, tmpVal1, tmpVal2);
     if ($$ == 0)
       GEN_ERROR("binary operator returned null!");
     delete $2;
@@ -2538,13 +2364,35 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
     CHECK_FOR_ERROR
     Value* tmpVal2 = getVal(*$2, $5);
     CHECK_FOR_ERROR
-    $$ = new SetCondInst($1.opcode, tmpVal1, tmpVal2);
+    $$ = new SetCondInst($1, tmpVal1, tmpVal2);
     if ($$ == 0)
       GEN_ERROR("binary operator returned null!");
     delete $2;
   }
+  | ICMP IPredicates Types ValueRef ',' ValueRef  {
+    if (isa<PackedType>((*$3).get()))
+      GEN_ERROR("Packed types not supported by icmp instruction");
+    Value* tmpVal1 = getVal(*$3, $4);
+    CHECK_FOR_ERROR
+    Value* tmpVal2 = getVal(*$3, $6);
+    CHECK_FOR_ERROR
+    $$ = CmpInst::create($1, $2, tmpVal1, tmpVal2);
+    if ($$ == 0)
+      GEN_ERROR("icmp operator returned null!");
+  }
+  | FCMP FPredicates Types ValueRef ',' ValueRef  {
+    if (isa<PackedType>((*$3).get()))
+      GEN_ERROR("Packed types not supported by fcmp instruction");
+    Value* tmpVal1 = getVal(*$3, $4);
+    CHECK_FOR_ERROR
+    Value* tmpVal2 = getVal(*$3, $6);
+    CHECK_FOR_ERROR
+    $$ = CmpInst::create($1, $2, tmpVal1, tmpVal2);
+    if ($$ == 0)
+      GEN_ERROR("fcmp operator returned null!");
+  }
   | NOT ResolvedVal {
-    std::cerr << "WARNING: Use of eliminated 'not' instruction:"
+    llvm_cerr << "WARNING: Use of eliminated 'not' instruction:"
               << " Replacing with 'xor'.\n";
 
     Value *Ones = ConstantIntegral::getAllOnesValue($2->getType());
@@ -2561,19 +2409,20 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
       GEN_ERROR("Shift amount must be ubyte!");
     if (!$2->getType()->isInteger())
       GEN_ERROR("Shift constant expression requires integer operand!");
-    // Handle opcode upgrade situations
-    sanitizeOpCode($1, $2->getType());
     CHECK_FOR_ERROR;
-    $$ = new ShiftInst($1.opcode, $2, $4);
+    $$ = new ShiftInst($1, $2, $4);
     CHECK_FOR_ERROR
   }
-  | CAST ResolvedVal TO Types {
-    if (!$4->get()->isFirstClassType())
-      GEN_ERROR("cast instruction to a non-primitive type: '" +
-                     $4->get()->getDescription() + "'!");
-    $$ = new CastInst($2, *$4);
+  | CastOps ResolvedVal TO Types {
+    Value* Val = $2;
+    const Type* Ty = $4->get();
+    if (!Val->getType()->isFirstClassType())
+      GEN_ERROR("cast from a non-primitive type: '" +
+                Val->getType()->getDescription() + "'!");
+    if (!Ty->isFirstClassType())
+      GEN_ERROR("cast to a non-primitive type: '" + Ty->getDescription() +"'!");
+    $$ = CastInst::create($1, $2, $4->get());
     delete $4;
-    CHECK_FOR_ERROR
   }
   | SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
     if ($2->getType() != Type::BoolTy)
@@ -2589,49 +2438,6 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
     delete $4;
     CHECK_FOR_ERROR
   }
-  | VAARG_old ResolvedVal ',' Types {
-    ObsoleteVarArgs = true;
-    const Type* ArgTy = $2->getType();
-    Function* NF = CurModule.CurrentModule->
-      getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0);
-
-    //b = vaarg a, t -> 
-    //foo = alloca 1 of t
-    //bar = vacopy a 
-    //store bar -> foo
-    //b = vaarg foo, t
-    AllocaInst* foo = new AllocaInst(ArgTy, 0, "vaarg.fix");
-    CurBB->getInstList().push_back(foo);
-    CallInst* bar = new CallInst(NF, $2);
-    CurBB->getInstList().push_back(bar);
-    CurBB->getInstList().push_back(new StoreInst(bar, foo));
-    $$ = new VAArgInst(foo, *$4);
-    delete $4;
-    CHECK_FOR_ERROR
-  }
-  | VANEXT_old ResolvedVal ',' Types {
-    ObsoleteVarArgs = true;
-    const Type* ArgTy = $2->getType();
-    Function* NF = CurModule.CurrentModule->
-      getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0);
-
-    //b = vanext a, t ->
-    //foo = alloca 1 of t
-    //bar = vacopy a
-    //store bar -> foo
-    //tmp = vaarg foo, t
-    //b = load foo
-    AllocaInst* foo = new AllocaInst(ArgTy, 0, "vanext.fix");
-    CurBB->getInstList().push_back(foo);
-    CallInst* bar = new CallInst(NF, $2);
-    CurBB->getInstList().push_back(bar);
-    CurBB->getInstList().push_back(new StoreInst(bar, foo));
-    Instruction* tmp = new VAArgInst(foo, *$4);
-    CurBB->getInstList().push_back(tmp);
-    $$ = new LoadInst(foo);
-    delete $4;
-    CHECK_FOR_ERROR
-  }
   | EXTRACTELEMENT ResolvedVal ',' ResolvedVal {
     if (!ExtractElementInst::isValidOperands($2, $4))
       GEN_ERROR("Invalid extractelement operands!");
@@ -2811,17 +2617,6 @@ MemoryInst : MALLOC Types OptCAlign {
     if (!isa<PointerType>($2->get()))
       GEN_ERROR("getelementptr insn requires pointer operand!");
 
-    // LLVM 1.2 and earlier used ubyte struct indices.  Convert any ubyte struct
-    // indices to uint struct indices for compatibility.
-    generic_gep_type_iterator<std::vector<Value*>::iterator>
-      GTI = gep_type_begin($2->get(), $4->begin(), $4->end()),
-      GTE = gep_type_end($2->get(), $4->begin(), $4->end());
-    for (unsigned i = 0, e = $4->size(); i != e && GTI != GTE; ++i, ++GTI)
-      if (isa<StructType>(*GTI))        // Only change struct indices
-        if (ConstantInt *CUI = dyn_cast<ConstantInt>((*$4)[i]))
-          if (CUI->getType() == Type::UByteTy)
-            (*$4)[i] = ConstantExpr::getCast(CUI, Type::UIntTy);
-
     if (!GetElementPtrInst::getIndexedType(*$2, *$4, true))
       GEN_ERROR("Invalid getelementptr indices for type '" +
                      (*$2)->getDescription()+ "'!");