From 8ea1268f849197d3551d65fbce3069136b075b67 Mon Sep 17 00:00:00 2001 From: Umar Arshad Date: Tue, 9 Aug 2016 14:05:03 -0400 Subject: [PATCH] Removed dead code/const_casts/lists --- source/val/Instruction.h | 7 +------ source/val/ValidationState.cpp | 14 ++++++++++---- source/val/ValidationState.h | 14 +++++++------- source/validate_id.cpp | 17 ++++------------- 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/source/val/Instruction.h b/source/val/Instruction.h index 45a93b9..51a94f0 100644 --- a/source/val/Instruction.h +++ b/source/val/Instruction.h @@ -73,16 +73,11 @@ class Instruction { } /// The word used to define the Instruction - uint32_t words(size_t index) const { return words_[index]; } + uint32_t word(size_t index) const { return words_[index]; } /// The words used to define the Instruction const std::vector& words() const { return words_; } - /// The operand of the Instruction at \p index - const spv_parsed_operand_t& operands(size_t index) const { - return operands_[index]; - } - /// The operands of the Instruction const std::vector& operands() const { return operands_; diff --git a/source/val/ValidationState.cpp b/source/val/ValidationState.cpp index 79c5241..adb4753 100644 --- a/source/val/ValidationState.cpp +++ b/source/val/ValidationState.cpp @@ -32,7 +32,7 @@ #include "val/Construct.h" #include "val/Function.h" -using std::list; +using std::deque; using std::make_pair; using std::pair; using std::string; @@ -268,8 +268,14 @@ const Instruction* ValidationState_t::FindDef(uint32_t id) const { } Instruction* ValidationState_t::FindDef(uint32_t id) { - return const_cast( - const_cast(this)->FindDef(id)); + if (all_definitions_.count(id) == 0) { + return nullptr; + } else { + /// We are in a const function, so we cannot use defs.operator[](). + /// Luckily we know the key exists, so defs_.at() won't throw an + /// exception. + return all_definitions_.at(id); + } } // Increments the instruction count. Used for diagnostic @@ -299,7 +305,7 @@ DiagnosticStream ValidationState_t::diag(spv_result_t error_code) const { error_code); } -list& ValidationState_t::functions() { return module_functions_; } +deque& ValidationState_t::functions() { return module_functions_; } Function& ValidationState_t::current_function() { assert(in_function_body()); diff --git a/source/val/ValidationState.h b/source/val/ValidationState.h index b2395ec..a8b77a3 100644 --- a/source/val/ValidationState.h +++ b/source/val/ValidationState.h @@ -27,7 +27,7 @@ #ifndef LIBSPIRV_VAL_VALIDATIONSTATE_H_ #define LIBSPIRV_VAL_VALIDATIONSTATE_H_ -#include +#include #include #include #include @@ -88,7 +88,7 @@ class ValidationState_t { /// defined size_t unresolved_forward_id_count() const; - /// Returns a list of unresolved forward ids. + /// Returns a vector of unresolved forward ids. std::vector UnresolvedForwardIds() const; /// Returns true if the id has been defined @@ -109,7 +109,7 @@ class ValidationState_t { libspirv::DiagnosticStream diag(spv_result_t error_code) const; /// Returns the function states - std::list& functions(); + std::deque& functions(); /// Returns the function states Function& current_function(); @@ -170,8 +170,8 @@ class ValidationState_t { /// nullptr Instruction* FindDef(uint32_t id); - /// Returns a vector of instructions in the order they appear in the binary - const std::list& ordered_instructions() { + /// Returns a deque of instructions in the order they appear in the binary + const std::deque& ordered_instructions() { return ordered_instructions_; } @@ -197,14 +197,14 @@ class ValidationState_t { ModuleLayoutSection current_layout_section_; /// A list of functions in the module - std::list module_functions_; + std::deque module_functions_; /// Mask of the capabilities available in the module spv_capability_mask_t module_capabilities_; /// Module's declared capabilities. /// List of all instructions in the order they appear in the binary - std::list ordered_instructions_; + std::deque ordered_instructions_; /// Instructions that can be referenced by Ids std::unordered_map all_definitions_; diff --git a/source/validate_id.cpp b/source/validate_id.cpp index 4489569..0a50c27 100644 --- a/source/validate_id.cpp +++ b/source/validate_id.cpp @@ -2386,19 +2386,10 @@ spv_result_t UpdateIdUse(ValidationState_t& _) { for (const auto& inst : _.ordered_instructions()) { for (auto& operand : inst.operands()) { const spv_operand_type_t& type = operand.type; - const uint32_t operand_id = inst.words()[operand.offset]; - - switch (type) { - case SPV_OPERAND_TYPE_VARIABLE_ID: - case SPV_OPERAND_TYPE_ID: - case SPV_OPERAND_TYPE_TYPE_ID: - case SPV_OPERAND_TYPE_MEMORY_SEMANTICS_ID: - case SPV_OPERAND_TYPE_SCOPE_ID: - if (auto def = _.FindDef(operand_id)) - def->RegisterUse(&inst, operand.offset); - break; - default: - break; + const uint32_t operand_id = inst.word(operand.offset); + if (spvIsIdType(type) && type != SPV_OPERAND_TYPE_RESULT_ID) { + if (auto def = _.FindDef(operand_id)) + def->RegisterUse(&inst, operand.offset); } } } -- 2.7.4