[llvm-commits] [llvm] r52435 - in /llvm/trunk: include/llvm/AutoUpgrade.h lib/VMCore/AutoUpgrade.cpp

Dan Gohman gohman at apple.com
Tue Jun 17 16:38:43 PDT 2008


Author: djg
Date: Tue Jun 17 18:38:43 2008
New Revision: 52435

URL: http://llvm.org/viewvc/llvm-project?rev=52435&view=rev
Log:
Auto-upgrade code for multiple-value return statements. This code
isn't actually called yet.

Modified:
    llvm/trunk/include/llvm/AutoUpgrade.h
    llvm/trunk/lib/VMCore/AutoUpgrade.cpp

Modified: llvm/trunk/include/llvm/AutoUpgrade.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/AutoUpgrade.h?rev=52435&r1=52434&r2=52435&view=diff

==============================================================================
--- llvm/trunk/include/llvm/AutoUpgrade.h (original)
+++ llvm/trunk/include/llvm/AutoUpgrade.h Tue Jun 17 18:38:43 2008
@@ -35,6 +35,12 @@
   /// so that it can update all calls to the old function.
   void UpgradeCallsToIntrinsic(Function* F);
 
+  /// This is an auto-upgrade hook for mutiple-value return statements.
+  /// This function auto-upgrades all such return statements in the given
+  /// function to use aggregate return values built with insertvalue
+  /// instructions.
+  void UpgradeMultipleReturnValues(Function *F);
+
 } // End llvm namespace
 
 #endif

Modified: llvm/trunk/lib/VMCore/AutoUpgrade.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AutoUpgrade.cpp?rev=52435&r1=52434&r2=52435&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/AutoUpgrade.cpp (original)
+++ llvm/trunk/lib/VMCore/AutoUpgrade.cpp Tue Jun 17 18:38:43 2008
@@ -391,3 +391,27 @@
   }
 }
 
+/// This is an auto-upgrade hook for mutiple-value return statements.
+/// This function auto-upgrades all such return statements in the given
+/// function to use aggregate return values built with insertvalue
+/// instructions.
+void llvm::UpgradeMultipleReturnValues(Function *CurrentFunction) {
+  for (Function::iterator I = CurrentFunction->begin(),
+       E = CurrentFunction->end(); I != E; ++I) {
+    BasicBlock *BB = I;
+    if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) {
+      unsigned NumVals = RI->getNumOperands();
+      if (NumVals > 1) {
+        std::vector<const Type *> Types(NumVals);
+        for (unsigned i = 0; i != NumVals; ++i)
+          Types[i] = RI->getOperand(i)->getType();
+        const Type *ReturnType = StructType::get(Types);
+        Value *RV = UndefValue::get(ReturnType);
+        for (unsigned i = 0; i != NumVals; ++i)
+          RV = InsertValueInst::Create(RV, RI->getOperand(i), i, "mrv", RI);
+        ReturnInst::Create(RV, RI);
+        RI->eraseFromParent();
+      }
+    }
+  }
+}





More information about the llvm-commits mailing list