gpt4 book ai didi

c - LLVM 内存依赖性分析中的 Read after Read 依赖性

转载 作者:行者123 更新时间:2023-11-30 16:51:47 28 4
gpt4 key购买 nike

下图中,左边是C代码,右边是未优化的LLVM IR形式。

The Figure

在 IR 上运行 MemoryDe​​pendenceAnalysis 可查找内存依赖性。原始代码及其 IR 等效代码中均使用箭头线显示了一种依赖关系。

以下是分析的输出,其中包括提到的依赖项:

Printing analysis 'Print MemDeps of function' for function 'main':
Def from: %retval = alloca i32, align 4
store i32 0, i32* %retval, align 4

Def from: %d = alloca i32, align 4
store i32 0, i32* %d, align 4

Def from: %a = alloca i32, align 4
store i32 0, i32* %a, align 4

Def from: store i32 0, i32* %a, align 4
%0 = load i32, i32* %a, align 4

Def from: %b = alloca i32, align 4
store i32 %0, i32* %b, align 4

Def from: %0 = load i32, i32* %a, align 4
%1 = load i32, i32* %a, align 4

Def from: store i32 0, i32* %d, align 4
%2 = load i32, i32* %d, align 4

Def from: %c = alloca i32, align 4
store i32 %add, i32* %c, align 4

Def from: %2 = load i32, i32* %d, align 4
store i32 2, i32* %d, align 4

在分析的输出中,我们有:

Def from:   %0 = load i32, i32* %a, align 4
%1 = load i32, i32* %a, align 4

变量a在两个语句中被读取,这是一个RAR依赖项。如代码片段(LLVM-3.9.0 at lib/Analysis/MemoryDe​​pendenceAnalysis.cpp:549-551)所示,LLVM 将这些负载视为彼此的定义。这是什么意思?

    // Must aliased loads are defs of each other.
if (R == MustAlias)
return MemDepResult::getDef(Inst);

另请注意,分析是在 IR 上执行的,而不是在 C 源代码上执行的。

最佳答案

我从未使用过 LLVM,但根据您提供的 C 代码和 LLVM IR,a 变量被读取了 2 次。我没有看到任何错误。难道我错了?

enter image description here

关于c - LLVM 内存依赖性分析中的 Read after Read 依赖性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41595545/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com