diff options
author | Chris Lattner <sabre@nondot.org> | 2008-03-02 05:28:33 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-03-02 05:28:33 +0000 |
commit | 8728f1915f332f09112848c6d30055be5b943ba5 (patch) | |
tree | 6c29f63d79c9c38e79d35ce7030f6f20c35ff073 | |
parent | 0452ed6bd6a227311b00f3777160415ea423b775 (diff) | |
download | external_llvm-8728f1915f332f09112848c6d30055be5b943ba5.zip external_llvm-8728f1915f332f09112848c6d30055be5b943ba5.tar.gz external_llvm-8728f1915f332f09112848c6d30055be5b943ba5.tar.bz2 |
Add a new ShuffleVectorInst::getMaskValue method.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47813 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Instructions.h | 5 | ||||
-rw-r--r-- | lib/VMCore/Instructions.cpp | 30 |
2 files changed, 29 insertions, 6 deletions
diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 3474429..a7fe6a0 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -1228,6 +1228,11 @@ public: 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; } diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index c0b3413..dfd3b83 100644 --- a/lib/VMCore/Instructions.cpp +++ b/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 |