41#define DEBUG_TYPE "wasm-cfg-stackify"
43STATISTIC(NumCallUnwindMismatches,
"Number of call unwind mismatches found");
44STATISTIC(NumCatchUnwindMismatches,
"Number of catch unwind mismatches found");
66 int EndNo =
End->getNumber();
67 if (!ScopeTops[EndNo] || ScopeTops[EndNo]->getNumber() > Begin->
getNumber())
68 ScopeTops[EndNo] = Begin;
87 std::pair<const MachineBasicBlock *, const MachineInstr *>;
151char WebAssemblyCFGStackify::ID = 0;
153 "Insert BLOCK/LOOP/TRY markers for WebAssembly scopes",
false,
157 return new WebAssemblyCFGStackify();
169 if (MO.isMBB() && MO.getMBB() ==
MBB)
179template <
typename Container>
182 const Container &AfterSet) {
183 auto InsertPos =
MBB->
end();
185 if (BeforeSet.count(&*std::prev(InsertPos))) {
188 for (
auto Pos = InsertPos, E =
MBB->
begin(); Pos != E; --Pos)
189 assert(!AfterSet.count(&*std::prev(Pos)));
203template <
typename Container>
206 const Container &AfterSet) {
208 while (InsertPos !=
MBB->
end()) {
209 if (AfterSet.count(&*InsertPos)) {
212 for (
auto Pos = InsertPos, E =
MBB->
end(); Pos != E; ++Pos)
213 assert(!BeforeSet.count(&*Pos));
222void WebAssemblyCFGStackify::registerScope(
MachineInstr *Begin,
224 BeginToEnd[Begin] =
End;
225 EndToBegin[
End] = Begin;
229void WebAssemblyCFGStackify::registerTryScope(
MachineInstr *Begin,
232 registerScope(Begin,
End);
233 TryToEHPad[Begin] = EHPad;
234 EHPadToTry[EHPad] = Begin;
237void WebAssemblyCFGStackify::unregisterScope(
MachineInstr *Begin) {
241 BeginToEnd.
erase(Begin);
246 TryToEHPad.
erase(Begin);
247 EHPadToTry.
erase(EHPad);
264 bool IsBranchedTo =
false;
267 if (Pred->getNumber() < MBBNumber) {
268 Header = Header ? MDT->findNearestCommonDominator(Header, Pred) : Pred;
278 assert(&
MBB != &MF.
front() &&
"Header blocks shouldn't have predecessors");
285 if (ScopeTop->getNumber() > Header->getNumber()) {
287 I = std::next(ScopeTop->getIterator());
302 for (
const auto &
MI : *Header) {
306 if (
MI.getOpcode() == WebAssembly::LOOP) {
307 auto *LoopBottom = BeginToEnd[&
MI]->getParent()->getPrevNode();
320 if (
MI.getOpcode() == WebAssembly::BLOCK ||
321 MI.getOpcode() == WebAssembly::TRY) {
332 if (
MI.getOpcode() == WebAssembly::END_BLOCK ||
333 MI.getOpcode() == WebAssembly::END_LOOP ||
334 MI.getOpcode() == WebAssembly::END_TRY)
339 if (
MI.isTerminator())
344 for (
auto I = Header->getFirstTerminator(), E = Header->begin();
I != E;
346 if (std::prev(
I)->isDebugInstr() || std::prev(
I)->isPosition())
349 AfterSet.
insert(&*std::prev(
I));
358 BuildMI(*Header, InsertPos, Header->findDebugLoc(InsertPos),
359 TII.get(WebAssembly::BLOCK))
360 .
addImm(int64_t(ReturnType));
365 for (
auto &
MI :
MBB) {
368 if (
MI.getOpcode() == WebAssembly::LOOP ||
369 MI.getOpcode() == WebAssembly::TRY)
377 if (
MI.getOpcode() == WebAssembly::END_LOOP ||
378 MI.getOpcode() == WebAssembly::END_TRY) {
379 if (EndToBegin[&
MI]->
getParent()->getNumber() >= Header->getNumber())
391 TII.get(WebAssembly::END_BLOCK));
392 registerScope(Begin,
End);
395 updateScopeTops(Header, &
MBB);
401 const auto &MLI = getAnalysis<MachineLoopInfoWrapperPass>().getLI();
402 const auto &WEI = getAnalysis<WebAssemblyExceptionInfo>();
414 if (Iter == MF.
end()) {
415 getAppendixBlock(MF);
423 for (
const auto &
MI :
MBB) {
426 if (
MI.getOpcode() == WebAssembly::END_LOOP)
437 TII.get(WebAssembly::LOOP))
438 .
addImm(int64_t(WebAssembly::BlockType::Void));
444 for (
const auto &
MI :
MBB)
446 if (
MI.getOpcode() == WebAssembly::END_LOOP)
455 : (*AfterLoop->pred_rbegin())->findBranchDebugLoc();
457 BuildMI(*AfterLoop, InsertPos, EndDL,
TII.get(WebAssembly::END_LOOP));
458 registerScope(Begin,
End);
462 "With block sorting the outermost loop for a block should be first.");
463 updateScopeTops(&
MBB, AfterLoop);
469 auto &MDT = getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
471 const auto &MLI = getAnalysis<MachineLoopInfoWrapperPass>().getLI();
472 const auto &WEI = getAnalysis<WebAssemblyExceptionInfo>();
480 if (Pred->getNumber() < MBBNumber) {
481 Header = Header ? MDT.findNearestCommonDominator(Header, Pred) : Pred;
483 "Explicit branch to an EH pad!");
496 if (Iter == MF.
end()) {
497 getAppendixBlock(MF);
509 if (ScopeTop->getNumber() > Header->getNumber()) {
511 I = std::next(ScopeTop->getIterator());
526 for (
const auto &
MI : *Header) {
530 if (
MI.getOpcode() == WebAssembly::LOOP) {
531 auto *LoopBottom = BeginToEnd[&
MI]->getParent()->getPrevNode();
542 if (
MI.getOpcode() == WebAssembly::BLOCK ||
543 MI.getOpcode() == WebAssembly::TRY)
548 if (
MI.getOpcode() == WebAssembly::END_BLOCK ||
549 MI.getOpcode() == WebAssembly::END_LOOP ||
550 MI.getOpcode() == WebAssembly::END_TRY)
555 if (
MI.isTerminator())
566 auto TermPos = Header->getFirstTerminator();
567 if (TermPos == Header->end() ||
568 TermPos->getOpcode() != WebAssembly::RETHROW) {
575 if (
MI.getIterator() != Header->begin() &&
576 std::prev(
MI.getIterator())->isEHLabel()) {
577 AfterSet.
insert(&*std::prev(
MI.getIterator()));
578 ThrowingCall = &*std::prev(
MI.getIterator());
593 : Header->getFirstTerminator();
594 for (
auto I = SearchStartPt, E = Header->begin();
I != E; --
I) {
595 if (std::prev(
I)->isDebugInstr() || std::prev(
I)->isPosition())
598 AfterSet.
insert(&*std::prev(
I));
606 BuildMI(*Header, InsertPos, Header->findDebugLoc(InsertPos),
607 TII.get(WebAssembly::TRY))
608 .
addImm(int64_t(WebAssembly::BlockType::Void));
613 for (
const auto &
MI : *Cont) {
616 if (
MI.getOpcode() == WebAssembly::LOOP ||
617 MI.getOpcode() == WebAssembly::BLOCK)
622 if (
MI.getOpcode() == WebAssembly::END_TRY)
630 if (
MI.getOpcode() == WebAssembly::END_LOOP) {
633 if (EndToBegin[&
MI]->
getParent()->getNumber() > Header->getNumber())
648 TII.get(WebAssembly::END_TRY));
649 registerTryScope(Begin,
End, &
MBB);
662 for (
auto *
End : {&
MBB, Cont})
663 updateScopeTops(Header,
End);
666void WebAssemblyCFGStackify::removeUnnecessaryInstrs(
MachineFunction &MF) {
702 for (
auto &
MBB : MF) {
726 if (Analyzable && ((
Cond.empty() &&
TBB &&
TBB == Cont) ||
727 (!
Cond.empty() && FBB && FBB == Cont))) {
728 bool ErasedUncondBr =
false;
729 (void)ErasedUncondBr;
730 for (
auto I = EHPadLayoutPred->
end(), E = EHPadLayoutPred->
begin();
732 auto PrevI = std::prev(
I);
733 if (PrevI->isTerminator()) {
734 assert(PrevI->getOpcode() == WebAssembly::BR);
735 PrevI->eraseFromParent();
736 ErasedUncondBr =
true;
740 assert(ErasedUncondBr &&
"Unconditional branch not erased!");
756 for (
auto &
MBB : MF) {
757 for (
auto &
MI :
MBB) {
758 if (
MI.getOpcode() != WebAssembly::TRY)
761 if (EndTry->getOpcode() == WebAssembly::DELEGATE)
767 for (
auto B = Try->
getIterator(), E = std::next(EndTry->getIterator());
768 B != TryBB->
begin() && E != Cont->
end() &&
769 std::prev(
B)->getOpcode() == WebAssembly::BLOCK &&
770 E->getOpcode() == WebAssembly::END_BLOCK &&
771 std::prev(
B)->getOperand(0).getImm() == RetType;
778 for (
auto *
MI : ToDelete) {
779 if (
MI->getOpcode() == WebAssembly::BLOCK)
781 MI->eraseFromParent();
794 for (
auto &
MI : Split) {
795 for (
auto &MO :
MI.explicit_uses()) {
796 if (!MO.isReg() || MO.getReg().isPhysical())
799 if (Def->getParent() == &
MBB)
800 MFI.unstackifyVReg(MO.getReg());
833 if (!MFI.isVRegStackified(TeeReg)) {
835 MFI.unstackifyVReg(DefReg);
841 MI.eraseFromParent();
848void WebAssemblyCFGStackify::addTryDelegate(
MachineInstr *RangeBegin,
860 AfterSet.
insert(RangeBegin);
863 if (std::prev(
I)->isDebugInstr() || std::prev(
I)->isPosition())
866 AfterSet.
insert(&*std::prev(
I));
875 TII.get(WebAssembly::TRY))
876 .
addImm(int64_t(WebAssembly::BlockType::Void));
882 if (DelegateDest != FakeCallerBB)
885 auto SplitPos = std::next(RangeEnd->
getIterator());
886 if (SplitPos == EndBB->end()) {
889 MF.
insert(std::next(EndBB->getIterator()), DelegateBB);
890 EndBB->addSuccessor(DelegateBB);
899 bool PostSplit =
true;
900 if (EndBB->isEHPad()) {
930 PostBB->splice(PostBB->end(), PreBB, SplitPos, PreBB->
end());
931 PostBB->transferSuccessors(PreBB);
950 MF.
insert(PostBB->getIterator(), PreBB);
951 MF.
insert(PostBB->getIterator(), DelegateBB);
952 PreBB->
splice(PreBB->
end(), PostBB, PostBB->begin(), SplitPos);
964 TII.get(WebAssembly::DELEGATE))
966 registerTryScope(Try, Delegate,
nullptr);
969bool WebAssemblyCFGStackify::fixCallUnwindMismatches(
MachineFunction &MF) {
1092 using TryRange = std::pair<MachineInstr *, MachineInstr *>;
1100 bool SeenThrowableInstInBB =
false;
1102 if (
MI.getOpcode() == WebAssembly::TRY)
1114 SeenThrowableInstInBB =
true;
1125 if (Succ->isEHPad()) {
1130 if (EHPadStack.
back() == UnwindDest)
1136 std::prev(RangeBegin->
getIterator())->isEHLabel())
1137 RangeBegin = &*std::prev(RangeBegin->
getIterator());
1138 if (std::next(RangeEnd->getIterator()) !=
MBB.
end() &&
1139 std::next(RangeEnd->getIterator())->isEHLabel())
1140 RangeEnd = &*std::next(RangeEnd->getIterator());
1143 UnwindDestToTryRanges[UnwindDest].push_back(
1144 TryRange(RangeBegin, RangeEnd));
1146 <<
"\nCall = " <<
MI
1147 <<
"\nOriginal dest = " << UnwindDest->
getName()
1148 <<
" Current dest = " << EHPadStack.
back()->getName()
1160 MachineInstr *RangeBegin =
nullptr, *RangeEnd =
nullptr;
1164 UnwindDestToTryRanges[getFakeCallerBlock(MF)].push_back(
1165 TryRange(RangeBegin, RangeEnd));
1168 <<
"\nRange begin = " << *RangeBegin
1169 <<
"Range end = " << *RangeEnd
1170 <<
"\nOriginal dest = caller Current dest = "
1171 << CurrentDest->getName() <<
"\n\n");
1172 RangeBegin = RangeEnd =
nullptr;
1176 bool SeenThrowableInstInBB =
false;
1184 SeenThrowableInstInBB =
true;
1189 RecordCallerMismatchRange(EHPadStack.
back());
1193 else if (EHPadStack.
empty() || !MayThrow) {
1201 RangeBegin = RangeEnd = &
MI;
1207 if (
MI.getOpcode() == WebAssembly::TRY)
1214 RecordCallerMismatchRange(EHPadStack.
back());
1220 if (UnwindDestToTryRanges.
empty())
1224 for (
auto &
P : UnwindDestToTryRanges) {
1225 NumCallUnwindMismatches +=
P.second.size();
1227 auto &TryRanges =
P.second;
1229 for (
auto Range : TryRanges) {
1230 MachineInstr *RangeBegin =
nullptr, *RangeEnd =
nullptr;
1231 std::tie(RangeBegin, RangeEnd) =
Range;
1241 if (Succ->isEHPad()) {
1249 addTryDelegate(RangeBegin, RangeEnd, UnwindDest);
1256bool WebAssemblyCFGStackify::fixCatchUnwindMismatches(
MachineFunction &MF) {
1303 if (
MI.getOpcode() == WebAssembly::TRY)
1305 else if (
MI.getOpcode() == WebAssembly::DELEGATE)
1312 if (
MI.getOpcode() == WebAssembly::CATCH_ALL) {
1317 else if (EHPadStack.
empty() && EHInfo->hasUnwindDest(EHPad)) {
1319 <<
"'s unwind destination does not exist anymore"
1325 else if (!EHPadStack.
empty() && !EHInfo->hasUnwindDest(EHPad)) {
1326 EHPadToUnwindDest[EHPad] = getFakeCallerBlock(MF);
1328 <<
"- Catch unwind mismatch:\nEHPad = " << EHPad->
getName()
1329 <<
" Original dest = caller Current dest = "
1330 << EHPadStack.
back()->getName() <<
"\n\n");
1335 else if (!EHPadStack.
empty() && EHInfo->hasUnwindDest(EHPad)) {
1336 auto *UnwindDest = EHInfo->getUnwindDest(EHPad);
1337 if (EHPadStack.
back() != UnwindDest) {
1338 EHPadToUnwindDest[EHPad] = UnwindDest;
1340 << EHPad->
getName() <<
" Original dest = "
1341 << UnwindDest->
getName() <<
" Current dest = "
1342 << EHPadStack.
back()->getName() <<
"\n\n");
1352 if (EHPadToUnwindDest.
empty())
1354 NumCatchUnwindMismatches += EHPadToUnwindDest.
size();
1357 for (
auto &
P : EHPadToUnwindDest) {
1362 addTryDelegate(Try, EndTry, UnwindDest);
1410 for (
auto &
MBB : MF) {
1411 for (
auto &
MI :
MBB) {
1412 if (
MI.isTerminator()) {
1413 for (
auto &MO :
MI.operands()) {
1414 if (MO.isMBB() && NewEndTryBBs.
count(MO.getMBB())) {
1415 auto *BrDest = MO.getMBB();
1416 bool FoundEndBlock =
false;
1417 for (; std::next(BrDest->getIterator()) != MF.end();
1418 BrDest = BrDest->getNextNode()) {
1419 for (
const auto &
MI : *BrDest) {
1420 if (
MI.getOpcode() == WebAssembly::END_BLOCK) {
1421 FoundEndBlock =
true;
1439void WebAssemblyCFGStackify::recalculateScopeTops(
MachineFunction &MF) {
1443 MDT->updateBlockNumbers();
1450 switch (
MI.getOpcode()) {
1451 case WebAssembly::END_BLOCK:
1452 case WebAssembly::END_LOOP:
1453 case WebAssembly::END_TRY:
1454 case WebAssembly::DELEGATE:
1457 case WebAssembly::CATCH:
1458 case WebAssembly::CATCH_ALL:
1473void WebAssemblyCFGStackify::fixEndsAtEndOfFunction(
MachineFunction &MF) {
1476 if (MFI.getResults().empty())
1483 ? WebAssembly::BlockType::Multivalue
1494 if (
MI.isPosition() ||
MI.isDebugInstr())
1496 switch (
MI.getOpcode()) {
1497 case WebAssembly::END_TRY: {
1501 auto *EHPad = TryToEHPad.
lookup(EndToBegin[&
MI]);
1505 if (NextIt != EHPad->
rend())
1509 case WebAssembly::END_BLOCK:
1510 case WebAssembly::END_LOOP:
1511 case WebAssembly::DELEGATE:
1512 EndToBegin[&
MI]->getOperand(0).setImm(int32_t(RetType));
1524 while (!Worklist.
empty())
1534 TII.get(WebAssembly::END_FUNCTION));
1543 for (
auto &
MBB : MF)
1544 placeLoopMarker(
MBB);
1546 const MCAsmInfo *MCAI = MF.getTarget().getMCAsmInfo();
1547 for (
auto &
MBB : MF) {
1551 MF.getFunction().hasPersonalityFn())
1552 placeTryMarker(
MBB);
1555 placeBlockMarker(
MBB);
1560 MF.getFunction().hasPersonalityFn()) {
1561 bool Changed = fixCallUnwindMismatches(MF);
1562 Changed |= fixCatchUnwindMismatches(MF);
1564 recalculateScopeTops(MF);
1568unsigned WebAssemblyCFGStackify::getBranchDepth(
1580unsigned WebAssemblyCFGStackify::getDelegateDepth(
1582 if (
MBB == FakeCallerBB)
1583 return Stack.size();
1589 return getBranchDepth(Stack,
MBB);
1607 if (
X.first == EndTry->
getParent() &&
X.second == EndTry)
1615unsigned WebAssemblyCFGStackify::getRethrowDepth(
1642 if (
End->getOpcode() == WebAssembly::END_TRY) {
1643 auto *EHPad = TryToEHPad[EndToBegin[
End]];
1644 if (EHPadStack.
back() == EHPad)
1653void WebAssemblyCFGStackify::rewriteDepthImmediates(
MachineFunction &MF) {
1659 switch (
MI.getOpcode()) {
1660 case WebAssembly::BLOCK:
1661 case WebAssembly::TRY:
1662 assert(ScopeTops[
Stack.back().first->getNumber()]->getNumber() <=
1664 "Block/try marker should be balanced");
1668 case WebAssembly::LOOP:
1669 assert(
Stack.back().first == &
MBB &&
"Loop top should be balanced");
1673 case WebAssembly::END_BLOCK:
1677 case WebAssembly::END_TRY: {
1681 auto *EHPad = TryToEHPad[EndToBegin[&
MI]];
1686 case WebAssembly::END_LOOP:
1690 case WebAssembly::CATCH:
1691 case WebAssembly::CATCH_ALL:
1695 case WebAssembly::RETHROW:
1696 MI.getOperand(0).setImm(getRethrowDepth(Stack, EHPadStack));
1700 if (
MI.isTerminator()) {
1703 while (
MI.getNumOperands() > 0)
1704 MI.removeOperand(
MI.getNumOperands() - 1);
1705 for (
auto MO : Ops) {
1707 if (
MI.getOpcode() == WebAssembly::DELEGATE)
1709 getDelegateDepth(Stack, MO.getMBB()));
1712 getBranchDepth(Stack, MO.getMBB()));
1714 MI.addOperand(MF, MO);
1718 if (
MI.getOpcode() == WebAssembly::DELEGATE)
1724 assert(
Stack.empty() &&
"Control flow should be balanced");
1727void WebAssemblyCFGStackify::cleanupFunctionData(
MachineFunction &MF) {
1730 AppendixBB = FakeCallerBB =
nullptr;
1733void WebAssemblyCFGStackify::releaseMemory() {
1741bool WebAssemblyCFGStackify::runOnMachineFunction(
MachineFunction &MF) {
1743 "********** Function: "
1746 MDT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
1759 removeUnnecessaryInstrs(MF);
1762 rewriteDepthImmediates(MF);
1766 fixEndsAtEndOfFunction(MF);
1775 cleanupFunctionData(MF);
unsigned const MachineRegisterInfo * MRI
static const Function * getParent(const Value *V)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
const HexagonInstrInfo * TII
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
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static bool explicitlyBranchesTo(MachineBasicBlock *Pred, MachineBasicBlock *MBB)
Test whether Pred has any terminators explicitly branching to MBB, as opposed to falling through.
static MachineBasicBlock::iterator getLatestInsertPos(MachineBasicBlock *MBB, const Container &BeforeSet, const Container &AfterSet)
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.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
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.
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....
BlockT * getHeader() const
Represents a single loop in the control flow graph.
This class is intended to be used as a base class for asm properties and features specific to the tar...
ExceptionHandling getExceptionHandlingType() const
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...
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
bool isPredecessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a predecessor of this block.
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any debug instructions.
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.
iterator_range< iterator > terminators()
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
StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
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.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
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.
void deleteMachineBasicBlock(MachineBasicBlock *MBB)
DeleteMachineBasicBlock - Delete the given MachineBasicBlock.
Function & getFunction()
Return the LLVM function that this machine code represents.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
const MachineBasicBlock & back() const
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const WasmEHFuncInfo * getWasmEHFuncInfo() const
getWasmEHFuncInfo - Return information about how the current function uses Wasm exception handling.
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)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
void insert(iterator MBBI, MachineBasicBlock *MBB)
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
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
MachineOperand class - Representation of each machine instruction operand.
static MachineOperand CreateImm(int64_t Val)
void invalidateLiveness()
invalidateLiveness - Indicates that register liveness is no longer being tracked accurately.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
virtual void releaseMemory()
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
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.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
const std::vector< MVT > & getResults() const
const Triple & getTargetTriple() const
self_iterator getIterator()
A collection of legacy interfaces for querying information about the current executing process.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI)
Test whether MI is a child of some other node in an expression tree.
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)
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...
auto reverse(ContainerTy &&C)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionPass * createWebAssemblyCFGStackify()