From 7a94e664338284a629ae42bbc53dea10984581d9 Mon Sep 17 00:00:00 2001 From: qining Date: Fri, 12 Aug 2016 10:05:58 -0400 Subject: [PATCH] Move the def-use analysis for single inst to public --- source/opt/def_use_manager.cpp | 44 +++++++++++++++++++++--------------------- source/opt/def_use_manager.h | 6 +++--- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/source/opt/def_use_manager.cpp b/source/opt/def_use_manager.cpp index 4775421..e05a0de 100644 --- a/source/opt/def_use_manager.cpp +++ b/source/opt/def_use_manager.cpp @@ -41,6 +41,28 @@ void DefUseManager::AnalyzeDefUse(ir::Module* module) { std::placeholders::_1)); } +void DefUseManager::AnalyzeInstDefUse(ir::Instruction* inst) { + const uint32_t def_id = inst->result_id(); + if (def_id != 0) id_to_def_[def_id] = inst; + + for (uint32_t i = 0; i < inst->NumOperands(); ++i) { + switch (inst->GetOperand(i).type) { + // For any id type but result id type + case SPV_OPERAND_TYPE_ID: + case SPV_OPERAND_TYPE_TYPE_ID: + case SPV_OPERAND_TYPE_MEMORY_SEMANTICS_ID: + case SPV_OPERAND_TYPE_SCOPE_ID: { + uint32_t use_id = inst->GetSingleWordOperand(i); + // use_id is used by the instruction generating def_id. + id_to_uses_[use_id].push_back({inst, i}); + if (def_id != 0) result_id_to_used_ids_[def_id].push_back(use_id); + } break; + default: + break; + } + } +} + ir::Instruction* DefUseManager::GetDef(uint32_t id) { if (id_to_def_.count(id) == 0) return nullptr; return id_to_def_.at(id); @@ -94,28 +116,6 @@ bool DefUseManager::ReplaceAllUsesWith(uint32_t before, uint32_t after) { return true; } -void DefUseManager::AnalyzeInstDefUse(ir::Instruction* inst) { - const uint32_t def_id = inst->result_id(); - if (def_id != 0) id_to_def_[def_id] = inst; - - for (uint32_t i = 0; i < inst->NumOperands(); ++i) { - switch (inst->GetOperand(i).type) { - // For any id type but result id type - case SPV_OPERAND_TYPE_ID: - case SPV_OPERAND_TYPE_TYPE_ID: - case SPV_OPERAND_TYPE_MEMORY_SEMANTICS_ID: - case SPV_OPERAND_TYPE_SCOPE_ID: { - uint32_t use_id = inst->GetSingleWordOperand(i); - // use_id is used by the instruction generating def_id. - id_to_uses_[use_id].push_back({inst, i}); - if (def_id != 0) result_id_to_used_ids_[def_id].push_back(use_id); - } break; - default: - break; - } - } -} - } // namespace analysis } // namespace opt } // namespace spvtools diff --git a/source/opt/def_use_manager.h b/source/opt/def_use_manager.h index d7745d7..8e0da1e 100644 --- a/source/opt/def_use_manager.h +++ b/source/opt/def_use_manager.h @@ -63,6 +63,9 @@ class DefUseManager { // const overload for ForEachInst(). void AnalyzeDefUse(ir::Module* module); + // Analyzes the defs and uses in the given |inst|. + void AnalyzeInstDefUse(ir::Instruction* inst); + // Returns the def instruction for the given |id|. If there is no instruction // defining |id|, returns nullptr. ir::Instruction* GetDef(uint32_t id); @@ -91,9 +94,6 @@ class DefUseManager { using ResultIdToUsedIdsMap = std::unordered_map>; - // Analyzes the defs and uses in the given |inst|. - void AnalyzeInstDefUse(ir::Instruction* inst); - IdToDefMap id_to_def_; // Mapping from ids to their definitions IdToUsesMap id_to_uses_; // Mapping from ids to their uses // Mapping from result ids to the ids used in the instructions generating the -- 2.7.4