1 //===-- llvm/CodeGen/MachineFunction.h --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // Collect native machine code for a function. This class contains a list of
11 // MachineBasicBlock instances that make up the current compiled function.
13 // This class also contains pointers to various classes which hold
14 // target-specific information about the generated code.
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_CODEGEN_MACHINEFUNCTION_H
19 #define LLVM_CODEGEN_MACHINEFUNCTION_H
21 #include "llvm/CodeGen/MachineBasicBlock.h"
22 #include "Support/Annotation.h"
28 class ilist_traits<MachineBasicBlock> {
29 // this is only set by the MachineFunction owning the ilist
30 friend class MachineFunction;
31 MachineFunction* Parent;
34 ilist_traits<MachineBasicBlock>() : Parent(0) { }
36 static MachineBasicBlock* getPrev(MachineBasicBlock* N) { return N->Prev; }
37 static MachineBasicBlock* getNext(MachineBasicBlock* N) { return N->Next; }
39 static const MachineBasicBlock*
40 getPrev(const MachineBasicBlock* N) { return N->Prev; }
42 static const MachineBasicBlock*
43 getNext(const MachineBasicBlock* N) { return N->Next; }
45 static void setPrev(MachineBasicBlock* N, MachineBasicBlock* prev) { N->Prev = prev; }
46 static void setNext(MachineBasicBlock* N, MachineBasicBlock* next) { N->Next = next; }
48 static MachineBasicBlock* createNode();
49 void addNodeToList(MachineBasicBlock* N);
50 void removeNodeFromList(MachineBasicBlock* N);
51 void transferNodesFromList(
52 iplist<MachineBasicBlock, ilist_traits<MachineBasicBlock> >& toList,
53 ilist_iterator<MachineBasicBlock> first,
54 ilist_iterator<MachineBasicBlock> last);
62 class MachineFunctionInfo;
63 class MachineFrameInfo;
64 class MachineConstantPool;
66 class MachineFunction : private Annotation {
68 const TargetMachine &Target;
70 // List of machine basic blocks in function
71 ilist<MachineBasicBlock> BasicBlocks;
73 // Keeping track of mapping from SSA values to registers
74 SSARegMap *SSARegMapping;
76 // Used to keep track of frame and constant area information for sparc be
77 MachineFunctionInfo *MFInfo;
79 // Keep track of objects allocated on the stack.
80 MachineFrameInfo *FrameInfo;
82 // Keep track of constants which are spilled to memory
83 MachineConstantPool *ConstantPool;
85 // Function-level unique numbering for MachineBasicBlocks
89 MachineFunction(const Function *Fn, const TargetMachine &TM);
92 /// getFunction - Return the LLVM function that this machine code represents
94 const Function *getFunction() const { return Fn; }
96 /// getTarget - Return the target machine this machine code is compiled with
98 const TargetMachine &getTarget() const { return Target; }
100 /// SSARegMap Interface... Keep track of information about each SSA virtual
101 /// register, such as which register class it belongs to.
103 SSARegMap *getSSARegMap() const { return SSARegMapping; }
104 void clearSSARegMap();
106 /// getFrameInfo - Return the frame info object for the current function.
107 /// This object contains information about objects allocated on the stack
108 /// frame of the current function in an abstract way.
110 MachineFrameInfo *getFrameInfo() const { return FrameInfo; }
112 /// getConstantPool - Return the constant pool object for the current
114 MachineConstantPool *getConstantPool() const { return ConstantPool; }
116 /// MachineFunctionInfo - Keep track of various per-function pieces of
117 /// information for the sparc backend.
119 MachineFunctionInfo *getInfo() const { return MFInfo; }
121 /// getNextMBBNumber - Returns the next unique number to be assigned
122 /// to a MachineBasicBlock in this MachineFunction.
124 int getNextMBBNumber() { return NextMBBNumber++; }
126 /// print - Print out the MachineFunction in a format suitable for debugging
127 /// to the specified stream.
129 void print(std::ostream &OS) const;
131 /// dump - Print the current MachineFunction to cerr, useful for debugger use.
135 // The next three methods are used to construct, destruct, and retrieve the
136 // MachineFunction object for the given method.
138 // construct() -- Allocates and initializes for a given method and target
139 // get() -- Returns a handle to the object.
140 // This should not be called before "construct()"
141 // for a given Method.
143 static MachineFunction& construct(const Function *F, const TargetMachine &TM);
144 static void destruct(const Function *F);
145 static MachineFunction& get(const Function *F);
147 // Provide accessors for the MachineBasicBlock list...
148 typedef ilist<MachineBasicBlock> BasicBlockListType;
149 typedef BasicBlockListType::iterator iterator;
150 typedef BasicBlockListType::const_iterator const_iterator;
151 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
152 typedef std::reverse_iterator<iterator> reverse_iterator;
154 // Provide accessors for basic blocks...
155 const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
156 BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
158 //===--------------------------------------------------------------------===//
159 // BasicBlock iterator forwarding functions
161 iterator begin() { return BasicBlocks.begin(); }
162 const_iterator begin() const { return BasicBlocks.begin(); }
163 iterator end () { return BasicBlocks.end(); }
164 const_iterator end () const { return BasicBlocks.end(); }
166 reverse_iterator rbegin() { return BasicBlocks.rbegin(); }
167 const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); }
168 reverse_iterator rend () { return BasicBlocks.rend(); }
169 const_reverse_iterator rend () const { return BasicBlocks.rend(); }
171 unsigned size() const { return BasicBlocks.size(); }
172 bool empty() const { return BasicBlocks.empty(); }
173 const MachineBasicBlock &front() const { return BasicBlocks.front(); }
174 MachineBasicBlock &front() { return BasicBlocks.front(); }
175 const MachineBasicBlock & back() const { return BasicBlocks.back(); }
176 MachineBasicBlock & back() { return BasicBlocks.back(); }
179 } // End llvm namespace