14 #ifndef LLVM_CLANG_LIB_CODEGEN_CGCLEANUP_H
15 #define LLVM_CLANG_LIB_CODEGEN_CGCLEANUP_H
18 #include "llvm/ADT/SmallPtrSet.h"
19 #include "llvm/ADT/SmallVector.h"
33 llvm::BasicBlock *CachedLandingPad;
34 llvm::BasicBlock *CachedEHDispatchBlock;
38 class CommonBitFields {
42 enum { NumCommonBits = 2 };
47 unsigned : NumCommonBits;
49 unsigned NumHandlers : 32 - NumCommonBits;
54 unsigned : NumCommonBits;
57 unsigned IsNormalCleanup : 1;
60 unsigned IsEHCleanup : 1;
63 unsigned IsActive : 1;
66 unsigned IsLifetimeMarker : 1;
69 unsigned TestFlagInNormalCleanup : 1;
72 unsigned TestFlagInEHCleanup : 1;
76 unsigned CleanupSize : 12;
81 unsigned FixupDepth : 32 - 18 - NumCommonBits;
86 unsigned : NumCommonBits;
88 unsigned NumFilters : 32 - NumCommonBits;
102 : CachedLandingPad(nullptr), CachedEHDispatchBlock(nullptr),
103 EnclosingEHScope(enclosingEHScope) {
110 return CachedLandingPad;
114 CachedLandingPad = block;
118 return CachedEHDispatchBlock;
122 CachedEHDispatchBlock = block;
127 return !block->use_empty();
132 return EnclosingEHScope;
163 return reinterpret_cast<Handler*
>(
this+1);
166 const Handler *getHandlers()
const {
167 return reinterpret_cast<const Handler*
>(
this+1);
191 getHandlers()[I].
Type = Type;
192 getHandlers()[I].
Block = Block;
197 return getHandlers()[I];
228 llvm::BasicBlock *NormalBlock;
232 llvm::AllocaInst *ActiveFlag;
240 llvm::SmallPtrSet<llvm::BasicBlock*, 4> Branches;
246 mutable struct ExtInfo *ExtInfo;
248 struct ExtInfo &getExtInfo() {
249 if (!ExtInfo) ExtInfo =
new struct ExtInfo();
253 const struct ExtInfo &getExtInfo()
const {
254 if (!ExtInfo) ExtInfo =
new struct ExtInfo();
270 unsigned cleanupSize,
unsigned fixupDepth,
274 NormalBlock(nullptr), ActiveFlag(nullptr), ExtInfo(nullptr) {
284 assert(
CleanupBits.CleanupSize == cleanupSize &&
"cleanup size overflow");
324 return EnclosingNormal;
335 bool hasBranches()
const {
return ExtInfo && !ExtInfo->Branches.empty(); }
349 llvm::BasicBlock *Block) {
350 struct ExtInfo &ExtInfo = getExtInfo();
351 if (ExtInfo.Branches.insert(Block).second)
352 ExtInfo.BranchAfters.push_back(std::make_pair(Block, Index));
357 return ExtInfo ? ExtInfo->BranchAfters.size() : 0;
362 return ExtInfo->BranchAfters[I].first;
367 return ExtInfo->BranchAfters[I].second;
386 return getExtInfo().Branches.insert(Block).second;
391 if (!ExtInfo)
return false;
392 return (ExtInfo->BranchAfters.size() != ExtInfo->Branches.size());
414 return reinterpret_cast<llvm::Value*
const *
>(
this+1);
431 getFilters()[i] = filterValue;
436 return getFilters()[i];
462 explicit iterator(
char *Ptr) : Ptr(Ptr) {}
468 return reinterpret_cast<EHScope*
>(Ptr);
478 static_cast<const EHCatchScope*>(
get())->getNumHandlers());
483 static_cast<const EHFilterScope*>(
get())->getNumFilters());
527 assert(!
empty() &&
"popping exception stack when not empty");
535 assert(!
empty() &&
"popping exception stack when not empty");
543 assert(sp.
isValid() &&
"finding invalid savepoint");
544 assert(sp.Size <=
stable_begin().Size &&
"finding savepoint after pop");
545 return iterator(EndOfBuffer - sp.Size);
550 assert(StartOfData <= ir.Ptr && ir.Ptr <= EndOfBuffer);
iterator end() const
Returns an iterator pointing to the outermost EH scope.
void setCatchAllHandler(unsigned I, llvm::BasicBlock *Block)
llvm::Value * getFilter(unsigned i) const
void clearHandlerBlocks()
EHCatchScope(unsigned numHandlers, EHScopeStack::stable_iterator enclosingEHScope)
EHScopeStack::stable_iterator getEnclosingNormalCleanup() const
A protected scope for zero-cost EH handling.
llvm::BasicBlock * getCachedEHDispatchBlock() const
bool addBranchThrough(llvm::BasicBlock *Block)
static size_t getSizeForCleanupSize(size_t Size)
stable_iterator stabilize(iterator it) const
Translates an iterator into a stable_iterator.
EHScope * operator->() const
bool hasEHBranches() const
llvm::AllocaInst * getActiveFlag() const
void setFilter(unsigned i, llvm::Value *filterValue)
void setCachedLandingPad(llvm::BasicBlock *block)
const Handler & getHandler(unsigned I) const
bool isLifetimeMarker() const
iterator begin() const
Returns an iterator pointing to the innermost EH scope.
void setNormalBlock(llvm::BasicBlock *BB)
bool strictlyEncloses(iterator other) const
static bool classof(const EHScope *scope)
size_t getCleanupSize() const
EHScope(Kind kind, EHScopeStack::stable_iterator enclosingEHScope)
static size_t getSizeForNumHandlers(unsigned N)
EHFilterScope(unsigned numFilters)
iterator find(stable_iterator save) const
static bool classof(const EHScope *Scope)
bool encloses(iterator other) const
EHScopeStack::Cleanup * getCleanup()
bool empty() const
Determines whether the exception-scopes stack is empty.
bool operator!=(iterator other) const
void * getCleanupBuffer()
static bool classof(const EHScope *Scope)
llvm::BasicBlock * getBranchAfterBlock(unsigned I) const
llvm::BasicBlock * Block
The catch handler for this type.
EHScopeStack::stable_iterator getEnclosingEHScope() const
bool hasBranchThroughs() const
Determines if this cleanup scope has any branch throughs.
stable_iterator stable_begin() const
llvm::BasicBlock * getCachedLandingPad() const
size_t getAllocatedSize() const
bool isNormalCleanup() const
bool shouldTestFlagInNormalCleanup() const
CommonBitFields CommonBits
void setTestFlagInNormalCleanup()
void popCatch()
Pops a catch scope off the stack. This is private to CGException.cpp.
CleanupBitFields CleanupBits
llvm::BasicBlock * getNormalBlock() const
void setCachedEHDispatchBlock(llvm::BasicBlock *block)
unsigned getNumHandlers() const
static size_t getSizeForNumFilters(unsigned numFilters)
EHScope & operator*() const
EHTerminateScope(EHScopeStack::stable_iterator enclosingEHScope)
bool hasBranches() const
True if this cleanup scope has any branch-afters or branch-throughs.
void addBranchAfter(llvm::ConstantInt *Index, llvm::BasicBlock *Block)
unsigned getFixupDepth() const
void setActiveFlag(llvm::AllocaInst *Var)
bool operator==(iterator other) const
unsigned getNumBranchAfters() const
Return the number of unique branch-afters on this scope.
void popTerminate()
Pops a terminate handler off the stack.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
A cleanup scope which generates the cleanup blocks lazily.
llvm::ConstantInt * getBranchAfterIndex(unsigned I) const
unsigned getNumFilters() const
EHCleanupScope(bool isNormal, bool isEH, bool isActive, unsigned cleanupSize, unsigned fixupDepth, EHScopeStack::stable_iterator enclosingNormal, EHScopeStack::stable_iterator enclosingEH)
static Decl::Kind getKind(const Decl *D)
A non-stable pointer into the scope stack.
void setTestFlagInEHCleanup()
void setHandler(unsigned I, llvm::Constant *Type, llvm::BasicBlock *Block)
FilterBitFields FilterBits
static bool classof(const EHScope *scope)
bool shouldTestFlagInEHCleanup() const