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();
210 if (CGF->
getLangOpts().EHAsynch && IsEHCleanup && !IsLifetimeMarker &&
214 return Scope->getCleanupBuffer();
218 assert(!
empty() &&
"popping exception stack when not empty");
220 assert(isa<EHCleanupScope>(*
begin()));
222 InnermostNormalCleanup =
Cleanup.getEnclosingNormalCleanup();
223 InnermostEHScope =
Cleanup.getEnclosingEHScope();
224 deallocate(
Cleanup.getAllocatedSize());
230 if (!BranchFixups.empty()) {
234 BranchFixups.clear();
251 assert(!
empty() &&
"popping exception stack when not empty");
262 new (buffer)
EHCatchScope(numHandlers, InnermostEHScope);
284 unsigned MinSize = cast<EHCleanupScope>(*it).getFixupDepth();
285 assert(BranchFixups.size() >= MinSize &&
"fixup stack out of order");
287 while (BranchFixups.size() > MinSize &&
288 BranchFixups.back().Destination ==
nullptr)
289 BranchFixups.pop_back();
310 assert(!cleanup.hasActiveFlag() &&
"cleanup already has active flag?");
311 cleanup.setActiveFlag(ActiveFlag);
313 if (cleanup.isNormalCleanup()) cleanup.setTestFlagInNormalCleanup();
314 if (cleanup.isEHCleanup()) cleanup.setTestFlagInEHCleanup();
317void EHScopeStack::Cleanup::anchor() {}
320 llvm::Instruction *beforeInst) {
321 auto store =
new llvm::StoreInst(value, addr.
getPointer(), beforeInst);
326 llvm::Instruction *beforeInst) {
337 llvm::BasicBlock *CleanupEntry) {
374 llvm::BasicBlock *
Block) {
377 llvm::Instruction *Term =
Block->getTerminator();
378 assert(Term &&
"can't transition block without terminator");
380 if (llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Term)) {
381 assert(Br->isUnconditional());
383 "cleanup.dest", Term);
384 llvm::SwitchInst *
Switch =
385 llvm::SwitchInst::Create(Load, Br->getSuccessor(0), 4,
Block);
386 Br->eraseFromParent();
389 return cast<llvm::SwitchInst>(Term);
394 assert(
Block &&
"resolving a null target block");
395 if (!EHStack.getNumBranchFixups())
return;
397 assert(EHStack.hasNormalCleanups() &&
398 "branch fixups exist with no normal cleanups on stack");
401 bool ResolvedAny =
false;
403 for (
unsigned I = 0, E = EHStack.getNumBranchFixups(); I != E; ++I) {
418 if (!ModifiedOptimisticBlocks.insert(BranchBB).second)
428 EHStack.popNullFixups();
434 std::initializer_list<llvm::Value **> ValuesToReload) {
437 bool HadBranches =
false;
438 while (EHStack.stable_begin() != Old) {
440 HadBranches |=
Scope.hasBranches();
445 bool FallThroughIsBranchThrough =
448 PopCleanupBlock(FallThroughIsBranchThrough);
459 for (llvm::Value **ReloadedValue : ValuesToReload) {
460 auto *Inst = dyn_cast_or_null<llvm::Instruction>(*ReloadedValue);
466 auto *AI = dyn_cast<llvm::AllocaInst>(Inst);
467 if (AI && AI->isStaticAlloca())
471 CreateDefaultAlignTempAlloca(Inst->getType(),
"tmp.exprcleanup");
474 llvm::BasicBlock::iterator InsertBefore;
475 if (
auto *Invoke = dyn_cast<llvm::InvokeInst>(Inst))
476 InsertBefore = Invoke->getNormalDest()->getFirstInsertionPt();
478 InsertBefore = std::next(Inst->getIterator());
482 *ReloadedValue = Builder.CreateLoad(Tmp);
490 std::initializer_list<llvm::Value **> ValuesToReload) {
491 PopCleanupBlocks(Old, ValuesToReload);
494 for (
size_t I = OldLifetimeExtendedSize,
495 E = LifetimeExtendedCleanupStack.size(); I != E; ) {
497 assert((I %
alignof(LifetimeExtendedCleanupHeader) == 0) &&
498 "misaligned cleanup stack entry");
500 LifetimeExtendedCleanupHeader &Header =
501 reinterpret_cast<LifetimeExtendedCleanupHeader&
>(
502 LifetimeExtendedCleanupStack[I]);
505 EHStack.pushCopyOfCleanup(Header.getKind(),
506 &LifetimeExtendedCleanupStack[I],
508 I += Header.getSize();
510 if (Header.isConditional()) {
512 reinterpret_cast<Address &
>(LifetimeExtendedCleanupStack[I]);
513 initFullExprCleanupWithFlag(ActiveFlag);
514 I +=
sizeof(ActiveFlag);
517 LifetimeExtendedCleanupStack.resize(OldLifetimeExtendedSize);
522 assert(
Scope.isNormalCleanup());
523 llvm::BasicBlock *Entry =
Scope.getNormalBlock();
526 Scope.setNormalBlock(Entry);
537 llvm::BasicBlock *Entry) {
538 llvm::BasicBlock *Pred = Entry->getSinglePredecessor();
539 if (!Pred)
return Entry;
541 llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Pred->getTerminator());
542 if (!Br || Br->isConditional())
return Entry;
543 assert(Br->getSuccessor(0) == Entry);
548 bool WasInsertBlock = CGF.
Builder.GetInsertBlock() == Entry;
549 assert(!WasInsertBlock || CGF.
Builder.GetInsertPoint() == Entry->end());
552 Br->eraseFromParent();
556 Entry->replaceAllUsesWith(Pred);
559 Pred->splice(Pred->end(), Entry);
562 Entry->eraseFromParent();
565 CGF.
Builder.SetInsertPoint(Pred);
576 llvm::BasicBlock *ContBB =
nullptr;
580 llvm::Value *IsActive
582 CGF.
Builder.CreateCondBr(IsActive, CleanupBB, ContBB);
587 Fn->
Emit(CGF, flags);
588 assert(CGF.
HaveInsertPoint() &&
"cleanup ended with no insertion point?");
596 llvm::BasicBlock *From,
597 llvm::BasicBlock *To) {
600 llvm::Instruction *Term = Exit->getTerminator();
602 if (llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Term)) {
603 assert(Br->isUnconditional() && Br->getSuccessor(0) == From);
604 Br->setSuccessor(0, To);
606 llvm::SwitchInst *
Switch = cast<llvm::SwitchInst>(Term);
607 for (
unsigned I = 0, E =
Switch->getNumSuccessors(); I != E; ++I)
608 if (
Switch->getSuccessor(I) == From)
609 Switch->setSuccessor(I, To);
626 for (llvm::BasicBlock::use_iterator
627 i = entry->use_begin(), e = entry->use_end(); i != e; ) {
631 use.set(unreachableBB);
634 llvm::SwitchInst *si = cast<llvm::SwitchInst>(use.getUser());
635 if (si->getNumCases() == 1 && si->getDefaultDest() == unreachableBB) {
637 llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(), si);
640 llvm::LoadInst *condition = cast<llvm::LoadInst>(si->getCondition());
643 si->eraseFromParent();
647 assert(condition->use_empty());
648 condition->eraseFromParent();
652 assert(entry->use_empty());
660 assert(!EHStack.empty() &&
"cleanup stack is empty!");
661 assert(isa<EHCleanupScope>(*EHStack.begin()) &&
"top not a cleanup!");
663 assert(
Scope.getFixupDepth() <= EHStack.getNumBranchFixups());
666 bool IsActive =
Scope.isActive();
668 Scope.shouldTestFlagInNormalCleanup() ?
Scope.getActiveFlag()
671 Scope.shouldTestFlagInEHCleanup() ?
Scope.getActiveFlag()
676 llvm::BasicBlock *EHEntry =
Scope.getCachedEHDispatchBlock();
677 assert(
Scope.hasEHBranches() == (EHEntry !=
nullptr));
678 bool RequiresEHCleanup = (EHEntry !=
nullptr);
684 unsigned FixupDepth =
Scope.getFixupDepth();
685 bool HasFixups = EHStack.getNumBranchFixups() != FixupDepth;
688 bool HasExistingBranches =
Scope.hasBranches();
691 llvm::BasicBlock *FallthroughSource = Builder.GetInsertBlock();
692 bool HasFallthrough = (FallthroughSource !=
nullptr && IsActive);
698 bool HasPrebranchedFallthrough =
699 (FallthroughSource && FallthroughSource->getTerminator());
704 assert(!
Scope.isNormalCleanup() || !HasPrebranchedFallthrough ||
705 (
Scope.getNormalBlock() &&
706 FallthroughSource->getTerminator()->getSuccessor(0)
707 ==
Scope.getNormalBlock()));
709 bool RequiresNormalCleanup =
false;
710 if (
Scope.isNormalCleanup() &&
711 (HasFixups || HasExistingBranches || HasFallthrough)) {
712 RequiresNormalCleanup =
true;
717 if (
Scope.isNormalCleanup() && HasPrebranchedFallthrough && !IsActive) {
718 llvm::BasicBlock *prebranchDest;
723 if (FallthroughIsBranchThrough) {
724 EHScope &enclosing = *EHStack.find(
Scope.getEnclosingNormalCleanup());
732 prebranchDest = createBasicBlock(
"forwarded-prebranch");
733 EmitBlock(prebranchDest);
736 llvm::BasicBlock *normalEntry =
Scope.getNormalBlock();
737 assert(normalEntry && !normalEntry->use_empty());
740 normalEntry, prebranchDest);
744 if (!RequiresNormalCleanup && !RequiresEHCleanup) {
746 EHStack.popCleanup();
747 assert(EHStack.getNumBranchFixups() == 0 ||
748 EHStack.hasNormalCleanups());
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() && Builder.GetInsertBlock()) {
787 EmitSehCppScopeEnd();
790 EHStack.popCleanup();
794 if (HasFallthrough && !HasPrebranchedFallthrough && !HasFixups &&
795 !HasExistingBranches) {
798 if (IsEHa && getInvokeDest()) {
800 EmitSehCppScopeEnd();
802 EmitSehTryScopeEnd();
806 EHStack.popCleanup();
808 EmitCleanup(*
this, Fn, cleanupFlags, NormalActiveFlag);
818 CGBuilderTy::InsertPoint savedInactiveFallthroughIP;
822 if (HasFallthrough) {
823 if (!HasPrebranchedFallthrough)
824 Builder.CreateStore(Builder.getInt32(0), getNormalCleanupDestSlot());
828 }
else if (FallthroughSource) {
829 assert(!IsActive &&
"source without fallthrough for active cleanup");
830 savedInactiveFallthroughIP = Builder.saveAndClearIP();
836 EmitBlock(NormalEntry);
839 if (IsEHa && getInvokeDest()) {
841 EmitSehCppScopeEnd();
843 EmitSehTryScopeEnd();
849 bool HasEnclosingCleanups =
850 (
Scope.getEnclosingNormalCleanup() != EHStack.stable_end());
857 llvm::BasicBlock *BranchThroughDest =
nullptr;
858 if (
Scope.hasBranchThroughs() ||
859 (FallthroughSource && FallthroughIsBranchThrough) ||
860 (HasFixups && HasEnclosingCleanups)) {
861 assert(HasEnclosingCleanups);
862 EHScope &S = *EHStack.find(
Scope.getEnclosingNormalCleanup());
866 llvm::BasicBlock *FallthroughDest =
nullptr;
871 if (!
Scope.hasBranchThroughs() && !HasFixups && !HasFallthrough &&
872 Scope.getNumBranchAfters() == 1) {
873 assert(!BranchThroughDest || !IsActive);
876 llvm::Instruction *NormalCleanupDestSlot =
877 cast<llvm::Instruction>(getNormalCleanupDestSlot().getPointer());
878 if (NormalCleanupDestSlot->hasOneUse()) {
879 NormalCleanupDestSlot->user_back()->eraseFromParent();
880 NormalCleanupDestSlot->eraseFromParent();
884 llvm::BasicBlock *BranchAfter =
Scope.getBranchAfterBlock(0);
885 InstsToAppend.push_back(llvm::BranchInst::Create(BranchAfter));
892 }
else if (
Scope.getNumBranchAfters() ||
893 (HasFallthrough && !FallthroughIsBranchThrough) ||
894 (HasFixups && !HasEnclosingCleanups)) {
897 (BranchThroughDest ? BranchThroughDest : getUnreachableBlock());
900 const unsigned SwitchCapacity = 10;
905 llvm::LoadInst *
Load =
908 llvm::SwitchInst *
Switch =
909 llvm::SwitchInst::Create(Load,
Default, SwitchCapacity);
911 InstsToAppend.push_back(Load);
912 InstsToAppend.push_back(
Switch);
915 if (FallthroughSource && !FallthroughIsBranchThrough) {
916 FallthroughDest = createBasicBlock(
"cleanup.cont");
918 Switch->addCase(Builder.getInt32(0), FallthroughDest);
921 for (
unsigned I = 0, E =
Scope.getNumBranchAfters(); I != E; ++I) {
923 Scope.getBranchAfterBlock(I));
928 if (HasFixups && !HasEnclosingCleanups)
932 assert(BranchThroughDest);
933 InstsToAppend.push_back(llvm::BranchInst::Create(BranchThroughDest));
937 EHStack.popCleanup();
938 assert(EHStack.hasNormalCleanups() == HasEnclosingCleanups);
940 EmitCleanup(*
this, Fn, cleanupFlags, NormalActiveFlag);
943 llvm::BasicBlock *NormalExit = Builder.GetInsertBlock();
944 for (
unsigned I = 0, E = InstsToAppend.size(); I != E; ++I)
945 InstsToAppend[I]->insertInto(NormalExit, NormalExit->end());
948 for (
unsigned I = FixupDepth, E = EHStack.getNumBranchFixups();
954 getNormalCleanupDestSlot(),
965 if (!HasFallthrough && FallthroughSource) {
970 Builder.restoreIP(savedInactiveFallthroughIP);
975 }
else if (HasFallthrough && FallthroughDest) {
976 assert(!FallthroughIsBranchThrough);
977 EmitBlock(FallthroughDest);
981 }
else if (HasFallthrough) {
986 Builder.ClearInsertionPoint();
993 llvm::BasicBlock *NewNormalEntry =
998 if (NewNormalEntry != NormalEntry && NormalEntry == NormalExit)
999 for (
unsigned I = FixupDepth, E = EHStack.getNumBranchFixups();
1001 EHStack.getBranchFixup(I).OptimisticBranchBlock = NewNormalEntry;
1005 assert(EHStack.hasNormalCleanups() || EHStack.getNumBranchFixups() == 0);
1008 if (RequiresEHCleanup) {
1009 CGBuilderTy::InsertPoint SavedIP = Builder.saveAndClearIP();
1013 llvm::BasicBlock *NextAction = getEHDispatchBlock(EHParent);
1018 bool PushedTerminate =
false;
1020 llvm::CleanupPadInst *CPI =
nullptr;
1024 llvm::Value *ParentPad = CurrentFuncletPad;
1026 ParentPad = llvm::ConstantTokenNone::get(CGM.getLLVMContext());
1027 CurrentFuncletPad = CPI = Builder.CreateCleanupPad(ParentPad);
1032 EHStack.pushTerminate();
1033 PushedTerminate =
true;
1034 }
else if (IsEHa && getInvokeDest()) {
1035 EmitSehCppScopeEnd();
1040 if (EHActiveFlag.
isValid() || IsActive) {
1042 EmitCleanup(*
this, Fn, cleanupFlags, EHActiveFlag);
1046 Builder.CreateCleanupRet(CPI, NextAction);
1048 Builder.CreateBr(NextAction);
1051 if (PushedTerminate)
1052 EHStack.popTerminate();
1054 Builder.restoreIP(SavedIP);
1064 assert(Dest.getScopeDepth().encloses(EHStack.stable_begin())
1065 &&
"stale jump destination");
1069 EHStack.getInnermostActiveNormalCleanup();
1074 if (TopCleanup == EHStack.stable_end() ||
1075 TopCleanup.
encloses(Dest.getScopeDepth()))
1089 assert(Dest.getScopeDepth().encloses(EHStack.stable_begin())
1090 &&
"stale jump destination");
1092 if (!HaveInsertPoint())
1096 llvm::BranchInst *BI = Builder.CreateBr(Dest.getBlock());
1100 TopCleanup = EHStack.getInnermostActiveNormalCleanup();
1105 if (TopCleanup == EHStack.stable_end() ||
1106 TopCleanup.
encloses(Dest.getScopeDepth())) {
1107 Builder.ClearInsertionPoint();
1113 if (!Dest.getScopeDepth().isValid()) {
1120 Builder.ClearInsertionPoint();
1127 llvm::ConstantInt *Index = Builder.getInt32(Dest.getDestIndex());
1133 cast<EHCleanupScope>(*EHStack.find(TopCleanup));
1143 assert(
Scope.isNormalCleanup());
1144 I =
Scope.getEnclosingNormalCleanup();
1149 Scope.addBranchAfter(Index, Dest.getBlock());
1156 if (!
Scope.addBranchThrough(Dest.getBlock()))
1161 Builder.ClearInsertionPoint();
1167 if (cast<EHCleanupScope>(*EHStack.
find(
C)).getNormalBlock())
1174 assert(
C.strictlyEncloses(I));
1176 if (S.getNormalBlock())
return true;
1177 I = S.getEnclosingNormalCleanup();
1192 assert(cleanup.strictlyEncloses(i));
1217 llvm::Instruction *dominatingIP) {
1223 bool isActivatedInConditional =
1226 bool needFlag =
false;
1231 if (
Scope.isNormalCleanup() &&
1233 Scope.setTestFlagInNormalCleanup();
1238 if (
Scope.isEHCleanup() &&
1240 Scope.setTestFlagInEHCleanup();
1245 if (!needFlag)
return;
1250 "cleanup.isactive");
1251 Scope.setActiveFlag(var);
1253 assert(dominatingIP &&
"no existing variable and no dominating IP!");
1273 llvm::Instruction *dominatingIP) {
1274 assert(
C != EHStack.stable_end() &&
"activating bottom of stack?");
1276 assert(!
Scope.isActive() &&
"double activation");
1280 Scope.setActive(
true);
1285 llvm::Instruction *dominatingIP) {
1286 assert(
C != EHStack.stable_end() &&
"deactivating bottom of stack?");
1288 assert(
Scope.isActive() &&
"double deactivation");
1292 if (
C == EHStack.stable_begin() &&
1293 CurrentCleanupScopeDepth.strictlyEncloses(
C)) {
1296 if (!
Scope.isNormalCleanup() && getLangOpts().EHAsynch) {
1301 CGBuilderTy::InsertPoint SavedIP = Builder.saveAndClearIP();
1303 Builder.restoreIP(SavedIP);
1311 Scope.setActive(
false);
1315 if (!NormalCleanupDest.isValid())
1317 CreateDefaultAlignTempAlloca(Builder.getInt32Ty(),
"cleanup.dest.slot");
1318 return NormalCleanupDest;
1332 llvm::FunctionCallee &SehCppScope) {
1334 assert(CGF.
Builder.GetInsertBlock() && InvokeDest);
1340 CGF.
Builder.CreateInvoke(SehCppScope, Cont, InvokeDest, std::nullopt,
1347 assert(getLangOpts().EHAsynch);
1348 llvm::FunctionType *FTy =
1349 llvm::FunctionType::get(CGM.VoidTy,
false);
1350 llvm::FunctionCallee SehCppScope =
1351 CGM.CreateRuntimeFunction(FTy,
"llvm.seh.scope.begin");
1358 assert(getLangOpts().EHAsynch);
1359 llvm::FunctionType *FTy =
1360 llvm::FunctionType::get(CGM.VoidTy,
false);
1361 llvm::FunctionCallee SehCppScope =
1362 CGM.CreateRuntimeFunction(FTy,
"llvm.seh.scope.end");
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.try.begin");
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.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)
@ C
Languages that the frontend can parse and compile.
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