blob: c855db8c7b75c1bd56c98e364202567bab9adc5b [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
78#ifndef NDEBUG
Dan Gohman25208642010-04-14 19:53:31 +000079 SmallSet<const Instruction *, 8> CatchInfoLost;
80 SmallSet<const Instruction *, 8> CatchInfoFound;
Dan Gohman6277eb22009-11-23 17:16:22 +000081#endif
82
Dan Gohmanb4be71e2010-04-14 02:09:45 +000083 struct LiveOutInfo {
84 unsigned NumSignBits;
85 APInt KnownOne, KnownZero;
86 LiveOutInfo() : NumSignBits(0), KnownOne(1, 0), KnownZero(1, 0) {}
87 };
88
89 /// LiveOutRegInfo - Information about live out vregs, indexed by their
90 /// register number offset by 'FirstVirtualRegister'.
91 std::vector<LiveOutInfo> LiveOutRegInfo;
92
Dan Gohman620427d2010-04-22 19:55:20 +000093 /// PHINodesToUpdate - A list of phi instructions whose operand list will
94 /// be updated after processing the current basic block.
95 /// TODO: This isn't per-function state, it's per-basic-block state. But
96 /// there's no other convenient place for it to live right now.
97 std::vector<std::pair<MachineInstr*, unsigned> > PHINodesToUpdate;
98
Dan Gohmand858e902010-04-17 15:26:15 +000099 explicit FunctionLoweringInfo(const TargetLowering &TLI);
Dan Gohmanb4be71e2010-04-14 02:09:45 +0000100
101 /// set - Initialize this FunctionLoweringInfo with the given Function
102 /// and its associated MachineFunction.
103 ///
Dan Gohmanae541aa2010-04-15 04:33:49 +0000104 void set(const Function &Fn, MachineFunction &MF, bool EnableFastISel);
Dan Gohmanb4be71e2010-04-14 02:09:45 +0000105
106 /// clear - Clear out all the function-specific state. This returns this
107 /// FunctionLoweringInfo to an empty state, ready to be used for a
108 /// different function.
109 void clear();
110
Dan Gohman6277eb22009-11-23 17:16:22 +0000111 unsigned MakeReg(EVT VT);
112
113 /// isExportedInst - Return true if the specified value is an instruction
114 /// exported from its block.
115 bool isExportedInst(const Value *V) {
116 return ValueMap.count(V);
117 }
118
119 unsigned CreateRegForValue(const Value *V);
120
121 unsigned InitializeRegForValue(const Value *V) {
122 unsigned &R = ValueMap[V];
123 assert(R == 0 && "Already initialized this value register!");
124 return R = CreateRegForValue(V);
125 }
Dan Gohman6277eb22009-11-23 17:16:22 +0000126};
127
Dan Gohman66336ed2009-11-23 17:42:46 +0000128/// AddCatchInfo - Extract the personality and type infos from an eh.selector
129/// call, and add them to the specified machine basic block.
Dan Gohman25208642010-04-14 19:53:31 +0000130void AddCatchInfo(const CallInst &I,
131 MachineModuleInfo *MMI, MachineBasicBlock *MBB);
Dan Gohman66336ed2009-11-23 17:42:46 +0000132
Dan Gohman5fca8b12009-11-23 18:12:11 +0000133/// CopyCatchInfo - Copy catch information from DestBB to SrcBB.
Dan Gohman25208642010-04-14 19:53:31 +0000134void CopyCatchInfo(const BasicBlock *SrcBB, const BasicBlock *DestBB,
Dan Gohman5fca8b12009-11-23 18:12:11 +0000135 MachineModuleInfo *MMI, FunctionLoweringInfo &FLI);
136
Dan Gohman6277eb22009-11-23 17:16:22 +0000137} // end namespace llvm
138
139#endif