blob: 333fe228d5f9d153a3967739664e1383806387b0 [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 Gohman46007b32010-04-19 18:41:46 +000027#include "llvm/Support/CallSite.h"
Dan Gohman6277eb22009-11-23 17:16:22 +000028#include <vector>
29
30namespace llvm {
31
32class AllocaInst;
33class BasicBlock;
Dan Gohman66336ed2009-11-23 17:42:46 +000034class CallInst;
Dan Gohman6277eb22009-11-23 17:16:22 +000035class Function;
Dan Gohman66336ed2009-11-23 17:42:46 +000036class GlobalVariable;
Dan Gohman6277eb22009-11-23 17:16:22 +000037class Instruction;
38class MachineBasicBlock;
39class MachineFunction;
Dan Gohman66336ed2009-11-23 17:42:46 +000040class MachineModuleInfo;
Dan Gohman6277eb22009-11-23 17:16:22 +000041class MachineRegisterInfo;
42class TargetLowering;
43class Value;
44
45//===--------------------------------------------------------------------===//
46/// FunctionLoweringInfo - This contains information that is global to a
47/// function that is used when lowering a region of the function.
48///
49class FunctionLoweringInfo {
50public:
Dan Gohmand858e902010-04-17 15:26:15 +000051 const TargetLowering &TLI;
Dan Gohmanae541aa2010-04-15 04:33:49 +000052 const Function *Fn;
Dan Gohman6277eb22009-11-23 17:16:22 +000053 MachineFunction *MF;
54 MachineRegisterInfo *RegInfo;
55
56 /// CanLowerReturn - true iff the function's return value can be lowered to
57 /// registers.
58 bool CanLowerReturn;
59
60 /// DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg
61 /// allocated to hold a pointer to the hidden sret parameter.
62 unsigned DemoteRegister;
63
Dan Gohman6277eb22009-11-23 17:16:22 +000064 /// MBBMap - A mapping from LLVM basic blocks to their machine code entry.
65 DenseMap<const BasicBlock*, MachineBasicBlock *> MBBMap;
66
67 /// ValueMap - Since we emit code for the function a basic block at a time,
68 /// we must remember which virtual registers hold the values for
69 /// cross-basic-block values.
70 DenseMap<const Value*, unsigned> ValueMap;
71
72 /// StaticAllocaMap - Keep track of frame indices for fixed sized allocas in
73 /// the entry block. This allows the allocas to be efficiently referenced
74 /// anywhere in the function.
75 DenseMap<const AllocaInst*, int> StaticAllocaMap;
76
77#ifndef NDEBUG
Dan Gohman25208642010-04-14 19:53:31 +000078 SmallSet<const Instruction *, 8> CatchInfoLost;
79 SmallSet<const Instruction *, 8> CatchInfoFound;
Dan Gohman6277eb22009-11-23 17:16:22 +000080#endif
81
Dan Gohmanb4be71e2010-04-14 02:09:45 +000082 struct LiveOutInfo {
83 unsigned NumSignBits;
84 APInt KnownOne, KnownZero;
85 LiveOutInfo() : NumSignBits(0), KnownOne(1, 0), KnownZero(1, 0) {}
86 };
87
88 /// LiveOutRegInfo - Information about live out vregs, indexed by their
89 /// register number offset by 'FirstVirtualRegister'.
90 std::vector<LiveOutInfo> LiveOutRegInfo;
91
Dan Gohmand858e902010-04-17 15:26:15 +000092 explicit FunctionLoweringInfo(const TargetLowering &TLI);
Dan Gohmanb4be71e2010-04-14 02:09:45 +000093
94 /// set - Initialize this FunctionLoweringInfo with the given Function
95 /// and its associated MachineFunction.
96 ///
Dan Gohmanae541aa2010-04-15 04:33:49 +000097 void set(const Function &Fn, MachineFunction &MF, bool EnableFastISel);
Dan Gohmanb4be71e2010-04-14 02:09:45 +000098
99 /// clear - Clear out all the function-specific state. This returns this
100 /// FunctionLoweringInfo to an empty state, ready to be used for a
101 /// different function.
102 void clear();
103
Dan Gohman6277eb22009-11-23 17:16:22 +0000104 unsigned MakeReg(EVT VT);
105
106 /// isExportedInst - Return true if the specified value is an instruction
107 /// exported from its block.
108 bool isExportedInst(const Value *V) {
109 return ValueMap.count(V);
110 }
111
112 unsigned CreateRegForValue(const Value *V);
113
114 unsigned InitializeRegForValue(const Value *V) {
115 unsigned &R = ValueMap[V];
116 assert(R == 0 && "Already initialized this value register!");
117 return R = CreateRegForValue(V);
118 }
Dan Gohman6277eb22009-11-23 17:16:22 +0000119};
120
Dan Gohman66336ed2009-11-23 17:42:46 +0000121/// AddCatchInfo - Extract the personality and type infos from an eh.selector
122/// call, and add them to the specified machine basic block.
Dan Gohman25208642010-04-14 19:53:31 +0000123void AddCatchInfo(const CallInst &I,
124 MachineModuleInfo *MMI, MachineBasicBlock *MBB);
Dan Gohman66336ed2009-11-23 17:42:46 +0000125
Dan Gohman5fca8b12009-11-23 18:12:11 +0000126/// CopyCatchInfo - Copy catch information from DestBB to SrcBB.
Dan Gohman25208642010-04-14 19:53:31 +0000127void CopyCatchInfo(const BasicBlock *SrcBB, const BasicBlock *DestBB,
Dan Gohman5fca8b12009-11-23 18:12:11 +0000128 MachineModuleInfo *MMI, FunctionLoweringInfo &FLI);
129
Dan Gohman6277eb22009-11-23 17:16:22 +0000130} // end namespace llvm
131
132#endif