LLVM 22.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
23
24namespace llvm {
25
26class Function;
27
28namespace coro {
29
30// This interface/API is to provide an object oriented way to implement ABI
31// functionality. This is intended to replace use of the ABI enum to perform
32// ABI operations. The ABIs (e.g. Switch, Async, Retcon{Once}) are the common
33// ABIs. However, specific users may need to modify the behavior of these. This
34// can be accomplished by inheriting one of the common ABIs and overriding one
35// or more of the methods to create a custom ABI. To use a custom ABI for a
36// given coroutine the coro.begin.custom.abi intrinsic is used in place of the
37// coro.begin intrinsic. This takes an additional i32 arg that specifies the
38// index of an ABI generator for the custom ABI object in a SmallVector passed
39// to CoroSplitPass ctor.
40
42public:
46 virtual ~BaseABI() = default;
47
48 // Initialize the coroutine ABI
49 virtual void init() = 0;
50
51 // Allocate the coroutine frame and do spill/reload as needed.
52 virtual void buildCoroutineFrame(bool OptimizeFrame);
53
54 // Perform the function splitting according to the ABI.
58
61
62 // Callback used by coro::BaseABI::buildCoroutineFrame for rematerialization.
63 // It is provided to coro::doMaterializations(..).
65};
66
67class LLVM_ABI SwitchABI : public BaseABI {
68public:
70 std::function<bool(Instruction &)> IsMaterializable)
72
73 void init() override;
74
75 void splitCoroutine(Function &F, coro::Shape &Shape,
77 TargetTransformInfo &TTI) override;
78};
79
80class LLVM_ABI AsyncABI : public BaseABI {
81public:
83 std::function<bool(Instruction &)> IsMaterializable)
85
86 void init() override;
87
88 void splitCoroutine(Function &F, coro::Shape &Shape,
90 TargetTransformInfo &TTI) override;
91};
92
94public:
98
99 void init() override;
100
101 void splitCoroutine(Function &F, coro::Shape &Shape,
103 TargetTransformInfo &TTI) override;
104};
105
106} // end namespace coro
107
108} // end namespace llvm
109
110#endif // LLVM_TRANSFORMS_COROUTINES_ABI_H
#define LLVM_ABI
Definition Compiler.h:213
#define F(x, y, z)
Definition MD5.cpp:55
#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...
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:95
AsyncABI(Function &F, coro::Shape &S, std::function< bool(Instruction &)> IsMaterializable)
Definition ABI.h:82
std::function< bool(Instruction &I)> IsMaterializable
Definition ABI.h:64
Function & F
Definition ABI.h:59
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:43
virtual void buildCoroutineFrame(bool OptimizeFrame)
virtual void init()=0
virtual ~BaseABI()=default
coro::Shape & Shape
Definition ABI.h:60
SwitchABI(Function &F, coro::Shape &S, std::function< bool(Instruction &)> IsMaterializable)
Definition ABI.h:69
This is an optimization pass for GlobalISel generic memory operations.
TargetTransformInfo TTI
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:1869
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:851