Skip to content

[NFC] Move DIExpressionCursor to DebugInfoMetadata.h #69768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions llvm/include/llvm/IR/DebugInfoMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -3150,6 +3150,67 @@ template <> struct DenseMapInfo<DIExpression::FragmentInfo> {
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<uint64_t> Expr)
: Start(Expr.begin()), End(Expr.end()) {}

DIExpressionCursor(const DIExpressionCursor &) = default;

/// Consume one operation.
std::optional<DIExpression::ExprOperand> 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<DIExpression::ExprOperand> peek() const {
if (Start == End)
return std::nullopt;
return *(Start);
}

/// Return the next operation.
std::optional<DIExpression::ExprOperand> 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<DIExpression::FragmentInfo> getFragmentInfo() const {
return DIExpression::getFragmentInfo(Start, End);
}
};

/// Global variables.
///
/// TODO: Remove DisplayName. It's always equal to Name.
Expand Down
61 changes: 0 additions & 61 deletions llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t> Expr)
: Start(Expr.begin()), End(Expr.end()) {}

DIExpressionCursor(const DIExpressionCursor &) = default;

/// Consume one operation.
std::optional<DIExpression::ExprOperand> 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<DIExpression::ExprOperand> peek() const {
if (Start == End)
return std::nullopt;
return *(Start);
}

/// Return the next operation.
std::optional<DIExpression::ExprOperand> 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<DIExpression::FragmentInfo> 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.
Expand Down
Loading