|
LLVM
10.0.0
|
#include "CoroInternal.h"#include "llvm/ADT/BitVector.h"#include "llvm/Analysis/PtrUseVisitor.h"#include "llvm/Transforms/Utils/Local.h"#include "llvm/Config/llvm-config.h"#include "llvm/IR/CFG.h"#include "llvm/IR/Dominators.h"#include "llvm/IR/IRBuilder.h"#include "llvm/IR/InstIterator.h"#include "llvm/Support/Debug.h"#include "llvm/Support/MathExtras.h"#include "llvm/Support/circular_raw_ostream.h"#include "llvm/Transforms/Utils/BasicBlockUtils.h"#include "llvm/Transforms/Utils/PromoteMemToReg.h"Go to the source code of this file.
Macros | |
| #define | DEBUG_TYPE "coro-suspend-crossing" |
| #define | DEBUG_TYPE "coro-frame" |
Typedefs | |
| using | SpillInfo = SmallVector< Spill, 8 > |
| typedef SmallPtrSet< BasicBlock *, 8 > | VisitedBlocksSet |
Enumerations | |
| enum | { SmallVectorThreshold = 32 } |
Functions | |
| static void | dump (StringRef Title, SpillInfo const &Spills) |
| static StructType * | buildFrameType (Function &F, coro::Shape &Shape, SpillInfo &Spills) |
| static bool | mightWriteIntoAllocaPtr (AllocaInst &A, const DominatorTree &DT, const CoroBeginInst &CB) |
| static Instruction * | splitBeforeCatchSwitch (CatchSwitchInst *CatchSwitch) |
| static Instruction * | insertSpills (const SpillInfo &Spills, coro::Shape &Shape) |
| static void | setUnwindEdgeTo (Instruction *TI, BasicBlock *Succ) |
| static void | updatePhiNodes (BasicBlock *DestBB, BasicBlock *OldPred, BasicBlock *NewPred, PHINode *LandingPadReplacement) |
| static BasicBlock * | ehAwareSplitEdge (BasicBlock *BB, BasicBlock *Succ, LandingPadInst *OriginalPad, PHINode *LandingPadReplacement) |
| static void | rewritePHIs (BasicBlock &BB) |
| static void | rewritePHIs (Function &F) |
| static bool | materializable (Instruction &V) |
| static bool | isCoroutineStructureIntrinsic (Instruction &I) |
| static void | rewriteMaterializableInstructions (IRBuilder<> &IRB, SpillInfo const &Spills) |
| static BasicBlock * | splitBlockIfNotFirst (Instruction *I, const Twine &Name) |
| static void | splitAround (Instruction *I, const Twine &Name) |
| static bool | isSuspendBlock (BasicBlock *BB) |
| static bool | isSuspendReachableFrom (BasicBlock *From, VisitedBlocksSet &VisitedOrFreeBBs) |
| Does control flow starting at the given block ever reach a suspend instruction before reaching a block in VisitedOrFreeBBs? More... | |
| static bool | isLocalAlloca (CoroAllocaAllocInst *AI) |
| Is the given alloca "local", i.e. More... | |
| static bool | willLeaveFunctionImmediatelyAfter (BasicBlock *BB, unsigned depth=3) |
| After we split the coroutine, will the given basic block be along an obvious exit path for the resumption function? More... | |
| static bool | localAllocaNeedsStackSave (CoroAllocaAllocInst *AI) |
| static void | lowerLocalAllocas (ArrayRef< CoroAllocaAllocInst *> LocalAllocas, SmallVectorImpl< Instruction *> &DeadInsts) |
| Turn each of the given local allocas into a normal (dynamic) alloca instruction. More... | |
| static Instruction * | lowerNonLocalAlloca (CoroAllocaAllocInst *AI, coro::Shape &Shape, SmallVectorImpl< Instruction *> &DeadInsts) |
| Turn the given coro.alloca.alloc call into a dynamic allocation. More... | |
| static Value * | emitGetSwiftErrorValue (IRBuilder<> &Builder, Type *ValueTy, coro::Shape &Shape) |
| Get the current swifterror value. More... | |
| static Value * | emitSetSwiftErrorValue (IRBuilder<> &Builder, Value *V, coro::Shape &Shape) |
| Set the given value as the current swifterror value. More... | |
| static Value * | emitSetAndGetSwiftErrorValueAround (Instruction *Call, AllocaInst *Alloca, coro::Shape &Shape) |
| Set the swifterror value from the given alloca before a call, then put in back in the alloca afterwards. More... | |
| static void | eliminateSwiftErrorAlloca (Function &F, AllocaInst *Alloca, coro::Shape &Shape) |
| Eliminate a formerly-swifterror alloca by inserting the get/set intrinsics and attempting to MemToReg the alloca away. More... | |
| static void | eliminateSwiftErrorArgument (Function &F, Argument &Arg, coro::Shape &Shape, SmallVectorImpl< AllocaInst *> &AllocasToPromote) |
| "Eliminate" a swifterror argument by reducing it to the alloca case and then loading and storing in the prologue and epilog. More... | |
| static void | eliminateSwiftError (Function &F, coro::Shape &Shape) |
| Eliminate all problematic uses of swifterror arguments and allocas from the function. More... | |
Variables | |
| static const unsigned | InvalidFieldIndex = ~0U |
| #define DEBUG_TYPE "coro-suspend-crossing" |
Definition at line 281 of file CoroFrame.cpp.
| #define DEBUG_TYPE "coro-frame" |
Definition at line 281 of file CoroFrame.cpp.
| using SpillInfo = SmallVector<Spill, 8> |
Definition at line 319 of file CoroFrame.cpp.
| typedef SmallPtrSet<BasicBlock*, 8> VisitedBlocksSet |
Definition at line 1016 of file CoroFrame.cpp.
| anonymous enum |
| Enumerator | |
|---|---|
| SmallVectorThreshold | |
Definition at line 40 of file CoroFrame.cpp.
|
static |
Definition at line 395 of file CoroFrame.cpp.
References llvm::coro::Shape::ABI, assert(), C, llvm::coro::Shape::CoroSuspends, llvm::StructType::create(), llvm::DominatorTree::dominates(), llvm::FunctionType::get(), llvm::ArrayType::get(), llvm::Function::getContext(), llvm::Module::getDataLayout(), llvm::PointerType::getElementType(), llvm::Type::getInt1Ty(), llvm::Type::getIntNTy(), llvm::Value::getName(), llvm::GlobalValue::getParent(), llvm::Type::getPointerTo(), llvm::coro::Shape::getPromiseAlloca(), llvm::coro::Shape::getRetconCoroId(), llvm::AllocaInst::getType(), llvm::Value::getType(), llvm::Type::getVoidTy(), I, llvm::coro::Shape::RetconLoweringStorage::IsFrameInlineInStorage, llvm::Log2_64_Ceil(), llvm::max(), Name, llvm::SmallVectorTemplateBase< T >::push_back(), llvm::report_fatal_error(), llvm::coro::Retcon, llvm::coro::Shape::RetconLowering, llvm::coro::RetconOnce, llvm::StructType::setBody(), SI, llvm::SmallVectorBase::size(), and llvm::coro::Switch.
Definition at line 322 of file CoroFrame.cpp.
References llvm::alignTo(), Context, llvm::dbgs(), llvm::Value::dump(), E, llvm::ArrayType::get(), llvm::DataLayout::getABITypeAlignment(), llvm::Type::getInt8Ty(), llvm::DataLayout::getTypeAllocSize(), and llvm::max().
Referenced by llvm::RegBankSelect::EdgeInsertPoint::canMaterialize(), computeBranchTargetAndInversion(), DoInitialMatch(), getSetupCost(), llvm::FullDependence::isSplitable(), mayUsePostIncMode(), operator<<(), llvm::AppleAcceleratorTable::readAtoms(), and llvm::ScoreboardHazardRecognizer::Reset().
|
static |
Definition at line 836 of file CoroFrame.cpp.
References llvm::PHINode::addIncoming(), llvm::Instruction::clone(), llvm::BasicBlock::Create(), llvm::BranchInst::Create(), llvm::CleanupPadInst::Create(), llvm::CleanupReturnInst::Create(), llvm::BasicBlock::getContext(), llvm::BasicBlock::getFirstNonPHI(), llvm::BasicBlock::getParent(), llvm::BasicBlock::getTerminator(), llvm::Instruction::isEHPad(), llvm_unreachable, setUnwindEdgeTo(), llvm::SplitEdge(), llvm::MCID::Terminator, and updatePhiNodes().
Referenced by rewritePHIs().
|
static |
Eliminate all problematic uses of swifterror arguments and allocas from the function.
We'll fix them up later when splitting the function.
Definition at line 1294 of file CoroFrame.cpp.
References Arg, llvm::Function::args(), llvm::dyn_cast(), eliminateSwiftErrorAlloca(), eliminateSwiftErrorArgument(), llvm::SmallVectorBase::empty(), llvm::Function::getEntryBlock(), llvm::PromoteMemToReg(), llvm::SmallVectorTemplateBase< T >::push_back(), and llvm::AllocaInst::setSwiftError().
Referenced by llvm::coro::buildCoroutineFrame().
|
static |
Eliminate a formerly-swifterror alloca by inserting the get/set intrinsics and attempting to MemToReg the alloca away.
Definition at line 1226 of file CoroFrame.cpp.
References assert(), emitSetAndGetSwiftErrorValueAround(), llvm::Use::getUser(), llvm::isAllocaPromotable(), llvm::Use::set(), llvm::Value::use_begin(), and llvm::Value::use_end().
Referenced by eliminateSwiftError().
|
static |
"Eliminate" a swifterror argument by reducing it to the alloca case and then loading and storing in the prologue and epilog.
The argument keeps the swifterror flag.
Definition at line 1257 of file CoroFrame.cpp.
References llvm::coro::Shape::CoroSuspends, llvm::IRBuilder< T, Inserter >::CreateAlloca(), emitSetAndGetSwiftErrorValueAround(), llvm::Function::getEntryBlock(), llvm::BasicBlock::getFirstNonPHIOrDbg(), llvm::Constant::getNullValue(), llvm::Value::getType(), and llvm::Value::replaceAllUsesWith().
Referenced by eliminateSwiftError().
|
static |
Get the current swifterror value.
Definition at line 1163 of file CoroFrame.cpp.
References llvm::IRBuilder< T, Inserter >::CreateCall(), llvm::FunctionType::get(), llvm::ConstantPointerNull::get(), and llvm::coro::Shape::SwiftErrorOps.
Referenced by emitSetAndGetSwiftErrorValueAround().
|
static |
Set the swifterror value from the given alloca before a call, then put in back in the alloca afterwards.
Returns an address that will stand in for the swifterror slot until splitting.
Definition at line 1196 of file CoroFrame.cpp.
References llvm::IRBuilder< T, Inserter >::CreateLoad(), llvm::IRBuilder< T, Inserter >::CreateStore(), emitGetSwiftErrorValue(), emitSetSwiftErrorValue(), llvm::AllocaInst::getAllocatedType(), llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getNextNode(), and llvm::IRBuilderBase::SetInsertPoint().
Referenced by eliminateSwiftErrorAlloca(), and eliminateSwiftErrorArgument().
|
static |
Set the given value as the current swifterror value.
Returns a slot that can be used as a swifterror slot.
Definition at line 1178 of file CoroFrame.cpp.
References llvm::IRBuilder< T, Inserter >::CreateCall(), llvm::FunctionType::get(), llvm::ConstantPointerNull::get(), llvm::Type::getPointerTo(), llvm::Value::getType(), and llvm::coro::Shape::SwiftErrorOps.
Referenced by emitSetAndGetSwiftErrorValueAround().
|
static |
Definition at line 586 of file CoroFrame.cpp.
References llvm::coro::Shape::ABI, llvm::coro::Shape::AllocaSpillBlock, Arg, assert(), C, llvm::SmallVectorImpl< T >::clear(), llvm::coro::Shape::CoroBegin, E, llvm::SmallVectorImpl< T >::emplace_back(), llvm::SmallVectorBase::empty(), llvm::coro::Shape::FrameTy, llvm::BasicBlock::front(), G, llvm::ConstantInt::get(), llvm::Value::getContext(), llvm::BasicBlock::getFirstInsertionPt(), llvm::BasicBlock::getFirstNonPHI(), llvm::Type::getInt32Ty(), llvm::Instruction::getParent(), getParent(), llvm::coro::Shape::getPromiseAlloca(), llvm::BasicBlock::getSingleSuccessor(), llvm::BasicBlock::getTerminator(), I, InvalidFieldIndex, llvm::AllocaInst::isArrayAllocation(), mightWriteIntoAllocaPtr(), P, llvm::coro::Shape::SwitchFieldIndex::Promise, llvm::SmallVectorTemplateBase< T >::push_back(), llvm::report_fatal_error(), llvm::BasicBlock::splitBasicBlock(), splitBeforeCatchSwitch(), llvm::SplitEdge(), llvm::coro::Switch, and llvm::Value::users().
|
static |
Definition at line 948 of file CoroFrame.cpp.
References I.
Referenced by llvm::coro::buildCoroutineFrame().
|
static |
Is the given alloca "local", i.e.
bounded in lifetime to not cross a suspend point?
Definition at line 1043 of file CoroFrame.cpp.
References llvm::Instruction::getParent(), llvm::SmallPtrSetImpl< PtrType >::insert(), isSuspendReachableFrom(), and llvm::Value::users().
Referenced by llvm::coro::buildCoroutineFrame().
|
static |
Definition at line 1012 of file CoroFrame.cpp.
References llvm::BasicBlock::front().
Referenced by isSuspendReachableFrom(), and willLeaveFunctionImmediatelyAfter().
|
static |
Does control flow starting at the given block ever reach a suspend instruction before reaching a block in VisitedOrFreeBBs?
Definition at line 1020 of file CoroFrame.cpp.
References llvm::SmallPtrSetImpl< PtrType >::insert(), isSuspendBlock(), and llvm::successors().
Referenced by isLocalAlloca().
|
static |
Definition at line 1076 of file CoroFrame.cpp.
References llvm::dyn_cast(), llvm::Value::users(), and willLeaveFunctionImmediatelyAfter().
Referenced by lowerLocalAllocas().
|
static |
Turn each of the given local allocas into a normal (dynamic) alloca instruction.
Definition at line 1094 of file CoroFrame.cpp.
References llvm::IRBuilder< T, Inserter >::CreateAlloca(), llvm::IRBuilder< T, Inserter >::CreateCall(), llvm::Intrinsic::getDeclaration(), llvm::IRBuilderBase::getInt8Ty(), localAllocaNeedsStackSave(), llvm::SmallVectorTemplateBase< T >::push_back(), llvm::AllocaInst::setAlignment(), and llvm::IRBuilderBase::SetInsertPoint().
|
static |
Turn the given coro.alloca.alloc call into a dynamic allocation.
This happens during the all-instructions iteration, so it must not delete the call.
Definition at line 1138 of file CoroFrame.cpp.
|
static |
Definition at line 941 of file CoroFrame.cpp.
Referenced by llvm::coro::buildCoroutineFrame().
|
static |
Definition at line 524 of file CoroFrame.cpp.
References llvm::dbgs(), llvm::Module::getDataLayout(), llvm::Instruction::getModule(), and LLVM_DEBUG.
Referenced by insertSpills().
|
static |
Definition at line 955 of file CoroFrame.cpp.
References assert(), E, llvm::BasicBlock::getFirstInsertionPt(), llvm::Value::getName(), llvm::Instruction::insertBefore(), and llvm::Value::setName().
Referenced by llvm::coro::buildCoroutineFrame().
|
static |
Definition at line 867 of file CoroFrame.cpp.
References llvm::PHINode::addIncoming(), llvm::PHINode::Create(), llvm::dyn_cast(), ehAwareSplitEdge(), llvm::Instruction::eraseFromParent(), llvm::StringRef::front(), llvm::BasicBlock::front(), llvm::BasicBlock::getFirstNonPHI(), llvm::Value::getName(), llvm::Value::getType(), llvm::pred_begin(), llvm::pred_end(), llvm::Value::replaceAllUsesWith(), and llvm::Value::takeName().
Referenced by llvm::coro::buildCoroutineFrame(), and rewritePHIs().
|
static |
Definition at line 927 of file CoroFrame.cpp.
References llvm::SmallVectorTemplateBase< T >::push_back(), and rewritePHIs().
|
static |
Definition at line 796 of file CoroFrame.cpp.
References llvm_unreachable.
Referenced by ehAwareSplitEdge().
|
static |
Definition at line 1007 of file CoroFrame.cpp.
References llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getNextNode(), Name, and splitBlockIfNotFirst().
Referenced by llvm::coro::buildCoroutineFrame().
|
static |
Definition at line 552 of file CoroFrame.cpp.
References llvm::CleanupPadInst::Create(), llvm::CleanupReturnInst::Create(), llvm::Instruction::eraseFromParent(), llvm::Instruction::getParent(), llvm::CatchSwitchInst::getParentPad(), llvm::BasicBlock::getTerminator(), and llvm::BasicBlock::splitBasicBlock().
Referenced by insertSpills().
|
static |
Definition at line 994 of file CoroFrame.cpp.
References llvm::Instruction::getParent(), I, and llvm::Value::setName().
Referenced by splitAround().
|
static |
Definition at line 809 of file CoroFrame.cpp.
References assert(), llvm::BasicBlock::begin(), llvm::PHINode::getBasicBlockIndex(), llvm::PHINode::getIncomingBlock(), I, and llvm::PHINode::setIncomingBlock().
Referenced by ehAwareSplitEdge().
|
static |
After we split the coroutine, will the given basic block be along an obvious exit path for the resumption function?
Definition at line 1057 of file CoroFrame.cpp.
References isSuspendBlock(), and llvm::successors().
Referenced by localAllocaNeedsStackSave().
Definition at line 286 of file CoroFrame.cpp.
Referenced by insertSpills().
1.8.13