Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / lib / orc / interval_set.h
blob20f40f9c7d370c1d9901849fb945059f027d44f9
1 //===--------- interval_set.h - A sorted interval set -----------*- 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 // Implements a coalescing interval set.
11 //===----------------------------------------------------------------------===//
13 #ifndef ORC_RT_INTERVAL_SET_H
14 #define ORC_RT_INTERVAL_SET_H
16 #include "interval_map.h"
18 namespace __orc_rt {
20 /// Implements a coalescing interval set.
21 ///
22 /// Adjacent intervals are coalesced.
23 ///
24 /// NOTE: The interface is kept mostly compatible with LLVM's IntervalMap
25 /// collection to make it easy to swap over in the future if we choose
26 /// to.
27 template <typename KeyT, IntervalCoalescing Coalescing>
28 class IntervalSet {
29 private:
30 using ImplMap = IntervalMap<KeyT, std::monostate, Coalescing>;
31 public:
33 using value_type = std::pair<KeyT, KeyT>;
35 class const_iterator {
36 friend class IntervalSet;
37 public:
38 using difference_type = typename ImplMap::iterator::difference_type;
39 using value_type = IntervalSet::value_type;
40 using pointer = const value_type *;
41 using reference = const value_type &;
42 using iterator_category = std::input_iterator_tag;
44 const_iterator() = default;
45 const value_type &operator*() const { return I->first; }
46 const value_type *operator->() const { return &I->first; }
47 const_iterator &operator++() { ++I; return *this; }
48 const_iterator operator++(int) { auto Tmp = I; ++I; return Tmp; }
49 friend bool operator==(const const_iterator &LHS,
50 const const_iterator &RHS) {
51 return LHS.I == RHS.I;
53 friend bool operator!=(const const_iterator &LHS,
54 const const_iterator &RHS) {
55 return LHS.I != RHS.I;
57 private:
58 const_iterator(typename ImplMap::const_iterator I) : I(std::move(I)) {}
59 typename ImplMap::const_iterator I;
62 bool empty() const { return Map.empty(); }
64 void clear() { Map.clear(); }
66 const_iterator begin() const { return const_iterator(Map.begin()); }
67 const_iterator end() const { return const_iterator(Map.end()); }
69 const_iterator find(KeyT K) const {
70 return const_iterator(Map.find(K));
73 void insert(KeyT KS, KeyT KE) {
74 Map.insert(std::move(KS), std::move(KE), std::monostate());
77 void erase(KeyT KS, KeyT KE) {
78 Map.erase(KS, KE);
81 private:
82 ImplMap Map;
85 } // End namespace __orc_rt
87 #endif // ORC_RT_INTERVAL_SET_H