llvmlite 0.42.0rc1__cp310-cp310-win_amd64.whl → 0.43.0rc1__cp310-cp310-win_amd64.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.

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