LLVM  10.0.0
Macros | Functions | Variables
CoroSplit.cpp File Reference
#include "CoroInstr.h"
#include "CoroInternal.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Analysis/CallGraphSCCPass.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/Verifier.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/ValueMapper.h"
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <initializer_list>
#include <iterator>
Include dependency graph for CoroSplit.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "coro-split"
 

Functions

static void maybeFreeRetconStorage (IRBuilder<> &Builder, const coro::Shape &Shape, Value *FramePtr, CallGraph *CG)
 
static void replaceFallthroughCoroEnd (CoroEndInst *End, const coro::Shape &Shape, Value *FramePtr, bool InResume, CallGraph *CG)
 Replace a non-unwind call to llvm.coro.end. More...
 
static void replaceUnwindCoroEnd (CoroEndInst *End, const coro::Shape &Shape, Value *FramePtr, bool InResume, CallGraph *CG)
 Replace an unwind call to llvm.coro.end. More...
 
static void replaceCoroEnd (CoroEndInst *End, const coro::Shape &Shape, Value *FramePtr, bool InResume, CallGraph *CG)
 
static void createResumeEntryBlock (Function &F, coro::Shape &Shape)
 
static Function * createCloneDeclaration (Function &OrigF, coro::Shape &Shape, const Twine &Suffix, Module::iterator InsertBefore)
 
static void replaceSwiftErrorOps (Function &F, coro::Shape &Shape, ValueToValueMapTy *VMap)
 
static Function * createClone (Function &F, const Twine &Suffix, coro::Shape &Shape, CoroCloner::Kind FKind)
 
static void removeCoroEnds (const coro::Shape &Shape, CallGraph *CG)
 Remove calls to llvm.coro.end in the original function. More...
 
static void replaceFrameSize (coro::Shape &Shape)
 
static void setCoroInfo (Function &F, coro::Shape &Shape, ArrayRef< Function *> Fns)
 
static void updateCoroFrame (coro::Shape &Shape, Function *ResumeFn, Function *DestroyFn, Function *CleanupFn)
 
static void postSplitCleanup (Function &F)
 
static void scanPHIsAndUpdateValueMap (Instruction *Prev, BasicBlock *NewBlock, DenseMap< Value *, Value *> &ResolvedValues)
 
static bool simplifyTerminatorLeadingToRet (Instruction *InitialInst)
 
static void addMustTailToCoroResumes (Function &F)
 
static void handleNoSuspendCoroutine (coro::Shape &Shape)
 
static bool hasCallsInBlockBetween (Instruction *From, Instruction *To)
 
static bool hasCallsInBlocksBetween (BasicBlock *SaveBB, BasicBlock *ResDesBB)
 
static bool hasCallsBetween (Instruction *Save, Instruction *ResumeOrDestroy)
 
static bool simplifySuspendPoint (CoroSuspendInst *Suspend, CoroBeginInst *CoroBegin)
 
static void simplifySuspendPoints (coro::Shape &Shape)
 
static void splitSwitchCoroutine (Function &F, coro::Shape &Shape, SmallVectorImpl< Function *> &Clones)
 
static void splitRetconCoroutine (Function &F, coro::Shape &Shape, SmallVectorImpl< Function *> &Clones)
 
static void splitCoroutine (Function &F, coro::Shape &Shape, SmallVectorImpl< Function *> &Clones)
 
static void splitCoroutine (Function &F, CallGraph &CG, CallGraphSCC &SCC)
 
static void prepareForSplit (Function &F, CallGraph &CG)
 
static void createDevirtTriggerFunc (CallGraph &CG, CallGraphSCC &SCC)
 
static void replacePrepare (CallInst *Prepare, CallGraph &CG)
 Replace a call to llvm.coro.prepare.retcon. More...
 
static bool replaceAllPrepares (Function *PrepareFn, CallGraph &CG)
 Remove calls to llvm.coro.prepare.retcon, a barrier meant to prevent IPO from operating on calls to a retcon coroutine before it's been split. More...
 
 INITIALIZE_PASS_BEGIN (CoroSplitLegacy, "coro-split", "Split coroutine into a set of functions driving its state machine", false, false) INITIALIZE_PASS_END(CoroSplitLegacy
 

Variables

coro split
 
coro Split coroutine into a set of functions driving its state machine
 
coro Split coroutine into a set of functions driving its state false
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "coro-split"

Definition at line 73 of file CoroSplit.cpp.

Function Documentation

◆ addMustTailToCoroResumes()

static void addMustTailToCoroResumes ( Function &  F)
static

◆ createClone()

static Function* createClone ( Function &  F,
const Twine &  Suffix,
coro::Shape &  Shape,
CoroCloner::Kind  FKind 
)
static

Definition at line 778 of file CoroSplit.cpp.

Referenced by splitSwitchCoroutine().

◆ createCloneDeclaration()

static Function* createCloneDeclaration ( Function &  OrigF,
coro::Shape &  Shape,
const Twine &  Suffix,
Module::iterator  InsertBefore 
)
static

◆ createDevirtTriggerFunc()

static void createDevirtTriggerFunc ( CallGraph &  CG,
CallGraphSCC &  SCC 
)
static

◆ createResumeEntryBlock()

static void createResumeEntryBlock ( Function &  F,
coro::Shape &  Shape 
)
static

◆ handleNoSuspendCoroutine()

static void handleNoSuspendCoroutine ( coro::Shape &  Shape)
static

◆ hasCallsBetween()

static bool hasCallsBetween ( Instruction *  Save,
Instruction *  ResumeOrDestroy 
)
static

◆ hasCallsInBlockBetween()

static bool hasCallsInBlockBetween ( Instruction *  From,
Instruction *  To 
)
static

Definition at line 1020 of file CoroSplit.cpp.

References I.

Referenced by hasCallsBetween(), and hasCallsInBlocksBetween().

◆ hasCallsInBlocksBetween()

static bool hasCallsInBlocksBetween ( BasicBlock *  SaveBB,
BasicBlock *  ResDesBB 
)
static

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( CoroSplitLegacy  ,
"coro-split"  ,
"Split coroutine into a set of functions driving its state machine"  ,
false  ,
false   
)

Referenced by replaceAllPrepares().

◆ maybeFreeRetconStorage()

static void maybeFreeRetconStorage ( IRBuilder<> &  Builder,
const coro::Shape &  Shape,
Value *  FramePtr,
CallGraph *  CG 
)
static

◆ postSplitCleanup()

static void postSplitCleanup ( Function &  F)
static

◆ prepareForSplit()

static void prepareForSplit ( Function &  F,
CallGraph &  CG 
)
static

◆ removeCoroEnds()

static void removeCoroEnds ( const coro::Shape &  Shape,
CallGraph *  CG 
)
static

Remove calls to llvm.coro.end in the original function.

Definition at line 786 of file CoroSplit.cpp.

Referenced by splitCoroutine().

◆ replaceAllPrepares()

static bool replaceAllPrepares ( Function *  PrepareFn,
CallGraph &  CG 
)
static

Remove calls to llvm.coro.prepare.retcon, a barrier meant to prevent IPO from operating on calls to a retcon coroutine before it's been split.

This is only safe to do after we've split all retcon coroutines in the module. We can do that this in this pass because this pass does promise to split all retcon coroutines (as opposed to switch coroutines, which are lowered in multiple stages).

Definition at line 1511 of file CoroSplit.cpp.

References CORO_PRESPLIT_ATTR, createDevirtTriggerFunc(), llvm::dbgs(), llvm::coro::declaresIntrinsics(), llvm::CallGraphSCCPass::doInitialization(), llvm::SmallVectorBase::empty(), F(), llvm::CallGraphSCCPass::getAnalysisUsage(), llvm::CallGraphSCC::getCallGraph(), llvm::Module::getFunction(), llvm::CallGraph::getModule(), llvm::PassRegistry::getPassRegistry(), llvm::Attribute::getValueAsString(), INITIALIZE_PASS_BEGIN(), INITIALIZE_PASS_DEPENDENCY, INITIALIZE_PASS_END(), llvm::initializeCoroSplitLegacyPass(), LLVM_DEBUG, prepareForSplit(), llvm::SmallVectorTemplateBase< T >::push_back(), replacePrepare(), splitCoroutine(), UNPREPARED_FOR_SPLIT, llvm::Value::use_begin(), and llvm::Value::use_end().

◆ replaceCoroEnd()

static void replaceCoroEnd ( CoroEndInst *  End,
const coro::Shape &  Shape,
Value *  FramePtr,
bool  InResume,
CallGraph *  CG 
)
static

Definition at line 250 of file CoroSplit.cpp.

Referenced by createCloneDeclaration().

◆ replaceFallthroughCoroEnd()

static void replaceFallthroughCoroEnd ( CoroEndInst *  End,
const coro::Shape &  Shape,
Value *  FramePtr,
bool  InResume,
CallGraph *  CG 
)
static

Replace a non-unwind call to llvm.coro.end.

Definition at line 173 of file CoroSplit.cpp.

◆ replaceFrameSize()

static void replaceFrameSize ( coro::Shape &  Shape)
static

◆ replacePrepare()

static void replacePrepare ( CallInst *  Prepare,
CallGraph &  CG 
)
static

◆ replaceSwiftErrorOps()

static void replaceSwiftErrorOps ( Function &  F,
coro::Shape &  Shape,
ValueToValueMapTy *  VMap 
)
static

◆ replaceUnwindCoroEnd()

static void replaceUnwindCoroEnd ( CoroEndInst *  End,
const coro::Shape &  Shape,
Value *  FramePtr,
bool  InResume,
CallGraph *  CG 
)
static

Replace an unwind call to llvm.coro.end.

Definition at line 223 of file CoroSplit.cpp.

◆ scanPHIsAndUpdateValueMap()

static void scanPHIsAndUpdateValueMap ( Instruction *  Prev,
BasicBlock *  NewBlock,
DenseMap< Value *, Value *> &  ResolvedValues 
)
static

◆ setCoroInfo()

static void setCoroInfo ( Function &  F,
coro::Shape &  Shape,
ArrayRef< Function *>  Fns 
)
static

◆ simplifySuspendPoint()

static bool simplifySuspendPoint ( CoroSuspendInst *  Suspend,
CoroBeginInst *  CoroBegin 
)
static

◆ simplifySuspendPoints()

static void simplifySuspendPoints ( coro::Shape &  Shape)
static

◆ simplifyTerminatorLeadingToRet()

static bool simplifyTerminatorLeadingToRet ( Instruction *  InitialInst)
static

◆ splitCoroutine() [1/2]

static void splitCoroutine ( Function &  F,
coro::Shape &  Shape,
SmallVectorImpl< Function *> &  Clones 
)
static

◆ splitCoroutine() [2/2]

static void splitCoroutine ( Function &  F,
CallGraph &  CG,
CallGraphSCC &  SCC 
)
static

◆ splitRetconCoroutine()

static void splitRetconCoroutine ( Function &  F,
coro::Shape &  Shape,
SmallVectorImpl< Function *> &  Clones 
)
static

Definition at line 1202 of file CoroSplit.cpp.

References llvm::coro::Shape::ABI, assert(), llvm::MCID::Branch, llvm::coro::Shape::CoroBegin, llvm::coro::Shape::CoroSuspends, llvm::BasicBlock::Create(), llvm::IRBuilder< T, Inserter >::CreateBitCast(), createCloneDeclaration(), llvm::IRBuilder< T, Inserter >::CreateInsertValue(), llvm::IRBuilder< T, Inserter >::CreatePHI(), llvm::IRBuilder< T, Inserter >::CreateRet(), llvm::IRBuilder< T, Inserter >::CreateStore(), llvm::numbers::e, E, llvm::coro::Shape::emitAlloc(), llvm::SmallVectorBase::empty(), F(), llvm::coro::Shape::FramePtr, llvm::coro::Shape::FrameTy, llvm::UndefValue::get(), llvm::Function::getContext(), llvm::Module::getDataLayout(), llvm::CoroBeginInst::getId(), llvm::IRBuilderBase::getInt64(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::GlobalValue::getParent(), llvm::coro::Shape::getRetconResultTypes(), llvm::Function::getReturnType(), llvm::Value::getType(), llvm::DataLayout::getTypeAllocSize(), llvm::TrackingVH< ValueTy >::getValPtr(), I, llvm::coro::Shape::RetconLoweringStorage::IsFrameInlineInStorage, llvm::NoAlias, print(), llvm::Value::printAsOperand(), llvm::SmallVectorTemplateBase< T >::push_back(), llvm::Function::removeAttribute(), llvm::Function::removeFnAttr(), llvm::Value::replaceAllUsesWith(), llvm::SmallVectorImpl< T >::reserve(), llvm::coro::Retcon, llvm::coro::Shape::RetconLowering, llvm::coro::RetconOnce, llvm::coro::Shape::RetconLoweringStorage::ReturnBlock, llvm::AttributeList::ReturnIndex, Size, and llvm::SmallVectorBase::size().

Referenced by splitCoroutine().

◆ splitSwitchCoroutine()

static void splitSwitchCoroutine ( Function &  F,
coro::Shape &  Shape,
SmallVectorImpl< Function *> &  Clones 
)
static

◆ updateCoroFrame()

static void updateCoroFrame ( coro::Shape &  Shape,
Function *  ResumeFn,
Function *  DestroyFn,
Function *  CleanupFn 
)
static

Variable Documentation

◆ false

coro Split coroutine into a set of functions driving its state false

Definition at line 1612 of file CoroSplit.cpp.

◆ machine

coro Split coroutine into a set of functions driving its state machine

Definition at line 1612 of file CoroSplit.cpp.

◆ split

coro split

Definition at line 1612 of file CoroSplit.cpp.

Referenced by llvm::createControlHeightReductionLegacyPass().