move select validation logic into a shared place where the select ctor,

verifier, asm parser, etc can share it.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61461 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2008-12-29 00:12:50 +00:00
parent d4f6fe55eb
commit b76ec320dc
3 changed files with 36 additions and 17 deletions

View File

@@ -138,6 +138,33 @@ TerminatorInst::~TerminatorInst() {
UnaryInstruction::~UnaryInstruction() {
}
//===----------------------------------------------------------------------===//
// SelectInst Class
//===----------------------------------------------------------------------===//
/// areInvalidOperands - Return a string if the specified operands are invalid
/// for a select operation, otherwise return null.
const char *SelectInst::areInvalidOperands(Value *Op0, Value *Op1, Value *Op2) {
if (Op1->getType() != Op2->getType())
return "both values to select must have same type";
if (const VectorType *VT = dyn_cast<VectorType>(Op0->getType())) {
// Vector select.
if (VT->getElementType() != Type::Int1Ty)
return "vector select condition element type must be i1";
const VectorType *ET = dyn_cast<VectorType>(Op1->getType());
if (ET == 0)
return "selected values for vector select must be vectors";
if (ET->getNumElements() != VT->getNumElements())
return "vector select requires selected vectors to have "
"the same vector length as select condition";
} else if (Op0->getType() != Type::Int1Ty) {
return "select condition must be i1 or <n x i1>";
}
return 0;
}
//===----------------------------------------------------------------------===//
// PHINode Class
//===----------------------------------------------------------------------===//