LLVM 23.0.0git
ProgramStack.h
Go to the documentation of this file.
1//===--- ProgramStack.h -----------------------------------------*- 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#ifndef LLVM_SUPPORT_PROGRAMSTACK_H
10#define LLVM_SUPPORT_PROGRAMSTACK_H
11
14
15namespace llvm {
16
17/// \returns an address close to the current value of the stack pointer.
18///
19/// The value is not guaranteed to point to anything specific. It can be used to
20/// estimate how much stack space has been used since the previous call.
21LLVM_ABI uintptr_t getStackPointer();
22
23/// \returns the default stack size for this platform.
24///
25/// Based on \p RLIMIT_STACK or the equivalent.
27
28/// Runs Fn on a new stack of at least the given size.
29///
30/// \param StackSize requested stack size. A size of 0 uses the default stack
31/// size of the platform.
32///
33/// The preferred implementation is split stacks on platforms that have a good
34/// debugging experience for them. On other platforms a new thread is used.
35LLVM_ABI void runOnNewStack(unsigned StackSize, function_ref<void()> Fn);
36
37template <typename R, typename... Ts>
38auto runOnNewStack(unsigned StackSize, function_ref<R(Ts...)> Fn,
39 Ts &&...Args) {
40 if constexpr (std::is_same_v<R, void>) {
41 runOnNewStack(StackSize, [&]() { Fn(std::forward<Ts>(Args)...); });
42 } else {
43 std::optional<R> Ret;
44 runOnNewStack(StackSize, [&]() { Ret = Fn(std::forward<Ts>(Args)...); });
45 return std::move(*Ret);
46 }
47}
48
49} // namespace llvm
50
51#endif // LLVM_SUPPORT_PROGRAMSTACK_H
#define LLVM_ABI
Definition Compiler.h:213
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
LLVM_ABI void runOnNewStack(unsigned StackSize, function_ref< void()> Fn)
Runs Fn on a new stack of at least the given size.
LLVM_ABI unsigned getDefaultStackSize()
LLVM_ABI uintptr_t getStackPointer()