From 867d1cb9822c21d7a81c3245455cde9ac1872816 Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Thu, 12 Jan 2023 12:27:43 +0000 Subject: [PATCH] Quick LLVM 15 support hacks - build.py: permit building with LLVM 15 - passmanagers.cpp: Rename DomPrinterPasses to match LLVM change Remove arg promotion and loop unswitch passes - value.cpp: Add needed GraphWriter.h header - passmanagers.py: Remove arg promotion and loop unswitch passes - tests: immediately fail anything that would crash LLVM with a failed assert --- ffi/build.py | 4 +-- ffi/passmanagers.cpp | 28 ++++++++++---------- ffi/value.cpp | 1 + llvmlite/binding/passmanagers.py | 44 ++++++++++++++++---------------- llvmlite/tests/test_binding.py | 4 +++ llvmlite/tests/test_ir.py | 3 +++ 6 files changed, 46 insertions(+), 38 deletions(-) diff --git a/ffi/build.py b/ffi/build.py index e58a691e0..7a9a86ecc 100755 --- a/ffi/build.py +++ b/ffi/build.py @@ -165,8 +165,8 @@ def main_posix(kind, library_ext): else: (version, _) = out.split('.', 1) version = int(version) - if version < 11 or version > 14: - msg = ("Building llvmlite requires LLVM 11, 12, 13, or 14, got " + if version < 11 or version > 15: + msg = ("Building llvmlite requires LLVM 11 - 15, got " "{!r}. Be sure to set LLVM_CONFIG to the right executable " "path.\nRead the documentation at " "http://llvmlite.pydata.org/ for more information about " diff --git a/ffi/passmanagers.cpp b/ffi/passmanagers.cpp index 60064cf10..65488cb0a 100644 --- a/ffi/passmanagers.cpp +++ b/ffi/passmanagers.cpp @@ -161,8 +161,8 @@ LLVMPY_AddCallGraphDOTPrinterPass(LLVMPassManagerRef PM) { API_EXPORT(void) LLVMPY_AddDotDomPrinterPass(LLVMPassManagerRef PM, bool showBody) { - unwrap(PM)->add(showBody ? llvm::createDomPrinterPass() - : llvm::createDomOnlyPrinterPass()); + unwrap(PM)->add(showBody ? llvm::createDomPrinterWrapperPassPass() + : llvm::createDomOnlyPrinterWrapperPassPass()); } API_EXPORT(void) @@ -172,8 +172,8 @@ LLVMPY_AddGlobalsModRefAAPass(LLVMPassManagerRef PM) { API_EXPORT(void) LLVMPY_AddDotPostDomPrinterPass(LLVMPassManagerRef PM, bool showBody) { - unwrap(PM)->add(showBody ? llvm::createPostDomPrinterPass() - : llvm::createPostDomOnlyPrinterPass()); + unwrap(PM)->add(showBody ? llvm::createPostDomPrinterWrapperPassPass() + : llvm::createPostDomOnlyPrinterWrapperPassPass()); } API_EXPORT(void) @@ -248,10 +248,10 @@ LLVMPY_AddAlwaysInlinerPass(LLVMPassManagerRef PM, bool insertLifetime) { unwrap(PM)->add(llvm::createAlwaysInlinerLegacyPass(insertLifetime)); } -API_EXPORT(void) -LLVMPY_AddArgPromotionPass(LLVMPassManagerRef PM, unsigned int maxElements) { - unwrap(PM)->add(llvm::createArgumentPromotionPass(maxElements)); -} +// API_EXPORT(void) +// LLVMPY_AddArgPromotionPass(LLVMPassManagerRef PM, unsigned int maxElements) { +// unwrap(PM)->add(llvm::createArgumentPromotionPass(maxElements)); +// } API_EXPORT(void) LLVMPY_AddBreakCriticalEdgesPass(LLVMPassManagerRef PM) { @@ -337,12 +337,12 @@ LLVMPY_AddLoopUnrollAndJamPass(LLVMPassManagerRef PM) { LLVMAddLoopUnrollAndJamPass(PM); } -API_EXPORT(void) -LLVMPY_AddLoopUnswitchPass(LLVMPassManagerRef PM, bool optimizeForSize, - bool hasBranchDivergence) { - unwrap(PM)->add( - createLoopUnswitchPass(optimizeForSize, hasBranchDivergence)); -} +// API_EXPORT(void) +// LLVMPY_AddLoopUnswitchPass(LLVMPassManagerRef PM, bool optimizeForSize, +// bool hasBranchDivergence) { +// unwrap(PM)->add( +// createLoopUnswitchPass(optimizeForSize, hasBranchDivergence)); +// } API_EXPORT(void) LLVMPY_AddLowerAtomicPass(LLVMPassManagerRef PM) { diff --git a/ffi/value.cpp b/ffi/value.cpp index 01871699d..7d5db9947 100644 --- a/ffi/value.cpp +++ b/ffi/value.cpp @@ -6,6 +6,7 @@ // the following is needed for WriteGraph() #include "llvm/Analysis/CFGPrinter.h" +#include "llvm/Support/GraphWriter.h" /* An iterator around a attribute list, including the stop condition */ struct AttributeListIterator { diff --git a/llvmlite/binding/passmanagers.py b/llvmlite/binding/passmanagers.py index 4b9daf468..7c785ee59 100644 --- a/llvmlite/binding/passmanagers.py +++ b/llvmlite/binding/passmanagers.py @@ -252,13 +252,13 @@ def add_always_inliner_pass(self, insert_lifetime=True): """ # noqa E501 ffi.lib.LLVMPY_AddAlwaysInlinerPass(self, insert_lifetime) - def add_arg_promotion_pass(self, max_elements=3): - """ - See https://llvm.org/docs/Passes.html#argpromotion-promote-by-reference-arguments-to-scalars + #def add_arg_promotion_pass(self, max_elements=3): + # """ + # See https://llvm.org/docs/Passes.html#argpromotion-promote-by-reference-arguments-to-scalars - LLVM 11+: `llvm::createArgumentPromotionPass` - """ # noqa E501 - ffi.lib.LLVMPY_AddArgPromotionPass(self, max_elements) + # LLVM 11+: `llvm::createArgumentPromotionPass` + # """ # noqa E501 + # ffi.lib.LLVMPY_AddArgPromotionPass(self, max_elements) def add_break_critical_edges_pass(self): """ @@ -459,17 +459,17 @@ def add_loop_unroll_and_jam_pass(self): """ # noqa E501 ffi.lib.LLVMPY_AddLoopUnrollAndJamPass(self) - def add_loop_unswitch_pass(self, - optimize_for_size=False, - has_branch_divergence=False): - """ - See https://llvm.org/docs/Passes.html#loop-unswitch-unswitch-loops - - LLVM 11+: `llvm::createLoopUnswitchPass` - """ # noqa E501 - ffi.lib.LLVMPY_AddLoopUnswitchPass(self, - optimize_for_size, - has_branch_divergence) +# def add_loop_unswitch_pass(self, +# optimize_for_size=False, +# has_branch_divergence=False): +# """ +# See https://llvm.org/docs/Passes.html#loop-unswitch-unswitch-loops +# +# LLVM 11+: `llvm::createLoopUnswitchPass` +# """ # noqa E501 +# ffi.lib.LLVMPY_AddLoopUnswitchPass(self, +# optimize_for_size, +# has_branch_divergence) def add_lower_atomic_pass(self): """ @@ -855,7 +855,7 @@ def run_with_remarks(self, function, remarks_format='yaml', ffi.lib.LLVMPY_AddScalarEvolutionAAPass.argtypes = [ffi.LLVMPassManagerRef] ffi.lib.LLVMPY_AddAggressiveDCEPass.argtypes = [ffi.LLVMPassManagerRef] ffi.lib.LLVMPY_AddAlwaysInlinerPass.argtypes = [ffi.LLVMPassManagerRef, c_bool] -ffi.lib.LLVMPY_AddArgPromotionPass.argtypes = [ffi.LLVMPassManagerRef, c_uint] +#ffi.lib.LLVMPY_AddArgPromotionPass.argtypes = [ffi.LLVMPassManagerRef, c_uint] ffi.lib.LLVMPY_AddBreakCriticalEdgesPass.argtypes = [ffi.LLVMPassManagerRef] ffi.lib.LLVMPY_AddDeadStoreEliminationPass.argtypes = [ ffi.LLVMPassManagerRef] @@ -872,10 +872,10 @@ def run_with_remarks(self, function, remarks_format='yaml', ffi.lib.LLVMPY_AddLoopSimplificationPass.argtypes = [ffi.LLVMPassManagerRef] ffi.lib.LLVMPY_AddLoopUnrollPass.argtypes = [ffi.LLVMPassManagerRef] ffi.lib.LLVMPY_AddLoopUnrollAndJamPass.argtypes = [ffi.LLVMPassManagerRef] -ffi.lib.LLVMPY_AddLoopUnswitchPass.argtypes = [ - ffi.LLVMPassManagerRef, - c_bool, - c_bool] +#ffi.lib.LLVMPY_AddLoopUnswitchPass.argtypes = [ +# ffi.LLVMPassManagerRef, +# c_bool, +# c_bool] ffi.lib.LLVMPY_AddLowerAtomicPass.argtypes = [ffi.LLVMPassManagerRef] ffi.lib.LLVMPY_AddLowerInvokePass.argtypes = [ffi.LLVMPassManagerRef] ffi.lib.LLVMPY_AddLowerSwitchPass.argtypes = [ffi.LLVMPassManagerRef] diff --git a/llvmlite/tests/test_binding.py b/llvmlite/tests/test_binding.py index 70902e04c..03c933e94 100644 --- a/llvmlite/tests/test_binding.py +++ b/llvmlite/tests/test_binding.py @@ -952,6 +952,7 @@ def test_target_data(self): str(td) def test_target_data_abi_enquiries(self): + self.fail("Failing due to LLVM 15 assertion fail") mod = self.module() ee = self.jit(mod) td = ee.target_data @@ -1151,6 +1152,7 @@ def test_type(self): self.assertIsInstance(tp, llvm.TypeRef) def test_type_name(self): + self.fail("Failing due to LLVM 15 assertion fail") mod = self.module() glob = mod.get_global_variable("glob") tp = glob.type @@ -1326,6 +1328,7 @@ def test_get_abi_size(self): self.assertEqual(td.get_abi_size(glob.type), 8) def test_get_pointee_abi_size(self): + self.fail("Failing due to LLVM 15 assertion fail") td = self.target_data() glob = self.glob() @@ -1335,6 +1338,7 @@ def test_get_pointee_abi_size(self): self.assertEqual(td.get_pointee_abi_size(glob.type), 24) def test_get_struct_element_offset(self): + self.fail("Failing due to LLVM 15 assertion fail") td = self.target_data() glob = self.glob("glob_struct") diff --git a/llvmlite/tests/test_ir.py b/llvmlite/tests/test_ir.py index 82bcef352..226a0dbbf 100644 --- a/llvmlite/tests/test_ir.py +++ b/llvmlite/tests/test_ir.py @@ -2213,6 +2213,7 @@ def check_index_type(tp): check_index_type(tp) def test_abi_size(self): + self.fail("Failing due to LLVM 15 assertion fail") td = llvm.create_target_data("e-m:e-i64:64-f80:128-n8:16:32:64-S128") def check(tp, expected): @@ -2225,6 +2226,7 @@ def check(tp, expected): check(ir.LiteralStructType((dbl, flt, flt)), 16) def test_abi_alignment(self): + self.fail("Failing due to LLVM 15 assertion fail") td = llvm.create_target_data("e-m:e-i64:64-f80:128-n8:16:32:64-S128") def check(tp, expected): @@ -2249,6 +2251,7 @@ def test_identified_struct(self): self.assertNotEqual(oldstr, str(module)) def test_target_data_non_default_context(self): + self.fail("Failing due to LLVM 15 assertion fail") context = ir.Context() mytype = context.get_identified_type("MyType") mytype.elements = [ir.IntType(32)]