mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-11-26 21:30:07 +00:00
Move the def-use analysis for single inst to public
This commit is contained in:
parent
e5bb46d274
commit
7a94e66433
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user