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::Instruction *beforeInst,
298 auto store =
new llvm::StoreInst(value, addr.
emitRawPointer(CGF), beforeInst);
303 llvm::Instruction *beforeInst,
315 llvm::BasicBlock *CleanupEntry) {
352 llvm::BasicBlock *
Block) {
355 llvm::Instruction *Term =
Block->getTerminator();
356 assert(Term &&
"can't transition block without terminator");
358 if (llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Term)) {
359 assert(Br->isUnconditional());
361 "cleanup.dest", Term, CGF);
362 llvm::SwitchInst *
Switch =
363 llvm::SwitchInst::Create(Load, Br->getSuccessor(0), 4,
Block);
364 Br->eraseFromParent();
367 return cast<llvm::SwitchInst>(Term);
372 assert(
Block &&
"resolving a null target block");
373 if (!EHStack.getNumBranchFixups())
return;
375 assert(EHStack.hasNormalCleanups() &&
376 "branch fixups exist with no normal cleanups on stack");
379 bool ResolvedAny =
false;
381 for (
unsigned I = 0, E = EHStack.getNumBranchFixups(); I != E; ++I) {
396 if (!ModifiedOptimisticBlocks.insert(BranchBB).second)
406 EHStack.popNullFixups();
412 std::initializer_list<llvm::Value **> ValuesToReload) {
415 bool HadBranches =
false;
416 while (EHStack.stable_begin() != Old) {
418 HadBranches |=
Scope.hasBranches();
423 bool FallThroughIsBranchThrough =
426 PopCleanupBlock(FallThroughIsBranchThrough);
437 for (llvm::Value **ReloadedValue : ValuesToReload) {
438 auto *Inst = dyn_cast_or_null<llvm::Instruction>(*ReloadedValue);
444 auto *AI = dyn_cast<llvm::AllocaInst>(Inst);
445 if (AI && AI->isStaticAlloca())
449 CreateDefaultAlignTempAlloca(Inst->getType(),
"tmp.exprcleanup");
452 llvm::BasicBlock::iterator InsertBefore;
453 if (
auto *Invoke = dyn_cast<llvm::InvokeInst>(Inst))
454 InsertBefore = Invoke->getNormalDest()->getFirstInsertionPt();
456 InsertBefore = std::next(Inst->getIterator());
460 *ReloadedValue = Builder.CreateLoad(Tmp);
468 std::initializer_list<llvm::Value **> ValuesToReload) {
469 PopCleanupBlocks(Old, ValuesToReload);
472 for (
size_t I = OldLifetimeExtendedSize,
473 E = LifetimeExtendedCleanupStack.size(); I != E; ) {
475 assert((I %
alignof(LifetimeExtendedCleanupHeader) == 0) &&
476 "misaligned cleanup stack entry");
478 LifetimeExtendedCleanupHeader &Header =
479 reinterpret_cast<LifetimeExtendedCleanupHeader&
>(
480 LifetimeExtendedCleanupStack[I]);
483 EHStack.pushCopyOfCleanup(Header.getKind(),
484 &LifetimeExtendedCleanupStack[I],
486 I += Header.getSize();
488 if (Header.isConditional()) {
490 reinterpret_cast<RawAddress &
>(LifetimeExtendedCleanupStack[I]);
491 initFullExprCleanupWithFlag(ActiveFlag);
492 I +=
sizeof(ActiveFlag);
495 LifetimeExtendedCleanupStack.resize(OldLifetimeExtendedSize);
500 assert(
Scope.isNormalCleanup());
501 llvm::BasicBlock *Entry =
Scope.getNormalBlock();
504 Scope.setNormalBlock(Entry);
515 llvm::BasicBlock *Entry) {
516 llvm::BasicBlock *Pred = Entry->getSinglePredecessor();
517 if (!Pred)
return Entry;
519 llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Pred->getTerminator());
520 if (!Br || Br->isConditional())
return Entry;
521 assert(Br->getSuccessor(0) == Entry);
526 bool WasInsertBlock = CGF.
Builder.GetInsertBlock() == Entry;
527 assert(!WasInsertBlock || CGF.
Builder.GetInsertPoint() == Entry->end());
530 Br->eraseFromParent();
534 Entry->replaceAllUsesWith(Pred);
537 Pred->splice(Pred->end(), Entry);
540 Entry->eraseFromParent();
543 CGF.
Builder.SetInsertPoint(Pred);
554 llvm::BasicBlock *ContBB =
nullptr;
558 llvm::Value *IsActive
560 CGF.
Builder.CreateCondBr(IsActive, CleanupBB, ContBB);
565 Fn->
Emit(CGF, flags);
566 assert(CGF.
HaveInsertPoint() &&
"cleanup ended with no insertion point?");
574 llvm::BasicBlock *From,
575 llvm::BasicBlock *To) {
578 llvm::Instruction *Term = Exit->getTerminator();
580 if (llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Term)) {
581 assert(Br->isUnconditional() && Br->getSuccessor(0) == From);
582 Br->setSuccessor(0, To);
584 llvm::SwitchInst *
Switch = cast<llvm::SwitchInst>(Term);
585 for (
unsigned I = 0, E =
Switch->getNumSuccessors(); I != E; ++I)
586 if (
Switch->getSuccessor(I) == From)
587 Switch->setSuccessor(I, To);
604 for (llvm::BasicBlock::use_iterator
605 i = entry->use_begin(), e = entry->use_end(); i != e; ) {
609 use.set(unreachableBB);
612 llvm::SwitchInst *si = cast<llvm::SwitchInst>(use.getUser());
613 if (si->getNumCases() == 1 && si->getDefaultDest() == unreachableBB) {
615 llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(), si);
618 llvm::LoadInst *condition = cast<llvm::LoadInst>(si->getCondition());
621 si->eraseFromParent();
625 assert(condition->use_empty());
626 condition->eraseFromParent();
630 assert(entry->use_empty());
638 assert(!EHStack.empty() &&
"cleanup stack is empty!");
639 assert(isa<EHCleanupScope>(*EHStack.begin()) &&
"top not a cleanup!");
641 assert(
Scope.getFixupDepth() <= EHStack.getNumBranchFixups());
644 bool IsActive =
Scope.isActive();
646 Scope.shouldTestFlagInNormalCleanup() ?
Scope.getActiveFlag()
649 Scope.shouldTestFlagInEHCleanup() ?
Scope.getActiveFlag()
654 llvm::BasicBlock *EHEntry =
Scope.getCachedEHDispatchBlock();
655 assert(
Scope.hasEHBranches() == (EHEntry !=
nullptr));
656 bool RequiresEHCleanup = (EHEntry !=
nullptr);
662 unsigned FixupDepth =
Scope.getFixupDepth();
663 bool HasFixups = EHStack.getNumBranchFixups() != FixupDepth;
666 bool HasExistingBranches =
Scope.hasBranches();
669 llvm::BasicBlock *FallthroughSource = Builder.GetInsertBlock();
670 bool HasFallthrough = (FallthroughSource !=
nullptr && IsActive);
676 bool HasPrebranchedFallthrough =
677 (FallthroughSource && FallthroughSource->getTerminator());
682 assert(!
Scope.isNormalCleanup() || !HasPrebranchedFallthrough ||
683 (
Scope.getNormalBlock() &&
684 FallthroughSource->getTerminator()->getSuccessor(0)
685 ==
Scope.getNormalBlock()));
687 bool RequiresNormalCleanup =
false;
688 if (
Scope.isNormalCleanup() &&
689 (HasFixups || HasExistingBranches || HasFallthrough)) {
690 RequiresNormalCleanup =
true;
695 if (
Scope.isNormalCleanup() && HasPrebranchedFallthrough && !IsActive) {
696 llvm::BasicBlock *prebranchDest;
701 if (FallthroughIsBranchThrough) {
702 EHScope &enclosing = *EHStack.find(
Scope.getEnclosingNormalCleanup());
710 prebranchDest = createBasicBlock(
"forwarded-prebranch");
711 EmitBlock(prebranchDest);
714 llvm::BasicBlock *normalEntry =
Scope.getNormalBlock();
715 assert(normalEntry && !normalEntry->use_empty());
718 normalEntry, prebranchDest);
722 if (!RequiresNormalCleanup && !RequiresEHCleanup) {
724 EHStack.popCleanup();
725 assert(EHStack.getNumBranchFixups() == 0 ||
726 EHStack.hasNormalCleanups());
735 auto *CleanupSource =
reinterpret_cast<char *
>(
Scope.getCleanupBuffer());
737 CleanupBufferStack[8 *
sizeof(
void *)];
738 std::unique_ptr<char[]> CleanupBufferHeap;
739 size_t CleanupSize =
Scope.getCleanupSize();
742 if (CleanupSize <=
sizeof(CleanupBufferStack)) {
743 memcpy(CleanupBufferStack, CleanupSource, CleanupSize);
746 CleanupBufferHeap.reset(
new char[CleanupSize]);
747 memcpy(CleanupBufferHeap.get(), CleanupSource, CleanupSize);
752 if (
Scope.isNormalCleanup())
754 if (
Scope.isEHCleanup())
758 bool IsEHa = getLangOpts().EHAsynch && !
Scope.isLifetimeMarker();
760 if (!RequiresNormalCleanup) {
763 if (IsEHa && getInvokeDest() && Builder.GetInsertBlock()) {
765 EmitSehCppScopeEnd();
768 EHStack.popCleanup();
772 if (HasFallthrough && !HasPrebranchedFallthrough && !HasFixups &&
773 !HasExistingBranches) {
776 if (IsEHa && getInvokeDest()) {
778 EmitSehCppScopeEnd();
780 EmitSehTryScopeEnd();
784 EHStack.popCleanup();
786 EmitCleanup(*
this, Fn, cleanupFlags, NormalActiveFlag);
796 CGBuilderTy::InsertPoint savedInactiveFallthroughIP;
800 if (HasFallthrough) {
801 if (!HasPrebranchedFallthrough)
802 Builder.CreateStore(Builder.getInt32(0), getNormalCleanupDestSlot());
806 }
else if (FallthroughSource) {
807 assert(!IsActive &&
"source without fallthrough for active cleanup");
808 savedInactiveFallthroughIP = Builder.saveAndClearIP();
814 EmitBlock(NormalEntry);
817 if (IsEHa && getInvokeDest()) {
819 EmitSehCppScopeEnd();
821 EmitSehTryScopeEnd();
827 bool HasEnclosingCleanups =
828 (
Scope.getEnclosingNormalCleanup() != EHStack.stable_end());
835 llvm::BasicBlock *BranchThroughDest =
nullptr;
836 if (
Scope.hasBranchThroughs() ||
837 (FallthroughSource && FallthroughIsBranchThrough) ||
838 (HasFixups && HasEnclosingCleanups)) {
839 assert(HasEnclosingCleanups);
840 EHScope &S = *EHStack.find(
Scope.getEnclosingNormalCleanup());
844 llvm::BasicBlock *FallthroughDest =
nullptr;
854 if (!
Scope.hasBranchThroughs() && !HasFixups && !HasFallthrough &&
855 !currentFunctionUsesSEHTry() &&
Scope.getNumBranchAfters() == 1) {
856 assert(!BranchThroughDest || !IsActive);
859 llvm::Instruction *NormalCleanupDestSlot =
860 cast<llvm::Instruction>(getNormalCleanupDestSlot().getPointer());
861 if (NormalCleanupDestSlot->hasOneUse()) {
862 NormalCleanupDestSlot->user_back()->eraseFromParent();
863 NormalCleanupDestSlot->eraseFromParent();
867 llvm::BasicBlock *BranchAfter =
Scope.getBranchAfterBlock(0);
868 InstsToAppend.push_back(llvm::BranchInst::Create(BranchAfter));
875 }
else if (
Scope.getNumBranchAfters() ||
876 (HasFallthrough && !FallthroughIsBranchThrough) ||
877 (HasFixups && !HasEnclosingCleanups)) {
880 (BranchThroughDest ? BranchThroughDest : getUnreachableBlock());
883 const unsigned SwitchCapacity = 10;
889 getNormalCleanupDestSlot(),
"cleanup.dest",
nullptr, *
this);
890 llvm::SwitchInst *
Switch =
891 llvm::SwitchInst::Create(Load,
Default, SwitchCapacity);
893 InstsToAppend.push_back(Load);
894 InstsToAppend.push_back(
Switch);
897 if (FallthroughSource && !FallthroughIsBranchThrough) {
898 FallthroughDest = createBasicBlock(
"cleanup.cont");
900 Switch->addCase(Builder.getInt32(0), FallthroughDest);
903 for (
unsigned I = 0, E =
Scope.getNumBranchAfters(); I != E; ++I) {
905 Scope.getBranchAfterBlock(I));
910 if (HasFixups && !HasEnclosingCleanups)
914 assert(BranchThroughDest);
915 InstsToAppend.push_back(llvm::BranchInst::Create(BranchThroughDest));
919 EHStack.popCleanup();
920 assert(EHStack.hasNormalCleanups() == HasEnclosingCleanups);
922 EmitCleanup(*
this, Fn, cleanupFlags, NormalActiveFlag);
925 llvm::BasicBlock *NormalExit = Builder.GetInsertBlock();
926 for (
unsigned I = 0, E = InstsToAppend.size(); I != E; ++I)
927 InstsToAppend[I]->insertInto(NormalExit, NormalExit->end());
930 for (
unsigned I = FixupDepth, E = EHStack.getNumBranchFixups();
947 if (!HasFallthrough && FallthroughSource) {
952 Builder.restoreIP(savedInactiveFallthroughIP);
957 }
else if (HasFallthrough && FallthroughDest) {
958 assert(!FallthroughIsBranchThrough);
959 EmitBlock(FallthroughDest);
963 }
else if (HasFallthrough) {
968 Builder.ClearInsertionPoint();
975 llvm::BasicBlock *NewNormalEntry =
980 if (NewNormalEntry != NormalEntry && NormalEntry == NormalExit)
981 for (
unsigned I = FixupDepth, E = EHStack.getNumBranchFixups();
983 EHStack.getBranchFixup(I).OptimisticBranchBlock = NewNormalEntry;
987 assert(EHStack.hasNormalCleanups() || EHStack.getNumBranchFixups() == 0);
990 if (RequiresEHCleanup) {
991 CGBuilderTy::InsertPoint SavedIP = Builder.saveAndClearIP();
995 llvm::BasicBlock *NextAction = getEHDispatchBlock(EHParent);
1000 bool PushedTerminate =
false;
1002 llvm::CleanupPadInst *CPI =
nullptr;
1006 llvm::Value *ParentPad = CurrentFuncletPad;
1008 ParentPad = llvm::ConstantTokenNone::get(CGM.getLLVMContext());
1009 CurrentFuncletPad = CPI = Builder.CreateCleanupPad(ParentPad);
1014 EHStack.pushTerminate();
1015 PushedTerminate =
true;
1016 }
else if (IsEHa && getInvokeDest()) {
1017 EmitSehCppScopeEnd();
1022 if (EHActiveFlag.
isValid() || IsActive) {
1024 EmitCleanup(*
this, Fn, cleanupFlags, EHActiveFlag);
1028 Builder.CreateCleanupRet(CPI, NextAction);
1030 Builder.CreateBr(NextAction);
1033 if (PushedTerminate)
1034 EHStack.popTerminate();
1036 Builder.restoreIP(SavedIP);
1046 assert(Dest.getScopeDepth().encloses(EHStack.stable_begin())
1047 &&
"stale jump destination");
1051 EHStack.getInnermostActiveNormalCleanup();
1056 if (TopCleanup == EHStack.stable_end() ||
1057 TopCleanup.
encloses(Dest.getScopeDepth()))
1071 assert(Dest.getScopeDepth().encloses(EHStack.stable_begin())
1072 &&
"stale jump destination");
1074 if (!HaveInsertPoint())
1078 llvm::BranchInst *BI = Builder.CreateBr(Dest.getBlock());
1082 TopCleanup = EHStack.getInnermostActiveNormalCleanup();
1087 if (TopCleanup == EHStack.stable_end() ||
1088 TopCleanup.
encloses(Dest.getScopeDepth())) {
1089 Builder.ClearInsertionPoint();
1095 if (!Dest.getScopeDepth().isValid()) {
1102 Builder.ClearInsertionPoint();
1109 llvm::ConstantInt *Index = Builder.getInt32(Dest.getDestIndex());
1115 cast<EHCleanupScope>(*EHStack.find(TopCleanup));
1125 assert(
Scope.isNormalCleanup());
1126 I =
Scope.getEnclosingNormalCleanup();
1131 Scope.addBranchAfter(Index, Dest.getBlock());
1138 if (!
Scope.addBranchThrough(Dest.getBlock()))
1143 Builder.ClearInsertionPoint();
1149 if (cast<EHCleanupScope>(*EHStack.
find(
C)).getNormalBlock())
1156 assert(
C.strictlyEncloses(I));
1158 if (S.getNormalBlock())
return true;
1159 I = S.getEnclosingNormalCleanup();
1174 assert(cleanup.strictlyEncloses(i));
1199 llvm::Instruction *dominatingIP) {
1205 bool isActivatedInConditional =
1208 bool needFlag =
false;
1213 if (
Scope.isNormalCleanup() &&
1215 Scope.setTestFlagInNormalCleanup();
1220 if (
Scope.isEHCleanup() &&
1222 Scope.setTestFlagInEHCleanup();
1227 if (!needFlag)
return;
1232 "cleanup.isactive");
1233 Scope.setActiveFlag(var);
1235 assert(dominatingIP &&
"no existing variable and no dominating IP!");
1255 llvm::Instruction *dominatingIP) {
1256 assert(
C != EHStack.stable_end() &&
"activating bottom of stack?");
1258 assert(!
Scope.isActive() &&
"double activation");
1262 Scope.setActive(
true);
1267 llvm::Instruction *dominatingIP) {
1268 assert(
C != EHStack.stable_end() &&
"deactivating bottom of stack?");
1270 assert(
Scope.isActive() &&
"double deactivation");
1274 if (
C == EHStack.stable_begin() &&
1275 CurrentCleanupScopeDepth.strictlyEncloses(
C)) {
1278 if (!
Scope.isNormalCleanup() && getLangOpts().EHAsynch) {
1283 CGBuilderTy::InsertPoint SavedIP = Builder.saveAndClearIP();
1285 Builder.restoreIP(SavedIP);
1293 Scope.setActive(
false);
1297 if (!NormalCleanupDest.isValid())
1299 CreateDefaultAlignTempAlloca(Builder.getInt32Ty(),
"cleanup.dest.slot");
1300 return NormalCleanupDest;
1314 llvm::FunctionCallee &SehCppScope) {
1316 assert(CGF.
Builder.GetInsertBlock() && InvokeDest);
1322 CGF.
Builder.CreateInvoke(SehCppScope, Cont, InvokeDest, std::nullopt,
1329 assert(getLangOpts().EHAsynch);
1330 llvm::FunctionType *FTy =
1331 llvm::FunctionType::get(CGM.VoidTy,
false);
1332 llvm::FunctionCallee SehCppScope =
1333 CGM.CreateRuntimeFunction(FTy,
"llvm.seh.scope.begin");
1340 assert(getLangOpts().EHAsynch);
1341 llvm::FunctionType *FTy =
1342 llvm::FunctionType::get(CGM.VoidTy,
false);
1343 llvm::FunctionCallee SehCppScope =
1344 CGM.CreateRuntimeFunction(FTy,
"llvm.seh.scope.end");
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.try.begin");
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.end");
static bool IsUsedAsNormalCleanup(EHScopeStack &EHStack, EHScopeStack::stable_iterator C)
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 llvm::LoadInst * createLoadInstBefore(Address addr, const Twine &name, llvm::Instruction *beforeInst, CodeGenFunction &CGF)
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::Instruction *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 PopCleanupBlock(bool FallThroughIsBranchThrough=false)
PopCleanupBlock - Will pop the cleanup entry on the stack and process all branch fixups.
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 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.
virtual void Emit(CodeGenFunction &CGF, Flags flags)=0
Emit the 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.
bool isVolatileQualified() const
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