Lines Matching +full:normal +full:-

1 //===--- CGCleanup.cpp - Bookkeeping and code emission for cleanups -------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
15 // normal control flow, or both.
17 //===----------------------------------------------------------------------===//
57 /// Given a saved r-value produced by SaveRValue, perform the code
76 llvm_unreachable("bad saved r-value kind"); in restore()
79 /// Push an entry of the given size onto this protected-scope stack.
87 } else if (static_cast<size_t>(StartOfData - StartOfBuffer) < Size) { in allocate()
88 unsigned CurrentCapacity = EndOfBuffer - StartOfBuffer; in allocate()
89 unsigned UsedCapacity = CurrentCapacity - (StartOfData - StartOfBuffer); in allocate()
98 char *NewStartOfData = NewEndOfBuffer - UsedCapacity; in allocate()
107 StartOfData -= Size; in allocate()
119 if (!cleanup || !cleanup->isLifetimeMarker()) in containsOnlyLifetimeMarkers()
130 if (cleanup->isLifetimeMarker()) { in requiresLandingPad()
131 si = cleanup->getEnclosingEHScope(); in requiresLandingPad()
158 // Per C++ [except.terminate], it is implementation-defined whether none, in pushCleanup()
163 find(InnermostEHScope)->getKind() == EHScope::Terminate) in pushCleanup()
178 Scope->setLifetimeMarker(); in pushCleanup()
180 // With Windows -EHa, Invoke llvm.seh.scope.begin() for EHCleanup in pushCleanup()
184 // consistent with MSVC's behavior, except in the presence of -EHa. in pushCleanup()
186 if (CGF->getLangOpts().EHAsynch && IsEHCleanup && !IsLifetimeMarker && in pushCleanup()
187 CGF->getTarget().getCXXABI().isMicrosoft() && CGF->getInvokeDest()) in pushCleanup()
188 CGF->EmitSehCppScopeBegin(); in pushCleanup()
190 return Scope->getCleanupBuffer(); in pushCleanup()
205 // Check whether we can shrink the branch-fixups stack. in popCleanup()
207 // If we no longer have any normal cleanups, all the fixups are in popCleanup()
250 /// fixups than the fixup depth on the innermost normal cleanup, or
256 // normal cleanup; otherwise there really shouldn't be any fixups. in popNullFixups()
299 store->setAlignment(addr.getAlignment().getAsAlign()); in createStoreInstBefore()
311 /// outermost normal cleanup; resolve them all by adding cases to the
335 Fixup.InitialBranch->setSuccessor(0, CleanupEntry); in ResolveAllBranchFixups()
342 Switch->addCase(CGF.Builder.getInt32(Fixup.DestinationIndex), in ResolveAllBranchFixups()
349 /// Transitions the terminator of the given exit-block of a cleanup to
355 llvm::Instruction *Term = Block->getTerminator(); in TransitionToCleanupSwitch()
359 assert(Br->isUnconditional()); in TransitionToCleanupSwitch()
363 llvm::SwitchInst::Create(Load, Br->getSuccessor(0), 4, Block); in TransitionToCleanupSwitch()
364 Br->eraseFromParent(); in TransitionToCleanupSwitch()
376 "branch fixups exist with no normal cleanups on stack"); in ResolveBranchFixups()
402 Switch->addCase(Builder.getInt32(Fixup.DestinationIndex), Block); in ResolveBranchFixups()
420 // As long as Old strictly encloses the scope's enclosing normal in PopCleanupBlocks()
421 // cleanup, we're going to emit another normal cleanup which in PopCleanupBlocks()
445 if (AI && AI->isStaticAlloca()) in PopCleanupBlocks()
449 CreateDefaultAlignTempAlloca(Inst->getType(), "tmp.exprcleanup"); in PopCleanupBlocks()
454 InsertBefore = Invoke->getNormalDest()->getFirstInsertionPt(); in PopCleanupBlocks()
456 InsertBefore = std::next(Inst->getIterator()); in PopCleanupBlocks()
465 /// cleanups from the given savepoint in the lifetime-extended cleanups stack.
516 llvm::BasicBlock *Pred = Entry->getSinglePredecessor(); in SimplifyCleanupEntry()
519 llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Pred->getTerminator()); in SimplifyCleanupEntry()
520 if (!Br || Br->isConditional()) return Entry; in SimplifyCleanupEntry()
521 assert(Br->getSuccessor(0) == Entry); in SimplifyCleanupEntry()
527 assert(!WasInsertBlock || CGF.Builder.GetInsertPoint() == Entry->end()); in SimplifyCleanupEntry()
530 Br->eraseFromParent(); in SimplifyCleanupEntry()
534 Entry->replaceAllUsesWith(Pred); in SimplifyCleanupEntry()
537 Pred->splice(Pred->end(), Entry); in SimplifyCleanupEntry()
540 Entry->eraseFromParent(); in SimplifyCleanupEntry()
565 Fn->Emit(CGF, flags); in EmitCleanup()
578 llvm::Instruction *Term = Exit->getTerminator(); in ForwardPrebranchedFallthrough()
581 assert(Br->isUnconditional() && Br->getSuccessor(0) == From); in ForwardPrebranchedFallthrough()
582 Br->setSuccessor(0, To); in ForwardPrebranchedFallthrough()
585 for (unsigned I = 0, E = Switch->getNumSuccessors(); I != E; ++I) in ForwardPrebranchedFallthrough()
586 if (Switch->getSuccessor(I) == From) in ForwardPrebranchedFallthrough()
587 Switch->setSuccessor(I, To); in ForwardPrebranchedFallthrough()
591 /// We don't need a normal entry block for the given cleanup.
605 i = entry->use_begin(), e = entry->use_end(); i != e; ) { in destroyOptimisticNormalEntry()
613 if (si->getNumCases() == 1 && si->getDefaultDest() == unreachableBB) { in destroyOptimisticNormalEntry()
615 llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(), si); in destroyOptimisticNormalEntry()
617 // The switch operand is a load from the cleanup-dest alloca. in destroyOptimisticNormalEntry()
618 llvm::LoadInst *condition = cast<llvm::LoadInst>(si->getCondition()); in destroyOptimisticNormalEntry()
621 si->eraseFromParent(); in destroyOptimisticNormalEntry()
624 assert(condition->getOperand(0) == CGF.NormalCleanupDest.getPointer()); in destroyOptimisticNormalEntry()
625 assert(condition->use_empty()); in destroyOptimisticNormalEntry()
626 condition->eraseFromParent(); in destroyOptimisticNormalEntry()
630 assert(entry->use_empty()); in destroyOptimisticNormalEntry()
634 /// Pops a cleanup block. If the block includes a normal cleanup, the
644 // If we are deactivating a normal cleanup, we need to pretend that the in PopCleanupBlock()
666 // Check the three conditions which might require a normal cleanup: in PopCleanupBlock()
668 // - whether there are branch fix-ups through this cleanup in PopCleanupBlock()
672 // - whether there are branch-throughs or branch-afters in PopCleanupBlock()
675 // - whether there's a fallthrough in PopCleanupBlock()
680 // Branch-through fall-throughs leave the insertion point set to the in PopCleanupBlock()
685 (FallthroughSource && FallthroughSource->getTerminator()); in PopCleanupBlock()
687 // If this is a normal cleanup, then having a prebranched in PopCleanupBlock()
692 FallthroughSource->getTerminator()->getSuccessor(0) in PopCleanupBlock()
701 // If we have a prebranched fallthrough into an inactive normal in PopCleanupBlock()
717 // Otherwise, we need to make a new block. If the normal cleanup in PopCleanupBlock()
718 // isn't being used at all, we could actually reuse the normal in PopCleanupBlock()
722 prebranchDest = createBasicBlock("forwarded-prebranch"); in PopCleanupBlock()
727 assert(normalEntry && !normalEntry->use_empty()); in PopCleanupBlock()
771 // Under -EHa, invoke seh.scope.end() to mark scope end before dtor in PopCleanupBlock()
775 // Mark CPP scope end for passed-by-value Arg temp in PopCleanupBlock()
778 // If we are deactivating a normal cleanup then we don't have a in PopCleanupBlock()
797 // mark SEH scope end for fall-through flow in PopCleanupBlock()
822 // destination index. For fall-throughs this is always zero. in PopCleanupBlock()
839 // intercept normal cleanup to mark SEH scope end in PopCleanupBlock()
853 // Compute the branch-through dest if we need it: in PopCleanupBlock()
854 // - if there are branch-throughs threaded through the scope in PopCleanupBlock()
855 // - if fall-through is a branch-through in PopCleanupBlock()
856 // - if there are fixups that will be optimistically forwarded in PopCleanupBlock()
870 // If there's exactly one branch-after and no other threads, in PopCleanupBlock()
873 // abnormal termination. (SEH: Except _leave and fall-through at in PopCleanupBlock()
884 if (NormalCleanupDestSlot->hasOneUse()) { in PopCleanupBlock()
885 NormalCleanupDestSlot->user_back()->eraseFromParent(); in PopCleanupBlock()
886 NormalCleanupDestSlot->eraseFromParent(); in PopCleanupBlock()
893 // Build a switch-out if we need it: in PopCleanupBlock()
894 // - if there are branch-afters threaded through the scope in PopCleanupBlock()
895 // - if fall-through is a branch-after in PopCleanupBlock()
896 // - if there are fixups that have nowhere left to go and in PopCleanupBlock()
905 // TODO: base this on the number of branch-afters and fixups in PopCleanupBlock()
919 // Branch-after fallthrough. in PopCleanupBlock()
923 Switch->addCase(Builder.getInt32(0), FallthroughDest); in PopCleanupBlock()
927 Switch->addCase(Scope.getBranchAfterIndex(I), in PopCleanupBlock()
936 // We should always have a branch-through destination in this case. in PopCleanupBlock()
951 InstsToAppend[I]->insertInto(NormalExit, NormalExit->end()); in PopCleanupBlock()
962 Fixup.InitialBranch->setSuccessor(0, NormalEntry); in PopCleanupBlock()
973 // Non-prebranched fallthrough doesn't need to be forwarded. in PopCleanupBlock()
998 // This might invalidate (non-IR) pointers to NormalEntry. in PopCleanupBlock()
1038 // Non-MSVC personalities need to terminate when an EH cleanup throws. in PopCleanupBlock()
1068 /// isObviouslyBranchWithoutCleanups - Return true if a branch to the
1075 // Calculate the innermost active normal cleanup. in isObviouslyBranchWithoutCleanups()
1079 // If we're not in an active normal cleanup scope, or if the in isObviouslyBranchWithoutCleanups()
1080 // destination scope is within the innermost active normal cleanup in isObviouslyBranchWithoutCleanups()
1092 /// the current cleanup-protected scope. The target scope may not yet
1095 /// As a side-effect, this method clears the insertion point.
1106 // Calculate the innermost active normal cleanup. in EmitBranchThroughCleanup()
1110 // If we're not in an active normal cleanup scope, or if the in EmitBranchThroughCleanup()
1111 // destination scope is within the innermost active normal cleanup in EmitBranchThroughCleanup()
1132 // Otherwise, thread through all the normal cleanups in scope. in EmitBranchThroughCleanup()
1142 BI->setSuccessor(0, CreateNormalEntry(*this, Scope)); in EmitBranchThroughCleanup()
1175 if (EHStack.find(cleanup)->hasEHBranches()) in IsUsedAsEHCleanup()
1202 /// extra uses *after* the change-over point.
1219 // - as a normal cleanup in SetupCleanupBlockActivation()
1225 // - as an EH cleanup in SetupCleanupBlockActivation()
1327 // Invoke a llvm.seh.scope.begin at the beginning of a CPP scope for -EHa
1337 // Invoke a llvm.seh.scope.end at the end of a CPP scope for -EHa
1348 // Invoke a llvm.seh.try.begin at the beginning of a SEH scope for -EHa
1358 // Invoke a llvm.seh.try.end at the end of a SEH scope for -EHa