[clang] [llvm] [LLVM] Add InsertPosition union-type to remove overloads of Instruction-creation (PR #94226)
Nikita Popov via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 19 06:17:24 PDT 2024
================
@@ -44,6 +44,23 @@ template <> struct ilist_alloc_traits<Instruction> {
iterator_range<simple_ilist<DbgRecord>::iterator>
getDbgRecordRange(DbgMarker *);
+class InsertPosition {
+ using InstListType = SymbolTableList<Instruction, ilist_iterator_bits<true>,
+ ilist_parent<BasicBlock>>;
+ InstListType::iterator InsertAt;
+
+public:
+ InsertPosition(std::nullopt_t) : InsertAt() {}
+ InsertPosition(std::nullptr_t) : InsertAt() {}
+ // LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
+ // "BasicBlock::iterator")
+ InsertPosition(Instruction *InsertBefore);
+ InsertPosition(BasicBlock *InsertAtEnd);
+ InsertPosition(InstListType::iterator InsertAt) : InsertAt(InsertAt) {}
+ operator InstListType::iterator() const { return InsertAt; }
+ bool IsValid() const { return InsertAt.getNodePtr(); }
----------------
nikic wrote:
I think you added an isValid() method to the iterator itself?
https://github.com/llvm/llvm-project/pull/94226
More information about the cfe-commits
mailing list