LLVM 19.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
21namespace llvm {
22
23class MachineBasicBlock;
24class MachineLoop;
25class MachineLoopInfo;
26class WebAssemblyException;
27class WebAssemblyExceptionInfo;
28
29namespace WebAssembly {
30
31// Wrapper for loops and exceptions
33public:
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;
40 virtual bool isLoop() const = 0;
41};
42
43template <typename T> class ConcreteSortRegion : public SortRegion {
44 const T *Unit;
45
46public:
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
71public:
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
MachineBasicBlock & MBB
This file defines the DenseMap class.
MachineBasicBlock * getHeader() const override
bool contains(const MachineBasicBlock *MBB) const override
iterator_range< block_iterator > blocks() const override
const SortRegion * getRegionFor(const MachineBasicBlock *MBB)
SortRegionInfo(const MachineLoopInfo &MLI, const WebAssemblyExceptionInfo &WEI)
MachineBasicBlock * getBottom(const SortRegion *R)
virtual bool contains(const MachineBasicBlock *MBB) const =0
virtual unsigned getNumBlocks() const =0
virtual iterator_range< block_iterator > blocks() const =0
virtual MachineBasicBlock * getHeader() const =0
virtual bool isLoop() const =0
typename ArrayRef< MachineBasicBlock * >::const_iterator block_iterator
virtual ~SortRegion()=default
A range adaptor for a pair of iterators.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18