gpt4 book ai didi

c++ - 限制 C 中的限定符与 LLVM IR 中的 noalias 属性

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:47:10 27 4
gpt4 key购买 nike

我的问题与 C 中的 restrict 限定符和 LLVM 中的 noalias 属性用作函数参数时的不同语义有关。

根据LLVM documentation for noalias :

This indicates that objects accessed via pointer values based on the argument or return value are not also accessed, during the execution of the function, via pointer values not based on the argument or return value.

如果是restrict 限定符,C11 (Example 3, page124, sect. 6.7.3.1) 的草案举了一个例子,其中两个 restrict 参数之间存在别名,只要它们只读取数据就可以:

void h(int n, int * restrict p, int * restrict q, int * restrict r) {
int i;
for (i = 0; i < n; i++)
p[i] = q[i] + r[i];
}

在我看来,上面给出的示例似乎无法满足noalias 的语义。是这样吗?

最佳答案

正如 Jens Gustedt 所建议的那样,深入挖掘链接将我带到了 AliasAnalysis页面上写着:

The most obvious example is when the two pointers point to non-overlapping memory ranges. Another is when the two pointers are only ever used for reading memory. Another is when the memory is freed and reallocated between accesses through one pointer and accesses through the other — in this case, there is a dependence, but it’s mediated by the free and reallocation.

这解决了问题:noalias 属性等同于函数参数中的 C restrict 限定符。

关于c++ - 限制 C 中的限定符与 LLVM IR 中的 noalias 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40223359/

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