46#define DEBUG_TYPE "wasm-cfg-stackify"
48STATISTIC(NumCallUnwindMismatches,
"Number of call unwind mismatches found");
49STATISTIC(NumCatchUnwindMismatches,
"Number of catch unwind mismatches found");
52class WebAssemblyCFGStackifyImpl {
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(MachineDominatorTree &MDT, MachineLoopInfo &MLI,
169 WebAssemblyExceptionInfo &WEI)
170 : MDT(MDT), MLI(MLI), WEI(WEI) {}
176 StringRef getPassName()
const override {
return "WebAssembly CFG Stackify"; }
178 void getAnalysisUsage(AnalysisUsage &AU)
const override {
181 AU.
addRequired<WebAssemblyExceptionInfoWrapperPass>();
188 WebAssemblyCFGStackifyLegacy() : MachineFunctionPass(ID) {}
192char WebAssemblyCFGStackifyLegacy::ID = 0;
195 "Insert BLOCK/LOOP/TRY/TRY_TABLE markers for WebAssembly scopes",
false,
199 return new WebAssemblyCFGStackifyLegacy();
211 if (MO.isMBB() && MO.getMBB() ==
MBB)
221template <
typename Container>
224 const Container &AfterSet) {
225 auto InsertPos =
MBB->end();
226 while (InsertPos !=
MBB->begin()) {
227 if (BeforeSet.count(&*std::prev(InsertPos))) {
230 for (
auto Pos = InsertPos,
E =
MBB->begin(); Pos !=
E; --Pos)
231 assert(!AfterSet.count(&*std::prev(Pos)));
245template <
typename Container>
248 const Container &AfterSet) {
249 auto InsertPos =
MBB->begin();
250 while (InsertPos !=
MBB->end()) {
251 if (AfterSet.count(&*InsertPos)) {
254 for (
auto Pos = InsertPos,
E =
MBB->end(); Pos !=
E; ++Pos)
255 assert(!BeforeSet.count(&*Pos));
264void WebAssemblyCFGStackifyImpl::registerScope(
MachineInstr *Begin,
266 BeginToEnd[Begin] =
End;
267 EndToBegin[
End] = Begin;
271void WebAssemblyCFGStackifyImpl::registerTryScope(MachineInstr *Begin,
273 MachineBasicBlock *EHPad) {
274 registerScope(Begin,
End);
275 TryToEHPad[Begin] = EHPad;
276 EHPadToTry[EHPad] = Begin;
279void WebAssemblyCFGStackifyImpl::unregisterScope(MachineInstr *Begin) {
281 MachineInstr *
End = BeginToEnd[Begin];
283 BeginToEnd.
erase(Begin);
285 MachineBasicBlock *EHPad = TryToEHPad.
lookup(Begin);
288 TryToEHPad.
erase(Begin);
289 EHPadToTry.
erase(EHPad);
296void WebAssemblyCFGStackifyImpl::placeBlockMarker(MachineBasicBlock &
MBB) {
299 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
300 const auto &MFI = *MF.
getInfo<WebAssemblyFunctionInfo>();
305 MachineBasicBlock *Header =
nullptr;
306 bool IsBranchedTo =
false;
309 if (Pred->getNumber() < MBBNumber) {
320 assert(&
MBB != &MF.
front() &&
"Header blocks shouldn't have predecessors");
326 if (MachineBasicBlock *ScopeTop = ScopeTops[
I->getNumber()]) {
327 if (ScopeTop->getNumber() > Header->getNumber()) {
329 I = std::next(ScopeTop->getIterator());
341 SmallPtrSet<const MachineInstr *, 4> BeforeSet;
343 SmallPtrSet<const MachineInstr *, 4> AfterSet;
344 for (
const auto &
MI : *Header) {
348 if (
MI.getOpcode() == WebAssembly::LOOP) {
349 auto *LoopBottom = BeginToEnd[&
MI]->getParent()->getPrevNode();
362 if (
MI.getOpcode() == WebAssembly::BLOCK ||
363 MI.getOpcode() == WebAssembly::TRY ||
364 MI.getOpcode() == WebAssembly::TRY_TABLE) {
375 if (
MI.getOpcode() == WebAssembly::END_BLOCK ||
376 MI.getOpcode() == WebAssembly::END_LOOP ||
377 MI.getOpcode() == WebAssembly::END_TRY ||
378 MI.getOpcode() == WebAssembly::END_TRY_TABLE)
383 if (
MI.isTerminator())
388 for (
auto I = Header->getFirstTerminator(),
E = Header->begin();
I !=
E;
390 if (std::prev(
I)->isDebugInstr() || std::prev(
I)->isPosition())
392 if (WebAssembly::isChild(*std::prev(
I), MFI))
393 AfterSet.
insert(&*std::prev(
I));
399 WebAssembly::BlockType
ReturnType = WebAssembly::BlockType::Void;
401 MachineInstr *Begin =
402 BuildMI(*Header, InsertPos, Header->findDebugLoc(InsertPos),
403 TII.get(WebAssembly::BLOCK))
404 .
addImm(int64_t(ReturnType));
409 for (
auto &
MI :
MBB) {
412 if (
MI.getOpcode() == WebAssembly::LOOP)
425 if (
MI.getOpcode() == WebAssembly::END_LOOP ||
426 MI.getOpcode() == WebAssembly::END_TRY) {
427 if (EndToBegin[&
MI]->
getParent()->getNumber() >= Header->getNumber())
439 TII.get(WebAssembly::END_BLOCK));
440 registerScope(Begin,
End);
443 updateScopeTops(Header, &
MBB);
447void WebAssemblyCFGStackifyImpl::placeLoopMarker(MachineBasicBlock &
MBB) {
449 SortRegionInfo SRI(MLI, WEI);
450 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
458 MachineBasicBlock *Bottom = SRI.getBottom(
Loop);
460 if (Iter == MF.
end()) {
461 getAppendixBlock(MF);
464 MachineBasicBlock *AfterLoop = &*Iter;
467 SmallPtrSet<const MachineInstr *, 4> BeforeSet;
468 SmallPtrSet<const MachineInstr *, 4> AfterSet;
469 for (
const auto &
MI :
MBB) {
472 if (
MI.getOpcode() == WebAssembly::END_LOOP)
483 TII.get(WebAssembly::LOOP))
484 .
addImm(int64_t(WebAssembly::BlockType::Void));
490 for (
const auto &
MI :
MBB)
492 if (
MI.getOpcode() == WebAssembly::END_LOOP)
501 : (*AfterLoop->pred_rbegin())->findBranchDebugLoc();
503 BuildMI(*AfterLoop, InsertPos, EndDL,
TII.get(WebAssembly::END_LOOP));
504 registerScope(Begin,
End);
508 "With block sorting the outermost loop for a block should be first.");
509 updateScopeTops(&
MBB, AfterLoop);
512void WebAssemblyCFGStackifyImpl::placeTryMarker(MachineBasicBlock &
MBB) {
515 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
516 SortRegionInfo SRI(MLI, WEI);
517 const auto &MFI = *MF.
getInfo<WebAssemblyFunctionInfo>();
520 MachineBasicBlock *Header =
nullptr;
523 if (Pred->getNumber() < MBBNumber) {
526 "Explicit branch to an EH pad!");
536 MachineBasicBlock *Bottom = SRI.getBottom(WE);
538 if (Iter == MF.
end()) {
539 getAppendixBlock(MF);
542 MachineBasicBlock *Cont = &*Iter;
547 if (MachineBasicBlock *ScopeTop = ScopeTops[
I->getNumber()]) {
548 if (ScopeTop->getNumber() > Header->getNumber()) {
550 I = std::next(ScopeTop->getIterator());
562 SmallPtrSet<const MachineInstr *, 4> BeforeSet;
564 SmallPtrSet<const MachineInstr *, 4> AfterSet;
565 for (
const auto &
MI : *Header) {
569 if (
MI.getOpcode() == WebAssembly::LOOP) {
570 auto *LoopBottom = BeginToEnd[&
MI]->getParent()->getPrevNode();
581 if (
MI.getOpcode() == WebAssembly::BLOCK ||
582 MI.getOpcode() == WebAssembly::TRY)
587 if (
MI.getOpcode() == WebAssembly::END_BLOCK ||
588 MI.getOpcode() == WebAssembly::END_LOOP ||
589 MI.getOpcode() == WebAssembly::END_TRY)
594 if (
MI.isTerminator())
603 MachineInstr *ThrowingCall =
nullptr;
605 auto TermPos = Header->getFirstTerminator();
606 if (TermPos == Header->end() ||
607 TermPos->getOpcode() != WebAssembly::RETHROW) {
625 : Header->getFirstTerminator();
626 for (
auto I = SearchStartPt,
E = Header->begin();
I !=
E; --
I) {
627 if (std::prev(I)->isDebugInstr() || std::prev(I)->isPosition())
629 if (WebAssembly::isChild(*std::prev(I), MFI))
630 AfterSet.insert(&*std::prev(I));
637 MachineInstr *Begin =
638 BuildMI(*Header, InsertPos, Header->findDebugLoc(InsertPos),
639 TII.get(WebAssembly::TRY))
640 .
addImm(int64_t(WebAssembly::BlockType::Void));
645 for (
const auto &
MI : *Cont) {
648 if (
MI.getOpcode() == WebAssembly::LOOP)
653 if (
MI.getOpcode() == WebAssembly::END_TRY)
661 if (
MI.getOpcode() == WebAssembly::END_LOOP) {
664 if (EndToBegin[&
MI]->
getParent()->getNumber() > Header->getNumber())
678 TII.get(WebAssembly::END_TRY));
679 registerTryScope(Begin,
End, &
MBB);
692 for (
auto *
End : {&
MBB, Cont})
693 updateScopeTops(Header,
End);
696void WebAssemblyCFGStackifyImpl::placeTryTableMarker(MachineBasicBlock &
MBB) {
699 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
700 SortRegionInfo SRI(MLI, WEI);
701 const auto &MFI = *MF.
getInfo<WebAssemblyFunctionInfo>();
704 MachineBasicBlock *Header =
nullptr;
707 if (Pred->getNumber() < MBBNumber) {
710 "Explicit branch to an EH pad!");
721 MachineBasicBlock *Bottom = SRI.getBottom(WE);
723 if (Iter == MF.
end())
725 MachineBasicBlock *Cont = &*Iter;
730 if (MachineBasicBlock *ScopeTop = ScopeTops[
I->getNumber()]) {
731 if (ScopeTop->getNumber() > Header->getNumber()) {
733 I = std::next(ScopeTop->getIterator());
745 SmallPtrSet<const MachineInstr *, 4> BeforeSet;
747 SmallPtrSet<const MachineInstr *, 4> AfterSet;
748 for (
const auto &
MI : *Header) {
752 if (
MI.getOpcode() == WebAssembly::LOOP) {
753 auto *LoopBottom = BeginToEnd[&
MI]->getParent()->getPrevNode();
764 if (
MI.getOpcode() == WebAssembly::BLOCK ||
765 MI.getOpcode() == WebAssembly::TRY_TABLE)
770 if (
MI.getOpcode() == WebAssembly::END_BLOCK ||
771 MI.getOpcode() == WebAssembly::END_LOOP ||
772 MI.getOpcode() == WebAssembly::END_TRY_TABLE)
777 if (
MI.isTerminator())
786 MachineInstr *ThrowingCall =
nullptr;
788 auto TermPos = Header->getFirstTerminator();
789 if (TermPos == Header->end() ||
790 TermPos->getOpcode() != WebAssembly::RETHROW) {
808 : Header->getFirstTerminator();
809 for (
auto I = SearchStartPt,
E = Header->begin();
I !=
E; --
I) {
810 if (std::prev(I)->isDebugInstr() || std::prev(I)->isPosition())
812 if (WebAssembly::isChild(*std::prev(I), MFI))
813 AfterSet.insert(&*std::prev(I));
832 MachineInstrBuilder BlockMIB =
833 BuildMI(*Header, InsertPos, Header->findDebugLoc(InsertPos),
834 TII.get(WebAssembly::BLOCK));
836 MachineInstrBuilder TryTableMIB =
837 BuildMI(*Header, InsertPos, Header->findDebugLoc(InsertPos),
838 TII.get(WebAssembly::TRY_TABLE))
839 .
addImm(int64_t(WebAssembly::BlockType::Void))
841 auto *TryTable = TryTableMIB.
getInstr();
847 *MF.
getSubtarget<WebAssemblySubtarget>().getTargetLowering();
848 WebAssembly::BlockType PtrTy =
850 ? WebAssembly::BlockType::I32
851 : WebAssembly::BlockType::I64;
852 auto *
Catch = WebAssembly::findCatch(&
MBB);
853 switch (
Catch->getOpcode()) {
854 case WebAssembly::CATCH:
858 BlockMIB.
addImm(int64_t(PtrTy));
860 for (
const auto &Use :
Catch->uses()) {
867 case WebAssembly::CATCH_REF:
872 BlockMIB.
addImm(int64_t(WebAssembly::BlockType::Multivalue));
875 for (
const auto &Use :
Catch->uses()) {
881 case WebAssembly::CATCH_ALL:
883 BlockMIB.
addImm(int64_t(WebAssembly::BlockType::Void));
887 case WebAssembly::CATCH_ALL_REF:
889 BlockMIB.
addImm(int64_t(WebAssembly::BlockType::Exnref));
899 for (
const auto &
MI :
MBB) {
902 if (
MI.getOpcode() == WebAssembly::LOOP)
910 if (
MI.getOpcode() == WebAssembly::END_LOOP) {
911 if (EndToBegin[&
MI]->
getParent()->getNumber() >= Header->getNumber())
923 if (WebAssembly::isCatch(
MI.getOpcode()))
930 MachineInstr *EndTryTable =
932 TII.get(WebAssembly::END_TRY_TABLE));
933 registerTryScope(TryTable, EndTryTable, &
MBB);
934 MachineInstr *EndBlock =
936 TII.get(WebAssembly::END_BLOCK));
937 registerScope(
Block, EndBlock);
979 for (
auto *
End : {&
MBB, Cont})
980 updateScopeTops(Header,
End);
983void WebAssemblyCFGStackifyImpl::removeUnnecessaryInstrs(
MachineFunction &MF) {
984 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
1019 for (
auto &
MBB : MF) {
1023 MachineBasicBlock *
TBB =
nullptr, *FBB =
nullptr;
1024 SmallVector<MachineOperand, 4>
Cond;
1027 MachineBasicBlock *Cont = &
MBB;
1029 MachineInstr *Try = EHPadToTry[Cont];
1030 MachineInstr *EndTry = BeginToEnd[Try];
1044 (!
Cond.
empty() && FBB && FBB == Cont))) {
1045 bool ErasedUncondBr =
false;
1046 (void)ErasedUncondBr;
1047 for (
auto I = EHPadLayoutPred->
end(),
E = EHPadLayoutPred->
begin();
1049 auto PrevI = std::prev(
I);
1050 if (PrevI->isTerminator()) {
1051 assert(PrevI->getOpcode() == WebAssembly::BR);
1052 PrevI->eraseFromParent();
1053 ErasedUncondBr =
true;
1057 assert(ErasedUncondBr &&
"Unconditional branch not erased!");
1073 for (
auto &
MBB : MF) {
1074 for (
auto &
MI :
MBB) {
1075 if (
MI.getOpcode() != WebAssembly::TRY)
1077 MachineInstr *Try = &
MI, *EndTry = BeginToEnd[Try];
1078 if (EndTry->getOpcode() == WebAssembly::DELEGATE)
1081 MachineBasicBlock *TryBB = Try->
getParent();
1082 MachineBasicBlock *Cont = EndTry->
getParent();
1084 for (
auto B = Try->
getIterator(),
E = std::next(EndTry->getIterator());
1086 std::prev(
B)->getOpcode() == WebAssembly::BLOCK &&
1087 E->getOpcode() == WebAssembly::END_BLOCK &&
1088 std::prev(
B)->getOperand(0).getImm() == RetType;
1095 for (
auto *
MI : ToDelete) {
1096 if (
MI->getOpcode() == WebAssembly::BLOCK)
1097 unregisterScope(
MI);
1098 MI->eraseFromParent();
1111 for (
auto &
MI : Split) {
1112 for (
auto &MO :
MI.explicit_uses()) {
1113 if (!MO.isReg() || MO.getReg().isPhysical())
1115 if (
MachineInstr *Def = MRI.getUniqueVRegDef(MO.getReg()))
1116 if (Def->getParent() == &
MBB)
1117 MFI.unstackifyVReg(MO.getReg());
1150 if (!MFI.isVRegStackified(TeeReg)) {
1152 MFI.unstackifyVReg(DefReg);
1158 MI.eraseFromParent();
1165void WebAssemblyCFGStackifyImpl::addNestedTryDelegate(
1166 MachineInstr *RangeBegin, MachineInstr *RangeEnd,
1167 MachineBasicBlock *UnwindDest) {
1168 auto *BeginBB = RangeBegin->
getParent();
1171 const auto &MFI = *MF.
getInfo<WebAssemblyFunctionInfo>();
1172 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
1176 SmallPtrSet<const MachineInstr *, 4> AfterSet;
1177 AfterSet.
insert(RangeBegin);
1180 if (std::prev(
I)->isDebugInstr() || std::prev(
I)->isPosition())
1182 if (WebAssembly::isChild(*std::prev(
I), MFI))
1183 AfterSet.
insert(&*std::prev(
I));
1190 BeginBB, SmallPtrSet<const MachineInstr *, 4>(), AfterSet);
1192 TII.get(WebAssembly::TRY))
1193 .
addImm(int64_t(WebAssembly::BlockType::Void));
1199 if (UnwindDest != FakeCallerBB)
1202 auto SplitPos = std::next(RangeEnd->
getIterator());
1203 if (SplitPos == EndBB->end()) {
1206 MF.
insert(std::next(EndBB->getIterator()), DelegateBB);
1207 EndBB->addSuccessor(DelegateBB);
1217 bool CatchAfterSplit =
false;
1218 if (EndBB->isEHPad()) {
1221 if (WebAssembly::isCatch(
I->getOpcode())) {
1222 CatchAfterSplit =
true;
1228 MachineBasicBlock *PreBB =
nullptr, *PostBB =
nullptr;
1229 if (!CatchAfterSplit) {
1248 PostBB->splice(PostBB->end(), PreBB, SplitPos, PreBB->
end());
1249 PostBB->transferSuccessors(PreBB);
1265 assert(EndBB->isEHPad());
1268 MF.
insert(PostBB->getIterator(), PreBB);
1269 MF.
insert(PostBB->getIterator(), DelegateBB);
1270 PreBB->
splice(PreBB->
end(), PostBB, PostBB->begin(), SplitPos);
1282 TII.get(WebAssembly::DELEGATE))
1284 registerTryScope(Try, Delegate,
nullptr);
1303WebAssemblyCFGStackifyImpl::getTrampolineBlock(MachineBasicBlock *UnwindDest) {
1307 auto It = UnwindDestToTrampoline.
find(UnwindDest);
1308 if (It != UnwindDestToTrampoline.
end())
1313 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
1315 MachineInstr *
Block =
nullptr;
1316 MachineBasicBlock *TrampolineBB =
nullptr;
1319 if (UnwindDest == getFakeCallerBlock(MF)) {
1323 auto BeginPos = MF.
begin()->begin();
1324 while (WebAssembly::isArgument(BeginPos->getOpcode()))
1327 TII.get(WebAssembly::BLOCK))
1328 .
addImm(int64_t(WebAssembly::BlockType::Exnref));
1329 TrampolineBB = getCallerTrampolineBlock(MF);
1330 MachineBasicBlock *PrevBB = &*std::prev(CallerTrampolineBB->
getIterator());
1336 auto *TargetBeginTry = EHPadToTry[UnwindDest];
1337 auto *TargetEndTry = BeginToEnd[TargetBeginTry];
1338 auto *TargetBeginBB = TargetBeginTry->getParent();
1339 auto *TargetEndBB = TargetEndTry->getParent();
1341 Block =
BuildMI(*TargetBeginBB, std::next(TargetBeginTry->getIterator()),
1342 TargetBeginTry->getDebugLoc(),
TII.get(WebAssembly::BLOCK))
1343 .
addImm(int64_t(WebAssembly::BlockType::Exnref));
1345 EndDebugLoc = TargetEndTry->getDebugLoc();
1346 MF.
insert(TargetEndBB->getIterator(), TrampolineBB);
1352 MachineInstr *EndBlock =
1353 BuildMI(TrampolineBB, EndDebugLoc,
TII.get(WebAssembly::END_BLOCK));
1354 auto ExnReg = MRI.createVirtualRegister(&WebAssembly::EXNREFRegClass);
1355 BuildMI(TrampolineBB, EndDebugLoc,
TII.get(WebAssembly::CATCH_ALL_REF))
1357 BuildMI(TrampolineBB, EndDebugLoc,
TII.get(WebAssembly::THROW_REF))
1363 MachineBasicBlock *TrampolineLayoutPred = TrampolineBB->
getPrevNode();
1365 TII.get(WebAssembly::UNREACHABLE));
1367 registerScope(
Block, EndBlock);
1368 UnwindDestToTrampoline[UnwindDest] = TrampolineBB;
1369 return TrampolineBB;
1374void WebAssemblyCFGStackifyImpl::addNestedTryTable(
1375 MachineInstr *RangeBegin, MachineInstr *RangeEnd,
1376 MachineBasicBlock *UnwindDest) {
1377 auto *BeginBB = RangeBegin->
getParent();
1381 const auto &MFI = *MF.
getInfo<WebAssemblyFunctionInfo>();
1382 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
1385 auto *TrampolineBB = getTrampolineBlock(UnwindDest);
1389 SmallPtrSet<const MachineInstr *, 4> AfterSet;
1390 AfterSet.
insert(RangeBegin);
1393 if (std::prev(
I)->isDebugInstr() || std::prev(
I)->isPosition())
1395 if (WebAssembly::isChild(*std::prev(
I), MFI))
1396 AfterSet.
insert(&*std::prev(
I));
1403 BeginBB, SmallPtrSet<const MachineInstr *, 4>(), AfterSet);
1404 MachineInstr *TryTable =
1406 TII.get(WebAssembly::TRY_TABLE))
1407 .
addImm(int64_t(WebAssembly::BlockType::Void))
1416 auto SplitPos = std::next(RangeEnd->
getIterator());
1417 if (SplitPos == EndBB->end()) {
1420 MF.
insert(std::next(EndBB->getIterator()), EndTryTableBB);
1421 EndBB->addSuccessor(EndTryTableBB);
1431 bool CatchAfterSplit =
false;
1432 if (EndBB->isEHPad()) {
1435 if (WebAssembly::isCatch(
I->getOpcode())) {
1436 CatchAfterSplit =
true;
1442 MachineBasicBlock *PreBB =
nullptr, *PostBB =
nullptr;
1443 if (!CatchAfterSplit) {
1462 PostBB->splice(PostBB->end(), PreBB, SplitPos, PreBB->
end());
1463 PostBB->transferSuccessors(PreBB);
1479 assert(EndBB->isEHPad());
1482 MF.
insert(PostBB->getIterator(), PreBB);
1483 MF.
insert(PostBB->getIterator(), EndTryTableBB);
1484 PreBB->
splice(PreBB->
end(), PostBB, PostBB->begin(), SplitPos);
1496 TII.get(WebAssembly::END_TRY_TABLE));
1497 registerTryScope(TryTable, EndTryTable, TrampolineBB);
1549 MachineInstr *EndTryTable =
nullptr, *EndLoop =
nullptr;
1550 for (
auto &
MI :
reverse(*EndTryTableBB)) {
1551 if (
MI.getOpcode() == WebAssembly::END_TRY_TABLE) {
1555 if (EndTryTable &&
MI.getOpcode() == WebAssembly::END_LOOP) {
1565 auto SplitPos = std::next(EndLoop->getIterator());
1566 EndLoopBB->splice(EndLoopBB->end(), EndTryTableBB, EndTryTableBB->
begin(),
1568 EndLoopBB->addSuccessor(EndTryTableBB);
1574 std::string Name =
"bb.";
1576 if (
MBB->getBasicBlock()) {
1578 Name +=
MBB->getBasicBlock()->getName();
1583bool WebAssemblyCFGStackifyImpl::fixCallUnwindMismatches(
MachineFunction &MF) {
1830 using TryRange = std::pair<MachineInstr *, MachineInstr *>;
1832 MapVector<MachineBasicBlock *, SmallVector<TryRange, 4>>
1833 UnwindDestToTryRanges;
1839 bool SeenThrowableInstInBB =
false;
1841 if (WebAssembly::isTry(
MI.getOpcode()))
1843 else if (
MI.getOpcode() == WebAssembly::DELEGATE)
1845 else if (WebAssembly::WasmUseLegacyEH &&
1846 WebAssembly::isCatch(
MI.getOpcode()))
1848 else if (
MI.getOpcode() == WebAssembly::END_TRY_TABLE)
1889 EHPadStack.
push_back(TryToEHPad[EndToBegin[&
MI]]);
1896 !WebAssembly::mayThrow(
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;
1951 bool MayThrow = WebAssembly::mayThrow(
MI);
1957 SeenThrowableInstInBB =
true;
1961 else if (RangeEnd && WebAssembly::isMarker(
MI.getOpcode()))
1962 RecordCallerMismatchRange(EHPadStack.
back());
1967 else if (EHPadStack.
empty() || EHPadStack.
back() == FakeCallerBB ||
1976 RangeBegin = RangeEnd = &
MI;
1982 if (WebAssembly::isTry(
MI.getOpcode()))
1984 else if (
MI.getOpcode() == WebAssembly::DELEGATE)
1986 else if (WebAssembly::WasmUseLegacyEH &&
1987 WebAssembly::isCatch(
MI.getOpcode()))
1989 else if (!WebAssembly::WasmUseLegacyEH &&
1990 MI.getOpcode() == WebAssembly::END_TRY_TABLE)
1991 EHPadStack.
push_back(TryToEHPad[EndToBegin[&
MI]]);
1995 RecordCallerMismatchRange(EHPadStack.
back());
2001 if (UnwindDestToTryRanges.
empty())
2006 if (!WebAssembly::WasmUseLegacyEH)
2007 for (
auto &[UnwindDest,
_] : UnwindDestToTryRanges) {
2008 auto It = EHPadToTry.
find(UnwindDest);
2011 if (It != EHPadToTry.
end()) {
2012 auto *TryTable = It->second;
2013 auto *EndTryTable = BeginToEnd[TryTable];
2019 for (
auto &
P : UnwindDestToTryRanges) {
2020 NumCallUnwindMismatches +=
P.second.size();
2021 MachineBasicBlock *UnwindDest =
P.first;
2022 auto &TryRanges =
P.second;
2024 for (
auto Range : TryRanges) {
2025 MachineInstr *RangeBegin =
nullptr, *RangeEnd =
nullptr;
2026 std::tie(RangeBegin, RangeEnd) =
Range;
2035 if (UnwindDest != getFakeCallerBlock(MF)) {
2036 MachineBasicBlock *EHPad =
nullptr;
2038 if (Succ->isEHPad()) {
2047 if (WebAssembly::WasmUseLegacyEH)
2048 addNestedTryDelegate(RangeBegin, RangeEnd, UnwindDest);
2050 addNestedTryTable(RangeBegin, RangeEnd, UnwindDest);
2057bool WebAssemblyCFGStackifyImpl::fixCatchUnwindMismatches(
MachineFunction &MF) {
2162 auto HasUnwindDest = [&](
const MachineBasicBlock *EHPad) {
2165 for (
auto I = InvokeBB->succ_begin(),
E = InvokeBB->succ_end();
I !=
E; ++
I)
2167 return std::next(
I) !=
E;
2173 auto GetUnwindDest = [&](
const MachineBasicBlock *EHPad) {
2176 for (
auto I = InvokeBB->succ_begin(),
E = InvokeBB->succ_end();
I !=
E;
2179 auto *
Next = std::next(
I);
2189 MapVector<MachineBasicBlock *, MachineBasicBlock *> EHPadToUnwindDest;
2193 if (WebAssembly::isTry(
MI.getOpcode())) {
2195 }
else if (
MI.getOpcode() == WebAssembly::DELEGATE) {
2197 }
else if (WebAssembly::isCatch(
MI.getOpcode())) {
2202 if (WebAssembly::isCatchAll(
MI.getOpcode())) {
2207 else if (EHPadStack.
empty() && HasUnwindDest(EHPad)) {
2209 <<
"'s unwind destination does not exist anymore"
2215 else if (!EHPadStack.
empty() && EHPadStack.
back() != FakeCallerBB &&
2216 !HasUnwindDest(EHPad)) {
2217 EHPadToUnwindDest[EHPad] = getFakeCallerBlock(MF);
2219 <<
"- Catch unwind mismatch:\nEHPad = " <<
getBBName(EHPad)
2220 <<
" Original dest = caller Current dest = "
2226 else if (!EHPadStack.
empty() && HasUnwindDest(EHPad)) {
2227 auto *UnwindDest = GetUnwindDest(EHPad);
2228 if (EHPadStack.
back() != UnwindDest) {
2229 EHPadToUnwindDest[EHPad] = UnwindDest;
2231 <<
getBBName(EHPad) <<
" Original dest = "
2232 <<
getBBName(UnwindDest) <<
" Current dest = "
2243 if (EHPadToUnwindDest.
empty())
2248 for (
auto &[
_, UnwindDest] : EHPadToUnwindDest) {
2249 auto It = EHPadToTry.
find(UnwindDest);
2251 if (It != EHPadToTry.
end()) {
2252 auto *TryTable = It->second;
2253 auto *EndTryTable = BeginToEnd[TryTable];
2258 NumCatchUnwindMismatches += EHPadToUnwindDest.size();
2259 SmallPtrSet<MachineBasicBlock *, 4> NewEndTryBBs;
2261 for (
auto &[EHPad, UnwindDest] : EHPadToUnwindDest) {
2262 MachineInstr *Try = EHPadToTry[EHPad];
2263 MachineInstr *EndTry = BeginToEnd[Try];
2264 if (WebAssembly::WasmUseLegacyEH) {
2265 addNestedTryDelegate(Try, EndTry, UnwindDest);
2268 addNestedTryTable(Try, EndTry, UnwindDest);
2272 if (!WebAssembly::WasmUseLegacyEH)
2319 for (
auto &
MBB : MF) {
2320 for (
auto &
MI :
MBB) {
2321 if (
MI.isTerminator()) {
2322 for (
auto &MO :
MI.operands()) {
2323 if (MO.isMBB() && NewEndTryBBs.
count(MO.getMBB())) {
2324 auto *BrDest = MO.getMBB();
2325 bool FoundEndBlock =
false;
2326 for (; std::next(BrDest->getIterator()) != MF.end();
2327 BrDest = BrDest->getNextNode()) {
2328 for (
const auto &
MI : *BrDest) {
2329 if (
MI.getOpcode() == WebAssembly::END_BLOCK) {
2330 FoundEndBlock =
true;
2348void WebAssemblyCFGStackifyImpl::recalculateScopeTops(
MachineFunction &MF) {
2358 switch (
MI.getOpcode()) {
2359 case WebAssembly::END_BLOCK:
2360 case WebAssembly::END_LOOP:
2361 case WebAssembly::END_TRY:
2362 case WebAssembly::END_TRY_TABLE:
2363 case WebAssembly::DELEGATE:
2366 case WebAssembly::CATCH_LEGACY:
2367 case WebAssembly::CATCH_ALL_LEGACY:
2382void WebAssemblyCFGStackifyImpl::fixEndsAtEndOfFunction(
MachineFunction &MF) {
2383 const auto &MFI = *MF.
getInfo<WebAssemblyFunctionInfo>();
2385 if (MFI.getResults().empty())
2390 WebAssembly::BlockType RetType =
2391 MFI.getResults().size() > 1
2392 ? WebAssembly::BlockType::Multivalue
2393 : WebAssembly::BlockType(
2394 WebAssembly::toValType(MFI.getResults().front()));
2402 MachineInstr &
MI = *It++;
2403 if (
MI.isPosition() ||
MI.isDebugInstr())
2405 switch (
MI.getOpcode()) {
2406 case WebAssembly::END_TRY: {
2410 auto *EHPad = TryToEHPad.
lookup(EndToBegin[&
MI]);
2413 std::next(WebAssembly::findCatch(EHPad)->getReverseIterator());
2414 if (NextIt != EHPad->
rend())
2418 case WebAssembly::END_BLOCK:
2419 case WebAssembly::END_LOOP:
2420 case WebAssembly::END_TRY_TABLE:
2421 case WebAssembly::DELEGATE:
2422 EndToBegin[&
MI]->getOperand(0).setImm(int32_t(RetType));
2434 while (!Worklist.
empty())
2444 TII.get(WebAssembly::END_FUNCTION));
2470 std::vector<MachineInstr *> EndTryTables;
2471 for (
auto &
MBB : MF)
2472 for (
auto &
MI :
MBB)
2473 if (
MI.getOpcode() == WebAssembly::END_TRY_TABLE)
2474 EndTryTables.push_back(&
MI);
2476 for (
auto *EndTryTable : EndTryTables) {
2479 MF.
insert(
MBB->getIterator(), NewEndTryTableBB);
2480 auto SplitPos = std::next(EndTryTable->
getIterator());
2481 NewEndTryTableBB->splice(NewEndTryTableBB->end(),
MBB,
MBB->begin(),
2483 NewEndTryTableBB->addSuccessor(
MBB);
2485 TII.get(WebAssembly::UNREACHABLE));
2495 for (
auto &
MBB : MF)
2496 placeLoopMarker(
MBB);
2498 for (
auto &
MBB : MF) {
2502 if (WebAssembly::WasmUseLegacyEH)
2503 placeTryMarker(
MBB);
2505 placeTryTableMarker(
MBB);
2509 placeBlockMarker(
MBB);
2514 const auto &
TII = *MF.getSubtarget<WebAssemblySubtarget>().getInstrInfo();
2521 fixCatchUnwindMismatches(MF);
2522 fixCallUnwindMismatches(MF);
2525 recalculateScopeTops(MF);
2529unsigned WebAssemblyCFGStackifyImpl::getBranchDepth(
2530 const SmallVectorImpl<EndMarkerInfo> &Stack,
const MachineBasicBlock *
MBB) {
2541unsigned WebAssemblyCFGStackifyImpl::getDelegateDepth(
2542 const SmallVectorImpl<EndMarkerInfo> &Stack,
const MachineBasicBlock *
MBB) {
2543 if (
MBB == FakeCallerBB)
2544 return Stack.size();
2550 return getBranchDepth(Stack,
MBB);
2566 const MachineInstr *EndTry = BeginToEnd[EHPadToTry[
MBB]];
2568 if (
X.first == EndTry->
getParent() &&
X.second == EndTry)
2576unsigned WebAssemblyCFGStackifyImpl::getRethrowDepth(
2577 const SmallVectorImpl<EndMarkerInfo> &Stack,
2578 const MachineBasicBlock *EHPadToRethrow) {
2581 const MachineInstr *
End =
X.second;
2582 if (
End->getOpcode() == WebAssembly::END_TRY) {
2583 auto *EHPad = TryToEHPad[EndToBegin[
End]];
2584 if (EHPadToRethrow == EHPad)
2593void WebAssemblyCFGStackifyImpl::rewriteDepthImmediates(
MachineFunction &MF) {
2597 auto RewriteOperands = [&](MachineInstr &
MI) {
2599 SmallVector<MachineOperand, 4>
Ops(
MI.operands());
2600 while (
MI.getNumOperands() > 0)
2601 MI.removeOperand(
MI.getNumOperands() - 1);
2602 for (
auto MO :
Ops) {
2604 if (
MI.getOpcode() == WebAssembly::DELEGATE)
2606 else if (
MI.getOpcode() == WebAssembly::RETHROW)
2611 MI.addOperand(MF, MO);
2617 switch (
MI.getOpcode()) {
2618 case WebAssembly::BLOCK:
2619 case WebAssembly::TRY:
2620 assert(ScopeTops[
Stack.back().first->getNumber()]->getNumber() <=
2622 "Block/try/try_table marker should be balanced");
2626 case WebAssembly::TRY_TABLE:
2627 assert(ScopeTops[
Stack.back().first->getNumber()]->getNumber() <=
2629 "Block/try/try_table marker should be balanced");
2631 RewriteOperands(
MI);
2634 case WebAssembly::LOOP:
2635 assert(
Stack.back().first == &
MBB &&
"Loop top should be balanced");
2639 case WebAssembly::END_BLOCK:
2640 case WebAssembly::END_TRY:
2641 case WebAssembly::END_TRY_TABLE:
2645 case WebAssembly::END_LOOP:
2649 case WebAssembly::DELEGATE:
2650 RewriteOperands(
MI);
2655 if (
MI.isTerminator())
2656 RewriteOperands(
MI);
2661 assert(
Stack.empty() &&
"Control flow should be balanced");
2664void WebAssemblyCFGStackifyImpl::cleanupFunctionData(
MachineFunction &MF) {
2667 AppendixBB = FakeCallerBB = CallerTrampolineBB =
nullptr;
2670bool WebAssemblyCFGStackifyImpl::runOnMachineFunction(
MachineFunction &MF) {
2672 "********** Function: "
2677 ExceptionHandling::Wasm;
2687 if (UsesWasmEH && WebAssembly::WasmUseLegacyEH)
2688 removeUnnecessaryInstrs(MF);
2691 rewriteDepthImmediates(MF);
2695 fixEndsAtEndOfFunction(MF);
2698 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
2701 cleanupFunctionData(MF);
2703 MF.
getInfo<WebAssemblyFunctionInfo>()->setCFGStackified();
2707bool WebAssemblyCFGStackifyLegacy::runOnMachineFunction(
MachineFunction &MF) {
2708 MachineDominatorTree &MDT =
2709 getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
2710 MachineLoopInfo &MLI = getAnalysis<MachineLoopInfoWrapperPass>().getLI();
2711 WebAssemblyExceptionInfo &WEI =
2712 getAnalysis<WebAssemblyExceptionInfoWrapperPass>().getWEI();
2713 WebAssemblyCFGStackifyImpl Impl(MDT, MLI, WEI);
2714 return Impl.runOnMachineFunction(MF);
2724 WebAssemblyCFGStackifyImpl Impl(MDT, MLI, WEI);
2725 return Impl.runOnMachineFunction(MF)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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")
const HexagonInstrInfo * TII
Module.h This file contains the declarations for the Module class.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
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)
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
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 declares the WebAssembly-specific subclass of TargetMachine.
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.
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...
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
Analyze the branching code at the end of MBB, returning true if it cannot be understood (e....
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)
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 ExceptionHandling::Defa...
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.
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 ...
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.
unsigned getCopyOpcodeForRegClass(const TargetRegisterClass *RC)
Returns the appropriate copy opcode for the given register class.
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.