SDNodeDbgValue.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //===-- llvm/CodeGen/SDNodeDbgValue.h - SelectionDAG dbg_value --*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file declares the SDDbgValue class.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_SDNODEDBGVALUE_H
  13. #define LLVM_LIB_CODEGEN_SELECTIONDAG_SDNODEDBGVALUE_H
  14. #include "llvm/IR/DebugLoc.h"
  15. #include "llvm/Support/DataTypes.h"
  16. #include <utility>
  17. namespace llvm {
  18. class DIVariable;
  19. class DIExpression;
  20. class SDNode;
  21. class Value;
  22. class raw_ostream;
  23. /// Holds the information from a dbg_value node through SDISel.
  24. /// We do not use SDValue here to avoid including its header.
  25. class SDDbgValue {
  26. public:
  27. enum DbgValueKind {
  28. SDNODE = 0, ///< Value is the result of an expression.
  29. CONST = 1, ///< Value is a constant.
  30. FRAMEIX = 2, ///< Value is contents of a stack location.
  31. VREG = 3 ///< Value is a virtual register.
  32. };
  33. private:
  34. union {
  35. struct {
  36. SDNode *Node; ///< Valid for expressions.
  37. unsigned ResNo; ///< Valid for expressions.
  38. } s;
  39. const Value *Const; ///< Valid for constants.
  40. unsigned FrameIx; ///< Valid for stack objects.
  41. unsigned VReg; ///< Valid for registers.
  42. } u;
  43. DIVariable *Var;
  44. DIExpression *Expr;
  45. DebugLoc DL;
  46. unsigned Order;
  47. enum DbgValueKind kind;
  48. bool IsIndirect;
  49. bool Invalid = false;
  50. bool Emitted = false;
  51. public:
  52. /// Constructor for non-constants.
  53. SDDbgValue(DIVariable *Var, DIExpression *Expr, SDNode *N, unsigned R,
  54. bool indir, DebugLoc dl, unsigned O)
  55. : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(indir) {
  56. kind = SDNODE;
  57. u.s.Node = N;
  58. u.s.ResNo = R;
  59. }
  60. /// Constructor for constants.
  61. SDDbgValue(DIVariable *Var, DIExpression *Expr, const Value *C, DebugLoc dl,
  62. unsigned O)
  63. : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(false) {
  64. kind = CONST;
  65. u.Const = C;
  66. }
  67. /// Constructor for virtual registers and frame indices.
  68. SDDbgValue(DIVariable *Var, DIExpression *Expr, unsigned VRegOrFrameIdx,
  69. bool IsIndirect, DebugLoc DL, unsigned Order,
  70. enum DbgValueKind Kind)
  71. : Var(Var), Expr(Expr), DL(DL), Order(Order), IsIndirect(IsIndirect) {
  72. assert((Kind == VREG || Kind == FRAMEIX) &&
  73. "Invalid SDDbgValue constructor");
  74. kind = Kind;
  75. if (kind == VREG)
  76. u.VReg = VRegOrFrameIdx;
  77. else
  78. u.FrameIx = VRegOrFrameIdx;
  79. }
  80. /// Returns the kind.
  81. DbgValueKind getKind() const { return kind; }
  82. /// Returns the DIVariable pointer for the variable.
  83. DIVariable *getVariable() const { return Var; }
  84. /// Returns the DIExpression pointer for the expression.
  85. DIExpression *getExpression() const { return Expr; }
  86. /// Returns the SDNode* for a register ref
  87. SDNode *getSDNode() const { assert (kind==SDNODE); return u.s.Node; }
  88. /// Returns the ResNo for a register ref
  89. unsigned getResNo() const { assert (kind==SDNODE); return u.s.ResNo; }
  90. /// Returns the Value* for a constant
  91. const Value *getConst() const { assert (kind==CONST); return u.Const; }
  92. /// Returns the FrameIx for a stack object
  93. unsigned getFrameIx() const { assert (kind==FRAMEIX); return u.FrameIx; }
  94. /// Returns the Virtual Register for a VReg
  95. unsigned getVReg() const { assert (kind==VREG); return u.VReg; }
  96. /// Returns whether this is an indirect value.
  97. bool isIndirect() const { return IsIndirect; }
  98. /// Returns the DebugLoc.
  99. DebugLoc getDebugLoc() const { return DL; }
  100. /// Returns the SDNodeOrder. This is the order of the preceding node in the
  101. /// input.
  102. unsigned getOrder() const { return Order; }
  103. /// setIsInvalidated / isInvalidated - Setter / getter of the "Invalidated"
  104. /// property. A SDDbgValue is invalid if the SDNode that produces the value is
  105. /// deleted.
  106. void setIsInvalidated() { Invalid = true; }
  107. bool isInvalidated() const { return Invalid; }
  108. /// setIsEmitted / isEmitted - Getter/Setter for flag indicating that this
  109. /// SDDbgValue has been emitted to an MBB.
  110. void setIsEmitted() { Emitted = true; }
  111. bool isEmitted() const { return Emitted; }
  112. /// clearIsEmitted - Reset Emitted flag, for certain special cases where
  113. /// dbg.addr is emitted twice.
  114. void clearIsEmitted() { Emitted = false; }
  115. LLVM_DUMP_METHOD void dump() const;
  116. LLVM_DUMP_METHOD void print(raw_ostream &OS) const;
  117. };
  118. /// Holds the information from a dbg_label node through SDISel.
  119. /// We do not use SDValue here to avoid including its header.
  120. class SDDbgLabel {
  121. MDNode *Label;
  122. DebugLoc DL;
  123. unsigned Order;
  124. public:
  125. SDDbgLabel(MDNode *Label, DebugLoc dl, unsigned O)
  126. : Label(Label), DL(std::move(dl)), Order(O) {}
  127. /// Returns the MDNode pointer for the label.
  128. MDNode *getLabel() const { return Label; }
  129. /// Returns the DebugLoc.
  130. DebugLoc getDebugLoc() const { return DL; }
  131. /// Returns the SDNodeOrder. This is the order of the preceding node in the
  132. /// input.
  133. unsigned getOrder() const { return Order; }
  134. };
  135. } // end llvm namespace
  136. #endif