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