如何告诉clang我的LLVM目标应该使用16位'int'? [英] How to tell clang that my LLVM Target should use 16-bit 'int'?
问题描述
对于我的PIC后端,我想要'int'为16位。我如何/我的目标告诉ang什么应该是'int'的大小?定义16位寄存器似乎不够。
For my PIC Backend, I want 'int' to be 16 bits. How can I / my target tell clang what should be the size of 'int'? Defining 16-bit registers only seems not sufficient.
目前clang -O2 -emit-llvm -target pic转换
Currently "clang -O2 -emit-llvm -target pic" converts
int foo(int a, int b) { return a + b; }
到此IR代码,使用32位整数:
to this IR code, using 32-bit integers:
; ModuleID = '../test/sum.c'
source_filename = "../test/sum.c"
target datalayout = "e-m:e-p:16:16-i16:16-a:0:16-n16-S16"
target triple = "pic"
; Function Attrs: norecurse nounwind readnone
define i32 @foo(i32 %a, i32 %b) local_unnamed_addr #0 {
entry:
%add = add nsw i32 %b, %a
ret i32 %add
}
attributes #0 = { norecurse nounwind readnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
!llvm.ident = !{!0}
!0 = !{!"clang version 4.0.0 (http://llvm.org/git/clang.git 92920e1616528c259756dd8190d4a47058fae127) (http://llvm.org/git/llvm.git 7ca31361200d6bc8a75fa06f112083a8be544287)"}
这可能是也可能不是原因返回操作数#1包含未处理类型i16 返回类型> PIC后端:16位寄存器/返回类型。但是,我应该在转向其他问题之前得到clang输出中使用的类型正确。
This may or may not be the cause of the "Return operand #1 has unhandled type i16" message I described in PIC Backend: 16-bit registers / return type. However I should probably get the type used in clang's output correct before turning to other problems.
推荐答案
SOLVED:clang占用大小int(和其他类型)从它自己的Target,在clang / lib / Basics / Targets.cpp中定义。本机大小设置-n16不足以覆盖(默认?)i32设置。而是:
SOLVED: clang takes the size of int (and other types) from its own Target, defined in clang/lib/Basics/Targets.cpp. The native size setting "-n16" is not sufficient to override the (default?) i32 setting. Instead:
IntWidth = 32;
IntAlign = 32;
在目标的构造函数中执行。
in my target's constructor does the trick.
这也解决了奇怪的未处理的返回类型i16问题。不知道为什么。
This also solves the strange 'unhandled return type i16' issue. Don't know why.
这篇关于如何告诉clang我的LLVM目标应该使用16位'int'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!