diff options
author | Dan Gohman <gohman@apple.com> | 2008-07-22 20:19:25 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2008-07-22 20:19:25 +0000 |
commit | a3da83270505fea08f0a4650aa082fa608db54fd (patch) | |
tree | d7dbe046a35286650787496674bcf24aa65c7c7a | |
parent | 8502112419c43eec044c70a101c6e863fa919cfb (diff) |
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
-rw-r--r-- | include/llvm/Support/IRBuilder.h | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h index d69a35edb1..95d9c5a060 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<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); } }; |