LLVM  3.7.0
FunctionLoweringInfo.h
Go to the documentation of this file.
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/ADT/APInt.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/IndexedMap.h"
21 #include "llvm/ADT/Optional.h"
22 #include "llvm/ADT/SmallPtrSet.h"
23 #include "llvm/ADT/SmallVector.h"
26 #include "llvm/IR/InlineAsm.h"
27 #include "llvm/IR/Instructions.h"
29 #include <vector>
30 
31 namespace llvm {
32 
33 class AllocaInst;
34 class BasicBlock;
35 class BranchProbabilityInfo;
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 SelectionDAG;
46 class MVT;
47 class TargetLowering;
48 class Value;
49 
50 //===--------------------------------------------------------------------===//
51 /// FunctionLoweringInfo - This contains information that is global to a
52 /// function that is used when lowering a region of the function.
53 ///
55 public:
56  const Function *Fn;
61  /// CanLowerReturn - true iff the function's return value can be lowered to
62  /// registers.
64 
65  /// DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg
66  /// allocated to hold a pointer to the hidden sret parameter.
67  unsigned DemoteRegister;
68 
69  /// MBBMap - A mapping from LLVM basic blocks to their machine code entry.
71 
72  /// ValueMap - Since we emit code for the function a basic block at a time,
73  /// we must remember which virtual registers hold the values for
74  /// cross-basic-block values.
76 
77  // Keep track of frame indices allocated for statepoints as they could be used
78  // across basic block boundaries.
79  // Key of the map is statepoint instruction, value is a map from spilled
80  // llvm Value to the optional stack stack slot index.
81  // If optional is unspecified it means that we have visited this value
82  // but didn't spill it.
86 
87  /// StaticAllocaMap - Keep track of frame indices for fixed sized allocas in
88  /// the entry block. This allows the allocas to be efficiently referenced
89  /// anywhere in the function.
91 
92  /// ByValArgFrameIndexMap - Keep track of frame indices for byval arguments.
94 
95  /// ArgDbgValues - A list of DBG_VALUE instructions created during isel for
96  /// function arguments that are inserted after scheduling is completed.
98 
99  /// RegFixups - Registers which need to be replaced after isel is done.
101 
102  /// StatepointStackSlots - A list of temporary stack slots (frame indices)
103  /// used to spill values at a statepoint. We store them here to enable
104  /// reuse of the same stack slots across different statepoints in different
105  /// basic blocks.
107 
108  /// MBB - The current block.
110 
111  /// MBB - The current insert position inside the current block.
113 
114 #ifndef NDEBUG
117 #endif
118 
119  struct LiveOutInfo {
120  unsigned NumSignBits : 31;
121  bool IsValid : 1;
124  KnownZero(1, 0) {}
125  };
126 
127  /// Record the preferred extend type (ISD::SIGN_EXTEND or ISD::ZERO_EXTEND)
128  /// for a value.
130 
131  /// VisitedBBs - The set of basic blocks visited thus far by instruction
132  /// selection.
134 
135  /// PHINodesToUpdate - A list of phi instructions whose operand list will
136  /// be updated after processing the current basic block.
137  /// TODO: This isn't per-function state, it's per-basic-block state. But
138  /// there's no other convenient place for it to live right now.
139  std::vector<std::pair<MachineInstr*, unsigned> > PHINodesToUpdate;
141 
142  /// If the current MBB is a landing pad, the exception pointer and exception
143  /// selector registers are copied into these virtual registers by
144  /// SelectionDAGISel::PrepareEHLandingPad().
146 
147  /// set - Initialize this FunctionLoweringInfo with the given Function
148  /// and its associated MachineFunction.
149  ///
150  void set(const Function &Fn, MachineFunction &MF, SelectionDAG *DAG);
151 
152  /// clear - Clear out all the function-specific state. This returns this
153  /// FunctionLoweringInfo to an empty state, ready to be used for a
154  /// different function.
155  void clear();
156 
157  /// isExportedInst - Return true if the specified value is an instruction
158  /// exported from its block.
159  bool isExportedInst(const Value *V) {
160  return ValueMap.count(V);
161  }
162 
163  unsigned CreateReg(MVT VT);
164 
165  unsigned CreateRegs(Type *Ty);
166 
167  unsigned InitializeRegForValue(const Value *V) {
168  unsigned &R = ValueMap[V];
169  assert(R == 0 && "Already initialized this value register!");
170  return R = CreateRegs(V->getType());
171  }
172 
173  /// GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the
174  /// register is a PHI destination and the PHI's LiveOutInfo is not valid.
175  const LiveOutInfo *GetLiveOutRegInfo(unsigned Reg) {
176  if (!LiveOutRegInfo.inBounds(Reg))
177  return nullptr;
178 
179  const LiveOutInfo *LOI = &LiveOutRegInfo[Reg];
180  if (!LOI->IsValid)
181  return nullptr;
182 
183  return LOI;
184  }
185 
186  /// GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the
187  /// register is a PHI destination and the PHI's LiveOutInfo is not valid. If
188  /// the register's LiveOutInfo is for a smaller bit width, it is extended to
189  /// the larger bit width by zero extension. The bit width must be no smaller
190  /// than the LiveOutInfo's existing bit width.
191  const LiveOutInfo *GetLiveOutRegInfo(unsigned Reg, unsigned BitWidth);
192 
193  /// AddLiveOutRegInfo - Adds LiveOutInfo for a register.
194  void AddLiveOutRegInfo(unsigned Reg, unsigned NumSignBits,
195  const APInt &KnownZero, const APInt &KnownOne) {
196  // Only install this information if it tells us something.
197  if (NumSignBits == 1 && KnownZero == 0 && KnownOne == 0)
198  return;
199 
200  LiveOutRegInfo.grow(Reg);
201  LiveOutInfo &LOI = LiveOutRegInfo[Reg];
202  LOI.NumSignBits = NumSignBits;
203  LOI.KnownOne = KnownOne;
204  LOI.KnownZero = KnownZero;
205  }
206 
207  /// ComputePHILiveOutRegInfo - Compute LiveOutInfo for a PHI's destination
208  /// register based on the LiveOutInfo of its operands.
209  void ComputePHILiveOutRegInfo(const PHINode*);
210 
211  /// InvalidatePHILiveOutRegInfo - Invalidates a PHI's LiveOutInfo, to be
212  /// called when a block is visited before all of its predecessors.
214  // PHIs with no uses have no ValueMap entry.
216  if (It == ValueMap.end())
217  return;
218 
219  unsigned Reg = It->second;
220  if (Reg == 0)
221  return;
222 
223  LiveOutRegInfo.grow(Reg);
224  LiveOutRegInfo[Reg].IsValid = false;
225  }
226 
227  /// setArgumentFrameIndex - Record frame index for the byval
228  /// argument.
229  void setArgumentFrameIndex(const Argument *A, int FI);
230 
231  /// getArgumentFrameIndex - Get frame index for the byval argument.
232  int getArgumentFrameIndex(const Argument *A);
233 
234 private:
235  void addSEHHandlersForLPads(ArrayRef<const LandingPadInst *> LPads);
236 
237  /// LiveOutRegInfo - Information about live out vregs.
239 };
240 
241 /// ComputeUsesVAFloatArgument - Determine if any floating-point values are
242 /// being passed to this variadic function, and set the MachineModuleInfo's
243 /// usesVAFloatArgument flag if so. This flag is used to emit an undefined
244 /// reference to _fltused on Windows, which will link in MSVCRT's
245 /// floating-point support.
246 void ComputeUsesVAFloatArgument(const CallInst &I, MachineModuleInfo *MMI);
247 
248 /// AddLandingPadInfo - Extract the exception handling information from the
249 /// landingpad instruction and add them to the specified machine module info.
250 void AddLandingPadInfo(const LandingPadInst &I, MachineModuleInfo &MMI,
251  MachineBasicBlock *MBB);
252 
253 } // end namespace llvm
254 
255 #endif
LLVM Argument representation.
Definition: Argument.h:35
Various leaf nodes.
Definition: ISDOpcodes.h:60
SmallPtrSet< const Instruction *, 8 > CatchInfoFound
DenseMap< const Instruction *, StatepointSpilledValueMapTy > StatepointRelocatedValues
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: ValueMap.h:128
bool CanLowerReturn
CanLowerReturn - true iff the function's return value can be lowered to registers.
void set(const Function &Fn, MachineFunction &MF, SelectionDAG *DAG)
set - Initialize this FunctionLoweringInfo with the given Function and its associated MachineFunction...
unsigned DemoteRegister
DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg allocated to hold a pointer to ...
void AddLiveOutRegInfo(unsigned Reg, unsigned NumSignBits, const APInt &KnownZero, const APInt &KnownOne)
AddLiveOutRegInfo - Adds LiveOutInfo for a register.
Reg
All possible values of the reg field in the ModR/M byte.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
This file implements a class to represent arbitrary precision integral constant values and operations...
int getArgumentFrameIndex(const Argument *A)
getArgumentFrameIndex - Get frame index for the byval argument.
DenseMap< const Value *, Optional< int > > StatepointSpilledValueMapTy
const LiveOutInfo * GetLiveOutRegInfo(unsigned Reg)
GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the register is a PHI destinat...
iterator find(const KeyT &Val)
Definition: ValueMap.h:132
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:31
void AddLandingPadInfo(const LandingPadInst &I, MachineModuleInfo &MMI, MachineBasicBlock *MBB)
AddLandingPadInfo - Extract the exception handling information from the landingpad instruction and ad...
void clear()
clear - Clear out all the function-specific state.
bundle_iterator< MachineInstr, instr_iterator > iterator
SmallPtrSet< const Instruction *, 8 > CatchInfoLost
#define true
Definition: ConvertUTF.c:66
std::vector< std::pair< MachineInstr *, unsigned > > PHINodesToUpdate
PHINodesToUpdate - A list of phi instructions whose operand list will be updated after processing the...
MVT - Machine Value Type.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
unsigned ExceptionPointerVirtReg
If the current MBB is a landing pad, the exception pointer and exception selector registers are copie...
SmallPtrSet< const BasicBlock *, 4 > VisitedBBs
VisitedBBs - The set of basic blocks visited thus far by instruction selection.
void ComputePHILiveOutRegInfo(const PHINode *)
ComputePHILiveOutRegInfo - Compute LiveOutInfo for a PHI's destination register based on the LiveOutI...
MachineBasicBlock * MBB
MBB - The current block.
SmallVector< unsigned, 50 > StatepointStackSlots
StatepointStackSlots - A list of temporary stack slots (frame indices) used to spill values at a stat...
iterator end()
Definition: ValueMap.h:112
See the file comment.
Definition: ValueMap.h:80
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:299
DenseMap< unsigned, unsigned > RegFixups
RegFixups - Registers which need to be replaced after isel is done.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:179
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
SmallVector< MachineInstr *, 8 > ArgDbgValues
ArgDbgValues - A list of DBG_VALUE instructions created during isel for function arguments that are i...
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:222
unsigned CreateRegs(Type *Ty)
CreateRegs - Allocate the appropriate number of virtual registers of the correctly promoted or expand...
Class for arbitrary precision integers.
Definition: APInt.h:73
BranchProbabilityInfo * BPI
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
DenseMap< const Value *, ISD::NodeType > PreferredExtendType
Record the preferred extend type (ISD::SIGN_EXTEND or ISD::ZERO_EXTEND) for a value.
Analysis pass providing branch probability information.
MachineRegisterInfo * RegInfo
DenseMap< const Argument *, int > ByValArgFrameIndexMap
ByValArgFrameIndexMap - Keep track of frame indices for byval arguments.
#define I(x, y, z)
Definition: MD5.cpp:54
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
MachineBasicBlock::iterator InsertPt
MBB - The current insert position inside the current block.
unsigned CreateReg(MVT VT)
CreateReg - Allocate a single virtual register for the given type.
DenseMap< const AllocaInst *, int > StaticAllocaMap
StaticAllocaMap - Keep track of frame indices for fixed sized allocas in the entry block...
void InvalidatePHILiveOutRegInfo(const PHINode *PN)
InvalidatePHILiveOutRegInfo - Invalidates a PHI's LiveOutInfo, to be called when a block is visited b...
LLVM Value Representation.
Definition: Value.h:69
DenseMap< const BasicBlock *, MachineBasicBlock * > MBBMap
MBBMap - A mapping from LLVM basic blocks to their machine code entry.
const TargetLowering * TLI
void setArgumentFrameIndex(const Argument *A, int FI)
setArgumentFrameIndex - Record frame index for the byval argument.
void ComputeUsesVAFloatArgument(const CallInst &I, MachineModuleInfo *MMI)
ComputeUsesVAFloatArgument - Determine if any floating-point values are being passed to this variadic...
DenseMap< const Value *, unsigned > ValueMap
ValueMap - Since we emit code for the function a basic block at a time, we must remember which virtua...
bool isExportedInst(const Value *V)
isExportedInst - Return true if the specified value is an instruction exported from its block...
unsigned InitializeRegForValue(const Value *V)