[PATCH] D136043: [CodeGen] Replace CCValAssign::Loc with a discriminated union (NFCI)

Sergei Barannikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 16 11:18:04 PDT 2022


barannikov88 created this revision.
Herald added subscribers: jrtc27, fedor.sergeev, hiraditya, jyknight.
Herald added a project: All.
barannikov88 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The motivation behind this change is as follows.
Targets with stack growing up (there are no such in-tree targets) pass
arguments at negative offsets relative to the stack pointer. This makes
it hard to use the generic value assigner because CCValAssign stores the
offset as an unsigned integer, which is then zero-extended when
converted to int64_t, e.g. when passing to `CreateFixedObject`. This
results in conversion of, for example, -4 into 4294967292, which is not
desired.

While it is possible to insert a cast to `int` before passing the result
of `getLocMemOffset` into `CreateFixedObject` in backend code, this is
error-prone, and some uses of `getLocMemOffset` are located in
places common to all backends (e.g. `CallLowering::handleAssignments`).

That said, I wanted to change the type of the memory offset from
`unsigned` to `int64_t` (this would be consistent with other places
where stack offsets are used). However, the `Loc` field which stores the
offset is shared between three different kinds of the location:
register, memory, and "pending". Storing a register number as `int64_t`
does not seem right (there are `Register` and `MCRegister` for this), so
I did the most straightforward change - replaced the `Loc` field with a
discriminated union.

The main change that changes the type of the memory offset from
`unsigned` to `int64_t` will be in a follow-up patch to simplify the
review.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136043

Files:
  llvm/include/llvm/CodeGen/CallingConvLower.h
  llvm/lib/CodeGen/CallingConvLower.cpp
  llvm/lib/Target/Sparc/SparcISelLowering.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136043.468087.patch
Type: text/x-patch
Size: 10038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221016/b23fa62d/attachment.bin>


More information about the llvm-commits mailing list