mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Move Split<...>() into DomTreeBase. This should make the #include's of DominatorInternals.h
in CodeExtractor and LoopSimplify unnecessary. Hartmut, could you confirm that this fixes the issues you were seeing? git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43115 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
cd2858ee16
commit
7b714321df
@ -303,93 +303,6 @@ void Calculate(DominatorTreeBase<typename GraphT::NodeType>& DT, Function& F) {
|
|||||||
DT.DFSInfoValid = false;
|
DT.DFSInfoValid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBB is split and now it has one successor. Update dominator tree to
|
|
||||||
// reflect this change.
|
|
||||||
template<class NodeT, class GraphT>
|
|
||||||
void Split(DominatorTreeBase<typename GraphT::NodeType>& DT,
|
|
||||||
typename GraphT::NodeType* NewBB) {
|
|
||||||
assert(std::distance(GraphT::child_begin(NewBB), GraphT::child_end(NewBB)) == 1
|
|
||||||
&& "NewBB should have a single successor!");
|
|
||||||
typename GraphT::NodeType* NewBBSucc = *GraphT::child_begin(NewBB);
|
|
||||||
|
|
||||||
std::vector<typename GraphT::NodeType*> PredBlocks;
|
|
||||||
for (typename GraphTraits<Inverse<NodeT> >::ChildIteratorType PI =
|
|
||||||
GraphTraits<Inverse<NodeT> >::child_begin(NewBB),
|
|
||||||
PE = GraphTraits<Inverse<NodeT> >::child_end(NewBB); PI != PE; ++PI)
|
|
||||||
PredBlocks.push_back(*PI);
|
|
||||||
|
|
||||||
assert(!PredBlocks.empty() && "No predblocks??");
|
|
||||||
|
|
||||||
// The newly inserted basic block will dominate existing basic blocks iff the
|
|
||||||
// PredBlocks dominate all of the non-pred blocks. If all predblocks dominate
|
|
||||||
// the non-pred blocks, then they all must be the same block!
|
|
||||||
//
|
|
||||||
bool NewBBDominatesNewBBSucc = true;
|
|
||||||
{
|
|
||||||
typename GraphT::NodeType* OnePred = PredBlocks[0];
|
|
||||||
unsigned i = 1, e = PredBlocks.size();
|
|
||||||
for (i = 1; !DT.isReachableFromEntry(OnePred); ++i) {
|
|
||||||
assert(i != e && "Didn't find reachable pred?");
|
|
||||||
OnePred = PredBlocks[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (; i != e; ++i)
|
|
||||||
if (PredBlocks[i] != OnePred && DT.isReachableFromEntry(OnePred)) {
|
|
||||||
NewBBDominatesNewBBSucc = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NewBBDominatesNewBBSucc)
|
|
||||||
for (typename GraphTraits<Inverse<NodeT> >::ChildIteratorType PI =
|
|
||||||
GraphTraits<Inverse<NodeT> >::child_begin(NewBBSucc),
|
|
||||||
E = GraphTraits<Inverse<NodeT> >::child_end(NewBBSucc); PI != E; ++PI)
|
|
||||||
if (*PI != NewBB && !DT.dominates(NewBBSucc, *PI)) {
|
|
||||||
NewBBDominatesNewBBSucc = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The other scenario where the new block can dominate its successors are when
|
|
||||||
// all predecessors of NewBBSucc that are not NewBB are dominated by NewBBSucc
|
|
||||||
// already.
|
|
||||||
if (!NewBBDominatesNewBBSucc) {
|
|
||||||
NewBBDominatesNewBBSucc = true;
|
|
||||||
for (typename GraphTraits<Inverse<NodeT> >::ChildIteratorType PI =
|
|
||||||
GraphTraits<Inverse<NodeT> >::child_begin(NewBBSucc),
|
|
||||||
E = GraphTraits<Inverse<NodeT> >::child_end(NewBBSucc); PI != E; ++PI)
|
|
||||||
if (*PI != NewBB && !DT.dominates(NewBBSucc, *PI)) {
|
|
||||||
NewBBDominatesNewBBSucc = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find NewBB's immediate dominator and create new dominator tree node for
|
|
||||||
// NewBB.
|
|
||||||
BasicBlock *NewBBIDom = 0;
|
|
||||||
unsigned i = 0;
|
|
||||||
for (i = 0; i < PredBlocks.size(); ++i)
|
|
||||||
if (DT.isReachableFromEntry(PredBlocks[i])) {
|
|
||||||
NewBBIDom = PredBlocks[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
assert(i != PredBlocks.size() && "No reachable preds?");
|
|
||||||
for (i = i + 1; i < PredBlocks.size(); ++i) {
|
|
||||||
if (DT.isReachableFromEntry(PredBlocks[i]))
|
|
||||||
NewBBIDom = DT.findNearestCommonDominator(NewBBIDom, PredBlocks[i]);
|
|
||||||
}
|
|
||||||
assert(NewBBIDom && "No immediate dominator found??");
|
|
||||||
|
|
||||||
// Create the new dominator tree node... and set the idom of NewBB.
|
|
||||||
DomTreeNode *NewBBNode = DT.addNewBlock(NewBB, NewBBIDom);
|
|
||||||
|
|
||||||
// If NewBB strictly dominates other blocks, then it is now the immediate
|
|
||||||
// dominator of NewBBSucc. Update the dominator tree as appropriate.
|
|
||||||
if (NewBBDominatesNewBBSucc) {
|
|
||||||
DomTreeNode *NewBBSuccNode = DT.getNode(NewBBSucc);
|
|
||||||
DT.changeImmediateDominator(NewBBSuccNode, NewBBNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -203,6 +203,93 @@ protected:
|
|||||||
RootNode = 0;
|
RootNode = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewBB is split and now it has one successor. Update dominator tree to
|
||||||
|
// reflect this change.
|
||||||
|
template<class N, class GraphT>
|
||||||
|
void Split(DominatorTreeBase<typename GraphT::NodeType>& DT,
|
||||||
|
typename GraphT::NodeType* NewBB) {
|
||||||
|
assert(std::distance(GraphT::child_begin(NewBB), GraphT::child_end(NewBB)) == 1
|
||||||
|
&& "NewBB should have a single successor!");
|
||||||
|
typename GraphT::NodeType* NewBBSucc = *GraphT::child_begin(NewBB);
|
||||||
|
|
||||||
|
std::vector<typename GraphT::NodeType*> PredBlocks;
|
||||||
|
for (typename GraphTraits<Inverse<N> >::ChildIteratorType PI =
|
||||||
|
GraphTraits<Inverse<N> >::child_begin(NewBB),
|
||||||
|
PE = GraphTraits<Inverse<N> >::child_end(NewBB); PI != PE; ++PI)
|
||||||
|
PredBlocks.push_back(*PI);
|
||||||
|
|
||||||
|
assert(!PredBlocks.empty() && "No predblocks??");
|
||||||
|
|
||||||
|
// The newly inserted basic block will dominate existing basic blocks iff the
|
||||||
|
// PredBlocks dominate all of the non-pred blocks. If all predblocks dominate
|
||||||
|
// the non-pred blocks, then they all must be the same block!
|
||||||
|
//
|
||||||
|
bool NewBBDominatesNewBBSucc = true;
|
||||||
|
{
|
||||||
|
typename GraphT::NodeType* OnePred = PredBlocks[0];
|
||||||
|
unsigned i = 1, e = PredBlocks.size();
|
||||||
|
for (i = 1; !DT.isReachableFromEntry(OnePred); ++i) {
|
||||||
|
assert(i != e && "Didn't find reachable pred?");
|
||||||
|
OnePred = PredBlocks[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; i != e; ++i)
|
||||||
|
if (PredBlocks[i] != OnePred && DT.isReachableFromEntry(OnePred)) {
|
||||||
|
NewBBDominatesNewBBSucc = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NewBBDominatesNewBBSucc)
|
||||||
|
for (typename GraphTraits<Inverse<N> >::ChildIteratorType PI =
|
||||||
|
GraphTraits<Inverse<N> >::child_begin(NewBBSucc),
|
||||||
|
E = GraphTraits<Inverse<N> >::child_end(NewBBSucc); PI != E; ++PI)
|
||||||
|
if (*PI != NewBB && !DT.dominates(NewBBSucc, *PI)) {
|
||||||
|
NewBBDominatesNewBBSucc = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The other scenario where the new block can dominate its successors are when
|
||||||
|
// all predecessors of NewBBSucc that are not NewBB are dominated by NewBBSucc
|
||||||
|
// already.
|
||||||
|
if (!NewBBDominatesNewBBSucc) {
|
||||||
|
NewBBDominatesNewBBSucc = true;
|
||||||
|
for (typename GraphTraits<Inverse<N> >::ChildIteratorType PI =
|
||||||
|
GraphTraits<Inverse<N> >::child_begin(NewBBSucc),
|
||||||
|
E = GraphTraits<Inverse<N> >::child_end(NewBBSucc); PI != E; ++PI)
|
||||||
|
if (*PI != NewBB && !DT.dominates(NewBBSucc, *PI)) {
|
||||||
|
NewBBDominatesNewBBSucc = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find NewBB's immediate dominator and create new dominator tree node for
|
||||||
|
// NewBB.
|
||||||
|
BasicBlock *NewBBIDom = 0;
|
||||||
|
unsigned i = 0;
|
||||||
|
for (i = 0; i < PredBlocks.size(); ++i)
|
||||||
|
if (DT.isReachableFromEntry(PredBlocks[i])) {
|
||||||
|
NewBBIDom = PredBlocks[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
assert(i != PredBlocks.size() && "No reachable preds?");
|
||||||
|
for (i = i + 1; i < PredBlocks.size(); ++i) {
|
||||||
|
if (DT.isReachableFromEntry(PredBlocks[i]))
|
||||||
|
NewBBIDom = DT.findNearestCommonDominator(NewBBIDom, PredBlocks[i]);
|
||||||
|
}
|
||||||
|
assert(NewBBIDom && "No immediate dominator found??");
|
||||||
|
|
||||||
|
// Create the new dominator tree node... and set the idom of NewBB.
|
||||||
|
DomTreeNode *NewBBNode = DT.addNewBlock(NewBB, NewBBIDom);
|
||||||
|
|
||||||
|
// If NewBB strictly dominates other blocks, then it is now the immediate
|
||||||
|
// dominator of NewBBSucc. Update the dominator tree as appropriate.
|
||||||
|
if (NewBBDominatesNewBBSucc) {
|
||||||
|
DomTreeNode *NewBBSuccNode = DT.getNode(NewBBSucc);
|
||||||
|
DT.changeImmediateDominator(NewBBSuccNode, NewBBNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DominatorTreeBase(intptr_t ID, bool isPostDom)
|
DominatorTreeBase(intptr_t ID, bool isPostDom)
|
||||||
: DominatorBase<NodeT>(ID, isPostDom), DFSInfoValid(false), SlowQueries(0) {}
|
: DominatorBase<NodeT>(ID, isPostDom), DFSInfoValid(false), SlowQueries(0) {}
|
||||||
@ -426,6 +513,15 @@ public:
|
|||||||
DomTreeNodes.erase(BB);
|
DomTreeNodes.erase(BB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// splitBlock - BB is split and now it has one successor. Update dominator
|
||||||
|
/// tree to reflect this change.
|
||||||
|
void splitBlock(NodeT* NewBB) {
|
||||||
|
if (this->IsPostDominators)
|
||||||
|
Split<Inverse<NodeT*>, GraphTraits<Inverse<NodeT*> > >(*this, NewBB);
|
||||||
|
else
|
||||||
|
Split<NodeT*, GraphTraits<NodeT*> >(*this, NewBB);
|
||||||
|
}
|
||||||
|
|
||||||
/// print - Convert to human readable form
|
/// print - Convert to human readable form
|
||||||
///
|
///
|
||||||
virtual void print(std::ostream &o, const Module* ) const {
|
virtual void print(std::ostream &o, const Module* ) const {
|
||||||
@ -471,21 +567,6 @@ protected:
|
|||||||
friend void Calculate(DominatorTreeBase<typename GraphT::NodeType>& DT,
|
friend void Calculate(DominatorTreeBase<typename GraphT::NodeType>& DT,
|
||||||
Function& F);
|
Function& F);
|
||||||
|
|
||||||
template<class N, class GraphT>
|
|
||||||
friend void Split(DominatorTreeBase<typename GraphT::NodeType>& DT,
|
|
||||||
typename GraphT::NodeType* NewBB);
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// splitBlock - BB is split and now it has one successor. Update dominator
|
|
||||||
/// tree to reflect this change.
|
|
||||||
void splitBlock(NodeT* NewBB) {
|
|
||||||
if (this->IsPostDominators)
|
|
||||||
Split<Inverse<NodeT*>, GraphTraits<Inverse<NodeT*> > >(*this, NewBB);
|
|
||||||
else
|
|
||||||
Split<NodeT*, GraphTraits<NodeT*> >(*this, NewBB);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
/// updateDFSNumbers - Assign In and Out numbers to the nodes while walking
|
/// updateDFSNumbers - Assign In and Out numbers to the nodes while walking
|
||||||
/// dominator tree in dfs order.
|
/// dominator tree in dfs order.
|
||||||
void updateDFSNumbers() {
|
void updateDFSNumbers() {
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Analysis/Dominators.h"
|
#include "llvm/Analysis/Dominators.h"
|
||||||
#include "llvm/Analysis/DominatorInternals.h"
|
|
||||||
#include "llvm/Analysis/LoopInfo.h"
|
#include "llvm/Analysis/LoopInfo.h"
|
||||||
#include "llvm/Analysis/Verifier.h"
|
#include "llvm/Analysis/Verifier.h"
|
||||||
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
||||||
|
@ -40,7 +40,6 @@
|
|||||||
#include "llvm/Type.h"
|
#include "llvm/Type.h"
|
||||||
#include "llvm/Analysis/AliasAnalysis.h"
|
#include "llvm/Analysis/AliasAnalysis.h"
|
||||||
#include "llvm/Analysis/Dominators.h"
|
#include "llvm/Analysis/Dominators.h"
|
||||||
#include "llvm/Analysis/DominatorInternals.h"
|
|
||||||
#include "llvm/Analysis/LoopInfo.h"
|
#include "llvm/Analysis/LoopInfo.h"
|
||||||
#include "llvm/Support/CFG.h"
|
#include "llvm/Support/CFG.h"
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user