40 #define DEBUG_TYPE "winehprepare" 45 "Clone multicolor basic blocks but do not demote cross scopes"),
50 cl::desc(
"Do not remove implausible terminators or other similar cleanups"),
62 WinEHPrepare(
bool DemoteCatchSwitchPHIOnly =
false)
63 :
FunctionPass(ID), DemoteCatchSwitchPHIOnly(DemoteCatchSwitchPHIOnly) {}
67 bool doFinalization(
Module &M)
override;
72 return "Windows exception handling preparation";
86 void demotePHIsOnFunclets(
Function &
F,
bool DemoteCatchSwitchPHIOnly);
88 void removeImplausibleInstructions(
Function &
F);
89 void cleanupPreparedFunclets(
Function &
F);
92 bool DemoteCatchSwitchPHIOnly;
109 return new WinEHPrepare(DemoteCatchSwitchPHIOnly);
124 return prepareExplicitEH(Fn);
127 bool WinEHPrepare::doFinalization(
Module &M) {
return false; }
129 void WinEHPrepare::getAnalysisUsage(
AnalysisUsage &AU)
const {}
141 int TryHigh,
int CatchHigh,
150 Constant *TypeInfo = cast<Constant>(CPI->getArgOperand(0));
155 HT.
Adjectives = cast<ConstantInt>(CPI->getArgOperand(1))->getZExtValue();
158 dyn_cast<AllocaInst>(CPI->getArgOperand(2)->stripPointerCasts()))
168 for (
const User *U : CleanupPad->
users())
169 if (
const auto *CRI = dyn_cast<CleanupReturnInst>(U))
170 return CRI->getUnwindDest();
183 auto &BBColors = BlockColors[&BB];
184 assert(BBColors.size() == 1 &&
"multi-color BB not removed by preparation");
192 FuncletUnwindDest =
nullptr;
193 else if (
auto *CatchPad = dyn_cast<CatchPadInst>(FuncletPad))
194 FuncletUnwindDest = CatchPad->getCatchSwitch()->getUnwindDest();
195 else if (
auto *CleanupPad = dyn_cast<CleanupPadInst>(FuncletPad))
200 BasicBlock *InvokeUnwindDest = II->getUnwindDest();
202 if (FuncletUnwindDest == InvokeUnwindDest) {
205 BaseState = BaseStateI->second;
208 if (BaseState != -1) {
223 if (isa<InvokeInst>(TI))
225 if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(TI)) {
226 if (CatchSwitch->getParentPad() != ParentPad)
231 auto *CleanupPad = cast<CleanupReturnInst>(TI)->getCleanupPad();
232 if (CleanupPad->getParentPad() != ParentPad)
234 return CleanupPad->getParent();
243 if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(FirstNonPHI)) {
245 "shouldn't revist catch funclets!");
248 for (
const BasicBlock *CatchPadBB : CatchSwitch->handlers()) {
249 auto *CatchPad = cast<CatchPadInst>(CatchPadBB->getFirstNonPHI());
256 CatchSwitch->getParentPad())))
262 int TryHigh = CatchLow - 1;
263 for (
const auto *CatchPad : Handlers) {
265 for (
const User *U : CatchPad->
users()) {
266 const auto *UserI = cast<Instruction>(U);
267 if (
auto *InnerCatchSwitch = dyn_cast<CatchSwitchInst>(UserI)) {
268 BasicBlock *UnwindDest = InnerCatchSwitch->getUnwindDest();
269 if (!UnwindDest || UnwindDest == CatchSwitch->getUnwindDest())
272 if (
auto *InnerCleanupPad = dyn_cast<CleanupPadInst>(UserI)) {
277 if (!UnwindDest || UnwindDest == CatchSwitch->getUnwindDest())
290 auto *CleanupPad = cast<CleanupPadInst>(FirstNonPHI);
299 LLVM_DEBUG(
dbgs() <<
"Assigning state #" << CleanupState <<
" to BB " 303 CleanupPad->getParentPad()))) {
308 for (
const User *U : CleanupPad->
users()) {
309 const auto *UserI = cast<Instruction>(U);
310 if (UserI->isEHPad())
312 "contain exceptional actions");
345 if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(FirstNonPHI)) {
347 "shouldn't revist catch funclets!");
351 assert(CatchSwitch->getNumHandlers() == 1 &&
352 "SEH doesn't have multiple handlers per __try");
353 const auto *CatchPad =
354 cast<CatchPadInst>((*CatchSwitch->handler_begin())->getFirstNonPHI());
357 cast<Constant>(CatchPad->getArgOperand(0)->stripPointerCasts());
360 "unexpected filter value");
361 int TryState =
addSEHExcept(FuncInfo, ParentState, Filter, CatchPadBB);
366 << CatchPadBB->getName() <<
'\n');
369 CatchSwitch->getParentPad())))
375 for (
const User *U : CatchPad->
users()) {
376 const auto *UserI = cast<Instruction>(U);
377 if (
auto *InnerCatchSwitch = dyn_cast<CatchSwitchInst>(UserI)) {
378 BasicBlock *UnwindDest = InnerCatchSwitch->getUnwindDest();
379 if (!UnwindDest || UnwindDest == CatchSwitch->getUnwindDest())
382 if (
auto *InnerCleanupPad = dyn_cast<CleanupPadInst>(UserI)) {
387 if (!UnwindDest || UnwindDest == CatchSwitch->getUnwindDest())
392 auto *CleanupPad = cast<CleanupPadInst>(FirstNonPHI);
401 LLVM_DEBUG(
dbgs() <<
"Assigning state #" << CleanupState <<
" to BB " 408 for (
const User *U : CleanupPad->
users()) {
409 const auto *UserI = cast<Instruction>(U);
410 if (UserI->isEHPad())
412 "contain exceptional actions");
418 if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(EHPad))
419 return isa<ConstantTokenNone>(CatchSwitch->getParentPad()) &&
420 CatchSwitch->unwindsToCaller();
421 if (
auto *CleanupPad = dyn_cast<CleanupPadInst>(EHPad))
422 return isa<ConstantTokenNone>(CleanupPad->getParentPad()) &&
424 if (isa<CatchPadInst>(EHPad))
438 const Instruction *FirstNonPHI = BB.getFirstNonPHI();
456 const Instruction *FirstNonPHI = BB.getFirstNonPHI();
510 const Instruction *FirstNonPHI = BB.getFirstNonPHI();
511 const Value *ParentPad;
512 if (
const auto *CPI = dyn_cast<CleanupPadInst>(FirstNonPHI))
513 ParentPad = CPI->getParentPad();
514 else if (
const auto *CSI = dyn_cast<CatchSwitchInst>(FirstNonPHI))
515 ParentPad = CSI->getParentPad();
518 if (isa<ConstantTokenNone>(ParentPad))
528 while (!Worklist.
empty()) {
530 int HandlerParentState;
531 std::tie(Pad, HandlerParentState) = Worklist.
pop_back_val();
533 if (
const auto *
Cleanup = dyn_cast<CleanupPadInst>(Pad)) {
543 if (
const auto *
I = dyn_cast<Instruction>(U))
551 const auto *CatchSwitch = cast<CatchSwitchInst>(Pad);
552 int CatchState = -1, FollowerState = -1;
554 for (
auto CBI = CatchBlocks.rbegin(), CBE = CatchBlocks.rend();
555 CBI != CBE; ++CBI, FollowerState = CatchState) {
561 cast<ConstantInt>(
Catch->getArgOperand(0))->getZExtValue());
567 if (
const auto *
I = dyn_cast<Instruction>(U))
574 assert(CatchSwitch->getNumHandlers());
590 if (
const auto *
Catch = dyn_cast<CatchPadInst>(Pad)) {
596 if (
Entry->TryParentState != -1)
599 UnwindDest =
Catch->getCatchSwitch()->getUnwindDest();
601 const auto *
Cleanup = cast<CleanupPadInst>(Pad);
602 UnwindDest =
nullptr;
604 if (
auto *CleanupRet = dyn_cast<CleanupReturnInst>(U)) {
607 UnwindDest = CleanupRet->getUnwindDest();
613 if (
auto *Invoke = dyn_cast<InvokeInst>(U)) {
614 UserUnwindDest = Invoke->getUnwindDest();
615 }
else if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(U)) {
616 UserUnwindDest = CatchSwitch->getUnwindDest();
617 }
else if (
auto *ChildCleanup = dyn_cast<CleanupPadInst>(U)) {
619 int UserUnwindState =
621 if (UserUnwindState != -1)
636 const Value *UserUnwindParent;
637 if (
auto *CSI = dyn_cast<CatchSwitchInst>(UserUnwindPad))
638 UserUnwindParent = CSI->getParentPad();
645 if (UserUnwindParent ==
Cleanup)
649 UnwindDest = UserUnwindDest;
668 UnwindDestState = -1;
673 Entry->TryParentState = UnwindDestState;
680 void WinEHPrepare::colorFunclets(
Function &
F) {
691 void WinEHPrepare::demotePHIsOnFunclets(
Function &F,
692 bool DemoteCatchSwitchPHIOnly) {
699 if (DemoteCatchSwitchPHIOnly && !isa<CatchSwitchInst>(BB->
getFirstNonPHI()))
709 AllocaInst *SpillSlot = insertPHILoads(PN, F);
711 insertPHIStores(PN, SpillSlot);
717 for (
auto *PN : PHINodes) {
720 PN->eraseFromParent();
724 void WinEHPrepare::cloneCommonBlocks(
Function &F) {
728 for (
auto &Funclets : FuncletBlocks) {
730 std::vector<BasicBlock *> &BlocksInFunclet = Funclets.second;
737 std::vector<std::pair<BasicBlock *, BasicBlock *>> Orig2Clone;
742 size_t NumColorsForBB = ColorsForBB.
size();
743 if (NumColorsForBB == 1)
747 dbgs() <<
" Cloning block \'" << BB->getName()
748 <<
"\' for funclet \'" << FuncletPadBB->
getName()
756 CBB->insertInto(&F, BB->getNextNode());
762 Orig2Clone.emplace_back(BB, CBB);
766 if (Orig2Clone.empty())
771 for (
auto &BBMapping : Orig2Clone) {
775 BlocksInFunclet.push_back(NewBlock);
777 assert(NewColors.
empty() &&
"A new block should only have one color!");
781 dbgs() <<
" Assigned color \'" << FuncletPadBB->
getName()
782 <<
"\' to block \'" << NewBlock->
getName()
785 BlocksInFunclet.erase(
786 std::remove(BlocksInFunclet.begin(), BlocksInFunclet.end(), OldBlock),
787 BlocksInFunclet.end());
794 dbgs() <<
" Removed color \'" << FuncletPadBB->
getName()
795 <<
"\' from block \'" << OldBlock->
getName()
810 for (
auto &BBMapping : Orig2Clone) {
814 FixupCatchrets.
clear();
816 if (
auto *CatchRet = dyn_cast<CatchReturnInst>(Pred->getTerminator()))
817 if (CatchRet->getCatchSwitchParentPad() == FuncletToken)
821 CatchRet->setSuccessor(NewBlock);
824 auto UpdatePHIOnClonedBlock = [&](
PHINode *PN,
bool IsForOldBlock) {
826 for (
unsigned PredIdx = 0, PredEnd = NumPreds; PredIdx != PredEnd;
829 bool EdgeTargetsFunclet;
832 EdgeTargetsFunclet = (CRI->getCatchSwitchParentPad() == FuncletToken);
834 ColorVector &IncomingColors = BlockColors[IncomingBlock];
835 assert(!IncomingColors.
empty() &&
"Block not colored!");
839 return Color != FuncletPadBB;
841 "Cloning should leave this funclet's blocks monochromatic");
842 EdgeTargetsFunclet = (IncomingColors.
front() == FuncletPadBB);
844 if (IsForOldBlock != EdgeTargetsFunclet)
853 for (
auto &BBMapping : Orig2Clone) {
857 UpdatePHIOnClonedBlock(&OldPN,
true);
860 UpdatePHIOnClonedBlock(&NewPN,
false);
866 for (
auto &BBMapping : Orig2Clone) {
870 for (
PHINode &SuccPN : SuccBB->phis()) {
873 int OldBlockIdx = SuccPN.getBasicBlockIndex(OldBlock);
874 if (OldBlockIdx == -1)
876 Value *IV = SuccPN.getIncomingValue(OldBlockIdx);
879 if (
auto *Inst = dyn_cast<Instruction>(IV)) {
885 SuccPN.addIncoming(IV, NewBlock);
901 auto *NewI = cast<Instruction>(VT.second);
905 Instruction *UserI = cast<Instruction>(U.getUser());
907 ColorVector &ColorsForUserBB = BlockColors[UserBB];
909 if (ColorsForUserBB.
size() > 1 ||
910 *ColorsForUserBB.
begin() != FuncletPadBB)
916 if (UsesToRename.
empty())
923 SSAUpdate.
Initialize(OldI->getType(), OldI->getName());
927 while (!UsesToRename.
empty())
933 void WinEHPrepare::removeImplausibleInstructions(
Function &F) {
935 for (
auto &Funclet : FuncletBlocks) {
937 std::vector<BasicBlock *> &BlocksInFunclet = Funclet.second;
940 auto *CatchPad = dyn_cast_or_null<CatchPadInst>(FuncletPad);
941 auto *CleanupPad = dyn_cast_or_null<CleanupPadInst>(FuncletPad);
949 Value *FuncletBundleOperand =
nullptr;
951 FuncletBundleOperand = BU->Inputs.front();
953 if (FuncletBundleOperand == FuncletPad)
959 if (CalledFn && ((CalledFn->isIntrinsic() && CS.
doesNotThrow()) ||
969 std::prev(BB->getTerminator()->getIterator());
970 auto *CI = cast<CallInst>(&*CallI);
983 bool IsUnreachableRet = isa<ReturnInst>(TI) && FuncletPad;
985 bool IsUnreachableCatchret =
false;
986 if (
auto *CRI = dyn_cast<CatchReturnInst>(TI))
987 IsUnreachableCatchret = CRI->getCatchPad() != CatchPad;
989 bool IsUnreachableCleanupret =
false;
990 if (
auto *CRI = dyn_cast<CleanupReturnInst>(TI))
991 IsUnreachableCleanupret = CRI->getCleanupPad() != CleanupPad;
992 if (IsUnreachableRet || IsUnreachableCatchret ||
993 IsUnreachableCleanupret) {
995 }
else if (isa<InvokeInst>(TI)) {
1007 void WinEHPrepare::cleanupPreparedFunclets(
Function &F) {
1023 void WinEHPrepare::verifyPreparedFunclets(
Function &F) {
1025 size_t NumColors = BlockColors[&BB].size();
1026 assert(NumColors == 1 &&
"Expected monochromatic BB!");
1032 "EH Pad still has a PHI!");
1037 bool WinEHPrepare::prepareExplicitEH(
Function &F) {
1046 cloneCommonBlocks(F);
1049 demotePHIsOnFunclets(F, DemoteCatchSwitchPHIOnly ||
1054 removeImplausibleInstructions(F);
1057 cleanupPreparedFunclets(F);
1065 BlockColors.clear();
1066 FuncletBlocks.clear();
1097 auto *UsingInst = cast<Instruction>(U.
getUser());
1098 if (isa<PHINode>(UsingInst) && UsingInst->getParent()->isEHPad()) {
1103 replaceUseWithLoad(PN, U, SpillSlot, Loads, F);
1112 void WinEHPrepare::insertPHIStores(
PHINode *OriginalPHI,
1120 while (!Worklist.
empty()) {
1134 if (isa<UndefValue>(PredVal))
1143 insertPHIStore(PredBlock, InVal, SpillSlot, Worklist);
1149 void WinEHPrepare::insertPHIStore(
1155 Worklist.push_back({PredBlock, PredVal});
1172 auto *UsingInst = cast<Instruction>(U.
getUser());
1173 if (
auto *UsingPHI = dyn_cast<PHINode>(UsingInst)) {
1183 BasicBlock *IncomingBlock = UsingPHI->getIncomingBlock(U);
1184 if (
auto *CatchRet =
1185 dyn_cast<CatchReturnInst>(IncomingBlock->
getTerminator())) {
1207 CatchRet->removeFromParent();
1211 CatchRet->setSuccessor(NewBlock);
1216 ColorVector &ColorsForNewBlock = BlockColors[NewBlock];
1217 ColorVector &ColorsForPHIBlock = BlockColors[PHIBlock];
1218 ColorsForNewBlock = ColorsForPHIBlock;
1219 for (
BasicBlock *FuncletPad : ColorsForPHIBlock)
1220 FuncletBlocks[FuncletPad].
push_back(NewBlock);
1222 IncomingBlock = NewBlock;
1244 assert(InvokeStateMap.count(II) &&
1245 "should get invoke with precomputed state");
1246 LabelToStateMap[InvokeBegin] = std::make_pair(InvokeStateMap[II], InvokeEnd);
A parsed version of the target data layout string in and methods for querying it. ...
reference emplace_back(ArgTypes &&... Args)
static Value * getParentPad(Value *EHPad)
iterator_range< use_iterator > uses()
SmallVector< WinEHHandlerType, 1 > HandlerArray
Helper class for SSA formation on a set of values defined in multiple blocks.
int getLastStateNumber() const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
void Initialize(Type *Ty, StringRef Name)
Reset this object to get ready for a new set of SSA updates with type 'Ty'.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
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...
A Module instance is used to store all the information related to an LLVM module. ...
SmallVector< SEHUnwindMapEntry, 4 > SEHUnwindMap
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
void push_back(const T &Elt)
static void Cleanup(DenseMap< Instruction *, Instruction *> &NewPredicates, SetVector< Instruction *> &MaybeDead, Loop *L)
void AddAvailableValue(BasicBlock *BB, Value *V)
Indicate that a rewritten value is available in the specified block with the specified value...
DenseMap< const FuncletPadInst *, int > FuncletBaseStateMap
const AllocaInst * Alloca
bool isTerminator() const
This class implements a map that also provides access to all stored values in a deterministic order...
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
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...
An instruction for reading from memory.
Optional< OperandBundleUse > getOperandBundle(StringRef Name) const
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
static cl::opt< bool > DisableCleanups("disable-cleanups", cl::Hidden, cl::desc("Do not remove implausible terminators or other similar cleanups"), cl::init(false))
iterator begin()
Instruction iterator methods.
bool MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, MemoryDependenceResults *MemDep=nullptr, bool PredecessorWithTwoSuccessors=false)
Attempts to merge a block into its predecessor, if possible.
MBBOrBasicBlock Handler
Holds the __except or __finally basic block.
BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Split the edge connecting specified block.
#define DEBUG_WITH_TYPE(TYPE, X)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
iterator erase(iterator I)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void calculateSEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
A Use represents the edge between a Value definition and its users.
ValTy * getCalledValue() const
Return the pointer to function that is being called.
int TryParentState
Outer try region enclosing this entry's try region, treating later catches on same try as "outer"...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
static BasicBlock * getCleanupRetUnwindDest(const CleanupPadInst *CleanupPad)
static cl::opt< bool > DisableDemotion("disable-demotion", cl::Hidden, cl::desc("Clone multicolor basic blocks but do not demote cross scopes"), cl::init(false))
int ToState
If unwinding continues through this handler, transition to the handler at this state.
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch, catchpad/ret, and cleanuppad/ret.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
User * getUser() const LLVM_READONLY
Returns the User that contains this Use.
Type * getType() const
All values are typed, get the type of this value.
static int addUnwindMapEntry(WinEHFuncInfo &FuncInfo, int ToState, const BasicBlock *BB)
static cl::opt< bool > DemoteCatchSwitchPHIOnlyOpt("demote-catchswitch-only", cl::Hidden, cl::desc("Demote catchswitch BBs only (for wasm EH)"), cl::init(false))
static void calculateStateNumbersForInvokes(const Function *Fn, WinEHFuncInfo &FuncInfo)
iterator find(const KeyT &Val)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
An instruction for storing to memory.
bool hasPersonalityFn() const
Check whether this function has a personality function.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
bool doesNotThrow() const
Determine if the call cannot unwind.
If this flag is set, the remapper knows that only local values within a function (such as an instruct...
use_iterator_impl< Use > use_iterator
Similar to CxxUnwindMapEntry, but supports SEH filters.
const BasicBlock & getEntryBlock() const
static bool runOnFunction(Function &F, bool PostInlining)
initializer< Ty > init(const Ty &Val)
SmallVector< ClrEHUnwindMapEntry, 4 > ClrEHUnwindMap
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
static int addSEHExcept(WinEHFuncInfo &FuncInfo, int ParentState, const Function *Filter, const BasicBlock *Handler)
LLVM Basic Block Representation.
void push_back(EltTy NewVal)
void RewriteUseAfterInsertions(Use &U)
Rewrite a use like RewriteUse but handling in-block definitions.
Conditional or Unconditional Branch instruction.
std::pair< const Value *, WeakTrackingVH > value_type
This is an important base class in LLVM.
const Instruction & front() const
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
DenseMap< const Instruction *, int > EHPadStateMap
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
DenseMap< const InvokeInst *, int > InvokeStateMap
FunctionPass * createWinEHPass(bool DemoteCatchSwitchPHIOnly=false)
createWinEHPass - Prepares personality functions used by MSVC on Windows, in addition to the Itanium ...
void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo)
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
const Constant * stripPointerCasts() const
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
static bool isTopLevelPadForMSVC(const Instruction *EHPad)
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setSuccessor(unsigned idx, BasicBlock *NewSucc)
void calculateWinCXXEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which describes the state number...
SmallVector< CxxUnwindMapEntry, 4 > CxxUnwindMap
const InstListType & getInstList() const
Return the underlying instruction list container.
const Function * Filter
Holds the filter expression function.
Iterator for intrusive lists based on ilist_node.
Color
A "color", which is either even or odd.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static void calculateCXXStateNumbers(WinEHFuncInfo &FuncInfo, const Instruction *FirstNonPHI, int ParentState)
int HandlerParentState
Outer handler enclosing this entry's handler.
LLVM_NODISCARD T pop_back_val()
void addIPToStateRange(const InvokeInst *II, MCSymbol *InvokeBegin, MCSymbol *InvokeEnd)
pred_range predecessors(BasicBlock *BB)
unsigned getNumIncomingValues() const
Return the number of incoming edges.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
SmallVector< WinEHTryBlockMapEntry, 4 > TryBlockMap
void push_back(pointer val)
BasicBlock * CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap, const Twine &NameSuffix="", Function *F=nullptr, ClonedCodeInfo *CodeInfo=nullptr, DebugInfoFinder *DIFinder=nullptr)
Return a copy of the specified basic block, but without embedding the block into a particular functio...
void removeUnwindEdge(BasicBlock *BB, DomTreeUpdater *DTU=nullptr)
Replace 'BB's terminator with one that does not have an unwind successor block.
iterator_range< user_iterator > users()
union llvm::WinEHHandlerType::@202 CatchObj
The CatchObj starts out life as an LLVM alloca and is eventually turned frame index.
void RemapInstruction(Instruction *I, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Convert the instruction operands from referencing the current values into those specified by VM...
GlobalVariable * TypeDescriptor
If this flag is set, the remapper ignores missing function-local entries (Argument, Instruction, BasicBlock) that are not in the value map.
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
LLVM_NODISCARD bool empty() const
static int addSEHFinally(WinEHFuncInfo &FuncInfo, int ParentState, const BasicBlock *Handler)
StringRef getName() const
Return a constant reference to the value's name.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
const Function * getParent() const
Return the enclosing method, or null if none.
bool verifyFunction(const Function &F, raw_ostream *OS=nullptr)
Check a function for errors, useful for use when debugging a pass.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
static ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
bool removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Remove all blocks that can not be reached from the function's entry.
ClrHandlerType HandlerType
bool isInvoke() const
Return true if a InvokeInst is enclosed.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isEHPad() const
Return true if this basic block is an exception handling block.
static int addClrEHHandler(WinEHFuncInfo &FuncInfo, int HandlerParentState, int TryParentState, ClrHandlerType HandlerType, uint32_t TypeToken, const BasicBlock *Handler)
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
succ_range successors(Instruction *I)
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
StringRef - Represent a constant reference to a string, i.e.
DenseMap< BasicBlock *, ColorVector > colorEHFunclets(Function &F)
If an EH funclet personality is in use (see isFuncletEHPersonality), this will recompute which blocks...
static const BasicBlock * getEHPadFromPredecessor(const BasicBlock *BB, Value *ParentPad)
static void addTryBlockMapEntry(WinEHFuncInfo &FuncInfo, int TryLow, int TryHigh, int CatchHigh, ArrayRef< const CatchPadInst *> Handlers)
unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap, 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...
INITIALIZE_PASS(WinEHPrepare, DEBUG_TYPE, "Prepare Windows exceptions", false, false) FunctionPass *llvm
const BasicBlock * getParent() const
an instruction to allocate memory on the stack