[llvm-commits] CVS: llvm/lib/Transforms/Utils/CodeExtractor.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Aug 11 20:17:13 PDT 2004



Changes in directory llvm/lib/Transforms/Utils:

CodeExtractor.cpp updated: 1.27 -> 1.28
---
Log message:

Fix code extraction of unwind blocks.  This fixed bugs that bugpoint can
run into.  This should go into 1.3


---
Diffs of the changes:  (+12 -9)

Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
diff -u llvm/lib/Transforms/Utils/CodeExtractor.cpp:1.27 llvm/lib/Transforms/Utils/CodeExtractor.cpp:1.28
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp:1.27	Wed Jul 21 15:50:33 2004
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp	Wed Aug 11 22:17:02 2004
@@ -513,21 +513,24 @@
   }
 
   // Now that we've done the deed, simplify the switch instruction.
+  const Type *OldFnRetTy = TheSwitch->getParent()->getParent()->getReturnType();
   switch (NumExitBlocks) {
   case 0:
-    // There is only 1 successor (the block containing the switch itself), which
+    // There are no successors (the block containing the switch itself), which
     // means that previously this was the last part of the function, and hence
     // this should be rewritten as a `ret'
     
     // Check if the function should return a value
-    if (TheSwitch->getParent()->getParent()->getReturnType() != Type::VoidTy &&
-        TheSwitch->getParent()->getParent()->getReturnType() ==
-        TheSwitch->getCondition()->getType())
+    if (OldFnRetTy == Type::VoidTy) {
+      new ReturnInst(0, TheSwitch);  // Return void
+    } else if (OldFnRetTy == TheSwitch->getCondition()->getType()) {
       // return what we have
       new ReturnInst(TheSwitch->getCondition(), TheSwitch);
-    else
-      // just return
-      new ReturnInst(0, TheSwitch);
+    } else {
+      // Otherwise we must have code extracted an unwind or something, just
+      // return whatever we want.
+      new ReturnInst(Constant::getNullValue(OldFnRetTy), TheSwitch);
+    }
 
     TheSwitch->getParent()->getInstList().erase(TheSwitch);
     break;
@@ -583,8 +586,8 @@
 /// for each scalar output in the function: at every exit, store intermediate 
 /// computed result back into memory.
 ///
-Function *CodeExtractor::ExtractCodeRegion(const std::vector<BasicBlock*> &code)
-{
+Function *CodeExtractor::
+ExtractCodeRegion(const std::vector<BasicBlock*> &code) {
   if (!isEligible(code))
     return 0;
 






More information about the llvm-commits mailing list