When a load operand is promoted to an extload, replace other uses with uses of extloa...
[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 #ifndef NDEBUG
79   SmallSet<const Instruction *, 8> CatchInfoLost;
80   SmallSet<const Instruction *, 8> CatchInfoFound;
81 #endif
82
83   struct LiveOutInfo {
84     unsigned NumSignBits;
85     APInt KnownOne, KnownZero;
86     LiveOutInfo() : NumSignBits(0), KnownOne(1, 0), KnownZero(1, 0) {}
87   };
88   
89   /// LiveOutRegInfo - Information about live out vregs, indexed by their
90   /// register number offset by 'FirstVirtualRegister'.
91   std::vector<LiveOutInfo> LiveOutRegInfo;
92
93   /// PHINodesToUpdate - A list of phi instructions whose operand list will
94   /// be updated after processing the current basic block.
95   /// TODO: This isn't per-function state, it's per-basic-block state. But
96   /// there's no other convenient place for it to live right now.
97   std::vector<std::pair<MachineInstr*, unsigned> > PHINodesToUpdate;
98
99   explicit FunctionLoweringInfo(const TargetLowering &TLI);
100
101   /// set - Initialize this FunctionLoweringInfo with the given Function
102   /// and its associated MachineFunction.
103   ///
104   void set(const Function &Fn, MachineFunction &MF, bool EnableFastISel);
105
106   /// clear - Clear out all the function-specific state. This returns this
107   /// FunctionLoweringInfo to an empty state, ready to be used for a
108   /// different function.
109   void clear();
110
111   unsigned MakeReg(EVT VT);
112   
113   /// isExportedInst - Return true if the specified value is an instruction
114   /// exported from its block.
115   bool isExportedInst(const Value *V) {
116     return ValueMap.count(V);
117   }
118
119   unsigned CreateRegForValue(const Value *V);
120   
121   unsigned InitializeRegForValue(const Value *V) {
122     unsigned &R = ValueMap[V];
123     assert(R == 0 && "Already initialized this value register!");
124     return R = CreateRegForValue(V);
125   }
126 };
127
128 /// AddCatchInfo - Extract the personality and type infos from an eh.selector
129 /// call, and add them to the specified machine basic block.
130 void AddCatchInfo(const CallInst &I,
131                   MachineModuleInfo *MMI, MachineBasicBlock *MBB);
132
133 /// CopyCatchInfo - Copy catch information from DestBB to SrcBB.
134 void CopyCatchInfo(const BasicBlock *SrcBB, const BasicBlock *DestBB,
135                    MachineModuleInfo *MMI, FunctionLoweringInfo &FLI);
136
137 } // end namespace llvm
138
139 #endif