[all-commits] [llvm/llvm-project] 39ec9d: [clang][CodeGen] `sret` args should always point t...

Alex Voicu via All-commits all-commits at lists.llvm.org
Fri Feb 14 03:21:07 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 39ec9de7c23063b87f5c56f4e80c8d0f8b511a4b
      https://github.com/llvm/llvm-project/commit/39ec9de7c23063b87f5c56f4e80c8d0f8b511a4b
  Author: Alex Voicu <alexandru.voicu at amd.com>
  Date:   2025-02-14 (Fri, 14 Feb 2025)

  Changed paths:
    M clang/include/clang/CodeGen/CGFunctionInfo.h
    M clang/lib/CodeGen/ABIInfo.cpp
    M clang/lib/CodeGen/ABIInfo.h
    M clang/lib/CodeGen/ABIInfoImpl.cpp
    M clang/lib/CodeGen/CGCall.cpp
    M clang/lib/CodeGen/CGExprAgg.cpp
    M clang/lib/CodeGen/ItaniumCXXABI.cpp
    M clang/lib/CodeGen/MicrosoftCXXABI.cpp
    M clang/lib/CodeGen/SwiftCallingConv.cpp
    M clang/lib/CodeGen/Targets/AArch64.cpp
    M clang/lib/CodeGen/Targets/AMDGPU.cpp
    M clang/lib/CodeGen/Targets/ARC.cpp
    M clang/lib/CodeGen/Targets/ARM.cpp
    M clang/lib/CodeGen/Targets/AVR.cpp
    M clang/lib/CodeGen/Targets/BPF.cpp
    M clang/lib/CodeGen/Targets/CSKY.cpp
    M clang/lib/CodeGen/Targets/Hexagon.cpp
    M clang/lib/CodeGen/Targets/Lanai.cpp
    M clang/lib/CodeGen/Targets/LoongArch.cpp
    M clang/lib/CodeGen/Targets/Mips.cpp
    M clang/lib/CodeGen/Targets/NVPTX.cpp
    M clang/lib/CodeGen/Targets/PNaCl.cpp
    M clang/lib/CodeGen/Targets/PPC.cpp
    M clang/lib/CodeGen/Targets/RISCV.cpp
    M clang/lib/CodeGen/Targets/SPIR.cpp
    M clang/lib/CodeGen/Targets/Sparc.cpp
    M clang/lib/CodeGen/Targets/SystemZ.cpp
    M clang/lib/CodeGen/Targets/WebAssembly.cpp
    M clang/lib/CodeGen/Targets/X86.cpp
    M clang/test/CodeGen/partial-reinitialization2.c
    M clang/test/CodeGen/sret.c
    M clang/test/CodeGenCXX/no-elide-constructors.cpp
    M clang/test/CodeGenOpenCL/addr-space-struct-arg.cl
    M clang/test/CodeGenOpenCL/amdgpu-abi-struct-arg-byref.cl
    A clang/test/CodeGenOpenCL/implicit-addrspacecast-function-parameter.cl

  Log Message:
  -----------
  [clang][CodeGen] `sret` args should always point to the `alloca` AS, so use that (#114062)

`sret` arguments are always going to reside in the stack/`alloca`
address space, which makes the current formulation where their AS is
derived from the pointee somewhat quaint. This patch ensures that `sret`
ends up pointing to the `alloca` AS in IR function signatures, and also
guards agains trying to pass a casted `alloca`d pointer to a `sret` arg,
which can happen for most languages, when compiled for targets that have
a non-zero `alloca` AS (e.g. AMDGCN) / map `LangAS::default` to a
non-zero value (SPIR-V). A target could still choose to do something
different here, by e.g. overriding `classifyReturnType` behaviour.

In a broader sense, this patch extends non-aliased indirect args to also
carry an AS, which leads to changing the `getIndirect()` interface. At
the moment we're only using this for (indirect) returns, but it allows
for future handling of indirect args themselves. We default to using the
AllocaAS as that matches what Clang is currently doing, however if, in
the future, a target would opt for e.g. placing indirect returns in some
other storage, with another AS, this will require revisiting.

---------

Co-authored-by: Matt Arsenault <arsenm2 at gmail.com>
Co-authored-by: Matt Arsenault <Matthew.Arsenault at amd.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list