Hi, LLVM only support primitive type i32 and i64, no i48. The clang translate "C int type" to i32 too. My question is if a cpu is 48 bits register size, how to write the backend for 48 bits register architecture. Can someone help me with this problem? Jonathan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130905/87c66095/attachment.html>
On Sep 5, 2013, at 3:37 AM, gamma_chen <gamma_chen at yahoo.com.tw> wrote:> LLVM only support primitive type i32 and i64, no i48. The clang translate "C int type" to i32 too. My question is if a cpu is 48 bits register size, how to write the backend for 48 bits register architecture. Can someone help me with this problem?I'm not LLVM expert, but I'm pretty sure your initial sentence is false. For example: steve$ cat a.ll ; ModuleID = 'a.c' target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.8.0" define i48 @foo() nounwind uwtable ssp { ret i48 3 } steve$ clang -S a.ll steve$ cat a.s .section __TEXT,__text,regular,pure_instructions .globl _foo .align 4, 0x90 _foo: ## @foo .cfi_startproc ## BB#0: pushq %rbp Ltmp2: .cfi_def_cfa_offset 16 Ltmp3: .cfi_offset %rbp, -16 movq %rsp, %rbp Ltmp4: .cfi_def_cfa_register %rbp movl $3, %eax popq %rbp ret .cfi_endproc .subsections_via_symbols As you can see, i48 was a perfectly valid LLVM type. Without having written a backend, I'd imagine you specify what types are legal and then either generic code or target-dependent code is going to legalize the type. In my example, I imagine the i48 was legalized to an i64 which is legal for my target architecture. -- Stephen Checkoway
Hi Jonathan> As you can see, i48 was a perfectly valid LLVM type. > > Without having written a backend, I'd imagine you specify what > types are legal and then either generic code or target-dependent > code is going to legalize the type. In my example, I imagine the > i48 was legalized to an i64 which is legal for my target architecture.Only certain types can be legal in a normal backend, everything gets mapped to the MVT enum. Currently the only backend integer types allowed are i1, i8, i16, i32, i64 and i128. To support i48 properly you'd have to add it to that list of types. Running a "grep -r i128" should give you a very rough indication of what's involved. Less than I expected, actually. There are three possible outcomes after doing that: 1. Everything works perfectly. 2. Code expects power-of-2 widths and breaks when your backend starts feeding it i48 (in particular it may expect to be able to reach a legal type by doubling or halving the width repeatedly) 3. Code expects power-of-2 widths and every existing backend breaks horribly because of this new i48. I'd hope for 2, but fear 3. Clang should be flexible about what int maps to, though. MSP430, for example, uses i16. Of course, you shouldn't be surprised if there are extra bugs to deal with there too. Cheers. Tim.
Stephen, Thank you. The llvm IR accept the i48 but it will fail if I use i48 as data type in *.td file. Do you know how to add i48 type in *.td, or it is not allowed. The other question is "Is it possible to make clang compiler generate i48 for "C int type varialbe?". If you don't know the answer of this clang question I will post it on clang development list. Best regards Jonathan ________________________________ 寄件者: Stephen Checkoway <s at pahtak.org> 收件者: gamma_chen <gamma_chen at yahoo.com.tw> 副本: "llvmdev at cs.uiuc.edu" <llvmdev at cs.uiuc.edu>; Vijay Daultani <vijay.daultani at gmail.com> 寄件日期: 2013/9/5 (週四) 3:59 PM 主旨: Re: [LLVMdev] C int type for 48bits cpu On Sep 5, 2013, at 3:37 AM, gamma_chen <gamma_chen at yahoo.com.tw> wrote:> LLVM only support primitive type i32 and i64, no i48. The clang translate "C int type" to i32 too. My question is if a cpu is 48 bits register size, how to write the backend for 48 bits register architecture. Can someone help me with this problem?I'm not LLVM expert, but I'm pretty sure your initial sentence is false. For example: steve$ cat a.ll ; ModuleID = 'a.c' target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.8.0" define i48 @foo() nounwind uwtable ssp { ret i48 3 } steve$ clang -S a.ll steve$ cat a.s .section __TEXT,__text,regular,pure_instructions .globl _foo .align 4, 0x90 _foo: ## @foo .cfi_startproc ## BB#0: pushq %rbp Ltmp2: .cfi_def_cfa_offset 16 Ltmp3: .cfi_offset %rbp, -16 movq %rsp, %rbp Ltmp4: .cfi_def_cfa_register %rbp movl $3, %eax popq %rbp ret .cfi_endproc .subsections_via_symbols As you can see, i48 was a perfectly valid LLVM type. Without having written a backend, I'd imagine you specify what types are legal and then either generic code or target-dependent code is going to legalize the type. In my example, I imagine the i48 was legalized to an i64 which is legal for my target architecture. -- Stephen Checkoway -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130905/0de5e8a2/attachment.html>
Hi Jonathan,> LLVM only support primitive type i32 and i64, no i48. The clang translate "C int > type" to i32 too. My question is if a cpu is 48 bits register size, how to write > the backend for 48 bits register architecture. Can someone help me with this > problem?the type legalizer expects legal integer types to have a power of 2 size. For someone who knows what they are doing it wouldn't be too hard to generalize this to allow arbitrary sizes, such as 48, but unfortunately no-one did this yet. Ciao, Duncan.