clover/llvm: Use llvm::DataLayout::getABITypeAlign with LLVM >= 16

llvm::DataLayout::getABITypeAlignment is deprecated:

../src/gallium/frontends/clover/llvm/codegen/common.cpp: In function ‘std::vector<clover::binary::argument> {anonymous}::make_kernel_args(const llvm::Module&, const std::string&, const clang::CompilerInstance&)’:
../src/gallium/frontends/clover/llvm/codegen/common.cpp:211:62: warning: ‘uint64_t llvm::DataLayout::getABITypeAlignment(llvm::Type*) const’ is deprecated: use getABITypeAlign instead [-Wdeprecated-declarations]
  211 |          const unsigned target_align = dl.getABITypeAlignment(arg_type);
      |                                        ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
In file included from /usr/include/llvm/IR/Module.h:24,
                 from ../src/gallium/frontends/clover/llvm/codegen.hpp:35,
                 from ../src/gallium/frontends/clover/llvm/codegen/common.cpp:36:
/usr/include/llvm/IR/DataLayout.h:527:12: note: declared here
  527 |   uint64_t getABITypeAlignment(Type *Ty) const;
      |            ^~~~~~~~~~~~~~~~~~~
../src/gallium/frontends/clover/llvm/codegen/common.cpp:232:53: warning: ‘uint64_t llvm::DataLayout::getABITypeAlignment(llvm::Type*) const’ is deprecated: use getABITypeAlign instead [-Wdeprecated-declarations]
  232 |                               dl.getABITypeAlignment(size_type),
      |                               ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
/usr/include/llvm/IR/DataLayout.h:527:12: note: declared here
  527 |   uint64_t getABITypeAlignment(Type *Ty) const;
      |            ^~~~~~~~~~~~~~~~~~~
../src/gallium/frontends/clover/llvm/codegen/common.cpp:240:53: warning: ‘uint64_t llvm::DataLayout::getABITypeAlignment(llvm::Type*) const’ is deprecated: use getABITypeAlign instead [-Wdeprecated-declarations]
  240 |                               dl.getABITypeAlignment(size_type),
      |                               ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
/usr/include/llvm/IR/DataLayout.h:527:12: note: declared here
  527 |   uint64_t getABITypeAlignment(Type *Ty) const;
      |            ^~~~~~~~~~~~~~~~~~~
../src/gallium/frontends/clover/llvm/codegen/common.cpp:262:92: warning: ‘uint64_t llvm::DataLayout::getABITypeAlignment(llvm::Type*) const’ is deprecated: use getABITypeAlign instead [-Wdeprecated-declarations]
  262 |                                     (pointee_type->isVoidTy()) ? 8 : dl.getABITypeAlignment(pointee_type),
      |                                                                      ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/llvm/IR/DataLayout.h:527:12: note: declared here
  527 |   uint64_t getABITypeAlignment(Type *Ty) const;
      |            ^~~~~~~~~~~~~~~~~~~
../src/gallium/frontends/clover/llvm/codegen/common.cpp:304:47: warning: ‘uint64_t llvm::DataLayout::getABITypeAlignment(llvm::Type*) const’ is deprecated: use getABITypeAlign instead [-Wdeprecated-declarations]
  304 |                         dl.getABITypeAlignment(size_type),
      |                         ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
/usr/include/llvm/IR/DataLayout.h:527:12: note: declared here
  527 |   uint64_t getABITypeAlignment(Type *Ty) const;
      |            ^~~~~~~~~~~~~~~~~~~
../src/gallium/frontends/clover/llvm/codegen/common.cpp:310:47: warning: ‘uint64_t llvm::DataLayout::getABITypeAlignment(llvm::Type*) const’ is deprecated: use getABITypeAlign instead [-Wdeprecated-declarations]
  310 |                         dl.getABITypeAlignment(size_type),
      |                         ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
/usr/include/llvm/IR/DataLayout.h:527:12: note: declared here
  527 |   uint64_t getABITypeAlignment(Type *Ty) const;
      |            ^~~~~~~~~~~~~~~~~~~

v2:
* Use compat helper function (Karol Herbst)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22718>
(cherry picked from commit 4ee1572008)
This commit is contained in:
Michel Dänzer 2023-04-26 09:30:05 +02:00 committed by Eric Engestrom
parent fc4592aef5
commit 1bdaca4da9
3 changed files with 20 additions and 7 deletions

View file

@ -1507,7 +1507,7 @@
"description": "clover/llvm: Use llvm::DataLayout::getABITypeAlign with LLVM >= 16",
"nominated": false,
"nomination_type": null,
"resolution": 4,
"resolution": 1,
"main_sha": null,
"because_sha": null
},

View file

@ -34,6 +34,7 @@
#include <llvm/Support/Allocator.h>
#include "llvm/codegen.hpp"
#include "llvm/compat.hpp"
#include "llvm/metadata.hpp"
#include "CL/cl.h"
@ -197,6 +198,7 @@ namespace {
::llvm::DataLayout dl(&mod);
const auto size_type =
dl.getSmallestLegalIntType(mod.getContext(), sizeof(cl_uint) * 8);
const unsigned size_align = compat::get_abi_type_alignment(dl, size_type);
for (const auto &arg : f.args()) {
const auto arg_type = arg.getType();
@ -208,7 +210,7 @@ namespace {
const unsigned arg_api_size = dl.getTypeAllocSize(arg_type);
const unsigned target_size = dl.getTypeStoreSize(arg_type);
const unsigned target_align = dl.getABITypeAlignment(arg_type);
const unsigned target_align = compat::get_abi_type_alignment(dl, arg_type);
const auto type_name = get_str_argument_metadata(f, arg,
"kernel_arg_type");
@ -229,7 +231,7 @@ namespace {
// Image size implicit argument.
args.emplace_back(binary::argument::scalar, sizeof(cl_uint),
dl.getTypeStoreSize(size_type),
dl.getABITypeAlignment(size_type),
size_align,
binary::argument::zero_ext,
binary::argument::image_size);
@ -237,7 +239,7 @@ namespace {
// Image format implicit argument.
args.emplace_back(binary::argument::scalar, sizeof(cl_uint),
dl.getTypeStoreSize(size_type),
dl.getABITypeAlignment(size_type),
size_align,
binary::argument::zero_ext,
binary::argument::image_format);
@ -259,7 +261,8 @@ namespace {
args.emplace_back(binary::argument::local, arg_api_size,
target_size,
(pointee_type->isVoidTy()) ? 8 : dl.getABITypeAlignment(pointee_type),
(pointee_type->isVoidTy()) ? 8 :
compat::get_abi_type_alignment(dl, pointee_type),
binary::argument::zero_ext);
} else {
// XXX: Correctly handle constant address space. There is no
@ -301,13 +304,13 @@ namespace {
// target according to the selected calling convention.
args.emplace_back(binary::argument::scalar, sizeof(cl_uint),
dl.getTypeStoreSize(size_type),
dl.getABITypeAlignment(size_type),
size_align,
binary::argument::zero_ext,
binary::argument::grid_dimension);
args.emplace_back(binary::argument::scalar, sizeof(cl_uint),
dl.getTypeStoreSize(size_type),
dl.getABITypeAlignment(size_type),
size_align,
binary::argument::zero_ext,
binary::argument::grid_offset);

View file

@ -101,6 +101,16 @@ namespace clover {
d);
}
static inline unsigned
get_abi_type_alignment(::llvm::DataLayout dl, ::llvm::Type *type)
{
#if LLVM_VERSION_MAJOR >= 16
return dl.getABITypeAlign(type).value();
#else
return dl.getABITypeAlignment(type);
#endif
}
static inline bool
is_scalable_vector(const ::llvm::Type *type)
{