how to change the pointer size to 64 bits in 32bit target

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

how to change the pointer size to 64 bits in 32bit target

Fangrui Song via cfe-dev

Hi all developers,

I’m currently working on a RISCV target with two address mode, 32 bit and 64 bit.  And all the registers are 32bits.

    The first thing I dose was changing the data layout of this target. So  I change the data layout string to "e-m:e-p:64:64-p1:64:32-i64:64-n32-S128" in clang/lib/Basic/Targets/RISCV.h and llvm/lib/TargetRISCV/RISCVTargteMachine.cpp.

 

    But I found that not work as expected, following is my test code:

 

    C language:

 

    int func() {

   return sizeof(int*);

}

    

 

    the IR code is :

 

    target datalayout = e-m:e-p:64:64-p1:64:32-i64:64-n32-S128

    target triple = riscv32-unkown-unkown-elf

     define dso_ocal i32 @func() local_unnamed_addr #0 {

entry:

   ret i32 4

}

 

     I see that the size of int* is 4 bytes, it is 32bits, not 64 bits as expected.

     

      Can you tell me if I am wrong in somewhere, or the way to change the pointer size correctly.

 

      Thank you all for your time and any help you can provide.

Lori


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: how to change the pointer size to 64 bits in 32bit target

Fangrui Song via cfe-dev
Clang evaluates `sizeof(x)` before it generates LLVM IR, as I think you can tell.

Look at the classes in `clang/lib/Basic/Targets/RISCV.h`. In particular, there are lots of variables in the `TargetInfo` class which give these sizes. You want to override `PointerWidth` (and also some others, in all likelihood). Look at the initializer for RISCV64TargetInfo.

Sam

> On 20 Apr 2020, at 6:32 am, Lori Yao Yu via cfe-dev <[hidden email]> wrote:
>
> Hi all developers,
> I’m currently working on a RISCV target with two address mode, 32 bit and 64 bit.  And all the registers are 32bits.
>     The first thing I dose was changing the data layout of this target. So  I change the data layout string to "e-m:e-p:64:64-p1:64:32-i64:64-n32-S128" in clang/lib/Basic/Targets/RISCV.h and llvm/lib/TargetRISCV/RISCVTargteMachine.cpp.
>  
>     But I found that not work as expected, following is my test code:
>  
>     C language:
>  
>     int func() {
>    return sizeof(int*);
> }
>    
>  
>     the IR code is :
>  
>     target datalayout = “e-m:e-p:64:64-p1:64:32-i64:64-n32-S128”
>     target triple = “riscv32-unkown-unkown-elf”
>      define dso_ocal i32 @func() local_unnamed_addr #0 {
> entry:
>    ret i32 4
> }
>  
>      I see that the size of int* is 4 bytes, it is 32bits, not 64 bits as expected.
>      
>       Can you tell me if I am wrong in somewhere, or the way to change the pointer size correctly.
>  
>       Thank you all for your time and any help you can provide.
> Lori
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

--
Sam Elliott
Software Team Lead
Senior Software Developer - LLVM and OpenTitan
lowRISC CIC

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

回复: how to change the pointer size to 64 bits in 32bit target

Fangrui Song via cfe-dev
Hi Sam,
   After I override TargetInfo::getPointerWidthV,  `sizeof(x)`  works correctly.
   Thanks a lot!
Lori

-----邮件原件-----
发件人: Sam Elliott <[hidden email]>
发送时间: 2020年4月20日 19:04
收件人: Lori Yao Yu <[hidden email]>
抄送: [hidden email]
主题: Re: [cfe-dev] how to change the pointer size to 64 bits in 32bit target

Clang evaluates `sizeof(x)` before it generates LLVM IR, as I think you can tell.

Look at the classes in `clang/lib/Basic/Targets/RISCV.h`. In particular, there are lots of variables in the `TargetInfo` class which give these sizes. You want to override `PointerWidth` (and also some others, in all likelihood). Look at the initializer for RISCV64TargetInfo.

Sam

> On 20 Apr 2020, at 6:32 am, Lori Yao Yu via cfe-dev <[hidden email]> wrote:
>
> Hi all developers,
> I’m currently working on a RISCV target with two address mode, 32 bit and 64 bit.  And all the registers are 32bits.
>     The first thing I dose was changing the data layout of this target. So  I change the data layout string to "e-m:e-p:64:64-p1:64:32-i64:64-n32-S128" in clang/lib/Basic/Targets/RISCV.h and llvm/lib/TargetRISCV/RISCVTargteMachine.cpp.
>  
>     But I found that not work as expected, following is my test code:
>  
>     C language:
>  
>     int func() {
>    return sizeof(int*);
> }
>    
>  
>     the IR code is :
>  
>     target datalayout = “e-m:e-p:64:64-p1:64:32-i64:64-n32-S128”
>     target triple = “riscv32-unkown-unkown-elf”
>      define dso_ocal i32 @func() local_unnamed_addr #0 {
> entry:
>    ret i32 4
> }
>  
>      I see that the size of int* is 4 bytes, it is 32bits, not 64 bits as expected.
>      
>       Can you tell me if I am wrong in somewhere, or the way to change the pointer size correctly.
>  
>       Thank you all for your time and any help you can provide.
> Lori
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

--
Sam Elliott
Software Team Lead
Senior Software Developer - LLVM and OpenTitan lowRISC CIC

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev