From 4cfd57dd489bab37ed77bddcfe4bbf55051f5362 Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Wed, 18 Nov 2020 18:34:07 -0800 Subject: [PATCH] clover/llvm: Work around MSVC quirks Two things: 1. While instantiating a template where clover::llvm and ::llvm are both resolvable for unscoped llvm, MSVC complains about ambiguity. Resolve by not using namespace clover, leaving only ::llvm as a valid namespace. 2. LLVM headers (specifically Allocator.h) use __declspec(restrict), but Mesa's util headers #define restrict to __restrict for C++. Since __declspec(__restrict) is invalid, make sure we always include Allocator.h first before the util header. 3. Change a uint/int to uint64_t to match the type returned from LLVM. Reviewed-by: Francisco Jerez Part-of: --- src/gallium/frontends/clover/llvm/codegen/bitcode.cpp | 4 +++- src/gallium/frontends/clover/llvm/codegen/common.cpp | 7 +++++-- src/gallium/frontends/clover/llvm/codegen/native.cpp | 11 ++++++----- src/gallium/frontends/clover/llvm/invocation.cpp | 11 ++++++++--- src/gallium/frontends/clover/llvm/metadata.hpp | 2 +- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/gallium/frontends/clover/llvm/codegen/bitcode.cpp b/src/gallium/frontends/clover/llvm/codegen/bitcode.cpp index 413f110..8ea3e57 100644 --- a/src/gallium/frontends/clover/llvm/codegen/bitcode.cpp +++ b/src/gallium/frontends/clover/llvm/codegen/bitcode.cpp @@ -31,6 +31,8 @@ /// after linking against other bitcode object files. /// +#include + #include "llvm/codegen.hpp" #include "llvm/compat.hpp" #include "llvm/metadata.hpp" @@ -47,7 +49,7 @@ #endif #include -using namespace clover; +using clover::module; using namespace clover::llvm; namespace { diff --git a/src/gallium/frontends/clover/llvm/codegen/common.cpp b/src/gallium/frontends/clover/llvm/codegen/common.cpp index cb2a9f6..989d0f3 100644 --- a/src/gallium/frontends/clover/llvm/codegen/common.cpp +++ b/src/gallium/frontends/clover/llvm/codegen/common.cpp @@ -30,6 +30,8 @@ /// understood by pipe drivers. /// +#include + #include "llvm/codegen.hpp" #include "llvm/metadata.hpp" @@ -40,7 +42,8 @@ #include -using namespace clover; +using clover::module; +using clover::detokenize; using namespace clover::llvm; using ::llvm::Module; @@ -69,7 +72,7 @@ namespace { module::arg_info create_arg_info(const std::string &arg_name, const std::string &type_name, const std::string &type_qualifier, - const int address_qualifier, + const uint64_t address_qualifier, const std::string &access_qualifier) { cl_kernel_arg_type_qualifier cl_type_qualifier = diff --git a/src/gallium/frontends/clover/llvm/codegen/native.cpp b/src/gallium/frontends/clover/llvm/codegen/native.cpp index dbd7a0c..683e966 100644 --- a/src/gallium/frontends/clover/llvm/codegen/native.cpp +++ b/src/gallium/frontends/clover/llvm/codegen/native.cpp @@ -27,16 +27,17 @@ /// executable code as an ELF object file. /// +#include +#include +#include + #include "llvm/codegen.hpp" #include "llvm/compat.hpp" #include "llvm/util.hpp" #include "core/error.hpp" -#include -#include -#include - -using namespace clover; +using clover::module; +using clover::build_error; using namespace clover::llvm; using ::llvm::TargetMachine; diff --git a/src/gallium/frontends/clover/llvm/invocation.cpp b/src/gallium/frontends/clover/llvm/invocation.cpp index ef0c31c..fe7dfdb 100644 --- a/src/gallium/frontends/clover/llvm/invocation.cpp +++ b/src/gallium/frontends/clover/llvm/invocation.cpp @@ -60,7 +60,12 @@ #include "util/algorithm.hpp" -using namespace clover; +using clover::module; +using clover::device; +using clover::build_error; +using clover::invalid_build_options_error; +using clover::map; +using clover::header_map; using namespace clover::llvm; using ::llvm::Function; @@ -346,13 +351,13 @@ namespace { #ifdef HAVE_CLOVER_SPIRV SPIRV::TranslatorOpts get_spirv_translator_options(const device &dev) { - const auto supported_versions = spirv::supported_versions(); + const auto supported_versions = clover::spirv::supported_versions(); const auto maximum_spirv_version = std::min(static_cast(supported_versions.back()), SPIRV::VersionNumber::MaximumVersion); SPIRV::TranslatorOpts::ExtensionsStatusMap spirv_extensions; - for (auto &ext : spirv::supported_extensions()) { + for (auto &ext : clover::spirv::supported_extensions()) { #define EXT(X) if (ext == #X) spirv_extensions.insert({ SPIRV::ExtensionID::X, true }); #include #undef EXT diff --git a/src/gallium/frontends/clover/llvm/metadata.hpp b/src/gallium/frontends/clover/llvm/metadata.hpp index be97a00..e3e58a3 100644 --- a/src/gallium/frontends/clover/llvm/metadata.hpp +++ b/src/gallium/frontends/clover/llvm/metadata.hpp @@ -164,7 +164,7 @@ namespace clover { /// Extract the int metadata node \p name corresponding to the kernel /// argument given by \p arg. /// - inline uint + inline uint64_t get_uint_argument_metadata(const ::llvm::Function &f, const ::llvm::Argument &arg, const std::string &name) { -- 2.7.4