1 //===-- FunctionLoweringInfo.h - Lower functions from LLVM IR to CodeGen --===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This implements routines for translating functions from LLVM IR into
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CODEGEN_FUNCTIONLOWERINGINFO_H
16 #define LLVM_CODEGEN_FUNCTIONLOWERINGINFO_H
18 #include "llvm/InlineAsm.h"
19 #include "llvm/Instructions.h"
20 #include "llvm/ADT/APInt.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/IndexedMap.h"
23 #include "llvm/ADT/SmallVector.h"
25 #include "llvm/ADT/SmallSet.h"
27 #include "llvm/CodeGen/ValueTypes.h"
28 #include "llvm/CodeGen/ISDOpcodes.h"
29 #include "llvm/CodeGen/MachineBasicBlock.h"
30 #include "llvm/Support/CallSite.h"
31 #include "llvm/Target/TargetRegisterInfo.h"
43 class MachineBasicBlock;
44 class MachineFunction;
45 class MachineModuleInfo;
46 class MachineRegisterInfo;
50 //===--------------------------------------------------------------------===//
51 /// FunctionLoweringInfo - This contains information that is global to a
52 /// function that is used when lowering a region of the function.
54 class FunctionLoweringInfo {
56 const TargetLowering &TLI;
59 MachineRegisterInfo *RegInfo;
61 /// CanLowerReturn - true iff the function's return value can be lowered to
65 /// DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg
66 /// allocated to hold a pointer to the hidden sret parameter.
67 unsigned DemoteRegister;
69 /// MBBMap - A mapping from LLVM basic blocks to their machine code entry.
70 DenseMap<const BasicBlock*, MachineBasicBlock *> MBBMap;
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.
75 DenseMap<const Value*, unsigned> ValueMap;
77 /// StaticAllocaMap - Keep track of frame indices for fixed sized allocas in
78 /// the entry block. This allows the allocas to be efficiently referenced
79 /// anywhere in the function.
80 DenseMap<const AllocaInst*, int> StaticAllocaMap;
82 /// ByValArgFrameIndexMap - Keep track of frame indices for byval arguments.
83 DenseMap<const Argument*, int> ByValArgFrameIndexMap;
85 /// ArgDbgValues - A list of DBG_VALUE instructions created during isel for
86 /// function arguments that are inserted after scheduling is completed.
87 SmallVector<MachineInstr*, 8> ArgDbgValues;
89 /// RegFixups - Registers which need to be replaced after isel is done.
90 DenseMap<unsigned, unsigned> RegFixups;
92 /// MBB - The current block.
93 MachineBasicBlock *MBB;
95 /// MBB - The current insert position inside the current block.
96 MachineBasicBlock::iterator InsertPt;
99 SmallSet<const Instruction *, 8> CatchInfoLost;
100 SmallSet<const Instruction *, 8> CatchInfoFound;
104 unsigned NumSignBits : 31;
106 APInt KnownOne, KnownZero;
107 LiveOutInfo() : NumSignBits(0), IsValid(false), KnownOne(1, 0),
111 /// LiveOutRegInfo - Information about live out vregs.
112 IndexedMap<LiveOutInfo, VirtReg2IndexFunctor> LiveOutRegInfo;
114 /// VisitedBBs - Basic blocks that have been visited by reverse postorder.
115 DenseSet<const BasicBlock*> VisitedBBs;
117 /// AllPredsVisited - Tracks whether all predecessors of the current basic
118 /// block have already been visited.
119 bool AllPredsVisited;
121 /// PHIDestRegs - Virtual registers that are the destinations of PHIs.
122 DenseSet<unsigned> PHIDestRegs;
124 /// PHISrcToDestMap - Maps the virtual register defining a PHI's source to the
125 /// virtual register defining its destination.
126 DenseMap<unsigned, unsigned> PHISrcToDestMap;
128 /// PHINodesToUpdate - A list of phi instructions whose operand list will
129 /// be updated after processing the current basic block.
130 /// TODO: This isn't per-function state, it's per-basic-block state. But
131 /// there's no other convenient place for it to live right now.
132 std::vector<std::pair<MachineInstr*, unsigned> > PHINodesToUpdate;
134 explicit FunctionLoweringInfo(const TargetLowering &TLI);
136 /// set - Initialize this FunctionLoweringInfo with the given Function
137 /// and its associated MachineFunction.
139 void set(const Function &Fn, MachineFunction &MF);
141 /// clear - Clear out all the function-specific state. This returns this
142 /// FunctionLoweringInfo to an empty state, ready to be used for a
143 /// different function.
146 /// isExportedInst - Return true if the specified value is an instruction
147 /// exported from its block.
148 bool isExportedInst(const Value *V) {
149 return ValueMap.count(V);
152 unsigned CreateReg(EVT VT);
154 unsigned CreateRegs(const Type *Ty);
156 unsigned InitializeRegForValue(const Value *V) {
157 unsigned &R = ValueMap[V];
158 assert(R == 0 && "Already initialized this value register!");
159 return R = CreateRegs(V->getType());
162 /// setByValArgumentFrameIndex - Record frame index for the byval
164 void setByValArgumentFrameIndex(const Argument *A, int FI);
166 /// getByValArgumentFrameIndex - Get frame index for the byval argument.
167 int getByValArgumentFrameIndex(const Argument *A);
170 /// AddCatchInfo - Extract the personality and type infos from an eh.selector
171 /// call, and add them to the specified machine basic block.
172 void AddCatchInfo(const CallInst &I,
173 MachineModuleInfo *MMI, MachineBasicBlock *MBB);
175 /// CopyCatchInfo - Copy catch information from DestBB to SrcBB.
176 void CopyCatchInfo(const BasicBlock *SrcBB, const BasicBlock *DestBB,
177 MachineModuleInfo *MMI, FunctionLoweringInfo &FLI);
179 } // end namespace llvm