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