LLVM 23.0.0git
MachineRegionInfo.cpp
Go to the documentation of this file.
1//===- lib/Codegen/MachineRegionInfo.cpp ----------------------------------===//
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
10#include "llvm/ADT/Statistic.h"
13#include "llvm/CodeGen/Passes.h"
14#include "llvm/Config/llvm-config.h"
16#include "llvm/Pass.h"
18#include "llvm/Support/Debug.h"
19
20#define DEBUG_TYPE "machine-region-info"
21
22using namespace llvm;
23
24STATISTIC(numMachineRegions, "The # of machine regions");
25STATISTIC(numMachineSimpleRegions, "The # of simple machine regions");
26
27namespace llvm {
28
32
33} // end namespace llvm
34
35//===----------------------------------------------------------------------===//
36// MachineRegion implementation
37
42
44
45//===----------------------------------------------------------------------===//
46// MachineRegionInfo implementation
47
49
51
53 ++numMachineRegions;
54
55 // TODO: Slow. Should only be enabled if -stats is used.
56 if (R->isSimple())
57 ++numMachineSimpleRegions;
58}
59
64 DT = DT_;
65 PDT = PDT_;
66 DF = DF_;
67
69
70 TopLevelRegion = new MachineRegion(Entry, nullptr, this, DT, nullptr);
71 updateStatistics(TopLevelRegion);
72 calculate(F);
73}
74
77 MachineFunctionAnalysisManager::Invalidator &) {
78 // Check whether the analysis, all analyses on functions, or the function's
79 // CFG has been preserved.
81 return !(PAC.preserved() ||
82 PAC.preservedSet<AllAnalysesOn<MachineFunction>>() ||
83 PAC.preservedSet<CFGAnalyses>());
84}
85
86//===----------------------------------------------------------------------===//
87// MachineRegionAnalysis implementation
88//
89AnalysisKey MachineRegionInfoAnalysis::Key;
99
107
108//===----------------------------------------------------------------------===//
109// MachineRegionInfoPass implementation
110//
111
113
115
118
119 auto DT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
120 auto PDT =
123
124 RI.recalculate(F, DT, PDT, DF);
125
126 LLVM_DEBUG(RI.dump());
127
128 return false;
129}
130
132 RI.releaseMemory();
133}
134
136 // Only do verification when user wants to, otherwise this expensive check
137 // will be invoked by PMDataManager::verifyPreservedAnalysis when
138 // a regionpass (marked PreservedAll) finish.
140 RI.verifyAnalysis();
141}
142
150
152 RI.print(OS);
153}
154
155#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
157 RI.dump();
158}
159#endif
160
163
165 "Detect single entry single exit regions", true, true)
170 "Detect single entry single exit regions", true, true)
171
172// Create methods available outside of this file, to use them
173// "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
174// the link time optimization.
175
176namespace llvm {
177
181
182} // end namespace llvm
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:663
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
#define DEBUG_TYPE
#define F(x, y, z)
Definition MD5.cpp:54
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition PassSupport.h:42
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
#define LLVM_DEBUG(...)
Definition Debug.h:119
This templated class represents "all analyses that operate over <aparticular IR unit>" (e....
Definition Analysis.h:50
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
Analysis pass which computes a MachineDominatorTree.
Analysis pass which computes a MachineDominatorTree.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
MachinePostDominatorTree - an analysis pass wrapper for DominatorTree used to compute the post-domina...
Result run(MachineFunction &F, MachineFunctionAnalysisManager &AM)
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...
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.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
~MachineRegionInfo() override
void recalculate(MachineFunction &F, MachineDominatorTree *DT, MachinePostDominatorTree *PDT, MachineDominanceFrontier *DF)
void updateStatistics(MachineRegion *R) final
bool invalidate(MachineFunction &F, const PreservedAnalyses &PA, MachineFunctionAnalysisManager::Invalidator &)
Handle invalidation explicitly.
LLVM_ABI ~MachineRegion()
LLVM_ABI MachineRegion(MachineBasicBlock *Entry, MachineBasicBlock *Exit, MachineRegionInfo *RI, MachineDominatorTree *DT, MachineRegion *Parent=nullptr)
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Definition Analysis.h:275
A single entry single exit Region.
Definition RegionInfo.h:252
RegionBase(BlockT *Entry, BlockT *Exit, RegionInfoT *RI, DomTreeT *DT, RegionT *Parent=nullptr)
Analysis that detects all canonical Regions.
Definition RegionInfo.h:672
void print(raw_ostream &OS) const
A RegionNode represents a subregion or a BasicBlock that is part of a Region.
Definition RegionInfo.h:115
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
FunctionPass * createMachineRegionInfoPass()
LLVM_ABI char & MachineRegionInfoPassID
MachineRegionInfo - This pass computes SESE regions for machine functions.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29