Enable -Wcast-qual for C++ files, where intentional qualifier-stripping can
[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 <vector>
28
29 namespace llvm {
30
31 class AllocaInst;
32 class BasicBlock;
33 class CallInst;
34 class Function;
35 class GlobalVariable;
36 class Instruction;
37 class MachineBasicBlock;
38 class MachineFunction;
39 class MachineModuleInfo;
40 class MachineRegisterInfo;
41 class TargetLowering;
42 class Value;
43
44 //===--------------------------------------------------------------------===//
45 /// FunctionLoweringInfo - This contains information that is global to a
46 /// function that is used when lowering a region of the function.
47 ///
48 class FunctionLoweringInfo {
49 public:
50   const TargetLowering &TLI;
51   const Function *Fn;
52   MachineFunction *MF;
53   MachineRegisterInfo *RegInfo;
54
55   /// CanLowerReturn - true iff the function's return value can be lowered to
56   /// registers.
57   bool CanLowerReturn;
58
59   /// DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg
60   /// allocated to hold a pointer to the hidden sret parameter.
61   unsigned DemoteRegister;
62
63   /// MBBMap - A mapping from LLVM basic blocks to their machine code entry.
64   DenseMap<const BasicBlock*, MachineBasicBlock *> MBBMap;
65
66   /// ValueMap - Since we emit code for the function a basic block at a time,
67   /// we must remember which virtual registers hold the values for
68   /// cross-basic-block values.
69   DenseMap<const Value*, unsigned> ValueMap;
70
71   /// StaticAllocaMap - Keep track of frame indices for fixed sized allocas in
72   /// the entry block.  This allows the allocas to be efficiently referenced
73   /// anywhere in the function.
74   DenseMap<const AllocaInst*, int> StaticAllocaMap;
75
76 #ifndef NDEBUG
77   SmallSet<const Instruction *, 8> CatchInfoLost;
78   SmallSet<const Instruction *, 8> CatchInfoFound;
79 #endif
80
81   struct LiveOutInfo {
82     unsigned NumSignBits;
83     APInt KnownOne, KnownZero;
84     LiveOutInfo() : NumSignBits(0), KnownOne(1, 0), KnownZero(1, 0) {}
85   };
86   
87   /// LiveOutRegInfo - Information about live out vregs, indexed by their
88   /// register number offset by 'FirstVirtualRegister'.
89   std::vector<LiveOutInfo> LiveOutRegInfo;
90
91   explicit FunctionLoweringInfo(const TargetLowering &TLI);
92
93   /// set - Initialize this FunctionLoweringInfo with the given Function
94   /// and its associated MachineFunction.
95   ///
96   void set(const Function &Fn, MachineFunction &MF, bool EnableFastISel);
97
98   /// clear - Clear out all the function-specific state. This returns this
99   /// FunctionLoweringInfo to an empty state, ready to be used for a
100   /// different function.
101   void clear();
102
103   unsigned MakeReg(EVT VT);
104   
105   /// isExportedInst - Return true if the specified value is an instruction
106   /// exported from its block.
107   bool isExportedInst(const Value *V) {
108     return ValueMap.count(V);
109   }
110
111   unsigned CreateRegForValue(const Value *V);
112   
113   unsigned InitializeRegForValue(const Value *V) {
114     unsigned &R = ValueMap[V];
115     assert(R == 0 && "Already initialized this value register!");
116     return R = CreateRegForValue(V);
117   }
118 };
119
120 /// ComputeLinearIndex - Given an LLVM IR aggregate type and a sequence
121 /// of insertvalue or extractvalue indices that identify a member, return
122 /// the linearized index of the start of the member.
123 ///
124 unsigned ComputeLinearIndex(const TargetLowering &TLI, const Type *Ty,
125                             const unsigned *Indices,
126                             const unsigned *IndicesEnd,
127                             unsigned CurIndex = 0);
128
129 /// ComputeValueVTs - Given an LLVM IR type, compute a sequence of
130 /// EVTs that represent all the individual underlying
131 /// non-aggregate types that comprise it.
132 ///
133 /// If Offsets is non-null, it points to a vector to be filled in
134 /// with the in-memory offsets of each of the individual values.
135 ///
136 void ComputeValueVTs(const TargetLowering &TLI, const Type *Ty,
137                      SmallVectorImpl<EVT> &ValueVTs,
138                      SmallVectorImpl<uint64_t> *Offsets = 0,
139                      uint64_t StartingOffset = 0);
140
141 /// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
142 GlobalVariable *ExtractTypeInfo(Value *V);
143
144 /// AddCatchInfo - Extract the personality and type infos from an eh.selector
145 /// call, and add them to the specified machine basic block.
146 void AddCatchInfo(const CallInst &I,
147                   MachineModuleInfo *MMI, MachineBasicBlock *MBB);
148
149 /// CopyCatchInfo - Copy catch information from DestBB to SrcBB.
150 void CopyCatchInfo(const BasicBlock *SrcBB, const BasicBlock *DestBB,
151                    MachineModuleInfo *MMI, FunctionLoweringInfo &FLI);
152
153 /// hasInlineAsmMemConstraint - Return true if the inline asm instruction being
154 /// processed uses a memory 'm' constraint.
155 bool hasInlineAsmMemConstraint(std::vector<InlineAsm::ConstraintInfo> &CInfos,
156                                const TargetLowering &TLI);
157
158 /// getFCmpCondCode - Return the ISD condition code corresponding to
159 /// the given LLVM IR floating-point condition code.  This includes
160 /// consideration of global floating-point math flags.
161 ///
162 ISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred);
163
164 /// getICmpCondCode - Return the ISD condition code corresponding to
165 /// the given LLVM IR integer condition code.
166 ///
167 ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred);
168
169 } // end namespace llvm
170
171 #endif