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.

291 lines
10 KiB

  1. //===-- llvm/CodeGen/SelectionDAGISel.h - Common Base Class------*- C++ -*-===//
  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 file implements the SelectionDAGISel class, which is used as the common
  11. // base class for SelectionDAG-based instruction selectors.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_CODEGEN_SELECTIONDAGISEL_H
  15. #define LLVM_CODEGEN_SELECTIONDAGISEL_H
  16. #include "llvm/CodeGen/MachineFunctionPass.h"
  17. #include "llvm/CodeGen/SelectionDAG.h"
  18. #include "llvm/IR/BasicBlock.h"
  19. #include "llvm/Pass.h"
  20. namespace llvm {
  21. class FastISel;
  22. class SelectionDAGBuilder;
  23. class SDValue;
  24. class MachineRegisterInfo;
  25. class MachineBasicBlock;
  26. class MachineFunction;
  27. class MachineInstr;
  28. class TargetLowering;
  29. class TargetLibraryInfo;
  30. class TargetInstrInfo;
  31. class TargetTransformInfo;
  32. class FunctionLoweringInfo;
  33. class ScheduleHazardRecognizer;
  34. class GCFunctionInfo;
  35. class ScheduleDAGSDNodes;
  36. class LoadInst;
  37. /// SelectionDAGISel - This is the common base class used for SelectionDAG-based
  38. /// pattern-matching instruction selectors.
  39. class SelectionDAGISel : public MachineFunctionPass {
  40. public:
  41. const TargetMachine &TM;
  42. const TargetLowering &TLI;
  43. const TargetLibraryInfo *LibInfo;
  44. const TargetTransformInfo *TTI;
  45. FunctionLoweringInfo *FuncInfo;
  46. MachineFunction *MF;
  47. MachineRegisterInfo *RegInfo;
  48. SelectionDAG *CurDAG;
  49. SelectionDAGBuilder *SDB;
  50. AliasAnalysis *AA;
  51. GCFunctionInfo *GFI;
  52. CodeGenOpt::Level OptLevel;
  53. static char ID;
  54. explicit SelectionDAGISel(const TargetMachine &tm,
  55. CodeGenOpt::Level OL = CodeGenOpt::Default);
  56. virtual ~SelectionDAGISel();
  57. const TargetLowering &getTargetLowering() { return TLI; }
  58. virtual void getAnalysisUsage(AnalysisUsage &AU) const;
  59. virtual bool runOnMachineFunction(MachineFunction &MF);
  60. virtual void EmitFunctionEntryCode() {}
  61. /// PreprocessISelDAG - This hook allows targets to hack on the graph before
  62. /// instruction selection starts.
  63. virtual void PreprocessISelDAG() {}
  64. /// PostprocessISelDAG() - This hook allows the target to hack on the graph
  65. /// right after selection.
  66. virtual void PostprocessISelDAG() {}
  67. /// Select - Main hook targets implement to select a node.
  68. virtual SDNode *Select(SDNode *N) = 0;
  69. /// SelectInlineAsmMemoryOperand - Select the specified address as a target
  70. /// addressing mode, according to the specified constraint code. If this does
  71. /// not match or is not implemented, return true. The resultant operands
  72. /// (which will appear in the machine instruction) should be added to the
  73. /// OutOps vector.
  74. virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
  75. char ConstraintCode,
  76. std::vector<SDValue> &OutOps) {
  77. return true;
  78. }
  79. /// IsProfitableToFold - Returns true if it's profitable to fold the specific
  80. /// operand node N of U during instruction selection that starts at Root.
  81. virtual bool IsProfitableToFold(SDValue N, SDNode *U, SDNode *Root) const;
  82. /// IsLegalToFold - Returns true if the specific operand node N of
  83. /// U can be folded during instruction selection that starts at Root.
  84. /// FIXME: This is a static member function because the MSP430/X86
  85. /// targets, which uses it during isel. This could become a proper member.
  86. static bool IsLegalToFold(SDValue N, SDNode *U, SDNode *Root,
  87. CodeGenOpt::Level OptLevel,
  88. bool IgnoreChains = false);
  89. // Opcodes used by the DAG state machine:
  90. enum BuiltinOpcodes {
  91. OPC_Scope,
  92. OPC_RecordNode,
  93. OPC_RecordChild0, OPC_RecordChild1, OPC_RecordChild2, OPC_RecordChild3,
  94. OPC_RecordChild4, OPC_RecordChild5, OPC_RecordChild6, OPC_RecordChild7,
  95. OPC_RecordMemRef,
  96. OPC_CaptureGlueInput,
  97. OPC_MoveChild,
  98. OPC_MoveParent,
  99. OPC_CheckSame,
  100. OPC_CheckPatternPredicate,
  101. OPC_CheckPredicate,
  102. OPC_CheckOpcode,
  103. OPC_SwitchOpcode,
  104. OPC_CheckType,
  105. OPC_SwitchType,
  106. OPC_CheckChild0Type, OPC_CheckChild1Type, OPC_CheckChild2Type,
  107. OPC_CheckChild3Type, OPC_CheckChild4Type, OPC_CheckChild5Type,
  108. OPC_CheckChild6Type, OPC_CheckChild7Type,
  109. OPC_CheckInteger,
  110. OPC_CheckCondCode,
  111. OPC_CheckValueType,
  112. OPC_CheckComplexPat,
  113. OPC_CheckAndImm, OPC_CheckOrImm,
  114. OPC_CheckFoldableChainNode,
  115. OPC_EmitInteger,
  116. OPC_EmitRegister,
  117. OPC_EmitRegister2,
  118. OPC_EmitConvertToTarget,
  119. OPC_EmitMergeInputChains,
  120. OPC_EmitMergeInputChains1_0,
  121. OPC_EmitMergeInputChains1_1,
  122. OPC_EmitCopyToReg,
  123. OPC_EmitNodeXForm,
  124. OPC_EmitNode,
  125. OPC_MorphNodeTo,
  126. OPC_MarkGlueResults,
  127. OPC_CompleteMatch
  128. };
  129. enum {
  130. OPFL_None = 0, // Node has no chain or glue input and isn't variadic.
  131. OPFL_Chain = 1, // Node has a chain input.
  132. OPFL_GlueInput = 2, // Node has a glue input.
  133. OPFL_GlueOutput = 4, // Node has a glue output.
  134. OPFL_MemRefs = 8, // Node gets accumulated MemRefs.
  135. OPFL_Variadic0 = 1<<4, // Node is variadic, root has 0 fixed inputs.
  136. OPFL_Variadic1 = 2<<4, // Node is variadic, root has 1 fixed inputs.
  137. OPFL_Variadic2 = 3<<4, // Node is variadic, root has 2 fixed inputs.
  138. OPFL_Variadic3 = 4<<4, // Node is variadic, root has 3 fixed inputs.
  139. OPFL_Variadic4 = 5<<4, // Node is variadic, root has 4 fixed inputs.
  140. OPFL_Variadic5 = 6<<4, // Node is variadic, root has 5 fixed inputs.
  141. OPFL_Variadic6 = 7<<4, // Node is variadic, root has 6 fixed inputs.
  142. OPFL_VariadicInfo = OPFL_Variadic6
  143. };
  144. /// getNumFixedFromVariadicInfo - Transform an EmitNode flags word into the
  145. /// number of fixed arity values that should be skipped when copying from the
  146. /// root.
  147. static inline int getNumFixedFromVariadicInfo(unsigned Flags) {
  148. return ((Flags&OPFL_VariadicInfo) >> 4)-1;
  149. }
  150. protected:
  151. /// DAGSize - Size of DAG being instruction selected.
  152. ///
  153. unsigned DAGSize;
  154. /// ReplaceUses - replace all uses of the old node F with the use
  155. /// of the new node T.
  156. void ReplaceUses(SDValue F, SDValue T) {
  157. CurDAG->ReplaceAllUsesOfValueWith(F, T);
  158. }
  159. /// ReplaceUses - replace all uses of the old nodes F with the use
  160. /// of the new nodes T.
  161. void ReplaceUses(const SDValue *F, const SDValue *T, unsigned Num) {
  162. CurDAG->ReplaceAllUsesOfValuesWith(F, T, Num);
  163. }
  164. /// ReplaceUses - replace all uses of the old node F with the use
  165. /// of the new node T.
  166. void ReplaceUses(SDNode *F, SDNode *T) {
  167. CurDAG->ReplaceAllUsesWith(F, T);
  168. }
  169. /// SelectInlineAsmMemoryOperands - Calls to this are automatically generated
  170. /// by tblgen. Others should not call it.
  171. void SelectInlineAsmMemoryOperands(std::vector<SDValue> &Ops);
  172. public:
  173. // Calls to these predicates are generated by tblgen.
  174. bool CheckAndMask(SDValue LHS, ConstantSDNode *RHS,
  175. int64_t DesiredMaskS) const;
  176. bool CheckOrMask(SDValue LHS, ConstantSDNode *RHS,
  177. int64_t DesiredMaskS) const;
  178. /// CheckPatternPredicate - This function is generated by tblgen in the
  179. /// target. It runs the specified pattern predicate and returns true if it
  180. /// succeeds or false if it fails. The number is a private implementation
  181. /// detail to the code tblgen produces.
  182. virtual bool CheckPatternPredicate(unsigned PredNo) const {
  183. llvm_unreachable("Tblgen should generate the implementation of this!");
  184. }
  185. /// CheckNodePredicate - This function is generated by tblgen in the target.
  186. /// It runs node predicate number PredNo and returns true if it succeeds or
  187. /// false if it fails. The number is a private implementation
  188. /// detail to the code tblgen produces.
  189. virtual bool CheckNodePredicate(SDNode *N, unsigned PredNo) const {
  190. llvm_unreachable("Tblgen should generate the implementation of this!");
  191. }
  192. virtual bool CheckComplexPattern(SDNode *Root, SDNode *Parent, SDValue N,
  193. unsigned PatternNo,
  194. SmallVectorImpl<std::pair<SDValue, SDNode*> > &Result) {
  195. llvm_unreachable("Tblgen should generate the implementation of this!");
  196. }
  197. virtual SDValue RunSDNodeXForm(SDValue V, unsigned XFormNo) {
  198. llvm_unreachable("Tblgen should generate this!");
  199. }
  200. SDNode *SelectCodeCommon(SDNode *NodeToMatch,
  201. const unsigned char *MatcherTable,
  202. unsigned TableSize);
  203. private:
  204. // Calls to these functions are generated by tblgen.
  205. SDNode *Select_INLINEASM(SDNode *N);
  206. SDNode *Select_UNDEF(SDNode *N);
  207. void CannotYetSelect(SDNode *N);
  208. private:
  209. void DoInstructionSelection();
  210. SDNode *MorphNode(SDNode *Node, unsigned TargetOpc, SDVTList VTs,
  211. const SDValue *Ops, unsigned NumOps, unsigned EmitNodeInfo);
  212. void PrepareEHLandingPad();
  213. /// \brief Perform instruction selection on all basic blocks in the function.
  214. void SelectAllBasicBlocks(const Function &Fn);
  215. /// \brief Perform instruction selection on a single basic block, for
  216. /// instructions between \p Begin and \p End. \p HadTailCall will be set
  217. /// to true if a call in the block was translated as a tail call.
  218. void SelectBasicBlock(BasicBlock::const_iterator Begin,
  219. BasicBlock::const_iterator End,
  220. bool &HadTailCall);
  221. void FinishBasicBlock();
  222. void CodeGenAndEmitDAG();
  223. /// \brief Generate instructions for lowering the incoming arguments of the
  224. /// given function.
  225. void LowerArguments(const Function &F);
  226. void ComputeLiveOutVRegInfo();
  227. /// Create the scheduler. If a specific scheduler was specified
  228. /// via the SchedulerRegistry, use it, otherwise select the
  229. /// one preferred by the target.
  230. ///
  231. ScheduleDAGSDNodes *CreateScheduler();
  232. /// OpcodeOffset - This is a cache used to dispatch efficiently into isel
  233. /// state machines that start with a OPC_SwitchOpcode node.
  234. std::vector<unsigned> OpcodeOffset;
  235. void UpdateChainsAndGlue(SDNode *NodeToMatch, SDValue InputChain,
  236. const SmallVectorImpl<SDNode*> &ChainNodesMatched,
  237. SDValue InputGlue, const SmallVectorImpl<SDNode*> &F,
  238. bool isMorphNodeTo);
  239. };
  240. }
  241. #endif /* LLVM_CODEGEN_SELECTIONDAGISEL_H */