LLVM  13.0.0git
WebAssemblySortRegion.cpp
Go to the documentation of this file.
4 
5 using namespace llvm;
6 using namespace WebAssembly;
7 
8 namespace llvm {
9 namespace WebAssembly {
10 template <>
12  return true;
13 }
14 } // end namespace WebAssembly
15 } // end namespace llvm
16 
18  const auto *ML = MLI.getLoopFor(MBB);
19  const auto *WE = WEI.getExceptionFor(MBB);
20  if (!ML && !WE)
21  return nullptr;
22  // We determine subregion relationship by domination of their headers, i.e.,
23  // if region A's header dominates region B's header, B is a subregion of A.
24  // WebAssemblyException contains BBs in all its subregions (loops or
25  // exceptions), but MachineLoop may not, because MachineLoop does not
26  // contain BBs that don't have a path to its header even if they are
27  // dominated by its header. So here we should use
28  // WE->contains(ML->getHeader()), but not ML->contains(WE->getHeader()).
29  if ((ML && !WE) || (ML && WE && WE->contains(ML->getHeader()))) {
30  // If the smallest region containing MBB is a loop
31  if (LoopMap.count(ML))
32  return LoopMap[ML].get();
33  LoopMap[ML] = std::make_unique<ConcreteSortRegion<MachineLoop>>(ML);
34  return LoopMap[ML].get();
35  } else {
36  // If the smallest region containing MBB is an exception
37  if (ExceptionMap.count(WE))
38  return ExceptionMap[WE].get();
39  ExceptionMap[WE] =
40  std::make_unique<ConcreteSortRegion<WebAssemblyException>>(WE);
41  return ExceptionMap[WE].get();
42  }
43 }
44 
46  if (R->isLoop())
47  return getBottom(MLI.getLoopFor(R->getHeader()));
48  else
49  return getBottom(WEI.getExceptionFor(R->getHeader()));
50 }
51 
53  MachineBasicBlock *Bottom = ML->getHeader();
54  for (MachineBasicBlock *MBB : ML->blocks()) {
55  if (MBB->getNumber() > Bottom->getNumber())
56  Bottom = MBB;
57  // MachineLoop does not contain all BBs dominated by its header. BBs that
58  // don't have a path back to the loop header aren't included. But for the
59  // purpose of CFG sorting and stackification, we need a bottom BB among all
60  // BBs that are dominated by the loop header. So we check if there is any
61  // WebAssemblyException contained in this loop, and computes the most bottom
62  // BB of them all.
63  if (MBB->isEHPad()) {
65  if (ExBottom->getNumber() > Bottom->getNumber())
66  Bottom = ExBottom;
67  }
68  }
69  return Bottom;
70 }
71 
73  MachineBasicBlock *Bottom = WE->getHeader();
74  for (MachineBasicBlock *MBB : WE->blocks())
75  if (MBB->getNumber() > Bottom->getNumber())
76  Bottom = MBB;
77  return Bottom;
78 }
WebAssemblySortRegion.h
This file implements regions used in CFGSort and CFGStackify.
llvm
Definition: AllocatorList.h:23
llvm::MachineLoopInfo::getLoopFor
MachineLoop * getLoopFor(const MachineBasicBlock *BB) const
Return the innermost loop that BB lives in.
Definition: MachineLoopInfo.h:124
llvm::WebAssembly::SortRegionInfo::getRegionFor
const SortRegion * getRegionFor(const MachineBasicBlock *MBB)
Definition: WebAssemblySortRegion.cpp:17
llvm::WebAssemblyException
Definition: WebAssemblyExceptionInfo.h:42
llvm::WebAssembly::ConcreteSortRegion::isLoop
bool isLoop() const override
Definition: WebAssemblySortRegion.h:56
MachineLoopInfo.h
llvm::LoopBase::blocks
iterator_range< block_iterator > blocks() const
Definition: LoopInfo.h:178
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::MachineLoop
Definition: MachineLoopInfo.h:45
llvm::WebAssemblyException::getHeader
MachineBasicBlock * getHeader() const
Definition: WebAssemblyExceptionInfo.h:56
llvm::MachineBasicBlock::getNumber
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
Definition: MachineBasicBlock.h:969
llvm::WebAssemblyException::blocks
iterator_range< block_iterator > blocks() const
Definition: WebAssemblyExceptionInfo.h:82
llvm::MachineBasicBlock::isEHPad
bool isEHPad() const
Returns true if the block is a landing pad.
Definition: MachineBasicBlock.h:435
llvm::WebAssemblyExceptionInfo::getExceptionFor
WebAssemblyException * getExceptionFor(const MachineBasicBlock *MBB) const
Definition: WebAssemblyExceptionInfo.h:153
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
get
Should compile to something r4 addze r3 instead we get
Definition: README.txt:24
llvm::LoopBase::getHeader
BlockT * getHeader() const
Definition: LoopInfo.h:104
llvm::WebAssembly::SortRegion
Definition: WebAssemblySortRegion.h:32
WebAssemblyExceptionInfo.h
This file implements WebAssemblyException information analysis.
llvm::WebAssembly::SortRegionInfo::getBottom
MachineBasicBlock * getBottom(const SortRegion *R)
Definition: WebAssemblySortRegion.cpp:45