blob: ae356e2dfb7c4e077f8bf07c357873ecf102bdbd [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"
Dan Gohmanc9245562010-04-29 01:39:13 +000022#include "llvm/ADT/SmallVector.h"
Dan Gohman6277eb22009-11-23 17:16:22 +000023#ifndef NDEBUG
24#include "llvm/ADT/SmallSet.h"
25#endif
26#include "llvm/CodeGen/ValueTypes.h"
Dan Gohman11609452010-04-14 18:49:17 +000027#include "llvm/CodeGen/ISDOpcodes.h"
Dan Gohman46007b32010-04-19 18:41:46 +000028#include "llvm/Support/CallSite.h"
Dan Gohman6277eb22009-11-23 17:16:22 +000029#include <vector>
30
31namespace llvm {
32
33class AllocaInst;
34class BasicBlock;
Dan Gohman66336ed2009-11-23 17:42:46 +000035class CallInst;
Dan Gohman6277eb22009-11-23 17:16:22 +000036class Function;
Dan Gohman66336ed2009-11-23 17:42:46 +000037class GlobalVariable;
Dan Gohman6277eb22009-11-23 17:16:22 +000038class Instruction;
Dan Gohman620427d2010-04-22 19:55:20 +000039class MachineInstr;
Dan Gohman6277eb22009-11-23 17:16:22 +000040class MachineBasicBlock;
41class MachineFunction;
Dan Gohman66336ed2009-11-23 17:42:46 +000042class MachineModuleInfo;
Dan Gohman6277eb22009-11-23 17:16:22 +000043class MachineRegisterInfo;
44class TargetLowering;
45class Value;
46
47//===--------------------------------------------------------------------===//
48/// FunctionLoweringInfo - This contains information that is global to a
49/// function that is used when lowering a region of the function.
50///
51class FunctionLoweringInfo {
52public:
Dan Gohmand858e902010-04-17 15:26:15 +000053 const TargetLowering &TLI;
Dan Gohmanae541aa2010-04-15 04:33:49 +000054 const Function *Fn;
Dan Gohman6277eb22009-11-23 17:16:22 +000055 MachineFunction *MF;
56 MachineRegisterInfo *RegInfo;
57
58 /// CanLowerReturn - true iff the function's return value can be lowered to
59 /// registers.
60 bool CanLowerReturn;
61
62 /// DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg
63 /// allocated to hold a pointer to the hidden sret parameter.
64 unsigned DemoteRegister;
65
Dan Gohman6277eb22009-11-23 17:16:22 +000066 /// MBBMap - A mapping from LLVM basic blocks to their machine code entry.
67 DenseMap<const BasicBlock*, MachineBasicBlock *> MBBMap;
68
69 /// ValueMap - Since we emit code for the function a basic block at a time,
70 /// we must remember which virtual registers hold the values for
71 /// cross-basic-block values.
72 DenseMap<const Value*, unsigned> ValueMap;
73
74 /// StaticAllocaMap - Keep track of frame indices for fixed sized allocas in
75 /// the entry block. This allows the allocas to be efficiently referenced
76 /// anywhere in the function.
77 DenseMap<const AllocaInst*, int> StaticAllocaMap;
78
Evan Cheng2ad0fcf2010-04-28 23:08:54 +000079 SmallVector<MachineInstr*, 8> ArgDbgValues;
80
Dan Gohman6277eb22009-11-23 17:16:22 +000081#ifndef NDEBUG
Dan Gohman25208642010-04-14 19:53:31 +000082 SmallSet<const Instruction *, 8> CatchInfoLost;
83 SmallSet<const Instruction *, 8> CatchInfoFound;
Dan Gohman6277eb22009-11-23 17:16:22 +000084#endif
85
Dan Gohmanb4be71e2010-04-14 02:09:45 +000086 struct LiveOutInfo {
87 unsigned NumSignBits;
88 APInt KnownOne, KnownZero;
89 LiveOutInfo() : NumSignBits(0), KnownOne(1, 0), KnownZero(1, 0) {}
90 };
91
92 /// LiveOutRegInfo - Information about live out vregs, indexed by their
93 /// register number offset by 'FirstVirtualRegister'.
94 std::vector<LiveOutInfo> LiveOutRegInfo;
95
Dan Gohman620427d2010-04-22 19:55:20 +000096 /// PHINodesToUpdate - A list of phi instructions whose operand list will
97 /// be updated after processing the current basic block.
98 /// TODO: This isn't per-function state, it's per-basic-block state. But
99 /// there's no other convenient place for it to live right now.
100 std::vector<std::pair<MachineInstr*, unsigned> > PHINodesToUpdate;
101
Dan Gohmand858e902010-04-17 15:26:15 +0000102 explicit FunctionLoweringInfo(const TargetLowering &TLI);
Dan Gohmanb4be71e2010-04-14 02:09:45 +0000103
104 /// set - Initialize this FunctionLoweringInfo with the given Function
105 /// and its associated MachineFunction.
106 ///
Dan Gohmanae541aa2010-04-15 04:33:49 +0000107 void set(const Function &Fn, MachineFunction &MF, bool EnableFastISel);
Dan Gohmanb4be71e2010-04-14 02:09:45 +0000108
109 /// clear - Clear out all the function-specific state. This returns this
110 /// FunctionLoweringInfo to an empty state, ready to be used for a
111 /// different function.
112 void clear();
113
Dan Gohman6277eb22009-11-23 17:16:22 +0000114 unsigned MakeReg(EVT VT);
115
116 /// isExportedInst - Return true if the specified value is an instruction
117 /// exported from its block.
118 bool isExportedInst(const Value *V) {
119 return ValueMap.count(V);
120 }
121
122 unsigned CreateRegForValue(const Value *V);
123
124 unsigned InitializeRegForValue(const Value *V) {
125 unsigned &R = ValueMap[V];
126 assert(R == 0 && "Already initialized this value register!");
127 return R = CreateRegForValue(V);
128 }
Dan Gohman6277eb22009-11-23 17:16:22 +0000129};
130
Dan Gohman66336ed2009-11-23 17:42:46 +0000131/// AddCatchInfo - Extract the personality and type infos from an eh.selector
132/// call, and add them to the specified machine basic block.
Dan Gohman25208642010-04-14 19:53:31 +0000133void AddCatchInfo(const CallInst &I,
134 MachineModuleInfo *MMI, MachineBasicBlock *MBB);
Dan Gohman66336ed2009-11-23 17:42:46 +0000135
Dan Gohman5fca8b12009-11-23 18:12:11 +0000136/// CopyCatchInfo - Copy catch information from DestBB to SrcBB.
Dan Gohman25208642010-04-14 19:53:31 +0000137void CopyCatchInfo(const BasicBlock *SrcBB, const BasicBlock *DestBB,
Dan Gohman5fca8b12009-11-23 18:12:11 +0000138 MachineModuleInfo *MMI, FunctionLoweringInfo &FLI);
139
Dan Gohman6277eb22009-11-23 17:16:22 +0000140} // end namespace llvm
141
142#endif