From a3da83270505fea08f0a4650aa082fa608db54fd Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 22 Jul 2008 20:19:25 +0000 Subject: [PATCH] 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 --- include/llvm/Support/IRBuilder.h | 35 +++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h index d69a35edb12..95d9c5a0600 100644 --- a/include/llvm/Support/IRBuilder.h +++ b/include/llvm/Support/IRBuilder.h @@ -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(Agg)) + return ConstantExpr::getExtractValue(AggC, &Idx, 1); return Insert(ExtractValueInst::Create(Agg, Idx), Name); } template - 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(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(Agg)) + if (Constant *ValC = dyn_cast(Val)) + return ConstantExpr::getInsertValue(AggC, ValC, &Idx, 1); return Insert(InsertValueInst::Create(Agg, Val, Idx), Name); } template - 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(Agg)) + if (Constant *ValC = dyn_cast(Val)) + return ConstantExpr::getInsertValue(AggC, ValC, + IdxBegin, IdxEnd - IdxBegin); return Insert(InsertValueInst::Create(Agg, Val, IdxBegin, IdxEnd), Name); } };