clover/llvm: Work around MSVC quirks
authorJesse Natalie <jenatali@microsoft.com>
Thu, 19 Nov 2020 02:34:07 +0000 (18:34 -0800)
committerJesse Natalie <jenatali@microsoft.com>
Wed, 2 Dec 2020 18:13:34 +0000 (10:13 -0800)
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 <currojerez@riseup.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7680>

src/gallium/frontends/clover/llvm/codegen/bitcode.cpp
src/gallium/frontends/clover/llvm/codegen/common.cpp
src/gallium/frontends/clover/llvm/codegen/native.cpp
src/gallium/frontends/clover/llvm/invocation.cpp
src/gallium/frontends/clover/llvm/metadata.hpp

index 413f110..8ea3e57 100644 (file)
@@ -31,6 +31,8 @@
 /// after linking against other bitcode object files.
 ///
 
+#include <llvm/Support/Allocator.h>
+
 #include "llvm/codegen.hpp"
 #include "llvm/compat.hpp"
 #include "llvm/metadata.hpp"
@@ -47,7 +49,7 @@
 #endif
 #include <llvm/Support/raw_ostream.h>
 
-using namespace clover;
+using clover::module;
 using namespace clover::llvm;
 
 namespace {
index cb2a9f6..989d0f3 100644 (file)
@@ -30,6 +30,8 @@
 /// understood by pipe drivers.
 ///
 
+#include <llvm/Support/Allocator.h>
+
 #include "llvm/codegen.hpp"
 #include "llvm/metadata.hpp"
 
@@ -40,7 +42,8 @@
 
 #include <clang/Basic/TargetInfo.h>
 
-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 =
index dbd7a0c..683e966 100644 (file)
 /// executable code as an ELF object file.
 ///
 
+#include <llvm/Target/TargetMachine.h>
+#include <llvm/Support/TargetRegistry.h>
+#include <llvm/Transforms/Utils/Cloning.h>
+
 #include "llvm/codegen.hpp"
 #include "llvm/compat.hpp"
 #include "llvm/util.hpp"
 #include "core/error.hpp"
 
-#include <llvm/Target/TargetMachine.h>
-#include <llvm/Support/TargetRegistry.h>
-#include <llvm/Transforms/Utils/Cloning.h>
-
-using namespace clover;
+using clover::module;
+using clover::build_error;
 using namespace clover::llvm;
 using ::llvm::TargetMachine;
 
index ef0c31c..fe7dfdb 100644 (file)
 #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<SPIRV::VersionNumber>(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 <LLVMSPIRVLib/LLVMSPIRVExtensions.inc>
          #undef EXT
index be97a00..e3e58a3 100644 (file)
@@ -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) {