Remove 'unwinds to' support from mainline. This patch undoes r47802 r47989
authorNick Lewycky <nicholas@mxc.ca>
Fri, 25 Apr 2008 16:53:59 +0000 (16:53 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Fri, 25 Apr 2008 16:53:59 +0000 (16:53 +0000)
r48047 r48084 r48085 r48086 r48088 r48096 r48099 r48109 and r48123.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50265 91177308-0d34-0410-b5e6-96231b3b80d8

28 files changed:
include/llvm/Analysis/LoopInfo.h
include/llvm/BasicBlock.h
include/llvm/Bitcode/LLVMBitCodes.h
include/llvm/Support/CFG.h
lib/AsmParser/LLLexer.cpp
lib/AsmParser/llvmAsmParser.y
lib/AsmParser/llvmAsmParser.y.cvs
lib/Bitcode/Reader/BitcodeReader.cpp
lib/Bitcode/Writer/BitcodeWriter.cpp
lib/Transforms/IPO/PruneEH.cpp
lib/Transforms/Scalar/InstructionCombining.cpp
lib/Transforms/Scalar/LoopUnroll.cpp
lib/Transforms/Scalar/LoopUnswitch.cpp
lib/Transforms/Scalar/SCCP.cpp
lib/Transforms/Utils/BasicBlockUtils.cpp
lib/Transforms/Utils/CloneFunction.cpp
lib/Transforms/Utils/CloneLoop.cpp
lib/Transforms/Utils/CloneTrace.cpp
lib/Transforms/Utils/InlineFunction.cpp
lib/Transforms/Utils/LoopSimplify.cpp
lib/Transforms/Utils/SimplifyCFG.cpp
lib/VMCore/AsmWriter.cpp
lib/VMCore/BasicBlock.cpp
lib/VMCore/Verifier.cpp
test/Transforms/Inline/unwindto.ll [deleted file]
test/Transforms/PruneEH/unwindto.ll [deleted file]
test/Transforms/SimplifyCFG/unwindto.ll [deleted file]
tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp

index ab7cb7e03e55f577c6b236d6e9575b30ad7160ab..fdb722c225b71350c296dda74093cbec2690936d 100644 (file)
@@ -118,8 +118,8 @@ public:
   block_iterator block_begin() const { return Blocks.begin(); }
   block_iterator block_end() const { return Blocks.end(); }
 
-  /// isLoopExit - True if this block can branch to another block that is
-  /// outside of the current loop.
+  /// isLoopExit - True if terminator in the block can branch to another block
+  /// that is outside of the current loop.
   ///
   bool isLoopExit(const BlockT *BB) const {
     typedef GraphTraits<BlockT*> BlockTraits;
index 797f50e86476e4fc6c19055b0323a9c5656bf693..b569a7aeaf0c42506c98c6ed76ba224267825a89 100644 (file)
@@ -49,14 +49,13 @@ template<> struct ilist_traits<Instruction>
 /// modifying a program. However, the verifier will ensure that basic blocks
 /// are "well formed".
 /// @brief LLVM Basic Block Representation
-class BasicBlock : public User {       // Basic blocks are data objects also
+class BasicBlock : public Value {       // Basic blocks are data objects also
 public:
   typedef iplist<Instruction> InstListType;
 private :
   InstListType InstList;
   BasicBlock *Prev, *Next; // Next and Prev links for our intrusive linked list
   Function *Parent;
-  Use unwindDest;
 
   void setParent(Function *parent);
   void setNext(BasicBlock *N) { Next = N; }
@@ -71,7 +70,7 @@ private :
   /// InsertBefore is null), or before the specified basic block.
   ///
   explicit BasicBlock(const std::string &Name = "", Function *Parent = 0,
-                      BasicBlock *InsertBefore = 0, BasicBlock *UnwindDest = 0);
+                      BasicBlock *InsertBefore = 0);
 public:
   /// Instruction iterators...
   typedef InstListType::iterator                              iterator;
@@ -79,27 +78,21 @@ public:
 
   // allocate space for exactly zero operands
   static BasicBlock *Create(const std::string &Name = "", Function *Parent = 0,
-                            BasicBlock *InsertBefore = 0, BasicBlock *UnwindDest = 0) {
-    return new(!!UnwindDest) BasicBlock(Name, Parent, InsertBefore, UnwindDest);
+                            BasicBlock *InsertBefore = 0) {
+    return new BasicBlock(Name, Parent, InsertBefore);
   }
   ~BasicBlock();
 
-  /// getUnwindDest - Returns the BasicBlock that flow will enter if an unwind
-  /// instruction occurs in this block. May be null, in which case unwinding
-  /// is undefined in this block.
-  const BasicBlock *getUnwindDest() const;
-  BasicBlock *getUnwindDest();
-
-  /// setUnwindDest - Set which BasicBlock flow will enter if an unwind is
-  /// executed within this block. It may be set to null if unwinding is not
-  /// permitted in this block.
-  void setUnwindDest(BasicBlock *unwindDest);
-
   /// getParent - Return the enclosing method, or null if none
   ///
   const Function *getParent() const { return Parent; }
         Function *getParent()       { return Parent; }
 
+  /// use_back - Specialize the methods defined in Value, as we know that an
+  /// BasicBlock can only be used by Instructions (specifically PHI and terms).
+  Instruction       *use_back()       { return cast<Instruction>(*use_begin());}
+  const Instruction *use_back() const { return cast<Instruction>(*use_begin());}
+  
   /// getTerminator() - If this is a well formed basic block, then this returns
   /// a pointer to the terminator instruction.  If it is not, then you get a
   /// null pointer back.
@@ -187,14 +180,7 @@ public:
   /// update the PHI nodes that reside in the block.  Note that this should be
   /// called while the predecessor still refers to this block.
   ///
-  /// DontDeleteUselessPHIs will keep PHIs that have one value or the same 
-  /// value for all entries.
-  ///
-  /// OnlyDeleteOne will only remove one entry from a PHI, in case there were
-  /// duplicate entries for the Pred.
-  ///
-  void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs = false,
-                         bool OnlyDeleteOne = false);
+  void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs = false);
 
   /// splitBasicBlock - This splits a basic block into two at the specified
   /// instruction.  Note that all instructions BEFORE the specified iterator
index 377ff420fd41d1e6e27e8bc57ea2507d110bd679..5ef832e187c66e79ac243bc3b546b46a3750a9b5 100644 (file)
@@ -202,9 +202,7 @@ namespace bitc {
     // this is so information only available in the pointer type (e.g. address
     // spaces) is retained.
     FUNC_CODE_INST_STORE2      = 24, // STORE:      [ptrty,ptr,val, align, vol]
-    FUNC_CODE_INST_GETRESULT   = 25, // GETRESULT:  [ty, opval, n]
-
-    FUNC_CODE_INST_BB_UNWINDDEST = 26  // BB_UNWINDDEST: [bb#]
+    FUNC_CODE_INST_GETRESULT   = 25  // GETRESULT:  [ty, opval, n]
   };
 } // End bitc namespace
 } // End llvm namespace
index f8cbeb0a50f053553e320912a54cfd8df51ddce1..0d49aecb097bfffe0b73f355681d57fdd114935e 100644 (file)
@@ -34,17 +34,14 @@ public:
   typedef PredIterator<_Ptr,_USE_iterator> _Self;
   typedef typename super::pointer pointer;
 
-  inline void advancePastNonPreds() {
-    // Loop to ignore non predecessor uses (for example PHI nodes)...
-    while (!It.atEnd()) {
-      if (isa<TerminatorInst>(*It) || isa<BasicBlock>(*It))
-       break;
+  inline void advancePastNonTerminators() {
+    // Loop to ignore non terminator uses (for example PHI nodes)...
+    while (!It.atEnd() && !isa<TerminatorInst>(*It))
       ++It;
-    }
   }
 
   inline PredIterator(_Ptr *bb) : It(bb->use_begin()) {
-    advancePastNonPreds();
+    advancePastNonTerminators();
   }
   inline PredIterator(_Ptr *bb, bool) : It(bb->use_end()) {}
 
@@ -53,16 +50,13 @@ public:
 
   inline pointer operator*() const {
     assert(!It.atEnd() && "pred_iterator out of range!");
-    if (isa<TerminatorInst>(*It))      // not dyn_cast due to const-correctness
-      return cast<TerminatorInst>(*It)->getParent();
-
-    return cast<_Ptr>(*It);
+    return cast<TerminatorInst>(*It)->getParent();
   }
   inline pointer *operator->() const { return &(operator*()); }
 
   inline _Self& operator++() {   // Preincrement
     assert(!It.atEnd() && "pred_iterator out of range!");
-    ++It; advancePastNonPreds();
+    ++It; advancePastNonTerminators();
     return *this;
   }
 
@@ -106,8 +100,6 @@ public:
   inline SuccIterator(Term_ T, bool)                       // end iterator
     : Term(T), idx(Term->getNumSuccessors()) {
     assert(T && "getTerminator returned null!");
-    if (Term->getParent()->getUnwindDest())
-      ++idx;
   }
 
   inline const _Self &operator=(const _Self &I) {
@@ -123,12 +115,7 @@ public:
   inline bool operator==(const _Self& x) const { return idx == x.idx; }
   inline bool operator!=(const _Self& x) const { return !operator==(x); }
 
-  inline pointer operator*() const {
-    if (idx == Term->getNumSuccessors())
-      return Term->getParent()->getUnwindDest();
-
-    return Term->getSuccessor(idx);
-  }
+  inline pointer operator*() const { return Term->getSuccessor(idx); }
   inline pointer operator->() const { return operator*(); }
 
   inline _Self& operator++() { ++idx; return *this; } // Preincrement
index 106bb4765a72fabddbc758bcda80fe63d683f909..f78079b606268c899cd0dc114c0b31817cac7c95 100644 (file)
@@ -474,7 +474,6 @@ int LLLexer::LexIdentifier() {
   KEYWORD("asm", ASM_TOK);
   KEYWORD("sideeffect", SIDEEFFECT);
   KEYWORD("gc", GC);
-  KEYWORD("unwinds", UNWINDS);
 
   KEYWORD("cc", CC_TOK);
   KEYWORD("ccc", CCC_TOK);
index 27238b6f18c5f7c5d1aa70580f994692a773e533..f3a59ee0a6e8112703ddb8c7430a8e9355f4d0a4 100644 (file)
@@ -517,7 +517,7 @@ static Value *getVal(const Type *Ty, const ValID &ID) {
 
 /// defineBBVal - This is a definition of a new basic block with the specified
 /// identifier which must be the same as CurFun.NextValNum, if its numeric.
-static BasicBlock *defineBBVal(const ValID &ID, BasicBlock *unwindDest) {
+static BasicBlock *defineBBVal(const ValID &ID) {
   assert(inFunctionScope() && "Can't get basic block at global scope!");
 
   BasicBlock *BB = 0;
@@ -559,7 +559,6 @@ static BasicBlock *defineBBVal(const ValID &ID, BasicBlock *unwindDest) {
   }
 
   ID.destroy();
-  BB->setUnwindDest(unwindDest);
   return BB;
 }
 
@@ -1063,7 +1062,7 @@ Module *llvm::RunVMAsmParser(llvm::MemoryBuffer *MB) {
 %token OPAQUE EXTERNAL TARGET TRIPLE ALIGN ADDRSPACE
 %token DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT
 %token CC_TOK CCC_TOK FASTCC_TOK COLDCC_TOK X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
-%token DATALAYOUT UNWINDS
+%token DATALAYOUT
 %type <UIntVal> OptCallingConv
 %type <ParamAttrs> OptParamAttrs ParamAttr 
 %type <ParamAttrs> OptFuncAttrs  FuncAttr
@@ -2559,22 +2558,14 @@ InstructionList : InstructionList Inst {
     CHECK_FOR_ERROR
   }
   | /* empty */ {          // Empty space between instruction lists
-    $$ = defineBBVal(ValID::createLocalID(CurFun.NextValNum), 0);
-    CHECK_FOR_ERROR
-  }
-  | UNWINDS TO ValueRef {   // Only the unwind to block
-    $$ = defineBBVal(ValID::createLocalID(CurFun.NextValNum), getBBVal($3));
+    $$ = defineBBVal(ValID::createLocalID(CurFun.NextValNum));
     CHECK_FOR_ERROR
   }
   | LABELSTR {             // Labelled (named) basic block
-    $$ = defineBBVal(ValID::createLocalName(*$1), 0);
-    delete $1;
-    CHECK_FOR_ERROR
-  }
-  | LABELSTR UNWINDS TO ValueRef {
-    $$ = defineBBVal(ValID::createLocalName(*$1), getBBVal($4));
+    $$ = defineBBVal(ValID::createLocalName(*$1));
     delete $1;
     CHECK_FOR_ERROR
+
   };
 
 BBTerminatorInst : 
index 27238b6f18c5f7c5d1aa70580f994692a773e533..f3a59ee0a6e8112703ddb8c7430a8e9355f4d0a4 100644 (file)
@@ -517,7 +517,7 @@ static Value *getVal(const Type *Ty, const ValID &ID) {
 
 /// defineBBVal - This is a definition of a new basic block with the specified
 /// identifier which must be the same as CurFun.NextValNum, if its numeric.
-static BasicBlock *defineBBVal(const ValID &ID, BasicBlock *unwindDest) {
+static BasicBlock *defineBBVal(const ValID &ID) {
   assert(inFunctionScope() && "Can't get basic block at global scope!");
 
   BasicBlock *BB = 0;
@@ -559,7 +559,6 @@ static BasicBlock *defineBBVal(const ValID &ID, BasicBlock *unwindDest) {
   }
 
   ID.destroy();
-  BB->setUnwindDest(unwindDest);
   return BB;
 }
 
@@ -1063,7 +1062,7 @@ Module *llvm::RunVMAsmParser(llvm::MemoryBuffer *MB) {
 %token OPAQUE EXTERNAL TARGET TRIPLE ALIGN ADDRSPACE
 %token DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT
 %token CC_TOK CCC_TOK FASTCC_TOK COLDCC_TOK X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
-%token DATALAYOUT UNWINDS
+%token DATALAYOUT
 %type <UIntVal> OptCallingConv
 %type <ParamAttrs> OptParamAttrs ParamAttr 
 %type <ParamAttrs> OptFuncAttrs  FuncAttr
@@ -2559,22 +2558,14 @@ InstructionList : InstructionList Inst {
     CHECK_FOR_ERROR
   }
   | /* empty */ {          // Empty space between instruction lists
-    $$ = defineBBVal(ValID::createLocalID(CurFun.NextValNum), 0);
-    CHECK_FOR_ERROR
-  }
-  | UNWINDS TO ValueRef {   // Only the unwind to block
-    $$ = defineBBVal(ValID::createLocalID(CurFun.NextValNum), getBBVal($3));
+    $$ = defineBBVal(ValID::createLocalID(CurFun.NextValNum));
     CHECK_FOR_ERROR
   }
   | LABELSTR {             // Labelled (named) basic block
-    $$ = defineBBVal(ValID::createLocalName(*$1), 0);
-    delete $1;
-    CHECK_FOR_ERROR
-  }
-  | LABELSTR UNWINDS TO ValueRef {
-    $$ = defineBBVal(ValID::createLocalName(*$1), getBBVal($4));
+    $$ = defineBBVal(ValID::createLocalName(*$1));
     delete $1;
     CHECK_FOR_ERROR
+
   };
 
 BBTerminatorInst : 
index ec099a7852a9a437c2e6136be41e41f3f369e5a9..ec25f52b1b04819886305d3e8a5f8bdc986b66f6 100644 (file)
@@ -1224,15 +1224,6 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
       CurBB = FunctionBBs[0];
       continue;
       
-    case bitc::FUNC_CODE_INST_BB_UNWINDDEST:   // BB_UNWINDDEST: [bb#]
-      if (CurBB->getUnwindDest())
-        return Error("Only permit one BB_UNWINDDEST per BB");
-      if (Record.size() != 1)
-        return Error("Invalid BB_UNWINDDEST record");
-
-      CurBB->setUnwindDest(getBasicBlock(Record[0]));
-      continue;
-      
     case bitc::FUNC_CODE_INST_BINOP: {    // BINOP: [opval, ty, opval, opcode]
       unsigned OpNum = 0;
       Value *LHS, *RHS;
index 96f045cd47f49c6dc74210400ae1d5cb7cde8b57..713a82b6b2f7c971ce68b05deac803a183b7f329 100644 (file)
@@ -970,20 +970,13 @@ static void WriteFunction(const Function &F, ValueEnumerator &VE,
   unsigned InstID = CstEnd;
   
   // Finally, emit all the instructions, in order.
-  for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
-    if (const BasicBlock *unwindDest = BB->getUnwindDest()) {
-      Vals.push_back(VE.getValueID(unwindDest));
-      Stream.EmitRecord(bitc::FUNC_CODE_INST_BB_UNWINDDEST, Vals);
-      Vals.clear();
-    }   
-
+  for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
     for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
          I != E; ++I) {
       WriteInstruction(*I, InstID, VE, Stream, Vals);
       if (I->getType() != Type::VoidTy)
         ++InstID;
     }
-  }
   
   // Emit names for all the instructions etc.
   WriteValueSymbolTable(F.getValueSymbolTable(), VE, Stream);
index 1b9aefc58205a28e4e869e5f3e40606f0389774d..01816052569036882a41c9a21faa3c347aa7f42e 100644 (file)
@@ -31,7 +31,6 @@ using namespace llvm;
 
 STATISTIC(NumRemoved, "Number of invokes removed");
 STATISTIC(NumUnreach, "Number of noreturn calls optimized");
-STATISTIC(NumBBUnwind, "Number of unwind dest removed from blocks");
 
 namespace {
   struct VISIBILITY_HIDDEN PruneEH : public CallGraphSCCPass {
@@ -152,8 +151,6 @@ bool PruneEH::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
 bool PruneEH::SimplifyFunction(Function *F) {
   bool MadeChange = false;
   for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
-    bool couldUnwind = false;
-
     if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator()))
       if (II->doesNotThrow()) {
         SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end());
@@ -183,12 +180,10 @@ bool PruneEH::SimplifyFunction(Function *F) {
 
         ++NumRemoved;
         MadeChange = true;
-      } else {
-        couldUnwind = true;
       }
 
     for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; )
-      if (CallInst *CI = dyn_cast<CallInst>(I++)) {
+      if (CallInst *CI = dyn_cast<CallInst>(I++))
         if (CI->doesNotReturn() && !isa<UnreachableInst>(I)) {
           // This call calls a function that cannot return.  Insert an
           // unreachable instruction after it and simplify the code.  Do this
@@ -204,19 +199,9 @@ bool PruneEH::SimplifyFunction(Function *F) {
           MadeChange = true;
           ++NumUnreach;
           break;
-        } else if (!CI->doesNotThrow()) {
-          couldUnwind = true;
         }
-      }
-
-    // Strip 'unwindTo' off of BBs that have no calls/invokes without nounwind.
-    if (!couldUnwind && BB->getUnwindDest()) {
-      MadeChange = true;
-      ++NumBBUnwind;
-      BB->getUnwindDest()->removePredecessor(BB, false, true);
-      BB->setUnwindDest(NULL);
-    }
   }
+
   return MadeChange;
 }
 
index f51f02da677b40a5dbacf819cc280e2fa1f49385..f061d497ea4cc238d63cb4b649c038664bcb1a21 100644 (file)
@@ -11180,15 +11180,12 @@ static void AddReachableCodeToWorklist(BasicBlock *BB,
 
     // Recursively visit successors.  If this is a branch or switch on a
     // constant, only visit the reachable successor.
-    if (BB->getUnwindDest())
-      Worklist.push_back(BB->getUnwindDest());
     TerminatorInst *TI = BB->getTerminator();
     if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
       if (BI->isConditional() && isa<ConstantInt>(BI->getCondition())) {
         bool CondVal = cast<ConstantInt>(BI->getCondition())->getZExtValue();
         BasicBlock *ReachableBB = BI->getSuccessor(!CondVal);
-        if (ReachableBB != BB->getUnwindDest())
-          Worklist.push_back(ReachableBB);
+        Worklist.push_back(ReachableBB);
         continue;
       }
     } else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
@@ -11197,8 +11194,7 @@ static void AddReachableCodeToWorklist(BasicBlock *BB,
         for (unsigned i = 1, e = SI->getNumSuccessors(); i != e; ++i)
           if (SI->getCaseValue(i) == Cond) {
             BasicBlock *ReachableBB = SI->getSuccessor(i);
-            if (ReachableBB != BB->getUnwindDest())
-              Worklist.push_back(ReachableBB);
+            Worklist.push_back(ReachableBB);
             continue;
           }
         
index 1962c14d5d6c64ad669054da0760d99ee8501221..18acb03b1b3e7ce4d2712e572a723f070fb8bcbe 100644 (file)
@@ -405,14 +405,10 @@ bool LoopUnroll::unrollLoop(Loop *L, unsigned Count, unsigned Threshold) {
     }
     
     // Remap all instructions in the most recent iteration
-    for (unsigned i = 0; i < NewBlocks.size(); ++i) {
-      BasicBlock *NB = NewBlocks[i];
-      if (BasicBlock *UnwindDest = NB->getUnwindDest())
-        NB->setUnwindDest(cast<BasicBlock>(LastValueMap[UnwindDest]));
-
-      for (BasicBlock::iterator I = NB->begin(), E = NB->end(); I != E; ++I)
+    for (unsigned i = 0; i < NewBlocks.size(); ++i)
+      for (BasicBlock::iterator I = NewBlocks[i]->begin(),
+           E = NewBlocks[i]->end(); I != E; ++I)
         RemapInstruction(I, LastValueMap);
-    }
   }
   
   // The latch block exits the loop.  If there are any PHI nodes in the
index 943c50f5f9257a738d4864f4f6c32e45eedf3021..47751235304a25f2ac93f7e1cd229f6ccc9b399a 100644 (file)
@@ -819,14 +819,10 @@ void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val,
   }
 
   // Rewrite the code to refer to itself.
-  for (unsigned i = 0, e = NewBlocks.size(); i != e; ++i) {
-    BasicBlock *NB = NewBlocks[i];
-    if (BasicBlock *UnwindDest = NB->getUnwindDest())
-      NB->setUnwindDest(cast<BasicBlock>(ValueMap[UnwindDest]));
-
-    for (BasicBlock::iterator I = NB->begin(), E = NB->end(); I != E; ++I)
+  for (unsigned i = 0, e = NewBlocks.size(); i != e; ++i)
+    for (BasicBlock::iterator I = NewBlocks[i]->begin(),
+           E = NewBlocks[i]->end(); I != E; ++I)
       RemapInstruction(I, ValueMap);
-  }
   
   // Rewrite the original preheader to select between versions of the loop.
   BranchInst *OldBR = cast<BranchInst>(OrigPreheader->getTerminator());
index 1ca29a8c032ee15c57f1d8628ca970406d031478..be071f8b1fa5927e541e1963e74d6c760775f815 100644 (file)
@@ -1727,11 +1727,6 @@ bool IPSCCP::runOnModule(Module &M) {
       // If there are any PHI nodes in this successor, drop entries for BB now.
       BasicBlock *DeadBB = BlocksToErase[i];
       while (!DeadBB->use_empty()) {
-        if (BasicBlock *PredBB = dyn_cast<BasicBlock>(DeadBB->use_back())) {
-          PredBB->setUnwindDest(NULL);
-          continue;
-        }
-
         Instruction *I = cast<Instruction>(DeadBB->use_back());
         bool Folded = ConstantFoldTerminator(I->getParent());
         if (!Folded) {
index f369d8a343c0acd4f37a4baa098ebc9ab6e382d9..93a8c8e593433809738bbc8b6e737b228ce87a71 100644 (file)
@@ -161,7 +161,6 @@ BasicBlock *llvm::SplitBlock(BasicBlock *Old, Instruction *SplitPt, Pass *P) {
   while (isa<PHINode>(SplitIt))
     ++SplitIt;
   BasicBlock *New = Old->splitBasicBlock(SplitIt, Old->getName()+".split");
-  New->setUnwindDest(Old->getUnwindDest());
 
   // The new block lives in whichever loop the old one did.
   if (Loop *L = LI.getLoopFor(Old))
@@ -210,12 +209,8 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB,
   BranchInst *BI = BranchInst::Create(BB, NewBB);
   
   // Move the edges from Preds to point to NewBB instead of BB.
-  for (unsigned i = 0; i != NumPreds; ++i) {
+  for (unsigned i = 0; i != NumPreds; ++i)
     Preds[i]->getTerminator()->replaceUsesOfWith(BB, NewBB);
-    
-    if (Preds[i]->getUnwindDest() == BB)
-      Preds[i]->setUnwindDest(NewBB);
-  }
   
   // Update dominator tree and dominator frontier if available.
   DominatorTree *DT = P ? P->getAnalysisToUpdate<DominatorTree>() : 0;
index ca63399c811521d063965c476f32da098834cd86..54c6a809da3fee9e8b85f241753c0ecceab9b4d4 100644 (file)
@@ -34,7 +34,6 @@ BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB,
                                   ClonedCodeInfo *CodeInfo) {
   BasicBlock *NewBB = BasicBlock::Create("", F);
   if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix);
-  NewBB->setUnwindDest(const_cast<BasicBlock*>(BB->getUnwindDest()));
 
   bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false;
   
@@ -108,15 +107,10 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
   // references as we go.  This uses ValueMap to do all the hard work.
   //
   for (Function::iterator BB = cast<BasicBlock>(ValueMap[OldFunc->begin()]),
-         BE = NewFunc->end(); BB != BE; ++BB) {
-    // Fix up the unwind destination.
-    if (BasicBlock *UnwindDest = BB->getUnwindDest())
-      BB->setUnwindDest(cast<BasicBlock>(ValueMap[UnwindDest]));
-
+         BE = NewFunc->end(); BB != BE; ++BB)
     // Loop over all instructions, fixing each one as we find it...
     for (BasicBlock::iterator II = BB->begin(); II != BB->end(); ++II)
       RemapInstruction(II, ValueMap);
-  }
 }
 
 /// CloneFunction - Return a copy of the specified function, but without
index 7b3359b2f9c6d47009b61075066dd8ae7f726fc9..d52d79598f0518fcf854e0522d6f415f8f9f2af4 100644 (file)
@@ -130,10 +130,6 @@ Loop *llvm::CloneLoop(Loop *OrigL, LPPassManager  *LPM, LoopInfo *LI,
   for(SmallVector<BasicBlock *, 16>::iterator NBItr = NewBlocks.begin(), 
         NBE = NewBlocks.end();  NBItr != NBE; ++NBItr) {
     BasicBlock *NB = *NBItr;
-
-    if (BasicBlock *UnwindDest = NB->getUnwindDest())
-      NB->setUnwindDest(cast<BasicBlock>(ValueMap[UnwindDest]));
-
     for(BasicBlock::iterator BI = NB->begin(), BE = NB->end(); 
         BI != BE; ++BI) {
       Instruction *Insn = BI;
index 968fb5abcc7d2bf7744de319cdb7bb9406d3ffd6..07111393e2757a638fd52af0028e4bdec61380f0 100644 (file)
@@ -68,11 +68,6 @@ llvm::CloneTrace(const std::vector<BasicBlock*> &origTrace) {
   //Second loop to do the remapping
   for (std::vector<BasicBlock *>::const_iterator BB = clonedTrace.begin(),
     BE = clonedTrace.end(); BB != BE; ++BB) {
-
-    //Remap the unwind destination
-    if (BasicBlock *UnwindDest = (*BB)->getUnwindDest())
-      (*BB)->setUnwindDest(cast<BasicBlock>(ValueMap[UnwindDest]));
-
     for (BasicBlock::iterator I = (*BB)->begin(); I != (*BB)->end(); ++I) {
       //Loop over all the operands of the instruction
       for (unsigned op=0, E = I->getNumOperands(); op != E; ++op) {
index 435be0c05cdc39f74ed9f1d66aedff69fe2ffa3f..6c96785aa10be88308b60df900df3d4032ac0687 100644 (file)
@@ -203,7 +203,6 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
 
   BasicBlock *OrigBB = TheCall->getParent();
   Function *Caller = OrigBB->getParent();
-  BasicBlock *UnwindBB = OrigBB->getUnwindDest();
 
   // GC poses two hazards to inlining, which only occur when the callee has GC:
   //  1. If the caller has no GC, then the callee's GC must be propagated to the
@@ -419,18 +418,6 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
       }
     }
 
-  // If we are inlining a function that unwinds into a BB with an unwind dest,
-  // turn the inlined unwinds into branches to the unwind dest.
-  if (InlinedFunctionInfo.ContainsUnwinds && UnwindBB && isa<CallInst>(TheCall))
-    for (Function::iterator BB = FirstNewBlock, E = Caller->end();
-         BB != E; ++BB) {
-      TerminatorInst *Term = BB->getTerminator();
-      if (isa<UnwindInst>(Term)) {
-        BranchInst::Create(UnwindBB, Term);
-        BB->getInstList().erase(Term);
-      }
-    }
-
   // If we are inlining for an invoke instruction, we must make sure to rewrite
   // any inlined 'unwind' instructions into branches to the invoke exception
   // destination, and call instructions into invoke instructions.
index fc97287f191fdca8a59c98e897badc636b553724..8e30e0428629d8c3cc46273b3505b44b6aa69726 100644 (file)
@@ -125,17 +125,18 @@ bool LoopSimplify::runOnFunction(Function &F) {
     if (LI->getLoopFor(BB)) continue;
     
     bool BlockUnreachable = false;
+    TerminatorInst *TI = BB->getTerminator();
 
     // Check to see if any successors of this block are non-loop-header loops
     // that are not the header.
-    for (succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I) {
+    for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i) {
       // If this successor is not in a loop, BB is clearly ok.
-      Loop *L = LI->getLoopFor(*I);
+      Loop *L = LI->getLoopFor(TI->getSuccessor(i));
       if (!L) continue;
       
       // If the succ is the loop header, and if L is a top-level loop, then this
       // is an entrance into a loop through the header, which is also ok.
-      if (L->getHeader() == *I && L->getParentLoop() == 0)
+      if (L->getHeader() == TI->getSuccessor(i) && L->getParentLoop() == 0)
         continue;
       
       // Otherwise, this is an entrance into a loop from some place invalid.
@@ -153,11 +154,10 @@ bool LoopSimplify::runOnFunction(Function &F) {
     // loop by replacing the terminator.
     
     // Remove PHI entries from the successors.
-    for (succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I)
-      (*I)->removePredecessor(BB);
+    for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
+      TI->getSuccessor(i)->removePredecessor(BB);
    
     // Add a new unreachable instruction before the old terminator.
-    TerminatorInst *TI = BB->getTerminator();
     new UnreachableInst(TI);
     
     // Delete the dead terminator.
@@ -576,15 +576,12 @@ void LoopSimplify::InsertUniqueBackedgeBlock(Loop *L) {
   }
 
   // Now that all of the PHI nodes have been inserted and adjusted, modify the
-  // backedge blocks to branch to the BEBlock instead of the header.
+  // backedge blocks to just to the BEBlock instead of the header.
   for (unsigned i = 0, e = BackedgeBlocks.size(); i != e; ++i) {
     TerminatorInst *TI = BackedgeBlocks[i]->getTerminator();
     for (unsigned Op = 0, e = TI->getNumSuccessors(); Op != e; ++Op)
       if (TI->getSuccessor(Op) == Header)
         TI->setSuccessor(Op, BEBlock);
-
-    if (BackedgeBlocks[i]->getUnwindDest() == Header)
-      BackedgeBlocks[i]->setUnwindDest(BEBlock);
   }
 
   //===--- Update all analyses which we must preserve now -----------------===//
index 8b8195ef1e3715f0e3939917b33ada7679261145..7f37b45f2d467bf3974eac687f116e403151c1de 100644 (file)
@@ -1342,8 +1342,6 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
       SmallVector<BasicBlock*, 8> UncondBranchPreds;
       SmallVector<BranchInst*, 8> CondBranchPreds;
       for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
-        if ((*PI)->getUnwindDest() == BB) continue;
-
         TerminatorInst *PTI = (*PI)->getTerminator();
         if (BranchInst *BI = dyn_cast<BranchInst>(PTI)) {
           if (BI->isUnconditional())
@@ -1408,14 +1406,8 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
     SmallVector<BasicBlock*, 8> Preds(pred_begin(BB), pred_end(BB));
     while (!Preds.empty()) {
       BasicBlock *Pred = Preds.back();
-
-      if (Pred->getUnwindDest() == BB) {
-        Pred->setUnwindDest(NULL);
-        Changed = true;
-      }
-
       if (BranchInst *BI = dyn_cast<BranchInst>(Pred->getTerminator())) {
-        if (BI->isUnconditional() && BI->getSuccessor(0) == BB) {
+        if (BI->isUnconditional()) {
           Pred->getInstList().pop_back();  // nuke uncond branch
           new UnwindInst(Pred);            // Use unwind.
           Changed = true;
@@ -1840,7 +1832,6 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
 
   BasicBlock *OnlySucc = 0;
   if (OnlyPred && OnlyPred != BB &&    // Don't break self loops
-      OnlyPred->getUnwindDest() != BB &&
       OnlyPred->getTerminator()->getOpcode() != Instruction::Invoke) {
     // Check to see if there is only one distinct successor...
     succ_iterator SI(succ_begin(OnlyPred)), SE(succ_end(OnlyPred));
@@ -1852,8 +1843,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
       }
   }
 
-  if (OnlySucc && (BB->getUnwindDest() == OnlyPred->getUnwindDest() ||
-                   !BB->getUnwindDest() || !OnlyPred->getUnwindDest())) {
+  if (OnlySucc) {
     DOUT << "Merging: " << *BB << "into: " << *OnlyPred;
 
     // Resolve any PHI nodes at the start of the block.  They are all
@@ -1873,10 +1863,6 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
     // Move all definitions in the successor to the predecessor.
     OnlyPred->getInstList().splice(OnlyPred->end(), BB->getInstList());
 
-    // Move the unwind destination block
-    if (!OnlyPred->getUnwindDest() && BB->getUnwindDest())
-      OnlyPred->setUnwindDest(BB->getUnwindDest());
-
     // Make all PHI nodes that referred to BB now refer to Pred as their
     // source.
     BB->replaceAllUsesWith(OnlyPred);
index 11586b5334474cad7453cf3df8063c987b8376fa..7af26d0e8a73b46ad4c603fceaef840bd9b25958 100644 (file)
@@ -1163,18 +1163,9 @@ void AssemblyWriter::printArgument(const Argument *Arg,
 /// printBasicBlock - This member is called for each basic block in a method.
 ///
 void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
-  if (BB->hasName())              // Print out the label if it exists...
-    Out << '\n' << getLLVMName(BB->getName(), LabelPrefix) << ':';
-
-  if (const BasicBlock* unwindDest = BB->getUnwindDest()) {
-    if (BB->hasName())
-      Out << ' ';
-
-    Out << "unwinds to";
-    writeOperand(unwindDest, false);
-  }
-
-  if (!BB->hasName() && !BB->use_empty()) { // Don't print block # of no uses...
+  if (BB->hasName()) {              // Print out the label if it exists...
+    Out << "\n" << getLLVMName(BB->getName(), LabelPrefix) << ':';
+  } else if (!BB->use_empty()) {      // Don't print block # of no uses...
     Out << "\n; <label>:";
     int Slot = Machine.getLocalSlot(BB);
     if (Slot != -1)
index 16aa7faa0859f6166f91058989ed24a42e1574b7..17469d6bdb2f9b1d61f03977eddd909249568ad9 100644 (file)
@@ -74,8 +74,8 @@ template class SymbolTableListTraits<Instruction, BasicBlock>;
 
 
 BasicBlock::BasicBlock(const std::string &Name, Function *NewParent,
-                       BasicBlock *InsertBefore, BasicBlock *Dest)
-  : User(Type::LabelTy, Value::BasicBlockVal, &unwindDest, 0/*FIXME*/), Parent(0) {
+                       BasicBlock *InsertBefore)
+  : Value(Type::LabelTy, Value::BasicBlockVal), Parent(0) {
 
   // Make sure that we get added to a function
   LeakDetector::addGarbageObject(this);
@@ -89,8 +89,6 @@ BasicBlock::BasicBlock(const std::string &Name, Function *NewParent,
   }
   
   setName(Name);
-  unwindDest.init(NULL, this);
-  setUnwindDest(Dest);
 }
 
 
@@ -119,19 +117,6 @@ void BasicBlock::eraseFromParent() {
   getParent()->getBasicBlockList().erase(this);
 }
 
-const BasicBlock *BasicBlock::getUnwindDest() const {
-  return cast_or_null<const BasicBlock>(unwindDest.get());
-}
-
-BasicBlock *BasicBlock::getUnwindDest() {
-  return cast_or_null<BasicBlock>(unwindDest.get());
-}
-
-void BasicBlock::setUnwindDest(BasicBlock *dest) {
-  NumOperands = unwindDest ? 1 : 0;
-  unwindDest.set(dest);
-}
-
 /// moveBefore - Unlink this basic block from its current function and
 /// insert it into the function that MovePos lives in, right before MovePos.
 void BasicBlock::moveBefore(BasicBlock *MovePos) {
@@ -170,7 +155,6 @@ Instruction* BasicBlock::getFirstNonPHI()
 }
 
 void BasicBlock::dropAllReferences() {
-  setUnwindDest(NULL);
   for(iterator I = begin(), E = end(); I != E; ++I)
     I->dropAllReferences();
 }
@@ -192,8 +176,7 @@ BasicBlock *BasicBlock::getSinglePredecessor() {
 /// called while the predecessor still refers to this block.
 ///
 void BasicBlock::removePredecessor(BasicBlock *Pred,
-                                   bool DontDeleteUselessPHIs,
-                                   bool OnlyDeleteOne) {
+                                   bool DontDeleteUselessPHIs) {
   assert((hasNUsesOrMore(16)||// Reduce cost of this assertion for complex CFGs.
           find(pred_begin(this), pred_end(this), Pred) != pred_end(this)) &&
          "removePredecessor: BB is not a predecessor!");
@@ -228,11 +211,7 @@ void BasicBlock::removePredecessor(BasicBlock *Pred,
     // Yup, loop through and nuke the PHI nodes
     while (PHINode *PN = dyn_cast<PHINode>(&front())) {
       // Remove the predecessor first.
-      if (OnlyDeleteOne) {
-        int idx = PN->getBasicBlockIndex(Pred);
-        PN->removeIncomingValue(idx, !DontDeleteUselessPHIs);
-      } else
-        PN->removeIncomingValue(Pred, !DontDeleteUselessPHIs);
+      PN->removeIncomingValue(Pred, !DontDeleteUselessPHIs);
 
       // If the PHI _HAD_ two uses, replace PHI node with its now *single* value
       if (max_idx == 2) {
@@ -253,12 +232,7 @@ void BasicBlock::removePredecessor(BasicBlock *Pred,
     PHINode *PN;
     for (iterator II = begin(); (PN = dyn_cast<PHINode>(II)); ) {
       ++II;
-      if (OnlyDeleteOne) {
-        int idx = PN->getBasicBlockIndex(Pred);
-        PN->removeIncomingValue(idx, false);
-      } else 
-        PN->removeIncomingValue(Pred, false);
-
+      PN->removeIncomingValue(Pred, false);
       // If all incoming values to the Phi are the same, we can replace the Phi
       // with that value.
       Value* PNV = 0;
@@ -287,7 +261,7 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const std::string &BBName) {
   assert(I != InstList.end() &&
          "Trying to get me to create degenerate basic block!");
 
-  BasicBlock *New = new(0/*FIXME*/) BasicBlock(BBName, getParent(), getNext());
+  BasicBlock *New = BasicBlock::Create(BBName, getParent(), getNext());
 
   // Move all of the specified instructions from the original basic block into
   // the new basic block.
index a0d7d0fe65ee6afca557f23141794332c4a65251..7449fe7ed6fbf037ed6a30610c15566cf72e0887 100644 (file)
@@ -530,12 +530,6 @@ void Verifier::visitBasicBlock(BasicBlock &BB) {
   // Ensure that basic blocks have terminators!
   Assert1(BB.getTerminator(), "Basic Block does not have terminator!", &BB);
 
-  // Ensure that the BB doesn't point out of its Function for unwinding.
-  Assert2(!BB.getUnwindDest() ||
-          BB.getUnwindDest()->getParent() == BB.getParent(),
-          "Basic Block unwinds to block in different function!",
-          &BB, BB.getUnwindDest());
-
   // Check constraints that this basic block imposes on all of the PHI nodes in
   // it.
   if (isa<PHINode>(BB.front())) {
diff --git a/test/Transforms/Inline/unwindto.ll b/test/Transforms/Inline/unwindto.ll
deleted file mode 100644 (file)
index 1213497..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-; RUN: llvm-as < %s | opt -inline | llvm-dis | grep "br label %cleanup"
-
-define void @g() {
-  unwind
-}
-
-define i32 @f1() {
-entry: unwinds to %cleanup
-  call void @g()
-  ret i32 0
-cleanup:
-  ret i32 1
-}
diff --git a/test/Transforms/PruneEH/unwindto.ll b/test/Transforms/PruneEH/unwindto.ll
deleted file mode 100644 (file)
index ed69f4c..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-; RUN: llvm-as < %s | opt -prune-eh | llvm-dis | not grep {unwinds to}
-
-define i8 @test7(i1 %b) {
-entry: unwinds to %cleanup
-  br i1 %b, label %cond_true, label %cond_false
-cond_true: unwinds to %cleanup
-  br label %cleanup
-cond_false: unwinds to %cleanup
-  br label %cleanup
-cleanup:
-  %x = phi i8 [0, %entry], [1, %cond_true], [1, %cond_true],
-                           [2, %cond_false], [2, %cond_false]
-  ret i8 %x
-}
-
diff --git a/test/Transforms/SimplifyCFG/unwindto.ll b/test/Transforms/SimplifyCFG/unwindto.ll
deleted file mode 100644 (file)
index a65e298..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-; RUN: llvm-as < %s | opt -simplifycfg | llvm-dis | grep {unwinds to} | count 3
-
-declare void @g(i32)
-
-define i32 @f1() {
-entry:
-  br label %bb1
-bb1: unwinds to %cleanup1
-  call void @g(i32 0)
-  br label %bb2
-bb2: unwinds to %cleanup2
-  call void @g(i32 1)
-  br label %exit
-exit:
-  ret i32 0
-cleanup1:
-  ret i32 1
-cleanup2:
-  ret i32 2
-}
-
-define i32 @f2() {
-entry: unwinds to %cleanup
-  br label %bb1
-bb1: unwinds to %cleanup
-  br label %bb2
-bb2: unwinds to %cleanup
-  br label %bb3
-bb3:
-  br label %bb4
-bb4: unwinds to %cleanup
-  ret i32 0
-cleanup:
-  ret i32 1
-}
-
-define i32 @f3() {
-entry: unwinds to %cleanup
-  call void @g(i32 0)
-  ret i32 0
-cleanup:
-  unwind
-}
-
-define i32 @f4() {
-entry: unwinds to %cleanup
-  call void @g(i32 0)
-  br label %cleanup
-cleanup:
-  unwind
-}
-
-define i32 @f5() {
-entry: unwinds to %cleanup
-  call void @g(i32 0)
-  br label %other
-other:
-  ret i32 0
-cleanup:
-  unwind
-}
index a7e27e3e08aa9cbb73b64055d4dd3c12dc6eaa73..1cd23679edd3fafea7ad0c1180334cca864934e8 100644 (file)
@@ -172,7 +172,6 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID) {
     switch (CodeID) {
     default: return 0;
     case bitc::FUNC_CODE_DECLAREBLOCKS: return "DECLAREBLOCKS";
-    case bitc::FUNC_CODE_INST_BB_UNWINDDEST: return "UNWINDDEST";
     
     case bitc::FUNC_CODE_INST_BINOP:       return "INST_BINOP";
     case bitc::FUNC_CODE_INST_CAST:        return "INST_CAST";