Add insertvalue and extractvalue folding support in IRBuilder.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53931 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2008-07-22 20:19:25 +00:00
parent 8502112419
commit a3da832705

View File

@ -573,29 +573,40 @@ public:
return Insert(new GetResultInst(V, Index), Name);
}
ExtractValueInst *CreateExtractValue(Value *Agg, unsigned Idx,
const char *Name = "") {
Value *CreateExtractValue(Value *Agg, unsigned Idx,
const char *Name = "") {
if (Constant *AggC = dyn_cast<Constant>(Agg))
return ConstantExpr::getExtractValue(AggC, &Idx, 1);
return Insert(ExtractValueInst::Create(Agg, Idx), Name);
}
template<typename InputIterator>
ExtractValueInst *CreateExtractValue(Value *Agg,
InputIterator IdxBegin,
InputIterator IdxEnd,
const char *Name = "") {
Value *CreateExtractValue(Value *Agg,
InputIterator IdxBegin,
InputIterator IdxEnd,
const char *Name = "") {
if (Constant *AggC = dyn_cast<Constant>(Agg))
return ConstantExpr::getExtractValue(AggC, IdxBegin, IdxEnd - IdxBegin);
return Insert(ExtractValueInst::Create(Agg, IdxBegin, IdxEnd), Name);
}
InsertValueInst *CreateInsertValue(Value *Agg, Value *Val, unsigned Idx,
const char *Name = "") {
Value *CreateInsertValue(Value *Agg, Value *Val, unsigned Idx,
const char *Name = "") {
if (Constant *AggC = dyn_cast<Constant>(Agg))
if (Constant *ValC = dyn_cast<Constant>(Val))
return ConstantExpr::getInsertValue(AggC, ValC, &Idx, 1);
return Insert(InsertValueInst::Create(Agg, Val, Idx), Name);
}
template<typename InputIterator>
InsertValueInst *CreateInsertValue(Value *Agg, Value *Val,
InputIterator IdxBegin,
InputIterator IdxEnd,
const char *Name = "") {
Value *CreateInsertValue(Value *Agg, Value *Val,
InputIterator IdxBegin,
InputIterator IdxEnd,
const char *Name = "") {
if (Constant *AggC = dyn_cast<Constant>(Agg))
if (Constant *ValC = dyn_cast<Constant>(Val))
return ConstantExpr::getInsertValue(AggC, ValC,
IdxBegin, IdxEnd - IdxBegin);
return Insert(InsertValueInst::Create(Agg, Val, IdxBegin, IdxEnd), Name);
}
};