Moved iterators to the new CFG.h file.
[oota-llvm.git] / include / llvm / BasicBlock.h
1 //===-- llvm/BasicBlock.h - Represent a basic block in the VM ----*- C++ -*--=//
2 //
3 // This file contains the declaration of the BasicBlock class, which represents
4 // a single basic block in the VM.
5 //
6 // Note that basic blocks themselves are Def's, because they are referenced
7 // by instructions like branches and can go in switch tables and stuff...
8 //
9 // This may see wierd at first, but it's really pretty cool.  :)
10 //
11 //===----------------------------------------------------------------------===//
12 //
13 // Note that well formed basic blocks are formed of a list of instructions 
14 // followed by a single TerminatorInst instruction.  TerminatorInst's may not
15 // occur in the middle of basic blocks, and must terminate the blocks.
16 //
17 // This code allows malformed basic blocks to occur, because it may be useful
18 // in the intermediate stage of analysis or modification of a program.
19 //
20 //===----------------------------------------------------------------------===//
21
22 #ifndef LLVM_BASICBLOCK_H
23 #define LLVM_BASICBLOCK_H
24
25 #include "llvm/Value.h"               // Get the definition of Value
26 #include "llvm/ValueHolder.h"
27
28 class Instruction;
29 class Method;
30 class BasicBlock;
31 class TerminatorInst;
32
33 typedef UseTy<BasicBlock> BasicBlockUse;
34
35 class BasicBlock : public Value {       // Basic blocks are data objects also
36 public:
37   typedef ValueHolder<Instruction, BasicBlock> InstListType;
38 private :
39   InstListType InstList;
40
41   friend class ValueHolder<BasicBlock,Method>;
42   void setParent(Method *parent);
43
44 public:
45   BasicBlock(const string &Name = "", Method *Parent = 0);
46   ~BasicBlock();
47
48   // Specialize setName to take care of symbol table majik
49   virtual void setName(const string &name);
50
51   const Method *getParent() const { return (const Method*)InstList.getParent();}
52         Method *getParent()       { return (Method*)InstList.getParent(); }
53
54   const InstListType &getInstList() const { return InstList; }
55         InstListType &getInstList()       { return InstList; }
56
57   // getTerminator() - If this is a well formed basic block, then this returns
58   // a pointer to the terminator instruction.  If it is not, then you get a null
59   // pointer back.
60   //
61   TerminatorInst *getTerminator();
62   const TerminatorInst *const getTerminator() const;
63
64   // hasConstantPoolReferences() - This predicate is true if there is a 
65   // reference to this basic block in the constant pool for this method.  For
66   // example, if a block is reached through a switch table, that table resides
67   // in the constant pool, and the basic block is reference from it.
68   //
69   bool hasConstantPoolReferences() const;
70
71   // dropAllReferences() - This function causes all the subinstructions to "let
72   // go" of all references that they are maintaining.  This allows one to
73   // 'delete' a whole class at a time, even though there may be circular
74   // references... first all references are dropped, and all use counts go to
75   // zero.  Then everything is delete'd for real.  Note that no operations are
76   // valid on an object that has "dropped all references", except operator 
77   // delete.
78   //
79   void dropAllReferences();
80
81   // splitBasicBlock - This splits a basic block into two at the specified
82   // instruction.  Note that all instructions BEFORE the specified iterator stay
83   // as part of the original basic block, an unconditional branch is added to 
84   // the new BB, and the rest of the instructions in the BB are moved to the new
85   // BB, including the old terminator.  The newly formed BasicBlock is returned.
86   // This function invalidates the specified iterator.
87   //
88   // Note that this only works on well formed basic blocks (must have a 
89   // terminator), and 'I' must not be the end of instruction list (which would
90   // cause a degenerate basic block to be formed, having a terminator inside of
91   // the basic block).
92   //
93   BasicBlock *splitBasicBlock(InstListType::iterator I);
94 };
95
96 #endif