2003-09-30 20:37:50 +02:00
|
|
|
//=- llvm/Analysis/PostDominators.h - Post Dominator Calculation-*- C++ -*-===//
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-08-22 01:43:50 +02:00
|
|
|
//
|
|
|
|
// This file exposes interfaces to post dominance information.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 01:45:19 +01:00
|
|
|
#ifndef LLVM_ANALYSIS_POSTDOMINATORS_H
|
|
|
|
#define LLVM_ANALYSIS_POSTDOMINATORS_H
|
2002-08-22 01:43:50 +02:00
|
|
|
|
2014-01-13 10:26:24 +01:00
|
|
|
#include "llvm/IR/Dominators.h"
|
2016-02-26 11:02:04 +01:00
|
|
|
#include "llvm/IR/PassManager.h"
|
2002-08-22 01:43:50 +02:00
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
2004-03-01 00:55:11 +01:00
|
|
|
/// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
|
2014-08-29 23:53:01 +02:00
|
|
|
/// compute the post-dominator tree.
|
2004-03-01 00:55:11 +01:00
|
|
|
///
|
2016-02-25 18:54:07 +01:00
|
|
|
struct PostDominatorTree : public DominatorTreeBase<BasicBlock> {
|
2016-02-25 19:24:19 +01:00
|
|
|
typedef DominatorTreeBase<BasicBlock> Base;
|
|
|
|
|
2016-02-25 18:54:07 +01:00
|
|
|
PostDominatorTree() : DominatorTreeBase<BasicBlock>(true) {}
|
2016-02-25 19:24:19 +01:00
|
|
|
|
|
|
|
PostDominatorTree(PostDominatorTree &&Arg)
|
|
|
|
: Base(std::move(static_cast<Base &>(Arg))) {}
|
|
|
|
|
|
|
|
PostDominatorTree &operator=(PostDominatorTree &&RHS) {
|
|
|
|
Base::operator=(std::move(static_cast<Base &>(RHS)));
|
|
|
|
return *this;
|
|
|
|
}
|
2016-02-25 18:54:07 +01:00
|
|
|
};
|
2007-05-01 23:15:47 +02:00
|
|
|
|
2016-02-25 18:54:07 +01:00
|
|
|
/// \brief Analysis pass which computes a \c PostDominatorTree.
|
2016-03-11 11:22:49 +01:00
|
|
|
class PostDominatorTreeAnalysis
|
2016-03-11 11:33:22 +01:00
|
|
|
: public AnalysisInfoMixin<PostDominatorTreeAnalysis> {
|
|
|
|
friend AnalysisInfoMixin<PostDominatorTreeAnalysis>;
|
2016-03-11 11:22:49 +01:00
|
|
|
static char PassID;
|
|
|
|
|
|
|
|
public:
|
2016-02-25 18:54:07 +01:00
|
|
|
/// \brief Provide the result typedef for this analysis pass.
|
|
|
|
typedef PostDominatorTree Result;
|
2002-08-22 01:43:50 +02:00
|
|
|
|
2016-02-25 18:54:07 +01:00
|
|
|
/// \brief Run the analysis pass over a function and produce a post dominator
|
|
|
|
/// tree.
|
2016-06-17 02:11:01 +02:00
|
|
|
PostDominatorTree run(Function &F, FunctionAnalysisManager &);
|
2016-02-25 18:54:07 +01:00
|
|
|
};
|
2009-09-27 19:39:12 +02:00
|
|
|
|
2016-02-25 18:54:07 +01:00
|
|
|
/// \brief Printer pass for the \c PostDominatorTree.
|
2016-02-26 12:44:45 +01:00
|
|
|
class PostDominatorTreePrinterPass
|
2016-03-11 11:33:22 +01:00
|
|
|
: public PassInfoMixin<PostDominatorTreePrinterPass> {
|
2016-02-25 18:54:07 +01:00
|
|
|
raw_ostream &OS;
|
2009-09-27 19:39:12 +02:00
|
|
|
|
2016-02-25 18:54:07 +01:00
|
|
|
public:
|
|
|
|
explicit PostDominatorTreePrinterPass(raw_ostream &OS);
|
2016-03-11 12:05:24 +01:00
|
|
|
PreservedAnalyses run(Function &F, AnalysisManager<Function> &AM);
|
2016-02-25 18:54:07 +01:00
|
|
|
};
|
2008-02-27 19:38:29 +01:00
|
|
|
|
2016-02-25 18:54:07 +01:00
|
|
|
struct PostDominatorTreeWrapperPass : public FunctionPass {
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
|
|
|
PostDominatorTree DT;
|
2010-03-07 12:15:04 +01:00
|
|
|
|
2016-02-25 18:54:07 +01:00
|
|
|
PostDominatorTreeWrapperPass() : FunctionPass(ID) {
|
|
|
|
initializePostDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry());
|
2016-02-25 17:45:53 +01:00
|
|
|
}
|
2013-06-09 17:09:30 +02:00
|
|
|
|
2016-02-25 18:54:07 +01:00
|
|
|
PostDominatorTree &getPostDomTree() { return DT; }
|
|
|
|
const PostDominatorTree &getPostDomTree() const { return DT; }
|
2016-02-25 17:45:53 +01:00
|
|
|
|
2016-02-25 18:54:07 +01:00
|
|
|
bool runOnFunction(Function &F) override;
|
2016-02-25 17:45:53 +01:00
|
|
|
|
2016-02-25 18:54:07 +01:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.setPreservesAll();
|
2013-11-26 21:11:12 +01:00
|
|
|
}
|
|
|
|
|
2014-03-05 08:30:04 +01:00
|
|
|
void releaseMemory() override {
|
2016-02-25 18:54:07 +01:00
|
|
|
DT.releaseMemory();
|
2009-09-27 19:39:12 +02:00
|
|
|
}
|
|
|
|
|
2014-03-05 08:30:04 +01:00
|
|
|
void print(raw_ostream &OS, const Module*) const override;
|
2002-08-22 01:43:50 +02:00
|
|
|
};
|
|
|
|
|
2008-05-29 19:00:13 +02:00
|
|
|
FunctionPass* createPostDomTree();
|
2002-08-22 01:43:50 +02:00
|
|
|
|
2009-10-18 06:05:53 +02:00
|
|
|
template <> struct GraphTraits<PostDominatorTree*>
|
|
|
|
: public GraphTraits<DomTreeNode*> {
|
|
|
|
static NodeType *getEntryNode(PostDominatorTree *DT) {
|
|
|
|
return DT->getRootNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
static nodes_iterator nodes_begin(PostDominatorTree *N) {
|
2009-11-30 13:06:37 +01:00
|
|
|
if (getEntryNode(N))
|
|
|
|
return df_begin(getEntryNode(N));
|
|
|
|
else
|
|
|
|
return df_end(getEntryNode(N));
|
2009-10-18 06:05:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static nodes_iterator nodes_end(PostDominatorTree *N) {
|
|
|
|
return df_end(getEntryNode(N));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-23 11:49:53 +02:00
|
|
|
} // End llvm namespace
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2002-08-22 01:43:50 +02:00
|
|
|
#endif
|