我正在编写一个LLVM pass(它是一个LoopPass),需要在IR中插入pthread函数调用,如pthread_create()和pthread_join()。我知道如何创建和插入函数调用到IR中,但是我无法获取LLVM中Function*的pthread表示形式。
这是我拥有的:
相比之下,
我在我的pass中包含了
这是我拥有的:
Function *pthread_create_func = currentModule->getFunction("pthread_create");
但是它返回NULL。相比之下,
Function *printf_func = currentModule->getFunction("printf");
将返回正确的Function*,允许我将新的函数调用插入到IR中。我在我的pass中包含了
#include "pthread.h"
,并在clang -emit-llvm
之后立即添加了-pthread
,但它仍然无法找到pthread_create或其他pthread_*函数。