diff options
author | Dan Gohman <gohman@apple.com> | 2008-09-09 01:02:47 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2008-09-09 01:02:47 +0000 |
commit | f72fb679eff7de84e3e18b75d63a18cb3510bcdd (patch) | |
tree | dbb8edc6c23b2810ff37d055e1f19f2a81bcb504 /lib/AsmParser | |
parent | 3eb594013f666d6af9f943df5fb6ac4d902debee (diff) |
Extend the vcmp/fcmp LLVM IR instructions to take vectors as arguments
and, if so, to return a vector of boolean as a result;
Extend the select LLVM IR instruction to allow you to specify a result
type which is a vector of boolean, in which case the result will be an
element-wise selection instead of choosing one vector or the other; and
Update LangRef.html to describe these changes.
This patch was contributed by Preston Gurd!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55969 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AsmParser')
-rw-r--r-- | lib/AsmParser/llvmAsmParser.y | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 5db76429b5..edc84c1fa1 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -1102,7 +1102,7 @@ Module *llvm::RunVMAsmParser(llvm::MemoryBuffer *MB) { %token <BinaryOpVal> ADD SUB MUL UDIV SDIV FDIV UREM SREM FREM AND OR XOR %token <BinaryOpVal> SHL LSHR ASHR -%token <OtherOpVal> ICMP FCMP VICMP VFCMP +%token <OtherOpVal> ICMP FCMP VICMP VFCMP %type <IPredicate> IPredicates %type <FPredicate> FPredicates %token EQ NE SLT SGT SLE SGE ULT UGT ULE UGE @@ -3097,8 +3097,6 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { | ICMP IPredicates Types ValueRef ',' ValueRef { if (!UpRefs.empty()) GEN_ERROR("Invalid upreference in type: " + (*$3)->getDescription()); - if (isa<VectorType>((*$3).get())) - GEN_ERROR("Vector types not supported by icmp instruction"); Value* tmpVal1 = getVal(*$3, $4); CHECK_FOR_ERROR Value* tmpVal2 = getVal(*$3, $6); @@ -3111,8 +3109,6 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { | FCMP FPredicates Types ValueRef ',' ValueRef { if (!UpRefs.empty()) GEN_ERROR("Invalid upreference in type: " + (*$3)->getDescription()); - if (isa<VectorType>((*$3).get())) - GEN_ERROR("Vector types not supported by fcmp instruction"); Value* tmpVal1 = getVal(*$3, $4); CHECK_FOR_ERROR Value* tmpVal2 = getVal(*$3, $6); @@ -3133,7 +3129,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { CHECK_FOR_ERROR $$ = CmpInst::Create($1, $2, tmpVal1, tmpVal2); if ($$ == 0) - GEN_ERROR("icmp operator returned null"); + GEN_ERROR("vicmp operator returned null"); delete $3; } | VFCMP FPredicates Types ValueRef ',' ValueRef { @@ -3147,7 +3143,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { CHECK_FOR_ERROR $$ = CmpInst::Create($1, $2, tmpVal1, tmpVal2); if ($$ == 0) - GEN_ERROR("fcmp operator returned null"); + GEN_ERROR("vfcmp operator returned null"); delete $3; } | CastOps ResolvedVal TO Types { @@ -3163,10 +3159,23 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef { delete $4; } | SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal { - if ($2->getType() != Type::Int1Ty) - GEN_ERROR("select condition must be boolean"); + if (isa<VectorType>($2->getType())) { + // vector select + if (!isa<VectorType>($4->getType()) + || !isa<VectorType>($6->getType()) ) + GEN_ERROR("vector select value types must be vector types"); + const VectorType* cond_type = cast<VectorType>($2->getType()); + const VectorType* select_type = cast<VectorType>($4->getType()); + if (cond_type->getElementType() != Type::Int1Ty) + GEN_ERROR("vector select condition element type must be boolean"); + if (cond_type->getNumElements() != select_type->getNumElements()) + GEN_ERROR("vector select number of elements must be the same"); + } else { + if ($2->getType() != Type::Int1Ty) + GEN_ERROR("select condition must be boolean"); + } if ($4->getType() != $6->getType()) - GEN_ERROR("select value types should match"); + GEN_ERROR("select value types must match"); $$ = SelectInst::Create($2, $4, $6); CHECK_FOR_ERROR } |