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