Move the def-use analysis for single inst to public
authorqining <qining@google.com>
Fri, 12 Aug 2016 14:05:58 +0000 (10:05 -0400)
committerqining <qining@google.com>
Fri, 12 Aug 2016 14:25:37 +0000 (10:25 -0400)
source/opt/def_use_manager.cpp
source/opt/def_use_manager.h

index 4775421..e05a0de 100644 (file)
@@ -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
index d7745d7..8e0da1e 100644 (file)
@@ -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<uint32_t, std::vector<uint32_t>>;
 
-  // 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