[CodeGen] Support allocating of arguments by decreasing offsets
authorSergei Barannikov <barannikov88@gmail.com>
Mon, 1 May 2023 08:56:39 +0000 (11:56 +0300)
committerSergei Barannikov <barannikov88@gmail.com>
Wed, 17 May 2023 18:51:52 +0000 (21:51 +0300)
commitda42b2846c82063bd1bce78d6a046f78f218eb72
tree7ccf5d5978d8987ad3142c830c48eeb1118d2b67
parent01a796744745d8413d0821c734caf2fbe19f2eca
[CodeGen] Support allocating of arguments by decreasing offsets

Previously, `CCState::AllocateStack` always allocated stack space by increasing
offsets. For targets with stack growing up (away from zero) it is more
convenient to allocate arguments by decreasing offsets, so that the first
argument is at the top of the stack. This is important when calling a function
with variable number of arguments: the callee does not know the size of the
stack, but must be able to access "fixed" arguments. For that to work, the
"fixed" arguments should have fixed offsets relative to the stack top, i.e. the
variadic arguments area should be at the stack bottom (at lowest addresses).

The in-tree target with stack growing up is AMDGPU, but it allocates
arguments by increasing addresses. It does not support variadic arguments.

A drive-by change is to promote stack size/offset to 64-bit integer.
This is what MachineFrameInfo expects.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D149575
llvm/include/llvm/CodeGen/CallingConvLower.h
llvm/lib/CodeGen/CallingConvLower.cpp
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
llvm/lib/Target/Sparc/SparcISelLowering.cpp
llvm/unittests/CodeGen/CCStateTest.cpp [new file with mode: 0644]
llvm/unittests/CodeGen/CMakeLists.txt
llvm/utils/TableGen/CallingConvEmitter.cpp