1 //===-- FunctionLoweringInfo.h - Lower functions from LLVM IR to CodeGen --===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This implements routines for translating functions from LLVM IR into
13 //===----------------------------------------------------------------------===//
15 #ifndef FUNCTIONLOWERINGINFO_H
16 #define FUNCTIONLOWERINGINFO_H
18 #include "llvm/InlineAsm.h"
19 #include "llvm/Instructions.h"
20 #include "llvm/ADT/APInt.h"
21 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/SmallSet.h"
25 #include "llvm/CodeGen/ValueTypes.h"
26 #include "llvm/CodeGen/ISDOpcodes.h"
27 #include "llvm/Support/CallSite.h"
39 class MachineBasicBlock;
40 class MachineFunction;
41 class MachineModuleInfo;
42 class MachineRegisterInfo;
46 //===--------------------------------------------------------------------===//
47 /// FunctionLoweringInfo - This contains information that is global to a
48 /// function that is used when lowering a region of the function.
50 class FunctionLoweringInfo {
52 const TargetLowering &TLI;
55 MachineRegisterInfo *RegInfo;
57 /// CanLowerReturn - true iff the function's return value can be lowered to
61 /// DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg
62 /// allocated to hold a pointer to the hidden sret parameter.
63 unsigned DemoteRegister;
65 /// MBBMap - A mapping from LLVM basic blocks to their machine code entry.
66 DenseMap<const BasicBlock*, MachineBasicBlock *> MBBMap;
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;
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;
78 SmallVector<MachineInstr*, 8> ArgDbgValues;
81 SmallSet<const Instruction *, 8> CatchInfoLost;
82 SmallSet<const Instruction *, 8> CatchInfoFound;
87 APInt KnownOne, KnownZero;
88 LiveOutInfo() : NumSignBits(0), KnownOne(1, 0), KnownZero(1, 0) {}
91 /// LiveOutRegInfo - Information about live out vregs, indexed by their
92 /// register number offset by 'FirstVirtualRegister'.
93 std::vector<LiveOutInfo> LiveOutRegInfo;
95 /// 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;
101 explicit FunctionLoweringInfo(const TargetLowering &TLI);
103 /// set - Initialize this FunctionLoweringInfo with the given Function
104 /// and its associated MachineFunction.
106 void set(const Function &Fn, MachineFunction &MF, bool EnableFastISel);
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.
113 unsigned MakeReg(EVT VT);
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);
121 unsigned CreateRegForValue(const Value *V);
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);
130 /// AddCatchInfo - Extract the personality and type infos from an eh.selector
131 /// call, and add them to the specified machine basic block.
132 void AddCatchInfo(const CallInst &I,
133 MachineModuleInfo *MMI, MachineBasicBlock *MBB);
135 /// CopyCatchInfo - Copy catch information from DestBB to SrcBB.
136 void CopyCatchInfo(const BasicBlock *SrcBB, const BasicBlock *DestBB,
137 MachineModuleInfo *MMI, FunctionLoweringInfo &FLI);
139 } // end namespace llvm