Change EXTRACT_SUBVECTOR to require a constant index.
[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   /// ByValArgFrameIndexMap - Keep track of frame indices for byval arguments.
81   DenseMap<const Argument*, int> ByValArgFrameIndexMap;
82
83   /// ArgDbgValues - A list of DBG_VALUE instructions created during isel for
84   /// function arguments that are inserted after scheduling is completed.
85   SmallVector<MachineInstr*, 8> ArgDbgValues;
86
87   /// RegFixups - Registers which need to be replaced after isel is done.
88   DenseMap<unsigned, unsigned> RegFixups;
89
90   /// MBB - The current block.
91   MachineBasicBlock *MBB;
92
93   /// MBB - The current insert position inside the current block.
94   MachineBasicBlock::iterator InsertPt;
95
96 #ifndef NDEBUG
97   SmallSet<const Instruction *, 8> CatchInfoLost;
98   SmallSet<const Instruction *, 8> CatchInfoFound;
99 #endif
100
101   struct LiveOutInfo {
102     unsigned NumSignBits;
103     APInt KnownOne, KnownZero;
104     LiveOutInfo() : NumSignBits(0), KnownOne(1, 0), KnownZero(1, 0) {}
105   };
106   
107   /// LiveOutRegInfo - Information about live out vregs, indexed by their
108   /// register number offset by 'FirstVirtualRegister'.
109   std::vector<LiveOutInfo> LiveOutRegInfo;
110
111   /// PHINodesToUpdate - A list of phi instructions whose operand list will
112   /// be updated after processing the current basic block.
113   /// TODO: This isn't per-function state, it's per-basic-block state. But
114   /// there's no other convenient place for it to live right now.
115   std::vector<std::pair<MachineInstr*, unsigned> > PHINodesToUpdate;
116
117   explicit FunctionLoweringInfo(const TargetLowering &TLI);
118
119   /// set - Initialize this FunctionLoweringInfo with the given Function
120   /// and its associated MachineFunction.
121   ///
122   void set(const Function &Fn, MachineFunction &MF);
123
124   /// clear - Clear out all the function-specific state. This returns this
125   /// FunctionLoweringInfo to an empty state, ready to be used for a
126   /// different function.
127   void clear();
128
129   /// isExportedInst - Return true if the specified value is an instruction
130   /// exported from its block.
131   bool isExportedInst(const Value *V) {
132     return ValueMap.count(V);
133   }
134
135   unsigned CreateReg(EVT VT);
136   
137   unsigned CreateRegs(const Type *Ty);
138   
139   unsigned InitializeRegForValue(const Value *V) {
140     unsigned &R = ValueMap[V];
141     assert(R == 0 && "Already initialized this value register!");
142     return R = CreateRegs(V->getType());
143   }
144
145   /// setByValArgumentFrameIndex - Record frame index for the byval
146   /// argument.
147   void setByValArgumentFrameIndex(const Argument *A, int FI);
148   
149   /// getByValArgumentFrameIndex - Get frame index for the byval argument.
150   int getByValArgumentFrameIndex(const Argument *A);
151 };
152
153 /// AddCatchInfo - Extract the personality and type infos from an eh.selector
154 /// call, and add them to the specified machine basic block.
155 void AddCatchInfo(const CallInst &I,
156                   MachineModuleInfo *MMI, MachineBasicBlock *MBB);
157
158 /// CopyCatchInfo - Copy catch information from DestBB to SrcBB.
159 void CopyCatchInfo(const BasicBlock *SrcBB, const BasicBlock *DestBB,
160                    MachineModuleInfo *MMI, FunctionLoweringInfo &FLI);
161
162 } // end namespace llvm
163
164 #endif