| 1 | //===-------- stl_extras.h - Useful STL related functions-------*- 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 | // This file is a part of the ORC runtime support library. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef ORC_RT_STL_EXTRAS_H |
| 14 | #define |
| 15 | |
| 16 | #include <cstdint> |
| 17 | #include <utility> |
| 18 | #include <tuple> |
| 19 | |
| 20 | namespace orc_rt { |
| 21 | |
| 22 | /// Substitute for std::identity. |
| 23 | /// Switch to std::identity once we can use c++20. |
| 24 | template <class Ty> struct identity { |
| 25 | using is_transparent = void; |
| 26 | using argument_type = Ty; |
| 27 | |
| 28 | Ty &operator()(Ty &self) const { return self; } |
| 29 | const Ty &operator()(const Ty &self) const { return self; } |
| 30 | }; |
| 31 | |
| 32 | /// Substitute for std::bit_ceil. |
| 33 | constexpr uint64_t bit_ceil(uint64_t Val) noexcept { |
| 34 | Val |= (Val >> 1); |
| 35 | Val |= (Val >> 2); |
| 36 | Val |= (Val >> 4); |
| 37 | Val |= (Val >> 8); |
| 38 | Val |= (Val >> 16); |
| 39 | Val |= (Val >> 32); |
| 40 | return Val + 1; |
| 41 | } |
| 42 | |
| 43 | } // namespace orc_rt |
| 44 | |
| 45 | #endif // ORC_RT_STL_EXTRAS |
| 46 | |