[PATCH] D72701: [Hexagon] Add support for Linux ABI.

Sid Manning via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 14 06:38:14 PST 2020


sidneym created this revision.
sidneym added reviewers: kparzysz, bcain, adasgupt.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

The patch adds a new option -mllvm enable-linux-abi.  The patch
primary deals with the way variable arguments are passed.

If a callee function has a variable argument list, it must perform the
following operations to set up its function prologue:

1. Determine the number of registers which could have been used for passing unnamed arguments. This can be calculated by counting the number of registers used for passing named arguments. For example, if the callee function is as follows:

  int foo(int a, ...){ ... }

  ... then register R0 is used to access the argument ' a '. The registers available for passing unnamed arguments are R1 <https://reviews.llvm.org/diffusion/L/>, R2 <https://reviews.llvm.org/source/clang-tools-extra/>, R3 <https://reviews.llvm.org/source/clang/>, R4 <https://reviews.llvm.org/source/lld/>, and R5 <https://reviews.llvm.org/source/polly/>.
2. Determine the number and size of the named arguments on the stack.
3. If the callee has named arguments on the stack, it should copy all of these arguments to a location below the current position on the stack, and the difference should be the size of the register-saved area plus padding (if any is necessary).

  The register-saved area constitutes all the registers that could have been used to pass unnamed arguments. If the number of registers forming the register-saved area is odd, it requires 4 bytes of padding; if the number is even, no padding is required. This is done to ensure an 8-byte alignment on the stack.  For example, if the callee is as follows:

  int foo(int a, ...){ ... }

  ... then the named arguments should be copied to the following location:

  current_position - 5 (for R1 <https://reviews.llvm.org/diffusion/L/>-R5) * 4 (bytes) - 4 (bytes of padding)

  If the callee is as follows:

  int foo(int a, int b, ...){ ... }

  ... then the named arguments should be copied to the following location:

  current_position - 4 (for R2 <https://reviews.llvm.org/source/clang-tools-extra/>-R5) * 4 (bytes) - 0 (bytes of padding)
4. After any named arguments have been copied, copy all the registers that could have been used to pass unnamed arguments on the stack. If the number of registers is odd, leave 4 bytes of padding and then start copying them on the stack; if the number is even, no padding is required. This constitutes the register-saved area. If padding is required, ensure that the start location of padding is 8-byte aligned.  If no padding is required, ensure that the start location of the on-stack copy of the first register which might have a variable argument is 8-byte aligned.
5. Decrement the stack pointer by the size of register saved area plus the padding.  For example, if the callee is as follows:

  int foo(int a, ...){ ... } ;

  ... then the decrement value should be the following:

  5 (for R1 <https://reviews.llvm.org/diffusion/L/>-R5) * 4 (bytes) + 4 (bytes of padding) = 24 bytes

  The decrement should be performed before the allocframe instruction. Increment the stack-pointer back by the same amount before returning from the function.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72701

Files:
  llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp
  llvm/lib/Target/Hexagon/HexagonFrameLowering.h
  llvm/lib/Target/Hexagon/HexagonISelLowering.cpp
  llvm/lib/Target/Hexagon/HexagonISelLowering.h
  llvm/lib/Target/Hexagon/HexagonMachineFunctionInfo.h
  llvm/test/CodeGen/Hexagon/vacopy.ll
  llvm/test/CodeGen/Hexagon/vararg-deallocate-sp.ll
  llvm/test/CodeGen/Hexagon/vararg-linux-abi.ll
  llvm/test/CodeGen/Hexagon/vararg.ll
  llvm/test/CodeGen/Hexagon/vararg_align_check.ll
  llvm/test/CodeGen/Hexagon/vararg_double_onstack.ll
  llvm/test/CodeGen/Hexagon/vararg_named.ll
  llvm/test/CodeGen/Hexagon/varargs-memv.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72701.237963.patch
Type: text/x-patch
Size: 64881 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200114/6e8a1984/attachment-0001.bin>


More information about the llvm-commits mailing list