LLVM  8.0.1
CoroInternal.h
Go to the documentation of this file.
1 //===- CoroInternal.h - Internal Coroutine interfaces ---------*- C++ -*---===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // Common definitions/declarations used internally by coroutine lowering passes.
10 //===----------------------------------------------------------------------===//
11 
12 #ifndef LLVM_LIB_TRANSFORMS_COROUTINES_COROINTERNAL_H
13 #define LLVM_LIB_TRANSFORMS_COROUTINES_COROINTERNAL_H
14 
15 #include "CoroInstr.h"
17 
18 namespace llvm {
19 
20 class CallGraph;
21 class CallGraphSCC;
22 class PassRegistry;
23 
24 void initializeCoroEarlyPass(PassRegistry &);
25 void initializeCoroSplitPass(PassRegistry &);
26 void initializeCoroElidePass(PassRegistry &);
27 void initializeCoroCleanupPass(PassRegistry &);
28 
29 // CoroEarly pass marks every function that has coro.begin with a string
30 // attribute "coroutine.presplit"="0". CoroSplit pass processes the coroutine
31 // twice. First, it lets it go through complete IPO optimization pipeline as a
32 // single function. It forces restart of the pipeline by inserting an indirect
33 // call to an empty function "coro.devirt.trigger" which is devirtualized by
34 // CoroElide pass that triggers a restart of the pipeline by CGPassManager.
35 // When CoroSplit pass sees the same coroutine the second time, it splits it up,
36 // adds coroutine subfunctions to the SCC to be processed by IPO pipeline.
37 
38 #define CORO_PRESPLIT_ATTR "coroutine.presplit"
39 #define UNPREPARED_FOR_SPLIT "0"
40 #define PREPARED_FOR_SPLIT "1"
41 
42 #define CORO_DEVIRT_TRIGGER_FN "coro.devirt.trigger"
43 
44 namespace coro {
45 
46 bool declaresIntrinsics(Module &M, std::initializer_list<StringRef>);
47 void replaceAllCoroAllocs(CoroBeginInst *CB, bool Replacement);
48 void replaceAllCoroFrees(CoroBeginInst *CB, Value *Replacement);
49 void replaceCoroFree(CoroIdInst *CoroId, bool Elide);
51  CallGraph &CG, CallGraphSCC &SCC);
52 
53 // Keeps data and helper functions for lowering coroutine intrinsics.
54 struct LowererBase {
60 
61  LowererBase(Module &M);
62  Value *makeSubFnCall(Value *Arg, int Index, Instruction *InsertPt);
63 };
64 
65 // Holds structural Coroutine Intrinsics for a particular function and other
66 // values used during CoroSplit pass.
72 
73  // Field Indexes for known coroutine frame fields.
74  enum {
79  };
80 
87 
89  assert(FrameTy && "frame type not assigned");
90  return cast<IntegerType>(FrameTy->getElementType(IndexField));
91  }
92  ConstantInt *getIndex(uint64_t Value) const {
93  return ConstantInt::get(getIndexType(), Value);
94  }
95 
96  Shape() = default;
97  explicit Shape(Function &F) { buildFrom(F); }
98  void buildFrom(Function &F);
99 };
100 
102 
103 } // End namespace coro.
104 } // End namespace llvm
105 
106 #endif
Instruction * FramePtr
Definition: CoroInternal.h:82
CoroBeginInst * CoroBegin
Definition: CoroInternal.h:68
This represents the llvm.coro.alloc instruction.
Definition: CoroInstr.h:82
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Type * getElementType(unsigned N) const
Definition: DerivedTypes.h:314
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:97
IntegerType * getIndexType() const
Definition: CoroInternal.h:88
F(f)
PointerType *const Int8Ptr
Definition: CoroInternal.h:57
Class to represent struct types.
Definition: DerivedTypes.h:201
ConstantInt * getIndex(uint64_t Value) const
Definition: CoroInternal.h:92
Class to represent function types.
Definition: DerivedTypes.h:103
void initializeCoroSplitPass(PassRegistry &)
FunctionType *const ResumeFnType
Definition: CoroInternal.h:58
SmallVector< CoroSizeInst *, 2 > CoroSizes
Definition: CoroInternal.h:70
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
SmallVector< CoroSuspendInst *, 4 > CoroSuspends
Definition: CoroInternal.h:71
Class to represent pointers.
Definition: DerivedTypes.h:467
void replaceAllCoroFrees(CoroBeginInst *CB, Value *Replacement)
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
Class to represent integer types.
Definition: DerivedTypes.h:40
LLVMContext & Context
Definition: CoroInternal.h:56
StructType * FrameTy
Definition: CoroInternal.h:81
void replaceAllCoroAllocs(CoroBeginInst *CB, bool Replacement)
This is the shared class of boolean and integer constants.
Definition: Constants.h:84
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
A constant pointer value that points to null.
Definition: Constants.h:539
ConstantPointerNull *const NullPtr
Definition: CoroInternal.h:59
void buildCoroutineFrame(Function &F, Shape &Shape)
Definition: CoroFrame.cpp:866
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:622
This class represents the llvm.coro.begin instruction.
Definition: CoroInstr.h:215
Value * makeSubFnCall(Value *Arg, int Index, Instruction *InsertPt)
Definition: Coroutines.cpp:108
amdgpu Simplify well known AMD library false Value Value * Arg
void initializeCoroCleanupPass(PassRegistry &)
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:74
SwitchInst * ResumeSwitch
Definition: CoroInternal.h:84
#define LLVM_LIBRARY_VISIBILITY
LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked into a shared library...
Definition: Compiler.h:108
void replaceCoroFree(CoroIdInst *CoroId, bool Elide)
Definition: Coroutines.cpp:153
Multiway switch.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SmallVector< CoroEndInst *, 4 > CoroEnds
Definition: CoroInternal.h:69
AllocaInst * PromiseAlloca
Definition: CoroInternal.h:85
LLVM Value Representation.
Definition: Value.h:73
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
bool declaresIntrinsics(Module &M, std::initializer_list< StringRef >)
Definition: Coroutines.cpp:140
BasicBlock * AllocaSpillBlock
Definition: CoroInternal.h:83
void updateCallGraph(Function &Caller, ArrayRef< Function *> Funcs, CallGraph &CG, CallGraphSCC &SCC)
Definition: Coroutines.cpp:194
an instruction to allocate memory on the stack
Definition: Instructions.h:60