libcxx to llvm ir

Hi all,

I am playing with llvm orc jit and I would like to be able to use the STL. So I am trying to find a way to compile libcxx to llvm ir.
Anybody had any success and have some pointers on how to do it? So far I tried to figure out a way to configure cmake to make it happen.
I am on windows and so I fear that clang-cl might not be able to do this. In any case, I would appreciate any pointers.

Thanks a lot

Clang is the right tool for this. I don't know the command-line options for `clang-cl`, but on `clang` invocations you would do this by using "-S -emit-llvm" instead of "-c".

+Reid, I assume there is an equivalent?

clang-cl doesn’t expose a way to get LLVM IR, but there are a couple of different ways to do what you want.

First, you can just use the clang driver, as long as you set the triple right, and set up the include search paths correctly. Mainly this means adding ‘-isystem’ flags for everything in the INCLUDE environment variable in a standard Visual C++ development environment. If you need to link, then you need LIB and LIBPATH as well.

Next, you can use the “-clang:” prefix on any GCC-style driver option to use it with clang-cl. I haven’t tried, but maybe -clang:-S -clang:-emit-llvm will do the right thing.

If that doesn’t work, I do know that you can use -Fa to emit assembly as you would with MSVC, and then pass -Xclang -emit-llvm to make that assembly actually LLVM IR. The invocation would be clang-cl foo.cpp -Fafoo.ll -Xclang -emit-llvm.

If that doesn’t work, you could enable LTO (-flto) and llvm-dis the object files.

After rereading your question, I think maybe the best way forward for you would be to configure libc++'s build to use clang-cl, and then enable LTO. I believe our cmake scripts support the clang-cl driver better than the clang driver on Windows.

Hopefully one of those approaches works. :slight_smile:

Hi all,

I am playing with llvm orc jit and I would like to be able to use the STL.

Most of the STL is header-only and templated code that needs to be instantiated, are you interested in a very specific subset of the STL? Otherwise how are you handling this?