blob: 969cdba89177a093240d635be39fac4a68968365 [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
18#include "llvm/ADT/APInt.h"
19#include "llvm/ADT/DenseMap.h"
20#ifndef NDEBUG
21#include "llvm/ADT/SmallSet.h"
22#endif
23#include "llvm/CodeGen/ValueTypes.h"
24#include <vector>
25
26namespace llvm {
27
28class AllocaInst;
29class BasicBlock;
Dan Gohman66336ed2009-11-23 17:42:46 +000030class CallInst;
Dan Gohman6277eb22009-11-23 17:16:22 +000031class Function;
Dan Gohman66336ed2009-11-23 17:42:46 +000032class GlobalVariable;
Dan Gohman6277eb22009-11-23 17:16:22 +000033class Instruction;
34class MachineBasicBlock;
35class MachineFunction;
Dan Gohman66336ed2009-11-23 17:42:46 +000036class MachineModuleInfo;
Dan Gohman6277eb22009-11-23 17:16:22 +000037class MachineRegisterInfo;
38class TargetLowering;
39class Value;
40
41//===--------------------------------------------------------------------===//
42/// FunctionLoweringInfo - This contains information that is global to a
43/// function that is used when lowering a region of the function.
44///
45class FunctionLoweringInfo {
46public:
47 TargetLowering &TLI;
48 Function *Fn;
49 MachineFunction *MF;
50 MachineRegisterInfo *RegInfo;
51
52 /// CanLowerReturn - true iff the function's return value can be lowered to
53 /// registers.
54 bool CanLowerReturn;
55
56 /// DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg
57 /// allocated to hold a pointer to the hidden sret parameter.
58 unsigned DemoteRegister;
59
Dan Gohman6277eb22009-11-23 17:16:22 +000060 /// MBBMap - A mapping from LLVM basic blocks to their machine code entry.
61 DenseMap<const BasicBlock*, MachineBasicBlock *> MBBMap;
62
63 /// ValueMap - Since we emit code for the function a basic block at a time,
64 /// we must remember which virtual registers hold the values for
65 /// cross-basic-block values.
66 DenseMap<const Value*, unsigned> ValueMap;
67
68 /// StaticAllocaMap - Keep track of frame indices for fixed sized allocas in
69 /// the entry block. This allows the allocas to be efficiently referenced
70 /// anywhere in the function.
71 DenseMap<const AllocaInst*, int> StaticAllocaMap;
72
73#ifndef NDEBUG
74 SmallSet<Instruction*, 8> CatchInfoLost;
75 SmallSet<Instruction*, 8> CatchInfoFound;
76#endif
77
Dan Gohmanb4be71e2010-04-14 02:09:45 +000078 struct LiveOutInfo {
79 unsigned NumSignBits;
80 APInt KnownOne, KnownZero;
81 LiveOutInfo() : NumSignBits(0), KnownOne(1, 0), KnownZero(1, 0) {}
82 };
83
84 /// LiveOutRegInfo - Information about live out vregs, indexed by their
85 /// register number offset by 'FirstVirtualRegister'.
86 std::vector<LiveOutInfo> LiveOutRegInfo;
87
88 explicit FunctionLoweringInfo(TargetLowering &TLI);
89
90 /// set - Initialize this FunctionLoweringInfo with the given Function
91 /// and its associated MachineFunction.
92 ///
93 void set(Function &Fn, MachineFunction &MF, bool EnableFastISel);
94
95 /// clear - Clear out all the function-specific state. This returns this
96 /// FunctionLoweringInfo to an empty state, ready to be used for a
97 /// different function.
98 void clear();
99
Dan Gohman6277eb22009-11-23 17:16:22 +0000100 unsigned MakeReg(EVT VT);
101
102 /// isExportedInst - Return true if the specified value is an instruction
103 /// exported from its block.
104 bool isExportedInst(const Value *V) {
105 return ValueMap.count(V);
106 }
107
108 unsigned CreateRegForValue(const Value *V);
109
110 unsigned InitializeRegForValue(const Value *V) {
111 unsigned &R = ValueMap[V];
112 assert(R == 0 && "Already initialized this value register!");
113 return R = CreateRegForValue(V);
114 }
Dan Gohman6277eb22009-11-23 17:16:22 +0000115};
116
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.
120///
121unsigned ComputeLinearIndex(const TargetLowering &TLI, const Type *Ty,
122 const unsigned *Indices,
123 const unsigned *IndicesEnd,
124 unsigned CurIndex = 0);
125
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.
129///
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.
132///
133void ComputeValueVTs(const TargetLowering &TLI, const Type *Ty,
134 SmallVectorImpl<EVT> &ValueVTs,
135 SmallVectorImpl<uint64_t> *Offsets = 0,
136 uint64_t StartingOffset = 0);
137
Dan Gohman66336ed2009-11-23 17:42:46 +0000138/// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
139GlobalVariable *ExtractTypeInfo(Value *V);
140
141/// AddCatchInfo - Extract the personality and type infos from an eh.selector
142/// call, and add them to the specified machine basic block.
143void AddCatchInfo(CallInst &I, MachineModuleInfo *MMI, MachineBasicBlock *MBB);
144
Dan Gohman5fca8b12009-11-23 18:12:11 +0000145/// CopyCatchInfo - Copy catch information from DestBB to SrcBB.
146void CopyCatchInfo(BasicBlock *SrcBB, BasicBlock *DestBB,
147 MachineModuleInfo *MMI, FunctionLoweringInfo &FLI);
148
Dan Gohman6277eb22009-11-23 17:16:22 +0000149} // end namespace llvm
150
151#endif