InstrEmitter.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //===- InstrEmitter.h - Emit MachineInstrs for the SelectionDAG -*- 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 declares the Emit routines for the SelectionDAG class, which creates
  11. // MachineInstrs based on the decisions of the SelectionDAG instruction
  12. // selection.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_INSTREMITTER_H
  16. #define LLVM_LIB_CODEGEN_SELECTIONDAG_INSTREMITTER_H
  17. #include "llvm/ADT/DenseMap.h"
  18. #include "llvm/CodeGen/MachineBasicBlock.h"
  19. #include "llvm/CodeGen/SelectionDAG.h"
  20. namespace llvm {
  21. class MachineInstrBuilder;
  22. class MCInstrDesc;
  23. class SDDbgValue;
  24. class LLVM_LIBRARY_VISIBILITY InstrEmitter {
  25. MachineFunction *MF;
  26. MachineRegisterInfo *MRI;
  27. const TargetInstrInfo *TII;
  28. const TargetRegisterInfo *TRI;
  29. const TargetLowering *TLI;
  30. MachineBasicBlock *MBB;
  31. MachineBasicBlock::iterator InsertPos;
  32. /// EmitCopyFromReg - Generate machine code for an CopyFromReg node or an
  33. /// implicit physical register output.
  34. void EmitCopyFromReg(SDNode *Node, unsigned ResNo,
  35. bool IsClone, bool IsCloned,
  36. unsigned SrcReg,
  37. DenseMap<SDValue, unsigned> &VRBaseMap);
  38. /// getDstOfCopyToRegUse - If the only use of the specified result number of
  39. /// node is a CopyToReg, return its destination register. Return 0 otherwise.
  40. unsigned getDstOfOnlyCopyToRegUse(SDNode *Node,
  41. unsigned ResNo) const;
  42. void CreateVirtualRegisters(SDNode *Node,
  43. MachineInstrBuilder &MIB,
  44. const MCInstrDesc &II,
  45. bool IsClone, bool IsCloned,
  46. DenseMap<SDValue, unsigned> &VRBaseMap);
  47. /// getVR - Return the virtual register corresponding to the specified result
  48. /// of the specified node.
  49. unsigned getVR(SDValue Op,
  50. DenseMap<SDValue, unsigned> &VRBaseMap);
  51. /// AddRegisterOperand - Add the specified register as an operand to the
  52. /// specified machine instr. Insert register copies if the register is
  53. /// not in the required register class.
  54. void AddRegisterOperand(MachineInstrBuilder &MIB,
  55. SDValue Op,
  56. unsigned IIOpNum,
  57. const MCInstrDesc *II,
  58. DenseMap<SDValue, unsigned> &VRBaseMap,
  59. bool IsDebug, bool IsClone, bool IsCloned);
  60. /// AddOperand - Add the specified operand to the specified machine instr. II
  61. /// specifies the instruction information for the node, and IIOpNum is the
  62. /// operand number (in the II) that we are adding. IIOpNum and II are used for
  63. /// assertions only.
  64. void AddOperand(MachineInstrBuilder &MIB,
  65. SDValue Op,
  66. unsigned IIOpNum,
  67. const MCInstrDesc *II,
  68. DenseMap<SDValue, unsigned> &VRBaseMap,
  69. bool IsDebug, bool IsClone, bool IsCloned);
  70. /// ConstrainForSubReg - Try to constrain VReg to a register class that
  71. /// supports SubIdx sub-registers. Emit a copy if that isn't possible.
  72. /// Return the virtual register to use.
  73. unsigned ConstrainForSubReg(unsigned VReg, unsigned SubIdx,
  74. MVT VT, DebugLoc DL);
  75. /// EmitSubregNode - Generate machine code for subreg nodes.
  76. ///
  77. void EmitSubregNode(SDNode *Node, DenseMap<SDValue, unsigned> &VRBaseMap,
  78. bool IsClone, bool IsCloned);
  79. /// EmitCopyToRegClassNode - Generate machine code for COPY_TO_REGCLASS nodes.
  80. /// COPY_TO_REGCLASS is just a normal copy, except that the destination
  81. /// register is constrained to be in a particular register class.
  82. ///
  83. void EmitCopyToRegClassNode(SDNode *Node,
  84. DenseMap<SDValue, unsigned> &VRBaseMap);
  85. /// EmitRegSequence - Generate machine code for REG_SEQUENCE nodes.
  86. ///
  87. void EmitRegSequence(SDNode *Node, DenseMap<SDValue, unsigned> &VRBaseMap,
  88. bool IsClone, bool IsCloned);
  89. public:
  90. /// CountResults - The results of target nodes have register or immediate
  91. /// operands first, then an optional chain, and optional flag operands
  92. /// (which do not go into the machine instrs.)
  93. static unsigned CountResults(SDNode *Node);
  94. /// EmitDbgValue - Generate machine instruction for a dbg_value node.
  95. ///
  96. MachineInstr *EmitDbgValue(SDDbgValue *SD,
  97. DenseMap<SDValue, unsigned> &VRBaseMap);
  98. /// EmitNode - Generate machine code for a node and needed dependencies.
  99. ///
  100. void EmitNode(SDNode *Node, bool IsClone, bool IsCloned,
  101. DenseMap<SDValue, unsigned> &VRBaseMap) {
  102. if (Node->isMachineOpcode())
  103. EmitMachineNode(Node, IsClone, IsCloned, VRBaseMap);
  104. else
  105. EmitSpecialNode(Node, IsClone, IsCloned, VRBaseMap);
  106. }
  107. /// getBlock - Return the current basic block.
  108. MachineBasicBlock *getBlock() { return MBB; }
  109. /// getInsertPos - Return the current insertion position.
  110. MachineBasicBlock::iterator getInsertPos() { return InsertPos; }
  111. /// InstrEmitter - Construct an InstrEmitter and set it to start inserting
  112. /// at the given position in the given block.
  113. InstrEmitter(MachineBasicBlock *mbb, MachineBasicBlock::iterator insertpos);
  114. private:
  115. void EmitMachineNode(SDNode *Node, bool IsClone, bool IsCloned,
  116. DenseMap<SDValue, unsigned> &VRBaseMap);
  117. void EmitSpecialNode(SDNode *Node, bool IsClone, bool IsCloned,
  118. DenseMap<SDValue, unsigned> &VRBaseMap);
  119. };
  120. }
  121. #endif