#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
//
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)
}
// 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!");
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;
}
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;
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;
// 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 &&
// 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);
}
}