LLVM 18.0.0git
|
#include "llvm/Transforms/Coroutines/CoroSplit.h"
#include "CoroInstr.h"
#include "CoroInternal.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/PriorityWorklist.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.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/DerivedTypes.h"
#include "llvm/IR/Dominators.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/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/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 "llvm/Transforms/Utils/ValueMapper.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 78 of file CoroSplit.cpp.
|
static |
Definition at line 913 of file CoroSplit.cpp.
References llvm::AttrBuilder::addAttribute(), and Context.
|
static |
Definition at line 898 of file CoroSplit.cpp.
References llvm::AttrBuilder::addAlignmentAttr(), llvm::AttrBuilder::addAttribute(), llvm::AttrBuilder::addDereferenceableAttr(), Context, and Size.
|
static |
Definition at line 1447 of file CoroSplit.cpp.
References F, I, instructions, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::removeUnreachableBlocks(), shouldBeMustTail(), simplifyTerminatorLeadingToRet(), llvm::TargetTransformInfo::supportsTailCallFor(), and llvm::CallInst::TCK_MustTail.
Referenced by splitSwitchCoroutine().
|
static |
Definition at line 2152 of file CoroSplit.cpp.
References Name, and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by llvm::CoroSplitPass::run().
|
static |
Definition at line 920 of file CoroSplit.cpp.
References llvm::AttrBuilder::addAttribute(), and Context.
|
static |
Definition at line 1727 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 729 of file CoroSplit.cpp.
References F, I, instructions, and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by splitCoroutine().
|
static |
|
static |
Definition at line 559 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, llvm::Function::Create(), getFunctionTypeFromAsyncSuspend(), llvm::Value::getName(), llvm::GlobalValue::getParent(), and llvm::coro::Shape::getResumeFunctionType().
Referenced by splitAsyncCoroutine(), and splitRetconCoroutine().
|
static |
Definition at line 412 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), llvm::CallingConv::C, llvm::coro::Shape::CoroSuspends, llvm::BasicBlock::Create(), llvm::PHINode::Create(), llvm::IRBuilderBase::CreateLoad(), llvm::IRBuilderBase::CreateStore(), llvm::IRBuilderBase::CreateStructGEP(), llvm::IRBuilderBase::CreateSwitch(), llvm::IRBuilderBase::CreateUnreachable(), F, FramePtr, llvm::coro::Shape::FramePtr, llvm::coro::Shape::FrameTy, llvm::ConstantTokenNone::get(), llvm::coro::Shape::getIndex(), llvm::coro::Shape::getIndexType(), llvm::IRBuilderBase::getInt8(), llvm::IRBuilderBase::getInt8Ty(), llvm::coro::Shape::getSwitchIndexField(), markCoroutineAsDone(), llvm::Value::replaceAllUsesWith(), llvm::coro::Shape::SwitchLoweringStorage::ResumeEntryBlock, llvm::coro::Shape::SwitchLoweringStorage::ResumeSwitch, llvm::IRBuilderBase::SetInsertPoint(), and llvm::coro::Shape::SwitchLowering.
Referenced by splitSwitchCoroutine().
|
static |
Definition at line 551 of file CoroSplit.cpp.
References Context, llvm::Function::getContext(), llvm::BasicBlock::getParent(), llvm::Instruction::getParent(), and llvm::Type::getVoidTy().
Referenced by createCloneDeclaration().
|
static |
Definition at line 1472 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, llvm::coro::Shape::CoroBegin, llvm::IRBuilderBase::CreateAlloca(), llvm::coro::Shape::FrameAlign, llvm::coro::Shape::FrameTy, llvm::UndefValue::get(), llvm::AnyCoroIdInst::getCoroAlloc(), llvm::IRBuilderBase::getFalse(), llvm::CoroBeginInst::getId(), llvm::coro::replaceCoroFree(), and llvm::AllocaInst::setAlignment().
Referenced by splitCoroutine().
|
static |
Definition at line 1547 of file CoroSplit.cpp.
References llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getNextNode(), llvm::Instruction::getParent(), hasCallsInBlockBetween(), and hasCallsInBlocksBetween().
Referenced by simplifySuspendPoint().
|
static |
Definition at line 1506 of file CoroSplit.cpp.
Referenced by hasCallsBetween(), and hasCallsInBlocksBetween().
|
static |
Definition at line 1518 of file CoroSplit.cpp.
References llvm::SmallPtrSetImpl< PtrType >::contains(), llvm::SmallVectorBase< Size_T >::empty(), llvm::SmallPtrSetImpl< PtrType >::erase(), hasCallsInBlockBetween(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::predecessors(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by hasCallsBetween().
|
static |
Definition at line 325 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 createResumeEntryBlock(), and replaceUnwindCoroEnd().
|
static |
Definition at line 170 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 1268 of file CoroSplit.cpp.
References llvm::errs(), F, llvm::removeUnreachableBlocks(), llvm::report_fatal_error(), and llvm::verifyFunction().
Referenced by splitSwitchCoroutine(), and updateCallGraphAfterCoroutineSplit().
|
static |
Definition at line 2050 of file CoroSplit.cpp.
References llvm::coro::Shape::CoroEnds, End, llvm::coro::Shape::FramePtr, and replaceCoroEnd().
Referenced by updateCallGraphAfterCoroutineSplit().
|
static |
Definition at line 2139 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 1712 of file CoroSplit.cpp.
References Context, llvm::IRBuilderBase::CreateBitOrPointerCast(), llvm::UndefValue::get(), llvm::Function::getContext(), llvm::BasicBlock::getParent(), llvm::Instruction::getParent(), llvm::CoroSuspendAsyncInst::getResumeFunction(), llvm::Value::replaceAllUsesWith(), llvm::CoroSuspendAsyncInst::ResumeFunctionArg, and llvm::User::setOperand().
Referenced by splitAsyncCoroutine().
|
static |
Definition at line 397 of file CoroSplit.cpp.
References Context, End, FramePtr, llvm::ConstantInt::getFalse(), llvm::ConstantInt::getTrue(), replaceFallthroughCoroEnd(), and replaceUnwindCoroEnd().
Referenced by removeCoroEnds().
|
static |
Replace an llvm.coro.end.async.
Will inline the must tail call function call if there is one.
Definition at line 184 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 227 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::UndefValue::get(), llvm::coro::Shape::getResumeFunctionType(), llvm::FunctionType::getReturnType(), Idx, maybeFreeRetconStorage(), llvm::Value::replaceAllUsesWith(), replaceCoroEndAsync(), and RetTy.
Referenced by replaceCoroEnd().
|
static |
Definition at line 1181 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, llvm::coro::Shape::CoroAligns, llvm::coro::Shape::CoroSizes, DL, llvm::Instruction::eraseFromParent(), llvm::coro::Shape::FrameAlign, llvm::coro::Shape::FrameTy, llvm::ConstantInt::get(), llvm::Value::getType(), llvm::Value::replaceAllUsesWith(), Size, updateAsyncFuncPointerContextSize(), and llvm::Align::value().
Referenced by splitCoroutine().
|
static |
Definition at line 2103 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 672 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), 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 splitCoroutine().
|
static |
Replace an unwind call to llvm.coro.end.
Definition at line 359 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 1283 of file CoroSplit.cpp.
References llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::Instruction::getParent(), and llvm::BasicBlock::phis().
Referenced by simplifyTerminatorLeadingToRet().
|
static |
Definition at line 1218 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), llvm::ArrayRef< T >::begin(), llvm::CallingConv::C, llvm::ArrayRef< T >::end(), F, llvm::ConstantArray::get(), llvm::GlobalValue::getParent(), llvm::ConstantExpr::getPointerCast(), llvm::coro::Shape::getSwitchCoroId(), llvm::GlobalValue::getType(), and llvm::CoroIdInst::setInfo().
Referenced by splitSwitchCoroutine().
Definition at line 1412 of file CoroSplit.cpp.
References F, llvm::CallBase::getAttributes(), llvm::CallBase::getCallingConv(), llvm::CallBase::getFunctionType(), llvm::Type::getPointerAddressSpace(), llvm::CallBase::isInlineAsm(), and llvm::Type::isPointerTy().
Referenced by addMustTailToCoroResumes().
|
static |
Definition at line 1572 of file CoroSplit.cpp.
References llvm::BranchInst::Create(), llvm::Instruction::eraseFromParent(), llvm::CallBase::getCalledOperand(), llvm::CoroSuspendInst::getCoroSave(), llvm::Instruction::getParent(), llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getPrevNode(), llvm::BasicBlock::getSinglePredecessor(), hasCallsBetween(), I, llvm::Value::replaceAllUsesWith(), and llvm::Value::stripPointerCasts().
Referenced by simplifySuspendPoints().
|
static |
Definition at line 1632 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(), and llvm::coro::Shape::SwitchLowering.
Referenced by splitCoroutine().
|
static |
Definition at line 1300 of file CoroSplit.cpp.
References assert(), Cond, llvm::ConstantFoldCompareInstOperands(), DL, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::Module::getDataLayout(), llvm::BasicBlock::getFirstNonPHIOrDbgOrLifetime(), llvm::Instruction::getModule(), I, llvm::isInstructionTriviallyDead(), llvm::ReplaceInstWithInst(), and scanPHIsAndUpdateValueMap().
Referenced by addMustTailToCoroResumes().
|
static |
Definition at line 1758 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), llvm::coro::Shape::AsyncLowering, Context, llvm::coro::Shape::CoroBegin, llvm::coro::Shape::CoroSuspends, llvm::BasicBlock::Create(), llvm::IRBuilderBase::CreateBitOrPointerCast(), createCloneDeclaration(), llvm::IRBuilderBase::CreateConstInBoundsGEP1_32(), llvm::coro::createMustTailCall(), llvm::IRBuilderBase::CreateRetVoid(), llvm::ArrayRef< T >::drop_front(), llvm::SmallVectorBase< Size_T >::empty(), End, F, llvm::coro::Shape::AsyncLoweringStorage::FrameOffset, FramePtr, llvm::coro::Shape::FramePtr, llvm::CoroBeginInst::getId(), llvm::Type::getInt8Ty(), llvm::TrackingVH< ValueTy >::getValPtr(), Idx, llvm::InlineFunction(), llvm::CoroSuspendAsyncInst::MustTailCallFuncArg, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::Value::replaceAllUsesWith(), replaceAsyncResumeFunction(), llvm::SmallVectorImpl< T >::reserve(), and llvm::SmallVectorBase< Size_T >::size().
Referenced by splitCoroutine().
|
static |
Definition at line 1998 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, collectDbgVariableIntrinsics(), llvm::coro::Shape::CoroBegin, llvm::coro::Shape::CoroSuspends, F, handleNoSuspendCoroutine(), llvm::coro::Shape::OptimizeFrame, llvm::removeUnreachableBlocks(), replaceFrameSizeAndAlignment(), replaceSwiftErrorOps(), llvm::coro::salvageDebugInfo(), simplifySuspendPoints(), splitAsyncCoroutine(), splitRetconCoroutine(), and splitSwitchCoroutine().
Referenced by llvm::CoroSplitPass::run().
|
static |
Definition at line 1855 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), llvm::coro::Shape::CoroBegin, llvm::coro::Shape::CoroSuspends, llvm::BasicBlock::Create(), llvm::IRBuilderBase::CreateBitCast(), createCloneDeclaration(), llvm::IRBuilderBase::CreateInsertValue(), llvm::IRBuilderBase::CreatePHI(), llvm::IRBuilderBase::CreateRet(), llvm::IRBuilderBase::CreateStore(), DL, E, llvm::coro::Shape::emitAlloc(), llvm::SmallVectorBase< Size_T >::empty(), F, llvm::coro::Shape::FramePtr, llvm::coro::Shape::FrameTy, llvm::PoisonValue::get(), llvm::CoroBeginInst::getId(), llvm::IRBuilderBase::getInt64(), llvm::coro::Shape::getRetconResultTypes(), llvm::Value::getType(), llvm::TrackingVH< ValueTy >::getValPtr(), I, llvm::coro::Shape::RetconLoweringStorage::IsFrameInlineInStorage, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::Value::replaceAllUsesWith(), llvm::SmallVectorImpl< T >::reserve(), llvm::coro::Shape::RetconLowering, RetTy, llvm::coro::Shape::RetconLoweringStorage::ReturnBlock, llvm::SmallVectorBase< Size_T >::size(), and Size.
Referenced by splitCoroutine().
|
static |
Definition at line 1673 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, addMustTailToCoroResumes(), assert(), createClone(), createResumeEntryBlock(), llvm::SmallVectorBase< Size_T >::empty(), F, postSplitCleanup(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), setCoroInfo(), llvm::TargetTransformInfo::supportsTailCalls(), and updateCoroFrame().
Referenced by splitCoroutine().
|
static |
Definition at line 1166 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), llvm::coro::Shape::AsyncLoweringStorage::AsyncFuncPointer, llvm::coro::Shape::AsyncLowering, llvm::coro::Shape::AsyncLoweringStorage::ContextSize, llvm::ConstantStruct::get(), llvm::ConstantInt::get(), llvm::GlobalVariable::getInitializer(), and llvm::GlobalVariable::setInitializer().
Referenced by replaceFrameSizeAndAlignment().
|
static |
Definition at line 2056 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, llvm::LazyCallGraph::addSplitFunction(), llvm::LazyCallGraph::addSplitRefRecursiveFunctions(), llvm::CallingConv::C, Context, llvm::coro::Shape::CoroBegin, llvm::coro::Shape::CoroEnds, llvm::SmallVectorBase< Size_T >::empty(), End, FAM, llvm::ConstantInt::getFalse(), N, postSplitCleanup(), removeCoroEnds(), llvm::updateCGAndAnalysisManagerForCGSCCPass(), and llvm::updateCGAndAnalysisManagerForFunctionPass().
Referenced by llvm::CoroSplitPass::run().
|
static |
Definition at line 1242 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), llvm::IRBuilderBase::CreateSelect(), llvm::IRBuilderBase::CreateStore(), llvm::IRBuilderBase::CreateStructGEP(), llvm::coro::Shape::SwitchFieldIndex::Destroy, llvm::coro::Shape::FramePtr, llvm::coro::Shape::FrameTy, llvm::AnyCoroIdInst::getCoroAlloc(), llvm::coro::Shape::getInsertPtAfterFramePtr(), llvm::coro::Shape::getSwitchCoroId(), and llvm::coro::Shape::SwitchFieldIndex::Resume.
Referenced by splitSwitchCoroutine().