LLVM  14.0.0git
MachinePostDominators.cpp
Go to the documentation of this file.
1 //===- MachinePostDominators.cpp -Machine Post Dominator Calculation ------===//
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 // This file implements simple dominator construction algorithms for finding
10 // post dominators on machine functions.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/InitializePasses.h"
16 
17 using namespace llvm;
18 
19 namespace llvm {
20 template class DominatorTreeBase<MachineBasicBlock, true>; // PostDomTreeBase
21 
22 extern bool VerifyMachineDomInfo;
23 } // namespace llvm
24 
26 
27 //declare initializeMachinePostDominatorTreePass
29  "MachinePostDominator Tree Construction", true, true)
30 
32  : MachineFunctionPass(ID), PDT(nullptr) {
34 }
35 
37  return new MachinePostDominatorTree();
38 }
39 
41  PDT = std::make_unique<PostDomTreeT>();
42  PDT->recalculate(F);
43  return false;
44 }
45 
47  AU.setPreservesAll();
49 }
50 
52  ArrayRef<MachineBasicBlock *> Blocks) const {
53  assert(!Blocks.empty());
54 
55  MachineBasicBlock *NCD = Blocks.front();
56  for (MachineBasicBlock *BB : Blocks.drop_front()) {
57  NCD = PDT->findNearestCommonDominator(NCD, BB);
58 
59  // Stop when the root is reached.
60  if (PDT->isVirtualRoot(PDT->getNode(NCD)))
61  return nullptr;
62  }
63 
64  return NCD;
65 }
66 
68  if (PDT && VerifyMachineDomInfo)
69  if (!PDT->verify(PostDomTreeT::VerificationLevel::Basic)) {
70  errs() << "MachinePostDominatorTree verification failed\n";
71 
72  abort();
73  }
74 }
75 
77  const Module *M) const {
78  PDT->print(OS);
79 }
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::VerifyMachineDomInfo
bool VerifyMachineDomInfo
Definition: MachineDominators.cpp:27
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:892
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:160
llvm::MachineFunctionPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: MachineFunctionPass.cpp:102
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
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::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::ArrayRef::drop_front
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition: ArrayRef.h:204
llvm::initializeMachinePostDominatorTreePass
void initializeMachinePostDominatorTreePass(PassRegistry &)
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MachinePostDominatorTree::createMachinePostDominatorTreePass
FunctionPass * createMachinePostDominatorTreePass()
Definition: MachinePostDominators.cpp:36
MachinePostDominators.h
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MachinePostDominatorTree::print
void print(llvm::raw_ostream &OS, const Module *M=nullptr) const override
print - Print out the internal state of the pass.
Definition: MachinePostDominators.cpp:76
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::MachinePostDominatorTree::ID
static char ID
Definition: MachinePostDominators.h:32
llvm::DominatorTreeBase
Core dominator tree base class.
Definition: LoopInfo.h:65
llvm::MachinePostDominatorTree::verifyAnalysis
void verifyAnalysis() const override
verifyAnalysis() - This member can be implemented by a analysis pass to check state of analysis infor...
Definition: MachinePostDominators.cpp:67
llvm::MachinePostDominatorTree::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: MachinePostDominators.cpp:46
llvm::ArrayRef::front
const T & front() const
front - Get the first element.
Definition: ArrayRef.h:168
llvm::MachinePostDominatorTree
MachinePostDominatorTree - an analysis pass wrapper for DominatorTree used to compute the post-domina...
Definition: MachinePostDominators.h:27
llvm::AnalysisUsage::setPreservesAll
void setPreservesAll()
Set by analyses that do not transform their input at all.
Definition: PassAnalysisSupport.h:130
llvm::DominatorTreeBase::VerificationLevel::Basic
@ Basic
llvm::MachinePostDominatorTree::MachinePostDominatorTree
MachinePostDominatorTree()
llvm::MachinePostDominatorTree::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition: MachinePostDominators.cpp:40
INITIALIZE_PASS
INITIALIZE_PASS(MachinePostDominatorTree, "machinepostdomtree", "MachinePostDominator Tree Construction", true, true) MachinePostDominatorTree
Definition: MachinePostDominators.cpp:28
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::MachinePostDominatorTree::findNearestCommonDominator
MachineBasicBlock * findNearestCommonDominator(MachineBasicBlock *A, MachineBasicBlock *B) const
Definition: MachinePostDominators.h:77
abort
*Add support for compiling functions in both ARM and Thumb then taking the smallest *Add support for compiling individual basic blocks in thumb when in a larger ARM function This can be used for presumed cold like paths to abort(failure path of asserts)
InitializePasses.h
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37