我需要在我的
目前,我已经定义了在新线程上运行的函数如下:
那么我应该如何获得指向这个
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
函数呢?