2007-10-31 11:30:14 +08:00
|
|
|
//===- MachineDominators.cpp - Machine Dominator Calculation --------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-10-31 11:30:14 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements simple dominator construction algorithms for finding
|
|
|
|
// forward dominators on machine functions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineDominators.h"
|
2008-01-05 04:54:55 +08:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2007-10-31 11:30:14 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2009-12-16 08:13:24 +08:00
|
|
|
namespace llvm {
|
2007-10-31 11:30:14 +08:00
|
|
|
TEMPLATE_INSTANTIATION(class DomTreeNodeBase<MachineBasicBlock>);
|
|
|
|
TEMPLATE_INSTANTIATION(class DominatorTreeBase<MachineBasicBlock>);
|
2009-12-16 08:13:24 +08:00
|
|
|
}
|
2007-10-31 11:30:14 +08:00
|
|
|
|
2008-01-06 04:15:42 +08:00
|
|
|
char MachineDominatorTree::ID = 0;
|
|
|
|
|
2010-08-24 01:52:01 +08:00
|
|
|
INITIALIZE_PASS(MachineDominatorTree, "machinedomtree",
|
2010-10-08 06:25:06 +08:00
|
|
|
"MachineDominator Tree Construction", true, true)
|
2008-01-05 04:54:55 +08:00
|
|
|
|
2010-08-07 02:33:48 +08:00
|
|
|
char &llvm::MachineDominatorsID = MachineDominatorTree::ID;
|
2009-01-06 01:59:02 +08:00
|
|
|
|
|
|
|
void MachineDominatorTree::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MachineDominatorTree::runOnMachineFunction(MachineFunction &F) {
|
[MachineDominatorTree] Provide a method to inform a MachineDominatorTree that a
critical edge has been split. The MachineDominatorTree will when lazy update the
underlying dominance properties when require.
** Context **
This is a follow-up of r215410.
Each time a critical edge is split this invalidates the dominator tree
information. Thus, subsequent queries of that interface will be slow until the
underlying information is actually recomputed (costly).
** Problem **
Prior to this patch, splitting a critical edge needed to query the dominator
tree to update the dominator information.
Therefore, splitting a bunch of critical edges will likely produce poor
performance as each query to the dominator tree will use the slow query path.
This happens a lot in passes like MachineSink and PHIElimination.
** Proposed Solution **
Splitting a critical edge is a local modification of the CFG. Moreover, as soon
as a critical edge is split, it is not critical anymore and thus cannot be a
candidate for critical edge splitting anymore. In other words, the predecessor
and successor of a basic block inserted on a critical edge cannot be inserted by
critical edge splitting.
Using these observations, we can pile up the splitting of critical edge and
apply then at once before updating the DT information.
The core of this patch moves the update of the MachineDominatorTree information
from MachineBasicBlock::SplitCriticalEdge to a lazy MachineDominatorTree.
** Performance **
Thanks to this patch, the motivating example compiles in 4- minutes instead of
6+ minutes. No test case added as the motivating example as nothing special but
being huge!
The binaries are strictly identical for all the llvm test-suite + SPECs with and
without this patch for both Os and O3.
Regarding compile time, I observed only noise, although on average I saw a
small improvement.
<rdar://problem/17894619>
llvm-svn: 215576
2014-08-14 05:00:07 +08:00
|
|
|
CriticalEdgesToSplit.clear();
|
|
|
|
NewBBs.clear();
|
2009-01-06 01:59:02 +08:00
|
|
|
DT->recalculate(F);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MachineDominatorTree::MachineDominatorTree()
|
2010-08-07 02:33:48 +08:00
|
|
|
: MachineFunctionPass(ID) {
|
2010-10-20 01:21:58 +08:00
|
|
|
initializeMachineDominatorTreePass(*PassRegistry::getPassRegistry());
|
2009-01-06 01:59:02 +08:00
|
|
|
DT = new DominatorTreeBase<MachineBasicBlock>(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
MachineDominatorTree::~MachineDominatorTree() {
|
|
|
|
delete DT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MachineDominatorTree::releaseMemory() {
|
|
|
|
DT->releaseMemory();
|
|
|
|
}
|
2009-08-23 13:17:37 +08:00
|
|
|
|
2009-08-23 14:03:38 +08:00
|
|
|
void MachineDominatorTree::print(raw_ostream &OS, const Module*) const {
|
|
|
|
DT->print(OS);
|
2009-08-23 13:17:37 +08:00
|
|
|
}
|