C 从LLVM中的不同文件内联代码

C 从LLVM中的不同文件内联代码,c,llvm,clang,C,Llvm,Clang,我需要在运行时使用LLVM内联几个函数。复杂的是,这些函数在单独的位代码文件中定义 在运行时,我需要为函数生成代码,例如 void snippet1(); //declaring that snippet1 and 2 are defined in snippet1.c and snippet2.c void snippet2(); void combo12(){ snippet1(); snippet1(); snippet2(); snipp

我需要在运行时使用LLVM内联几个函数。复杂的是,这些函数在单独的位代码文件中定义

在运行时,我需要为函数生成代码,例如

void snippet1();         //declaring that snippet1 and 2 are defined in snippet1.c and snippet2.c
void snippet2();

void combo12(){
    snippet1();
    snippet1();
    snippet2();
    snippet2();
}
来自从combo12.c、snippet1.c和snippet2.c编译的单独LLVM位代码文件。问题是,我需要在combo12中内联所有对snippet1和snippet2的调用。我尝试使用以下代码(main.cpp)执行此操作:

和main.cpp

clang++ -g main.cpp `llvm-config --cppflags --ldflags --libs --cppflags --ldflags --libs core jit native linker transformutils ipo bitreader` -O0 -o main
当我运行./main时,它不会内联代码段,尽管我用AlwaysInline属性显式地标记函数,并使用AlwaysInline传递。它从不在屏幕上打印修改过的野兽

为什么会发生这种情况?我认为,通过将所有模块链接在一起并应用IPO通行证(AlwaysInline),这将是可行的


谢谢你的洞察力

内联发生在编译过程中,不链接,只有在编译时使用完全定义的函数才能使用内联。所以,不可能从其他文件内联函数(因为在编译文件时,忽略了其他文件)。唯一的解决方案是在每个需要内联函数的文件中定义函数。

你找到了吗?我也有同样的问题,我有llvm.uadd.with.overflow.*的包装器,但我希望它们内联。你注意到了吗?
//What this function does is irrelevant
#include "post_opt.h"     //contains the struct exstr declaration
extern struct exstr a;
inline void snippet1() __attribute((always_inline));
void snippet1(){
    int x, y;
    a.b = 10;
    x = 2;
    if(x < a.a){
        y = x + 1;
    }
}
clang -c -emit-llvm snippet1.c -o snippet1.bc -O0
clang -c -emit-llvm snippet2.c -o snippet2.bc -O0
clang -c -emit-llvm combo12.c -o combo12.bc -O0
clang++ -g main.cpp `llvm-config --cppflags --ldflags --libs --cppflags --ldflags --libs core jit native linker transformutils ipo bitreader` -O0 -o main