LLVM 20.0.0git
ABI.h
Go to the documentation of this file.
1//===- ABI.h - Coroutine lowering class definitions (ABIs) ----*- 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// This file defines coroutine lowering classes. The interface for coroutine
9// lowering is defined by BaseABI. Each lowering method (ABI) implements the
10// interface. Note that the enum class ABI, such as ABI::Switch, determines
11// which ABI class, such as SwitchABI, is used to lower the coroutine. Both the
12// ABI enum and ABI class are used by the Coroutine passes when lowering.
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_TRANSFORMS_COROUTINES_ABI_H
16#define LLVM_TRANSFORMS_COROUTINES_ABI_H
17
22
23namespace llvm {
24
25class Function;
26
27namespace coro {
28
29// This interface/API is to provide an object oriented way to implement ABI
30// functionality. This is intended to replace use of the ABI enum to perform
31// ABI operations. The ABIs (e.g. Switch, Async, Retcon{Once}) are the common
32// ABIs. However, specific users may need to modify the behavior of these. This
33// can be accomplished by inheriting one of the common ABIs and overriding one
34// or more of the methods to create a custom ABI. To use a custom ABI for a
35// given coroutine the coro.begin.custom.abi intrinsic is used in place of the
36// coro.begin intrinsic. This takes an additional i32 arg that specifies the
37// index of an ABI generator for the custom ABI object in a SmallVector passed
38// to CoroSplitPass ctor.
39
40class BaseABI {
41public:
43 std::function<bool(Instruction &)> IsMaterializable)
45 virtual ~BaseABI() = default;
46
47 // Initialize the coroutine ABI
48 virtual void init() = 0;
49
50 // Allocate the coroutine frame and do spill/reload as needed.
51 virtual void buildCoroutineFrame(bool OptimizeFrame);
52
53 // Perform the function splitting according to the ABI.
57
60
61 // Callback used by coro::BaseABI::buildCoroutineFrame for rematerialization.
62 // It is provided to coro::doMaterializations(..).
64};
65
66class SwitchABI : public BaseABI {
67public:
69 std::function<bool(Instruction &)> IsMaterializable)
71
72 void init() override;
73
76 TargetTransformInfo &TTI) override;
77};
78
79class AsyncABI : public BaseABI {
80public:
82 std::function<bool(Instruction &)> IsMaterializable)
84
85 void init() override;
86
89 TargetTransformInfo &TTI) override;
90};
91
92class AnyRetconABI : public BaseABI {
93public:
95 std::function<bool(Instruction &)> IsMaterializable)
97
98 void init() override;
99
102 TargetTransformInfo &TTI) override;
103};
104
105} // end namespace coro
106
107} // end namespace llvm
108
109#endif // LLVM_TRANSFORMS_COROUTINES_ABI_H
#define I(x, y, z)
Definition: MD5.cpp:58
This pass exposes codegen information to IR-level passes.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
AnyRetconABI(Function &F, coro::Shape &S, std::function< bool(Instruction &)> IsMaterializable)
Definition: ABI.h:94
void init() override
Definition: Coroutines.cpp:398
void splitCoroutine(Function &F, coro::Shape &Shape, SmallVectorImpl< Function * > &Clones, TargetTransformInfo &TTI) override
Definition: CoroSplit.cpp:1780
void init() override
Definition: Coroutines.cpp:396
AsyncABI(Function &F, coro::Shape &S, std::function< bool(Instruction &)> IsMaterializable)
Definition: ABI.h:81
void splitCoroutine(Function &F, coro::Shape &Shape, SmallVectorImpl< Function * > &Clones, TargetTransformInfo &TTI) override
Definition: CoroSplit.cpp:1684
std::function< bool(Instruction &I)> IsMaterializable
Definition: ABI.h:63
Function & F
Definition: ABI.h:58
virtual void splitCoroutine(Function &F, coro::Shape &Shape, SmallVectorImpl< Function * > &Clones, TargetTransformInfo &TTI)=0
BaseABI(Function &F, coro::Shape &S, std::function< bool(Instruction &)> IsMaterializable)
Definition: ABI.h:42
virtual void buildCoroutineFrame(bool OptimizeFrame)
Definition: CoroFrame.cpp:2063
virtual void init()=0
virtual ~BaseABI()=default
coro::Shape & Shape
Definition: ABI.h:59
void init() override
Definition: Coroutines.cpp:378
void splitCoroutine(Function &F, coro::Shape &Shape, SmallVectorImpl< Function * > &Clones, TargetTransformInfo &TTI) override
Definition: CoroSplit.cpp:1952
SwitchABI(Function &F, coro::Shape &S, std::function< bool(Instruction &)> IsMaterializable)
Definition: ABI.h:68
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1873
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858