blob: dfbcef9e97f9a8e55067e709a036d32c32f5ba22 [file] [log] [blame]
Dan Gohman6277eb22009-11-23 17:16:22 +00001//===-- 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
Dan Gohmanfe85e762010-04-14 18:31:02 +000018#include "llvm/InlineAsm.h"
19#include "llvm/Instructions.h"
Dan Gohman6277eb22009-11-23 17:16:22 +000020#include "llvm/ADT/APInt.h"
21#include "llvm/ADT/DenseMap.h"
22#ifndef NDEBUG
23#include "llvm/ADT/SmallSet.h"
24#endif
25#include "llvm/CodeGen/ValueTypes.h"
Dan Gohman11609452010-04-14 18:49:17 +000026#include "llvm/CodeGen/ISDOpcodes.h"
Dan Gohman6277eb22009-11-23 17:16:22 +000027#include <vector>
28
29namespace llvm {
30
31class AllocaInst;
32class BasicBlock;
Dan Gohman66336ed2009-11-23 17:42:46 +000033class CallInst;
Dan Gohman6277eb22009-11-23 17:16:22 +000034class Function;
Dan Gohman66336ed2009-11-23 17:42:46 +000035class GlobalVariable;
Dan Gohman6277eb22009-11-23 17:16:22 +000036class Instruction;
37class MachineBasicBlock;
38class MachineFunction;
Dan Gohman66336ed2009-11-23 17:42:46 +000039class MachineModuleInfo;
Dan Gohman6277eb22009-11-23 17:16:22 +000040class MachineRegisterInfo;
41class TargetLowering;
42class Value;
43
44//===--------------------------------------------------------------------===//
45/// FunctionLoweringInfo - This contains information that is global to a
46/// function that is used when lowering a region of the function.
47///
48class FunctionLoweringInfo {
49public:
50 TargetLowering &TLI;
Dan Gohmanae541aa2010-04-15 04:33:49 +000051 const Function *Fn;
Dan Gohman6277eb22009-11-23 17:16:22 +000052 MachineFunction *MF;
53 MachineRegisterInfo *RegInfo;
54
55 /// CanLowerReturn - true iff the function's return value can be lowered to
56 /// registers.
57 bool CanLowerReturn;
58
59 /// DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg
60 /// allocated to hold a pointer to the hidden sret parameter.
61 unsigned DemoteRegister;
62
Dan Gohman6277eb22009-11-23 17:16:22 +000063 /// MBBMap - A mapping from LLVM basic blocks to their machine code entry.
64 DenseMap<const BasicBlock*, MachineBasicBlock *> MBBMap;
65
66 /// ValueMap - Since we emit code for the function a basic block at a time,
67 /// we must remember which virtual registers hold the values for
68 /// cross-basic-block values.
69 DenseMap<const Value*, unsigned> ValueMap;
70
71 /// StaticAllocaMap - Keep track of frame indices for fixed sized allocas in
72 /// the entry block. This allows the allocas to be efficiently referenced
73 /// anywhere in the function.
74 DenseMap<const AllocaInst*, int> StaticAllocaMap;
75
76#ifndef NDEBUG
Dan Gohman25208642010-04-14 19:53:31 +000077 SmallSet<const Instruction *, 8> CatchInfoLost;
78 SmallSet<const Instruction *, 8> CatchInfoFound;
Dan Gohman6277eb22009-11-23 17:16:22 +000079#endif
80
Dan Gohmanb4be71e2010-04-14 02:09:45 +000081 struct LiveOutInfo {
82 unsigned NumSignBits;
83 APInt KnownOne, KnownZero;
84 LiveOutInfo() : NumSignBits(0), KnownOne(1, 0), KnownZero(1, 0) {}
85 };
86
87 /// LiveOutRegInfo - Information about live out vregs, indexed by their
88 /// register number offset by 'FirstVirtualRegister'.
89 std::vector<LiveOutInfo> LiveOutRegInfo;
90
91 explicit FunctionLoweringInfo(TargetLowering &TLI);
92
93 /// set - Initialize this FunctionLoweringInfo with the given Function
94 /// and its associated MachineFunction.
95 ///
Dan Gohmanae541aa2010-04-15 04:33:49 +000096 void set(const Function &Fn, MachineFunction &MF, bool EnableFastISel);
Dan Gohmanb4be71e2010-04-14 02:09:45 +000097
98 /// clear - Clear out all the function-specific state. This returns this
99 /// FunctionLoweringInfo to an empty state, ready to be used for a
100 /// different function.
101 void clear();
102
Dan Gohman6277eb22009-11-23 17:16:22 +0000103 unsigned MakeReg(EVT VT);
104
105 /// isExportedInst - Return true if the specified value is an instruction
106 /// exported from its block.
107 bool isExportedInst(const Value *V) {
108 return ValueMap.count(V);
109 }
110
111 unsigned CreateRegForValue(const Value *V);
112
113 unsigned InitializeRegForValue(const Value *V) {
114 unsigned &R = ValueMap[V];
115 assert(R == 0 && "Already initialized this value register!");
116 return R = CreateRegForValue(V);
117 }
Dan Gohman6277eb22009-11-23 17:16:22 +0000118};
119
120/// ComputeLinearIndex - Given an LLVM IR aggregate type and a sequence
121/// of insertvalue or extractvalue indices that identify a member, return
122/// the linearized index of the start of the member.
123///
124unsigned ComputeLinearIndex(const TargetLowering &TLI, const Type *Ty,
125 const unsigned *Indices,
126 const unsigned *IndicesEnd,
127 unsigned CurIndex = 0);
128
129/// ComputeValueVTs - Given an LLVM IR type, compute a sequence of
130/// EVTs that represent all the individual underlying
131/// non-aggregate types that comprise it.
132///
133/// If Offsets is non-null, it points to a vector to be filled in
134/// with the in-memory offsets of each of the individual values.
135///
136void ComputeValueVTs(const TargetLowering &TLI, const Type *Ty,
137 SmallVectorImpl<EVT> &ValueVTs,
138 SmallVectorImpl<uint64_t> *Offsets = 0,
139 uint64_t StartingOffset = 0);
140
Dan Gohman66336ed2009-11-23 17:42:46 +0000141/// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
142GlobalVariable *ExtractTypeInfo(Value *V);
143
144/// AddCatchInfo - Extract the personality and type infos from an eh.selector
145/// call, and add them to the specified machine basic block.
Dan Gohman25208642010-04-14 19:53:31 +0000146void AddCatchInfo(const CallInst &I,
147 MachineModuleInfo *MMI, MachineBasicBlock *MBB);
Dan Gohman66336ed2009-11-23 17:42:46 +0000148
Dan Gohman5fca8b12009-11-23 18:12:11 +0000149/// CopyCatchInfo - Copy catch information from DestBB to SrcBB.
Dan Gohman25208642010-04-14 19:53:31 +0000150void CopyCatchInfo(const BasicBlock *SrcBB, const BasicBlock *DestBB,
Dan Gohman5fca8b12009-11-23 18:12:11 +0000151 MachineModuleInfo *MMI, FunctionLoweringInfo &FLI);
152
Dan Gohmanfe85e762010-04-14 18:31:02 +0000153/// hasInlineAsmMemConstraint - Return true if the inline asm instruction being
154/// processed uses a memory 'm' constraint.
155bool hasInlineAsmMemConstraint(std::vector<InlineAsm::ConstraintInfo> &CInfos,
156 const TargetLowering &TLI);
157
158/// getFCmpCondCode - Return the ISD condition code corresponding to
159/// the given LLVM IR floating-point condition code. This includes
160/// consideration of global floating-point math flags.
161///
162ISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred);
163
164/// getICmpCondCode - Return the ISD condition code corresponding to
165/// the given LLVM IR integer condition code.
166///
167ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred);
168
Dan Gohman6277eb22009-11-23 17:16:22 +0000169} // end namespace llvm
170
171#endif