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