diff --git a/llvmpipe-add-an-implementation-with-llvm-orcjit.patch b/llvmpipe-add-an-implementation-with-llvm-orcjit.patch index c9f64b4bd4532f1cb5d6b00106708e255a64c29a..89b00434a8181764eb978bdac785bbcb3bc0714c 100644 --- a/llvmpipe-add-an-implementation-with-llvm-orcjit.patch +++ b/llvmpipe-add-an-implementation-with-llvm-orcjit.patch @@ -6,41 +6,11 @@ Subject: [PATCH] llvmpipe: add an implementation with llvm orcjit no per-func perf nor disasm is implemented yet. disk cache is also left empty --- - src/gallium/auxiliary/draw/draw_context.c | 4 + - src/gallium/auxiliary/draw/draw_llvm.c | 94 +- - src/gallium/auxiliary/draw/draw_llvm.h | 27 +- - src/gallium/auxiliary/gallivm/lp_bld_coro.c | 6 +- - src/gallium/auxiliary/gallivm/lp_bld_coro.h | 8 + - src/gallium/auxiliary/gallivm/lp_bld_init.c | 9 +- - src/gallium/auxiliary/gallivm/lp_bld_init.h | 41 +- - .../auxiliary/gallivm/lp_bld_init_orc.cpp | 882 ++++++++++++++++++ - src/gallium/auxiliary/meson.build | 2 +- - src/gallium/drivers/llvmpipe/lp_context.c | 14 + - src/gallium/drivers/llvmpipe/lp_context.h | 4 + - src/gallium/drivers/llvmpipe/lp_screen.c | 4 + - src/gallium/drivers/llvmpipe/lp_state_cs.c | 19 + - src/gallium/drivers/llvmpipe/lp_state_cs.h | 3 + - src/gallium/drivers/llvmpipe/lp_state_fs.c | 33 + - src/gallium/drivers/llvmpipe/lp_state_fs.h | 6 + - .../llvmpipe/lp_state_fs_linear_llvm.c | 4 + - src/gallium/drivers/llvmpipe/lp_state_setup.c | 9 + - src/gallium/drivers/llvmpipe/lp_state_setup.h | 3 + - src/gallium/drivers/llvmpipe/lp_test_arit.c | 19 + - src/gallium/drivers/llvmpipe/lp_test_blend.c | 33 +- - src/gallium/drivers/llvmpipe/lp_test_conv.c | 33 +- - src/gallium/drivers/llvmpipe/lp_test_format.c | 50 +- - .../llvmpipe/lp_test_lookup_multiple.c | 173 ++++ - src/gallium/drivers/llvmpipe/lp_test_printf.c | 31 +- - src/gallium/drivers/llvmpipe/meson.build | 2 +- - 26 files changed, 1494 insertions(+), 19 deletions(-) - create mode 100644 src/gallium/auxiliary/gallivm/lp_bld_init_orc.cpp - create mode 100644 src/gallium/drivers/llvmpipe/lp_test_lookup_multiple.c - diff --git a/src/gallium/auxiliary/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c -index 81ceefc32bb..4fdd7f319b6 100644 +index 9ddf91b..e3138cb 100644 --- a/src/gallium/auxiliary/draw/draw_context.c +++ b/src/gallium/auxiliary/draw/draw_context.c -@@ -76,7 +76,11 @@ draw_create_context(struct pipe_context *pipe, void *context, +@@ -77,7 +77,11 @@ draw_create_context(struct pipe_context *pipe, void *context, #ifdef DRAW_LLVM_AVAILABLE if (try_llvm && draw_get_option_use_llvm()) { @@ -53,10 +23,10 @@ index 81ceefc32bb..4fdd7f319b6 100644 #endif diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c -index 8b3a1522725..ae9dd4d64f5 100644 +index 4e8b001..58ea8fd 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.c +++ b/src/gallium/auxiliary/draw/draw_llvm.c -@@ -766,8 +766,13 @@ get_vertex_header_ptr_type(struct draw_llvm_variant *variant) +@@ -384,8 +384,13 @@ get_vertex_header_ptr_type(struct draw_llvm_variant *variant) /** * Create per-context LLVM info. */ @@ -70,7 +40,7 @@ index 8b3a1522725..ae9dd4d64f5 100644 { struct draw_llvm *llvm; -@@ -780,6 +785,16 @@ draw_llvm_create(struct draw_context *draw, LLVMContextRef context) +@@ -398,6 +403,16 @@ draw_llvm_create(struct draw_context *draw, LLVMContextRef context) llvm->draw = draw; @@ -87,7 +57,7 @@ index 8b3a1522725..ae9dd4d64f5 100644 llvm->context = context; if (!llvm->context) { llvm->context = LLVMContextCreate(); -@@ -792,6 +807,7 @@ draw_llvm_create(struct draw_context *draw, LLVMContextRef context) +@@ -410,6 +425,7 @@ draw_llvm_create(struct draw_context *draw, LLVMContextRef context) } if (!llvm->context) goto fail; @@ -95,7 +65,7 @@ index 8b3a1522725..ae9dd4d64f5 100644 llvm->nr_variants = 0; list_inithead(&llvm->vs_variants_list.list); -@@ -819,9 +835,16 @@ fail: +@@ -437,9 +453,16 @@ fail: void draw_llvm_destroy(struct draw_llvm *llvm) { @@ -112,7 +82,7 @@ index 8b3a1522725..ae9dd4d64f5 100644 /* XXX free other draw_llvm data? */ FREE(llvm); -@@ -895,7 +918,11 @@ draw_llvm_create_variant(struct draw_llvm *llvm, +@@ -513,7 +536,11 @@ draw_llvm_create_variant(struct draw_llvm *llvm, if (!cached.data_size) needs_caching = true; } @@ -122,9 +92,9 @@ index 8b3a1522725..ae9dd4d64f5 100644 variant->gallivm = gallivm_create(module_name, llvm->context, &cached); +#endif - create_jit_types(variant); + create_vs_jit_types(variant); -@@ -914,8 +941,13 @@ draw_llvm_create_variant(struct draw_llvm *llvm, +@@ -532,8 +559,13 @@ draw_llvm_create_variant(struct draw_llvm *llvm, gallivm_compile_module(variant->gallivm); @@ -138,7 +108,7 @@ index 8b3a1522725..ae9dd4d64f5 100644 if (needs_caching) llvm->draw->disk_cache_insert_shader(llvm->draw->disk_cache_cookie, -@@ -1990,6 +2022,10 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) +@@ -1633,6 +1665,10 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) variant_func = LLVMAddFunction(gallivm->module, func_name, func_type); variant->function = variant_func; @@ -149,7 +119,7 @@ index 8b3a1522725..ae9dd4d64f5 100644 LLVMSetFunctionCallConv(variant_func, LLVMCCallConv); for (i = 0; i < num_arg_types; ++i) -@@ -2684,6 +2720,11 @@ draw_llvm_destroy_variant(struct draw_llvm_variant *variant) +@@ -2244,6 +2280,11 @@ draw_llvm_destroy_variant(struct draw_llvm_variant *variant) variant->shader->variants_cached--; list_del(&variant->list_item_global.list); llvm->nr_variants--; @@ -161,7 +131,7 @@ index 8b3a1522725..ae9dd4d64f5 100644 FREE(variant); } -@@ -2798,6 +2839,10 @@ draw_gs_llvm_generate(struct draw_llvm *llvm, +@@ -2353,6 +2394,10 @@ draw_gs_llvm_generate(struct draw_llvm *llvm, variant_func = LLVMAddFunction(gallivm->module, func_name, func_type); variant->function = variant_func; @@ -172,7 +142,7 @@ index 8b3a1522725..ae9dd4d64f5 100644 LLVMSetFunctionCallConv(variant_func, LLVMCCallConv); -@@ -2957,7 +3002,11 @@ draw_gs_llvm_create_variant(struct draw_llvm *llvm, +@@ -2518,7 +2563,11 @@ draw_gs_llvm_create_variant(struct draw_llvm *llvm, if (!cached.data_size) needs_caching = true; } @@ -184,7 +154,7 @@ index 8b3a1522725..ae9dd4d64f5 100644 create_gs_jit_types(variant); -@@ -2968,8 +3017,13 @@ draw_gs_llvm_create_variant(struct draw_llvm *llvm, +@@ -2529,8 +2578,13 @@ draw_gs_llvm_create_variant(struct draw_llvm *llvm, gallivm_compile_module(variant->gallivm); @@ -198,7 +168,7 @@ index 8b3a1522725..ae9dd4d64f5 100644 if (needs_caching) llvm->draw->disk_cache_insert_shader(llvm->draw->disk_cache_cookie, -@@ -3002,6 +3056,10 @@ draw_gs_llvm_destroy_variant(struct draw_gs_llvm_variant *variant) +@@ -2563,6 +2617,10 @@ draw_gs_llvm_destroy_variant(struct draw_gs_llvm_variant *variant) variant->shader->variants_cached--; list_del(&variant->list_item_global.list); llvm->nr_gs_variants--; @@ -209,7 +179,7 @@ index 8b3a1522725..ae9dd4d64f5 100644 FREE(variant); } -@@ -3386,6 +3444,10 @@ draw_tcs_llvm_generate(struct draw_llvm *llvm, +@@ -2936,6 +2994,10 @@ draw_tcs_llvm_generate(struct draw_llvm *llvm, variant_coro = LLVMAddFunction(gallivm->module, func_name_coro, coro_func_type); variant->function = variant_func; @@ -220,7 +190,7 @@ index 8b3a1522725..ae9dd4d64f5 100644 LLVMSetFunctionCallConv(variant_func, LLVMCCallConv); LLVMSetFunctionCallConv(variant_coro, LLVMCCallConv); -@@ -3619,8 +3681,11 @@ draw_tcs_llvm_create_variant(struct draw_llvm *llvm, +@@ -3171,8 +3233,11 @@ draw_tcs_llvm_create_variant(struct draw_llvm *llvm, if (!cached.data_size) needs_caching = true; } @@ -233,11 +203,13 @@ index 8b3a1522725..ae9dd4d64f5 100644 create_tcs_jit_types(variant); -@@ -3631,10 +3696,16 @@ draw_tcs_llvm_create_variant(struct draw_llvm *llvm, +@@ -3183,10 +3248,18 @@ draw_tcs_llvm_create_variant(struct draw_llvm *llvm, draw_tcs_llvm_generate(llvm, variant); +#if GALLIVM_USE_ORCJIT == 1 ++ lp_build_coro_add_malloc_hooks(variant->gallivm); ++ + gallivm_compile_module(variant->gallivm); + variant->jit_func = (draw_tcs_jit_func) + gallivm_jit_function(variant->gallivm, variant->function_name); @@ -250,7 +222,7 @@ index 8b3a1522725..ae9dd4d64f5 100644 if (needs_caching) llvm->draw->disk_cache_insert_shader(llvm->draw->disk_cache_cookie, -@@ -3667,6 +3738,10 @@ draw_tcs_llvm_destroy_variant(struct draw_tcs_llvm_variant *variant) +@@ -3219,6 +3292,10 @@ draw_tcs_llvm_destroy_variant(struct draw_tcs_llvm_variant *variant) variant->shader->variants_cached--; list_del(&variant->list_item_global.list); llvm->nr_tcs_variants--; @@ -261,7 +233,7 @@ index 8b3a1522725..ae9dd4d64f5 100644 FREE(variant); } -@@ -3961,6 +4036,10 @@ draw_tes_llvm_generate(struct draw_llvm *llvm, +@@ -3501,6 +3578,10 @@ draw_tes_llvm_generate(struct draw_llvm *llvm, variant_func = LLVMAddFunction(gallivm->module, func_name, func_type); variant->function = variant_func; @@ -272,7 +244,7 @@ index 8b3a1522725..ae9dd4d64f5 100644 LLVMSetFunctionCallConv(variant_func, LLVMCCallConv); for (i = 0; i < ARRAY_SIZE(arg_types); ++i) -@@ -4151,7 +4230,11 @@ draw_tes_llvm_create_variant(struct draw_llvm *llvm, +@@ -3691,7 +3772,11 @@ draw_tes_llvm_create_variant(struct draw_llvm *llvm, if (!cached.data_size) needs_caching = true; } @@ -284,7 +256,7 @@ index 8b3a1522725..ae9dd4d64f5 100644 create_tes_jit_types(variant); -@@ -4167,8 +4250,13 @@ draw_tes_llvm_create_variant(struct draw_llvm *llvm, +@@ -3707,8 +3792,13 @@ draw_tes_llvm_create_variant(struct draw_llvm *llvm, gallivm_compile_module(variant->gallivm); @@ -298,7 +270,7 @@ index 8b3a1522725..ae9dd4d64f5 100644 if (needs_caching) llvm->draw->disk_cache_insert_shader(llvm->draw->disk_cache_cookie, -@@ -4201,6 +4289,10 @@ draw_tes_llvm_destroy_variant(struct draw_tes_llvm_variant *variant) +@@ -3741,6 +3831,10 @@ draw_tes_llvm_destroy_variant(struct draw_tes_llvm_variant *variant) variant->shader->variants_cached--; list_del(&variant->list_item_global.list); llvm->nr_tes_variants--; @@ -310,10 +282,10 @@ index 8b3a1522725..ae9dd4d64f5 100644 } diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h -index f82a6a61112..1a2f08d43b1 100644 +index 2f66c80..dfc818e 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.h +++ b/src/gallium/auxiliary/draw/draw_llvm.h -@@ -41,6 +41,11 @@ +@@ -42,6 +42,11 @@ #include "pipe/p_context.h" #include "util/list.h" @@ -325,7 +297,7 @@ index f82a6a61112..1a2f08d43b1 100644 struct draw_llvm; struct llvm_vertex_shader; -@@ -624,6 +629,9 @@ struct draw_llvm_variant +@@ -401,6 +406,9 @@ struct draw_llvm_variant LLVMTypeRef vertex_header_ptr_type; LLVMValueRef function; @@ -335,7 +307,7 @@ index f82a6a61112..1a2f08d43b1 100644 draw_jit_vert_func jit_func; struct llvm_vertex_shader *shader; -@@ -654,6 +662,9 @@ struct draw_gs_llvm_variant +@@ -434,6 +442,9 @@ struct draw_gs_llvm_variant LLVMValueRef io_ptr; LLVMValueRef num_prims; LLVMValueRef function; @@ -345,7 +317,7 @@ index f82a6a61112..1a2f08d43b1 100644 draw_gs_jit_func jit_func; struct llvm_geometry_shader *shader; -@@ -680,6 +691,9 @@ struct draw_tcs_llvm_variant +@@ -460,6 +471,9 @@ struct draw_tcs_llvm_variant /* LLVMValueRef io_ptr; */ LLVMValueRef num_prims; LLVMValueRef function; @@ -355,7 +327,7 @@ index f82a6a61112..1a2f08d43b1 100644 draw_tcs_jit_func jit_func; struct llvm_tess_ctrl_shader *shader; -@@ -710,6 +724,9 @@ struct draw_tes_llvm_variant +@@ -490,6 +504,9 @@ struct draw_tes_llvm_variant LLVMValueRef io_ptr; LLVMValueRef num_prims; LLVMValueRef function; @@ -365,17 +337,17 @@ index f82a6a61112..1a2f08d43b1 100644 draw_tes_jit_func jit_func; struct llvm_tess_eval_shader *shader; -@@ -762,6 +779,9 @@ struct draw_llvm { +@@ -542,6 +559,9 @@ struct draw_llvm { struct draw_context *draw; LLVMContextRef context; +#if GALLIVM_USE_ORCJIT == 1 + LLVMOrcThreadSafeContextRef _ts_context; +#endif - boolean context_owned; + bool context_owned; - struct draw_jit_context jit_context; -@@ -807,8 +827,13 @@ llvm_tess_eval_shader(struct draw_tess_eval_shader *tes) + struct draw_vs_jit_context vs_jit_context; +@@ -587,8 +607,13 @@ llvm_tess_eval_shader(struct draw_tess_eval_shader *tes) return (struct llvm_tess_eval_shader *)tes; } @@ -391,7 +363,7 @@ index f82a6a61112..1a2f08d43b1 100644 void draw_llvm_destroy(struct draw_llvm *llvm); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_coro.c b/src/gallium/auxiliary/gallivm/lp_bld_coro.c -index 0214dcf6742..f5a2b31b6d9 100644 +index 0214dcf..f5a2b31 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_coro.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_coro.c @@ -156,12 +156,14 @@ coro_free(char *ptr) @@ -411,36 +383,12 @@ index 0214dcf6742..f5a2b31b6d9 100644 } void lp_build_coro_declare_malloc_hooks(struct gallivm_state *gallivm) -diff --git a/src/gallium/auxiliary/gallivm/lp_bld_coro.h b/src/gallium/auxiliary/gallivm/lp_bld_coro.h -index e3cf415230e..070f9756bb4 100644 ---- a/src/gallium/auxiliary/gallivm/lp_bld_coro.h -+++ b/src/gallium/auxiliary/gallivm/lp_bld_coro.h -@@ -26,6 +26,10 @@ - #ifndef LP_BLD_CORO_H - #define LP_BLD_CORO_H - -+#ifdef __cplusplus -+extern "C" { -+#endif -+ - #include - #include "pipe/p_compiler.h" - #include "gallivm/lp_bld.h" -@@ -84,4 +88,8 @@ static inline void lp_build_coro_add_presplit(LLVMValueRef coro) - #endif - } - -+#ifdef __cplusplus -+} -+#endif -+ - #endif diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c -index 24d082398e9..76846e365d9 100644 +index cd2108f..41a6257 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_init.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c -@@ -540,6 +540,12 @@ gallivm_verify_function(struct gallivm_state *gallivm, - } +@@ -515,6 +515,11 @@ gallivm_destroy(struct gallivm_state *gallivm) + FREE(gallivm); } +void @@ -448,22 +396,20 @@ index 24d082398e9..76846e365d9 100644 +{ + LLVMAddGlobalMapping(gallivm->engine, sym, addr); +} -+ - void lp_init_clock_hook(struct gallivm_state *gallivm) - { - if (gallivm->get_time_hook) -@@ -670,7 +676,8 @@ gallivm_compile_module(struct gallivm_state *gallivm) + + /** + * Validate a function. +@@ -670,7 +675,7 @@ gallivm_compile_module(struct gallivm_state *gallivm) ++gallivm->compiled; lp_init_printf_hook(gallivm); - LLVMAddGlobalMapping(gallivm->engine, gallivm->debug_printf_hook, debug_printf); -+ if (gallivm->debug_printf_hook) -+ gallivm_add_global_mapping(gallivm, gallivm->debug_printf_hook, debug_printf); ++ gallivm_add_global_mapping(gallivm, gallivm->debug_printf_hook, debug_printf); lp_init_clock_hook(gallivm); LLVMAddGlobalMapping(gallivm->engine, gallivm->get_time_hook, os_time_get_nano); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.h b/src/gallium/auxiliary/gallivm/lp_bld_init.h -index be41a34485b..fcdf6f85fce 100644 +index 418921c..294d608 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_init.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h @@ -29,11 +29,16 @@ @@ -472,7 +418,7 @@ index be41a34485b..fcdf6f85fce 100644 +#define GALLIVM_USE_ORCJIT 1 - #include "pipe/p_compiler.h" + #include "util/compiler.h" #include "util/u_pointer.h" // for func_pointer #include "lp_bld.h" +#if GALLIVM_USE_ORCJIT == 1 @@ -514,8 +460,8 @@ index be41a34485b..fcdf6f85fce 100644 struct lp_cached_code *cache; unsigned compiled; LLVMValueRef coro_malloc_hook; -@@ -74,10 +88,15 @@ lp_build_init_native_width(void); - boolean +@@ -77,10 +91,15 @@ lp_build_init_native_width(void); + bool lp_build_init(void); - @@ -531,7 +477,7 @@ index be41a34485b..fcdf6f85fce 100644 void gallivm_destroy(struct gallivm_state *gallivm); -@@ -90,11 +109,25 @@ gallivm_verify_function(struct gallivm_state *gallivm, +@@ -93,11 +112,25 @@ gallivm_verify_function(struct gallivm_state *gallivm, LLVMValueRef func); void @@ -559,21 +505,17 @@ index be41a34485b..fcdf6f85fce 100644 diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init_orc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_init_orc.cpp new file mode 100644 -index 00000000000..b245edc5586 +index 0000000..8ea4df7 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_init_orc.cpp -@@ -0,0 +1,882 @@ +@@ -0,0 +1,905 @@ +#include "util/detect.h" -+#include "pipe/p_compiler.h" -+#include "util/macros.h" +#include "util/u_cpu_detect.h" +#include "util/u_debug.h" +#include "util/os_time.h" +#include "lp_bld.h" +#include "lp_bld_debug.h" +#include "lp_bld_init.h" -+#include "lp_bld_coro.h" -+#include "lp_bld_printf.h" + +#include +#include @@ -591,7 +533,7 @@ index 00000000000..b245edc5586 +#if GALLIVM_USE_NEW_PASS == 1 +#include +#elif GALLIVM_HAVE_CORO == 1 -+#if LLVM_VERSION_MAJOR <= 8 && (DETECT_ARCH_AARCH64 || DETECT_ARCH_ARM || DETECT_ARCH_S390 || DETECT_ARCH_MIPS64) ++#if LLVM_VERSION_MAJOR <= 8 && (defined(PIPE_ARCH_AARCH64) || defined (PIPE_ARCH_ARM) || defined(PIPE_ARCH_S390) || defined(PIPE_ARCH_MIPS64)) +#include +#endif +#include @@ -640,10 +582,7 @@ index 00000000000..b245edc5586 + { "asm", GALLIVM_DEBUG_ASM, NULL }, + { "perf", GALLIVM_DEBUG_PERF, NULL }, + { "gc", GALLIVM_DEBUG_GC, NULL }, -+/* Don't allow setting DUMP_BC for release builds, since writing the files may be an issue with setuid. */ -+#ifdef DEBUG + { "dumpbc", GALLIVM_DEBUG_DUMP_BC, NULL }, -+#endif + DEBUG_NAMED_VALUE_END +}; + @@ -658,6 +597,8 @@ index 00000000000..b245edc5586 + +namespace { + ++class LPJit; ++ +class LLVMEnsureMultithreaded { +public: + LLVMEnsureMultithreaded() @@ -825,15 +766,15 @@ index 00000000000..b245edc5586 +#endif +}; + ++LPJit* LPJit::jit = NULL; ++ +LLVMErrorRef module_transform(void *Ctx, LLVMModuleRef mod) { + int64_t time_begin = 0; -+ if (gallivm_debug & GALLIVM_DEBUG_PERF) ++ if (::gallivm_debug & GALLIVM_DEBUG_PERF) + time_begin = os_time_get(); -+ +#if GALLIVM_USE_NEW_PASS == 1 + char passes[1024]; + passes[0] = 0; -+ LLVMTargetMachineRef tm = LPJit::get_instance()->tm; + + /* + * there should be some way to combine these two pass runs but I'm not seeing it, @@ -842,16 +783,18 @@ index 00000000000..b245edc5586 + strcpy(passes, "default"); + + LLVMPassBuilderOptionsRef opts = LLVMCreatePassBuilderOptions(); -+ LLVMRunPasses(mod, passes, tm, opts); ++ LLVMRunPasses(mod, passes, LPJit::get_instance()->tm, opts); + + if (!(gallivm_perf & GALLIVM_PERF_NO_OPT)) -+ strcpy(passes, "sroa,early-cse,simplifycfg,reassociate,mem2reg,instsimplify,instcombine"); ++ strcpy(passes, "sroa,early-cse,simplifycfg,reassociate,mem2reg,constprop,instcombine,"); + else + strcpy(passes, "mem2reg"); + -+ LLVMRunPasses(mod, passes, tm, opts); ++ LLVMRunPasses(mod, passes, LPJit::get_instance()->tm, opts); + LLVMDisposePassBuilderOptions(opts); + ++ return LLVMErrorSuccess; ++ +#else /* GALLIVM_USE_NEW_PASS */ + LLVMPassManagerRef passmgr = LLVMCreateFunctionPassManagerForModule(mod); + @@ -860,7 +803,7 @@ index 00000000000..b245edc5586 +#endif + +#if GALLIVM_HAVE_CORO == 1 -+#if LLVM_VERSION_MAJOR <= 8 && (DETECT_ARCH_AARCH64 || DETECT_ARCH_ARM || DETECT_ARCH_S390 || DETECT_ARCH_MIPS64) ++#if LLVM_VERSION_MAJOR <= 8 && (defined(PIPE_ARCH_AARCH64) || defined (PIPE_ARCH_ARM) || defined(PIPE_ARCH_S390) || defined(PIPE_ARCH_MIPS64)) + LLVMAddArgumentPromotionPass(cgpassmgr); + LLVMAddFunctionAttrsPass(cgpassmgr); +#endif @@ -922,7 +865,7 @@ index 00000000000..b245edc5586 + + /* Disable frame pointer omission on debug/profile builds */ + /* XXX: And workaround http://llvm.org/PR21435 */ -+#if defined(DEBUG) || defined(PROFILE) || DETECT_ARCH_X86 || DETECT_ARCH_X86_64 ++#if defined(DEBUG) || defined(PROFILE) || defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) + LLVMAddTargetDependentFunctionAttr(func, "no-frame-pointer-elim", "true"); + LLVMAddTargetDependentFunctionAttr(func, "no-frame-pointer-elim-non-leaf", "true"); +#endif @@ -931,11 +874,6 @@ index 00000000000..b245edc5586 + func = LLVMGetNextFunction(func); + } + LLVMFinalizeFunctionPassManager(passmgr); -+#if GALLIVM_HAVE_CORO == 1 -+ LLVMDisposePassManager(cgpassmgr); -+#endif -+ LLVMDisposePassManager(passmgr); -+#endif /* GALLIVM_USE_NEW_PASS */ + if (gallivm_debug & GALLIVM_DEBUG_PERF) { + int64_t time_end = os_time_get(); + int time_msec = (int)((time_end - time_begin) / 1000); @@ -945,7 +883,12 @@ index 00000000000..b245edc5586 + module_name, time_msec); + } + ++#if GALLIVM_HAVE_CORO == 1 ++ LLVMDisposePassManager(cgpassmgr); ++#endif ++ LLVMDisposePassManager(passmgr); + return LLVMErrorSuccess; ++#endif /* GALLIVM_USE_NEW_PASS */ +} + +LLVMErrorRef module_transform_wrapper( @@ -954,11 +897,11 @@ index 00000000000..b245edc5586 + return LLVMOrcThreadSafeModuleWithModuleDo(*ModInOut, *module_transform, Ctx); +} + -+LPJit* LPJit::jit = NULL; -+ +LPJit::LPJit() :jit_dylib_count(0) { + using namespace llvm::orc; -+ gallivm_debug = debug_get_option_gallivm_debug(); ++#ifdef DEBUG ++ ::gallivm_debug = debug_get_option_gallivm_debug(); ++#endif + + gallivm_perf = debug_get_flags_option("GALLIVM_PERF", lp_bld_perf_flags, 0 ); + @@ -1009,7 +952,7 @@ index 00000000000..b245edc5586 + for (n = 0, option = strtok(env_llc_options, " "); option; n++, option = strtok(NULL, " ")) { + options[n + 1] = option; + } -+ if (gallivm_debug & (GALLIVM_DEBUG_IR | GALLIVM_DEBUG_ASM | GALLIVM_DEBUG_DUMP_BC)) { ++ if (::gallivm_debug & (GALLIVM_DEBUG_IR | GALLIVM_DEBUG_ASM | GALLIVM_DEBUG_DUMP_BC)) { + debug_printf("llc additional options (%d):\n", n); + for (int i = 1; i <= n; i++) + debug_printf("\t%s\n", options[i]); @@ -1018,6 +961,20 @@ index 00000000000..b245edc5586 + LLVMParseCommandLineOptions(n + 1, options, NULL); + } + } ++ ++ /* For simulating less capable machines */ ++ if (debug_get_bool_option("LP_FORCE_SSE2", false)) { ++ extern struct util_cpu_caps_t util_cpu_caps; ++ assert(util_cpu_caps.has_sse2); ++ util_cpu_caps.has_sse3 = 0; ++ util_cpu_caps.has_ssse3 = 0; ++ util_cpu_caps.has_sse4_1 = 0; ++ util_cpu_caps.has_sse4_2 = 0; ++ util_cpu_caps.has_avx = 0; ++ util_cpu_caps.has_avx2 = 0; ++ util_cpu_caps.has_f16c = 0; ++ util_cpu_caps.has_fma = 0; ++ } +#endif + + if (util_get_cpu_caps()->has_avx2 || util_get_cpu_caps()->has_avx) { @@ -1029,7 +986,26 @@ index 00000000000..b245edc5586 + ::lp_native_vector_width = 128; + } + -+#if DETECT_ARCH_PPC_64 ++ ::lp_native_vector_width = debug_get_num_option("LP_NATIVE_VECTOR_WIDTH", ++ lp_native_vector_width); ++ ++#if LLVM_VERSION_MAJOR < 4 ++ if (::lp_native_vector_width <= 128) { ++ /* Hide AVX support, as often LLVM AVX intrinsics are only guarded by ++ * "util_get_cpu_caps()->has_avx" predicate, and lack the ++ * "lp_native_vector_width > 128" predicate. And also to ensure a more ++ * consistent behavior, allowing one to test SSE2 on AVX machines. ++ * XXX: should not play games with util_cpu_caps directly as it might ++ * get used for other things outside llvm too. ++ */ ++ util_get_cpu_caps()->has_avx = 0; ++ util_get_cpu_caps()->has_avx2 = 0; ++ util_get_cpu_caps()->has_f16c = 0; ++ util_get_cpu_caps()->has_fma = 0; ++ } ++#endif ++ ++#ifdef PIPE_ARCH_PPC_64 + /* Set the NJ bit in VSCR to 0 so denormalized values are handled as + * specified by IEEE standard (PowerISA 2.06 - Section 6.3). This guarantees + * that some rounding and half-float to float handling does not round @@ -1082,7 +1058,7 @@ index 00000000000..b245edc5586 + * LLVM 3.1+ haven't more "extern unsigned llvm::StackAlignmentOverride" and + * friends for configuring code generation options, like stack alignment. + */ -+#if DETECT_ARCH_X86 && LLVM_VERSION_MAJOR < 13 ++#if defined(PIPE_ARCH_X86) && LLVM_VERSION_MAJOR < 13 + options.StackAlignmentOverride = 4; +#endif + @@ -1090,7 +1066,7 @@ index 00000000000..b245edc5586 + + std::vector MAttrs; + -+#if LLVM_VERSION_MAJOR >= 4 && (DETECT_ARCH_X86 || DETECT_ARCH_X86_64 || DETECT_ARCH_ARM) ++#if LLVM_VERSION_MAJOR >= 4 && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) || defined(PIPE_ARCH_ARM)) + /* llvm-3.3+ implements sys::getHostCPUFeatures for Arm + * and llvm-3.7+ for x86, which allows us to enable/disable + * code generation based on the results of cpuid on these @@ -1104,7 +1080,7 @@ index 00000000000..b245edc5586 + ++f) { + MAttrs.push_back(((*f).second ? "+" : "-") + (*f).first().str()); + } -+#elif DETECT_ARCH_X86 || DETECT_ARCH_X86_64 ++#elif defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) + /* + * We need to unset attributes because sometimes LLVM mistakenly assumes + * certain features are present given the processor name. @@ -1139,7 +1115,7 @@ index 00000000000..b245edc5586 + MAttrs.push_back("-avx512dq"); + MAttrs.push_back("-avx512vl"); +#endif -+#if DETECT_ARCH_ARM ++#if defined(PIPE_ARCH_ARM) + if (!util_get_cpu_caps()->has_neon) { + MAttrs.push_back("-neon"); + MAttrs.push_back("-crypto"); @@ -1147,7 +1123,7 @@ index 00000000000..b245edc5586 + } +#endif + -+#if DETECT_ARCH_PPC ++#if defined(PIPE_ARCH_PPC) + MAttrs.push_back(util_get_cpu_caps()->has_altivec ? "+altivec" : "-altivec"); +#if (LLVM_VERSION_MAJOR < 4) + /* @@ -1178,7 +1154,7 @@ index 00000000000..b245edc5586 +#endif +#endif + -+#if DETECT_ARCH_MIPS64 ++#if defined(PIPE_ARCH_MIPS64) + MAttrs.push_back(util_get_cpu_caps()->has_msa ? "+msa" : "-msa"); + /* MSA requires a 64-bit FPU register file */ + MAttrs.push_back("+fp64"); @@ -1186,7 +1162,7 @@ index 00000000000..b245edc5586 + + JTMB.addFeatures(MAttrs); + -+ if (gallivm_debug & (GALLIVM_DEBUG_IR | GALLIVM_DEBUG_ASM | GALLIVM_DEBUG_DUMP_BC)) { ++ if (::gallivm_debug & (GALLIVM_DEBUG_IR | GALLIVM_DEBUG_ASM | GALLIVM_DEBUG_DUMP_BC)) { + int n = MAttrs.size(); + if (n > 0) { + debug_printf("llc -mattr option(s): "); @@ -1212,7 +1188,7 @@ index 00000000000..b245edc5586 + * manually since we don't use JITTargetMachineBuilder::detectHost() + */ + -+#if DETECT_ARCH_PPC_64 ++#ifdef PIPE_ARCH_PPC_64 + /* + * Large programs, e.g. gnome-shell and firefox, may tax the addressability + * of the Medium code model once dynamically generated JIT-compiled shader @@ -1239,7 +1215,7 @@ index 00000000000..b245edc5586 +#endif +#endif + -+#if DETECT_ARCH_MIPS64 ++#if defined(PIPE_ARCH_MIPS64) + /* + * ls3a4000 CPU and ls2k1000 SoC is a mips64r5 compatible with MSA SIMD + * instruction set implemented, while ls3a3000 is mips64r2 compatible @@ -1275,15 +1251,14 @@ index 00000000000..b245edc5586 + return lp_native_vector_width; +} + -+boolean ++bool +lp_build_init(void) +{ -+ lp_build_init_native_width(); + (void)LPJit::get_instance(); -+ return TRUE; ++ return true; +} + -+boolean ++bool +init_gallivm_state(struct gallivm_state *gallivm, const char *name, + LLVMOrcThreadSafeContextRef context, struct lp_cached_code *cache) +{ @@ -1292,7 +1267,7 @@ index 00000000000..b245edc5586 + assert(!gallivm->module); + + if (!lp_build_init()) -+ return FALSE; ++ return false; + + // cache is not implemented + gallivm->cache = cache; @@ -1305,7 +1280,7 @@ index 00000000000..b245edc5586 + gallivm->module_name = LPJit::get_unique_name(name); + gallivm->module = LLVMModuleCreateWithNameInContext(gallivm->module_name, + gallivm->context); -+#if DETECT_ARCH_X86 ++#if defined(PIPE_ARCH_X86) + lp_set_module_stack_alignment_override(gallivm->module, 4); +#endif + gallivm->builder = LLVMCreateBuilderInContext(gallivm->context); @@ -1313,9 +1288,7 @@ index 00000000000..b245edc5586 + + gallivm->target = LLVMCreateTargetDataLayout(LPJit::get_instance()->tm); + -+ lp_build_coro_declare_malloc_hooks(gallivm); -+ -+ return TRUE; ++ return true; +} + +struct gallivm_state * @@ -1384,7 +1357,7 @@ index 00000000000..b245edc5586 + lp_debug_dump_value(func); + debug_printf("\n"); + } -+ return; ++return; +} + +void @@ -1405,13 +1378,9 @@ index 00000000000..b245edc5586 +void +gallivm_compile_module(struct gallivm_state *gallivm) +{ -+ lp_init_printf_hook(gallivm); -+ gallivm_add_global_mapping(gallivm, gallivm->debug_printf_hook, (void *)debug_printf); -+ -+ lp_init_clock_hook(gallivm); -+ gallivm_add_global_mapping(gallivm, gallivm->get_time_hook, (void *)os_time_get_nano); -+ -+ lp_build_coro_add_malloc_hooks(gallivm); ++ if (gallivm->debug_printf_hook) ++ gallivm_add_global_mapping(gallivm, gallivm->debug_printf_hook, ++ (void *)debug_printf); + + LPJit::add_ir_module_to_jd(gallivm->_ts_context, gallivm->module, + gallivm->_per_module_jd); @@ -1446,10 +1415,10 @@ index 00000000000..b245edc5586 +#endif +} diff --git a/src/gallium/auxiliary/meson.build b/src/gallium/auxiliary/meson.build -index 3d7ec917e49..e65417da18c 100644 +index 4be71a4..c3fea24 100644 --- a/src/gallium/auxiliary/meson.build +++ b/src/gallium/auxiliary/meson.build -@@ -335,7 +335,7 @@ if draw_with_llvm +@@ -343,7 +343,7 @@ if draw_with_llvm 'gallivm/lp_bld_gather.c', 'gallivm/lp_bld_gather.h', 'gallivm/lp_bld.h', @@ -1459,11 +1428,22 @@ index 3d7ec917e49..e65417da18c 100644 'gallivm/lp_bld_intr.c', 'gallivm/lp_bld_intr.h', diff --git a/src/gallium/drivers/llvmpipe/lp_context.c b/src/gallium/drivers/llvmpipe/lp_context.c -index 301a132c9c0..9dd2e857c9c 100644 +index 8e5e8ce..cbb442b 100644 --- a/src/gallium/drivers/llvmpipe/lp_context.c +++ b/src/gallium/drivers/llvmpipe/lp_context.c -@@ -100,7 +100,11 @@ llvmpipe_destroy(struct pipe_context *pipe) - lp_delete_setup_variants(llvmpipe); +@@ -49,6 +49,10 @@ + #include "lp_screen.h" + #include "lp_fence.h" + ++#if ! (GALLIVM_USE_ORCJIT == 1) ++#define USE_GLOBAL_LLVM_CONTEXT ++#endif ++ + static void + llvmpipe_destroy(struct pipe_context *pipe) + { +@@ -108,7 +112,11 @@ llvmpipe_destroy(struct pipe_context *pipe) + llvmpipe_sampler_matrix_destroy(llvmpipe); #ifndef USE_GLOBAL_LLVM_CONTEXT +#if GALLIVM_USE_ORCJIT == 1 @@ -1474,7 +1454,7 @@ index 301a132c9c0..9dd2e857c9c 100644 #endif llvmpipe->context = NULL; -@@ -246,15 +250,25 @@ llvmpipe_create_context(struct pipe_screen *screen, void *priv, +@@ -258,15 +266,25 @@ llvmpipe_create_context(struct pipe_screen *screen, void *priv, #ifdef USE_GLOBAL_LLVM_CONTEXT llvmpipe->context = LLVMGetGlobalContext(); @@ -1489,22 +1469,23 @@ index 301a132c9c0..9dd2e857c9c 100644 if (!llvmpipe->context) goto fail; +-#if LLVM_VERSION_MAJOR == 15 +#if GALLIVM_USE_ORCJIT == 1 -+#if LLVM_VERSION_MAJOR == 15 ++#if LLVM_VERSION_MAJOR >= 15 + LLVMContextSetOpaquePointers(LLVMOrcThreadSafeContextGetContext(llvmpipe->context), false); +#endif +#else - #if LLVM_VERSION_MAJOR == 15 ++#if LLVM_VERSION_MAJOR >= 15 LLVMContextSetOpaquePointers(llvmpipe->context, false); +#endif #endif /* diff --git a/src/gallium/drivers/llvmpipe/lp_context.h b/src/gallium/drivers/llvmpipe/lp_context.h -index 95e9a1e9709..a64e7620bde 100644 +index 7dd6a3f..d30aa89 100644 --- a/src/gallium/drivers/llvmpipe/lp_context.h +++ b/src/gallium/drivers/llvmpipe/lp_context.h -@@ -181,7 +181,11 @@ struct llvmpipe_context { +@@ -190,7 +190,11 @@ struct llvmpipe_context { unsigned render_cond_offset; /** The LLVMContext to use for LLVM related work */ @@ -1517,10 +1498,10 @@ index 95e9a1e9709..a64e7620bde 100644 int max_global_buffers; struct pipe_resource **global_buffers; diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c -index 9b623372d4e..d03e732d582 100644 +index bd6379d..91bd065 100644 --- a/src/gallium/drivers/llvmpipe/lp_screen.c +++ b/src/gallium/drivers/llvmpipe/lp_screen.c -@@ -935,7 +935,11 @@ static void +@@ -942,7 +942,11 @@ static void lp_disk_cache_create(struct llvmpipe_screen *screen) { struct mesa_sha1 ctx; @@ -1533,10 +1514,10 @@ index 9b623372d4e..d03e732d582 100644 char cache_id[20 * 2 + 1]; _mesa_sha1_init(&ctx); diff --git a/src/gallium/drivers/llvmpipe/lp_state_cs.c b/src/gallium/drivers/llvmpipe/lp_state_cs.c -index 1f005cef46d..37c8224ebd8 100644 +index 97c094c..f7f4cbd 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_cs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_cs.c -@@ -139,6 +139,10 @@ generate_compute(struct llvmpipe_context *lp, +@@ -404,6 +404,10 @@ generate_compute(struct llvmpipe_context *lp, lp_build_coro_add_presplit(coro); variant->function = function; @@ -1545,9 +1526,9 @@ index 1f005cef46d..37c8224ebd8 100644 + strcpy(variant->function_name, func_name); +#endif - for (i = 0; i < ARRAY_SIZE(arg_types); ++i) { + for (i = 0; i < CS_ARG_MAX - !is_mesh; ++i) { if (LLVMGetTypeKind(arg_types[i]) == LLVMPointerTypeKind) { -@@ -590,6 +594,10 @@ llvmpipe_remove_cs_shader_variant(struct llvmpipe_context *lp, +@@ -957,6 +961,10 @@ llvmpipe_remove_cs_shader_variant(struct llvmpipe_context *lp, lp->nr_cs_variants--; lp->nr_cs_instrs -= variant->nr_instrs; @@ -1558,7 +1539,7 @@ index 1f005cef46d..37c8224ebd8 100644 FREE(variant); } -@@ -839,12 +847,23 @@ generate_variant(struct llvmpipe_context *lp, +@@ -1222,12 +1230,23 @@ generate_variant(struct llvmpipe_context *lp, generate_compute(lp, shader, variant); @@ -1583,12 +1564,12 @@ index 1f005cef46d..37c8224ebd8 100644 if (needs_caching) { lp_disk_cache_insert_shader(screen, &cached, ir_sha1_cache_key); diff --git a/src/gallium/drivers/llvmpipe/lp_state_cs.h b/src/gallium/drivers/llvmpipe/lp_state_cs.h -index 0a19d745c44..d569198cd61 100644 +index 855f195..26b6e87 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_cs.h +++ b/src/gallium/drivers/llvmpipe/lp_state_cs.h -@@ -85,6 +85,9 @@ struct lp_compute_shader_variant - LLVMTypeRef jit_cs_thread_data_ptr_type; - +@@ -91,6 +91,9 @@ struct lp_compute_shader_variant + LLVMTypeRef jit_vertex_header_ptr_type; + LLVMTypeRef jit_prim_type; LLVMValueRef function; +#if GALLIVM_USE_ORCJIT == 1 + char* function_name; @@ -1597,10 +1578,10 @@ index 0a19d745c44..d569198cd61 100644 /* Total number of LLVM instructions generated */ diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c -index ac55f8e3d69..2a5977134b0 100644 +index 78c3b25..4e0b693 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c -@@ -3205,6 +3205,10 @@ generate_fragment(struct llvmpipe_context *lp, +@@ -3217,6 +3217,10 @@ generate_fragment(struct llvmpipe_context *lp, LLVMSetFunctionCallConv(function, LLVMCCallConv); variant->function[partial_mask] = function; @@ -1611,7 +1592,7 @@ index ac55f8e3d69..2a5977134b0 100644 /* XXX: need to propagate noalias down into color param now we are * passing a pointer-to-pointer? -@@ -3908,20 +3912,37 @@ generate_variant(struct llvmpipe_context *lp, +@@ -3926,20 +3930,37 @@ generate_variant(struct llvmpipe_context *lp, * Compile everything */ @@ -1649,7 +1630,7 @@ index ac55f8e3d69..2a5977134b0 100644 } else if (!variant->jit_function[RAST_WHOLE]) { variant->jit_function[RAST_WHOLE] = (lp_jit_frag_func) variant->jit_function[RAST_EDGE_TEST]; -@@ -3930,7 +3951,11 @@ generate_variant(struct llvmpipe_context *lp, +@@ -3948,7 +3969,11 @@ generate_variant(struct llvmpipe_context *lp, if (linear_pipeline) { if (variant->linear_function) { variant->jit_linear_llvm = (lp_jit_linear_llvm_func) @@ -1661,7 +1642,7 @@ index ac55f8e3d69..2a5977134b0 100644 } /* -@@ -4115,6 +4140,14 @@ llvmpipe_destroy_shader_variant(struct llvmpipe_context *lp, +@@ -4136,6 +4161,14 @@ llvmpipe_destroy_shader_variant(struct llvmpipe_context *lp, { gallivm_destroy(variant->gallivm); lp_fs_reference(lp, &variant->shader, NULL); @@ -1677,10 +1658,10 @@ index ac55f8e3d69..2a5977134b0 100644 } diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.h b/src/gallium/drivers/llvmpipe/lp_state_fs.h -index 797d46b0484..57565a3e300 100644 +index 023b7e8..fff6ebe 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.h +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.h -@@ -184,6 +184,9 @@ struct lp_fragment_shader_variant +@@ -169,6 +169,9 @@ struct lp_fragment_shader_variant LLVMTypeRef jit_linear_textures_type; LLVMValueRef function[2]; // [RAST_WHOLE], [RAST_EDGE_TEST] @@ -1690,7 +1671,7 @@ index 797d46b0484..57565a3e300 100644 lp_jit_frag_func jit_function[2]; // [RAST_WHOLE], [RAST_EDGE_TEST] -@@ -193,6 +196,9 @@ struct lp_fragment_shader_variant +@@ -178,6 +181,9 @@ struct lp_fragment_shader_variant /* Functions within the linear path: */ LLVMValueRef linear_function; @@ -1701,10 +1682,10 @@ index 797d46b0484..57565a3e300 100644 /* Bitmask to say what cbufs are unswizzled */ diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs_linear_llvm.c b/src/gallium/drivers/llvmpipe/lp_state_fs_linear_llvm.c -index 0136632dfdf..5e06342379b 100644 +index 8d94691..54d8554 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs_linear_llvm.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs_linear_llvm.c -@@ -297,6 +297,10 @@ llvmpipe_fs_variant_linear_llvm(struct llvmpipe_context *lp, +@@ -298,6 +298,10 @@ llvmpipe_fs_variant_linear_llvm(struct llvmpipe_context *lp, LLVMSetFunctionCallConv(function, LLVMCCallConv); variant->linear_function = function; @@ -1716,7 +1697,7 @@ index 0136632dfdf..5e06342379b 100644 /* XXX: need to propagate noalias down into color param now we are * passing a pointer-to-pointer? diff --git a/src/gallium/drivers/llvmpipe/lp_state_setup.c b/src/gallium/drivers/llvmpipe/lp_state_setup.c -index 3b2438fab04..cba6ee197b5 100644 +index a4900e6..99afcd5 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_state_setup.c @@ -687,6 +687,10 @@ generate_setup_variant(struct lp_setup_variant_key *key, @@ -1745,7 +1726,7 @@ index 3b2438fab04..cba6ee197b5 100644 goto fail; diff --git a/src/gallium/drivers/llvmpipe/lp_state_setup.h b/src/gallium/drivers/llvmpipe/lp_state_setup.h -index 3199cb5c92e..0633775f48b 100644 +index ef20893..1e9c6db 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_setup.h +++ b/src/gallium/drivers/llvmpipe/lp_state_setup.h @@ -66,6 +66,9 @@ struct lp_setup_variant { @@ -1759,7 +1740,7 @@ index 3199cb5c92e..0633775f48b 100644 /* The actual generated setup function: */ diff --git a/src/gallium/drivers/llvmpipe/lp_test_arit.c b/src/gallium/drivers/llvmpipe/lp_test_arit.c -index 05db2131479..86e876364d5 100644 +index fd8489f..fe192f5 100644 --- a/src/gallium/drivers/llvmpipe/lp_test_arit.c +++ b/src/gallium/drivers/llvmpipe/lp_test_arit.c @@ -417,7 +417,11 @@ test_unary(unsigned verbose, FILE *fp, const struct unary_test_t *test, unsigned @@ -1780,7 +1761,7 @@ index 05db2131479..86e876364d5 100644 +#if GALLIVM_USE_ORCJIT == 1 + context = LLVMOrcCreateNewThreadSafeContext(); -+#if LLVM_VERSION_MAJOR == 15 ++#if LLVM_VERSION_MAJOR >= 15 + LLVMContextSetOpaquePointers(LLVMOrcThreadSafeContextGetContext(context), false); +#endif +#else @@ -1816,7 +1797,7 @@ index 05db2131479..86e876364d5 100644 align_free(in); align_free(out); diff --git a/src/gallium/drivers/llvmpipe/lp_test_blend.c b/src/gallium/drivers/llvmpipe/lp_test_blend.c -index daab0ef2d4a..1a79b25b616 100644 +index 7851bf2..f066a68 100644 --- a/src/gallium/drivers/llvmpipe/lp_test_blend.c +++ b/src/gallium/drivers/llvmpipe/lp_test_blend.c @@ -131,16 +131,24 @@ dump_blend_type(FILE *fp, @@ -1881,7 +1862,7 @@ index daab0ef2d4a..1a79b25b616 100644 LLVMValueRef func = NULL; +#endif blend_test_ptr_t blend_test_ptr; - boolean success; + bool success; const unsigned n = LP_TEST_NUM_SAMPLES; @@ -451,9 +471,16 @@ test_one(unsigned verbose, if (verbose >= 1) @@ -1889,7 +1870,7 @@ index daab0ef2d4a..1a79b25b616 100644 +#if GALLIVM_USE_ORCJIT == 1 + context = LLVMOrcCreateNewThreadSafeContext(); -+#if LLVM_VERSION_MAJOR == 15 ++#if LLVM_VERSION_MAJOR >= 15 + LLVMContextSetOpaquePointers(LLVMOrcThreadSafeContextGetContext(context), false); +#endif +#else @@ -1913,7 +1894,7 @@ index daab0ef2d4a..1a79b25b616 100644 return success; } diff --git a/src/gallium/drivers/llvmpipe/lp_test_conv.c b/src/gallium/drivers/llvmpipe/lp_test_conv.c -index ad95a36fb42..4282b9cb18d 100644 +index 9fb6448..ac14185 100644 --- a/src/gallium/drivers/llvmpipe/lp_test_conv.c +++ b/src/gallium/drivers/llvmpipe/lp_test_conv.c @@ -96,16 +96,24 @@ dump_conv_types(FILE *fp, @@ -1978,7 +1959,7 @@ index ad95a36fb42..4282b9cb18d 100644 LLVMValueRef func = NULL; +#endif conv_test_ptr_t conv_test_ptr; - boolean success; + bool success; const unsigned n = LP_TEST_NUM_SAMPLES; @@ -222,9 +242,16 @@ test_one(unsigned verbose, eps *= 2; @@ -1986,7 +1967,7 @@ index ad95a36fb42..4282b9cb18d 100644 +#if GALLIVM_USE_ORCJIT == 1 + context = LLVMOrcCreateNewThreadSafeContext(); -+#if LLVM_VERSION_MAJOR == 15 ++#if LLVM_VERSION_MAJOR >= 15 + LLVMContextSetOpaquePointers(LLVMOrcThreadSafeContextGetContext(context), false); +#endif +#else @@ -2010,7 +1991,7 @@ index ad95a36fb42..4282b9cb18d 100644 return success; } diff --git a/src/gallium/drivers/llvmpipe/lp_test_format.c b/src/gallium/drivers/llvmpipe/lp_test_format.c -index f1531879cc9..370649754ef 100644 +index 6d3a60b..81d0753 100644 --- a/src/gallium/drivers/llvmpipe/lp_test_format.c +++ b/src/gallium/drivers/llvmpipe/lp_test_format.c @@ -79,9 +79,9 @@ static LLVMValueRef @@ -2050,12 +2031,12 @@ index f1531879cc9..370649754ef 100644 alignas(16) uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; alignas(16) float unpacked[4]; @@ -149,18 +154,29 @@ test_format_float(unsigned verbose, FILE *fp, - boolean success = TRUE; + bool success = true; unsigned i, j, k, l; +#if GALLIVM_USE_ORCJIT == 1 + context = LLVMOrcCreateNewThreadSafeContext(); -+#if LLVM_VERSION_MAJOR == 15 ++#if LLVM_VERSION_MAJOR >= 15 + LLVMContextSetOpaquePointers(LLVMOrcThreadSafeContextGetContext(context), false); +#endif +#else @@ -2108,12 +2089,12 @@ index f1531879cc9..370649754ef 100644 alignas(16) uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; uint8_t unpacked[4]; @@ -253,18 +278,29 @@ test_format_unorm8(unsigned verbose, FILE *fp, - boolean success = TRUE; + bool success = true; unsigned i, j, k, l; +#if GALLIVM_USE_ORCJIT == 1 + context = LLVMOrcCreateNewThreadSafeContext(); -+#if LLVM_VERSION_MAJOR == 15 ++#if LLVM_VERSION_MAJOR >= 15 + LLVMContextSetOpaquePointers(LLVMOrcThreadSafeContextGetContext(context), false); +#endif +#else @@ -2152,10 +2133,10 @@ index f1531879cc9..370649754ef 100644 write_tsv_row(fp, desc, success); diff --git a/src/gallium/drivers/llvmpipe/lp_test_lookup_multiple.c b/src/gallium/drivers/llvmpipe/lp_test_lookup_multiple.c new file mode 100644 -index 00000000000..8f820c820d2 +index 0000000..2acb339 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_test_lookup_multiple.c -@@ -0,0 +1,173 @@ +@@ -0,0 +1,172 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. @@ -2244,8 +2225,7 @@ index 00000000000..8f820c820d2 +} + + -+UTIL_ALIGN_STACK -+static boolean ++static bool +test_lookup_multiple(unsigned verbose, FILE *fp, + const struct printf_test_case *testcase) +{ @@ -2254,17 +2234,17 @@ index 00000000000..8f820c820d2 + LLVMValueRef func[N]; + char func_name[N][64]; + test_printf_t test_lookup_multiple_func[N]; -+ boolean success = TRUE; ++ bool success = true; + int i; + +#if GALLIVM_USE_ORCJIT == 1 + LLVMOrcThreadSafeContextRef context = LLVMOrcCreateNewThreadSafeContext(); -+#if LLVM_VERSION_MAJOR == 15 ++#if LLVM_VERSION_MAJOR >= 15 + LLVMContextSetOpaquePointers(LLVMOrcThreadSafeContextGetContext(context), false); +#endif +#else + LLVMContextRef context = LLVMContextCreate(); -+#if LLVM_VERSION_MAJOR == 15 ++#if LLVM_VERSION_MAJOR >= 15 + LLVMContextSetOpaquePointers(context, false); +#endif +#endif @@ -2304,10 +2284,10 @@ index 00000000000..8f820c820d2 +} + + -+boolean ++bool +test_all(unsigned verbose, FILE *fp) +{ -+ boolean success = TRUE; ++ bool success = true; + + test_lookup_multiple(verbose, fp, NULL); + @@ -2315,7 +2295,7 @@ index 00000000000..8f820c820d2 +} + + -+boolean ++bool +test_some(unsigned verbose, FILE *fp, + unsigned long n) +{ @@ -2323,14 +2303,14 @@ index 00000000000..8f820c820d2 +} + + -+boolean ++bool +test_single(unsigned verbose, FILE *fp) +{ + printf("no test_single()"); -+ return TRUE; ++ return true; +} diff --git a/src/gallium/drivers/llvmpipe/lp_test_printf.c b/src/gallium/drivers/llvmpipe/lp_test_printf.c -index ee9299b1cfa..eaf8b261f66 100644 +index 7e53aa5..fb2a684 100644 --- a/src/gallium/drivers/llvmpipe/lp_test_printf.c +++ b/src/gallium/drivers/llvmpipe/lp_test_printf.c @@ -57,12 +57,18 @@ write_tsv_header(FILE *fp) @@ -2365,7 +2345,7 @@ index ee9299b1cfa..eaf8b261f66 100644 } -@@ -89,15 +99,30 @@ static boolean +@@ -89,15 +99,30 @@ static bool test_printf(unsigned verbose, FILE *fp, const struct printf_test_case *testcase) { @@ -2381,11 +2361,11 @@ index ee9299b1cfa..eaf8b261f66 100644 LLVMValueRef test; +#endif test_printf_t test_printf_func; - boolean success = TRUE; + bool success = true; +#if GALLIVM_USE_ORCJIT == 1 + context = LLVMOrcCreateNewThreadSafeContext(); -+#if LLVM_VERSION_MAJOR == 15 ++#if LLVM_VERSION_MAJOR >= 15 + LLVMContextSetOpaquePointers(LLVMOrcThreadSafeContextGetContext(context), false); +#endif +#else @@ -2408,11 +2388,71 @@ index ee9299b1cfa..eaf8b261f66 100644 return success; } +diff --git a/src/gallium/drivers/llvmpipe/lp_texture_handle.c b/src/gallium/drivers/llvmpipe/lp_texture_handle.c +index 9bb8f22..bfd1134 100644 +--- a/src/gallium/drivers/llvmpipe/lp_texture_handle.c ++++ b/src/gallium/drivers/llvmpipe/lp_texture_handle.c +@@ -200,11 +200,19 @@ llvmpipe_sampler_matrix_destroy(struct llvmpipe_context *ctx) + util_dynarray_fini(&ctx->sampler_matrix.gallivms); + } + ++#if GALLIVM_USE_ORCJIT == 1 ++static void * ++compile_function(struct llvmpipe_context *ctx, struct gallivm_state *gallivm, LLVMValueRef function_ref, const char *function, ++ uint8_t cache_key[SHA1_DIGEST_LENGTH]) ++{ ++ gallivm_verify_function(gallivm, function_ref); ++#else + static void * + compile_function(struct llvmpipe_context *ctx, struct gallivm_state *gallivm, LLVMValueRef function, + uint8_t cache_key[SHA1_DIGEST_LENGTH]) + { + gallivm_verify_function(gallivm, function); ++#endif + gallivm_compile_module(gallivm); + + void *function_ptr = func_to_pointer(gallivm_jit_function(gallivm, function)); +@@ -333,7 +341,11 @@ compile_image_function(struct llvmpipe_context *ctx, struct lp_static_texture_st + + free(image_soa); + ++#if GALLIVM_USE_ORCJIT == 1 ++ return compile_function(ctx, gallivm, function, "image", cache_key); ++#else + return compile_function(ctx, gallivm, function, cache_key); ++#endif + } + + static void * +@@ -471,7 +483,11 @@ compile_sample_function(struct llvmpipe_context *ctx, struct lp_static_texture_s + + free(sampler_soa); + ++#if GALLIVM_USE_ORCJIT == 1 ++ return compile_function(ctx, gallivm, function, "sample", cache_key); ++#else + return compile_function(ctx, gallivm, function, cache_key); ++#endif + } + + static void * +@@ -551,7 +567,11 @@ compile_size_function(struct llvmpipe_context *ctx, struct lp_static_texture_sta + + free(sampler_soa); + ++#if GALLIVM_USE_ORCJIT == 1 ++ return compile_function(ctx, gallivm, function, "size", cache_key); ++#else + return compile_function(ctx, gallivm, function, cache_key); ++#endif + } + + static void diff --git a/src/gallium/drivers/llvmpipe/meson.build b/src/gallium/drivers/llvmpipe/meson.build -index 1fd527e0313..7083c641c8a 100644 +index 38ff889..d405c67 100644 --- a/src/gallium/drivers/llvmpipe/meson.build +++ b/src/gallium/drivers/llvmpipe/meson.build -@@ -129,7 +129,7 @@ driver_swrast = declare_dependency( +@@ -132,7 +132,7 @@ driver_swrast = declare_dependency( if with_tests and with_gallium_softpipe and draw_with_llvm foreach t : ['lp_test_format', 'lp_test_arit', 'lp_test_blend', @@ -2421,6 +2461,3 @@ index 1fd527e0313..7083c641c8a 100644 test( t, executable( --- -2.41.0 - diff --git a/llvmpipe-add-riscv-support-in-orcjit.patch b/llvmpipe-add-riscv-support-in-orcjit.patch index f20b092471a22b3e991f5c166186204420528ae1..f10c12046de9194df577503289cfa68de34af268 100644 --- a/llvmpipe-add-riscv-support-in-orcjit.patch +++ b/llvmpipe-add-riscv-support-in-orcjit.patch @@ -1,32 +1,28 @@ -From 337f91f990070b6a3251550c682fec5ffcce478c Mon Sep 17 00:00:00 2001 +From b4cc97ac05b70fa328ad57cf6defee8113666cac Mon Sep 17 00:00:00 2001 From: Alex Fan Date: Fri, 29 Jul 2022 12:44:14 +1000 Subject: [PATCH] llvmpipe: add riscv support in orcjit assume cpu supports extension +i,+m,+a,+f,+d,+c --- - .../auxiliary/gallivm/lp_bld_init_orc.cpp | 58 ++++++++++++++++++- - src/util/detect_arch.h | 16 +++++ - 2 files changed, 73 insertions(+), 1 deletion(-) - diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init_orc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_init_orc.cpp -index b245edc5586..eaacebd65d6 100644 +index 8ea4df7..91dde78 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_init_orc.cpp +++ b/src/gallium/auxiliary/gallivm/lp_bld_init_orc.cpp -@@ -48,7 +48,7 @@ +@@ -44,7 +44,7 @@ /* conflict with ObjectLinkingLayer.h */ #include "util/u_memory.h" -#if (defined(_WIN32) && LLVM_VERSION_MAJOR >= 15) -+#if DETECT_ARCH_RISCV64 || DETECT_ARCH_RISCV32 || (defined(_WIN32) && LLVM_VERSION_MAJOR >= 15) ++#if defined(PIPE_ARCH_RISCV64) || defined(PIPE_ARCH_RISCV32) || (defined(_WIN32) && LLVM_VERSION_MAJOR >= 15) /* use ObjectLinkingLayer (JITLINK backend) */ #define USE_JITLINK #endif -@@ -521,6 +521,30 @@ llvm::orc::JITTargetMachineBuilder LPJit::create_jtdb() { +@@ -551,6 +551,30 @@ llvm::orc::JITTargetMachineBuilder LPJit::create_jtdb() { options.StackAlignmentOverride = 4; #endif -+#if DETECT_ARCH_RISCV64 ++#if defined(PIPE_ARCH_RISCV64) +#if defined(__riscv_float_abi_soft) + options.MCOptions.ABIName = "lp64"; +#elif defined(__riscv_float_abi_single) @@ -38,7 +34,7 @@ index b245edc5586..eaacebd65d6 100644 +#endif +#endif + -+#if DETECT_ARCH_RISCV32 ++#if defined(PIPE_ARCH_RISCV32) +#if defined(__riscv_float_abi_soft) + options.MCOptions.ABIName = "ilp32"; +#elif defined(__riscv_float_abi_single) @@ -53,11 +49,11 @@ index b245edc5586..eaacebd65d6 100644 JTMB.setOptions(options); std::vector MAttrs; -@@ -619,6 +643,14 @@ llvm::orc::JITTargetMachineBuilder LPJit::create_jtdb() { +@@ -649,6 +673,14 @@ llvm::orc::JITTargetMachineBuilder LPJit::create_jtdb() { MAttrs.push_back("+fp64"); #endif -+#if DETECT_ARCH_RISCV64 ++#if defined(PIPE_ARCH_RISCV64) + /* Before riscv is more matured and util_get_cpu_caps() is implemented, + * assume this for now since most of linux capable riscv machine are + * riscv64gc @@ -67,12 +63,12 @@ index b245edc5586..eaacebd65d6 100644 + JTMB.addFeatures(MAttrs); - if (gallivm_debug & (GALLIVM_DEBUG_IR | GALLIVM_DEBUG_ASM | GALLIVM_DEBUG_DUMP_BC)) { -@@ -686,6 +718,30 @@ llvm::orc::JITTargetMachineBuilder LPJit::create_jtdb() { + if (::gallivm_debug & (GALLIVM_DEBUG_IR | GALLIVM_DEBUG_ASM | GALLIVM_DEBUG_DUMP_BC)) { +@@ -716,6 +748,30 @@ llvm::orc::JITTargetMachineBuilder LPJit::create_jtdb() { MCPU = util_get_cpu_caps()->has_msa ? "mips64r5" : "mips64r2"; #endif -+#if DETECT_ARCH_RISCV64 ++#if defined(PIPE_ARCH_RISCV64) + /** + * should be fixed with https://reviews.llvm.org/D121149 in llvm 15, + * set it anyway for llvm 14 @@ -84,7 +80,7 @@ index b245edc5586..eaacebd65d6 100644 + JTMB.setRelocationModel(Reloc::PIC_); +#endif + -+#if DETECT_ARCH_RISCV32 ++#if defined(PIPE_ARCH_RISCV32) + /** + * should be fixed with https://reviews.llvm.org/D121149 in llvm 15, + * set it anyway for llvm 14 @@ -100,37 +96,21 @@ index b245edc5586..eaacebd65d6 100644 if (gallivm_debug & (GALLIVM_DEBUG_IR | GALLIVM_DEBUG_ASM | GALLIVM_DEBUG_DUMP_BC)) { debug_printf("llc -mcpu option: %s\n", MCPU.c_str()); diff --git a/src/util/detect_arch.h b/src/util/detect_arch.h -index 334358fcc26..34c0928216d 100644 +index 334358f..8c7bd15 100644 --- a/src/util/detect_arch.h +++ b/src/util/detect_arch.h -@@ -97,6 +97,14 @@ - #define DETECT_ARCH_MIPS 1 +@@ -137,4 +137,14 @@ + #define DETECT_ARCH_MIPS 0 #endif +#if defined(__riscv) +#if __riscv_xlen == 64 -+#define DETECT_ARCH_RISCV64 1 ++#define PIPE_ARCH_RISCV64 +#elif __riscv_xlen == 32 -+#define DETECT_ARCH_RISCV32 1 -+#endif -+#endif -+ - #ifndef DETECT_ARCH_X86 - #define DETECT_ARCH_X86 0 - #endif -@@ -137,4 +145,12 @@ - #define DETECT_ARCH_MIPS 0 - #endif - -+#ifndef DETECT_ARCH_RISCV32 -+#define DETECT_ARCH_RISCV32 0 ++#define PIPE_ARCH_RISCV32 ++#else ++#error "pipe: unknown target riscv xlen" +#endif -+ -+#ifndef DETECT_ARCH_RISCV64 -+#define DETECT_ARCH_RISCV64 0 +#endif + #endif /* UTIL_DETECT_ARCH_H_ */ --- -2.41.0 - diff --git a/llvmpipe-make-unnamed-global-have-internal-linkage.patch b/llvmpipe-make-unnamed-global-have-internal-linkage.patch index 1bfd34e79325ad04b11fa0dc7f66af762ad101d3..d67d8672806a8e73c409624df4e28ca12b9d46ab 100644 --- a/llvmpipe-make-unnamed-global-have-internal-linkage.patch +++ b/llvmpipe-make-unnamed-global-have-internal-linkage.patch @@ -9,14 +9,11 @@ changing to internal linkage is safe Signed-off-by: Alex Fan --- - src/gallium/drivers/llvmpipe/lp_state_fs.c | 1 + - 1 file changed, 1 insertion(+) - diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c -index 2a5977134b0..5a396b44137 100644 +index 4e0b693..5b29610 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c -@@ -3306,6 +3306,7 @@ generate_fragment(struct llvmpipe_context *lp, +@@ -3320,6 +3320,7 @@ generate_fragment(struct llvmpipe_context *lp, LLVMValueRef glob_sample_pos = LLVMAddGlobal(gallivm->module, LLVMArrayType(flt_type, key->coverage_samples * 2), ""); @@ -24,6 +21,3 @@ index 2a5977134b0..5a396b44137 100644 LLVMValueRef sample_pos_array; if (key->multisample && key->coverage_samples == 4) { --- -2.41.0 - diff --git a/mesa-23.1.6.tar.xz b/mesa-23.2.1.tar.xz similarity index 66% rename from mesa-23.1.6.tar.xz rename to mesa-23.2.1.tar.xz index be403dde5e342b295d3d2812b6e1bf683a47a99f..f3a9e34d2f44c60e591332f2908daa558a719651 100644 Binary files a/mesa-23.1.6.tar.xz and b/mesa-23.2.1.tar.xz differ diff --git a/mesa.spec b/mesa.spec index c253a332b9607a0225bd8579e457545e7cfb02f2..bf503d08103520528ce86b5d19f0988bb9ee8f6d 100644 --- a/mesa.spec +++ b/mesa.spec @@ -51,7 +51,7 @@ Name: mesa Summary: Mesa graphics libraries -Version: 23.1.6 +Version: 23.2.1 Release: 1 License: MIT @@ -571,6 +571,10 @@ done %endif %changelog +* Thu Nov 02 2023 Jingwiw - 23.2.1-1 +- upgrade to version 23.2.1 +- fix llvmpipe interface support for the new version + * Sun Aug 20 2023 Funda Wang - 23.1.6-1 - update to 23.1.6