对于我的 PIC 后端,我希望“int”为 16 位。我/我的目标如何告诉 clang 'int' 的大小应该是多少?仅定义 16 位寄存器似乎是不够的。
当前“clang -O2 -emit-llvm -target pic”转换
int foo(int a, int b) { return a + b; }
此 IR 代码,使用 32 位整数:
; 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)"}
这可能是也可能不是我在 PIC Backend: 16-bit registers / return type 中描述的“Return operand #1 has unhandled type i16”消息的原因。但是,在转向其他问题之前,我可能应该正确使用 clang 输出中使用的类型。
最佳答案
已解决:clang 从其自己的 Target 中获取 int(和其他类型)的大小,该 Target 在 clang/lib/Basics/Targets.cpp 中定义。 native 大小设置“-n16”不足以覆盖(默认?)i32 设置。相反:
IntWidth = 32;
IntAlign = 32;
在我的目标的构造函数中就可以了。
这也解决了奇怪的“未处理的返回类型 i16”问题。不知道为什么。
关于clang - 如何告诉 clang 我的 LLVM 目标应该使用 16 位 'int'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39524994/