[Beignet] [PATCH 1/3] backend/src/backend: Handle -dump-opt-llvm=[PATH] in clCompileProgram and clBuildProgram OpenCL API

Yang, Rong R rong.r.yang at intel.com
Mon Aug 24 00:26:27 PDT 2015


Pushed, thanks.

> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> Guo, Yejun
> Sent: Thursday, August 20, 2015 16:08
> To: Navare, Manasi D; beignet at lists.freedesktop.org
> Cc: Navare, Manasi D
> Subject: Re: [Beignet] [PATCH 1/3] backend/src/backend: Handle -dump-
> opt-llvm=[PATH] in clCompileProgram and clBuildProgram OpenCL API
> 
> LGTM, thanks.
> 
> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> Manasi Navare
> Sent: Tuesday, August 18, 2015 7:17 PM
> To: beignet at lists.freedesktop.org
> Cc: Navare, Manasi D
> Subject: [Beignet] [PATCH 1/3] backend/src/backend: Handle -dump-opt-
> llvm=[PATH] in clCompileProgram and clBuildProgram OpenCL API
> 
> This is a resubmission of the patch with support for LLVM 3.4 Allows the user
> to request a dump of the LLVM-generated IR to the file specified in [PATH]
> through clCompileProgram options
> 
> Signed-off-by: Manasi Navare <manasi.d.navare at intel.com>
> ---
>  backend/src/backend/program.cpp | 61 +++++++++++++++++++++----------
> ----------
>  1 file changed, 31 insertions(+), 30 deletions(-)
> 
> diff --git a/backend/src/backend/program.cpp
> b/backend/src/backend/program.cpp index c02096f..d9e6416 100644
> --- a/backend/src/backend/program.cpp
> +++ b/backend/src/backend/program.cpp
> @@ -519,7 +519,7 @@ namespace gbe {
>    BVAR(OCL_OUTPUT_BUILD_LOG, false);
> 
>    static bool buildModuleFromSource(const char* input, llvm::Module**
> out_module, llvm::LLVMContext* llvm_ctx,
> -                                    std::vector<std::string>& options, size_t stringSize, char
> *err,
> +                                    std::string dumpLLVMFileName,
> + std::vector<std::string>& options, size_t stringSize, char *err,
>                                      size_t *errSize) {
>      // Arguments to pass to the clang frontend
>      vector<const char *> args;
> @@ -628,6 +628,34 @@ namespace gbe {
>  #endif
> 
>      *out_module = module;
> +
> +// Dump the LLVM if requested.
> +#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 6)
> +    if (!dumpLLVMFileName.empty()) {
> +      std::string err;
> +      llvm::raw_fd_ostream ostream (dumpLLVMFileName.c_str(),
> +                                    err,
> +      #if LLVM_VERSION_MINOR == 3
> +                                    0
> +      #else
> +                                    llvm::sys::fs::F_None
> +      #endif
> +                                    );
> +
> +      if (err.empty()) {
> +        (*out_module)->print(ostream, 0);
> +      } //Otherwise, you'll have to make do without the dump.
> +    }
> +#else
> +    if (!dumpLLVMFileName.empty()) {
> +      std::error_code err;
> +      llvm::raw_fd_ostream ostream (dumpLLVMFileName.c_str(),
> +                                    err, llvm::sys::fs::F_None);
> +      if (!err) {
> +        (*out_module)->print(ostream, 0);
> +      } //Otherwise, you'll have to make do without the dump.
> +    }
> +#endif
>      return true;
>    }
> 
> @@ -808,7 +836,7 @@ namespace gbe {
>      if (!llvm::llvm_is_multithreaded())
>        llvm_mutex.lock();
> 
> -    if (buildModuleFromSource(clName.c_str(), &out_module, llvm_ctx, clOpt,
> +    if (buildModuleFromSource(clName.c_str(), &out_module, llvm_ctx,
> + dumpLLVMFileName, clOpt,
>                                stringSize, err, errSize)) {
>      // Now build the program from llvm
>        size_t clangErrSize = 0;
> @@ -819,33 +847,6 @@ namespace gbe {
>          clangErrSize = *errSize;
>        }
> 
> -      // Dump the LLVM if requested.
> -      #if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 6)
> -      if (!dumpLLVMFileName.empty()) {
> -        std::string err;
> -        llvm::raw_fd_ostream ostream (dumpLLVMFileName.c_str(),
> -                                      err,
> -        #if LLVM_VERSION_MINOR == 3
> -                                      0
> -        #else
> -                                      llvm::sys::fs::F_RW
> -        #endif
> -                                      );
> -        if (err.empty()) {
> -          out_module->print(ostream, 0);
> -        } //Otherwise, you'll have to make do without the dump.
> -      }
> -      #else
> -      if (!dumpLLVMFileName.empty()) {
> -        std::error_code err;
> -        llvm::raw_fd_ostream ostream (dumpLLVMFileName.c_str(),
> -                                      err, llvm::sys::fs::F_RW);
> -        if (!err) {
> -          out_module->print(ostream, 0);
> -        } //Otherwise, you'll have to make do without the dump.
> -      }
> -      #endif
> -
>        FILE *asmDumpStream = fopen(dumpASMFileName.c_str(), "w");
>        if (asmDumpStream)
>          fclose(asmDumpStream);
> @@ -891,7 +892,7 @@ namespace gbe {
>      //for some functions, so we use global context now, need switch to new
> context later.
>      llvm::Module * out_module;
>      llvm::LLVMContext* llvm_ctx = &llvm::getGlobalContext();
> -    if (buildModuleFromSource(clName.c_str(), &out_module, llvm_ctx, clOpt,
> +    if (buildModuleFromSource(clName.c_str(), &out_module, llvm_ctx,
> + dumpLLVMFileName, clOpt,
>                                stringSize, err, errSize)) {
>      // Now build the program from llvm
>        if (err != NULL) {
> --
> 1.9.1
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list