[PATCH] D69249: [Alignment] Change implementation of TargetCallingConv::OrigAlign

Guillaume Chatelet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 21 04:44:25 PDT 2019


gchatelet created this revision.
gchatelet added reviewers: t.p.northover, courbet.
Herald added subscribers: llvm-commits, kristof.beyls.
Herald added a project: LLVM.

This patch makes sure that getOrigAlign() cannot return 0.
It now stores the OrigAlign value as a Log2 instead of `Log2 - 1` (see Alignment.h `encode` and `decodeMaybeAlign`).
This change is not NFC but all the tests passes.

While reviewing the references to `TargetCallingConv::getOrigAlign` I stumbled upon this call which seems dubious:

- https://github.com/llvm/llvm-project/blob/2bf01dcbaa6723c9c41f8d6005a1f69818ddbd23/llvm/lib/Target/ARM/ARMCallingConv.cpp#L188
- https://github.com/llvm/llvm-project/blob/2bf01dcbaa6723c9c41f8d6005a1f69818ddbd23/llvm/include/llvm/CodeGen/CallingConvLower.h#L128
- https://github.com/llvm/llvm-project/blob/2bf01dcbaa6723c9c41f8d6005a1f69818ddbd23/llvm/include/llvm/CodeGen/CallingConvLower.h#L84

It looks like `getOrigAlign` (which is an alignment) is stored in `CCValAssign::Loc` (which is an offset or a Reg).
I traced it back to e95c5b3236cf <https://reviews.llvm.org/rGe95c5b3236cf43cee9f8ea793adbe9cc86f262c3> @t.p.northover do you mind havong a look?

This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69249

Files:
  llvm/include/llvm/CodeGen/TargetCallingConv.h


Index: llvm/include/llvm/CodeGen/TargetCallingConv.h
===================================================================
--- llvm/include/llvm/CodeGen/TargetCallingConv.h
+++ llvm/include/llvm/CodeGen/TargetCallingConv.h
@@ -42,7 +42,7 @@
     unsigned IsHvaStart : 1;   ///< HVA structure start
     unsigned IsSecArgPass : 1; ///< Second argument
     unsigned ByValAlign : 4;   ///< Log 2 of byval alignment
-    unsigned OrigAlign : 5;    ///< Log 2 of original alignment
+    unsigned OrigLogAlign : 5; ///< Log 2 of original alignment
     unsigned IsInConsecutiveRegsLast : 1;
     unsigned IsInConsecutiveRegs : 1;
     unsigned IsCopyElisionCandidate : 1; ///< Argument copy elision candidate
@@ -57,7 +57,7 @@
         : IsZExt(0), IsSExt(0), IsInReg(0), IsSRet(0), IsByVal(0), IsNest(0),
           IsReturned(0), IsSplit(0), IsInAlloca(0), IsSplitEnd(0),
           IsSwiftSelf(0), IsSwiftError(0), IsHva(0), IsHvaStart(0),
-          IsSecArgPass(0), ByValAlign(0), OrigAlign(0),
+          IsSecArgPass(0), ByValAlign(0), OrigLogAlign(0),
           IsInConsecutiveRegsLast(0), IsInConsecutiveRegs(0),
           IsCopyElisionCandidate(0), IsPointer(0), ByValSize(0),
           PointerAddrSpace(0) {
@@ -131,11 +131,11 @@
     }
 
     unsigned getOrigAlign() const {
-      MaybeAlign A = decodeMaybeAlign(OrigAlign);
-      return A ? A->value() : 0;
+      const Align A(1ULL << OrigLogAlign);
+      return A.value();
     }
     void setOrigAlign(Align A) {
-      OrigAlign = encode(A);
+      OrigLogAlign = Log2(A);
       assert(getOrigAlign() == A.value() && "bitfield overflow");
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69249.225854.patch
Type: text/x-patch
Size: 1615 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191021/5776fe97/attachment.bin>


More information about the llvm-commits mailing list