const unsigned char * code;
unsigned i;
+ shader->llvm_ctx = LLVMContextCreate();
+
COMPUTE_DBG(ctx->screen, "*** evergreen_create_compute_state\n");
header = cso->prog;
shader->input_size = cso->req_input_mem;
#ifdef HAVE_OPENCL
- shader->num_kernels = radeon_llvm_get_num_kernels(code, header->num_bytes);
+ shader->num_kernels = radeon_llvm_get_num_kernels(shader->llvm_ctx, code,
+ header->num_bytes);
shader->kernels = CALLOC(sizeof(struct r600_kernel), shader->num_kernels);
for (i = 0; i < shader->num_kernels; i++) {
struct r600_kernel *kernel = &shader->kernels[i];
- kernel->llvm_module = radeon_llvm_get_kernel_module(i, code,
- header->num_bytes);
+ kernel->llvm_module = radeon_llvm_get_kernel_module(shader->llvm_ctx, i,
+ code, header->num_bytes);
}
#endif
return shader;
{
struct r600_pipe_compute *shader = (struct r600_pipe_compute *)state;
+ if (!shader)
+ return;
+
+#ifdef HAVE_OPENCL
+ if (shader->llvm_ctx){
+ LLVMContextDispose(shader->llvm_ctx);
+ }
+#endif
+
free(shader);
}
unsigned private_size;
unsigned input_size;
struct r600_resource *kernel_param;
+
+#ifdef HAVE_OPENCL
+ LLVMContextRef llvm_ctx;
+#endif
};
struct r600_resource* r600_compute_buffer_alloc_vram(struct r600_screen *screen, unsigned size);
#include <llvm-c/Transforms/IPO.h>
#include <llvm-c/Transforms/PassManagerBuilder.h>
-LLVMModuleRef radeon_llvm_parse_bitcode(const unsigned char * bitcode,
- unsigned bitcode_len)
+LLVMModuleRef radeon_llvm_parse_bitcode(LLVMContextRef ctx,
+ const unsigned char * bitcode, unsigned bitcode_len)
{
LLVMMemoryBufferRef buf;
- LLVMContextRef ctx = LLVMContextCreate();
LLVMModuleRef module;
buf = LLVMCreateMemoryBufferWithMemoryRangeCopy((const char*)bitcode,
return module;
}
-unsigned radeon_llvm_get_num_kernels(const unsigned char *bitcode,
- unsigned bitcode_len)
+unsigned radeon_llvm_get_num_kernels(LLVMContextRef ctx,
+ const unsigned char *bitcode, unsigned bitcode_len)
{
- LLVMModuleRef mod = radeon_llvm_parse_bitcode(bitcode, bitcode_len);
+ LLVMModuleRef mod = radeon_llvm_parse_bitcode(ctx, bitcode, bitcode_len);
return LLVMGetNamedMetadataNumOperands(mod, "opencl.kernels");
}
LLVMDisposePassManager(pass_manager);
}
-LLVMModuleRef radeon_llvm_get_kernel_module(unsigned index,
+LLVMModuleRef radeon_llvm_get_kernel_module(LLVMContextRef ctx, unsigned index,
const unsigned char *bitcode, unsigned bitcode_len)
{
LLVMModuleRef mod;
LLVMValueRef *kernel_metadata;
unsigned i;
- mod = radeon_llvm_parse_bitcode(bitcode, bitcode_len);
+ mod = radeon_llvm_parse_bitcode(ctx, bitcode, bitcode_len);
num_kernels = LLVMGetNamedMetadataNumOperands(mod, "opencl.kernels");
kernel_metadata = MALLOC(num_kernels * sizeof(LLVMValueRef));
LLVMGetNamedMetadataOperands(mod, "opencl.kernels", kernel_metadata);
#include <llvm-c/Core.h>
-LLVMModuleRef radeon_llvm_parse_bitcode(const unsigned char * bitcode,
- unsigned bitcode_len);
-unsigned radeon_llvm_get_num_kernels(const unsigned char *bitcode, unsigned bitcode_len);
-LLVMModuleRef radeon_llvm_get_kernel_module(unsigned index,
+LLVMModuleRef radeon_llvm_parse_bitcode(LLVMContextRef ctx,
+ const unsigned char * bitcode, unsigned bitcode_len);
+unsigned radeon_llvm_get_num_kernels(LLVMContextRef ctx,
+ const unsigned char *bitcode, unsigned bitcode_len);
+LLVMModuleRef radeon_llvm_get_kernel_module(LLVMContextRef ctx, unsigned index,
const unsigned char *bitcode, unsigned bitcode_len);
#endif
struct pipe_resource *global_buffers[MAX_GLOBAL_BUFFERS];
+ LLVMContextRef llvm_ctx;
};
static void *radeonsi_create_compute_state(
const unsigned char *code;
unsigned i;
+ program->llvm_ctx = LLVMContextCreate();
+
header = cso->prog;
code = cso->prog + sizeof(struct pipe_llvm_program_header);
program->private_size = cso->req_private_mem;
program->input_size = cso->req_input_mem;
- program->num_kernels = radeon_llvm_get_num_kernels(code,
+ program->num_kernels = radeon_llvm_get_num_kernels(program->llvm_ctx, code,
header->num_bytes);
program->kernels = CALLOC(sizeof(struct si_pipe_shader),
program->num_kernels);
for (i = 0; i < program->num_kernels; i++) {
- LLVMModuleRef mod = radeon_llvm_get_kernel_module(i, code,
- header->num_bytes);
+ LLVMModuleRef mod = radeon_llvm_get_kernel_module(program->llvm_ctx, i,
+ code, header->num_bytes);
si_compile_llvm(rctx, &program->kernels[i], mod);
LLVMDisposeModule(mod);
}
FREE(program->kernels);
}
+ if (program->llvm_ctx){
+ LLVMContextDispose(program->llvm_ctx);
+ }
+
//And then free the program itself.
FREE(program);
}