I have a question about exit blocks : is it true that every loop’s exit block will contain only those comparisons that will lead to exit or to continue execution in loop? I have tried many examples , after optimizations it seems to be true, but does it have to be so?
Yes, that’s right. Some LLVM terminology though: The blocks you mention, are called the “exiting blocks” of the loop, and the blocks outside the loop (that are the targets of these exiting blocks) are called the exit blocks.
getExitingBlocks in LoopInfoImpl.h is the code you’re interested in.
By definition: one of the successor’s of the exiting block is an exit block, and it should have another successor that’s a block within the loop (since we know that an exiting block is *inside* a loop).
I was able to compile LLVM to LLVM IR. However, when I read the results into my program, I got "warning: ignoring debug info with an invalid version (700000003)." I figured out it was because the Clang that comes with Xcode uses an LLVM that's older than the LLVM I compiled from source, and LLVM's IR isn't backwards compatible. I've tried using the following CMake flags:
-DCMAKE_C_COMPILER=<path to clang built from source>
-DCMAKE_CXX_COMPILER=<path to clang++ built from source>
I also tried exporting the CC and CXX variables before invoking CMake. Both attempts lead to the following message:
Scanning dependencies of target LLVMDemangle
[ 0%] Building CXX object lib/Demangle/CMakeFiles/LLVMDemangle.dir/ItaniumDemangle.cpp.o
[ 0%] Linking CXX static library ../libLLVMDemangle.a
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: CMakeFiles/LLVMDemangle.dir/ItaniumDemangle.cpp.o is not an object file (not allowed in a library)
make: *** [lib/libLLVMDemangle.a] Error 1
make: *** [lib/Demangle/CMakeFiles/LLVMDemangle.dir/all] Error 2
make: *** [all] Error 2
How do I get CMake to use the correct Clang binary?
The problem is that libtool (or ar/ranlib), and ld need to be able to read the bitcode files in order to generate symbol tables for the archives and to link the final binaries. You've updated your clang to generate new bitcode, but the libtool, and ld on the system can't read the bitcode.
There are two ways to get around this.
(1) You can allow LLVM's build system to do all the hard work for you by configuring your initial LLVM build with this command:
cmake -G <generator> -C <path to clang>/cmake/caches/Apple-stage1.cmake
Then build the "stage2" target. This will take a long time to run, but it will build clang, then use that clang to build a second LTO'd clang where you can rip apart the LLVM archives.
(2) Alternatively you can set two CMake options DARWIN_LTO_LIBRARY and DYLD_LIBRARY_PATH. DARWIN_LTO_LIBRARY needs to point to the lib/libLTO.dylib which matches your clang and DYLD_LIBRARY_PATH needs to point to the lib directory containing the libLTO.dylib.