llvmlite 0.43.0rc1__cp311-cp311-macosx_11_0_arm64.whl → 0.44.0rc2__cp311-cp311-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of llvmlite might be problematic. Click here for more details.

llvmlite/__init__.py CHANGED
@@ -1,3 +1,10 @@
1
1
  from ._version import get_versions
2
2
  __version__ = get_versions()['version']
3
3
  del get_versions
4
+
5
+ # FIXME: Remove me once typed pointers are no longer supported.
6
+ def _opaque_pointers_enabled():
7
+ import os
8
+ return os.environ.get('LLVMLITE_ENABLE_OPAQUE_POINTERS', '0') == '1'
9
+ opaque_pointers_enabled = _opaque_pointers_enabled()
10
+ del _opaque_pointers_enabled
llvmlite/_version.py CHANGED
@@ -4,8 +4,8 @@
4
4
  # unpacked source archive. Distribution tarballs contain a pre-generated copy
5
5
  # of this file.
6
6
 
7
- version_version = '0.43.0rc1'
8
- version_full = '4868420e431184249a2db85a1ad88a60c88b7e51'
7
+ version_version = '0.44.0rc2'
8
+ version_full = '8213a18880cfe34a54b684aea555975bfe6f110b'
9
9
  def get_versions(default={}, verbose=False):
10
10
  return {'version': version_version, 'full': version_full}
11
11
 
@@ -7,6 +7,7 @@ from .initfini import *
7
7
  from .linker import *
8
8
  from .module import *
9
9
  from .options import *
10
+ from .newpassmanagers import *
10
11
  from .passmanagers import *
11
12
  from .targets import *
12
13
  from .transforms import *
@@ -1,12 +1,18 @@
1
1
  from llvmlite.binding import ffi
2
2
 
3
+ # FIXME: Remove me once typed pointers are no longer supported.
4
+ from llvmlite import opaque_pointers_enabled
5
+ from ctypes import c_bool
6
+
3
7
 
4
8
  def create_context():
5
- return ContextRef(ffi.lib.LLVMPY_ContextCreate())
9
+ return ContextRef(
10
+ ffi.lib.LLVMPY_ContextCreate(opaque_pointers_enabled))
6
11
 
7
12
 
8
13
  def get_global_context():
9
- return GlobalContextRef(ffi.lib.LLVMPY_GetGlobalContext())
14
+ return GlobalContextRef(
15
+ ffi.lib.LLVMPY_GetGlobalContext(opaque_pointers_enabled))
10
16
 
11
17
 
12
18
  class ContextRef(ffi.ObjectRef):
@@ -22,8 +28,12 @@ class GlobalContextRef(ContextRef):
22
28
  pass
23
29
 
24
30
 
31
+ # FIXME: Remove argtypes once typed pointers are no longer supported.
32
+ ffi.lib.LLVMPY_GetGlobalContext.argtypes = [c_bool]
25
33
  ffi.lib.LLVMPY_GetGlobalContext.restype = ffi.LLVMContextRef
26
34
 
35
+ # FIXME: Remove argtypes once typed pointers are no longer supported.
36
+ ffi.lib.LLVMPY_ContextCreate.argtypes = [c_bool]
27
37
  ffi.lib.LLVMPY_ContextCreate.restype = ffi.LLVMContextRef
28
38
 
29
39
  ffi.lib.LLVMPY_ContextDispose.argtypes = [ffi.LLVMContextRef]
llvmlite/binding/ffi.py CHANGED
@@ -41,6 +41,11 @@ LLVMSectionIteratorRef = _make_opaque_ref("LLVMSectionIterator")
41
41
  LLVMOrcLLJITRef = _make_opaque_ref("LLVMOrcLLJITRef")
42
42
  LLVMOrcDylibTrackerRef = _make_opaque_ref("LLVMOrcDylibTrackerRef")
43
43
 
44
+ LLVMPipelineTuningOptionsRef = _make_opaque_ref("LLVMPipeLineTuningOptions")
45
+ LLVMModulePassManagerRef = _make_opaque_ref("LLVMModulePassManager")
46
+ LLVMFunctionPassManagerRef = _make_opaque_ref("LLVMFunctionPassManager")
47
+ LLVMPassBuilderRef = _make_opaque_ref("LLVMPassBuilder")
48
+
44
49
 
45
50
  class _LLVMLock:
46
51
  """A Lock to guarantee thread-safety for the LLVM C-API.
@@ -207,7 +212,7 @@ def _importlib_resources_path_repl(package, resource):
207
212
 
208
213
 
209
214
  _importlib_resources_path = (_importlib_resources_path_repl
210
- if sys.version_info[:2] >= (3, 9)
215
+ if sys.version_info[:2] >= (3, 10)
211
216
  else _impres.path)
212
217
 
213
218
 
Binary file
@@ -0,0 +1,357 @@
1
+ from ctypes import c_bool, c_int, c_size_t
2
+ from enum import IntFlag
3
+ from llvmlite.binding import ffi
4
+
5
+
6
+ def create_new_module_pass_manager():
7
+ return ModulePassManager()
8
+
9
+
10
+ def create_new_function_pass_manager():
11
+ return FunctionPassManager()
12
+
13
+
14
+ def create_pass_builder(tm, pto):
15
+ return PassBuilder(tm, pto)
16
+
17
+
18
+ def create_pipeline_tuning_options(speed_level=2, size_level=0):
19
+ return PipelineTuningOptions(speed_level, size_level)
20
+
21
+
22
+ class RefPruneSubpasses(IntFlag):
23
+ PER_BB = 0b0001 # noqa: E221
24
+ DIAMOND = 0b0010 # noqa: E221
25
+ FANOUT = 0b0100 # noqa: E221
26
+ FANOUT_RAISE = 0b1000
27
+ ALL = PER_BB | DIAMOND | FANOUT | FANOUT_RAISE
28
+
29
+
30
+ class ModulePassManager(ffi.ObjectRef):
31
+
32
+ def __init__(self, ptr=None):
33
+ if ptr is None:
34
+ ptr = ffi.lib.LLVMPY_CreateNewModulePassManager()
35
+ super().__init__(ptr)
36
+
37
+ def run(self, module, pb):
38
+ ffi.lib.LLVMPY_RunNewModulePassManager(self, module, pb)
39
+
40
+ def add_verifier(self):
41
+ ffi.lib.LLVMPY_AddVerifierPass(self)
42
+
43
+ def add_aa_eval_pass(self):
44
+ ffi.lib.LLVMPY_AddAAEvalPass_module(self)
45
+
46
+ def add_simplify_cfg_pass(self):
47
+ ffi.lib.LLVMPY_AddSimplifyCFGPass_module(self)
48
+
49
+ def add_loop_unroll_pass(self):
50
+ ffi.lib.LLVMPY_AddLoopUnrollPass_module(self)
51
+
52
+ def add_loop_rotate_pass(self):
53
+ ffi.lib.LLVMPY_AddLoopRotatePass_module(self)
54
+
55
+ def add_instruction_combine_pass(self):
56
+ ffi.lib.LLVMPY_AddInstructionCombinePass_module(self)
57
+
58
+ def add_jump_threading_pass(self, threshold=-1):
59
+ ffi.lib.LLVMPY_AddJumpThreadingPass_module(self, threshold)
60
+
61
+ def _dispose(self):
62
+ ffi.lib.LLVMPY_DisposeNewModulePassManger(self)
63
+
64
+ # Non-standard LLVM passes
65
+ def add_refprune_pass(self, subpasses_flags=RefPruneSubpasses.ALL,
66
+ subgraph_limit=1000):
67
+ """Add Numba specific Reference count pruning pass.
68
+
69
+ Parameters
70
+ ----------
71
+ subpasses_flags : RefPruneSubpasses
72
+ A bitmask to control the subpasses to be enabled.
73
+ subgraph_limit : int
74
+ Limit the fanout pruners to working on a subgraph no bigger than
75
+ this number of basic-blocks to avoid spending too much time in very
76
+ large graphs. Default is 1000. Subject to change in future
77
+ versions.
78
+ """
79
+ iflags = RefPruneSubpasses(subpasses_flags)
80
+ ffi.lib.LLVMPY_AddRefPrunePass_module(self, iflags, subgraph_limit)
81
+
82
+
83
+ class FunctionPassManager(ffi.ObjectRef):
84
+
85
+ def __init__(self, ptr=None):
86
+ if ptr is None:
87
+ ptr = ffi.lib.LLVMPY_CreateNewFunctionPassManager()
88
+ super().__init__(ptr)
89
+
90
+ def run(self, fun, pb):
91
+ ffi.lib.LLVMPY_RunNewFunctionPassManager(self, fun, pb)
92
+
93
+ def add_aa_eval_pass(self):
94
+ ffi.lib.LLVMPY_AddAAEvalPass_function(self)
95
+
96
+ def add_simplify_cfg_pass(self):
97
+ ffi.lib.LLVMPY_AddSimplifyCFGPass_function(self)
98
+
99
+ def add_loop_unroll_pass(self):
100
+ ffi.lib.LLVMPY_AddLoopUnrollPass_function(self)
101
+
102
+ def add_loop_rotate_pass(self):
103
+ ffi.lib.LLVMPY_AddLoopRotatePass_function(self)
104
+
105
+ def add_instruction_combine_pass(self):
106
+ ffi.lib.LLVMPY_AddInstructionCombinePass_function(self)
107
+
108
+ def add_jump_threading_pass(self, threshold=-1):
109
+ ffi.lib.LLVMPY_AddJumpThreadingPass_function(self, threshold)
110
+
111
+ def _dispose(self):
112
+ ffi.lib.LLVMPY_DisposeNewFunctionPassManger(self)
113
+
114
+ # Non-standard LLVM passes
115
+ def add_refprune_pass(self, subpasses_flags=RefPruneSubpasses.ALL,
116
+ subgraph_limit=1000):
117
+ """Add Numba specific Reference count pruning pass.
118
+
119
+ Parameters
120
+ ----------
121
+ subpasses_flags : RefPruneSubpasses
122
+ A bitmask to control the subpasses to be enabled.
123
+ subgraph_limit : int
124
+ Limit the fanout pruners to working on a subgraph no bigger than
125
+ this number of basic-blocks to avoid spending too much time in very
126
+ large graphs. Default is 1000. Subject to change in future
127
+ versions.
128
+ """
129
+ iflags = RefPruneSubpasses(subpasses_flags)
130
+ ffi.lib.LLVMPY_AddRefPrunePass_function(self, iflags, subgraph_limit)
131
+
132
+
133
+ class PipelineTuningOptions(ffi.ObjectRef):
134
+
135
+ def __init__(self, speed_level=2, size_level=0):
136
+ self._speed_level = None
137
+ self._size_level = None
138
+ self.speed_level = speed_level
139
+ self.size_level = size_level
140
+ super().__init__(ffi.lib.LLVMPY_CreatePipelineTuningOptions())
141
+
142
+ @property
143
+ def speed_level(self):
144
+ return self._speed_level
145
+
146
+ @speed_level.setter
147
+ def speed_level(self, value):
148
+ if not 0 <= value <= 3:
149
+ raise ValueError(
150
+ "Optimization level for speed should be 0, 1, 2, or 3")
151
+ self._speed_level = value
152
+
153
+ @property
154
+ def size_level(self):
155
+ return self._size_level
156
+
157
+ @size_level.setter
158
+ def size_level(self, value):
159
+ if not 0 <= value <= 2:
160
+ raise ValueError("Optimization level for size should be 0, 1, or 2")
161
+ if value != 0 and self.speed_level != 2:
162
+ raise ValueError(
163
+ "Optimization for size should be encoded with speed level == 2")
164
+ self._size_level = value
165
+
166
+ @property
167
+ def loop_interleaving(self):
168
+ return ffi.lib.LLVMPY_PTOGetLoopInterleaving(self)
169
+
170
+ @loop_interleaving.setter
171
+ def loop_interleaving(self, value):
172
+ ffi.lib.LLVMPY_PTOSetLoopInterleaving(self, value)
173
+
174
+ @property
175
+ def loop_vectorization(self):
176
+ return ffi.lib.LLVMPY_PTOGetLoopVectorization(self)
177
+
178
+ @loop_vectorization.setter
179
+ def loop_vectorization(self, value):
180
+ ffi.lib.LLVMPY_PTOSetLoopVectorization(self, value)
181
+
182
+ @property
183
+ def slp_vectorization(self):
184
+ return ffi.lib.LLVMPY_PTOGetSLPVectorization(self)
185
+
186
+ @slp_vectorization.setter
187
+ def slp_vectorization(self, value):
188
+ ffi.lib.LLVMPY_PTOSetSLPVectorization(self, value)
189
+
190
+ @property
191
+ def loop_unrolling(self):
192
+ return ffi.lib.LLVMPY_PTOGetLoopUnrolling(self)
193
+
194
+ @loop_unrolling.setter
195
+ def loop_unrolling(self, value):
196
+ ffi.lib.LLVMPY_PTOSetLoopUnrolling(self, value)
197
+
198
+ # // FIXME: Available from llvm16
199
+ # @property
200
+ # def inlining_threshold(self):
201
+ # return ffi.lib.LLVMPY_PTOGetInlinerThreshold(self)
202
+
203
+ # @inlining_threshold.setter
204
+ # def inlining_threshold(self, value):
205
+ # ffi.lib.LLVMPY_PTOSetInlinerThreshold(self, value)
206
+
207
+ def _dispose(self):
208
+ ffi.lib.LLVMPY_DisposePipelineTuningOptions(self)
209
+
210
+
211
+ class PassBuilder(ffi.ObjectRef):
212
+
213
+ def __init__(self, tm, pto):
214
+ super().__init__(ffi.lib.LLVMPY_CreatePassBuilder(tm, pto))
215
+ self._pto = pto
216
+ self._tm = tm
217
+
218
+ def getModulePassManager(self):
219
+ return ModulePassManager(
220
+ ffi.lib.LLVMPY_buildPerModuleDefaultPipeline(
221
+ self, self._pto.speed_level, self._pto.size_level)
222
+ )
223
+
224
+ def getFunctionPassManager(self):
225
+ return FunctionPassManager(
226
+ ffi.lib.LLVMPY_buildFunctionSimplificationPipeline(
227
+ self, self._pto.speed_level, self._pto.size_level)
228
+ )
229
+
230
+ def _dispose(self):
231
+ ffi.lib.LLVMPY_DisposePassBuilder(self)
232
+
233
+
234
+ # ============================================================================
235
+ # FFI
236
+
237
+ # ModulePassManager
238
+
239
+ ffi.lib.LLVMPY_CreateNewModulePassManager.restype = ffi.LLVMModulePassManagerRef
240
+
241
+ ffi.lib.LLVMPY_RunNewModulePassManager.argtypes = [
242
+ ffi.LLVMModulePassManagerRef, ffi.LLVMModuleRef,
243
+ ffi.LLVMPassBuilderRef,]
244
+
245
+ ffi.lib.LLVMPY_AddVerifierPass.argtypes = [ffi.LLVMModulePassManagerRef,]
246
+ ffi.lib.LLVMPY_AddAAEvalPass_module.argtypes = [ffi.LLVMModulePassManagerRef,]
247
+ ffi.lib.LLVMPY_AddSimplifyCFGPass_module.argtypes = [
248
+ ffi.LLVMModulePassManagerRef,]
249
+
250
+ ffi.lib.LLVMPY_AddLoopUnrollPass_module.argtypes = [
251
+ ffi.LLVMModulePassManagerRef,]
252
+
253
+ ffi.lib.LLVMPY_AddLoopRotatePass_module.argtypes = [
254
+ ffi.LLVMModulePassManagerRef,]
255
+
256
+ ffi.lib.LLVMPY_AddInstructionCombinePass_module.argtypes = [
257
+ ffi.LLVMModulePassManagerRef,]
258
+
259
+ ffi.lib.LLVMPY_AddJumpThreadingPass_module.argtypes = [
260
+ ffi.LLVMModulePassManagerRef,]
261
+
262
+ ffi.lib.LLVMPY_DisposeNewModulePassManger.argtypes = [
263
+ ffi.LLVMModulePassManagerRef,]
264
+
265
+ ffi.lib.LLVMPY_AddRefPrunePass_module.argtypes = [
266
+ ffi.LLVMModulePassManagerRef, c_int, c_size_t,
267
+ ]
268
+
269
+ # FunctionPassManager
270
+
271
+ ffi.lib.LLVMPY_CreateNewFunctionPassManager.restype = \
272
+ ffi.LLVMFunctionPassManagerRef
273
+
274
+ ffi.lib.LLVMPY_RunNewFunctionPassManager.argtypes = [
275
+ ffi.LLVMFunctionPassManagerRef, ffi.LLVMValueRef,
276
+ ffi.LLVMPassBuilderRef,]
277
+
278
+ ffi.lib.LLVMPY_AddAAEvalPass_function.argtypes = [
279
+ ffi.LLVMFunctionPassManagerRef,]
280
+
281
+ ffi.lib.LLVMPY_AddSimplifyCFGPass_function.argtypes = [
282
+ ffi.LLVMFunctionPassManagerRef,]
283
+
284
+ ffi.lib.LLVMPY_AddLoopUnrollPass_function.argtypes = [
285
+ ffi.LLVMFunctionPassManagerRef,]
286
+
287
+ ffi.lib.LLVMPY_AddLoopRotatePass_function.argtypes = [
288
+ ffi.LLVMFunctionPassManagerRef,]
289
+
290
+ ffi.lib.LLVMPY_AddInstructionCombinePass_function.argtypes = [
291
+ ffi.LLVMFunctionPassManagerRef,]
292
+
293
+ ffi.lib.LLVMPY_AddJumpThreadingPass_function.argtypes = [
294
+ ffi.LLVMFunctionPassManagerRef, c_int,]
295
+
296
+ ffi.lib.LLVMPY_DisposeNewFunctionPassManger.argtypes = [
297
+ ffi.LLVMFunctionPassManagerRef,]
298
+
299
+ ffi.lib.LLVMPY_AddRefPrunePass_function.argtypes = [
300
+ ffi.LLVMFunctionPassManagerRef, c_int, c_size_t,
301
+ ]
302
+
303
+ # PipelineTuningOptions
304
+
305
+ ffi.lib.LLVMPY_CreatePipelineTuningOptions.restype = \
306
+ ffi.LLVMPipelineTuningOptionsRef
307
+
308
+ ffi.lib.LLVMPY_PTOGetLoopInterleaving.restype = c_bool
309
+ ffi.lib.LLVMPY_PTOGetLoopInterleaving.argtypes = [
310
+ ffi.LLVMPipelineTuningOptionsRef,]
311
+
312
+ ffi.lib.LLVMPY_PTOSetLoopInterleaving.argtypes = [
313
+ ffi.LLVMPipelineTuningOptionsRef, c_bool]
314
+
315
+ ffi.lib.LLVMPY_PTOGetLoopVectorization.restype = c_bool
316
+ ffi.lib.LLVMPY_PTOGetLoopVectorization.argtypes = [
317
+ ffi.LLVMPipelineTuningOptionsRef,]
318
+
319
+ ffi.lib.LLVMPY_PTOSetLoopVectorization.argtypes = [
320
+ ffi.LLVMPipelineTuningOptionsRef, c_bool]
321
+
322
+ ffi.lib.LLVMPY_PTOGetSLPVectorization.restype = c_bool
323
+ ffi.lib.LLVMPY_PTOGetSLPVectorization.argtypes = [
324
+ ffi.LLVMPipelineTuningOptionsRef,]
325
+
326
+ ffi.lib.LLVMPY_PTOSetSLPVectorization.argtypes = [
327
+ ffi.LLVMPipelineTuningOptionsRef, c_bool]
328
+
329
+ ffi.lib.LLVMPY_PTOGetLoopUnrolling.restype = c_bool
330
+ ffi.lib.LLVMPY_PTOGetLoopUnrolling.argtypes = [
331
+ ffi.LLVMPipelineTuningOptionsRef,]
332
+
333
+ ffi.lib.LLVMPY_PTOSetLoopUnrolling.argtypes = [
334
+ ffi.LLVMPipelineTuningOptionsRef, c_bool]
335
+
336
+ ffi.lib.LLVMPY_DisposePipelineTuningOptions.argtypes = \
337
+ [ffi.LLVMPipelineTuningOptionsRef,]
338
+
339
+ # PassBuilder
340
+
341
+ ffi.lib.LLVMPY_CreatePassBuilder.restype = ffi.LLVMPassBuilderRef
342
+ ffi.lib.LLVMPY_CreatePassBuilder.argtypes = [ffi.LLVMTargetMachineRef,
343
+ ffi.LLVMPipelineTuningOptionsRef,]
344
+
345
+ ffi.lib.LLVMPY_DisposePassBuilder.argtypes = [ffi.LLVMPassBuilderRef,]
346
+
347
+ # Pipeline builders
348
+
349
+ ffi.lib.LLVMPY_buildPerModuleDefaultPipeline.restype = \
350
+ ffi.LLVMModulePassManagerRef
351
+ ffi.lib.LLVMPY_buildPerModuleDefaultPipeline.argtypes = [
352
+ ffi.LLVMPassBuilderRef, c_int, c_int]
353
+
354
+ ffi.lib.LLVMPY_buildFunctionSimplificationPipeline.restype = \
355
+ ffi.LLVMFunctionPassManagerRef
356
+ ffi.lib.LLVMPY_buildFunctionSimplificationPipeline.argtypes = [
357
+ ffi.LLVMPassBuilderRef, c_int, c_int]
@@ -1,4 +1,4 @@
1
- from ctypes import (c_bool, c_char_p, c_int, c_size_t, c_uint, Structure, byref,
1
+ from ctypes import (c_bool, c_char_p, c_int, c_size_t, Structure, byref,
2
2
  POINTER)
3
3
  from collections import namedtuple
4
4
  from enum import IntFlag
@@ -8,11 +8,11 @@ import os
8
8
  from tempfile import mkstemp
9
9
  from llvmlite.binding.common import _encode_string
10
10
 
11
+ llvm_version_major = llvm_version_info[0]
12
+
11
13
  _prunestats = namedtuple('PruneStats',
12
14
  ('basicblock diamond fanout fanout_raise'))
13
15
 
14
- llvm_version_major = llvm_version_info[0]
15
-
16
16
 
17
17
  class PruneStats(_prunestats):
18
18
  """ Holds statistics from reference count pruning.
@@ -261,9 +261,7 @@ class PassManager(ffi.ObjectRef):
261
261
 
262
262
  LLVM 14: `llvm::createArgumentPromotionPass`
263
263
  """ # noqa E501
264
- if llvm_version_major > 14:
265
- raise RuntimeError('ArgumentPromotionPass unavailable in LLVM > 14')
266
- ffi.lib.LLVMPY_AddArgPromotionPass(self, max_elements)
264
+ raise RuntimeError('ArgumentPromotionPass unavailable in LLVM > 14')
267
265
 
268
266
  def add_break_critical_edges_pass(self):
269
267
  """
@@ -342,6 +340,10 @@ class PassManager(ffi.ObjectRef):
342
340
 
343
341
  LLVM 14: `llvm::createAggressiveInstCombinerPass`
344
342
  """ # noqa E501
343
+ if llvm_version_major > 15:
344
+ msg = "AggressiveInstrCombinerPass unavailable in LLVM > 15"
345
+ raise RuntimeError(msg)
346
+
345
347
  ffi.lib.LLVMPY_AddAggressiveInstructionCombiningPass(self)
346
348
 
347
349
  def add_internalize_pass(self):
@@ -538,6 +540,8 @@ class PassManager(ffi.ObjectRef):
538
540
 
539
541
  LLVM 14: `llvm::createPruneEHPass`
540
542
  """ # noqa E501
543
+ if llvm_version_major > 15:
544
+ raise RuntimeError("PruneEHPass unavailable in LLVM > 15")
541
545
  ffi.lib.LLVMPY_AddPruneExceptionHandlingPass(self)
542
546
 
543
547
  def add_reassociate_expressions_pass(self):
@@ -638,7 +642,7 @@ class PassManager(ffi.ObjectRef):
638
642
 
639
643
  def add_loop_rotate_pass(self):
640
644
  """http://llvm.org/docs/Passes.html#loop-rotate-rotate-loops."""
641
- ffi.lib.LLVMPY_LLVMAddLoopRotatePass(self)
645
+ ffi.lib.LLVMPY_AddLoopRotatePass(self)
642
646
 
643
647
  def add_target_library_info(self, triple):
644
648
  ffi.lib.LLVMPY_AddTargetLibraryInfoPass(self, _encode_string(triple))
@@ -668,7 +672,7 @@ class PassManager(ffi.ObjectRef):
668
672
  versions.
669
673
  """
670
674
  iflags = RefPruneSubpasses(subpasses_flags)
671
- ffi.lib.LLVMPY_AddRefPrunePass(self, iflags, subgraph_limit)
675
+ ffi.lib.LLVMPY_AddLegacyRefPrunePass(self, iflags, subgraph_limit)
672
676
 
673
677
 
674
678
  class ModulePassManager(PassManager):
@@ -871,18 +875,16 @@ ffi.lib.LLVMPY_AddRegionInfoPass.argtypes = [ffi.LLVMPassManagerRef]
871
875
  ffi.lib.LLVMPY_AddScalarEvolutionAAPass.argtypes = [ffi.LLVMPassManagerRef]
872
876
  ffi.lib.LLVMPY_AddAggressiveDCEPass.argtypes = [ffi.LLVMPassManagerRef]
873
877
  ffi.lib.LLVMPY_AddAlwaysInlinerPass.argtypes = [ffi.LLVMPassManagerRef, c_bool]
874
-
875
- if llvm_version_major < 15:
876
- ffi.lib.LLVMPY_AddArgPromotionPass.argtypes = [
877
- ffi.LLVMPassManagerRef, c_uint]
878
-
879
878
  ffi.lib.LLVMPY_AddBreakCriticalEdgesPass.argtypes = [ffi.LLVMPassManagerRef]
880
879
  ffi.lib.LLVMPY_AddDeadStoreEliminationPass.argtypes = [
881
880
  ffi.LLVMPassManagerRef]
882
881
  ffi.lib.LLVMPY_AddReversePostOrderFunctionAttrsPass.argtypes = [
883
882
  ffi.LLVMPassManagerRef]
884
- ffi.lib.LLVMPY_AddAggressiveInstructionCombiningPass.argtypes = [
885
- ffi.LLVMPassManagerRef]
883
+
884
+ if llvm_version_major < 16:
885
+ ffi.lib.LLVMPY_AddAggressiveInstructionCombiningPass.argtypes = [
886
+ ffi.LLVMPassManagerRef]
887
+
886
888
  ffi.lib.LLVMPY_AddInternalizePass.argtypes = [ffi.LLVMPassManagerRef]
887
889
  ffi.lib.LLVMPY_AddLCSSAPass.argtypes = [ffi.LLVMPassManagerRef]
888
890
  ffi.lib.LLVMPY_AddLoopDeletionPass.argtypes = [ffi.LLVMPassManagerRef]
@@ -901,7 +903,12 @@ ffi.lib.LLVMPY_AddMemCpyOptimizationPass.argtypes = [ffi.LLVMPassManagerRef]
901
903
  ffi.lib.LLVMPY_AddMergeFunctionsPass.argtypes = [ffi.LLVMPassManagerRef]
902
904
  ffi.lib.LLVMPY_AddMergeReturnsPass.argtypes = [ffi.LLVMPassManagerRef]
903
905
  ffi.lib.LLVMPY_AddPartialInliningPass.argtypes = [ffi.LLVMPassManagerRef]
904
- ffi.lib.LLVMPY_AddPruneExceptionHandlingPass.argtypes = [ffi.LLVMPassManagerRef]
906
+
907
+ if llvm_version_major < 16:
908
+ ffi.lib.LLVMPY_AddPruneExceptionHandlingPass.argtypes = [
909
+ ffi.LLVMPassManagerRef
910
+ ]
911
+
905
912
  ffi.lib.LLVMPY_AddReassociatePass.argtypes = [ffi.LLVMPassManagerRef]
906
913
  ffi.lib.LLVMPY_AddDemoteRegisterToMemoryPass.argtypes = [ffi.LLVMPassManagerRef]
907
914
  ffi.lib.LLVMPY_AddSinkPass.argtypes = [ffi.LLVMPassManagerRef]
@@ -933,7 +940,7 @@ ffi.lib.LLVMPY_AddTargetLibraryInfoPass.argtypes = [ffi.LLVMPassManagerRef,
933
940
  c_char_p]
934
941
  ffi.lib.LLVMPY_AddInstructionNamerPass.argtypes = [ffi.LLVMPassManagerRef]
935
942
 
936
- ffi.lib.LLVMPY_AddRefPrunePass.argtypes = [ffi.LLVMPassManagerRef, c_int,
937
- c_size_t]
943
+ ffi.lib.LLVMPY_AddLegacyRefPrunePass.argtypes = [ffi.LLVMPassManagerRef, c_int,
944
+ c_size_t]
938
945
 
939
946
  ffi.lib.LLVMPY_DumpRefPruneStats.argtypes = [POINTER(_c_PruneStats), c_bool]
@@ -3,7 +3,16 @@ from ctypes import (POINTER, c_char_p, c_longlong, c_int, c_size_t,
3
3
  c_void_p, string_at)
4
4
 
5
5
  from llvmlite.binding import ffi
6
+ from llvmlite.binding.initfini import llvm_version_info
6
7
  from llvmlite.binding.common import _decode_string, _encode_string
8
+ from collections import namedtuple
9
+
10
+ # FIXME: Remove `opaque_pointers_enabled` once typed pointers are no longer
11
+ # supported.
12
+ from llvmlite import opaque_pointers_enabled
13
+
14
+ Triple = namedtuple('Triple', ['Arch', 'SubArch', 'Vendor',
15
+ 'OS', 'Env', 'ObjectFormat'])
7
16
 
8
17
 
9
18
  def get_process_triple():
@@ -18,6 +27,25 @@ def get_process_triple():
18
27
  return str(out)
19
28
 
20
29
 
30
+ def get_triple_parts(triple: str):
31
+ """
32
+ Return a tuple of the parts of the given triple.
33
+ """
34
+ with ffi.OutputString() as arch, \
35
+ ffi.OutputString() as vendor, \
36
+ ffi.OutputString() as os, ffi.OutputString() as env:
37
+ ffi.lib.LLVMPY_GetTripleParts(triple.encode('utf8'),
38
+ arch, vendor, os, env)
39
+ arch = str(arch)
40
+ subarch = ''
41
+ for _str in triple.split('-'):
42
+ if _str.startswith(arch):
43
+ subarch = _str[len(arch):]
44
+ break
45
+ return Triple(arch, subarch, str(vendor), str(os),
46
+ str(env), get_object_format(triple))
47
+
48
+
21
49
  class FeatureMap(dict):
22
50
  """
23
51
  Maps feature name to a boolean indicating the availability of the feature.
@@ -87,11 +115,32 @@ def get_host_cpu_name():
87
115
  return str(out)
88
116
 
89
117
 
90
- _object_formats = {
91
- 1: "COFF",
92
- 2: "ELF",
93
- 3: "MachO",
94
- }
118
+ # Adapted from https://github.com/llvm/llvm-project/blob/release/15.x/llvm/include/llvm/ADT/Triple.h#L269 # noqa
119
+ llvm_version_major = llvm_version_info[0]
120
+
121
+
122
+ if llvm_version_major >= 15:
123
+ _object_formats = {
124
+ 0: "Unknown",
125
+ 1: "COFF",
126
+ 2: "DXContainer",
127
+ 3: "ELF",
128
+ 4: "GOFF",
129
+ 5: "MachO",
130
+ 6: "SPIRV",
131
+ 7: "Wasm",
132
+ 8: "XCOFF",
133
+ }
134
+ else:
135
+ _object_formats = {
136
+ 0: "Unknown",
137
+ 1: "COFF",
138
+ 2: "ELF",
139
+ 3: "GOFF",
140
+ 4: "MachO",
141
+ 5: "Wasm",
142
+ 6: "XCOFF",
143
+ }
95
144
 
96
145
 
97
146
  def get_object_format(triple=None):
@@ -147,10 +196,19 @@ class TargetData(ffi.ObjectRef):
147
196
  "type?".format(position, str(ty)))
148
197
  return offset
149
198
 
199
+ def get_abi_alignment(self, ty):
200
+ """
201
+ Get minimum ABI alignment of LLVM type *ty*.
202
+ """
203
+ return ffi.lib.LLVMPY_ABIAlignmentOfType(self, ty)
204
+
150
205
  def get_pointee_abi_size(self, ty):
151
206
  """
152
207
  Get ABI size of pointee type of LLVM pointer type *ty*.
153
208
  """
209
+ if opaque_pointers_enabled:
210
+ raise RuntimeError("Cannot get pointee type in opaque pointer "
211
+ "mode.")
154
212
  size = ffi.lib.LLVMPY_ABISizeOfElementType(self, ty)
155
213
  if size == -1:
156
214
  raise RuntimeError("Not a pointer type: %s" % (ty,))
@@ -160,6 +218,9 @@ class TargetData(ffi.ObjectRef):
160
218
  """
161
219
  Get minimum ABI alignment of pointee type of LLVM pointer type *ty*.
162
220
  """
221
+ if opaque_pointers_enabled:
222
+ raise RuntimeError("Cannot get pointee type in opaque pointer "
223
+ "mode.")
163
224
  size = ffi.lib.LLVMPY_ABIAlignmentOfElementType(self, ty)
164
225
  if size == -1:
165
226
  raise RuntimeError("Not a pointer type: %s" % (ty,))
@@ -340,6 +401,9 @@ def has_svml():
340
401
  # FFI
341
402
 
342
403
  ffi.lib.LLVMPY_GetProcessTriple.argtypes = [POINTER(c_char_p)]
404
+ ffi.lib.LLVMPY_GetTripleParts.argtypes = [c_char_p, POINTER(c_char_p),
405
+ POINTER(c_char_p), POINTER(c_char_p),
406
+ POINTER(c_char_p)]
343
407
 
344
408
  ffi.lib.LLVMPY_GetHostCPUFeatures.argtypes = [POINTER(c_char_p)]
345
409
  ffi.lib.LLVMPY_GetHostCPUFeatures.restype = c_int
@@ -372,10 +436,16 @@ ffi.lib.LLVMPY_OffsetOfElement.argtypes = [ffi.LLVMTargetDataRef,
372
436
  c_int]
373
437
  ffi.lib.LLVMPY_OffsetOfElement.restype = c_longlong
374
438
 
439
+ ffi.lib.LLVMPY_ABIAlignmentOfType.argtypes = [ffi.LLVMTargetDataRef,
440
+ ffi.LLVMTypeRef]
441
+ ffi.lib.LLVMPY_ABIAlignmentOfType.restype = c_longlong
442
+
443
+ # FIXME: Remove me once typed pointers are no longer supported.
375
444
  ffi.lib.LLVMPY_ABISizeOfElementType.argtypes = [ffi.LLVMTargetDataRef,
376
445
  ffi.LLVMTypeRef]
377
446
  ffi.lib.LLVMPY_ABISizeOfElementType.restype = c_longlong
378
447
 
448
+ # FIXME: Remove me once typed pointers are no longer supported.
379
449
  ffi.lib.LLVMPY_ABIAlignmentOfElementType.argtypes = [ffi.LLVMTargetDataRef,
380
450
  ffi.LLVMTypeRef]
381
451
  ffi.lib.LLVMPY_ABIAlignmentOfElementType.restype = c_longlong