[llvm-commits] [llvm] r47813 - in /llvm/trunk: include/llvm/Instructions.h lib/VMCore/Instructions.cpp

Chris Lattner sabre at nondot.org
Sat Mar 1 21:28:34 PST 2008


Author: lattner
Date: Sat Mar  1 23:28:33 2008
New Revision: 47813

URL: http://llvm.org/viewvc/llvm-project?rev=47813&view=rev
Log:
Add a new ShuffleVectorInst::getMaskValue method.

Modified:
    llvm/trunk/include/llvm/Instructions.h
    llvm/trunk/lib/VMCore/Instructions.cpp

Modified: llvm/trunk/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Instructions.h?rev=47813&r1=47812&r2=47813&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Instructions.h (original)
+++ llvm/trunk/include/llvm/Instructions.h Sat Mar  1 23:28:33 2008
@@ -1228,6 +1228,11 @@
     Ops[i] = Val;
   }
   unsigned getNumOperands() const { return 3; }
+  
+  /// getMaskValue - Return the index from the shuffle mask for the specified
+  /// output result.  This is either -1 if the element is undef or a number less
+  /// than 2*numelements.
+  int getMaskValue(unsigned i) const;
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const ShuffleVectorInst *) { return true; }

Modified: llvm/trunk/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instructions.cpp?rev=47813&r1=47812&r2=47813&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Instructions.cpp (original)
+++ llvm/trunk/lib/VMCore/Instructions.cpp Sat Mar  1 23:28:33 2008
@@ -1350,16 +1350,34 @@
 
 bool ShuffleVectorInst::isValidOperands(const Value *V1, const Value *V2, 
                                         const Value *Mask) {
-  if (!isa<VectorType>(V1->getType())) return false;
-  if (V1->getType() != V2->getType()) return false;
-  if (!isa<VectorType>(Mask->getType()) ||
-         cast<VectorType>(Mask->getType())->getElementType() != Type::Int32Ty ||
-         cast<VectorType>(Mask->getType())->getNumElements() !=
-         cast<VectorType>(V1->getType())->getNumElements())
+  if (!isa<VectorType>(V1->getType()) || 
+      V1->getType() != V2->getType()) 
+    return false;
+  
+  const VectorType *MaskTy = dyn_cast<VectorType>(Mask->getType());
+  if (!isa<Constant>(Mask) || MaskTy == 0 ||
+      MaskTy->getElementType() != Type::Int32Ty ||
+      MaskTy->getNumElements() != 
+      cast<VectorType>(V1->getType())->getNumElements())
     return false;
   return true;
 }
 
+/// getMaskValue - Return the index from the shuffle mask for the specified
+/// output result.  This is either -1 if the element is undef or a number less
+/// than 2*numelements.
+int ShuffleVectorInst::getMaskValue(unsigned i) const {
+  const Constant *Mask = cast<Constant>(getOperand(2));
+  if (isa<UndefValue>(Mask)) return -1;
+  if (isa<ConstantAggregateZero>(Mask)) return 0;
+  const ConstantVector *MaskCV = cast<ConstantVector>(Mask);
+  assert(i < MaskCV->getNumOperands() && "Index out of range");
+
+  if (isa<UndefValue>(MaskCV->getOperand(i)))
+    return -1;
+  return cast<ConstantInt>(MaskCV->getOperand(i))->getZExtValue();
+}
+
 
 //===----------------------------------------------------------------------===//
 //                             BinaryOperator Class





More information about the llvm-commits mailing list