LLVM  10.0.0svn
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 
16 using namespace llvm;
17 
18 namespace llvm {
19 template class DominatorTreeBase<MachineBasicBlock, true>; // PostDomTreeBase
20 
21 extern bool VerifyMachineDomInfo;
22 } // namespace llvm
23 
25 
26 //declare initializeMachinePostDominatorTreePass
28  "MachinePostDominator Tree Construction", true, true)
29 
31  : MachineFunctionPass(ID), PDT(nullptr) {
33 }
34 
36  return new MachinePostDominatorTree();
37 }
38 
40  PDT = std::make_unique<PostDomTreeT>();
41  PDT->recalculate(F);
42  return false;
43 }
44 
46  AU.setPreservesAll();
48 }
49 
51  ArrayRef<MachineBasicBlock *> Blocks) const {
52  assert(!Blocks.empty());
53 
54  MachineBasicBlock *NCD = Blocks.front();
55  for (MachineBasicBlock *BB : Blocks.drop_front()) {
56  NCD = PDT->findNearestCommonDominator(NCD, BB);
57 
58  // Stop when the root is reached.
59  if (PDT->isVirtualRoot(PDT->getNode(NCD)))
60  return nullptr;
61  }
62 
63  return NCD;
64 }
65 
67  if (PDT && VerifyMachineDomInfo)
68  if (!PDT->verify(PostDomTreeT::VerificationLevel::Basic)) {
69  errs() << "MachinePostDominatorTree verification failed\n";
70 
71  abort();
72  }
73 }
74 
76  const Module *M) const {
77  PDT->print(OS);
78 }
const T & front() const
front - Get the first element.
Definition: ArrayRef.h:151
void print(llvm::raw_ostream &OS, const Module *M=nullptr) const override
print - Print out the internal state of the pass.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:66
F(f)
FunctionPass * createMachinePostDominatorTreePass()
void verifyAnalysis() const override
verifyAnalysis() - This member can be implemented by a analysis pass to check state of analysis infor...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
MachineBasicBlock * findNearestCommonDominator(MachineBasicBlock *A, MachineBasicBlock *B) const
void initializeMachinePostDominatorTreePass(PassRegistry &)
Core dominator tree base class.
Definition: LoopInfo.h:66
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
INITIALIZE_PASS(MachinePostDominatorTree, "machinepostdomtree", "MachinePostDominator Tree Construction", true, true) MachinePostDominatorTree
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:284
void setPreservesAll()
Set by analyses that do not transform their input at all.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition: ArrayRef.h:187
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MachinePostDominatorTree - an analysis pass wrapper for DominatorTree used to compute the post-domina...
bool VerifyMachineDomInfo
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:143