LLVM 20.0.0git
|
#include "llvm/Transforms/Coroutines/CoroSplit.h"
#include "CoroCloner.h"
#include "CoroInternal.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/PriorityWorklist.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/CFG.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.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/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/Verifier.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/Coroutines/MaterializationUtils.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/CallGraphUpdater.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/Local.h"
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <initializer_list>
#include <iterator>
Go to the source code of this file.
Macros | |
#define | DEBUG_TYPE "coro-split" |
#define DEBUG_TYPE "coro-split" |
Definition at line 79 of file CoroSplit.cpp.
|
static |
Definition at line 881 of file CoroSplit.cpp.
References llvm::AttrBuilder::addAttribute().
Referenced by llvm::coro::BaseCloner::create().
|
static |
Definition at line 866 of file CoroSplit.cpp.
References llvm::AttrBuilder::addAlignmentAttr(), llvm::AttrBuilder::addAttribute(), llvm::AttrBuilder::addDereferenceableAttr(), and Size.
Referenced by llvm::coro::BaseCloner::create().
|
static |
Definition at line 2143 of file CoroSplit.cpp.
References Name, and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by llvm::CoroSplitPass::run().
|
static |
Definition at line 888 of file CoroSplit.cpp.
References llvm::AttrBuilder::addAttribute().
Referenced by llvm::coro::BaseCloner::create().
|
static |
Definition at line 1690 of file CoroSplit.cpp.
References assert(), llvm::IRBuilderBase::CreateBitOrPointerCast(), getType(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and llvm::ArrayRef< T >::size().
Referenced by llvm::coro::createMustTailCall().
|
static |
Returns all DbgVariableIntrinsic in F.
Definition at line 641 of file CoroSplit.cpp.
References F, llvm::filterDbgVars(), I, instructions, and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by doSplitCoroutine(), and llvm::coro::BaseCloner::salvageDebugInfo().
|
static |
Definition at line 466 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, llvm::coro::Async, llvm::Function::Create(), getFunctionTypeFromAsyncSuspend(), llvm::Value::getName(), llvm::GlobalValue::getParent(), llvm::coro::Shape::getResumeFunctionType(), and llvm::GlobalValue::InternalLinkage.
Referenced by llvm::coro::SwitchCloner::create(), llvm::coro::AsyncABI::splitCoroutine(), and llvm::coro::AnyRetconABI::splitCoroutine().
|
static |
Definition at line 2152 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, llvm::coro::Async, llvm::coro::Shape::CoroBegin, F, llvm::CoroBeginInst::getCustomABI(), llvm::CoroBeginInst::hasCustomABI(), llvm_unreachable, llvm::coro::Retcon, llvm::coro::RetconOnce, llvm::SmallVectorBase< Size_T >::size(), and llvm::coro::Switch.
Referenced by llvm::CoroSplitPass::CoroSplitPass().
|
static |
Definition at line 2005 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), collectDbgVariableIntrinsics(), llvm::coro::Shape::CoroBegin, llvm::coro::Shape::CoroSuspends, F, handleNoSuspendCoroutine(), hasSafeElideCaller(), lowerAwaitSuspends(), llvm::coro::normalizeCoroutine(), removeCoroEndsFromRampFunction(), replaceFrameSizeAndAlignment(), replaceSwiftErrorOps(), llvm::coro::salvageDebugInfo(), simplifySuspendPoints(), and llvm::coro::Switch.
Referenced by llvm::CoroSplitPass::run().
|
static |
Definition at line 1156 of file CoroSplit.cpp.
References llvm::coro::Shape::CoroSizes, DL, and llvm::coro::Shape::FrameTy.
Referenced by replaceFrameSizeAndAlignment().
|
static |
Definition at line 458 of file CoroSplit.cpp.
References llvm::FunctionType::get(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), and llvm::Type::getVoidTy().
Referenced by createCloneDeclaration().
|
static |
Definition at line 1202 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, llvm::coro::Async, llvm::coro::Shape::CoroBegin, llvm::IRBuilderBase::CreateAlloca(), llvm::coro::Shape::FrameAlign, llvm::coro::Shape::FrameTy, llvm::PoisonValue::get(), llvm::AnyCoroIdInst::getCoroAlloc(), llvm::IRBuilderBase::getFalse(), llvm::coro::Shape::getSwitchCoroId(), llvm::coro::replaceCoroFree(), llvm::coro::Retcon, llvm::coro::RetconOnce, llvm::AllocaInst::setAlignment(), and llvm::coro::Switch.
Referenced by doSplitCoroutine().
|
static |
Definition at line 1277 of file CoroSplit.cpp.
References llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), hasCallsInBlockBetween(), and hasCallsInBlocksBetween().
Referenced by simplifySuspendPoint().
|
static |
Definition at line 1236 of file CoroSplit.cpp.
References I.
Referenced by hasCallsBetween(), and hasCallsInBlocksBetween().
|
static |
Definition at line 1248 of file CoroSplit.cpp.
References llvm::SmallVectorBase< Size_T >::empty(), hasCallsInBlockBetween(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::predecessors(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by hasCallsBetween().
|
static |
Definition at line 103 of file CoroSplit.cpp.
References llvm::IRBuilderBase::CreateCall(), llvm::IRBuilderBase::CreateInvoke(), llvm::Instruction::eraseFromParent(), llvm::CallingConv::Fast, FramePtr, llvm::CallBase::getAttributes(), llvm::CoroAwaitSuspendInst::getAwaiter(), llvm::CallBase::getCalledFunction(), llvm::IRBuilderBase::getContext(), llvm::Value::getContext(), llvm::CoroAwaitSuspendInst::getFrame(), llvm::IRBuilderBase::GetInsertPoint(), llvm::Function::getIntrinsicID(), llvm::Type::getVoidTy(), llvm::CoroAwaitSuspendInst::getWrapperFunction(), llvm_unreachable, llvm::coro::LowererBase::makeSubFnCall(), llvm::AttributeList::removeParamAttributes(), llvm::Value::replaceAllUsesWith(), llvm::CoroSubFnInst::ResumeIndex, llvm::CallBase::setAttributes(), llvm::CallBase::setCallingConv(), llvm::IRBuilderBase::SetInsertPoint(), llvm::coro::Shape::SymmetricTransfers, and Wrapper.
Referenced by lowerAwaitSuspends().
|
static |
Definition at line 169 of file CoroSplit.cpp.
References llvm::coro::Shape::CoroAwaitSuspends, F, and lowerAwaitSuspend().
Referenced by doSplitCoroutine().
|
static |
Definition at line 330 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), llvm::coro::Shape::CoroSuspends, llvm::IRBuilderBase::CreateStore(), llvm::IRBuilderBase::CreateStructGEP(), FramePtr, llvm::coro::Shape::FrameTy, llvm::ConstantPointerNull::get(), llvm::coro::Shape::getIndex(), llvm::coro::Shape::getSwitchIndexField(), llvm::StructType::getTypeAtIndex(), llvm::coro::Shape::SwitchLoweringStorage::HasFinalSuspend, llvm::coro::Shape::SwitchLoweringStorage::HasUnwindCoroEnd, llvm::coro::Shape::SwitchFieldIndex::Resume, and llvm::coro::Shape::SwitchLowering.
Referenced by replaceUnwindCoroEnd().
|
static |
Definition at line 175 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), llvm::coro::Shape::emitDealloc(), FramePtr, llvm::coro::Shape::RetconLoweringStorage::IsFrameInlineInStorage, and llvm::coro::Shape::RetconLowering.
Referenced by replaceFallthroughCoroEnd(), and replaceUnwindCoroEnd().
|
static |
Definition at line 1188 of file CoroSplit.cpp.
References llvm::errs(), F, llvm::removeUnreachableBlocks(), llvm::report_fatal_error(), and llvm::verifyFunction().
Referenced by updateCallGraphAfterCoroutineSplit().
|
static |
Definition at line 1973 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, llvm::coro::Shape::CoroEnds, End, llvm::coro::Shape::FramePtr, llvm::ConstantInt::getFalse(), replaceCoroEnd(), and llvm::coro::Switch.
Referenced by doSplitCoroutine().
|
static |
Definition at line 2130 of file CoroSplit.cpp.
References llvm::CallingConv::C, llvm::make_early_inc_range(), P, replacePrepare(), and llvm::Value::uses().
Referenced by llvm::CoroSplitPass::run().
|
static |
Definition at line 1675 of file CoroSplit.cpp.
References llvm::coro::Continuation, llvm::IRBuilderBase::CreateBitOrPointerCast(), llvm::PoisonValue::get(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::CoroSuspendAsyncInst::getResumeFunction(), llvm::PointerType::getUnqual(), llvm::Value::replaceAllUsesWith(), llvm::CoroSuspendAsyncInst::ResumeFunctionArg, and llvm::User::setOperand().
Referenced by llvm::coro::AsyncABI::splitCoroutine().
|
static |
Definition at line 402 of file CoroSplit.cpp.
References End, FramePtr, llvm::ConstantInt::getFalse(), llvm::ConstantInt::getTrue(), replaceFallthroughCoroEnd(), and replaceUnwindCoroEnd().
Referenced by removeCoroEndsFromRampFunction(), and llvm::coro::BaseCloner::replaceCoroEnds().
|
static |
Replace an llvm.coro.end.async.
Will inline the must tail call function call if there is one.
Definition at line 188 of file CoroSplit.cpp.
References assert(), llvm::IRBuilderBase::CreateRetVoid(), End, llvm::InlineFunction(), and llvm::IRBuilderBase::SetInsertPoint().
Referenced by replaceFallthroughCoroEnd().
|
static |
Replace a non-unwind call to llvm.coro.end.
Definition at line 231 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), llvm::IRBuilderBase::CreateInsertValue(), llvm::IRBuilderBase::CreateRet(), llvm::IRBuilderBase::CreateRetVoid(), End, FramePtr, llvm::ConstantTokenNone::get(), llvm::ConstantPointerNull::get(), llvm::PoisonValue::get(), llvm::coro::Shape::getResumeFunctionType(), llvm::FunctionType::getReturnType(), Idx, maybeFreeRetconStorage(), llvm::Value::replaceAllUsesWith(), replaceCoroEndAsync(), and RetTy.
Referenced by replaceCoroEnd().
|
static |
Definition at line 1164 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, llvm::coro::Async, llvm::coro::Shape::CoroAligns, llvm::coro::Shape::CoroSizes, llvm::Instruction::eraseFromParent(), llvm::coro::Shape::FrameAlign, getFrameSizeForShape(), llvm::Value::getType(), llvm::Value::replaceAllUsesWith(), updateAsyncFuncPointerContextSize(), and llvm::Align::value().
Referenced by doSplitCoroutine().
|
static |
Definition at line 2094 of file CoroSplit.cpp.
References llvm::Instruction::eraseFromParent(), llvm::CallBase::getArgOperand(), llvm::make_early_inc_range(), llvm::Value::replaceAllUsesWith(), llvm::Value::stripPointerCasts(), and llvm::Value::uses().
Referenced by replaceAllPrepares().
|
static |
Definition at line 582 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), llvm::coro::Async, llvm::coro::Shape::CoroSuspends, llvm::IRBuilderBase::CreateAlloca(), llvm::IRBuilderBase::CreateLoad(), llvm::IRBuilderBase::CreateStore(), F, llvm::Value::getType(), llvm::AllocaInst::setSwiftError(), and llvm::coro::Shape::SwiftErrorOps.
Referenced by llvm::coro::BaseCloner::create(), doSplitCoroutine(), and llvm::coro::BaseCloner::replaceSwiftErrorOps().
|
static |
Replace an unwind call to llvm.coro.end.
Definition at line 364 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, llvm::IRBuilderBase::CreateCleanupRet(), End, FramePtr, markCoroutineAsDone(), maybeFreeRetconStorage(), and llvm::LLVMContext::OB_funclet.
Referenced by replaceCoroEnd().
|
static |
Definition at line 1304 of file CoroSplit.cpp.
References llvm::BranchInst::Create(), llvm::Instruction::eraseFromParent(), llvm::CallBase::getCalledOperand(), llvm::CoroSuspendInst::getCoroSave(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getPrevNode(), hasCallsBetween(), I, llvm::Value::replaceAllUsesWith(), and llvm::Value::stripPointerCasts().
Referenced by simplifySuspendPoints().
|
static |
Definition at line 1364 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), llvm::coro::Shape::CoroBegin, llvm::coro::Shape::CoroSuspends, llvm::coro::Shape::SwitchLoweringStorage::HasFinalSuspend, I, N, simplifySuspendPoint(), std::swap(), llvm::coro::Switch, and llvm::coro::Shape::SwitchLowering.
Referenced by doSplitCoroutine().
|
static |
Definition at line 1141 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), llvm::coro::Async, llvm::coro::Shape::AsyncLoweringStorage::AsyncFuncPointer, llvm::coro::Shape::AsyncLowering, llvm::coro::Shape::AsyncLoweringStorage::ContextSize, llvm::ConstantStruct::get(), llvm::GlobalVariable::getInitializer(), and llvm::GlobalVariable::setInitializer().
Referenced by replaceFrameSizeAndAlignment().
|
static |
Definition at line 2055 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, llvm::LazyCallGraph::addSplitFunction(), llvm::LazyCallGraph::addSplitRefRecursiveFunctions(), llvm::coro::Async, llvm::CallingConv::C, llvm::SmallVectorBase< Size_T >::empty(), FAM, N, postSplitCleanup(), llvm::coro::Retcon, llvm::coro::RetconOnce, llvm::coro::Switch, llvm::updateCGAndAnalysisManagerForCGSCCPass(), and llvm::updateCGAndAnalysisManagerForFunctionPass().
Referenced by llvm::CoroSplitPass::run().
|
static |
Adjust the scope line of the funclet to the first line number after the suspend point.
This avoids a jump in the line table from the function declaration (where prologue instructions are attributed to) to the suspend point. Only adjust the scope line when the files are the same. If no candidate line number is found, fallback to the line of ActiveSuspend.
Definition at line 822 of file CoroSplit.cpp.
References DL, llvm::BasicBlock::end(), llvm::Instruction::getDebugLoc(), llvm::DIScope::getFile(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Instruction::getNextNonDebugInstruction(), llvm::skipDebugIntrinsics(), and llvm::Successor.
Referenced by llvm::coro::BaseCloner::create().