return act.takeModule();
}
+
+#ifdef HAVE_CLOVER_SPIRV
+ SPIRV::TranslatorOpts
+ get_spirv_translator_options(const device &dev) {
+ const auto supported_versions = spirv::supported_versions();
+ const auto maximum_spirv_version =
+ std::min(static_cast<SPIRV::VersionNumber>(supported_versions.back()),
+ SPIRV::VersionNumber::MaximumVersion);
+
+ return SPIRV::TranslatorOpts(maximum_spirv_version);
+ }
+#endif
}
module
if (has_flag(debug::llvm))
debug::log(".ll", print_module_bitcode(*mod));
+ const auto spirv_options = get_spirv_translator_options(dev);
+
std::string error_msg;
if (!::llvm::regularizeLlvmForSpirv(mod.get(), error_msg)) {
r_log += "Failed to regularize LLVM IR for SPIR-V: " + error_msg + ".\n";
}
std::ostringstream os;
- if (!::llvm::writeSpirv(mod.get(), os, error_msg)) {
+ if (!::llvm::writeSpirv(mod.get(), spirv_options, os, error_msg)) {
r_log += "Translation from LLVM IR to SPIR-V failed: " + error_msg + ".\n";
throw error(CL_INVALID_VALUE);
}
#ifdef HAVE_CLOVER_SPIRV
namespace {
+ uint32_t
+ make_spirv_version(uint8_t major, uint8_t minor) {
+ return (static_cast<uint32_t>(major) << 16u) |
+ (static_cast<uint32_t>(minor) << 8u);
+ }
+
template<typename T>
T get(const char *source, size_t index) {
const uint32_t *word_ptr = reinterpret_cast<const uint32_t *>(source);
};
}
+std::vector<uint32_t>
+clover::spirv::supported_versions() {
+ return { make_spirv_version(1u, 0u) };
+}
+
#else
bool
clover::spirv::is_valid_spirv(const std::vector<char> &/*binary*/,
clover::spirv::supported_extensions() {
return {};
}
+
+std::vector<uint32_t>
+clover::spirv::supported_versions() {
+ return {};
+}
#endif
// Returns a set of supported SPIR-V extensions.
std::unordered_set<std::string> supported_extensions();
+
+ // Returns a vector (sorted in increasing order) of supported SPIR-V
+ // versions.
+ std::vector<uint32_t> supported_versions();
}
}