summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/Instructions.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-04-08 04:05:48 +0000
committerChris Lattner <sabre@nondot.org>2006-04-08 04:05:48 +0000
commit54865b39ab34e3c3a47652eb48628fb445a589f7 (patch)
tree06e990c6622a2dbe6dd212b3ff245d250b9a161e /llvm/lib/VMCore/Instructions.cpp
parent425aaac9559b2402d34d97df628917ca07f738b8 (diff)
downloadbcm5719-llvm-54865b39ab34e3c3a47652eb48628fb445a589f7.tar.gz
bcm5719-llvm-54865b39ab34e3c3a47652eb48628fb445a589f7.zip
Add methods to check insertelement/extractelement instructions for validity,
check validity when instructions are created. llvm-svn: 27523
Diffstat (limited to 'llvm/lib/VMCore/Instructions.cpp')
-rw-r--r--llvm/lib/VMCore/Instructions.cpp43
1 files changed, 37 insertions, 6 deletions
diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp
index 9ef72d43536..9eaa8f7e846 100644
--- a/llvm/lib/VMCore/Instructions.cpp
+++ b/llvm/lib/VMCore/Instructions.cpp
@@ -804,6 +804,8 @@ ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
Instruction *InsertBef)
: Instruction(cast<PackedType>(Val->getType())->getElementType(),
ExtractElement, Ops, 2, Name, InsertBef) {
+ assert(isValidOperands(Val, Index) &&
+ "Invalid extractelement instruction operands!");
Ops[0].init(Val, this);
Ops[1].init(Index, this);
}
@@ -813,32 +815,61 @@ ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
BasicBlock *InsertAE)
: Instruction(cast<PackedType>(Val->getType())->getElementType(),
ExtractElement, Ops, 2, Name, InsertAE) {
+ assert(isValidOperands(Val, Index) &&
+ "Invalid extractelement instruction operands!");
+
Ops[0].init(Val, this);
Ops[1].init(Index, this);
}
+bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) {
+ if (!isa<PackedType>(Val->getType()) || Index->getType() != Type::UIntTy)
+ return false;
+ return true;
+}
+
+
//===----------------------------------------------------------------------===//
// InsertElementInst Implementation
//===----------------------------------------------------------------------===//
-InsertElementInst::InsertElementInst(Value *Val, Value *Elt, Value *Index,
+InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
const std::string &Name,
Instruction *InsertBef)
- : Instruction(Val->getType(), InsertElement, Ops, 3, Name, InsertBef) {
- Ops[0].init(Val, this);
+ : Instruction(Vec->getType(), InsertElement, Ops, 3, Name, InsertBef) {
+ assert(isValidOperands(Vec, Elt, Index) &&
+ "Invalid insertelement instruction operands!");
+ Ops[0].init(Vec, this);
Ops[1].init(Elt, this);
Ops[2].init(Index, this);
}
-InsertElementInst::InsertElementInst(Value *Val, Value *Elt, Value *Index,
+InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
const std::string &Name,
BasicBlock *InsertAE)
- : Instruction(Val->getType(), InsertElement, Ops, 3, Name, InsertAE) {
- Ops[0].init(Val, this);
+ : Instruction(Vec->getType(), InsertElement, Ops, 3, Name, InsertAE) {
+ assert(isValidOperands(Vec, Elt, Index) &&
+ "Invalid insertelement instruction operands!");
+
+ Ops[0].init(Vec, this);
Ops[1].init(Elt, this);
Ops[2].init(Index, this);
}
+bool InsertElementInst::isValidOperands(const Value *Vec, const Value *Elt,
+ const Value *Index) {
+ if (!isa<PackedType>(Vec->getType()))
+ return false; // First operand of insertelement must be packed type.
+
+ if (Elt->getType() != cast<PackedType>(Vec->getType())->getElementType())
+ return false;// Second operand of insertelement must be packed element type.
+
+ if (Index->getType() != Type::UIntTy)
+ return false; // Third operand of insertelement must be uint.
+ return true;
+}
+
+
//===----------------------------------------------------------------------===//
// ShuffleVectorInst Implementation
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud