如果位代码是由clang生成的,则使用llvm helloworld过程不会给出任何输出
我对llvm/clang非常陌生,并尝试使用新的过程管理器编写自定义llvm过程 我的第一步是使用文档中的HelloWorld过程: 当我使用文档中的文件a.ll和命令如果位代码是由clang生成的,则使用llvm helloworld过程不会给出任何输出,clang,llvm,Clang,Llvm,我对llvm/clang非常陌生,并尝试使用新的过程管理器编写自定义llvm过程 我的第一步是使用文档中的HelloWorld过程: 当我使用文档中的文件a.ll和命令/bin/opt a.ll-passs=helloworld-S foo bar ; ModuleID = 'a.ll' source_filename = "a.ll" define i32 @foo() { %a = add i32 2, 3 ret i32 %a } define void @ba
/bin/opt a.ll-passs=helloworld-S
foo
bar
; ModuleID = 'a.ll'
source_filename = "a.ll"
define i32 @foo() {
%a = add i32 2, 3
ret i32 %a
}
define void @bar() {
ret void
}
现在我有了一个C文件a2.C,其中包含:
void test(){
}
并使用/bin/clang-S-emit llvm a2.c
在a2.ll上运行上一个opt命令
; ModuleID = 'a2.ll'
source_filename = "a2.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; Function Attrs: noinline nounwind optnone uwtable
define dso_local void @test() #0 {
entry:
ret void
}
attributes #0 = { noinline nounwind optnone uwtable "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
!llvm.module.flags = !{!0}
!llvm.ident = !{!1}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 13.0.0 (https://github.com/llvm/llvm-project.git 8e7df996e3054cc174b91bc103057747c8349c06)"}
我无法在文件开头看到预期的“测试”
我的考试有什么问题吗?
谢谢你的帮助
[编辑]在clang命令中使用optim flags-O1或更多可以解决这个问题,但我不明白为什么使用-O0的clang会添加
optnone
属性,该属性会禁用任何通过转换传递的IR的进一步处理。为了获得我想要的bahaviour,我需要在clang编译行中添加-Xclang-disable-O0-optnone。谢谢你,安东,你的回答帮助我找到了答案。