gallivm: add support for a cache object

This plumbs the cache object into the gallivm API, nothing uses
it yet.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5049>
This commit is contained in:
Dave Airlie 2020-05-13 09:30:44 +10:00
parent 333ee94285
commit 7b7c02d161
14 changed files with 41 additions and 19 deletions

View file

@ -850,7 +850,7 @@ draw_llvm_create_variant(struct draw_llvm *llvm,
snprintf(module_name, sizeof(module_name), "draw_llvm_vs_variant%u",
variant->shader->variants_cached);
variant->gallivm = gallivm_create(module_name, llvm->context);
variant->gallivm = gallivm_create(module_name, llvm->context, NULL);
create_jit_types(variant);
@ -2848,7 +2848,7 @@ draw_gs_llvm_create_variant(struct draw_llvm *llvm,
snprintf(module_name, sizeof(module_name), "draw_llvm_gs_variant%u",
variant->shader->variants_cached);
variant->gallivm = gallivm_create(module_name, llvm->context);
variant->gallivm = gallivm_create(module_name, llvm->context, NULL);
create_gs_jit_types(variant);
@ -3453,7 +3453,7 @@ draw_tcs_llvm_create_variant(struct draw_llvm *llvm,
snprintf(module_name, sizeof(module_name), "draw_llvm_tcs_variant%u",
variant->shader->variants_cached);
variant->gallivm = gallivm_create(module_name, llvm->context);
variant->gallivm = gallivm_create(module_name, llvm->context, NULL);
create_tcs_jit_types(variant);
@ -3928,7 +3928,7 @@ draw_tes_llvm_create_variant(struct draw_llvm *llvm,
snprintf(module_name, sizeof(module_name), "draw_llvm_tes_variant%u",
variant->shader->variants_cached);
variant->gallivm = gallivm_create(module_name, llvm->context);
variant->gallivm = gallivm_create(module_name, llvm->context, NULL);
create_tes_jit_types(variant);

View file

@ -211,6 +211,9 @@ gallivm_free_ir(struct gallivm_state *gallivm)
LLVMDisposeModule(gallivm->module);
}
if (gallivm->cache) {
free(gallivm->cache->data);
}
FREE(gallivm->module_name);
if (gallivm->target) {
@ -230,6 +233,7 @@ gallivm_free_ir(struct gallivm_state *gallivm)
gallivm->passmgr = NULL;
gallivm->context = NULL;
gallivm->builder = NULL;
gallivm->cache = NULL;
}
@ -265,6 +269,7 @@ init_gallivm_engine(struct gallivm_state *gallivm)
ret = lp_build_create_jit_compiler_for_module(&gallivm->engine,
&gallivm->code,
gallivm->cache,
gallivm->module,
gallivm->memorymgr,
(unsigned) optlevel,
@ -310,7 +315,7 @@ fail:
*/
static boolean
init_gallivm_state(struct gallivm_state *gallivm, const char *name,
LLVMContextRef context)
LLVMContextRef context, struct lp_cached_code *cache)
{
assert(!gallivm->context);
assert(!gallivm->module);
@ -319,7 +324,7 @@ init_gallivm_state(struct gallivm_state *gallivm, const char *name,
return FALSE;
gallivm->context = context;
gallivm->cache = cache;
if (!gallivm->context)
goto fail;
@ -496,13 +501,14 @@ lp_build_init(void)
* Create a new gallivm_state object.
*/
struct gallivm_state *
gallivm_create(const char *name, LLVMContextRef context)
gallivm_create(const char *name, LLVMContextRef context,
struct lp_cached_code *cache)
{
struct gallivm_state *gallivm;
gallivm = CALLOC_STRUCT(gallivm_state);
if (gallivm) {
if (!init_gallivm_state(gallivm, name, context)) {
if (!init_gallivm_state(gallivm, name, context, cache)) {
FREE(gallivm);
gallivm = NULL;
}

View file

@ -39,6 +39,7 @@
extern "C" {
#endif
struct lp_cached_code;
struct gallivm_state
{
char *module_name;
@ -51,6 +52,7 @@ struct gallivm_state
LLVMBuilderRef builder;
LLVMMCJITMemoryManagerRef memorymgr;
struct lp_generated_code *code;
struct lp_cached_code *cache;
unsigned compiled;
LLVMValueRef coro_malloc_hook;
LLVMValueRef coro_free_hook;
@ -63,7 +65,8 @@ lp_build_init(void);
struct gallivm_state *
gallivm_create(const char *name, LLVMContextRef context);
gallivm_create(const char *name, LLVMContextRef context,
struct lp_cached_code *cache);
void
gallivm_destroy(struct gallivm_state *gallivm);

View file

@ -304,6 +304,7 @@ extern "C"
LLVMBool
lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
lp_generated_code **OutCode,
struct lp_cached_code *cache_out,
LLVMModuleRef M,
LLVMMCJITMemoryManagerRef CMM,
unsigned OptLevel,

View file

@ -40,6 +40,17 @@
extern "C" {
#endif
/*
* some shaders use function pointers incorrectly so can't be relinked
* properly. (mostly the fallback fetch shaders).
* We should fix them, but the dont_cache flag can be set for now,
* so they don't end up getting cached at all.
*/
struct lp_cached_code {
void *data;
size_t data_size;
bool dont_cache;
};
struct lp_generated_code;
@ -56,6 +67,7 @@ lp_set_target_options(void);
extern int
lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
struct lp_generated_code **OutCode,
struct lp_cached_code *cache_out,
LLVMModuleRef M,
LLVMMCJITMemoryManagerRef MM,
unsigned OptLevel,

View file

@ -688,7 +688,7 @@ generate_variant(struct llvmpipe_context *lp,
snprintf(module_name, sizeof(module_name), "cs%u_variant%u",
shader->no, shader->variants_created);
variant->gallivm = gallivm_create(module_name, lp->context);
variant->gallivm = gallivm_create(module_name, lp->context, NULL);
if (!variant->gallivm) {
FREE(variant);
return NULL;

View file

@ -3270,7 +3270,7 @@ generate_variant(struct llvmpipe_context *lp,
snprintf(module_name, sizeof(module_name), "fs%u_variant%u",
shader->no, shader->variants_created);
variant->gallivm = gallivm_create(module_name, lp->context);
variant->gallivm = gallivm_create(module_name, lp->context, NULL);
if (!variant->gallivm) {
FREE(variant);
return NULL;

View file

@ -730,7 +730,7 @@ generate_setup_variant(struct lp_setup_variant_key *key,
snprintf(func_name, sizeof(func_name), "setup_variant_%u",
variant->no);
variant->gallivm = gallivm = gallivm_create(func_name, lp->context);
variant->gallivm = gallivm = gallivm_create(func_name, lp->context, NULL);
if (!variant->gallivm) {
goto fail;
}

View file

@ -417,7 +417,7 @@ test_unary(unsigned verbose, FILE *fp, const struct unary_test_t *test, unsigned
}
context = LLVMContextCreate();
gallivm = gallivm_create("test_module", context);
gallivm = gallivm_create("test_module", context, NULL);
test_func = build_unary_test_func(gallivm, test, length, test_name);

View file

@ -452,7 +452,7 @@ test_one(unsigned verbose,
dump_blend_type(stdout, blend, type);
context = LLVMContextCreate();
gallivm = gallivm_create("test_module", context);
gallivm = gallivm_create("test_module", context, NULL);
func = add_blend_test(gallivm, blend, type);

View file

@ -221,7 +221,7 @@ test_one(unsigned verbose,
}
context = LLVMContextCreate();
gallivm = gallivm_create("test_module", context);
gallivm = gallivm_create("test_module", context, NULL);
func = add_conv_test(gallivm, src_type, num_srcs, dst_type, num_dsts);

View file

@ -150,7 +150,7 @@ test_format_float(unsigned verbose, FILE *fp,
unsigned i, j, k, l;
context = LLVMContextCreate();
gallivm = gallivm_create("test_module_float", context);
gallivm = gallivm_create("test_module_float", context, NULL);
fetch = add_fetch_rgba_test(gallivm, verbose, desc,
lp_float32_vec4_type(), use_cache);
@ -251,7 +251,7 @@ test_format_unorm8(unsigned verbose, FILE *fp,
unsigned i, j, k, l;
context = LLVMContextCreate();
gallivm = gallivm_create("test_module_unorm8", context);
gallivm = gallivm_create("test_module_unorm8", context, NULL);
fetch = add_fetch_rgba_test(gallivm, verbose, desc,
lp_unorm8_vec4_type(), use_cache);

View file

@ -96,7 +96,7 @@ test_printf(unsigned verbose, FILE *fp,
boolean success = TRUE;
context = LLVMContextCreate();
gallivm = gallivm_create("test_module", context);
gallivm = gallivm_create("test_module", context, NULL);
test = add_printf_test(gallivm);

View file

@ -327,7 +327,7 @@ struct BuilderSWR : public Builder {
: Builder(pJitMgr)
{
pJitMgr->SetupNewModule();
gallivm = gallivm_create(pName, wrap(&JM()->mContext));
gallivm = gallivm_create(pName, wrap(&JM()->mContext), NULL);
pJitMgr->mpCurrentModule = unwrap(gallivm->module);
}