[PATCH] D71551: [AIX][XCOFF]Implement mergeable const

Digger via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 2 07:35:39 PST 2020


DiggerLin marked 2 inline comments as done.
DiggerLin added inline comments.


================
Comment at: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp:1870
 
+  if (Kind.isMergeableConst()) {
+    return getContext().getXCOFFSection(".rodata.cst",
----------------
hubert.reinterpretcast wrote:
> DiggerLin wrote:
> > hubert.reinterpretcast wrote:
> > > As @jasonliu mentioned, there is not much precedent for this in the context of AIX. What is the rationale for not using the normal read-only data section?
> > I implemented the Mergeable const as gcc did.  
> > 1 .gcc use a separate csect for all mergeable const. gcc generate is as 
> >   .csect _mergeableconst.ro_[RO],4
> >         .align 3
> > cnst32:
> >         .long   1073741824
> >         .long   50
> >         .space 24
> >         .globl cnst16
> >         .align 3
> > cnst16:
> >         .long   1073741824
> >         .long   22
> >         .space 8
> >         .globl cnst8
> >         .align 2
> > cnst8:
> >         .long   1073741832
> >         .space 4
> >         .globl cnst4
> >         .align 1
> > cnst4:
> >         .short  16392
> >         .space 2
> >         .csect .text[PR]
> > _section_.text:
> >         .csect .data[RW],4
> >         .long _section_.text
> > 2. xlc use separate csect const32, const16,const8, const4 for mergeable const32 ,  mergeable const16, mergeable const8. mergeable const4.
> > 
> > 
> >        .csect  cnst32{RO}, 3
> >         .long   0x40000000              # "@\0\0\0"
> >         .long   0x00000032              # "\0\0\0002"
> >         .long   0x00000000              # "\0\0\0\0"
> >         .long   0x00000000              # "\0\0\0\0"
> >         .long   0x00000000              # "\0\0\0\0"
> >         .long   0x00000000              # "\0\0\0\0"
> >         .long   0x00000000              # "\0\0\0\0"
> >         .long   0x00000000              # "\0\0\0\0"
> > 
> >         .csect  cnst16{RO}, 3
> >         .long   0x40000000              # "@\0\0\0"
> >         .long   0x00000016              # "\0\0\0\026"
> >         .long   0x00000000              # "\0\0\0\0"
> >         .long   0x00000000              # "\0\0\0\0"
> > 
> >         .csect  cnst8{RO}, 3
> >         .long   0x40000008              # "@\0\0\b"
> >         .long   0x00000000              # "\0\0\0\0"
> > 
> >         .csect  cnst4{RO}
> >         .long   0x40080000              # "@\b\0\0"
> > 
> In the assembly you list, the naming of the labels (for the GCC case) or csects (for the XL case) is suspect (they are indicative of declared variables). Declared variables are not mergeable in the general sense.
> 
> It is observed that GCC on AIX uses `.ro` and `.rw` as suffixes for read-only sections; however, the naming does not seem to indicate "mergeable" as a factor.
> 
yes,  you are correct, the for gcc and xlc in the aix , I used the source code as

typedef struct {
 unsigned long long  id;
 unsigned int  option1;
 unsigned long long option2;
 unsigned int option3;
} Merge_cnst32;

typedef struct {
 unsigned long long  id;
 unsigned int options;
} Merge_cnst16;

typedef struct {
 unsigned int id;
 unsigned int  options;
} Merge_cnst8;

typedef struct {
 unsigned short id;
 unsigned char  options;
} Merge_cnst4;

//int main() {   
 Merge_cnst32 const cnst32 = { .id = 0x4000000000000032ULL };
 Merge_cnst16 const cnst16 = { .id = 0x4000000000000016ULL };
 Merge_cnst8 const cnst8  = { .id = 0x40000008 };
 Merge_cnst4 const cnst4  = { .id = 0x4008 };
//} 

if I uncomment the int main() {  , gcc and xlc will not generate any csect for the cnst32 ,cnst16,cnst8. cnst32  or they also do not put the value in any csect. it put the value in the text asm instruction directly. 


================
Comment at: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp:1870
 
+  if (Kind.isMergeableConst()) {
+    return getContext().getXCOFFSection(".rodata.cst",
----------------
DiggerLin wrote:
> hubert.reinterpretcast wrote:
> > DiggerLin wrote:
> > > hubert.reinterpretcast wrote:
> > > > As @jasonliu mentioned, there is not much precedent for this in the context of AIX. What is the rationale for not using the normal read-only data section?
> > > I implemented the Mergeable const as gcc did.  
> > > 1 .gcc use a separate csect for all mergeable const. gcc generate is as 
> > >   .csect _mergeableconst.ro_[RO],4
> > >         .align 3
> > > cnst32:
> > >         .long   1073741824
> > >         .long   50
> > >         .space 24
> > >         .globl cnst16
> > >         .align 3
> > > cnst16:
> > >         .long   1073741824
> > >         .long   22
> > >         .space 8
> > >         .globl cnst8
> > >         .align 2
> > > cnst8:
> > >         .long   1073741832
> > >         .space 4
> > >         .globl cnst4
> > >         .align 1
> > > cnst4:
> > >         .short  16392
> > >         .space 2
> > >         .csect .text[PR]
> > > _section_.text:
> > >         .csect .data[RW],4
> > >         .long _section_.text
> > > 2. xlc use separate csect const32, const16,const8, const4 for mergeable const32 ,  mergeable const16, mergeable const8. mergeable const4.
> > > 
> > > 
> > >        .csect  cnst32{RO}, 3
> > >         .long   0x40000000              # "@\0\0\0"
> > >         .long   0x00000032              # "\0\0\0002"
> > >         .long   0x00000000              # "\0\0\0\0"
> > >         .long   0x00000000              # "\0\0\0\0"
> > >         .long   0x00000000              # "\0\0\0\0"
> > >         .long   0x00000000              # "\0\0\0\0"
> > >         .long   0x00000000              # "\0\0\0\0"
> > >         .long   0x00000000              # "\0\0\0\0"
> > > 
> > >         .csect  cnst16{RO}, 3
> > >         .long   0x40000000              # "@\0\0\0"
> > >         .long   0x00000016              # "\0\0\0\026"
> > >         .long   0x00000000              # "\0\0\0\0"
> > >         .long   0x00000000              # "\0\0\0\0"
> > > 
> > >         .csect  cnst8{RO}, 3
> > >         .long   0x40000008              # "@\0\0\b"
> > >         .long   0x00000000              # "\0\0\0\0"
> > > 
> > >         .csect  cnst4{RO}
> > >         .long   0x40080000              # "@\b\0\0"
> > > 
> > In the assembly you list, the naming of the labels (for the GCC case) or csects (for the XL case) is suspect (they are indicative of declared variables). Declared variables are not mergeable in the general sense.
> > 
> > It is observed that GCC on AIX uses `.ro` and `.rw` as suffixes for read-only sections; however, the naming does not seem to indicate "mergeable" as a factor.
> > 
> yes,  you are correct, the for gcc and xlc in the aix , I used the source code as
> 
> typedef struct {
>  unsigned long long  id;
>  unsigned int  option1;
>  unsigned long long option2;
>  unsigned int option3;
> } Merge_cnst32;
> 
> typedef struct {
>  unsigned long long  id;
>  unsigned int options;
> } Merge_cnst16;
> 
> typedef struct {
>  unsigned int id;
>  unsigned int  options;
> } Merge_cnst8;
> 
> typedef struct {
>  unsigned short id;
>  unsigned char  options;
> } Merge_cnst4;
> 
> //int main() {   
>  Merge_cnst32 const cnst32 = { .id = 0x4000000000000032ULL };
>  Merge_cnst16 const cnst16 = { .id = 0x4000000000000016ULL };
>  Merge_cnst8 const cnst8  = { .id = 0x40000008 };
>  Merge_cnst4 const cnst4  = { .id = 0x4008 };
> //} 
> 
> if I uncomment the int main() {  , gcc and xlc will not generate any csect for the cnst32 ,cnst16,cnst8. cnst32  or they also do not put the value in any csect. it put the value in the text asm instruction directly. 
and in the linux , the llvm put the mergeabe const in the readonly  as 

        .csect .rodata.cst[RO]
        .align  4
.L__const.main.cnst32:
        .llong  4611686018427387954     # 0x4000000000000032
        .long   0                       # 0x0
        .space  4
        .llong  0                       # 0x0
        .long   0                       # 0x0
        .space  4
        .align  3
.L__const.main.cnst16:
        .llong  4611686018427387926     # 0x4000000000000016
        .long   0                       # 0x0
        .space  4
        .align  3
.L__const.main.cnst8:
        .long   1073741832              # 0x40000008
        .long   0                       # 0x0
        .align  3
.L__const.main.cnst4:
        .short  16392                   # 0x4008
        .byte   0                       # 0x0
        .space  1
        
it also  put the merge const in the a new .csect .rodata.cst[RO] . 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71551





More information about the llvm-commits mailing list