Commit f3e0560d by Ben Clayton

Squashed 'third_party/SPIRV-Headers/' changes from 79b6681aa..e4322e3be

e4322e3be Merge pull request #123 from AaronHaganAMD/master 5bc5041bd Add SPV_KHR_shader_clock to spirv-headers 45c2cc372 Merge pull request #122 from mkinsner/array_init_loop_control_bit 7971055a8 Reserve additional loop control bit for upcoming update to SPV_INTEL_fpga_loop_controls extension 29c11140b Merge pull request #120 from antiagainst/mlir-serializer 123dc278f Merge pull request #121 from jeffbolznv/demote_to_helper_invocation dcce859e3 add SPV_EXT_demote_to_helper_invocation 739546b1c Reserve ID 23 for MLIR SPIR-V Serializer de99d4d83 Merge pull request #119 from dneto0/spirv-issue-476 9baa9e099 Add Volatile to Memory Semantics, for SPV_KHR_vulkan_memory_model 9cf7c3a7d Merge pull request #117 from ehsannas/UserTypeGOOGLE b1344c0d1 Add grammar and symbols for UserTypeGOOGLE extension to unified1. 9242862c8 Merge pull request #105 from mchiasson/cmake_install_config a7741727e Add missing "version" : "None" to a bunch of reserved enumerants. d5d33167d Add more detail about reserving tokens to the README. e88e050b2 Restore numerical order in enumerants. 8b911bd2b Merge pull request #114 from jeffbolznv/fsi 326779e4b Add SPV_EXT_fragment_shader_interlock 9280c0b4f Merge pull request #115 from dgkoch/SPV_NV_sm_shader_builts 630d06236 Add support for SPV_NV_sm_shader_builtins 903d447d9 OpenCL ext. inst. header: Support C in addition to C++. 7ac42f80c Merge pull request #112 from mkinsner/master d6936f933 Proposed LoopControl bitfield allocation mechanism in spir-v.xml 7f4277e21 Merge pull request #111 from Naghasan/codeplay-range 1edd6c43a Reserve token range for Codeplay ed8674d22 Update CMakeLists.txt 9674a1a54 Merge pull request #102 from ianromanick/INTEL_shader_integer_functions2 a08d4f0aa Merge pull request #107 from jeffbolznv/duplicate_enum_switch 9f50e659a Update HasResultAndType code generation to skip duplicate enum values. There weren't any until SPIR-V 1.4 release, now there are two. f7b06c277 updated as per code review 4b0985f29 Merge pull request #106 from alankemp/fix_json_writer 823750b56 Compare enum names rather than values to determine last element c5a291f7a cmake development configuration package Fixes #104 30ebd2f19 Merge pull request #103 from amdrexu/bugfix 30c51d36e Enable Groups capability by the extension SPV_AMD_shader_ballot 40798610d Add INTEL_shader_integer_functions2 c4f8f6579 Move to version 1.4 of SPIR-V. a5d33a253 Rationalize opcode ordering and a few spaces. 7af56c133 Merge pull request #101 from dneto0/clspv-generator 92d10249b Reserve generator 21 for Clspv 2434b8934 Merge pull request #100 from jeffbolznv/hasresult 9f7761857 Add a function that returns whether an opcode has a result and/or result type. Currently only implemented in C-based printers. 111a25e4a Merge pull request #99 from Naghasan/contact-update 0e0d1765e Update Codeplay's contact details 3beb2a037 Add ability to skip ranges of instructions; no impact to public headers 2d08d12d8 Sync to rev. 7 of headers from Khronos. f25b91a61 Merge pull request #98 from jeffbolznv/partitioned d20b78c77 Add GroupNonUniformPartitionedNV capability to all the GroupNonUniform instructions a946e7319 Header build for previous grammar update. 8f1cce947 Merge pull request #92 from PawelJurek/SPV_INTEL_device_side_avc_motion_estimation 03a081524 Make all "IdScope" be either Execution or Memory. dc3db3a5a Fix #96: Don't include a comment after #endif for the C header. d3752ea20 Merge pull request #95 from mkinsner/fpga_enum_block 2b3bbbc28 Reserve double SPIR-V enum block for upcoming Intel FPGA extension e74c389f8 Merge pull request #94 from jeffbolznv/cooperative_matrix 56decd41b Add SPV_NV_cooperative_matrix d0cc5acdf Grammar for SPV_INTEL_device_side_avc_motion_estimation extension. 8bea0a266 Update headers from previous SPV_INTEL_media_block_io grammar addition. 21f0d0744 Merge pull request #93 from PawelJurek/SPV_INTEL_media_block_io f2aef5d04 Grammar for SPV_INTEL_media_block_io extension f3abb280c Merge pull request #91 from LukasBanana/master b6a6dc041 Added '.DS_Store' (MacOS specific file) to gitignore. git-subtree-dir: third_party/SPIRV-Headers git-subtree-split: e4322e3be589e1ddd44afb20ea842a977c1319b8
parent 670217af
......@@ -28,8 +28,8 @@
# The SPIR-V headers from the SPIR-V Registry
# https://www.khronos.org/registry/spir-v/
#
cmake_minimum_required(VERSION 2.8.11)
project(SPIRV-Headers)
cmake_minimum_required(VERSION 3.0)
project(SPIRV-Headers VERSION 1.4.1)
# There are two ways to use this project.
#
......@@ -44,14 +44,6 @@ project(SPIRV-Headers)
# 2. cmake ..
# 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
add_custom_target(install-headers
COMMAND cmake -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/include/spirv
......@@ -66,3 +58,58 @@ if (SPIRV_HEADERS_ENABLE_EXAMPLES)
message(STATUS "Building SPIRV-Header examples")
add_subdirectory(example)
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}"
)
......@@ -25,10 +25,18 @@ the files under [include](include).
The SPIR-V XML registry file is updated by Khronos whenever a new enum range is allocated.
Pull requests can be made to
Pull requests can be made to
- request allocation of new enum ranges in the XML registry file
- 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
```
......
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")
check_required_components("@PROJECT_NAME@")
......@@ -52,7 +52,7 @@
<id value="0" vendor="Khronos" comment="Reserved by Khronos"/>
<id value="1" vendor="LunarG" 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="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"/>
......@@ -70,7 +70,9 @@
<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="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>
<!-- SECTION: SPIR-V Opcodes and Enumerants -->
......@@ -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="4096" end="4159" vendor="Mesa" comment="Contact TBD"/>
<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="4992" end="5247" vendor="AMD"/>
<ids type="opcode" start="5248" end="5503" vendor="NVIDIA"/>
......@@ -107,6 +109,8 @@
<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="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
multiples of 64 starting at the lowest available point in this
block and add a corresponding <ids> tag immediately above. Make
......@@ -115,6 +119,27 @@
<!-- 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>
......@@ -27,6 +27,7 @@
#ifndef OPENCLstd_H
#define OPENCLstd_H
#ifdef __cplusplus
namespace OpenCLLIB {
enum Entrypoints {
......@@ -212,4 +213,189 @@ enum Entrypoints {
} // 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
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -42,6 +42,7 @@
#include <cctype>
#include <vector>
#include <utility>
#include <set>
#include "jsoncpp/dist/json/json.h"
......@@ -68,9 +69,9 @@ namespace {
TPrinter();
static const int DocMagicNumber = 0x07230203;
static const int DocVersion = 0x00010300;
static const int DocRevision = 6;
#define DocRevisionString "6"
static const int DocVersion = 0x00010400;
static const int DocRevision = 1;
#define DocRevisionString "1"
static const std::string DocCopyright;
static const std::string DocComment1;
static const std::string DocComment2;
......@@ -97,6 +98,7 @@ namespace {
virtual void printEpilogue(std::ostream&) const { }
virtual void printMeta(std::ostream&) const;
virtual void printTypes(std::ostream&) const { }
virtual void printHasResultType(std::ostream&) const { };
virtual std::string escapeComment(const std::string& s) const;
......@@ -346,7 +348,7 @@ namespace {
bool printMax = (style != enumMask && maxEnum.size() > 0);
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)
out << maxEnum;
......@@ -364,6 +366,7 @@ namespace {
printTypes(out);
printMeta(out);
printDefs(out);
printHasResultType(out);
printEpilogue(out);
}
......@@ -478,7 +481,7 @@ namespace {
}
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 {
......@@ -494,6 +497,45 @@ namespace {
virtual std::string pre() const { return ""; } // C name prefix
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
......@@ -552,7 +594,7 @@ namespace {
}
out << "\n} // end namespace spv\n\n";
TPrinterCBase::printEpilogue(out);
out << "#endif // #ifndef spirv_" << headerGuardSuffix() << std::endl;
}
std::string commentBOL() const override { return "// "; }
......@@ -600,6 +642,9 @@ namespace {
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"; }
};
......
......@@ -119,8 +119,7 @@ ClassOptionality ToOperandClassAndOptionality(const std::string& operandKind, co
else if (quantifier == "?")
return {OperandLiteralString, true};
else {
assert(0 && "this case should not exist");
return {OperandNone, false};
return {OperandOptionalLiteralStrings, false};
}
} else if (operandKind == "PairLiteralIntegerIdRef") {
// Used by OpSwitch in the grammar
......@@ -198,7 +197,7 @@ ClassOptionality ToOperandClassAndOptionality(const std::string& operandKind, co
} else if (operandKind == "FunctionControl") {
type = OperandFunction;
} else if (operandKind == "MemoryAccess") {
type = OperandMemoryAccess;
type = OperandMemoryOperands;
}
if (type == OperandNone) {
......@@ -230,7 +229,21 @@ unsigned int NumberStringToBit(const std::string& str)
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.
static bool initialized = false;
......@@ -288,9 +301,12 @@ void jsonToSpirv(const std::string& jsonPath)
const Json::Value insts = root["instructions"];
for (const auto& inst : insts) {
const unsigned int opcode = inst["opcode"].asUInt();
if (ExcludeInstruction(opcode, buildingHeaders))
continue;
const std::string name = inst["opname"].asString();
EnumCaps caps = getCaps(inst);
std::string version = inst["version"].asString();
std::string lastVersion = inst["lastVersion"].asString();
Extensions exts = getExts(inst);
OperandParameters operands;
bool defResultId = false;
......@@ -306,7 +322,7 @@ void jsonToSpirv(const std::string& jsonPath)
}
InstructionDesc.emplace_back(
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))),
defTypeId, defResultId);
}
......@@ -339,6 +355,7 @@ void jsonToSpirv(const std::string& jsonPath)
continue;
EnumCaps caps(getCaps(enumerant));
std::string version = enumerant["version"].asString();
std::string lastVersion = enumerant["lastVersion"].asString();
Extensions exts(getExts(enumerant));
OperandParameters params;
const Json::Value& paramsJson = enumerant["parameters"];
......@@ -353,7 +370,7 @@ void jsonToSpirv(const std::string& jsonPath)
}
dest->emplace_back(
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)
} else if (enumName == "Dim") {
establishOperandClass(enumName, OperandDimensionality, &DimensionalityParams, operandEnum, category);
} else if (enumName == "MemoryAccess") {
establishOperandClass(enumName, OperandMemoryAccess, &MemoryAccessParams, operandEnum, category);
establishOperandClass(enumName, OperandMemoryOperands, &MemoryAccessParams, operandEnum, category);
} else if (enumName == "Scope") {
establishOperandClass(enumName, OperandScope, &ScopeParams, operandEnum, category);
} else if (enumName == "GroupOperation") {
......
......@@ -38,7 +38,7 @@ namespace spv {
std::pair<bool, std::string> ReadFile(const std::string& path);
// Fill in all the parameters
void jsonToSpirv(const std::string& jsonPath);
void jsonToSpirv(const std::string& jsonPath, bool buildingHeaders);
// For parameterizing operands.
enum OperandClass {
......@@ -47,6 +47,7 @@ enum OperandClass {
OperandVariableIds,
OperandOptionalLiteral,
OperandOptionalLiteralString,
OperandOptionalLiteralStrings,
OperandVariableLiterals,
OperandVariableIdLiteral,
OperandVariableLiteralId,
......@@ -76,7 +77,7 @@ enum OperandClass {
OperandLoop,
OperandFunction,
OperandMemorySemantics,
OperandMemoryAccess,
OperandMemoryOperands,
OperandScope,
OperandGroupOperation,
OperandKernelEnqueueFlags,
......@@ -145,6 +146,12 @@ public:
assert((where != end()) && "Could not find enum in the enum list");
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
// by name.
EValue& at(std::string name) {
......@@ -167,9 +174,11 @@ private:
class EnumValue {
public:
EnumValue() : value(0), desc(nullptr) {}
EnumValue(unsigned int the_value, const std::string& the_name, EnumCaps&& the_caps, const std::string& the_version,
Extensions&& the_extensions, OperandParameters&& the_operands) :
value(the_value), name(the_name), capabilities(std::move(the_caps)), version(std::move(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) :
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) { }
// For ValueEnum, the value from the JSON file.
......@@ -178,7 +187,8 @@ public:
unsigned value;
std::string name;
EnumCaps capabilities;
std::string version;
std::string firstVersion;
std::string lastVersion;
// A feature only be enabled by certain extensions.
// An empty list means the feature does not require an extension.
// Normally, only Capability enums are enabled by extension. In turn,
......@@ -233,10 +243,19 @@ public:
opDesc("TBD"),
opClass(0),
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 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;
int opClass;
......@@ -244,6 +263,7 @@ public:
protected:
int typePresent : 1;
int resultPresent : 1;
const InstructionValue* alias; // correct only after discovering the aliases; otherwise points to this
};
using InstructionValues = EnumValuesContainer<InstructionValue>;
......
......@@ -119,7 +119,7 @@ int main(int argc, char* argv[])
return 1;
}
spv::jsonToSpirv(jsonPath);
spv::jsonToSpirv(jsonPath, (Options & EOptionPrintHeader) != 0);
if (Options & EOptionPrintHeader)
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