summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-03-02 05:28:33 +0000
committerChris Lattner <sabre@nondot.org>2008-03-02 05:28:33 +0000
commitf724e34ddc28580da124a3e7bd9dd08f728247d1 (patch)
tree48dd7d77ca7ab89b9e063481abec73e73ed43a9e /llvm/lib
parent689d830b6d51ac586ce77e5de1e414f5cd4527c3 (diff)
downloadbcm5719-llvm-f724e34ddc28580da124a3e7bd9dd08f728247d1.tar.gz
bcm5719-llvm-f724e34ddc28580da124a3e7bd9dd08f728247d1.zip
Add a new ShuffleVectorInst::getMaskValue method.
llvm-svn: 47813
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/VMCore/Instructions.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp
index c0b3413da33..dfd3b830caa 100644
--- a/llvm/lib/VMCore/Instructions.cpp
+++ b/llvm/lib/VMCore/Instructions.cpp
@@ -1350,16 +1350,34 @@ ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
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
OpenPOWER on IntegriCloud