// This file contains the declaration of the BasicBlock class, which represents
// a single basic block in the VM.
//
-// Note that basic blocks themselves are Def's, because they are referenced
+// Note that basic blocks themselves are Value's, because they are referenced
// by instructions like branches and can go in switch tables and stuff...
//
-// This may see wierd at first, but it's really pretty cool. :)
-//
//===----------------------------------------------------------------------===//
//
// Note that well formed basic blocks are formed of a list of instructions
#ifndef LLVM_BASICBLOCK_H
#define LLVM_BASICBLOCK_H
-#include "llvm/Value.h" // Get the definition of Value
#include "llvm/ValueHolder.h"
-#include "llvm/CFGdecls.h"
+#include "llvm/Value.h"
-class Instruction;
-class Method;
class TerminatorInst;
+class MachineCodeForBasicBlock;
+template <class _Term, class _BB> class SuccIterator; // Successor Iterator
+template <class _Ptr, class _USE_iterator> class PredIterator;
class BasicBlock : public Value { // Basic blocks are data objects also
public:
- typedef ValueHolder<Instruction, BasicBlock> InstListType;
+ typedef ValueHolder<Instruction, BasicBlock, Function> InstListType;
private :
InstListType InstList;
+ MachineCodeForBasicBlock* machineInstrVec;
- friend class ValueHolder<BasicBlock,Method>;
- void setParent(Method *parent);
+ friend class ValueHolder<BasicBlock,Function,Function>;
+ void setParent(Function *parent);
public:
// Instruction iterators...
typedef InstListType::iterator iterator;
typedef InstListType::const_iterator const_iterator;
- typedef reverse_iterator<const_iterator> const_reverse_iterator;
- typedef reverse_iterator<iterator> reverse_iterator;
-
- typedef cfg::succ_iterator succ_iterator; // Include CFG.h to use these
- typedef cfg::pred_iterator pred_iterator;
- typedef cfg::succ_const_iterator succ_const_iterator;
- typedef cfg::pred_const_iterator pred_const_iterator;
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+ typedef std::reverse_iterator<iterator> reverse_iterator;
- BasicBlock(const string &Name = "", Method *Parent = 0);
+ // Ctor, dtor
+ BasicBlock(const std::string &Name = "", Function *Parent = 0);
~BasicBlock();
// Specialize setName to take care of symbol table majik
- virtual void setName(const string &name);
+ virtual void setName(const std::string &name, SymbolTable *ST = 0);
- const Method *getParent() const { return (const Method*)InstList.getParent();}
- Method *getParent() { return (Method*)InstList.getParent(); }
+ // getParent - Return the enclosing method, or null if none
+ const Function *getParent() const { return InstList.getParent(); }
+ Function *getParent() { return InstList.getParent(); }
// 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
//
TerminatorInst *getTerminator();
const TerminatorInst *const getTerminator() const;
-
+
+ // Machine code accessor...
+ inline MachineCodeForBasicBlock& getMachineInstrVec() const {
+ return *machineInstrVec;
+ }
+
+ // Provide a scoped predecessor and successor iterator
+ typedef PredIterator<BasicBlock, Value::use_iterator> pred_iterator;
+ typedef PredIterator<const BasicBlock,
+ Value::use_const_iterator> pred_const_iterator;
+
+ typedef SuccIterator<TerminatorInst*, BasicBlock> succ_iterator;
+ typedef SuccIterator<const TerminatorInst*,
+ const BasicBlock> succ_const_iterator;
+
+
//===--------------------------------------------------------------------===//
// Instruction iterator methods
+ //
inline iterator begin() { return InstList.begin(); }
inline const_iterator begin() const { return InstList.begin(); }
inline iterator end () { return InstList.end(); }
const InstListType &getInstList() const { return InstList; }
InstListType &getInstList() { return InstList; }
- // hasConstantPoolReferences() - This predicate is true if there is a
+ // Methods for support type inquiry through isa, cast, and dyn_cast:
+ static inline bool classof(const BasicBlock *BB) { return true; }
+ static inline bool classof(const Value *V) {
+ return V->getValueType() == Value::BasicBlockVal;
+ }
+
+ // 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 hasConstantPoolReferences() const;
+ bool hasConstantReferences() const;
// dropAllReferences() - This function causes all the subinstructions to "let
// go" of all references that they are maintaining. This allows one to