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 FUNCTIONLOWERINGINFO_H
16 #define FUNCTIONLOWERINGINFO_H
18 #include "llvm/ADT/APInt.h"
19 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/SmallSet.h"
23 #include "llvm/CodeGen/ValueTypes.h"
34 class MachineBasicBlock;
35 class MachineFunction;
36 class MachineModuleInfo;
37 class MachineRegisterInfo;
41 //===--------------------------------------------------------------------===//
42 /// FunctionLoweringInfo - This contains information that is global to a
43 /// function that is used when lowering a region of the function.
45 class FunctionLoweringInfo {
50 MachineRegisterInfo *RegInfo;
52 /// CanLowerReturn - true iff the function's return value can be lowered to
56 /// DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg
57 /// allocated to hold a pointer to the hidden sret parameter.
58 unsigned DemoteRegister;
60 explicit FunctionLoweringInfo(TargetLowering &TLI);
62 /// set - Initialize this FunctionLoweringInfo with the given Function
63 /// and its associated MachineFunction.
65 void set(Function &Fn, MachineFunction &MF, bool EnableFastISel);
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;
81 SmallSet<Instruction*, 8> CatchInfoLost;
82 SmallSet<Instruction*, 8> CatchInfoFound;
85 unsigned MakeReg(EVT VT);
87 /// isExportedInst - Return true if the specified value is an instruction
88 /// exported from its block.
89 bool isExportedInst(const Value *V) {
90 return ValueMap.count(V);
93 unsigned CreateRegForValue(const Value *V);
95 unsigned InitializeRegForValue(const Value *V) {
96 unsigned &R = ValueMap[V];
97 assert(R == 0 && "Already initialized this value register!");
98 return R = CreateRegForValue(V);
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 /// clear - Clear out all the function-specific state. This returns this
112 /// FunctionLoweringInfo to an empty state, ready to be used for a
113 /// different function.
117 /// ComputeLinearIndex - Given an LLVM IR aggregate type and a sequence
118 /// of insertvalue or extractvalue indices that identify a member, return
119 /// the linearized index of the start of the member.
121 unsigned ComputeLinearIndex(const TargetLowering &TLI, const Type *Ty,
122 const unsigned *Indices,
123 const unsigned *IndicesEnd,
124 unsigned CurIndex = 0);
126 /// ComputeValueVTs - Given an LLVM IR type, compute a sequence of
127 /// EVTs that represent all the individual underlying
128 /// non-aggregate types that comprise it.
130 /// If Offsets is non-null, it points to a vector to be filled in
131 /// with the in-memory offsets of each of the individual values.
133 void ComputeValueVTs(const TargetLowering &TLI, const Type *Ty,
134 SmallVectorImpl<EVT> &ValueVTs,
135 SmallVectorImpl<uint64_t> *Offsets = 0,
136 uint64_t StartingOffset = 0);
138 /// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
139 GlobalVariable *ExtractTypeInfo(Value *V);
141 /// AddCatchInfo - Extract the personality and type infos from an eh.selector
142 /// call, and add them to the specified machine basic block.
143 void AddCatchInfo(CallInst &I, MachineModuleInfo *MMI, MachineBasicBlock *MBB);
145 /// CopyCatchInfo - Copy catch information from DestBB to SrcBB.
146 void CopyCatchInfo(BasicBlock *SrcBB, BasicBlock *DestBB,
147 MachineModuleInfo *MMI, FunctionLoweringInfo &FLI);
149 } // end namespace llvm