Commit 348ba200 by Nicolas Capens Committed by Nicolas Capens

Eliminate SpirvShaderEnumNames.cpp

It only contained the now trivial OpcodeName() implementation. Since the SpirvShaderInstructions.cpp file already contains other SPIR-V opcode utility functions, move it there. Also make this function return a pointer to a constant char string, to avoid needless std::string construction. Bug: b/145351270 Change-Id: Iacfc887566b0a9057f37391ad52d43cdca912308 Signed-off-by: 's avatarNicolas Capens <capn@google.com> Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/51448 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent 588d32cb
...@@ -43,10 +43,10 @@ swiftshader_source_set("Pipeline") { ...@@ -43,10 +43,10 @@ swiftshader_source_set("Pipeline") {
"SpirvShaderArithmetic.cpp", "SpirvShaderArithmetic.cpp",
"SpirvShaderControlFlow.cpp", "SpirvShaderControlFlow.cpp",
"SpirvShaderDebugger.cpp", "SpirvShaderDebugger.cpp",
"SpirvShaderEnumNames.cpp",
"SpirvShaderGLSLstd450.cpp", "SpirvShaderGLSLstd450.cpp",
"SpirvShaderGroup.cpp", "SpirvShaderGroup.cpp",
"SpirvShaderImage.cpp", "SpirvShaderImage.cpp",
"SpirvShaderInstructions.cpp",
"SpirvShaderMemory.cpp", "SpirvShaderMemory.cpp",
"SpirvShaderSampling.cpp", "SpirvShaderSampling.cpp",
"SpirvShaderSpec.cpp", "SpirvShaderSpec.cpp",
......
...@@ -38,7 +38,6 @@ set(PIPELINE_SRC_FILES ...@@ -38,7 +38,6 @@ set(PIPELINE_SRC_FILES
SpirvShaderArithmetic.cpp SpirvShaderArithmetic.cpp
SpirvShaderControlFlow.cpp SpirvShaderControlFlow.cpp
SpirvShaderDebugger.cpp SpirvShaderDebugger.cpp
SpirvShaderEnumNames.cpp
SpirvShaderGLSLstd450.cpp SpirvShaderGLSLstd450.cpp
SpirvShaderGroup.cpp SpirvShaderGroup.cpp
SpirvShaderImage.cpp SpirvShaderImage.cpp
......
...@@ -483,7 +483,7 @@ SpirvShader::SpirvShader( ...@@ -483,7 +483,7 @@ SpirvShader::SpirvShader(
case spv::OpFunctionParameter: case spv::OpFunctionParameter:
// These should have all been removed by preprocessing passes. If we see them here, // These should have all been removed by preprocessing passes. If we see them here,
// our assumptions are wrong and we will probably generate wrong code. // our assumptions are wrong and we will probably generate wrong code.
UNREACHABLE("%s should have already been lowered.", OpcodeName(opcode).c_str()); UNREACHABLE("%s should have already been lowered.", OpcodeName(opcode));
break; break;
case spv::OpFunctionCall: case spv::OpFunctionCall:
...@@ -743,7 +743,7 @@ SpirvShader::SpirvShader( ...@@ -743,7 +743,7 @@ SpirvShader::SpirvShader(
} }
default: default:
UNSUPPORTED("%s", OpcodeName(opcode).c_str()); UNSUPPORTED("%s", OpcodeName(opcode));
} }
} }
...@@ -987,7 +987,7 @@ uint32_t SpirvShader::ComputeTypeSize(InsnIterator insn) ...@@ -987,7 +987,7 @@ uint32_t SpirvShader::ComputeTypeSize(InsnIterator insn)
return 1; return 1;
default: default:
UNREACHABLE("%s", OpcodeName(insn.opcode()).c_str()); UNREACHABLE("%s", OpcodeName(insn.opcode()));
return 0; return 0;
} }
} }
...@@ -1110,7 +1110,7 @@ void SpirvShader::ApplyDecorationsForAccessChain(Decorations *d, DescriptorDecor ...@@ -1110,7 +1110,7 @@ void SpirvShader::ApplyDecorationsForAccessChain(Decorations *d, DescriptorDecor
d->InsideMatrix = true; d->InsideMatrix = true;
break; break;
default: default:
UNREACHABLE("%s", OpcodeName(type.definition.opcode()).c_str()); UNREACHABLE("%s", OpcodeName(type.definition.opcode()));
} }
} }
} }
...@@ -1219,7 +1219,7 @@ SIMD::Pointer SpirvShader::WalkExplicitLayoutAccessChain(Object::ID baseId, uint ...@@ -1219,7 +1219,7 @@ SIMD::Pointer SpirvShader::WalkExplicitLayoutAccessChain(Object::ID baseId, uint
break; break;
} }
default: default:
UNREACHABLE("%s", OpcodeName(type.definition.opcode()).c_str()); UNREACHABLE("%s", OpcodeName(type.definition.opcode()));
} }
} }
...@@ -1300,7 +1300,7 @@ SIMD::Pointer SpirvShader::WalkAccessChain(Object::ID baseId, uint32_t numIndexe ...@@ -1300,7 +1300,7 @@ SIMD::Pointer SpirvShader::WalkAccessChain(Object::ID baseId, uint32_t numIndexe
} }
default: default:
UNREACHABLE("%s", OpcodeName(type.opcode()).c_str()); UNREACHABLE("%s", OpcodeName(type.opcode()));
} }
} }
...@@ -1346,7 +1346,7 @@ uint32_t SpirvShader::WalkLiteralAccessChain(Type::ID typeId, uint32_t numIndexe ...@@ -1346,7 +1346,7 @@ uint32_t SpirvShader::WalkLiteralAccessChain(Type::ID typeId, uint32_t numIndexe
} }
default: default:
UNREACHABLE("%s", OpcodeName(type.opcode()).c_str()); UNREACHABLE("%s", OpcodeName(type.opcode()));
} }
} }
...@@ -2028,7 +2028,7 @@ SpirvShader::EmitResult SpirvShader::EmitInstruction(InsnIterator insn, EmitStat ...@@ -2028,7 +2028,7 @@ SpirvShader::EmitResult SpirvShader::EmitInstruction(InsnIterator insn, EmitStat
return EmitArrayLength(insn, state); return EmitArrayLength(insn, state);
default: default:
UNREACHABLE("%s", OpcodeName(opcode).c_str()); UNREACHABLE("%s", OpcodeName(opcode));
break; break;
} }
...@@ -2328,7 +2328,7 @@ SpirvShader::EmitResult SpirvShader::EmitAtomicOp(InsnIterator insn, EmitState * ...@@ -2328,7 +2328,7 @@ SpirvShader::EmitResult SpirvShader::EmitAtomicOp(InsnIterator insn, EmitState *
v = ExchangeAtomic(Pointer<UInt>(&ptr.base[offset]), laneValue, memoryOrder); v = ExchangeAtomic(Pointer<UInt>(&ptr.base[offset]), laneValue, memoryOrder);
break; break;
default: default:
UNREACHABLE("%s", OpcodeName(insn.opcode()).c_str()); UNREACHABLE("%s", OpcodeName(insn.opcode()));
break; break;
} }
result = Insert(result, v, j); result = Insert(result, v, j);
......
...@@ -1250,8 +1250,7 @@ private: ...@@ -1250,8 +1250,7 @@ private:
void WriteCFGGraphVizDotFile(const char *path) const; void WriteCFGGraphVizDotFile(const char *path) const;
// OpcodeName() returns the name of the opcode op. // OpcodeName() returns the name of the opcode op.
// If NDEBUG is defined, then OpcodeName() will only return the numerical code. static const char *OpcodeName(spv::Op op);
static std::string OpcodeName(spv::Op op);
static std::memory_order MemoryOrder(spv::MemorySemanticsMask memorySemantics); static std::memory_order MemoryOrder(spv::MemorySemanticsMask memorySemantics);
// IsStatement() returns true if the given opcode actually performs // IsStatement() returns true if the given opcode actually performs
......
...@@ -299,7 +299,7 @@ SpirvShader::EmitResult SpirvShader::EmitUnaryOp(InsnIterator insn, EmitState *s ...@@ -299,7 +299,7 @@ SpirvShader::EmitResult SpirvShader::EmitUnaryOp(InsnIterator insn, EmitState *s
break; break;
} }
default: default:
UNREACHABLE("%s", OpcodeName(insn.opcode()).c_str()); UNREACHABLE("%s", OpcodeName(insn.opcode()));
} }
} }
...@@ -502,7 +502,7 @@ SpirvShader::EmitResult SpirvShader::EmitBinaryOp(InsnIterator insn, EmitState * ...@@ -502,7 +502,7 @@ SpirvShader::EmitResult SpirvShader::EmitBinaryOp(InsnIterator insn, EmitState *
dst.move(i + lhsType.componentCount, CmpLT(lhs.UInt(i), rhs.UInt(i)) >> 31); dst.move(i + lhsType.componentCount, CmpLT(lhs.UInt(i), rhs.UInt(i)) >> 31);
break; break;
default: default:
UNREACHABLE("%s", OpcodeName(insn.opcode()).c_str()); UNREACHABLE("%s", OpcodeName(insn.opcode()));
} }
} }
......
...@@ -605,7 +605,7 @@ SpirvShader::EmitResult SpirvShader::EmitFunctionCall(InsnIterator insn, EmitSta ...@@ -605,7 +605,7 @@ SpirvShader::EmitResult SpirvShader::EmitFunctionCall(InsnIterator insn, EmitSta
if(blockInsn.opcode() != wrapOpKill[insnNumber++]) if(blockInsn.opcode() != wrapOpKill[insnNumber++])
{ {
UNIMPLEMENTED("b/141246700: Function block instruction %d : %s", insnNumber - 1, OpcodeName(blockInsn.opcode()).c_str()); // FIXME(b/141246700) UNIMPLEMENTED("b/141246700: Function block instruction %d : %s", insnNumber - 1, OpcodeName(blockInsn.opcode())); // FIXME(b/141246700)
return EmitResult::Continue; return EmitResult::Continue;
} }
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#ifndef sw_SpirvShaderDebug_hpp #ifndef sw_SpirvShaderDebug_hpp
#define sw_SpirvShaderDebug_hpp #define sw_SpirvShaderDebug_hpp
#include "SpirvShader.hpp"
// Enable this to print verbose debug messages as each SPIR-V instructon is // Enable this to print verbose debug messages as each SPIR-V instructon is
// executed. Very handy for performing text diffs when the thread count is // executed. Very handy for performing text diffs when the thread count is
// reduced to 1 and execution is deterministic. // reduced to 1 and execution is deterministic.
......
...@@ -1991,7 +1991,7 @@ SpirvShader::Impl::Debugger::Shadow::get(const State *state, Object::ID objId) c ...@@ -1991,7 +1991,7 @@ SpirvShader::Impl::Debugger::Shadow::get(const State *state, Object::ID objId) c
auto entryIt = entries.find(objId); auto entryIt = entries.find(objId);
ASSERT_MSG(entryIt != entries.end(), "Missing shadow entry for object %%%d (%s)", ASSERT_MSG(entryIt != entries.end(), "Missing shadow entry for object %%%d (%s)",
(int)objId.value(), (int)objId.value(),
OpcodeName(state->debugger->shader->getObject(objId).opcode()).c_str()); OpcodeName(state->debugger->shader->getObject(objId).opcode()));
auto &entry = entryIt->second; auto &entry = entryIt->second;
auto data = &state->shadow[entry.offset]; auto data = &state->shadow[entry.offset];
return Memory{ data }; return Memory{ data };
......
// Copyright 2019 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This file contains code used to aid debugging.
#include "SpirvShader.hpp"
#include "spirv-tools/libspirv.h"
#include "spirv/unified1/spirv.h"
namespace sw {
std::string SpirvShader::OpcodeName(spv::Op op)
{
return spvOpcodeString(static_cast<SpvOp>(op));
}
} // namespace sw
...@@ -70,7 +70,7 @@ struct SpirvShader::Impl::Group ...@@ -70,7 +70,7 @@ struct SpirvShader::Impl::Group
} }
default: default:
UNSUPPORTED("EmitGroupNonUniform op: %s Group operation: %d", UNSUPPORTED("EmitGroupNonUniform op: %s Group operation: %d",
SpirvShader::OpcodeName(type.opcode()).c_str(), insn.word(4)); SpirvShader::OpcodeName(type.opcode()), insn.word(4));
} }
} }
} }
...@@ -449,7 +449,7 @@ SpirvShader::EmitResult SpirvShader::EmitGroupNonUniform(InsnIterator insn, Emit ...@@ -449,7 +449,7 @@ SpirvShader::EmitResult SpirvShader::EmitGroupNonUniform(InsnIterator insn, Emit
break; break;
default: default:
UNSUPPORTED("EmitGroupNonUniform op: %s", OpcodeName(type.opcode()).c_str()); UNSUPPORTED("EmitGroupNonUniform op: %s", OpcodeName(type.opcode()));
} }
return EmitResult::Continue; return EmitResult::Continue;
} }
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "SpirvShader.hpp" #include "SpirvShader.hpp"
#include "spirv-tools/libspirv.h"
#include <spirv/unified1/spirv.hpp> #include <spirv/unified1/spirv.hpp>
#define CONCAT(a, b) a##b #define CONCAT(a, b) a##b
...@@ -45,6 +47,11 @@ constexpr void checkForNoMissingOps(spv::Op op) ...@@ -45,6 +47,11 @@ constexpr void checkForNoMissingOps(spv::Op op)
namespace sw { namespace sw {
const char *SpirvShader::OpcodeName(spv::Op op)
{
return spvOpcodeString(op);
}
bool SpirvShader::IsStatement(spv::Op op) bool SpirvShader::IsStatement(spv::Op op)
{ {
switch(op) switch(op)
......
...@@ -344,7 +344,7 @@ void SpirvShader::VisitMemoryObjectInner(sw::SpirvShader::Type::ID id, sw::Spirv ...@@ -344,7 +344,7 @@ void SpirvShader::VisitMemoryObjectInner(sw::SpirvShader::Type::ID id, sw::Spirv
break; break;
} }
default: default:
UNREACHABLE("%s", OpcodeName(type.opcode()).c_str()); UNREACHABLE("%s", OpcodeName(type.opcode()));
} }
} }
......
...@@ -149,7 +149,7 @@ void SpirvShader::EvalSpecConstantOp(InsnIterator insn) ...@@ -149,7 +149,7 @@ void SpirvShader::EvalSpecConstantOp(InsnIterator insn)
// Other spec constant ops are possible, but require capabilities that are // Other spec constant ops are possible, but require capabilities that are
// not exposed in our Vulkan implementation (eg Kernel), so we should never // not exposed in our Vulkan implementation (eg Kernel), so we should never
// get here for correct shaders. // get here for correct shaders.
UNSUPPORTED("EvalSpecConstantOp op: %s", OpcodeName(opcode).c_str()); UNSUPPORTED("EvalSpecConstantOp op: %s", OpcodeName(opcode));
} }
} }
...@@ -198,7 +198,7 @@ void SpirvShader::EvalSpecConstantUnaryOp(InsnIterator insn) ...@@ -198,7 +198,7 @@ void SpirvShader::EvalSpecConstantUnaryOp(InsnIterator insn)
break; break;
} }
default: default:
UNREACHABLE("EvalSpecConstantUnaryOp op: %s", OpcodeName(opcode).c_str()); UNREACHABLE("EvalSpecConstantUnaryOp op: %s", OpcodeName(opcode));
} }
} }
} }
...@@ -306,7 +306,7 @@ void SpirvShader::EvalSpecConstantBinaryOp(InsnIterator insn) ...@@ -306,7 +306,7 @@ void SpirvShader::EvalSpecConstantBinaryOp(InsnIterator insn)
v = static_cast<int32_t>(l) >= static_cast<int32_t>(r) ? ~0u : 0u; v = static_cast<int32_t>(l) >= static_cast<int32_t>(r) ? ~0u : 0u;
break; break;
default: default:
UNREACHABLE("EvalSpecConstantBinaryOp op: %s", OpcodeName(opcode).c_str()); UNREACHABLE("EvalSpecConstantBinaryOp op: %s", OpcodeName(opcode));
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment