LLVM Help

Hi All,

aa.bc (884 Bytes)

aa.c (106 Bytes)

welcome.bc (940 Bytes)

welcome.c (70 Bytes)

InstCount.cpp (3.17 KB)

Hi Omar,

fprintf(f, "NumGetElementPtrInst: %d\n, NumLoadInst: %d\n,NumStoreInst:
%d\n,NumCallInst: %d\n,NumInvokeInst: %d\n,NumAllocaInst:
%d\n",NumGetElementPtrInst ,
NumLoadInst,NumStoreInst,NumCallInst,NumInvokeInst,NumAllocaInst);

These variables aren't simply integers. They're C++ class types and
because of that are being passed oddly into the variadic function
fprintf. You should be able to cast them all to "unsigned" for your
purposes.

2-If I changed the InstCount.cpp do I have to make llvm from the scratch or
their is a simple way to do the make (where it doesn't take long time just
take the minor changes)

It ought to be possible to compile your own pass to a .so file and
load it into opt dynamically. There's some kind of documentation at
http://llvm.org/docs/CMake.html#cmake-out-of-source-pass, but I've not
done it before so I don't know how reliable it is.

Cheers.

Tim.

It ought to be possible to compile your own pass to a .so file and
load it into opt dynamically. There’s some kind of documentation at
http://llvm.org/docs/CMake.html#cmake-out-of-source-pass, but I’ve not
done it before so I don’t know how reliable it is.

It is indeed possible. I have a simple example of doing this for the “hello pass” in [1] in the “helloPass” folder. In the same directory it also shows how to load the pass as a clang plug-in and have it run automatically. This built fine against LLVM3.5 but I’ve not tested if this builds against trunk.

[1] https://github.com/delcypher/srg-llvm-pass-tutorial/

HTH,
Dan

very simple and good commands :

$ clang++ -c basic_block_pass.cpp llvm-config --cxxflags
$ clang++ -shared -o pass.so basic_block_pass.o llvm-config --ldflags
$ opt -load ./pass.so -myPass < hello.bc > /dev/null

link : http://stackoverflow.com/questions/22007458/how-to-create-you-own-pass-in-llvm?rq=1