aboutsummaryrefslogtreecommitdiff
path: root/compiler-rt/lib/orc/stl_extras.h
blob: ad7b661024065ff9a07c35c506286680949696b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//===-------- stl_extras.h - Useful STL related functions-------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file is a part of the ORC runtime support library.
//
//===----------------------------------------------------------------------===//

#ifndef ORC_RT_STL_EXTRAS_H
#define ORC_RT_STL_EXTRAS_H

#include <cstdint>
#include <utility>
#include <tuple>

namespace orc_rt {

/// Substitute for std::identity.
/// Switch to std::identity once we can use c++20.
template <class Ty> struct identity {
  using is_transparent = void;
  using argument_type = Ty;

  Ty &operator()(Ty &self) const { return self; }
  const Ty &operator()(const Ty &self) const { return self; }
};

/// Substitute for std::bit_ceil.
constexpr uint64_t bit_ceil(uint64_t Val) noexcept {
  Val |= (Val >> 1);
  Val |= (Val >> 2);
  Val |= (Val >> 4);
  Val |= (Val >> 8);
  Val |= (Val >> 16);
  Val |= (Val >> 32);
  return Val + 1;
}

} // namespace orc_rt

#endif // ORC_RT_STL_EXTRAS