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 | |
Dan Gohman | fed90b6 | 2008-07-28 21:51:04 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/ilist.h" |
Evan Cheng | d0adbb5 | 2009-01-26 07:41:49 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/DebugLoc.h" |
Chris Lattner | 0551f54 | 2002-10-28 02:01:06 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineBasicBlock.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Annotation.h" |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Allocator.h" |
| 26 | #include "llvm/Support/Recycler.h" |
Chris Lattner | 8e7ae98 | 2002-10-28 02:08:43 +0000 | [diff] [blame] | 27 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 28 | namespace llvm { |
| 29 | |
Chris Lattner | 8bdf87d | 2004-08-18 18:13:16 +0000 | [diff] [blame] | 30 | class Function; |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 31 | class MachineRegisterInfo; |
Chris Lattner | 8bdf87d | 2004-08-18 18:13:16 +0000 | [diff] [blame] | 32 | class MachineFrameInfo; |
| 33 | class MachineConstantPool; |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 34 | class MachineJumpTableInfo; |
Evan Cheng | d0adbb5 | 2009-01-26 07:41:49 +0000 | [diff] [blame] | 35 | class TargetMachine; |
Chris Lattner | 8bdf87d | 2004-08-18 18:13:16 +0000 | [diff] [blame] | 36 | |
Tanya Lattner | 792699c | 2004-05-24 06:11:51 +0000 | [diff] [blame] | 37 | template <> |
Cedric Venet | 8e4018e | 2008-09-20 18:02:18 +0000 | [diff] [blame] | 38 | struct ilist_traits<MachineBasicBlock> |
Dan Gohman | fed90b6 | 2008-07-28 21:51:04 +0000 | [diff] [blame] | 39 | : public ilist_default_traits<MachineBasicBlock> { |
| 40 | mutable MachineBasicBlock Sentinel; |
Tanya Lattner | 792699c | 2004-05-24 06:11:51 +0000 | [diff] [blame] | 41 | public: |
Dan Gohman | fed90b6 | 2008-07-28 21:51:04 +0000 | [diff] [blame] | 42 | MachineBasicBlock *createSentinel() const { return &Sentinel; } |
| 43 | void destroySentinel(MachineBasicBlock *) const {} |
| 44 | |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 45 | void addNodeToList(MachineBasicBlock* MBB); |
| 46 | void removeNodeFromList(MachineBasicBlock* MBB); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 47 | void deleteNode(MachineBasicBlock *MBB); |
Dan Gohman | fed90b6 | 2008-07-28 21:51:04 +0000 | [diff] [blame] | 48 | private: |
| 49 | void createNode(const MachineBasicBlock &); |
Tanya Lattner | 792699c | 2004-05-24 06:11:51 +0000 | [diff] [blame] | 50 | }; |
Tanya Lattner | 792699c | 2004-05-24 06:11:51 +0000 | [diff] [blame] | 51 | |
Chris Lattner | 8bdf87d | 2004-08-18 18:13:16 +0000 | [diff] [blame] | 52 | /// MachineFunctionInfo - This class can be derived from and used by targets to |
| 53 | /// hold private target-specific information for each MachineFunction. Objects |
| 54 | /// of type are accessed/created with MF::getInfo and destroyed when the |
| 55 | /// MachineFunction is destroyed. |
| 56 | struct MachineFunctionInfo { |
Dan Gohman | 81975f6 | 2007-08-27 14:50:10 +0000 | [diff] [blame] | 57 | virtual ~MachineFunctionInfo() {} |
Chris Lattner | 8bdf87d | 2004-08-18 18:13:16 +0000 | [diff] [blame] | 58 | }; |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 59 | |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 60 | class MachineFunction : private Annotation { |
Chris Lattner | 335d5c3 | 2002-10-28 05:58:46 +0000 | [diff] [blame] | 61 | const Function *Fn; |
| 62 | const TargetMachine &Target; |
Chris Lattner | 8e7ae98 | 2002-10-28 02:08:43 +0000 | [diff] [blame] | 63 | |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 64 | // RegInfo - Information about each register in use in the function. |
| 65 | MachineRegisterInfo *RegInfo; |
Chris Lattner | 03ab7af | 2002-12-25 05:00:16 +0000 | [diff] [blame] | 66 | |
Chris Lattner | 8bdf87d | 2004-08-18 18:13:16 +0000 | [diff] [blame] | 67 | // Used to keep track of target-specific per-machine function information for |
| 68 | // the target implementation. |
| 69 | MachineFunctionInfo *MFInfo; |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 70 | |
| 71 | // Keep track of objects allocated on the stack. |
Chris Lattner | aa09b75 | 2002-12-28 21:08:28 +0000 | [diff] [blame] | 72 | MachineFrameInfo *FrameInfo; |
Misha Brukman | 1617e6c | 2002-11-20 00:53:10 +0000 | [diff] [blame] | 73 | |
Chris Lattner | 40a7557 | 2003-01-13 00:16:10 +0000 | [diff] [blame] | 74 | // Keep track of constants which are spilled to memory |
| 75 | MachineConstantPool *ConstantPool; |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 76 | |
| 77 | // Keep track of jump tables for switch instructions |
| 78 | MachineJumpTableInfo *JumpTableInfo; |
Chris Lattner | 40a7557 | 2003-01-13 00:16:10 +0000 | [diff] [blame] | 79 | |
Chris Lattner | 25d8039 | 2004-07-01 06:01:36 +0000 | [diff] [blame] | 80 | // Function-level unique numbering for MachineBasicBlocks. When a |
| 81 | // MachineBasicBlock is inserted into a MachineFunction is it automatically |
| 82 | // numbered and this vector keeps track of the mapping from ID's to MBB's. |
| 83 | std::vector<MachineBasicBlock*> MBBNumbering; |
Brian Gaeke | f460f16 | 2004-05-12 21:35:21 +0000 | [diff] [blame] | 84 | |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 85 | // Pool-allocate MachineFunction-lifetime and IR objects. |
| 86 | BumpPtrAllocator Allocator; |
| 87 | |
| 88 | // Allocation management for instructions in function. |
| 89 | Recycler<MachineInstr> InstructionRecycler; |
| 90 | |
| 91 | // Allocation management for basic blocks in function. |
| 92 | Recycler<MachineBasicBlock> BasicBlockRecycler; |
| 93 | |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 94 | // List of machine basic blocks in function |
Dan Gohman | fed90b6 | 2008-07-28 21:51:04 +0000 | [diff] [blame] | 95 | typedef ilist<MachineBasicBlock> BasicBlockListType; |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 96 | BasicBlockListType BasicBlocks; |
| 97 | |
Evan Cheng | d0adbb5 | 2009-01-26 07:41:49 +0000 | [diff] [blame] | 98 | // Tracks debug locations. |
| 99 | DebugLocTracker DebugLocInfo; |
| 100 | |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 101 | public: |
Chris Lattner | 40a7557 | 2003-01-13 00:16:10 +0000 | [diff] [blame] | 102 | MachineFunction(const Function *Fn, const TargetMachine &TM); |
Chris Lattner | 03ab7af | 2002-12-25 05:00:16 +0000 | [diff] [blame] | 103 | ~MachineFunction(); |
Chris Lattner | 335d5c3 | 2002-10-28 05:58:46 +0000 | [diff] [blame] | 104 | |
| 105 | /// getFunction - Return the LLVM function that this machine code represents |
| 106 | /// |
| 107 | const Function *getFunction() const { return Fn; } |
| 108 | |
| 109 | /// getTarget - Return the target machine this machine code is compiled with |
| 110 | /// |
| 111 | const TargetMachine &getTarget() const { return Target; } |
Chris Lattner | dea7383 | 2002-10-30 00:46:31 +0000 | [diff] [blame] | 112 | |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 113 | /// getRegInfo - Return information about the registers currently in use. |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 114 | /// |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 115 | MachineRegisterInfo &getRegInfo() { return *RegInfo; } |
| 116 | const MachineRegisterInfo &getRegInfo() const { return *RegInfo; } |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 117 | |
| 118 | /// getFrameInfo - Return the frame info object for the current function. |
| 119 | /// This object contains information about objects allocated on the stack |
| 120 | /// frame of the current function in an abstract way. |
| 121 | /// |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 122 | MachineFrameInfo *getFrameInfo() { return FrameInfo; } |
| 123 | const MachineFrameInfo *getFrameInfo() const { return FrameInfo; } |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 124 | |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 125 | /// getJumpTableInfo - Return the jump table info object for the current |
| 126 | /// function. This object contains information about jump tables for switch |
| 127 | /// instructions in the current function. |
| 128 | /// |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 129 | MachineJumpTableInfo *getJumpTableInfo() { return JumpTableInfo; } |
| 130 | const MachineJumpTableInfo *getJumpTableInfo() const { return JumpTableInfo; } |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 131 | |
Chris Lattner | 40a7557 | 2003-01-13 00:16:10 +0000 | [diff] [blame] | 132 | /// getConstantPool - Return the constant pool object for the current |
| 133 | /// function. |
Misha Brukman | 274ba03 | 2004-08-17 17:52:36 +0000 | [diff] [blame] | 134 | /// |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 135 | MachineConstantPool *getConstantPool() { return ConstantPool; } |
| 136 | const MachineConstantPool *getConstantPool() const { return ConstantPool; } |
Chris Lattner | 40a7557 | 2003-01-13 00:16:10 +0000 | [diff] [blame] | 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() { |
Dan Gohman | 219c790 | 2008-07-25 00:36:05 +0000 | [diff] [blame] | 143 | if (!MFInfo) { |
| 144 | // This should be just `new (Allocator.Allocate<Ty>()) Ty(*this)', but |
| 145 | // that apparently breaks GCC 3.3. |
| 146 | Ty *Loc = static_cast<Ty*>(Allocator.Allocate(sizeof(Ty), |
| 147 | AlignOf<Ty>::Alignment)); |
| 148 | MFInfo = new (Loc) Ty(*this); |
| 149 | } |
Chris Lattner | 8bdf87d | 2004-08-18 18:13:16 +0000 | [diff] [blame] | 150 | |
| 151 | assert((void*)dynamic_cast<Ty*>(MFInfo) == (void*)MFInfo && |
| 152 | "Invalid concrete type or multiple inheritence for getInfo"); |
| 153 | return static_cast<Ty*>(MFInfo); |
| 154 | } |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 155 | |
Chris Lattner | 5ea64fd | 2006-08-17 22:00:08 +0000 | [diff] [blame] | 156 | template<typename Ty> |
| 157 | const Ty *getInfo() const { |
| 158 | return const_cast<MachineFunction*>(this)->getInfo<Ty>(); |
| 159 | } |
| 160 | |
Chris Lattner | 25d8039 | 2004-07-01 06:01:36 +0000 | [diff] [blame] | 161 | /// getBlockNumbered - MachineBasicBlocks are automatically numbered when they |
| 162 | /// are inserted into the machine function. The block number for a machine |
| 163 | /// basic block can be found by using the MBB::getBlockNumber method, this |
| 164 | /// method provides the inverse mapping. |
Misha Brukman | 274ba03 | 2004-08-17 17:52:36 +0000 | [diff] [blame] | 165 | /// |
Chris Lattner | 25d8039 | 2004-07-01 06:01:36 +0000 | [diff] [blame] | 166 | MachineBasicBlock *getBlockNumbered(unsigned N) { |
| 167 | assert(N < MBBNumbering.size() && "Illegal block number"); |
| 168 | assert(MBBNumbering[N] && "Block was removed from the machine function!"); |
| 169 | return MBBNumbering[N]; |
| 170 | } |
Chris Lattner | cd0d1d1 | 2002-12-28 20:04:31 +0000 | [diff] [blame] | 171 | |
Chris Lattner | 2540813 | 2006-09-14 06:40:48 +0000 | [diff] [blame] | 172 | /// getNumBlockIDs - Return the number of MBB ID's allocated. |
Chris Lattner | e70cab0 | 2006-10-03 19:18:57 +0000 | [diff] [blame] | 173 | /// |
Evan Cheng | 34cd4a4 | 2008-05-05 18:30:58 +0000 | [diff] [blame] | 174 | unsigned getNumBlockIDs() const { return (unsigned)MBBNumbering.size(); } |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 175 | |
Chris Lattner | e70cab0 | 2006-10-03 19:18:57 +0000 | [diff] [blame] | 176 | /// RenumberBlocks - This discards all of the MachineBasicBlock numbers and |
| 177 | /// recomputes them. This guarantees that the MBB numbers are sequential, |
| 178 | /// dense, and match the ordering of the blocks within the function. If a |
| 179 | /// specific MachineBasicBlock is specified, only that block and those after |
| 180 | /// it are renumbered. |
| 181 | void RenumberBlocks(MachineBasicBlock *MBBFrom = 0); |
| 182 | |
Chris Lattner | dea7383 | 2002-10-30 00:46:31 +0000 | [diff] [blame] | 183 | /// print - Print out the MachineFunction in a format suitable for debugging |
| 184 | /// to the specified stream. |
| 185 | /// |
| 186 | void print(std::ostream &OS) const; |
Bill Wendling | 5c7e326 | 2006-12-17 05:15:13 +0000 | [diff] [blame] | 187 | void print(std::ostream *OS) const { if (OS) print(*OS); } |
Chris Lattner | dea7383 | 2002-10-30 00:46:31 +0000 | [diff] [blame] | 188 | |
Alkis Evlogimenos | 71bf404 | 2004-07-08 00:47:58 +0000 | [diff] [blame] | 189 | /// viewCFG - This function is meant for use from the debugger. You can just |
| 190 | /// say 'call F->viewCFG()' and a ghostview window should pop up from the |
| 191 | /// program, displaying the CFG of the current function with the code for each |
| 192 | /// basic block inside. This depends on there being a 'dot' and 'gv' program |
| 193 | /// in your path. |
| 194 | /// |
| 195 | void viewCFG() const; |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 196 | |
Alkis Evlogimenos | 71bf404 | 2004-07-08 00:47:58 +0000 | [diff] [blame] | 197 | /// viewCFGOnly - This function is meant for use from the debugger. It works |
| 198 | /// just like viewCFG, but it does not include the contents of basic blocks |
| 199 | /// into the nodes, just the label. If you are only interested in the CFG |
| 200 | /// this can make the graph smaller. |
| 201 | /// |
| 202 | void viewCFGOnly() const; |
| 203 | |
Chris Lattner | dea7383 | 2002-10-30 00:46:31 +0000 | [diff] [blame] | 204 | /// dump - Print the current MachineFunction to cerr, useful for debugger use. |
| 205 | /// |
| 206 | void dump() const; |
| 207 | |
Misha Brukman | a7afa37 | 2004-06-04 14:51:25 +0000 | [diff] [blame] | 208 | /// construct - Allocate and initialize a MachineFunction for a given Function |
| 209 | /// and Target |
| 210 | /// |
Chris Lattner | 40a7557 | 2003-01-13 00:16:10 +0000 | [diff] [blame] | 211 | static MachineFunction& construct(const Function *F, const TargetMachine &TM); |
Misha Brukman | a7afa37 | 2004-06-04 14:51:25 +0000 | [diff] [blame] | 212 | |
| 213 | /// destruct - Destroy the MachineFunction corresponding to a given Function |
| 214 | /// |
Chris Lattner | e7506a3 | 2002-03-23 22:51:58 +0000 | [diff] [blame] | 215 | static void destruct(const Function *F); |
Misha Brukman | a7afa37 | 2004-06-04 14:51:25 +0000 | [diff] [blame] | 216 | |
| 217 | /// get - Return a handle to a MachineFunction corresponding to the given |
| 218 | /// Function. This should not be called before "construct()" for a given |
| 219 | /// Function. |
| 220 | /// |
Chris Lattner | d0aa0cd | 2002-10-28 05:30:46 +0000 | [diff] [blame] | 221 | static MachineFunction& get(const Function *F); |
Chris Lattner | 9c6342d | 2002-10-28 01:27:51 +0000 | [diff] [blame] | 222 | |
Chris Lattner | d0aa0cd | 2002-10-28 05:30:46 +0000 | [diff] [blame] | 223 | // Provide accessors for the MachineBasicBlock list... |
Chris Lattner | d0aa0cd | 2002-10-28 05:30:46 +0000 | [diff] [blame] | 224 | typedef BasicBlockListType::iterator iterator; |
| 225 | typedef BasicBlockListType::const_iterator const_iterator; |
| 226 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 227 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 228 | |
Chris Lattner | d0aa0cd | 2002-10-28 05:30:46 +0000 | [diff] [blame] | 229 | //===--------------------------------------------------------------------===// |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 230 | // BasicBlock accessor functions. |
Chris Lattner | d0aa0cd | 2002-10-28 05:30:46 +0000 | [diff] [blame] | 231 | // |
| 232 | iterator begin() { return BasicBlocks.begin(); } |
| 233 | const_iterator begin() const { return BasicBlocks.begin(); } |
| 234 | iterator end () { return BasicBlocks.end(); } |
| 235 | const_iterator end () const { return BasicBlocks.end(); } |
| 236 | |
| 237 | reverse_iterator rbegin() { return BasicBlocks.rbegin(); } |
| 238 | const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); } |
| 239 | reverse_iterator rend () { return BasicBlocks.rend(); } |
| 240 | const_reverse_iterator rend () const { return BasicBlocks.rend(); } |
| 241 | |
Evan Cheng | 34cd4a4 | 2008-05-05 18:30:58 +0000 | [diff] [blame] | 242 | unsigned size() const { return (unsigned)BasicBlocks.size();} |
Chris Lattner | d0aa0cd | 2002-10-28 05:30:46 +0000 | [diff] [blame] | 243 | bool empty() const { return BasicBlocks.empty(); } |
| 244 | const MachineBasicBlock &front() const { return BasicBlocks.front(); } |
| 245 | MachineBasicBlock &front() { return BasicBlocks.front(); } |
Misha Brukman | d5806ff | 2002-10-28 19:58:38 +0000 | [diff] [blame] | 246 | const MachineBasicBlock & back() const { return BasicBlocks.back(); } |
| 247 | MachineBasicBlock & back() { return BasicBlocks.back(); } |
Chris Lattner | 25d8039 | 2004-07-01 06:01:36 +0000 | [diff] [blame] | 248 | |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 249 | void push_back (MachineBasicBlock *MBB) { BasicBlocks.push_back (MBB); } |
| 250 | void push_front(MachineBasicBlock *MBB) { BasicBlocks.push_front(MBB); } |
| 251 | void insert(iterator MBBI, MachineBasicBlock *MBB) { |
| 252 | BasicBlocks.insert(MBBI, MBB); |
| 253 | } |
| 254 | void splice(iterator InsertPt, iterator MBBI) { |
| 255 | BasicBlocks.splice(InsertPt, BasicBlocks, MBBI); |
| 256 | } |
| 257 | |
| 258 | void remove(iterator MBBI) { |
| 259 | BasicBlocks.remove(MBBI); |
| 260 | } |
| 261 | void erase(iterator MBBI) { |
| 262 | BasicBlocks.erase(MBBI); |
| 263 | } |
| 264 | |
Chris Lattner | 25d8039 | 2004-07-01 06:01:36 +0000 | [diff] [blame] | 265 | //===--------------------------------------------------------------------===// |
| 266 | // Internal functions used to automatically number MachineBasicBlocks |
| 267 | // |
| 268 | |
| 269 | /// getNextMBBNumber - Returns the next unique number to be assigned |
| 270 | /// to a MachineBasicBlock in this MachineFunction. |
| 271 | /// |
| 272 | unsigned addToMBBNumbering(MachineBasicBlock *MBB) { |
| 273 | MBBNumbering.push_back(MBB); |
Evan Cheng | 34cd4a4 | 2008-05-05 18:30:58 +0000 | [diff] [blame] | 274 | return (unsigned)MBBNumbering.size()-1; |
Chris Lattner | 25d8039 | 2004-07-01 06:01:36 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | /// removeFromMBBNumbering - Remove the specific machine basic block from our |
| 278 | /// tracker, this is only really to be used by the MachineBasicBlock |
| 279 | /// implementation. |
| 280 | void removeFromMBBNumbering(unsigned N) { |
| 281 | assert(N < MBBNumbering.size() && "Illegal basic block #"); |
| 282 | MBBNumbering[N] = 0; |
| 283 | } |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 284 | |
| 285 | /// CreateMachineInstr - Allocate a new MachineInstr. Use this instead |
| 286 | /// of `new MachineInstr'. |
| 287 | /// |
| 288 | MachineInstr *CreateMachineInstr(const TargetInstrDesc &TID, |
Bill Wendling | 9bc96a5 | 2009-02-03 00:55:04 +0000 | [diff] [blame] | 289 | DebugLoc DL, |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 290 | bool NoImp = false); |
| 291 | |
| 292 | /// CloneMachineInstr - Create a new MachineInstr which is a copy of the |
| 293 | /// 'Orig' instruction, identical in all ways except the the instruction |
| 294 | /// has no parent, prev, or next. |
| 295 | /// |
| 296 | MachineInstr *CloneMachineInstr(const MachineInstr *Orig); |
| 297 | |
| 298 | /// DeleteMachineInstr - Delete the given MachineInstr. |
| 299 | /// |
| 300 | void DeleteMachineInstr(MachineInstr *MI); |
| 301 | |
| 302 | /// CreateMachineBasicBlock - Allocate a new MachineBasicBlock. Use this |
| 303 | /// instead of `new MachineBasicBlock'. |
| 304 | /// |
| 305 | MachineBasicBlock *CreateMachineBasicBlock(const BasicBlock *bb = 0); |
| 306 | |
| 307 | /// DeleteMachineBasicBlock - Delete the given MachineBasicBlock. |
| 308 | /// |
| 309 | void DeleteMachineBasicBlock(MachineBasicBlock *MBB); |
Evan Cheng | d0adbb5 | 2009-01-26 07:41:49 +0000 | [diff] [blame] | 310 | |
| 311 | //===--------------------------------------------------------------------===// |
| 312 | // Debug location. |
| 313 | // |
| 314 | |
Evan Cheng | aaeea9e | 2009-01-27 21:15:07 +0000 | [diff] [blame] | 315 | /// getOrCreateDebugLocID - Look up the DebugLocTuple index with the given |
Bill Wendling | 85e3af9 | 2009-02-03 22:49:58 +0000 | [diff] [blame^] | 316 | /// source file, line, and column. If none currently exists, create a new |
| 317 | /// DebugLocTuple, and insert it into the DebugIdMap. |
Evan Cheng | aaeea9e | 2009-01-27 21:15:07 +0000 | [diff] [blame] | 318 | unsigned getOrCreateDebugLocID(unsigned Src, unsigned Line, unsigned Col); |
Bill Wendling | 85e3af9 | 2009-02-03 22:49:58 +0000 | [diff] [blame^] | 319 | |
| 320 | /// getDebugLocTuple - Get the DebugLocTuple for a given DebugLoc object. |
| 321 | const DebugLocTuple &getDebugLocTuple(DebugLoc DL); |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 322 | }; |
| 323 | |
Alkis Evlogimenos | 71bf404 | 2004-07-08 00:47:58 +0000 | [diff] [blame] | 324 | //===--------------------------------------------------------------------===// |
| 325 | // GraphTraits specializations for function basic block graphs (CFGs) |
| 326 | //===--------------------------------------------------------------------===// |
| 327 | |
| 328 | // Provide specializations of GraphTraits to be able to treat a |
| 329 | // machine function as a graph of machine basic blocks... these are |
| 330 | // the same as the machine basic block iterators, except that the root |
| 331 | // node is implicitly the first node of the function. |
| 332 | // |
| 333 | template <> struct GraphTraits<MachineFunction*> : |
| 334 | public GraphTraits<MachineBasicBlock*> { |
| 335 | static NodeType *getEntryNode(MachineFunction *F) { |
| 336 | return &F->front(); |
| 337 | } |
| 338 | |
| 339 | // nodes_iterator/begin/end - Allow iteration over all nodes in the graph |
| 340 | typedef MachineFunction::iterator nodes_iterator; |
| 341 | static nodes_iterator nodes_begin(MachineFunction *F) { return F->begin(); } |
| 342 | static nodes_iterator nodes_end (MachineFunction *F) { return F->end(); } |
| 343 | }; |
| 344 | template <> struct GraphTraits<const MachineFunction*> : |
| 345 | public GraphTraits<const MachineBasicBlock*> { |
| 346 | static NodeType *getEntryNode(const MachineFunction *F) { |
| 347 | return &F->front(); |
| 348 | } |
| 349 | |
| 350 | // nodes_iterator/begin/end - Allow iteration over all nodes in the graph |
| 351 | typedef MachineFunction::const_iterator nodes_iterator; |
| 352 | static nodes_iterator nodes_begin(const MachineFunction *F) { return F->begin(); } |
| 353 | static nodes_iterator nodes_end (const MachineFunction *F) { return F->end(); } |
| 354 | }; |
| 355 | |
| 356 | |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 357 | // 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] | 358 | // graph of basic blocks... and to walk it in inverse order. Inverse order for |
| 359 | // a function is considered to be when traversing the predecessor edges of a BB |
| 360 | // instead of the successor edges. |
| 361 | // |
| 362 | template <> struct GraphTraits<Inverse<MachineFunction*> > : |
| 363 | public GraphTraits<Inverse<MachineBasicBlock*> > { |
| 364 | static NodeType *getEntryNode(Inverse<MachineFunction*> G) { |
| 365 | return &G.Graph->front(); |
| 366 | } |
| 367 | }; |
| 368 | template <> struct GraphTraits<Inverse<const MachineFunction*> > : |
| 369 | public GraphTraits<Inverse<const MachineBasicBlock*> > { |
| 370 | static NodeType *getEntryNode(Inverse<const MachineFunction *> G) { |
| 371 | return &G.Graph->front(); |
| 372 | } |
| 373 | }; |
| 374 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 375 | } // End llvm namespace |
| 376 | |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 377 | #endif |