45#define DEBUG_TYPE "win-eh-prepare"
49 switch (Personality) {
103class WinEHPrepareImpl {
105 explicit WinEHPrepareImpl(
const CodeGenOptions &Opts) : Opts(Opts) {}
109 void insertPHIStores(PHINode *OriginalPHI, AllocaInst *SpillSlot);
111 insertPHIStore(BasicBlock *PredBlock,
Value *PredVal, AllocaInst *SpillSlot,
112 SmallVectorImpl<std::pair<BasicBlock *, Value *>> &Worklist);
113 AllocaInst *insertPHILoads(PHINode *PN,
Function &
F);
114 void replaceUseWithLoad(
Value *
V, Use &U, AllocaInst *&SpillSlot,
115 DenseMap<BasicBlock *, Value *> &Loads,
Function &
F);
119 bool demotePHIsOnFunclets(
Function &
F,
bool DemoteCatchSwitchPHIOnly);
121 bool removeMalformedCatchswitch(
Value *FuncletToken);
122 bool removeImplausibleInstructions(
Function &
F);
123 bool cleanupPreparedFunclets(
Function &
F);
124 void verifyPreparedFunclets(
Function &
F);
126 const CodeGenOptions &Opts;
129 bool DemoteCatchSwitchPHIOnly =
false;
134 const DataLayout *DL =
nullptr;
135 DenseMap<BasicBlock *, ColorVector> BlockColors;
136 MapVector<BasicBlock *, std::vector<BasicBlock *>> FuncletBlocks;
143 WinEHPrepare() : FunctionPass(ID) {}
145 StringRef getPassName()
const override {
146 return "Windows exception handling preparation";
162char WinEHPrepare::ID = 0;
168bool WinEHPrepareImpl::runOnFunction(
Function &Fn) {
185 return prepareExplicitEH(Fn);
198 int TryHigh,
int CatchHigh,
208 "Malformed CatchPadInst not caught by win-eh-prepare");
227 for (
const User *U : CleanupPad->
users())
229 return CRI->getUnwindDest();
242 auto &BBColors = BlockColors[&BB];
243 assert(BBColors.size() == 1 &&
"multi-color BB not removed by preparation");
251 FuncletUnwindDest =
nullptr;
253 FuncletUnwindDest = CatchPad->getCatchSwitch()->getUnwindDest();
261 if (FuncletUnwindDest == InvokeUnwindDest) {
264 BaseState = BaseStateI->second;
267 if (BaseState != -1) {
290 struct WorkItem *WI =
new WorkItem(BB, State);
293 while (!WorkList.
empty()) {
296 int State = WI->State;
299 if (!Inserted && StateIt->second <= State)
306 StateIt->second = State;
330 WI =
new WorkItem(SuccBB, State);
352 struct WorkItem *WI =
new WorkItem(BB, State);
355 while (!WorkList.
empty()) {
358 int State = WI->State;
373 "Malformed CatchPadInst not caught by win-eh-prepare");
377 if (!
Filter || !
Filter->getName().starts_with(
"__IsLocalUnwind"))
397 WI =
new WorkItem(SuccBB, State);
411 if (CatchSwitch->getParentPad() != ParentPad)
417 if (CleanupPad->getParentPad() != ParentPad)
419 return CleanupPad->getParent();
433 "shouldn't revist catch funclets!");
436 for (
const BasicBlock *CatchPadBB : CatchSwitch->handlers()) {
444 CatchSwitch->getParentPad())))
450 int TryHigh = CatchLow - 1;
456 bool IsPreOrder =
Mod->getTargetTriple().isArch64Bit();
459 unsigned TBMEIdx = FuncInfo.
TryBlockMap.size() - 1;
461 for (
const auto *CatchPad : Handlers) {
464 for (
const User *U : CatchPad->
users()) {
467 BasicBlock *UnwindDest = InnerCatchSwitch->getUnwindDest();
468 if (!UnwindDest || UnwindDest == CatchSwitch->getUnwindDest())
476 if (!UnwindDest || UnwindDest == CatchSwitch->getUnwindDest())
484 FuncInfo.
TryBlockMap[TBMEIdx].CatchHigh = CatchHigh;
498 auto [It, Inserted] = FuncInfo.
EHPadStateMap.try_emplace(CleanupPad);
503 It->second = CleanupState;
504 LLVM_DEBUG(
dbgs() <<
"Assigning state #" << CleanupState <<
" to BB "
508 CleanupPad->getParentPad()))) {
513 for (
const User *U : CleanupPad->
users()) {
515 if (UserI->isEHPad())
517 "contain exceptional actions");
526 Entry.IsFinally =
false;
528 Entry.Handler = Handler;
537 Entry.IsFinally =
true;
538 Entry.Filter =
nullptr;
539 Entry.Handler = Handler;
555 "shouldn't revist catch funclets!");
559 assert(CatchSwitch->getNumHandlers() == 1 &&
560 "SEH doesn't have multiple handlers per __try");
561 const auto *CatchPad =
565 "Malformed CatchPadInst not caught by win-eh-prepare");
570 "unexpected filter value");
577 << CatchPadBB->
getName() <<
'\n');
580 CatchSwitch->getParentPad())))
586 for (
const User *U : CatchPad->
users()) {
589 BasicBlock *UnwindDest = InnerCatchSwitch->getUnwindDest();
590 if (!UnwindDest || UnwindDest == CatchSwitch->getUnwindDest())
598 if (!UnwindDest || UnwindDest == CatchSwitch->getUnwindDest())
607 auto [It, Inserted] = FuncInfo.
EHPadStateMap.try_emplace(CleanupPad);
612 It->second = CleanupState;
613 LLVM_DEBUG(
dbgs() <<
"Assigning state #" << CleanupState <<
" to BB "
620 for (
const User *U : CleanupPad->
users()) {
622 if (UserI->isEHPad())
624 "contain exceptional actions");
632 CatchSwitch->unwindsToCaller();
650 const Instruction *FirstNonPHI = &*BB.getFirstNonPHIIt();
674 const Instruction *FirstNonPHI = &*BB.getFirstNonPHIIt();
694 Entry.TryParentState = TryParentState;
695 Entry.Handler = Handler;
696 Entry.HandlerType = HandlerType;
697 Entry.TypeToken = TypeToken;
734 const Instruction *FirstNonPHI = &*BB.getFirstNonPHIIt();
735 const Value *ParentPad;
737 ParentPad = CPI->getParentPad();
739 ParentPad = CSI->getParentPad();
752 while (!Worklist.
empty()) {
754 int HandlerParentState;
755 std::tie(Pad, HandlerParentState) = Worklist.
pop_back_val();
776 int CatchState = -1, FollowerState = -1;
783 "Malformed CatchPadInst not caught by win-eh-prepare");
796 FollowerState = CatchState;
799 assert(CatchSwitch->getNumHandlers());
819 if (Entry.TryParentState != -1)
822 UnwindDest =
Catch->getCatchSwitch()->getUnwindDest();
825 UnwindDest =
nullptr;
830 UnwindDest = CleanupRet->getUnwindDest();
837 UserUnwindDest = Invoke->getUnwindDest();
839 UserUnwindDest = CatchSwitch->getUnwindDest();
842 int UserUnwindState =
844 if (UserUnwindState != -1)
859 const Value *UserUnwindParent;
861 UserUnwindParent = CSI->getParentPad();
868 if (UserUnwindParent ==
Cleanup)
872 UnwindDest = UserUnwindDest;
891 UnwindDestState = -1;
897 Entry.TryParentState = UnwindDestState;
904void WinEHPrepareImpl::colorFunclets(
Function &
F) {
911 FuncletBlocks[Color].push_back(&BB);
915bool WinEHPrepareImpl::demotePHIsOnFunclets(
Function &
F,
916 bool DemoteCatchSwitchPHIOnly) {
934 if (DemoteCatchSwitchPHIOnly) {
936 bool HasIncomingCatchSwitchBB =
false;
937 for (
unsigned I = 0,
E = PN->getNumIncomingValues();
I <
E; ++
I) {
939 PN->getIncomingBlock(
I)->getFirstNonPHIIt())) {
940 HasIncomingCatchSwitchBB =
true;
944 if (!IsCatchSwitchBB && !HasIncomingCatchSwitchBB)
952 insertPHIStores(PN, SpillSlot);
958 for (
auto *PN : PHINodes) {
961 PN->eraseFromParent();
967bool WinEHPrepareImpl::removeMalformedCatchswitch(
Value *FuncletToken) {
979 "catchpad with unexpected arguments", *CatchPad->
getParent()->getParent(),
993 switch (Personality) {
995 args = {nullPtr, constantZero, nullPtr};
1004 args = {constantZero};
1009 Value *NewCatchPad =
1010 Builder.CreateCatchPad(CPI->getParentPad(),
args, CPI->getName());
1019bool WinEHPrepareImpl::cloneCommonBlocks(
Function &
F) {
1025 for (
auto &Funclets : FuncletBlocks) {
1027 std::vector<BasicBlock *> &BlocksInFunclet = Funclets.second;
1028 Value *FuncletToken;
1029 if (FuncletPadBB == &
F.getEntryBlock())
1033 Changed |= removeMalformedCatchswitch(FuncletToken);
1036 std::vector<std::pair<BasicBlock *, BasicBlock *>> Orig2Clone;
1041 size_t NumColorsForBB = ColorsForBB.
size();
1042 if (NumColorsForBB == 1)
1046 dbgs() <<
" Cloning block \'" << BB->getName()
1047 <<
"\' for funclet \'" << FuncletPadBB->
getName()
1061 Orig2Clone.emplace_back(BB, CBB);
1065 if (Orig2Clone.empty())
1072 for (
auto &BBMapping : Orig2Clone) {
1076 BlocksInFunclet.push_back(NewBlock);
1078 assert(NewColors.
empty() &&
"A new block should only have one color!");
1082 dbgs() <<
" Assigned color \'" << FuncletPadBB->
getName()
1083 <<
"\' to block \'" << NewBlock->
getName()
1091 dbgs() <<
" Removed color \'" << FuncletPadBB->
getName()
1092 <<
"\' from block \'" << OldBlock->
getName()
1107 for (
auto &BBMapping : Orig2Clone) {
1111 FixupCatchrets.
clear();
1114 if (CatchRet->getCatchSwitchParentPad() == FuncletToken)
1118 CatchRet->setSuccessor(NewBlock);
1121 auto UpdatePHIOnClonedBlock = [&](
PHINode *PN,
bool IsForOldBlock) {
1125 bool EdgeTargetsFunclet;
1128 EdgeTargetsFunclet =
1129 (CRI->getCatchSwitchParentPad() == FuncletToken);
1131 ColorVector &IncomingColors = BlockColors[IncomingBlock];
1132 assert(!IncomingColors.
empty() &&
"Block not colored!");
1134 (IncomingColors.
size() == 1 ||
1136 "Cloning should leave this funclet's blocks monochromatic");
1137 EdgeTargetsFunclet = (IncomingColors.
front() == FuncletPadBB);
1139 return IsForOldBlock == EdgeTargetsFunclet;
1144 for (
auto &BBMapping : Orig2Clone) {
1148 UpdatePHIOnClonedBlock(&OldPN,
true);
1151 UpdatePHIOnClonedBlock(&NewPN,
false);
1157 for (
auto &BBMapping : Orig2Clone) {
1161 for (
PHINode &SuccPN : SuccBB->phis()) {
1164 int OldBlockIdx = SuccPN.getBasicBlockIndex(OldBlock);
1165 if (OldBlockIdx == -1)
1167 Value *
IV = SuccPN.getIncomingValue(OldBlockIdx);
1172 if (
I != VMap.
end())
1176 SuccPN.addIncoming(
IV, NewBlock);
1198 ColorVector &ColorsForUserBB = BlockColors[UserBB];
1200 if (ColorsForUserBB.
size() > 1 ||
1201 *ColorsForUserBB.
begin() != FuncletPadBB)
1207 if (UsesToRename.
empty())
1214 SSAUpdate.
Initialize(OldI->getType(), OldI->getName());
1218 while (!UsesToRename.
empty())
1226bool WinEHPrepareImpl::removeImplausibleInstructions(
Function &
F) {
1230 for (
auto &Funclet : FuncletBlocks) {
1232 std::vector<BasicBlock *> &BlocksInFunclet = Funclet.second;
1244 Value *FuncletBundleOperand =
nullptr;
1246 FuncletBundleOperand = BU->Inputs.front();
1248 if (FuncletBundleOperand == FuncletPad)
1254 if (CB->isInlineAsm() ||
1255 (CalledFn && CalledFn->isIntrinsic() && CB->doesNotThrow()))
1266 std::prev(BB->getTerminator()->getIterator());
1282 bool IsUnreachableCatchret =
false;
1284 IsUnreachableCatchret = CRI->getCatchPad() != CatchPad;
1286 bool IsUnreachableCleanupret =
false;
1288 IsUnreachableCleanupret = CRI->getCleanupPad() != CleanupPad;
1289 if (IsUnreachableRet || IsUnreachableCatchret ||
1290 IsUnreachableCleanupret) {
1308bool WinEHPrepareImpl::cleanupPreparedFunclets(
Function &
F) {
1327void WinEHPrepareImpl::verifyPreparedFunclets(
Function &
F) {
1329 size_t NumColors = BlockColors[&BB].size();
1330 assert(NumColors == 1 &&
"Expected monochromatic BB!");
1335 assert((!Opts.win_eh_prepare_demotion ||
1337 "EH Pad still has a PHI!");
1342bool WinEHPrepareImpl::prepareExplicitEH(
Function &
F) {
1353 if (Opts.win_eh_prepare_demotion)
1354 Changed |= demotePHIsOnFunclets(
F, DemoteCatchSwitchPHIOnly);
1356 if (Opts.win_eh_prepare_cleanups) {
1358 Changed |= removeImplausibleInstructions(
F);
1361 Changed |= cleanupPreparedFunclets(
F);
1384 F.getEntryBlock().begin());
1397 if (
isa<PHINode>(UsingInst) && UsingInst->getParent()->isEHPad()) {
1402 replaceUseWithLoad(PN, U, SpillSlot, Loads,
F);
1411void WinEHPrepareImpl::insertPHIStores(
PHINode *OriginalPHI,
1419 while (!Worklist.
empty()) {
1442 insertPHIStore(PredBlock, InVal, SpillSlot, Worklist);
1448void WinEHPrepareImpl::insertPHIStore(
1454 Worklist.
push_back({PredBlock, PredVal});
1462void WinEHPrepareImpl::replaceUseWithLoad(
1467 SpillSlot =
new AllocaInst(
V->getType(),
DL->getAllocaAddrSpace(),
nullptr,
1468 Twine(
V->getName(),
".wineh.spillslot"),
1469 F.getEntryBlock().begin());
1482 BasicBlock *IncomingBlock = UsingPHI->getIncomingBlock(U);
1483 if (
auto *CatchRet =
1506 CatchRet->removeFromParent();
1507 CatchRet->insertInto(IncomingBlock, IncomingBlock->
end());
1510 CatchRet->setSuccessor(NewBlock);
1515 ColorVector &ColorsForNewBlock = BlockColors[NewBlock];
1516 ColorVector &ColorsForPHIBlock = BlockColors[PHIBlock];
1517 ColorsForNewBlock = ColorsForPHIBlock;
1518 for (
BasicBlock *FuncletPad : ColorsForPHIBlock)
1519 FuncletBlocks[FuncletPad].
push_back(NewBlock);
1521 IncomingBlock = NewBlock;
1527 V->getType(), SpillSlot,
Twine(
V->getName(),
".wineh.reload"),
1534 Twine(
V->getName(),
".wineh.reload"),
1535 false, UsingInst->getIterator());
1544 "should get invoke with precomputed state");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
static bool runOnFunction(Function &F, bool PostInlining)
ManagedStatic< HTTPClientCleanup > Cleanup
Module.h This file contains the declarations for the Module class.
This file implements a map that provides insertion order iteration.
uint64_t IntrinsicInst * II
if(auto Err=PB.parsePassPipeline(MPM, Passes)) return wrap(std MPM run * Mod
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
#define DEBUG_WITH_TYPE(TYPE,...)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
static bool isMalformedCatchpad(const CatchPadInst *CPI, EHPersonality Personality)
static int addUnwindMapEntry(WinEHFuncInfo &FuncInfo, int ToState, const BasicBlock *BB)
static void calculateStateNumbersForInvokes(const Function *Fn, WinEHFuncInfo &FuncInfo)
static BasicBlock * getCleanupRetUnwindDest(const CleanupPadInst *CleanupPad)
static int addSEHFinally(WinEHFuncInfo &FuncInfo, int ParentState, const BasicBlock *Handler)
static const BasicBlock * getEHPadFromPredecessor(const BasicBlock *BB, Value *ParentPad)
static int addClrEHHandler(WinEHFuncInfo &FuncInfo, int HandlerParentState, int TryParentState, ClrHandlerType HandlerType, uint32_t TypeToken, const BasicBlock *Handler)
static void calculateCXXStateNumbers(WinEHFuncInfo &FuncInfo, const Instruction *FirstNonPHI, int ParentState)
static void addTryBlockMapEntry(WinEHFuncInfo &FuncInfo, int TryLow, int TryHigh, int CatchHigh, ArrayRef< const CatchPadInst * > Handlers)
static bool isTopLevelPadForMSVC(const Instruction *EHPad)
static int addSEHExcept(WinEHFuncInfo &FuncInfo, int ParentState, const Function *Filter, const BasicBlock *Handler)
static const uint32_t IV[8]
an instruction to allocate memory on the stack
Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
LLVM_ABI const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
const Function * getParent() const
Return the enclosing method, or null if none.
LLVM_ABI InstListType::const_iterator getFirstNonPHIIt() const
Returns an iterator to the first instruction in this block that is not a PHINode instruction.
InstListType::const_iterator const_iterator
const Instruction & front() const
LLVM_ABI void insertInto(Function *Parent, BasicBlock *InsertBefore=nullptr)
Insert unlinked basic block into a function.
InstListType::iterator iterator
Instruction iterators...
bool isEHPad() const
Return true if this basic block is an exception handling block.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
CatchSwitchInst * getCatchSwitch() const
Convenience accessors.
handler_range handlers()
iteration adapter for range-for loops.
static LLVM_ABI ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
static LLVM_ABI ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
This is an important base class in LLVM.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
const Constant * stripPointerCasts() const
unsigned arg_size() const
arg_size - Return the number of funcletpad arguments.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th funcletpad argument.
FunctionPass class - This class is used to implement most global optimizations.
const BasicBlock & getEntryBlock() const
const DataLayout & getDataLayout() const
Get the data layout of the module this function belongs to.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
bool hasPersonalityFn() const
Check whether this function has a personality function.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
Module * getParent()
Get the module that this global value is contained inside of...
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
LLVM_ABI void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
bool isTerminator() const
iterator_range< user_iterator > users()
LLVM_ABI InstListType::iterator insertInto(BasicBlock *ParentBB, InstListType::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
This is an important class for using LLVM in a threaded context.
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
An instruction for reading from memory.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
A Module instance is used to store all the information related to an LLVM module.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
LLVM_ABI void removeIncomingValueIf(function_ref< bool(unsigned)> Predicate, bool DeletePHIIfEmpty=true)
Remove all incoming values for which the predicate returns true.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PointerType * getUnqual(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Helper class for SSA formation on a set of values defined in multiple blocks.
LLVM_ABI void RewriteUseAfterInsertions(Use &U)
Rewrite a use like RewriteUse but handling in-block definitions.
LLVM_ABI void Initialize(Type *Ty, StringRef Name)
Reset this object to get ready for a new set of SSA updates with type 'Ty'.
LLVM_ABI void AddAvailableValue(BasicBlock *BB, Value *V)
Indicate that a rewritten value is available in the specified block with the specified value.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
void push_back(EltTy NewVal)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Unconditional Branch instruction.
void setSuccessor(BasicBlock *NewSucc)
A Use represents the edge between a Value definition and its users.
std::pair< const Value *, WeakTrackingVH > value_type
iterator find(const KeyT &Val)
ValueMapIteratorImpl< MapT, const Value *, false > iterator
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVMContext & getContext() const
All values hold a context through their type.
iterator_range< user_iterator > users()
iterator_range< use_iterator > uses()
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
const ParentTy * getParent() const
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI FunctionPass * createWinEHPass()
createWinEHPass - Prepares personality functions used by MSVC on Windows, in addition to the Itanium ...
LLVM_ABI bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=nullptr, DomTreeUpdater *DTU=nullptr)
If a terminator instruction is predicated on a constant value, convert it into an unconditional branc...
LLVM_ABI BasicBlock * CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap, const Twine &NameSuffix="", Function *F=nullptr, ClonedCodeInfo *CodeInfo=nullptr, bool MapAtoms=true)
Return a copy of the specified basic block, but without embedding the block into a particular functio...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI bool verifyFunction(const Function &F, raw_ostream *OS=nullptr)
Check a function for errors, useful for use when debugging a pass.
auto successors(const MachineBasicBlock *BB)
@ Load
The value being inserted comes from a load (InsertElement only).
LLVM_ABI DenseMap< BasicBlock *, ColorVector > colorEHFunclets(Function &F)
If an EH funclet personality is in use (see isFuncletEHPersonality), this will recompute which blocks...
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
LLVM_ABI bool SimplifyInstructionsInBlock(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr)
Scan the specified basic block and try to simplify any instructions in it and recursively delete dead...
LLVM_ABI void calculateWinCXXEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which describes the state number...
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch,...
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
LLVM_ABI bool removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr, bool FoldInstsToUnreachable=true)
Remove all blocks that can not be reached from the function's entry.
auto dyn_cast_or_null(const Y &Val)
void erase(Container &C, ValueType V)
Wrapper function to remove a value from a container:
auto reverse(ContainerTy &&C)
@ RF_IgnoreMissingLocals
If this flag is set, the remapper ignores missing function-local entries (Argument,...
@ RF_NoModuleLevelChanges
If this flag is set, the remapper knows that only local values within a function (such as an instruct...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ABI Instruction * removeUnwindEdge(BasicBlock *BB, DomTreeUpdater *DTU=nullptr)
Replace 'BB's terminator with one that does not have an unwind successor block.
LLVM_ABI void calculateSEHStateForAsynchEH(const BasicBlock *BB, int State, WinEHFuncInfo &FuncInfo)
LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI unsigned changeToUnreachable(Instruction *I, bool PreserveLCSSA=false, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
LLVM_ABI void calculateCXXStateForAsynchEH(const BasicBlock *BB, int State, WinEHFuncInfo &FuncInfo)
bool isFuncletEHPersonality(EHPersonality Pers)
Returns true if this is a personality function that invokes handler funclets (which must return to it...
LLVM_ABI void calculateSEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
LLVM_ABI bool MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, MemoryDependenceResults *MemDep=nullptr, bool PredecessorWithTwoSuccessors=false, DominatorTree *DT=nullptr)
Attempts to merge a block into its predecessor, if possible.
void RemapInstruction(Instruction *I, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr, const MetadataPredicate *IdentityMD=nullptr)
Convert the instruction operands from referencing the current values into those specified by VM.
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
TinyPtrVector< BasicBlock * > ColorVector
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="")
Split the edge connecting the specified blocks, and return the newly created basic block between From...
const CodeGenOptions & getCodeGenOptions(const LLVMContext &C)
LLVM_ABI void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo)
WorkItem(const BasicBlock *BB, int St)
int HandlerParentState
Outer handler enclosing this entry's handler.
Similar to CxxUnwindMapEntry, but supports SEH filters.
int ToState
If unwinding continues through this handler, transition to the handler at this state.
LLVM_ABI void addIPToStateRange(const InvokeInst *II, MCSymbol *InvokeBegin, MCSymbol *InvokeEnd)
SmallVector< SEHUnwindMapEntry, 4 > SEHUnwindMap
SmallVector< ClrEHUnwindMapEntry, 4 > ClrEHUnwindMap
DenseMap< const FuncletPadInst *, int > FuncletBaseStateMap
DenseMap< const BasicBlock *, int > BlockToStateMap
DenseMap< const InvokeInst *, int > InvokeStateMap
SmallVector< WinEHTryBlockMapEntry, 4 > TryBlockMap
DenseMap< const Instruction *, int > EHPadStateMap
DenseMap< MCSymbol *, std::pair< int, MCSymbol * > > LabelToStateMap
SmallVector< CxxUnwindMapEntry, 4 > CxxUnwindMap
int getLastStateNumber() const
GlobalVariable * TypeDescriptor
union llvm::WinEHHandlerType::@246205307012256373115155017221207221353102114334 CatchObj
The CatchObj starts out life as an LLVM alloca and is eventually turned frame index.
const AllocaInst * Alloca
SmallVector< WinEHHandlerType, 1 > HandlerArray