Chris Lattner | 9c6342d | 2002-10-28 01:27:51 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/MachineFunction.h --------------------------*- C++ -*-===// |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 2 | // |
John Criswell | 6fbcc26 | 2003-10-20 20:19:47 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 7 | // |
John Criswell | 6fbcc26 | 2003-10-20 20:19:47 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 10 | // Collect native machine code for a function. This class contains a list of |
| 11 | // MachineBasicBlock instances that make up the current compiled function. |
| 12 | // |
| 13 | // This class also contains pointers to various classes which hold |
| 14 | // target-specific information about the generated code. |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 15 | // |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 16 | //===----------------------------------------------------------------------===// |
| 17 | |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 18 | #ifndef LLVM_CODEGEN_MACHINEFUNCTION_H |
| 19 | #define LLVM_CODEGEN_MACHINEFUNCTION_H |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 20 | |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineDebugInfo.h" |
Chris Lattner | 0551f54 | 2002-10-28 02:01:06 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineBasicBlock.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Annotation.h" |
Chris Lattner | 8e7ae98 | 2002-10-28 02:08:43 +0000 | [diff] [blame] | 24 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 25 | namespace llvm { |
| 26 | |
Chris Lattner | 8bdf87d | 2004-08-18 18:13:16 +0000 | [diff] [blame] | 27 | class Function; |
| 28 | class TargetMachine; |
| 29 | class SSARegMap; |
| 30 | class MachineFrameInfo; |
| 31 | class MachineConstantPool; |
| 32 | |
Tanya Lattner | 792699c | 2004-05-24 06:11:51 +0000 | [diff] [blame] | 33 | // ilist_traits |
| 34 | template <> |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 35 | struct ilist_traits<MachineBasicBlock> { |
Tanya Lattner | 792699c | 2004-05-24 06:11:51 +0000 | [diff] [blame] | 36 | // this is only set by the MachineFunction owning the ilist |
| 37 | friend class MachineFunction; |
Tanya Lattner | 17fb34b | 2004-05-24 07:14:35 +0000 | [diff] [blame] | 38 | MachineFunction* Parent; |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 39 | |
Tanya Lattner | 792699c | 2004-05-24 06:11:51 +0000 | [diff] [blame] | 40 | public: |
Tanya Lattner | 17fb34b | 2004-05-24 07:14:35 +0000 | [diff] [blame] | 41 | ilist_traits<MachineBasicBlock>() : Parent(0) { } |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 42 | |
Tanya Lattner | 792699c | 2004-05-24 06:11:51 +0000 | [diff] [blame] | 43 | static MachineBasicBlock* getPrev(MachineBasicBlock* N) { return N->Prev; } |
| 44 | static MachineBasicBlock* getNext(MachineBasicBlock* N) { return N->Next; } |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 45 | |
Tanya Lattner | 792699c | 2004-05-24 06:11:51 +0000 | [diff] [blame] | 46 | static const MachineBasicBlock* |
| 47 | getPrev(const MachineBasicBlock* N) { return N->Prev; } |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 48 | |
Tanya Lattner | 792699c | 2004-05-24 06:11:51 +0000 | [diff] [blame] | 49 | static const MachineBasicBlock* |
| 50 | getNext(const MachineBasicBlock* N) { return N->Next; } |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 51 | |
Chris Lattner | 2fcd451 | 2004-08-16 22:35:26 +0000 | [diff] [blame] | 52 | static void setPrev(MachineBasicBlock* N, MachineBasicBlock* prev) { |
| 53 | N->Prev = prev; |
| 54 | } |
| 55 | static void setNext(MachineBasicBlock* N, MachineBasicBlock* next) { |
| 56 | N->Next = next; |
| 57 | } |
Misha Brukman | 274ba03 | 2004-08-17 17:52:36 +0000 | [diff] [blame] | 58 | |
Chris Lattner | bbec41d | 2005-01-30 00:13:34 +0000 | [diff] [blame] | 59 | static MachineBasicBlock* createSentinel(); |
| 60 | static void destroySentinel(MachineBasicBlock *MBB) { delete MBB; } |
Tanya Lattner | 792699c | 2004-05-24 06:11:51 +0000 | [diff] [blame] | 61 | void addNodeToList(MachineBasicBlock* N); |
| 62 | void removeNodeFromList(MachineBasicBlock* N); |
Chris Lattner | 2fcd451 | 2004-08-16 22:35:26 +0000 | [diff] [blame] | 63 | void transferNodesFromList(iplist<MachineBasicBlock, |
| 64 | ilist_traits<MachineBasicBlock> > &toList, |
Misha Brukman | 00876a2 | 2005-04-22 03:46:24 +0000 | [diff] [blame] | 65 | ilist_iterator<MachineBasicBlock> first, |
| 66 | ilist_iterator<MachineBasicBlock> last); |
Tanya Lattner | 792699c | 2004-05-24 06:11:51 +0000 | [diff] [blame] | 67 | }; |
Tanya Lattner | 792699c | 2004-05-24 06:11:51 +0000 | [diff] [blame] | 68 | |
Chris Lattner | 8bdf87d | 2004-08-18 18:13:16 +0000 | [diff] [blame] | 69 | /// MachineFunctionInfo - This class can be derived from and used by targets to |
| 70 | /// hold private target-specific information for each MachineFunction. Objects |
| 71 | /// of type are accessed/created with MF::getInfo and destroyed when the |
| 72 | /// MachineFunction is destroyed. |
| 73 | struct MachineFunctionInfo { |
| 74 | virtual ~MachineFunctionInfo() {}; |
| 75 | }; |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 76 | |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 77 | class MachineFunction : private Annotation { |
Chris Lattner | 335d5c3 | 2002-10-28 05:58:46 +0000 | [diff] [blame] | 78 | const Function *Fn; |
| 79 | const TargetMachine &Target; |
Chris Lattner | 8e7ae98 | 2002-10-28 02:08:43 +0000 | [diff] [blame] | 80 | |
| 81 | // List of machine basic blocks in function |
Tanya Lattner | 17fb34b | 2004-05-24 07:14:35 +0000 | [diff] [blame] | 82 | ilist<MachineBasicBlock> BasicBlocks; |
Chris Lattner | 9c6342d | 2002-10-28 01:27:51 +0000 | [diff] [blame] | 83 | |
Chris Lattner | 03ab7af | 2002-12-25 05:00:16 +0000 | [diff] [blame] | 84 | // Keeping track of mapping from SSA values to registers |
| 85 | SSARegMap *SSARegMapping; |
| 86 | |
Chris Lattner | 8bdf87d | 2004-08-18 18:13:16 +0000 | [diff] [blame] | 87 | // Used to keep track of target-specific per-machine function information for |
| 88 | // the target implementation. |
| 89 | MachineFunctionInfo *MFInfo; |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 90 | |
| 91 | // Keep track of objects allocated on the stack. |
Chris Lattner | aa09b75 | 2002-12-28 21:08:28 +0000 | [diff] [blame] | 92 | MachineFrameInfo *FrameInfo; |
Misha Brukman | 1617e6c | 2002-11-20 00:53:10 +0000 | [diff] [blame] | 93 | |
Chris Lattner | 40a7557 | 2003-01-13 00:16:10 +0000 | [diff] [blame] | 94 | // Keep track of constants which are spilled to memory |
| 95 | MachineConstantPool *ConstantPool; |
| 96 | |
Chris Lattner | 25d8039 | 2004-07-01 06:01:36 +0000 | [diff] [blame] | 97 | // Function-level unique numbering for MachineBasicBlocks. When a |
| 98 | // MachineBasicBlock is inserted into a MachineFunction is it automatically |
| 99 | // numbered and this vector keeps track of the mapping from ID's to MBB's. |
| 100 | std::vector<MachineBasicBlock*> MBBNumbering; |
Brian Gaeke | f460f16 | 2004-05-12 21:35:21 +0000 | [diff] [blame] | 101 | |
Chris Lattner | d6b210c | 2005-01-23 22:13:36 +0000 | [diff] [blame] | 102 | /// UsedPhysRegs - This is a new[]'d array of bools that is computed and set |
| 103 | /// by the register allocator, and must be kept up to date by passes that run |
| 104 | /// after register allocation (though most don't modify this). This is used |
| 105 | /// so that the code generator knows which callee save registers to save and |
| 106 | /// for other target specific uses. |
| 107 | bool *UsedPhysRegs; |
| 108 | |
Chris Lattner | dde3a9a | 2005-04-09 15:22:53 +0000 | [diff] [blame] | 109 | /// LiveIns/LiveOuts - Keep track of the physical registers that are |
| 110 | /// livein/liveout of the function. Live in values are typically arguments in |
| 111 | /// registers, live out values are typically return values in registers. |
Chris Lattner | 712ad0c | 2005-05-13 07:08:07 +0000 | [diff] [blame] | 112 | /// LiveIn values are allowed to have virtual registers associated with them, |
| 113 | /// stored in the second element. |
| 114 | std::vector<std::pair<unsigned, unsigned> > LiveIns; |
| 115 | std::vector<unsigned> LiveOuts; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 116 | |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 117 | public: |
Chris Lattner | 40a7557 | 2003-01-13 00:16:10 +0000 | [diff] [blame] | 118 | MachineFunction(const Function *Fn, const TargetMachine &TM); |
Chris Lattner | 03ab7af | 2002-12-25 05:00:16 +0000 | [diff] [blame] | 119 | ~MachineFunction(); |
Chris Lattner | 335d5c3 | 2002-10-28 05:58:46 +0000 | [diff] [blame] | 120 | |
| 121 | /// getFunction - Return the LLVM function that this machine code represents |
| 122 | /// |
| 123 | const Function *getFunction() const { return Fn; } |
| 124 | |
| 125 | /// getTarget - Return the target machine this machine code is compiled with |
| 126 | /// |
| 127 | const TargetMachine &getTarget() const { return Target; } |
Chris Lattner | dea7383 | 2002-10-30 00:46:31 +0000 | [diff] [blame] | 128 | |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 129 | /// SSARegMap Interface... Keep track of information about each SSA virtual |
| 130 | /// register, such as which register class it belongs to. |
| 131 | /// |
| 132 | SSARegMap *getSSARegMap() const { return SSARegMapping; } |
| 133 | void clearSSARegMap(); |
| 134 | |
| 135 | /// getFrameInfo - Return the frame info object for the current function. |
| 136 | /// This object contains information about objects allocated on the stack |
| 137 | /// frame of the current function in an abstract way. |
| 138 | /// |
Chris Lattner | aa09b75 | 2002-12-28 21:08:28 +0000 | [diff] [blame] | 139 | MachineFrameInfo *getFrameInfo() const { return FrameInfo; } |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 140 | |
Chris Lattner | 40a7557 | 2003-01-13 00:16:10 +0000 | [diff] [blame] | 141 | /// getConstantPool - Return the constant pool object for the current |
| 142 | /// function. |
Misha Brukman | 274ba03 | 2004-08-17 17:52:36 +0000 | [diff] [blame] | 143 | /// |
Chris Lattner | 40a7557 | 2003-01-13 00:16:10 +0000 | [diff] [blame] | 144 | MachineConstantPool *getConstantPool() const { return ConstantPool; } |
| 145 | |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 146 | /// MachineFunctionInfo - Keep track of various per-function pieces of |
Chris Lattner | 67d2562 | 2005-08-31 22:49:51 +0000 | [diff] [blame] | 147 | /// information for backends that would like to do so. |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 148 | /// |
Chris Lattner | 8bdf87d | 2004-08-18 18:13:16 +0000 | [diff] [blame] | 149 | template<typename Ty> |
| 150 | Ty *getInfo() { |
| 151 | if (!MFInfo) MFInfo = new Ty(*this); |
| 152 | |
| 153 | assert((void*)dynamic_cast<Ty*>(MFInfo) == (void*)MFInfo && |
| 154 | "Invalid concrete type or multiple inheritence for getInfo"); |
| 155 | return static_cast<Ty*>(MFInfo); |
| 156 | } |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 157 | |
Chris Lattner | d6b210c | 2005-01-23 22:13:36 +0000 | [diff] [blame] | 158 | /// setUsedPhysRegs - The register allocator should call this to initialized |
| 159 | /// the UsedPhysRegs set. This should be passed a new[]'d array with entries |
| 160 | /// for all of the physical registers that the target supports. Each array |
| 161 | /// entry should be set to true iff the physical register is used within the |
| 162 | /// function. |
| 163 | void setUsedPhysRegs(bool *UPR) { UsedPhysRegs = UPR; } |
| 164 | |
| 165 | /// getUsedPhysregs - This returns the UsedPhysRegs array. This returns null |
| 166 | /// before register allocation. |
Chris Lattner | 471f090 | 2005-01-23 22:57:27 +0000 | [diff] [blame] | 167 | bool *getUsedPhysregs() { return UsedPhysRegs; } |
| 168 | const bool *getUsedPhysregs() const { return UsedPhysRegs; } |
Chris Lattner | d6b210c | 2005-01-23 22:13:36 +0000 | [diff] [blame] | 169 | |
| 170 | /// isPhysRegUsed - Return true if the specified register is used in this |
| 171 | /// function. This only works after register allocation. |
| 172 | bool isPhysRegUsed(unsigned Reg) { return UsedPhysRegs[Reg]; } |
| 173 | |
| 174 | /// changePhyRegUsed - This method allows code that runs after register |
| 175 | /// allocation to keep the PhysRegsUsed array up-to-date. |
| 176 | void changePhyRegUsed(unsigned Reg, bool State) { UsedPhysRegs[Reg] = State; } |
| 177 | |
Chris Lattner | dde3a9a | 2005-04-09 15:22:53 +0000 | [diff] [blame] | 178 | |
| 179 | // LiveIn/LiveOut management methods. |
| 180 | |
| 181 | /// addLiveIn/Out - Add the specified register as a live in/out. Note that it |
| 182 | /// is an error to add the same register to the same set more than once. |
Chris Lattner | 712ad0c | 2005-05-13 07:08:07 +0000 | [diff] [blame] | 183 | void addLiveIn(unsigned Reg, unsigned vreg = 0) { |
| 184 | LiveIns.push_back(std::make_pair(Reg, vreg)); |
| 185 | } |
Chris Lattner | dde3a9a | 2005-04-09 15:22:53 +0000 | [diff] [blame] | 186 | void addLiveOut(unsigned Reg) { LiveOuts.push_back(Reg); } |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 187 | |
Chris Lattner | dde3a9a | 2005-04-09 15:22:53 +0000 | [diff] [blame] | 188 | // Iteration support for live in/out sets. These sets are kept in sorted |
| 189 | // order by their register number. |
Chris Lattner | 712ad0c | 2005-05-13 07:08:07 +0000 | [diff] [blame] | 190 | typedef std::vector<std::pair<unsigned,unsigned> >::const_iterator |
| 191 | livein_iterator; |
| 192 | typedef std::vector<unsigned>::const_iterator liveout_iterator; |
| 193 | livein_iterator livein_begin() const { return LiveIns.begin(); } |
| 194 | livein_iterator livein_end() const { return LiveIns.end(); } |
Chris Lattner | 347d9d6 | 2006-04-11 01:09:25 +0000 | [diff] [blame^] | 195 | bool livein_empty() const { return LiveIns.empty(); } |
Chris Lattner | 712ad0c | 2005-05-13 07:08:07 +0000 | [diff] [blame] | 196 | liveout_iterator liveout_begin() const { return LiveOuts.begin(); } |
| 197 | liveout_iterator liveout_end() const { return LiveOuts.end(); } |
Chris Lattner | 347d9d6 | 2006-04-11 01:09:25 +0000 | [diff] [blame^] | 198 | bool liveout_empty() const { return LiveOuts.empty(); } |
Chris Lattner | dde3a9a | 2005-04-09 15:22:53 +0000 | [diff] [blame] | 199 | |
Chris Lattner | 25d8039 | 2004-07-01 06:01:36 +0000 | [diff] [blame] | 200 | /// getBlockNumbered - MachineBasicBlocks are automatically numbered when they |
| 201 | /// are inserted into the machine function. The block number for a machine |
| 202 | /// basic block can be found by using the MBB::getBlockNumber method, this |
| 203 | /// method provides the inverse mapping. |
Misha Brukman | 274ba03 | 2004-08-17 17:52:36 +0000 | [diff] [blame] | 204 | /// |
Chris Lattner | 25d8039 | 2004-07-01 06:01:36 +0000 | [diff] [blame] | 205 | MachineBasicBlock *getBlockNumbered(unsigned N) { |
| 206 | assert(N < MBBNumbering.size() && "Illegal block number"); |
| 207 | assert(MBBNumbering[N] && "Block was removed from the machine function!"); |
| 208 | return MBBNumbering[N]; |
| 209 | } |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 210 | |
Alkis Evlogimenos | fec656c | 2004-08-27 04:02:35 +0000 | [diff] [blame] | 211 | /// getLastBlock - Returns the MachineBasicBlock with the greatest number |
| 212 | MachineBasicBlock *getLastBlock() { |
| 213 | return MBBNumbering.back(); |
| 214 | } |
Alkis Evlogimenos | 4b97f23 | 2004-09-30 21:42:02 +0000 | [diff] [blame] | 215 | const MachineBasicBlock *getLastBlock() const { |
| 216 | return MBBNumbering.back(); |
| 217 | } |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 218 | |
Chris Lattner | dea7383 | 2002-10-30 00:46:31 +0000 | [diff] [blame] | 219 | /// print - Print out the MachineFunction in a format suitable for debugging |
| 220 | /// to the specified stream. |
| 221 | /// |
| 222 | void print(std::ostream &OS) const; |
| 223 | |
Alkis Evlogimenos | 71bf404 | 2004-07-08 00:47:58 +0000 | [diff] [blame] | 224 | /// viewCFG - This function is meant for use from the debugger. You can just |
| 225 | /// say 'call F->viewCFG()' and a ghostview window should pop up from the |
| 226 | /// program, displaying the CFG of the current function with the code for each |
| 227 | /// basic block inside. This depends on there being a 'dot' and 'gv' program |
| 228 | /// in your path. |
| 229 | /// |
| 230 | void viewCFG() const; |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 231 | |
Alkis Evlogimenos | 71bf404 | 2004-07-08 00:47:58 +0000 | [diff] [blame] | 232 | /// viewCFGOnly - This function is meant for use from the debugger. It works |
| 233 | /// just like viewCFG, but it does not include the contents of basic blocks |
| 234 | /// into the nodes, just the label. If you are only interested in the CFG |
| 235 | /// this can make the graph smaller. |
| 236 | /// |
| 237 | void viewCFGOnly() const; |
| 238 | |
Chris Lattner | dea7383 | 2002-10-30 00:46:31 +0000 | [diff] [blame] | 239 | /// dump - Print the current MachineFunction to cerr, useful for debugger use. |
| 240 | /// |
| 241 | void dump() const; |
| 242 | |
Misha Brukman | a7afa37 | 2004-06-04 14:51:25 +0000 | [diff] [blame] | 243 | /// construct - Allocate and initialize a MachineFunction for a given Function |
| 244 | /// and Target |
| 245 | /// |
Chris Lattner | 40a7557 | 2003-01-13 00:16:10 +0000 | [diff] [blame] | 246 | static MachineFunction& construct(const Function *F, const TargetMachine &TM); |
Misha Brukman | a7afa37 | 2004-06-04 14:51:25 +0000 | [diff] [blame] | 247 | |
| 248 | /// destruct - Destroy the MachineFunction corresponding to a given Function |
| 249 | /// |
Chris Lattner | e7506a3 | 2002-03-23 22:51:58 +0000 | [diff] [blame] | 250 | static void destruct(const Function *F); |
Misha Brukman | a7afa37 | 2004-06-04 14:51:25 +0000 | [diff] [blame] | 251 | |
| 252 | /// get - Return a handle to a MachineFunction corresponding to the given |
| 253 | /// Function. This should not be called before "construct()" for a given |
| 254 | /// Function. |
| 255 | /// |
Chris Lattner | d0aa0cd | 2002-10-28 05:30:46 +0000 | [diff] [blame] | 256 | static MachineFunction& get(const Function *F); |
Chris Lattner | 9c6342d | 2002-10-28 01:27:51 +0000 | [diff] [blame] | 257 | |
Chris Lattner | d0aa0cd | 2002-10-28 05:30:46 +0000 | [diff] [blame] | 258 | // Provide accessors for the MachineBasicBlock list... |
Tanya Lattner | 17fb34b | 2004-05-24 07:14:35 +0000 | [diff] [blame] | 259 | typedef ilist<MachineBasicBlock> BasicBlockListType; |
Chris Lattner | d0aa0cd | 2002-10-28 05:30:46 +0000 | [diff] [blame] | 260 | typedef BasicBlockListType::iterator iterator; |
| 261 | typedef BasicBlockListType::const_iterator const_iterator; |
| 262 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 263 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 264 | |
| 265 | // Provide accessors for basic blocks... |
| 266 | const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; } |
| 267 | BasicBlockListType &getBasicBlockList() { return BasicBlocks; } |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 268 | |
Chris Lattner | d0aa0cd | 2002-10-28 05:30:46 +0000 | [diff] [blame] | 269 | //===--------------------------------------------------------------------===// |
| 270 | // BasicBlock iterator forwarding functions |
| 271 | // |
| 272 | iterator begin() { return BasicBlocks.begin(); } |
| 273 | const_iterator begin() const { return BasicBlocks.begin(); } |
| 274 | iterator end () { return BasicBlocks.end(); } |
| 275 | const_iterator end () const { return BasicBlocks.end(); } |
| 276 | |
| 277 | reverse_iterator rbegin() { return BasicBlocks.rbegin(); } |
| 278 | const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); } |
| 279 | reverse_iterator rend () { return BasicBlocks.rend(); } |
| 280 | const_reverse_iterator rend () const { return BasicBlocks.rend(); } |
| 281 | |
| 282 | unsigned size() const { return BasicBlocks.size(); } |
| 283 | bool empty() const { return BasicBlocks.empty(); } |
| 284 | const MachineBasicBlock &front() const { return BasicBlocks.front(); } |
| 285 | MachineBasicBlock &front() { return BasicBlocks.front(); } |
Misha Brukman | d5806ff | 2002-10-28 19:58:38 +0000 | [diff] [blame] | 286 | const MachineBasicBlock & back() const { return BasicBlocks.back(); } |
| 287 | MachineBasicBlock & back() { return BasicBlocks.back(); } |
Chris Lattner | 25d8039 | 2004-07-01 06:01:36 +0000 | [diff] [blame] | 288 | |
| 289 | //===--------------------------------------------------------------------===// |
| 290 | // Internal functions used to automatically number MachineBasicBlocks |
| 291 | // |
| 292 | |
| 293 | /// getNextMBBNumber - Returns the next unique number to be assigned |
| 294 | /// to a MachineBasicBlock in this MachineFunction. |
| 295 | /// |
| 296 | unsigned addToMBBNumbering(MachineBasicBlock *MBB) { |
| 297 | MBBNumbering.push_back(MBB); |
| 298 | return MBBNumbering.size()-1; |
| 299 | } |
| 300 | |
| 301 | /// removeFromMBBNumbering - Remove the specific machine basic block from our |
| 302 | /// tracker, this is only really to be used by the MachineBasicBlock |
| 303 | /// implementation. |
| 304 | void removeFromMBBNumbering(unsigned N) { |
| 305 | assert(N < MBBNumbering.size() && "Illegal basic block #"); |
| 306 | MBBNumbering[N] = 0; |
| 307 | } |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 308 | }; |
| 309 | |
Alkis Evlogimenos | 71bf404 | 2004-07-08 00:47:58 +0000 | [diff] [blame] | 310 | //===--------------------------------------------------------------------===// |
| 311 | // GraphTraits specializations for function basic block graphs (CFGs) |
| 312 | //===--------------------------------------------------------------------===// |
| 313 | |
| 314 | // Provide specializations of GraphTraits to be able to treat a |
| 315 | // machine function as a graph of machine basic blocks... these are |
| 316 | // the same as the machine basic block iterators, except that the root |
| 317 | // node is implicitly the first node of the function. |
| 318 | // |
| 319 | template <> struct GraphTraits<MachineFunction*> : |
| 320 | public GraphTraits<MachineBasicBlock*> { |
| 321 | static NodeType *getEntryNode(MachineFunction *F) { |
| 322 | return &F->front(); |
| 323 | } |
| 324 | |
| 325 | // nodes_iterator/begin/end - Allow iteration over all nodes in the graph |
| 326 | typedef MachineFunction::iterator nodes_iterator; |
| 327 | static nodes_iterator nodes_begin(MachineFunction *F) { return F->begin(); } |
| 328 | static nodes_iterator nodes_end (MachineFunction *F) { return F->end(); } |
| 329 | }; |
| 330 | template <> struct GraphTraits<const MachineFunction*> : |
| 331 | public GraphTraits<const MachineBasicBlock*> { |
| 332 | static NodeType *getEntryNode(const MachineFunction *F) { |
| 333 | return &F->front(); |
| 334 | } |
| 335 | |
| 336 | // nodes_iterator/begin/end - Allow iteration over all nodes in the graph |
| 337 | typedef MachineFunction::const_iterator nodes_iterator; |
| 338 | static nodes_iterator nodes_begin(const MachineFunction *F) { return F->begin(); } |
| 339 | static nodes_iterator nodes_end (const MachineFunction *F) { return F->end(); } |
| 340 | }; |
| 341 | |
| 342 | |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 343 | // Provide specializations of GraphTraits to be able to treat a function as a |
Alkis Evlogimenos | 71bf404 | 2004-07-08 00:47:58 +0000 | [diff] [blame] | 344 | // graph of basic blocks... and to walk it in inverse order. Inverse order for |
| 345 | // a function is considered to be when traversing the predecessor edges of a BB |
| 346 | // instead of the successor edges. |
| 347 | // |
| 348 | template <> struct GraphTraits<Inverse<MachineFunction*> > : |
| 349 | public GraphTraits<Inverse<MachineBasicBlock*> > { |
| 350 | static NodeType *getEntryNode(Inverse<MachineFunction*> G) { |
| 351 | return &G.Graph->front(); |
| 352 | } |
| 353 | }; |
| 354 | template <> struct GraphTraits<Inverse<const MachineFunction*> > : |
| 355 | public GraphTraits<Inverse<const MachineBasicBlock*> > { |
| 356 | static NodeType *getEntryNode(Inverse<const MachineFunction *> G) { |
| 357 | return &G.Graph->front(); |
| 358 | } |
| 359 | }; |
| 360 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 361 | } // End llvm namespace |
| 362 | |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 363 | #endif |