[llvm] a3f9066 - Add functions peekNextN(unsigned) and assignNewExpr(ArrayRef<uint64_t>) to DIExpressionCursor (#71717)

via llvm-commits llvm-commits at lists.llvm.org
Wed May 29 15:42:35 PDT 2024


Author: Shubham Sandeep Rastogi
Date: 2024-05-29T15:42:31-07:00
New Revision: a3f9066e99f3685b4f2271f54ba73210396c00b4

URL: https://github.com/llvm/llvm-project/commit/a3f9066e99f3685b4f2271f54ba73210396c00b4
DIFF: https://github.com/llvm/llvm-project/commit/a3f9066e99f3685b4f2271f54ba73210396c00b4.diff

LOG: Add functions peekNextN(unsigned) and assignNewExpr(ArrayRef<uint64_t>) to DIExpressionCursor (#71717)

This commit adds two functions to the DIExpressionCursor class.

`peekNextN(unsigned)` works like peekNext, but lets you peek the next
Nth element
    
`assignNewExpr(ArrayRef<uint64_t>)` lets you assign a new expression to
the same DIExpressionCursor object

This is part of a stack of patches, it comes after
https://github.com/llvm/llvm-project/pull/69768

Added: 
    

Modified: 
    llvm/include/llvm/IR/DebugInfoMetadata.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h
index a1c554677f8bf..555bd623ad9ef 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -3199,6 +3199,23 @@ class DIExpressionCursor {
     return *Next;
   }
 
+  std::optional<DIExpression::ExprOperand> peekNextN(unsigned N) const {
+    if (Start == End)
+      return std::nullopt;
+    DIExpression::expr_op_iterator Nth = Start;
+    for (unsigned I = 0; I < N; I++) {
+      Nth = Nth.getNext();
+      if (Nth == End)
+        return std::nullopt;
+    }
+    return *Nth;
+  }
+
+  void assignNewExpr(ArrayRef<uint64_t> Expr) {
+    this->Start = DIExpression::expr_op_iterator(Expr.begin());
+    this->End = DIExpression::expr_op_iterator(Expr.end());
+  }
+
   /// Determine whether there are any operations left in this expression.
   operator bool() const { return Start != End; }
 


        


More information about the llvm-commits mailing list