LLVM  10.0.0
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 }
const T & front() const
front - Get the first element.
Definition: ArrayRef.h:161
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:282
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:197
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:46
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:153