[llvm-commits] [llvm] r53931 - /llvm/trunk/include/llvm/Support/IRBuilder.h

Dan Gohman gohman at apple.com
Tue Jul 22 13:19:26 PDT 2008


Author: djg
Date: Tue Jul 22 15:19:25 2008
New Revision: 53931

URL: http://llvm.org/viewvc/llvm-project?rev=53931&view=rev
Log:
Add insertvalue and extractvalue folding support in IRBuilder.

Modified:
    llvm/trunk/include/llvm/Support/IRBuilder.h

Modified: llvm/trunk/include/llvm/Support/IRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/IRBuilder.h?rev=53931&r1=53930&r2=53931&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/IRBuilder.h (original)
+++ llvm/trunk/include/llvm/Support/IRBuilder.h Tue Jul 22 15:19:25 2008
@@ -573,29 +573,40 @@
     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);
   }
 };





More information about the llvm-commits mailing list