0

I'm building an IR level Pass for LLVM which instrument the functions with calls to my runtime library. So far I have used the following lines to compile any C file with my pass and link it with the runtime library and guaranteeing that the runtime library function calls are inlined.

Compiling source to IR...
clang -S -emit-llvm example.c -o example-codeIR.ll -I ../runtime
Running Pass with opt...
opt -load=../build/PSS/libPSSPass.so -PSSPass -overwrite -always-inline -S -o example-codeOpt.ll example-codeIR.ll
Linking IR with runtime library...
llvm-link -o example-linked.bc example-codeOpt.ll ../runtime/obj/PSSutils.ll
Compiling bitcode to binary...
clang -ldl -O3 -o example example-linked.bc ../initializer/so/shim.so

Now I would like to test my pass with the LLVM testsuite and the only thing I can do is pass flags to the test suite. I can't control the steps of of compilation and generate so many files for each test case.

Is there a way to do the same as above without having to save intermediate files and yet keep the order of the steps?

I have tried the following:

clang -ldl -Xclang -load -Xclang ../build/PSS/libPSSPass.so ../initializer/so/shim.so ../runtime/obj/PSSutils.ll $<

But I ran into the problem that I can't compile both IR and .c files. If I compile the runtime library to be an object file the functions in it will not get inlined anymore which is the main goal of the above steps.

Nour
  • 1

1 Answers1

0

So to Answer my question: first of all, call to shared objects are never inlined. hence, the above mentioned shared objects should be compiled to objects instead. The -flto=thin flag should be used when compiling the objects to build a summary of the functions so the linker can perform link time optimizations. And in the final step of compiling the target you will need to also compile it with -flto=thin flag and the compiler will do the magic for you.

Nour
  • 1
  • using -flto will not have the same effects since it will only merge all the sources of the object files into one executable. – Nour May 19 '20 at 16:04