Ticket #16991: mesa-22.1.7-llvm_14-1.patch

File mesa-22.1.7-llvm_14-1.patch, 15.2 KB (added by Xi Ruoyao, 20 months ago)
  • src/gallium/auxiliary/draw/draw_llvm.c

    diff --color -Naur mesa-22.1.7/src/gallium/auxiliary/draw/draw_llvm.c mesa-22.1.7-patched/src/gallium/auxiliary/draw/draw_llvm.c
    old new  
    797797   llvm->context = context;
    798798   if (!llvm->context) {
    799799      llvm->context = LLVMContextCreate();
     800
     801#if LLVM_VERSION_MAJOR >= 15
     802      LLVMContextSetOpaquePointers(llvm->context, false);
     803#endif
     804
    800805      llvm->context_owned = true;
    801806   }
    802807   if (!llvm->context)
  • src/gallium/auxiliary/gallivm/lp_bld_arit.c

    diff --color -Naur mesa-22.1.7/src/gallium/auxiliary/gallivm/lp_bld_arit.c mesa-22.1.7-patched/src/gallium/auxiliary/gallivm/lp_bld_arit.c
    old new  
    391391         return LLVMBuildNot(builder, a, "");
    392392   }
    393393
    394    if(LLVMIsConstant(a))
    395       if (type.floating)
    396           return LLVMConstFSub(bld->one, a);
    397       else
    398           return LLVMConstSub(bld->one, a);
     394   if (type.floating)
     395      return LLVMBuildFSub(builder, bld->one, a, "");
    399396   else
    400       if (type.floating)
    401          return LLVMBuildFSub(builder, bld->one, a, "");
    402       else
    403          return LLVMBuildSub(builder, bld->one, a, "");
     397      return LLVMBuildSub(builder, bld->one, a, "");
    404398}
    405399
    406400
     
    479473      }
    480474   }
    481475
    482    if(LLVMIsConstant(a) && LLVMIsConstant(b))
    483       if (type.floating)
    484          res = LLVMConstFAdd(a, b);
    485       else
    486          res = LLVMConstAdd(a, b);
     476   if (type.floating)
     477      res = LLVMBuildFAdd(builder, a, b, "");
    487478   else
    488       if (type.floating)
    489          res = LLVMBuildFAdd(builder, a, b, "");
    490       else
    491          res = LLVMBuildAdd(builder, a, b, "");
     479      res = LLVMBuildAdd(builder, a, b, "");
    492480
    493481   /* clamp to ceiling of 1.0 */
    494482   if(bld->type.norm && (bld->type.floating || bld->type.fixed))
     
    815803      }
    816804   }
    817805
    818    if(LLVMIsConstant(a) && LLVMIsConstant(b))
    819       if (type.floating)
    820          res = LLVMConstFSub(a, b);
    821       else
    822          res = LLVMConstSub(a, b);
     806   if (type.floating)
     807      res = LLVMBuildFSub(builder, a, b, "");
    823808   else
    824       if (type.floating)
    825          res = LLVMBuildFSub(builder, a, b, "");
    826       else
    827          res = LLVMBuildSub(builder, a, b, "");
     809      res = LLVMBuildSub(builder, a, b, "");
    828810
    829811   if(bld->type.norm && (bld->type.floating || bld->type.fixed))
    830812      res = lp_build_max_simple(bld, res, bld->zero, GALLIVM_NAN_RETURN_OTHER_SECOND_NONNAN);
     
    980962   else
    981963      shift = NULL;
    982964
    983    if(LLVMIsConstant(a) && LLVMIsConstant(b)) {
    984       if (type.floating)
    985          res = LLVMConstFMul(a, b);
    986       else
    987          res = LLVMConstMul(a, b);
    988       if(shift) {
    989          if(type.sign)
    990             res = LLVMConstAShr(res, shift);
    991          else
    992             res = LLVMConstLShr(res, shift);
    993       }
    994    }
    995    else {
    996       if (type.floating)
    997          res = LLVMBuildFMul(builder, a, b, "");
     965   if (type.floating)
     966      res = LLVMBuildFMul(builder, a, b, "");
     967   else
     968      res = LLVMBuildMul(builder, a, b, "");
     969   if(shift) {
     970      if(type.sign)
     971         res = LLVMBuildAShr(builder, res, shift, "");
    998972      else
    999          res = LLVMBuildMul(builder, a, b, "");
    1000       if(shift) {
    1001          if(type.sign)
    1002             res = LLVMBuildAShr(builder, res, shift, "");
    1003          else
    1004             res = LLVMBuildLShr(builder, res, shift, "");
    1005       }
     973         res = LLVMBuildLShr(builder, res, shift, "");
    1006974   }
    1007975
    1008976   return res;
     
    12881256   if(a == bld->undef || b == bld->undef)
    12891257      return bld->undef;
    12901258
    1291    if(LLVMIsConstant(a) && LLVMIsConstant(b)) {
    1292       if (type.floating)
    1293          return LLVMConstFDiv(a, b);
    1294       else if (type.sign)
    1295          return LLVMConstSDiv(a, b);
    1296       else
    1297          return LLVMConstUDiv(a, b);
    1298    }
    1299 
    13001259   /* fast rcp is disabled (just uses div), so makes no sense to try that */
    13011260   if(FALSE &&
    13021261      ((util_get_cpu_caps()->has_sse && type.width == 32 && type.length == 4) ||
     
    26452604
    26462605   assert(type.floating);
    26472606
    2648    if(LLVMIsConstant(a))
    2649       return LLVMConstFDiv(bld->one, a);
    2650 
    26512607   /*
    26522608    * We don't use RCPPS because:
    26532609    * - it only has 10bits of precision
  • src/gallium/auxiliary/gallivm/lp_bld.h

    diff --color -Naur mesa-22.1.7/src/gallium/auxiliary/gallivm/lp_bld.h mesa-22.1.7-patched/src/gallium/auxiliary/gallivm/lp_bld.h
    old new  
    8282#define LLVMCreateBuilder ILLEGAL_LLVM_FUNCTION
    8383
    8484#if LLVM_VERSION_MAJOR >= 8
     85#if LLVM_VERSION_MAJOR >= 15
     86#define GALLIVM_HAVE_CORO 0
     87#define GALLIVM_USE_NEW_PASS 1
     88#elif LLVM_VERSION_MAJOR >= 8
    8589#define GALLIVM_HAVE_CORO 1
     90#define GALLIVM_USE_NEW_PASS 0
    8691#else
    8792#define GALLIVM_HAVE_CORO 0
     93#define GALLIVM_USE_NEW_PASS 0
     94#endif
    8895#endif
     96 
     97#define GALLIVM_COROUTINES (GALLIVM_HAVE_CORO || GALLIVM_USE_NEW_PASS)
    8998
    9099#endif /* LP_BLD_H */
  • src/gallium/auxiliary/gallivm/lp_bld_init.c

    diff --color -Naur mesa-22.1.7/src/gallium/auxiliary/gallivm/lp_bld_init.c mesa-22.1.7-patched/src/gallium/auxiliary/gallivm/lp_bld_init.c
    old new  
    4545#include <llvm-c/Transforms/Utils.h>
    4646#endif
    4747#include <llvm-c/BitWriter.h>
    48 #if GALLIVM_HAVE_CORO
     48#if GALLIVM_USE_NEW_PASS == 1
     49#include <llvm-c/Transforms/PassBuilder.h>
     50#elif GALLIVM_HAVE_CORO == 1
    4951#if LLVM_VERSION_MAJOR <= 8 && (defined(PIPE_ARCH_AARCH64) || defined (PIPE_ARCH_ARM) || defined(PIPE_ARCH_S390) || defined(PIPE_ARCH_MIPS64))
    5052#include <llvm-c/Transforms/IPO.h>
    5153#endif
     
    110112static boolean
    111113create_pass_manager(struct gallivm_state *gallivm)
    112114{
     115#if GALLIVM_USE_NEW_PASS == 0
    113116   assert(!gallivm->passmgr);
    114117   assert(gallivm->target);
    115118
     
    117120   if (!gallivm->passmgr)
    118121      return FALSE;
    119122
    120 #if GALLIVM_HAVE_CORO
     123#if GALLIVM_HAVE_CORO == 1
    121124   gallivm->cgpassmgr = LLVMCreatePassManager();
    122125#endif
    123126   /*
     
    134137      free(td_str);
    135138   }
    136139
    137 #if GALLIVM_HAVE_CORO
     140#if GALLIVM_HAVE_CORO == 1
    138141#if LLVM_VERSION_MAJOR <= 8 && (defined(PIPE_ARCH_AARCH64) || defined (PIPE_ARCH_ARM) || defined(PIPE_ARCH_S390) || defined(PIPE_ARCH_MIPS64))
    139142   LLVMAddArgumentPromotionPass(gallivm->cgpassmgr);
    140143   LLVMAddFunctionAttrsPass(gallivm->cgpassmgr);
     
    181184       */
    182185      LLVMAddPromoteMemoryToRegisterPass(gallivm->passmgr);
    183186   }
    184 #if GALLIVM_HAVE_CORO
     187#if GALLIVM_HAVE_CORO == 1
    185188   LLVMAddCoroCleanupPass(gallivm->passmgr);
    186189#endif
    187 
     190#endif
    188191   return TRUE;
    189192}
    190193
    191 
    192194/**
    193195 * Free gallivm object's LLVM allocations, but not any generated code
    194196 * nor the gallivm object itself.
     
    196198void
    197199gallivm_free_ir(struct gallivm_state *gallivm)
    198200{
     201#if GALLIVM_USE_NEW_PASS == 0
    199202   if (gallivm->passmgr) {
    200203      LLVMDisposePassManager(gallivm->passmgr);
    201204   }
    202205
    203 #if GALLIVM_HAVE_CORO
     206#if GALLIVM_HAVE_CORO == 1
    204207   if (gallivm->cgpassmgr) {
    205208      LLVMDisposePassManager(gallivm->cgpassmgr);
    206209   }
    207210#endif
     211#endif
    208212
    209213   if (gallivm->engine) {
    210214      /* This will already destroy any associated module */
     
    232236   gallivm->target = NULL;
    233237   gallivm->module = NULL;
    234238   gallivm->module_name = NULL;
     239#if GALLIVM_USE_NEW_PASS == 0
     240#if GALLIVM_HAVE_CORO == 1
    235241   gallivm->cgpassmgr = NULL;
     242#endif
    236243   gallivm->passmgr = NULL;
     244#endif
    237245   gallivm->context = NULL;
    238246   gallivm->builder = NULL;
    239247   gallivm->cache = NULL;
     
    571579void
    572580gallivm_compile_module(struct gallivm_state *gallivm)
    573581{
    574    LLVMValueRef func;
    575582   int64_t time_begin = 0;
    576583
    577584   assert(!gallivm->compiled);
     
    581588      gallivm->builder = NULL;
    582589   }
    583590
     591   LLVMSetDataLayout(gallivm->module, "");
     592   assert(!gallivm->engine);
     593   if (!init_gallivm_engine(gallivm)) {
     594      assert(0);
     595   }
     596   assert(gallivm->engine);
     597
    584598   if (gallivm->cache && gallivm->cache->data_size) {
    585599      goto skip_cached;
    586600   }
     
    604618   if (gallivm_debug & GALLIVM_DEBUG_PERF)
    605619      time_begin = os_time_get();
    606620
    607 #if GALLIVM_HAVE_CORO
     621#if GALLIVM_USE_NEW_PASS == 1
     622   char passes[1024];
     623   passes[0] = 0;
     624
     625   /*
     626    * there should be some way to combine these two pass runs but I'm not seeing it,
     627    * at the time of writing.
     628    */
     629   strcpy(passes, "default<O0>");
     630
     631   LLVMPassBuilderOptionsRef opts = LLVMCreatePassBuilderOptions();
     632   LLVMRunPasses(gallivm->module, passes, LLVMGetExecutionEngineTargetMachine(gallivm->engine), opts);
     633
     634   if (!(gallivm_perf & GALLIVM_PERF_NO_OPT))
     635      strcpy(passes, "sroa,early-cse,simplifycfg,reassociate,mem2reg,constprop,instcombine,");
     636   else
     637      strcpy(passes, "mem2reg");
     638
     639   LLVMRunPasses(gallivm->module, passes, LLVMGetExecutionEngineTargetMachine(gallivm->engine), opts);
     640   LLVMDisposePassBuilderOptions(opts);
     641#else
     642#if GALLIVM_HAVE_CORO == 1
    608643   LLVMRunPassManager(gallivm->cgpassmgr, gallivm->module);
    609644#endif
    610645   /* Run optimization passes */
    611646   LLVMInitializeFunctionPassManager(gallivm->passmgr);
     647   LLVMValueRef func;
    612648   func = LLVMGetFirstFunction(gallivm->module);
    613649   while (func) {
    614650      if (0) {
     
    626662      func = LLVMGetNextFunction(func);
    627663   }
    628664   LLVMFinalizeFunctionPassManager(gallivm->passmgr);
    629 
     665#endif
    630666   if (gallivm_debug & GALLIVM_DEBUG_PERF) {
    631667      int64_t time_end = os_time_get();
    632668      int time_msec = (int)((time_end - time_begin) / 1000);
     
    653689    * lp_build_create_jit_compiler_for_module()
    654690    */
    655691 skip_cached:
    656    LLVMSetDataLayout(gallivm->module, "");
    657    assert(!gallivm->engine);
    658    if (!init_gallivm_engine(gallivm)) {
    659       assert(0);
    660    }
    661    assert(gallivm->engine);
    662692
    663693   ++gallivm->compiled;
    664694
  • src/gallium/auxiliary/gallivm/lp_bld_init.h

    diff --color -Naur mesa-22.1.7/src/gallium/auxiliary/gallivm/lp_bld_init.h mesa-22.1.7-patched/src/gallium/auxiliary/gallivm/lp_bld_init.h
    old new  
    4646   LLVMModuleRef module;
    4747   LLVMExecutionEngineRef engine;
    4848   LLVMTargetDataRef target;
     49#if GALLIVM_USE_NEW_PASS == 0
    4950   LLVMPassManagerRef passmgr;
     51#if GALLIVM_HAVE_CORO == 1
    5052   LLVMPassManagerRef cgpassmgr;
     53#endif
     54#endif
    5155   LLVMContextRef context;
    5256   LLVMBuilderRef builder;
    5357   LLVMMCJITMemoryManagerRef memorymgr;
  • src/gallium/drivers/llvmpipe/lp_context.c

    diff --color -Naur mesa-22.1.7/src/gallium/drivers/llvmpipe/lp_context.c mesa-22.1.7-patched/src/gallium/drivers/llvmpipe/lp_context.c
    old new  
    250250   if (!llvmpipe->context)
    251251      goto fail;
    252252
     253#if LLVM_VERSION_MAJOR >= 15
     254   LLVMContextSetOpaquePointers(llvmpipe->context, false);
     255#endif
     256
    253257   /*
    254258    * Create drawing context and plug our rendering stage into it.
    255259    */
  • src/gallium/drivers/llvmpipe/lp_screen.c

    diff --color -Naur mesa-22.1.7/src/gallium/drivers/llvmpipe/lp_screen.c mesa-22.1.7-patched/src/gallium/drivers/llvmpipe/lp_screen.c
    old new  
    215215      return lscreen->use_tgsi ? 330 : 450;
    216216   }
    217217   case PIPE_CAP_COMPUTE:
    218       return GALLIVM_HAVE_CORO;
     218      return GALLIVM_COROUTINES;
    219219   case PIPE_CAP_USER_VERTEX_BUFFERS:
    220220      return 1;
    221221   case PIPE_CAP_TGSI_TEXCOORD:
     
    394394   case PIPE_SHADER_TESS_CTRL:
    395395   case PIPE_SHADER_TESS_EVAL:
    396396      /* Tessellation shader needs llvm coroutines support */
    397       if (!GALLIVM_HAVE_CORO || lscreen->use_tgsi)
     397      if (!GALLIVM_COROUTINES || lscreen->use_tgsi)
    398398         return 0;
    399399      FALLTHROUGH;
    400400   case PIPE_SHADER_VERTEX:
  • src/gallium/drivers/llvmpipe/lp_test_arit.c

    diff --color -Naur mesa-22.1.7/src/gallium/drivers/llvmpipe/lp_test_arit.c mesa-22.1.7-patched/src/gallium/drivers/llvmpipe/lp_test_arit.c
    old new  
    438438   }
    439439
    440440   context = LLVMContextCreate();
     441#if LLVM_VERSION_MAJOR >= 15
     442   LLVMContextSetOpaquePointers(context, false);
     443#endif
    441444   gallivm = gallivm_create("test_module", context, NULL);
    442445
    443446   test_func = build_unary_test_func(gallivm, test, length, test_name);
  • src/gallium/drivers/llvmpipe/lp_test_blend.c

    diff --color -Naur mesa-22.1.7/src/gallium/drivers/llvmpipe/lp_test_blend.c mesa-22.1.7-patched/src/gallium/drivers/llvmpipe/lp_test_blend.c
    old new  
    452452      dump_blend_type(stdout, blend, type);
    453453
    454454   context = LLVMContextCreate();
     455#if LLVM_VERSION_MAJOR >= 15
     456   LLVMContextSetOpaquePointers(context, false);
     457#endif
    455458   gallivm = gallivm_create("test_module", context, NULL);
    456459
    457460   func = add_blend_test(gallivm, blend, type);
  • src/gallium/drivers/llvmpipe/lp_test_conv.c

    diff --color -Naur mesa-22.1.7/src/gallium/drivers/llvmpipe/lp_test_conv.c mesa-22.1.7-patched/src/gallium/drivers/llvmpipe/lp_test_conv.c
    old new  
    221221   }
    222222
    223223   context = LLVMContextCreate();
     224#if LLVM_VERSION_MAJOR >= 15
     225   LLVMContextSetOpaquePointers(context, false);
     226#endif
    224227   gallivm = gallivm_create("test_module", context, NULL);
    225228
    226229   func = add_conv_test(gallivm, src_type, num_srcs, dst_type, num_dsts);
  • src/gallium/drivers/llvmpipe/lp_test_format.c

    diff --color -Naur mesa-22.1.7/src/gallium/drivers/llvmpipe/lp_test_format.c mesa-22.1.7-patched/src/gallium/drivers/llvmpipe/lp_test_format.c
    old new  
    150150   unsigned i, j, k, l;
    151151
    152152   context = LLVMContextCreate();
     153#if LLVM_VERSION_MAJOR >= 15
     154   LLVMContextSetOpaquePointers(context, false);
     155#endif
    153156   gallivm = gallivm_create("test_module_float", context, NULL);
    154157
    155158   fetch = add_fetch_rgba_test(gallivm, verbose, desc,
     
    251254   unsigned i, j, k, l;
    252255
    253256   context = LLVMContextCreate();
     257#if LLVM_VERSION_MAJOR >= 15
     258   LLVMContextSetOpaquePointers(context, false);
     259#endif
    254260   gallivm = gallivm_create("test_module_unorm8", context, NULL);
    255261
    256262   fetch = add_fetch_rgba_test(gallivm, verbose, desc,
  • src/gallium/drivers/llvmpipe/lp_test_printf.c

    diff --color -Naur mesa-22.1.7/src/gallium/drivers/llvmpipe/lp_test_printf.c mesa-22.1.7-patched/src/gallium/drivers/llvmpipe/lp_test_printf.c
    old new  
    9696   boolean success = TRUE;
    9797
    9898   context = LLVMContextCreate();
     99#if LLVM_VERSION_MAJOR >= 15
     100   LLVMContextSetOpaquePointers(context, false);
     101#endif
    99102   gallivm = gallivm_create("test_module", context, NULL);
    100103
    101104   test = add_printf_test(gallivm);