Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/ADT/FunctionExtras.h
Line
Count
Source (jump to first uncovered line)
1
//===- FunctionExtras.h - Function type erasure utilities -------*- 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
/// \file
9
/// This file provides a collection of function (or more generally, callable)
10
/// type erasure utilities supplementing those provided by the standard library
11
/// in `<function>`.
12
///
13
/// It provides `unique_function`, which works like `std::function` but supports
14
/// move-only callable objects.
15
///
16
/// Future plans:
17
/// - Add a `function` that provides const, volatile, and ref-qualified support,
18
///   which doesn't work with `std::function`.
19
/// - Provide support for specifying multiple signatures to type erase callable
20
///   objects with an overload set, such as those produced by generic lambdas.
21
/// - Expand to include a copyable utility that directly replaces std::function
22
///   but brings the above improvements.
23
///
24
/// Note that LLVM's utilities are greatly simplified by not supporting
25
/// allocators.
26
///
27
/// If the standard library ever begins to provide comparable facilities we can
28
/// consider switching to those.
29
///
30
//===----------------------------------------------------------------------===//
31
32
#ifndef LLVM_ADT_FUNCTION_EXTRAS_H
33
#define LLVM_ADT_FUNCTION_EXTRAS_H
34
35
#include "llvm/ADT/PointerIntPair.h"
36
#include "llvm/ADT/PointerUnion.h"
37
#include "llvm/Support/type_traits.h"
38
#include <memory>
39
40
namespace llvm {
41
42
template <typename FunctionT> class unique_function;
43
44
template <typename ReturnT, typename... ParamTs>
45
class unique_function<ReturnT(ParamTs...)> {
46
  static constexpr size_t InlineStorageSize = sizeof(void *) * 3;
47
48
  // MSVC has a bug and ICEs if we give it a particular dependent value
49
  // expression as part of the `std::conditional` below. To work around this,
50
  // we build that into a template struct's constexpr bool.
51
  template <typename T> struct IsSizeLessThanThresholdT {
52
    static constexpr bool value = sizeof(T) <= (2 * sizeof(void *));
53
  };
54
55
  // Provide a type function to map parameters that won't observe extra copies
56
  // or moves and which are small enough to likely pass in register to values
57
  // and all other types to l-value reference types. We use this to compute the
58
  // types used in our erased call utility to minimize copies and moves unless
59
  // doing so would force things unnecessarily into memory.
60
  //
61
  // The heuristic used is related to common ABI register passing conventions.
62
  // It doesn't have to be exact though, and in one way it is more strict
63
  // because we want to still be able to observe either moves *or* copies.
64
  template <typename T>
65
  using AdjustedParamT = typename std::conditional<
66
      !std::is_reference<T>::value &&
67
          llvm::is_trivially_copy_constructible<T>::value &&
68
          llvm::is_trivially_move_constructible<T>::value &&
69
          IsSizeLessThanThresholdT<T>::value,
70
      T, T &>::type;
71
72
  // The type of the erased function pointer we use as a callback to dispatch to
73
  // the stored callable when it is trivial to move and destroy.
74
  using CallPtrT = ReturnT (*)(void *CallableAddr,
75
                               AdjustedParamT<ParamTs>... Params);
76
  using MovePtrT = void (*)(void *LHSCallableAddr, void *RHSCallableAddr);
77
  using DestroyPtrT = void (*)(void *CallableAddr);
78
79
  /// A struct to hold a single trivial callback with sufficient alignment for
80
  /// our bitpacking.
81
  struct alignas(8) TrivialCallback {
82
    CallPtrT CallPtr;
83
  };
84
85
  /// A struct we use to aggregate three callbacks when we need full set of
86
  /// operations.
87
  struct alignas(8) NonTrivialCallbacks {
88
    CallPtrT CallPtr;
89
    MovePtrT MovePtr;
90
    DestroyPtrT DestroyPtr;
91
  };
92
93
  // Create a pointer union between either a pointer to a static trivial call
94
  // pointer in a struct or a pointer to a static struct of the call, move, and
95
  // destroy pointers.
96
  using CallbackPointerUnionT =
97
      PointerUnion<TrivialCallback *, NonTrivialCallbacks *>;
98
99
  // The main storage buffer. This will either have a pointer to out-of-line
100
  // storage or an inline buffer storing the callable.
101
  union StorageUnionT {
102
    // For out-of-line storage we keep a pointer to the underlying storage and
103
    // the size. This is enough to deallocate the memory.
104
    struct OutOfLineStorageT {
105
      void *StoragePtr;
106
      size_t Size;
107
      size_t Alignment;
108
    } OutOfLineStorage;
109
    static_assert(
110
        sizeof(OutOfLineStorageT) <= InlineStorageSize,
111
        "Should always use all of the out-of-line storage for inline storage!");
112
113
    // For in-line storage, we just provide an aligned character buffer. We
114
    // provide three pointers worth of storage here.
115
    typename std::aligned_storage<InlineStorageSize, alignof(void *)>::type
116
        InlineStorage;
117
  } StorageUnion;
118
119
  // A compressed pointer to either our dispatching callback or our table of
120
  // dispatching callbacks and the flag for whether the callable itself is
121
  // stored inline or not.
122
  PointerIntPair<CallbackPointerUnionT, 1, bool> CallbackAndInlineFlag;
123
124
2.84k
  bool isInlineStorage() const { return CallbackAndInlineFlag.getInt(); }
llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::isInlineStorage() const
Line
Count
Source
124
818
  bool isInlineStorage() const { return CallbackAndInlineFlag.getInt(); }
llvm::unique_function<void (llvm::StringRef, llvm::Any)>::isInlineStorage() const
Line
Count
Source
124
1.66k
  bool isInlineStorage() const { return CallbackAndInlineFlag.getInt(); }
llvm::unique_function<void (llvm::StringRef)>::isInlineStorage() const
Line
Count
Source
124
40
  bool isInlineStorage() const { return CallbackAndInlineFlag.getInt(); }
llvm::unique_function<void (clang::Token const&)>::isInlineStorage() const
Line
Count
Source
124
326
  bool isInlineStorage() const { return CallbackAndInlineFlag.getInt(); }
125
126
2.84k
  bool isTrivialCallback() const {
127
2.84k
    return CallbackAndInlineFlag.getPointer().template is<TrivialCallback *>();
128
2.84k
  }
llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::isTrivialCallback() const
Line
Count
Source
126
818
  bool isTrivialCallback() const {
127
818
    return CallbackAndInlineFlag.getPointer().template is<TrivialCallback *>();
128
818
  }
llvm::unique_function<void (llvm::StringRef, llvm::Any)>::isTrivialCallback() const
Line
Count
Source
126
1.66k
  bool isTrivialCallback() const {
127
1.66k
    return CallbackAndInlineFlag.getPointer().template is<TrivialCallback *>();
128
1.66k
  }
llvm::unique_function<void (llvm::StringRef)>::isTrivialCallback() const
Line
Count
Source
126
40
  bool isTrivialCallback() const {
127
40
    return CallbackAndInlineFlag.getPointer().template is<TrivialCallback *>();
128
40
  }
llvm::unique_function<void (clang::Token const&)>::isTrivialCallback() const
Line
Count
Source
126
326
  bool isTrivialCallback() const {
127
326
    return CallbackAndInlineFlag.getPointer().template is<TrivialCallback *>();
128
326
  }
129
130
2.68k
  CallPtrT getTrivialCallback() const {
131
2.68k
    return CallbackAndInlineFlag.getPointer().template get<TrivialCallback *>()->CallPtr;
132
2.68k
  }
llvm::unique_function<void (llvm::StringRef, llvm::Any)>::getTrivialCallback() const
Line
Count
Source
130
1.60k
  CallPtrT getTrivialCallback() const {
131
1.60k
    return CallbackAndInlineFlag.getPointer().template get<TrivialCallback *>()->CallPtr;
132
1.60k
  }
llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::getTrivialCallback() const
Line
Count
Source
130
794
  CallPtrT getTrivialCallback() const {
131
794
    return CallbackAndInlineFlag.getPointer().template get<TrivialCallback *>()->CallPtr;
132
794
  }
llvm::unique_function<void (llvm::StringRef)>::getTrivialCallback() const
Line
Count
Source
130
12
  CallPtrT getTrivialCallback() const {
131
12
    return CallbackAndInlineFlag.getPointer().template get<TrivialCallback *>()->CallPtr;
132
12
  }
llvm::unique_function<void (clang::Token const&)>::getTrivialCallback() const
Line
Count
Source
130
272
  CallPtrT getTrivialCallback() const {
131
272
    return CallbackAndInlineFlag.getPointer().template get<TrivialCallback *>()->CallPtr;
132
272
  }
133
134
0
  NonTrivialCallbacks *getNonTrivialCallbacks() const {
135
0
    return CallbackAndInlineFlag.getPointer()
136
0
        .template get<NonTrivialCallbacks *>();
137
0
  }
Unexecuted instantiation: llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::getNonTrivialCallbacks() const
Unexecuted instantiation: llvm::unique_function<void (llvm::StringRef, llvm::Any)>::getNonTrivialCallbacks() const
Unexecuted instantiation: llvm::unique_function<void (llvm::StringRef)>::getNonTrivialCallbacks() const
Unexecuted instantiation: llvm::unique_function<void (clang::Token const&)>::getNonTrivialCallbacks() const
138
139
2.87k
  void *getInlineStorage() { return &StorageUnion.InlineStorage; }
llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::getInlineStorage()
Line
Count
Source
139
818
  void *getInlineStorage() { return &StorageUnion.InlineStorage; }
llvm::unique_function<void (llvm::StringRef, llvm::Any)>::getInlineStorage()
Line
Count
Source
139
1.66k
  void *getInlineStorage() { return &StorageUnion.InlineStorage; }
llvm::unique_function<void (llvm::StringRef)>::getInlineStorage()
Line
Count
Source
139
40
  void *getInlineStorage() { return &StorageUnion.InlineStorage; }
llvm::unique_function<void (clang::Token const&)>::getInlineStorage()
Line
Count
Source
139
353
  void *getInlineStorage() { return &StorageUnion.InlineStorage; }
140
141
0
  void *getOutOfLineStorage() {
142
0
    return StorageUnion.OutOfLineStorage.StoragePtr;
143
0
  }
Unexecuted instantiation: llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::getOutOfLineStorage()
Unexecuted instantiation: llvm::unique_function<void (llvm::StringRef, llvm::Any)>::getOutOfLineStorage()
Unexecuted instantiation: llvm::unique_function<void (llvm::StringRef)>::getOutOfLineStorage()
Unexecuted instantiation: llvm::unique_function<void (clang::Token const&)>::getOutOfLineStorage()
144
0
  size_t getOutOfLineStorageSize() const {
145
0
    return StorageUnion.OutOfLineStorage.Size;
146
0
  }
Unexecuted instantiation: llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::getOutOfLineStorageSize() const
Unexecuted instantiation: llvm::unique_function<void (llvm::StringRef, llvm::Any)>::getOutOfLineStorageSize() const
Unexecuted instantiation: llvm::unique_function<void (llvm::StringRef)>::getOutOfLineStorageSize() const
Unexecuted instantiation: llvm::unique_function<void (clang::Token const&)>::getOutOfLineStorageSize() const
147
0
  size_t getOutOfLineStorageAlignment() const {
148
0
    return StorageUnion.OutOfLineStorage.Alignment;
149
0
  }
Unexecuted instantiation: llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::getOutOfLineStorageAlignment() const
Unexecuted instantiation: llvm::unique_function<void (llvm::StringRef, llvm::Any)>::getOutOfLineStorageAlignment() const
Unexecuted instantiation: llvm::unique_function<void (llvm::StringRef)>::getOutOfLineStorageAlignment() const
Unexecuted instantiation: llvm::unique_function<void (clang::Token const&)>::getOutOfLineStorageAlignment() const
150
151
0
  void setOutOfLineStorage(void *Ptr, size_t Size, size_t Alignment) {
152
0
    StorageUnion.OutOfLineStorage = {Ptr, Size, Alignment};
153
0
  }
Unexecuted instantiation: llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::setOutOfLineStorage(void*, unsigned long, unsigned long)
Unexecuted instantiation: llvm::unique_function<void (llvm::StringRef, llvm::Any)>::setOutOfLineStorage(void*, unsigned long, unsigned long)
Unexecuted instantiation: llvm::unique_function<void (llvm::StringRef)>::setOutOfLineStorage(void*, unsigned long, unsigned long)
154
155
  template <typename CallableT>
156
2.16k
  static ReturnT CallImpl(void *CallableAddr, AdjustedParamT<ParamTs>... Params) {
157
2.16k
    return (*reinterpret_cast<CallableT *>(CallableAddr))(
158
2.16k
        std::forward<ParamTs>(Params)...);
159
2.16k
  }
PassTimingInfo.cpp:bool llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::CallImpl<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_0>(void*, llvm::StringRef, llvm::Any&)
Line
Count
Source
156
657
  static ReturnT CallImpl(void *CallableAddr, AdjustedParamT<ParamTs>... Params) {
157
657
    return (*reinterpret_cast<CallableT *>(CallableAddr))(
158
657
        std::forward<ParamTs>(Params)...);
159
657
  }
PassTimingInfo.cpp:void llvm::unique_function<void (llvm::StringRef, llvm::Any)>::CallImpl<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_1>(void*, llvm::StringRef, llvm::Any&)
Line
Count
Source
156
657
  static ReturnT CallImpl(void *CallableAddr, AdjustedParamT<ParamTs>... Params) {
157
657
    return (*reinterpret_cast<CallableT *>(CallableAddr))(
158
657
        std::forward<ParamTs>(Params)...);
159
657
  }
Unexecuted instantiation: PassTimingInfo.cpp:void llvm::unique_function<void (llvm::StringRef)>::CallImpl<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_2>(void*, llvm::StringRef)
PassTimingInfo.cpp:void llvm::unique_function<void (llvm::StringRef, llvm::Any)>::CallImpl<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_3>(void*, llvm::StringRef, llvm::Any&)
Line
Count
Source
156
325
  static ReturnT CallImpl(void *CallableAddr, AdjustedParamT<ParamTs>... Params) {
157
325
    return (*reinterpret_cast<CallableT *>(CallableAddr))(
158
325
        std::forward<ParamTs>(Params)...);
159
325
  }
PassTimingInfo.cpp:void llvm::unique_function<void (llvm::StringRef, llvm::Any)>::CallImpl<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_4>(void*, llvm::StringRef, llvm::Any&)
Line
Count
Source
156
325
  static ReturnT CallImpl(void *CallableAddr, AdjustedParamT<ParamTs>... Params) {
157
325
    return (*reinterpret_cast<CallableT *>(CallableAddr))(
158
325
        std::forward<ParamTs>(Params)...);
159
325
  }
StandardInstrumentations.cpp:bool llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::CallImpl<llvm::PrintIRInstrumentation::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_0>(void*, llvm::StringRef, llvm::Any&)
Line
Count
Source
156
81
  static ReturnT CallImpl(void *CallableAddr, AdjustedParamT<ParamTs>... Params) {
157
81
    return (*reinterpret_cast<CallableT *>(CallableAddr))(
158
81
        std::forward<ParamTs>(Params)...);
159
81
  }
StandardInstrumentations.cpp:void llvm::unique_function<void (llvm::StringRef, llvm::Any)>::CallImpl<llvm::PrintIRInstrumentation::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_1>(void*, llvm::StringRef, llvm::Any&)
Line
Count
Source
156
111
  static ReturnT CallImpl(void *CallableAddr, AdjustedParamT<ParamTs>... Params) {
157
111
    return (*reinterpret_cast<CallableT *>(CallableAddr))(
158
111
        std::forward<ParamTs>(Params)...);
159
111
  }
StandardInstrumentations.cpp:void llvm::unique_function<void (llvm::StringRef)>::CallImpl<llvm::PrintIRInstrumentation::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_2>(void*, llvm::StringRef)
Line
Count
Source
156
8
  static ReturnT CallImpl(void *CallableAddr, AdjustedParamT<ParamTs>... Params) {
157
8
    return (*reinterpret_cast<CallableT *>(CallableAddr))(
158
8
        std::forward<ParamTs>(Params)...);
159
8
  }
160
161
  template <typename CallableT>
162
0
  static void MoveImpl(void *LHSCallableAddr, void *RHSCallableAddr) noexcept {
163
0
    new (LHSCallableAddr)
164
0
        CallableT(std::move(*reinterpret_cast<CallableT *>(RHSCallableAddr)));
165
0
  }
Unexecuted instantiation: PassTimingInfo.cpp:void llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::MoveImpl<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_0>(void*, void*)
Unexecuted instantiation: PassTimingInfo.cpp:void llvm::unique_function<void (llvm::StringRef, llvm::Any)>::MoveImpl<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_1>(void*, void*)
Unexecuted instantiation: PassTimingInfo.cpp:void llvm::unique_function<void (llvm::StringRef)>::MoveImpl<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_2>(void*, void*)
Unexecuted instantiation: PassTimingInfo.cpp:void llvm::unique_function<void (llvm::StringRef, llvm::Any)>::MoveImpl<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_3>(void*, void*)
Unexecuted instantiation: PassTimingInfo.cpp:void llvm::unique_function<void (llvm::StringRef, llvm::Any)>::MoveImpl<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_4>(void*, void*)
Unexecuted instantiation: StandardInstrumentations.cpp:void llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::MoveImpl<llvm::PrintIRInstrumentation::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_0>(void*, void*)
Unexecuted instantiation: StandardInstrumentations.cpp:void llvm::unique_function<void (llvm::StringRef, llvm::Any)>::MoveImpl<llvm::PrintIRInstrumentation::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_1>(void*, void*)
Unexecuted instantiation: StandardInstrumentations.cpp:void llvm::unique_function<void (llvm::StringRef)>::MoveImpl<llvm::PrintIRInstrumentation::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_2>(void*, void*)
166
167
  template <typename CallableT>
168
0
  static void DestroyImpl(void *CallableAddr) noexcept {
169
0
    reinterpret_cast<CallableT *>(CallableAddr)->~CallableT();
170
0
  }
Unexecuted instantiation: PassTimingInfo.cpp:void llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::DestroyImpl<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_0>(void*)
Unexecuted instantiation: PassTimingInfo.cpp:void llvm::unique_function<void (llvm::StringRef, llvm::Any)>::DestroyImpl<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_1>(void*)
Unexecuted instantiation: PassTimingInfo.cpp:void llvm::unique_function<void (llvm::StringRef)>::DestroyImpl<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_2>(void*)
Unexecuted instantiation: PassTimingInfo.cpp:void llvm::unique_function<void (llvm::StringRef, llvm::Any)>::DestroyImpl<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_3>(void*)
Unexecuted instantiation: PassTimingInfo.cpp:void llvm::unique_function<void (llvm::StringRef, llvm::Any)>::DestroyImpl<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_4>(void*)
Unexecuted instantiation: StandardInstrumentations.cpp:void llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::DestroyImpl<llvm::PrintIRInstrumentation::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_0>(void*)
Unexecuted instantiation: StandardInstrumentations.cpp:void llvm::unique_function<void (llvm::StringRef, llvm::Any)>::DestroyImpl<llvm::PrintIRInstrumentation::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_1>(void*)
Unexecuted instantiation: StandardInstrumentations.cpp:void llvm::unique_function<void (llvm::StringRef)>::DestroyImpl<llvm::PrintIRInstrumentation::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_2>(void*)
171
172
public:
173
44.2k
  unique_function() = default;
174
  unique_function(std::nullptr_t /*null_callable*/) {}
175
176
34.2k
  ~unique_function() {
177
34.2k
    if (!CallbackAndInlineFlag.getPointer())
178
34.1k
      return;
179
139
180
139
    // Cache this value so we don't re-check it after type-erased operations.
181
139
    bool IsInlineStorage = isInlineStorage();
182
139
183
139
    if (!isTrivialCallback())
184
0
      getNonTrivialCallbacks()->DestroyPtr(
185
0
          IsInlineStorage ? getInlineStorage() : getOutOfLineStorage());
186
139
187
139
    if (!IsInlineStorage)
188
0
      deallocate_buffer(getOutOfLineStorage(), getOutOfLineStorageSize(),
189
0
                        getOutOfLineStorageAlignment());
190
139
  }
llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::~unique_function()
Line
Count
Source
176
24
  ~unique_function() {
177
24
    if (!CallbackAndInlineFlag.getPointer())
178
0
      return;
179
24
180
24
    // Cache this value so we don't re-check it after type-erased operations.
181
24
    bool IsInlineStorage = isInlineStorage();
182
24
183
24
    if (!isTrivialCallback())
184
0
      getNonTrivialCallbacks()->DestroyPtr(
185
0
          IsInlineStorage ? getInlineStorage() : getOutOfLineStorage());
186
24
187
24
    if (!IsInlineStorage)
188
0
      deallocate_buffer(getOutOfLineStorage(), getOutOfLineStorageSize(),
189
0
                        getOutOfLineStorageAlignment());
190
24
  }
llvm::unique_function<void (llvm::StringRef, llvm::Any)>::~unique_function()
Line
Count
Source
176
60
  ~unique_function() {
177
60
    if (!CallbackAndInlineFlag.getPointer())
178
0
      return;
179
60
180
60
    // Cache this value so we don't re-check it after type-erased operations.
181
60
    bool IsInlineStorage = isInlineStorage();
182
60
183
60
    if (!isTrivialCallback())
184
0
      getNonTrivialCallbacks()->DestroyPtr(
185
0
          IsInlineStorage ? getInlineStorage() : getOutOfLineStorage());
186
60
187
60
    if (!IsInlineStorage)
188
0
      deallocate_buffer(getOutOfLineStorage(), getOutOfLineStorageSize(),
189
0
                        getOutOfLineStorageAlignment());
190
60
  }
llvm::unique_function<void (llvm::StringRef)>::~unique_function()
Line
Count
Source
176
28
  ~unique_function() {
177
28
    if (!CallbackAndInlineFlag.getPointer())
178
0
      return;
179
28
180
28
    // Cache this value so we don't re-check it after type-erased operations.
181
28
    bool IsInlineStorage = isInlineStorage();
182
28
183
28
    if (!isTrivialCallback())
184
0
      getNonTrivialCallbacks()->DestroyPtr(
185
0
          IsInlineStorage ? getInlineStorage() : getOutOfLineStorage());
186
28
187
28
    if (!IsInlineStorage)
188
0
      deallocate_buffer(getOutOfLineStorage(), getOutOfLineStorageSize(),
189
0
                        getOutOfLineStorageAlignment());
190
28
  }
llvm::unique_function<void (clang::Token const&)>::~unique_function()
Line
Count
Source
176
34.1k
  ~unique_function() {
177
34.1k
    if (!CallbackAndInlineFlag.getPointer())
178
34.1k
      return;
179
27
180
27
    // Cache this value so we don't re-check it after type-erased operations.
181
27
    bool IsInlineStorage = isInlineStorage();
182
27
183
27
    if (!isTrivialCallback())
184
0
      getNonTrivialCallbacks()->DestroyPtr(
185
0
          IsInlineStorage ? getInlineStorage() : getOutOfLineStorage());
186
27
187
27
    if (!IsInlineStorage)
188
0
      deallocate_buffer(getOutOfLineStorage(), getOutOfLineStorageSize(),
189
0
                        getOutOfLineStorageAlignment());
190
27
  }
191
192
0
  unique_function(unique_function &&RHS) noexcept {
193
0
    // Copy the callback and inline flag.
194
0
    CallbackAndInlineFlag = RHS.CallbackAndInlineFlag;
195
0
196
0
    // If the RHS is empty, just copying the above is sufficient.
197
0
    if (!RHS)
198
0
      return;
199
0
200
0
    if (!isInlineStorage()) {
201
0
      // The out-of-line case is easiest to move.
202
0
      StorageUnion.OutOfLineStorage = RHS.StorageUnion.OutOfLineStorage;
203
0
    } else if (isTrivialCallback()) {
204
0
      // Move is trivial, just memcpy the bytes across.
205
0
      memcpy(getInlineStorage(), RHS.getInlineStorage(), InlineStorageSize);
206
0
    } else {
207
0
      // Non-trivial move, so dispatch to a type-erased implementation.
208
0
      getNonTrivialCallbacks()->MovePtr(getInlineStorage(),
209
0
                                        RHS.getInlineStorage());
210
0
    }
211
0
212
0
    // Clear the old callback and inline flag to get back to as-if-null.
213
0
    RHS.CallbackAndInlineFlag = {};
214
0
215
#ifndef NDEBUG
216
    // In debug builds, we also scribble across the rest of the storage.
217
    memset(RHS.getInlineStorage(), 0xAD, InlineStorageSize);
218
#endif
219
  }
Unexecuted instantiation: llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::unique_function(llvm::unique_function<bool (llvm::StringRef, llvm::Any)>&&)
Unexecuted instantiation: llvm::unique_function<void (llvm::StringRef, llvm::Any)>::unique_function(llvm::unique_function<void (llvm::StringRef, llvm::Any)>&&)
Unexecuted instantiation: llvm::unique_function<void (llvm::StringRef)>::unique_function(llvm::unique_function<void (llvm::StringRef)>&&)
220
221
  unique_function &operator=(unique_function &&RHS) noexcept {
222
    if (this == &RHS)
223
      return *this;
224
225
    // Because we don't try to provide any exception safety guarantees we can
226
    // implement move assignment very simply by first destroying the current
227
    // object and then move-constructing over top of it.
228
    this->~unique_function();
229
    new (this) unique_function(std::move(RHS));
230
    return *this;
231
  }
232
233
62
  template <typename CallableT> unique_function(CallableT Callable) {
234
62
    bool IsInlineStorage = true;
235
62
    void *CallableAddr = getInlineStorage();
236
62
    if (sizeof(CallableT) > InlineStorageSize ||
237
62
        
alignof(CallableT) > alignof(decltype(StorageUnion.InlineStorage))0
) {
238
0
      IsInlineStorage = false;
239
0
      // Allocate out-of-line storage. FIXME: Use an explicit alignment
240
0
      // parameter in C++17 mode.
241
0
      auto Size = sizeof(CallableT);
242
0
      auto Alignment = alignof(CallableT);
243
0
      CallableAddr = allocate_buffer(Size, Alignment);
244
0
      setOutOfLineStorage(CallableAddr, Size, Alignment);
245
0
    }
246
62
247
62
    // Now move into the storage.
248
62
    new (CallableAddr) CallableT(std::move(Callable));
249
62
250
62
    // See if we can create a trivial callback. We need the callable to be
251
62
    // trivially moved and trivially destroyed so that we don't have to store
252
62
    // type erased callbacks for those operations.
253
62
    //
254
62
    // FIXME: We should use constexpr if here and below to avoid instantiating
255
62
    // the non-trivial static objects when unnecessary. While the linker should
256
62
    // remove them, it is still wasteful.
257
62
    if (llvm::is_trivially_move_constructible<CallableT>::value &&
258
62
        
std::is_trivially_destructible<CallableT>::value0
) {
259
62
      // We need to create a nicely aligned object. We use a static variable
260
62
      // for this because it is a trivial struct.
261
62
      static TrivialCallback Callback = { &CallImpl<CallableT> };
262
62
263
62
      CallbackAndInlineFlag = {&Callback, IsInlineStorage};
264
62
      return;
265
62
    }
266
0
267
0
    // Otherwise, we need to point at an object that contains all the different
268
0
    // type erased behaviors needed. Create a static instance of the struct type
269
0
    // here and then use a pointer to that.
270
0
    static NonTrivialCallbacks Callbacks = {
271
0
        &CallImpl<CallableT>, &MoveImpl<CallableT>, &DestroyImpl<CallableT>};
272
0
273
0
    CallbackAndInlineFlag = {&Callbacks, IsInlineStorage};
274
0
  }
PassTimingInfo.cpp:llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::unique_function<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_0>(llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_0)
Line
Count
Source
233
6
  template <typename CallableT> unique_function(CallableT Callable) {
234
6
    bool IsInlineStorage = true;
235
6
    void *CallableAddr = getInlineStorage();
236
6
    if (sizeof(CallableT) > InlineStorageSize ||
237
6
        
alignof(CallableT) > alignof(decltype(StorageUnion.InlineStorage))0
) {
238
0
      IsInlineStorage = false;
239
0
      // Allocate out-of-line storage. FIXME: Use an explicit alignment
240
0
      // parameter in C++17 mode.
241
0
      auto Size = sizeof(CallableT);
242
0
      auto Alignment = alignof(CallableT);
243
0
      CallableAddr = allocate_buffer(Size, Alignment);
244
0
      setOutOfLineStorage(CallableAddr, Size, Alignment);
245
0
    }
246
6
247
6
    // Now move into the storage.
248
6
    new (CallableAddr) CallableT(std::move(Callable));
249
6
250
6
    // See if we can create a trivial callback. We need the callable to be
251
6
    // trivially moved and trivially destroyed so that we don't have to store
252
6
    // type erased callbacks for those operations.
253
6
    //
254
6
    // FIXME: We should use constexpr if here and below to avoid instantiating
255
6
    // the non-trivial static objects when unnecessary. While the linker should
256
6
    // remove them, it is still wasteful.
257
6
    if (llvm::is_trivially_move_constructible<CallableT>::value &&
258
6
        
std::is_trivially_destructible<CallableT>::value0
) {
259
6
      // We need to create a nicely aligned object. We use a static variable
260
6
      // for this because it is a trivial struct.
261
6
      static TrivialCallback Callback = { &CallImpl<CallableT> };
262
6
263
6
      CallbackAndInlineFlag = {&Callback, IsInlineStorage};
264
6
      return;
265
6
    }
266
0
267
0
    // Otherwise, we need to point at an object that contains all the different
268
0
    // type erased behaviors needed. Create a static instance of the struct type
269
0
    // here and then use a pointer to that.
270
0
    static NonTrivialCallbacks Callbacks = {
271
0
        &CallImpl<CallableT>, &MoveImpl<CallableT>, &DestroyImpl<CallableT>};
272
0
273
0
    CallbackAndInlineFlag = {&Callbacks, IsInlineStorage};
274
0
  }
PassTimingInfo.cpp:llvm::unique_function<void (llvm::StringRef, llvm::Any)>::unique_function<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_1>(llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_1)
Line
Count
Source
233
6
  template <typename CallableT> unique_function(CallableT Callable) {
234
6
    bool IsInlineStorage = true;
235
6
    void *CallableAddr = getInlineStorage();
236
6
    if (sizeof(CallableT) > InlineStorageSize ||
237
6
        
alignof(CallableT) > alignof(decltype(StorageUnion.InlineStorage))0
) {
238
0
      IsInlineStorage = false;
239
0
      // Allocate out-of-line storage. FIXME: Use an explicit alignment
240
0
      // parameter in C++17 mode.
241
0
      auto Size = sizeof(CallableT);
242
0
      auto Alignment = alignof(CallableT);
243
0
      CallableAddr = allocate_buffer(Size, Alignment);
244
0
      setOutOfLineStorage(CallableAddr, Size, Alignment);
245
0
    }
246
6
247
6
    // Now move into the storage.
248
6
    new (CallableAddr) CallableT(std::move(Callable));
249
6
250
6
    // See if we can create a trivial callback. We need the callable to be
251
6
    // trivially moved and trivially destroyed so that we don't have to store
252
6
    // type erased callbacks for those operations.
253
6
    //
254
6
    // FIXME: We should use constexpr if here and below to avoid instantiating
255
6
    // the non-trivial static objects when unnecessary. While the linker should
256
6
    // remove them, it is still wasteful.
257
6
    if (llvm::is_trivially_move_constructible<CallableT>::value &&
258
6
        
std::is_trivially_destructible<CallableT>::value0
) {
259
6
      // We need to create a nicely aligned object. We use a static variable
260
6
      // for this because it is a trivial struct.
261
6
      static TrivialCallback Callback = { &CallImpl<CallableT> };
262
6
263
6
      CallbackAndInlineFlag = {&Callback, IsInlineStorage};
264
6
      return;
265
6
    }
266
0
267
0
    // Otherwise, we need to point at an object that contains all the different
268
0
    // type erased behaviors needed. Create a static instance of the struct type
269
0
    // here and then use a pointer to that.
270
0
    static NonTrivialCallbacks Callbacks = {
271
0
        &CallImpl<CallableT>, &MoveImpl<CallableT>, &DestroyImpl<CallableT>};
272
0
273
0
    CallbackAndInlineFlag = {&Callbacks, IsInlineStorage};
274
0
  }
PassTimingInfo.cpp:llvm::unique_function<void (llvm::StringRef)>::unique_function<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_2>(llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_2)
Line
Count
Source
233
6
  template <typename CallableT> unique_function(CallableT Callable) {
234
6
    bool IsInlineStorage = true;
235
6
    void *CallableAddr = getInlineStorage();
236
6
    if (sizeof(CallableT) > InlineStorageSize ||
237
6
        
alignof(CallableT) > alignof(decltype(StorageUnion.InlineStorage))0
) {
238
0
      IsInlineStorage = false;
239
0
      // Allocate out-of-line storage. FIXME: Use an explicit alignment
240
0
      // parameter in C++17 mode.
241
0
      auto Size = sizeof(CallableT);
242
0
      auto Alignment = alignof(CallableT);
243
0
      CallableAddr = allocate_buffer(Size, Alignment);
244
0
      setOutOfLineStorage(CallableAddr, Size, Alignment);
245
0
    }
246
6
247
6
    // Now move into the storage.
248
6
    new (CallableAddr) CallableT(std::move(Callable));
249
6
250
6
    // See if we can create a trivial callback. We need the callable to be
251
6
    // trivially moved and trivially destroyed so that we don't have to store
252
6
    // type erased callbacks for those operations.
253
6
    //
254
6
    // FIXME: We should use constexpr if here and below to avoid instantiating
255
6
    // the non-trivial static objects when unnecessary. While the linker should
256
6
    // remove them, it is still wasteful.
257
6
    if (llvm::is_trivially_move_constructible<CallableT>::value &&
258
6
        
std::is_trivially_destructible<CallableT>::value0
) {
259
6
      // We need to create a nicely aligned object. We use a static variable
260
6
      // for this because it is a trivial struct.
261
6
      static TrivialCallback Callback = { &CallImpl<CallableT> };
262
6
263
6
      CallbackAndInlineFlag = {&Callback, IsInlineStorage};
264
6
      return;
265
6
    }
266
0
267
0
    // Otherwise, we need to point at an object that contains all the different
268
0
    // type erased behaviors needed. Create a static instance of the struct type
269
0
    // here and then use a pointer to that.
270
0
    static NonTrivialCallbacks Callbacks = {
271
0
        &CallImpl<CallableT>, &MoveImpl<CallableT>, &DestroyImpl<CallableT>};
272
0
273
0
    CallbackAndInlineFlag = {&Callbacks, IsInlineStorage};
274
0
  }
PassTimingInfo.cpp:llvm::unique_function<void (llvm::StringRef, llvm::Any)>::unique_function<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_3>(llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_3)
Line
Count
Source
233
6
  template <typename CallableT> unique_function(CallableT Callable) {
234
6
    bool IsInlineStorage = true;
235
6
    void *CallableAddr = getInlineStorage();
236
6
    if (sizeof(CallableT) > InlineStorageSize ||
237
6
        
alignof(CallableT) > alignof(decltype(StorageUnion.InlineStorage))0
) {
238
0
      IsInlineStorage = false;
239
0
      // Allocate out-of-line storage. FIXME: Use an explicit alignment
240
0
      // parameter in C++17 mode.
241
0
      auto Size = sizeof(CallableT);
242
0
      auto Alignment = alignof(CallableT);
243
0
      CallableAddr = allocate_buffer(Size, Alignment);
244
0
      setOutOfLineStorage(CallableAddr, Size, Alignment);
245
0
    }
246
6
247
6
    // Now move into the storage.
248
6
    new (CallableAddr) CallableT(std::move(Callable));
249
6
250
6
    // See if we can create a trivial callback. We need the callable to be
251
6
    // trivially moved and trivially destroyed so that we don't have to store
252
6
    // type erased callbacks for those operations.
253
6
    //
254
6
    // FIXME: We should use constexpr if here and below to avoid instantiating
255
6
    // the non-trivial static objects when unnecessary. While the linker should
256
6
    // remove them, it is still wasteful.
257
6
    if (llvm::is_trivially_move_constructible<CallableT>::value &&
258
6
        
std::is_trivially_destructible<CallableT>::value0
) {
259
6
      // We need to create a nicely aligned object. We use a static variable
260
6
      // for this because it is a trivial struct.
261
6
      static TrivialCallback Callback = { &CallImpl<CallableT> };
262
6
263
6
      CallbackAndInlineFlag = {&Callback, IsInlineStorage};
264
6
      return;
265
6
    }
266
0
267
0
    // Otherwise, we need to point at an object that contains all the different
268
0
    // type erased behaviors needed. Create a static instance of the struct type
269
0
    // here and then use a pointer to that.
270
0
    static NonTrivialCallbacks Callbacks = {
271
0
        &CallImpl<CallableT>, &MoveImpl<CallableT>, &DestroyImpl<CallableT>};
272
0
273
0
    CallbackAndInlineFlag = {&Callbacks, IsInlineStorage};
274
0
  }
PassTimingInfo.cpp:llvm::unique_function<void (llvm::StringRef, llvm::Any)>::unique_function<llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_4>(llvm::TimePassesHandler::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_4)
Line
Count
Source
233
6
  template <typename CallableT> unique_function(CallableT Callable) {
234
6
    bool IsInlineStorage = true;
235
6
    void *CallableAddr = getInlineStorage();
236
6
    if (sizeof(CallableT) > InlineStorageSize ||
237
6
        
alignof(CallableT) > alignof(decltype(StorageUnion.InlineStorage))0
) {
238
0
      IsInlineStorage = false;
239
0
      // Allocate out-of-line storage. FIXME: Use an explicit alignment
240
0
      // parameter in C++17 mode.
241
0
      auto Size = sizeof(CallableT);
242
0
      auto Alignment = alignof(CallableT);
243
0
      CallableAddr = allocate_buffer(Size, Alignment);
244
0
      setOutOfLineStorage(CallableAddr, Size, Alignment);
245
0
    }
246
6
247
6
    // Now move into the storage.
248
6
    new (CallableAddr) CallableT(std::move(Callable));
249
6
250
6
    // See if we can create a trivial callback. We need the callable to be
251
6
    // trivially moved and trivially destroyed so that we don't have to store
252
6
    // type erased callbacks for those operations.
253
6
    //
254
6
    // FIXME: We should use constexpr if here and below to avoid instantiating
255
6
    // the non-trivial static objects when unnecessary. While the linker should
256
6
    // remove them, it is still wasteful.
257
6
    if (llvm::is_trivially_move_constructible<CallableT>::value &&
258
6
        
std::is_trivially_destructible<CallableT>::value0
) {
259
6
      // We need to create a nicely aligned object. We use a static variable
260
6
      // for this because it is a trivial struct.
261
6
      static TrivialCallback Callback = { &CallImpl<CallableT> };
262
6
263
6
      CallbackAndInlineFlag = {&Callback, IsInlineStorage};
264
6
      return;
265
6
    }
266
0
267
0
    // Otherwise, we need to point at an object that contains all the different
268
0
    // type erased behaviors needed. Create a static instance of the struct type
269
0
    // here and then use a pointer to that.
270
0
    static NonTrivialCallbacks Callbacks = {
271
0
        &CallImpl<CallableT>, &MoveImpl<CallableT>, &DestroyImpl<CallableT>};
272
0
273
0
    CallbackAndInlineFlag = {&Callbacks, IsInlineStorage};
274
0
  }
StandardInstrumentations.cpp:llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::unique_function<llvm::PrintIRInstrumentation::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_0>(llvm::PrintIRInstrumentation::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_0)
Line
Count
Source
233
8
  template <typename CallableT> unique_function(CallableT Callable) {
234
8
    bool IsInlineStorage = true;
235
8
    void *CallableAddr = getInlineStorage();
236
8
    if (sizeof(CallableT) > InlineStorageSize ||
237
8
        
alignof(CallableT) > alignof(decltype(StorageUnion.InlineStorage))0
) {
238
0
      IsInlineStorage = false;
239
0
      // Allocate out-of-line storage. FIXME: Use an explicit alignment
240
0
      // parameter in C++17 mode.
241
0
      auto Size = sizeof(CallableT);
242
0
      auto Alignment = alignof(CallableT);
243
0
      CallableAddr = allocate_buffer(Size, Alignment);
244
0
      setOutOfLineStorage(CallableAddr, Size, Alignment);
245
0
    }
246
8
247
8
    // Now move into the storage.
248
8
    new (CallableAddr) CallableT(std::move(Callable));
249
8
250
8
    // See if we can create a trivial callback. We need the callable to be
251
8
    // trivially moved and trivially destroyed so that we don't have to store
252
8
    // type erased callbacks for those operations.
253
8
    //
254
8
    // FIXME: We should use constexpr if here and below to avoid instantiating
255
8
    // the non-trivial static objects when unnecessary. While the linker should
256
8
    // remove them, it is still wasteful.
257
8
    if (llvm::is_trivially_move_constructible<CallableT>::value &&
258
8
        
std::is_trivially_destructible<CallableT>::value0
) {
259
8
      // We need to create a nicely aligned object. We use a static variable
260
8
      // for this because it is a trivial struct.
261
8
      static TrivialCallback Callback = { &CallImpl<CallableT> };
262
8
263
8
      CallbackAndInlineFlag = {&Callback, IsInlineStorage};
264
8
      return;
265
8
    }
266
0
267
0
    // Otherwise, we need to point at an object that contains all the different
268
0
    // type erased behaviors needed. Create a static instance of the struct type
269
0
    // here and then use a pointer to that.
270
0
    static NonTrivialCallbacks Callbacks = {
271
0
        &CallImpl<CallableT>, &MoveImpl<CallableT>, &DestroyImpl<CallableT>};
272
0
273
0
    CallbackAndInlineFlag = {&Callbacks, IsInlineStorage};
274
0
  }
StandardInstrumentations.cpp:llvm::unique_function<void (llvm::StringRef, llvm::Any)>::unique_function<llvm::PrintIRInstrumentation::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_1>(llvm::PrintIRInstrumentation::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_1)
Line
Count
Source
233
12
  template <typename CallableT> unique_function(CallableT Callable) {
234
12
    bool IsInlineStorage = true;
235
12
    void *CallableAddr = getInlineStorage();
236
12
    if (sizeof(CallableT) > InlineStorageSize ||
237
12
        
alignof(CallableT) > alignof(decltype(StorageUnion.InlineStorage))0
) {
238
0
      IsInlineStorage = false;
239
0
      // Allocate out-of-line storage. FIXME: Use an explicit alignment
240
0
      // parameter in C++17 mode.
241
0
      auto Size = sizeof(CallableT);
242
0
      auto Alignment = alignof(CallableT);
243
0
      CallableAddr = allocate_buffer(Size, Alignment);
244
0
      setOutOfLineStorage(CallableAddr, Size, Alignment);
245
0
    }
246
12
247
12
    // Now move into the storage.
248
12
    new (CallableAddr) CallableT(std::move(Callable));
249
12
250
12
    // See if we can create a trivial callback. We need the callable to be
251
12
    // trivially moved and trivially destroyed so that we don't have to store
252
12
    // type erased callbacks for those operations.
253
12
    //
254
12
    // FIXME: We should use constexpr if here and below to avoid instantiating
255
12
    // the non-trivial static objects when unnecessary. While the linker should
256
12
    // remove them, it is still wasteful.
257
12
    if (llvm::is_trivially_move_constructible<CallableT>::value &&
258
12
        
std::is_trivially_destructible<CallableT>::value0
) {
259
12
      // We need to create a nicely aligned object. We use a static variable
260
12
      // for this because it is a trivial struct.
261
12
      static TrivialCallback Callback = { &CallImpl<CallableT> };
262
12
263
12
      CallbackAndInlineFlag = {&Callback, IsInlineStorage};
264
12
      return;
265
12
    }
266
0
267
0
    // Otherwise, we need to point at an object that contains all the different
268
0
    // type erased behaviors needed. Create a static instance of the struct type
269
0
    // here and then use a pointer to that.
270
0
    static NonTrivialCallbacks Callbacks = {
271
0
        &CallImpl<CallableT>, &MoveImpl<CallableT>, &DestroyImpl<CallableT>};
272
0
273
0
    CallbackAndInlineFlag = {&Callbacks, IsInlineStorage};
274
0
  }
StandardInstrumentations.cpp:llvm::unique_function<void (llvm::StringRef)>::unique_function<llvm::PrintIRInstrumentation::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_2>(llvm::PrintIRInstrumentation::registerCallbacks(llvm::PassInstrumentationCallbacks&)::$_2)
Line
Count
Source
233
12
  template <typename CallableT> unique_function(CallableT Callable) {
234
12
    bool IsInlineStorage = true;
235
12
    void *CallableAddr = getInlineStorage();
236
12
    if (sizeof(CallableT) > InlineStorageSize ||
237
12
        
alignof(CallableT) > alignof(decltype(StorageUnion.InlineStorage))0
) {
238
0
      IsInlineStorage = false;
239
0
      // Allocate out-of-line storage. FIXME: Use an explicit alignment
240
0
      // parameter in C++17 mode.
241
0
      auto Size = sizeof(CallableT);
242
0
      auto Alignment = alignof(CallableT);
243
0
      CallableAddr = allocate_buffer(Size, Alignment);
244
0
      setOutOfLineStorage(CallableAddr, Size, Alignment);
245
0
    }
246
12
247
12
    // Now move into the storage.
248
12
    new (CallableAddr) CallableT(std::move(Callable));
249
12
250
12
    // See if we can create a trivial callback. We need the callable to be
251
12
    // trivially moved and trivially destroyed so that we don't have to store
252
12
    // type erased callbacks for those operations.
253
12
    //
254
12
    // FIXME: We should use constexpr if here and below to avoid instantiating
255
12
    // the non-trivial static objects when unnecessary. While the linker should
256
12
    // remove them, it is still wasteful.
257
12
    if (llvm::is_trivially_move_constructible<CallableT>::value &&
258
12
        
std::is_trivially_destructible<CallableT>::value0
) {
259
12
      // We need to create a nicely aligned object. We use a static variable
260
12
      // for this because it is a trivial struct.
261
12
      static TrivialCallback Callback = { &CallImpl<CallableT> };
262
12
263
12
      CallbackAndInlineFlag = {&Callback, IsInlineStorage};
264
12
      return;
265
12
    }
266
0
267
0
    // Otherwise, we need to point at an object that contains all the different
268
0
    // type erased behaviors needed. Create a static instance of the struct type
269
0
    // here and then use a pointer to that.
270
0
    static NonTrivialCallbacks Callbacks = {
271
0
        &CallImpl<CallableT>, &MoveImpl<CallableT>, &DestroyImpl<CallableT>};
272
0
273
0
    CallbackAndInlineFlag = {&Callbacks, IsInlineStorage};
274
0
  }
275
276
2.68k
  ReturnT operator()(ParamTs... Params) {
277
2.68k
    void *CallableAddr =
278
2.68k
        isInlineStorage() ? getInlineStorage() : 
getOutOfLineStorage()0
;
279
2.68k
280
2.68k
    return (isTrivialCallback()
281
2.68k
                ? getTrivialCallback()
282
2.68k
                : 
getNonTrivialCallbacks()->CallPtr0
)(CallableAddr, Params...);
283
2.68k
  }
llvm::unique_function<void (llvm::StringRef, llvm::Any)>::operator()(llvm::StringRef, llvm::Any)
Line
Count
Source
276
1.60k
  ReturnT operator()(ParamTs... Params) {
277
1.60k
    void *CallableAddr =
278
1.60k
        isInlineStorage() ? getInlineStorage() : 
getOutOfLineStorage()0
;
279
1.60k
280
1.60k
    return (isTrivialCallback()
281
1.60k
                ? getTrivialCallback()
282
1.60k
                : 
getNonTrivialCallbacks()->CallPtr0
)(CallableAddr, Params...);
283
1.60k
  }
llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::operator()(llvm::StringRef, llvm::Any)
Line
Count
Source
276
794
  ReturnT operator()(ParamTs... Params) {
277
794
    void *CallableAddr =
278
794
        isInlineStorage() ? getInlineStorage() : 
getOutOfLineStorage()0
;
279
794
280
794
    return (isTrivialCallback()
281
794
                ? getTrivialCallback()
282
794
                : 
getNonTrivialCallbacks()->CallPtr0
)(CallableAddr, Params...);
283
794
  }
llvm::unique_function<void (llvm::StringRef)>::operator()(llvm::StringRef)
Line
Count
Source
276
12
  ReturnT operator()(ParamTs... Params) {
277
12
    void *CallableAddr =
278
12
        isInlineStorage() ? getInlineStorage() : 
getOutOfLineStorage()0
;
279
12
280
12
    return (isTrivialCallback()
281
12
                ? getTrivialCallback()
282
12
                : 
getNonTrivialCallbacks()->CallPtr0
)(CallableAddr, Params...);
283
12
  }
llvm::unique_function<void (clang::Token const&)>::operator()(clang::Token const&)
Line
Count
Source
276
272
  ReturnT operator()(ParamTs... Params) {
277
272
    void *CallableAddr =
278
272
        isInlineStorage() ? getInlineStorage() : 
getOutOfLineStorage()0
;
279
272
280
272
    return (isTrivialCallback()
281
272
                ? getTrivialCallback()
282
272
                : 
getNonTrivialCallbacks()->CallPtr0
)(CallableAddr, Params...);
283
272
  }
284
285
902M
  explicit operator bool() const {
286
902M
    return (bool)CallbackAndInlineFlag.getPointer();
287
902M
  }
Unexecuted instantiation: llvm::unique_function<bool (llvm::StringRef, llvm::Any)>::operator bool() const
Unexecuted instantiation: llvm::unique_function<void (llvm::StringRef, llvm::Any)>::operator bool() const
Unexecuted instantiation: llvm::unique_function<void (llvm::StringRef)>::operator bool() const
llvm::unique_function<void (clang::Token const&)>::operator bool() const
Line
Count
Source
285
902M
  explicit operator bool() const {
286
902M
    return (bool)CallbackAndInlineFlag.getPointer();
287
902M
  }
288
};
289
290
} // end namespace llvm
291
292
#endif // LLVM_ADT_FUNCTION_H