21#include "llvm/Support/SaveAndRestore.h"
24using namespace CodeGen;
41 return saved_type(
V,
nullptr, ScalarLiteral);
47 return saved_type(addr.
getPointer(),
nullptr, ScalarAddress);
52 llvm::Type *ComplexTy =
53 llvm::StructType::get(
V.first->getType(),
V.second->getType());
57 return saved_type(addr.
getPointer(),
nullptr, ComplexAddress);
63 return saved_type(
V.getPointer(),
V.getElementType(), AggregateLiteral,
64 V.getAlignment().getQuantity());
69 return saved_type(addr.
getPointer(),
V.getElementType(), AggregateAddress,
70 V.getAlignment().getQuantity());
77 auto getSavingAddress = [&](llvm::Value *value) {
78 auto *AI = cast<llvm::AllocaInst>(value);
79 return Address(value, AI->getAllocatedType(),
87 case AggregateLiteral:
90 case AggregateAddress: {
95 case ComplexAddress: {
105 llvm_unreachable(
"bad saved r-value kind");
109char *EHScopeStack::allocate(
size_t Size) {
111 if (!StartOfBuffer) {
112 unsigned Capacity = 1024;
113 while (Capacity < Size) Capacity *= 2;
114 StartOfBuffer =
new char[Capacity];
115 StartOfData = EndOfBuffer = StartOfBuffer + Capacity;
116 }
else if (
static_cast<size_t>(StartOfData - StartOfBuffer) < Size) {
117 unsigned CurrentCapacity = EndOfBuffer - StartOfBuffer;
118 unsigned UsedCapacity = CurrentCapacity - (StartOfData - StartOfBuffer);
120 unsigned NewCapacity = CurrentCapacity;
123 }
while (NewCapacity < UsedCapacity + Size);
125 char *NewStartOfBuffer =
new char[NewCapacity];
126 char *NewEndOfBuffer = NewStartOfBuffer + NewCapacity;
127 char *NewStartOfData = NewEndOfBuffer - UsedCapacity;
128 memcpy(NewStartOfData, StartOfData, UsedCapacity);
129 delete [] StartOfBuffer;
130 StartOfBuffer = NewStartOfBuffer;
131 EndOfBuffer = NewEndOfBuffer;
132 StartOfData = NewStartOfData;
135 assert(StartOfBuffer + Size <= StartOfData);
140void EHScopeStack::deallocate(
size_t Size) {
148 if (!cleanup || !cleanup->isLifetimeMarker())
158 if (
auto *cleanup = dyn_cast<EHCleanupScope>(&*
find(si)))
159 if (cleanup->isLifetimeMarker()) {
160 si = cleanup->getEnclosingEHScope();
174 if (cleanup.isActive())
return si;
175 si = cleanup.getEnclosingNormalCleanup();
181void *EHScopeStack::pushCleanup(
CleanupKind Kind,
size_t Size) {
200 InnermostNormalCleanup,
206 if (IsLifetimeMarker)
207 Scope->setLifetimeMarker();
215 if (CGF->
getLangOpts().EHAsynch && IsEHCleanup && !IsLifetimeMarker &&
219 return Scope->getCleanupBuffer();
223 assert(!
empty() &&
"popping exception stack when not empty");
225 assert(isa<EHCleanupScope>(*
begin()));
227 InnermostNormalCleanup =
Cleanup.getEnclosingNormalCleanup();
228 InnermostEHScope =
Cleanup.getEnclosingEHScope();
229 deallocate(
Cleanup.getAllocatedSize());
235 if (!BranchFixups.empty()) {
239 BranchFixups.clear();
256 assert(!
empty() &&
"popping exception stack when not empty");
267 new (buffer)
EHCatchScope(numHandlers, InnermostEHScope);
289 unsigned MinSize = cast<EHCleanupScope>(*it).getFixupDepth();
290 assert(BranchFixups.size() >= MinSize &&
"fixup stack out of order");
292 while (BranchFixups.size() > MinSize &&
293 BranchFixups.back().Destination ==
nullptr)
294 BranchFixups.pop_back();
315 assert(!cleanup.hasActiveFlag() &&
"cleanup already has active flag?");
316 cleanup.setActiveFlag(ActiveFlag);
318 if (cleanup.isNormalCleanup()) cleanup.setTestFlagInNormalCleanup();
319 if (cleanup.isEHCleanup()) cleanup.setTestFlagInEHCleanup();
322void EHScopeStack::Cleanup::anchor() {}
325 llvm::Instruction *beforeInst) {
326 auto store =
new llvm::StoreInst(value, addr.
getPointer(), beforeInst);
331 llvm::Instruction *beforeInst) {
342 llvm::BasicBlock *CleanupEntry) {
379 llvm::BasicBlock *
Block) {
382 llvm::Instruction *Term =
Block->getTerminator();
383 assert(Term &&
"can't transition block without terminator");
385 if (llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Term)) {
386 assert(Br->isUnconditional());
388 "cleanup.dest", Term);
389 llvm::SwitchInst *
Switch =
390 llvm::SwitchInst::Create(Load, Br->getSuccessor(0), 4,
Block);
391 Br->eraseFromParent();
394 return cast<llvm::SwitchInst>(Term);
399 assert(
Block &&
"resolving a null target block");
400 if (!EHStack.getNumBranchFixups())
return;
402 assert(EHStack.hasNormalCleanups() &&
403 "branch fixups exist with no normal cleanups on stack");
406 bool ResolvedAny =
false;
408 for (
unsigned I = 0, E = EHStack.getNumBranchFixups(); I != E; ++I) {
423 if (!ModifiedOptimisticBlocks.insert(BranchBB).second)
433 EHStack.popNullFixups();
439 std::initializer_list<llvm::Value **> ValuesToReload) {
442 bool HadBranches =
false;
443 while (EHStack.stable_begin() != Old) {
445 HadBranches |=
Scope.hasBranches();
450 bool FallThroughIsBranchThrough =
453 PopCleanupBlock(FallThroughIsBranchThrough);
464 for (llvm::Value **ReloadedValue : ValuesToReload) {
465 auto *Inst = dyn_cast_or_null<llvm::Instruction>(*ReloadedValue);
471 auto *AI = dyn_cast<llvm::AllocaInst>(Inst);
472 if (AI && AI->isStaticAlloca())
476 CreateDefaultAlignTempAlloca(Inst->getType(),
"tmp.exprcleanup");
479 llvm::BasicBlock::iterator InsertBefore;
480 if (
auto *Invoke = dyn_cast<llvm::InvokeInst>(Inst))
481 InsertBefore = Invoke->getNormalDest()->getFirstInsertionPt();
483 InsertBefore = std::next(Inst->getIterator());
487 *ReloadedValue = Builder.CreateLoad(Tmp);
495 std::initializer_list<llvm::Value **> ValuesToReload) {
496 PopCleanupBlocks(Old, ValuesToReload);
499 for (
size_t I = OldLifetimeExtendedSize,
500 E = LifetimeExtendedCleanupStack.size(); I != E; ) {
502 assert((I %
alignof(LifetimeExtendedCleanupHeader) == 0) &&
503 "misaligned cleanup stack entry");
505 LifetimeExtendedCleanupHeader &Header =
506 reinterpret_cast<LifetimeExtendedCleanupHeader&
>(
507 LifetimeExtendedCleanupStack[I]);
510 EHStack.pushCopyOfCleanup(Header.getKind(),
511 &LifetimeExtendedCleanupStack[I],
513 I += Header.getSize();
515 if (Header.isConditional()) {
517 reinterpret_cast<Address &
>(LifetimeExtendedCleanupStack[I]);
518 initFullExprCleanupWithFlag(ActiveFlag);
519 I +=
sizeof(ActiveFlag);
522 LifetimeExtendedCleanupStack.resize(OldLifetimeExtendedSize);
527 assert(
Scope.isNormalCleanup());
528 llvm::BasicBlock *Entry =
Scope.getNormalBlock();
531 Scope.setNormalBlock(Entry);
542 llvm::BasicBlock *Entry) {
543 llvm::BasicBlock *Pred = Entry->getSinglePredecessor();
544 if (!Pred)
return Entry;
546 llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Pred->getTerminator());
547 if (!Br || Br->isConditional())
return Entry;
548 assert(Br->getSuccessor(0) == Entry);
553 bool WasInsertBlock = CGF.
Builder.GetInsertBlock() == Entry;
554 assert(!WasInsertBlock || CGF.
Builder.GetInsertPoint() == Entry->end());
557 Br->eraseFromParent();
561 Entry->replaceAllUsesWith(Pred);
564 Pred->splice(Pred->end(), Entry);
567 Entry->eraseFromParent();
570 CGF.
Builder.SetInsertPoint(Pred);
581 llvm::BasicBlock *ContBB =
nullptr;
585 llvm::Value *IsActive
587 CGF.
Builder.CreateCondBr(IsActive, CleanupBB, ContBB);
592 Fn->
Emit(CGF, flags);
593 assert(CGF.
HaveInsertPoint() &&
"cleanup ended with no insertion point?");
601 llvm::BasicBlock *From,
602 llvm::BasicBlock *To) {
605 llvm::Instruction *Term = Exit->getTerminator();
607 if (llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Term)) {
608 assert(Br->isUnconditional() && Br->getSuccessor(0) == From);
609 Br->setSuccessor(0, To);
611 llvm::SwitchInst *
Switch = cast<llvm::SwitchInst>(Term);
612 for (
unsigned I = 0, E =
Switch->getNumSuccessors(); I != E; ++I)
613 if (
Switch->getSuccessor(I) == From)
614 Switch->setSuccessor(I, To);
631 for (llvm::BasicBlock::use_iterator
632 i = entry->use_begin(), e = entry->use_end(); i != e; ) {
636 use.set(unreachableBB);
639 llvm::SwitchInst *si = cast<llvm::SwitchInst>(use.getUser());
640 if (si->getNumCases() == 1 && si->getDefaultDest() == unreachableBB) {
642 llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(), si);
645 llvm::LoadInst *condition = cast<llvm::LoadInst>(si->getCondition());
648 si->eraseFromParent();
652 assert(condition->use_empty());
653 condition->eraseFromParent();
657 assert(entry->use_empty());
665 assert(!EHStack.empty() &&
"cleanup stack is empty!");
666 assert(isa<EHCleanupScope>(*EHStack.begin()) &&
"top not a cleanup!");
668 assert(
Scope.getFixupDepth() <= EHStack.getNumBranchFixups());
671 bool IsActive =
Scope.isActive();
673 Scope.shouldTestFlagInNormalCleanup() ?
Scope.getActiveFlag()
676 Scope.shouldTestFlagInEHCleanup() ?
Scope.getActiveFlag()
681 llvm::BasicBlock *EHEntry =
Scope.getCachedEHDispatchBlock();
682 assert(
Scope.hasEHBranches() == (EHEntry !=
nullptr));
683 bool RequiresEHCleanup = (EHEntry !=
nullptr);
689 unsigned FixupDepth =
Scope.getFixupDepth();
690 bool HasFixups = EHStack.getNumBranchFixups() != FixupDepth;
693 bool HasExistingBranches =
Scope.hasBranches();
696 llvm::BasicBlock *FallthroughSource = Builder.GetInsertBlock();
697 bool HasFallthrough = (FallthroughSource !=
nullptr && IsActive);
703 bool HasPrebranchedFallthrough =
704 (FallthroughSource && FallthroughSource->getTerminator());
709 assert(!
Scope.isNormalCleanup() || !HasPrebranchedFallthrough ||
710 (
Scope.getNormalBlock() &&
711 FallthroughSource->getTerminator()->getSuccessor(0)
712 ==
Scope.getNormalBlock()));
714 bool RequiresNormalCleanup =
false;
715 if (
Scope.isNormalCleanup() &&
716 (HasFixups || HasExistingBranches || HasFallthrough)) {
717 RequiresNormalCleanup =
true;
722 if (
Scope.isNormalCleanup() && HasPrebranchedFallthrough && !IsActive) {
723 llvm::BasicBlock *prebranchDest;
728 if (FallthroughIsBranchThrough) {
729 EHScope &enclosing = *EHStack.find(
Scope.getEnclosingNormalCleanup());
737 prebranchDest = createBasicBlock(
"forwarded-prebranch");
738 EmitBlock(prebranchDest);
741 llvm::BasicBlock *normalEntry =
Scope.getNormalBlock();
742 assert(normalEntry && !normalEntry->use_empty());
745 normalEntry, prebranchDest);
749 if (!RequiresNormalCleanup && !RequiresEHCleanup) {
751 EHStack.popCleanup();
752 assert(EHStack.getNumBranchFixups() == 0 ||
753 EHStack.hasNormalCleanups());
762 auto *CleanupSource =
reinterpret_cast<char *
>(
Scope.getCleanupBuffer());
764 CleanupBufferStack[8 *
sizeof(
void *)];
765 std::unique_ptr<char[]> CleanupBufferHeap;
766 size_t CleanupSize =
Scope.getCleanupSize();
769 if (CleanupSize <=
sizeof(CleanupBufferStack)) {
770 memcpy(CleanupBufferStack, CleanupSource, CleanupSize);
773 CleanupBufferHeap.reset(
new char[CleanupSize]);
774 memcpy(CleanupBufferHeap.get(), CleanupSource, CleanupSize);
779 if (
Scope.isNormalCleanup())
781 if (
Scope.isEHCleanup())
785 bool IsEHa = getLangOpts().EHAsynch && !
Scope.isLifetimeMarker();
787 if (!RequiresNormalCleanup) {
790 if (IsEHa && getInvokeDest() && Builder.GetInsertBlock()) {
792 EmitSehCppScopeEnd();
795 EHStack.popCleanup();
799 if (HasFallthrough && !HasPrebranchedFallthrough && !HasFixups &&
800 !HasExistingBranches) {
803 if (IsEHa && getInvokeDest()) {
805 EmitSehCppScopeEnd();
807 EmitSehTryScopeEnd();
811 EHStack.popCleanup();
813 EmitCleanup(*
this, Fn, cleanupFlags, NormalActiveFlag);
823 CGBuilderTy::InsertPoint savedInactiveFallthroughIP;
827 if (HasFallthrough) {
828 if (!HasPrebranchedFallthrough)
829 Builder.CreateStore(Builder.getInt32(0), getNormalCleanupDestSlot());
833 }
else if (FallthroughSource) {
834 assert(!IsActive &&
"source without fallthrough for active cleanup");
835 savedInactiveFallthroughIP = Builder.saveAndClearIP();
841 EmitBlock(NormalEntry);
844 if (IsEHa && getInvokeDest()) {
846 EmitSehCppScopeEnd();
848 EmitSehTryScopeEnd();
854 bool HasEnclosingCleanups =
855 (
Scope.getEnclosingNormalCleanup() != EHStack.stable_end());
862 llvm::BasicBlock *BranchThroughDest =
nullptr;
863 if (
Scope.hasBranchThroughs() ||
864 (FallthroughSource && FallthroughIsBranchThrough) ||
865 (HasFixups && HasEnclosingCleanups)) {
866 assert(HasEnclosingCleanups);
867 EHScope &S = *EHStack.find(
Scope.getEnclosingNormalCleanup());
871 llvm::BasicBlock *FallthroughDest =
nullptr;
881 if (!
Scope.hasBranchThroughs() && !HasFixups && !HasFallthrough &&
882 !currentFunctionUsesSEHTry() &&
Scope.getNumBranchAfters() == 1) {
883 assert(!BranchThroughDest || !IsActive);
886 llvm::Instruction *NormalCleanupDestSlot =
887 cast<llvm::Instruction>(getNormalCleanupDestSlot().getPointer());
888 if (NormalCleanupDestSlot->hasOneUse()) {
889 NormalCleanupDestSlot->user_back()->eraseFromParent();
890 NormalCleanupDestSlot->eraseFromParent();
894 llvm::BasicBlock *BranchAfter =
Scope.getBranchAfterBlock(0);
895 InstsToAppend.push_back(llvm::BranchInst::Create(BranchAfter));
902 }
else if (
Scope.getNumBranchAfters() ||
903 (HasFallthrough && !FallthroughIsBranchThrough) ||
904 (HasFixups && !HasEnclosingCleanups)) {
907 (BranchThroughDest ? BranchThroughDest : getUnreachableBlock());
910 const unsigned SwitchCapacity = 10;
915 llvm::LoadInst *
Load =
918 llvm::SwitchInst *
Switch =
919 llvm::SwitchInst::Create(Load,
Default, SwitchCapacity);
921 InstsToAppend.push_back(Load);
922 InstsToAppend.push_back(
Switch);
925 if (FallthroughSource && !FallthroughIsBranchThrough) {
926 FallthroughDest = createBasicBlock(
"cleanup.cont");
928 Switch->addCase(Builder.getInt32(0), FallthroughDest);
931 for (
unsigned I = 0, E =
Scope.getNumBranchAfters(); I != E; ++I) {
933 Scope.getBranchAfterBlock(I));
938 if (HasFixups && !HasEnclosingCleanups)
942 assert(BranchThroughDest);
943 InstsToAppend.push_back(llvm::BranchInst::Create(BranchThroughDest));
947 EHStack.popCleanup();
948 assert(EHStack.hasNormalCleanups() == HasEnclosingCleanups);
950 EmitCleanup(*
this, Fn, cleanupFlags, NormalActiveFlag);
953 llvm::BasicBlock *NormalExit = Builder.GetInsertBlock();
954 for (
unsigned I = 0, E = InstsToAppend.size(); I != E; ++I)
955 InstsToAppend[I]->insertInto(NormalExit, NormalExit->end());
958 for (
unsigned I = FixupDepth, E = EHStack.getNumBranchFixups();
964 getNormalCleanupDestSlot(),
975 if (!HasFallthrough && FallthroughSource) {
980 Builder.restoreIP(savedInactiveFallthroughIP);
985 }
else if (HasFallthrough && FallthroughDest) {
986 assert(!FallthroughIsBranchThrough);
987 EmitBlock(FallthroughDest);
991 }
else if (HasFallthrough) {
996 Builder.ClearInsertionPoint();
1003 llvm::BasicBlock *NewNormalEntry =
1008 if (NewNormalEntry != NormalEntry && NormalEntry == NormalExit)
1009 for (
unsigned I = FixupDepth, E = EHStack.getNumBranchFixups();
1011 EHStack.getBranchFixup(I).OptimisticBranchBlock = NewNormalEntry;
1015 assert(EHStack.hasNormalCleanups() || EHStack.getNumBranchFixups() == 0);
1018 if (RequiresEHCleanup) {
1019 CGBuilderTy::InsertPoint SavedIP = Builder.saveAndClearIP();
1023 llvm::BasicBlock *NextAction = getEHDispatchBlock(EHParent);
1028 bool PushedTerminate =
false;
1030 llvm::CleanupPadInst *CPI =
nullptr;
1034 llvm::Value *ParentPad = CurrentFuncletPad;
1036 ParentPad = llvm::ConstantTokenNone::get(CGM.getLLVMContext());
1037 CurrentFuncletPad = CPI = Builder.CreateCleanupPad(ParentPad);
1042 EHStack.pushTerminate();
1043 PushedTerminate =
true;
1044 }
else if (IsEHa && getInvokeDest()) {
1045 EmitSehCppScopeEnd();
1050 if (EHActiveFlag.
isValid() || IsActive) {
1052 EmitCleanup(*
this, Fn, cleanupFlags, EHActiveFlag);
1056 Builder.CreateCleanupRet(CPI, NextAction);
1058 Builder.CreateBr(NextAction);
1061 if (PushedTerminate)
1062 EHStack.popTerminate();
1064 Builder.restoreIP(SavedIP);
1074 assert(Dest.getScopeDepth().encloses(EHStack.stable_begin())
1075 &&
"stale jump destination");
1079 EHStack.getInnermostActiveNormalCleanup();
1084 if (TopCleanup == EHStack.stable_end() ||
1085 TopCleanup.
encloses(Dest.getScopeDepth()))
1099 assert(Dest.getScopeDepth().encloses(EHStack.stable_begin())
1100 &&
"stale jump destination");
1102 if (!HaveInsertPoint())
1106 llvm::BranchInst *BI = Builder.CreateBr(Dest.getBlock());
1110 TopCleanup = EHStack.getInnermostActiveNormalCleanup();
1115 if (TopCleanup == EHStack.stable_end() ||
1116 TopCleanup.
encloses(Dest.getScopeDepth())) {
1117 Builder.ClearInsertionPoint();
1123 if (!Dest.getScopeDepth().isValid()) {
1130 Builder.ClearInsertionPoint();
1137 llvm::ConstantInt *Index = Builder.getInt32(Dest.getDestIndex());
1143 cast<EHCleanupScope>(*EHStack.find(TopCleanup));
1153 assert(
Scope.isNormalCleanup());
1154 I =
Scope.getEnclosingNormalCleanup();
1159 Scope.addBranchAfter(Index, Dest.getBlock());
1166 if (!
Scope.addBranchThrough(Dest.getBlock()))
1171 Builder.ClearInsertionPoint();
1177 if (cast<EHCleanupScope>(*EHStack.
find(
C)).getNormalBlock())
1184 assert(
C.strictlyEncloses(I));
1186 if (S.getNormalBlock())
return true;
1187 I = S.getEnclosingNormalCleanup();
1202 assert(cleanup.strictlyEncloses(i));
1227 llvm::Instruction *dominatingIP) {
1233 bool isActivatedInConditional =
1236 bool needFlag =
false;
1241 if (
Scope.isNormalCleanup() &&
1243 Scope.setTestFlagInNormalCleanup();
1248 if (
Scope.isEHCleanup() &&
1250 Scope.setTestFlagInEHCleanup();
1255 if (!needFlag)
return;
1260 "cleanup.isactive");
1261 Scope.setActiveFlag(var);
1263 assert(dominatingIP &&
"no existing variable and no dominating IP!");
1283 llvm::Instruction *dominatingIP) {
1284 assert(
C != EHStack.stable_end() &&
"activating bottom of stack?");
1286 assert(!
Scope.isActive() &&
"double activation");
1290 Scope.setActive(
true);
1295 llvm::Instruction *dominatingIP) {
1296 assert(
C != EHStack.stable_end() &&
"deactivating bottom of stack?");
1298 assert(
Scope.isActive() &&
"double deactivation");
1302 if (
C == EHStack.stable_begin() &&
1303 CurrentCleanupScopeDepth.strictlyEncloses(
C)) {
1306 if (!
Scope.isNormalCleanup() && getLangOpts().EHAsynch) {
1311 CGBuilderTy::InsertPoint SavedIP = Builder.saveAndClearIP();
1313 Builder.restoreIP(SavedIP);
1321 Scope.setActive(
false);
1325 if (!NormalCleanupDest.isValid())
1327 CreateDefaultAlignTempAlloca(Builder.getInt32Ty(),
"cleanup.dest.slot");
1328 return NormalCleanupDest;
1342 llvm::FunctionCallee &SehCppScope) {
1344 assert(CGF.
Builder.GetInsertBlock() && InvokeDest);
1350 CGF.
Builder.CreateInvoke(SehCppScope, Cont, InvokeDest, std::nullopt,
1357 assert(getLangOpts().EHAsynch);
1358 llvm::FunctionType *FTy =
1359 llvm::FunctionType::get(CGM.VoidTy,
false);
1360 llvm::FunctionCallee SehCppScope =
1361 CGM.CreateRuntimeFunction(FTy,
"llvm.seh.scope.begin");
1368 assert(getLangOpts().EHAsynch);
1369 llvm::FunctionType *FTy =
1370 llvm::FunctionType::get(CGM.VoidTy,
false);
1371 llvm::FunctionCallee SehCppScope =
1372 CGM.CreateRuntimeFunction(FTy,
"llvm.seh.scope.end");
1378 assert(getLangOpts().EHAsynch);
1379 llvm::FunctionType *FTy =
1380 llvm::FunctionType::get(CGM.VoidTy,
false);
1381 llvm::FunctionCallee SehCppScope =
1382 CGM.CreateRuntimeFunction(FTy,
"llvm.seh.try.begin");
1388 assert(getLangOpts().EHAsynch);
1389 llvm::FunctionType *FTy =
1390 llvm::FunctionType::get(CGM.VoidTy,
false);
1391 llvm::FunctionCallee SehCppScope =
1392 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 createStoreInstBefore(llvm::Value *value, Address addr, llvm::Instruction *beforeInst)
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)
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 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.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
CharUnits getAlignment() const
Return the alignment of this pointer.
llvm::Type * getElementType() const
Return the type of the values stored in this address.
llvm::Value * getPointer() const
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
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()
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
Address CreateTempAllocaWithoutCast(llvm::Type *Ty, CharUnits align, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
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)
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...
Address getNormalCleanupDestSlot()
void EmitSehCppScopeEnd()
void setBeforeOutermostConditional(llvm::Value *value, Address addr)
llvm::BasicBlock * getInvokeDest()
void EmitSehTryScopeBegin()
void EmitSehTryScopeEnd()
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
Address createCleanupActiveFlag()
Address CreateDefaultAlignTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
CreateDefaultAlignedTempAlloca - This creates an alloca with the default ABI alignment of the given L...
Address NormalCleanupDest
i32s containing the indexes of the cleanup destinations.
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.
void initFullExprCleanupWithFlag(Address ActiveFlag)
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)
llvm::Value * getAggregatePointer() const
static RValue getAggregate(Address addr, bool isVolatile=false)
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.
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)
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.
CharUnits getPointerAlign() const
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