[all-commits] [llvm/llvm-project] f05ce9: [NVPTX] Add NVPTXCtorDtorLoweringPass to handle gl...

Joseph Huber via All-commits all-commits at lists.llvm.org
Thu May 4 05:13:17 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f05ce9045af4a40232c08451cb0aef64b0e673b2
      https://github.com/llvm/llvm-project/commit/f05ce9045af4a40232c08451cb0aef64b0e673b2
  Author: Joseph Huber <jhuber6 at vols.utk.edu>
  Date:   2023-05-04 (Thu, 04 May 2023)

  Changed paths:
    M clang/lib/Driver/ToolChains/Cuda.cpp
    M clang/lib/Driver/ToolChains/Cuda.h
    M clang/test/Driver/cuda-cross-compiling.c
    M llvm/lib/Target/NVPTX/CMakeLists.txt
    M llvm/lib/Target/NVPTX/NVPTX.h
    M llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
    A llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp
    A llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.h
    M llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
    A llvm/test/CodeGen/NVPTX/lower-ctor-dtor.ll

  Log Message:
  -----------
  [NVPTX] Add NVPTXCtorDtorLoweringPass to handle global ctors / dtors

This patch mostly adapts the existing AMDGPUCtorDtorLoweringPass for use
by the Nvidia backend. This pass transforms the ctor / dtor list into a
kernel call that can be used to invoke those functinos. Furthermore, we
emit globals such that the names and addresses of these constructor
functions can be found by the driver. Unfortunately, since NVPTX has no
way to emit variables at a named section, nor a functioning linker to
provide the begin / end symbols, we need to mangle these names and have
an external application find them.

This work is related to the work in D149398 and D149340.

Reviewed By: tra

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


  Commit: 2e1c0ec6297958f73ca5ed35ce47803ea0f48dba
      https://github.com/llvm/llvm-project/commit/2e1c0ec6297958f73ca5ed35ce47803ea0f48dba
  Author: Joseph Huber <jhuber6 at vols.utk.edu>
  Date:   2023-05-04 (Thu, 04 May 2023)

  Changed paths:
    M libc/cmake/modules/LLVMLibCTestRules.cmake
    M libc/startup/gpu/nvptx/CMakeLists.txt
    M libc/startup/gpu/nvptx/start.cpp
    M libc/test/IntegrationTest/test.cpp
    M libc/test/integration/startup/gpu/CMakeLists.txt
    M libc/test/integration/startup/gpu/init_fini_array_test.cpp
    M libc/utils/gpu/loader/CMakeLists.txt
    M libc/utils/gpu/loader/nvptx/CMakeLists.txt
    M libc/utils/gpu/loader/nvptx/Loader.cpp

  Log Message:
  -----------
  [libc] Support global constructors and destructors on NVPTX

This patch adds the necessary hacks to support global constructors and
destructors. This is an incredibly hacky process caused by the primary
fact that Nvidia does not provide any binary tools and very little
linker support. We first had to emit references to these functions and
their priority in D149451. Then we dig them out of the module once it's
loaded to manually create the list that the linker should have made for
us. This patch also contains a few Nvidia specific hacks, but it passes
the test, albeit with a stack size warning from `ptxas` for the
callback. But this should be fine given the resource usage of a common
test.

This also adds a dependency on LLVM to the NVPTX loader, which hopefully doesn't
cause problems with our CUDA buildbot.

Depends on D149451

Reviewed By: tra

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


Compare: https://github.com/llvm/llvm-project/compare/909095a88048...2e1c0ec62979


More information about the All-commits mailing list