LLVM 20.0.0git
MachineRegionInfo.h
Go to the documentation of this file.
1//===- llvm/CodeGen/MachineRegionInfo.h -------------------------*- 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#ifndef LLVM_CODEGEN_MACHINEREGIONINFO_H
10#define LLVM_CODEGEN_MACHINEREGIONINFO_H
11
21#include <cassert>
22
23namespace llvm {
24
25class MachinePostDominatorTree;
26class MachineRegion;
27class MachineRegionNode;
28class MachineRegionInfo;
29
30template <> struct RegionTraits<MachineFunction> {
43
44 static unsigned getNumSuccessors(MachineBasicBlock *BB) {
45 return BB->succ_size();
46 }
47};
48
49class MachineRegionNode : public RegionNodeBase<RegionTraits<MachineFunction>> {
50public:
52 bool isSubRegion = false)
54 isSubRegion) {}
55
56 bool operator==(const MachineRegion &RN) const {
57 return this == reinterpret_cast<const MachineRegionNode *>(&RN);
58 }
59};
60
61class MachineRegion : public RegionBase<RegionTraits<MachineFunction>> {
62public:
65 MachineRegion *Parent = nullptr);
67
68 bool operator==(const MachineRegionNode &RN) const {
69 return &RN == reinterpret_cast<const MachineRegionNode *>(this);
70 }
71};
72
73class MachineRegionInfo : public RegionInfoBase<RegionTraits<MachineFunction>> {
74public:
77
78 // updateStatistics - Update statistic about created regions.
79 void updateStatistics(MachineRegion *R) final;
80
83};
84
87
88public:
89 static char ID;
90
91 explicit MachineRegionInfoPass();
93
95
96 const MachineRegionInfo &getRegionInfo() const { return RI; }
97
98 /// @name MachineFunctionPass interface
99 //@{
100 bool runOnMachineFunction(MachineFunction &F) override;
101 void releaseMemory() override;
102 void verifyAnalysis() const override;
103 void getAnalysisUsage(AnalysisUsage &AU) const override;
104 void print(raw_ostream &OS, const Module *) const override;
105 void dump() const;
106 //@}
107};
108
109template <>
110template <>
112RegionNodeBase<RegionTraits<MachineFunction>>::getNodeAs<MachineBasicBlock>()
113 const {
114 assert(!isSubRegion() && "This is not a MachineBasicBlock RegionNode!");
115 return getEntry();
116}
117
118template <>
119template <>
121RegionNodeBase<RegionTraits<MachineFunction>>::getNodeAs<MachineRegion>()
122 const {
123 assert(isSubRegion() && "This is not a subregion RegionNode!");
124 auto Unconst =
126 return reinterpret_cast<MachineRegion *>(Unconst);
127}
128
132
135
136template <>
141
143 return GraphTraits<FlatIt<MachineRegion *>>::getEntryNode(
144 RI->getTopLevelRegion());
145 }
146
148 return nodes_iterator::begin(getEntryNode(RI));
149 }
150
152 return nodes_iterator::end(getEntryNode(RI));
153 }
154};
155
156template <>
161
164 }
165
168 }
169
172 }
173};
174
175extern template class RegionBase<RegionTraits<MachineFunction>>;
176extern template class RegionNodeBase<RegionTraits<MachineFunction>>;
177extern template class RegionInfoBase<RegionTraits<MachineFunction>>;
178
179} // end namespace llvm
180
181#endif // LLVM_CODEGEN_MACHINEREGIONINFO_H
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
#define F(x, y, z)
Definition: MD5.cpp:55
#define RegionNodeGraphTraits(NodeT, BlockT, RegionT)
#define RegionGraphTraits(RegionT, NodeT)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
Represent the analysis usage information of a pass.
Base class for the actual dominator tree node.
unsigned succ_size() const
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...
Representation of each machine instruction.
Definition: MachineInstr.h:69
MachinePostDominatorTree - an analysis pass wrapper for DominatorTree used to compute the post-domina...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
bool runOnMachineFunction(MachineFunction &F) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
MachineRegionInfo & getRegionInfo()
const MachineRegionInfo & getRegionInfo() const
void verifyAnalysis() const override
verifyAnalysis() - This member can be implemented by a analysis pass to check state of analysis infor...
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
void print(raw_ostream &OS, const Module *) const override
print - Print out the internal state of the pass.
~MachineRegionInfo() override
void recalculate(MachineFunction &F, MachineDominatorTree *DT, MachinePostDominatorTree *PDT, MachineDominanceFrontier *DF)
void updateStatistics(MachineRegion *R) final
bool operator==(const MachineRegion &RN) const
MachineRegionNode(MachineRegion *Parent, MachineBasicBlock *Entry, bool isSubRegion=false)
bool operator==(const MachineRegionNode &RN) const
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A single entry single exit Region.
Definition: RegionInfo.h:252
Analysis that detects all canonical Regions.
Definition: RegionInfo.h:672
RegionT * getTopLevelRegion() const
Definition: RegionInfo.h:864
A RegionNode represents a subregion or a BasicBlock that is part of a Region.
Definition: RegionInfo.h:115
bool isSubRegion() const
Is this RegionNode a subregion?
Definition: RegionInfo.h:186
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
DomTreeNodeBase< MachineBasicBlock > MachineDomTreeNode
static NodeRef getEntryNode(MachineRegionInfoPass *RI)
static nodes_iterator nodes_end(MachineRegionInfoPass *RI)
static nodes_iterator nodes_begin(MachineRegionInfoPass *RI)
static nodes_iterator nodes_end(MachineRegionInfo *RI)
static NodeRef getEntryNode(MachineRegionInfo *RI)
static nodes_iterator nodes_begin(MachineRegionInfo *RI)
typename GraphType::UnknownGraphTypeError NodeRef
Definition: GraphTraits.h:95
static unsigned getNumSuccessors(MachineBasicBlock *BB)