Skip to content

Commit

Permalink
[Coroutines] Move util headers to include/llvm (#111599)
Browse files Browse the repository at this point in the history
Plugin libraries that use coroutines can do so right now, however, to
provide their own ABI they need to be able to use various headers, some
of which such are required (such as the ABI header). This change exposes
the coro utils and required headers by moving them to
include/llvm/Transforms/Coroutines. My experience with our out-of-tree
plugin ABI has been that at least these headers are needed. The headers
moved are:
* ABI.h (ABI object)
* CoroInstr.h (helpers)
 * Coroshape.h (Shape object)
 * MaterializationUtils.h (helpers)
 * SpillingUtils.h (helpers)
 * SuspendCrossingInfo.h (analysis)

This has no code changes other than those required to move the headers
and these are:
 * include guard name changes
 * include path changes
 * minor clang-format induced changes
 * removal of LLVM_LIBRARY_VISIBILITY
  • Loading branch information
TylerNowicki authored Oct 9, 2024
1 parent 1cfe5b8 commit e82fcda
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
// ABI enum and ABI class are used by the Coroutine passes when lowering.
//===----------------------------------------------------------------------===//

#ifndef LIB_TRANSFORMS_COROUTINES_ABI_H
#define LIB_TRANSFORMS_COROUTINES_ABI_H
#ifndef LLVM_TRANSFORMS_COROUTINES_ABI_H
#define LLVM_TRANSFORMS_COROUTINES_ABI_H

#include "CoroShape.h"
#include "SuspendCrossingInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Transforms/Coroutines/CoroShape.h"
#include "llvm/Transforms/Coroutines/MaterializationUtils.h"
#include "llvm/Transforms/Coroutines/SuspendCrossingInfo.h"

namespace llvm {

Expand All @@ -30,7 +31,7 @@ namespace coro {
// ABI operations. The ABIs (e.g. Switch, Async, Retcon{Once}) are the common
// ABIs.

class LLVM_LIBRARY_VISIBILITY BaseABI {
class BaseABI {
public:
BaseABI(Function &F, coro::Shape &S,
std::function<bool(Instruction &)> IsMaterializable)
Expand All @@ -56,7 +57,7 @@ class LLVM_LIBRARY_VISIBILITY BaseABI {
std::function<bool(Instruction &I)> IsMaterializable;
};

class LLVM_LIBRARY_VISIBILITY SwitchABI : public BaseABI {
class SwitchABI : public BaseABI {
public:
SwitchABI(Function &F, coro::Shape &S,
std::function<bool(Instruction &)> IsMaterializable)
Expand All @@ -69,7 +70,7 @@ class LLVM_LIBRARY_VISIBILITY SwitchABI : public BaseABI {
TargetTransformInfo &TTI) override;
};

class LLVM_LIBRARY_VISIBILITY AsyncABI : public BaseABI {
class AsyncABI : public BaseABI {
public:
AsyncABI(Function &F, coro::Shape &S,
std::function<bool(Instruction &)> IsMaterializable)
Expand All @@ -82,7 +83,7 @@ class LLVM_LIBRARY_VISIBILITY AsyncABI : public BaseABI {
TargetTransformInfo &TTI) override;
};

class LLVM_LIBRARY_VISIBILITY AnyRetconABI : public BaseABI {
class AnyRetconABI : public BaseABI {
public:
AnyRetconABI(Function &F, coro::Shape &S,
std::function<bool(Instruction &)> IsMaterializable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
// the Coroutine library.
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIB_TRANSFORMS_COROUTINES_COROINSTR_H
#define LLVM_LIB_TRANSFORMS_COROUTINES_COROINSTR_H
#ifndef LLVM_TRANSFORMS_COROUTINES_COROINSTR_H
#define LLVM_TRANSFORMS_COROUTINES_COROINSTR_H

#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/IntrinsicInst.h"
Expand All @@ -32,7 +32,7 @@
namespace llvm {

/// This class represents the llvm.coro.subfn.addr instruction.
class LLVM_LIBRARY_VISIBILITY CoroSubFnInst : public IntrinsicInst {
class CoroSubFnInst : public IntrinsicInst {
enum { FrameArg, IndexArg };

public:
Expand Down Expand Up @@ -67,7 +67,7 @@ class LLVM_LIBRARY_VISIBILITY CoroSubFnInst : public IntrinsicInst {
};

/// This represents the llvm.coro.alloc instruction.
class LLVM_LIBRARY_VISIBILITY CoroAllocInst : public IntrinsicInst {
class CoroAllocInst : public IntrinsicInst {
public:
// Methods to support type inquiry through isa, cast, and dyn_cast:
static bool classof(const IntrinsicInst *I) {
Expand All @@ -82,7 +82,7 @@ class LLVM_LIBRARY_VISIBILITY CoroAllocInst : public IntrinsicInst {
// FIXME: add callback metadata
// FIXME: make a proper IntrinisicInst. Currently this is not possible,
// because llvm.coro.await.suspend.* can be invoked.
class LLVM_LIBRARY_VISIBILITY CoroAwaitSuspendInst : public CallBase {
class CoroAwaitSuspendInst : public CallBase {
enum { AwaiterArg, FrameArg, WrapperArg };

public:
Expand Down Expand Up @@ -112,7 +112,7 @@ class LLVM_LIBRARY_VISIBILITY CoroAwaitSuspendInst : public CallBase {
};

/// This represents a common base class for llvm.coro.id instructions.
class LLVM_LIBRARY_VISIBILITY AnyCoroIdInst : public IntrinsicInst {
class AnyCoroIdInst : public IntrinsicInst {
public:
CoroAllocInst *getCoroAlloc() {
for (User *U : users())
Expand Down Expand Up @@ -143,7 +143,7 @@ class LLVM_LIBRARY_VISIBILITY AnyCoroIdInst : public IntrinsicInst {
};

/// This represents the llvm.coro.id instruction.
class LLVM_LIBRARY_VISIBILITY CoroIdInst : public AnyCoroIdInst {
class CoroIdInst : public AnyCoroIdInst {
enum { AlignArg, PromiseArg, CoroutineArg, InfoArg };

public:
Expand Down Expand Up @@ -232,7 +232,7 @@ class LLVM_LIBRARY_VISIBILITY CoroIdInst : public AnyCoroIdInst {

/// This represents either the llvm.coro.id.retcon or
/// llvm.coro.id.retcon.once instruction.
class LLVM_LIBRARY_VISIBILITY AnyCoroIdRetconInst : public AnyCoroIdInst {
class AnyCoroIdRetconInst : public AnyCoroIdInst {
enum { SizeArg, AlignArg, StorageArg, PrototypeArg, AllocArg, DeallocArg };

public:
Expand All @@ -246,9 +246,7 @@ class LLVM_LIBRARY_VISIBILITY AnyCoroIdRetconInst : public AnyCoroIdInst {
return cast<ConstantInt>(getArgOperand(AlignArg))->getAlignValue();
}

Value *getStorage() const {
return getArgOperand(StorageArg);
}
Value *getStorage() const { return getArgOperand(StorageArg); }

/// Return the prototype for the continuation function. The type,
/// attributes, and calling convention of the continuation function(s)
Expand All @@ -270,17 +268,16 @@ class LLVM_LIBRARY_VISIBILITY AnyCoroIdRetconInst : public AnyCoroIdInst {
// Methods to support type inquiry through isa, cast, and dyn_cast:
static bool classof(const IntrinsicInst *I) {
auto ID = I->getIntrinsicID();
return ID == Intrinsic::coro_id_retcon
|| ID == Intrinsic::coro_id_retcon_once;
return ID == Intrinsic::coro_id_retcon ||
ID == Intrinsic::coro_id_retcon_once;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
};

/// This represents the llvm.coro.id.retcon instruction.
class LLVM_LIBRARY_VISIBILITY CoroIdRetconInst
: public AnyCoroIdRetconInst {
class CoroIdRetconInst : public AnyCoroIdRetconInst {
public:
// Methods to support type inquiry through isa, cast, and dyn_cast:
static bool classof(const IntrinsicInst *I) {
Expand All @@ -292,8 +289,7 @@ class LLVM_LIBRARY_VISIBILITY CoroIdRetconInst
};

/// This represents the llvm.coro.id.retcon.once instruction.
class LLVM_LIBRARY_VISIBILITY CoroIdRetconOnceInst
: public AnyCoroIdRetconInst {
class CoroIdRetconOnceInst : public AnyCoroIdRetconInst {
public:
// Methods to support type inquiry through isa, cast, and dyn_cast:
static bool classof(const IntrinsicInst *I) {
Expand All @@ -305,7 +301,7 @@ class LLVM_LIBRARY_VISIBILITY CoroIdRetconOnceInst
};

/// This represents the llvm.coro.id.async instruction.
class LLVM_LIBRARY_VISIBILITY CoroIdAsyncInst : public AnyCoroIdInst {
class CoroIdAsyncInst : public AnyCoroIdInst {
enum { SizeArg, AlignArg, StorageArg, AsyncFuncPtrArg };

public:
Expand Down Expand Up @@ -356,7 +352,7 @@ class LLVM_LIBRARY_VISIBILITY CoroIdAsyncInst : public AnyCoroIdInst {
};

/// This represents the llvm.coro.context.alloc instruction.
class LLVM_LIBRARY_VISIBILITY CoroAsyncContextAllocInst : public IntrinsicInst {
class CoroAsyncContextAllocInst : public IntrinsicInst {
enum { AsyncFuncPtrArg };

public:
Expand All @@ -375,8 +371,7 @@ class LLVM_LIBRARY_VISIBILITY CoroAsyncContextAllocInst : public IntrinsicInst {
};

/// This represents the llvm.coro.context.dealloc instruction.
class LLVM_LIBRARY_VISIBILITY CoroAsyncContextDeallocInst
: public IntrinsicInst {
class CoroAsyncContextDeallocInst : public IntrinsicInst {
enum { AsyncContextArg };

public:
Expand All @@ -396,7 +391,7 @@ class LLVM_LIBRARY_VISIBILITY CoroAsyncContextDeallocInst
/// This represents the llvm.coro.async.resume instruction.
/// During lowering this is replaced by the resume function of a suspend point
/// (the continuation function).
class LLVM_LIBRARY_VISIBILITY CoroAsyncResumeInst : public IntrinsicInst {
class CoroAsyncResumeInst : public IntrinsicInst {
public:
// Methods to support type inquiry through isa, cast, and dyn_cast:
static bool classof(const IntrinsicInst *I) {
Expand All @@ -408,7 +403,7 @@ class LLVM_LIBRARY_VISIBILITY CoroAsyncResumeInst : public IntrinsicInst {
};

/// This represents the llvm.coro.async.size.replace instruction.
class LLVM_LIBRARY_VISIBILITY CoroAsyncSizeReplace : public IntrinsicInst {
class CoroAsyncSizeReplace : public IntrinsicInst {
public:
// Methods to support type inquiry through isa, cast, and dyn_cast:
static bool classof(const IntrinsicInst *I) {
Expand All @@ -420,7 +415,7 @@ class LLVM_LIBRARY_VISIBILITY CoroAsyncSizeReplace : public IntrinsicInst {
};

/// This represents the llvm.coro.frame instruction.
class LLVM_LIBRARY_VISIBILITY CoroFrameInst : public IntrinsicInst {
class CoroFrameInst : public IntrinsicInst {
public:
// Methods to support type inquiry through isa, cast, and dyn_cast:
static bool classof(const IntrinsicInst *I) {
Expand All @@ -432,7 +427,7 @@ class LLVM_LIBRARY_VISIBILITY CoroFrameInst : public IntrinsicInst {
};

/// This represents the llvm.coro.free instruction.
class LLVM_LIBRARY_VISIBILITY CoroFreeInst : public IntrinsicInst {
class CoroFreeInst : public IntrinsicInst {
enum { IdArg, FrameArg };

public:
Expand All @@ -447,8 +442,8 @@ class LLVM_LIBRARY_VISIBILITY CoroFreeInst : public IntrinsicInst {
}
};

/// This class represents the llvm.coro.begin instruction.
class LLVM_LIBRARY_VISIBILITY CoroBeginInst : public IntrinsicInst {
/// This class represents the llvm.coro.begin instructions.
class CoroBeginInst : public IntrinsicInst {
enum { IdArg, MemArg };

public:
Expand All @@ -468,7 +463,7 @@ class LLVM_LIBRARY_VISIBILITY CoroBeginInst : public IntrinsicInst {
};

/// This represents the llvm.coro.save instruction.
class LLVM_LIBRARY_VISIBILITY CoroSaveInst : public IntrinsicInst {
class CoroSaveInst : public IntrinsicInst {
public:
// Methods to support type inquiry through isa, cast, and dyn_cast:
static bool classof(const IntrinsicInst *I) {
Expand All @@ -480,7 +475,7 @@ class LLVM_LIBRARY_VISIBILITY CoroSaveInst : public IntrinsicInst {
};

/// This represents the llvm.coro.promise instruction.
class LLVM_LIBRARY_VISIBILITY CoroPromiseInst : public IntrinsicInst {
class CoroPromiseInst : public IntrinsicInst {
enum { FrameArg, AlignArg, FromArg };

public:
Expand All @@ -505,7 +500,7 @@ class LLVM_LIBRARY_VISIBILITY CoroPromiseInst : public IntrinsicInst {
}
};

class LLVM_LIBRARY_VISIBILITY AnyCoroSuspendInst : public IntrinsicInst {
class AnyCoroSuspendInst : public IntrinsicInst {
public:
CoroSaveInst *getCoroSave() const;

Expand All @@ -521,7 +516,7 @@ class LLVM_LIBRARY_VISIBILITY AnyCoroSuspendInst : public IntrinsicInst {
};

/// This represents the llvm.coro.suspend instruction.
class LLVM_LIBRARY_VISIBILITY CoroSuspendInst : public AnyCoroSuspendInst {
class CoroSuspendInst : public AnyCoroSuspendInst {
enum { SaveArg, FinalArg };

public:
Expand Down Expand Up @@ -553,7 +548,7 @@ inline CoroSaveInst *AnyCoroSuspendInst::getCoroSave() const {
}

/// This represents the llvm.coro.suspend.async instruction.
class LLVM_LIBRARY_VISIBILITY CoroSuspendAsyncInst : public AnyCoroSuspendInst {
class CoroSuspendAsyncInst : public AnyCoroSuspendInst {
public:
enum {
StorageArgNoArg,
Expand Down Expand Up @@ -594,7 +589,7 @@ class LLVM_LIBRARY_VISIBILITY CoroSuspendAsyncInst : public AnyCoroSuspendInst {
};

/// This represents the llvm.coro.suspend.retcon instruction.
class LLVM_LIBRARY_VISIBILITY CoroSuspendRetconInst : public AnyCoroSuspendInst {
class CoroSuspendRetconInst : public AnyCoroSuspendInst {
public:
op_iterator value_begin() { return arg_begin(); }
const_op_iterator value_begin() const { return arg_begin(); }
Expand All @@ -619,7 +614,7 @@ class LLVM_LIBRARY_VISIBILITY CoroSuspendRetconInst : public AnyCoroSuspendInst
};

/// This represents the llvm.coro.size instruction.
class LLVM_LIBRARY_VISIBILITY CoroSizeInst : public IntrinsicInst {
class CoroSizeInst : public IntrinsicInst {
public:
// Methods to support type inquiry through isa, cast, and dyn_cast:
static bool classof(const IntrinsicInst *I) {
Expand All @@ -631,7 +626,7 @@ class LLVM_LIBRARY_VISIBILITY CoroSizeInst : public IntrinsicInst {
};

/// This represents the llvm.coro.align instruction.
class LLVM_LIBRARY_VISIBILITY CoroAlignInst : public IntrinsicInst {
class CoroAlignInst : public IntrinsicInst {
public:
// Methods to support type inquiry through isa, cast, and dyn_cast:
static bool classof(const IntrinsicInst *I) {
Expand All @@ -643,7 +638,7 @@ class LLVM_LIBRARY_VISIBILITY CoroAlignInst : public IntrinsicInst {
};

/// This represents the llvm.end.results instruction.
class LLVM_LIBRARY_VISIBILITY CoroEndResults : public IntrinsicInst {
class CoroEndResults : public IntrinsicInst {
public:
op_iterator retval_begin() { return arg_begin(); }
const_op_iterator retval_begin() const { return arg_begin(); }
Expand Down Expand Up @@ -671,7 +666,7 @@ class LLVM_LIBRARY_VISIBILITY CoroEndResults : public IntrinsicInst {
}
};

class LLVM_LIBRARY_VISIBILITY AnyCoroEndInst : public IntrinsicInst {
class AnyCoroEndInst : public IntrinsicInst {
enum { FrameArg, UnwindArg, TokenArg };

public:
Expand Down Expand Up @@ -700,7 +695,7 @@ class LLVM_LIBRARY_VISIBILITY AnyCoroEndInst : public IntrinsicInst {
};

/// This represents the llvm.coro.end instruction.
class LLVM_LIBRARY_VISIBILITY CoroEndInst : public AnyCoroEndInst {
class CoroEndInst : public AnyCoroEndInst {
public:
// Methods to support type inquiry through isa, cast, and dyn_cast:
static bool classof(const IntrinsicInst *I) {
Expand All @@ -712,7 +707,7 @@ class LLVM_LIBRARY_VISIBILITY CoroEndInst : public AnyCoroEndInst {
};

/// This represents the llvm.coro.end instruction.
class LLVM_LIBRARY_VISIBILITY CoroAsyncEndInst : public AnyCoroEndInst {
class CoroAsyncEndInst : public AnyCoroEndInst {
enum { FrameArg, UnwindArg, MustTailCallFuncArg };

public:
Expand All @@ -736,12 +731,11 @@ class LLVM_LIBRARY_VISIBILITY CoroAsyncEndInst : public AnyCoroEndInst {
};

/// This represents the llvm.coro.alloca.alloc instruction.
class LLVM_LIBRARY_VISIBILITY CoroAllocaAllocInst : public IntrinsicInst {
class CoroAllocaAllocInst : public IntrinsicInst {
enum { SizeArg, AlignArg };

public:
Value *getSize() const {
return getArgOperand(SizeArg);
}
Value *getSize() const { return getArgOperand(SizeArg); }
Align getAlignment() const {
return cast<ConstantInt>(getArgOperand(AlignArg))->getAlignValue();
}
Expand All @@ -756,8 +750,9 @@ class LLVM_LIBRARY_VISIBILITY CoroAllocaAllocInst : public IntrinsicInst {
};

/// This represents the llvm.coro.alloca.get instruction.
class LLVM_LIBRARY_VISIBILITY CoroAllocaGetInst : public IntrinsicInst {
class CoroAllocaGetInst : public IntrinsicInst {
enum { AllocArg };

public:
CoroAllocaAllocInst *getAlloc() const {
return cast<CoroAllocaAllocInst>(getArgOperand(AllocArg));
Expand All @@ -773,8 +768,9 @@ class LLVM_LIBRARY_VISIBILITY CoroAllocaGetInst : public IntrinsicInst {
};

/// This represents the llvm.coro.alloca.free instruction.
class LLVM_LIBRARY_VISIBILITY CoroAllocaFreeInst : public IntrinsicInst {
class CoroAllocaFreeInst : public IntrinsicInst {
enum { AllocArg };

public:
CoroAllocaAllocInst *getAlloc() const {
return cast<CoroAllocaAllocInst>(getArgOperand(AllocArg));
Expand All @@ -791,4 +787,4 @@ class LLVM_LIBRARY_VISIBILITY CoroAllocaFreeInst : public IntrinsicInst {

} // End namespace llvm.

#endif
#endif // LLVM_TRANSFORMS_COROUTINES_COROINSTR_H
Loading

0 comments on commit e82fcda

Please sign in to comment.