LLVM  13.0.0git
WebAssemblySortRegion.h
Go to the documentation of this file.
1 //===-- WebAssemblySortRegion.h - WebAssembly Sort SortRegion ----*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file implements regions used in CFGSort and CFGStackify.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYSORTREGION_H
15 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYSORTREGION_H
16 
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/DenseMap.h"
20 
21 namespace llvm {
22 
23 class MachineBasicBlock;
24 class MachineLoop;
25 class MachineLoopInfo;
26 class WebAssemblyException;
27 class WebAssemblyExceptionInfo;
28 
29 namespace WebAssembly {
30 
31 // Wrapper for loops and exceptions
32 class SortRegion {
33 public:
34  virtual ~SortRegion() = default;
35  virtual MachineBasicBlock *getHeader() const = 0;
36  virtual bool contains(const MachineBasicBlock *MBB) const = 0;
37  virtual unsigned getNumBlocks() const = 0;
39  virtual iterator_range<block_iterator> blocks() const = 0;
40  virtual bool isLoop() const = 0;
41 };
42 
43 template <typename T> class ConcreteSortRegion : public SortRegion {
44  const T *Unit;
45 
46 public:
47  ConcreteSortRegion(const T *Unit) : Unit(Unit) {}
48  MachineBasicBlock *getHeader() const override { return Unit->getHeader(); }
49  bool contains(const MachineBasicBlock *MBB) const override {
50  return Unit->contains(MBB);
51  }
52  unsigned getNumBlocks() const override { return Unit->getNumBlocks(); }
54  return Unit->blocks();
55  }
56  bool isLoop() const override { return false; }
57 };
58 
59 // This class has information of nested SortRegions; this is analogous to what
60 // LoopInfo is for loops.
64 
65  const MachineLoopInfo &MLI;
66  const WebAssemblyExceptionInfo &WEI;
69  ExceptionMap;
70 
71 public:
73  const WebAssemblyExceptionInfo &WEI)
74  : MLI(MLI), WEI(WEI) {}
75 
76  // Returns a smallest loop or exception that contains MBB
78 
79  // Return the "bottom" block among all blocks dominated by the region
80  // (MachineLoop or WebAssemblyException) header. This works when the entity is
81  // discontiguous.
85 };
86 
87 } // end namespace WebAssembly
88 
89 } // end namespace llvm
90 
91 #endif
llvm::WebAssembly::SortRegion::getHeader
virtual MachineBasicBlock * getHeader() const =0
llvm
Definition: AllocatorList.h:23
llvm::WebAssembly::ConcreteSortRegion::blocks
iterator_range< block_iterator > blocks() const override
Definition: WebAssemblySortRegion.h:53
llvm::WebAssembly::SortRegion::block_iterator
typename ArrayRef< MachineBasicBlock * >::const_iterator block_iterator
Definition: WebAssemblySortRegion.h:38
llvm::WebAssembly::SortRegion::contains
virtual bool contains(const MachineBasicBlock *MBB) const =0
llvm::WebAssembly::SortRegion::~SortRegion
virtual ~SortRegion()=default
llvm::WebAssembly::SortRegionInfo::getRegionFor
const SortRegion * getRegionFor(const MachineBasicBlock *MBB)
Definition: WebAssemblySortRegion.cpp:17
llvm::WebAssembly::ConcreteSortRegion
Definition: WebAssemblySortRegion.h:43
llvm::WebAssembly::ConcreteSortRegion::getNumBlocks
unsigned getNumBlocks() const override
Definition: WebAssemblySortRegion.h:52
llvm::WebAssembly::SortRegion::getNumBlocks
virtual unsigned getNumBlocks() const =0
DenseMap.h
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::WebAssemblyException
Definition: WebAssemblyExceptionInfo.h:42
llvm::ArrayRef::const_iterator
const_pointer const_iterator
Definition: ArrayRef.h:49
llvm::RISCVFenceField::R
@ R
Definition: RISCVBaseInfo.h:133
llvm::MachineLoopInfo
Definition: MachineLoopInfo.h:90
llvm::WebAssembly::ConcreteSortRegion::isLoop
bool isLoop() const override
Definition: WebAssemblySortRegion.h:56
llvm::WebAssembly::ConcreteSortRegion::ConcreteSortRegion
ConcreteSortRegion(const T *Unit)
Definition: WebAssemblySortRegion.h:47
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::MachineLoop
Definition: MachineLoopInfo.h:45
llvm::WebAssembly::SortRegion::blocks
virtual iterator_range< block_iterator > blocks() const =0
llvm::DenseMap
Definition: DenseMap.h:714
llvm::WebAssemblyExceptionInfo
Definition: WebAssemblyExceptionInfo.h:123
ArrayRef.h
iterator_range.h
llvm::WebAssembly::ConcreteSortRegion::getHeader
MachineBasicBlock * getHeader() const override
Definition: WebAssemblySortRegion.h:48
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::WebAssembly::SortRegion::isLoop
virtual bool isLoop() const =0
llvm::WebAssembly::SortRegionInfo::SortRegionInfo
SortRegionInfo(const MachineLoopInfo &MLI, const WebAssemblyExceptionInfo &WEI)
Definition: WebAssemblySortRegion.h:72
llvm::WebAssembly::ConcreteSortRegion::contains
bool contains(const MachineBasicBlock *MBB) const override
Definition: WebAssemblySortRegion.h:49
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::WebAssembly::SortRegion
Definition: WebAssemblySortRegion.h:32
llvm::WebAssembly::SortRegionInfo::getBottom
MachineBasicBlock * getBottom(const SortRegion *R)
Definition: WebAssemblySortRegion.cpp:45
llvm::WebAssembly::SortRegionInfo
Definition: WebAssemblySortRegion.h:61