- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在LLVM 6.0.0版中使用C++编译器时,以下代码
bool isEven(int n) {
bool ret = true;
for (int i = 0; i < n; i ++) {
ret = !ret;
}
return ret;
}
define zeroext i1 @_Z6isEveni(i32) local_unnamed_addr #0 !dbg !7 {
call void @llvm.dbg.value(metadata i32 %0, metadata !14, metadata !DIExpression()), !dbg !18
call void @llvm.dbg.value(metadata i8 1, metadata !15, metadata !DIExpression()), !dbg !19
call void @llvm.dbg.value(metadata i32 0, metadata !16, metadata !DIExpression()), !dbg !20
%2 = icmp slt i32 %0, 1, !dbg !21
%3 = and i32 %0, 1, !dbg !23
%4 = icmp eq i32 %3, 0, !dbg !23
%5 = or i1 %4, %2, !dbg !23
ret i1 %5, !dbg !24
}
declare void @llvm.dbg.value(metadata, metadata, metadata) #1
attributes #0 = { nounwind readnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "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" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { nounwind readnone speculatable }
julia> isEven(n::Int) = rem(n, 2) != 0
isEven (generic function with 1 method)
julia> @code_llvm debuginfo=:none isEven(7)
define i8 @julia_isEven_18796(i64) {
top:
%1 = trunc i64 %0 to i8
%2 = and i8 %1, 1
%3 = xor i8 %2, 1
ret i8 %3
}
julia>
julia> function isEven(n::Int)
out = true
for i in 0:n-1
out = !out
end
return out
end
isEven (generic function with 1 method)
julia> @code_llvm debuginfo=:none isEven(7)
define i8 @julia_isEven_18793(i64) {
top:
%1 = add i64 %0, -1
%2 = icmp sgt i64 %1, -1
br i1 %2, label %L8.L12_crit_edge, label %L25
L8.L12_crit_edge: ; preds = %top
%min.iters.check = icmp ult i64 %0, 128
br i1 %min.iters.check, label %scalar.ph, label %vector.ph
vector.ph: ; preds = %L8.L12_crit_edge
%n.vec = and i64 %0, -128
br label %vector.body
vector.body: ; preds = %vector.body, %vector.ph
%index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
%vec.phi = phi <32 x i8> [ <i8 1, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0>, %vector.ph ], [ %3, %vector.body ]
%vec.phi8 = phi <32 x i8> [ zeroinitializer, %vector.ph ], [ %4, %vector.body ]
%vec.phi9 = phi <32 x i8> [ zeroinitializer, %vector.ph ], [ %5, %vector.body ]
%vec.phi10 = phi <32 x i8> [ zeroinitializer, %vector.ph ], [ %6, %vector.body ]
%3 = xor <32 x i8> %vec.phi, <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
%4 = xor <32 x i8> %vec.phi8, <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
%5 = xor <32 x i8> %vec.phi9, <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
%6 = xor <32 x i8> %vec.phi10, <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
%index.next = add i64 %index, 128
%7 = icmp eq i64 %index.next, %n.vec
br i1 %7, label %middle.block, label %vector.body
middle.block: ; preds = %vector.body
%bin.rdx = xor <32 x i8> %vec.phi8, %vec.phi
%bin.rdx14 = xor <32 x i8> %5, %bin.rdx
%bin.rdx15 = xor <32 x i8> %6, %bin.rdx14
%rdx.shuf = shufflevector <32 x i8> %bin.rdx15, <32 x i8> undef, <32 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%bin.rdx16 = xor <32 x i8> %bin.rdx15, %rdx.shuf
%rdx.shuf17 = shufflevector <32 x i8> %bin.rdx16, <32 x i8> undef, <32 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%bin.rdx18 = xor <32 x i8> %bin.rdx16, %rdx.shuf17
%rdx.shuf19 = shufflevector <32 x i8> %bin.rdx18, <32 x i8> undef, <32 x i32> <i32 4, i32 5, i32 6, i32 7, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%bin.rdx20 = xor <32 x i8> %bin.rdx18, %rdx.shuf19
%rdx.shuf21 = shufflevector <32 x i8> %bin.rdx20, <32 x i8> undef, <32 x i32> <i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%bin.rdx22 = xor <32 x i8> %bin.rdx20, %rdx.shuf21
%rdx.shuf23 = shufflevector <32 x i8> %bin.rdx22, <32 x i8> undef, <32 x i32> <i32 1, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%bin.rdx24 = xor <32 x i8> %bin.rdx22, %rdx.shuf23
%8 = extractelement <32 x i8> %bin.rdx24, i32 0
%cmp.n = icmp eq i64 %n.vec, %0
br i1 %cmp.n, label %L25, label %scalar.ph
scalar.ph: ; preds = %middle.block, %L8.L12_crit_edge
%bc.resume.val = phi i64 [ %n.vec, %middle.block ], [ 0, %L8.L12_crit_edge ]
%bc.merge.rdx = phi i8 [ %8, %middle.block ], [ 1, %L8.L12_crit_edge ]
br label %L12
L12: ; preds = %L12, %scalar.ph
%value_phi2 = phi i8 [ %bc.merge.rdx, %scalar.ph ], [ %9, %L12 ]
%value_phi3 = phi i64 [ %bc.resume.val, %scalar.ph ], [ %11, %L12 ]
%9 = xor i8 %value_phi2, 1
%10 = icmp eq i64 %value_phi3, %1
%11 = add i64 %value_phi3, 1
br i1 %10, label %L25, label %L12
L25: ; preds = %L12, %middle.block, %top
%value_phi6 = phi i8 [ 1, %top ], [ %9, %L12 ], [ %8, %middle.block ]
ret i8 %value_phi6
}
julia> versioninfo()
Julia Version 1.3.1
Commit 2d5741174c (2019-12-30 21:36 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin18.6.0)
CPU: Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
julia>
最佳答案
的简短答案是:
Julia和C++是具有不同语义和不同编译器的不同语言。
不同的语义意味着法律上的不同优化。
需要仔细检查一下这是否在C++中是合法的,而在Julia中却是非法的。
如果是的话,我会感到惊讶。
不同的编译器意味着编译器执行不同的操作。
C++编译器投入了数十年的时间,甚至可能花费了数亿美元的开发人员时间(即使其中很多是由开源志愿者捐赠的);即使是像Clang这样的较年轻的编译器,也仍然可以直接基于GCC等较老的编译器数十年久经考验的思想来构建。
Julia编译器于2012年首次启动。
花费了更少的时间。实际上,直到2017年v0.6才真正拥有自己的优化器。
LLVM确实有Julia和Clang都使用的优化器。
但是他们使用的方式不同,它们启用了不同的 channel ,并且为它们提供了不同的信息(由于语义不同)。
另外,您正在运行LLVM之前查看代码。
(因此可能要看一下程序集的instread)。
两者之间的LLVM版本是否相同,仅取决于存在的指令,而与LLVM的优化无关,因为在运行代码之前您正在查看代码。
关于julia - 当C++(LLVM)可以时,为什么Julia不优化此代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60457008/
我指的是 https://llvm.org/docs/GettingStarted.html从其源代码构建 LLVM。我正在使用 Ubuntu 18.04。 $ cmake -G Ninja -DCM
使用 ModulePass,我的目标是向上遍历 SSA 图:从一个具有 0..2 个操作数的语句(大多数操作码属于该语句)开始,我想找出两件事: 操作数是元数据/常量(简单:只需尝试转换为常量类型)还
注意:我注意到 this question与这个问题有很大关系,所以如果您对我的问题感兴趣,那么您一定要阅读另一个问题及其答案。 我可以想到一些 OOP 语言前端可以做的优化,例如创建临时变量来保存来
我正在尝试使用 clang-3.2 创建自动矢量化代码 从这里的幻灯片 - http://llvm.org/devmtg/2012-04-12/Slides/Hal_Finkel.pdf 我应该能够使
我想问的是,我们可以将现有pass生成的信息转化为新pass吗? 如果是,那么如何? 例如 -loops 给出了自然循环信息,所以我们可以通过调用它来将这些信息用于新的传递。 最佳答案 您可以通过覆盖
在 LLVM IR 中,当我想从一个数组中获取一个值时,似乎有三种方法可以做到这一点:使用 extractvalue、使用 extractelement 和使用 getelementptr 然后加载。
我想逐步介绍一下我生成的LLVM IR代码。就llc和lli而言,该代码在语法上是有效的并且类型有效,但是结果不是我所期望的。 这些块足够大,以至于我无法简单地读取该错误就无法成功完成,并且我很难制作
我想弄清楚如何使用 trampoline intrinsics在 LLVM 中。该文档提到了存储蹦床所需的一些存储量,这取决于平台。我的问题是,我如何确定需要多少? 我找到了 this example
我需要使用抽象解释来使用 LLVM 进行一些分析。这可能吗?或者我需要更轻松地使用分析工具。如果我可以通过 LLVM 做到这一点,哪些类将帮助我从原始源代码中制定语句以获取变量之间的关系(以及每个变量
我正在创建一种静态编译的编程语言,并使用 LLVM 作为其后端。我希望我的语言在发生整数溢出时陷入/崩溃。 我知道类似 llvm.sadd.with.overflow 的事情,但我认为这不是最佳/有效
我正在尝试学习 LLVM tablegen。 http://llvm.org/docs/TableGen/LangRef.html表明 field关键字存在但不解释其含义。有人知道这是什么意思吗? 我
Fibonacci LLVM 示例使用 errs() getIR() ) 我一直在搜索 llvm::Module Class Reference并没有得到任何帮助。 Fibonacci.cpp 的一部
我想在 llvm IR 中找到对 llvm.pow.f64 函数的所有函数调用。请建议我一个方法来做到这一点。 最佳答案 嗯,这是一个基本的 FunctionPass找到所有对函数的调用: class
我正在尝试从 llvm 中间代码中删除未使用的 block 。 首先,我通过从入口 basicblock 开始并从它们的终止符指令添加所有 basicblock 后继者来构建可访问的 basicblo
我想获取 llvm 中每条指令的后继列表。如果我没理解错的话,对于除了branch(br)之外的所有指令,后继指令就是下一条。但是对于分支指令来说有点棘手。 例如,如果我有以下 C 代码: int m
我有文本格式的 LLVM IR 代码。我想做的是能够解析它并修改该代码。是否有可以帮助解析 LLVM IR 代码的 API?我的系统中应该有哪些库?此刻我有clang编译器也安装了 LLVM,因为我可
(1) @str = private constant [13 x i8] c"Hello World\0A\00" (2) define i32 @main(){ (3) %r2 = getelem
如果我有一组基本块和边,我需要为它们创建一个具有新入口和端点的新函数。 我可以直接在 LLVM 中创建它吗,就像 createFunction(F) 一样然后 F.insert(bb, edges)其
我通过教程使用 LLVM http://llvm.org/releases/3.1/docs/tutorial/ 编写玩具编译器 但是关于符号表处理的内容并不多。 有一个命令 llvm-nm 显示符号
我希望编写一个 LLVM 传递两个 i32 类型的参数来选择函数。我的第一次尝试(如下所示)失败了: bool MyFunctionPass::runOnFunction(Function &f) {
我是一名优秀的程序员,十分优秀!