[cfe-dev] 回复: how to change the pointer size to 64 bits in 32bit target

Lori Yao Yu via cfe-dev cfe-dev at lists.llvm.org
Mon Apr 20 23:50:22 PDT 2020


Hi Sam,
   After I override TargetInfo::getPointerWidthV,  `sizeof(x)`  works correctly.
   Thanks a lot!
Lori

-----邮件原件-----
发件人: Sam Elliott <selliott at lowrisc.org> 
发送时间: 2020年4月20日 19:04
收件人: Lori Yao Yu <loriyu at panyi.ai>
抄送: cfe-dev at lists.llvm.org
主题: 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 <cfe-dev at lists.llvm.org> 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
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

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



More information about the cfe-dev mailing list