[all-commits] [llvm/llvm-project] 985757: [CUDA][HIP] Fix device template variables

Yaxun (Sam) Liu via All-commits all-commits at lists.llvm.org
Wed May 12 08:14:36 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 98575708da9544ccab8939fece9c3d638a32f09f
      https://github.com/llvm/llvm-project/commit/98575708da9544ccab8939fece9c3d638a32f09f
  Author: Yaxun (Sam) Liu <yaxun.liu at amd.com>
  Date:   2021-05-12 (Wed, 12 May 2021)

  Changed paths:
    M clang/include/clang/AST/ASTContext.h
    M clang/lib/AST/ASTContext.cpp
    M clang/lib/CodeGen/CGCUDANV.cpp
    M clang/lib/CodeGen/CodeGenModule.cpp
    M clang/lib/Sema/SemaExpr.cpp
    M clang/test/CodeGenCUDA/device-stub.cu
    M clang/test/CodeGenCUDA/host-used-device-var.cu
    M clang/test/CodeGenCUDA/static-device-var-no-rdc.cu
    M clang/test/CodeGenCUDA/static-device-var-rdc.cu

  Log Message:
  -----------
  [CUDA][HIP] Fix device template variables

Currently clang does not emit device template variables
instantiated only in host functions, however, nvcc is
able to do that:

https://godbolt.org/z/fneEfferY

This patch fixes this issue by refactoring and extending
the existing mechanism for emitting static device
var ODR-used by host only. Basically clang records
device variables ODR-used by host code and force
them to be emitted in device compilation. The existing
mechanism makes sure these device variables ODR-used
by host code are added to llvm.compiler-used, therefore
they are guaranteed not to be deleted.

It also fixes non-ODR-use of static device variable by host code
causing static device variable to be emitted and registered,
which should not.

Reviewed by: Artem Belevich

Differential Revision: https://reviews.llvm.org/D102237




More information about the All-commits mailing list