blob: 38e940953e3ea97db162929b2cc310af7505eadb [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
60 explicit FunctionLoweringInfo(TargetLowering &TLI);
61
62 /// set - Initialize this FunctionLoweringInfo with the given Function
63 /// and its associated MachineFunction.
64 ///
65 void set(Function &Fn, MachineFunction &MF, bool EnableFastISel);
66
67 /// MBBMap - A mapping from LLVM basic blocks to their machine code entry.
68 DenseMap<const BasicBlock*, MachineBasicBlock *> MBBMap;
69
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;
74
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;
79
80#ifndef NDEBUG
81 SmallSet<Instruction*, 8> CatchInfoLost;
82 SmallSet<Instruction*, 8> CatchInfoFound;
83#endif
84
85 unsigned MakeReg(EVT VT);
86
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);
91 }
92
93 unsigned CreateRegForValue(const Value *V);
94
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);
99 }
100
101 struct LiveOutInfo {
102 unsigned NumSignBits;
103 APInt KnownOne, KnownZero;
104 LiveOutInfo() : NumSignBits(0), KnownOne(1, 0), KnownZero(1, 0) {}
105 };
106
107 /// LiveOutRegInfo - Information about live out vregs, indexed by their
108 /// register number offset by 'FirstVirtualRegister'.
109 std::vector<LiveOutInfo> LiveOutRegInfo;
110
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.
114 void clear();
115};
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 Gohman6277eb22009-11-23 17:16:22 +0000145} // end namespace llvm
146
147#endif