[llvm-commits] CVS: llvm/lib/VMCore/Constants.cpp Instruction.cpp Instructions.cpp Verifier.cpp
Robert L. Bocchino Jr.
bocchino at persephone.cs.uiuc.edu
Tue Jan 10 11:06:31 PST 2006
Changes in directory llvm/lib/VMCore:
Constants.cpp updated: 1.142 -> 1.143
Instruction.cpp updated: 1.48 -> 1.49
Instructions.cpp updated: 1.29 -> 1.30
Verifier.cpp updated: 1.136 -> 1.137
---
Log message:
Added support for the extractelement operation.
---
Diffs of the changes: (+73 -0)
Constants.cpp | 38 ++++++++++++++++++++++++++++++++++++++
Instruction.cpp | 1 +
Instructions.cpp | 21 +++++++++++++++++++++
Verifier.cpp | 13 +++++++++++++
4 files changed, 73 insertions(+)
Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.142 llvm/lib/VMCore/Constants.cpp:1.143
--- llvm/lib/VMCore/Constants.cpp:1.142 Tue Jan 3 19:01:04 2006
+++ llvm/lib/VMCore/Constants.cpp Tue Jan 10 13:05:24 2006
@@ -347,6 +347,19 @@
}
};
+/// ExtractElementConstantExpr - This class is private to Constants.cpp, and is used
+/// behind the scenes to implement extractelement constant exprs.
+class ExtractElementConstantExpr : public ConstantExpr {
+ Use Ops[2];
+public:
+ ExtractElementConstantExpr(Constant *C1, Constant *C2)
+ : ConstantExpr(cast<PackedType>(C1->getType())->getElementType(),
+ Instruction::ExtractElement, Ops, 2) {
+ Ops[0].init(C1, this);
+ Ops[1].init(C2, this);
+ }
+};
+
/// GetElementPtrConstantExpr - This class is private to Constants.cpp, and is
/// used behind the scenes to implement getelementpr constant exprs.
struct GetElementPtrConstantExpr : public ConstantExpr {
@@ -1141,6 +1154,8 @@
return new BinaryConstantExpr(V.first, V.second[0], V.second[1]);
if (V.first == Instruction::Select)
return new SelectConstantExpr(V.second[0], V.second[1], V.second[2]);
+ if (V.first == Instruction::ExtractElement)
+ return new ExtractElementConstantExpr(V.second[0], V.second[1]);
assert(V.first == Instruction::GetElementPtr && "Invalid ConstantExpr!");
@@ -1386,7 +1401,24 @@
return getGetElementPtrTy(PointerType::get(Ty), C, IdxList);
}
+Constant *ConstantExpr::getExtractElementTy(const Type *ReqTy, Constant *Val,
+ Constant *Idx) {
+ // Look up the constant in the table first to ensure uniqueness
+ std::vector<Constant*> ArgVec(1, Val);
+ ArgVec.push_back(Idx);
+ const ExprMapKeyType &Key = std::make_pair(Instruction::ExtractElement,ArgVec);
+ return ExprConstants.getOrCreate(ReqTy, Key);
+}
+Constant *ConstantExpr::getExtractElement(Constant *Val, Constant *Idx) {
+ assert(isa<PackedType>(Val->getType()) &&
+ "Tried to create extractelement operation on non-packed type!");
+ assert(Idx->getType() == Type::UIntTy &&
+ "Index must be uint type!");
+ return getExtractElementTy(cast<PackedType>(Val->getType())->getElementType(),
+ Val, Idx);
+}
+
// destroyConstant - Remove the constant from the constant table...
//
void ConstantExpr::destroyConstant() {
@@ -1581,6 +1613,12 @@
if (C2 == From) C2 = To;
if (C3 == From) C3 = To;
Replacement = ConstantExpr::getSelect(C1, C2, C3);
+ } else if (getOpcode() == Instruction::ExtractElement) {
+ Constant *C1 = getOperand(0);
+ Constant *C2 = getOperand(1);
+ if (C1 == From) C1 = To;
+ if (C2 == From) C2 = To;
+ Replacement = ConstantExpr::getExtractElement(C1, C2);
} else if (getNumOperands() == 2) {
Constant *C1 = getOperand(0);
Constant *C2 = getOperand(1);
Index: llvm/lib/VMCore/Instruction.cpp
diff -u llvm/lib/VMCore/Instruction.cpp:1.48 llvm/lib/VMCore/Instruction.cpp:1.49
--- llvm/lib/VMCore/Instruction.cpp:1.48 Mon Aug 8 00:21:50 2005
+++ llvm/lib/VMCore/Instruction.cpp Tue Jan 10 13:05:24 2006
@@ -120,6 +120,7 @@
case Shl: return "shl";
case Shr: return "shr";
case VAArg: return "va_arg";
+ case ExtractElement: return "extractelement";
default: return "<Invalid operator> ";
}
Index: llvm/lib/VMCore/Instructions.cpp
diff -u llvm/lib/VMCore/Instructions.cpp:1.29 llvm/lib/VMCore/Instructions.cpp:1.30
--- llvm/lib/VMCore/Instructions.cpp:1.29 Wed Dec 21 12:22:19 2005
+++ llvm/lib/VMCore/Instructions.cpp Tue Jan 10 13:05:24 2006
@@ -796,6 +796,26 @@
}
//===----------------------------------------------------------------------===//
+// ExtractElementInst Implementation
+//===----------------------------------------------------------------------===//
+
+ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
+ const std::string &Name, Instruction *InsertBef)
+ : Instruction(cast<PackedType>(Val->getType())->getElementType(),
+ ExtractElement, Ops, 2, Name, InsertBef) {
+ Ops[0].init(Val, this);
+ Ops[1].init(Index, this);
+}
+
+ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
+ const std::string &Name, BasicBlock *InsertAE)
+ : Instruction(cast<PackedType>(Val->getType())->getElementType(),
+ ExtractElement, Ops, 2, Name, InsertAE) {
+ Ops[0].init(Val, this);
+ Ops[1].init(Index, this);
+}
+
+//===----------------------------------------------------------------------===//
// BinaryOperator Class
//===----------------------------------------------------------------------===//
@@ -1155,6 +1175,7 @@
ShiftInst *ShiftInst::clone() const { return new ShiftInst(*this); }
SelectInst *SelectInst::clone() const { return new SelectInst(*this); }
VAArgInst *VAArgInst::clone() const { return new VAArgInst(*this); }
+ExtractElementInst *ExtractElementInst::clone() const {return new ExtractElementInst(*this); }
PHINode *PHINode::clone() const { return new PHINode(*this); }
ReturnInst *ReturnInst::clone() const { return new ReturnInst(*this); }
BranchInst *BranchInst::clone() const { return new BranchInst(*this); }
Index: llvm/lib/VMCore/Verifier.cpp
diff -u llvm/lib/VMCore/Verifier.cpp:1.136 llvm/lib/VMCore/Verifier.cpp:1.137
--- llvm/lib/VMCore/Verifier.cpp:1.136 Wed Dec 21 12:22:19 2005
+++ llvm/lib/VMCore/Verifier.cpp Tue Jan 10 13:05:24 2006
@@ -178,6 +178,7 @@
void visitPHINode(PHINode &PN);
void visitBinaryOperator(BinaryOperator &B);
void visitShiftInst(ShiftInst &SI);
+ void visitExtractElementInst(ExtractElementInst &EI);
void visitVAArgInst(VAArgInst &VAA) { visitInstruction(VAA); }
void visitCallInst(CallInst &CI);
void visitGetElementPtrInst(GetElementPtrInst &GEP);
@@ -530,6 +531,18 @@
Assert1(SI.getOperand(1)->getType() == Type::UByteTy,
"Second operand to shift must be ubyte type!", &SI);
visitInstruction(SI);
+}
+
+void Verifier::visitExtractElementInst(ExtractElementInst &EI) {
+ Assert1(isa<PackedType>(EI.getOperand(0)->getType()),
+ "First operand to extractelement must be packed type!", &EI);
+ Assert1(EI.getOperand(1)->getType() == Type::UIntTy,
+ "Second operand to extractelement must be uint type!", &EI);
+ Assert1(EI.getType() ==
+ cast<PackedType>(EI.getOperand(0)->getType())->getElementType(),
+ "Extractelement return type must be same as "
+ "first operand element type!", &EI);
+ visitInstruction(EI);
}
void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) {
More information about the llvm-commits
mailing list