1 //===-- llvm/CodeGen/MachineFunction.h --------------------------*- C++ -*-===//
3 // Collect native machine code for a function. This class contains a list of
4 // MachineBasicBlock instances that make up the current compiled function.
6 // This class also contains pointers to various classes which hold
7 // target-specific information about the generated code.
9 //===----------------------------------------------------------------------===//
11 #ifndef LLVM_CODEGEN_MACHINEFUNCTION_H
12 #define LLVM_CODEGEN_MACHINEFUNCTION_H
14 #include "llvm/CodeGen/MachineBasicBlock.h"
15 #include "Support/Annotation.h"
16 #include "Support/ilist"
22 class MachineFunctionInfo;
23 class MachineFrameInfo;
24 class MachineConstantPool;
26 Pass *createMachineCodeConstructionPass(TargetMachine &TM);
27 Pass *createMachineCodeDestructionPass();
28 Pass *createMachineFunctionPrinterPass();
30 class MachineFunction : private Annotation {
32 const TargetMachine &Target;
34 // List of machine basic blocks in function
35 iplist<MachineBasicBlock> BasicBlocks;
37 // Keeping track of mapping from SSA values to registers
38 SSARegMap *SSARegMapping;
40 // Used to keep track of frame and constant area information for sparc be
41 MachineFunctionInfo *MFInfo;
43 // Keep track of objects allocated on the stack.
44 MachineFrameInfo *FrameInfo;
46 // Keep track of constants which are spilled to memory
47 MachineConstantPool *ConstantPool;
50 MachineFunction(const Function *Fn, const TargetMachine &TM);
53 /// getFunction - Return the LLVM function that this machine code represents
55 const Function *getFunction() const { return Fn; }
57 /// getTarget - Return the target machine this machine code is compiled with
59 const TargetMachine &getTarget() const { return Target; }
61 /// SSARegMap Interface... Keep track of information about each SSA virtual
62 /// register, such as which register class it belongs to.
64 SSARegMap *getSSARegMap() const { return SSARegMapping; }
65 void clearSSARegMap();
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.
71 MachineFrameInfo *getFrameInfo() const { return FrameInfo; }
73 /// getConstantPool - Return the constant pool object for the current
75 MachineConstantPool *getConstantPool() const { return ConstantPool; }
77 /// MachineFunctionInfo - Keep track of various per-function pieces of
78 /// information for the sparc backend.
80 MachineFunctionInfo *getInfo() const { return MFInfo; }
83 /// print - Print out the MachineFunction in a format suitable for debugging
84 /// to the specified stream.
86 void print(std::ostream &OS) const;
88 /// dump - Print the current MachineFunction to cerr, useful for debugger use.
92 // The next three methods are used to construct, destruct, and retrieve the
93 // MachineFunction object for the given method.
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
101 static MachineFunction& construct(const Function *F, const TargetMachine &TM);
102 static void destruct(const Function *F);
103 static MachineFunction& get(const Function *F);
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;
112 // Provide accessors for basic blocks...
113 const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
114 BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
116 //===--------------------------------------------------------------------===//
117 // BasicBlock iterator forwarding functions
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(); }
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(); }
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(); }