Commit 9fca494a by Ben Clayton

Update SPIRV-Headers to e4322e3b

Commands: git subtree pull --prefix third_party/SPIRV-Headers https://github.com/KhronosGroup/SPIRV-Headers e4322e3be589e1ddd44afb20ea842a977c1319b8 --squash Bug: b/123642959 Change-Id: Iec85e0df84b60c9b02299aa2b21bbc874ce684ac
parents 782a9802 f3e0560d
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
# The SPIR-V headers from the SPIR-V Registry # The SPIR-V headers from the SPIR-V Registry
# https://www.khronos.org/registry/spir-v/ # https://www.khronos.org/registry/spir-v/
# #
cmake_minimum_required(VERSION 2.8.11) cmake_minimum_required(VERSION 3.0)
project(SPIRV-Headers) project(SPIRV-Headers VERSION 1.4.1)
# There are two ways to use this project. # There are two ways to use this project.
# #
...@@ -44,14 +44,6 @@ project(SPIRV-Headers) ...@@ -44,14 +44,6 @@ project(SPIRV-Headers)
# 2. cmake .. # 2. cmake ..
# 3. cmake --build . --target install # 3. cmake --build . --target install
file(GLOB_RECURSE HEADER_FILES
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
include/spirv/*)
foreach(HEADER_FILE ${HEADER_FILES})
get_filename_component(HEADER_INSTALL_DIR ${HEADER_FILE} PATH)
install(FILES ${HEADER_FILE} DESTINATION ${HEADER_INSTALL_DIR})
endforeach()
# legacy # legacy
add_custom_target(install-headers add_custom_target(install-headers
COMMAND cmake -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/include/spirv COMMAND cmake -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/include/spirv
...@@ -66,3 +58,58 @@ if (SPIRV_HEADERS_ENABLE_EXAMPLES) ...@@ -66,3 +58,58 @@ if (SPIRV_HEADERS_ENABLE_EXAMPLES)
message(STATUS "Building SPIRV-Header examples") message(STATUS "Building SPIRV-Header examples")
add_subdirectory(example) add_subdirectory(example)
endif() endif()
include(GNUInstallDirs)
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
# Installation
set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${version_config}"
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"cmake/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)
install(
TARGETS ${PROJECT_NAME}
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
DIRECTORY include/spirv
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)
install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)
...@@ -29,6 +29,14 @@ Pull requests can be made to ...@@ -29,6 +29,14 @@ Pull requests can be made to
- request allocation of new enum ranges in the XML registry file - request allocation of new enum ranges in the XML registry file
- reserve specific tokens in the JSON grammar - reserve specific tokens in the JSON grammar
### Reserving tokens in the JSON grammar
Care should be taken to follow existing precedent in populating the details of reserved tokens. This includes:
- pointing to what extension has more information, when possible
- keeping enumerants in numeric order
- when there are aliases, listing the preferred spelling first
- adding the statement `"version" : "None"`
## How to install the headers ## How to install the headers
``` ```
......
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")
check_required_components("@PROJECT_NAME@")
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
<id value="0" vendor="Khronos" comment="Reserved by Khronos"/> <id value="0" vendor="Khronos" comment="Reserved by Khronos"/>
<id value="1" vendor="LunarG" comment="Contact TBD"/> <id value="1" vendor="LunarG" comment="Contact TBD"/>
<id value="2" vendor="Valve" comment="Contact TBD"/> <id value="2" vendor="Valve" comment="Contact TBD"/>
<id value="3" vendor="Codeplay" comment="Contact Neil Henning, neil@codeplay.com"/> <id value="3" vendor="Codeplay" comment="Contact Victor Lomuller, victor@codeplay.com"/>
<id value="4" vendor="NVIDIA" comment="Contact Kerch Holt, kholt@nvidia.com"/> <id value="4" vendor="NVIDIA" comment="Contact Kerch Holt, kholt@nvidia.com"/>
<id value="5" vendor="ARM" comment="Contact Alexander Galazin, alexander.galazin@arm.com"/> <id value="5" vendor="ARM" comment="Contact Alexander Galazin, alexander.galazin@arm.com"/>
<id value="6" vendor="Khronos" tool="LLVM/SPIR-V Translator" comment="Contact Yaxun (Sam) Liu, yaxun.liu@amd.com"/> <id value="6" vendor="Khronos" tool="LLVM/SPIR-V Translator" comment="Contact Yaxun (Sam) Liu, yaxun.liu@amd.com"/>
...@@ -70,7 +70,9 @@ ...@@ -70,7 +70,9 @@
<id value="18" vendor="Wine" tool="VKD3D Shader Compiler" comment="Contact wine-devel@winehq.org"/> <id value="18" vendor="Wine" tool="VKD3D Shader Compiler" comment="Contact wine-devel@winehq.org"/>
<id value="19" vendor="Clay" tool="Clay Shader Compiler" comment="Contact info@clayengine.com"/> <id value="19" vendor="Clay" tool="Clay Shader Compiler" comment="Contact info@clayengine.com"/>
<id value="20" vendor="W3C WebGPU Group" tool="WHLSL Shader Translator" comment="https://github.com/gpuweb/WHLSL"/> <id value="20" vendor="W3C WebGPU Group" tool="WHLSL Shader Translator" comment="https://github.com/gpuweb/WHLSL"/>
<unused start="21" end="0xFFFF" comment="Tool ID range reservable for future use by vendors"/> <id value="21" vendor="Google" tool="Clspv" comment="Contact David Neto, dneto@google.com"/>
<id value="22" vendor="Google" tool="MLIR SPIR-V Serializer" comment="Contact Lei Zhang, antiagainst@google.com"/>
<unused start="23" end="0xFFFF" comment="Tool ID range reservable for future use by vendors"/>
</ids> </ids>
<!-- SECTION: SPIR-V Opcodes and Enumerants --> <!-- SECTION: SPIR-V Opcodes and Enumerants -->
...@@ -99,7 +101,7 @@ ...@@ -99,7 +101,7 @@
<ids type="opcode" start="0" end="4095" vendor="Khronos" comment="Reserved opcodes, not available to vendors - see the SPIR-V Specification"/> <ids type="opcode" start="0" end="4095" vendor="Khronos" comment="Reserved opcodes, not available to vendors - see the SPIR-V Specification"/>
<ids type="opcode" start="4096" end="4159" vendor="Mesa" comment="Contact TBD"/> <ids type="opcode" start="4096" end="4159" vendor="Mesa" comment="Contact TBD"/>
<ids type="opcode" start="4160" end="4415" vendor="ARM"/> <ids type="opcode" start="4160" end="4415" vendor="ARM"/>
<ids type="opcode" start="4416" end="4479" vendor="Khronos" comment="SPV_ARB_shader_ballot - contact Neil Henning, neil@codeplay.com"/> <ids type="opcode" start="4416" end="4479" vendor="Khronos" comment="SPV_ARB_shader_ballot - contact Neil Henning, neil.henning@amd.com"/>
<ids type="opcode" start="4480" end="4991" vendor="Qualcomm" comment="Contact weifengz@qti.qualcomm.com"/> <ids type="opcode" start="4480" end="4991" vendor="Qualcomm" comment="Contact weifengz@qti.qualcomm.com"/>
<ids type="opcode" start="4992" end="5247" vendor="AMD"/> <ids type="opcode" start="4992" end="5247" vendor="AMD"/>
<ids type="opcode" start="5248" end="5503" vendor="NVIDIA"/> <ids type="opcode" start="5248" end="5503" vendor="NVIDIA"/>
...@@ -107,6 +109,8 @@ ...@@ -107,6 +109,8 @@
<ids type="opcode" start="5568" end="5631" vendor="Intel" comment="Contact ben.ashbaugh@intel.com"/> <ids type="opcode" start="5568" end="5631" vendor="Intel" comment="Contact ben.ashbaugh@intel.com"/>
<ids type="opcode" start="5632" end="5695" vendor="Google" comment="Contact dneto@google.com"/> <ids type="opcode" start="5632" end="5695" vendor="Google" comment="Contact dneto@google.com"/>
<ids type="opcode" start="5696" end="5823" vendor="Intel" comment="Contact ben.ashbaugh@intel.com"/> <ids type="opcode" start="5696" end="5823" vendor="Intel" comment="Contact ben.ashbaugh@intel.com"/>
<ids type="opcode" start="5824" end="5951" vendor="Intel" comment="Contact michael.kinsner@intel.com"/>
<ids type="opcode" start="5952" end="6015" vendor="Codeplay" comment="Contact victor@codeplay.com"/>
<!-- Opcodes & enumerants reservable for future use. To get a block, allocate <!-- Opcodes & enumerants reservable for future use. To get a block, allocate
multiples of 64 starting at the lowest available point in this multiples of 64 starting at the lowest available point in this
block and add a corresponding <ids> tag immediately above. Make block and add a corresponding <ids> tag immediately above. Make
...@@ -115,6 +119,27 @@ ...@@ -115,6 +119,27 @@
<!-- Example new block: <ids type="opcode" start="XXXX" end="XXXX+64n-1" vendor="Add vendor" comment="Contact TBD"/> --> <!-- Example new block: <ids type="opcode" start="XXXX" end="XXXX+64n-1" vendor="Add vendor" comment="Contact TBD"/> -->
<ids type="opcode" start="5824" end="4294967295" comment="Opcode range reservable for future use by vendors"/> <ids type="opcode" start="6016" end="4294967295" comment="Opcode range reservable for future use by vendors"/>
<!-- SECTION: SPIR-V Loop Control Bit Reservations -->
<!-- Reserve ranges of bits in the loop control bitfield.
Each vendor determines the use of values in their own ranges.
Vendors are not required to disclose those uses. If the use of a
value is included in an extension that is adopted by a Khronos
extension or specification, then that value's use may be permanently
fixed as if originally reserved in a Khronos range.
The SPIR Working Group strongly recommends:
- Each value is used for only one purpose.
- All values in a range should be used before allocating a new range.
-->
<!-- Reserved loop control bits -->
<ids type="LoopControl" start="0" end="15" vendor="Khronos" comment="Reserved LoopControl bits, not available to vendors - see the SPIR-V Specification"/>
<ids type="LoopControl" start="16" end="19" vendor="Intel" comment="Contact michael.kinsner@intel.com"/>
<ids type="LoopControl" start="20" end="30" comment="Unreserved bits reservable for use by vendors"/>
<ids type="LoopControl" start="31" end="31" vendor="Khronos" comment="Reserved LoopControl bit, not available to vendors"/>
</registry> </registry>
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#ifndef OPENCLstd_H #ifndef OPENCLstd_H
#define OPENCLstd_H #define OPENCLstd_H
#ifdef __cplusplus
namespace OpenCLLIB { namespace OpenCLLIB {
enum Entrypoints { enum Entrypoints {
...@@ -212,4 +213,189 @@ enum Entrypoints { ...@@ -212,4 +213,189 @@ enum Entrypoints {
} // end namespace OpenCLLIB } // end namespace OpenCLLIB
#else
enum OpenCLstd_Entrypoints {
// Section 2.1: Math extended instructions
OpenCLstd_Acos = 0,
OpenCLstd_Acosh = 1,
OpenCLstd_Acospi = 2,
OpenCLstd_Asin = 3,
OpenCLstd_Asinh = 4,
OpenCLstd_Asinpi = 5,
OpenCLstd_Atan = 6,
OpenCLstd_Atan2 = 7,
OpenCLstd_Atanh = 8,
OpenCLstd_Atanpi = 9,
OpenCLstd_Atan2pi = 10,
OpenCLstd_Cbrt = 11,
OpenCLstd_Ceil = 12,
OpenCLstd_Copysign = 13,
OpenCLstd_Cos = 14,
OpenCLstd_Cosh = 15,
OpenCLstd_Cospi = 16,
OpenCLstd_Erfc = 17,
OpenCLstd_Erf = 18,
OpenCLstd_Exp = 19,
OpenCLstd_Exp2 = 20,
OpenCLstd_Exp10 = 21,
OpenCLstd_Expm1 = 22,
OpenCLstd_Fabs = 23,
OpenCLstd_Fdim = 24,
OpenCLstd_Floor = 25,
OpenCLstd_Fma = 26,
OpenCLstd_Fmax = 27,
OpenCLstd_Fmin = 28,
OpenCLstd_Fmod = 29,
OpenCLstd_Fract = 30,
OpenCLstd_Frexp = 31,
OpenCLstd_Hypot = 32,
OpenCLstd_Ilogb = 33,
OpenCLstd_Ldexp = 34,
OpenCLstd_Lgamma = 35,
OpenCLstd_Lgamma_r = 36,
OpenCLstd_Log = 37,
OpenCLstd_Log2 = 38,
OpenCLstd_Log10 = 39,
OpenCLstd_Log1p = 40,
OpenCLstd_Logb = 41,
OpenCLstd_Mad = 42,
OpenCLstd_Maxmag = 43,
OpenCLstd_Minmag = 44,
OpenCLstd_Modf = 45,
OpenCLstd_Nan = 46,
OpenCLstd_Nextafter = 47,
OpenCLstd_Pow = 48,
OpenCLstd_Pown = 49,
OpenCLstd_Powr = 50,
OpenCLstd_Remainder = 51,
OpenCLstd_Remquo = 52,
OpenCLstd_Rint = 53,
OpenCLstd_Rootn = 54,
OpenCLstd_Round = 55,
OpenCLstd_Rsqrt = 56,
OpenCLstd_Sin = 57,
OpenCLstd_Sincos = 58,
OpenCLstd_Sinh = 59,
OpenCLstd_Sinpi = 60,
OpenCLstd_Sqrt = 61,
OpenCLstd_Tan = 62,
OpenCLstd_Tanh = 63,
OpenCLstd_Tanpi = 64,
OpenCLstd_Tgamma = 65,
OpenCLstd_Trunc = 66,
OpenCLstd_Half_cos = 67,
OpenCLstd_Half_divide = 68,
OpenCLstd_Half_exp = 69,
OpenCLstd_Half_exp2 = 70,
OpenCLstd_Half_exp10 = 71,
OpenCLstd_Half_log = 72,
OpenCLstd_Half_log2 = 73,
OpenCLstd_Half_log10 = 74,
OpenCLstd_Half_powr = 75,
OpenCLstd_Half_recip = 76,
OpenCLstd_Half_rsqrt = 77,
OpenCLstd_Half_sin = 78,
OpenCLstd_Half_sqrt = 79,
OpenCLstd_Half_tan = 80,
OpenCLstd_Native_cos = 81,
OpenCLstd_Native_divide = 82,
OpenCLstd_Native_exp = 83,
OpenCLstd_Native_exp2 = 84,
OpenCLstd_Native_exp10 = 85,
OpenCLstd_Native_log = 86,
OpenCLstd_Native_log2 = 87,
OpenCLstd_Native_log10 = 88,
OpenCLstd_Native_powr = 89,
OpenCLstd_Native_recip = 90,
OpenCLstd_Native_rsqrt = 91,
OpenCLstd_Native_sin = 92,
OpenCLstd_Native_sqrt = 93,
OpenCLstd_Native_tan = 94,
// Section 2.2: Integer instructions
OpenCLstd_SAbs = 141,
OpenCLstd_SAbs_diff = 142,
OpenCLstd_SAdd_sat = 143,
OpenCLstd_UAdd_sat = 144,
OpenCLstd_SHadd = 145,
OpenCLstd_UHadd = 146,
OpenCLstd_SRhadd = 147,
OpenCLstd_URhadd = 148,
OpenCLstd_SClamp = 149,
OpenCLstd_UClamp = 150,
OpenCLstd_Clz = 151,
OpenCLstd_Ctz = 152,
OpenCLstd_SMad_hi = 153,
OpenCLstd_UMad_sat = 154,
OpenCLstd_SMad_sat = 155,
OpenCLstd_SMax = 156,
OpenCLstd_UMax = 157,
OpenCLstd_SMin = 158,
OpenCLstd_UMin = 159,
OpenCLstd_SMul_hi = 160,
OpenCLstd_Rotate = 161,
OpenCLstd_SSub_sat = 162,
OpenCLstd_USub_sat = 163,
OpenCLstd_U_Upsample = 164,
OpenCLstd_S_Upsample = 165,
OpenCLstd_Popcount = 166,
OpenCLstd_SMad24 = 167,
OpenCLstd_UMad24 = 168,
OpenCLstd_SMul24 = 169,
OpenCLstd_UMul24 = 170,
OpenCLstd_UAbs = 201,
OpenCLstd_UAbs_diff = 202,
OpenCLstd_UMul_hi = 203,
OpenCLstd_UMad_hi = 204,
// Section 2.3: Common instructions
OpenCLstd_FClamp = 95,
OpenCLstd_Degrees = 96,
OpenCLstd_FMax_common = 97,
OpenCLstd_FMin_common = 98,
OpenCLstd_Mix = 99,
OpenCLstd_Radians = 100,
OpenCLstd_Step = 101,
OpenCLstd_Smoothstep = 102,
OpenCLstd_Sign = 103,
// Section 2.4: Geometric instructions
OpenCLstd_Cross = 104,
OpenCLstd_Distance = 105,
OpenCLstd_Length = 106,
OpenCLstd_Normalize = 107,
OpenCLstd_Fast_distance = 108,
OpenCLstd_Fast_length = 109,
OpenCLstd_Fast_normalize = 110,
// Section 2.5: Relational instructions
OpenCLstd_Bitselect = 186,
OpenCLstd_Select = 187,
// Section 2.6: Vector Data Load and Store instructions
OpenCLstd_Vloadn = 171,
OpenCLstd_Vstoren = 172,
OpenCLstd_Vload_half = 173,
OpenCLstd_Vload_halfn = 174,
OpenCLstd_Vstore_half = 175,
OpenCLstd_Vstore_half_r = 176,
OpenCLstd_Vstore_halfn = 177,
OpenCLstd_Vstore_halfn_r = 178,
OpenCLstd_Vloada_halfn = 179,
OpenCLstd_Vstorea_halfn = 180,
OpenCLstd_Vstorea_halfn_r = 181,
// Section 2.7: Miscellaneous Vector instructions
OpenCLstd_Shuffle = 182,
OpenCLstd_Shuffle2 = 183,
// Section 2.8: Misc instructions
OpenCLstd_Printf = 184,
OpenCLstd_Prefetch = 185,
};
#endif
#endif // #ifndef OPENCLstd_H #endif // #ifndef OPENCLstd_H
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <cctype> #include <cctype>
#include <vector> #include <vector>
#include <utility> #include <utility>
#include <set>
#include "jsoncpp/dist/json/json.h" #include "jsoncpp/dist/json/json.h"
...@@ -68,9 +69,9 @@ namespace { ...@@ -68,9 +69,9 @@ namespace {
TPrinter(); TPrinter();
static const int DocMagicNumber = 0x07230203; static const int DocMagicNumber = 0x07230203;
static const int DocVersion = 0x00010300; static const int DocVersion = 0x00010400;
static const int DocRevision = 6; static const int DocRevision = 1;
#define DocRevisionString "6" #define DocRevisionString "1"
static const std::string DocCopyright; static const std::string DocCopyright;
static const std::string DocComment1; static const std::string DocComment1;
static const std::string DocComment2; static const std::string DocComment2;
...@@ -97,6 +98,7 @@ namespace { ...@@ -97,6 +98,7 @@ namespace {
virtual void printEpilogue(std::ostream&) const { } virtual void printEpilogue(std::ostream&) const { }
virtual void printMeta(std::ostream&) const; virtual void printMeta(std::ostream&) const;
virtual void printTypes(std::ostream&) const { } virtual void printTypes(std::ostream&) const { }
virtual void printHasResultType(std::ostream&) const { };
virtual std::string escapeComment(const std::string& s) const; virtual std::string escapeComment(const std::string& s) const;
...@@ -346,7 +348,7 @@ namespace { ...@@ -346,7 +348,7 @@ namespace {
bool printMax = (style != enumMask && maxEnum.size() > 0); bool printMax = (style != enumMask && maxEnum.size() > 0);
for (const auto& v : sorted) for (const auto& v : sorted)
out << enumFmt(opPrefix, v, style, !printMax && v.first == sorted.back().first); out << enumFmt(opPrefix, v, style, !printMax && v.second == sorted.back().second);
if (printMax) if (printMax)
out << maxEnum; out << maxEnum;
...@@ -364,6 +366,7 @@ namespace { ...@@ -364,6 +366,7 @@ namespace {
printTypes(out); printTypes(out);
printMeta(out); printMeta(out);
printDefs(out); printDefs(out);
printHasResultType(out);
printEpilogue(out); printEpilogue(out);
} }
...@@ -478,7 +481,7 @@ namespace { ...@@ -478,7 +481,7 @@ namespace {
} }
virtual void printEpilogue(std::ostream& out) const override { virtual void printEpilogue(std::ostream& out) const override {
out << "#endif // #ifndef spirv_" << headerGuardSuffix() << std::endl; out << "#endif" << std::endl;
} }
virtual void printTypes(std::ostream& out) const override { virtual void printTypes(std::ostream& out) const override {
...@@ -494,6 +497,45 @@ namespace { ...@@ -494,6 +497,45 @@ namespace {
virtual std::string pre() const { return ""; } // C name prefix virtual std::string pre() const { return ""; } // C name prefix
virtual std::string headerGuardSuffix() const = 0; virtual std::string headerGuardSuffix() const = 0;
virtual std::string fmtEnumUse(const std::string& opPrefix, const std::string& name) const { return pre() + name; }
virtual void printHasResultType(std::ostream& out) const
{
const Json::Value& enums = spvRoot["spv"]["enum"];
std::set<unsigned> seenValues;
for (auto opClass = enums.begin(); opClass != enums.end(); ++opClass) {
const auto opName = (*opClass)["Name"].asString();
if (opName != "Op") {
continue;
}
out << "#ifdef SPV_ENABLE_UTILITY_CODE" << std::endl;
out << "inline void " << pre() << "HasResultAndType(" << pre() << opName << " opcode, bool *hasResult, bool *hasResultType) {" << std::endl;
out << " *hasResult = *hasResultType = false;" << std::endl;
out << " switch (opcode) {" << std::endl;
out << " default: /* unknown opcode */ break;" << std::endl;
for (auto& inst : spv::InstructionDesc) {
// Filter out duplicate enum values, which would break the switch statement.
// These are probably just extension enums promoted to core.
if (seenValues.find(inst.value) != seenValues.end()) {
continue;
}
seenValues.insert(inst.value);
std::string name = inst.name;
out << " case " << fmtEnumUse("Op", name) << ": *hasResult = " << (inst.hasResult() ? "true" : "false") << "; *hasResultType = " << (inst.hasType() ? "true" : "false") << "; break;" << std::endl;
}
out << " }" << std::endl;
out << "}" << std::endl;
out << "#endif /* SPV_ENABLE_UTILITY_CODE */" << std::endl << std::endl;
}
}
}; };
// C printer // C printer
...@@ -552,7 +594,7 @@ namespace { ...@@ -552,7 +594,7 @@ namespace {
} }
out << "\n} // end namespace spv\n\n"; out << "\n} // end namespace spv\n\n";
TPrinterCBase::printEpilogue(out); out << "#endif // #ifndef spirv_" << headerGuardSuffix() << std::endl;
} }
std::string commentBOL() const override { return "// "; } std::string commentBOL() const override { return "// "; }
...@@ -600,6 +642,9 @@ namespace { ...@@ -600,6 +642,9 @@ namespace {
return enumFmt(s, v, style, true); return enumFmt(s, v, style, true);
} }
// Add type prefix for scoped enum
virtual std::string fmtEnumUse(const std::string& opPrefix, const std::string& name) const { return opPrefix + "::" + name; }
std::string headerGuardSuffix() const override { return "HPP"; } std::string headerGuardSuffix() const override { return "HPP"; }
}; };
......
...@@ -119,8 +119,7 @@ ClassOptionality ToOperandClassAndOptionality(const std::string& operandKind, co ...@@ -119,8 +119,7 @@ ClassOptionality ToOperandClassAndOptionality(const std::string& operandKind, co
else if (quantifier == "?") else if (quantifier == "?")
return {OperandLiteralString, true}; return {OperandLiteralString, true};
else { else {
assert(0 && "this case should not exist"); return {OperandOptionalLiteralStrings, false};
return {OperandNone, false};
} }
} else if (operandKind == "PairLiteralIntegerIdRef") { } else if (operandKind == "PairLiteralIntegerIdRef") {
// Used by OpSwitch in the grammar // Used by OpSwitch in the grammar
...@@ -198,7 +197,7 @@ ClassOptionality ToOperandClassAndOptionality(const std::string& operandKind, co ...@@ -198,7 +197,7 @@ ClassOptionality ToOperandClassAndOptionality(const std::string& operandKind, co
} else if (operandKind == "FunctionControl") { } else if (operandKind == "FunctionControl") {
type = OperandFunction; type = OperandFunction;
} else if (operandKind == "MemoryAccess") { } else if (operandKind == "MemoryAccess") {
type = OperandMemoryAccess; type = OperandMemoryOperands;
} }
if (type == OperandNone) { if (type == OperandNone) {
...@@ -230,7 +229,21 @@ unsigned int NumberStringToBit(const std::string& str) ...@@ -230,7 +229,21 @@ unsigned int NumberStringToBit(const std::string& str)
return bit; return bit;
} }
void jsonToSpirv(const std::string& jsonPath) bool ExcludeInstruction(unsigned op, bool buildingHeaders)
{
// Some instructions in the grammar don't need to be reflected
// in the specification.
if (buildingHeaders)
return false;
if (op >= 5699 /* OpVmeImageINTEL */ && op <= 5816 /* OpSubgroupAvcSicGetInterRawSadsINTEL */)
return true;
return false;
}
void jsonToSpirv(const std::string& jsonPath, bool buildingHeaders)
{ {
// only do this once. // only do this once.
static bool initialized = false; static bool initialized = false;
...@@ -288,9 +301,12 @@ void jsonToSpirv(const std::string& jsonPath) ...@@ -288,9 +301,12 @@ void jsonToSpirv(const std::string& jsonPath)
const Json::Value insts = root["instructions"]; const Json::Value insts = root["instructions"];
for (const auto& inst : insts) { for (const auto& inst : insts) {
const unsigned int opcode = inst["opcode"].asUInt(); const unsigned int opcode = inst["opcode"].asUInt();
if (ExcludeInstruction(opcode, buildingHeaders))
continue;
const std::string name = inst["opname"].asString(); const std::string name = inst["opname"].asString();
EnumCaps caps = getCaps(inst); EnumCaps caps = getCaps(inst);
std::string version = inst["version"].asString(); std::string version = inst["version"].asString();
std::string lastVersion = inst["lastVersion"].asString();
Extensions exts = getExts(inst); Extensions exts = getExts(inst);
OperandParameters operands; OperandParameters operands;
bool defResultId = false; bool defResultId = false;
...@@ -306,7 +322,7 @@ void jsonToSpirv(const std::string& jsonPath) ...@@ -306,7 +322,7 @@ void jsonToSpirv(const std::string& jsonPath)
} }
InstructionDesc.emplace_back( InstructionDesc.emplace_back(
std::move(EnumValue(opcode, name, std::move(EnumValue(opcode, name,
std::move(caps), std::move(version), std::move(exts), std::move(caps), std::move(version), std::move(lastVersion), std::move(exts),
std::move(operands))), std::move(operands))),
defTypeId, defResultId); defTypeId, defResultId);
} }
...@@ -339,6 +355,7 @@ void jsonToSpirv(const std::string& jsonPath) ...@@ -339,6 +355,7 @@ void jsonToSpirv(const std::string& jsonPath)
continue; continue;
EnumCaps caps(getCaps(enumerant)); EnumCaps caps(getCaps(enumerant));
std::string version = enumerant["version"].asString(); std::string version = enumerant["version"].asString();
std::string lastVersion = enumerant["lastVersion"].asString();
Extensions exts(getExts(enumerant)); Extensions exts(getExts(enumerant));
OperandParameters params; OperandParameters params;
const Json::Value& paramsJson = enumerant["parameters"]; const Json::Value& paramsJson = enumerant["parameters"];
...@@ -353,7 +370,7 @@ void jsonToSpirv(const std::string& jsonPath) ...@@ -353,7 +370,7 @@ void jsonToSpirv(const std::string& jsonPath)
} }
dest->emplace_back( dest->emplace_back(
value, enumerant["enumerant"].asString(), value, enumerant["enumerant"].asString(),
std::move(caps), std::move(version), std::move(exts), std::move(params)); std::move(caps), std::move(version), std::move(lastVersion), std::move(exts), std::move(params));
} }
}; };
...@@ -421,7 +438,7 @@ void jsonToSpirv(const std::string& jsonPath) ...@@ -421,7 +438,7 @@ void jsonToSpirv(const std::string& jsonPath)
} else if (enumName == "Dim") { } else if (enumName == "Dim") {
establishOperandClass(enumName, OperandDimensionality, &DimensionalityParams, operandEnum, category); establishOperandClass(enumName, OperandDimensionality, &DimensionalityParams, operandEnum, category);
} else if (enumName == "MemoryAccess") { } else if (enumName == "MemoryAccess") {
establishOperandClass(enumName, OperandMemoryAccess, &MemoryAccessParams, operandEnum, category); establishOperandClass(enumName, OperandMemoryOperands, &MemoryAccessParams, operandEnum, category);
} else if (enumName == "Scope") { } else if (enumName == "Scope") {
establishOperandClass(enumName, OperandScope, &ScopeParams, operandEnum, category); establishOperandClass(enumName, OperandScope, &ScopeParams, operandEnum, category);
} else if (enumName == "GroupOperation") { } else if (enumName == "GroupOperation") {
......
...@@ -38,7 +38,7 @@ namespace spv { ...@@ -38,7 +38,7 @@ namespace spv {
std::pair<bool, std::string> ReadFile(const std::string& path); std::pair<bool, std::string> ReadFile(const std::string& path);
// Fill in all the parameters // Fill in all the parameters
void jsonToSpirv(const std::string& jsonPath); void jsonToSpirv(const std::string& jsonPath, bool buildingHeaders);
// For parameterizing operands. // For parameterizing operands.
enum OperandClass { enum OperandClass {
...@@ -47,6 +47,7 @@ enum OperandClass { ...@@ -47,6 +47,7 @@ enum OperandClass {
OperandVariableIds, OperandVariableIds,
OperandOptionalLiteral, OperandOptionalLiteral,
OperandOptionalLiteralString, OperandOptionalLiteralString,
OperandOptionalLiteralStrings,
OperandVariableLiterals, OperandVariableLiterals,
OperandVariableIdLiteral, OperandVariableIdLiteral,
OperandVariableLiteralId, OperandVariableLiteralId,
...@@ -76,7 +77,7 @@ enum OperandClass { ...@@ -76,7 +77,7 @@ enum OperandClass {
OperandLoop, OperandLoop,
OperandFunction, OperandFunction,
OperandMemorySemantics, OperandMemorySemantics,
OperandMemoryAccess, OperandMemoryOperands,
OperandScope, OperandScope,
OperandGroupOperation, OperandGroupOperation,
OperandKernelEnqueueFlags, OperandKernelEnqueueFlags,
...@@ -145,6 +146,12 @@ public: ...@@ -145,6 +146,12 @@ public:
assert((where != end()) && "Could not find enum in the enum list"); assert((where != end()) && "Could not find enum in the enum list");
return *where; return *where;
} }
// gets *all* entries for the value, including the first one
void gatherAliases(unsigned value, std::vector<EValue*>& aliases) {
std::for_each(begin(), end(), [&](EValue& e) {
if (value == e.value)
aliases.push_back(&e);});
}
// Returns the EValue with the given name. We assume uniqueness // Returns the EValue with the given name. We assume uniqueness
// by name. // by name.
EValue& at(std::string name) { EValue& at(std::string name) {
...@@ -167,9 +174,11 @@ private: ...@@ -167,9 +174,11 @@ private:
class EnumValue { class EnumValue {
public: public:
EnumValue() : value(0), desc(nullptr) {} EnumValue() : value(0), desc(nullptr) {}
EnumValue(unsigned int the_value, const std::string& the_name, EnumCaps&& the_caps, const std::string& the_version, EnumValue(unsigned int the_value, const std::string& the_name, EnumCaps&& the_caps,
const std::string& the_firstVersion, const std::string& the_lastVersion,
Extensions&& the_extensions, OperandParameters&& the_operands) : Extensions&& the_extensions, OperandParameters&& the_operands) :
value(the_value), name(the_name), capabilities(std::move(the_caps)), version(std::move(the_version)), value(the_value), name(the_name), capabilities(std::move(the_caps)),
firstVersion(std::move(the_firstVersion)), lastVersion(std::move(the_lastVersion)),
extensions(std::move(the_extensions)), operands(std::move(the_operands)), desc(nullptr) { } extensions(std::move(the_extensions)), operands(std::move(the_operands)), desc(nullptr) { }
// For ValueEnum, the value from the JSON file. // For ValueEnum, the value from the JSON file.
...@@ -178,7 +187,8 @@ public: ...@@ -178,7 +187,8 @@ public:
unsigned value; unsigned value;
std::string name; std::string name;
EnumCaps capabilities; EnumCaps capabilities;
std::string version; std::string firstVersion;
std::string lastVersion;
// A feature only be enabled by certain extensions. // A feature only be enabled by certain extensions.
// An empty list means the feature does not require an extension. // An empty list means the feature does not require an extension.
// Normally, only Capability enums are enabled by extension. In turn, // Normally, only Capability enums are enabled by extension. In turn,
...@@ -233,10 +243,19 @@ public: ...@@ -233,10 +243,19 @@ public:
opDesc("TBD"), opDesc("TBD"),
opClass(0), opClass(0),
typePresent(has_type), typePresent(has_type),
resultPresent(has_result) {} resultPresent(has_result),
alias(this) { }
InstructionValue(const InstructionValue& v)
{
*this = v;
alias = this;
}
bool hasResult() const { return resultPresent != 0; } bool hasResult() const { return resultPresent != 0; }
bool hasType() const { return typePresent != 0; } bool hasType() const { return typePresent != 0; }
void setAlias(const InstructionValue& a) { alias = &a; }
const InstructionValue& getAlias() const { return *alias; }
bool isAlias() const { return alias != this; }
const char* opDesc; const char* opDesc;
int opClass; int opClass;
...@@ -244,6 +263,7 @@ public: ...@@ -244,6 +263,7 @@ public:
protected: protected:
int typePresent : 1; int typePresent : 1;
int resultPresent : 1; int resultPresent : 1;
const InstructionValue* alias; // correct only after discovering the aliases; otherwise points to this
}; };
using InstructionValues = EnumValuesContainer<InstructionValue>; using InstructionValues = EnumValuesContainer<InstructionValue>;
......
...@@ -119,7 +119,7 @@ int main(int argc, char* argv[]) ...@@ -119,7 +119,7 @@ int main(int argc, char* argv[])
return 1; return 1;
} }
spv::jsonToSpirv(jsonPath); spv::jsonToSpirv(jsonPath, (Options & EOptionPrintHeader) != 0);
if (Options & EOptionPrintHeader) if (Options & EOptionPrintHeader)
spv::PrintHeader(Language, std::cout); spv::PrintHeader(Language, std::cout);
......
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