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/SmallVector.h"
24 #include "llvm/ADT/SmallSet.h"
26 #include "llvm/CodeGen/ValueTypes.h"
27 #include "llvm/CodeGen/ISDOpcodes.h"
28 #include "llvm/CodeGen/MachineBasicBlock.h"
29 #include "llvm/Support/CallSite.h"
41 class MachineBasicBlock;
42 class MachineFunction;
43 class MachineModuleInfo;
44 class MachineRegisterInfo;
48 //===--------------------------------------------------------------------===//
49 /// FunctionLoweringInfo - This contains information that is global to a
50 /// function that is used when lowering a region of the function.
52 class FunctionLoweringInfo {
54 const TargetLowering &TLI;
57 MachineRegisterInfo *RegInfo;
59 /// CanLowerReturn - true iff the function's return value can be lowered to
63 /// DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg
64 /// allocated to hold a pointer to the hidden sret parameter.
65 unsigned DemoteRegister;
67 /// MBBMap - A mapping from LLVM basic blocks to their machine code entry.
68 DenseMap<const BasicBlock*, MachineBasicBlock *> MBBMap;
70 /// ValueMap - Since we emit code for the function a basic block at a time,
71 /// we must remember which virtual registers hold the values for
72 /// cross-basic-block values.
73 DenseMap<const Value*, unsigned> ValueMap;
75 /// StaticAllocaMap - Keep track of frame indices for fixed sized allocas in
76 /// the entry block. This allows the allocas to be efficiently referenced
77 /// anywhere in the function.
78 DenseMap<const AllocaInst*, int> StaticAllocaMap;
80 /// ByValArgFrameIndexMap - Keep track of frame indices for byval arguments.
81 DenseMap<const Argument*, int> ByValArgFrameIndexMap;
83 /// ArgDbgValues - A list of DBG_VALUE instructions created during isel for
84 /// function arguments that are inserted after scheduling is completed.
85 SmallVector<MachineInstr*, 8> ArgDbgValues;
87 /// RegFixups - Registers which need to be replaced after isel is done.
88 DenseMap<unsigned, unsigned> RegFixups;
90 /// MBB - The current block.
91 MachineBasicBlock *MBB;
93 /// MBB - The current insert position inside the current block.
94 MachineBasicBlock::iterator InsertPt;
97 SmallSet<const Instruction *, 8> CatchInfoLost;
98 SmallSet<const Instruction *, 8> CatchInfoFound;
102 unsigned NumSignBits;
103 APInt KnownOne, KnownZero;
104 LiveOutInfo() : NumSignBits(0), KnownOne(1, 0), KnownZero(1, 0) {}
107 /// LiveOutRegInfo - Information about live out vregs, indexed by their
108 /// register number offset by 'FirstVirtualRegister'.
109 std::vector<LiveOutInfo> LiveOutRegInfo;
111 /// PHINodesToUpdate - A list of phi instructions whose operand list will
112 /// be updated after processing the current basic block.
113 /// TODO: This isn't per-function state, it's per-basic-block state. But
114 /// there's no other convenient place for it to live right now.
115 std::vector<std::pair<MachineInstr*, unsigned> > PHINodesToUpdate;
117 explicit FunctionLoweringInfo(const TargetLowering &TLI);
119 /// set - Initialize this FunctionLoweringInfo with the given Function
120 /// and its associated MachineFunction.
122 void set(const Function &Fn, MachineFunction &MF);
124 /// clear - Clear out all the function-specific state. This returns this
125 /// FunctionLoweringInfo to an empty state, ready to be used for a
126 /// different function.
129 /// isExportedInst - Return true if the specified value is an instruction
130 /// exported from its block.
131 bool isExportedInst(const Value *V) {
132 return ValueMap.count(V);
135 unsigned CreateReg(EVT VT);
137 unsigned CreateRegs(const Type *Ty);
139 unsigned InitializeRegForValue(const Value *V) {
140 unsigned &R = ValueMap[V];
141 assert(R == 0 && "Already initialized this value register!");
142 return R = CreateRegs(V->getType());
145 /// setByValArgumentFrameIndex - Record frame index for the byval
147 void setByValArgumentFrameIndex(const Argument *A, int FI);
149 /// getByValArgumentFrameIndex - Get frame index for the byval argument.
150 int getByValArgumentFrameIndex(const Argument *A);
153 /// AddCatchInfo - Extract the personality and type infos from an eh.selector
154 /// call, and add them to the specified machine basic block.
155 void AddCatchInfo(const CallInst &I,
156 MachineModuleInfo *MMI, MachineBasicBlock *MBB);
158 /// CopyCatchInfo - Copy catch information from DestBB to SrcBB.
159 void CopyCatchInfo(const BasicBlock *SrcBB, const BasicBlock *DestBB,
160 MachineModuleInfo *MMI, FunctionLoweringInfo &FLI);
162 } // end namespace llvm