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"
31 class MachineFunctionInfo;
32 class MachineFrameInfo;
33 class MachineConstantPool;
35 FunctionPass *createMachineCodeConstructionPass(TargetMachine &TM);
36 FunctionPass *createMachineCodeDestructionPass();
37 FunctionPass *createMachineFunctionPrinterPass();
39 class MachineFunction : private Annotation {
41 const TargetMachine &Target;
43 // List of machine basic blocks in function
44 iplist<MachineBasicBlock> BasicBlocks;
46 // Keeping track of mapping from SSA values to registers
47 SSARegMap *SSARegMapping;
49 // Used to keep track of frame and constant area information for sparc be
50 MachineFunctionInfo *MFInfo;
52 // Keep track of objects allocated on the stack.
53 MachineFrameInfo *FrameInfo;
55 // Keep track of constants which are spilled to memory
56 MachineConstantPool *ConstantPool;
59 MachineFunction(const Function *Fn, const TargetMachine &TM);
62 /// getFunction - Return the LLVM function that this machine code represents
64 const Function *getFunction() const { return Fn; }
66 /// getTarget - Return the target machine this machine code is compiled with
68 const TargetMachine &getTarget() const { return Target; }
70 /// SSARegMap Interface... Keep track of information about each SSA virtual
71 /// register, such as which register class it belongs to.
73 SSARegMap *getSSARegMap() const { return SSARegMapping; }
74 void clearSSARegMap();
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.
80 MachineFrameInfo *getFrameInfo() const { return FrameInfo; }
82 /// getConstantPool - Return the constant pool object for the current
84 MachineConstantPool *getConstantPool() const { return ConstantPool; }
86 /// MachineFunctionInfo - Keep track of various per-function pieces of
87 /// information for the sparc backend.
89 MachineFunctionInfo *getInfo() const { return MFInfo; }
92 /// print - Print out the MachineFunction in a format suitable for debugging
93 /// to the specified stream.
95 void print(std::ostream &OS) const;
97 /// dump - Print the current MachineFunction to cerr, useful for debugger use.
101 // The next three methods are used to construct, destruct, and retrieve the
102 // MachineFunction object for the given method.
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
110 static MachineFunction& construct(const Function *F, const TargetMachine &TM);
111 static void destruct(const Function *F);
112 static MachineFunction& get(const Function *F);
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;
121 // Provide accessors for basic blocks...
122 const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
123 BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
125 //===--------------------------------------------------------------------===//
126 // BasicBlock iterator forwarding functions
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(); }
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(); }
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(); }
146 } // End llvm namespace