21#include "llvm/Support/SaveAndRestore.h"
24using namespace CodeGen;
65 case AggregateLiteral:
66 case AggregateAddress:
69 case ComplexAddress: {
76 llvm_unreachable(
"bad saved r-value kind");
80char *EHScopeStack::allocate(
size_t Size) {
83 unsigned Capacity = 1024;
84 while (Capacity < Size) Capacity *= 2;
85 StartOfBuffer =
new char[Capacity];
86 StartOfData = EndOfBuffer = StartOfBuffer + Capacity;
87 }
else if (
static_cast<size_t>(StartOfData - StartOfBuffer) < Size) {
88 unsigned CurrentCapacity = EndOfBuffer - StartOfBuffer;
89 unsigned UsedCapacity = CurrentCapacity - (StartOfData - StartOfBuffer);
91 unsigned NewCapacity = CurrentCapacity;
94 }
while (NewCapacity < UsedCapacity + Size);
96 char *NewStartOfBuffer =
new char[NewCapacity];
97 char *NewEndOfBuffer = NewStartOfBuffer + NewCapacity;
98 char *NewStartOfData = NewEndOfBuffer - UsedCapacity;
99 memcpy(NewStartOfData, StartOfData, UsedCapacity);
100 delete [] StartOfBuffer;
101 StartOfBuffer = NewStartOfBuffer;
102 EndOfBuffer = NewEndOfBuffer;
103 StartOfData = NewStartOfData;
106 assert(StartOfBuffer + Size <= StartOfData);
111void EHScopeStack::deallocate(
size_t Size) {
119 if (!cleanup || !cleanup->isLifetimeMarker())
129 if (
auto *cleanup = dyn_cast<EHCleanupScope>(&*
find(si)))
130 if (cleanup->isLifetimeMarker()) {
131 si = cleanup->getEnclosingEHScope();
145 if (cleanup.isActive())
return si;
146 si = cleanup.getEnclosingNormalCleanup();
152void *EHScopeStack::pushCleanup(
CleanupKind Kind,
size_t Size) {
171 InnermostNormalCleanup,
177 if (IsLifetimeMarker)
178 Scope->setLifetimeMarker();
186 if (CGF->
getLangOpts().EHAsynch && IsEHCleanup && !IsLifetimeMarker &&
190 return Scope->getCleanupBuffer();
194 assert(!
empty() &&
"popping exception stack when not empty");
196 assert(isa<EHCleanupScope>(*
begin()));
198 InnermostNormalCleanup =
Cleanup.getEnclosingNormalCleanup();
199 InnermostEHScope =
Cleanup.getEnclosingEHScope();
200 deallocate(
Cleanup.getAllocatedSize());
206 if (!BranchFixups.empty()) {
210 BranchFixups.clear();
227 assert(!
empty() &&
"popping exception stack when not empty");
238 new (buffer)
EHCatchScope(numHandlers, InnermostEHScope);
260 unsigned MinSize = cast<EHCleanupScope>(*it).getFixupDepth();
261 assert(BranchFixups.size() >= MinSize &&
"fixup stack out of order");
263 while (BranchFixups.size() > MinSize &&
264 BranchFixups.back().Destination ==
nullptr)
265 BranchFixups.pop_back();
286 assert(!cleanup.hasActiveFlag() &&
"cleanup already has active flag?");
287 cleanup.setActiveFlag(ActiveFlag);
289 if (cleanup.isNormalCleanup()) cleanup.setTestFlagInNormalCleanup();
290 if (cleanup.isEHCleanup()) cleanup.setTestFlagInEHCleanup();
293void EHScopeStack::Cleanup::anchor() {}
296 llvm::BasicBlock::iterator beforeInst,
298 auto store =
new llvm::StoreInst(value, addr.
emitRawPointer(CGF), beforeInst);
302static llvm::LoadInst *
304 llvm::BasicBlock::iterator beforeInst,
322 llvm::BasicBlock *CleanupEntry) {
359 llvm::BasicBlock *
Block) {
362 llvm::Instruction *Term =
Block->getTerminator();
363 assert(Term &&
"can't transition block without terminator");
365 if (llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Term)) {
366 assert(Br->isUnconditional());
368 "cleanup.dest", Term->getIterator(), CGF);
369 llvm::SwitchInst *
Switch =
370 llvm::SwitchInst::Create(Load, Br->getSuccessor(0), 4,
Block);
371 Br->eraseFromParent();
374 return cast<llvm::SwitchInst>(Term);
379 assert(
Block &&
"resolving a null target block");
380 if (!EHStack.getNumBranchFixups())
return;
382 assert(EHStack.hasNormalCleanups() &&
383 "branch fixups exist with no normal cleanups on stack");
386 bool ResolvedAny =
false;
388 for (
unsigned I = 0,
E = EHStack.getNumBranchFixups(); I !=
E; ++I) {
403 if (!ModifiedOptimisticBlocks.insert(BranchBB).second)
413 EHStack.popNullFixups();
419 std::initializer_list<llvm::Value **> ValuesToReload) {
422 bool HadBranches =
false;
423 while (EHStack.stable_begin() != Old) {
425 HadBranches |=
Scope.hasBranches();
430 bool FallThroughIsBranchThrough =
433 PopCleanupBlock(FallThroughIsBranchThrough);
444 for (llvm::Value **ReloadedValue : ValuesToReload) {
445 auto *Inst = dyn_cast_or_null<llvm::Instruction>(*ReloadedValue);
451 auto *AI = dyn_cast<llvm::AllocaInst>(Inst);
452 if (AI && AI->isStaticAlloca())
456 CreateDefaultAlignTempAlloca(Inst->getType(),
"tmp.exprcleanup");
459 llvm::BasicBlock::iterator InsertBefore;
460 if (
auto *Invoke = dyn_cast<llvm::InvokeInst>(Inst))
461 InsertBefore = Invoke->getNormalDest()->getFirstInsertionPt();
463 InsertBefore = std::next(Inst->getIterator());
467 *ReloadedValue = Builder.CreateLoad(Tmp);
475 std::initializer_list<llvm::Value **> ValuesToReload) {
476 PopCleanupBlocks(Old, ValuesToReload);
479 for (
size_t I = OldLifetimeExtendedSize,
480 E = LifetimeExtendedCleanupStack.size(); I !=
E; ) {
482 assert((I %
alignof(LifetimeExtendedCleanupHeader) == 0) &&
483 "misaligned cleanup stack entry");
485 LifetimeExtendedCleanupHeader &Header =
486 reinterpret_cast<LifetimeExtendedCleanupHeader&
>(
487 LifetimeExtendedCleanupStack[I]);
490 EHStack.pushCopyOfCleanup(Header.getKind(),
491 &LifetimeExtendedCleanupStack[I],
493 I += Header.getSize();
495 if (Header.isConditional()) {
497 reinterpret_cast<RawAddress &
>(LifetimeExtendedCleanupStack[I]);
498 initFullExprCleanupWithFlag(ActiveFlag);
499 I +=
sizeof(ActiveFlag);
502 LifetimeExtendedCleanupStack.resize(OldLifetimeExtendedSize);
507 assert(
Scope.isNormalCleanup());
508 llvm::BasicBlock *Entry =
Scope.getNormalBlock();
511 Scope.setNormalBlock(Entry);
522 llvm::BasicBlock *Entry) {
523 llvm::BasicBlock *Pred = Entry->getSinglePredecessor();
524 if (!Pred)
return Entry;
526 llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Pred->getTerminator());
527 if (!Br || Br->isConditional())
return Entry;
528 assert(Br->getSuccessor(0) == Entry);
533 bool WasInsertBlock = CGF.
Builder.GetInsertBlock() == Entry;
534 assert(!WasInsertBlock || CGF.
Builder.GetInsertPoint() == Entry->end());
537 Br->eraseFromParent();
541 Entry->replaceAllUsesWith(Pred);
544 Pred->splice(Pred->end(), Entry);
547 Entry->eraseFromParent();
550 CGF.
Builder.SetInsertPoint(Pred);
561 llvm::BasicBlock *ContBB =
nullptr;
565 llvm::Value *IsActive
567 CGF.
Builder.CreateCondBr(IsActive, CleanupBB, ContBB);
572 Fn->Emit(CGF, flags);
573 assert(CGF.
HaveInsertPoint() &&
"cleanup ended with no insertion point?");
581 llvm::BasicBlock *From,
582 llvm::BasicBlock *To) {
585 llvm::Instruction *Term = Exit->getTerminator();
587 if (llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Term)) {
588 assert(Br->isUnconditional() && Br->getSuccessor(0) == From);
589 Br->setSuccessor(0, To);
591 llvm::SwitchInst *
Switch = cast<llvm::SwitchInst>(Term);
592 for (
unsigned I = 0,
E =
Switch->getNumSuccessors(); I !=
E; ++I)
593 if (
Switch->getSuccessor(I) == From)
594 Switch->setSuccessor(I, To);
611 for (llvm::BasicBlock::use_iterator
612 i = entry->use_begin(), e = entry->use_end(); i != e; ) {
616 use.set(unreachableBB);
619 llvm::SwitchInst *si = cast<llvm::SwitchInst>(use.getUser());
620 if (si->getNumCases() == 1 && si->getDefaultDest() == unreachableBB) {
622 llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(),
626 llvm::LoadInst *condition = cast<llvm::LoadInst>(si->getCondition());
629 si->eraseFromParent();
633 assert(condition->use_empty());
634 condition->eraseFromParent();
638 assert(entry->use_empty());
647 assert(!EHStack.empty() &&
"cleanup stack is empty!");
648 assert(isa<EHCleanupScope>(*EHStack.begin()) &&
"top not a cleanup!");
650 assert(
Scope.getFixupDepth() <= EHStack.getNumBranchFixups());
654 CGBuilderTy::InsertPoint NormalDeactivateOrigIP;
656 NormalDeactivateOrigIP = Builder.saveAndClearIP();
659 bool IsActive =
Scope.isActive();
661 Scope.shouldTestFlagInNormalCleanup() ?
Scope.getActiveFlag()
664 Scope.shouldTestFlagInEHCleanup() ?
Scope.getActiveFlag()
669 llvm::BasicBlock *EHEntry =
Scope.getCachedEHDispatchBlock();
670 assert(
Scope.hasEHBranches() == (EHEntry !=
nullptr));
671 bool RequiresEHCleanup = (EHEntry !=
nullptr);
677 unsigned FixupDepth =
Scope.getFixupDepth();
678 bool HasFixups = EHStack.getNumBranchFixups() != FixupDepth;
681 bool HasExistingBranches =
Scope.hasBranches();
684 llvm::BasicBlock *FallthroughSource = Builder.GetInsertBlock();
685 bool HasFallthrough =
686 FallthroughSource !=
nullptr && (IsActive || HasExistingBranches);
692 bool HasPrebranchedFallthrough =
693 (FallthroughSource && FallthroughSource->getTerminator());
698 assert(!
Scope.isNormalCleanup() || !HasPrebranchedFallthrough ||
699 (
Scope.getNormalBlock() &&
700 FallthroughSource->getTerminator()->getSuccessor(0)
701 ==
Scope.getNormalBlock()));
703 bool RequiresNormalCleanup =
false;
704 if (
Scope.isNormalCleanup() &&
705 (HasFixups || HasExistingBranches || HasFallthrough)) {
706 RequiresNormalCleanup =
true;
711 if (
Scope.isNormalCleanup() && HasPrebranchedFallthrough &&
712 !RequiresNormalCleanup) {
716 llvm::BasicBlock *prebranchDest;
721 if (FallthroughIsBranchThrough) {
722 EHScope &enclosing = *EHStack.find(
Scope.getEnclosingNormalCleanup());
730 prebranchDest = createBasicBlock(
"forwarded-prebranch");
731 EmitBlock(prebranchDest);
734 llvm::BasicBlock *normalEntry =
Scope.getNormalBlock();
735 assert(normalEntry && !normalEntry->use_empty());
738 normalEntry, prebranchDest);
742 if (!RequiresNormalCleanup && !RequiresEHCleanup) {
744 EHStack.popCleanup();
745 assert(EHStack.getNumBranchFixups() == 0 ||
746 EHStack.hasNormalCleanups());
747 if (NormalDeactivateOrigIP.isSet())
748 Builder.restoreIP(NormalDeactivateOrigIP);
757 auto *CleanupSource =
reinterpret_cast<char *
>(
Scope.getCleanupBuffer());
759 CleanupBufferStack[8 *
sizeof(
void *)];
760 std::unique_ptr<char[]> CleanupBufferHeap;
761 size_t CleanupSize =
Scope.getCleanupSize();
764 if (CleanupSize <=
sizeof(CleanupBufferStack)) {
765 memcpy(CleanupBufferStack, CleanupSource, CleanupSize);
768 CleanupBufferHeap.reset(
new char[CleanupSize]);
769 memcpy(CleanupBufferHeap.get(), CleanupSource, CleanupSize);
774 if (
Scope.isNormalCleanup())
776 if (
Scope.isEHCleanup())
780 bool IsEHa = getLangOpts().EHAsynch && !
Scope.isLifetimeMarker();
782 if (!RequiresNormalCleanup) {
785 if (IsEHa && getInvokeDest()) {
789 if (NormalDeactivateOrigIP.isSet())
790 Builder.restoreIP(NormalDeactivateOrigIP);
792 EmitSehCppScopeEnd();
793 if (NormalDeactivateOrigIP.isSet())
794 NormalDeactivateOrigIP = Builder.saveAndClearIP();
798 EHStack.popCleanup();
802 if (HasFallthrough && !HasPrebranchedFallthrough && !HasFixups &&
803 !HasExistingBranches) {
806 if (IsEHa && getInvokeDest()) {
808 EmitSehCppScopeEnd();
810 EmitSehTryScopeEnd();
815 EHStack.popCleanup();
817 EmitCleanup(*
this, Fn, cleanupFlags, NormalActiveFlag);
827 CGBuilderTy::InsertPoint savedInactiveFallthroughIP;
831 if (HasFallthrough) {
832 if (!HasPrebranchedFallthrough)
833 Builder.CreateStore(Builder.getInt32(0), getNormalCleanupDestSlot());
837 }
else if (FallthroughSource) {
838 assert(!IsActive &&
"source without fallthrough for active cleanup");
839 savedInactiveFallthroughIP = Builder.saveAndClearIP();
845 EmitBlock(NormalEntry);
848 if (IsEHa && getInvokeDest()) {
850 EmitSehCppScopeEnd();
852 EmitSehTryScopeEnd();
858 bool HasEnclosingCleanups =
859 (
Scope.getEnclosingNormalCleanup() != EHStack.stable_end());
866 llvm::BasicBlock *BranchThroughDest =
nullptr;
867 if (
Scope.hasBranchThroughs() ||
868 (FallthroughSource && FallthroughIsBranchThrough) ||
869 (HasFixups && HasEnclosingCleanups)) {
870 assert(HasEnclosingCleanups);
871 EHScope &S = *EHStack.find(
Scope.getEnclosingNormalCleanup());
875 llvm::BasicBlock *FallthroughDest =
nullptr;
885 if (!
Scope.hasBranchThroughs() && !HasFixups && !HasFallthrough &&
886 !currentFunctionUsesSEHTry() &&
Scope.getNumBranchAfters() == 1) {
887 assert(!BranchThroughDest || !IsActive);
890 llvm::Instruction *NormalCleanupDestSlot =
891 cast<llvm::Instruction>(getNormalCleanupDestSlot().getPointer());
892 if (NormalCleanupDestSlot->hasOneUse()) {
893 NormalCleanupDestSlot->user_back()->eraseFromParent();
894 NormalCleanupDestSlot->eraseFromParent();
898 llvm::BasicBlock *BranchAfter =
Scope.getBranchAfterBlock(0);
899 InstsToAppend.push_back(llvm::BranchInst::Create(BranchAfter));
906 }
else if (
Scope.getNumBranchAfters() ||
907 (HasFallthrough && !FallthroughIsBranchThrough) ||
908 (HasFixups && !HasEnclosingCleanups)) {
911 (BranchThroughDest ? BranchThroughDest : getUnreachableBlock());
914 const unsigned SwitchCapacity = 10;
920 "cleanup.dest", *
this);
921 llvm::SwitchInst *
Switch =
922 llvm::SwitchInst::Create(Load,
Default, SwitchCapacity);
924 InstsToAppend.push_back(Load);
925 InstsToAppend.push_back(
Switch);
928 if (FallthroughSource && !FallthroughIsBranchThrough) {
929 FallthroughDest = createBasicBlock(
"cleanup.cont");
931 Switch->addCase(Builder.getInt32(0), FallthroughDest);
934 for (
unsigned I = 0,
E =
Scope.getNumBranchAfters(); I !=
E; ++I) {
936 Scope.getBranchAfterBlock(I));
941 if (HasFixups && !HasEnclosingCleanups)
945 assert(BranchThroughDest);
946 InstsToAppend.push_back(llvm::BranchInst::Create(BranchThroughDest));
951 EHStack.popCleanup();
952 assert(EHStack.hasNormalCleanups() == HasEnclosingCleanups);
954 EmitCleanup(*
this, Fn, cleanupFlags, NormalActiveFlag);
957 llvm::BasicBlock *NormalExit = Builder.GetInsertBlock();
958 for (
unsigned I = 0,
E = InstsToAppend.size(); I !=
E; ++I)
959 InstsToAppend[I]->insertInto(NormalExit, NormalExit->end());
962 for (
unsigned I = FixupDepth,
E = EHStack.getNumBranchFixups();
969 getNormalCleanupDestSlot(),
980 if (!HasFallthrough && FallthroughSource) {
985 Builder.restoreIP(savedInactiveFallthroughIP);
990 }
else if (HasFallthrough && FallthroughDest) {
991 assert(!FallthroughIsBranchThrough);
992 EmitBlock(FallthroughDest);
996 }
else if (HasFallthrough) {
1001 Builder.ClearInsertionPoint();
1008 llvm::BasicBlock *NewNormalEntry =
1013 if (NewNormalEntry != NormalEntry && NormalEntry == NormalExit)
1014 for (
unsigned I = FixupDepth,
E = EHStack.getNumBranchFixups();
1016 EHStack.getBranchFixup(I).OptimisticBranchBlock = NewNormalEntry;
1020 if (NormalDeactivateOrigIP.isSet())
1021 Builder.restoreIP(NormalDeactivateOrigIP);
1022 assert(EHStack.hasNormalCleanups() || EHStack.getNumBranchFixups() == 0);
1025 if (RequiresEHCleanup) {
1026 CGBuilderTy::InsertPoint SavedIP = Builder.saveAndClearIP();
1030 llvm::BasicBlock *NextAction = getEHDispatchBlock(EHParent);
1035 bool PushedTerminate =
false;
1037 llvm::CleanupPadInst *CPI =
nullptr;
1041 llvm::Value *ParentPad = CurrentFuncletPad;
1043 ParentPad = llvm::ConstantTokenNone::get(CGM.getLLVMContext());
1044 CurrentFuncletPad = CPI = Builder.CreateCleanupPad(ParentPad);
1049 EHStack.pushTerminate();
1050 PushedTerminate =
true;
1051 }
else if (IsEHa && getInvokeDest()) {
1052 EmitSehCppScopeEnd();
1057 if (EHActiveFlag.
isValid() || IsActive) {
1059 EmitCleanup(*
this, Fn, cleanupFlags, EHActiveFlag);
1063 Builder.CreateCleanupRet(CPI, NextAction);
1065 Builder.CreateBr(NextAction);
1068 if (PushedTerminate)
1069 EHStack.popTerminate();
1071 Builder.restoreIP(SavedIP);
1081 assert(Dest.getScopeDepth().encloses(EHStack.stable_begin())
1082 &&
"stale jump destination");
1086 EHStack.getInnermostActiveNormalCleanup();
1091 if (TopCleanup == EHStack.stable_end() ||
1092 TopCleanup.
encloses(Dest.getScopeDepth()))
1106 assert(Dest.getScopeDepth().encloses(EHStack.stable_begin())
1107 &&
"stale jump destination");
1109 if (!HaveInsertPoint())
1113 llvm::BranchInst *BI = Builder.CreateBr(Dest.getBlock());
1117 TopCleanup = EHStack.getInnermostActiveNormalCleanup();
1122 if (TopCleanup == EHStack.stable_end() ||
1123 TopCleanup.
encloses(Dest.getScopeDepth())) {
1124 Builder.ClearInsertionPoint();
1130 if (!Dest.getScopeDepth().isValid()) {
1137 Builder.ClearInsertionPoint();
1144 llvm::ConstantInt *Index = Builder.getInt32(Dest.getDestIndex());
1151 cast<EHCleanupScope>(*EHStack.find(TopCleanup));
1158 if (
E.strictlyEncloses(I)) {
1161 assert(
Scope.isNormalCleanup());
1162 I =
Scope.getEnclosingNormalCleanup();
1166 if (!
E.strictlyEncloses(I)) {
1167 Scope.addBranchAfter(Index, Dest.getBlock());
1174 if (!
Scope.addBranchThrough(Dest.getBlock()))
1179 Builder.ClearInsertionPoint();
1191 assert(cleanup.strictlyEncloses(i));
1216 llvm::Instruction *dominatingIP) {
1222 bool isActivatedInConditional =
1225 bool needFlag =
false;
1230 if (
Scope.isNormalCleanup()) {
1231 Scope.setTestFlagInNormalCleanup();
1236 if (
Scope.isEHCleanup() &&
1238 Scope.setTestFlagInEHCleanup();
1247 if (!var.isValid()) {
1248 CodeGenFunction::AllocaTrackerRAII AllocaTracker(CGF);
1250 "cleanup.isactive");
1251 Scope.setActiveFlag(var);
1252 Scope.AddAuxAllocas(AllocaTracker.Take());
1254 assert(dominatingIP &&
"no existing variable and no dominating IP!");
1274 llvm::Instruction *dominatingIP) {
1275 assert(
C != EHStack.stable_end() &&
"activating bottom of stack?");
1277 assert(!
Scope.isActive() &&
"double activation");
1281 Scope.setActive(
true);
1286 llvm::Instruction *dominatingIP) {
1287 assert(
C != EHStack.stable_end() &&
"deactivating bottom of stack?");
1289 assert(
Scope.isActive() &&
"double deactivation");
1293 if (
C == EHStack.stable_begin() &&
1294 CurrentCleanupScopeDepth.strictlyEncloses(
C)) {
1295 PopCleanupBlock(
false,
1303 Scope.setActive(
false);
1307 if (!NormalCleanupDest.isValid())
1309 CreateDefaultAlignTempAlloca(Builder.getInt32Ty(),
"cleanup.dest.slot");
1310 return NormalCleanupDest;
1324 llvm::FunctionCallee &SehCppScope) {
1326 assert(CGF.
Builder.GetInsertBlock() && InvokeDest);
1332 CGF.
Builder.CreateInvoke(SehCppScope, Cont, InvokeDest, std::nullopt,
1339 assert(getLangOpts().EHAsynch);
1340 llvm::FunctionType *FTy =
1341 llvm::FunctionType::get(CGM.VoidTy,
false);
1342 llvm::FunctionCallee SehCppScope =
1343 CGM.CreateRuntimeFunction(FTy,
"llvm.seh.scope.begin");
1350 assert(getLangOpts().EHAsynch);
1351 llvm::FunctionType *FTy =
1352 llvm::FunctionType::get(CGM.VoidTy,
false);
1353 llvm::FunctionCallee SehCppScope =
1354 CGM.CreateRuntimeFunction(FTy,
"llvm.seh.scope.end");
1360 assert(getLangOpts().EHAsynch);
1361 llvm::FunctionType *FTy =
1362 llvm::FunctionType::get(CGM.VoidTy,
false);
1363 llvm::FunctionCallee SehCppScope =
1364 CGM.CreateRuntimeFunction(FTy,
"llvm.seh.try.begin");
1370 assert(getLangOpts().EHAsynch);
1371 llvm::FunctionType *FTy =
1372 llvm::FunctionType::get(CGM.VoidTy,
false);
1373 llvm::FunctionCallee SehCppScope =
1374 CGM.CreateRuntimeFunction(FTy,
"llvm.seh.try.end");
static llvm::LoadInst * createLoadInstBefore(Address addr, const Twine &name, llvm::BasicBlock::iterator beforeInst, CodeGenFunction &CGF)
static void EmitSehScope(CodeGenFunction &CGF, llvm::FunctionCallee &SehCppScope)
static llvm::BasicBlock * CreateNormalEntry(CodeGenFunction &CGF, EHCleanupScope &Scope)
static void EmitCleanup(CodeGenFunction &CGF, EHScopeStack::Cleanup *Fn, EHScopeStack::Cleanup::Flags flags, Address ActiveFlag)
static void destroyOptimisticNormalEntry(CodeGenFunction &CGF, EHCleanupScope &scope)
We don't need a normal entry block for the given cleanup.
static void SetupCleanupBlockActivation(CodeGenFunction &CGF, EHScopeStack::stable_iterator C, ForActivation_t kind, llvm::Instruction *dominatingIP)
The given cleanup block is changing activation state.
static void ForwardPrebranchedFallthrough(llvm::BasicBlock *Exit, llvm::BasicBlock *From, llvm::BasicBlock *To)
static void createStoreInstBefore(llvm::Value *value, Address addr, llvm::BasicBlock::iterator beforeInst, CodeGenFunction &CGF)
static void ResolveAllBranchFixups(CodeGenFunction &CGF, llvm::SwitchInst *Switch, llvm::BasicBlock *CleanupEntry)
All the branch fixups on the EH stack have propagated out past the outermost normal cleanup; resolve ...
static bool IsUsedAsEHCleanup(EHScopeStack &EHStack, EHScopeStack::stable_iterator cleanup)
static llvm::BasicBlock * SimplifyCleanupEntry(CodeGenFunction &CGF, llvm::BasicBlock *Entry)
Attempts to reduce a cleanup's entry block to a fallthrough.
static llvm::SwitchInst * TransitionToCleanupSwitch(CodeGenFunction &CGF, llvm::BasicBlock *Block)
Transitions the terminator of the given exit-block of a cleanup to be a cleanup switch.
static Decl::Kind getKind(const Decl *D)
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
Represents a C++ temporary.
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
static CharUnits One()
One - Construct a CharUnits quantity of one.
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
CharUnits getAlignment() const
llvm::Type * getElementType() const
Return the type of the values stored in this address.
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *DominatingIP)
DeactivateCleanupBlock - Deactivates the given cleanup block.
void EmitSehCppScopeBegin()
RawAddress createCleanupActiveFlag()
RawAddress CreateTempAllocaWithoutCast(llvm::Type *Ty, CharUnits align, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
const LangOptions & getLangOpts() const
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates an alloca and inserts it into the entry block if ArraySize is nullptr...
SmallVector< llvm::OperandBundleDef, 1 > getBundlesForFunclet(llvm::Value *Callee)
RawAddress getNormalCleanupDestSlot()
void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize, std::initializer_list< llvm::Value ** > ValuesToReload={})
Takes the old cleanup stack size and emits the cleanup blocks that have been added.
llvm::BasicBlock * getUnreachableBlock()
const TargetInfo & getTarget() const
bool isInConditionalBranch() const
isInConditionalBranch - Return true if we're currently emitting one branch or the other of a conditio...
void EmitSehCppScopeEnd()
void initFullExprCleanupWithFlag(RawAddress ActiveFlag)
llvm::BasicBlock * getInvokeDest()
void EmitSehTryScopeBegin()
void EmitSehTryScopeEnd()
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
void setBeforeOutermostConditional(llvm::Value *value, Address addr, CodeGenFunction &CGF)
void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType, Address Ptr)
void EmitBranchThroughCleanup(JumpDest Dest)
EmitBranchThroughCleanup - Emit a branch from the current insert block through the normal cleanup han...
void PopCleanupBlock(bool FallThroughIsBranchThrough=false, bool ForDeactivation=false)
PopCleanupBlock - Will pop the cleanup entry on the stack and process all branch fixups.
void ActivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *DominatingIP)
ActivateCleanupBlock - Activates an initially-inactive cleanup.
RawAddress NormalCleanupDest
i32s containing the indexes of the cleanup destinations.
bool isObviouslyBranchWithoutCleanups(JumpDest Dest) const
isObviouslyBranchWithoutCleanups - Return true if a branch to the specified destination obviously has...
llvm::Instruction * CurrentFuncletPad
void ResolveBranchFixups(llvm::BasicBlock *Target)
A scope which attempts to handle some, possibly all, types of exceptions.
static size_t getSizeForNumHandlers(unsigned N)
A cleanup scope which generates the cleanup blocks lazily.
static size_t getSizeForCleanupSize(size_t Size)
Gets the size required for a lazy cleanup scope with the given cleanup-data requirements.
llvm::BasicBlock * getNormalBlock() const
An exceptions scope which filters exceptions thrown through it.
static size_t getSizeForNumFilters(unsigned numFilters)
unsigned getNumFilters() const
void setIsNormalCleanupKind()
void setIsEHCleanupKind()
Information for lazily generating a cleanup.
A non-stable pointer into the scope stack.
A saved depth on the scope stack.
bool encloses(stable_iterator I) const
Returns true if this scope encloses I.
bool strictlyEncloses(stable_iterator I) const
Returns true if this scope strictly encloses I: that is, if it encloses I and is not I.
A stack of scopes which respond to exceptions, including cleanups and catch blocks.
class EHFilterScope * pushFilter(unsigned NumFilters)
Push an exceptions filter on the stack.
BranchFixup & getBranchFixup(unsigned I)
stable_iterator getInnermostNormalCleanup() const
Returns the innermost normal cleanup on the stack, or stable_end() if there are no normal cleanups.
stable_iterator stable_begin() const
Create a stable reference to the top of the EH stack.
unsigned getNumBranchFixups() const
void popCleanup()
Pops a cleanup scope off the stack. This is private to CGCleanup.cpp.
stable_iterator getInnermostEHScope() const
bool requiresLandingPad() const
bool containsOnlyLifetimeMarkers(stable_iterator Old) const
bool empty() const
Determines whether the exception-scopes stack is empty.
void popFilter()
Pops an exceptions filter off the stack.
iterator begin() const
Returns an iterator pointing to the innermost EH scope.
class EHCatchScope * pushCatch(unsigned NumHandlers)
Push a set of catch handlers on the stack.
iterator find(stable_iterator save) const
Turn a stable reference to a scope depth into a unstable pointer to the EH stack.
void popNullFixups()
Pops lazily-removed fixups from the end of the list.
bool hasNormalCleanups() const
Determines whether there are any normal cleanups on the stack.
stable_iterator getInnermostActiveNormalCleanup() const
stable_iterator stabilize(iterator it) const
Translates an iterator into a stable_iterator.
static stable_iterator stable_end()
Create a stable reference to the bottom of the EH stack.
void clearFixups()
Clears the branch-fixups list.
void pushTerminate()
Push a terminate handler on the stack.
A protected scope for zero-cost EH handling.
EHScopeStack::stable_iterator getEnclosingEHScope() const
bool hasEHBranches() const
An exceptions scope which calls std::terminate if any exception reaches it.
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
static RValue get(llvm::Value *V)
static RValue getAggregate(Address addr, bool isVolatile=false)
Convert an Address to an RValue.
static RValue getComplex(llvm::Value *V1, llvm::Value *V2)
Address getAggregateAddress() const
getAggregateAddr() - Return the Value* of the address of the aggregate.
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
std::pair< llvm::Value *, llvm::Value * > getComplexVal() const
getComplexVal - Return the real/imag components of this complex value.
An abstract representation of an aligned address.
llvm::Value * getPointer() const
static RawAddress invalid()
A (possibly-)qualified type.
Scope - A scope is a transient data structure that is used while parsing the program.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
@ NormalCleanup
Denotes a cleanup that should run when a scope is exited using normal control flow (falling off the e...
@ EHCleanup
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
bool Load(InterpState &S, CodePtr OpPC)
The JSON file list parser is used to communicate input to InstallAPI.
unsigned DestinationIndex
The destination index value.
llvm::BasicBlock * Destination
The ultimate destination of the branch.
llvm::BasicBlock * OptimisticBranchBlock
The block containing the terminator which needs to be modified into a switch if this fixup is resolve...
llvm::BranchInst * InitialBranch
The initial branch of the fixup.
static llvm::Value * restore(CodeGenFunction &CGF, saved_type value)
static saved_type save(CodeGenFunction &CGF, llvm::Value *value)
static bool needsSaving(llvm::Value *value)
Answer whether the given value needs extra work to be saved.
A metaprogramming class for ensuring that a value will dominate an arbitrary position in a function.
The exceptions personality for a function.
bool isMSVCXXPersonality() const
static const EHPersonality & get(CodeGenModule &CGM, const FunctionDecl *FD)
bool usesFuncletPads() const
Does this personality use landingpads or the family of pad instructions designed to form funclets?
bool isMSVCPersonality() const