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 | // |
Chris Lattner | 7ed47a1 | 2007-12-29 19:59:42 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // 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 | |
Chris Lattner | 0551f54 | 2002-10-28 02:01:06 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineBasicBlock.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Annotation.h" |
Chris Lattner | 8e7ae98 | 2002-10-28 02:08:43 +0000 | [diff] [blame] | 23 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 24 | namespace llvm { |
| 25 | |
Chris Lattner | 8bdf87d | 2004-08-18 18:13:16 +0000 | [diff] [blame] | 26 | class Function; |
| 27 | class TargetMachine; |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 28 | class MachineRegisterInfo; |
Chris Lattner | 8bdf87d | 2004-08-18 18:13:16 +0000 | [diff] [blame] | 29 | class MachineFrameInfo; |
| 30 | class MachineConstantPool; |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 31 | class MachineJumpTableInfo; |
Chris Lattner | 8bdf87d | 2004-08-18 18:13:16 +0000 | [diff] [blame] | 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 { |
Dan Gohman | 81975f6 | 2007-08-27 14:50:10 +0000 | [diff] [blame] | 74 | virtual ~MachineFunctionInfo() {} |
Chris Lattner | 8bdf87d | 2004-08-18 18:13:16 +0000 | [diff] [blame] | 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 | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 84 | // RegInfo - Information about each register in use in the function. |
| 85 | MachineRegisterInfo *RegInfo; |
Chris Lattner | 03ab7af | 2002-12-25 05:00:16 +0000 | [diff] [blame] | 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; |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 96 | |
| 97 | // Keep track of jump tables for switch instructions |
| 98 | MachineJumpTableInfo *JumpTableInfo; |
Chris Lattner | 40a7557 | 2003-01-13 00:16:10 +0000 | [diff] [blame] | 99 | |
Chris Lattner | 25d8039 | 2004-07-01 06:01:36 +0000 | [diff] [blame] | 100 | // Function-level unique numbering for MachineBasicBlocks. When a |
| 101 | // MachineBasicBlock is inserted into a MachineFunction is it automatically |
| 102 | // numbered and this vector keeps track of the mapping from ID's to MBB's. |
| 103 | std::vector<MachineBasicBlock*> MBBNumbering; |
Brian Gaeke | f460f16 | 2004-05-12 21:35:21 +0000 | [diff] [blame] | 104 | |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 105 | public: |
Chris Lattner | 40a7557 | 2003-01-13 00:16:10 +0000 | [diff] [blame] | 106 | MachineFunction(const Function *Fn, const TargetMachine &TM); |
Chris Lattner | 03ab7af | 2002-12-25 05:00:16 +0000 | [diff] [blame] | 107 | ~MachineFunction(); |
Chris Lattner | 335d5c3 | 2002-10-28 05:58:46 +0000 | [diff] [blame] | 108 | |
| 109 | /// getFunction - Return the LLVM function that this machine code represents |
| 110 | /// |
| 111 | const Function *getFunction() const { return Fn; } |
| 112 | |
| 113 | /// getTarget - Return the target machine this machine code is compiled with |
| 114 | /// |
| 115 | const TargetMachine &getTarget() const { return Target; } |
Chris Lattner | dea7383 | 2002-10-30 00:46:31 +0000 | [diff] [blame] | 116 | |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 117 | /// getRegInfo - Return information about the registers currently in use. |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 118 | /// |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 119 | MachineRegisterInfo &getRegInfo() const { return *RegInfo; } |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 120 | |
| 121 | /// getFrameInfo - Return the frame info object for the current function. |
| 122 | /// This object contains information about objects allocated on the stack |
| 123 | /// frame of the current function in an abstract way. |
| 124 | /// |
Chris Lattner | aa09b75 | 2002-12-28 21:08:28 +0000 | [diff] [blame] | 125 | MachineFrameInfo *getFrameInfo() const { return FrameInfo; } |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 126 | |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 127 | /// getJumpTableInfo - Return the jump table info object for the current |
| 128 | /// function. This object contains information about jump tables for switch |
| 129 | /// instructions in the current function. |
| 130 | /// |
| 131 | MachineJumpTableInfo *getJumpTableInfo() const { return JumpTableInfo; } |
| 132 | |
Chris Lattner | 40a7557 | 2003-01-13 00:16:10 +0000 | [diff] [blame] | 133 | /// getConstantPool - Return the constant pool object for the current |
| 134 | /// function. |
Misha Brukman | 274ba03 | 2004-08-17 17:52:36 +0000 | [diff] [blame] | 135 | /// |
Chris Lattner | 40a7557 | 2003-01-13 00:16:10 +0000 | [diff] [blame] | 136 | MachineConstantPool *getConstantPool() const { return ConstantPool; } |
| 137 | |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 138 | /// MachineFunctionInfo - Keep track of various per-function pieces of |
Chris Lattner | 67d2562 | 2005-08-31 22:49:51 +0000 | [diff] [blame] | 139 | /// information for backends that would like to do so. |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 140 | /// |
Chris Lattner | 8bdf87d | 2004-08-18 18:13:16 +0000 | [diff] [blame] | 141 | template<typename Ty> |
| 142 | Ty *getInfo() { |
| 143 | if (!MFInfo) MFInfo = new Ty(*this); |
| 144 | |
| 145 | assert((void*)dynamic_cast<Ty*>(MFInfo) == (void*)MFInfo && |
| 146 | "Invalid concrete type or multiple inheritence for getInfo"); |
| 147 | return static_cast<Ty*>(MFInfo); |
| 148 | } |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 149 | |
Chris Lattner | 5ea64fd | 2006-08-17 22:00:08 +0000 | [diff] [blame] | 150 | template<typename Ty> |
| 151 | const Ty *getInfo() const { |
| 152 | return const_cast<MachineFunction*>(this)->getInfo<Ty>(); |
| 153 | } |
| 154 | |
Chris Lattner | 25d8039 | 2004-07-01 06:01:36 +0000 | [diff] [blame] | 155 | /// getBlockNumbered - MachineBasicBlocks are automatically numbered when they |
| 156 | /// are inserted into the machine function. The block number for a machine |
| 157 | /// basic block can be found by using the MBB::getBlockNumber method, this |
| 158 | /// method provides the inverse mapping. |
Misha Brukman | 274ba03 | 2004-08-17 17:52:36 +0000 | [diff] [blame] | 159 | /// |
Chris Lattner | 25d8039 | 2004-07-01 06:01:36 +0000 | [diff] [blame] | 160 | MachineBasicBlock *getBlockNumbered(unsigned N) { |
| 161 | assert(N < MBBNumbering.size() && "Illegal block number"); |
| 162 | assert(MBBNumbering[N] && "Block was removed from the machine function!"); |
| 163 | return MBBNumbering[N]; |
| 164 | } |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 165 | |
Chris Lattner | 2540813 | 2006-09-14 06:40:48 +0000 | [diff] [blame] | 166 | /// getNumBlockIDs - Return the number of MBB ID's allocated. |
Chris Lattner | e70cab0 | 2006-10-03 19:18:57 +0000 | [diff] [blame] | 167 | /// |
Evan Cheng | 34cd4a4 | 2008-05-05 18:30:58 +0000 | [diff] [blame^] | 168 | unsigned getNumBlockIDs() const { return (unsigned)MBBNumbering.size(); } |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 169 | |
Chris Lattner | e70cab0 | 2006-10-03 19:18:57 +0000 | [diff] [blame] | 170 | /// RenumberBlocks - This discards all of the MachineBasicBlock numbers and |
| 171 | /// recomputes them. This guarantees that the MBB numbers are sequential, |
| 172 | /// dense, and match the ordering of the blocks within the function. If a |
| 173 | /// specific MachineBasicBlock is specified, only that block and those after |
| 174 | /// it are renumbered. |
| 175 | void RenumberBlocks(MachineBasicBlock *MBBFrom = 0); |
| 176 | |
Chris Lattner | dea7383 | 2002-10-30 00:46:31 +0000 | [diff] [blame] | 177 | /// print - Print out the MachineFunction in a format suitable for debugging |
| 178 | /// to the specified stream. |
| 179 | /// |
| 180 | void print(std::ostream &OS) const; |
Bill Wendling | 5c7e326 | 2006-12-17 05:15:13 +0000 | [diff] [blame] | 181 | void print(std::ostream *OS) const { if (OS) print(*OS); } |
Chris Lattner | dea7383 | 2002-10-30 00:46:31 +0000 | [diff] [blame] | 182 | |
Alkis Evlogimenos | 71bf404 | 2004-07-08 00:47:58 +0000 | [diff] [blame] | 183 | /// viewCFG - This function is meant for use from the debugger. You can just |
| 184 | /// say 'call F->viewCFG()' and a ghostview window should pop up from the |
| 185 | /// program, displaying the CFG of the current function with the code for each |
| 186 | /// basic block inside. This depends on there being a 'dot' and 'gv' program |
| 187 | /// in your path. |
| 188 | /// |
| 189 | void viewCFG() const; |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 190 | |
Alkis Evlogimenos | 71bf404 | 2004-07-08 00:47:58 +0000 | [diff] [blame] | 191 | /// viewCFGOnly - This function is meant for use from the debugger. It works |
| 192 | /// just like viewCFG, but it does not include the contents of basic blocks |
| 193 | /// into the nodes, just the label. If you are only interested in the CFG |
| 194 | /// this can make the graph smaller. |
| 195 | /// |
| 196 | void viewCFGOnly() const; |
| 197 | |
Chris Lattner | dea7383 | 2002-10-30 00:46:31 +0000 | [diff] [blame] | 198 | /// dump - Print the current MachineFunction to cerr, useful for debugger use. |
| 199 | /// |
| 200 | void dump() const; |
| 201 | |
Misha Brukman | a7afa37 | 2004-06-04 14:51:25 +0000 | [diff] [blame] | 202 | /// construct - Allocate and initialize a MachineFunction for a given Function |
| 203 | /// and Target |
| 204 | /// |
Chris Lattner | 40a7557 | 2003-01-13 00:16:10 +0000 | [diff] [blame] | 205 | static MachineFunction& construct(const Function *F, const TargetMachine &TM); |
Misha Brukman | a7afa37 | 2004-06-04 14:51:25 +0000 | [diff] [blame] | 206 | |
| 207 | /// destruct - Destroy the MachineFunction corresponding to a given Function |
| 208 | /// |
Chris Lattner | e7506a3 | 2002-03-23 22:51:58 +0000 | [diff] [blame] | 209 | static void destruct(const Function *F); |
Misha Brukman | a7afa37 | 2004-06-04 14:51:25 +0000 | [diff] [blame] | 210 | |
| 211 | /// get - Return a handle to a MachineFunction corresponding to the given |
| 212 | /// Function. This should not be called before "construct()" for a given |
| 213 | /// Function. |
| 214 | /// |
Chris Lattner | d0aa0cd | 2002-10-28 05:30:46 +0000 | [diff] [blame] | 215 | static MachineFunction& get(const Function *F); |
Chris Lattner | 9c6342d | 2002-10-28 01:27:51 +0000 | [diff] [blame] | 216 | |
Chris Lattner | d0aa0cd | 2002-10-28 05:30:46 +0000 | [diff] [blame] | 217 | // Provide accessors for the MachineBasicBlock list... |
Tanya Lattner | 17fb34b | 2004-05-24 07:14:35 +0000 | [diff] [blame] | 218 | typedef ilist<MachineBasicBlock> BasicBlockListType; |
Chris Lattner | d0aa0cd | 2002-10-28 05:30:46 +0000 | [diff] [blame] | 219 | typedef BasicBlockListType::iterator iterator; |
| 220 | typedef BasicBlockListType::const_iterator const_iterator; |
| 221 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 222 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 223 | |
| 224 | // Provide accessors for basic blocks... |
| 225 | const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; } |
| 226 | BasicBlockListType &getBasicBlockList() { return BasicBlocks; } |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 227 | |
Chris Lattner | d0aa0cd | 2002-10-28 05:30:46 +0000 | [diff] [blame] | 228 | //===--------------------------------------------------------------------===// |
| 229 | // BasicBlock iterator forwarding functions |
| 230 | // |
| 231 | iterator begin() { return BasicBlocks.begin(); } |
| 232 | const_iterator begin() const { return BasicBlocks.begin(); } |
| 233 | iterator end () { return BasicBlocks.end(); } |
| 234 | const_iterator end () const { return BasicBlocks.end(); } |
| 235 | |
| 236 | reverse_iterator rbegin() { return BasicBlocks.rbegin(); } |
| 237 | const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); } |
| 238 | reverse_iterator rend () { return BasicBlocks.rend(); } |
| 239 | const_reverse_iterator rend () const { return BasicBlocks.rend(); } |
| 240 | |
Evan Cheng | 34cd4a4 | 2008-05-05 18:30:58 +0000 | [diff] [blame^] | 241 | unsigned size() const { return (unsigned)BasicBlocks.size();} |
Chris Lattner | d0aa0cd | 2002-10-28 05:30:46 +0000 | [diff] [blame] | 242 | bool empty() const { return BasicBlocks.empty(); } |
| 243 | const MachineBasicBlock &front() const { return BasicBlocks.front(); } |
| 244 | MachineBasicBlock &front() { return BasicBlocks.front(); } |
Misha Brukman | d5806ff | 2002-10-28 19:58:38 +0000 | [diff] [blame] | 245 | const MachineBasicBlock & back() const { return BasicBlocks.back(); } |
| 246 | MachineBasicBlock & back() { return BasicBlocks.back(); } |
Chris Lattner | 25d8039 | 2004-07-01 06:01:36 +0000 | [diff] [blame] | 247 | |
| 248 | //===--------------------------------------------------------------------===// |
| 249 | // Internal functions used to automatically number MachineBasicBlocks |
| 250 | // |
| 251 | |
| 252 | /// getNextMBBNumber - Returns the next unique number to be assigned |
| 253 | /// to a MachineBasicBlock in this MachineFunction. |
| 254 | /// |
| 255 | unsigned addToMBBNumbering(MachineBasicBlock *MBB) { |
| 256 | MBBNumbering.push_back(MBB); |
Evan Cheng | 34cd4a4 | 2008-05-05 18:30:58 +0000 | [diff] [blame^] | 257 | return (unsigned)MBBNumbering.size()-1; |
Chris Lattner | 25d8039 | 2004-07-01 06:01:36 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /// removeFromMBBNumbering - Remove the specific machine basic block from our |
| 261 | /// tracker, this is only really to be used by the MachineBasicBlock |
| 262 | /// implementation. |
| 263 | void removeFromMBBNumbering(unsigned N) { |
| 264 | assert(N < MBBNumbering.size() && "Illegal basic block #"); |
| 265 | MBBNumbering[N] = 0; |
| 266 | } |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 267 | }; |
| 268 | |
Alkis Evlogimenos | 71bf404 | 2004-07-08 00:47:58 +0000 | [diff] [blame] | 269 | //===--------------------------------------------------------------------===// |
| 270 | // GraphTraits specializations for function basic block graphs (CFGs) |
| 271 | //===--------------------------------------------------------------------===// |
| 272 | |
| 273 | // Provide specializations of GraphTraits to be able to treat a |
| 274 | // machine function as a graph of machine basic blocks... these are |
| 275 | // the same as the machine basic block iterators, except that the root |
| 276 | // node is implicitly the first node of the function. |
| 277 | // |
| 278 | template <> struct GraphTraits<MachineFunction*> : |
| 279 | public GraphTraits<MachineBasicBlock*> { |
| 280 | static NodeType *getEntryNode(MachineFunction *F) { |
| 281 | return &F->front(); |
| 282 | } |
| 283 | |
| 284 | // nodes_iterator/begin/end - Allow iteration over all nodes in the graph |
| 285 | typedef MachineFunction::iterator nodes_iterator; |
| 286 | static nodes_iterator nodes_begin(MachineFunction *F) { return F->begin(); } |
| 287 | static nodes_iterator nodes_end (MachineFunction *F) { return F->end(); } |
| 288 | }; |
| 289 | template <> struct GraphTraits<const MachineFunction*> : |
| 290 | public GraphTraits<const MachineBasicBlock*> { |
| 291 | static NodeType *getEntryNode(const MachineFunction *F) { |
| 292 | return &F->front(); |
| 293 | } |
| 294 | |
| 295 | // nodes_iterator/begin/end - Allow iteration over all nodes in the graph |
| 296 | typedef MachineFunction::const_iterator nodes_iterator; |
| 297 | static nodes_iterator nodes_begin(const MachineFunction *F) { return F->begin(); } |
| 298 | static nodes_iterator nodes_end (const MachineFunction *F) { return F->end(); } |
| 299 | }; |
| 300 | |
| 301 | |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 302 | // 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] | 303 | // graph of basic blocks... and to walk it in inverse order. Inverse order for |
| 304 | // a function is considered to be when traversing the predecessor edges of a BB |
| 305 | // instead of the successor edges. |
| 306 | // |
| 307 | template <> struct GraphTraits<Inverse<MachineFunction*> > : |
| 308 | public GraphTraits<Inverse<MachineBasicBlock*> > { |
| 309 | static NodeType *getEntryNode(Inverse<MachineFunction*> G) { |
| 310 | return &G.Graph->front(); |
| 311 | } |
| 312 | }; |
| 313 | template <> struct GraphTraits<Inverse<const MachineFunction*> > : |
| 314 | public GraphTraits<Inverse<const MachineBasicBlock*> > { |
| 315 | static NodeType *getEntryNode(Inverse<const MachineFunction *> G) { |
| 316 | return &G.Graph->front(); |
| 317 | } |
| 318 | }; |
| 319 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 320 | } // End llvm namespace |
| 321 | |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 322 | #endif |