[cfe-dev] how to change the pointer size to 64 bits in 32bit target
Sam Elliott via cfe-dev
cfe-dev at lists.llvm.org
Mon Apr 20 04:04:01 PDT 2020
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