llvmlite 0.44.0rc1__cp311-cp311-macosx_11_0_arm64.whl → 0.45.0rc1__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.

@@ -1,946 +0,0 @@
1
- from ctypes import (c_bool, c_char_p, c_int, c_size_t, Structure, byref,
2
- POINTER)
3
- from collections import namedtuple
4
- from enum import IntFlag
5
- from llvmlite.binding import ffi
6
- from llvmlite.binding.initfini import llvm_version_info
7
- import os
8
- from tempfile import mkstemp
9
- from llvmlite.binding.common import _encode_string
10
-
11
- llvm_version_major = llvm_version_info[0]
12
-
13
- _prunestats = namedtuple('PruneStats',
14
- ('basicblock diamond fanout fanout_raise'))
15
-
16
-
17
- class PruneStats(_prunestats):
18
- """ Holds statistics from reference count pruning.
19
- """
20
-
21
- def __add__(self, other):
22
- if not isinstance(other, PruneStats):
23
- msg = 'PruneStats can only be added to another PruneStats, got {}.'
24
- raise TypeError(msg.format(type(other)))
25
- return PruneStats(self.basicblock + other.basicblock,
26
- self.diamond + other.diamond,
27
- self.fanout + other.fanout,
28
- self.fanout_raise + other.fanout_raise)
29
-
30
- def __sub__(self, other):
31
- if not isinstance(other, PruneStats):
32
- msg = ('PruneStats can only be subtracted from another PruneStats, '
33
- 'got {}.')
34
- raise TypeError(msg.format(type(other)))
35
- return PruneStats(self.basicblock - other.basicblock,
36
- self.diamond - other.diamond,
37
- self.fanout - other.fanout,
38
- self.fanout_raise - other.fanout_raise)
39
-
40
-
41
- class _c_PruneStats(Structure):
42
- _fields_ = [
43
- ('basicblock', c_size_t),
44
- ('diamond', c_size_t),
45
- ('fanout', c_size_t),
46
- ('fanout_raise', c_size_t)]
47
-
48
-
49
- def dump_refprune_stats(printout=False):
50
- """ Returns a namedtuple containing the current values for the refop pruning
51
- statistics. If kwarg `printout` is True the stats are printed to stderr,
52
- default is False.
53
- """
54
-
55
- stats = _c_PruneStats(0, 0, 0, 0)
56
- do_print = c_bool(printout)
57
-
58
- ffi.lib.LLVMPY_DumpRefPruneStats(byref(stats), do_print)
59
- return PruneStats(stats.basicblock, stats.diamond, stats.fanout,
60
- stats.fanout_raise)
61
-
62
-
63
- def set_time_passes(enable):
64
- """Enable or disable the pass timers.
65
-
66
- Parameters
67
- ----------
68
- enable : bool
69
- Set to True to enable the pass timers.
70
- Set to False to disable the pass timers.
71
- """
72
- ffi.lib.LLVMPY_SetTimePasses(c_bool(enable))
73
-
74
-
75
- def report_and_reset_timings():
76
- """Returns the pass timings report and resets the LLVM internal timers.
77
-
78
- Pass timers are enabled by ``set_time_passes()``. If the timers are not
79
- enabled, this function will return an empty string.
80
-
81
- Returns
82
- -------
83
- res : str
84
- LLVM generated timing report.
85
- """
86
- with ffi.OutputString() as buf:
87
- ffi.lib.LLVMPY_ReportAndResetTimings(buf)
88
- return str(buf)
89
-
90
-
91
- def create_module_pass_manager():
92
- return ModulePassManager()
93
-
94
-
95
- def create_function_pass_manager(module):
96
- return FunctionPassManager(module)
97
-
98
-
99
- class RefPruneSubpasses(IntFlag):
100
- PER_BB = 0b0001 # noqa: E221
101
- DIAMOND = 0b0010 # noqa: E221
102
- FANOUT = 0b0100 # noqa: E221
103
- FANOUT_RAISE = 0b1000
104
- ALL = PER_BB | DIAMOND | FANOUT | FANOUT_RAISE
105
-
106
-
107
- class PassManager(ffi.ObjectRef):
108
- """PassManager
109
- """
110
-
111
- def _dispose(self):
112
- self._capi.LLVMPY_DisposePassManager(self)
113
-
114
- def add_aa_eval_pass(self):
115
- """
116
- See https://llvm.org/docs/Passes.html#aa-eval-exhaustive-alias-analysis-precision-evaluator
117
-
118
- LLVM 14: `llvm::createAAEvalPass`
119
- """ # noqa E501
120
- ffi.lib.LLVMPY_AddAAEvalPass(self)
121
-
122
- def add_basic_aa_pass(self):
123
- """
124
- See https://llvm.org/docs/Passes.html#basic-aa-basic-alias-analysis-stateless-aa-impl
125
-
126
- LLVM 14: `llvm::createBasicAAWrapperPass`
127
- """ # noqa E501
128
- ffi.lib.LLVMPY_AddBasicAAWrapperPass(self)
129
-
130
- def add_constant_merge_pass(self):
131
- """
132
- See http://llvm.org/docs/Passes.html#constmerge-merge-duplicate-global-constants
133
-
134
- LLVM 14: `LLVMAddConstantMergePass`
135
- """ # noqa E501
136
- ffi.lib.LLVMPY_AddConstantMergePass(self)
137
-
138
- def add_dead_arg_elimination_pass(self):
139
- """
140
- See http://llvm.org/docs/Passes.html#deadargelim-dead-argument-elimination
141
-
142
- LLVM 14: `LLVMAddDeadArgEliminationPass`
143
- """ # noqa E501
144
- ffi.lib.LLVMPY_AddDeadArgEliminationPass(self)
145
-
146
- def add_dependence_analysis_pass(self):
147
- """
148
- See https://llvm.org/docs/Passes.html#da-dependence-analysis
149
-
150
- LLVM 14: `llvm::createDependenceAnalysisWrapperPass`
151
- """ # noqa E501
152
- ffi.lib.LLVMPY_AddDependenceAnalysisPass(self)
153
-
154
- def add_dot_call_graph_pass(self):
155
- """
156
- See https://llvm.org/docs/Passes.html#dot-callgraph-print-call-graph-to-dot-file
157
-
158
- LLVM 14: `llvm::createCallGraphDOTPrinterPass`
159
- """ # noqa E501
160
- ffi.lib.LLVMPY_AddCallGraphDOTPrinterPass(self)
161
-
162
- def add_dot_cfg_printer_pass(self):
163
- """
164
- See https://llvm.org/docs/Passes.html#dot-cfg-print-cfg-of-function-to-dot-file
165
-
166
- LLVM 14: `llvm::createCFGPrinterLegacyPassPass`
167
- """ # noqa E501
168
- ffi.lib.LLVMPY_AddCFGPrinterPass(self)
169
-
170
- def add_dot_dom_printer_pass(self, show_body=False):
171
- """
172
- See https://llvm.org/docs/Passes.html#dot-dom-print-dominance-tree-of-function-to-dot-file
173
-
174
- LLVM 14: `llvm::createDomPrinterPass` and `llvm::createDomOnlyPrinterPass`
175
- """ # noqa E501
176
- ffi.lib.LLVMPY_AddDotDomPrinterPass(self, show_body)
177
-
178
- def add_dot_postdom_printer_pass(self, show_body=False):
179
- """
180
- See https://llvm.org/docs/Passes.html#dot-postdom-print-postdominance-tree-of-function-to-dot-file
181
-
182
- LLVM 14: `llvm::createPostDomPrinterPass` and `llvm::createPostDomOnlyPrinterPass`
183
- """ # noqa E501
184
- ffi.lib.LLVMPY_AddDotPostDomPrinterPass(self, show_body)
185
-
186
- def add_globals_mod_ref_aa_pass(self):
187
- """
188
- See https://llvm.org/docs/Passes.html#globalsmodref-aa-simple-mod-ref-analysis-for-globals
189
-
190
- LLVM 14: `llvm::createGlobalsAAWrapperPass`
191
- """ # noqa E501
192
- ffi.lib.LLVMPY_AddGlobalsModRefAAPass(self)
193
-
194
- def add_iv_users_pass(self):
195
- """
196
- See https://llvm.org/docs/Passes.html#iv-users-induction-variable-users
197
-
198
- LLVM 14: `llvm::createIVUsersPass`
199
- """ # noqa E501
200
- ffi.lib.LLVMPY_AddIVUsersPass(self)
201
-
202
- def add_lint_pass(self):
203
- """
204
- See https://llvm.org/docs/Passes.html#lint-statically-lint-checks-llvm-ir
205
-
206
- LLVM 14: `llvm::createLintLegacyPassPass`
207
- """ # noqa E501
208
- ffi.lib.LLVMPY_AddLintPass(self)
209
-
210
- def add_lazy_value_info_pass(self):
211
- """
212
- See https://llvm.org/docs/Passes.html#lazy-value-info-lazy-value-information-analysis
213
-
214
- LLVM 14: `llvm::createLazyValueInfoPass`
215
- """ # noqa E501
216
- ffi.lib.LLVMPY_AddLazyValueInfoPass(self)
217
-
218
- def add_module_debug_info_pass(self):
219
- """
220
- See https://llvm.org/docs/Passes.html#module-debuginfo-decodes-module-level-debug-info
221
-
222
- LLVM 14: `llvm::createModuleDebugInfoPrinterPass`
223
- """ # noqa E501
224
- ffi.lib.LLVMPY_AddModuleDebugInfoPrinterPass(self)
225
-
226
- def add_region_info_pass(self):
227
- """
228
- See https://llvm.org/docs/Passes.html#regions-detect-single-entry-single-exit-regions
229
-
230
- LLVM 14: `llvm::createRegionInfoPass`
231
- """ # noqa E501
232
- ffi.lib.LLVMPY_AddRegionInfoPass(self)
233
-
234
- def add_scalar_evolution_aa_pass(self):
235
- """
236
- See https://llvm.org/docs/Passes.html#scev-aa-scalarevolution-based-alias-analysis
237
-
238
- LLVM 14: `llvm::createSCEVAAWrapperPass`
239
- """ # noqa E501
240
- ffi.lib.LLVMPY_AddScalarEvolutionAAPass(self)
241
-
242
- def add_aggressive_dead_code_elimination_pass(self):
243
- """
244
- See https://llvm.org/docs/Passes.html#adce-aggressive-dead-code-elimination
245
-
246
- LLVM 14: `llvm::createAggressiveDCEPass`
247
- """ # noqa E501
248
- ffi.lib.LLVMPY_AddAggressiveDCEPass(self)
249
-
250
- def add_always_inliner_pass(self, insert_lifetime=True):
251
- """
252
- See https://llvm.org/docs/Passes.html#always-inline-inliner-for-always-inline-functions
253
-
254
- LLVM 14: `llvm::createAlwaysInlinerLegacyPass`
255
- """ # noqa E501
256
- ffi.lib.LLVMPY_AddAlwaysInlinerPass(self, insert_lifetime)
257
-
258
- def add_arg_promotion_pass(self, max_elements=3):
259
- """
260
- See https://llvm.org/docs/Passes.html#argpromotion-promote-by-reference-arguments-to-scalars
261
-
262
- LLVM 14: `llvm::createArgumentPromotionPass`
263
- """ # noqa E501
264
- raise RuntimeError('ArgumentPromotionPass unavailable in LLVM > 14')
265
-
266
- def add_break_critical_edges_pass(self):
267
- """
268
- See https://llvm.org/docs/Passes.html#break-crit-edges-break-critical-edges-in-cfg
269
-
270
- LLVM 14: `llvm::createBreakCriticalEdgesPass`
271
- """ # noqa E501
272
- ffi.lib.LLVMPY_AddBreakCriticalEdgesPass(self)
273
-
274
- def add_dead_store_elimination_pass(self):
275
- """
276
- See https://llvm.org/docs/Passes.html#dse-dead-store-elimination
277
-
278
- LLVM 14: `llvm::createDeadStoreEliminationPass`
279
- """ # noqa E501
280
- ffi.lib.LLVMPY_AddDeadStoreEliminationPass(self)
281
-
282
- def add_reverse_post_order_function_attrs_pass(self):
283
- """
284
- See https://llvm.org/docs/Passes.html#function-attrs-deduce-function-attributes
285
-
286
- LLVM 14: `llvm::createReversePostOrderFunctionAttrsPass`
287
- """ # noqa E501
288
- ffi.lib.LLVMPY_AddReversePostOrderFunctionAttrsPass(self)
289
-
290
- def add_function_attrs_pass(self):
291
- """
292
- See http://llvm.org/docs/Passes.html#functionattrs-deduce-function-attributes
293
-
294
- LLVM 14: `LLVMAddFunctionAttrsPass`
295
- """ # noqa E501
296
- ffi.lib.LLVMPY_AddFunctionAttrsPass(self)
297
-
298
- def add_function_inlining_pass(self, threshold):
299
- """
300
- See http://llvm.org/docs/Passes.html#inline-function-integration-inlining
301
-
302
- LLVM 14: `createFunctionInliningPass`
303
- """ # noqa E501
304
- ffi.lib.LLVMPY_AddFunctionInliningPass(self, threshold)
305
-
306
- def add_global_dce_pass(self):
307
- """
308
- See http://llvm.org/docs/Passes.html#globaldce-dead-global-elimination
309
-
310
- LLVM 14: `LLVMAddGlobalDCEPass`
311
- """ # noqa E501
312
- ffi.lib.LLVMPY_AddGlobalDCEPass(self)
313
-
314
- def add_global_optimizer_pass(self):
315
- """
316
- See http://llvm.org/docs/Passes.html#globalopt-global-variable-optimizer
317
-
318
- LLVM 14: `LLVMAddGlobalOptimizerPass`
319
- """ # noqa E501
320
- ffi.lib.LLVMPY_AddGlobalOptimizerPass(self)
321
-
322
- def add_ipsccp_pass(self):
323
- """
324
- See http://llvm.org/docs/Passes.html#ipsccp-interprocedural-sparse-conditional-constant-propagation
325
-
326
- LLVM 14: `LLVMAddIPSCCPPass`
327
- """ # noqa E501
328
- ffi.lib.LLVMPY_AddIPSCCPPass(self)
329
-
330
- def add_dead_code_elimination_pass(self):
331
- """
332
- See http://llvm.org/docs/Passes.html#dce-dead-code-elimination
333
- LLVM 14: `llvm::createDeadCodeEliminationPass`
334
- """
335
- ffi.lib.LLVMPY_AddDeadCodeEliminationPass(self)
336
-
337
- def add_aggressive_instruction_combining_pass(self):
338
- """
339
- See https://llvm.org/docs/Passes.html#aggressive-instcombine-combine-expression-patterns
340
-
341
- LLVM 14: `llvm::createAggressiveInstCombinerPass`
342
- """ # noqa E501
343
- if llvm_version_major > 15:
344
- msg = "AggressiveInstrCombinerPass unavailable in LLVM > 15"
345
- raise RuntimeError(msg)
346
-
347
- ffi.lib.LLVMPY_AddAggressiveInstructionCombiningPass(self)
348
-
349
- def add_internalize_pass(self):
350
- """
351
- See https://llvm.org/docs/Passes.html#internalize-internalize-global-symbols
352
-
353
- LLVM 14: `llvm::createInternalizePass`
354
- """ # noqa E501
355
- ffi.lib.LLVMPY_AddInternalizePass(self)
356
-
357
- def add_cfg_simplification_pass(self):
358
- """
359
- See http://llvm.org/docs/Passes.html#simplifycfg-simplify-the-cfg
360
-
361
- LLVM 14: `LLVMAddCFGSimplificationPass`
362
- """
363
- ffi.lib.LLVMPY_AddCFGSimplificationPass(self)
364
-
365
- def add_jump_threading_pass(self, threshold=-1):
366
- """
367
- See https://llvm.org/docs/Passes.html#jump-threading-jump-threading
368
-
369
- LLVM 14: `llvm::createJumpThreadingPass`
370
- """ # noqa E501
371
- ffi.lib.LLVMPY_AddJumpThreadingPass(self, threshold)
372
-
373
- def add_lcssa_pass(self):
374
- """
375
- See https://llvm.org/docs/Passes.html#lcssa-loop-closed-ssa-form-pass
376
-
377
- LLVM 14: `llvm::createLCSSAPass`
378
- """ # noqa E501
379
- ffi.lib.LLVMPY_AddLCSSAPass(self)
380
-
381
- def add_gvn_pass(self):
382
- """
383
- See http://llvm.org/docs/Passes.html#gvn-global-value-numbering
384
-
385
- LLVM 14: `LLVMAddGVNPass`
386
- """
387
- ffi.lib.LLVMPY_AddGVNPass(self)
388
-
389
- def add_instruction_combining_pass(self):
390
- """
391
- See http://llvm.org/docs/Passes.html#passes-instcombine
392
-
393
- LLVM 14: `LLVMAddInstructionCombiningPass`
394
- """
395
- ffi.lib.LLVMPY_AddInstructionCombiningPass(self)
396
-
397
- def add_licm_pass(self):
398
- """
399
- See http://llvm.org/docs/Passes.html#licm-loop-invariant-code-motion
400
-
401
- LLVM 14: `LLVMAddLICMPass`
402
- """ # noqa E501
403
- ffi.lib.LLVMPY_AddLICMPass(self)
404
-
405
- def add_loop_deletion_pass(self):
406
- """
407
- See https://llvm.org/docs/Passes.html#loop-deletion-delete-dead-loops
408
-
409
- LLVM 14: `llvm::createLoopDeletionPass`
410
- """ # noqa E501
411
- ffi.lib.LLVMPY_AddLoopDeletionPass(self)
412
-
413
- def add_loop_extractor_pass(self):
414
- """
415
- See https://llvm.org/docs/Passes.html#loop-extract-extract-loops-into-new-functions
416
-
417
- LLVM 14: `llvm::createLoopExtractorPass`
418
- """ # noqa E501
419
- ffi.lib.LLVMPY_AddLoopExtractorPass(self)
420
-
421
- def add_single_loop_extractor_pass(self):
422
- """
423
- See https://llvm.org/docs/Passes.html#loop-extract-single-extract-at-most-one-loop-into-a-new-function
424
-
425
- LLVM 14: `llvm::createSingleLoopExtractorPass`
426
- """ # noqa E501
427
- ffi.lib.LLVMPY_AddSingleLoopExtractorPass(self)
428
-
429
- def add_sccp_pass(self):
430
- """
431
- See http://llvm.org/docs/Passes.html#sccp-sparse-conditional-constant-propagation
432
-
433
- LLVM 14: `LLVMAddSCCPPass`
434
- """ # noqa E501
435
- ffi.lib.LLVMPY_AddSCCPPass(self)
436
-
437
- def add_loop_strength_reduce_pass(self):
438
- """
439
- See https://llvm.org/docs/Passes.html#loop-reduce-loop-strength-reduction
440
-
441
- LLVM 14: `llvm::createLoopStrengthReducePass`
442
- """ # noqa E501
443
- ffi.lib.LLVMPY_AddLoopStrengthReducePass(self)
444
-
445
- def add_loop_simplification_pass(self):
446
- """
447
- See https://llvm.org/docs/Passes.html#loop-simplify-canonicalize-natural-loops
448
-
449
- LLVM 14: `llvm::createLoopSimplifyPass`
450
- """ # noqa E501
451
- ffi.lib.LLVMPY_AddLoopSimplificationPass(self)
452
-
453
- def add_loop_unroll_pass(self):
454
- """
455
- See https://llvm.org/docs/Passes.html#loop-unroll-unroll-loops
456
-
457
- LLVM 14: `LLVMAddLoopUnrollPass`
458
- """ # noqa E501
459
- ffi.lib.LLVMPY_AddLoopUnrollPass(self)
460
-
461
- def add_loop_unroll_and_jam_pass(self):
462
- """
463
- See https://llvm.org/docs/Passes.html#loop-unroll-and-jam-unroll-and-jam-loops
464
-
465
- LLVM 14: `LLVMAddLoopUnrollAndJamPass`
466
- """ # noqa E501
467
- ffi.lib.LLVMPY_AddLoopUnrollAndJamPass(self)
468
-
469
- def add_loop_unswitch_pass(self,
470
- optimize_for_size=False,
471
- has_branch_divergence=False):
472
- """
473
- See https://llvm.org/docs/Passes.html#loop-unswitch-unswitch-loops
474
-
475
- LLVM 14: `llvm::createLoopUnswitchPass`
476
- LLVM 15: `llvm::createSimpleLoopUnswitchLegacyPass`
477
- """ # noqa E501
478
- ffi.lib.LLVMPY_AddLoopUnswitchPass(self, optimize_for_size,
479
- has_branch_divergence)
480
-
481
- def add_lower_atomic_pass(self):
482
- """
483
- See https://llvm.org/docs/Passes.html#loweratomic-lower-atomic-intrinsics-to-non-atomic-form
484
-
485
- LLVM 14: `llvm::createLowerAtomicPass`
486
- """ # noqa E501
487
- ffi.lib.LLVMPY_AddLowerAtomicPass(self)
488
-
489
- def add_lower_invoke_pass(self):
490
- """
491
- See https://llvm.org/docs/Passes.html#lowerinvoke-lower-invokes-to-calls-for-unwindless-code-generators
492
-
493
- LLVM 14: `llvm::createLowerInvokePass`
494
- """ # noqa E501
495
- ffi.lib.LLVMPY_AddLowerInvokePass(self)
496
-
497
- def add_lower_switch_pass(self):
498
- """
499
- See https://llvm.org/docs/Passes.html#lowerswitch-lower-switchinsts-to-branches
500
-
501
- LLVM 14: `llvm::createLowerSwitchPass`
502
- """ # noqa E501
503
- ffi.lib.LLVMPY_AddLowerSwitchPass(self)
504
-
505
- def add_memcpy_optimization_pass(self):
506
- """
507
- See https://llvm.org/docs/Passes.html#memcpyopt-memcpy-optimization
508
-
509
- LLVM 14: `llvm::createMemCpyOptPass`
510
- """ # noqa E501
511
- ffi.lib.LLVMPY_AddMemCpyOptimizationPass(self)
512
-
513
- def add_merge_functions_pass(self):
514
- """
515
- See https://llvm.org/docs/Passes.html#mergefunc-merge-functions
516
-
517
- LLVM 14: `llvm::createMergeFunctionsPass`
518
- """ # noqa E501
519
- ffi.lib.LLVMPY_AddMergeFunctionsPass(self)
520
-
521
- def add_merge_returns_pass(self):
522
- """
523
- See https://llvm.org/docs/Passes.html#mergereturn-unify-function-exit-nodes
524
-
525
- LLVM 14: `llvm::createUnifyFunctionExitNodesPass`
526
- """ # noqa E501
527
- ffi.lib.LLVMPY_AddMergeReturnsPass(self)
528
-
529
- def add_partial_inlining_pass(self):
530
- """
531
- See https://llvm.org/docs/Passes.html#partial-inliner-partial-inliner
532
-
533
- LLVM 14: `llvm::createPartialInliningPass`
534
- """ # noqa E501
535
- ffi.lib.LLVMPY_AddPartialInliningPass(self)
536
-
537
- def add_prune_exception_handling_pass(self):
538
- """
539
- See https://llvm.org/docs/Passes.html#prune-eh-remove-unused-exception-handling-info
540
-
541
- LLVM 14: `llvm::createPruneEHPass`
542
- """ # noqa E501
543
- if llvm_version_major > 15:
544
- raise RuntimeError("PruneEHPass unavailable in LLVM > 15")
545
- ffi.lib.LLVMPY_AddPruneExceptionHandlingPass(self)
546
-
547
- def add_reassociate_expressions_pass(self):
548
- """
549
- See https://llvm.org/docs/Passes.html#reassociate-reassociate-expressions
550
-
551
- LLVM 14: `llvm::createReassociatePass`
552
- """ # noqa E501
553
- ffi.lib.LLVMPY_AddReassociatePass(self)
554
-
555
- def add_demote_register_to_memory_pass(self):
556
- """
557
- See https://llvm.org/docs/Passes.html#rel-lookup-table-converter-relative-lookup-table-converter
558
-
559
- LLVM 14: `llvm::createDemoteRegisterToMemoryPass`
560
- """ # noqa E501
561
- ffi.lib.LLVMPY_AddDemoteRegisterToMemoryPass(self)
562
-
563
- def add_sroa_pass(self):
564
- """
565
- See http://llvm.org/docs/Passes.html#scalarrepl-scalar-replacement-of-aggregates-dt
566
- Note that this pass corresponds to the ``opt -sroa`` command-line option,
567
- despite the link above.
568
-
569
- LLVM 14: `llvm::createSROAPass`
570
- """ # noqa E501
571
- ffi.lib.LLVMPY_AddSROAPass(self)
572
-
573
- def add_sink_pass(self):
574
- """
575
- See https://llvm.org/docs/Passes.html#sink-code-sinking
576
-
577
- LLVM 14: `llvm::createSinkingPass`
578
- """ # noqa E501
579
- ffi.lib.LLVMPY_AddSinkPass(self)
580
-
581
- def add_strip_symbols_pass(self, only_debug=False):
582
- """
583
- See https://llvm.org/docs/Passes.html#strip-strip-all-symbols-from-a-module
584
-
585
- LLVM 14: `llvm::createStripSymbolsPass`
586
- """ # noqa E501
587
- ffi.lib.LLVMPY_AddStripSymbolsPass(self, only_debug)
588
-
589
- def add_strip_dead_debug_info_pass(self):
590
- """
591
- See https://llvm.org/docs/Passes.html#strip-dead-debug-info-strip-debug-info-for-unused-symbols
592
-
593
- LLVM 14: `llvm::createStripDeadDebugInfoPass`
594
- """ # noqa E501
595
- ffi.lib.LLVMPY_AddStripDeadDebugInfoPass(self)
596
-
597
- def add_strip_dead_prototypes_pass(self):
598
- """
599
- See https://llvm.org/docs/Passes.html#strip-dead-prototypes-strip-unused-function-prototypes
600
-
601
- LLVM 14: `llvm::createStripDeadPrototypesPass`
602
- """ # noqa E501
603
- ffi.lib.LLVMPY_AddStripDeadPrototypesPass(self)
604
-
605
- def add_strip_debug_declare_pass(self):
606
- """
607
- See https://llvm.org/docs/Passes.html#strip-debug-declare-strip-all-llvm-dbg-declare-intrinsics
608
-
609
- LLVM 14: `llvm::createStripDebugDeclarePass`
610
- """ # noqa E501
611
- ffi.lib.LLVMPY_AddStripDebugDeclarePrototypesPass(self)
612
-
613
- def add_strip_nondebug_symbols_pass(self):
614
- """
615
- See https://llvm.org/docs/Passes.html#strip-nondebug-strip-all-symbols-except-dbg-symbols-from-a-module
616
-
617
- LLVM 14: `llvm::createStripNonDebugSymbolsPass`
618
- """ # noqa E501
619
- ffi.lib.LLVMPY_AddStripNondebugSymbolsPass(self)
620
-
621
- def add_tail_call_elimination_pass(self):
622
- """
623
- See https://llvm.org/docs/Passes.html#tailcallelim-tail-call-elimination
624
-
625
- LLVM 14: `llvm::createTailCallEliminationPass`
626
- """ # noqa E501
627
- ffi.lib.LLVMPY_AddTailCallEliminationPass(self)
628
-
629
- def add_type_based_alias_analysis_pass(self):
630
- """
631
- LLVM 14: `LLVMAddTypeBasedAliasAnalysisPass`
632
- """ # noqa E501
633
- ffi.lib.LLVMPY_AddTypeBasedAliasAnalysisPass(self)
634
-
635
- def add_basic_alias_analysis_pass(self):
636
- """
637
- See http://llvm.org/docs/AliasAnalysis.html#the-basicaa-pass
638
-
639
- LLVM 14: `LLVMAddBasicAliasAnalysisPass`
640
- """
641
- ffi.lib.LLVMPY_AddBasicAliasAnalysisPass(self)
642
-
643
- def add_loop_rotate_pass(self):
644
- """http://llvm.org/docs/Passes.html#loop-rotate-rotate-loops."""
645
- ffi.lib.LLVMPY_AddLoopRotatePass(self)
646
-
647
- def add_target_library_info(self, triple):
648
- ffi.lib.LLVMPY_AddTargetLibraryInfoPass(self, _encode_string(triple))
649
-
650
- def add_instruction_namer_pass(self):
651
- """
652
- See https://llvm.org/docs/Passes.html#instnamer-assign-names-to-anonymous-instructions.
653
-
654
- LLVM 14: `llvm::createInstructionNamerPass`
655
- """ # noqa E501
656
- ffi.lib.LLVMPY_AddInstructionNamerPass(self)
657
-
658
- # Non-standard LLVM passes
659
-
660
- def add_refprune_pass(self, subpasses_flags=RefPruneSubpasses.ALL,
661
- subgraph_limit=1000):
662
- """Add Numba specific Reference count pruning pass.
663
-
664
- Parameters
665
- ----------
666
- subpasses_flags : RefPruneSubpasses
667
- A bitmask to control the subpasses to be enabled.
668
- subgraph_limit : int
669
- Limit the fanout pruners to working on a subgraph no bigger than
670
- this number of basic-blocks to avoid spending too much time in very
671
- large graphs. Default is 1000. Subject to change in future
672
- versions.
673
- """
674
- iflags = RefPruneSubpasses(subpasses_flags)
675
- ffi.lib.LLVMPY_AddLegacyRefPrunePass(self, iflags, subgraph_limit)
676
-
677
-
678
- class ModulePassManager(PassManager):
679
-
680
- def __init__(self, ptr=None):
681
- if ptr is None:
682
- ptr = ffi.lib.LLVMPY_CreatePassManager()
683
- PassManager.__init__(self, ptr)
684
-
685
- def run(self, module, remarks_file=None, remarks_format='yaml',
686
- remarks_filter=''):
687
- """
688
- Run optimization passes on the given module.
689
-
690
- Parameters
691
- ----------
692
- module : llvmlite.binding.ModuleRef
693
- The module to be optimized inplace
694
- remarks_file : str; optional
695
- If not `None`, it is the file to store the optimization remarks.
696
- remarks_format : str; optional
697
- The format to write; YAML is default
698
- remarks_filter : str; optional
699
- The filter that should be applied to the remarks output.
700
- """
701
- if remarks_file is None:
702
- return ffi.lib.LLVMPY_RunPassManager(self, module)
703
- else:
704
- r = ffi.lib.LLVMPY_RunPassManagerWithRemarks(
705
- self, module, _encode_string(remarks_format),
706
- _encode_string(remarks_filter),
707
- _encode_string(remarks_file))
708
- if r == -1:
709
- raise IOError("Failed to initialize remarks file.")
710
- return r > 0
711
-
712
- def run_with_remarks(self, module, remarks_format='yaml',
713
- remarks_filter=''):
714
- """
715
- Run optimization passes on the given module and returns the result and
716
- the remarks data.
717
-
718
- Parameters
719
- ----------
720
- module : llvmlite.binding.ModuleRef
721
- The module to be optimized
722
- remarks_format : str
723
- The remarks output; YAML is the default
724
- remarks_filter : str; optional
725
- The filter that should be applied to the remarks output.
726
- """
727
- remarkdesc, remarkfile = mkstemp()
728
- try:
729
- with os.fdopen(remarkdesc, 'r'):
730
- pass
731
- r = self.run(module, remarkfile, remarks_format, remarks_filter)
732
- if r == -1:
733
- raise IOError("Failed to initialize remarks file.")
734
- with open(remarkfile) as f:
735
- return bool(r), f.read()
736
- finally:
737
- os.unlink(remarkfile)
738
-
739
-
740
- class FunctionPassManager(PassManager):
741
-
742
- def __init__(self, module):
743
- ptr = ffi.lib.LLVMPY_CreateFunctionPassManager(module)
744
- self._module = module
745
- module._owned = True
746
- PassManager.__init__(self, ptr)
747
-
748
- def initialize(self):
749
- """
750
- Initialize the FunctionPassManager. Returns True if it produced
751
- any changes (?).
752
- """
753
- return ffi.lib.LLVMPY_InitializeFunctionPassManager(self)
754
-
755
- def finalize(self):
756
- """
757
- Finalize the FunctionPassManager. Returns True if it produced
758
- any changes (?).
759
- """
760
- return ffi.lib.LLVMPY_FinalizeFunctionPassManager(self)
761
-
762
- def run(self, function, remarks_file=None, remarks_format='yaml',
763
- remarks_filter=''):
764
- """
765
- Run optimization passes on the given function.
766
-
767
- Parameters
768
- ----------
769
- function : llvmlite.binding.FunctionRef
770
- The function to be optimized inplace
771
- remarks_file : str; optional
772
- If not `None`, it is the file to store the optimization remarks.
773
- remarks_format : str; optional
774
- The format of the remarks file; the default is YAML
775
- remarks_filter : str; optional
776
- The filter that should be applied to the remarks output.
777
- """
778
- if remarks_file is None:
779
- return ffi.lib.LLVMPY_RunFunctionPassManager(self, function)
780
- else:
781
- r = ffi.lib.LLVMPY_RunFunctionPassManagerWithRemarks(
782
- self, function, _encode_string(remarks_format),
783
- _encode_string(remarks_filter),
784
- _encode_string(remarks_file))
785
- if r == -1:
786
- raise IOError("Failed to initialize remarks file.")
787
- return bool(r)
788
-
789
- def run_with_remarks(self, function, remarks_format='yaml',
790
- remarks_filter=''):
791
- """
792
- Run optimization passes on the given function and returns the result
793
- and the remarks data.
794
-
795
- Parameters
796
- ----------
797
- function : llvmlite.binding.FunctionRef
798
- The function to be optimized inplace
799
- remarks_format : str; optional
800
- The format of the remarks file; the default is YAML
801
- remarks_filter : str; optional
802
- The filter that should be applied to the remarks output.
803
- """
804
- # LLVM is going to need to close this file and then reopen it, so we
805
- # can't use an unlinked temporary file.
806
- remarkdesc, remarkfile = mkstemp()
807
- try:
808
- # We get an open handle, but we need LLVM to write first, so close
809
- # it.
810
- with os.fdopen(remarkdesc, 'r'):
811
- pass
812
- r = self.run(function, remarkfile, remarks_format, remarks_filter)
813
- if r == -1:
814
- raise IOError("Failed to initialize remarks file.")
815
- with open(remarkfile) as f:
816
- return bool(r), f.read()
817
- finally:
818
- os.unlink(remarkfile)
819
-
820
-
821
- # ============================================================================
822
- # FFI
823
-
824
- ffi.lib.LLVMPY_CreatePassManager.restype = ffi.LLVMPassManagerRef
825
-
826
- ffi.lib.LLVMPY_CreateFunctionPassManager.argtypes = [ffi.LLVMModuleRef]
827
- ffi.lib.LLVMPY_CreateFunctionPassManager.restype = ffi.LLVMPassManagerRef
828
-
829
- ffi.lib.LLVMPY_DisposePassManager.argtypes = [ffi.LLVMPassManagerRef]
830
-
831
- ffi.lib.LLVMPY_RunPassManager.argtypes = [ffi.LLVMPassManagerRef,
832
- ffi.LLVMModuleRef]
833
- ffi.lib.LLVMPY_RunPassManager.restype = c_bool
834
-
835
- ffi.lib.LLVMPY_RunPassManagerWithRemarks.argtypes = [ffi.LLVMPassManagerRef,
836
- ffi.LLVMModuleRef,
837
- c_char_p,
838
- c_char_p,
839
- c_char_p]
840
- ffi.lib.LLVMPY_RunPassManagerWithRemarks.restype = c_int
841
-
842
- ffi.lib.LLVMPY_InitializeFunctionPassManager.argtypes = [ffi.LLVMPassManagerRef]
843
- ffi.lib.LLVMPY_InitializeFunctionPassManager.restype = c_bool
844
-
845
- ffi.lib.LLVMPY_FinalizeFunctionPassManager.argtypes = [ffi.LLVMPassManagerRef]
846
- ffi.lib.LLVMPY_FinalizeFunctionPassManager.restype = c_bool
847
-
848
- ffi.lib.LLVMPY_RunFunctionPassManager.argtypes = [ffi.LLVMPassManagerRef,
849
- ffi.LLVMValueRef]
850
- ffi.lib.LLVMPY_RunFunctionPassManager.restype = c_bool
851
-
852
- ffi.lib.LLVMPY_RunFunctionPassManagerWithRemarks.argtypes = [
853
- ffi.LLVMPassManagerRef, ffi.LLVMValueRef, c_char_p, c_char_p, c_char_p
854
- ]
855
- ffi.lib.LLVMPY_RunFunctionPassManagerWithRemarks.restype = c_int
856
-
857
- ffi.lib.LLVMPY_AddAAEvalPass.argtypes = [ffi.LLVMPassManagerRef]
858
- ffi.lib.LLVMPY_AddBasicAAWrapperPass.argtypes = [ffi.LLVMPassManagerRef]
859
- ffi.lib.LLVMPY_AddConstantMergePass.argtypes = [ffi.LLVMPassManagerRef]
860
- ffi.lib.LLVMPY_AddDeadArgEliminationPass.argtypes = [ffi.LLVMPassManagerRef]
861
- ffi.lib.LLVMPY_AddDependenceAnalysisPass.argtypes = [ffi.LLVMPassManagerRef]
862
- ffi.lib.LLVMPY_AddCallGraphDOTPrinterPass.argtypes = [ffi.LLVMPassManagerRef]
863
- ffi.lib.LLVMPY_AddCFGPrinterPass.argtypes = [ffi.LLVMPassManagerRef]
864
- ffi.lib.LLVMPY_AddDotDomPrinterPass.argtypes = [ffi.LLVMPassManagerRef, c_bool]
865
- ffi.lib.LLVMPY_AddDotPostDomPrinterPass.argtypes = [
866
- ffi.LLVMPassManagerRef,
867
- c_bool]
868
- ffi.lib.LLVMPY_AddGlobalsModRefAAPass.argtypes = [ffi.LLVMPassManagerRef]
869
- ffi.lib.LLVMPY_AddInstructionCountPass.argtypes = [ffi.LLVMPassManagerRef]
870
- ffi.lib.LLVMPY_AddIVUsersPass.argtypes = [ffi.LLVMPassManagerRef]
871
- ffi.lib.LLVMPY_AddLazyValueInfoPass.argtypes = [ffi.LLVMPassManagerRef]
872
- ffi.lib.LLVMPY_AddLintPass.argtypes = [ffi.LLVMPassManagerRef]
873
- ffi.lib.LLVMPY_AddModuleDebugInfoPrinterPass.argtypes = [ffi.LLVMPassManagerRef]
874
- ffi.lib.LLVMPY_AddRegionInfoPass.argtypes = [ffi.LLVMPassManagerRef]
875
- ffi.lib.LLVMPY_AddScalarEvolutionAAPass.argtypes = [ffi.LLVMPassManagerRef]
876
- ffi.lib.LLVMPY_AddAggressiveDCEPass.argtypes = [ffi.LLVMPassManagerRef]
877
- ffi.lib.LLVMPY_AddAlwaysInlinerPass.argtypes = [ffi.LLVMPassManagerRef, c_bool]
878
- ffi.lib.LLVMPY_AddBreakCriticalEdgesPass.argtypes = [ffi.LLVMPassManagerRef]
879
- ffi.lib.LLVMPY_AddDeadStoreEliminationPass.argtypes = [
880
- ffi.LLVMPassManagerRef]
881
- ffi.lib.LLVMPY_AddReversePostOrderFunctionAttrsPass.argtypes = [
882
- ffi.LLVMPassManagerRef]
883
-
884
- if llvm_version_major < 16:
885
- ffi.lib.LLVMPY_AddAggressiveInstructionCombiningPass.argtypes = [
886
- ffi.LLVMPassManagerRef]
887
-
888
- ffi.lib.LLVMPY_AddInternalizePass.argtypes = [ffi.LLVMPassManagerRef]
889
- ffi.lib.LLVMPY_AddLCSSAPass.argtypes = [ffi.LLVMPassManagerRef]
890
- ffi.lib.LLVMPY_AddLoopDeletionPass.argtypes = [ffi.LLVMPassManagerRef]
891
- ffi.lib.LLVMPY_AddLoopExtractorPass.argtypes = [ffi.LLVMPassManagerRef]
892
- ffi.lib.LLVMPY_AddSingleLoopExtractorPass.argtypes = [ffi.LLVMPassManagerRef]
893
- ffi.lib.LLVMPY_AddLoopStrengthReducePass.argtypes = [ffi.LLVMPassManagerRef]
894
- ffi.lib.LLVMPY_AddLoopSimplificationPass.argtypes = [ffi.LLVMPassManagerRef]
895
- ffi.lib.LLVMPY_AddLoopUnrollPass.argtypes = [ffi.LLVMPassManagerRef]
896
- ffi.lib.LLVMPY_AddLoopUnrollAndJamPass.argtypes = [ffi.LLVMPassManagerRef]
897
- ffi.lib.LLVMPY_AddLoopUnswitchPass.argtypes = [ffi.LLVMPassManagerRef, c_bool,
898
- c_bool]
899
- ffi.lib.LLVMPY_AddLowerAtomicPass.argtypes = [ffi.LLVMPassManagerRef]
900
- ffi.lib.LLVMPY_AddLowerInvokePass.argtypes = [ffi.LLVMPassManagerRef]
901
- ffi.lib.LLVMPY_AddLowerSwitchPass.argtypes = [ffi.LLVMPassManagerRef]
902
- ffi.lib.LLVMPY_AddMemCpyOptimizationPass.argtypes = [ffi.LLVMPassManagerRef]
903
- ffi.lib.LLVMPY_AddMergeFunctionsPass.argtypes = [ffi.LLVMPassManagerRef]
904
- ffi.lib.LLVMPY_AddMergeReturnsPass.argtypes = [ffi.LLVMPassManagerRef]
905
- ffi.lib.LLVMPY_AddPartialInliningPass.argtypes = [ffi.LLVMPassManagerRef]
906
-
907
- if llvm_version_major < 16:
908
- ffi.lib.LLVMPY_AddPruneExceptionHandlingPass.argtypes = [
909
- ffi.LLVMPassManagerRef
910
- ]
911
-
912
- ffi.lib.LLVMPY_AddReassociatePass.argtypes = [ffi.LLVMPassManagerRef]
913
- ffi.lib.LLVMPY_AddDemoteRegisterToMemoryPass.argtypes = [ffi.LLVMPassManagerRef]
914
- ffi.lib.LLVMPY_AddSinkPass.argtypes = [ffi.LLVMPassManagerRef]
915
- ffi.lib.LLVMPY_AddStripSymbolsPass.argtypes = [ffi.LLVMPassManagerRef, c_bool]
916
- ffi.lib.LLVMPY_AddStripDeadDebugInfoPass.argtypes = [ffi.LLVMPassManagerRef]
917
- ffi.lib.LLVMPY_AddStripDeadPrototypesPass.argtypes = [ffi.LLVMPassManagerRef]
918
- ffi.lib.LLVMPY_AddStripDebugDeclarePrototypesPass.argtypes = [
919
- ffi.LLVMPassManagerRef]
920
- ffi.lib.LLVMPY_AddStripNondebugSymbolsPass.argtypes = [ffi.LLVMPassManagerRef]
921
- ffi.lib.LLVMPY_AddTailCallEliminationPass.argtypes = [ffi.LLVMPassManagerRef]
922
- ffi.lib.LLVMPY_AddJumpThreadingPass.argtypes = [ffi.LLVMPassManagerRef, c_int]
923
- ffi.lib.LLVMPY_AddFunctionAttrsPass.argtypes = [ffi.LLVMPassManagerRef]
924
- ffi.lib.LLVMPY_AddFunctionInliningPass.argtypes = [
925
- ffi.LLVMPassManagerRef, c_int]
926
- ffi.lib.LLVMPY_AddGlobalDCEPass.argtypes = [ffi.LLVMPassManagerRef]
927
- ffi.lib.LLVMPY_AddGlobalOptimizerPass.argtypes = [ffi.LLVMPassManagerRef]
928
- ffi.lib.LLVMPY_AddIPSCCPPass.argtypes = [ffi.LLVMPassManagerRef]
929
-
930
- ffi.lib.LLVMPY_AddDeadCodeEliminationPass.argtypes = [ffi.LLVMPassManagerRef]
931
- ffi.lib.LLVMPY_AddCFGSimplificationPass.argtypes = [ffi.LLVMPassManagerRef]
932
- ffi.lib.LLVMPY_AddGVNPass.argtypes = [ffi.LLVMPassManagerRef]
933
- ffi.lib.LLVMPY_AddInstructionCombiningPass.argtypes = [ffi.LLVMPassManagerRef]
934
- ffi.lib.LLVMPY_AddLICMPass.argtypes = [ffi.LLVMPassManagerRef]
935
- ffi.lib.LLVMPY_AddSCCPPass.argtypes = [ffi.LLVMPassManagerRef]
936
- ffi.lib.LLVMPY_AddSROAPass.argtypes = [ffi.LLVMPassManagerRef]
937
- ffi.lib.LLVMPY_AddTypeBasedAliasAnalysisPass.argtypes = [ffi.LLVMPassManagerRef]
938
- ffi.lib.LLVMPY_AddBasicAliasAnalysisPass.argtypes = [ffi.LLVMPassManagerRef]
939
- ffi.lib.LLVMPY_AddTargetLibraryInfoPass.argtypes = [ffi.LLVMPassManagerRef,
940
- c_char_p]
941
- ffi.lib.LLVMPY_AddInstructionNamerPass.argtypes = [ffi.LLVMPassManagerRef]
942
-
943
- ffi.lib.LLVMPY_AddLegacyRefPrunePass.argtypes = [ffi.LLVMPassManagerRef, c_int,
944
- c_size_t]
945
-
946
- ffi.lib.LLVMPY_DumpRefPruneStats.argtypes = [POINTER(_c_PruneStats), c_bool]