#include "llvm/ValueHolderImpl.h"
#include "llvm/BasicBlock.h"
#include "llvm/iTerminators.h"
-#include "llvm/Module.h"
#include "llvm/Method.h"
#include "llvm/SymbolTable.h"
#include "llvm/Type.h"
-#include "llvm/CFG.h"
#include "llvm/iOther.h"
#include "llvm/CodeGen/MachineInstr.h"
template class ValueHolder<Instruction, BasicBlock, Method>;
BasicBlock::BasicBlock(const string &name, Method *Parent)
- : Value(Type::LabelTy, Value::BasicBlockVal, name),
- InstList(this, 0),
- machineInstrVec(new MachineCodeForBasicBlock)
-{
+ : Value(Type::LabelTy, Value::BasicBlockVal, name), InstList(this, 0),
+ machineInstrVec(new MachineCodeForBasicBlock) {
if (Parent)
Parent->getBasicBlocks().push_back(this);
}
}
// Specialize setName to take care of symbol table majik
-void BasicBlock::setName(const string &name) {
+void BasicBlock::setName(const string &name, SymbolTable *ST) {
Method *P;
+ assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) &&
+ "Invalid symtab argument!");
if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this);
Value::setName(name);
if (P && hasName()) P->getSymbolTable()->insert(this);
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;
}
//
bool BasicBlock::hasConstantPoolReferences() const {
for (use_const_iterator I = use_begin(), E = use_end(); I != E; ++I)
- if ((*I)->isConstant())
+ if (::isa<ConstPoolVal>(*I))
return true;
return false;
// called while the predecessor still refers to this block.
//
void BasicBlock::removePredecessor(BasicBlock *Pred) {
- using cfg::pred_begin; using cfg::pred_end; using cfg::pred_iterator;
- assert(find(pred_begin(this), pred_end(this), Pred) != pred_end(this) &&
+ 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(this)), EI(pred_end(this));
+ pred_iterator PI(pred_begin()), EI(pred_end());
unsigned max_idx;
// Loop over the rest of the predecessors until we run out, or until we find
// 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);
}
}