Factory methods for FunctionPasses now return type FunctionPass *.
[oota-llvm.git] / include / llvm / CodeGen / MachineFunction.h
1 //===-- llvm/CodeGen/MachineFunction.h --------------------------*- C++ -*-===//
2 // 
3 // Collect native machine code for a function.  This class contains a list of
4 // MachineBasicBlock instances that make up the current compiled function.
5 //
6 // This class also contains pointers to various classes which hold
7 // target-specific information about the generated code.
8 //   
9 //===----------------------------------------------------------------------===//
10
11 #ifndef LLVM_CODEGEN_MACHINEFUNCTION_H
12 #define LLVM_CODEGEN_MACHINEFUNCTION_H
13
14 #include "llvm/CodeGen/MachineBasicBlock.h"
15 #include "Support/Annotation.h"
16 #include "Support/ilist"
17
18 class Function;
19 class TargetMachine;
20 class FunctionPass;
21 class SSARegMap;
22 class MachineFunctionInfo;
23 class MachineFrameInfo;
24 class MachineConstantPool;
25
26 FunctionPass *createMachineCodeConstructionPass(TargetMachine &TM);
27 FunctionPass *createMachineCodeDestructionPass();
28 FunctionPass *createMachineFunctionPrinterPass();
29
30 class MachineFunction : private Annotation {
31   const Function *Fn;
32   const TargetMachine &Target;
33
34   // List of machine basic blocks in function
35   iplist<MachineBasicBlock> BasicBlocks;
36
37   // Keeping track of mapping from SSA values to registers
38   SSARegMap *SSARegMapping;
39
40   // Used to keep track of frame and constant area information for sparc be
41   MachineFunctionInfo *MFInfo;
42
43   // Keep track of objects allocated on the stack.
44   MachineFrameInfo *FrameInfo;
45
46   // Keep track of constants which are spilled to memory
47   MachineConstantPool *ConstantPool;
48
49 public:
50   MachineFunction(const Function *Fn, const TargetMachine &TM);
51   ~MachineFunction();
52
53   /// getFunction - Return the LLVM function that this machine code represents
54   ///
55   const Function *getFunction() const { return Fn; }
56
57   /// getTarget - Return the target machine this machine code is compiled with
58   ///
59   const TargetMachine &getTarget() const { return Target; }
60
61   /// SSARegMap Interface... Keep track of information about each SSA virtual
62   /// register, such as which register class it belongs to.
63   ///
64   SSARegMap *getSSARegMap() const { return SSARegMapping; }
65   void clearSSARegMap();
66
67   /// getFrameInfo - Return the frame info object for the current function.
68   /// This object contains information about objects allocated on the stack
69   /// frame of the current function in an abstract way.
70   ///
71   MachineFrameInfo *getFrameInfo() const { return FrameInfo; }
72
73   /// getConstantPool - Return the constant pool object for the current
74   /// function.
75   MachineConstantPool *getConstantPool() const { return ConstantPool; }
76
77   /// MachineFunctionInfo - Keep track of various per-function pieces of
78   /// information for the sparc backend.
79   ///
80   MachineFunctionInfo *getInfo() const { return MFInfo; }
81
82
83   /// print - Print out the MachineFunction in a format suitable for debugging
84   /// to the specified stream.
85   ///
86   void print(std::ostream &OS) const;
87
88   /// dump - Print the current MachineFunction to cerr, useful for debugger use.
89   ///
90   void dump() const;
91
92   // The next three methods are used to construct, destruct, and retrieve the
93   // MachineFunction object for the given method.
94   //
95   // construct() -- Allocates and initializes for a given method and target
96   // get()       -- Returns a handle to the object.
97   //                This should not be called before "construct()"
98   //                for a given Method.
99   // destruct()  -- Destroy the MachineFunction object
100   // 
101   static MachineFunction& construct(const Function *F, const TargetMachine &TM);
102   static void destruct(const Function *F);
103   static MachineFunction& get(const Function *F);
104
105   // Provide accessors for the MachineBasicBlock list...
106   typedef iplist<MachineBasicBlock> BasicBlockListType;
107   typedef BasicBlockListType::iterator iterator;
108   typedef BasicBlockListType::const_iterator const_iterator;
109   typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
110   typedef std::reverse_iterator<iterator>             reverse_iterator;
111
112   // Provide accessors for basic blocks...
113   const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
114         BasicBlockListType &getBasicBlockList()       { return BasicBlocks; }
115  
116   //===--------------------------------------------------------------------===//
117   // BasicBlock iterator forwarding functions
118   //
119   iterator                 begin()       { return BasicBlocks.begin(); }
120   const_iterator           begin() const { return BasicBlocks.begin(); }
121   iterator                 end  ()       { return BasicBlocks.end();   }
122   const_iterator           end  () const { return BasicBlocks.end();   }
123
124   reverse_iterator        rbegin()       { return BasicBlocks.rbegin(); }
125   const_reverse_iterator  rbegin() const { return BasicBlocks.rbegin(); }
126   reverse_iterator        rend  ()       { return BasicBlocks.rend();   }
127   const_reverse_iterator  rend  () const { return BasicBlocks.rend();   }
128
129   unsigned                  size() const { return BasicBlocks.size(); }
130   bool                     empty() const { return BasicBlocks.empty(); }
131   const MachineBasicBlock &front() const { return BasicBlocks.front(); }
132         MachineBasicBlock &front()       { return BasicBlocks.front(); }
133   const MachineBasicBlock & back() const { return BasicBlocks.back(); }
134         MachineBasicBlock & back()       { return BasicBlocks.back(); }
135 };
136
137 #endif