[llvm] [SandboxIR] Add BasicBlock and adds functionality to Function and Context (PR #97637)
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 8 14:09:19 PDT 2024
================
@@ -205,6 +210,53 @@ class Constant : public sandboxir::User {
#endif
};
+/// The BasicBlock::iterator.
+class BBIterator {
+public:
+ using difference_type = std::ptrdiff_t;
+ using value_type = Instruction;
+ using pointer = value_type *;
+ using reference = value_type &;
+ using iterator_category = std::bidirectional_iterator_tag;
+
+private:
+ llvm::BasicBlock *BB;
+ llvm::BasicBlock::iterator It;
+ Context *Ctx;
+ pointer getI(llvm::BasicBlock::iterator It) const;
+
+public:
+ BBIterator() : BB(nullptr), Ctx(nullptr) {}
+ BBIterator(llvm::BasicBlock *BB, llvm::BasicBlock::iterator It, Context *Ctx)
+ : BB(BB), It(It), Ctx(Ctx) {}
+ reference operator*() const { return *getI(It); }
+ BBIterator &operator++();
+ BBIterator operator++(int) {
+ auto Copy = *this;
+ ++*this;
+ return Copy;
+ }
+ BBIterator &operator--();
+ BBIterator operator--(int) {
+ auto Copy = *this;
+ --*this;
+ return Copy;
+ }
+ bool operator==(const BBIterator &Other) const {
+ assert(Ctx == Other.Ctx && "BBIterators in different context!");
+ return It == Other.It;
+ }
+ bool operator!=(const BBIterator &Other) const { return !(*this == Other); }
+ /// \Returns true if the internal iterator is at the beginning of the IR BB.
+ /// NOTE: This is meant to be used internally, during the construction of a
+ /// SBBB, during which SBBB->begin() fails due to the missing mapping of
+ /// BB->begin() to SandboxIR.
+ bool atBegin() const;
----------------
aeubanks wrote:
can you remove the declaration if it's unused?
https://github.com/llvm/llvm-project/pull/97637
More information about the llvm-commits
mailing list