47#define DEBUG_TYPE "wasm-cfg-stackify"
49STATISTIC(NumCallUnwindMismatches,
"Number of call unwind mismatches found");
50STATISTIC(NumCatchUnwindMismatches,
"Number of catch unwind mismatches found");
53class WebAssemblyCFGStackifyImpl {
65 if (!ScopeTops[EndNo] || ScopeTops[EndNo]->getNumber() > BeginNo)
66 ScopeTops[EndNo] = Begin;
71 void placeBlockMarker(MachineBasicBlock &
MBB);
72 void placeLoopMarker(MachineBasicBlock &
MBB);
73 void placeTryMarker(MachineBasicBlock &
MBB);
74 void placeTryTableMarker(MachineBasicBlock &
MBB);
82 void addNestedTryDelegate(MachineInstr *RangeBegin, MachineInstr *RangeEnd,
83 MachineBasicBlock *UnwindDest);
86 void addNestedTryTable(MachineInstr *RangeBegin, MachineInstr *RangeEnd,
87 MachineBasicBlock *UnwindDest);
88 MachineBasicBlock *getTrampolineBlock(MachineBasicBlock *UnwindDest);
92 std::pair<const MachineBasicBlock *, const MachineInstr *>;
93 unsigned getBranchDepth(
const SmallVectorImpl<EndMarkerInfo> &Stack,
94 const MachineBasicBlock *
MBB);
95 unsigned getDelegateDepth(
const SmallVectorImpl<EndMarkerInfo> &Stack,
96 const MachineBasicBlock *
MBB);
97 unsigned getRethrowDepth(
const SmallVectorImpl<EndMarkerInfo> &Stack,
98 const MachineBasicBlock *EHPadToRethrow);
105 DenseMap<const MachineInstr *, MachineInstr *> BeginToEnd;
108 DenseMap<const MachineInstr *, MachineInstr *> EndToBegin;
110 DenseMap<const MachineInstr *, MachineBasicBlock *> TryToEHPad;
112 DenseMap<const MachineBasicBlock *, MachineInstr *> EHPadToTry;
114 DenseMap<const MachineBasicBlock *, MachineBasicBlock *>
115 UnwindDestToTrampoline;
119 MachineBasicBlock *AppendixBB =
nullptr;
127 if (CallerTrampolineBB)
128 MF.
insert(CallerTrampolineBB->getIterator(), AppendixBB);
137 MachineBasicBlock *CallerTrampolineBB =
nullptr;
139 if (!CallerTrampolineBB) {
143 return CallerTrampolineBB;
152 MachineBasicBlock *FakeCallerBB =
nullptr;
161 void registerScope(MachineInstr *Begin, MachineInstr *End);
162 void registerTryScope(MachineInstr *Begin, MachineInstr *End,
163 MachineBasicBlock *EHPad);
164 void unregisterScope(MachineInstr *Begin);
167 WebAssemblyCFGStackifyImpl(MachineDominatorTree &MDT, MachineLoopInfo &MLI,
168 WebAssemblyExceptionInfo &WEI)
169 : MDT(MDT), MLI(MLI), WEI(WEI) {}
175 StringRef getPassName()
const override {
return "WebAssembly CFG Stackify"; }
177 void getAnalysisUsage(AnalysisUsage &AU)
const override {
180 AU.
addRequired<WebAssemblyExceptionInfoWrapperPass>();
187 WebAssemblyCFGStackifyLegacy() : MachineFunctionPass(ID) {}
191char WebAssemblyCFGStackifyLegacy::ID = 0;
194 "Insert BLOCK/LOOP/TRY/TRY_TABLE markers for WebAssembly scopes",
false,
198 return new WebAssemblyCFGStackifyLegacy();
210 if (MO.isMBB() && MO.getMBB() ==
MBB)
220template <
typename Container>
223 const Container &AfterSet) {
224 auto InsertPos =
MBB->end();
225 while (InsertPos !=
MBB->begin()) {
226 if (BeforeSet.count(&*std::prev(InsertPos))) {
229 for (
auto Pos = InsertPos,
E =
MBB->begin(); Pos !=
E; --Pos)
230 assert(!AfterSet.count(&*std::prev(Pos)));
244template <
typename Container>
247 const Container &AfterSet) {
248 auto InsertPos =
MBB->begin();
249 while (InsertPos !=
MBB->end()) {
250 if (AfterSet.count(&*InsertPos)) {
253 for (
auto Pos = InsertPos,
E =
MBB->end(); Pos !=
E; ++Pos)
254 assert(!BeforeSet.count(&*Pos));
263void WebAssemblyCFGStackifyImpl::registerScope(
MachineInstr *Begin,
265 BeginToEnd[Begin] = End;
266 EndToBegin[End] = Begin;
270void WebAssemblyCFGStackifyImpl::registerTryScope(MachineInstr *Begin,
272 MachineBasicBlock *EHPad) {
273 registerScope(Begin, End);
274 TryToEHPad[Begin] = EHPad;
275 EHPadToTry[EHPad] = Begin;
278void WebAssemblyCFGStackifyImpl::unregisterScope(MachineInstr *Begin) {
280 MachineInstr *End = BeginToEnd[Begin];
282 BeginToEnd.
erase(Begin);
283 EndToBegin.
erase(End);
284 MachineBasicBlock *EHPad = TryToEHPad.
lookup(Begin);
287 TryToEHPad.
erase(Begin);
288 EHPadToTry.
erase(EHPad);
295void WebAssemblyCFGStackifyImpl::placeBlockMarker(MachineBasicBlock &
MBB) {
298 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
299 const auto &MFI = *MF.
getInfo<WebAssemblyFunctionInfo>();
304 MachineBasicBlock *Header =
nullptr;
305 bool IsBranchedTo =
false;
308 if (Pred->getNumber() < MBBNumber) {
319 assert(&
MBB != &MF.
front() &&
"Header blocks shouldn't have predecessors");
325 if (MachineBasicBlock *ScopeTop = ScopeTops[
I->getNumber()]) {
326 if (ScopeTop->getNumber() > Header->getNumber()) {
328 I = std::next(ScopeTop->getIterator());
340 SmallPtrSet<const MachineInstr *, 4> BeforeSet;
342 SmallPtrSet<const MachineInstr *, 4> AfterSet;
343 for (
const auto &
MI : *Header) {
347 if (
MI.getOpcode() == WebAssembly::LOOP) {
348 auto *LoopBottom = BeginToEnd[&
MI]->getParent()->getPrevNode();
361 if (
MI.getOpcode() == WebAssembly::BLOCK ||
362 MI.getOpcode() == WebAssembly::TRY ||
363 MI.getOpcode() == WebAssembly::TRY_TABLE) {
374 if (
MI.getOpcode() == WebAssembly::END_BLOCK ||
375 MI.getOpcode() == WebAssembly::END_LOOP ||
376 MI.getOpcode() == WebAssembly::END_TRY ||
377 MI.getOpcode() == WebAssembly::END_TRY_TABLE)
382 if (
MI.isTerminator())
387 for (
auto I = Header->getFirstTerminator(),
E = Header->begin();
I !=
E;
389 if (std::prev(
I)->isDebugInstr() || std::prev(
I)->isPosition())
391 if (WebAssembly::isChild(*std::prev(
I), MFI))
392 AfterSet.
insert(&*std::prev(
I));
398 WebAssembly::BlockType
ReturnType = WebAssembly::BlockType::Void;
400 MachineInstr *Begin =
401 BuildMI(*Header, InsertPos, Header->findDebugLoc(InsertPos),
402 TII.get(WebAssembly::BLOCK))
403 .
addImm(int64_t(ReturnType));
408 for (
auto &
MI :
MBB) {
411 if (
MI.getOpcode() == WebAssembly::LOOP)
424 if (
MI.getOpcode() == WebAssembly::END_LOOP ||
425 MI.getOpcode() == WebAssembly::END_TRY) {
426 if (EndToBegin[&
MI]->
getParent()->getNumber() >= Header->getNumber())
438 TII.get(WebAssembly::END_BLOCK));
439 registerScope(Begin, End);
442 updateScopeTops(Header, &
MBB);
446void WebAssemblyCFGStackifyImpl::placeLoopMarker(MachineBasicBlock &
MBB) {
448 SortRegionInfo SRI(MLI, WEI);
449 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
457 MachineBasicBlock *Bottom = SRI.getBottom(
Loop);
459 if (Iter == MF.
end()) {
460 getAppendixBlock(MF);
463 MachineBasicBlock *AfterLoop = &*Iter;
466 SmallPtrSet<const MachineInstr *, 4> BeforeSet;
467 SmallPtrSet<const MachineInstr *, 4> AfterSet;
468 for (
const auto &
MI :
MBB) {
471 if (
MI.getOpcode() == WebAssembly::END_LOOP)
482 TII.get(WebAssembly::LOOP))
483 .
addImm(int64_t(WebAssembly::BlockType::Void));
489 for (
const auto &
MI :
MBB)
491 if (
MI.getOpcode() == WebAssembly::END_LOOP)
500 : (*AfterLoop->pred_rbegin())->findBranchDebugLoc();
502 BuildMI(*AfterLoop, InsertPos, EndDL,
TII.get(WebAssembly::END_LOOP));
503 registerScope(Begin, End);
507 "With block sorting the outermost loop for a block should be first.");
508 updateScopeTops(&
MBB, AfterLoop);
511void WebAssemblyCFGStackifyImpl::placeTryMarker(MachineBasicBlock &
MBB) {
514 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
515 SortRegionInfo SRI(MLI, WEI);
516 const auto &MFI = *MF.
getInfo<WebAssemblyFunctionInfo>();
519 MachineBasicBlock *Header =
nullptr;
522 if (Pred->getNumber() < MBBNumber) {
525 "Explicit branch to an EH pad!");
535 MachineBasicBlock *Bottom = SRI.getBottom(WE);
537 if (Iter == MF.
end()) {
538 getAppendixBlock(MF);
541 MachineBasicBlock *Cont = &*Iter;
546 if (MachineBasicBlock *ScopeTop = ScopeTops[
I->getNumber()]) {
547 if (ScopeTop->getNumber() > Header->getNumber()) {
549 I = std::next(ScopeTop->getIterator());
561 SmallPtrSet<const MachineInstr *, 4> BeforeSet;
563 SmallPtrSet<const MachineInstr *, 4> AfterSet;
564 for (
const auto &
MI : *Header) {
568 if (
MI.getOpcode() == WebAssembly::LOOP) {
569 auto *LoopBottom = BeginToEnd[&
MI]->getParent()->getPrevNode();
580 if (
MI.getOpcode() == WebAssembly::BLOCK ||
581 MI.getOpcode() == WebAssembly::TRY)
586 if (
MI.getOpcode() == WebAssembly::END_BLOCK ||
587 MI.getOpcode() == WebAssembly::END_LOOP ||
588 MI.getOpcode() == WebAssembly::END_TRY)
593 if (
MI.isTerminator())
602 MachineInstr *ThrowingCall =
nullptr;
604 auto TermPos = Header->getFirstTerminator();
605 if (TermPos == Header->end() ||
606 TermPos->getOpcode() != WebAssembly::RETHROW) {
624 : Header->getFirstTerminator();
625 for (
auto I = SearchStartPt,
E = Header->begin();
I !=
E; --
I) {
626 if (std::prev(I)->isDebugInstr() || std::prev(I)->isPosition())
628 if (WebAssembly::isChild(*std::prev(I), MFI))
629 AfterSet.insert(&*std::prev(I));
636 MachineInstr *Begin =
637 BuildMI(*Header, InsertPos, Header->findDebugLoc(InsertPos),
638 TII.get(WebAssembly::TRY))
639 .
addImm(int64_t(WebAssembly::BlockType::Void));
644 for (
const auto &
MI : *Cont) {
647 if (
MI.getOpcode() == WebAssembly::LOOP)
652 if (
MI.getOpcode() == WebAssembly::END_TRY)
660 if (
MI.getOpcode() == WebAssembly::END_LOOP) {
663 if (EndToBegin[&
MI]->
getParent()->getNumber() > Header->getNumber())
677 TII.get(WebAssembly::END_TRY));
678 registerTryScope(Begin, End, &
MBB);
691 for (
auto *End : {&
MBB, Cont})
692 updateScopeTops(Header, End);
695void WebAssemblyCFGStackifyImpl::placeTryTableMarker(MachineBasicBlock &
MBB) {
698 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
699 SortRegionInfo SRI(MLI, WEI);
700 const auto &MFI = *MF.
getInfo<WebAssemblyFunctionInfo>();
703 MachineBasicBlock *Header =
nullptr;
706 if (Pred->getNumber() < MBBNumber) {
709 "Explicit branch to an EH pad!");
720 MachineBasicBlock *Bottom = SRI.getBottom(WE);
722 if (Iter == MF.
end())
724 MachineBasicBlock *Cont = &*Iter;
729 if (MachineBasicBlock *ScopeTop = ScopeTops[
I->getNumber()]) {
730 if (ScopeTop->getNumber() > Header->getNumber()) {
732 I = std::next(ScopeTop->getIterator());
744 SmallPtrSet<const MachineInstr *, 4> BeforeSet;
746 SmallPtrSet<const MachineInstr *, 4> AfterSet;
747 for (
const auto &
MI : *Header) {
751 if (
MI.getOpcode() == WebAssembly::LOOP) {
752 auto *LoopBottom = BeginToEnd[&
MI]->getParent()->getPrevNode();
763 if (
MI.getOpcode() == WebAssembly::BLOCK ||
764 MI.getOpcode() == WebAssembly::TRY_TABLE)
769 if (
MI.getOpcode() == WebAssembly::END_BLOCK ||
770 MI.getOpcode() == WebAssembly::END_LOOP ||
771 MI.getOpcode() == WebAssembly::END_TRY_TABLE)
776 if (
MI.isTerminator())
785 MachineInstr *ThrowingCall =
nullptr;
787 auto TermPos = Header->getFirstTerminator();
788 if (TermPos == Header->end() ||
789 TermPos->getOpcode() != WebAssembly::RETHROW) {
807 : Header->getFirstTerminator();
808 for (
auto I = SearchStartPt,
E = Header->begin();
I !=
E; --
I) {
809 if (std::prev(I)->isDebugInstr() || std::prev(I)->isPosition())
811 if (WebAssembly::isChild(*std::prev(I), MFI))
812 AfterSet.insert(&*std::prev(I));
831 MachineInstrBuilder BlockMIB =
832 BuildMI(*Header, InsertPos, Header->findDebugLoc(InsertPos),
833 TII.get(WebAssembly::BLOCK));
835 MachineInstrBuilder TryTableMIB =
836 BuildMI(*Header, InsertPos, Header->findDebugLoc(InsertPos),
837 TII.get(WebAssembly::TRY_TABLE))
838 .
addImm(int64_t(WebAssembly::BlockType::Void))
840 auto *TryTable = TryTableMIB.
getInstr();
846 *MF.
getSubtarget<WebAssemblySubtarget>().getTargetLowering();
847 WebAssembly::BlockType PtrTy =
849 ? WebAssembly::BlockType::I32
850 : WebAssembly::BlockType::I64;
851 auto *
Catch = WebAssembly::findCatch(&
MBB);
852 switch (
Catch->getOpcode()) {
853 case WebAssembly::CATCH:
857 BlockMIB.
addImm(int64_t(PtrTy));
859 for (
const auto &Use :
Catch->uses()) {
866 case WebAssembly::CATCH_REF:
871 BlockMIB.
addImm(int64_t(WebAssembly::BlockType::Multivalue));
874 for (
const auto &Use :
Catch->uses()) {
880 case WebAssembly::CATCH_ALL:
882 BlockMIB.
addImm(int64_t(WebAssembly::BlockType::Void));
886 case WebAssembly::CATCH_ALL_REF:
888 BlockMIB.
addImm(int64_t(WebAssembly::BlockType::Exnref));
898 for (
const auto &
MI :
MBB) {
901 if (
MI.getOpcode() == WebAssembly::LOOP)
909 if (
MI.getOpcode() == WebAssembly::END_LOOP) {
910 if (EndToBegin[&
MI]->
getParent()->getNumber() >= Header->getNumber())
922 if (WebAssembly::isCatch(
MI.getOpcode()))
929 MachineInstr *EndTryTable =
931 TII.get(WebAssembly::END_TRY_TABLE));
932 registerTryScope(TryTable, EndTryTable, &
MBB);
933 MachineInstr *EndBlock =
935 TII.get(WebAssembly::END_BLOCK));
936 registerScope(
Block, EndBlock);
978 for (
auto *End : {&
MBB, Cont})
979 updateScopeTops(Header, End);
982void WebAssemblyCFGStackifyImpl::removeUnnecessaryInstrs(
MachineFunction &MF) {
983 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
1018 for (
auto &
MBB : MF) {
1022 MachineBasicBlock *
TBB =
nullptr, *FBB =
nullptr;
1023 SmallVector<MachineOperand, 4>
Cond;
1026 MachineBasicBlock *Cont = &
MBB;
1028 MachineInstr *Try = EHPadToTry[Cont];
1029 MachineInstr *EndTry = BeginToEnd[Try];
1043 (!
Cond.
empty() && FBB && FBB == Cont))) {
1044 bool ErasedUncondBr =
false;
1045 (void)ErasedUncondBr;
1046 for (
auto I = EHPadLayoutPred->
end(),
E = EHPadLayoutPred->
begin();
1048 auto PrevI = std::prev(
I);
1049 if (PrevI->isTerminator()) {
1050 assert(PrevI->getOpcode() == WebAssembly::BR);
1051 PrevI->eraseFromParent();
1052 ErasedUncondBr =
true;
1056 assert(ErasedUncondBr &&
"Unconditional branch not erased!");
1072 for (
auto &
MBB : MF) {
1073 for (
auto &
MI :
MBB) {
1074 if (
MI.getOpcode() != WebAssembly::TRY)
1076 MachineInstr *Try = &
MI, *EndTry = BeginToEnd[Try];
1077 if (EndTry->getOpcode() == WebAssembly::DELEGATE)
1080 MachineBasicBlock *TryBB = Try->
getParent();
1081 MachineBasicBlock *Cont = EndTry->
getParent();
1083 for (
auto B = Try->
getIterator(),
E = std::next(EndTry->getIterator());
1085 std::prev(
B)->getOpcode() == WebAssembly::BLOCK &&
1086 E->getOpcode() == WebAssembly::END_BLOCK &&
1087 std::prev(
B)->getOperand(0).getImm() == RetType;
1094 for (
auto *
MI : ToDelete) {
1095 if (
MI->getOpcode() == WebAssembly::BLOCK)
1096 unregisterScope(
MI);
1097 MI->eraseFromParent();
1110 for (
auto &
MI : Split) {
1111 for (
auto &MO :
MI.explicit_uses()) {
1112 if (!MO.isReg() || MO.getReg().isPhysical())
1114 if (
MachineInstr *Def = MRI.getUniqueVRegDef(MO.getReg()))
1115 if (Def->getParent() == &
MBB)
1116 MFI.unstackifyVReg(MO.getReg());
1149 if (!MFI.isVRegStackified(TeeReg)) {
1151 MFI.unstackifyVReg(DefReg);
1157 MI.eraseFromParent();
1164void WebAssemblyCFGStackifyImpl::addNestedTryDelegate(
1165 MachineInstr *RangeBegin, MachineInstr *RangeEnd,
1166 MachineBasicBlock *UnwindDest) {
1167 auto *BeginBB = RangeBegin->
getParent();
1170 const auto &MFI = *MF.
getInfo<WebAssemblyFunctionInfo>();
1171 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
1175 SmallPtrSet<const MachineInstr *, 4> AfterSet;
1176 AfterSet.
insert(RangeBegin);
1179 if (std::prev(
I)->isDebugInstr() || std::prev(
I)->isPosition())
1181 if (WebAssembly::isChild(*std::prev(
I), MFI))
1182 AfterSet.
insert(&*std::prev(
I));
1189 BeginBB, SmallPtrSet<const MachineInstr *, 4>(), AfterSet);
1191 TII.get(WebAssembly::TRY))
1192 .
addImm(int64_t(WebAssembly::BlockType::Void));
1198 if (UnwindDest != FakeCallerBB)
1201 auto SplitPos = std::next(RangeEnd->
getIterator());
1202 if (SplitPos == EndBB->end()) {
1205 MF.
insert(std::next(EndBB->getIterator()), DelegateBB);
1206 EndBB->addSuccessor(DelegateBB);
1216 bool CatchAfterSplit =
false;
1217 if (EndBB->isEHPad()) {
1220 if (WebAssembly::isCatch(
I->getOpcode())) {
1221 CatchAfterSplit =
true;
1227 MachineBasicBlock *PreBB =
nullptr, *PostBB =
nullptr;
1228 if (!CatchAfterSplit) {
1247 PostBB->splice(PostBB->end(), PreBB, SplitPos, PreBB->
end());
1248 PostBB->transferSuccessors(PreBB);
1264 assert(EndBB->isEHPad());
1267 MF.
insert(PostBB->getIterator(), PreBB);
1268 MF.
insert(PostBB->getIterator(), DelegateBB);
1269 PreBB->
splice(PreBB->
end(), PostBB, PostBB->begin(), SplitPos);
1281 TII.get(WebAssembly::DELEGATE))
1283 registerTryScope(Try, Delegate,
nullptr);
1302WebAssemblyCFGStackifyImpl::getTrampolineBlock(MachineBasicBlock *UnwindDest) {
1306 auto It = UnwindDestToTrampoline.
find(UnwindDest);
1307 if (It != UnwindDestToTrampoline.
end())
1312 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
1314 MachineInstr *
Block =
nullptr;
1315 MachineBasicBlock *TrampolineBB =
nullptr;
1318 if (UnwindDest == getFakeCallerBlock(MF)) {
1322 auto BeginPos = MF.
begin()->begin();
1323 while (WebAssembly::isArgument(BeginPos->getOpcode()))
1326 TII.get(WebAssembly::BLOCK))
1327 .
addImm(int64_t(WebAssembly::BlockType::Exnref));
1328 TrampolineBB = getCallerTrampolineBlock(MF);
1329 MachineBasicBlock *PrevBB = &*std::prev(CallerTrampolineBB->
getIterator());
1335 auto *TargetBeginTry = EHPadToTry[UnwindDest];
1336 auto *TargetEndTry = BeginToEnd[TargetBeginTry];
1337 auto *TargetBeginBB = TargetBeginTry->getParent();
1338 auto *TargetEndBB = TargetEndTry->getParent();
1340 Block =
BuildMI(*TargetBeginBB, std::next(TargetBeginTry->getIterator()),
1341 TargetBeginTry->getDebugLoc(),
TII.get(WebAssembly::BLOCK))
1342 .
addImm(int64_t(WebAssembly::BlockType::Exnref));
1344 EndDebugLoc = TargetEndTry->getDebugLoc();
1345 MF.
insert(TargetEndBB->getIterator(), TrampolineBB);
1351 MachineInstr *EndBlock =
1352 BuildMI(TrampolineBB, EndDebugLoc,
TII.get(WebAssembly::END_BLOCK));
1353 auto ExnReg = MRI.createVirtualRegister(&WebAssembly::EXNREFRegClass);
1354 BuildMI(TrampolineBB, EndDebugLoc,
TII.get(WebAssembly::CATCH_ALL_REF))
1356 BuildMI(TrampolineBB, EndDebugLoc,
TII.get(WebAssembly::THROW_REF))
1362 MachineBasicBlock *TrampolineLayoutPred = TrampolineBB->
getPrevNode();
1364 TII.get(WebAssembly::UNREACHABLE));
1366 registerScope(
Block, EndBlock);
1367 UnwindDestToTrampoline[UnwindDest] = TrampolineBB;
1368 return TrampolineBB;
1373void WebAssemblyCFGStackifyImpl::addNestedTryTable(
1374 MachineInstr *RangeBegin, MachineInstr *RangeEnd,
1375 MachineBasicBlock *UnwindDest) {
1376 auto *BeginBB = RangeBegin->
getParent();
1380 const auto &MFI = *MF.
getInfo<WebAssemblyFunctionInfo>();
1381 const auto &
TII = *MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
1384 auto *TrampolineBB = getTrampolineBlock(UnwindDest);
1388 SmallPtrSet<const MachineInstr *, 4> AfterSet;
1389 AfterSet.
insert(RangeBegin);
1392 if (std::prev(
I)->isDebugInstr() || std::prev(
I)->isPosition())
1394 if (WebAssembly::isChild(*std::prev(
I), MFI))
1395 AfterSet.
insert(&*std::prev(
I));
1402 BeginBB, SmallPtrSet<const MachineInstr *, 4>(), AfterSet);
1403 MachineInstr *TryTable =
1405 TII.get(WebAssembly::TRY_TABLE))
1406 .
addImm(int64_t(WebAssembly::BlockType::Void))
1415 auto SplitPos = std::next(RangeEnd->
getIterator());
1416 if (SplitPos == EndBB->end()) {
1419 MF.
insert(std::next(EndBB->getIterator()), EndTryTableBB);
1420 EndBB->addSuccessor(EndTryTableBB);
1430 bool CatchAfterSplit =
false;
1431 if (EndBB->isEHPad()) {
1434 if (WebAssembly::isCatch(
I->getOpcode())) {
1435 CatchAfterSplit =
true;
1441 MachineBasicBlock *PreBB =
nullptr, *PostBB =
nullptr;
1442 if (!CatchAfterSplit) {
1461 PostBB->splice(PostBB->end(), PreBB, SplitPos, PreBB->
end());
1462 PostBB->transferSuccessors(PreBB);
1478 assert(EndBB->isEHPad());
1481 MF.
insert(PostBB->getIterator(), PreBB);
1482 MF.
insert(PostBB->getIterator(), EndTryTableBB);
1483 PreBB->
splice(PreBB->
end(), PostBB, PostBB->begin(), SplitPos);
1495 TII.get(WebAssembly::END_TRY_TABLE));
1496 registerTryScope(TryTable, EndTryTable, TrampolineBB);
1548 MachineInstr *EndTryTable =
nullptr, *EndLoop =
nullptr;
1549 for (
auto &
MI :
reverse(*EndTryTableBB)) {
1550 if (
MI.getOpcode() == WebAssembly::END_TRY_TABLE) {
1554 if (EndTryTable &&
MI.getOpcode() == WebAssembly::END_LOOP) {
1564 auto SplitPos = std::next(EndLoop->getIterator());
1565 EndLoopBB->splice(EndLoopBB->end(), EndTryTableBB, EndTryTableBB->
begin(),
1567 EndLoopBB->addSuccessor(EndTryTableBB);
1573 std::string Name =
"bb.";
1575 if (
MBB->getBasicBlock()) {
1577 Name +=
MBB->getBasicBlock()->getName();
1582bool WebAssemblyCFGStackifyImpl::fixCallUnwindMismatches(
MachineFunction &MF) {
1829 using TryRange = std::pair<MachineInstr *, MachineInstr *>;
1831 MapVector<MachineBasicBlock *, SmallVector<TryRange, 4>>
1832 UnwindDestToTryRanges;
1838 bool SeenThrowableInstInBB =
false;
1840 if (WebAssembly::isTry(
MI.getOpcode()))
1842 else if (
MI.getOpcode() == WebAssembly::DELEGATE)
1844 else if (WebAssembly::WasmUseLegacyEH &&
1845 WebAssembly::isCatch(
MI.getOpcode()))
1847 else if (
MI.getOpcode() == WebAssembly::END_TRY_TABLE)
1888 EHPadStack.
push_back(TryToEHPad[EndToBegin[&
MI]]);
1895 !WebAssembly::mayThrow(
MI))
1897 SeenThrowableInstInBB =
true;
1901 MachineBasicBlock *UnwindDest =
nullptr;
1907 if (Succ->isEHPad()) {
1912 if (EHPadStack.
back() == UnwindDest)
1916 UnwindDestToTryRanges[UnwindDest].push_back(TryRange(&
MI, &
MI));
1918 <<
"\nCall = " <<
MI
1919 <<
"\nOriginal dest = " <<
getBBName(UnwindDest)
1932 MachineInstr *RangeBegin =
nullptr, *RangeEnd =
nullptr;
1935 auto RecordCallerMismatchRange = [&](
const MachineBasicBlock *CurrentDest) {
1936 UnwindDestToTryRanges[getFakeCallerBlock(MF)].push_back(
1937 TryRange(RangeBegin, RangeEnd));
1940 <<
"\nRange begin = " << *RangeBegin
1941 <<
"Range end = " << *RangeEnd
1942 <<
"\nOriginal dest = caller Current dest = "
1944 RangeBegin = RangeEnd =
nullptr;
1948 bool SeenThrowableInstInBB =
false;
1950 bool MayThrow = WebAssembly::mayThrow(
MI);
1956 SeenThrowableInstInBB =
true;
1960 else if (RangeEnd && WebAssembly::isMarker(
MI.getOpcode()))
1961 RecordCallerMismatchRange(EHPadStack.
back());
1966 else if (EHPadStack.
empty() || EHPadStack.
back() == FakeCallerBB ||
1975 RangeBegin = RangeEnd = &
MI;
1981 if (WebAssembly::isTry(
MI.getOpcode()))
1983 else if (
MI.getOpcode() == WebAssembly::DELEGATE)
1985 else if (WebAssembly::WasmUseLegacyEH &&
1986 WebAssembly::isCatch(
MI.getOpcode()))
1988 else if (!WebAssembly::WasmUseLegacyEH &&
1989 MI.getOpcode() == WebAssembly::END_TRY_TABLE)
1990 EHPadStack.
push_back(TryToEHPad[EndToBegin[&
MI]]);
1994 RecordCallerMismatchRange(EHPadStack.
back());
2000 if (UnwindDestToTryRanges.
empty())
2005 if (!WebAssembly::WasmUseLegacyEH)
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 (WebAssembly::WasmUseLegacyEH)
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;
2192 if (WebAssembly::isTry(
MI.getOpcode())) {
2194 }
else if (
MI.getOpcode() == WebAssembly::DELEGATE) {
2196 }
else if (WebAssembly::isCatch(
MI.getOpcode())) {
2201 if (WebAssembly::isCatchAll(
MI.getOpcode())) {
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 (WebAssembly::WasmUseLegacyEH) {
2264 addNestedTryDelegate(Try, EndTry, UnwindDest);
2267 addNestedTryTable(Try, EndTry, UnwindDest);
2271 if (!WebAssembly::WasmUseLegacyEH)
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())
2389 WebAssembly::BlockType RetType =
2390 MFI.getResults().size() > 1
2391 ? WebAssembly::BlockType::Multivalue
2392 : WebAssembly::BlockType(
2393 WebAssembly::toValType(MFI.getResults().front()));
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]);
2412 std::next(WebAssembly::findCatch(EHPad)->getReverseIterator());
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 const MCAsmInfo &MCAI = MF.getTarget().getMCAsmInfo();
2498 for (
auto &
MBB : MF) {
2502 MF.getFunction().hasPersonalityFn()) {
2503 if (WebAssembly::WasmUseLegacyEH)
2504 placeTryMarker(
MBB);
2506 placeTryTableMarker(
MBB);
2510 placeBlockMarker(
MBB);
2515 MF.getFunction().hasPersonalityFn()) {
2516 const auto &
TII = *MF.getSubtarget<WebAssemblySubtarget>().getInstrInfo();
2523 fixCatchUnwindMismatches(MF);
2524 fixCallUnwindMismatches(MF);
2527 recalculateScopeTops(MF);
2531unsigned WebAssemblyCFGStackifyImpl::getBranchDepth(
2532 const SmallVectorImpl<EndMarkerInfo> &Stack,
const MachineBasicBlock *
MBB) {
2543unsigned WebAssemblyCFGStackifyImpl::getDelegateDepth(
2544 const SmallVectorImpl<EndMarkerInfo> &Stack,
const MachineBasicBlock *
MBB) {
2545 if (
MBB == FakeCallerBB)
2546 return Stack.size();
2552 return getBranchDepth(Stack,
MBB);
2568 const MachineInstr *EndTry = BeginToEnd[EHPadToTry[
MBB]];
2570 if (
X.first == EndTry->
getParent() &&
X.second == EndTry)
2578unsigned WebAssemblyCFGStackifyImpl::getRethrowDepth(
2579 const SmallVectorImpl<EndMarkerInfo> &Stack,
2580 const MachineBasicBlock *EHPadToRethrow) {
2583 const MachineInstr *End =
X.second;
2584 if (End->
getOpcode() == WebAssembly::END_TRY) {
2585 auto *EHPad = TryToEHPad[EndToBegin[End]];
2586 if (EHPadToRethrow == EHPad)
2595void WebAssemblyCFGStackifyImpl::rewriteDepthImmediates(
MachineFunction &MF) {
2599 auto RewriteOperands = [&](MachineInstr &
MI) {
2601 SmallVector<MachineOperand, 4>
Ops(
MI.operands());
2602 while (
MI.getNumOperands() > 0)
2603 MI.removeOperand(
MI.getNumOperands() - 1);
2604 for (
auto MO :
Ops) {
2606 if (
MI.getOpcode() == WebAssembly::DELEGATE)
2608 else if (
MI.getOpcode() == WebAssembly::RETHROW)
2613 MI.addOperand(MF, MO);
2619 switch (
MI.getOpcode()) {
2620 case WebAssembly::BLOCK:
2621 case WebAssembly::TRY:
2622 assert(ScopeTops[
Stack.back().first->getNumber()]->getNumber() <=
2624 "Block/try/try_table marker should be balanced");
2628 case WebAssembly::TRY_TABLE:
2629 assert(ScopeTops[
Stack.back().first->getNumber()]->getNumber() <=
2631 "Block/try/try_table marker should be balanced");
2633 RewriteOperands(
MI);
2636 case WebAssembly::LOOP:
2637 assert(
Stack.back().first == &
MBB &&
"Loop top should be balanced");
2641 case WebAssembly::END_BLOCK:
2642 case WebAssembly::END_TRY:
2643 case WebAssembly::END_TRY_TABLE:
2647 case WebAssembly::END_LOOP:
2651 case WebAssembly::DELEGATE:
2652 RewriteOperands(
MI);
2657 if (
MI.isTerminator())
2658 RewriteOperands(
MI);
2663 assert(
Stack.empty() &&
"Control flow should be balanced");
2666void WebAssemblyCFGStackifyImpl::cleanupFunctionData(
MachineFunction &MF) {
2669 AppendixBB = FakeCallerBB = CallerTrampolineBB =
nullptr;
2672bool WebAssemblyCFGStackifyImpl::runOnMachineFunction(
MachineFunction &MF) {
2674 "********** Function: "
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
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()
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.
iterator find(const_arg_type_t< KeyT > Val)
bool erase(const KeyT &Val)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
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.
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.
ExceptionHandling getExceptionHandlingType() const
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 TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
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.
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.
const MCAsmInfo & getMCAsmInfo() const
Return target specific asm information.
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