blob: 53e1fccdf75843b1a4772716eac72925b820a374 [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;
Dan Gohman620427d2010-04-22 19:55:20 +000038class MachineInstr;
Dan Gohman6277eb22009-11-23 17:16:22 +000039class MachineBasicBlock;
40class MachineFunction;
Dan Gohman66336ed2009-11-23 17:42:46 +000041class MachineModuleInfo;
Dan Gohman6277eb22009-11-23 17:16:22 +000042class MachineRegisterInfo;
43class TargetLowering;
44class Value;
45
46//===--------------------------------------------------------------------===//
47/// FunctionLoweringInfo - This contains information that is global to a
48/// function that is used when lowering a region of the function.
49///
50class FunctionLoweringInfo {
51public:
Dan Gohmand858e902010-04-17 15:26:15 +000052 const TargetLowering &TLI;
Dan Gohmanae541aa2010-04-15 04:33:49 +000053 const Function *Fn;
Dan Gohman6277eb22009-11-23 17:16:22 +000054 MachineFunction *MF;
55 MachineRegisterInfo *RegInfo;
56
57 /// CanLowerReturn - true iff the function's return value can be lowered to
58 /// registers.
59 bool CanLowerReturn;
60
61 /// DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg
62 /// allocated to hold a pointer to the hidden sret parameter.
63 unsigned DemoteRegister;
64
Dan Gohman6277eb22009-11-23 17:16:22 +000065 /// MBBMap - A mapping from LLVM basic blocks to their machine code entry.
66 DenseMap<const BasicBlock*, MachineBasicBlock *> MBBMap;
67
68 /// ValueMap - Since we emit code for the function a basic block at a time,
69 /// we must remember which virtual registers hold the values for
70 /// cross-basic-block values.
71 DenseMap<const Value*, unsigned> ValueMap;
72
73 /// StaticAllocaMap - Keep track of frame indices for fixed sized allocas in
74 /// the entry block. This allows the allocas to be efficiently referenced
75 /// anywhere in the function.
76 DenseMap<const AllocaInst*, int> StaticAllocaMap;
77
Evan Cheng2ad0fcf2010-04-28 23:08:54 +000078 SmallVector<MachineInstr*, 8> ArgDbgValues;
79
Dan Gohman6277eb22009-11-23 17:16:22 +000080#ifndef NDEBUG
Dan Gohman25208642010-04-14 19:53:31 +000081 SmallSet<const Instruction *, 8> CatchInfoLost;
82 SmallSet<const Instruction *, 8> CatchInfoFound;
Dan Gohman6277eb22009-11-23 17:16:22 +000083#endif
84
Dan Gohmanb4be71e2010-04-14 02:09:45 +000085 struct LiveOutInfo {
86 unsigned NumSignBits;
87 APInt KnownOne, KnownZero;
88 LiveOutInfo() : NumSignBits(0), KnownOne(1, 0), KnownZero(1, 0) {}
89 };
90
91 /// LiveOutRegInfo - Information about live out vregs, indexed by their
92 /// register number offset by 'FirstVirtualRegister'.
93 std::vector<LiveOutInfo> LiveOutRegInfo;
94
Dan Gohman620427d2010-04-22 19:55:20 +000095 /// PHINodesToUpdate - A list of phi instructions whose operand list will
96 /// be updated after processing the current basic block.
97 /// TODO: This isn't per-function state, it's per-basic-block state. But
98 /// there's no other convenient place for it to live right now.
99 std::vector<std::pair<MachineInstr*, unsigned> > PHINodesToUpdate;
100
Dan Gohmand858e902010-04-17 15:26:15 +0000101 explicit FunctionLoweringInfo(const TargetLowering &TLI);
Dan Gohmanb4be71e2010-04-14 02:09:45 +0000102
103 /// set - Initialize this FunctionLoweringInfo with the given Function
104 /// and its associated MachineFunction.
105 ///
Dan Gohmanae541aa2010-04-15 04:33:49 +0000106 void set(const Function &Fn, MachineFunction &MF, bool EnableFastISel);
Dan Gohmanb4be71e2010-04-14 02:09:45 +0000107
108 /// clear - Clear out all the function-specific state. This returns this
109 /// FunctionLoweringInfo to an empty state, ready to be used for a
110 /// different function.
111 void clear();
112
Dan Gohman6277eb22009-11-23 17:16:22 +0000113 unsigned MakeReg(EVT VT);
114
115 /// isExportedInst - Return true if the specified value is an instruction
116 /// exported from its block.
117 bool isExportedInst(const Value *V) {
118 return ValueMap.count(V);
119 }
120
121 unsigned CreateRegForValue(const Value *V);
122
123 unsigned InitializeRegForValue(const Value *V) {
124 unsigned &R = ValueMap[V];
125 assert(R == 0 && "Already initialized this value register!");
126 return R = CreateRegForValue(V);
127 }
Dan Gohman6277eb22009-11-23 17:16:22 +0000128};
129
Dan Gohman66336ed2009-11-23 17:42:46 +0000130/// AddCatchInfo - Extract the personality and type infos from an eh.selector
131/// call, and add them to the specified machine basic block.
Dan Gohman25208642010-04-14 19:53:31 +0000132void AddCatchInfo(const CallInst &I,
133 MachineModuleInfo *MMI, MachineBasicBlock *MBB);
Dan Gohman66336ed2009-11-23 17:42:46 +0000134
Dan Gohman5fca8b12009-11-23 18:12:11 +0000135/// CopyCatchInfo - Copy catch information from DestBB to SrcBB.
Dan Gohman25208642010-04-14 19:53:31 +0000136void CopyCatchInfo(const BasicBlock *SrcBB, const BasicBlock *DestBB,
Dan Gohman5fca8b12009-11-23 18:12:11 +0000137 MachineModuleInfo *MMI, FunctionLoweringInfo &FLI);
138
Dan Gohman6277eb22009-11-23 17:16:22 +0000139} // end namespace llvm
140
141#endif