aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpencer Fricke <spencerfricke@gmail.com>2022-09-03 01:24:02 +0900
committerGitHub <noreply@github.com>2022-09-02 16:24:02 +0000
commit4386afb057a828360853672c0b94be66a1f0b6ee (patch)
tree825615f7866a41940ebd2806488970e928aff786
parent4c456f7da67c5437a6fb7d4d20d78e2a5ae2acf2 (diff)
downloadSPIRV-Tools-4386afb057a828360853672c0b94be66a1f0b6ee.tar.gz
spirv-opt: Remove unused fold spec const code (#4906)
-rw-r--r--source/opt/fold_spec_constant_op_and_composite_pass.cpp89
-rw-r--r--source/opt/fold_spec_constant_op_and_composite_pass.h11
-rw-r--r--source/opt/instruction.cpp20
-rw-r--r--source/opt/instruction.h4
4 files changed, 0 insertions, 124 deletions
diff --git a/source/opt/fold_spec_constant_op_and_composite_pass.cpp b/source/opt/fold_spec_constant_op_and_composite_pass.cpp
index 85f11fde..8d68850a 100644
--- a/source/opt/fold_spec_constant_op_and_composite_pass.cpp
+++ b/source/opt/fold_spec_constant_op_and_composite_pass.cpp
@@ -144,15 +144,6 @@ bool FoldSpecConstantOpAndCompositePass::ProcessOpSpecConstantOp(
return true;
}
-uint32_t FoldSpecConstantOpAndCompositePass::GetTypeComponent(
- uint32_t typeId, uint32_t element) const {
- Instruction* type = context()->get_def_use_mgr()->GetDef(typeId);
- uint32_t subtype = type->GetTypeComponent(element);
- assert(subtype != 0);
-
- return subtype;
-}
-
Instruction* FoldSpecConstantOpAndCompositePass::FoldWithInstructionFolder(
Module::inst_iterator* inst_iter_ptr) {
// If one of operands to the instruction is not a
@@ -214,86 +205,6 @@ Instruction* FoldSpecConstantOpAndCompositePass::FoldWithInstructionFolder(
return new_const_inst;
}
-Instruction* FoldSpecConstantOpAndCompositePass::DoVectorShuffle(
- Module::inst_iterator* pos) {
- Instruction* inst = &**pos;
- analysis::Vector* result_vec_type =
- context()->get_constant_mgr()->GetType(inst)->AsVector();
- assert(inst->NumInOperands() - 1 > 2 &&
- "OpSpecConstantOp DoVectorShuffle instruction requires more than 2 "
- "operands (2 vector ids and at least one literal operand");
- assert(result_vec_type &&
- "The result of VectorShuffle must be of type vector");
-
- // A temporary null constants that can be used as the components of the result
- // vector. This is needed when any one of the vector operands are null
- // constant.
- const analysis::Constant* null_component_constants = nullptr;
-
- // Get a concatenated vector of scalar constants. The vector should be built
- // with the components from the first and the second operand of VectorShuffle.
- std::vector<const analysis::Constant*> concatenated_components;
- // Note that for OpSpecConstantOp, the second in-operand is the first id
- // operand. The first in-operand is the spec opcode.
- for (uint32_t i : {1, 2}) {
- assert(inst->GetInOperand(i).type == SPV_OPERAND_TYPE_ID &&
- "The vector operand must have a SPV_OPERAND_TYPE_ID type");
- uint32_t operand_id = inst->GetSingleWordInOperand(i);
- auto operand_const =
- context()->get_constant_mgr()->FindDeclaredConstant(operand_id);
- if (!operand_const) return nullptr;
- const analysis::Type* operand_type = operand_const->type();
- assert(operand_type->AsVector() &&
- "The first two operand of VectorShuffle must be of vector type");
- if (auto vec_const = operand_const->AsVectorConstant()) {
- // case 1: current operand is a non-null vector constant.
- concatenated_components.insert(concatenated_components.end(),
- vec_const->GetComponents().begin(),
- vec_const->GetComponents().end());
- } else if (operand_const->AsNullConstant()) {
- // case 2: current operand is a null vector constant. Create a temporary
- // null scalar constant as the component.
- if (!null_component_constants) {
- const analysis::Type* component_type =
- operand_type->AsVector()->element_type();
- null_component_constants =
- context()->get_constant_mgr()->GetConstant(component_type, {});
- }
- // Append the null scalar consts to the concatenated components
- // vector.
- concatenated_components.insert(concatenated_components.end(),
- operand_type->AsVector()->element_count(),
- null_component_constants);
- } else {
- // no other valid cases
- return nullptr;
- }
- }
- // Create null component constants if there are any. The component constants
- // must be added to the module before the dependee composite constants to
- // satisfy SSA def-use dominance.
- if (null_component_constants) {
- context()->get_constant_mgr()->BuildInstructionAndAddToModule(
- null_component_constants, pos);
- }
- // Create the new vector constant with the selected components.
- std::vector<const analysis::Constant*> selected_components;
- for (uint32_t i = 3; i < inst->NumInOperands(); i++) {
- assert(inst->GetInOperand(i).type == SPV_OPERAND_TYPE_LITERAL_INTEGER &&
- "The literal operand must of type SPV_OPERAND_TYPE_LITERAL_INTEGER");
- uint32_t literal = inst->GetSingleWordInOperand(i);
- assert(literal < concatenated_components.size() &&
- "Literal index out of bound of the concatenated vector");
- selected_components.push_back(concatenated_components[literal]);
- }
- auto new_vec_const = MakeUnique<analysis::VectorConstant>(
- result_vec_type, selected_components);
- auto reg_vec_const =
- context()->get_constant_mgr()->RegisterConstant(std::move(new_vec_const));
- return context()->get_constant_mgr()->BuildInstructionAndAddToModule(
- reg_vec_const, pos);
-}
-
namespace {
// A helper function to check the type for component wise operations. Returns
// true if the type:
diff --git a/source/opt/fold_spec_constant_op_and_composite_pass.h b/source/opt/fold_spec_constant_op_and_composite_pass.h
index 361d3cac..9a8fb403 100644
--- a/source/opt/fold_spec_constant_op_and_composite_pass.h
+++ b/source/opt/fold_spec_constant_op_and_composite_pass.h
@@ -58,22 +58,11 @@ class FoldSpecConstantOpAndCompositePass : public Pass {
// |inst_iter_ptr| using the instruction folder.
Instruction* FoldWithInstructionFolder(Module::inst_iterator* inst_iter_ptr);
- // Try to fold the OpSpecConstantOp VectorShuffle instruction pointed by the
- // given instruction iterator to a normal constant defining instruction.
- // Returns the pointer to the new constant defining instruction if succeeded.
- // Otherwise return nullptr.
- Instruction* DoVectorShuffle(Module::inst_iterator* inst_iter_ptr);
-
// Try to fold the OpSpecConstantOp <component wise operations> instruction
// pointed by the given instruction iterator to a normal constant defining
// instruction. Returns the pointer to the new constant defining instruction
// if succeeded, otherwise return nullptr.
Instruction* DoComponentWiseOperation(Module::inst_iterator* inst_iter_ptr);
-
- // Returns the |element|'th subtype of |type|.
- //
- // |type| must be a composite type.
- uint32_t GetTypeComponent(uint32_t type, uint32_t element) const;
};
} // namespace opt
diff --git a/source/opt/instruction.cpp b/source/opt/instruction.cpp
index 6a8daea3..e775a992 100644
--- a/source/opt/instruction.cpp
+++ b/source/opt/instruction.cpp
@@ -504,26 +504,6 @@ bool Instruction::IsReadOnlyPointerKernel() const {
return storage_class == SpvStorageClassUniformConstant;
}
-uint32_t Instruction::GetTypeComponent(uint32_t element) const {
- uint32_t subtype = 0;
- switch (opcode()) {
- case SpvOpTypeStruct:
- subtype = GetSingleWordInOperand(element);
- break;
- case SpvOpTypeArray:
- case SpvOpTypeRuntimeArray:
- case SpvOpTypeVector:
- case SpvOpTypeMatrix:
- // These types all have uniform subtypes.
- subtype = GetSingleWordInOperand(0u);
- break;
- default:
- break;
- }
-
- return subtype;
-}
-
void Instruction::UpdateLexicalScope(uint32_t scope) {
dbg_scope_.SetLexicalScope(scope);
for (auto& i : dbg_line_insts_) {
diff --git a/source/opt/instruction.h b/source/opt/instruction.h
index 2163d99b..e79c6289 100644
--- a/source/opt/instruction.h
+++ b/source/opt/instruction.h
@@ -504,10 +504,6 @@ class Instruction : public utils::IntrusiveNodeBase<Instruction> {
// Returns true if this instruction exits this function or aborts execution.
bool IsReturnOrAbort() const { return spvOpcodeIsReturnOrAbort(opcode()); }
- // Returns the id for the |element|'th subtype. If the |this| is not a
- // composite type, this function returns 0.
- uint32_t GetTypeComponent(uint32_t element) const;
-
// Returns true if this instruction is a basic block terminator.
bool IsBlockTerminator() const {
return spvOpcodeIsBlockTerminator(opcode());