15#ifndef LLVM_CLANG_LIB_CODEGEN_EHSCOPESTACK_H
16#define LLVM_CLANG_LIB_CODEGEN_EHSCOPESTACK_H
19#include "llvm/ADT/STLExtras.h"
20#include "llvm/ADT/SmallVector.h"
21#include "llvm/IR/BasicBlock.h"
22#include "llvm/IR/Instructions.h"
23#include "llvm/IR/Value.h"
67template <
class T,
bool mightBeInstruction =
68 std::is_base_of<llvm::Value, T>::value &&
69 !std::is_base_of<llvm::Constant, T>::value &&
70 !std::is_base_of<llvm::BasicBlock, T>::value>
127 return A.Size == B.Size;
130 return A.Size != B.Size;
143 virtual void anchor();
159 F_IsNormalCleanupKind = 0x2,
160 F_IsEHCleanupKind = 0x4,
161 F_HasExitSwitch = 0x8,
196 template <
class T,
class... As>
198 typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple;
201 template <std::size_t... Is>
209 restore(CGF, std::index_sequence_for<As...>()).Emit(CGF, flags);
236 stable_iterator InnermostNormalCleanup;
239 stable_iterator InnermostEHScope;
263 char *allocate(
size_t Size);
264 void deallocate(
size_t Size);
270 : StartOfBuffer(nullptr), EndOfBuffer(nullptr), StartOfData(nullptr),
278 "Cleanup's alignment is too large.");
279 void *Buffer = pushCleanup(Kind,
sizeof(T));
280 Cleanup *Obj =
new (Buffer) T(A...);
285 template <
class T,
class... As>
288 "Cleanup's alignment is too large.");
289 void *Buffer = pushCleanup(Kind,
sizeof(T));
290 Cleanup *Obj =
new (Buffer) T(std::move(A));
307 template <
class T,
class... As>
310 "Cleanup's alignment is too large.");
311 void *Buffer = pushCleanup(Kind,
sizeof(T) + T::getExtraSize(N));
312 return new (Buffer) T(N, A...);
316 void *Buffer = pushCleanup(Kind, Size);
317 std::memcpy(Buffer,
Cleanup, Size);
350 bool empty()
const {
return StartOfData == EndOfBuffer; }
356 return InnermostNormalCleanup !=
stable_end();
362 return InnermostNormalCleanup;
367 return InnermostEHScope;
376 iterator
begin()
const;
379 iterator
end()
const;
394 stable_iterator
stabilize(iterator it)
const;
398 iterator
find(stable_iterator save)
const;
404 return BranchFixups.back();
410 return BranchFixups[I];
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
A scope which attempts to handle some, possibly all, types of exceptions.
An exceptions scope which filters exceptions thrown through it.
bool isEHCleanupKind() const
isEHCleanupKind - true if the cleanup was pushed as an EH cleanup.
bool hasExitSwitch() const
bool isForNormalCleanup() const
bool isNormalCleanupKind() const
void setIsNormalCleanupKind()
bool isForEHCleanup() const
isForEH - true if the current emission is for an EH cleanup.
void setIsEHCleanupKind()
Information for lazily generating a cleanup.
virtual void Emit(CodeGenFunction &CGF, Flags flags)=0
Emit the cleanup.
Cleanup(const Cleanup &)=default
virtual bool isRedundantBeforeReturn()
ConditionalCleanup stores the saved form of its parameters, then restores them and performs the clean...
ConditionalCleanup(SavedTuple Tuple)
ConditionalCleanup(typename DominatingValue< As >::saved_type... A)
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.
static stable_iterator invalid()
friend bool operator==(stable_iterator A, stable_iterator B)
friend bool operator!=(stable_iterator A, stable_iterator B)
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.
void setCGF(CodeGenFunction *inCGF)
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
void pushCopyOfCleanup(CleanupKind Kind, const void *Cleanup, size_t Size)
bool containsOnlyLifetimeMarkers(stable_iterator Old) const
bool empty() const
Determines whether the exception-scopes stack is empty.
void pushCleanup(CleanupKind Kind, As... A)
Push a lazily-created cleanup on the stack.
T * pushCleanupWithExtra(CleanupKind Kind, size_t N, As... A)
Push a cleanup with non-constant storage requirements on the stack.
iterator end() const
Returns an iterator pointing to the outermost EH scope.
void popFilter()
Pops an exceptions filter off the stack.
iterator begin() const
Returns an iterator pointing to the innermost EH scope.
BranchFixup & addBranchFixup()
Add a branch fixup to the current cleanup scope.
void popCatch()
Pops a catch scope off the stack. This is private to CGException.cpp.
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 popTerminate()
Pops a terminate handler off the stack.
void pushTerminate()
Push a terminate handler on the stack.
void pushCleanupTuple(CleanupKind Kind, std::tuple< As... > A)
Push a lazily-created cleanup on the stack. Tuple version.
@ 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...
__PTRDIFF_TYPE__ ptrdiff_t
A signed integer type that is the result of subtracting two pointers.
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.
A metaprogramming class for ensuring that a value will dominate an arbitrary position in a function.
static bool needsSaving(type value)
static type restore(CodeGenFunction &CGF, saved_type value)
static saved_type save(CodeGenFunction &CGF, type value)