Move FunctionLoweringInfo.h out into include/llvm/CodeGen. This will
[oota-llvm.git] / include / llvm / CodeGen / FunctionLoweringInfo.h
1 //===-- FunctionLoweringInfo.h - Lower functions from LLVM IR to CodeGen --===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This implements routines for translating functions from LLVM IR into
11 // Machine IR.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CODEGEN_FUNCTIONLOWERINGINFO_H
16 #define LLVM_CODEGEN_FUNCTIONLOWERINGINFO_H
17
18 #include "llvm/InlineAsm.h"
19 #include "llvm/Instructions.h"
20 #include "llvm/ADT/APInt.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/SmallVector.h"
23 #ifndef NDEBUG
24 #include "llvm/ADT/SmallSet.h"
25 #endif
26 #include "llvm/CodeGen/ValueTypes.h"
27 #include "llvm/CodeGen/ISDOpcodes.h"
28 #include "llvm/Support/CallSite.h"
29 #include <vector>
30
31 namespace llvm {
32
33 class AllocaInst;
34 class BasicBlock;
35 class CallInst;
36 class Function;
37 class GlobalVariable;
38 class Instruction;
39 class MachineInstr;
40 class MachineBasicBlock;
41 class MachineFunction;
42 class MachineModuleInfo;
43 class MachineRegisterInfo;
44 class TargetLowering;
45 class Value;
46
47 //===--------------------------------------------------------------------===//
48 /// FunctionLoweringInfo - This contains information that is global to a
49 /// function that is used when lowering a region of the function.
50 ///
51 class FunctionLoweringInfo {
52 public:
53   const TargetLowering &TLI;
54   const Function *Fn;
55   MachineFunction *MF;
56   MachineRegisterInfo *RegInfo;
57
58   /// CanLowerReturn - true iff the function's return value can be lowered to
59   /// registers.
60   bool CanLowerReturn;
61
62   /// DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg
63   /// allocated to hold a pointer to the hidden sret parameter.
64   unsigned DemoteRegister;
65
66   /// MBBMap - A mapping from LLVM basic blocks to their machine code entry.
67   DenseMap<const BasicBlock*, MachineBasicBlock *> MBBMap;
68
69   /// ValueMap - Since we emit code for the function a basic block at a time,
70   /// we must remember which virtual registers hold the values for
71   /// cross-basic-block values.
72   DenseMap<const Value*, unsigned> ValueMap;
73
74   /// StaticAllocaMap - Keep track of frame indices for fixed sized allocas in
75   /// the entry block.  This allows the allocas to be efficiently referenced
76   /// anywhere in the function.
77   DenseMap<const AllocaInst*, int> StaticAllocaMap;
78
79   /// ArgDbgValues - A list of DBG_VALUE instructions created during isel for
80   /// function arguments that are inserted after scheduling is completed.
81   SmallVector<MachineInstr*, 8> ArgDbgValues;
82
83 #ifndef NDEBUG
84   SmallSet<const Instruction *, 8> CatchInfoLost;
85   SmallSet<const Instruction *, 8> CatchInfoFound;
86 #endif
87
88   struct LiveOutInfo {
89     unsigned NumSignBits;
90     APInt KnownOne, KnownZero;
91     LiveOutInfo() : NumSignBits(0), KnownOne(1, 0), KnownZero(1, 0) {}
92   };
93   
94   /// LiveOutRegInfo - Information about live out vregs, indexed by their
95   /// register number offset by 'FirstVirtualRegister'.
96   std::vector<LiveOutInfo> LiveOutRegInfo;
97
98   /// PHINodesToUpdate - A list of phi instructions whose operand list will
99   /// be updated after processing the current basic block.
100   /// TODO: This isn't per-function state, it's per-basic-block state. But
101   /// there's no other convenient place for it to live right now.
102   std::vector<std::pair<MachineInstr*, unsigned> > PHINodesToUpdate;
103
104   explicit FunctionLoweringInfo(const TargetLowering &TLI);
105
106   /// set - Initialize this FunctionLoweringInfo with the given Function
107   /// and its associated MachineFunction.
108   ///
109   void set(const Function &Fn, MachineFunction &MF);
110
111   /// clear - Clear out all the function-specific state. This returns this
112   /// FunctionLoweringInfo to an empty state, ready to be used for a
113   /// different function.
114   void clear();
115
116   /// isExportedInst - Return true if the specified value is an instruction
117   /// exported from its block.
118   bool isExportedInst(const Value *V) {
119     return ValueMap.count(V);
120   }
121
122   unsigned CreateReg(EVT VT);
123   
124   unsigned CreateRegs(const Type *Ty);
125   
126   unsigned InitializeRegForValue(const Value *V) {
127     unsigned &R = ValueMap[V];
128     assert(R == 0 && "Already initialized this value register!");
129     return R = CreateRegs(V->getType());
130   }
131 };
132
133 /// AddCatchInfo - Extract the personality and type infos from an eh.selector
134 /// call, and add them to the specified machine basic block.
135 void AddCatchInfo(const CallInst &I,
136                   MachineModuleInfo *MMI, MachineBasicBlock *MBB);
137
138 /// CopyCatchInfo - Copy catch information from DestBB to SrcBB.
139 void CopyCatchInfo(const BasicBlock *SrcBB, const BasicBlock *DestBB,
140                    MachineModuleInfo *MMI, FunctionLoweringInfo &FLI);
141
142 } // end namespace llvm
143
144 #endif