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 <currojerez@riseup.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7680>
This commit is contained in:
Jesse Natalie 2020-11-18 18:34:07 -08:00
parent 149a036825
commit 4cfd57dd48
5 changed files with 23 additions and 12 deletions

View 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 {

View 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 =

View File

@ -27,16 +27,17 @@
/// 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;

View File

@ -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<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

View 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) {