1fe6060f1SDimitry Andric //===-------- stl_extras.h - Useful STL related functions-------*- C++ -*-===// 2fe6060f1SDimitry Andric // 3fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6fe6060f1SDimitry Andric // 7fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 8fe6060f1SDimitry Andric // 9fe6060f1SDimitry Andric // This file is a part of the ORC runtime support library. 10fe6060f1SDimitry Andric // 11fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 12fe6060f1SDimitry Andric 13fe6060f1SDimitry Andric #ifndef ORC_RT_STL_EXTRAS_H 14fe6060f1SDimitry Andric #define ORC_RT_STL_EXTRAS_H 15fe6060f1SDimitry Andric 16*5f757f3fSDimitry Andric #include <cstdint> 17fe6060f1SDimitry Andric #include <utility> 18fe6060f1SDimitry Andric #include <tuple> 19fe6060f1SDimitry Andric 20fe6060f1SDimitry Andric namespace __orc_rt { 21fe6060f1SDimitry Andric 22bdd1243dSDimitry Andric /// Substitute for std::identity. 23bdd1243dSDimitry Andric /// Switch to std::identity once we can use c++20. 24bdd1243dSDimitry Andric template <class Ty> struct identity { 25bdd1243dSDimitry Andric using is_transparent = void; 26bdd1243dSDimitry Andric using argument_type = Ty; 27fe6060f1SDimitry Andric operatoridentity28bdd1243dSDimitry Andric Ty &operator()(Ty &self) const { return self; } operatoridentity29bdd1243dSDimitry Andric const Ty &operator()(const Ty &self) const { return self; } 30bdd1243dSDimitry Andric }; 31fe6060f1SDimitry Andric 32*5f757f3fSDimitry Andric /// Substitute for std::bit_ceil. bit_ceil(uint64_t Val)33*5f757f3fSDimitry Andricconstexpr uint64_t bit_ceil(uint64_t Val) noexcept { 34*5f757f3fSDimitry Andric Val |= (Val >> 1); 35*5f757f3fSDimitry Andric Val |= (Val >> 2); 36*5f757f3fSDimitry Andric Val |= (Val >> 4); 37*5f757f3fSDimitry Andric Val |= (Val >> 8); 38*5f757f3fSDimitry Andric Val |= (Val >> 16); 39*5f757f3fSDimitry Andric Val |= (Val >> 32); 40*5f757f3fSDimitry Andric return Val + 1; 41*5f757f3fSDimitry Andric } 42*5f757f3fSDimitry Andric 43fe6060f1SDimitry Andric } // namespace __orc_rt 44fe6060f1SDimitry Andric 45fe6060f1SDimitry Andric #endif // ORC_RT_STL_EXTRAS 46