summaryrefslogtreecommitdiff
path: root/source/opt/remove_duplicates_pass.cpp
diff options
context:
space:
mode:
authorSteven Perron <stevenperron@google.com>2017-11-02 14:25:48 -0400
committerSteven Perron <stevenperron@google.com>2017-11-08 13:35:34 -0500
commitf32d11f74b75eb7660375ab295fb9c150c429948 (patch)
treed714cce4ac41b4aeebf568c5f7d05645216f40c8 /source/opt/remove_duplicates_pass.cpp
parentac04b2faeabc15811e8c542a5d7a36dbdba243b8 (diff)
downloadSPIRV-Tools-f32d11f74b75eb7660375ab295fb9c150c429948.tar.gz
SPIRV-Tools-f32d11f74b75eb7660375ab295fb9c150c429948.tar.bz2
SPIRV-Tools-f32d11f74b75eb7660375ab295fb9c150c429948.zip
Add the IRContext (part 2): Add def-use manager
This change will move the instances of the def-use manager to the IRContext. This allows it to persists across optimization, and does not have to be rebuilt multiple times. Added test to ensure that the IRContext is validating and invalidating the analyses correctly.
Diffstat (limited to 'source/opt/remove_duplicates_pass.cpp')
-rw-r--r--source/opt/remove_duplicates_pass.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/source/opt/remove_duplicates_pass.cpp b/source/opt/remove_duplicates_pass.cpp
index 6b78f3eb..3ee78f4d 100644
--- a/source/opt/remove_duplicates_pass.cpp
+++ b/source/opt/remove_duplicates_pass.cpp
@@ -36,12 +36,11 @@ using opt::analysis::DefUseManager;
using opt::analysis::DecorationManager;
Pass::Status RemoveDuplicatesPass::Process(ir::IRContext* irContext) {
- DefUseManager defUseManager(consumer(), irContext->module());
DecorationManager decManager(irContext->module());
bool modified = RemoveDuplicateCapabilities(irContext);
- modified |= RemoveDuplicatesExtInstImports(irContext, defUseManager);
- modified |= RemoveDuplicateTypes(irContext, defUseManager, decManager);
+ modified |= RemoveDuplicatesExtInstImports(irContext);
+ modified |= RemoveDuplicateTypes(irContext, decManager);
modified |= RemoveDuplicateDecorations(irContext);
return modified ? Status::SuccessWithChange : Status::SuccessWithoutChange;
@@ -67,8 +66,8 @@ bool RemoveDuplicatesPass::RemoveDuplicateCapabilities(ir::IRContext* irContext)
return modified;
}
-bool RemoveDuplicatesPass::RemoveDuplicatesExtInstImports(
- ir::IRContext* irContext, analysis::DefUseManager& defUseManager) const {
+bool
+RemoveDuplicatesPass::RemoveDuplicatesExtInstImports(ir::IRContext* irContext) const {
bool modified = false;
std::unordered_map<std::string, SpvId> extInstImports;
@@ -82,7 +81,7 @@ bool RemoveDuplicatesPass::RemoveDuplicatesExtInstImports(
++i;
} else {
// It's a duplicate, remove it.
- defUseManager.ReplaceAllUsesWith(i->result_id(), res.first->second);
+ irContext->ReplaceAllUsesWith(i->result_id(), res.first->second);
i = i.Erase();
modified = true;
}
@@ -91,9 +90,8 @@ bool RemoveDuplicatesPass::RemoveDuplicatesExtInstImports(
return modified;
}
-bool RemoveDuplicatesPass::RemoveDuplicateTypes(
- ir::IRContext* irContext, DefUseManager& defUseManager,
- DecorationManager& decManager) const {
+bool RemoveDuplicatesPass::RemoveDuplicateTypes(ir::IRContext* irContext,
+ DecorationManager& decManager) const {
bool modified = false;
std::vector<Instruction> visitedTypes;
@@ -110,7 +108,7 @@ bool RemoveDuplicatesPass::RemoveDuplicateTypes(
// Is the current type equal to one of the types we have aready visited?
SpvId idToKeep = 0u;
for (auto j : visitedTypes) {
- if (AreTypesEqual(*i, j, defUseManager, decManager)) {
+ if (AreTypesEqual(*i, j, *irContext->get_def_use_mgr(), decManager)) {
idToKeep = j.result_id();
break;
}
@@ -122,7 +120,7 @@ bool RemoveDuplicatesPass::RemoveDuplicateTypes(
++i;
} else {
// The same type has already been seen before, remove this one.
- defUseManager.ReplaceAllUsesWith(i->result_id(), idToKeep);
+ irContext->ReplaceAllUsesWith(i->result_id(), idToKeep);
modified = true;
i = i.Erase();
}