LLVM  14.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/Config/llvm-config.h"
14 #include "llvm/InitializePasses.h"
15 #include "llvm/Pass.h"
16 #include "llvm/Support/Compiler.h"
17 #include "llvm/Support/Debug.h"
18 
19 #define DEBUG_TYPE "machine-region-info"
20 
21 using namespace llvm;
22 
23 STATISTIC(numMachineRegions, "The # of machine regions");
24 STATISTIC(numMachineSimpleRegions, "The # of simple machine regions");
25 
26 namespace llvm {
27 
31 
32 } // end namespace llvm
33 
34 //===----------------------------------------------------------------------===//
35 // MachineRegion implementation
36 
39  MachineDominatorTree *DT, MachineRegion *Parent) :
40  RegionBase<RegionTraits<MachineFunction>>(Entry, Exit, RI, DT, Parent) {}
41 
43 
44 //===----------------------------------------------------------------------===//
45 // MachineRegionInfo implementation
46 
48 
50 
52  ++numMachineRegions;
53 
54  // TODO: Slow. Should only be enabled if -stats is used.
55  if (R->isSimple())
56  ++numMachineSimpleRegions;
57 }
58 
63  DT = DT_;
64  PDT = PDT_;
65  DF = DF_;
66 
68 
69  TopLevelRegion = new MachineRegion(Entry, nullptr, this, DT, nullptr);
70  updateStatistics(TopLevelRegion);
71  calculate(F);
72 }
73 
74 //===----------------------------------------------------------------------===//
75 // MachineRegionInfoPass implementation
76 //
77 
80 }
81 
83 
85  releaseMemory();
86 
87  auto DT = &getAnalysis<MachineDominatorTree>();
88  auto PDT = &getAnalysis<MachinePostDominatorTree>();
89  auto DF = &getAnalysis<MachineDominanceFrontier>();
90 
91  RI.recalculate(F, DT, PDT, DF);
92 
93  LLVM_DEBUG(RI.dump());
94 
95  return false;
96 }
97 
99  RI.releaseMemory();
100 }
101 
103  // Only do verification when user wants to, otherwise this expensive check
104  // will be invoked by PMDataManager::verifyPreservedAnalysis when
105  // a regionpass (marked PreservedAll) finish.
107  RI.verifyAnalysis();
108 }
109 
111  AU.setPreservesAll();
116 }
117 
119  RI.print(OS);
120 }
121 
122 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
124  RI.dump();
125 }
126 #endif
127 
130 
132  "Detect single entry single exit regions", true, true)
137  "Detect single entry single exit regions", true, true)
138 
139 // Create methods available outside of this file, to use them
140 // "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
141 // the link time optimization.
142 
143 namespace llvm {
144 
146  return new MachineRegionInfoPass();
147 }
148 
149 } // end namespace llvm
llvm::MachineRegionInfoPass::ID
static char ID
Definition: MachineRegionInfo.h:89
LLVM_DUMP_METHOD
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:506
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::MachineRegionInfo::updateStatistics
void updateStatistics(MachineRegion *R) final
Definition: MachineRegionInfo.cpp:51
Pass.h
llvm::RegionBase
A single entry single exit Region.
Definition: RegionInfo.h:66
llvm::MachineRegion::MachineRegion
MachineRegion(MachineBasicBlock *Entry, MachineBasicBlock *Exit, MachineRegionInfo *RI, MachineDominatorTree *DT, MachineRegion *Parent=nullptr)
Definition: MachineRegionInfo.cpp:37
Statistic.h
true
Detect single entry single exit true
Definition: MachineRegionInfo.cpp:137
llvm::createMachineRegionInfoPass
FunctionPass * createMachineRegionInfoPass()
Definition: MachineRegionInfo.cpp:145
llvm::MachineRegionInfoPass::dump
void dump() const
Definition: MachineRegionInfo.cpp:123
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(MachineRegionInfoPass, DEBUG_TYPE, "Detect single entry single exit regions", true, true) INITIALIZE_PASS_END(MachineRegionInfoPass
regions
Detect single entry single exit regions
Definition: MachineRegionInfo.cpp:137
llvm::MachineRegionInfoPass::verifyAnalysis
void verifyAnalysis() const override
verifyAnalysis() - This member can be implemented by a analysis pass to check state of analysis infor...
Definition: MachineRegionInfo.cpp:102
llvm::MachineRegionInfo::MachineRegionInfo
MachineRegionInfo()
llvm::MachineFunctionPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: MachineFunctionPass.cpp:102
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
F
#define F(x, y, z)
Definition: MD5.cpp:56
DEBUG_TYPE
#define DEBUG_TYPE
Definition: MachineRegionInfo.cpp:19
llvm::MachineRegionInfo::~MachineRegionInfo
~MachineRegionInfo() override
llvm::MachineRegionInfo::recalculate
void recalculate(MachineFunction &F, MachineDominatorTree *DT, MachinePostDominatorTree *PDT, MachineDominanceFrontier *DF)
Definition: MachineRegionInfo.cpp:59
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
llvm::RegionInfoBase< RegionTraits< MachineFunction > >::VerifyRegionInfo
static bool VerifyRegionInfo
Definition: RegionInfo.h:802
llvm::MachineRegion::~MachineRegion
~MachineRegion()
llvm::RegionInfoBase::dump
void dump() const
Definition: RegionInfoImpl.h:792
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::MachineRegionInfoPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: MachineRegionInfo.cpp:110
llvm::MachineRegionInfoPass
Definition: MachineRegionInfo.h:85
llvm::STATISTIC
STATISTIC(NumFunctions, "Total number of functions")
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::MachineRegion
Definition: MachineRegionInfo.h:61
llvm::RegionInfoBase
Analysis that detects all canonical Regions.
Definition: RegionInfo.h:68
MachineRegionInfo.h
DF
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::MachineRegionInfoPass::print
void print(raw_ostream &OS, const Module *) const override
print - Print out the internal state of the pass.
Definition: MachineRegionInfo.cpp:118
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
llvm::MachineDominanceFrontier
Definition: MachineDominanceFrontier.h:20
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
llvm::MachineRegionInfoPass::~MachineRegionInfoPass
~MachineRegionInfoPass() override
llvm::MachineRegionInfoPass::releaseMemory
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Definition: MachineRegionInfo.cpp:98
RegionInfoImpl.h
llvm::RegionInfoBase::print
void print(raw_ostream &OS) const
Definition: RegionInfoImpl.h:784
MachinePostDominators.h
llvm::MachineRegionInfoPass::MachineRegionInfoPass
MachineRegionInfoPass()
Definition: MachineRegionInfo.cpp:78
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MachineFunction
Definition: MachineFunction.h:241
Compiler.h
llvm::MachineRegionInfoPass::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &F) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition: MachineRegionInfo.cpp:84
llvm::MachineRegionInfoPassID
char & MachineRegionInfoPassID
MachineRegionInfo - This pass computes SESE regions for machine functions.
Definition: MachineRegionInfo.cpp:129
llvm::MachinePostDominatorTree
MachinePostDominatorTree - an analysis pass wrapper for DominatorTree used to compute the post-domina...
Definition: MachinePostDominators.h:27
llvm::RegionInfoBase::verifyAnalysis
void verifyAnalysis() const
Definition: RegionInfoImpl.h:804
llvm::AnalysisUsage::setPreservesAll
void setPreservesAll()
Set by analyses that do not transform their input at all.
Definition: PassAnalysisSupport.h:130
llvm::RegionTraits
Definition: RegionInfo.h:75
llvm::MachineRegionInfo
Definition: MachineRegionInfo.h:73
llvm::RegionInfoBase::releaseMemory
void releaseMemory()
Definition: RegionInfoImpl.h:796
exit
declare void exit(i32) noreturn nounwind This compiles into
Definition: README.txt:1072
llvm::RegionNodeBase
A RegionNode represents a subregion or a BasicBlock that is part of a Region.
Definition: RegionInfo.h:117
llvm::initializeMachineRegionInfoPassPass
void initializeMachineRegionInfoPassPass(PassRegistry &)
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
llvm::GraphTraits
Definition: GraphTraits.h:35
llvm::MachineDominatorTree
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
Definition: MachineDominators.h:46
InitializePasses.h
Debug.h
entry
print Instructions which execute on loop entry
Definition: MustExecute.cpp:339
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38