Implementation of the new spiffy pass system
[oota-llvm.git] / lib / VMCore / BasicBlock.cpp
index 7d97c85f7de3001f264727c33ada8eddcd3bcb75..df999b84bffd3072e7182042e476c89c57a0a008 100644 (file)
@@ -10,7 +10,7 @@
 #include "llvm/Method.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/Type.h"
-#include "llvm/iOther.h"
+#include "llvm/iPHINode.h"
 #include "llvm/CodeGen/MachineInstr.h"
 
 // Instantiate Templates - This ugliness is the price we have to pay
@@ -18,7 +18,7 @@
 //
 template class ValueHolder<Instruction, BasicBlock, Method>;
 
-BasicBlock::BasicBlock(const string &name, Method *Parent)
+BasicBlock::BasicBlock(const std::string &name, Method *Parent)
   : Value(Type::LabelTy, Value::BasicBlockVal, name), InstList(this, 0),
     machineInstrVec(new MachineCodeForBasicBlock) {
   if (Parent)
@@ -32,7 +32,7 @@ BasicBlock::~BasicBlock() {
 }
 
 // Specialize setName to take care of symbol table majik
-void BasicBlock::setName(const string &name, SymbolTable *ST) {
+void BasicBlock::setName(const std::string &name, SymbolTable *ST) {
   Method *P;
   assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) &&
         "Invalid symtab argument!");
@@ -54,14 +54,14 @@ void BasicBlock::setParent(Method *parent) {
 TerminatorInst *BasicBlock::getTerminator() {
   if (InstList.empty()) return 0;
   Instruction *T = InstList.back();
-  if (T->isTerminator()) return (TerminatorInst*)T;
+  if (isa<TerminatorInst>(T)) return cast<TerminatorInst>(T);
   return 0;
 }
 
 const TerminatorInst *const BasicBlock::getTerminator() const {
   if (InstList.empty()) return 0;
-  const Instruction *T = InstList.back();
-  if (T->isTerminator()) return (TerminatorInst*)T;
+  if (const TerminatorInst *TI = dyn_cast<TerminatorInst>(InstList.back()))
+    return TI;
   return 0;
 }
 
@@ -70,14 +70,14 @@ void BasicBlock::dropAllReferences() {
           std::mem_fun(&Instruction::dropAllReferences));
 }
 
-// hasConstantPoolReferences() - This predicate is true if there is a 
+// hasConstantReferences() - This predicate is true if there is a 
 // reference to this basic block in the constant pool for this method.  For
 // example, if a block is reached through a switch table, that table resides
 // in the constant pool, and the basic block is reference from it.
 //
-bool BasicBlock::hasConstantPoolReferences() const {
+bool BasicBlock::hasConstantReferences() const {
   for (use_const_iterator I = use_begin(), E = use_end(); I != E; ++I)
-    if ((*I)->isConstant())
+    if (::isa<Constant>(*I))
       return true;
 
   return false;
@@ -92,7 +92,7 @@ bool BasicBlock::hasConstantPoolReferences() const {
 void BasicBlock::removePredecessor(BasicBlock *Pred) {
   assert(find(pred_begin(), pred_end(), Pred) != pred_end() &&
         "removePredecessor: BB is not a predecessor!");
-  if (!front()->isPHINode()) return;   // Quick exit.
+  if (!isa<PHINode>(front())) return;   // Quick exit.
 
   pred_iterator PI(pred_begin()), EI(pred_end());
   unsigned max_idx;
@@ -105,8 +105,8 @@ void BasicBlock::removePredecessor(BasicBlock *Pred) {
   // altogether.
   assert(max_idx != 0 && "PHI Node in block with 0 predecessors!?!?!");
   if (max_idx <= 2) {                // <= Two predecessors BEFORE I remove one?
-    while (front()->isPHINode()) {   // Yup, loop through and nuke the PHI nodes
-      PHINode *PN = (PHINode*)front();
+    // Yup, loop through and nuke the PHI nodes
+    while (PHINode *PN = dyn_cast<PHINode>(front())) {
       PN->removeIncomingValue(Pred); // Remove the predecessor first...
       
       assert(PN->getNumIncomingValues() == max_idx-1 && 
@@ -121,10 +121,8 @@ void BasicBlock::removePredecessor(BasicBlock *Pred) {
     // Okay, now we know that we need to remove predecessor #pred_idx from all
     // PHI nodes.  Iterate over each PHI node fixing them up
     iterator II(begin());
-    for (; (*II)->isPHINode(); ++II) {
-      PHINode *PN = (PHINode*)*II;
-      PN->removeIncomingValue(Pred);
-    }
+    for (; isa<PHINode>(*II); ++II)
+      cast<PHINode>(*II)->removeIncomingValue(Pred);
   }
 }