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 "llvm/Annotation.h"
16 #include "Support/ilist"
22 class MachineFunctionInfo;
23 class MachineFrameInfo;
25 Pass *createMachineCodeConstructionPass(TargetMachine &Target);
26 Pass *createMachineCodeDestructionPass();
27 Pass *createMachineFunctionPrinterPass();
29 class MachineFunction : private Annotation {
31 const TargetMachine &Target;
33 // List of machine basic blocks in function
34 iplist<MachineBasicBlock> BasicBlocks;
36 // Keeping track of mapping from SSA values to registers
37 SSARegMap *SSARegMapping;
39 // Used to keep track of frame and constant area information for sparc be
40 MachineFunctionInfo *MFInfo;
42 // Keep track of objects allocated on the stack.
43 MachineFrameInfo *FrameInfo;
46 MachineFunction(const Function *Fn, const TargetMachine& target);
49 /// getFunction - Return the LLVM function that this machine code represents
51 const Function *getFunction() const { return Fn; }
53 /// getTarget - Return the target machine this machine code is compiled with
55 const TargetMachine &getTarget() const { return Target; }
57 /// SSARegMap Interface... Keep track of information about each SSA virtual
58 /// register, such as which register class it belongs to.
60 SSARegMap *getSSARegMap() const { return SSARegMapping; }
61 void clearSSARegMap();
63 /// getFrameInfo - Return the frame info object for the current function.
64 /// This object contains information about objects allocated on the stack
65 /// frame of the current function in an abstract way.
67 MachineFrameInfo *getFrameInfo() const { return FrameInfo; }
69 /// MachineFunctionInfo - Keep track of various per-function pieces of
70 /// information for the sparc backend.
72 MachineFunctionInfo *getInfo() const { return MFInfo; }
75 /// print - Print out the MachineFunction in a format suitable for debugging
76 /// to the specified stream.
78 void print(std::ostream &OS) const;
80 /// dump - Print the current MachineFunction to cerr, useful for debugger use.
84 // The next three methods are used to construct, destruct, and retrieve the
85 // MachineFunction object for the given method.
87 // construct() -- Allocates and initializes for a given method and target
88 // get() -- Returns a handle to the object.
89 // This should not be called before "construct()"
90 // for a given Method.
91 // destruct() -- Destroy the MachineFunction object
93 static MachineFunction& construct(const Function *Fn,
94 const TargetMachine &target);
95 static void destruct(const Function *F);
96 static MachineFunction& get(const Function *F);
98 // Provide accessors for the MachineBasicBlock list...
99 typedef iplist<MachineBasicBlock> BasicBlockListType;
100 typedef BasicBlockListType::iterator iterator;
101 typedef BasicBlockListType::const_iterator const_iterator;
102 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
103 typedef std::reverse_iterator<iterator> reverse_iterator;
105 // Provide accessors for basic blocks...
106 const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
107 BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
109 //===--------------------------------------------------------------------===//
110 // BasicBlock iterator forwarding functions
112 iterator begin() { return BasicBlocks.begin(); }
113 const_iterator begin() const { return BasicBlocks.begin(); }
114 iterator end () { return BasicBlocks.end(); }
115 const_iterator end () const { return BasicBlocks.end(); }
117 reverse_iterator rbegin() { return BasicBlocks.rbegin(); }
118 const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); }
119 reverse_iterator rend () { return BasicBlocks.rend(); }
120 const_reverse_iterator rend () const { return BasicBlocks.rend(); }
122 unsigned size() const { return BasicBlocks.size(); }
123 bool empty() const { return BasicBlocks.empty(); }
124 const MachineBasicBlock &front() const { return BasicBlocks.front(); }
125 MachineBasicBlock &front() { return BasicBlocks.front(); }
126 const MachineBasicBlock & back() const { return BasicBlocks.back(); }
127 MachineBasicBlock & back() { return BasicBlocks.back(); }