aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-05-23 00:36:11 +0000
committerDan Gohman <gohman@apple.com>2008-05-23 00:36:11 +0000
commit71af7153bc44e5526d4ebb28a30e464aa85566d7 (patch)
tree8918af17baca9e072ee2f33e1b1ee4bdc3faa294 /lib/VMCore
parentf9a85a33113be7403c6321c708741036ce04dcc8 (diff)
downloadexternal_llvm-71af7153bc44e5526d4ebb28a30e464aa85566d7.zip
external_llvm-71af7153bc44e5526d4ebb28a30e464aa85566d7.tar.gz
external_llvm-71af7153bc44e5526d4ebb28a30e464aa85566d7.tar.bz2
Add more IR support for the new extractvalue and insertvalue
instructions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51461 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/Constants.cpp23
-rw-r--r--lib/VMCore/Instructions.cpp68
2 files changed, 79 insertions, 12 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 75a2b00..1a79811 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -2308,8 +2308,8 @@ Constant *ConstantExpr::getInsertValueTy(const Type *ReqTy, Constant *Agg,
if (Constant *FC = ConstantFoldInsertValue(Agg, Val, Idxs, NumIdx))
return FC; // Fold a few common cases...
- assert(isa<PointerType>(Agg->getType()) &&
- "Non-pointer type for constant InsertValue expression");
+ assert(Agg->getType()->isFirstClassType() &&
+ "Non-first-class type for constant InsertValue expression");
// Look up the constant in the table first to ensure uniqueness
std::vector<Constant*> ArgVec;
ArgVec.reserve(NumIdx+2);
@@ -2323,13 +2323,13 @@ Constant *ConstantExpr::getInsertValueTy(const Type *ReqTy, Constant *Agg,
Constant *ConstantExpr::getInsertValue(Constant *Agg, Constant *Val,
Constant* const *IdxList, unsigned NumIdx) {
- assert((isa<StructType>(Agg->getType()) || isa<ArrayType>(Agg->getType()) ||
- isa<VectorType>(Agg->getType())) &&
- "Tried to create insertelement operation on non-aggregate type!");
+ assert(Agg->getType()->isFirstClassType() &&
+ "Tried to create insertelement operation on non-first-class type!");
- const Type *ReqTy =
+ const Type *ReqTy = Agg->getType();
+ const Type *ValTy =
ExtractValueInst::getIndexedType(Agg->getType(), IdxList, IdxList+NumIdx);
- assert(ReqTy && "insertvalue indices invalid!");
+ assert(ValTy == Val->getType() && "insertvalue indices invalid!");
return getInsertValueTy(ReqTy, Agg, Val, IdxList, NumIdx);
}
@@ -2342,8 +2342,8 @@ Constant *ConstantExpr::getExtractValueTy(const Type *ReqTy, Constant *Agg,
if (Constant *FC = ConstantFoldExtractValue(Agg, Idxs, NumIdx))
return FC; // Fold a few common cases...
- assert(isa<PointerType>(Agg->getType()) &&
- "Non-pointer type for constant ExtractValue expression");
+ assert(Agg->getType()->isFirstClassType() &&
+ "Non-first-class type for constant extractvalue expression");
// Look up the constant in the table first to ensure uniqueness
std::vector<Constant*> ArgVec;
ArgVec.reserve(NumIdx+1);
@@ -2356,9 +2356,8 @@ Constant *ConstantExpr::getExtractValueTy(const Type *ReqTy, Constant *Agg,
Constant *ConstantExpr::getExtractValue(Constant *Agg,
Constant* const *IdxList, unsigned NumIdx) {
- assert((isa<StructType>(Agg->getType()) || isa<ArrayType>(Agg->getType()) ||
- isa<VectorType>(Agg->getType())) &&
- "Tried to create extractelement operation on non-aggregate type!");
+ assert(Agg->getType()->isFirstClassType() &&
+ "Tried to create extractelement operation on non-first-class type!");
const Type *ReqTy =
ExtractValueInst::getIndexedType(Agg->getType(), IdxList, IdxList+NumIdx);
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index 40eea13..95e0fc5 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -1333,9 +1333,69 @@ int ShuffleVectorInst::getMaskValue(unsigned i) const {
}
//===----------------------------------------------------------------------===//
+// InsertValueInst Class
+//===----------------------------------------------------------------------===//
+
+void InsertValueInst::init(Value *Agg, Value *Val, Value* const *Idx, unsigned NumIdx) {
+ assert(NumOperands == 1+NumIdx && "NumOperands not initialized?");
+ Use *OL = OperandList;
+ OL[0].init(Agg, this);
+ OL[1].init(Val, this);
+
+ for (unsigned i = 0; i != NumIdx; ++i)
+ OL[i+2].init(Idx[i], this);
+}
+
+void InsertValueInst::init(Value *Agg, Value *Val, Value *Idx) {
+ assert(NumOperands == 3 && "NumOperands not initialized?");
+ Use *OL = OperandList;
+ OL[0].init(Agg, this);
+ OL[1].init(Val, this);
+ OL[2].init(Idx, this);
+}
+
+InsertValueInst::InsertValueInst(const InsertValueInst &IVI)
+ : Instruction(reinterpret_cast<const Type*>(IVI.getType()), InsertValue,
+ OperandTraits<InsertValueInst>::op_end(this)
+ - IVI.getNumOperands(),
+ IVI.getNumOperands()) {
+ Use *OL = OperandList;
+ Use *IVIOL = IVI.OperandList;
+ for (unsigned i = 0, E = NumOperands; i != E; ++i)
+ OL[i].init(IVIOL[i], this);
+}
+
+//===----------------------------------------------------------------------===//
// ExtractValueInst Class
//===----------------------------------------------------------------------===//
+void ExtractValueInst::init(Value *Agg, Value* const *Idx, unsigned NumIdx) {
+ assert(NumOperands == 1+NumIdx && "NumOperands not initialized?");
+ Use *OL = OperandList;
+ OL[0].init(Agg, this);
+
+ for (unsigned i = 0; i != NumIdx; ++i)
+ OL[i+1].init(Idx[i], this);
+}
+
+void ExtractValueInst::init(Value *Agg, Value *Idx) {
+ assert(NumOperands == 2 && "NumOperands not initialized?");
+ Use *OL = OperandList;
+ OL[0].init(Agg, this);
+ OL[1].init(Idx, this);
+}
+
+ExtractValueInst::ExtractValueInst(const ExtractValueInst &EVI)
+ : Instruction(reinterpret_cast<const Type*>(EVI.getType()), ExtractValue,
+ OperandTraits<ExtractValueInst>::op_end(this)
+ - EVI.getNumOperands(),
+ EVI.getNumOperands()) {
+ Use *OL = OperandList;
+ Use *EVIOL = EVI.OperandList;
+ for (unsigned i = 0, E = NumOperands; i != E; ++i)
+ OL[i].init(EVIOL[i], this);
+}
+
// getIndexedType - Returns the type of the element that would be extracted
// with an extractvalue instruction with the specified parameters.
//
@@ -2809,6 +2869,14 @@ VICmpInst* VICmpInst::clone() const {
return new VICmpInst(getPredicate(), Op<0>(), Op<1>());
}
+ExtractValueInst *ExtractValueInst::clone() const {
+ return new(getNumOperands()) ExtractValueInst(*this);
+}
+InsertValueInst *InsertValueInst::clone() const {
+ return new(getNumOperands()) InsertValueInst(*this);
+}
+
+
MallocInst *MallocInst::clone() const { return new MallocInst(*this); }
AllocaInst *AllocaInst::clone() const { return new AllocaInst(*this); }
FreeInst *FreeInst::clone() const { return new FreeInst(getOperand(0)); }