/home/arjun/llvm-project/llvm/include/llvm/ADT/ilist_base.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===- llvm/ADT/ilist_base.h - Intrusive List Base --------------*- C++ -*-===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | #ifndef LLVM_ADT_ILIST_BASE_H |
10 | | #define LLVM_ADT_ILIST_BASE_H |
11 | | |
12 | | #include "llvm/ADT/ilist_node_base.h" |
13 | | #include <cassert> |
14 | | |
15 | | namespace llvm { |
16 | | |
17 | | /// Implementations of list algorithms using ilist_node_base. |
18 | | template <bool EnableSentinelTracking> class ilist_base { |
19 | | public: |
20 | | using node_base_type = ilist_node_base<EnableSentinelTracking>; |
21 | | |
22 | 0 | static void insertBeforeImpl(node_base_type &Next, node_base_type &N) { |
23 | 0 | node_base_type &Prev = *Next.getPrev(); |
24 | 0 | N.setNext(&Next); |
25 | 0 | N.setPrev(&Prev); |
26 | 0 | Prev.setNext(&N); |
27 | 0 | Next.setPrev(&N); |
28 | 0 | } |
29 | | |
30 | 0 | static void removeImpl(node_base_type &N) { |
31 | 0 | node_base_type *Prev = N.getPrev(); |
32 | 0 | node_base_type *Next = N.getNext(); |
33 | 0 | Next->setPrev(Prev); |
34 | 0 | Prev->setNext(Next); |
35 | 0 |
|
36 | 0 | // Not strictly necessary, but helps catch a class of bugs. |
37 | 0 | N.setPrev(nullptr); |
38 | 0 | N.setNext(nullptr); |
39 | 0 | } |
40 | | |
41 | | static void removeRangeImpl(node_base_type &First, node_base_type &Last) { |
42 | | node_base_type *Prev = First.getPrev(); |
43 | | node_base_type *Final = Last.getPrev(); |
44 | | Last.setPrev(Prev); |
45 | | Prev->setNext(&Last); |
46 | | |
47 | | // Not strictly necessary, but helps catch a class of bugs. |
48 | | First.setPrev(nullptr); |
49 | | Final->setNext(nullptr); |
50 | | } |
51 | | |
52 | | static void transferBeforeImpl(node_base_type &Next, node_base_type &First, |
53 | 0 | node_base_type &Last) { |
54 | 0 | if (&Next == &Last || &First == &Last) |
55 | 0 | return; |
56 | 0 | |
57 | 0 | // Position cannot be contained in the range to be transferred. |
58 | 0 | assert(&Next != &First && |
59 | 0 | // Check for the most common mistake. |
60 | 0 | "Insertion point can't be one of the transferred nodes"); |
61 | 0 |
|
62 | 0 | node_base_type &Final = *Last.getPrev(); |
63 | 0 |
|
64 | 0 | // Detach from old list/position. |
65 | 0 | First.getPrev()->setNext(&Last); |
66 | 0 | Last.setPrev(First.getPrev()); |
67 | 0 |
|
68 | 0 | // Splice [First, Final] into its new list/position. |
69 | 0 | node_base_type &Prev = *Next.getPrev(); |
70 | 0 | Final.setNext(&Next); |
71 | 0 | First.setPrev(&Prev); |
72 | 0 | Prev.setNext(&First); |
73 | 0 | Next.setPrev(&Final); |
74 | 0 | } |
75 | | |
76 | 0 | template <class T> static void insertBefore(T &Next, T &N) { |
77 | 0 | insertBeforeImpl(Next, N); |
78 | 0 | } Unexecuted instantiation: _ZN4llvm10ilist_baseILb1EE12insertBeforeINS_15ilist_node_implINS_12ilist_detail12node_optionsIN4mlir9OperationELb1ELb0EvEEEEEEvRT_SB_ Unexecuted instantiation: _ZN4llvm10ilist_baseILb1EE12insertBeforeINS_15ilist_node_implINS_12ilist_detail12node_optionsIN4mlir5BlockELb1ELb0EvEEEEEEvRT_SB_ Unexecuted instantiation: _ZN4llvm10ilist_baseILb1EE12insertBeforeINS_15ilist_node_implINS_12ilist_detail12node_optionsINS_13AllocatorListINS_4yaml5TokenENS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE4NodeELb1ELb0EvEEEEEEvRT_SH_ |
79 | | |
80 | 0 | template <class T> static void remove(T &N) { removeImpl(N); } Unexecuted instantiation: _ZN4llvm10ilist_baseILb1EE6removeINS_15ilist_node_implINS_12ilist_detail12node_optionsIN4mlir9OperationELb1ELb0EvEEEEEEvRT_ Unexecuted instantiation: _ZN4llvm10ilist_baseILb1EE6removeINS_15ilist_node_implINS_12ilist_detail12node_optionsIN4mlir5BlockELb1ELb0EvEEEEEEvRT_ Unexecuted instantiation: _ZN4llvm10ilist_baseILb1EE6removeINS_15ilist_node_implINS_12ilist_detail12node_optionsINS_13AllocatorListINS_4yaml5TokenENS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEE4NodeELb1ELb0EvEEEEEEvRT_ |
81 | | template <class T> static void removeRange(T &First, T &Last) { |
82 | | removeRangeImpl(First, Last); |
83 | | } |
84 | | |
85 | 0 | template <class T> static void transferBefore(T &Next, T &First, T &Last) { |
86 | 0 | transferBeforeImpl(Next, First, Last); |
87 | 0 | } Unexecuted instantiation: _ZN4llvm10ilist_baseILb1EE14transferBeforeINS_15ilist_node_implINS_12ilist_detail12node_optionsIN4mlir5BlockELb1ELb0EvEEEEEEvRT_SB_SB_ Unexecuted instantiation: _ZN4llvm10ilist_baseILb1EE14transferBeforeINS_15ilist_node_implINS_12ilist_detail12node_optionsIN4mlir9OperationELb1ELb0EvEEEEEEvRT_SB_SB_ |
88 | | }; |
89 | | |
90 | | } // end namespace llvm |
91 | | |
92 | | #endif // LLVM_ADT_ILIST_BASE_H |