1 //===-- llvm/CodeGen/MachineFunction.h --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // Collect native machine code for a function. This class contains a list of
11 // MachineBasicBlock instances that make up the current compiled function.
13 // This class also contains pointers to various classes which hold
14 // target-specific information about the generated code.
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_CODEGEN_MACHINEFUNCTION_H
19 #define LLVM_CODEGEN_MACHINEFUNCTION_H
21 #include "llvm/CodeGen/MachineBasicBlock.h"
22 #include "Support/Annotation.h"
23 #include "Support/ilist"
30 class MachineFunctionInfo;
31 class MachineFrameInfo;
32 class MachineConstantPool;
34 class MachineFunction : private Annotation {
36 const TargetMachine &Target;
38 // List of machine basic blocks in function
39 iplist<MachineBasicBlock> BasicBlocks;
41 // Keeping track of mapping from SSA values to registers
42 SSARegMap *SSARegMapping;
44 // Used to keep track of frame and constant area information for sparc be
45 MachineFunctionInfo *MFInfo;
47 // Keep track of objects allocated on the stack.
48 MachineFrameInfo *FrameInfo;
50 // Keep track of constants which are spilled to memory
51 MachineConstantPool *ConstantPool;
54 MachineFunction(const Function *Fn, const TargetMachine &TM);
57 /// getFunction - Return the LLVM function that this machine code represents
59 const Function *getFunction() const { return Fn; }
61 /// getTarget - Return the target machine this machine code is compiled with
63 const TargetMachine &getTarget() const { return Target; }
65 /// SSARegMap Interface... Keep track of information about each SSA virtual
66 /// register, such as which register class it belongs to.
68 SSARegMap *getSSARegMap() const { return SSARegMapping; }
69 void clearSSARegMap();
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.
75 MachineFrameInfo *getFrameInfo() const { return FrameInfo; }
77 /// getConstantPool - Return the constant pool object for the current
79 MachineConstantPool *getConstantPool() const { return ConstantPool; }
81 /// MachineFunctionInfo - Keep track of various per-function pieces of
82 /// information for the sparc backend.
84 MachineFunctionInfo *getInfo() const { return MFInfo; }
87 /// print - Print out the MachineFunction in a format suitable for debugging
88 /// to the specified stream.
90 void print(std::ostream &OS) const;
92 /// dump - Print the current MachineFunction to cerr, useful for debugger use.
96 // The next three methods are used to construct, destruct, and retrieve the
97 // MachineFunction object for the given method.
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.
104 static MachineFunction& construct(const Function *F, const TargetMachine &TM);
105 static void destruct(const Function *F);
106 static MachineFunction& get(const Function *F);
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;
115 // Provide accessors for basic blocks...
116 const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
117 BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
119 //===--------------------------------------------------------------------===//
120 // BasicBlock iterator forwarding functions
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(); }
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(); }
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(); }
140 } // End llvm namespace