[PATCH] D91050: [NFC] Add the EmitTargetCodeForConstantPool hook for target to customize it with MachineConstantPoolValue

Qing Shan Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 5 21:49:46 PST 2021


steven.zhang added a comment.

- **Reason why we need to change the interface**

  I want to put the constants with the same  type and alignment into the same constant pool(ConstantPoolSDNode) to reduce the TOC and improve the access performance.  See the description in D91053 <https://reviews.llvm.org/D91053> if you're interested in the detail. So, when we are trying to create the constant pool in DAG(DAG.getConstantPool), what it returns is the `ADD ConstantPoolSDNode, Offset`. And when emitting the ConstantPoolSDNode, we will have something like this(One TOC entry for 4 constants in this example):

  .LCPI0_0:
          .quad   0x402cc28f5c28f5c3              # double 14.380000000000001
          .quad   0x4002b851eb851eb8              # double 2.3399999999999999
          .quad   0x40120c49ba5e353f              # double 4.5119999999999996
          .quad   0x3ff3ae147ae147ae              # double 1.23
  
  .LC0:
          .tc .LCPI0_0[TC],.LCPI0_0

As the return of DAG.getConstantPool() is NOT ConstantPoolSDNode anymore(It is shared ConstantPoolSDNode + Offset), we cannot get the alignment by casting the return value of DAG.getConstantPool() to ConstantPoolSDNode.

- **Reason why we change the interface that way**

  The semantic of the interface of getConstantPool is that, if we specify the alignment, use it, otherwise, it will calculate the alignment for you.  You have to get the alignment from the result of DAG.getConstantPool() if it is calculated internal which shows as follows:

  SDValue SelectionDAG::getConstantPool(const Constant *C, EVT VT,
                                        MaybeAlign Alignment, int Offset,
                                        bool isTarget, unsigned TargetFlags) {
    assert((TargetFlags == 0 || isTarget) &&
           "Cannot set target flags on target-independent globals");
    if (!Alignment)
      Alignment = shouldOptForSize()
                      ? getDataLayout().getABITypeAlign(C->getType())
                      : getDataLayout().getPrefTypeAlign(C->getType());

So, I added a new parameter NewAlign to tell us what the final alignment constant pool has instead of casting from the return value that assume that, the return value must be ConstantPoolSDNode:

  SDValue getConstantPool(const Constant *C, EVT VT, MaybeAlign Alignment, Align &NewAlign, ...)

`DAG.getConstantPool(C, VT, None, NewAlign,...)` means you don't have preference on the alignment and we will calculate it for you.
`DAG.getConstantPool(C, VT, Align, NewAlign,...)` means you have the alignment preference, but the final alignment is still set in NewAlign and they can be difference technical speaking. (i.e. you want the 4 byte aligned constant pool, we can still return the 8 byte aligned constant pool to share with it on PowerPC)

This is the way I am proposing and I am open and welcome for any suggestion. Thank you for all the comments and happy new year :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91050/new/

https://reviews.llvm.org/D91050



More information about the llvm-commits mailing list