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 | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 27 | #include <vector> |
| 28 | |
| 29 | namespace llvm { |
| 30 | |
| 31 | class AllocaInst; |
| 32 | class BasicBlock; |
Dan Gohman | 66336ed | 2009-11-23 17:42:46 +0000 | [diff] [blame] | 33 | class CallInst; |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 34 | class Function; |
Dan Gohman | 66336ed | 2009-11-23 17:42:46 +0000 | [diff] [blame] | 35 | class GlobalVariable; |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 36 | class Instruction; |
| 37 | class MachineBasicBlock; |
| 38 | class MachineFunction; |
Dan Gohman | 66336ed | 2009-11-23 17:42:46 +0000 | [diff] [blame] | 39 | class MachineModuleInfo; |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 40 | class MachineRegisterInfo; |
| 41 | class TargetLowering; |
| 42 | class Value; |
| 43 | |
| 44 | //===--------------------------------------------------------------------===// |
| 45 | /// FunctionLoweringInfo - This contains information that is global to a |
| 46 | /// function that is used when lowering a region of the function. |
| 47 | /// |
| 48 | class FunctionLoweringInfo { |
| 49 | public: |
| 50 | TargetLowering &TLI; |
Dan Gohman | ae541aa | 2010-04-15 04:33:49 +0000 | [diff] [blame^] | 51 | const Function *Fn; |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 52 | MachineFunction *MF; |
| 53 | MachineRegisterInfo *RegInfo; |
| 54 | |
| 55 | /// CanLowerReturn - true iff the function's return value can be lowered to |
| 56 | /// registers. |
| 57 | bool CanLowerReturn; |
| 58 | |
| 59 | /// DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg |
| 60 | /// allocated to hold a pointer to the hidden sret parameter. |
| 61 | unsigned DemoteRegister; |
| 62 | |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 63 | /// MBBMap - A mapping from LLVM basic blocks to their machine code entry. |
| 64 | DenseMap<const BasicBlock*, MachineBasicBlock *> MBBMap; |
| 65 | |
| 66 | /// ValueMap - Since we emit code for the function a basic block at a time, |
| 67 | /// we must remember which virtual registers hold the values for |
| 68 | /// cross-basic-block values. |
| 69 | DenseMap<const Value*, unsigned> ValueMap; |
| 70 | |
| 71 | /// StaticAllocaMap - Keep track of frame indices for fixed sized allocas in |
| 72 | /// the entry block. This allows the allocas to be efficiently referenced |
| 73 | /// anywhere in the function. |
| 74 | DenseMap<const AllocaInst*, int> StaticAllocaMap; |
| 75 | |
| 76 | #ifndef NDEBUG |
Dan Gohman | 2520864 | 2010-04-14 19:53:31 +0000 | [diff] [blame] | 77 | SmallSet<const Instruction *, 8> CatchInfoLost; |
| 78 | SmallSet<const Instruction *, 8> CatchInfoFound; |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 79 | #endif |
| 80 | |
Dan Gohman | b4be71e | 2010-04-14 02:09:45 +0000 | [diff] [blame] | 81 | struct LiveOutInfo { |
| 82 | unsigned NumSignBits; |
| 83 | APInt KnownOne, KnownZero; |
| 84 | LiveOutInfo() : NumSignBits(0), KnownOne(1, 0), KnownZero(1, 0) {} |
| 85 | }; |
| 86 | |
| 87 | /// LiveOutRegInfo - Information about live out vregs, indexed by their |
| 88 | /// register number offset by 'FirstVirtualRegister'. |
| 89 | std::vector<LiveOutInfo> LiveOutRegInfo; |
| 90 | |
| 91 | explicit FunctionLoweringInfo(TargetLowering &TLI); |
| 92 | |
| 93 | /// set - Initialize this FunctionLoweringInfo with the given Function |
| 94 | /// and its associated MachineFunction. |
| 95 | /// |
Dan Gohman | ae541aa | 2010-04-15 04:33:49 +0000 | [diff] [blame^] | 96 | void set(const Function &Fn, MachineFunction &MF, bool EnableFastISel); |
Dan Gohman | b4be71e | 2010-04-14 02:09:45 +0000 | [diff] [blame] | 97 | |
| 98 | /// clear - Clear out all the function-specific state. This returns this |
| 99 | /// FunctionLoweringInfo to an empty state, ready to be used for a |
| 100 | /// different function. |
| 101 | void clear(); |
| 102 | |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 103 | unsigned MakeReg(EVT VT); |
| 104 | |
| 105 | /// isExportedInst - Return true if the specified value is an instruction |
| 106 | /// exported from its block. |
| 107 | bool isExportedInst(const Value *V) { |
| 108 | return ValueMap.count(V); |
| 109 | } |
| 110 | |
| 111 | unsigned CreateRegForValue(const Value *V); |
| 112 | |
| 113 | unsigned InitializeRegForValue(const Value *V) { |
| 114 | unsigned &R = ValueMap[V]; |
| 115 | assert(R == 0 && "Already initialized this value register!"); |
| 116 | return R = CreateRegForValue(V); |
| 117 | } |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | /// ComputeLinearIndex - Given an LLVM IR aggregate type and a sequence |
| 121 | /// of insertvalue or extractvalue indices that identify a member, return |
| 122 | /// the linearized index of the start of the member. |
| 123 | /// |
| 124 | unsigned ComputeLinearIndex(const TargetLowering &TLI, const Type *Ty, |
| 125 | const unsigned *Indices, |
| 126 | const unsigned *IndicesEnd, |
| 127 | unsigned CurIndex = 0); |
| 128 | |
| 129 | /// ComputeValueVTs - Given an LLVM IR type, compute a sequence of |
| 130 | /// EVTs that represent all the individual underlying |
| 131 | /// non-aggregate types that comprise it. |
| 132 | /// |
| 133 | /// If Offsets is non-null, it points to a vector to be filled in |
| 134 | /// with the in-memory offsets of each of the individual values. |
| 135 | /// |
| 136 | void ComputeValueVTs(const TargetLowering &TLI, const Type *Ty, |
| 137 | SmallVectorImpl<EVT> &ValueVTs, |
| 138 | SmallVectorImpl<uint64_t> *Offsets = 0, |
| 139 | uint64_t StartingOffset = 0); |
| 140 | |
Dan Gohman | 66336ed | 2009-11-23 17:42:46 +0000 | [diff] [blame] | 141 | /// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V. |
| 142 | GlobalVariable *ExtractTypeInfo(Value *V); |
| 143 | |
| 144 | /// AddCatchInfo - Extract the personality and type infos from an eh.selector |
| 145 | /// call, and add them to the specified machine basic block. |
Dan Gohman | 2520864 | 2010-04-14 19:53:31 +0000 | [diff] [blame] | 146 | void AddCatchInfo(const CallInst &I, |
| 147 | MachineModuleInfo *MMI, MachineBasicBlock *MBB); |
Dan Gohman | 66336ed | 2009-11-23 17:42:46 +0000 | [diff] [blame] | 148 | |
Dan Gohman | 5fca8b1 | 2009-11-23 18:12:11 +0000 | [diff] [blame] | 149 | /// CopyCatchInfo - Copy catch information from DestBB to SrcBB. |
Dan Gohman | 2520864 | 2010-04-14 19:53:31 +0000 | [diff] [blame] | 150 | void CopyCatchInfo(const BasicBlock *SrcBB, const BasicBlock *DestBB, |
Dan Gohman | 5fca8b1 | 2009-11-23 18:12:11 +0000 | [diff] [blame] | 151 | MachineModuleInfo *MMI, FunctionLoweringInfo &FLI); |
| 152 | |
Dan Gohman | fe85e76 | 2010-04-14 18:31:02 +0000 | [diff] [blame] | 153 | /// hasInlineAsmMemConstraint - Return true if the inline asm instruction being |
| 154 | /// processed uses a memory 'm' constraint. |
| 155 | bool hasInlineAsmMemConstraint(std::vector<InlineAsm::ConstraintInfo> &CInfos, |
| 156 | const TargetLowering &TLI); |
| 157 | |
| 158 | /// getFCmpCondCode - Return the ISD condition code corresponding to |
| 159 | /// the given LLVM IR floating-point condition code. This includes |
| 160 | /// consideration of global floating-point math flags. |
| 161 | /// |
| 162 | ISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred); |
| 163 | |
| 164 | /// getICmpCondCode - Return the ISD condition code corresponding to |
| 165 | /// the given LLVM IR integer condition code. |
| 166 | /// |
| 167 | ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred); |
| 168 | |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 169 | } // end namespace llvm |
| 170 | |
| 171 | #endif |