diff --git a/src/common/intrusive_list.h b/src/common/intrusive_list.h index 9e656f0b..c4c90345 100644 --- a/src/common/intrusive_list.h +++ b/src/common/intrusive_list.h @@ -54,38 +54,37 @@ public: using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; + /** + * Inserts a node at the given location indicated by an iterator. + * + * @param location The location to insert the node. + * @param new_node The node to add. + */ + iterator insert(iterator location, pointer new_node) { + auto existing_node = location.AsNodePointer(); + + new_node->next = existing_node; + new_node->prev = existing_node->prev; + existing_node->prev->next = new_node; + existing_node->prev = new_node; + + return iterator(root.get(), new_node); + } + /** * Add an entry to the start of the list. * @param node Node to add to the list. */ - void Prepend(reference node) { - AddAfter(root.get(), &node); + void push_front(pointer node) { + insert(begin(), node); } /** * Add an entry to the end of the list - * @param node Node to add to the list. + * @param node Node to add to the list. */ - void Append(reference node) { - AddBefore(root.get(), &node); - } - - /** - * Add an entry after an existing node in this list - * @param existing_node Node to add new_node after. Must already be member of the list. - * @param new_node Node to add to the list. - */ - void AddAfter(reference existing, reference node) { - AddAfter(&existing, &node); - } - - /** - * Add an entry before an existing node in this list - * @param existing_node Node to add new_node before. Must already be member of the list. - * @param new_node Node to add to the list. - */ - void AddBefore(reference existing, reference node) { - AddBefore(&existing, &node); + void push_back(pointer node) { + insert(end(), node); } /** @@ -133,20 +132,6 @@ public: } private: - void AddAfter(IntrusiveListNode* existing_node, IntrusiveListNode* new_node) { - new_node->next = existing_node->next; - new_node->prev = existing_node; - existing_node->next->prev = new_node; - existing_node->next = new_node; - } - - void AddBefore(IntrusiveListNode* existing_node, IntrusiveListNode* new_node) { - new_node->next = existing_node; - new_node->prev = existing_node->prev; - existing_node->prev->next = new_node; - existing_node->prev = new_node; - } - std::shared_ptr> root = std::make_shared>(); }; @@ -211,6 +196,10 @@ public: return std::addressof(operator*()); } + node_pointer AsNodePointer() const { + return node; + } + private: friend class IntrusiveList; node_pointer root = nullptr; diff --git a/src/frontend/ir/ir_emitter.cpp b/src/frontend/ir/ir_emitter.cpp index a4381db6..1fd5d5f4 100644 --- a/src/frontend/ir/ir_emitter.cpp +++ b/src/frontend/ir/ir_emitter.cpp @@ -515,7 +515,7 @@ IR::Value IREmitter::Inst(IR::Opcode op, std::initializer_list args) index++; }); - block.instructions.Append(*inst); + block.instructions.push_back(inst); return IR::Value(inst); }