[PATCH] D73290: [PowerPC] Add clang -msvr4-struct-return for 32-bit ELF

George Koehler via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 23 13:24:33 PST 2020


kernigh created this revision.
kernigh added reviewers: brad, markmi, chmeee.
kernigh added a project: clang.
Herald added subscribers: cfe-commits, steven.zhang, shchenz, jsji, kbarton, krytarowski, arichardson, nemanjai, emaste.

This is a patch for https://bugs.llvm.org/show_bug.cgi?id=40736

**Beware:** This diff passes its own tests, and writes asm that looks correct to me, but I have not yet tried running the code on PowerPC. I intend to backport the diff to llvm/clang 8.0.1 (the version in OpenBSD), and try it on an old and slow PowerPC Macintosh. I upload the diff now, because other people might want to see it.

This is only my 2nd patch on reviews.llvm.org, so I might have filled some fields wrong. I don't have commit access to LLVM.

[PowerPC] Add clang -msvr4-struct-return for 32-bit ELF

Change the default ABI to be compatible with GCC.  For 32-bit ELF targets other than Linux, Clang now returns small structs in registers r3/r4.  This affects FreeBSD, NetBSD, OpenBSD.  There is no change for 32-bit Linux, where Clang continues to return all structs in memory.

Add clang options -maix-struct-return (to return structs in memory) and -msvr4-struct-return (to return structs in registers) to be compatible with gcc.  These options are only for PPC32; reject them on PPC64 and other targets.  The options are like -fpcc-struct-return and -freg-struct-return for X86_32, and use similar code.

To actually return a struct in registers, coerce it to an integer of the same size.  LLVM may optimize the code to remove unnecessary accesses to memory, and will return i32 in r3 or i64 in r3:r4.

Fixes PR#40736


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73290

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/ppc32-struct-return.c
  clang/test/Driver/ppc-unsupported.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73290.239982.patch
Type: text/x-patch
Size: 12882 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200123/f5172922/attachment.bin>


More information about the cfe-commits mailing list