namespace opt {
namespace analysis {
-void DefUseManager::AnalyzeDefUse(ir::Module* module) {
- module->ForEachInst(std::bind(&DefUseManager::AnalyzeInstDefUse, this,
- std::placeholders::_1));
-}
-
void DefUseManager::AnalyzeInstDefUse(ir::Instruction* inst) {
const uint32_t def_id = inst->result_id();
// Clear the records of def_id first if it has been recorded before.
return true;
}
+void DefUseManager::AnalyzeDefUse(ir::Module* module) {
+ module->ForEachInst(std::bind(&DefUseManager::AnalyzeInstDefUse, this,
+ std::placeholders::_1));
+}
+
void DefUseManager::ClearDef(uint32_t def_id) {
if (id_to_def_.count(def_id) == 0) return;
namespace opt {
namespace analysis {
-// Class for representing a use of id. Note that result:
-// * Type id is a use.
+// Class for representing a use of id. Note that:
+// * Result type id is a use.
// * Ids referenced in OpSectionMerge & OpLoopMerge are considered as use.
// * Ids referenced in OpPhi's in operands are considered as use.
struct Use {
using IdToDefMap = std::unordered_map<uint32_t, ir::Instruction*>;
using IdToUsesMap = std::unordered_map<uint32_t, UseList>;
- // Analyzes the defs and uses in the given |module| and populates data
- // structures in this class.
- // TODO(antiagainst): This method should not modify the given module. Create
- // const overload for ForEachInst().
- void AnalyzeDefUse(ir::Module* module);
+ inline explicit DefUseManager(ir::Module* module) { AnalyzeDefUse(module); }
+ DefUseManager(const DefUseManager&) = delete;
+ DefUseManager(DefUseManager&&) = delete;
+ DefUseManager& operator=(const DefUseManager&) = delete;
+ DefUseManager& operator=(DefUseManager&&) = delete;
// Analyzes the defs and uses in the given |inst|.
void AnalyzeInstDefUse(ir::Instruction* inst);
bool ReplaceAllUsesWith(uint32_t before, uint32_t after);
private:
+ // Analyzes the defs and uses in the given |module| and populates data
+ // structures in this class.
+ void AnalyzeDefUse(ir::Module* module);
+
// Clear the internal def-use record of a defined id if the given |def_id| is
// recorded by this manager. This method will erase both the uses of |def_id|
// and the |def_id|-generating instruction's use information kept in this
}
bool EliminateDeadConstantPass::Process(ir::Module* module) {
- analysis::DefUseManager def_use;
- def_use.AnalyzeDefUse(module);
+ analysis::DefUseManager def_use(module);
std::unordered_set<ir::Instruction*> working_list;
// Traverse all the instructions to get the initial set of dead constants as
// working list and count number of real uses for constants. Uses in
using TypeToIdMap = std::unordered_map<const Type*, uint32_t>;
using ForwardPointerVector = std::vector<std::unique_ptr<ForwardPointer>>;
- TypeManager(const spvtools::ir::Module& module) { AnalyzeTypes(module); }
+ inline explicit TypeManager(const spvtools::ir::Module& module);
TypeManager(const TypeManager&) = delete;
TypeManager(TypeManager&&) = delete;
TypeManager& operator=(const TypeManager&) = delete;
std::unordered_set<ForwardPointer*> unresolved_forward_pointers_;
};
+inline TypeManager::TypeManager(const spvtools::ir::Module& module) {
+ AnalyzeTypes(module);
+}
+
} // namespace analysis
} // namespace opt
} // namespace spvtools
ASSERT_NE(nullptr, module);
// Analyze def and use.
- opt::analysis::DefUseManager manager;
- manager.AnalyzeDefUse(module.get());
+ opt::analysis::DefUseManager manager(module.get());
CheckDef(tc.du, manager.id_to_defs());
CheckUse(tc.du, manager.id_to_uses());
ASSERT_NE(nullptr, module);
// Analyze def and use.
- opt::analysis::DefUseManager manager;
- manager.AnalyzeDefUse(module.get());
+ opt::analysis::DefUseManager manager(module.get());
// Do the substitution.
for (const auto& candiate : tc.candidates) {
ASSERT_NE(nullptr, module);
// Analyze def and use.
- opt::analysis::DefUseManager manager;
- manager.AnalyzeDefUse(module.get());
+ opt::analysis::DefUseManager manager(module.get());
// Do the substitution.
for (const auto id : tc.ids_to_kill) manager.KillDef(id);
ASSERT_NE(nullptr, module);
// Analyze def and use.
- opt::analysis::DefUseManager manager;
- manager.AnalyzeDefUse(module.get());
+ opt::analysis::DefUseManager manager(module.get());
// Do a bunch replacements.
manager.ReplaceAllUsesWith(9, 900); // to unused id