diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h index 42291d45da2be..a1c554677f8bf 100644 --- a/llvm/include/llvm/IR/DebugInfoMetadata.h +++ b/llvm/include/llvm/IR/DebugInfoMetadata.h @@ -3150,6 +3150,67 @@ template <> struct DenseMapInfo { static bool isEqual(const FragInfo &A, const FragInfo &B) { return A == B; } }; +/// Holds a DIExpression and keeps track of how many operands have been consumed +/// so far. +class DIExpressionCursor { + DIExpression::expr_op_iterator Start, End; + +public: + DIExpressionCursor(const DIExpression *Expr) { + if (!Expr) { + assert(Start == End); + return; + } + Start = Expr->expr_op_begin(); + End = Expr->expr_op_end(); + } + + DIExpressionCursor(ArrayRef Expr) + : Start(Expr.begin()), End(Expr.end()) {} + + DIExpressionCursor(const DIExpressionCursor &) = default; + + /// Consume one operation. + std::optional take() { + if (Start == End) + return std::nullopt; + return *(Start++); + } + + /// Consume N operations. + void consume(unsigned N) { std::advance(Start, N); } + + /// Return the current operation. + std::optional peek() const { + if (Start == End) + return std::nullopt; + return *(Start); + } + + /// Return the next operation. + std::optional peekNext() const { + if (Start == End) + return std::nullopt; + + auto Next = Start.getNext(); + if (Next == End) + return std::nullopt; + + return *Next; + } + + /// Determine whether there are any operations left in this expression. + operator bool() const { return Start != End; } + + DIExpression::expr_op_iterator begin() const { return Start; } + DIExpression::expr_op_iterator end() const { return End; } + + /// Retrieve the fragment information, if any. + std::optional getFragmentInfo() const { + return DIExpression::getFragmentInfo(Start, End); + } +}; + /// Global variables. /// /// TODO: Remove DisplayName. It's always equal to Name. diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h index 667a9efc6f6c0..4daa78b15b8e2 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h @@ -31,67 +31,6 @@ class DIELoc; class TargetRegisterInfo; class MachineLocation; -/// Holds a DIExpression and keeps track of how many operands have been consumed -/// so far. -class DIExpressionCursor { - DIExpression::expr_op_iterator Start, End; - -public: - DIExpressionCursor(const DIExpression *Expr) { - if (!Expr) { - assert(Start == End); - return; - } - Start = Expr->expr_op_begin(); - End = Expr->expr_op_end(); - } - - DIExpressionCursor(ArrayRef Expr) - : Start(Expr.begin()), End(Expr.end()) {} - - DIExpressionCursor(const DIExpressionCursor &) = default; - - /// Consume one operation. - std::optional take() { - if (Start == End) - return std::nullopt; - return *(Start++); - } - - /// Consume N operations. - void consume(unsigned N) { std::advance(Start, N); } - - /// Return the current operation. - std::optional peek() const { - if (Start == End) - return std::nullopt; - return *(Start); - } - - /// Return the next operation. - std::optional peekNext() const { - if (Start == End) - return std::nullopt; - - auto Next = Start.getNext(); - if (Next == End) - return std::nullopt; - - return *Next; - } - - /// Determine whether there are any operations left in this expression. - operator bool() const { return Start != End; } - - DIExpression::expr_op_iterator begin() const { return Start; } - DIExpression::expr_op_iterator end() const { return End; } - - /// Retrieve the fragment information, if any. - std::optional getFragmentInfo() const { - return DIExpression::getFragmentInfo(Start, End); - } -}; - /// Base class containing the logic for constructing DWARF expressions /// independently of whether they are emitted into a DIE or into a .debug_loc /// entry.