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

标签 c++ c llvm-ir

我的问题与 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/

相关文章:

c - 与 Wolfssl 和 Nordic 的蓝牙 LE 安全连接 : key exchange

c - 为什么 C 有这些奇怪的翻译限制(第 2.2.4.1 节)?

c++ - 从 FloatingLiteral/APFloat 获取原始解析数字

c++ - 如何将 OpenCL 内核文件(.cl)编译为 llvm IR 文件

c++ - 在 int 数组的情况下可以使用 new 表达式 "overflow"吗?

c++ - GDB - 如何打破 "something is written to cout"?

c++ - 使用Callgrind追踪不必要的拷贝

C:将元素插入结构数组

javascript - 如何将 javascript 转换为 LLVM IR?

c++ - friend 声明声明了一个非模板函数