Go to the documentation of this file.
13 #ifndef LLVM_CLANG_LIB_CODEGEN_CGCLEANUP_H
14 #define LLVM_CLANG_LIB_CODEGEN_CGCLEANUP_H
19 #include "llvm/ADT/SmallPtrSet.h"
20 #include "llvm/ADT/SmallVector.h"
32 class CodeGenFunction;
43 llvm::BasicBlock *CachedLandingPad;
44 llvm::BasicBlock *CachedEHDispatchBlock;
48 class CommonBitFields {
52 enum { NumCommonBits = 3 };
59 unsigned NumHandlers : 32 - NumCommonBits;
67 unsigned IsNormalCleanup : 1;
70 unsigned IsEHCleanup : 1;
73 unsigned IsActive : 1;
76 unsigned IsLifetimeMarker : 1;
79 unsigned TestFlagInNormalCleanup : 1;
82 unsigned TestFlagInEHCleanup : 1;
86 unsigned CleanupSize : 12;
93 unsigned NumFilters : 32 - NumCommonBits;
107 : CachedLandingPad(nullptr), CachedEHDispatchBlock(nullptr),
108 EnclosingEHScope(enclosingEHScope) {
115 return CachedLandingPad;
119 CachedLandingPad = block;
123 return CachedEHDispatchBlock;
127 CachedEHDispatchBlock = block;
132 return !block->use_empty();
137 return EnclosingEHScope;
168 return reinterpret_cast<Handler*
>(
this+1);
171 const Handler *getHandlers()
const {
172 return reinterpret_cast<const Handler*
>(
this+1);
184 assert(
CatchBits.NumHandlers == numHandlers &&
"NumHandlers overflow?");
209 return getHandlers()[I];
240 llvm::BasicBlock *NormalBlock;
258 mutable struct ExtInfo *ExtInfo;
265 struct ExtInfo &getExtInfo() {
266 if (!ExtInfo) ExtInfo =
new struct ExtInfo();
270 const struct ExtInfo &getExtInfo()
const {
271 if (!ExtInfo) ExtInfo =
new struct ExtInfo();
291 EnclosingNormal(enclosingNormal), NormalBlock(nullptr),
292 ActiveFlag(
Address::invalid()), ExtInfo(nullptr),
293 FixupDepth(fixupDepth) {
302 assert(
CleanupBits.CleanupSize == cleanupSize &&
"cleanup size overflow");
348 return EnclosingNormal;
359 bool hasBranches()
const {
return ExtInfo && !ExtInfo->Branches.empty(); }
373 llvm::BasicBlock *Block) {
374 struct ExtInfo &ExtInfo = getExtInfo();
375 if (ExtInfo.Branches.insert(
Block).second)
376 ExtInfo.BranchAfters.push_back(std::make_pair(
Block, Index));
381 return ExtInfo ? ExtInfo->BranchAfters.size() : 0;
386 return ExtInfo->BranchAfters[I].first;
391 return ExtInfo->BranchAfters[I].second;
410 return getExtInfo().Branches.insert(
Block).second;
415 if (!ExtInfo)
return false;
416 return (ExtInfo->BranchAfters.size() != ExtInfo->Branches.size());
430 "EHCleanupScope expected alignment");
441 llvm::Value **getFilters() {
442 return reinterpret_cast<llvm::Value**
>(
this+1);
445 llvm::Value *
const *getFilters()
const {
446 return reinterpret_cast<llvm::Value*
const *
>(
this+1);
453 assert(
FilterBits.NumFilters == numFilters &&
"NumFilters overflow");
457 return sizeof(
EHFilterScope) + numFilters *
sizeof(llvm::Value*);
464 getFilters()[i] = filterValue;
469 return getFilters()[i];
495 explicit iterator(
char *Ptr) : Ptr(Ptr) {}
501 return reinterpret_cast<EHScope*
>(Ptr);
560 assert(!
empty() &&
"popping exception stack when not empty");
568 assert(!
empty() &&
"popping exception stack when not empty");
576 assert(sp.
isValid() &&
"finding invalid savepoint");
577 assert(sp.Size <=
stable_begin().Size &&
"finding savepoint after pop");
578 return iterator(EndOfBuffer - sp.Size);
583 assert(StartOfData <= ir.Ptr && ir.Ptr <= EndOfBuffer);
bool isWasmPersonality() const
static const EHPersonality GNU_C_SJLJ
bool isOne() const
isOne - Test whether the quantity equals one.
YAML serialization mapping.
static const EHPersonality NeXT_ObjC
static size_t getSizeForCleanupSize(size_t Size)
Gets the size required for a lazy cleanup scope with the given cleanup-data requirements.
bool isMSVCXXPersonality() const
static const EHPersonality GNU_C
static const EHPersonality GNUstep_ObjC
static const EHPersonality GNU_CPlusPlus_SEH
CharUnits getAlignment() const
Return the alignment of this pointer.
EHCleanupScope(bool isNormal, bool isEH, unsigned cleanupSize, unsigned fixupDepth, EHScopeStack::stable_iterator enclosingNormal, EHScopeStack::stable_iterator enclosingEH)
void setCatchAllHandler(unsigned I, llvm::BasicBlock *Block)
llvm::BasicBlock * getCachedLandingPad() const
bool addBranchThrough(llvm::BasicBlock *Block)
Add a branch-through to this cleanup scope.
EHFilterScope(unsigned numFilters)
A protected scope for zero-cost EH handling.
bool encloses(iterator other) const
const Handler & getHandler(unsigned I) const
A cleanup scope which generates the cleanup blocks lazily.
static const EHPersonality GNU_Wasm_CPlusPlus
static const EHPersonality GNU_ObjC_SEH
bool hasEHBranches() const
llvm::BasicBlock * getNormalBlock() const
const char * CatchallRethrowFn
static bool classof(const EHScope *Scope)
const char * PersonalityFn
static const EHPersonality & get(CodeGenModule &CGM, const FunctionDecl *FD)
static const EHPersonality GNU_C_SEH
llvm::BasicBlock * Block
The catch handler for this type.
The base class of the type hierarchy.
void setCachedLandingPad(llvm::BasicBlock *block)
bool usesFuncletPads() const
Does this personality use landingpads or the family of pad instructions designed to form funclets?
static bool classof(const EHScope *scope)
void * getCleanupBuffer()
unsigned getNumHandlers() const
A scope which attempts to handle some, possibly all, types of exceptions.
bool shouldTestFlagInNormalCleanup() const
unsigned getNumBranchAfters() const
Return the number of unique branch-afters on this scope.
Information for lazily generating a cleanup.
unsigned getFixupDepth() const
bool hasActiveFlag() const
llvm::ConstantInt * getBranchAfterIndex(unsigned I) const
void setActiveFlag(Address Var)
Scope - A scope is a transient data structure that is used while parsing the program.
CatchTypeInfo Type
A type info value, or null (C++ null, not an LLVM null pointer) for a catch-all.
stable_iterator stabilize(iterator it) const
Translates an iterator into a stable_iterator.
A stack of scopes which respond to exceptions, including cleanups and catch blocks.
An exceptions scope which calls std::terminate if any exception reaches it.
static const EHPersonality GNU_ObjCXX
size_t getAllocatedSize() const
EHScope * operator->() const
FilterBitFields FilterBits
void setHandler(unsigned I, CatchTypeInfo Type, llvm::BasicBlock *Block)
void setCachedEHDispatchBlock(llvm::BasicBlock *block)
EHScopeStack::stable_iterator getEnclosingEHScope() const
bool empty() const
Determines whether the exception-scopes stack is empty.
void setNormalBlock(llvm::BasicBlock *BB)
bool operator!=(iterator other) const
void setTestFlagInNormalCleanup()
void clearHandlerBlocks()
const typedef Handler * iterator
iterator end() const
Returns an iterator pointing to the outermost EH scope.
static Decl::Kind getKind(const Decl *D)
static const EHPersonality GNU_CPlusPlus
EHScope(Kind kind, EHScopeStack::stable_iterator enclosingEHScope)
void setHandler(unsigned I, llvm::Constant *Type, llvm::BasicBlock *Block)
bool isLifetimeMarker() const
CommonBitFields CommonBits
EHScopeStack::Cleanup * getCleanup()
CleanupBitFields CleanupBits
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
bool strictlyEncloses(iterator other) const
size_t getCleanupSize() const
EHCatchScope(unsigned numHandlers, EHScopeStack::stable_iterator enclosingEHScope)
This class organizes the cross-function state that is used while generating LLVM code.
bool hasBranches() const
True if this cleanup scope has any branch-afters or branch-throughs.
static const EHPersonality MSVC_except_handler
EHScopeStack::stable_iterator getEnclosingNormalCleanup() const
llvm::BasicBlock * getCachedEHDispatchBlock() const
static const EHPersonality MSVC_C_specific_handler
An exceptions scope which filters exceptions thrown through it.
bool operator==(iterator other) const
bool hasBranchThroughs() const
Determines if this cleanup scope has any branch throughs.
void popCatch()
Pops a catch scope off the stack. This is private to CGException.cpp.
The exceptions personality for a function.
EHTerminateScope(EHScopeStack::stable_iterator enclosingEHScope)
The MS C++ ABI needs a pointer to RTTI data plus some flags to describe the type of a catch handler,...
A non-stable pointer into the scope stack.
bool shouldTestFlagInEHCleanup() const
void addBranchAfter(llvm::ConstantInt *Index, llvm::BasicBlock *Block)
Add a branch-after to this cleanup scope.
static size_t getSizeForNumHandlers(unsigned N)
static const EHPersonality MSVC_CxxFrameHandler3
stable_iterator stable_begin() const
Create a stable reference to the top of the EH stack.
unsigned getNumFilters() const
bool isMSVCPersonality() const
void setFilter(unsigned i, llvm::Value *filterValue)
static bool classof(const EHScope *scope)
static bool classof(const EHScope *Scope)
void setTestFlagInEHCleanup()
iterator begin() const
Returns an iterator pointing to the innermost EH scope.
EHScope & operator*() const
static const EHPersonality XL_CPlusPlus
llvm::Value * getFilter(unsigned i) const
Address getActiveFlag() const
static size_t getSizeForNumFilters(unsigned numFilters)
Represents a function declaration or definition.
void popTerminate()
Pops a terminate handler off the stack.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
iterator find(stable_iterator save) const
Turn a stable reference to a scope depth into a unstable pointer to the EH stack.
static const EHPersonality GNU_CPlusPlus_SJLJ
A saved depth on the scope stack.
llvm::BasicBlock * getBranchAfterBlock(unsigned I) const
static const EHPersonality GNU_ObjC_SJLJ
static const EHPersonality GNU_ObjC
bool isNormalCleanup() const