blob: 35335c1d2a576afdcf96d8702109f50012082636 [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 Cheng8fed7612010-04-29 06:58:53 +000079 /// ArgDbgValues - A list of DBG_VALUE instructions created during isel for
80 /// function arguments that are inserted after scheduling is completed.
Evan Cheng2ad0fcf2010-04-28 23:08:54 +000081 SmallVector<MachineInstr*, 8> ArgDbgValues;
82
Dan Gohman6277eb22009-11-23 17:16:22 +000083#ifndef NDEBUG
Dan Gohman25208642010-04-14 19:53:31 +000084 SmallSet<const Instruction *, 8> CatchInfoLost;
85 SmallSet<const Instruction *, 8> CatchInfoFound;
Dan Gohman6277eb22009-11-23 17:16:22 +000086#endif
87
Dan Gohmanb4be71e2010-04-14 02:09:45 +000088 struct LiveOutInfo {
89 unsigned NumSignBits;
90 APInt KnownOne, KnownZero;
91 LiveOutInfo() : NumSignBits(0), KnownOne(1, 0), KnownZero(1, 0) {}
92 };
93
94 /// LiveOutRegInfo - Information about live out vregs, indexed by their
95 /// register number offset by 'FirstVirtualRegister'.
96 std::vector<LiveOutInfo> LiveOutRegInfo;
97
Dan Gohman620427d2010-04-22 19:55:20 +000098 /// PHINodesToUpdate - A list of phi instructions whose operand list will
99 /// be updated after processing the current basic block.
100 /// TODO: This isn't per-function state, it's per-basic-block state. But
101 /// there's no other convenient place for it to live right now.
102 std::vector<std::pair<MachineInstr*, unsigned> > PHINodesToUpdate;
103
Dan Gohmand858e902010-04-17 15:26:15 +0000104 explicit FunctionLoweringInfo(const TargetLowering &TLI);
Dan Gohmanb4be71e2010-04-14 02:09:45 +0000105
106 /// set - Initialize this FunctionLoweringInfo with the given Function
107 /// and its associated MachineFunction.
108 ///
Dan Gohman7451d3e2010-05-29 17:03:36 +0000109 void set(const Function &Fn, MachineFunction &MF);
Dan Gohmanb4be71e2010-04-14 02:09:45 +0000110
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
Dan Gohman6277eb22009-11-23 17:16:22 +0000116 unsigned MakeReg(EVT VT);
117
118 /// isExportedInst - Return true if the specified value is an instruction
119 /// exported from its block.
120 bool isExportedInst(const Value *V) {
121 return ValueMap.count(V);
122 }
123
Dan Gohmanffda6ba2010-07-01 03:55:39 +0000124 unsigned CreateReg(const Type *Ty);
Dan Gohman6277eb22009-11-23 17:16:22 +0000125
126 unsigned InitializeRegForValue(const Value *V) {
127 unsigned &R = ValueMap[V];
128 assert(R == 0 && "Already initialized this value register!");
Dan Gohmanffda6ba2010-07-01 03:55:39 +0000129 return R = CreateReg(V->getType());
Dan Gohman6277eb22009-11-23 17:16:22 +0000130 }
Dan Gohman6277eb22009-11-23 17:16:22 +0000131};
132
Dan Gohman66336ed2009-11-23 17:42:46 +0000133/// AddCatchInfo - Extract the personality and type infos from an eh.selector
134/// call, and add them to the specified machine basic block.
Dan Gohman25208642010-04-14 19:53:31 +0000135void AddCatchInfo(const CallInst &I,
136 MachineModuleInfo *MMI, MachineBasicBlock *MBB);
Dan Gohman66336ed2009-11-23 17:42:46 +0000137
Dan Gohman5fca8b12009-11-23 18:12:11 +0000138/// CopyCatchInfo - Copy catch information from DestBB to SrcBB.
Dan Gohman25208642010-04-14 19:53:31 +0000139void CopyCatchInfo(const BasicBlock *SrcBB, const BasicBlock *DestBB,
Dan Gohman5fca8b12009-11-23 18:12:11 +0000140 MachineModuleInfo *MMI, FunctionLoweringInfo &FLI);
141
Dan Gohman6277eb22009-11-23 17:16:22 +0000142} // end namespace llvm
143
144#endif