[llvm-commits] [llvm] r61461 - in /llvm/trunk: include/llvm/Instructions.h lib/VMCore/Instructions.cpp lib/VMCore/Verifier.cpp
Chris Lattner
sabre at nondot.org
Sun Dec 28 16:12:51 PST 2008
Author: lattner
Date: Sun Dec 28 18:12:50 2008
New Revision: 61461
URL: http://llvm.org/viewvc/llvm-project?rev=61461&view=rev
Log:
move select validation logic into a shared place where the select ctor,
verifier, asm parser, etc can share it.
Modified:
llvm/trunk/include/llvm/Instructions.h
llvm/trunk/lib/VMCore/Instructions.cpp
llvm/trunk/lib/VMCore/Verifier.cpp
Modified: llvm/trunk/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Instructions.h?rev=61461&r1=61460&r2=61461&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Instructions.h (original)
+++ llvm/trunk/include/llvm/Instructions.h Sun Dec 28 18:12:50 2008
@@ -1208,6 +1208,7 @@
///
class SelectInst : public Instruction {
void init(Value *C, Value *S1, Value *S2) {
+ assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
Op<0>() = C;
Op<1>() = S1;
Op<2>() = S2;
@@ -1246,6 +1247,10 @@
Value *getCondition() const { return Op<0>(); }
Value *getTrueValue() const { return Op<1>(); }
Value *getFalseValue() const { return Op<2>(); }
+
+ /// areInvalidOperands - Return a string if the specified operands are invalid
+ /// for a select operation, otherwise return null.
+ static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Modified: llvm/trunk/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instructions.cpp?rev=61461&r1=61460&r2=61461&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Instructions.cpp (original)
+++ llvm/trunk/lib/VMCore/Instructions.cpp Sun Dec 28 18:12:50 2008
@@ -139,6 +139,33 @@
}
//===----------------------------------------------------------------------===//
+// 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
//===----------------------------------------------------------------------===//
Modified: llvm/trunk/lib/VMCore/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Verifier.cpp?rev=61461&r1=61460&r2=61461&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Verifier.cpp (original)
+++ llvm/trunk/lib/VMCore/Verifier.cpp Sun Dec 28 18:12:50 2008
@@ -687,23 +687,10 @@
}
void Verifier::visitSelectInst(SelectInst &SI) {
- if (const VectorType* vt
- = dyn_cast<VectorType>(SI.getCondition()->getType())) {
- Assert1( vt->getElementType() == Type::Int1Ty,
- "Select condition type must be vector of bool!", &SI);
- if (const VectorType* val_vt
- = dyn_cast<VectorType>(SI.getTrueValue()->getType())) {
- Assert1( vt->getNumElements() == val_vt->getNumElements(),
- "Select vector size != value vector size", &SI);
- } else {
- Assert1(0, "Vector select values must have vector types", &SI);
- }
- } else {
- Assert1(SI.getCondition()->getType() == Type::Int1Ty,
- "Select condition type must be bool!", &SI);
- }
- Assert1(SI.getTrueValue()->getType() == SI.getFalseValue()->getType(),
- "Select values must have identical types!", &SI);
+ Assert1(!SelectInst::areInvalidOperands(SI.getOperand(0), SI.getOperand(1),
+ SI.getOperand(2)),
+ "Invalid operands for select instruction!", &SI);
+
Assert1(SI.getTrueValue()->getType() == SI.getType(),
"Select values must have same type as select instruction!", &SI);
visitInstruction(SI);
More information about the llvm-commits
mailing list