【问题标题】:Representing the pthread function call types with LLVM type builder使用 LLVM 类型构建器表示 pthread 函数调用类型
【发布时间】:2015-11-20 13:05:26
【问题描述】:

我对 LLVM 中的并行循环感兴趣,我想在导入 pthread 函数时使用类型生成器。

Pthread_join 有一个相当简单的签名,但 Pthread_create 有签名:

 int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
                          void *(*start_routine) (void *), void *arg);

目前我有:

FunctionType *pthreadJoinTy = TypeBuilder<int(int,void *,void*(void*) (void*),void*),false>::get(C);
M.getOrInsertFunction("pthread_create", pthreadCreateTy);

但是 LLVM 对我构建 pthreadCreateTy 的尝试并不满意。它吐出的三个构建错误是:

错误:“参数”声明为函数返回函数 (void*),void*),false>::get(c);

错误:模板参数的数量错误(1,应该是 2) (void*),void*),false>::get(c);

错误:为“模板类”提供 llvm::TypeBuilder 模板类 类型生成器 {};

此处使用的正确 TypeBuilder 代码是什么?

【问题讨论】:

    标签: compiler-construction pthreads llvm compiler-optimization


    【解决方案1】:

    我认为你被 C 声明 void *(*start_routine) (void *) 搞砸了。这只是一个函数(称为 start_routine),它接受一个 void 指针并返回一个 void 指针。

    您在TypeBuilder 中描述的方式在语法上是错误的:void*(void*) (void*)。您添加了一个额外的(void*)

    右边的TypeBuildervoid*(void*)

    但通常,您尝试构建的声明无论如何都是错误的。看看 Clang 做了什么,你的目标是这样的声明:

    %union.pthread_attr_t = type { i64, [48 x i8] }
    declare i32 @pthread_create(i64*, %union.pthread_attr_t*, i8* (i8*)*, i8*)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-13
      • 1970-01-01
      • 2017-03-12
      • 1970-01-01
      • 2021-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多