summaryrefslogtreecommitdiff
path: root/source/opt/ir_context.cpp
diff options
context:
space:
mode:
authorStephen McGroarty <smcgro@googlemail.com>2017-11-27 21:21:26 +0000
committerSteven Perron <stevenperron@google.com>2017-12-05 22:59:43 -0500
commit8ba68fa9b94da071e879e3064adf8aaaea1a7051 (patch)
treefae044f70d1d190415d8246f611f864db9a2e047 /source/opt/ir_context.cpp
parent692a22c5bc5150d5dcb54006f6400282f0108719 (diff)
downloadSPIRV-Tools-8ba68fa9b94da071e879e3064adf8aaaea1a7051.tar.gz
SPIRV-Tools-8ba68fa9b94da071e879e3064adf8aaaea1a7051.tar.bz2
SPIRV-Tools-8ba68fa9b94da071e879e3064adf8aaaea1a7051.zip
Dominator Tree Analysis (#3)
Support for dominator and post dominator analysis on ir::Functions. This patch contains a DominatorTree class for building the tree and DominatorAnalysis and DominatorAnalysisPass classes for interfacing and caching the built trees.
Diffstat (limited to 'source/opt/ir_context.cpp')
-rw-r--r--source/opt/ir_context.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/source/opt/ir_context.cpp b/source/opt/ir_context.cpp
index 6576a0d4..f1d7103a 100644
--- a/source/opt/ir_context.cpp
+++ b/source/opt/ir_context.cpp
@@ -34,6 +34,12 @@ void IRContext::BuildInvalidAnalyses(IRContext::Analysis set) {
if (set & kAnalysisCFG) {
BuildCFG();
}
+ if (set & kAnalysisDominatorAnalysis) {
+ // An invalid dominator tree analysis will be empty so rebuilding it just
+ // means marking it as valid. Each tree will be initalisalised when
+ // requested on a per function basis.
+ valid_analyses_ |= kAnalysisDominatorAnalysis;
+ }
}
void IRContext::InvalidateAnalysesExceptFor(
@@ -58,6 +64,11 @@ void IRContext::InvalidateAnalyses(IRContext::Analysis analyses_to_invalidate) {
if (analyses_to_invalidate & kAnalysisCFG) {
cfg_.reset(nullptr);
}
+ if (analyses_to_invalidate & kAnalysisDominatorAnalysis) {
+ dominator_trees_.clear();
+ post_dominator_trees_.clear();
+ }
+
valid_analyses_ = Analysis(valid_analyses_ & ~analyses_to_invalidate);
}
@@ -456,5 +467,28 @@ void IRContext::InitializeCombinators() {
valid_analyses_ |= kAnalysisCombinators;
}
+
+// Gets the dominator analysis for function |f|.
+opt::DominatorAnalysis* IRContext::GetDominatorAnalysis(const ir::Function* f,
+ const ir::CFG& in_cfg) {
+ if (dominator_trees_.find(f) == dominator_trees_.end() ||
+ !AreAnalysesValid(kAnalysisDominatorAnalysis)) {
+ dominator_trees_[f].InitializeTree(f, in_cfg);
+ }
+
+ return &dominator_trees_[f];
+}
+
+// Gets the postdominator analysis for function |f|.
+opt::PostDominatorAnalysis* IRContext::GetPostDominatorAnalysis(
+ const ir::Function* f, const ir::CFG& in_cfg) {
+ if (post_dominator_trees_.find(f) == post_dominator_trees_.end() ||
+ !AreAnalysesValid(kAnalysisDominatorAnalysis)) {
+ post_dominator_trees_[f].InitializeTree(f, in_cfg);
+ }
+
+ return &post_dominator_trees_[f];
+}
+
} // namespace ir
} // namespace spvtools