LLVM 17.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 860 of file CoroSplit.cpp.
References llvm::AttrBuilder::addAttribute(), and Context.
|
static |
Definition at line 845 of file CoroSplit.cpp.
References llvm::AttrBuilder::addAlignmentAttr(), llvm::AttrBuilder::addAttribute(), llvm::AttrBuilder::addDereferenceableAttr(), Context, and Size.
|
static |
Definition at line 1380 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 2096 of file CoroSplit.cpp.
References Name, and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by llvm::CoroSplitPass::run().
|
static |
Definition at line 867 of file CoroSplit.cpp.
References llvm::AttrBuilder::addAttribute(), and Context.
|
static |
Definition at line 1661 of file CoroSplit.cpp.
References assert(), Builder, getType(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and llvm::ArrayRef< T >::size().
Referenced by llvm::coro::createMustTailCall().
|
static |
|
static |
Definition at line 508 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 359 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), Builder, llvm::CallingConv::C, llvm::coro::Shape::CoroSuspends, llvm::BasicBlock::Create(), llvm::PHINode::Create(), F, FramePtr, llvm::coro::Shape::FramePtr, llvm::coro::Shape::FrameTy, llvm::ConstantTokenNone::get(), llvm::coro::Shape::getIndex(), llvm::coro::Shape::getIndexType(), llvm::coro::Shape::getSwitchIndexField(), llvm::coro::Shape::SwitchLoweringStorage::HasUnwindCoroEnd, markCoroutineAsDone(), llvm::coro::Shape::SwitchLoweringStorage::ResumeEntryBlock, llvm::coro::Shape::SwitchLoweringStorage::ResumeSwitch, and llvm::coro::Shape::SwitchLowering.
Referenced by splitSwitchCoroutine().
|
static |
Definition at line 500 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 1405 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, Builder, llvm::coro::Shape::CoroBegin, llvm::coro::Shape::FrameAlign, llvm::coro::Shape::FrameTy, llvm::UndefValue::get(), llvm::AnyCoroIdInst::getCoroAlloc(), llvm::CoroBeginInst::getId(), and llvm::coro::replaceCoroFree().
Referenced by splitCoroutine().
|
static |
Definition at line 1481 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 1440 of file CoroSplit.cpp.
Referenced by hasCallsBetween(), and hasCallsInBlocksBetween().
|
static |
Definition at line 1452 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 292 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), Builder, FramePtr, llvm::coro::Shape::FrameTy, llvm::ConstantPointerNull::get(), llvm::StructType::getTypeAtIndex(), and llvm::coro::Shape::SwitchFieldIndex::Resume.
Referenced by createResumeEntryBlock(), and replaceUnwindCoroEnd().
|
static |
Definition at line 170 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), Builder, llvm::coro::Shape::emitDealloc(), FramePtr, llvm::coro::Shape::RetconLoweringStorage::IsFrameInlineInStorage, and llvm::coro::Shape::RetconLowering.
Referenced by replaceFallthroughCoroEnd(), and replaceUnwindCoroEnd().
|
static |
Definition at line 1202 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 1994 of file CoroSplit.cpp.
References llvm::coro::Shape::CoroEnds, llvm::coro::Shape::FramePtr, and replaceCoroEnd().
Referenced by updateCallGraphAfterCoroutineSplit().
|
static |
Definition at line 2083 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 1646 of file CoroSplit.cpp.
References Builder, Context, llvm::UndefValue::get(), llvm::Function::getContext(), llvm::Type::getInt8PtrTy(), llvm::BasicBlock::getParent(), llvm::Instruction::getParent(), llvm::CoroSuspendAsyncInst::getResumeFunction(), llvm::CoroSuspendAsyncInst::ResumeFunctionArg, and llvm::User::setOperand().
Referenced by splitAsyncCoroutine().
|
static |
Definition at line 344 of file CoroSplit.cpp.
References Context, 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(), Builder, and llvm::InlineFunction().
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, Builder, FramePtr, llvm::ConstantPointerNull::get(), llvm::UndefValue::get(), llvm::coro::Shape::getResumeFunctionType(), llvm::FunctionType::getReturnType(), maybeFreeRetconStorage(), replaceCoroEndAsync(), and RetTy.
Referenced by replaceCoroEnd().
|
static |
Definition at line 1115 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 2047 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 621 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, Arg, assert(), Builder, llvm::coro::Shape::CoroSuspends, F, llvm::Value::getType(), and llvm::coro::Shape::SwiftErrorOps.
Referenced by splitCoroutine().
|
static |
Replace an unwind call to llvm.coro.end.
Definition at line 306 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, Builder, FramePtr, markCoroutineAsDone(), maybeFreeRetconStorage(), and llvm::LLVMContext::OB_funclet.
Referenced by replaceCoroEnd().
|
static |
Definition at line 1217 of file CoroSplit.cpp.
References llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::Instruction::getParent(), llvm::BasicBlock::phis(), and VI.
Referenced by simplifyTerminatorLeadingToRet().
|
static |
Definition at line 1152 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::Type::getInt8PtrTy(), llvm::GlobalValue::getParent(), llvm::ConstantExpr::getPointerCast(), llvm::coro::Shape::getSwitchCoroId(), llvm::GlobalValue::getType(), and llvm::CoroIdInst::setInfo().
Referenced by splitSwitchCoroutine().
Definition at line 1345 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 1506 of file CoroSplit.cpp.
References Callee, 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 1566 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, SI, simplifySuspendPoint(), std::swap(), and llvm::coro::Shape::SwitchLowering.
Referenced by splitCoroutine().
|
static |
Definition at line 1234 of file CoroSplit.cpp.
References assert(), Cond, llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldTerminator(), 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(), llvm::Instruction::getParent(), llvm::BasicBlock::getTerminator(), I, llvm::isInstructionTriviallyDead(), llvm::BasicBlock::removePredecessor(), llvm::ReplaceInstWithInst(), scanPHIsAndUpdateValueMap(), and SI.
Referenced by addMustTailToCoroResumes().
|
static |
Definition at line 1692 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), llvm::coro::Shape::AsyncLowering, Builder, Context, llvm::coro::Shape::CoroBegin, llvm::coro::Shape::CoroSuspends, llvm::BasicBlock::Create(), createCloneDeclaration(), llvm::coro::createMustTailCall(), llvm::ArrayRef< T >::drop_front(), llvm::SmallVectorBase< Size_T >::empty(), F, llvm::coro::Shape::AsyncLoweringStorage::FrameOffset, FramePtr, llvm::coro::Shape::FramePtr, llvm::CoroBeginInst::getId(), llvm::Type::getInt8PtrTy(), 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 1934 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, llvm::coro::Shape::CoroBegin, llvm::coro::Shape::CoroSuspends, F, handleNoSuspendCoroutine(), I, llvm::coro::Shape::OptimizeFrame, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::removeUnreachableBlocks(), replaceFrameSizeAndAlignment(), replaceSwiftErrorOps(), llvm::coro::salvageDebugInfo(), simplifySuspendPoints(), splitAsyncCoroutine(), splitRetconCoroutine(), and splitSwitchCoroutine().
Referenced by llvm::CoroSplitPass::run().
|
static |
Definition at line 1789 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), Builder, llvm::coro::Shape::CoroBegin, llvm::coro::Shape::CoroSuspends, llvm::BasicBlock::Create(), createCloneDeclaration(), DL, E, llvm::coro::Shape::emitAlloc(), llvm::SmallVectorBase< Size_T >::empty(), F, llvm::coro::Shape::FramePtr, llvm::coro::Shape::FrameTy, llvm::UndefValue::get(), llvm::CoroBeginInst::getId(), llvm::Type::getPointerTo(), 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 1607 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 1100 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 2000 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(), FAM, llvm::ConstantInt::getFalse(), N, postSplitCleanup(), removeCoroEnds(), llvm::updateCGAndAnalysisManagerForCGSCCPass(), and llvm::updateCGAndAnalysisManagerForFunctionPass().
Referenced by llvm::CoroSplitPass::run().
|
static |
Definition at line 1176 of file CoroSplit.cpp.
References llvm::coro::Shape::ABI, assert(), Builder, 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().