Move the FunctionLoweringInfo class and some related utility functions out
[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/ADT/APInt.h"
19 #include "llvm/ADT/DenseMap.h"
20 #ifndef NDEBUG
21 #include "llvm/ADT/SmallSet.h"
22 #endif
23 #include "llvm/CodeGen/ValueTypes.h"
24 #include <vector>
25
26 namespace llvm {
27
28 class AllocaInst;
29 class BasicBlock;
30 class Function;
31 class Instruction;
32 class MachineBasicBlock;
33 class MachineFunction;
34 class MachineRegisterInfo;
35 class TargetLowering;
36 class Value;
37
38 //===--------------------------------------------------------------------===//
39 /// FunctionLoweringInfo - This contains information that is global to a
40 /// function that is used when lowering a region of the function.
41 ///
42 class FunctionLoweringInfo {
43 public:
44   TargetLowering &TLI;
45   Function *Fn;
46   MachineFunction *MF;
47   MachineRegisterInfo *RegInfo;
48
49   /// CanLowerReturn - true iff the function's return value can be lowered to
50   /// registers.
51   bool CanLowerReturn;
52
53   /// DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg
54   /// allocated to hold a pointer to the hidden sret parameter.
55   unsigned DemoteRegister;
56
57   explicit FunctionLoweringInfo(TargetLowering &TLI);
58
59   /// set - Initialize this FunctionLoweringInfo with the given Function
60   /// and its associated MachineFunction.
61   ///
62   void set(Function &Fn, MachineFunction &MF, bool EnableFastISel);
63
64   /// MBBMap - A mapping from LLVM basic blocks to their machine code entry.
65   DenseMap<const BasicBlock*, MachineBasicBlock *> MBBMap;
66
67   /// ValueMap - Since we emit code for the function a basic block at a time,
68   /// we must remember which virtual registers hold the values for
69   /// cross-basic-block values.
70   DenseMap<const Value*, unsigned> ValueMap;
71
72   /// StaticAllocaMap - Keep track of frame indices for fixed sized allocas in
73   /// the entry block.  This allows the allocas to be efficiently referenced
74   /// anywhere in the function.
75   DenseMap<const AllocaInst*, int> StaticAllocaMap;
76
77 #ifndef NDEBUG
78   SmallSet<Instruction*, 8> CatchInfoLost;
79   SmallSet<Instruction*, 8> CatchInfoFound;
80 #endif
81
82   unsigned MakeReg(EVT VT);
83   
84   /// isExportedInst - Return true if the specified value is an instruction
85   /// exported from its block.
86   bool isExportedInst(const Value *V) {
87     return ValueMap.count(V);
88   }
89
90   unsigned CreateRegForValue(const Value *V);
91   
92   unsigned InitializeRegForValue(const Value *V) {
93     unsigned &R = ValueMap[V];
94     assert(R == 0 && "Already initialized this value register!");
95     return R = CreateRegForValue(V);
96   }
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   /// 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
114 /// ComputeLinearIndex - Given an LLVM IR aggregate type and a sequence
115 /// of insertvalue or extractvalue indices that identify a member, return
116 /// the linearized index of the start of the member.
117 ///
118 unsigned ComputeLinearIndex(const TargetLowering &TLI, const Type *Ty,
119                             const unsigned *Indices,
120                             const unsigned *IndicesEnd,
121                             unsigned CurIndex = 0);
122
123 /// ComputeValueVTs - Given an LLVM IR type, compute a sequence of
124 /// EVTs that represent all the individual underlying
125 /// non-aggregate types that comprise it.
126 ///
127 /// If Offsets is non-null, it points to a vector to be filled in
128 /// with the in-memory offsets of each of the individual values.
129 ///
130 void ComputeValueVTs(const TargetLowering &TLI, const Type *Ty,
131                      SmallVectorImpl<EVT> &ValueVTs,
132                      SmallVectorImpl<uint64_t> *Offsets = 0,
133                      uint64_t StartingOffset = 0);
134
135 } // end namespace llvm
136
137 #endif