For PR411:
[oota-llvm.git] / lib / AsmParser / llvmAsmParser.y
index dfaeb8301529b9fbae91f1e9ea04d93066c569af..67d20fed804e9151416989147969baa2e8607b8e 100644 (file)
@@ -17,6 +17,7 @@
 #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"
@@ -104,12 +105,16 @@ static struct PerModuleInfo {
       ThrowException(UndefinedReferences);
     }
 
+    // Rename any overloaded intrinsic functions.
+    for (Module::iterator FI = CurrentModule->begin(), FE =
+         CurrentModule->end(); FI != FE; ++FI)
+      UpgradeIntrinsicFunction(&(*FI));
+
     Values.clear();         // Clear out function local definitions
     Types.clear();
     CurrentModule = 0;
   }
 
-
   // GetForwardRefForGlobal - Check to see if there is a forward reference
   // for this global.  If so, remove it from the GlobalRefs map and return it.
   // If not, just return null.
@@ -979,7 +984,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
 
 // Other Operators
 %type  <OtherOpVal> ShiftOps
-%token <OtherOpVal> PHI_TOK CAST SELECT SHL SHR VAARG
+%token <OtherOpVal> PHI_TOK CAST SELECT SHL SHR VAARG EXTRACTELEMENT
 %token VAARG_old VANEXT_old //OBSOLETE
 
 
@@ -1501,8 +1506,11 @@ ConstExpr: CAST '(' ConstVal TO Types ')' {
   | LogicalOps '(' ConstVal ',' ConstVal ')' {
     if ($3->getType() != $5->getType())
       ThrowException("Logical operator types must match!");
-    if (!$3->getType()->isIntegral())
-      ThrowException("Logical operands must have integral types!");
+    if (!$3->getType()->isIntegral()) {
+      if (!isa<PackedType>($3->getType()) || 
+          !cast<PackedType>($3->getType())->getElementType()->isIntegral())
+        ThrowException("Logical operator requires integral operands!");
+    }
     $$ = ConstantExpr::get($1, $3, $5);
   }
   | SetCondOps '(' ConstVal ',' ConstVal ')' {
@@ -1516,9 +1524,16 @@ ConstExpr: CAST '(' ConstVal TO Types ')' {
     if (!$3->getType()->isInteger())
       ThrowException("Shift constant expression requires integer operand!");
     $$ = ConstantExpr::get($1, $3, $5);
+  }
+  | EXTRACTELEMENT '(' ConstVal ',' ConstVal ')' {
+        if (!isa<PackedType>($3->getType()))
+      ThrowException("First operand of extractelement must be "
+                     "packed type!");
+    if ($5->getType() != Type::UIntTy)
+      ThrowException("Second operand of extractelement must be uint!");
+    $$ = ConstantExpr::getExtractElement($3, $5);
   };
 
-
 // ConstVector - A list of comma separated constants.
 ConstVector : ConstVector ',' ConstVal {
     ($$ = $1)->push_back($3);
@@ -2079,8 +2094,11 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
     delete $2;
   }
   | LogicalOps Types ValueRef ',' ValueRef {
-    if (!(*$2)->isIntegral())
-      ThrowException("Logical operator requires integral operands!");
+    if (!(*$2)->isIntegral()) {
+      if (!isa<PackedType>($2->get()) ||
+          !cast<PackedType>($2->get())->getElementType()->isIntegral())
+        ThrowException("Logical operator requires integral operands!");
+    }
     $$ = BinaryOperator::create($1, getVal(*$2, $3), getVal(*$2, $5));
     if ($$ == 0)
       ThrowException("binary operator returned null!");
@@ -2175,6 +2193,14 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
     $$ = new LoadInst(foo);
     delete $4;
   }
+  | EXTRACTELEMENT ResolvedVal ',' ResolvedVal {
+    if (!isa<PackedType>($2->getType()))
+      ThrowException("First operand of extractelement must be a "
+                     "packed type val!");
+    if ($4->getType() != Type::UIntTy)
+      ThrowException("Second operand of extractelement must be a uint!");
+    $$ = new ExtractElementInst($2, $4);
+  }
   | PHI_TOK PHIList {
     const Type *Ty = $2->front().first->getType();
     if (!Ty->isFirstClassType())