2 Replies Latest reply on Mar 10, 2012 12:09 AM by hyouklee

    Extract LLVM IR from BIF

    hyouklee

      Hi.

       

      I'm trying to extract LLVM IR from the binary generated by OpenCL offline compiler.

      (http://developer.amd.com/support/KnowledgeBase/Lists/KnowledgeBase/DispForm.aspx?ID=115)

      I tested with the clbinarygen.c given from the above link with the option (-fno-bin-exe -fno-bin-amdil),

      and I could get the .llvmir section for a simple vector addition cl kernel.

      But this output format is still not a pure LLVM bitcode and has other  BIF-related stuffs.

      How could I easily get the LLVM IR for the kernel so that I can feed it into llvm-dis?

      (The attached is the output from running clbinarygen.c with the above option.)

      Thanks.

        • Re: Extract LLVM IR from BIF
          MicahVillmow

          hyouklee,

          The article still produces an ELF object as its result, you need to decompose the ELF object itself to get the LLVMIR. If you use readelf on the attached file, then you see that llvmir starts at offset 0xc8 and is 0x5bc bytes in size. So, your best bet is to write a program that takes in an elf file and offset and a size and strips that section and stores it into a seperate file.

           

          Another thing you can do is use a binary editor and remove the first 0xc8 bytes and everything after byte 0xc8 + 0x5bc.