Put all LLVM code into the llvm namespace, as per bug 109.
[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 FunctionPass;
30 class SSARegMap;
31 class MachineFunctionInfo;
32 class MachineFrameInfo;
33 class MachineConstantPool;
34
35 FunctionPass *createMachineCodeConstructionPass(TargetMachine &TM);
36 FunctionPass *createMachineCodeDestructionPass();
37 FunctionPass *createMachineFunctionPrinterPass();
38
39 class MachineFunction : private Annotation {
40   const Function *Fn;
41   const TargetMachine &Target;
42
43   // List of machine basic blocks in function
44   iplist<MachineBasicBlock> BasicBlocks;
45
46   // Keeping track of mapping from SSA values to registers
47   SSARegMap *SSARegMapping;
48
49   // Used to keep track of frame and constant area information for sparc be
50   MachineFunctionInfo *MFInfo;
51
52   // Keep track of objects allocated on the stack.
53   MachineFrameInfo *FrameInfo;
54
55   // Keep track of constants which are spilled to memory
56   MachineConstantPool *ConstantPool;
57
58 public:
59   MachineFunction(const Function *Fn, const TargetMachine &TM);
60   ~MachineFunction();
61
62   /// getFunction - Return the LLVM function that this machine code represents
63   ///
64   const Function *getFunction() const { return Fn; }
65
66   /// getTarget - Return the target machine this machine code is compiled with
67   ///
68   const TargetMachine &getTarget() const { return Target; }
69
70   /// SSARegMap Interface... Keep track of information about each SSA virtual
71   /// register, such as which register class it belongs to.
72   ///
73   SSARegMap *getSSARegMap() const { return SSARegMapping; }
74   void clearSSARegMap();
75
76   /// getFrameInfo - Return the frame info object for the current function.
77   /// This object contains information about objects allocated on the stack
78   /// frame of the current function in an abstract way.
79   ///
80   MachineFrameInfo *getFrameInfo() const { return FrameInfo; }
81
82   /// getConstantPool - Return the constant pool object for the current
83   /// function.
84   MachineConstantPool *getConstantPool() const { return ConstantPool; }
85
86   /// MachineFunctionInfo - Keep track of various per-function pieces of
87   /// information for the sparc backend.
88   ///
89   MachineFunctionInfo *getInfo() const { return MFInfo; }
90
91
92   /// print - Print out the MachineFunction in a format suitable for debugging
93   /// to the specified stream.
94   ///
95   void print(std::ostream &OS) const;
96
97   /// dump - Print the current MachineFunction to cerr, useful for debugger use.
98   ///
99   void dump() const;
100
101   // The next three methods are used to construct, destruct, and retrieve the
102   // MachineFunction object for the given method.
103   //
104   // construct() -- Allocates and initializes for a given method and target
105   // get()       -- Returns a handle to the object.
106   //                This should not be called before "construct()"
107   //                for a given Method.
108   // destruct()  -- Destroy the MachineFunction object
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