LLVM  10.0.0svn
Go to the documentation of this file.
1 //===- CoroInternal.h - Internal Coroutine interfaces ---------*- 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 // Common definitions/declarations used internally by coroutine lowering passes.
9 //===----------------------------------------------------------------------===//
14 #include "CoroInstr.h"
17 namespace llvm {
19 class CallGraph;
20 class CallGraphSCC;
21 class PassRegistry;
23 void initializeCoroEarlyPass(PassRegistry &);
24 void initializeCoroSplitPass(PassRegistry &);
25 void initializeCoroElidePass(PassRegistry &);
26 void initializeCoroCleanupPass(PassRegistry &);
28 // CoroEarly pass marks every function that has coro.begin with a string
29 // attribute "coroutine.presplit"="0". CoroSplit pass processes the coroutine
30 // twice. First, it lets it go through complete IPO optimization pipeline as a
31 // single function. It forces restart of the pipeline by inserting an indirect
32 // call to an empty function "coro.devirt.trigger" which is devirtualized by
33 // CoroElide pass that triggers a restart of the pipeline by CGPassManager.
34 // When CoroSplit pass sees the same coroutine the second time, it splits it up,
35 // adds coroutine subfunctions to the SCC to be processed by IPO pipeline.
37 #define CORO_PRESPLIT_ATTR "coroutine.presplit"
39 #define PREPARED_FOR_SPLIT "1"
41 #define CORO_DEVIRT_TRIGGER_FN "coro.devirt.trigger"
43 namespace coro {
45 bool declaresIntrinsics(Module &M, std::initializer_list<StringRef>);
46 void replaceAllCoroAllocs(CoroBeginInst *CB, bool Replacement);
47 void replaceAllCoroFrees(CoroBeginInst *CB, Value *Replacement);
48 void replaceCoroFree(CoroIdInst *CoroId, bool Elide);
50  CallGraph &CG, CallGraphSCC &SCC);
52 // Keeps data and helper functions for lowering coroutine intrinsics.
53 struct LowererBase {
60  LowererBase(Module &M);
61  Value *makeSubFnCall(Value *Arg, int Index, Instruction *InsertPt);
62 };
64 // Holds structural Coroutine Intrinsics for a particular function and other
65 // values used during CoroSplit pass.
72  // Field Indexes for known coroutine frame fields.
73  enum {
78  };
88  assert(FrameTy && "frame type not assigned");
89  return cast<IntegerType>(FrameTy->getElementType(IndexField));
90  }
91  ConstantInt *getIndex(uint64_t Value) const {
92  return ConstantInt::get(getIndexType(), Value);
93  }
95  Shape() = default;
96  explicit Shape(Function &F) { buildFrom(F); }
97  void buildFrom(Function &F);
98 };
102 } // End namespace coro.
103 } // End namespace llvm
105 #endif
Instruction * FramePtr
Definition: CoroInternal.h:81
CoroBeginInst * CoroBegin
Definition: CoroInternal.h:67
This represents the llvm.coro.alloc instruction.
Definition: CoroInstr.h:81
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Type * getElementType(unsigned N) const
Definition: DerivedTypes.h:346
void initializeCoroEarlyPass(PassRegistry &)
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
void initializeCoroElidePass(PassRegistry &)
Shape(Function &F)
Definition: CoroInternal.h:96
IntegerType * getIndexType() const
Definition: CoroInternal.h:87
PointerType *const Int8Ptr
Definition: CoroInternal.h:56
Class to represent struct types.
Definition: DerivedTypes.h:233
ConstantInt * getIndex(uint64_t Value) const
Definition: CoroInternal.h:91
Class to represent function types.
Definition: DerivedTypes.h:103
void initializeCoroSplitPass(PassRegistry &)
FunctionType *const ResumeFnType
Definition: CoroInternal.h:57
SmallVector< CoroSizeInst *, 2 > CoroSizes
Definition: CoroInternal.h:69
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
SmallVector< CoroSuspendInst *, 4 > CoroSuspends
Definition: CoroInternal.h:70
Class to represent pointers.
Definition: DerivedTypes.h:544
void replaceAllCoroFrees(CoroBeginInst *CB, Value *Replacement)
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:64
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked into a shared library...
Definition: Compiler.h:107
Class to represent integer types.
Definition: DerivedTypes.h:40
LLVMContext & Context
Definition: CoroInternal.h:55
StructType * FrameTy
Definition: CoroInternal.h:80
void replaceAllCoroAllocs(CoroBeginInst *CB, bool Replacement)
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
A constant pointer value that points to null.
Definition: Constants.h:538
ConstantPointerNull *const NullPtr
Definition: CoroInternal.h:58
void buildCoroutineFrame(Function &F, Shape &Shape)
Definition: CoroFrame.cpp:898
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:643
This class represents the llvm.coro.begin instruction.
Definition: CoroInstr.h:214
Value * makeSubFnCall(Value *Arg, int Index, Instruction *InsertPt)
Definition: Coroutines.cpp:107
void initializeCoroCleanupPass(PassRegistry &)
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:73
SwitchInst * ResumeSwitch
Definition: CoroInternal.h:83
void replaceCoroFree(CoroIdInst *CoroId, bool Elide)
Definition: Coroutines.cpp:152
Multiway switch.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SmallVector< CoroEndInst *, 4 > CoroEnds
Definition: CoroInternal.h:68
AllocaInst * PromiseAlloca
Definition: CoroInternal.h:84
LLVM Value Representation.
Definition: Value.h:72
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
bool declaresIntrinsics(Module &M, std::initializer_list< StringRef >)
Definition: Coroutines.cpp:139
BasicBlock * AllocaSpillBlock
Definition: CoroInternal.h:82
void updateCallGraph(Function &Caller, ArrayRef< Function *> Funcs, CallGraph &CG, CallGraphSCC &SCC)
Definition: Coroutines.cpp:193
an instruction to allocate memory on the stack
Definition: Instructions.h:59