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);
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
// 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);
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