Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 1 | //===-- 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 Gohman | fe85e76 | 2010-04-14 18:31:02 +0000 | [diff] [blame] | 18 | #include "llvm/InlineAsm.h" |
| 19 | #include "llvm/Instructions.h" |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 20 | #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 Gohman | 1160945 | 2010-04-14 18:49:17 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/ISDOpcodes.h" |
Dan Gohman | 46007b3 | 2010-04-19 18:41:46 +0000 | [diff] [blame] | 27 | #include "llvm/Support/CallSite.h" |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 28 | #include <vector> |
| 29 | |
| 30 | namespace llvm { |
| 31 | |
| 32 | class AllocaInst; |
| 33 | class BasicBlock; |
Dan Gohman | 66336ed | 2009-11-23 17:42:46 +0000 | [diff] [blame] | 34 | class CallInst; |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 35 | class Function; |
Dan Gohman | 66336ed | 2009-11-23 17:42:46 +0000 | [diff] [blame] | 36 | class GlobalVariable; |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 37 | class Instruction; |
| 38 | class MachineBasicBlock; |
| 39 | class MachineFunction; |
Dan Gohman | 66336ed | 2009-11-23 17:42:46 +0000 | [diff] [blame] | 40 | class MachineModuleInfo; |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 41 | class MachineRegisterInfo; |
| 42 | class TargetLowering; |
| 43 | class Value; |
| 44 | |
| 45 | //===--------------------------------------------------------------------===// |
| 46 | /// FunctionLoweringInfo - This contains information that is global to a |
| 47 | /// function that is used when lowering a region of the function. |
| 48 | /// |
| 49 | class FunctionLoweringInfo { |
| 50 | public: |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 51 | const TargetLowering &TLI; |
Dan Gohman | ae541aa | 2010-04-15 04:33:49 +0000 | [diff] [blame] | 52 | const Function *Fn; |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 53 | MachineFunction *MF; |
| 54 | MachineRegisterInfo *RegInfo; |
| 55 | |
| 56 | /// CanLowerReturn - true iff the function's return value can be lowered to |
| 57 | /// registers. |
| 58 | bool CanLowerReturn; |
| 59 | |
| 60 | /// DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg |
| 61 | /// allocated to hold a pointer to the hidden sret parameter. |
| 62 | unsigned DemoteRegister; |
| 63 | |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 64 | /// MBBMap - A mapping from LLVM basic blocks to their machine code entry. |
| 65 | DenseMap<const BasicBlock*, MachineBasicBlock *> MBBMap; |
| 66 | |
| 67 | /// ValueMap - Since we emit code for the function a basic block at a time, |
| 68 | /// we must remember which virtual registers hold the values for |
| 69 | /// cross-basic-block values. |
| 70 | DenseMap<const Value*, unsigned> ValueMap; |
| 71 | |
| 72 | /// StaticAllocaMap - Keep track of frame indices for fixed sized allocas in |
| 73 | /// the entry block. This allows the allocas to be efficiently referenced |
| 74 | /// anywhere in the function. |
| 75 | DenseMap<const AllocaInst*, int> StaticAllocaMap; |
| 76 | |
| 77 | #ifndef NDEBUG |
Dan Gohman | 2520864 | 2010-04-14 19:53:31 +0000 | [diff] [blame] | 78 | SmallSet<const Instruction *, 8> CatchInfoLost; |
| 79 | SmallSet<const Instruction *, 8> CatchInfoFound; |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 80 | #endif |
| 81 | |
Dan Gohman | b4be71e | 2010-04-14 02:09:45 +0000 | [diff] [blame] | 82 | struct LiveOutInfo { |
| 83 | unsigned NumSignBits; |
| 84 | APInt KnownOne, KnownZero; |
| 85 | LiveOutInfo() : NumSignBits(0), KnownOne(1, 0), KnownZero(1, 0) {} |
| 86 | }; |
| 87 | |
| 88 | /// LiveOutRegInfo - Information about live out vregs, indexed by their |
| 89 | /// register number offset by 'FirstVirtualRegister'. |
| 90 | std::vector<LiveOutInfo> LiveOutRegInfo; |
| 91 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 92 | explicit FunctionLoweringInfo(const TargetLowering &TLI); |
Dan Gohman | b4be71e | 2010-04-14 02:09:45 +0000 | [diff] [blame] | 93 | |
| 94 | /// set - Initialize this FunctionLoweringInfo with the given Function |
| 95 | /// and its associated MachineFunction. |
| 96 | /// |
Dan Gohman | ae541aa | 2010-04-15 04:33:49 +0000 | [diff] [blame] | 97 | void set(const Function &Fn, MachineFunction &MF, bool EnableFastISel); |
Dan Gohman | b4be71e | 2010-04-14 02:09:45 +0000 | [diff] [blame] | 98 | |
| 99 | /// clear - Clear out all the function-specific state. This returns this |
| 100 | /// FunctionLoweringInfo to an empty state, ready to be used for a |
| 101 | /// different function. |
| 102 | void clear(); |
| 103 | |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 104 | unsigned MakeReg(EVT VT); |
| 105 | |
| 106 | /// isExportedInst - Return true if the specified value is an instruction |
| 107 | /// exported from its block. |
| 108 | bool isExportedInst(const Value *V) { |
| 109 | return ValueMap.count(V); |
| 110 | } |
| 111 | |
| 112 | unsigned CreateRegForValue(const Value *V); |
| 113 | |
| 114 | unsigned InitializeRegForValue(const Value *V) { |
| 115 | unsigned &R = ValueMap[V]; |
| 116 | assert(R == 0 && "Already initialized this value register!"); |
| 117 | return R = CreateRegForValue(V); |
| 118 | } |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
Dan Gohman | 66336ed | 2009-11-23 17:42:46 +0000 | [diff] [blame] | 121 | /// AddCatchInfo - Extract the personality and type infos from an eh.selector |
| 122 | /// call, and add them to the specified machine basic block. |
Dan Gohman | 2520864 | 2010-04-14 19:53:31 +0000 | [diff] [blame] | 123 | void AddCatchInfo(const CallInst &I, |
| 124 | MachineModuleInfo *MMI, MachineBasicBlock *MBB); |
Dan Gohman | 66336ed | 2009-11-23 17:42:46 +0000 | [diff] [blame] | 125 | |
Dan Gohman | 5fca8b1 | 2009-11-23 18:12:11 +0000 | [diff] [blame] | 126 | /// CopyCatchInfo - Copy catch information from DestBB to SrcBB. |
Dan Gohman | 2520864 | 2010-04-14 19:53:31 +0000 | [diff] [blame] | 127 | void CopyCatchInfo(const BasicBlock *SrcBB, const BasicBlock *DestBB, |
Dan Gohman | 5fca8b1 | 2009-11-23 18:12:11 +0000 | [diff] [blame] | 128 | MachineModuleInfo *MMI, FunctionLoweringInfo &FLI); |
| 129 | |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 130 | } // end namespace llvm |
| 131 | |
| 132 | #endif |