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