1 //===- llvm/ADT/ilist_node_base.h - Intrusive List Node Base -----*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_ADT_ILIST_NODE_BASE_H
11 #define LLVM_ADT_ILIST_NODE_BASE_H
13 #include "llvm/ADT/PointerIntPair.h"
17 /// Base class for ilist nodes.
19 /// Optionally tracks whether this node is the sentinel.
20 template <bool EnableSentinelTracking> class ilist_node_base;
22 template <> class ilist_node_base<false> {
23 ilist_node_base *Prev = nullptr;
24 ilist_node_base *Next = nullptr;
27 void setPrev(ilist_node_base *Prev) { this->Prev = Prev; }
28 void setNext(ilist_node_base *Next) { this->Next = Next; }
29 ilist_node_base *getPrev() const { return Prev; }
30 ilist_node_base *getNext() const { return Next; }
32 bool isKnownSentinel() const { return false; }
33 void initializeSentinel() {}
36 template <> class ilist_node_base<true> {
37 PointerIntPair<ilist_node_base *, 1> PrevAndSentinel;
38 ilist_node_base *Next = nullptr;
41 void setPrev(ilist_node_base *Prev) { PrevAndSentinel.setPointer(Prev); }
42 void setNext(ilist_node_base *Next) { this->Next = Next; }
43 ilist_node_base *getPrev() const { return PrevAndSentinel.getPointer(); }
44 ilist_node_base *getNext() const { return Next; }
46 bool isSentinel() const { return PrevAndSentinel.getInt(); }
47 bool isKnownSentinel() const { return isSentinel(); }
48 void initializeSentinel() { PrevAndSentinel.setInt(true); }
51 } // end namespace llvm
53 #endif // LLVM_ADT_ILIST_NODE_BASE_H