45#define DEBUG_TYPE "wasm-cfg-stackify"
47STATISTIC(NumCallUnwindMismatches,
"Number of call unwind mismatches found");
48STATISTIC(NumCatchUnwindMismatches,
"Number of catch unwind mismatches found");
51class WebAssemblyCFGStackifyImpl {
52 const WebAssemblyOptions &CLOpts;
57 bool UsesWasmEH =
false;
65 int EndNo =
End->getNumber();
66 if (!ScopeTops[EndNo] || ScopeTops[EndNo]->getNumber() > BeginNo)
67 ScopeTops[EndNo] = Begin;
72 void placeBlockMarker(MachineBasicBlock &
MBB);
73 void placeLoopMarker(MachineBasicBlock &
MBB);
74 void placeTryMarker(MachineBasicBlock &
MBB);
75 void placeTryTableMarker(MachineBasicBlock &
MBB);
83 void addNestedTryDelegate(MachineInstr *RangeBegin, MachineInstr *RangeEnd,
84 MachineBasicBlock *UnwindDest);
87 void addNestedTryTable(MachineInstr *RangeBegin, MachineInstr *RangeEnd,
88 MachineBasicBlock *UnwindDest);
89 MachineBasicBlock *getTrampolineBlock(MachineBasicBlock *UnwindDest);
93 std::pair<const MachineBasicBlock *, const MachineInstr *>;
94 unsigned getBranchDepth(
const SmallVectorImpl<EndMarkerInfo> &Stack,
95 const MachineBasicBlock *
MBB);
96 unsigned getDelegateDepth(
const SmallVectorImpl<EndMarkerInfo> &Stack,
97 const MachineBasicBlock *
MBB);
98 unsigned getRethrowDepth(
const SmallVectorImpl<EndMarkerInfo> &Stack,
99 const MachineBasicBlock *EHPadToRethrow);
106 DenseMap<const MachineInstr *, MachineInstr *> BeginToEnd;
109 DenseMap<const MachineInstr *, MachineInstr *> EndToBegin;
111 DenseMap<const MachineInstr *, MachineBasicBlock *> TryToEHPad;
113 DenseMap<const MachineBasicBlock *, MachineInstr *> EHPadToTry;
115 DenseMap<const MachineBasicBlock *, MachineBasicBlock *>
116 UnwindDestToTrampoline;
120 MachineBasicBlock *AppendixBB =
nullptr;
128 if (CallerTrampolineBB)
129 MF.
insert(CallerTrampolineBB->getIterator(), AppendixBB);
138 MachineBasicBlock *CallerTrampolineBB =
nullptr;
140 if (!CallerTrampolineBB) {
144 return CallerTrampolineBB;
153 MachineBasicBlock *FakeCallerBB =
nullptr;
162 void registerScope(MachineInstr *Begin, MachineInstr *
End);
163 void registerTryScope(MachineInstr *Begin, MachineInstr *
End,
164 MachineBasicBlock *EHPad);
165 void unregisterScope(MachineInstr *Begin);
168 WebAssemblyCFGStackifyImpl(
const WebAssemblyOptions &CLOpts,
169 MachineDominatorTree &MDT, MachineLoopInfo &MLI,
170 WebAssemblyExceptionInfo &WEI)
171 : CLOpts(CLOpts), MDT(MDT), MLI(MLI), WEI(WEI) {}
177 StringRef getPassName()
const override {
return "WebAssembly CFG Stackify"; }
179 void getAnalysisUsage(AnalysisUsage &AU)
const override {
182 AU.
addRequired<WebAssemblyExceptionInfoWrapperPass>();
189 WebAssemblyCFGStackifyLegacy() : MachineFunctionPass(ID) {}
193char WebAssemblyCFGStackifyLegacy::ID = 0;
196 "Insert BLOCK/LOOP/TRY/TRY_TABLE markers for WebAssembly scopes",
false,
200 return new WebAssemblyCFGStackifyLegacy();
212 if (MO.isMBB() && MO.getMBB() ==
MBB)
222template <
typename Container>
225 const Container &AfterSet) {
226 auto InsertPos =
MBB->end();
227 while (InsertPos !=
MBB->begin()) {
228 if (BeforeSet.count(&*std::prev(InsertPos))) {
231 for (
auto Pos = InsertPos,
E =
MBB->begin(); Pos !=
E; --Pos)
232 assert(!AfterSet.count(&*std::prev(Pos)));
246template <
typename Container>
249 const Container &AfterSet) {
250 auto InsertPos =
MBB->begin();
251 while (InsertPos !=
MBB->end()) {
252 if (AfterSet.count(&*InsertPos)) {
255 for (
auto Pos = InsertPos,
E =
MBB->end(); Pos !=
E; ++Pos)
256 assert(!BeforeSet.count(&*Pos));
265void WebAssemblyCFGStackifyImpl::registerScope(
MachineInstr *Begin,
267 BeginToEnd[Begin] =
End;
268 EndToBegin[
End] = Begin;
272void WebAssemblyCFGStackifyImpl::registerTryScope(MachineInstr *Begin,
274 MachineBasicBlock *EHPad) {
275 registerScope(Begin,
End);
276 TryToEHPad[Begin] = EHPad;
277 EHPadToTry[EHPad] = Begin;
280void WebAssemblyCFGStackifyImpl::unregisterScope(MachineInstr *Begin) {
282 MachineInstr *
End = BeginToEnd[Begin];
284 BeginToEnd.
erase(Begin);
286 MachineBasicBlock *EHPad = TryToEHPad.
lookup(Begin);
289 TryToEHPad.
erase(Begin);
290 EHPadToTry.
erase(EHPad);
297void WebAssemblyCFGStackifyImpl::placeBlockMarker(MachineBasicBlock &
MBB) {
300 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
301 const auto &MFI = *MF.
getInfo<WebAssemblyFunctionInfo>();
306 MachineBasicBlock *Header =
nullptr;
307 bool IsBranchedTo =
false;
310 if (
Pred->getNumber() < MBBNumber) {
321 assert(&
MBB != &MF.
front() &&
"Header blocks shouldn't have predecessors");
327 if (MachineBasicBlock *ScopeTop = ScopeTops[
I->getNumber()]) {
328 if (ScopeTop->getNumber() > Header->getNumber()) {
330 I = std::next(ScopeTop->getIterator());
342 SmallPtrSet<const MachineInstr *, 4> BeforeSet;
344 SmallPtrSet<const MachineInstr *, 4> AfterSet;
345 for (
const auto &
MI : *Header) {
349 if (
MI.getOpcode() == WebAssembly::LOOP) {
350 auto *LoopBottom = BeginToEnd[&
MI]->getParent()->getPrevNode();
363 if (
MI.getOpcode() == WebAssembly::BLOCK ||
364 MI.getOpcode() == WebAssembly::TRY ||
365 MI.getOpcode() == WebAssembly::TRY_TABLE) {
376 if (
MI.getOpcode() == WebAssembly::END_BLOCK ||
377 MI.getOpcode() == WebAssembly::END_LOOP ||
378 MI.getOpcode() == WebAssembly::END_TRY ||
379 MI.getOpcode() == WebAssembly::END_TRY_TABLE)
384 if (
MI.isTerminator())
389 for (
auto I = Header->getFirstTerminator(),
E = Header->begin();
I !=
E;
391 if (std::prev(
I)->isDebugInstr() || std::prev(
I)->isPosition())
394 AfterSet.
insert(&*std::prev(
I));
402 MachineInstr *Begin =
403 BuildMI(*Header, InsertPos, Header->findDebugLoc(InsertPos),
404 TII.get(WebAssembly::BLOCK))
405 .
addImm(int64_t(ReturnType));
410 for (
auto &
MI :
MBB) {
413 if (
MI.getOpcode() == WebAssembly::LOOP)
426 if (
MI.getOpcode() == WebAssembly::END_LOOP ||
427 MI.getOpcode() == WebAssembly::END_TRY) {
428 if (EndToBegin[&
MI]->
getParent()->getNumber() >= Header->getNumber())
440 TII.get(WebAssembly::END_BLOCK));
441 registerScope(Begin,
End);
444 updateScopeTops(Header, &
MBB);
448void WebAssemblyCFGStackifyImpl::placeLoopMarker(MachineBasicBlock &
MBB) {
450 SortRegionInfo SRI(MLI, WEI);
451 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
459 MachineBasicBlock *Bottom = SRI.getBottom(
Loop);
461 if (Iter == MF.
end()) {
462 getAppendixBlock(MF);
465 MachineBasicBlock *AfterLoop = &*Iter;
468 SmallPtrSet<const MachineInstr *, 4> BeforeSet;
469 SmallPtrSet<const MachineInstr *, 4> AfterSet;
470 for (
const auto &
MI :
MBB) {
473 if (
MI.getOpcode() == WebAssembly::END_LOOP)
484 TII.get(WebAssembly::LOOP))
485 .
addImm(int64_t(WebAssembly::BlockType::Void));
491 for (
const auto &
MI :
MBB)
493 if (
MI.getOpcode() == WebAssembly::END_LOOP)
502 : (*AfterLoop->pred_rbegin())->findBranchDebugLoc();
504 BuildMI(*AfterLoop, InsertPos, EndDL,
TII.get(WebAssembly::END_LOOP));
505 registerScope(Begin,
End);
509 "With block sorting the outermost loop for a block should be first.");
510 updateScopeTops(&
MBB, AfterLoop);
513void WebAssemblyCFGStackifyImpl::placeTryMarker(MachineBasicBlock &
MBB) {
516 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
517 SortRegionInfo SRI(MLI, WEI);
518 const auto &MFI = *MF.
getInfo<WebAssemblyFunctionInfo>();
521 MachineBasicBlock *Header =
nullptr;
524 if (
Pred->getNumber() < MBBNumber) {
527 "Explicit branch to an EH pad!");
537 MachineBasicBlock *Bottom = SRI.getBottom(WE);
539 if (Iter == MF.
end()) {
540 getAppendixBlock(MF);
543 MachineBasicBlock *Cont = &*Iter;
548 if (MachineBasicBlock *ScopeTop = ScopeTops[
I->getNumber()]) {
549 if (ScopeTop->getNumber() > Header->getNumber()) {
551 I = std::next(ScopeTop->getIterator());
563 SmallPtrSet<const MachineInstr *, 4> BeforeSet;
565 SmallPtrSet<const MachineInstr *, 4> AfterSet;
566 for (
const auto &
MI : *Header) {
570 if (
MI.getOpcode() == WebAssembly::LOOP) {
571 auto *LoopBottom = BeginToEnd[&
MI]->getParent()->getPrevNode();
582 if (
MI.getOpcode() == WebAssembly::BLOCK ||
583 MI.getOpcode() == WebAssembly::TRY)
588 if (
MI.getOpcode() == WebAssembly::END_BLOCK ||
589 MI.getOpcode() == WebAssembly::END_LOOP ||
590 MI.getOpcode() == WebAssembly::END_TRY)
595 if (
MI.isTerminator())
604 MachineInstr *ThrowingCall =
nullptr;
606 auto TermPos = Header->getFirstTerminator();
607 if (TermPos == Header->end() ||
608 TermPos->getOpcode() != WebAssembly::RETHROW) {
626 : Header->getFirstTerminator();
627 for (
auto I = SearchStartPt,
E = Header->begin();
I !=
E; --
I) {
628 if (std::prev(I)->isDebugInstr() || std::prev(I)->isPosition())
630 if (WebAssembly::isChild(*std::prev(I), MFI))
631 AfterSet.insert(&*std::prev(I));
638 MachineInstr *Begin =
639 BuildMI(*Header, InsertPos, Header->findDebugLoc(InsertPos),
640 TII.get(WebAssembly::TRY))
641 .
addImm(int64_t(WebAssembly::BlockType::Void));
646 for (
const auto &
MI : *Cont) {
649 if (
MI.getOpcode() == WebAssembly::LOOP)
654 if (
MI.getOpcode() == WebAssembly::END_TRY)
662 if (
MI.getOpcode() == WebAssembly::END_LOOP) {
665 if (EndToBegin[&
MI]->
getParent()->getNumber() > Header->getNumber())
679 TII.get(WebAssembly::END_TRY));
680 registerTryScope(Begin,
End, &
MBB);
693 for (
auto *
End : {&
MBB, Cont})
694 updateScopeTops(Header,
End);
697void WebAssemblyCFGStackifyImpl::placeTryTableMarker(MachineBasicBlock &
MBB) {
700 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
701 SortRegionInfo SRI(MLI, WEI);
702 const auto &MFI = *MF.
getInfo<WebAssemblyFunctionInfo>();
705 MachineBasicBlock *Header =
nullptr;
708 if (
Pred->getNumber() < MBBNumber) {
711 "Explicit branch to an EH pad!");
722 MachineBasicBlock *Bottom = SRI.getBottom(WE);
724 if (Iter == MF.
end())
726 MachineBasicBlock *Cont = &*Iter;
731 if (MachineBasicBlock *ScopeTop = ScopeTops[
I->getNumber()]) {
732 if (ScopeTop->getNumber() > Header->getNumber()) {
734 I = std::next(ScopeTop->getIterator());
746 SmallPtrSet<const MachineInstr *, 4> BeforeSet;
748 SmallPtrSet<const MachineInstr *, 4> AfterSet;
749 for (
const auto &
MI : *Header) {
753 if (
MI.getOpcode() == WebAssembly::LOOP) {
754 auto *LoopBottom = BeginToEnd[&
MI]->getParent()->getPrevNode();
765 if (
MI.getOpcode() == WebAssembly::BLOCK ||
766 MI.getOpcode() == WebAssembly::TRY_TABLE)
771 if (
MI.getOpcode() == WebAssembly::END_BLOCK ||
772 MI.getOpcode() == WebAssembly::END_LOOP ||
773 MI.getOpcode() == WebAssembly::END_TRY_TABLE)
778 if (
MI.isTerminator())
787 MachineInstr *ThrowingCall =
nullptr;
789 auto TermPos = Header->getFirstTerminator();
790 if (TermPos == Header->end() ||
791 TermPos->getOpcode() != WebAssembly::RETHROW) {
809 : Header->getFirstTerminator();
810 for (
auto I = SearchStartPt,
E = Header->begin();
I !=
E; --
I) {
811 if (std::prev(I)->isDebugInstr() || std::prev(I)->isPosition())
813 if (WebAssembly::isChild(*std::prev(I), MFI))
814 AfterSet.insert(&*std::prev(I));
833 MachineInstrBuilder BlockMIB =
834 BuildMI(*Header, InsertPos, Header->findDebugLoc(InsertPos),
835 TII.get(WebAssembly::BLOCK));
837 MachineInstrBuilder TryTableMIB =
838 BuildMI(*Header, InsertPos, Header->findDebugLoc(InsertPos),
839 TII.get(WebAssembly::TRY_TABLE))
840 .
addImm(int64_t(WebAssembly::BlockType::Void))
842 auto *TryTable = TryTableMIB.
getInstr();
848 *MF.
getSubtarget<WebAssemblySubtarget>().getTargetLowering();
851 ? WebAssembly::BlockType::I32
852 : WebAssembly::BlockType::I64;
854 switch (
Catch->getOpcode()) {
855 case WebAssembly::CATCH:
859 BlockMIB.
addImm(int64_t(PtrTy));
861 for (
const auto &Use :
Catch->uses()) {
868 case WebAssembly::CATCH_REF:
873 BlockMIB.
addImm(int64_t(WebAssembly::BlockType::Multivalue));
876 for (
const auto &Use :
Catch->uses()) {
882 case WebAssembly::CATCH_ALL:
884 BlockMIB.
addImm(int64_t(WebAssembly::BlockType::Void));
888 case WebAssembly::CATCH_ALL_REF:
890 BlockMIB.
addImm(int64_t(WebAssembly::BlockType::Exnref));
900 for (
const auto &
MI :
MBB) {
903 if (
MI.getOpcode() == WebAssembly::LOOP)
911 if (
MI.getOpcode() == WebAssembly::END_LOOP) {
912 if (EndToBegin[&
MI]->
getParent()->getNumber() >= Header->getNumber())
931 MachineInstr *EndTryTable =
933 TII.get(WebAssembly::END_TRY_TABLE));
934 registerTryScope(TryTable, EndTryTable, &
MBB);
935 MachineInstr *EndBlock =
937 TII.get(WebAssembly::END_BLOCK));
938 registerScope(
Block, EndBlock);
980 for (
auto *
End : {&
MBB, Cont})
981 updateScopeTops(Header,
End);
984void WebAssemblyCFGStackifyImpl::removeUnnecessaryInstrs(
MachineFunction &MF) {
985 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
1020 for (
auto &
MBB : MF) {
1024 MachineBasicBlock *
TBB =
nullptr, *FBB =
nullptr;
1025 SmallVector<MachineOperand, 4>
Cond;
1028 MachineBasicBlock *Cont = &
MBB;
1030 MachineInstr *Try = EHPadToTry[Cont];
1031 MachineInstr *EndTry = BeginToEnd[Try];
1045 (!
Cond.
empty() && FBB && FBB == Cont))) {
1046 bool ErasedUncondBr =
false;
1047 (void)ErasedUncondBr;
1048 for (
auto I = EHPadLayoutPred->
end(),
E = EHPadLayoutPred->
begin();
1050 auto PrevI = std::prev(
I);
1051 if (PrevI->isTerminator()) {
1052 assert(PrevI->getOpcode() == WebAssembly::BR);
1053 PrevI->eraseFromParent();
1054 ErasedUncondBr =
true;
1058 assert(ErasedUncondBr &&
"Unconditional branch not erased!");
1074 for (
auto &
MBB : MF) {
1075 for (
auto &
MI :
MBB) {
1076 if (
MI.getOpcode() != WebAssembly::TRY)
1078 MachineInstr *Try = &
MI, *EndTry = BeginToEnd[Try];
1079 if (EndTry->getOpcode() == WebAssembly::DELEGATE)
1082 MachineBasicBlock *TryBB = Try->
getParent();
1083 MachineBasicBlock *Cont = EndTry->
getParent();
1085 for (
auto B = Try->
getIterator(),
E = std::next(EndTry->getIterator());
1087 std::prev(
B)->getOpcode() == WebAssembly::BLOCK &&
1088 E->getOpcode() == WebAssembly::END_BLOCK &&
1089 std::prev(
B)->getOperand(0).getImm() == RetType;
1096 for (
auto *
MI : ToDelete) {
1097 if (
MI->getOpcode() == WebAssembly::BLOCK)
1098 unregisterScope(
MI);
1099 MI->eraseFromParent();
1112 for (
auto &
MI : Split) {
1113 for (
auto &MO :
MI.explicit_uses()) {
1114 if (!MO.isReg() || MO.getReg().isPhysical())
1117 if (Def->getParent() == &
MBB)
1118 MFI.unstackifyVReg(MO.getReg());
1151 if (!MFI.isVRegStackified(TeeReg)) {
1153 MFI.unstackifyVReg(DefReg);
1159 MI.eraseFromParent();
1166void WebAssemblyCFGStackifyImpl::addNestedTryDelegate(
1167 MachineInstr *RangeBegin, MachineInstr *RangeEnd,
1168 MachineBasicBlock *UnwindDest) {
1169 auto *BeginBB = RangeBegin->
getParent();
1172 const auto &MFI = *MF.
getInfo<WebAssemblyFunctionInfo>();
1173 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
1177 SmallPtrSet<const MachineInstr *, 4> AfterSet;
1178 AfterSet.
insert(RangeBegin);
1181 if (std::prev(
I)->isDebugInstr() || std::prev(
I)->isPosition())
1184 AfterSet.
insert(&*std::prev(
I));
1191 BeginBB, SmallPtrSet<const MachineInstr *, 4>(), AfterSet);
1193 TII.get(WebAssembly::TRY))
1194 .
addImm(int64_t(WebAssembly::BlockType::Void));
1200 if (UnwindDest != FakeCallerBB)
1203 auto SplitPos = std::next(RangeEnd->
getIterator());
1204 if (SplitPos == EndBB->end()) {
1207 MF.
insert(std::next(EndBB->getIterator()), DelegateBB);
1208 EndBB->addSuccessor(DelegateBB);
1218 bool CatchAfterSplit =
false;
1219 if (EndBB->isEHPad()) {
1223 CatchAfterSplit =
true;
1229 MachineBasicBlock *PreBB =
nullptr, *PostBB =
nullptr;
1230 if (!CatchAfterSplit) {
1249 PostBB->splice(PostBB->end(), PreBB, SplitPos, PreBB->
end());
1250 PostBB->transferSuccessors(PreBB);
1266 assert(EndBB->isEHPad());
1269 MF.
insert(PostBB->getIterator(), PreBB);
1270 MF.
insert(PostBB->getIterator(), DelegateBB);
1271 PreBB->
splice(PreBB->
end(), PostBB, PostBB->begin(), SplitPos);
1283 TII.get(WebAssembly::DELEGATE))
1285 registerTryScope(Try, Delegate,
nullptr);
1304WebAssemblyCFGStackifyImpl::getTrampolineBlock(MachineBasicBlock *UnwindDest) {
1308 auto It = UnwindDestToTrampoline.
find(UnwindDest);
1309 if (It != UnwindDestToTrampoline.
end())
1314 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
1316 MachineInstr *
Block =
nullptr;
1317 MachineBasicBlock *TrampolineBB =
nullptr;
1320 if (UnwindDest == getFakeCallerBlock(MF)) {
1324 auto BeginPos = MF.
begin()->begin();
1328 TII.get(WebAssembly::BLOCK))
1329 .
addImm(int64_t(WebAssembly::BlockType::Exnref));
1330 TrampolineBB = getCallerTrampolineBlock(MF);
1331 MachineBasicBlock *PrevBB = &*std::prev(CallerTrampolineBB->
getIterator());
1337 auto *TargetBeginTry = EHPadToTry[UnwindDest];
1338 auto *TargetEndTry = BeginToEnd[TargetBeginTry];
1339 auto *TargetBeginBB = TargetBeginTry->getParent();
1340 auto *TargetEndBB = TargetEndTry->getParent();
1342 Block =
BuildMI(*TargetBeginBB, std::next(TargetBeginTry->getIterator()),
1343 TargetBeginTry->getDebugLoc(),
TII.get(WebAssembly::BLOCK))
1344 .
addImm(int64_t(WebAssembly::BlockType::Exnref));
1346 EndDebugLoc = TargetEndTry->getDebugLoc();
1347 MF.
insert(TargetEndBB->getIterator(), TrampolineBB);
1353 MachineInstr *EndBlock =
1354 BuildMI(TrampolineBB, EndDebugLoc,
TII.get(WebAssembly::END_BLOCK));
1356 BuildMI(TrampolineBB, EndDebugLoc,
TII.get(WebAssembly::CATCH_ALL_REF))
1358 BuildMI(TrampolineBB, EndDebugLoc,
TII.get(WebAssembly::THROW_REF))
1364 MachineBasicBlock *TrampolineLayoutPred = TrampolineBB->
getPrevNode();
1366 TII.get(WebAssembly::UNREACHABLE));
1368 registerScope(
Block, EndBlock);
1369 UnwindDestToTrampoline[UnwindDest] = TrampolineBB;
1370 return TrampolineBB;
1375void WebAssemblyCFGStackifyImpl::addNestedTryTable(
1376 MachineInstr *RangeBegin, MachineInstr *RangeEnd,
1377 MachineBasicBlock *UnwindDest) {
1378 auto *BeginBB = RangeBegin->
getParent();
1382 const auto &MFI = *MF.
getInfo<WebAssemblyFunctionInfo>();
1383 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
1386 auto *TrampolineBB = getTrampolineBlock(UnwindDest);
1390 SmallPtrSet<const MachineInstr *, 4> AfterSet;
1391 AfterSet.
insert(RangeBegin);
1394 if (std::prev(
I)->isDebugInstr() || std::prev(
I)->isPosition())
1397 AfterSet.
insert(&*std::prev(
I));
1404 BeginBB, SmallPtrSet<const MachineInstr *, 4>(), AfterSet);
1405 MachineInstr *TryTable =
1407 TII.get(WebAssembly::TRY_TABLE))
1408 .
addImm(int64_t(WebAssembly::BlockType::Void))
1417 auto SplitPos = std::next(RangeEnd->
getIterator());
1418 if (SplitPos == EndBB->end()) {
1421 MF.
insert(std::next(EndBB->getIterator()), EndTryTableBB);
1422 EndBB->addSuccessor(EndTryTableBB);
1432 bool CatchAfterSplit =
false;
1433 if (EndBB->isEHPad()) {
1437 CatchAfterSplit =
true;
1443 MachineBasicBlock *PreBB =
nullptr, *PostBB =
nullptr;
1444 if (!CatchAfterSplit) {
1463 PostBB->splice(PostBB->end(), PreBB, SplitPos, PreBB->
end());
1464 PostBB->transferSuccessors(PreBB);
1480 assert(EndBB->isEHPad());
1483 MF.
insert(PostBB->getIterator(), PreBB);
1484 MF.
insert(PostBB->getIterator(), EndTryTableBB);
1485 PreBB->
splice(PreBB->
end(), PostBB, PostBB->begin(), SplitPos);
1497 TII.get(WebAssembly::END_TRY_TABLE));
1498 registerTryScope(TryTable, EndTryTable, TrampolineBB);
1550 MachineInstr *EndTryTable =
nullptr, *EndLoop =
nullptr;
1551 for (
auto &
MI :
reverse(*EndTryTableBB)) {
1552 if (
MI.getOpcode() == WebAssembly::END_TRY_TABLE) {
1556 if (EndTryTable &&
MI.getOpcode() == WebAssembly::END_LOOP) {
1566 auto SplitPos = std::next(EndLoop->getIterator());
1567 EndLoopBB->splice(EndLoopBB->end(), EndTryTableBB, EndTryTableBB->
begin(),
1569 EndLoopBB->addSuccessor(EndTryTableBB);
1575 std::string Name =
"bb.";
1577 if (
MBB->getBasicBlock()) {
1579 Name +=
MBB->getBasicBlock()->getName();
1584bool WebAssemblyCFGStackifyImpl::fixCallUnwindMismatches(
MachineFunction &MF) {
1831 using TryRange = std::pair<MachineInstr *, MachineInstr *>;
1833 MapVector<MachineBasicBlock *, SmallVector<TryRange, 4>>
1834 UnwindDestToTryRanges;
1840 bool SeenThrowableInstInBB =
false;
1844 else if (
MI.getOpcode() == WebAssembly::DELEGATE)
1848 else if (
MI.getOpcode() == WebAssembly::END_TRY_TABLE)
1889 EHPadStack.
push_back(TryToEHPad[EndToBegin[&
MI]]);
1898 SeenThrowableInstInBB =
true;
1902 MachineBasicBlock *UnwindDest =
nullptr;
1908 if (Succ->isEHPad()) {
1913 if (EHPadStack.
back() == UnwindDest)
1917 UnwindDestToTryRanges[UnwindDest].push_back(TryRange(&
MI, &
MI));
1919 <<
"\nCall = " <<
MI
1920 <<
"\nOriginal dest = " <<
getBBName(UnwindDest)
1933 MachineInstr *RangeBegin =
nullptr, *RangeEnd =
nullptr;
1936 auto RecordCallerMismatchRange = [&](
const MachineBasicBlock *CurrentDest) {
1937 UnwindDestToTryRanges[getFakeCallerBlock(MF)].push_back(
1938 TryRange(RangeBegin, RangeEnd));
1941 <<
"\nRange begin = " << *RangeBegin
1942 <<
"Range end = " << *RangeEnd
1943 <<
"\nOriginal dest = caller Current dest = "
1945 RangeBegin = RangeEnd =
nullptr;
1949 bool SeenThrowableInstInBB =
false;
1957 SeenThrowableInstInBB =
true;
1962 RecordCallerMismatchRange(EHPadStack.
back());
1967 else if (EHPadStack.
empty() || EHPadStack.
back() == FakeCallerBB ||
1976 RangeBegin = RangeEnd = &
MI;
1984 else if (
MI.getOpcode() == WebAssembly::DELEGATE)
1988 else if (!CLOpts.use_legacy_eh &&
1989 MI.getOpcode() == WebAssembly::END_TRY_TABLE)
1990 EHPadStack.
push_back(TryToEHPad[EndToBegin[&
MI]]);
1994 RecordCallerMismatchRange(EHPadStack.
back());
2000 if (UnwindDestToTryRanges.
empty())
2005 if (!CLOpts.use_legacy_eh)
2006 for (
auto &[UnwindDest,
_] : UnwindDestToTryRanges) {
2007 auto It = EHPadToTry.
find(UnwindDest);
2010 if (It != EHPadToTry.
end()) {
2011 auto *TryTable = It->second;
2012 auto *EndTryTable = BeginToEnd[TryTable];
2018 for (
auto &
P : UnwindDestToTryRanges) {
2019 NumCallUnwindMismatches +=
P.second.size();
2020 MachineBasicBlock *UnwindDest =
P.first;
2021 auto &TryRanges =
P.second;
2023 for (
auto Range : TryRanges) {
2024 MachineInstr *RangeBegin =
nullptr, *RangeEnd =
nullptr;
2025 std::tie(RangeBegin, RangeEnd) =
Range;
2034 if (UnwindDest != getFakeCallerBlock(MF)) {
2035 MachineBasicBlock *EHPad =
nullptr;
2037 if (Succ->isEHPad()) {
2046 if (CLOpts.use_legacy_eh)
2047 addNestedTryDelegate(RangeBegin, RangeEnd, UnwindDest);
2049 addNestedTryTable(RangeBegin, RangeEnd, UnwindDest);
2056bool WebAssemblyCFGStackifyImpl::fixCatchUnwindMismatches(
MachineFunction &MF) {
2161 auto HasUnwindDest = [&](
const MachineBasicBlock *EHPad) {
2164 for (
auto I = InvokeBB->succ_begin(),
E = InvokeBB->succ_end();
I !=
E; ++
I)
2166 return std::next(
I) !=
E;
2172 auto GetUnwindDest = [&](
const MachineBasicBlock *EHPad) {
2175 for (
auto I = InvokeBB->succ_begin(),
E = InvokeBB->succ_end();
I !=
E;
2178 auto *
Next = std::next(
I);
2188 MapVector<MachineBasicBlock *, MachineBasicBlock *> EHPadToUnwindDest;
2194 }
else if (
MI.getOpcode() == WebAssembly::DELEGATE) {
2206 else if (EHPadStack.
empty() && HasUnwindDest(EHPad)) {
2208 <<
"'s unwind destination does not exist anymore"
2214 else if (!EHPadStack.
empty() && EHPadStack.
back() != FakeCallerBB &&
2215 !HasUnwindDest(EHPad)) {
2216 EHPadToUnwindDest[EHPad] = getFakeCallerBlock(MF);
2218 <<
"- Catch unwind mismatch:\nEHPad = " <<
getBBName(EHPad)
2219 <<
" Original dest = caller Current dest = "
2225 else if (!EHPadStack.
empty() && HasUnwindDest(EHPad)) {
2226 auto *UnwindDest = GetUnwindDest(EHPad);
2227 if (EHPadStack.
back() != UnwindDest) {
2228 EHPadToUnwindDest[EHPad] = UnwindDest;
2230 <<
getBBName(EHPad) <<
" Original dest = "
2231 <<
getBBName(UnwindDest) <<
" Current dest = "
2242 if (EHPadToUnwindDest.
empty())
2247 for (
auto &[
_, UnwindDest] : EHPadToUnwindDest) {
2248 auto It = EHPadToTry.
find(UnwindDest);
2250 if (It != EHPadToTry.
end()) {
2251 auto *TryTable = It->second;
2252 auto *EndTryTable = BeginToEnd[TryTable];
2257 NumCatchUnwindMismatches += EHPadToUnwindDest.size();
2258 SmallPtrSet<MachineBasicBlock *, 4> NewEndTryBBs;
2260 for (
auto &[EHPad, UnwindDest] : EHPadToUnwindDest) {
2261 MachineInstr *Try = EHPadToTry[EHPad];
2262 MachineInstr *EndTry = BeginToEnd[Try];
2263 if (CLOpts.use_legacy_eh) {
2264 addNestedTryDelegate(Try, EndTry, UnwindDest);
2267 addNestedTryTable(Try, EndTry, UnwindDest);
2271 if (!CLOpts.use_legacy_eh)
2318 for (
auto &
MBB : MF) {
2319 for (
auto &
MI :
MBB) {
2320 if (
MI.isTerminator()) {
2321 for (
auto &MO :
MI.operands()) {
2322 if (MO.isMBB() && NewEndTryBBs.
count(MO.getMBB())) {
2323 auto *BrDest = MO.getMBB();
2324 bool FoundEndBlock =
false;
2325 for (; std::next(BrDest->getIterator()) != MF.end();
2326 BrDest = BrDest->getNextNode()) {
2327 for (
const auto &
MI : *BrDest) {
2328 if (
MI.getOpcode() == WebAssembly::END_BLOCK) {
2329 FoundEndBlock =
true;
2347void WebAssemblyCFGStackifyImpl::recalculateScopeTops(
MachineFunction &MF) {
2357 switch (
MI.getOpcode()) {
2358 case WebAssembly::END_BLOCK:
2359 case WebAssembly::END_LOOP:
2360 case WebAssembly::END_TRY:
2361 case WebAssembly::END_TRY_TABLE:
2362 case WebAssembly::DELEGATE:
2365 case WebAssembly::CATCH_LEGACY:
2366 case WebAssembly::CATCH_ALL_LEGACY:
2381void WebAssemblyCFGStackifyImpl::fixEndsAtEndOfFunction(
MachineFunction &MF) {
2382 const auto &MFI = *MF.
getInfo<WebAssemblyFunctionInfo>();
2384 if (MFI.getResults().empty())
2390 MFI.getResults().size() > 1
2391 ? WebAssembly::BlockType::Multivalue
2401 MachineInstr &
MI = *It++;
2402 if (
MI.isPosition() ||
MI.isDebugInstr())
2404 switch (
MI.getOpcode()) {
2405 case WebAssembly::END_TRY: {
2409 auto *EHPad = TryToEHPad.
lookup(EndToBegin[&
MI]);
2413 if (NextIt != EHPad->
rend())
2417 case WebAssembly::END_BLOCK:
2418 case WebAssembly::END_LOOP:
2419 case WebAssembly::END_TRY_TABLE:
2420 case WebAssembly::DELEGATE:
2421 EndToBegin[&
MI]->getOperand(0).setImm(int32_t(RetType));
2433 while (!Worklist.
empty())
2443 TII.get(WebAssembly::END_FUNCTION));
2469 std::vector<MachineInstr *> EndTryTables;
2470 for (
auto &
MBB : MF)
2471 for (
auto &
MI :
MBB)
2472 if (
MI.getOpcode() == WebAssembly::END_TRY_TABLE)
2473 EndTryTables.push_back(&
MI);
2475 for (
auto *EndTryTable : EndTryTables) {
2478 MF.
insert(
MBB->getIterator(), NewEndTryTableBB);
2479 auto SplitPos = std::next(EndTryTable->
getIterator());
2480 NewEndTryTableBB->splice(NewEndTryTableBB->end(),
MBB,
MBB->begin(),
2482 NewEndTryTableBB->addSuccessor(
MBB);
2484 TII.get(WebAssembly::UNREACHABLE));
2494 for (
auto &
MBB : MF)
2495 placeLoopMarker(
MBB);
2497 for (
auto &
MBB : MF) {
2501 if (CLOpts.use_legacy_eh)
2502 placeTryMarker(
MBB);
2504 placeTryTableMarker(
MBB);
2508 placeBlockMarker(
MBB);
2513 const auto &
TII = *MF.getSubtarget<WebAssemblySubtarget>().getInstrInfo();
2520 fixCatchUnwindMismatches(MF);
2521 fixCallUnwindMismatches(MF);
2524 recalculateScopeTops(MF);
2528unsigned WebAssemblyCFGStackifyImpl::getBranchDepth(
2529 const SmallVectorImpl<EndMarkerInfo> &Stack,
const MachineBasicBlock *
MBB) {
2540unsigned WebAssemblyCFGStackifyImpl::getDelegateDepth(
2541 const SmallVectorImpl<EndMarkerInfo> &Stack,
const MachineBasicBlock *
MBB) {
2542 if (
MBB == FakeCallerBB)
2543 return Stack.size();
2549 return getBranchDepth(Stack,
MBB);
2565 const MachineInstr *EndTry = BeginToEnd[EHPadToTry[
MBB]];
2567 if (
X.first == EndTry->
getParent() &&
X.second == EndTry)
2575unsigned WebAssemblyCFGStackifyImpl::getRethrowDepth(
2576 const SmallVectorImpl<EndMarkerInfo> &Stack,
2577 const MachineBasicBlock *EHPadToRethrow) {
2580 const MachineInstr *
End =
X.second;
2581 if (
End->getOpcode() == WebAssembly::END_TRY) {
2582 auto *EHPad = TryToEHPad[EndToBegin[
End]];
2583 if (EHPadToRethrow == EHPad)
2592void WebAssemblyCFGStackifyImpl::rewriteDepthImmediates(
MachineFunction &MF) {
2596 auto RewriteOperands = [&](MachineInstr &
MI) {
2598 SmallVector<MachineOperand, 4>
Ops(
MI.operands());
2599 while (
MI.getNumOperands() > 0)
2600 MI.removeOperand(
MI.getNumOperands() - 1);
2601 for (
auto MO :
Ops) {
2603 if (
MI.getOpcode() == WebAssembly::DELEGATE)
2605 else if (
MI.getOpcode() == WebAssembly::RETHROW)
2610 MI.addOperand(MF, MO);
2616 switch (
MI.getOpcode()) {
2617 case WebAssembly::BLOCK:
2618 case WebAssembly::TRY:
2619 assert(ScopeTops[
Stack.back().first->getNumber()]->getNumber() <=
2621 "Block/try/try_table marker should be balanced");
2625 case WebAssembly::TRY_TABLE:
2626 assert(ScopeTops[
Stack.back().first->getNumber()]->getNumber() <=
2628 "Block/try/try_table marker should be balanced");
2630 RewriteOperands(
MI);
2633 case WebAssembly::LOOP:
2634 assert(
Stack.back().first == &
MBB &&
"Loop top should be balanced");
2638 case WebAssembly::END_BLOCK:
2639 case WebAssembly::END_TRY:
2640 case WebAssembly::END_TRY_TABLE:
2644 case WebAssembly::END_LOOP:
2648 case WebAssembly::DELEGATE:
2649 RewriteOperands(
MI);
2654 if (
MI.isTerminator())
2655 RewriteOperands(
MI);
2660 assert(
Stack.empty() &&
"Control flow should be balanced");
2663void WebAssemblyCFGStackifyImpl::cleanupFunctionData(
MachineFunction &MF) {
2666 AppendixBB = FakeCallerBB = CallerTrampolineBB =
nullptr;
2669bool WebAssemblyCFGStackifyImpl::runOnMachineFunction(
MachineFunction &MF) {
2671 "********** Function: "
2676 ExceptionHandling::Wasm;
2686 if (UsesWasmEH && CLOpts.use_legacy_eh)
2687 removeUnnecessaryInstrs(MF);
2690 rewriteDepthImmediates(MF);
2694 fixEndsAtEndOfFunction(MF);
2697 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
2700 cleanupFunctionData(MF);
2702 MF.
getInfo<WebAssemblyFunctionInfo>()->setCFGStackified();
2706bool WebAssemblyCFGStackifyLegacy::runOnMachineFunction(
MachineFunction &MF) {
2707 MachineDominatorTree &MDT =
2708 getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
2709 MachineLoopInfo &MLI = getAnalysis<MachineLoopInfoWrapperPass>().getLI();
2710 WebAssemblyExceptionInfo &WEI =
2711 getAnalysis<WebAssemblyExceptionInfoWrapperPass>().getWEI();
2712 WebAssemblyCFGStackifyImpl Impl(
2713 MF.
getSubtarget<WebAssemblySubtarget>().getCLOpts(), MDT, MLI, WEI);
2714 return Impl.runOnMachineFunction(MF);
2724 WebAssemblyCFGStackifyImpl Impl(
2726 return Impl.runOnMachineFunction(MF)
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo & TII
static const Function * getParent(const Value *V)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Module.h This file contains the declarations for the Module class.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
SmallVector< MachineOperand, 4 > Cond
This file implements a map that provides insertion order iteration.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
MachineRegisterInfo & MRI
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static std::string getBBName(const MachineBasicBlock *MBB)
static bool explicitlyBranchesTo(MachineBasicBlock *Pred, MachineBasicBlock *MBB)
Test whether Pred has any terminators explicitly branching to MBB, as opposed to falling through.
static void addUnreachableAfterTryTables(MachineFunction &MF, const WebAssemblyInstrInfo &TII)
static MachineBasicBlock::iterator getLatestInsertPos(MachineBasicBlock *MBB, const Container &BeforeSet, const Container &AfterSet)
static void splitEndLoopBB(MachineBasicBlock *EndTryTableBB)
static void appendEndToFunction(MachineFunction &MF, const WebAssemblyInstrInfo &TII)
static void unstackifyVRegsUsedInSplitBB(MachineBasicBlock &MBB, MachineBasicBlock &Split)
static MachineBasicBlock::iterator getEarliestInsertPos(MachineBasicBlock *MBB, const Container &BeforeSet, const Container &AfterSet)
This file implements WebAssemblyException information analysis.
This file declares WebAssembly-specific per-machine-function information.
This file implements regions used in CFGSort and CFGStackify.
This file declares the WebAssembly-specific subclass of TargetSubtarget.
This file contains the declaration of the WebAssembly-specific type parsing utility functions.
This file contains the declaration of the WebAssembly-specific utility functions.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end.
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify=false) const override
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
AnalysisUsage & addRequired()
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
iterator find(const_arg_type_t< KeyT > Val)
bool erase(const KeyT &Val)
ValueT lookup(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or a default constructed value if no such entry exists.
NodeT * findNearestCommonDominator(NodeT *A, NodeT *B) const
Find nearest common dominator basic block for basic block A and B.
FunctionPass class - This class is used to implement most global optimizations.
bool hasPersonalityFn() const
Check whether this function has a personality function.
Module * getParent()
Get the module that this global value is contained inside of...
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
LLVM_ABI bool hasEHPadSuccessor() const
bool isEHPad() const
Returns true if the block is a landing pad.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
LLVM_ABI void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
LLVM_ABI bool isPredecessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a predecessor of this block.
LLVM_ABI DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any debug instructions.
pred_iterator pred_begin()
MachineInstrBundleIterator< MachineInstr, true > reverse_iterator
LLVM_ABI DebugLoc findPrevDebugLoc(instr_iterator MBBI)
Find the previous valid DebugLoc preceding MBBI, skipping any debug instructions.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
LLVM_ABI DebugLoc findBranchDebugLoc()
Find and return the merged DebugLoc of the branch instructions of the block.
iterator_range< succ_iterator > successors()
reverse_iterator rbegin()
iterator_range< pred_iterator > predecessors()
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineInstrBundleIterator< MachineInstr > iterator
Analysis pass which computes a MachineDominatorTree.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
void push_back(MachineBasicBlock *MBB)
reverse_iterator rbegin()
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
void deleteMachineBasicBlock(MachineBasicBlock *MBB)
DeleteMachineBasicBlock - Delete the given MachineBasicBlock.
Function & getFunction()
Return the LLVM function that this machine code represents.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
const MachineBasicBlock & back() const
BasicBlockListType::iterator iterator
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
void RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)
RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them.
const MachineBasicBlock & front() const
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
void insert(iterator MBBI, MachineBasicBlock *MBB)
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned TargetFlags=0) const
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
Analysis pass that exposes the MachineLoopInfo for a machine function.
MachineOperand class - Representation of each machine instruction operand.
static MachineOperand CreateImm(int64_t Val)
void setTargetFlags(unsigned F)
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
void invalidateLiveness()
invalidateLiveness - Indicates that register liveness is no longer being tracked accurately.
ExceptionHandling getExceptionModel() const
Returns the exception model recorded by the "exception-model" module flag, or the target's default ex...
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Wrapper class representing virtual and physical registers.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
WebAssemblyException * getExceptionFor(const MachineBasicBlock *MBB) const
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
const WebAssemblyOptions & getCLOpts() const
self_iterator getIterator()
Pass manager infrastructure for declaring and invalidating analyses.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI)
Test whether MI is a child of some other node in an expression tree.
bool isArgument(unsigned Opc)
bool isCatchAll(unsigned Opc)
bool isMarker(unsigned Opc)
unsigned getCopyOpcodeForRegClass(const TargetRegisterClass *RC)
Returns the appropriate copy opcode for the given register class.
wasm::ValType toValType(MVT Type)
MachineInstr * findCatch(MachineBasicBlock *EHPad)
Find a catch instruction from an EH pad.
bool isCatch(unsigned Opc)
BlockType
Used as immediate MachineOperands for block signatures.
bool mayThrow(const MachineInstr &MI)
NodeAddr< UseNode * > Use
@ WASM_OPCODE_CATCH_ALL_REF
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
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...
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
FunctionPass * createWebAssemblyCFGStackifyLegacyPass()
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
@ End
Run the machine verifier once, at the end of the pipeline.