【发布时间】:2013-11-12 00:29:11
【问题描述】:
我需要在LoopPass 中插入IR 指令以调用pthread_create,因此我需要将实际函数作为pthread_create 应该在新线程上调用的参数传递。
目前我已将要在新线程上运行的函数定义为
Function *worker_func = Function::Create(funcType,
GlobalValue::ExternalLinkage,
"worker_func",
CurrentModule);
我通过以下方式获得了指向 pthread_create 的指针:
Function *func_pthread_create = dyn_cast<Function>(
TheModule->getOrInsertFunction("pthread_create", pthreadCreateTy));
我需要将Type* 的数组作为参数传递给pthread_create,如下所示。
Value* pthread_create_call = builder.CreateCall(
func_pthread_create, args, "pthread_create");
参数为:
Value* args[4];
args[0] = pthread_t_ld
args[1] = llvm::Constant::getNullValue(llvm::Type::getInt8Ty(getGlobalContext())->getPointerTo());
args[2] = ??? // supposed to be the pointer to worker_func`
args[3] = llvm::Constant::getNullValue(llvm::Type::getInt8Ty(getGlobalContext())->getPointerTo());
那么我怎样才能将指向这个worker_func 函数的指针传递给pthread_create?
【问题讨论】:
-
反引号
`用于内联代码。代码块缩进四个空格。
标签: c compiler-construction pthreads llvm llvm-ir