如何告诉 clang 我的 LLVM 目标应该使用 16 位“int”?

2024-01-11

对于我的 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)"}

这可能是也可能不是“返回操作数 #1 具有未处理的类型 i16“我在中描述的消息PIC后端:16位寄存器/返回类型 https://stackoverflow.com/questions/39456108/pic-backend-16-bit-registers-return-type。然而,在转向其他问题之前,我可能应该正确地获取 clang 输出中使用的类型。


已解决:clang 从其自己的目标中获取 int (和其他类型)的大小,该目标在 clang/lib/Basics/Targets.cpp 中定义。本机大小设置“-n16”不足以覆盖(默认?)i32 设置。反而:

IntWidth = 32;
IntAlign = 32;

在我的目标的构造函数中可以解决这个问题。

这也解决了奇怪的“未处理的返回类型 i16”问题。不知道为什么。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何告诉 clang 我的 LLVM 目标应该使用 16 位“int”? 的相关文章

随机推荐