Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

228 lines
8.0 KiB

  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. #ifndef LLVM_CODEGEN_FUNCTIONLOWERINGINFO_H
  15. #define LLVM_CODEGEN_FUNCTIONLOWERINGINFO_H
  16. #include "llvm/ADT/APInt.h"
  17. #include "llvm/ADT/DenseMap.h"
  18. #include "llvm/ADT/IndexedMap.h"
  19. #include "llvm/ADT/SmallPtrSet.h"
  20. #include "llvm/ADT/SmallVector.h"
  21. #include "llvm/CodeGen/MachineBasicBlock.h"
  22. #include "llvm/CodeGen/ValueTypes.h"
  23. #include "llvm/IR/InlineAsm.h"
  24. #include "llvm/IR/Instructions.h"
  25. #include "llvm/Target/TargetRegisterInfo.h"
  26. #include <vector>
  27. namespace llvm {
  28. class AllocaInst;
  29. class BasicBlock;
  30. class BranchProbabilityInfo;
  31. class CallInst;
  32. class Function;
  33. class GlobalVariable;
  34. class Instruction;
  35. class MachineInstr;
  36. class MachineBasicBlock;
  37. class MachineFunction;
  38. class MachineModuleInfo;
  39. class MachineRegisterInfo;
  40. class TargetLowering;
  41. class Value;
  42. //===--------------------------------------------------------------------===//
  43. /// FunctionLoweringInfo - This contains information that is global to a
  44. /// function that is used when lowering a region of the function.
  45. ///
  46. class FunctionLoweringInfo {
  47. public:
  48. const TargetLowering &TLI;
  49. const Function *Fn;
  50. MachineFunction *MF;
  51. MachineRegisterInfo *RegInfo;
  52. BranchProbabilityInfo *BPI;
  53. /// CanLowerReturn - true iff the function's return value can be lowered to
  54. /// registers.
  55. bool CanLowerReturn;
  56. /// DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg
  57. /// allocated to hold a pointer to the hidden sret parameter.
  58. unsigned DemoteRegister;
  59. /// MBBMap - A mapping from LLVM basic blocks to their machine code entry.
  60. DenseMap<const BasicBlock*, MachineBasicBlock *> MBBMap;
  61. /// ValueMap - Since we emit code for the function a basic block at a time,
  62. /// we must remember which virtual registers hold the values for
  63. /// cross-basic-block values.
  64. DenseMap<const Value*, unsigned> ValueMap;
  65. /// StaticAllocaMap - Keep track of frame indices for fixed sized allocas in
  66. /// the entry block. This allows the allocas to be efficiently referenced
  67. /// anywhere in the function.
  68. DenseMap<const AllocaInst*, int> StaticAllocaMap;
  69. /// ByValArgFrameIndexMap - Keep track of frame indices for byval arguments.
  70. DenseMap<const Argument*, int> ByValArgFrameIndexMap;
  71. /// ArgDbgValues - A list of DBG_VALUE instructions created during isel for
  72. /// function arguments that are inserted after scheduling is completed.
  73. SmallVector<MachineInstr*, 8> ArgDbgValues;
  74. /// RegFixups - Registers which need to be replaced after isel is done.
  75. DenseMap<unsigned, unsigned> RegFixups;
  76. /// MBB - The current block.
  77. MachineBasicBlock *MBB;
  78. /// MBB - The current insert position inside the current block.
  79. MachineBasicBlock::iterator InsertPt;
  80. #ifndef NDEBUG
  81. SmallPtrSet<const Instruction *, 8> CatchInfoLost;
  82. SmallPtrSet<const Instruction *, 8> CatchInfoFound;
  83. #endif
  84. struct LiveOutInfo {
  85. unsigned NumSignBits : 31;
  86. bool IsValid : 1;
  87. APInt KnownOne, KnownZero;
  88. LiveOutInfo() : NumSignBits(0), IsValid(true), KnownOne(1, 0),
  89. KnownZero(1, 0) {}
  90. };
  91. /// VisitedBBs - The set of basic blocks visited thus far by instruction
  92. /// selection.
  93. SmallPtrSet<const BasicBlock*, 4> VisitedBBs;
  94. /// PHINodesToUpdate - A list of phi instructions whose operand list will
  95. /// be updated after processing the current basic block.
  96. /// TODO: This isn't per-function state, it's per-basic-block state. But
  97. /// there's no other convenient place for it to live right now.
  98. std::vector<std::pair<MachineInstr*, unsigned> > PHINodesToUpdate;
  99. explicit FunctionLoweringInfo(const TargetLowering &TLI);
  100. /// set - Initialize this FunctionLoweringInfo with the given Function
  101. /// and its associated MachineFunction.
  102. ///
  103. void set(const Function &Fn, MachineFunction &MF);
  104. /// clear - Clear out all the function-specific state. This returns this
  105. /// FunctionLoweringInfo to an empty state, ready to be used for a
  106. /// different function.
  107. void clear();
  108. /// isExportedInst - Return true if the specified value is an instruction
  109. /// exported from its block.
  110. bool isExportedInst(const Value *V) {
  111. return ValueMap.count(V);
  112. }
  113. unsigned CreateReg(MVT VT);
  114. unsigned CreateRegs(Type *Ty);
  115. unsigned InitializeRegForValue(const Value *V) {
  116. unsigned &R = ValueMap[V];
  117. assert(R == 0 && "Already initialized this value register!");
  118. return R = CreateRegs(V->getType());
  119. }
  120. /// GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the
  121. /// register is a PHI destination and the PHI's LiveOutInfo is not valid.
  122. const LiveOutInfo *GetLiveOutRegInfo(unsigned Reg) {
  123. if (!LiveOutRegInfo.inBounds(Reg))
  124. return NULL;
  125. const LiveOutInfo *LOI = &LiveOutRegInfo[Reg];
  126. if (!LOI->IsValid)
  127. return NULL;
  128. return LOI;
  129. }
  130. /// GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the
  131. /// register is a PHI destination and the PHI's LiveOutInfo is not valid. If
  132. /// the register's LiveOutInfo is for a smaller bit width, it is extended to
  133. /// the larger bit width by zero extension. The bit width must be no smaller
  134. /// than the LiveOutInfo's existing bit width.
  135. const LiveOutInfo *GetLiveOutRegInfo(unsigned Reg, unsigned BitWidth);
  136. /// AddLiveOutRegInfo - Adds LiveOutInfo for a register.
  137. void AddLiveOutRegInfo(unsigned Reg, unsigned NumSignBits,
  138. const APInt &KnownZero, const APInt &KnownOne) {
  139. // Only install this information if it tells us something.
  140. if (NumSignBits == 1 && KnownZero == 0 && KnownOne == 0)
  141. return;
  142. LiveOutRegInfo.grow(Reg);
  143. LiveOutInfo &LOI = LiveOutRegInfo[Reg];
  144. LOI.NumSignBits = NumSignBits;
  145. LOI.KnownOne = KnownOne;
  146. LOI.KnownZero = KnownZero;
  147. }
  148. /// ComputePHILiveOutRegInfo - Compute LiveOutInfo for a PHI's destination
  149. /// register based on the LiveOutInfo of its operands.
  150. void ComputePHILiveOutRegInfo(const PHINode*);
  151. /// InvalidatePHILiveOutRegInfo - Invalidates a PHI's LiveOutInfo, to be
  152. /// called when a block is visited before all of its predecessors.
  153. void InvalidatePHILiveOutRegInfo(const PHINode *PN) {
  154. // PHIs with no uses have no ValueMap entry.
  155. DenseMap<const Value*, unsigned>::const_iterator It = ValueMap.find(PN);
  156. if (It == ValueMap.end())
  157. return;
  158. unsigned Reg = It->second;
  159. LiveOutRegInfo.grow(Reg);
  160. LiveOutRegInfo[Reg].IsValid = false;
  161. }
  162. /// setArgumentFrameIndex - Record frame index for the byval
  163. /// argument.
  164. void setArgumentFrameIndex(const Argument *A, int FI);
  165. /// getArgumentFrameIndex - Get frame index for the byval argument.
  166. int getArgumentFrameIndex(const Argument *A);
  167. private:
  168. /// LiveOutRegInfo - Information about live out vregs.
  169. IndexedMap<LiveOutInfo, VirtReg2IndexFunctor> LiveOutRegInfo;
  170. };
  171. /// ComputeUsesVAFloatArgument - Determine if any floating-point values are
  172. /// being passed to this variadic function, and set the MachineModuleInfo's
  173. /// usesVAFloatArgument flag if so. This flag is used to emit an undefined
  174. /// reference to _fltused on Windows, which will link in MSVCRT's
  175. /// floating-point support.
  176. void ComputeUsesVAFloatArgument(const CallInst &I, MachineModuleInfo *MMI);
  177. /// AddCatchInfo - Extract the personality and type infos from an eh.selector
  178. /// call, and add them to the specified machine basic block.
  179. void AddCatchInfo(const CallInst &I,
  180. MachineModuleInfo *MMI, MachineBasicBlock *MBB);
  181. /// AddLandingPadInfo - Extract the exception handling information from the
  182. /// landingpad instruction and add them to the specified machine module info.
  183. void AddLandingPadInfo(const LandingPadInst &I, MachineModuleInfo &MMI,
  184. MachineBasicBlock *MBB);
  185. } // end namespace llvm
  186. #endif