Minor cleanups and simplifications
authorChris Lattner <sabre@nondot.org>
Fri, 21 Nov 2003 16:52:05 +0000 (16:52 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 21 Nov 2003 16:52:05 +0000 (16:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10127 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/ADCE.cpp
lib/Transforms/Scalar/TailRecursionElimination.cpp
lib/Transforms/Utils/BreakCriticalEdges.cpp
lib/Transforms/Utils/LoopSimplify.cpp
lib/Transforms/Utils/LowerSwitch.cpp
lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
lib/VMCore/BasicBlock.cpp

index 5a5151e8b64858f54ddc6536a0ddd545d1564ca1..4d7efd8ae4de0b0895079f3fa257d51fbac51770 100644 (file)
@@ -302,7 +302,7 @@ bool ADCE::doADCE() {
     //
     if (!AliveBlocks.count(&Func->front())) {
       BasicBlock *NewEntry = new BasicBlock();
-      new BranchInst(&Func->front(), 0, 0, NewEntry);
+      new BranchInst(&Func->front(), NewEntry);
       Func->getBasicBlockList().push_front(NewEntry);
       AliveBlocks.insert(NewEntry);    // This block is always alive!
       LiveSet.insert(NewEntry->getTerminator());  // The branch is live
index 87cd27d22be8c5989150584e851acb8dff26843d..f8215c57718b816bdc712af5888629611d7821e3 100644 (file)
@@ -76,7 +76,7 @@ bool TailCallElim::runOnFunction(Function &F) {
               // us to branch back to the old entry block.
               OldEntry = &F.getEntryBlock();
               BasicBlock *NewEntry = new BasicBlock("tailrecurse", OldEntry);
-              new BranchInst(OldEntry, 0, 0, NewEntry);
+              new BranchInst(OldEntry, NewEntry);
               
               // Now that we have created a new block, which jumps to the entry
               // block, insert a PHI node for each argument of the function.
index 0b597102d87617f00ca903ee6b629ae9317810c4..1175b1053b2d386dace2552c1d4c33d5a6ed02a4 100644 (file)
@@ -106,7 +106,7 @@ bool SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P) {
   BasicBlock *NewBB = new BasicBlock(TIBB->getName() + "." +
                                      DestBB->getName() + "_crit_edge");
   // Create our unconditional branch...
-  new BranchInst(DestBB, 0, 0, NewBB);
+  new BranchInst(DestBB, NewBB);
   
   // Branch to the new block, breaking the edge...
   TI->setSuccessor(SuccNum, NewBB);
index 46f2beb34b03afc39b9ad3b280b11d632a8469ca..60e35d5ca927e92cb3a2bfa89f5eb705e1908e3a 100644 (file)
@@ -153,7 +153,7 @@ BasicBlock *LoopSimplify::SplitBlockPredecessors(BasicBlock *BB,
   BasicBlock *NewBB = new BasicBlock(BB->getName()+Suffix, BB);
 
   // The preheader first gets an unconditional branch to the loop header...
-  BranchInst *BI = new BranchInst(BB, 0, 0, NewBB);
+  BranchInst *BI = new BranchInst(BB, NewBB);
   
   // For every PHI node in the block, insert a PHI node into NewBB where the
   // incoming values from the out of loop edges are moved to NewBB.  We have two
@@ -379,7 +379,7 @@ void LoopSimplify::InsertUniqueBackedgeBlock(Loop *L) {
 
   // Create and insert the new backedge block...
   BasicBlock *BEBlock = new BasicBlock(Header->getName()+".backedge", F);
-  BranchInst *BETerminator = new BranchInst(Header, 0, 0, BEBlock);
+  BranchInst *BETerminator = new BranchInst(Header, BEBlock);
 
   // Move the new backedge block to right after the last backedge block.
   Function::iterator InsertPos = BackedgeBlocks.back(); ++InsertPos;
index bec23fffc8586079482d3a1b58139f7fe955afa4..24e48d4c5d26d0901bd0a30140a5b3ca8136df7b 100644 (file)
@@ -186,7 +186,7 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI) {
 
   // If there is only the default destination, don't bother with the code below.
   if (SI->getNumOperands() == 2) {
-    new BranchInst(SI->getDefaultDest(), 0, 0, CurBlock);
+    new BranchInst(SI->getDefaultDest(), CurBlock);
     delete SI;
     return;
   }
@@ -196,7 +196,7 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI) {
   BasicBlock* NewDefault = new BasicBlock("NewDefault");
   F->getBasicBlockList().insert(Default, NewDefault);
 
-  new BranchInst(Default, 0, 0, NewDefault);
+  new BranchInst(Default, NewDefault);
 
   // If there is an entry in any PHI nodes for the default edge, make sure
   // to update them as well.
@@ -219,7 +219,7 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI) {
                                           OrigBlock, NewDefault);
 
   // Branch to our shiny new if-then stuff...
-  new BranchInst(SwitchBlock, 0, 0, OrigBlock);
+  new BranchInst(SwitchBlock, OrigBlock);
 
   // We are now done with the switch instruction, delete it.
   delete SI;
index 18164220f840a05a1e7fc93dfc71a15c14ffb93a..064bba5dddd0f36de4596f3bc4ce6940c4f82271 100644 (file)
 #include "llvm/iTerminators.h"
 #include "llvm/iPHINode.h"
 #include "llvm/Type.h"
-
-namespace llvm {
+using namespace llvm;
 
 static RegisterOpt<UnifyFunctionExitNodes>
 X("mergereturn", "Unify function exit nodes");
 
-Pass *createUnifyFunctionExitNodesPass() {
+Pass *llvm::createUnifyFunctionExitNodesPass() {
   return new UnifyFunctionExitNodes();
 }
 
@@ -91,11 +90,8 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) {
     // If the function doesn't return void... add a PHI node to the block...
     PN = new PHINode(F.getReturnType(), "UnifiedRetVal");
     NewRetBlock->getInstList().push_back(PN);
-    new ReturnInst(PN, NewRetBlock);
-  } else {
-    // If it returns void, just add a return void instruction to the block
-    new ReturnInst(0, NewRetBlock);
   }
+  new ReturnInst(PN, NewRetBlock);
 
   // Loop over all of the blocks, replacing the return instruction with an
   // unconditional branch.
@@ -109,10 +105,8 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) {
     if (PN) PN->addIncoming(BB->getTerminator()->getOperand(0), BB);
 
     BB->getInstList().pop_back();  // Remove the return insn
-    new BranchInst(NewRetBlock, 0, 0, BB);
+    new BranchInst(NewRetBlock, BB);
   }
   ReturnBlock = NewRetBlock;
   return true;
 }
-
-} // End llvm namespace
index b00ce51f2f71e59f9876d156d0632f99e2651013..f2b551bbd90ca1f3dabe471b72bf0a820306bbd8 100644 (file)
 #include "Support/LeakDetector.h"
 #include "SymbolTableListTraitsImpl.h"
 #include <algorithm>
+using namespace llvm;
+
+namespace {
+  /// DummyInst - An instance of this class is used to mark the end of the
+  /// instruction list.  This is not a real instruction.
+  struct DummyInst : public Instruction {
+    DummyInst() : Instruction(Type::VoidTy, OtherOpsEnd) {
+      // This should not be garbage monitored.
+      LeakDetector::removeGarbageObject(this);
+    }
 
-namespace llvm {
-
-// DummyInst - An instance of this class is used to mark the end of the
-// instruction list.  This is not a real instruction.
-//
-struct DummyInst : public Instruction {
-  DummyInst() : Instruction(Type::VoidTy, OtherOpsEnd) {
-    // This should not be garbage monitored.
-    LeakDetector::removeGarbageObject(this);
-  }
-
-  virtual Instruction *clone() const {
-    assert(0 && "Cannot clone EOL");abort();
-    return 0;
-  }
-  virtual const char *getOpcodeName() const { return "*end-of-list-inst*"; }
+    virtual Instruction *clone() const {
+      assert(0 && "Cannot clone EOL");abort();
+      return 0;
+    }
+    virtual const char *getOpcodeName() const { return "*end-of-list-inst*"; }
 
-  // Methods for support type inquiry through isa, cast, and dyn_cast...
-  static inline bool classof(const DummyInst *) { return true; }
-  static inline bool classof(const Instruction *I) {
-    return I->getOpcode() == OtherOpsEnd;
-  }
-  static inline bool classof(const Value *V) {
-    return isa<Instruction>(V) && classof(cast<Instruction>(V));
-  }
-};
+    // Methods for support type inquiry through isa, cast, and dyn_cast...
+    static inline bool classof(const DummyInst *) { return true; }
+    static inline bool classof(const Instruction *I) {
+      return I->getOpcode() == OtherOpsEnd;
+    }
+    static inline bool classof(const Value *V) {
+      return isa<Instruction>(V) && classof(cast<Instruction>(V));
+    }
+  };
+}
 
 Instruction *ilist_traits<Instruction>::createNode() {
   return new DummyInst();
@@ -243,7 +243,7 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const std::string &BBName) {
   } while (Inst != &*I);   // Loop until we move the specified instruction.
 
   // Add a branch instruction to the newly formed basic block.
-  new BranchInst(New, 0, 0, this);
+  new BranchInst(New, this);
 
   // Now we must loop through all of the successors of the New block (which
   // _were_ the successors of the 'this' block), and update any PHI nodes in
@@ -265,5 +265,3 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const std::string &BBName) {
   }
   return New;
 }
-
-} // End llvm namespace