Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- data/conda_envs/evalclaw/lib/python3.11/site-packages/colorlog-6.10.1.dist-info/licenses/LICENSE +20 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/dataproperty-1.1.1.dist-info/licenses/LICENSE +21 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/idna/__pycache__/__init__.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/idna/__pycache__/codec.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/idna/__pycache__/compat.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/idna/__pycache__/core.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/idna/__pycache__/intranges.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/idna/__pycache__/package_data.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/jsonschema_specifications-2025.9.1.dist-info/licenses/COPYING +19 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/__pycache__/__init__.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/__pycache__/_version.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/__pycache__/utils.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__init__.py +18 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/__init__.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/analysis.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/common.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/config.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/context.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/dylib.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/executionengine.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/ffi.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/initfini.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/linker.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/module.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/newpassmanagers.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/object_file.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/options.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/orcjit.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/targets.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/typeref.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/value.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/analysis.py +69 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/common.py +34 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/config.py +143 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/context.py +31 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/dylib.py +45 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/executionengine.py +330 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/ffi.py +410 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/initfini.py +85 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/linker.py +20 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/module.py +349 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/newpassmanagers.py +1049 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/object_file.py +82 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/options.py +17 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/orcjit.py +342 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/targets.py +462 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/typeref.py +267 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/value.py +632 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/ir/__init__.py +11 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/ir/__pycache__/__init__.cpython-311.pyc +0 -0
data/conda_envs/evalclaw/lib/python3.11/site-packages/colorlog-6.10.1.dist-info/licenses/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The MIT License (MIT)
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2012-2021 Sam Clements <sam@borntyping.co.uk>
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 6 |
+
this software and associated documentation files (the "Software"), to deal in
|
| 7 |
+
the Software without restriction, including without limitation the rights to
|
| 8 |
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 9 |
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
| 10 |
+
subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 17 |
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 18 |
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 19 |
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 20 |
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/dataproperty-1.1.1.dist-info/licenses/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The MIT License (MIT)
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2016-2026 Tsuyoshi Hombashi
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/idna/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (1.1 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/idna/__pycache__/codec.cpython-311.pyc
ADDED
|
Binary file (5.78 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/idna/__pycache__/compat.cpython-311.pyc
ADDED
|
Binary file (1.02 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/idna/__pycache__/core.cpython-311.pyc
ADDED
|
Binary file (19.3 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/idna/__pycache__/intranges.cpython-311.pyc
ADDED
|
Binary file (2.98 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/idna/__pycache__/package_data.cpython-311.pyc
ADDED
|
Binary file (215 Bytes). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/jsonschema_specifications-2025.9.1.dist-info/licenses/COPYING
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2022 Julian Berman
|
| 2 |
+
|
| 3 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 5 |
+
in the Software without restriction, including without limitation the rights
|
| 6 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 7 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
The above copyright notice and this permission notice shall be included in
|
| 11 |
+
all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 18 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 19 |
+
THE SOFTWARE.
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (715 Bytes). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/__pycache__/_version.cpython-311.pyc
ADDED
|
Binary file (508 Bytes). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/__pycache__/utils.cpython-311.pyc
ADDED
|
Binary file (1.1 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__init__.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Things that rely on the LLVM library
|
| 3 |
+
"""
|
| 4 |
+
from .dylib import *
|
| 5 |
+
from .executionengine import *
|
| 6 |
+
from .initfini import *
|
| 7 |
+
from .linker import *
|
| 8 |
+
from .module import *
|
| 9 |
+
from .options import *
|
| 10 |
+
from .newpassmanagers import *
|
| 11 |
+
from .targets import *
|
| 12 |
+
from .value import *
|
| 13 |
+
from .typeref import *
|
| 14 |
+
from .analysis import *
|
| 15 |
+
from .object_file import *
|
| 16 |
+
from .context import *
|
| 17 |
+
from .orcjit import *
|
| 18 |
+
from .config import *
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (721 Bytes). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/analysis.cpython-311.pyc
ADDED
|
Binary file (3.3 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/common.cpython-311.pyc
ADDED
|
Binary file (1.43 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/config.cpython-311.pyc
ADDED
|
Binary file (5.92 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/context.cpython-311.pyc
ADDED
|
Binary file (2.25 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/dylib.cpython-311.pyc
ADDED
|
Binary file (2.36 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/executionengine.cpython-311.pyc
ADDED
|
Binary file (15.7 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/ffi.cpython-311.pyc
ADDED
|
Binary file (21.5 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/initfini.cpython-311.pyc
ADDED
|
Binary file (3.88 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/linker.cpython-311.pyc
ADDED
|
Binary file (1.24 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/module.cpython-311.pyc
ADDED
|
Binary file (19.8 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/newpassmanagers.cpython-311.pyc
ADDED
|
Binary file (54.5 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/object_file.cpython-311.pyc
ADDED
|
Binary file (6.08 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/options.cpython-311.pyc
ADDED
|
Binary file (987 Bytes). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/orcjit.cpython-311.pyc
ADDED
|
Binary file (18.3 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/targets.cpython-311.pyc
ADDED
|
Binary file (23.8 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/typeref.cpython-311.pyc
ADDED
|
Binary file (13.5 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/__pycache__/value.cpython-311.pyc
ADDED
|
Binary file (32.6 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/analysis.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
A collection of analysis utilities
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from ctypes import POINTER, c_char_p, c_int
|
| 6 |
+
|
| 7 |
+
from llvmlite.binding import ffi
|
| 8 |
+
from llvmlite.binding.module import parse_assembly
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def get_function_cfg(func, show_inst=True):
|
| 12 |
+
"""Return a string of the control-flow graph of the function in DOT
|
| 13 |
+
format. If the input `func` is not a materialized function, the module
|
| 14 |
+
containing the function is parsed to create an actual LLVM module.
|
| 15 |
+
The `show_inst` flag controls whether the instructions of each block
|
| 16 |
+
are printed.
|
| 17 |
+
"""
|
| 18 |
+
assert func is not None
|
| 19 |
+
from llvmlite import ir
|
| 20 |
+
if isinstance(func, ir.Function):
|
| 21 |
+
mod = parse_assembly(str(func.module))
|
| 22 |
+
func = mod.get_function(func.name)
|
| 23 |
+
|
| 24 |
+
# Assume func is a materialized function
|
| 25 |
+
with ffi.OutputString() as dotstr:
|
| 26 |
+
ffi.lib.LLVMPY_WriteCFG(func, dotstr, show_inst)
|
| 27 |
+
return str(dotstr)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def view_dot_graph(graph, filename=None, view=False):
|
| 31 |
+
"""
|
| 32 |
+
View the given DOT source. If view is True, the image is rendered
|
| 33 |
+
and viewed by the default application in the system. The file path of
|
| 34 |
+
the output is returned. If view is False, a graphviz.Source object is
|
| 35 |
+
returned. If view is False and the environment is in a IPython session,
|
| 36 |
+
an IPython image object is returned and can be displayed inline in the
|
| 37 |
+
notebook.
|
| 38 |
+
|
| 39 |
+
This function requires the graphviz package.
|
| 40 |
+
|
| 41 |
+
Args
|
| 42 |
+
----
|
| 43 |
+
- graph [str]: a DOT source code
|
| 44 |
+
- filename [str]: optional. if given and view is True, this specifies
|
| 45 |
+
the file path for the rendered output to write to.
|
| 46 |
+
- view [bool]: if True, opens the rendered output file.
|
| 47 |
+
|
| 48 |
+
"""
|
| 49 |
+
# Optionally depends on graphviz package
|
| 50 |
+
import graphviz as gv
|
| 51 |
+
|
| 52 |
+
src = gv.Source(graph)
|
| 53 |
+
if view:
|
| 54 |
+
# Returns the output file path
|
| 55 |
+
return src.render(filename, view=view)
|
| 56 |
+
else:
|
| 57 |
+
# Attempts to show the graph in IPython notebook
|
| 58 |
+
try:
|
| 59 |
+
__IPYTHON__
|
| 60 |
+
except NameError:
|
| 61 |
+
return src
|
| 62 |
+
else:
|
| 63 |
+
import IPython.display as display
|
| 64 |
+
format = 'svg'
|
| 65 |
+
return display.SVG(data=src.pipe(format))
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
# Ctypes binding
|
| 69 |
+
ffi.lib.LLVMPY_WriteCFG.argtypes = [ffi.LLVMValueRef, POINTER(c_char_p), c_int]
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/common.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import atexit
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def _encode_string(s):
|
| 5 |
+
encoded = s.encode('utf-8')
|
| 6 |
+
return encoded
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def _decode_string(b):
|
| 10 |
+
return b.decode('utf-8')
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
_encode_string.__doc__ = """Encode a string for use by LLVM."""
|
| 14 |
+
_decode_string.__doc__ = """Decode a LLVM character (byte)string."""
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
_shutting_down = [False]
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _at_shutdown():
|
| 21 |
+
_shutting_down[0] = True
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
atexit.register(_at_shutdown)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def _is_shutting_down(_shutting_down=_shutting_down):
|
| 28 |
+
"""
|
| 29 |
+
Whether the interpreter is currently shutting down.
|
| 30 |
+
For use in finalizers, __del__ methods, and similar; it is advised
|
| 31 |
+
to early bind this function rather than look it up when calling it,
|
| 32 |
+
since at shutdown module globals may be cleared.
|
| 33 |
+
"""
|
| 34 |
+
return _shutting_down[0]
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/config.py
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import warnings
|
| 3 |
+
from functools import cache
|
| 4 |
+
from ctypes import c_int, c_char_p
|
| 5 |
+
from llvmlite.binding import ffi
|
| 6 |
+
|
| 7 |
+
# these are here as they cannot be lazy bound as the module globals make calls
|
| 8 |
+
# to the LLVMPY API functions
|
| 9 |
+
ffi.lib.LLVMPY_HasSVMLSupport.argtypes = ()
|
| 10 |
+
ffi.lib.LLVMPY_HasSVMLSupport.restype = c_int
|
| 11 |
+
|
| 12 |
+
ffi.lib.LLVMPY_IsStaticLibstdcxxLinkageBuild.argtypes = ()
|
| 13 |
+
ffi.lib.LLVMPY_IsStaticLibstdcxxLinkageBuild.restype = c_int
|
| 14 |
+
|
| 15 |
+
ffi.lib.LLVMPY_IsDynamicLLVMLinkageBuild.argtypes = ()
|
| 16 |
+
ffi.lib.LLVMPY_IsDynamicLLVMLinkageBuild.restype = c_int
|
| 17 |
+
|
| 18 |
+
ffi.lib.LLVMPY_PackageFormat.argtypes = ()
|
| 19 |
+
ffi.lib.LLVMPY_PackageFormat.restype = c_char_p
|
| 20 |
+
|
| 21 |
+
ffi.lib.LLVMPY_LlvmAssertionsState.argtypes = ()
|
| 22 |
+
ffi.lib.LLVMPY_LlvmAssertionsState.restype = c_char_p
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _has_svml():
|
| 26 |
+
"""
|
| 27 |
+
Returns True if SVML was enabled at FFI support compile time.
|
| 28 |
+
"""
|
| 29 |
+
if ffi.lib.LLVMPY_HasSVMLSupport() == 0:
|
| 30 |
+
return False
|
| 31 |
+
else:
|
| 32 |
+
return True
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
has_svml = _has_svml()
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def _build_llvm_linkage_type():
|
| 39 |
+
"""
|
| 40 |
+
Returns "static" if the FFI support is statically linked against LLVM,
|
| 41 |
+
returns "dynamic" otherwise.
|
| 42 |
+
"""
|
| 43 |
+
if ffi.lib.LLVMPY_IsDynamicLLVMLinkageBuild() == 0:
|
| 44 |
+
return "static"
|
| 45 |
+
else:
|
| 46 |
+
return "dynamic"
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
build_llvm_linkage_type = _build_llvm_linkage_type()
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def _build_libstdcxx_linkage_type():
|
| 53 |
+
"""
|
| 54 |
+
Returns "static" if the FFI support is statically linked against libstdc++,
|
| 55 |
+
returns "dynamic" otherwise.
|
| 56 |
+
"""
|
| 57 |
+
if ffi.lib.LLVMPY_IsStaticLibstdcxxLinkageBuild() == 1:
|
| 58 |
+
return "static"
|
| 59 |
+
else:
|
| 60 |
+
return "dynamic"
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
build_libstdcxx_linkage_type = _build_libstdcxx_linkage_type()
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def _package_format():
|
| 67 |
+
"""
|
| 68 |
+
Returns "wheel", "conda" or "unspecified"
|
| 69 |
+
"""
|
| 70 |
+
return ffi.lib.LLVMPY_PackageFormat().decode()
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
package_format = _package_format()
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def _llvm_assertions_state():
|
| 77 |
+
"""
|
| 78 |
+
Returns one of "on", "off" or "unknown". Depending on whether it is
|
| 79 |
+
determined that LLVM was build with assertions on, off, or is not known.
|
| 80 |
+
"Is not known" is typically from a dynamic linkage against LLVM in which
|
| 81 |
+
case it's not easily identified whether LLVM was built with assertions.
|
| 82 |
+
"""
|
| 83 |
+
return ffi.lib.LLVMPY_LlvmAssertionsState().decode()
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
llvm_assertions_state = _llvm_assertions_state()
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
@cache
|
| 90 |
+
def get_sysinfo():
|
| 91 |
+
d = dict()
|
| 92 |
+
d["ffi_lib_location"] = ffi.lib._name
|
| 93 |
+
d["package_format"] = package_format
|
| 94 |
+
d["llvm_linkage_type"] = build_llvm_linkage_type
|
| 95 |
+
d["libstdcxx_linkage_type"] = build_libstdcxx_linkage_type
|
| 96 |
+
d["llvm_assertions_state"] = llvm_assertions_state
|
| 97 |
+
|
| 98 |
+
# import lief
|
| 99 |
+
HAVE_LIEF = False
|
| 100 |
+
try:
|
| 101 |
+
import lief
|
| 102 |
+
HAVE_LIEF = True
|
| 103 |
+
except ImportError:
|
| 104 |
+
msg = "py-lief package not found, sysinfo is limited as a result"
|
| 105 |
+
warnings.warn(msg)
|
| 106 |
+
|
| 107 |
+
d["lief_probe_status"] = HAVE_LIEF
|
| 108 |
+
d["linked_libraries"] = None
|
| 109 |
+
d["canonicalised_linked_libraries"] = None
|
| 110 |
+
|
| 111 |
+
def canonicalise_library_type(dso):
|
| 112 |
+
"""Canonicalises the representation of the binary::libraries as a
|
| 113 |
+
sequence of strings"""
|
| 114 |
+
# Note lief v16:
|
| 115 |
+
# Mach-O .libraries are DylibCommand instances.
|
| 116 |
+
# Windows PE and Linux ELF .libraries are strings.
|
| 117 |
+
return [getattr(x, "name", x) for x in dso.libraries]
|
| 118 |
+
|
| 119 |
+
def canonicalise_library_spelling(libs):
|
| 120 |
+
# This adjusts the library "spelling" so that it just contains the
|
| 121 |
+
# name given to the linker. e.g. `@rpath/somewhere/libfoo.so.1.3`
|
| 122 |
+
# would be canonicalised to "foo".
|
| 123 |
+
fixes = []
|
| 124 |
+
for lib in libs:
|
| 125 |
+
# some libraries, e.g. Mach-O have an @rpath or system path
|
| 126 |
+
# prefix in their name, remove it.
|
| 127 |
+
path_stripped = os.path.split(lib)[-1]
|
| 128 |
+
# Assume all library names contain at least one dot, even if they
|
| 129 |
+
# don't it's fine, the first part is the piece of interest.
|
| 130 |
+
prefix_libname = path_stripped.split(".")[0]
|
| 131 |
+
linker_name = prefix_libname.replace("lib", "").replace("LIB", "")
|
| 132 |
+
# further canonicalize by referring to all libraries in lower case.
|
| 133 |
+
fixes.append(linker_name.lower())
|
| 134 |
+
return fixes
|
| 135 |
+
|
| 136 |
+
if HAVE_LIEF:
|
| 137 |
+
dso = lief.parse(d["ffi_lib_location"])
|
| 138 |
+
link_libs = tuple(canonicalise_library_type(dso))
|
| 139 |
+
d["linked_libraries"] = link_libs
|
| 140 |
+
canonicalised_libs = canonicalise_library_spelling(link_libs)
|
| 141 |
+
d["canonicalised_linked_libraries"] = canonicalised_libs
|
| 142 |
+
|
| 143 |
+
return d
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/context.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llvmlite.binding import ffi
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def create_context():
|
| 5 |
+
return ContextRef(
|
| 6 |
+
ffi.lib.LLVMPY_ContextCreate())
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def get_global_context():
|
| 10 |
+
return GlobalContextRef(
|
| 11 |
+
ffi.lib.LLVMPY_GetGlobalContext())
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class ContextRef(ffi.ObjectRef):
|
| 15 |
+
def __init__(self, context_ptr):
|
| 16 |
+
super(ContextRef, self).__init__(context_ptr)
|
| 17 |
+
|
| 18 |
+
def _dispose(self):
|
| 19 |
+
ffi.lib.LLVMPY_ContextDispose(self)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class GlobalContextRef(ContextRef):
|
| 23 |
+
def _dispose(self):
|
| 24 |
+
pass
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
ffi.lib.LLVMPY_GetGlobalContext.restype = ffi.LLVMContextRef
|
| 28 |
+
|
| 29 |
+
ffi.lib.LLVMPY_ContextCreate.restype = ffi.LLVMContextRef
|
| 30 |
+
|
| 31 |
+
ffi.lib.LLVMPY_ContextDispose.argtypes = [ffi.LLVMContextRef]
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/dylib.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ctypes import c_void_p, c_char_p, c_bool, POINTER
|
| 2 |
+
|
| 3 |
+
from llvmlite.binding import ffi
|
| 4 |
+
from llvmlite.binding.common import _encode_string
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def address_of_symbol(name):
|
| 8 |
+
"""
|
| 9 |
+
Get the in-process address of symbol named *name*.
|
| 10 |
+
An integer is returned, or None if the symbol isn't found.
|
| 11 |
+
"""
|
| 12 |
+
return ffi.lib.LLVMPY_SearchAddressOfSymbol(_encode_string(name))
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def add_symbol(name, address):
|
| 16 |
+
"""
|
| 17 |
+
Register the *address* of global symbol *name*. This will make
|
| 18 |
+
it usable (e.g. callable) from LLVM-compiled functions.
|
| 19 |
+
"""
|
| 20 |
+
ffi.lib.LLVMPY_AddSymbol(_encode_string(name), c_void_p(address))
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def load_library_permanently(filename):
|
| 24 |
+
"""
|
| 25 |
+
Load an external library
|
| 26 |
+
"""
|
| 27 |
+
with ffi.OutputString() as outerr:
|
| 28 |
+
if ffi.lib.LLVMPY_LoadLibraryPermanently(
|
| 29 |
+
_encode_string(filename), outerr):
|
| 30 |
+
raise RuntimeError(str(outerr))
|
| 31 |
+
|
| 32 |
+
# ============================================================================
|
| 33 |
+
# FFI
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
ffi.lib.LLVMPY_AddSymbol.argtypes = [
|
| 37 |
+
c_char_p,
|
| 38 |
+
c_void_p,
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
ffi.lib.LLVMPY_SearchAddressOfSymbol.argtypes = [c_char_p]
|
| 42 |
+
ffi.lib.LLVMPY_SearchAddressOfSymbol.restype = c_void_p
|
| 43 |
+
|
| 44 |
+
ffi.lib.LLVMPY_LoadLibraryPermanently.argtypes = [c_char_p, POINTER(c_char_p)]
|
| 45 |
+
ffi.lib.LLVMPY_LoadLibraryPermanently.restype = c_bool
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/executionengine.py
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import platform
|
| 2 |
+
from ctypes import (POINTER, c_char_p, c_bool, c_void_p,
|
| 3 |
+
c_int, c_uint64, c_size_t, CFUNCTYPE, string_at, cast,
|
| 4 |
+
py_object, Structure)
|
| 5 |
+
|
| 6 |
+
from llvmlite.binding import ffi, targets, object_file
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
# Just check these weren't optimized out of the DLL.
|
| 10 |
+
ffi.lib.LLVMPY_LinkInMCJIT
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def create_mcjit_compiler(module, target_machine, use_lmm=None):
|
| 14 |
+
"""
|
| 15 |
+
Create a MCJIT ExecutionEngine from the given *module* and
|
| 16 |
+
*target_machine*.
|
| 17 |
+
|
| 18 |
+
*lmm* controls whether the llvmlite memory manager is used. If not supplied,
|
| 19 |
+
the default choice for the platform will be used (``True`` on 64-bit ARM
|
| 20 |
+
systems, ``False`` otherwise).
|
| 21 |
+
"""
|
| 22 |
+
if use_lmm is None:
|
| 23 |
+
use_lmm = platform.machine() in ('arm64', 'aarch64')
|
| 24 |
+
|
| 25 |
+
with ffi.OutputString() as outerr:
|
| 26 |
+
engine = ffi.lib.LLVMPY_CreateMCJITCompiler(
|
| 27 |
+
module, target_machine, use_lmm, outerr)
|
| 28 |
+
if not engine:
|
| 29 |
+
raise RuntimeError(str(outerr))
|
| 30 |
+
|
| 31 |
+
target_machine._owned = True
|
| 32 |
+
return ExecutionEngine(engine, module=module)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def check_jit_execution():
|
| 36 |
+
"""
|
| 37 |
+
Check the system allows execution of in-memory JITted functions.
|
| 38 |
+
An exception is raised otherwise.
|
| 39 |
+
"""
|
| 40 |
+
errno = ffi.lib.LLVMPY_TryAllocateExecutableMemory()
|
| 41 |
+
if errno != 0:
|
| 42 |
+
raise OSError(errno,
|
| 43 |
+
"cannot allocate executable memory. "
|
| 44 |
+
"This may be due to security restrictions on your "
|
| 45 |
+
"system, such as SELinux or similar mechanisms."
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class ExecutionEngine(ffi.ObjectRef):
|
| 50 |
+
"""An ExecutionEngine owns all Modules associated with it.
|
| 51 |
+
Deleting the engine will remove all associated modules.
|
| 52 |
+
It is an error to delete the associated modules.
|
| 53 |
+
"""
|
| 54 |
+
_object_cache = None
|
| 55 |
+
|
| 56 |
+
def __init__(self, ptr, module):
|
| 57 |
+
"""
|
| 58 |
+
Module ownership is transferred to the EE
|
| 59 |
+
"""
|
| 60 |
+
self._modules = set([module])
|
| 61 |
+
self._td = None
|
| 62 |
+
module._owned = True
|
| 63 |
+
ffi.ObjectRef.__init__(self, ptr)
|
| 64 |
+
|
| 65 |
+
def get_function_address(self, name):
|
| 66 |
+
"""
|
| 67 |
+
Return the address of the function named *name* as an integer.
|
| 68 |
+
|
| 69 |
+
It's a fatal error in LLVM if the symbol of *name* doesn't exist.
|
| 70 |
+
"""
|
| 71 |
+
return ffi.lib.LLVMPY_GetFunctionAddress(self, name.encode("ascii"))
|
| 72 |
+
|
| 73 |
+
def get_global_value_address(self, name):
|
| 74 |
+
"""
|
| 75 |
+
Return the address of the global value named *name* as an integer.
|
| 76 |
+
|
| 77 |
+
It's a fatal error in LLVM if the symbol of *name* doesn't exist.
|
| 78 |
+
"""
|
| 79 |
+
return ffi.lib.LLVMPY_GetGlobalValueAddress(self, name.encode("ascii"))
|
| 80 |
+
|
| 81 |
+
def add_global_mapping(self, gv, addr):
|
| 82 |
+
ffi.lib.LLVMPY_AddGlobalMapping(self, gv, addr)
|
| 83 |
+
|
| 84 |
+
def add_module(self, module):
|
| 85 |
+
"""
|
| 86 |
+
Ownership of module is transferred to the execution engine
|
| 87 |
+
"""
|
| 88 |
+
if module in self._modules:
|
| 89 |
+
raise KeyError("module already added to this engine")
|
| 90 |
+
ffi.lib.LLVMPY_AddModule(self, module)
|
| 91 |
+
module._owned = True
|
| 92 |
+
self._modules.add(module)
|
| 93 |
+
|
| 94 |
+
def finalize_object(self):
|
| 95 |
+
"""
|
| 96 |
+
Make sure all modules owned by the execution engine are fully processed
|
| 97 |
+
and "usable" for execution.
|
| 98 |
+
"""
|
| 99 |
+
ffi.lib.LLVMPY_FinalizeObject(self)
|
| 100 |
+
|
| 101 |
+
def run_static_constructors(self):
|
| 102 |
+
"""
|
| 103 |
+
Run static constructors which initialize module-level static objects.
|
| 104 |
+
"""
|
| 105 |
+
ffi.lib.LLVMPY_RunStaticConstructors(self)
|
| 106 |
+
|
| 107 |
+
def run_static_destructors(self):
|
| 108 |
+
"""
|
| 109 |
+
Run static destructors which perform module-level cleanup of static
|
| 110 |
+
resources.
|
| 111 |
+
"""
|
| 112 |
+
ffi.lib.LLVMPY_RunStaticDestructors(self)
|
| 113 |
+
|
| 114 |
+
def remove_module(self, module):
|
| 115 |
+
"""
|
| 116 |
+
Ownership of module is returned
|
| 117 |
+
"""
|
| 118 |
+
with ffi.OutputString() as outerr:
|
| 119 |
+
if ffi.lib.LLVMPY_RemoveModule(self, module, outerr):
|
| 120 |
+
raise RuntimeError(str(outerr))
|
| 121 |
+
self._modules.remove(module)
|
| 122 |
+
module._owned = False
|
| 123 |
+
|
| 124 |
+
@property
|
| 125 |
+
def target_data(self):
|
| 126 |
+
"""
|
| 127 |
+
The TargetData for this execution engine.
|
| 128 |
+
"""
|
| 129 |
+
if self._td is not None:
|
| 130 |
+
return self._td
|
| 131 |
+
ptr = ffi.lib.LLVMPY_GetExecutionEngineTargetData(self)
|
| 132 |
+
self._td = targets.TargetData(ptr)
|
| 133 |
+
self._td._owned = True
|
| 134 |
+
return self._td
|
| 135 |
+
|
| 136 |
+
def enable_jit_events(self):
|
| 137 |
+
"""
|
| 138 |
+
Enable JIT events for profiling of generated code.
|
| 139 |
+
Return value indicates whether connection to profiling tool
|
| 140 |
+
was successful.
|
| 141 |
+
"""
|
| 142 |
+
ret = ffi.lib.LLVMPY_EnableJITEvents(self)
|
| 143 |
+
return ret
|
| 144 |
+
|
| 145 |
+
def _find_module_ptr(self, module_ptr):
|
| 146 |
+
"""
|
| 147 |
+
Find the ModuleRef corresponding to the given pointer.
|
| 148 |
+
"""
|
| 149 |
+
ptr = cast(module_ptr, c_void_p).value
|
| 150 |
+
for module in self._modules:
|
| 151 |
+
if cast(module._ptr, c_void_p).value == ptr:
|
| 152 |
+
return module
|
| 153 |
+
return None
|
| 154 |
+
|
| 155 |
+
def add_object_file(self, obj_file):
|
| 156 |
+
"""
|
| 157 |
+
Add object file to the jit. object_file can be instance of
|
| 158 |
+
:class:ObjectFile or a string representing file system path
|
| 159 |
+
"""
|
| 160 |
+
if isinstance(obj_file, str):
|
| 161 |
+
obj_file = object_file.ObjectFileRef.from_path(obj_file)
|
| 162 |
+
|
| 163 |
+
ffi.lib.LLVMPY_MCJITAddObjectFile(self, obj_file)
|
| 164 |
+
|
| 165 |
+
def set_object_cache(self, notify_func=None, getbuffer_func=None):
|
| 166 |
+
"""
|
| 167 |
+
Set the object cache "notifyObjectCompiled" and "getBuffer"
|
| 168 |
+
callbacks to the given Python functions.
|
| 169 |
+
"""
|
| 170 |
+
self._object_cache_notify = notify_func
|
| 171 |
+
self._object_cache_getbuffer = getbuffer_func
|
| 172 |
+
# Lifetime of the object cache is managed by us.
|
| 173 |
+
self._object_cache = _ObjectCacheRef(self)
|
| 174 |
+
# Note this doesn't keep a reference to self, to avoid reference
|
| 175 |
+
# cycles.
|
| 176 |
+
ffi.lib.LLVMPY_SetObjectCache(self, self._object_cache)
|
| 177 |
+
|
| 178 |
+
def _raw_object_cache_notify(self, data):
|
| 179 |
+
"""
|
| 180 |
+
Low-level notify hook.
|
| 181 |
+
"""
|
| 182 |
+
if self._object_cache_notify is None:
|
| 183 |
+
return
|
| 184 |
+
module_ptr = data.contents.module_ptr
|
| 185 |
+
buf_ptr = data.contents.buf_ptr
|
| 186 |
+
buf_len = data.contents.buf_len
|
| 187 |
+
buf = string_at(buf_ptr, buf_len)
|
| 188 |
+
module = self._find_module_ptr(module_ptr)
|
| 189 |
+
if module is None:
|
| 190 |
+
# The LLVM EE should only give notifications for modules
|
| 191 |
+
# known by us.
|
| 192 |
+
raise RuntimeError("object compilation notification "
|
| 193 |
+
"for unknown module %s" % (module_ptr,))
|
| 194 |
+
self._object_cache_notify(module, buf)
|
| 195 |
+
|
| 196 |
+
def _raw_object_cache_getbuffer(self, data):
|
| 197 |
+
"""
|
| 198 |
+
Low-level getbuffer hook.
|
| 199 |
+
"""
|
| 200 |
+
if self._object_cache_getbuffer is None:
|
| 201 |
+
return
|
| 202 |
+
module_ptr = data.contents.module_ptr
|
| 203 |
+
module = self._find_module_ptr(module_ptr)
|
| 204 |
+
if module is None:
|
| 205 |
+
# The LLVM EE should only give notifications for modules
|
| 206 |
+
# known by us.
|
| 207 |
+
raise RuntimeError("object compilation notification "
|
| 208 |
+
"for unknown module %s" % (module_ptr,))
|
| 209 |
+
|
| 210 |
+
buf = self._object_cache_getbuffer(module)
|
| 211 |
+
if buf is not None:
|
| 212 |
+
# Create a copy, which will be freed by the caller
|
| 213 |
+
data[0].buf_ptr = ffi.lib.LLVMPY_CreateByteString(buf, len(buf))
|
| 214 |
+
data[0].buf_len = len(buf)
|
| 215 |
+
|
| 216 |
+
def _dispose(self):
|
| 217 |
+
# The modules will be cleaned up by the EE
|
| 218 |
+
for mod in self._modules:
|
| 219 |
+
mod.detach()
|
| 220 |
+
if self._td is not None:
|
| 221 |
+
self._td.detach()
|
| 222 |
+
self._modules.clear()
|
| 223 |
+
self._object_cache = None
|
| 224 |
+
self._capi.LLVMPY_DisposeExecutionEngine(self)
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
class _ObjectCacheRef(ffi.ObjectRef):
|
| 228 |
+
"""
|
| 229 |
+
Internal: an ObjectCache instance for use within an ExecutionEngine.
|
| 230 |
+
"""
|
| 231 |
+
|
| 232 |
+
def __init__(self, obj):
|
| 233 |
+
ptr = ffi.lib.LLVMPY_CreateObjectCache(_notify_c_hook,
|
| 234 |
+
_getbuffer_c_hook,
|
| 235 |
+
obj)
|
| 236 |
+
ffi.ObjectRef.__init__(self, ptr)
|
| 237 |
+
|
| 238 |
+
def _dispose(self):
|
| 239 |
+
self._capi.LLVMPY_DisposeObjectCache(self)
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
# ============================================================================
|
| 243 |
+
# FFI
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
ffi.lib.LLVMPY_CreateMCJITCompiler.argtypes = [
|
| 247 |
+
ffi.LLVMModuleRef,
|
| 248 |
+
ffi.LLVMTargetMachineRef,
|
| 249 |
+
c_bool,
|
| 250 |
+
POINTER(c_char_p),
|
| 251 |
+
]
|
| 252 |
+
ffi.lib.LLVMPY_CreateMCJITCompiler.restype = ffi.LLVMExecutionEngineRef
|
| 253 |
+
|
| 254 |
+
ffi.lib.LLVMPY_RemoveModule.argtypes = [
|
| 255 |
+
ffi.LLVMExecutionEngineRef,
|
| 256 |
+
ffi.LLVMModuleRef,
|
| 257 |
+
POINTER(c_char_p),
|
| 258 |
+
]
|
| 259 |
+
ffi.lib.LLVMPY_RemoveModule.restype = c_bool
|
| 260 |
+
|
| 261 |
+
ffi.lib.LLVMPY_AddModule.argtypes = [
|
| 262 |
+
ffi.LLVMExecutionEngineRef,
|
| 263 |
+
ffi.LLVMModuleRef
|
| 264 |
+
]
|
| 265 |
+
|
| 266 |
+
ffi.lib.LLVMPY_AddGlobalMapping.argtypes = [ffi.LLVMExecutionEngineRef,
|
| 267 |
+
ffi.LLVMValueRef,
|
| 268 |
+
c_void_p]
|
| 269 |
+
|
| 270 |
+
ffi.lib.LLVMPY_FinalizeObject.argtypes = [ffi.LLVMExecutionEngineRef]
|
| 271 |
+
|
| 272 |
+
ffi.lib.LLVMPY_GetExecutionEngineTargetData.argtypes = [
|
| 273 |
+
ffi.LLVMExecutionEngineRef
|
| 274 |
+
]
|
| 275 |
+
ffi.lib.LLVMPY_GetExecutionEngineTargetData.restype = ffi.LLVMTargetDataRef
|
| 276 |
+
|
| 277 |
+
ffi.lib.LLVMPY_TryAllocateExecutableMemory.argtypes = []
|
| 278 |
+
ffi.lib.LLVMPY_TryAllocateExecutableMemory.restype = c_int
|
| 279 |
+
|
| 280 |
+
ffi.lib.LLVMPY_GetFunctionAddress.argtypes = [
|
| 281 |
+
ffi.LLVMExecutionEngineRef,
|
| 282 |
+
c_char_p
|
| 283 |
+
]
|
| 284 |
+
ffi.lib.LLVMPY_GetFunctionAddress.restype = c_uint64
|
| 285 |
+
|
| 286 |
+
ffi.lib.LLVMPY_GetGlobalValueAddress.argtypes = [
|
| 287 |
+
ffi.LLVMExecutionEngineRef,
|
| 288 |
+
c_char_p
|
| 289 |
+
]
|
| 290 |
+
ffi.lib.LLVMPY_GetGlobalValueAddress.restype = c_uint64
|
| 291 |
+
|
| 292 |
+
ffi.lib.LLVMPY_MCJITAddObjectFile.argtypes = [
|
| 293 |
+
ffi.LLVMExecutionEngineRef,
|
| 294 |
+
ffi.LLVMObjectFileRef
|
| 295 |
+
]
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
class _ObjectCacheData(Structure):
|
| 299 |
+
_fields_ = [
|
| 300 |
+
('module_ptr', ffi.LLVMModuleRef),
|
| 301 |
+
('buf_ptr', c_void_p),
|
| 302 |
+
('buf_len', c_size_t),
|
| 303 |
+
]
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
_ObjectCacheNotifyFunc = CFUNCTYPE(None, py_object,
|
| 307 |
+
POINTER(_ObjectCacheData))
|
| 308 |
+
_ObjectCacheGetBufferFunc = CFUNCTYPE(None, py_object,
|
| 309 |
+
POINTER(_ObjectCacheData))
|
| 310 |
+
|
| 311 |
+
# XXX The ctypes function wrappers are created at the top-level, otherwise
|
| 312 |
+
# there are issues when creating CFUNCTYPEs in child processes on CentOS 5
|
| 313 |
+
# 32 bits.
|
| 314 |
+
_notify_c_hook = _ObjectCacheNotifyFunc(
|
| 315 |
+
ExecutionEngine._raw_object_cache_notify)
|
| 316 |
+
_getbuffer_c_hook = _ObjectCacheGetBufferFunc(
|
| 317 |
+
ExecutionEngine._raw_object_cache_getbuffer)
|
| 318 |
+
|
| 319 |
+
ffi.lib.LLVMPY_CreateObjectCache.argtypes = [_ObjectCacheNotifyFunc,
|
| 320 |
+
_ObjectCacheGetBufferFunc,
|
| 321 |
+
py_object]
|
| 322 |
+
ffi.lib.LLVMPY_CreateObjectCache.restype = ffi.LLVMObjectCacheRef
|
| 323 |
+
|
| 324 |
+
ffi.lib.LLVMPY_DisposeObjectCache.argtypes = [ffi.LLVMObjectCacheRef]
|
| 325 |
+
|
| 326 |
+
ffi.lib.LLVMPY_SetObjectCache.argtypes = [ffi.LLVMExecutionEngineRef,
|
| 327 |
+
ffi.LLVMObjectCacheRef]
|
| 328 |
+
|
| 329 |
+
ffi.lib.LLVMPY_CreateByteString.restype = c_void_p
|
| 330 |
+
ffi.lib.LLVMPY_CreateByteString.argtypes = [c_void_p, c_size_t]
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/ffi.py
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import ctypes
|
| 3 |
+
import threading
|
| 4 |
+
import importlib.resources as _impres
|
| 5 |
+
|
| 6 |
+
from llvmlite.binding.common import _decode_string, _is_shutting_down
|
| 7 |
+
from llvmlite.utils import get_library_name
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _make_opaque_ref(name):
|
| 11 |
+
newcls = type(name, (ctypes.Structure,), {})
|
| 12 |
+
return ctypes.POINTER(newcls)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
LLVMContextRef = _make_opaque_ref("LLVMContext")
|
| 16 |
+
LLVMModuleRef = _make_opaque_ref("LLVMModule")
|
| 17 |
+
LLVMValueRef = _make_opaque_ref("LLVMValue")
|
| 18 |
+
LLVMTypeRef = _make_opaque_ref("LLVMType")
|
| 19 |
+
LLVMExecutionEngineRef = _make_opaque_ref("LLVMExecutionEngine")
|
| 20 |
+
LLVMPassManagerBuilderRef = _make_opaque_ref("LLVMPassManagerBuilder")
|
| 21 |
+
LLVMPassManagerRef = _make_opaque_ref("LLVMPassManager")
|
| 22 |
+
LLVMTargetDataRef = _make_opaque_ref("LLVMTargetData")
|
| 23 |
+
LLVMTargetLibraryInfoRef = _make_opaque_ref("LLVMTargetLibraryInfo")
|
| 24 |
+
LLVMTargetRef = _make_opaque_ref("LLVMTarget")
|
| 25 |
+
LLVMTargetMachineRef = _make_opaque_ref("LLVMTargetMachine")
|
| 26 |
+
LLVMMemoryBufferRef = _make_opaque_ref("LLVMMemoryBuffer")
|
| 27 |
+
LLVMAttributeListIterator = _make_opaque_ref("LLVMAttributeListIterator")
|
| 28 |
+
LLVMElementIterator = _make_opaque_ref("LLVMElementIterator")
|
| 29 |
+
LLVMAttributeSetIterator = _make_opaque_ref("LLVMAttributeSetIterator")
|
| 30 |
+
LLVMGlobalsIterator = _make_opaque_ref("LLVMGlobalsIterator")
|
| 31 |
+
LLVMFunctionsIterator = _make_opaque_ref("LLVMFunctionsIterator")
|
| 32 |
+
LLVMBlocksIterator = _make_opaque_ref("LLVMBlocksIterator")
|
| 33 |
+
LLVMArgumentsIterator = _make_opaque_ref("LLVMArgumentsIterator")
|
| 34 |
+
LLVMInstructionsIterator = _make_opaque_ref("LLVMInstructionsIterator")
|
| 35 |
+
LLVMOperandsIterator = _make_opaque_ref("LLVMOperandsIterator")
|
| 36 |
+
LLVMIncomingBlocksIterator = _make_opaque_ref("LLVMIncomingBlocksIterator")
|
| 37 |
+
LLVMTypesIterator = _make_opaque_ref("LLVMTypesIterator")
|
| 38 |
+
LLVMObjectCacheRef = _make_opaque_ref("LLVMObjectCache")
|
| 39 |
+
LLVMObjectFileRef = _make_opaque_ref("LLVMObjectFile")
|
| 40 |
+
LLVMSectionIteratorRef = _make_opaque_ref("LLVMSectionIterator")
|
| 41 |
+
LLVMOrcLLJITRef = _make_opaque_ref("LLVMOrcLLJITRef")
|
| 42 |
+
LLVMOrcDylibTrackerRef = _make_opaque_ref("LLVMOrcDylibTrackerRef")
|
| 43 |
+
LLVMTimePassesHandlerRef = _make_opaque_ref("LLVMTimePassesHandler")
|
| 44 |
+
LLVMPipelineTuningOptionsRef = _make_opaque_ref("LLVMPipeLineTuningOptions")
|
| 45 |
+
LLVMModulePassManagerRef = _make_opaque_ref("LLVMModulePassManager")
|
| 46 |
+
LLVMFunctionPassManagerRef = _make_opaque_ref("LLVMFunctionPassManager")
|
| 47 |
+
LLVMPassBuilderRef = _make_opaque_ref("LLVMPassBuilder")
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class _LLVMLock:
|
| 51 |
+
"""A Lock to guarantee thread-safety for the LLVM C-API.
|
| 52 |
+
|
| 53 |
+
This class implements __enter__ and __exit__ for acquiring and releasing
|
| 54 |
+
the lock as a context manager.
|
| 55 |
+
|
| 56 |
+
Also, callbacks can be attached so that every time the lock is acquired
|
| 57 |
+
and released the corresponding callbacks will be invoked.
|
| 58 |
+
"""
|
| 59 |
+
def __init__(self):
|
| 60 |
+
# The reentrant lock is needed for callbacks that re-enter
|
| 61 |
+
# the Python interpreter.
|
| 62 |
+
self._lock = threading.RLock()
|
| 63 |
+
self._cblist = []
|
| 64 |
+
|
| 65 |
+
def register(self, acq_fn, rel_fn):
|
| 66 |
+
"""Register callbacks that are invoked immediately after the lock is
|
| 67 |
+
acquired (``acq_fn()``) and immediately before the lock is released
|
| 68 |
+
(``rel_fn()``).
|
| 69 |
+
"""
|
| 70 |
+
self._cblist.append((acq_fn, rel_fn))
|
| 71 |
+
|
| 72 |
+
def unregister(self, acq_fn, rel_fn):
|
| 73 |
+
"""Remove the registered callbacks.
|
| 74 |
+
"""
|
| 75 |
+
self._cblist.remove((acq_fn, rel_fn))
|
| 76 |
+
|
| 77 |
+
def __enter__(self):
|
| 78 |
+
self._lock.acquire()
|
| 79 |
+
# Invoke all callbacks
|
| 80 |
+
for acq_fn, rel_fn in self._cblist:
|
| 81 |
+
acq_fn()
|
| 82 |
+
|
| 83 |
+
def __exit__(self, *exc_details):
|
| 84 |
+
# Invoke all callbacks
|
| 85 |
+
for acq_fn, rel_fn in self._cblist:
|
| 86 |
+
rel_fn()
|
| 87 |
+
self._lock.release()
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
class _suppress_cleanup_errors:
|
| 91 |
+
def __init__(self, context):
|
| 92 |
+
self._context = context
|
| 93 |
+
|
| 94 |
+
def __enter__(self):
|
| 95 |
+
return self._context.__enter__()
|
| 96 |
+
|
| 97 |
+
def __exit__(self, exc_type, exc_value, traceback):
|
| 98 |
+
try:
|
| 99 |
+
return self._context.__exit__(exc_type, exc_value, traceback)
|
| 100 |
+
except PermissionError:
|
| 101 |
+
pass # Resource dylibs can't be deleted on Windows.
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
class _lib_wrapper(object):
|
| 105 |
+
"""Wrap libllvmlite with a lock such that only one thread may access it at
|
| 106 |
+
a time.
|
| 107 |
+
|
| 108 |
+
This class duck-types a CDLL.
|
| 109 |
+
"""
|
| 110 |
+
__slots__ = ['_lib_handle', '_fntab', '_lock']
|
| 111 |
+
|
| 112 |
+
def __init__(self):
|
| 113 |
+
self._lib_handle = None
|
| 114 |
+
self._fntab = {}
|
| 115 |
+
self._lock = _LLVMLock()
|
| 116 |
+
|
| 117 |
+
def _load_lib(self):
|
| 118 |
+
test_sym = "LLVMPY_GetVersionInfo"
|
| 119 |
+
mod_name = __name__.rpartition(".")[0]
|
| 120 |
+
lib_name = get_library_name()
|
| 121 |
+
|
| 122 |
+
with _suppress_cleanup_errors(_importlib_resources_path(
|
| 123 |
+
mod_name, lib_name)) as lib_path:
|
| 124 |
+
try:
|
| 125 |
+
self._lib_handle = ctypes.CDLL(str(lib_path))
|
| 126 |
+
# Check that we can look up expected symbols.
|
| 127 |
+
getattr(self._lib_handle, test_sym)()
|
| 128 |
+
except OSError:
|
| 129 |
+
# OSError may be raised if the file cannot be opened, or is not
|
| 130 |
+
# a shared library.
|
| 131 |
+
msg = (f"Could not find/load shared object file '{lib_name}' "
|
| 132 |
+
f"from resource location: '{mod_name}'. This could mean "
|
| 133 |
+
"that the library literally cannot be found, but may "
|
| 134 |
+
"also mean that the permissions are incorrect or that a "
|
| 135 |
+
"dependency of/a symbol in the library could not be "
|
| 136 |
+
"resolved.")
|
| 137 |
+
raise OSError(msg)
|
| 138 |
+
except AttributeError:
|
| 139 |
+
# AttributeError is raised if the test_sym symbol does not
|
| 140 |
+
# exist.
|
| 141 |
+
msg = ("During testing of symbol lookup, the symbol "
|
| 142 |
+
f"'{test_sym}' could not be found in the library "
|
| 143 |
+
f"'{lib_path}'")
|
| 144 |
+
raise OSError(msg)
|
| 145 |
+
|
| 146 |
+
@property
|
| 147 |
+
def _lib(self):
|
| 148 |
+
# Not threadsafe.
|
| 149 |
+
if not self._lib_handle:
|
| 150 |
+
self._load_lib()
|
| 151 |
+
return self._lib_handle
|
| 152 |
+
|
| 153 |
+
def __getattr__(self, name):
|
| 154 |
+
try:
|
| 155 |
+
return self._fntab[name]
|
| 156 |
+
except KeyError:
|
| 157 |
+
pass
|
| 158 |
+
# Lazily wraps new functions as they are requested
|
| 159 |
+
cfn = getattr(self._lib, name)
|
| 160 |
+
wrapped = _lib_fn_wrapper(self._lock, cfn)
|
| 161 |
+
self._fntab[name] = wrapped
|
| 162 |
+
return wrapped
|
| 163 |
+
|
| 164 |
+
@property
|
| 165 |
+
def _name(self):
|
| 166 |
+
"""The name of the library passed in the CDLL constructor.
|
| 167 |
+
|
| 168 |
+
For duck-typing a ctypes.CDLL
|
| 169 |
+
"""
|
| 170 |
+
return self._lib._name
|
| 171 |
+
|
| 172 |
+
@property
|
| 173 |
+
def _handle(self):
|
| 174 |
+
"""The system handle used to access the library.
|
| 175 |
+
|
| 176 |
+
For duck-typing a ctypes.CDLL
|
| 177 |
+
"""
|
| 178 |
+
return self._lib._handle
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
class _lib_fn_wrapper(object):
|
| 182 |
+
"""Wraps and duck-types a ctypes.CFUNCTYPE to provide
|
| 183 |
+
automatic locking when the wrapped function is called.
|
| 184 |
+
|
| 185 |
+
TODO: we can add methods to mark the function as threadsafe
|
| 186 |
+
and remove the locking-step on call when marked.
|
| 187 |
+
"""
|
| 188 |
+
__slots__ = ['_lock', '_cfn']
|
| 189 |
+
|
| 190 |
+
def __init__(self, lock, cfn):
|
| 191 |
+
self._lock = lock
|
| 192 |
+
self._cfn = cfn
|
| 193 |
+
|
| 194 |
+
@property
|
| 195 |
+
def argtypes(self):
|
| 196 |
+
return self._cfn.argtypes
|
| 197 |
+
|
| 198 |
+
@argtypes.setter
|
| 199 |
+
def argtypes(self, argtypes):
|
| 200 |
+
self._cfn.argtypes = argtypes
|
| 201 |
+
|
| 202 |
+
@property
|
| 203 |
+
def restype(self):
|
| 204 |
+
return self._cfn.restype
|
| 205 |
+
|
| 206 |
+
@restype.setter
|
| 207 |
+
def restype(self, restype):
|
| 208 |
+
self._cfn.restype = restype
|
| 209 |
+
|
| 210 |
+
def __call__(self, *args, **kwargs):
|
| 211 |
+
with self._lock:
|
| 212 |
+
return self._cfn(*args, **kwargs)
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def _importlib_resources_path_repl(package, resource):
|
| 216 |
+
"""Replacement implementation of `import.resources.path` to avoid
|
| 217 |
+
deprecation warning following code at importlib_resources/_legacy.py
|
| 218 |
+
as suggested by https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy
|
| 219 |
+
|
| 220 |
+
Notes on differences from importlib.resources implementation:
|
| 221 |
+
|
| 222 |
+
The `_common.normalize_path(resource)` call is skipped because it is an
|
| 223 |
+
internal API and it is unnecessary for the use here. What it does is
|
| 224 |
+
ensuring `resource` is a str and that it does not contain path separators.
|
| 225 |
+
""" # noqa E501
|
| 226 |
+
return _impres.as_file(_impres.files(package) / resource)
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
_importlib_resources_path = (_importlib_resources_path_repl
|
| 230 |
+
if sys.version_info[:2] >= (3, 10)
|
| 231 |
+
else _impres.path)
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
lib = _lib_wrapper()
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
def register_lock_callback(acq_fn, rel_fn):
|
| 238 |
+
"""Register callback functions for lock acquire and release.
|
| 239 |
+
*acq_fn* and *rel_fn* are callables that take no arguments.
|
| 240 |
+
"""
|
| 241 |
+
lib._lock.register(acq_fn, rel_fn)
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
def unregister_lock_callback(acq_fn, rel_fn):
|
| 245 |
+
"""Remove the registered callback functions for lock acquire and release.
|
| 246 |
+
The arguments are the same as used in `register_lock_callback()`.
|
| 247 |
+
"""
|
| 248 |
+
lib._lock.unregister(acq_fn, rel_fn)
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
class _DeadPointer(object):
|
| 252 |
+
"""
|
| 253 |
+
Dummy class to make error messages more helpful.
|
| 254 |
+
"""
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
class OutputString(object):
|
| 258 |
+
"""
|
| 259 |
+
Object for managing the char* output of LLVM APIs.
|
| 260 |
+
"""
|
| 261 |
+
_as_parameter_ = _DeadPointer()
|
| 262 |
+
|
| 263 |
+
@classmethod
|
| 264 |
+
def from_return(cls, ptr):
|
| 265 |
+
"""Constructing from a pointer returned from the C-API.
|
| 266 |
+
The pointer must be allocated with LLVMPY_CreateString.
|
| 267 |
+
|
| 268 |
+
Note
|
| 269 |
+
----
|
| 270 |
+
Because ctypes auto-converts *restype* of *c_char_p* into a python
|
| 271 |
+
string, we must use *c_void_p* to obtain the raw pointer.
|
| 272 |
+
"""
|
| 273 |
+
return cls(init=ctypes.cast(ptr, ctypes.c_char_p))
|
| 274 |
+
|
| 275 |
+
def __init__(self, owned=True, init=None):
|
| 276 |
+
self._ptr = init if init is not None else ctypes.c_char_p(None)
|
| 277 |
+
self._as_parameter_ = ctypes.byref(self._ptr)
|
| 278 |
+
self._owned = owned
|
| 279 |
+
|
| 280 |
+
def close(self):
|
| 281 |
+
if self._ptr is not None:
|
| 282 |
+
if self._owned:
|
| 283 |
+
lib.LLVMPY_DisposeString(self._ptr)
|
| 284 |
+
self._ptr = None
|
| 285 |
+
del self._as_parameter_
|
| 286 |
+
|
| 287 |
+
def __enter__(self):
|
| 288 |
+
return self
|
| 289 |
+
|
| 290 |
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
| 291 |
+
self.close()
|
| 292 |
+
|
| 293 |
+
def __del__(self, _is_shutting_down=_is_shutting_down):
|
| 294 |
+
# Avoid errors trying to rely on globals and modules at interpreter
|
| 295 |
+
# shutdown.
|
| 296 |
+
if not _is_shutting_down():
|
| 297 |
+
if self.close is not None:
|
| 298 |
+
self.close()
|
| 299 |
+
|
| 300 |
+
def __str__(self):
|
| 301 |
+
if self._ptr is None:
|
| 302 |
+
return "<dead OutputString>"
|
| 303 |
+
s = self._ptr.value
|
| 304 |
+
assert s is not None
|
| 305 |
+
return _decode_string(s)
|
| 306 |
+
|
| 307 |
+
def __bool__(self):
|
| 308 |
+
return bool(self._ptr)
|
| 309 |
+
|
| 310 |
+
__nonzero__ = __bool__
|
| 311 |
+
|
| 312 |
+
@property
|
| 313 |
+
def bytes(self):
|
| 314 |
+
"""Get the raw bytes of content of the char pointer.
|
| 315 |
+
"""
|
| 316 |
+
return self._ptr.value
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
def ret_string(ptr):
|
| 320 |
+
"""To wrap string return-value from C-API.
|
| 321 |
+
"""
|
| 322 |
+
if ptr is not None:
|
| 323 |
+
return str(OutputString.from_return(ptr))
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
def ret_bytes(ptr):
|
| 327 |
+
"""To wrap bytes return-value from C-API.
|
| 328 |
+
"""
|
| 329 |
+
if ptr is not None:
|
| 330 |
+
return OutputString.from_return(ptr).bytes
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
class ObjectRef(object):
|
| 334 |
+
"""
|
| 335 |
+
A wrapper around a ctypes pointer to a LLVM object ("resource").
|
| 336 |
+
"""
|
| 337 |
+
_closed = False
|
| 338 |
+
_as_parameter_ = _DeadPointer()
|
| 339 |
+
# Whether this object pointer is owned by another one.
|
| 340 |
+
_owned = False
|
| 341 |
+
|
| 342 |
+
def __init__(self, ptr):
|
| 343 |
+
if ptr is None:
|
| 344 |
+
raise ValueError("NULL pointer")
|
| 345 |
+
self._ptr = ptr
|
| 346 |
+
self._as_parameter_ = ptr
|
| 347 |
+
self._capi = lib
|
| 348 |
+
|
| 349 |
+
def close(self):
|
| 350 |
+
"""
|
| 351 |
+
Close this object and do any required clean-up actions.
|
| 352 |
+
"""
|
| 353 |
+
try:
|
| 354 |
+
if not self._closed and not self._owned:
|
| 355 |
+
self._dispose()
|
| 356 |
+
finally:
|
| 357 |
+
self.detach()
|
| 358 |
+
|
| 359 |
+
def detach(self):
|
| 360 |
+
"""
|
| 361 |
+
Detach the underlying LLVM resource without disposing of it.
|
| 362 |
+
"""
|
| 363 |
+
if not self._closed:
|
| 364 |
+
del self._as_parameter_
|
| 365 |
+
self._closed = True
|
| 366 |
+
self._ptr = None
|
| 367 |
+
|
| 368 |
+
def _dispose(self):
|
| 369 |
+
"""
|
| 370 |
+
Dispose of the underlying LLVM resource. Should be overriden
|
| 371 |
+
by subclasses. Automatically called by close(), __del__() and
|
| 372 |
+
__exit__() (unless the resource has been detached).
|
| 373 |
+
"""
|
| 374 |
+
|
| 375 |
+
@property
|
| 376 |
+
def closed(self):
|
| 377 |
+
"""
|
| 378 |
+
Whether this object has been closed. A closed object can't
|
| 379 |
+
be used anymore.
|
| 380 |
+
"""
|
| 381 |
+
return self._closed
|
| 382 |
+
|
| 383 |
+
def __enter__(self):
|
| 384 |
+
assert hasattr(self, "close")
|
| 385 |
+
if self._closed:
|
| 386 |
+
raise RuntimeError("%s instance already closed" % (self.__class__,))
|
| 387 |
+
return self
|
| 388 |
+
|
| 389 |
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
| 390 |
+
self.close()
|
| 391 |
+
|
| 392 |
+
def __del__(self, _is_shutting_down=_is_shutting_down):
|
| 393 |
+
if not _is_shutting_down():
|
| 394 |
+
if self.close is not None:
|
| 395 |
+
self.close()
|
| 396 |
+
|
| 397 |
+
def __bool__(self):
|
| 398 |
+
return bool(self._ptr)
|
| 399 |
+
|
| 400 |
+
def __eq__(self, other):
|
| 401 |
+
if not hasattr(other, "_ptr"):
|
| 402 |
+
return False
|
| 403 |
+
return ctypes.addressof(self._ptr[0]) == \
|
| 404 |
+
ctypes.addressof(other._ptr[0])
|
| 405 |
+
|
| 406 |
+
__nonzero__ = __bool__
|
| 407 |
+
|
| 408 |
+
# XXX useful?
|
| 409 |
+
def __hash__(self):
|
| 410 |
+
return hash(ctypes.cast(self._ptr, ctypes.c_void_p).value)
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/initfini.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ctypes import c_uint
|
| 2 |
+
|
| 3 |
+
from llvmlite.binding import ffi
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def initialize():
|
| 7 |
+
"""
|
| 8 |
+
Initialize the LLVM core (deprecated).
|
| 9 |
+
|
| 10 |
+
This function is deprecated and will raise an error when called.
|
| 11 |
+
LLVM initialization is now handled automatically and no longer
|
| 12 |
+
requires explicit initialization calls.
|
| 13 |
+
|
| 14 |
+
Raises:
|
| 15 |
+
RuntimeError: Always raised as this function is no longer needed.
|
| 16 |
+
"""
|
| 17 |
+
raise RuntimeError(
|
| 18 |
+
"llvmlite.binding.initialize() is deprecated and will be removed. "
|
| 19 |
+
"LLVM initialization is now handled automatically. "
|
| 20 |
+
"Please remove calls to this function from your code and check for "
|
| 21 |
+
"other behavioral changes that may have occurred due to LLVM updates."
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def initialize_all_targets():
|
| 26 |
+
"""
|
| 27 |
+
Initialize all targets. Necessary before targets can be looked up
|
| 28 |
+
via the :class:`Target` class.
|
| 29 |
+
"""
|
| 30 |
+
ffi.lib.LLVMPY_InitializeAllTargetInfos()
|
| 31 |
+
ffi.lib.LLVMPY_InitializeAllTargets()
|
| 32 |
+
ffi.lib.LLVMPY_InitializeAllTargetMCs()
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def initialize_all_asmprinters():
|
| 36 |
+
"""
|
| 37 |
+
Initialize all code generators. Necessary before generating
|
| 38 |
+
any assembly or machine code via the :meth:`TargetMachine.emit_object`
|
| 39 |
+
and :meth:`TargetMachine.emit_assembly` methods.
|
| 40 |
+
"""
|
| 41 |
+
ffi.lib.LLVMPY_InitializeAllAsmPrinters()
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def initialize_native_target():
|
| 45 |
+
"""
|
| 46 |
+
Initialize the native (host) target. Necessary before doing any
|
| 47 |
+
code generation.
|
| 48 |
+
"""
|
| 49 |
+
ffi.lib.LLVMPY_InitializeNativeTarget()
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def initialize_native_asmprinter():
|
| 53 |
+
"""
|
| 54 |
+
Initialize the native ASM printer.
|
| 55 |
+
"""
|
| 56 |
+
ffi.lib.LLVMPY_InitializeNativeAsmPrinter()
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def initialize_native_asmparser():
|
| 60 |
+
"""
|
| 61 |
+
Initialize the native ASM parser.
|
| 62 |
+
"""
|
| 63 |
+
ffi.lib.LLVMPY_InitializeNativeAsmParser()
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def shutdown():
|
| 67 |
+
ffi.lib.LLVMPY_Shutdown()
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
# =============================================================================
|
| 71 |
+
# Set function FFI
|
| 72 |
+
|
| 73 |
+
ffi.lib.LLVMPY_GetVersionInfo.restype = c_uint
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def _version_info():
|
| 77 |
+
v = []
|
| 78 |
+
x = ffi.lib.LLVMPY_GetVersionInfo()
|
| 79 |
+
while x:
|
| 80 |
+
v.append(x & 0xff)
|
| 81 |
+
x >>= 8
|
| 82 |
+
return tuple(reversed(v))
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
llvm_version_info = _version_info()
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/linker.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ctypes import c_int, c_char_p, POINTER
|
| 2 |
+
from llvmlite.binding import ffi
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def link_modules(dst, src):
|
| 6 |
+
with ffi.OutputString() as outerr:
|
| 7 |
+
err = ffi.lib.LLVMPY_LinkModules(dst, src, outerr)
|
| 8 |
+
# The underlying module was destroyed
|
| 9 |
+
src.detach()
|
| 10 |
+
if err:
|
| 11 |
+
raise RuntimeError(str(outerr))
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
ffi.lib.LLVMPY_LinkModules.argtypes = [
|
| 15 |
+
ffi.LLVMModuleRef,
|
| 16 |
+
ffi.LLVMModuleRef,
|
| 17 |
+
POINTER(c_char_p),
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
ffi.lib.LLVMPY_LinkModules.restype = c_int
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/module.py
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ctypes import (c_char_p, byref, POINTER, c_bool, create_string_buffer,
|
| 2 |
+
c_size_t, string_at)
|
| 3 |
+
|
| 4 |
+
from llvmlite.binding import ffi
|
| 5 |
+
from llvmlite.binding.linker import link_modules
|
| 6 |
+
from llvmlite.binding.common import _decode_string, _encode_string
|
| 7 |
+
from llvmlite.binding.value import ValueRef, TypeRef
|
| 8 |
+
from llvmlite.binding.context import get_global_context
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def parse_assembly(llvmir, context=None):
|
| 12 |
+
"""
|
| 13 |
+
Create Module from a LLVM IR string
|
| 14 |
+
"""
|
| 15 |
+
if context is None:
|
| 16 |
+
context = get_global_context()
|
| 17 |
+
llvmir = _encode_string(llvmir)
|
| 18 |
+
strbuf = c_char_p(llvmir)
|
| 19 |
+
with ffi.OutputString() as errmsg:
|
| 20 |
+
mod = ModuleRef(
|
| 21 |
+
ffi.lib.LLVMPY_ParseAssembly(context, strbuf, errmsg),
|
| 22 |
+
context)
|
| 23 |
+
if errmsg:
|
| 24 |
+
mod.close()
|
| 25 |
+
raise RuntimeError("LLVM IR parsing error\n{0}".format(errmsg))
|
| 26 |
+
return mod
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def parse_bitcode(bitcode, context=None):
|
| 30 |
+
"""
|
| 31 |
+
Create Module from a LLVM *bitcode* (a bytes object).
|
| 32 |
+
"""
|
| 33 |
+
if context is None:
|
| 34 |
+
context = get_global_context()
|
| 35 |
+
buf = c_char_p(bitcode)
|
| 36 |
+
bufsize = len(bitcode)
|
| 37 |
+
with ffi.OutputString() as errmsg:
|
| 38 |
+
mod = ModuleRef(ffi.lib.LLVMPY_ParseBitcode(
|
| 39 |
+
context, buf, bufsize, errmsg), context)
|
| 40 |
+
if errmsg:
|
| 41 |
+
mod.close()
|
| 42 |
+
raise RuntimeError(
|
| 43 |
+
"LLVM bitcode parsing error\n{0}".format(errmsg))
|
| 44 |
+
return mod
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class ModuleRef(ffi.ObjectRef):
|
| 48 |
+
"""
|
| 49 |
+
A reference to a LLVM module.
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
def __init__(self, module_ptr, context):
|
| 53 |
+
super(ModuleRef, self).__init__(module_ptr)
|
| 54 |
+
self._context = context
|
| 55 |
+
|
| 56 |
+
def __str__(self):
|
| 57 |
+
with ffi.OutputString() as outstr:
|
| 58 |
+
ffi.lib.LLVMPY_PrintModuleToString(self, outstr)
|
| 59 |
+
return str(outstr)
|
| 60 |
+
|
| 61 |
+
def as_bitcode(self):
|
| 62 |
+
"""
|
| 63 |
+
Return the module's LLVM bitcode, as a bytes object.
|
| 64 |
+
"""
|
| 65 |
+
ptr = c_char_p(None)
|
| 66 |
+
size = c_size_t(-1)
|
| 67 |
+
ffi.lib.LLVMPY_WriteBitcodeToString(self, byref(ptr), byref(size))
|
| 68 |
+
if not ptr:
|
| 69 |
+
raise MemoryError
|
| 70 |
+
try:
|
| 71 |
+
assert size.value >= 0
|
| 72 |
+
return string_at(ptr, size.value)
|
| 73 |
+
finally:
|
| 74 |
+
ffi.lib.LLVMPY_DisposeString(ptr)
|
| 75 |
+
|
| 76 |
+
def _dispose(self):
|
| 77 |
+
self._capi.LLVMPY_DisposeModule(self)
|
| 78 |
+
|
| 79 |
+
def get_function(self, name):
|
| 80 |
+
"""
|
| 81 |
+
Get a ValueRef pointing to the function named *name*.
|
| 82 |
+
NameError is raised if the symbol isn't found.
|
| 83 |
+
"""
|
| 84 |
+
p = ffi.lib.LLVMPY_GetNamedFunction(self, _encode_string(name))
|
| 85 |
+
if not p:
|
| 86 |
+
raise NameError(name)
|
| 87 |
+
return ValueRef(p, 'function', dict(module=self))
|
| 88 |
+
|
| 89 |
+
def get_global_variable(self, name):
|
| 90 |
+
"""
|
| 91 |
+
Get a ValueRef pointing to the global variable named *name*.
|
| 92 |
+
NameError is raised if the symbol isn't found.
|
| 93 |
+
"""
|
| 94 |
+
p = ffi.lib.LLVMPY_GetNamedGlobalVariable(self, _encode_string(name))
|
| 95 |
+
if not p:
|
| 96 |
+
raise NameError(name)
|
| 97 |
+
return ValueRef(p, 'global', dict(module=self))
|
| 98 |
+
|
| 99 |
+
def get_struct_type(self, name):
|
| 100 |
+
"""
|
| 101 |
+
Get a TypeRef pointing to a structure type named *name*.
|
| 102 |
+
NameError is raised if the struct type isn't found.
|
| 103 |
+
"""
|
| 104 |
+
p = ffi.lib.LLVMPY_GetNamedStructType(self, _encode_string(name))
|
| 105 |
+
if not p:
|
| 106 |
+
raise NameError(name)
|
| 107 |
+
return TypeRef(p)
|
| 108 |
+
|
| 109 |
+
def verify(self):
|
| 110 |
+
"""
|
| 111 |
+
Verify the module IR's correctness. RuntimeError is raised on error.
|
| 112 |
+
"""
|
| 113 |
+
with ffi.OutputString() as outmsg:
|
| 114 |
+
if ffi.lib.LLVMPY_VerifyModule(self, outmsg):
|
| 115 |
+
raise RuntimeError(str(outmsg))
|
| 116 |
+
|
| 117 |
+
@property
|
| 118 |
+
def name(self):
|
| 119 |
+
"""
|
| 120 |
+
The module's identifier.
|
| 121 |
+
"""
|
| 122 |
+
return _decode_string(ffi.lib.LLVMPY_GetModuleName(self))
|
| 123 |
+
|
| 124 |
+
@name.setter
|
| 125 |
+
def name(self, value):
|
| 126 |
+
ffi.lib.LLVMPY_SetModuleName(self, _encode_string(value))
|
| 127 |
+
|
| 128 |
+
@property
|
| 129 |
+
def source_file(self):
|
| 130 |
+
"""
|
| 131 |
+
The module's original source file name
|
| 132 |
+
"""
|
| 133 |
+
return _decode_string(ffi.lib.LLVMPY_GetModuleSourceFileName(self))
|
| 134 |
+
|
| 135 |
+
@property
|
| 136 |
+
def data_layout(self):
|
| 137 |
+
"""
|
| 138 |
+
This module's data layout specification, as a string.
|
| 139 |
+
"""
|
| 140 |
+
# LLVMGetDataLayout() points inside a std::string managed by LLVM.
|
| 141 |
+
with ffi.OutputString(owned=False) as outmsg:
|
| 142 |
+
ffi.lib.LLVMPY_GetDataLayout(self, outmsg)
|
| 143 |
+
return str(outmsg)
|
| 144 |
+
|
| 145 |
+
@data_layout.setter
|
| 146 |
+
def data_layout(self, strrep):
|
| 147 |
+
ffi.lib.LLVMPY_SetDataLayout(self,
|
| 148 |
+
create_string_buffer(
|
| 149 |
+
strrep.encode('utf8')))
|
| 150 |
+
|
| 151 |
+
@property
|
| 152 |
+
def triple(self):
|
| 153 |
+
"""
|
| 154 |
+
This module's target "triple" specification, as a string.
|
| 155 |
+
"""
|
| 156 |
+
# LLVMGetTarget() points inside a std::string managed by LLVM.
|
| 157 |
+
with ffi.OutputString(owned=False) as outmsg:
|
| 158 |
+
ffi.lib.LLVMPY_GetTarget(self, outmsg)
|
| 159 |
+
return str(outmsg)
|
| 160 |
+
|
| 161 |
+
@triple.setter
|
| 162 |
+
def triple(self, strrep):
|
| 163 |
+
ffi.lib.LLVMPY_SetTarget(self,
|
| 164 |
+
create_string_buffer(
|
| 165 |
+
strrep.encode('utf8')))
|
| 166 |
+
|
| 167 |
+
def link_in(self, other, preserve=False):
|
| 168 |
+
"""
|
| 169 |
+
Link the *other* module into this one. The *other* module will
|
| 170 |
+
be destroyed unless *preserve* is true.
|
| 171 |
+
"""
|
| 172 |
+
if preserve:
|
| 173 |
+
other = other.clone()
|
| 174 |
+
link_modules(self, other)
|
| 175 |
+
|
| 176 |
+
@property
|
| 177 |
+
def global_variables(self):
|
| 178 |
+
"""
|
| 179 |
+
Return an iterator over this module's global variables.
|
| 180 |
+
The iterator will yield a ValueRef for each global variable.
|
| 181 |
+
|
| 182 |
+
Note that global variables don't include functions
|
| 183 |
+
(a function is a "global value" but not a "global variable" in
|
| 184 |
+
LLVM parlance)
|
| 185 |
+
"""
|
| 186 |
+
it = ffi.lib.LLVMPY_ModuleGlobalsIter(self)
|
| 187 |
+
return _GlobalsIterator(it, dict(module=self))
|
| 188 |
+
|
| 189 |
+
@property
|
| 190 |
+
def functions(self):
|
| 191 |
+
"""
|
| 192 |
+
Return an iterator over this module's functions.
|
| 193 |
+
The iterator will yield a ValueRef for each function.
|
| 194 |
+
"""
|
| 195 |
+
it = ffi.lib.LLVMPY_ModuleFunctionsIter(self)
|
| 196 |
+
return _FunctionsIterator(it, dict(module=self))
|
| 197 |
+
|
| 198 |
+
@property
|
| 199 |
+
def struct_types(self):
|
| 200 |
+
"""
|
| 201 |
+
Return an iterator over the struct types defined in
|
| 202 |
+
the module. The iterator will yield a TypeRef.
|
| 203 |
+
"""
|
| 204 |
+
it = ffi.lib.LLVMPY_ModuleTypesIter(self)
|
| 205 |
+
return _TypesIterator(it, dict(module=self))
|
| 206 |
+
|
| 207 |
+
def clone(self):
|
| 208 |
+
return ModuleRef(ffi.lib.LLVMPY_CloneModule(self), self._context)
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
class _Iterator(ffi.ObjectRef):
|
| 212 |
+
|
| 213 |
+
kind = None
|
| 214 |
+
|
| 215 |
+
def __init__(self, ptr, parents):
|
| 216 |
+
ffi.ObjectRef.__init__(self, ptr)
|
| 217 |
+
self._parents = parents
|
| 218 |
+
assert self.kind is not None
|
| 219 |
+
|
| 220 |
+
def __next__(self):
|
| 221 |
+
vp = self._next()
|
| 222 |
+
if vp:
|
| 223 |
+
return ValueRef(vp, self.kind, self._parents)
|
| 224 |
+
else:
|
| 225 |
+
raise StopIteration
|
| 226 |
+
|
| 227 |
+
next = __next__
|
| 228 |
+
|
| 229 |
+
def __iter__(self):
|
| 230 |
+
return self
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
class _GlobalsIterator(_Iterator):
|
| 234 |
+
|
| 235 |
+
kind = 'global'
|
| 236 |
+
|
| 237 |
+
def _dispose(self):
|
| 238 |
+
self._capi.LLVMPY_DisposeGlobalsIter(self)
|
| 239 |
+
|
| 240 |
+
def _next(self):
|
| 241 |
+
return ffi.lib.LLVMPY_GlobalsIterNext(self)
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
class _FunctionsIterator(_Iterator):
|
| 245 |
+
|
| 246 |
+
kind = 'function'
|
| 247 |
+
|
| 248 |
+
def _dispose(self):
|
| 249 |
+
self._capi.LLVMPY_DisposeFunctionsIter(self)
|
| 250 |
+
|
| 251 |
+
def _next(self):
|
| 252 |
+
return ffi.lib.LLVMPY_FunctionsIterNext(self)
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
class _TypesIterator(_Iterator):
|
| 256 |
+
|
| 257 |
+
kind = 'type'
|
| 258 |
+
|
| 259 |
+
def _dispose(self):
|
| 260 |
+
self._capi.LLVMPY_DisposeTypesIter(self)
|
| 261 |
+
|
| 262 |
+
def __next__(self):
|
| 263 |
+
vp = self._next()
|
| 264 |
+
if vp:
|
| 265 |
+
return TypeRef(vp)
|
| 266 |
+
else:
|
| 267 |
+
raise StopIteration
|
| 268 |
+
|
| 269 |
+
def _next(self):
|
| 270 |
+
return ffi.lib.LLVMPY_TypesIterNext(self)
|
| 271 |
+
|
| 272 |
+
next = __next__
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
# =============================================================================
|
| 276 |
+
# Set function FFI
|
| 277 |
+
|
| 278 |
+
ffi.lib.LLVMPY_ParseAssembly.argtypes = [ffi.LLVMContextRef,
|
| 279 |
+
c_char_p,
|
| 280 |
+
POINTER(c_char_p)]
|
| 281 |
+
ffi.lib.LLVMPY_ParseAssembly.restype = ffi.LLVMModuleRef
|
| 282 |
+
|
| 283 |
+
ffi.lib.LLVMPY_ParseBitcode.argtypes = [ffi.LLVMContextRef,
|
| 284 |
+
c_char_p, c_size_t,
|
| 285 |
+
POINTER(c_char_p)]
|
| 286 |
+
ffi.lib.LLVMPY_ParseBitcode.restype = ffi.LLVMModuleRef
|
| 287 |
+
|
| 288 |
+
ffi.lib.LLVMPY_DisposeModule.argtypes = [ffi.LLVMModuleRef]
|
| 289 |
+
|
| 290 |
+
ffi.lib.LLVMPY_PrintModuleToString.argtypes = [ffi.LLVMModuleRef,
|
| 291 |
+
POINTER(c_char_p)]
|
| 292 |
+
ffi.lib.LLVMPY_WriteBitcodeToString.argtypes = [ffi.LLVMModuleRef,
|
| 293 |
+
POINTER(c_char_p),
|
| 294 |
+
POINTER(c_size_t)]
|
| 295 |
+
|
| 296 |
+
ffi.lib.LLVMPY_GetNamedFunction.argtypes = [ffi.LLVMModuleRef,
|
| 297 |
+
c_char_p]
|
| 298 |
+
ffi.lib.LLVMPY_GetNamedFunction.restype = ffi.LLVMValueRef
|
| 299 |
+
|
| 300 |
+
ffi.lib.LLVMPY_VerifyModule.argtypes = [ffi.LLVMModuleRef,
|
| 301 |
+
POINTER(c_char_p)]
|
| 302 |
+
ffi.lib.LLVMPY_VerifyModule.restype = c_bool
|
| 303 |
+
|
| 304 |
+
ffi.lib.LLVMPY_GetDataLayout.argtypes = [ffi.LLVMModuleRef, POINTER(c_char_p)]
|
| 305 |
+
ffi.lib.LLVMPY_SetDataLayout.argtypes = [ffi.LLVMModuleRef, c_char_p]
|
| 306 |
+
|
| 307 |
+
ffi.lib.LLVMPY_GetTarget.argtypes = [ffi.LLVMModuleRef, POINTER(c_char_p)]
|
| 308 |
+
ffi.lib.LLVMPY_SetTarget.argtypes = [ffi.LLVMModuleRef, c_char_p]
|
| 309 |
+
|
| 310 |
+
ffi.lib.LLVMPY_GetNamedGlobalVariable.argtypes = [ffi.LLVMModuleRef, c_char_p]
|
| 311 |
+
ffi.lib.LLVMPY_GetNamedGlobalVariable.restype = ffi.LLVMValueRef
|
| 312 |
+
|
| 313 |
+
ffi.lib.LLVMPY_GetNamedStructType.argtypes = [ffi.LLVMModuleRef, c_char_p]
|
| 314 |
+
ffi.lib.LLVMPY_GetNamedStructType.restype = ffi.LLVMTypeRef
|
| 315 |
+
|
| 316 |
+
ffi.lib.LLVMPY_ModuleGlobalsIter.argtypes = [ffi.LLVMModuleRef]
|
| 317 |
+
ffi.lib.LLVMPY_ModuleGlobalsIter.restype = ffi.LLVMGlobalsIterator
|
| 318 |
+
|
| 319 |
+
ffi.lib.LLVMPY_DisposeGlobalsIter.argtypes = [ffi.LLVMGlobalsIterator]
|
| 320 |
+
|
| 321 |
+
ffi.lib.LLVMPY_GlobalsIterNext.argtypes = [ffi.LLVMGlobalsIterator]
|
| 322 |
+
ffi.lib.LLVMPY_GlobalsIterNext.restype = ffi.LLVMValueRef
|
| 323 |
+
|
| 324 |
+
ffi.lib.LLVMPY_ModuleFunctionsIter.argtypes = [ffi.LLVMModuleRef]
|
| 325 |
+
ffi.lib.LLVMPY_ModuleFunctionsIter.restype = ffi.LLVMFunctionsIterator
|
| 326 |
+
|
| 327 |
+
ffi.lib.LLVMPY_ModuleTypesIter.argtypes = [ffi.LLVMModuleRef]
|
| 328 |
+
ffi.lib.LLVMPY_ModuleTypesIter.restype = ffi.LLVMTypesIterator
|
| 329 |
+
|
| 330 |
+
ffi.lib.LLVMPY_DisposeFunctionsIter.argtypes = [ffi.LLVMFunctionsIterator]
|
| 331 |
+
|
| 332 |
+
ffi.lib.LLVMPY_DisposeTypesIter.argtypes = [ffi.LLVMTypesIterator]
|
| 333 |
+
|
| 334 |
+
ffi.lib.LLVMPY_FunctionsIterNext.argtypes = [ffi.LLVMFunctionsIterator]
|
| 335 |
+
ffi.lib.LLVMPY_FunctionsIterNext.restype = ffi.LLVMValueRef
|
| 336 |
+
|
| 337 |
+
ffi.lib.LLVMPY_TypesIterNext.argtypes = [ffi.LLVMTypesIterator]
|
| 338 |
+
ffi.lib.LLVMPY_TypesIterNext.restype = ffi.LLVMTypeRef
|
| 339 |
+
|
| 340 |
+
ffi.lib.LLVMPY_CloneModule.argtypes = [ffi.LLVMModuleRef]
|
| 341 |
+
ffi.lib.LLVMPY_CloneModule.restype = ffi.LLVMModuleRef
|
| 342 |
+
|
| 343 |
+
ffi.lib.LLVMPY_GetModuleName.argtypes = [ffi.LLVMModuleRef]
|
| 344 |
+
ffi.lib.LLVMPY_GetModuleName.restype = c_char_p
|
| 345 |
+
|
| 346 |
+
ffi.lib.LLVMPY_SetModuleName.argtypes = [ffi.LLVMModuleRef, c_char_p]
|
| 347 |
+
|
| 348 |
+
ffi.lib.LLVMPY_GetModuleSourceFileName.argtypes = [ffi.LLVMModuleRef]
|
| 349 |
+
ffi.lib.LLVMPY_GetModuleSourceFileName.restype = c_char_p
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/newpassmanagers.py
ADDED
|
@@ -0,0 +1,1049 @@
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ctypes import c_bool, c_int, c_size_t, POINTER, Structure, byref, c_char_p
|
| 2 |
+
from collections import namedtuple
|
| 3 |
+
from enum import IntFlag
|
| 4 |
+
from llvmlite.binding import ffi
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def create_new_module_pass_manager():
|
| 8 |
+
return ModulePassManager()
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def create_new_function_pass_manager():
|
| 12 |
+
return FunctionPassManager()
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def create_pass_builder(tm, pto):
|
| 16 |
+
return PassBuilder(tm, pto)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def create_pipeline_tuning_options(speed_level=2, size_level=0):
|
| 20 |
+
return PipelineTuningOptions(speed_level, size_level)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
_prunestats = namedtuple('PruneStats',
|
| 24 |
+
('basicblock diamond fanout fanout_raise'))
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class PruneStats(_prunestats):
|
| 28 |
+
""" Holds statistics from reference count pruning.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
def __add__(self, other):
|
| 32 |
+
if not isinstance(other, PruneStats):
|
| 33 |
+
msg = 'PruneStats can only be added to another PruneStats, 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 |
+
def __sub__(self, other):
|
| 41 |
+
if not isinstance(other, PruneStats):
|
| 42 |
+
msg = ('PruneStats can only be subtracted from another PruneStats, '
|
| 43 |
+
'got {}.')
|
| 44 |
+
raise TypeError(msg.format(type(other)))
|
| 45 |
+
return PruneStats(self.basicblock - other.basicblock,
|
| 46 |
+
self.diamond - other.diamond,
|
| 47 |
+
self.fanout - other.fanout,
|
| 48 |
+
self.fanout_raise - other.fanout_raise)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class _c_PruneStats(Structure):
|
| 52 |
+
_fields_ = [
|
| 53 |
+
('basicblock', c_size_t),
|
| 54 |
+
('diamond', c_size_t),
|
| 55 |
+
('fanout', c_size_t),
|
| 56 |
+
('fanout_raise', c_size_t)]
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def dump_refprune_stats(printout=False):
|
| 60 |
+
""" Returns a namedtuple containing the current values for the refop pruning
|
| 61 |
+
statistics. If kwarg `printout` is True the stats are printed to stderr,
|
| 62 |
+
default is False.
|
| 63 |
+
"""
|
| 64 |
+
|
| 65 |
+
stats = _c_PruneStats(0, 0, 0, 0)
|
| 66 |
+
do_print = c_bool(printout)
|
| 67 |
+
|
| 68 |
+
ffi.lib.LLVMPY_DumpRefPruneStats(byref(stats), do_print)
|
| 69 |
+
return PruneStats(stats.basicblock, stats.diamond, stats.fanout,
|
| 70 |
+
stats.fanout_raise)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
# TODO: Rename and add tests for these
|
| 74 |
+
# Although new pass manager has its own timing APIs, we still need to support
|
| 75 |
+
# the legacy ones as LLVM backend still used the LegacyPassManager. These APIs
|
| 76 |
+
# will be used to time the backend passes such as instruction selection,
|
| 77 |
+
# regalloc, etc
|
| 78 |
+
def set_time_passes(enable):
|
| 79 |
+
"""Enable or disable the pass timers.
|
| 80 |
+
|
| 81 |
+
Parameters
|
| 82 |
+
----------
|
| 83 |
+
enable : bool
|
| 84 |
+
Set to True to enable the pass timers.
|
| 85 |
+
Set to False to disable the pass timers.
|
| 86 |
+
"""
|
| 87 |
+
ffi.lib.LLVMPY_SetTimePasses(c_bool(enable))
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def report_and_reset_timings():
|
| 91 |
+
"""Returns the pass timings report and resets the LLVM internal timers.
|
| 92 |
+
|
| 93 |
+
Pass timers are enabled by ``set_time_passes()``. If the timers are not
|
| 94 |
+
enabled, this function will return an empty string.
|
| 95 |
+
|
| 96 |
+
Returns
|
| 97 |
+
-------
|
| 98 |
+
res : str
|
| 99 |
+
LLVM generated timing report.
|
| 100 |
+
"""
|
| 101 |
+
with ffi.OutputString() as buf:
|
| 102 |
+
ffi.lib.LLVMPY_ReportAndResetTimings(buf)
|
| 103 |
+
return str(buf)
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
class RefPruneSubpasses(IntFlag):
|
| 107 |
+
PER_BB = 0b0001 # noqa: E221
|
| 108 |
+
DIAMOND = 0b0010 # noqa: E221
|
| 109 |
+
FANOUT = 0b0100 # noqa: E221
|
| 110 |
+
FANOUT_RAISE = 0b1000
|
| 111 |
+
ALL = PER_BB | DIAMOND | FANOUT | FANOUT_RAISE
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
class NewPassManager():
|
| 115 |
+
|
| 116 |
+
def __init__(self):
|
| 117 |
+
if type(self) is NewPassManager:
|
| 118 |
+
raise TypeError("Cannot instantiate NewPassManager directly")
|
| 119 |
+
|
| 120 |
+
def run(self,IR, pb):
|
| 121 |
+
if isinstance(self, ModulePassManager):
|
| 122 |
+
ffi.lib.LLVMPY_RunNewModulePassManager(self, IR, pb)
|
| 123 |
+
else:
|
| 124 |
+
ffi.lib.LLVMPY_RunNewFunctionPassManager(self, IR, pb)
|
| 125 |
+
|
| 126 |
+
def add_aa_eval_pass(self):
|
| 127 |
+
if isinstance(self, ModulePassManager):
|
| 128 |
+
ffi.lib.LLVMPY_module_AddAAEvaluator(self)
|
| 129 |
+
else:
|
| 130 |
+
ffi.lib.LLVMPY_function_AddAAEvaluator(self)
|
| 131 |
+
|
| 132 |
+
def add_simplify_cfg_pass(self):
|
| 133 |
+
if isinstance(self, ModulePassManager):
|
| 134 |
+
ffi.lib.LLVMPY_module_AddSimplifyCFGPass(self)
|
| 135 |
+
else:
|
| 136 |
+
ffi.lib.LLVMPY_function_AddSimplifyCFGPass(self)
|
| 137 |
+
|
| 138 |
+
def add_loop_unroll_pass(self):
|
| 139 |
+
if isinstance(self, ModulePassManager):
|
| 140 |
+
ffi.lib.LLVMPY_module_AddLoopUnrollPass(self)
|
| 141 |
+
else:
|
| 142 |
+
ffi.lib.LLVMPY_function_AddLoopUnrollPass(self)
|
| 143 |
+
|
| 144 |
+
def add_instruction_combine_pass(self):
|
| 145 |
+
if isinstance(self, ModulePassManager):
|
| 146 |
+
ffi.lib.LLVMPY_module_AddInstCombinePass(self)
|
| 147 |
+
else:
|
| 148 |
+
ffi.lib.LLVMPY_function_AddInstCombinePass(self)
|
| 149 |
+
|
| 150 |
+
def add_jump_threading_pass(self, threshold=-1):
|
| 151 |
+
if isinstance(self, ModulePassManager):
|
| 152 |
+
ffi.lib.LLVMPY_AddJumpThreadingPass_module(self, threshold)
|
| 153 |
+
else:
|
| 154 |
+
ffi.lib.LLVMPY_AddJumpThreadingPass_function(self, threshold)
|
| 155 |
+
|
| 156 |
+
def add_cfg_printer_pass(self):
|
| 157 |
+
if isinstance(self, ModulePassManager):
|
| 158 |
+
ffi.lib.LLVMPY_module_AddCFGPrinterPass(self)
|
| 159 |
+
else:
|
| 160 |
+
ffi.lib.LLVMPY_function_AddCFGPrinterPass(self)
|
| 161 |
+
|
| 162 |
+
def add_cfg_only_printer_pass(self):
|
| 163 |
+
if isinstance(self, ModulePassManager):
|
| 164 |
+
ffi.lib.LLVMPY_module_AddCFGOnlyPrinterPass(self)
|
| 165 |
+
else:
|
| 166 |
+
ffi.lib.LLVMPY_function_AddCFGOnlyPrinterPass(self)
|
| 167 |
+
|
| 168 |
+
def add_dom_printer_pass(self):
|
| 169 |
+
if isinstance(self, ModulePassManager):
|
| 170 |
+
ffi.lib.LLVMPY_module_AddDomPrinter(self)
|
| 171 |
+
else:
|
| 172 |
+
ffi.lib.LLVMPY_function_AddDomPrinter(self)
|
| 173 |
+
|
| 174 |
+
def add_dom_only_printer_pass(self):
|
| 175 |
+
if isinstance(self, ModulePassManager):
|
| 176 |
+
ffi.lib.LLVMPY_module_AddDomOnlyPrinter(self)
|
| 177 |
+
else:
|
| 178 |
+
ffi.lib.LLVMPY_function_AddDomOnlyPrinter(self)
|
| 179 |
+
|
| 180 |
+
def add_post_dom_printer_pass(self):
|
| 181 |
+
if isinstance(self, ModulePassManager):
|
| 182 |
+
ffi.lib.LLVMPY_module_AddPostDomPrinter(self)
|
| 183 |
+
else:
|
| 184 |
+
ffi.lib.LLVMPY_function_AddPostDomPrinter(self)
|
| 185 |
+
|
| 186 |
+
def add_post_dom_only_printer_pass(self):
|
| 187 |
+
if isinstance(self, ModulePassManager):
|
| 188 |
+
ffi.lib.LLVMPY_module_AddPostDomOnlyPrinter(self)
|
| 189 |
+
else:
|
| 190 |
+
ffi.lib.LLVMPY_function_AddPostDomOnlyPrinter(self)
|
| 191 |
+
|
| 192 |
+
def add_dom_viewer_pass(self):
|
| 193 |
+
if isinstance(self, ModulePassManager):
|
| 194 |
+
ffi.lib.LLVMPY_module_AddDomViewer(self)
|
| 195 |
+
else:
|
| 196 |
+
ffi.lib.LLVMPY_function_AddDomViewer(self)
|
| 197 |
+
|
| 198 |
+
def add_dom_only_viewer_pass(self):
|
| 199 |
+
if isinstance(self, ModulePassManager):
|
| 200 |
+
ffi.lib.LLVMPY_module_AddDomOnlyViewer(self)
|
| 201 |
+
else:
|
| 202 |
+
ffi.lib.LLVMPY_function_AddDomOnlyViewer(self)
|
| 203 |
+
|
| 204 |
+
def add_post_dom_viewer_pass(self):
|
| 205 |
+
if isinstance(self, ModulePassManager):
|
| 206 |
+
ffi.lib.LLVMPY_module_AddPostDomViewer(self)
|
| 207 |
+
else:
|
| 208 |
+
ffi.lib.LLVMPY_function_AddPostDomViewer(self)
|
| 209 |
+
|
| 210 |
+
def add_post_dom_only_viewer_pass(self):
|
| 211 |
+
if isinstance(self, ModulePassManager):
|
| 212 |
+
ffi.lib.LLVMPY_module_AddPostDomOnlyViewer(self)
|
| 213 |
+
else:
|
| 214 |
+
ffi.lib.LLVMPY_function_AddPostDomOnlyViewer(self)
|
| 215 |
+
|
| 216 |
+
def add_lint_pass(self):
|
| 217 |
+
if isinstance(self, ModulePassManager):
|
| 218 |
+
ffi.lib.LLVMPY_module_AddLintPass(self)
|
| 219 |
+
else:
|
| 220 |
+
ffi.lib.LLVMPY_function_AddLintPass(self)
|
| 221 |
+
|
| 222 |
+
def add_aggressive_dce_pass(self):
|
| 223 |
+
if isinstance(self, ModulePassManager):
|
| 224 |
+
ffi.lib.LLVMPY_module_AddADCEPass(self)
|
| 225 |
+
else:
|
| 226 |
+
ffi.lib.LLVMPY_function_AddADCEPass(self)
|
| 227 |
+
|
| 228 |
+
def add_break_critical_edges_pass(self):
|
| 229 |
+
if isinstance(self, ModulePassManager):
|
| 230 |
+
ffi.lib.LLVMPY_module_AddBreakCriticalEdgesPass(self)
|
| 231 |
+
else:
|
| 232 |
+
ffi.lib.LLVMPY_function_AddBreakCriticalEdgesPass(self)
|
| 233 |
+
|
| 234 |
+
def add_dead_store_elimination_pass(self):
|
| 235 |
+
if isinstance(self, ModulePassManager):
|
| 236 |
+
ffi.lib.LLVMPY_module_AddDSEPass(self)
|
| 237 |
+
else:
|
| 238 |
+
ffi.lib.LLVMPY_function_AddDSEPass(self)
|
| 239 |
+
|
| 240 |
+
def add_dead_code_elimination_pass(self):
|
| 241 |
+
if isinstance(self, ModulePassManager):
|
| 242 |
+
ffi.lib.LLVMPY_module_AddDCEPass(self)
|
| 243 |
+
else:
|
| 244 |
+
ffi.lib.LLVMPY_function_AddDCEPass(self)
|
| 245 |
+
|
| 246 |
+
def add_aggressive_instcombine_pass(self):
|
| 247 |
+
if isinstance(self, ModulePassManager):
|
| 248 |
+
ffi.lib.LLVMPY_module_AddAggressiveInstCombinePass(self)
|
| 249 |
+
else:
|
| 250 |
+
ffi.lib.LLVMPY_function_AddAggressiveInstCombinePass(self)
|
| 251 |
+
|
| 252 |
+
def add_lcssa_pass(self):
|
| 253 |
+
if isinstance(self, ModulePassManager):
|
| 254 |
+
ffi.lib.LLVMPY_module_AddLCSSAPass(self)
|
| 255 |
+
else:
|
| 256 |
+
ffi.lib.LLVMPY_function_AddLCSSAPass(self)
|
| 257 |
+
|
| 258 |
+
def add_new_gvn_pass(self):
|
| 259 |
+
if isinstance(self, ModulePassManager):
|
| 260 |
+
ffi.lib.LLVMPY_module_AddNewGVNPass(self)
|
| 261 |
+
else:
|
| 262 |
+
ffi.lib.LLVMPY_function_AddNewGVNPass(self)
|
| 263 |
+
|
| 264 |
+
def add_loop_simplify_pass(self):
|
| 265 |
+
if isinstance(self, ModulePassManager):
|
| 266 |
+
ffi.lib.LLVMPY_module_AddLoopSimplifyPass(self)
|
| 267 |
+
else:
|
| 268 |
+
ffi.lib.LLVMPY_function_AddLoopSimplifyPass(self)
|
| 269 |
+
|
| 270 |
+
def add_loop_unroll_and_jam_pass(self):
|
| 271 |
+
if isinstance(self, ModulePassManager):
|
| 272 |
+
ffi.lib.LLVMPY_module_AddLoopUnrollAndJamPass(self)
|
| 273 |
+
else:
|
| 274 |
+
ffi.lib.LLVMPY_function_AddLoopUnrollAndJamPass(self)
|
| 275 |
+
|
| 276 |
+
def add_sccp_pass(self):
|
| 277 |
+
if isinstance(self, ModulePassManager):
|
| 278 |
+
ffi.lib.LLVMPY_module_AddSCCPPass(self)
|
| 279 |
+
else:
|
| 280 |
+
ffi.lib.LLVMPY_function_AddSCCPPass(self)
|
| 281 |
+
|
| 282 |
+
def add_lower_atomic_pass(self):
|
| 283 |
+
if isinstance(self, ModulePassManager):
|
| 284 |
+
ffi.lib.LLVMPY_module_AddLowerAtomicPass(self)
|
| 285 |
+
else:
|
| 286 |
+
ffi.lib.LLVMPY_function_AddLowerAtomicPass(self)
|
| 287 |
+
|
| 288 |
+
def add_lower_invoke_pass(self):
|
| 289 |
+
if isinstance(self, ModulePassManager):
|
| 290 |
+
ffi.lib.LLVMPY_module_AddLowerInvokePass(self)
|
| 291 |
+
else:
|
| 292 |
+
ffi.lib.LLVMPY_function_AddLowerInvokePass(self)
|
| 293 |
+
|
| 294 |
+
def add_lower_switch_pass(self):
|
| 295 |
+
if isinstance(self, ModulePassManager):
|
| 296 |
+
ffi.lib.LLVMPY_module_AddLowerSwitchPass(self)
|
| 297 |
+
else:
|
| 298 |
+
ffi.lib.LLVMPY_function_AddLowerSwitchPass(self)
|
| 299 |
+
|
| 300 |
+
def add_mem_copy_opt_pass(self):
|
| 301 |
+
if isinstance(self, ModulePassManager):
|
| 302 |
+
ffi.lib.LLVMPY_module_AddMemCpyOptPass(self)
|
| 303 |
+
else:
|
| 304 |
+
ffi.lib.LLVMPY_function_AddMemCpyOptPass(self)
|
| 305 |
+
|
| 306 |
+
def add_unify_function_exit_nodes_pass(self):
|
| 307 |
+
if isinstance(self, ModulePassManager):
|
| 308 |
+
ffi.lib.LLVMPY_module_AddUnifyFunctionExitNodesPass(self)
|
| 309 |
+
else:
|
| 310 |
+
ffi.lib.LLVMPY_function_AddUnifyFunctionExitNodesPass(self)
|
| 311 |
+
|
| 312 |
+
def add_reassociate_pass(self):
|
| 313 |
+
if isinstance(self, ModulePassManager):
|
| 314 |
+
ffi.lib.LLVMPY_module_AddReassociatePass(self)
|
| 315 |
+
else:
|
| 316 |
+
ffi.lib.LLVMPY_function_AddReassociatePass(self)
|
| 317 |
+
|
| 318 |
+
def add_register_to_memory_pass(self):
|
| 319 |
+
if isinstance(self, ModulePassManager):
|
| 320 |
+
ffi.lib.LLVMPY_module_AddRegToMemPass(self)
|
| 321 |
+
else:
|
| 322 |
+
ffi.lib.LLVMPY_function_AddRegToMemPass(self)
|
| 323 |
+
|
| 324 |
+
def add_sroa_pass(self):
|
| 325 |
+
if isinstance(self, ModulePassManager):
|
| 326 |
+
ffi.lib.LLVMPY_module_AddSROAPass(self)
|
| 327 |
+
else:
|
| 328 |
+
ffi.lib.LLVMPY_function_AddSROAPass(self)
|
| 329 |
+
|
| 330 |
+
def add_sinking_pass(self):
|
| 331 |
+
if isinstance(self, ModulePassManager):
|
| 332 |
+
ffi.lib.LLVMPY_module_AddSinkingPass(self)
|
| 333 |
+
else:
|
| 334 |
+
ffi.lib.LLVMPY_function_AddSinkingPass(self)
|
| 335 |
+
|
| 336 |
+
def add_tail_call_elimination_pass(self):
|
| 337 |
+
if isinstance(self, ModulePassManager):
|
| 338 |
+
ffi.lib.LLVMPY_module_AddTailCallElimPass(self)
|
| 339 |
+
else:
|
| 340 |
+
ffi.lib.LLVMPY_function_AddTailCallElimPass(self)
|
| 341 |
+
|
| 342 |
+
def add_instruction_namer_pass(self):
|
| 343 |
+
if isinstance(self, ModulePassManager):
|
| 344 |
+
ffi.lib.LLVMPY_module_AddInstructionNamerPass(self)
|
| 345 |
+
else:
|
| 346 |
+
ffi.lib.LLVMPY_function_AddInstructionNamerPass(self)
|
| 347 |
+
|
| 348 |
+
def add_loop_deletion_pass(self):
|
| 349 |
+
if isinstance(self, ModulePassManager):
|
| 350 |
+
ffi.lib.LLVMPY_module_AddLoopDeletionPass(self)
|
| 351 |
+
else:
|
| 352 |
+
ffi.lib.LLVMPY_function_AddLoopDeletionPass(self)
|
| 353 |
+
|
| 354 |
+
def add_loop_strength_reduce_pass(self):
|
| 355 |
+
if isinstance(self, ModulePassManager):
|
| 356 |
+
ffi.lib.LLVMPY_module_AddLoopStrengthReducePass(self)
|
| 357 |
+
else:
|
| 358 |
+
ffi.lib.LLVMPY_function_AddLoopStrengthReducePass(self)
|
| 359 |
+
|
| 360 |
+
def add_loop_rotate_pass(self):
|
| 361 |
+
if isinstance(self, ModulePassManager):
|
| 362 |
+
ffi.lib.LLVMPY_module_AddLoopRotatePass(self)
|
| 363 |
+
else:
|
| 364 |
+
ffi.lib.LLVMPY_function_AddLoopRotatePass(self)
|
| 365 |
+
|
| 366 |
+
def _dispose(self):
|
| 367 |
+
if isinstance(self, ModulePassManager):
|
| 368 |
+
ffi.lib.LLVMPY_DisposeNewModulePassManger(self)
|
| 369 |
+
else:
|
| 370 |
+
ffi.lib.LLVMPY_DisposeNewFunctionPassManger(self)
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
class ModulePassManager(ffi.ObjectRef, NewPassManager):
|
| 374 |
+
|
| 375 |
+
def __init__(self, ptr=None):
|
| 376 |
+
if ptr is None:
|
| 377 |
+
ptr = ffi.lib.LLVMPY_CreateNewModulePassManager()
|
| 378 |
+
super().__init__(ptr)
|
| 379 |
+
|
| 380 |
+
def add_verifier(self):
|
| 381 |
+
ffi.lib.LLVMPY_module_AddVerifierPass(self)
|
| 382 |
+
|
| 383 |
+
def add_constant_merge_pass(self):
|
| 384 |
+
ffi.lib.LLVMPY_module_AddConstantMergePass(self)
|
| 385 |
+
|
| 386 |
+
def add_dead_arg_elimination_pass(self):
|
| 387 |
+
ffi.lib.LLVMPY_module_AddDeadArgumentEliminationPass(self)
|
| 388 |
+
|
| 389 |
+
def add_dot_call_graph_printer_pass(self):
|
| 390 |
+
ffi.lib.LLVMPY_module_AddCallGraphDOTPrinterPass(self)
|
| 391 |
+
|
| 392 |
+
# TODO: There are a lot more printer passes in llvm that can be exposed
|
| 393 |
+
# FIXME: Find a way to write the output to a buffer instead of stdout
|
| 394 |
+
def add_module_debug_info_pass(self):
|
| 395 |
+
ffi.lib.LLVMPY_module_AddModuleDebugInfoPrinterPass(self)
|
| 396 |
+
|
| 397 |
+
def add_always_inliner_pass(self):
|
| 398 |
+
ffi.lib.LLVMPY_module_AddAlwaysInlinerPass(self)
|
| 399 |
+
|
| 400 |
+
def add_rpo_function_attrs_pass(self):
|
| 401 |
+
ffi.lib.LLVMPY_module_AddReversePostOrderFunctionAttrsPass(self)
|
| 402 |
+
|
| 403 |
+
def add_global_dead_code_eliminate_pass(self):
|
| 404 |
+
ffi.lib.LLVMPY_module_AddGlobalDCEPass(self)
|
| 405 |
+
|
| 406 |
+
def add_global_opt_pass(self):
|
| 407 |
+
ffi.lib.LLVMPY_module_AddGlobalOptPass(self)
|
| 408 |
+
|
| 409 |
+
def add_ipsccp_pass(self):
|
| 410 |
+
ffi.lib.LLVMPY_module_AddIPSCCPPass(self)
|
| 411 |
+
|
| 412 |
+
def add_internalize_pass(self):
|
| 413 |
+
ffi.lib.LLVMPY_module_AddInternalizePass(self)
|
| 414 |
+
|
| 415 |
+
def add_loop_extract_pass(self):
|
| 416 |
+
ffi.lib.LLVMPY_module_AddLoopExtractorPass(self)
|
| 417 |
+
|
| 418 |
+
def add_merge_functions_pass(self):
|
| 419 |
+
ffi.lib.LLVMPY_module_AddMergeFunctionsPass(self)
|
| 420 |
+
|
| 421 |
+
def add_partial_inliner_pass(self):
|
| 422 |
+
ffi.lib.LLVMPY_module_AddPartialInlinerPass(self)
|
| 423 |
+
|
| 424 |
+
def add_strip_symbols_pass(self):
|
| 425 |
+
ffi.lib.LLVMPY_module_AddStripSymbolsPass(self)
|
| 426 |
+
|
| 427 |
+
def add_strip_dead_debug_info_pass(self):
|
| 428 |
+
ffi.lib.LLVMPY_module_AddStripDeadDebugInfoPass(self)
|
| 429 |
+
|
| 430 |
+
def add_strip_dead_prototype_pass(self):
|
| 431 |
+
ffi.lib.LLVMPY_module_AddStripDeadPrototypesPass(self)
|
| 432 |
+
|
| 433 |
+
def add_strip_debug_declare_pass(self):
|
| 434 |
+
ffi.lib.LLVMPY_module_AddStripDebugDeclarePass(self)
|
| 435 |
+
|
| 436 |
+
def add_strip_non_debug_symbols_pass(self):
|
| 437 |
+
ffi.lib.LLVMPY_module_AddStripNonDebugSymbolsPass(self)
|
| 438 |
+
|
| 439 |
+
def add_argument_promotion_pass(self):
|
| 440 |
+
ffi.lib.LLVMPY_module_AddArgumentPromotionPass(self)
|
| 441 |
+
|
| 442 |
+
def add_post_order_function_attributes_pass(self):
|
| 443 |
+
ffi.lib.LLVMPY_module_AddPostOrderFunctionAttrsPass(self)
|
| 444 |
+
|
| 445 |
+
# Non-standard LLVM passes
|
| 446 |
+
def add_refprune_pass(self, subpasses_flags=RefPruneSubpasses.ALL,
|
| 447 |
+
subgraph_limit=1000):
|
| 448 |
+
"""Add Numba specific Reference count pruning pass.
|
| 449 |
+
|
| 450 |
+
Parameters
|
| 451 |
+
----------
|
| 452 |
+
subpasses_flags : RefPruneSubpasses
|
| 453 |
+
A bitmask to control the subpasses to be enabled.
|
| 454 |
+
subgraph_limit : int
|
| 455 |
+
Limit the fanout pruners to working on a subgraph no bigger than
|
| 456 |
+
this number of basic-blocks to avoid spending too much time in very
|
| 457 |
+
large graphs. Default is 1000. Subject to change in future
|
| 458 |
+
versions.
|
| 459 |
+
"""
|
| 460 |
+
iflags = RefPruneSubpasses(subpasses_flags)
|
| 461 |
+
ffi.lib.LLVMPY_AddRefPrunePass_module(self, iflags, subgraph_limit)
|
| 462 |
+
|
| 463 |
+
|
| 464 |
+
class FunctionPassManager(ffi.ObjectRef, NewPassManager):
|
| 465 |
+
|
| 466 |
+
def __init__(self, ptr=None):
|
| 467 |
+
if ptr is None:
|
| 468 |
+
ptr = ffi.lib.LLVMPY_CreateNewFunctionPassManager()
|
| 469 |
+
super().__init__(ptr)
|
| 470 |
+
|
| 471 |
+
# Non-standard LLVM passes
|
| 472 |
+
def add_refprune_pass(self, subpasses_flags=RefPruneSubpasses.ALL,
|
| 473 |
+
subgraph_limit=1000):
|
| 474 |
+
"""Add Numba specific Reference count pruning pass.
|
| 475 |
+
|
| 476 |
+
Parameters
|
| 477 |
+
----------
|
| 478 |
+
subpasses_flags : RefPruneSubpasses
|
| 479 |
+
A bitmask to control the subpasses to be enabled.
|
| 480 |
+
subgraph_limit : int
|
| 481 |
+
Limit the fanout pruners to working on a subgraph no bigger than
|
| 482 |
+
this number of basic-blocks to avoid spending too much time in very
|
| 483 |
+
large graphs. Default is 1000. Subject to change in future
|
| 484 |
+
versions.
|
| 485 |
+
"""
|
| 486 |
+
iflags = RefPruneSubpasses(subpasses_flags)
|
| 487 |
+
ffi.lib.LLVMPY_AddRefPrunePass_function(self, iflags, subgraph_limit)
|
| 488 |
+
|
| 489 |
+
|
| 490 |
+
class PipelineTuningOptions(ffi.ObjectRef):
|
| 491 |
+
|
| 492 |
+
def __init__(self, speed_level=2, size_level=0):
|
| 493 |
+
self._speed_level = None
|
| 494 |
+
self._size_level = None
|
| 495 |
+
self.speed_level = speed_level
|
| 496 |
+
self.size_level = size_level
|
| 497 |
+
super().__init__(ffi.lib.LLVMPY_CreatePipelineTuningOptions())
|
| 498 |
+
|
| 499 |
+
@property
|
| 500 |
+
def speed_level(self):
|
| 501 |
+
return self._speed_level
|
| 502 |
+
|
| 503 |
+
@speed_level.setter
|
| 504 |
+
def speed_level(self, value):
|
| 505 |
+
if not 0 <= value <= 3:
|
| 506 |
+
raise ValueError(
|
| 507 |
+
"Optimization level for speed should be 0, 1, 2, or 3")
|
| 508 |
+
self._speed_level = value
|
| 509 |
+
|
| 510 |
+
@property
|
| 511 |
+
def size_level(self):
|
| 512 |
+
return self._size_level
|
| 513 |
+
|
| 514 |
+
@size_level.setter
|
| 515 |
+
def size_level(self, value):
|
| 516 |
+
if not 0 <= value <= 2:
|
| 517 |
+
raise ValueError("Optimization level for size should be 0, 1, or 2")
|
| 518 |
+
if value != 0 and self.speed_level != 2:
|
| 519 |
+
raise ValueError(
|
| 520 |
+
"Optimization for size should be encoded with speed level == 2")
|
| 521 |
+
self._size_level = value
|
| 522 |
+
|
| 523 |
+
@property
|
| 524 |
+
def loop_interleaving(self):
|
| 525 |
+
return ffi.lib.LLVMPY_PTOGetLoopInterleaving(self)
|
| 526 |
+
|
| 527 |
+
@loop_interleaving.setter
|
| 528 |
+
def loop_interleaving(self, value):
|
| 529 |
+
ffi.lib.LLVMPY_PTOSetLoopInterleaving(self, value)
|
| 530 |
+
|
| 531 |
+
@property
|
| 532 |
+
def loop_vectorization(self):
|
| 533 |
+
return ffi.lib.LLVMPY_PTOGetLoopVectorization(self)
|
| 534 |
+
|
| 535 |
+
@loop_vectorization.setter
|
| 536 |
+
def loop_vectorization(self, value):
|
| 537 |
+
ffi.lib.LLVMPY_PTOSetLoopVectorization(self, value)
|
| 538 |
+
|
| 539 |
+
@property
|
| 540 |
+
def slp_vectorization(self):
|
| 541 |
+
return ffi.lib.LLVMPY_PTOGetSLPVectorization(self)
|
| 542 |
+
|
| 543 |
+
@slp_vectorization.setter
|
| 544 |
+
def slp_vectorization(self, value):
|
| 545 |
+
ffi.lib.LLVMPY_PTOSetSLPVectorization(self, value)
|
| 546 |
+
|
| 547 |
+
@property
|
| 548 |
+
def loop_unrolling(self):
|
| 549 |
+
return ffi.lib.LLVMPY_PTOGetLoopUnrolling(self)
|
| 550 |
+
|
| 551 |
+
@loop_unrolling.setter
|
| 552 |
+
def loop_unrolling(self, value):
|
| 553 |
+
ffi.lib.LLVMPY_PTOSetLoopUnrolling(self, value)
|
| 554 |
+
|
| 555 |
+
@property
|
| 556 |
+
def inlining_threshold(self):
|
| 557 |
+
return ffi.lib.LLVMPY_PTOGetInlinerThreshold(self)
|
| 558 |
+
|
| 559 |
+
@inlining_threshold.setter
|
| 560 |
+
def inlining_threshold(self, value):
|
| 561 |
+
ffi.lib.LLVMPY_PTOSetInlinerThreshold(self, value)
|
| 562 |
+
|
| 563 |
+
def _dispose(self):
|
| 564 |
+
ffi.lib.LLVMPY_DisposePipelineTuningOptions(self)
|
| 565 |
+
|
| 566 |
+
|
| 567 |
+
class TimePassesHandler(ffi.ObjectRef):
|
| 568 |
+
def __init__(self):
|
| 569 |
+
super().__init__(ffi.lib.LLVMPY_CreateTimePassesHandler())
|
| 570 |
+
|
| 571 |
+
def _dispose(self):
|
| 572 |
+
ffi.lib.LLVMPY_DisposeTimePassesHandler(self)
|
| 573 |
+
|
| 574 |
+
|
| 575 |
+
class PassBuilder(ffi.ObjectRef):
|
| 576 |
+
|
| 577 |
+
def __init__(self, tm, pto):
|
| 578 |
+
super().__init__(ffi.lib.LLVMPY_CreatePassBuilder(tm, pto))
|
| 579 |
+
self._pto = pto
|
| 580 |
+
self._tm = tm
|
| 581 |
+
self._time_passes_handler = None
|
| 582 |
+
|
| 583 |
+
def getModulePassManager(self):
|
| 584 |
+
return ModulePassManager(
|
| 585 |
+
ffi.lib.LLVMPY_buildPerModuleDefaultPipeline(
|
| 586 |
+
self, self._pto.speed_level, self._pto.size_level)
|
| 587 |
+
)
|
| 588 |
+
|
| 589 |
+
def getFunctionPassManager(self):
|
| 590 |
+
return FunctionPassManager(
|
| 591 |
+
ffi.lib.LLVMPY_buildFunctionSimplificationPipeline(
|
| 592 |
+
self, self._pto.speed_level, self._pto.size_level)
|
| 593 |
+
)
|
| 594 |
+
|
| 595 |
+
def start_pass_timing(self):
|
| 596 |
+
"""Enable the pass timers.
|
| 597 |
+
|
| 598 |
+
Raises
|
| 599 |
+
------
|
| 600 |
+
RuntimeError
|
| 601 |
+
If pass timing is already enabled.
|
| 602 |
+
"""
|
| 603 |
+
if self._time_passes_handler:
|
| 604 |
+
raise RuntimeError("Pass timing can only be done once")
|
| 605 |
+
self._time_passes_handler = TimePassesHandler()
|
| 606 |
+
ffi.lib.LLVMPY_EnableTimePasses(self, self._time_passes_handler)
|
| 607 |
+
|
| 608 |
+
def finish_pass_timing(self):
|
| 609 |
+
"""Returns the pass timings report and disables the LLVM internal
|
| 610 |
+
timers. Pass timers are enabled by ``start_pass_timing()``. If the
|
| 611 |
+
timers are not enabled, this function will return an empty string.
|
| 612 |
+
|
| 613 |
+
Returns
|
| 614 |
+
-------
|
| 615 |
+
res : str
|
| 616 |
+
LLVM generated timing report.
|
| 617 |
+
"""
|
| 618 |
+
|
| 619 |
+
if not self._time_passes_handler:
|
| 620 |
+
raise RuntimeError("Pass timing is not enabled")
|
| 621 |
+
|
| 622 |
+
with ffi.OutputString() as buf:
|
| 623 |
+
ffi.lib.LLVMPY_ReportAndDisableTimePasses(
|
| 624 |
+
self._time_passes_handler, buf)
|
| 625 |
+
return str(buf)
|
| 626 |
+
|
| 627 |
+
def _dispose(self):
|
| 628 |
+
ffi.lib.LLVMPY_DisposePassBuilder(self)
|
| 629 |
+
|
| 630 |
+
|
| 631 |
+
# ============================================================================
|
| 632 |
+
# FFI
|
| 633 |
+
|
| 634 |
+
ffi.lib.LLVMPY_DumpRefPruneStats.argtypes = [POINTER(_c_PruneStats), c_bool]
|
| 635 |
+
|
| 636 |
+
ffi.lib.LLVMPY_SetTimePasses.argtypes = [c_bool]
|
| 637 |
+
|
| 638 |
+
ffi.lib.LLVMPY_ReportAndResetTimings.argtypes = [POINTER(c_char_p)]
|
| 639 |
+
|
| 640 |
+
# ModulePassManager
|
| 641 |
+
|
| 642 |
+
ffi.lib.LLVMPY_CreateNewModulePassManager.restype = ffi.LLVMModulePassManagerRef
|
| 643 |
+
|
| 644 |
+
ffi.lib.LLVMPY_RunNewModulePassManager.argtypes = [
|
| 645 |
+
ffi.LLVMModulePassManagerRef, ffi.LLVMModuleRef,
|
| 646 |
+
ffi.LLVMPassBuilderRef,]
|
| 647 |
+
|
| 648 |
+
ffi.lib.LLVMPY_module_AddVerifierPass.argtypes = [ffi.LLVMModulePassManagerRef,]
|
| 649 |
+
ffi.lib.LLVMPY_module_AddAAEvaluator.argtypes = [ffi.LLVMModulePassManagerRef,]
|
| 650 |
+
ffi.lib.LLVMPY_module_AddSimplifyCFGPass.argtypes = [
|
| 651 |
+
ffi.LLVMModulePassManagerRef,]
|
| 652 |
+
|
| 653 |
+
ffi.lib.LLVMPY_module_AddLoopUnrollPass.argtypes = [
|
| 654 |
+
ffi.LLVMModulePassManagerRef,]
|
| 655 |
+
|
| 656 |
+
ffi.lib.LLVMPY_module_AddLoopRotatePass.argtypes = [
|
| 657 |
+
ffi.LLVMModulePassManagerRef,]
|
| 658 |
+
|
| 659 |
+
ffi.lib.LLVMPY_module_AddInstCombinePass.argtypes = [
|
| 660 |
+
ffi.LLVMModulePassManagerRef,]
|
| 661 |
+
|
| 662 |
+
ffi.lib.LLVMPY_AddJumpThreadingPass_module.argtypes = [
|
| 663 |
+
ffi.LLVMModulePassManagerRef,]
|
| 664 |
+
|
| 665 |
+
ffi.lib.LLVMPY_module_AddCFGPrinterPass.argtypes = [
|
| 666 |
+
ffi.LLVMModulePassManagerRef,]
|
| 667 |
+
|
| 668 |
+
ffi.lib.LLVMPY_module_AddCFGOnlyPrinterPass.argtypes = [
|
| 669 |
+
ffi.LLVMModulePassManagerRef,]
|
| 670 |
+
|
| 671 |
+
ffi.lib.LLVMPY_module_AddDomPrinter.argtypes = [
|
| 672 |
+
ffi.LLVMModulePassManagerRef,]
|
| 673 |
+
|
| 674 |
+
ffi.lib.LLVMPY_module_AddDomOnlyPrinter.argtypes = [
|
| 675 |
+
ffi.LLVMModulePassManagerRef,]
|
| 676 |
+
|
| 677 |
+
ffi.lib.LLVMPY_module_AddPostDomPrinter.argtypes = [
|
| 678 |
+
ffi.LLVMModulePassManagerRef,]
|
| 679 |
+
|
| 680 |
+
ffi.lib.LLVMPY_module_AddPostDomOnlyPrinter.argtypes = [
|
| 681 |
+
ffi.LLVMModulePassManagerRef,]
|
| 682 |
+
|
| 683 |
+
ffi.lib.LLVMPY_module_AddDomViewer.argtypes = [
|
| 684 |
+
ffi.LLVMModulePassManagerRef,]
|
| 685 |
+
|
| 686 |
+
ffi.lib.LLVMPY_module_AddDomOnlyViewer.argtypes = [
|
| 687 |
+
ffi.LLVMModulePassManagerRef,]
|
| 688 |
+
|
| 689 |
+
ffi.lib.LLVMPY_module_AddPostDomViewer.argtypes = [
|
| 690 |
+
ffi.LLVMModulePassManagerRef,]
|
| 691 |
+
|
| 692 |
+
ffi.lib.LLVMPY_module_AddPostDomOnlyViewer.argtypes = [
|
| 693 |
+
ffi.LLVMModulePassManagerRef,]
|
| 694 |
+
|
| 695 |
+
ffi.lib.LLVMPY_module_AddLintPass.argtypes = [
|
| 696 |
+
ffi.LLVMModulePassManagerRef,]
|
| 697 |
+
|
| 698 |
+
ffi.lib.LLVMPY_module_AddADCEPass.argtypes = [
|
| 699 |
+
ffi.LLVMModulePassManagerRef,]
|
| 700 |
+
|
| 701 |
+
ffi.lib.LLVMPY_module_AddBreakCriticalEdgesPass.argtypes = [
|
| 702 |
+
ffi.LLVMModulePassManagerRef,]
|
| 703 |
+
|
| 704 |
+
ffi.lib.LLVMPY_module_AddDSEPass.argtypes = [
|
| 705 |
+
ffi.LLVMModulePassManagerRef,]
|
| 706 |
+
|
| 707 |
+
ffi.lib.LLVMPY_module_AddDCEPass.argtypes = [
|
| 708 |
+
ffi.LLVMModulePassManagerRef,]
|
| 709 |
+
|
| 710 |
+
ffi.lib.LLVMPY_module_AddAggressiveInstCombinePass.argtypes = [
|
| 711 |
+
ffi.LLVMModulePassManagerRef,]
|
| 712 |
+
|
| 713 |
+
ffi.lib.LLVMPY_module_AddLCSSAPass.argtypes = [
|
| 714 |
+
ffi.LLVMModulePassManagerRef,]
|
| 715 |
+
|
| 716 |
+
ffi.lib.LLVMPY_module_AddNewGVNPass.argtypes = [
|
| 717 |
+
ffi.LLVMModulePassManagerRef,]
|
| 718 |
+
|
| 719 |
+
ffi.lib.LLVMPY_module_AddLoopSimplifyPass.argtypes = [
|
| 720 |
+
ffi.LLVMModulePassManagerRef,]
|
| 721 |
+
|
| 722 |
+
ffi.lib.LLVMPY_module_AddLoopUnrollAndJamPass.argtypes = [
|
| 723 |
+
ffi.LLVMModulePassManagerRef,]
|
| 724 |
+
|
| 725 |
+
ffi.lib.LLVMPY_module_AddSCCPPass.argtypes = [
|
| 726 |
+
ffi.LLVMModulePassManagerRef,]
|
| 727 |
+
|
| 728 |
+
ffi.lib.LLVMPY_module_AddLowerAtomicPass.argtypes = [
|
| 729 |
+
ffi.LLVMModulePassManagerRef,]
|
| 730 |
+
|
| 731 |
+
ffi.lib.LLVMPY_module_AddLowerInvokePass.argtypes = [
|
| 732 |
+
ffi.LLVMModulePassManagerRef,]
|
| 733 |
+
|
| 734 |
+
ffi.lib.LLVMPY_module_AddLowerSwitchPass.argtypes = [
|
| 735 |
+
ffi.LLVMModulePassManagerRef,]
|
| 736 |
+
|
| 737 |
+
ffi.lib.LLVMPY_module_AddMemCpyOptPass.argtypes = [
|
| 738 |
+
ffi.LLVMModulePassManagerRef,]
|
| 739 |
+
|
| 740 |
+
ffi.lib.LLVMPY_module_AddUnifyFunctionExitNodesPass.argtypes = [
|
| 741 |
+
ffi.LLVMModulePassManagerRef,]
|
| 742 |
+
|
| 743 |
+
ffi.lib.LLVMPY_module_AddReassociatePass.argtypes = [
|
| 744 |
+
ffi.LLVMModulePassManagerRef,]
|
| 745 |
+
|
| 746 |
+
ffi.lib.LLVMPY_module_AddRegToMemPass.argtypes = [
|
| 747 |
+
ffi.LLVMModulePassManagerRef,]
|
| 748 |
+
|
| 749 |
+
ffi.lib.LLVMPY_module_AddSROAPass.argtypes = [
|
| 750 |
+
ffi.LLVMModulePassManagerRef,]
|
| 751 |
+
|
| 752 |
+
ffi.lib.LLVMPY_module_AddSinkingPass.argtypes = [
|
| 753 |
+
ffi.LLVMModulePassManagerRef,]
|
| 754 |
+
|
| 755 |
+
ffi.lib.LLVMPY_module_AddTailCallElimPass.argtypes = [
|
| 756 |
+
ffi.LLVMModulePassManagerRef,]
|
| 757 |
+
|
| 758 |
+
ffi.lib.LLVMPY_module_AddInstructionNamerPass.argtypes = [
|
| 759 |
+
ffi.LLVMModulePassManagerRef,]
|
| 760 |
+
|
| 761 |
+
ffi.lib.LLVMPY_module_AddLoopDeletionPass.argtypes = [
|
| 762 |
+
ffi.LLVMModulePassManagerRef,]
|
| 763 |
+
|
| 764 |
+
ffi.lib.LLVMPY_module_AddLoopStrengthReducePass.argtypes = [
|
| 765 |
+
ffi.LLVMModulePassManagerRef,]
|
| 766 |
+
|
| 767 |
+
ffi.lib.LLVMPY_module_AddConstantMergePass.argtypes = [
|
| 768 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 769 |
+
|
| 770 |
+
ffi.lib.LLVMPY_module_AddDeadArgumentEliminationPass.argtypes = [
|
| 771 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 772 |
+
|
| 773 |
+
ffi.lib.LLVMPY_module_AddCallGraphDOTPrinterPass.argtypes = [
|
| 774 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 775 |
+
|
| 776 |
+
ffi.lib.LLVMPY_module_AddModuleDebugInfoPrinterPass.argtypes = [
|
| 777 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 778 |
+
|
| 779 |
+
ffi.lib.LLVMPY_module_AddAlwaysInlinerPass.argtypes = [
|
| 780 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 781 |
+
|
| 782 |
+
ffi.lib.LLVMPY_module_AddReversePostOrderFunctionAttrsPass.argtypes = [
|
| 783 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 784 |
+
|
| 785 |
+
ffi.lib.LLVMPY_module_AddGlobalDCEPass.argtypes = [
|
| 786 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 787 |
+
|
| 788 |
+
ffi.lib.LLVMPY_module_AddGlobalOptPass.argtypes = [
|
| 789 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 790 |
+
|
| 791 |
+
ffi.lib.LLVMPY_module_AddIPSCCPPass.argtypes = [
|
| 792 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 793 |
+
|
| 794 |
+
ffi.lib.LLVMPY_module_AddInternalizePass.argtypes = [
|
| 795 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 796 |
+
|
| 797 |
+
ffi.lib.LLVMPY_module_AddLoopExtractorPass.argtypes = [
|
| 798 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 799 |
+
|
| 800 |
+
ffi.lib.LLVMPY_module_AddMergeFunctionsPass.argtypes = [
|
| 801 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 802 |
+
|
| 803 |
+
ffi.lib.LLVMPY_module_AddPartialInlinerPass.argtypes = [
|
| 804 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 805 |
+
|
| 806 |
+
ffi.lib.LLVMPY_module_AddStripSymbolsPass.argtypes = [
|
| 807 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 808 |
+
|
| 809 |
+
ffi.lib.LLVMPY_module_AddStripDeadDebugInfoPass.argtypes = [
|
| 810 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 811 |
+
|
| 812 |
+
ffi.lib.LLVMPY_module_AddStripDeadPrototypesPass.argtypes = [
|
| 813 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 814 |
+
|
| 815 |
+
ffi.lib.LLVMPY_module_AddStripDebugDeclarePass.argtypes = [
|
| 816 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 817 |
+
|
| 818 |
+
ffi.lib.LLVMPY_module_AddStripNonDebugSymbolsPass.argtypes = [
|
| 819 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 820 |
+
|
| 821 |
+
ffi.lib.LLVMPY_module_AddArgumentPromotionPass.argtypes = [
|
| 822 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 823 |
+
|
| 824 |
+
ffi.lib.LLVMPY_module_AddPostOrderFunctionAttrsPass.argtypes = [
|
| 825 |
+
ffi.LLVMModulePassManagerRef, ]
|
| 826 |
+
|
| 827 |
+
ffi.lib.LLVMPY_DisposeNewModulePassManger.argtypes = [
|
| 828 |
+
ffi.LLVMModulePassManagerRef,]
|
| 829 |
+
|
| 830 |
+
ffi.lib.LLVMPY_AddRefPrunePass_module.argtypes = [
|
| 831 |
+
ffi.LLVMModulePassManagerRef, c_int, c_size_t,
|
| 832 |
+
]
|
| 833 |
+
|
| 834 |
+
# FunctionPassManager
|
| 835 |
+
|
| 836 |
+
ffi.lib.LLVMPY_CreateNewFunctionPassManager.restype = \
|
| 837 |
+
ffi.LLVMFunctionPassManagerRef
|
| 838 |
+
|
| 839 |
+
ffi.lib.LLVMPY_RunNewFunctionPassManager.argtypes = [
|
| 840 |
+
ffi.LLVMFunctionPassManagerRef, ffi.LLVMValueRef,
|
| 841 |
+
ffi.LLVMPassBuilderRef,]
|
| 842 |
+
|
| 843 |
+
ffi.lib.LLVMPY_function_AddAAEvaluator.argtypes = [
|
| 844 |
+
ffi.LLVMFunctionPassManagerRef,]
|
| 845 |
+
|
| 846 |
+
ffi.lib.LLVMPY_function_AddSimplifyCFGPass.argtypes = [
|
| 847 |
+
ffi.LLVMFunctionPassManagerRef,]
|
| 848 |
+
|
| 849 |
+
ffi.lib.LLVMPY_function_AddLoopUnrollPass.argtypes = [
|
| 850 |
+
ffi.LLVMFunctionPassManagerRef,]
|
| 851 |
+
|
| 852 |
+
ffi.lib.LLVMPY_function_AddInstCombinePass.argtypes = [
|
| 853 |
+
ffi.LLVMFunctionPassManagerRef,]
|
| 854 |
+
|
| 855 |
+
ffi.lib.LLVMPY_AddJumpThreadingPass_function.argtypes = [
|
| 856 |
+
ffi.LLVMFunctionPassManagerRef, c_int,]
|
| 857 |
+
|
| 858 |
+
ffi.lib.LLVMPY_function_AddCFGPrinterPass.argtypes = [
|
| 859 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 860 |
+
|
| 861 |
+
ffi.lib.LLVMPY_function_AddCFGOnlyPrinterPass.argtypes = [
|
| 862 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 863 |
+
|
| 864 |
+
ffi.lib.LLVMPY_function_AddDomPrinter.argtypes = [
|
| 865 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 866 |
+
|
| 867 |
+
ffi.lib.LLVMPY_function_AddDomOnlyPrinter.argtypes = [
|
| 868 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 869 |
+
|
| 870 |
+
ffi.lib.LLVMPY_function_AddPostDomPrinter.argtypes = [
|
| 871 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 872 |
+
|
| 873 |
+
ffi.lib.LLVMPY_function_AddPostDomOnlyPrinter.argtypes = [
|
| 874 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 875 |
+
|
| 876 |
+
ffi.lib.LLVMPY_function_AddDomViewer.argtypes = [
|
| 877 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 878 |
+
|
| 879 |
+
ffi.lib.LLVMPY_function_AddDomOnlyViewer.argtypes = [
|
| 880 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 881 |
+
|
| 882 |
+
ffi.lib.LLVMPY_function_AddPostDomViewer.argtypes = [
|
| 883 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 884 |
+
|
| 885 |
+
ffi.lib.LLVMPY_function_AddPostDomOnlyViewer.argtypes = [
|
| 886 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 887 |
+
|
| 888 |
+
ffi.lib.LLVMPY_function_AddLintPass.argtypes = [
|
| 889 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 890 |
+
|
| 891 |
+
ffi.lib.LLVMPY_function_AddADCEPass.argtypes = [
|
| 892 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 893 |
+
|
| 894 |
+
ffi.lib.LLVMPY_function_AddBreakCriticalEdgesPass.argtypes = [
|
| 895 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 896 |
+
|
| 897 |
+
ffi.lib.LLVMPY_function_AddDSEPass.argtypes = [
|
| 898 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 899 |
+
|
| 900 |
+
ffi.lib.LLVMPY_function_AddDCEPass.argtypes = [
|
| 901 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 902 |
+
|
| 903 |
+
ffi.lib.LLVMPY_function_AddAggressiveInstCombinePass.argtypes = [
|
| 904 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 905 |
+
|
| 906 |
+
ffi.lib.LLVMPY_function_AddLCSSAPass.argtypes = [
|
| 907 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 908 |
+
|
| 909 |
+
ffi.lib.LLVMPY_function_AddNewGVNPass.argtypes = [
|
| 910 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 911 |
+
|
| 912 |
+
ffi.lib.LLVMPY_function_AddLoopSimplifyPass.argtypes = [
|
| 913 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 914 |
+
|
| 915 |
+
ffi.lib.LLVMPY_function_AddLoopUnrollAndJamPass.argtypes = [
|
| 916 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 917 |
+
|
| 918 |
+
ffi.lib.LLVMPY_function_AddSCCPPass.argtypes = [
|
| 919 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 920 |
+
|
| 921 |
+
ffi.lib.LLVMPY_function_AddLowerAtomicPass.argtypes = [
|
| 922 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 923 |
+
|
| 924 |
+
ffi.lib.LLVMPY_function_AddLowerInvokePass.argtypes = [
|
| 925 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 926 |
+
|
| 927 |
+
ffi.lib.LLVMPY_function_AddLowerSwitchPass.argtypes = [
|
| 928 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 929 |
+
|
| 930 |
+
ffi.lib.LLVMPY_function_AddMemCpyOptPass.argtypes = [
|
| 931 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 932 |
+
|
| 933 |
+
ffi.lib.LLVMPY_function_AddUnifyFunctionExitNodesPass.argtypes = [
|
| 934 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 935 |
+
|
| 936 |
+
ffi.lib.LLVMPY_function_AddReassociatePass.argtypes = [
|
| 937 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 938 |
+
|
| 939 |
+
ffi.lib.LLVMPY_function_AddRegToMemPass.argtypes = [
|
| 940 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 941 |
+
|
| 942 |
+
ffi.lib.LLVMPY_function_AddSROAPass.argtypes = [
|
| 943 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 944 |
+
|
| 945 |
+
ffi.lib.LLVMPY_function_AddSinkingPass.argtypes = [
|
| 946 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 947 |
+
|
| 948 |
+
ffi.lib.LLVMPY_function_AddTailCallElimPass.argtypes = [
|
| 949 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 950 |
+
|
| 951 |
+
ffi.lib.LLVMPY_function_AddInstructionNamerPass.argtypes = [
|
| 952 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 953 |
+
|
| 954 |
+
ffi.lib.LLVMPY_function_AddLoopRotatePass.argtypes = [
|
| 955 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 956 |
+
|
| 957 |
+
ffi.lib.LLVMPY_function_AddLoopDeletionPass.argtypes = [
|
| 958 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 959 |
+
|
| 960 |
+
ffi.lib.LLVMPY_function_AddLoopStrengthReducePass.argtypes = [
|
| 961 |
+
ffi.LLVMFunctionPassManagerRef, ]
|
| 962 |
+
|
| 963 |
+
ffi.lib.LLVMPY_DisposeNewFunctionPassManger.argtypes = [
|
| 964 |
+
ffi.LLVMFunctionPassManagerRef,]
|
| 965 |
+
|
| 966 |
+
ffi.lib.LLVMPY_AddRefPrunePass_function.argtypes = [
|
| 967 |
+
ffi.LLVMFunctionPassManagerRef, c_int, c_size_t,
|
| 968 |
+
]
|
| 969 |
+
|
| 970 |
+
# PipelineTuningOptions
|
| 971 |
+
|
| 972 |
+
ffi.lib.LLVMPY_CreatePipelineTuningOptions.restype = \
|
| 973 |
+
ffi.LLVMPipelineTuningOptionsRef
|
| 974 |
+
|
| 975 |
+
ffi.lib.LLVMPY_PTOGetLoopInterleaving.restype = c_bool
|
| 976 |
+
ffi.lib.LLVMPY_PTOGetLoopInterleaving.argtypes = [
|
| 977 |
+
ffi.LLVMPipelineTuningOptionsRef,]
|
| 978 |
+
|
| 979 |
+
ffi.lib.LLVMPY_PTOSetLoopInterleaving.argtypes = [
|
| 980 |
+
ffi.LLVMPipelineTuningOptionsRef, c_bool]
|
| 981 |
+
|
| 982 |
+
ffi.lib.LLVMPY_PTOGetLoopVectorization.restype = c_bool
|
| 983 |
+
ffi.lib.LLVMPY_PTOGetLoopVectorization.argtypes = [
|
| 984 |
+
ffi.LLVMPipelineTuningOptionsRef,]
|
| 985 |
+
|
| 986 |
+
ffi.lib.LLVMPY_PTOSetLoopVectorization.argtypes = [
|
| 987 |
+
ffi.LLVMPipelineTuningOptionsRef, c_bool]
|
| 988 |
+
|
| 989 |
+
ffi.lib.LLVMPY_PTOGetSLPVectorization.restype = c_bool
|
| 990 |
+
ffi.lib.LLVMPY_PTOGetSLPVectorization.argtypes = [
|
| 991 |
+
ffi.LLVMPipelineTuningOptionsRef,]
|
| 992 |
+
|
| 993 |
+
ffi.lib.LLVMPY_PTOSetSLPVectorization.argtypes = [
|
| 994 |
+
ffi.LLVMPipelineTuningOptionsRef, c_bool]
|
| 995 |
+
|
| 996 |
+
ffi.lib.LLVMPY_PTOGetLoopUnrolling.restype = c_bool
|
| 997 |
+
ffi.lib.LLVMPY_PTOGetLoopUnrolling.argtypes = [
|
| 998 |
+
ffi.LLVMPipelineTuningOptionsRef,]
|
| 999 |
+
|
| 1000 |
+
ffi.lib.LLVMPY_PTOSetLoopUnrolling.argtypes = [
|
| 1001 |
+
ffi.LLVMPipelineTuningOptionsRef, c_bool]
|
| 1002 |
+
|
| 1003 |
+
ffi.lib.LLVMPY_PTOGetInlinerThreshold.restype = c_int
|
| 1004 |
+
|
| 1005 |
+
ffi.lib.LLVMPY_PTOSetInlinerThreshold.argtypes = [
|
| 1006 |
+
ffi.LLVMPipelineTuningOptionsRef, c_int]
|
| 1007 |
+
|
| 1008 |
+
ffi.lib.LLVMPY_DisposePipelineTuningOptions.argtypes = \
|
| 1009 |
+
[ffi.LLVMPipelineTuningOptionsRef,]
|
| 1010 |
+
|
| 1011 |
+
# PassBuilder
|
| 1012 |
+
|
| 1013 |
+
ffi.lib.LLVMPY_CreatePassBuilder.restype = ffi.LLVMPassBuilderRef
|
| 1014 |
+
ffi.lib.LLVMPY_CreatePassBuilder.argtypes = [
|
| 1015 |
+
ffi.LLVMTargetMachineRef,
|
| 1016 |
+
ffi.LLVMPipelineTuningOptionsRef,
|
| 1017 |
+
]
|
| 1018 |
+
|
| 1019 |
+
ffi.lib.LLVMPY_DisposePassBuilder.argtypes = [ffi.LLVMPassBuilderRef,]
|
| 1020 |
+
|
| 1021 |
+
ffi.lib.LLVMPY_CreateTimePassesHandler.restype = \
|
| 1022 |
+
ffi.LLVMTimePassesHandlerRef
|
| 1023 |
+
|
| 1024 |
+
ffi.lib.LLVMPY_DisposeTimePassesHandler.argtypes = [
|
| 1025 |
+
ffi.LLVMTimePassesHandlerRef,]
|
| 1026 |
+
|
| 1027 |
+
ffi.lib.LLVMPY_EnableTimePasses.argtypes = [
|
| 1028 |
+
ffi.LLVMPassBuilderRef,
|
| 1029 |
+
ffi.LLVMTimePassesHandlerRef,
|
| 1030 |
+
]
|
| 1031 |
+
|
| 1032 |
+
ffi.lib.LLVMPY_ReportAndDisableTimePasses.argtypes = [
|
| 1033 |
+
ffi.LLVMTimePassesHandlerRef,
|
| 1034 |
+
POINTER(c_char_p),
|
| 1035 |
+
]
|
| 1036 |
+
|
| 1037 |
+
# Pipeline builders
|
| 1038 |
+
|
| 1039 |
+
ffi.lib.LLVMPY_buildPerModuleDefaultPipeline.restype = \
|
| 1040 |
+
ffi.LLVMModulePassManagerRef
|
| 1041 |
+
|
| 1042 |
+
ffi.lib.LLVMPY_buildPerModuleDefaultPipeline.argtypes = [
|
| 1043 |
+
ffi.LLVMPassBuilderRef, c_int, c_int]
|
| 1044 |
+
|
| 1045 |
+
ffi.lib.LLVMPY_buildFunctionSimplificationPipeline.restype = \
|
| 1046 |
+
ffi.LLVMFunctionPassManagerRef
|
| 1047 |
+
|
| 1048 |
+
ffi.lib.LLVMPY_buildFunctionSimplificationPipeline.argtypes = [
|
| 1049 |
+
ffi.LLVMPassBuilderRef, c_int, c_int]
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/object_file.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llvmlite.binding import ffi
|
| 2 |
+
from ctypes import (c_bool, c_char_p, c_char, c_size_t, string_at, c_uint64,
|
| 3 |
+
POINTER)
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class SectionIteratorRef(ffi.ObjectRef):
|
| 7 |
+
def name(self):
|
| 8 |
+
return ffi.lib.LLVMPY_GetSectionName(self)
|
| 9 |
+
|
| 10 |
+
def is_text(self):
|
| 11 |
+
return ffi.lib.LLVMPY_IsSectionText(self)
|
| 12 |
+
|
| 13 |
+
def size(self):
|
| 14 |
+
return ffi.lib.LLVMPY_GetSectionSize(self)
|
| 15 |
+
|
| 16 |
+
def address(self):
|
| 17 |
+
return ffi.lib.LLVMPY_GetSectionAddress(self)
|
| 18 |
+
|
| 19 |
+
def data(self):
|
| 20 |
+
return string_at(ffi.lib.LLVMPY_GetSectionContents(self), self.size())
|
| 21 |
+
|
| 22 |
+
def is_end(self, object_file):
|
| 23 |
+
return ffi.lib.LLVMPY_IsSectionIteratorAtEnd(object_file, self)
|
| 24 |
+
|
| 25 |
+
def next(self):
|
| 26 |
+
ffi.lib.LLVMPY_MoveToNextSection(self)
|
| 27 |
+
|
| 28 |
+
def _dispose(self):
|
| 29 |
+
ffi.lib.LLVMPY_DisposeSectionIterator(self)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class ObjectFileRef(ffi.ObjectRef):
|
| 33 |
+
@classmethod
|
| 34 |
+
def from_data(cls, data):
|
| 35 |
+
return cls(ffi.lib.LLVMPY_CreateObjectFile(data, len(data)))
|
| 36 |
+
|
| 37 |
+
@classmethod
|
| 38 |
+
def from_path(cls, path):
|
| 39 |
+
with open(path, 'rb') as f:
|
| 40 |
+
data = f.read()
|
| 41 |
+
return cls(ffi.lib.LLVMPY_CreateObjectFile(data, len(data)))
|
| 42 |
+
|
| 43 |
+
def sections(self):
|
| 44 |
+
it = SectionIteratorRef(ffi.lib.LLVMPY_GetSections(self))
|
| 45 |
+
while not it.is_end(self):
|
| 46 |
+
yield it
|
| 47 |
+
it.next()
|
| 48 |
+
|
| 49 |
+
def _dispose(self):
|
| 50 |
+
ffi.lib.LLVMPY_DisposeObjectFile(self)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
ffi.lib.LLVMPY_CreateObjectFile.argtypes = [c_char_p, c_size_t]
|
| 54 |
+
ffi.lib.LLVMPY_CreateObjectFile.restype = ffi.LLVMObjectFileRef
|
| 55 |
+
|
| 56 |
+
ffi.lib.LLVMPY_DisposeObjectFile.argtypes = [ffi.LLVMObjectFileRef]
|
| 57 |
+
|
| 58 |
+
ffi.lib.LLVMPY_GetSections.argtypes = [ffi.LLVMObjectFileRef]
|
| 59 |
+
ffi.lib.LLVMPY_GetSections.restype = ffi.LLVMSectionIteratorRef
|
| 60 |
+
|
| 61 |
+
ffi.lib.LLVMPY_DisposeSectionIterator.argtypes = [ffi.LLVMSectionIteratorRef]
|
| 62 |
+
|
| 63 |
+
ffi.lib.LLVMPY_MoveToNextSection.argtypes = [ffi.LLVMSectionIteratorRef]
|
| 64 |
+
|
| 65 |
+
ffi.lib.LLVMPY_IsSectionIteratorAtEnd.argtypes = [
|
| 66 |
+
ffi.LLVMObjectFileRef, ffi.LLVMSectionIteratorRef]
|
| 67 |
+
ffi.lib.LLVMPY_IsSectionIteratorAtEnd.restype = c_bool
|
| 68 |
+
|
| 69 |
+
ffi.lib.LLVMPY_GetSectionName.argtypes = [ffi.LLVMSectionIteratorRef]
|
| 70 |
+
ffi.lib.LLVMPY_GetSectionName.restype = c_char_p
|
| 71 |
+
|
| 72 |
+
ffi.lib.LLVMPY_GetSectionSize.argtypes = [ffi.LLVMSectionIteratorRef]
|
| 73 |
+
ffi.lib.LLVMPY_GetSectionSize.restype = c_uint64
|
| 74 |
+
|
| 75 |
+
ffi.lib.LLVMPY_GetSectionAddress.argtypes = [ffi.LLVMSectionIteratorRef]
|
| 76 |
+
ffi.lib.LLVMPY_GetSectionAddress.restype = c_uint64
|
| 77 |
+
|
| 78 |
+
ffi.lib.LLVMPY_GetSectionContents.argtypes = [ffi.LLVMSectionIteratorRef]
|
| 79 |
+
ffi.lib.LLVMPY_GetSectionContents.restype = POINTER(c_char)
|
| 80 |
+
|
| 81 |
+
ffi.lib.LLVMPY_IsSectionText.argtypes = [ffi.LLVMSectionIteratorRef]
|
| 82 |
+
ffi.lib.LLVMPY_IsSectionText.restype = c_bool
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/options.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llvmlite.binding import ffi
|
| 2 |
+
from llvmlite.binding.common import _encode_string
|
| 3 |
+
from ctypes import c_char_p
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def set_option(name, option):
|
| 7 |
+
"""
|
| 8 |
+
Set the given LLVM "command-line" option.
|
| 9 |
+
|
| 10 |
+
For example set_option("test", "-debug-pass=Structure") would display
|
| 11 |
+
all optimization passes when generating code.
|
| 12 |
+
"""
|
| 13 |
+
ffi.lib.LLVMPY_SetCommandLine(_encode_string(name),
|
| 14 |
+
_encode_string(option))
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
ffi.lib.LLVMPY_SetCommandLine.argtypes = [c_char_p, c_char_p]
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/orcjit.py
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
from ctypes import POINTER, c_bool, c_char_p, c_uint8, c_uint64, c_size_t
|
| 3 |
+
|
| 4 |
+
from llvmlite.binding import ffi, targets
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class _LinkElement(ctypes.Structure):
|
| 8 |
+
_fields_ = [("element_kind", c_uint8),
|
| 9 |
+
("value", c_char_p),
|
| 10 |
+
("value_len", c_size_t)]
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class _SymbolAddress(ctypes.Structure):
|
| 14 |
+
_fields_ = [("name", c_char_p), ("address", c_uint64)]
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class JITLibraryBuilder:
|
| 18 |
+
"""
|
| 19 |
+
Create a library for linking by OrcJIT
|
| 20 |
+
|
| 21 |
+
OrcJIT operates like a linker: a number of compilation units and
|
| 22 |
+
dependencies are collected together and linked into a single dynamic library
|
| 23 |
+
that can export functions to other libraries or to be consumed directly as
|
| 24 |
+
entry points into JITted code. The native OrcJIT has a lot of memory
|
| 25 |
+
management complications so this API is designed to work well with Python's
|
| 26 |
+
garbage collection.
|
| 27 |
+
|
| 28 |
+
The creation of a new library is a bit like a linker command line where
|
| 29 |
+
compilation units, mostly as LLVM IR, and previously constructed libraries
|
| 30 |
+
are linked together, then loaded into memory, and the addresses of exported
|
| 31 |
+
symbols are extracted. Any static initializers are run and the exported
|
| 32 |
+
addresses and a resource tracker is produced. As long as the resource
|
| 33 |
+
tracker is referenced somewhere in Python, the exported addresses will be
|
| 34 |
+
valid. Once the resource tracker is garbage collected, the static
|
| 35 |
+
destructors will run and library will be unloaded from memory.
|
| 36 |
+
"""
|
| 37 |
+
def __init__(self):
|
| 38 |
+
self.__entries = []
|
| 39 |
+
self.__exports = set()
|
| 40 |
+
self.__imports = {}
|
| 41 |
+
|
| 42 |
+
def add_ir(self, llvmir):
|
| 43 |
+
"""
|
| 44 |
+
Adds a compilation unit to the library using LLVM IR as the input
|
| 45 |
+
format.
|
| 46 |
+
|
| 47 |
+
This takes a string or an object that can be converted to a string,
|
| 48 |
+
including IRBuilder, that contains LLVM IR.
|
| 49 |
+
"""
|
| 50 |
+
self.__entries.append((0, str(llvmir).encode('utf-8')))
|
| 51 |
+
return self
|
| 52 |
+
|
| 53 |
+
def add_native_assembly(self, asm):
|
| 54 |
+
"""
|
| 55 |
+
Adds a compilation unit to the library using native assembly as the
|
| 56 |
+
input format.
|
| 57 |
+
|
| 58 |
+
This takes a string or an object that can be converted to a string that
|
| 59 |
+
contains native assembly, which will be
|
| 60 |
+
parsed by LLVM.
|
| 61 |
+
"""
|
| 62 |
+
self.__entries.append((1, str(asm).encode('utf-8')))
|
| 63 |
+
return self
|
| 64 |
+
|
| 65 |
+
def add_object_img(self, data):
|
| 66 |
+
"""
|
| 67 |
+
Adds a compilation unit to the library using pre-compiled object code.
|
| 68 |
+
|
| 69 |
+
This takes the bytes of the contents of an object artifact which will be
|
| 70 |
+
loaded by LLVM.
|
| 71 |
+
"""
|
| 72 |
+
self.__entries.append((2, bytes(data)))
|
| 73 |
+
return self
|
| 74 |
+
|
| 75 |
+
def add_object_file(self, file_path):
|
| 76 |
+
"""
|
| 77 |
+
Adds a compilation unit to the library using pre-compiled object file.
|
| 78 |
+
|
| 79 |
+
This takes a string or path-like object that references an object file
|
| 80 |
+
which will be loaded by LLVM.
|
| 81 |
+
"""
|
| 82 |
+
with open(file_path, "rb") as f:
|
| 83 |
+
self.__entries.append((2, f.read()))
|
| 84 |
+
return self
|
| 85 |
+
|
| 86 |
+
def add_jit_library(self, name):
|
| 87 |
+
"""
|
| 88 |
+
Adds an existing JIT library as prerequisite.
|
| 89 |
+
|
| 90 |
+
The name of the library must match the one provided in a previous link
|
| 91 |
+
command.
|
| 92 |
+
"""
|
| 93 |
+
self.__entries.append((3, str(name).encode('utf-8')))
|
| 94 |
+
return self
|
| 95 |
+
|
| 96 |
+
def add_current_process(self):
|
| 97 |
+
"""
|
| 98 |
+
Allows the JITted library to access symbols in the current binary.
|
| 99 |
+
|
| 100 |
+
That is, it allows exporting the current binary's symbols, including
|
| 101 |
+
loaded libraries, as imports to the JITted
|
| 102 |
+
library.
|
| 103 |
+
"""
|
| 104 |
+
self.__entries.append((3, b''))
|
| 105 |
+
return self
|
| 106 |
+
|
| 107 |
+
def import_symbol(self, name, address):
|
| 108 |
+
"""
|
| 109 |
+
Register the *address* of global symbol *name*. This will make
|
| 110 |
+
it usable (e.g. callable) from LLVM-compiled functions.
|
| 111 |
+
"""
|
| 112 |
+
self.__imports[str(name)] = c_uint64(address)
|
| 113 |
+
return self
|
| 114 |
+
|
| 115 |
+
def export_symbol(self, name):
|
| 116 |
+
"""
|
| 117 |
+
During linking, extract the address of a symbol that was defined in one
|
| 118 |
+
of the compilation units.
|
| 119 |
+
|
| 120 |
+
This allows getting symbols, functions or global variables, out of the
|
| 121 |
+
JIT linked library. The addresses will be
|
| 122 |
+
available when the link method is called.
|
| 123 |
+
"""
|
| 124 |
+
self.__exports.add(str(name))
|
| 125 |
+
return self
|
| 126 |
+
|
| 127 |
+
def link(self, lljit, library_name):
|
| 128 |
+
"""
|
| 129 |
+
Link all the current compilation units into a JITted library and extract
|
| 130 |
+
the address of exported symbols.
|
| 131 |
+
|
| 132 |
+
An instance of the OrcJIT instance must be provided and this will be the
|
| 133 |
+
scope that is used to find other JITted libraries that are dependencies
|
| 134 |
+
and also be the place where this library will be defined.
|
| 135 |
+
|
| 136 |
+
After linking, the method will return a resource tracker that keeps the
|
| 137 |
+
library alive. This tracker also knows the addresses of any exported
|
| 138 |
+
symbols that were requested.
|
| 139 |
+
|
| 140 |
+
The addresses will be valid as long as the resource tracker is
|
| 141 |
+
referenced.
|
| 142 |
+
|
| 143 |
+
When the resource tracker is destroyed, the library will be cleaned up,
|
| 144 |
+
however, the name of the library cannot be reused.
|
| 145 |
+
"""
|
| 146 |
+
assert not lljit.closed, "Cannot add to closed JIT"
|
| 147 |
+
encoded_library_name = str(library_name).encode('utf-8')
|
| 148 |
+
assert len(encoded_library_name) > 0, "Library cannot be empty"
|
| 149 |
+
elements = (_LinkElement * len(self.__entries))()
|
| 150 |
+
for idx, (kind, value) in enumerate(self.__entries):
|
| 151 |
+
elements[idx].element_kind = c_uint8(kind)
|
| 152 |
+
elements[idx].value = c_char_p(value)
|
| 153 |
+
elements[idx].value_len = c_size_t(len(value))
|
| 154 |
+
exports = (_SymbolAddress * len(self.__exports))()
|
| 155 |
+
for idx, name in enumerate(self.__exports):
|
| 156 |
+
exports[idx].name = name.encode('utf-8')
|
| 157 |
+
|
| 158 |
+
imports = (_SymbolAddress * len(self.__imports))()
|
| 159 |
+
for idx, (name, addr) in enumerate(self.__imports.items()):
|
| 160 |
+
imports[idx].name = name.encode('utf-8')
|
| 161 |
+
imports[idx].address = addr
|
| 162 |
+
|
| 163 |
+
with ffi.OutputString() as outerr:
|
| 164 |
+
tracker = lljit._capi.LLVMPY_LLJIT_Link(
|
| 165 |
+
lljit._ptr,
|
| 166 |
+
encoded_library_name,
|
| 167 |
+
elements,
|
| 168 |
+
len(self.__entries),
|
| 169 |
+
imports,
|
| 170 |
+
len(self.__imports),
|
| 171 |
+
exports,
|
| 172 |
+
len(self.__exports),
|
| 173 |
+
outerr)
|
| 174 |
+
if not tracker:
|
| 175 |
+
raise RuntimeError(str(outerr))
|
| 176 |
+
return ResourceTracker(tracker,
|
| 177 |
+
library_name,
|
| 178 |
+
{name: exports[idx].address
|
| 179 |
+
for idx, name in enumerate(self.__exports)})
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
class ResourceTracker(ffi.ObjectRef):
|
| 183 |
+
"""
|
| 184 |
+
A resource tracker is created for each loaded JIT library and keeps the
|
| 185 |
+
module alive.
|
| 186 |
+
|
| 187 |
+
OrcJIT supports unloading libraries that are no longer used. This resource
|
| 188 |
+
tracker should be stored in any object that reference functions or constants
|
| 189 |
+
for a JITted library. When all references to the resource tracker are
|
| 190 |
+
dropped, this will trigger LLVM to unload the library and destroy any
|
| 191 |
+
functions.
|
| 192 |
+
|
| 193 |
+
Failure to keep resource trackers while calling a function or accessing a
|
| 194 |
+
symbol can result in crashes or memory corruption.
|
| 195 |
+
|
| 196 |
+
LLVM internally tracks references between different libraries, so only
|
| 197 |
+
"leaf" libraries need to be tracked.
|
| 198 |
+
"""
|
| 199 |
+
def __init__(self, ptr, name, addresses):
|
| 200 |
+
self.__addresses = addresses
|
| 201 |
+
self.__name = name
|
| 202 |
+
ffi.ObjectRef.__init__(self, ptr)
|
| 203 |
+
|
| 204 |
+
def __getitem__(self, item):
|
| 205 |
+
"""
|
| 206 |
+
Get the address of an exported symbol as an integer
|
| 207 |
+
"""
|
| 208 |
+
return self.__addresses[item]
|
| 209 |
+
|
| 210 |
+
@property
|
| 211 |
+
def name(self):
|
| 212 |
+
return self.__name
|
| 213 |
+
|
| 214 |
+
def _dispose(self):
|
| 215 |
+
with ffi.OutputString() as outerr:
|
| 216 |
+
if self._capi.LLVMPY_LLJIT_Dylib_Tracker_Dispose(self, outerr):
|
| 217 |
+
raise RuntimeError(str(outerr))
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
class LLJIT(ffi.ObjectRef):
|
| 221 |
+
"""
|
| 222 |
+
A OrcJIT-based LLVM JIT engine that can compile and run LLVM IR as a
|
| 223 |
+
collection of JITted dynamic libraries
|
| 224 |
+
|
| 225 |
+
The C++ OrcJIT API has a lot of memory ownership patterns that do not work
|
| 226 |
+
with Python. This API attempts to provide ones that are safe at the expense
|
| 227 |
+
of some features. Each LLJIT instance is a collection of JIT-compiled
|
| 228 |
+
libraries. In the C++ API, there is a "main" library; this API does not
|
| 229 |
+
provide access to the main library. Use the JITLibraryBuilder to create a
|
| 230 |
+
new named library instead.
|
| 231 |
+
"""
|
| 232 |
+
def __init__(self, ptr):
|
| 233 |
+
self._td = None
|
| 234 |
+
ffi.ObjectRef.__init__(self, ptr)
|
| 235 |
+
|
| 236 |
+
def lookup(self, dylib, fn):
|
| 237 |
+
"""
|
| 238 |
+
Find a function in this dynamic library and construct a new tracking
|
| 239 |
+
object for it
|
| 240 |
+
|
| 241 |
+
If the library or function do not exist, an exception will occur.
|
| 242 |
+
|
| 243 |
+
Parameters
|
| 244 |
+
----------
|
| 245 |
+
dylib : str or None
|
| 246 |
+
the name of the library containing the symbol
|
| 247 |
+
fn : str
|
| 248 |
+
the name of the function to get
|
| 249 |
+
"""
|
| 250 |
+
assert not self.closed, "Cannot lookup in closed JIT"
|
| 251 |
+
address = ctypes.c_uint64()
|
| 252 |
+
with ffi.OutputString() as outerr:
|
| 253 |
+
tracker = ffi.lib.LLVMPY_LLJITLookup(self,
|
| 254 |
+
dylib.encode("utf-8"),
|
| 255 |
+
fn.encode("utf-8"),
|
| 256 |
+
ctypes.byref(address),
|
| 257 |
+
outerr)
|
| 258 |
+
if not tracker:
|
| 259 |
+
raise RuntimeError(str(outerr))
|
| 260 |
+
|
| 261 |
+
return ResourceTracker(tracker, dylib, {fn: address.value})
|
| 262 |
+
|
| 263 |
+
@property
|
| 264 |
+
def target_data(self):
|
| 265 |
+
"""
|
| 266 |
+
The TargetData for this LLJIT instance.
|
| 267 |
+
"""
|
| 268 |
+
if self._td is not None:
|
| 269 |
+
return self._td
|
| 270 |
+
ptr = ffi.lib.LLVMPY_LLJITGetDataLayout(self)
|
| 271 |
+
self._td = targets.TargetData(ptr)
|
| 272 |
+
self._td._owned = True
|
| 273 |
+
return self._td
|
| 274 |
+
|
| 275 |
+
def _dispose(self):
|
| 276 |
+
if self._td is not None:
|
| 277 |
+
self._td.detach()
|
| 278 |
+
self._capi.LLVMPY_LLJITDispose(self)
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
def create_lljit_compiler(target_machine=None, *,
|
| 282 |
+
use_jit_link=False,
|
| 283 |
+
suppress_errors=False):
|
| 284 |
+
"""
|
| 285 |
+
Create an LLJIT instance
|
| 286 |
+
"""
|
| 287 |
+
with ffi.OutputString() as outerr:
|
| 288 |
+
lljit = ffi.lib.LLVMPY_CreateLLJITCompiler(target_machine,
|
| 289 |
+
suppress_errors,
|
| 290 |
+
use_jit_link,
|
| 291 |
+
outerr)
|
| 292 |
+
if not lljit:
|
| 293 |
+
raise RuntimeError(str(outerr))
|
| 294 |
+
|
| 295 |
+
return LLJIT(lljit)
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
ffi.lib.LLVMPY_LLJITLookup.argtypes = [
|
| 299 |
+
ffi.LLVMOrcLLJITRef,
|
| 300 |
+
c_char_p,
|
| 301 |
+
c_char_p,
|
| 302 |
+
POINTER(c_uint64),
|
| 303 |
+
POINTER(c_char_p),
|
| 304 |
+
]
|
| 305 |
+
ffi.lib.LLVMPY_LLJITLookup.restype = ffi.LLVMOrcDylibTrackerRef
|
| 306 |
+
|
| 307 |
+
ffi.lib.LLVMPY_LLJITGetDataLayout.argtypes = [
|
| 308 |
+
ffi.LLVMOrcLLJITRef,
|
| 309 |
+
]
|
| 310 |
+
ffi.lib.LLVMPY_LLJITGetDataLayout.restype = ffi.LLVMTargetDataRef
|
| 311 |
+
|
| 312 |
+
ffi.lib.LLVMPY_CreateLLJITCompiler.argtypes = [
|
| 313 |
+
ffi.LLVMTargetMachineRef,
|
| 314 |
+
c_bool,
|
| 315 |
+
c_bool,
|
| 316 |
+
POINTER(c_char_p),
|
| 317 |
+
]
|
| 318 |
+
ffi.lib.LLVMPY_CreateLLJITCompiler.restype = ffi.LLVMOrcLLJITRef
|
| 319 |
+
|
| 320 |
+
ffi.lib.LLVMPY_LLJITDispose.argtypes = [
|
| 321 |
+
ffi.LLVMOrcLLJITRef,
|
| 322 |
+
]
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
ffi.lib.LLVMPY_LLJIT_Link.argtypes = [
|
| 326 |
+
ffi.LLVMOrcLLJITRef,
|
| 327 |
+
c_char_p,
|
| 328 |
+
POINTER(_LinkElement),
|
| 329 |
+
c_size_t,
|
| 330 |
+
POINTER(_SymbolAddress),
|
| 331 |
+
c_size_t,
|
| 332 |
+
POINTER(_SymbolAddress),
|
| 333 |
+
c_size_t,
|
| 334 |
+
POINTER(c_char_p)
|
| 335 |
+
]
|
| 336 |
+
ffi.lib.LLVMPY_LLJIT_Link.restype = ffi.LLVMOrcDylibTrackerRef
|
| 337 |
+
|
| 338 |
+
ffi.lib.LLVMPY_LLJIT_Dylib_Tracker_Dispose.argtypes = [
|
| 339 |
+
ffi.LLVMOrcDylibTrackerRef,
|
| 340 |
+
POINTER(c_char_p)
|
| 341 |
+
]
|
| 342 |
+
ffi.lib.LLVMPY_LLJIT_Dylib_Tracker_Dispose.restype = c_bool
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/targets.py
ADDED
|
@@ -0,0 +1,462 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from ctypes import (POINTER, c_char_p, c_longlong, c_int, c_size_t,
|
| 3 |
+
c_void_p, string_at)
|
| 4 |
+
|
| 5 |
+
from llvmlite.binding import ffi
|
| 6 |
+
from llvmlite.binding.initfini import llvm_version_info
|
| 7 |
+
from llvmlite.binding.common import _decode_string, _encode_string
|
| 8 |
+
from collections import namedtuple
|
| 9 |
+
|
| 10 |
+
# import for backward compatible API, `has_svml` is now in config module.
|
| 11 |
+
from llvmlite.binding.config import _has_svml as has_svml # noqa: F401
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
Triple = namedtuple('Triple', ['Arch', 'SubArch', 'Vendor',
|
| 15 |
+
'OS', 'Env', 'ObjectFormat'])
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def get_process_triple():
|
| 19 |
+
"""
|
| 20 |
+
Return a target triple suitable for generating code for the current process.
|
| 21 |
+
An example when the default triple from ``get_default_triple()`` is not be
|
| 22 |
+
suitable is when LLVM is compiled for 32-bit but the process is executing
|
| 23 |
+
in 64-bit mode.
|
| 24 |
+
"""
|
| 25 |
+
with ffi.OutputString() as out:
|
| 26 |
+
ffi.lib.LLVMPY_GetProcessTriple(out)
|
| 27 |
+
return str(out)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def get_triple_parts(triple: str):
|
| 31 |
+
"""
|
| 32 |
+
Return a tuple of the parts of the given triple.
|
| 33 |
+
"""
|
| 34 |
+
with ffi.OutputString() as arch, \
|
| 35 |
+
ffi.OutputString() as vendor, \
|
| 36 |
+
ffi.OutputString() as os, ffi.OutputString() as env:
|
| 37 |
+
ffi.lib.LLVMPY_GetTripleParts(triple.encode('utf8'),
|
| 38 |
+
arch, vendor, os, env)
|
| 39 |
+
arch = str(arch)
|
| 40 |
+
subarch = ''
|
| 41 |
+
for _str in triple.split('-'):
|
| 42 |
+
if _str.startswith(arch):
|
| 43 |
+
subarch = _str[len(arch):]
|
| 44 |
+
break
|
| 45 |
+
return Triple(arch, subarch, str(vendor), str(os),
|
| 46 |
+
str(env), get_object_format(triple))
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class FeatureMap(dict):
|
| 50 |
+
"""
|
| 51 |
+
Maps feature name to a boolean indicating the availability of the feature.
|
| 52 |
+
Extends ``dict`` to add `.flatten()` method.
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
def flatten(self, sort=True):
|
| 56 |
+
"""
|
| 57 |
+
Args
|
| 58 |
+
----
|
| 59 |
+
sort: bool
|
| 60 |
+
Optional. If True, the features are sorted by name; otherwise,
|
| 61 |
+
the ordering is unstable between python session due to hash
|
| 62 |
+
randomization. Defaults to True.
|
| 63 |
+
|
| 64 |
+
Returns a string suitable for use as the ``features`` argument to
|
| 65 |
+
``Target.create_target_machine()``.
|
| 66 |
+
|
| 67 |
+
"""
|
| 68 |
+
iterator = sorted(self.items()) if sort else iter(self.items())
|
| 69 |
+
flag_map = {True: '+', False: '-'}
|
| 70 |
+
return ','.join('{0}{1}'.format(flag_map[v], k)
|
| 71 |
+
for k, v in iterator)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def get_host_cpu_features():
|
| 75 |
+
"""
|
| 76 |
+
Returns a dictionary-like object indicating the CPU features for current
|
| 77 |
+
architecture and whether they are enabled for this CPU. The key-value pairs
|
| 78 |
+
are the feature name as string and a boolean indicating whether the feature
|
| 79 |
+
is available. The returned value is an instance of ``FeatureMap`` class,
|
| 80 |
+
which adds a new method ``.flatten()`` for returning a string suitable for
|
| 81 |
+
use as the "features" argument to ``Target.create_target_machine()``.
|
| 82 |
+
|
| 83 |
+
If LLVM has not implemented this feature or it fails to get the information,
|
| 84 |
+
this function will raise a RuntimeError exception.
|
| 85 |
+
"""
|
| 86 |
+
with ffi.OutputString() as out:
|
| 87 |
+
outdict = FeatureMap()
|
| 88 |
+
if not ffi.lib.LLVMPY_GetHostCPUFeatures(out):
|
| 89 |
+
return outdict
|
| 90 |
+
flag_map = {'+': True, '-': False}
|
| 91 |
+
content = str(out)
|
| 92 |
+
if content: # protect against empty string
|
| 93 |
+
for feat in content.split(','):
|
| 94 |
+
if feat: # protect against empty feature
|
| 95 |
+
outdict[feat[1:]] = flag_map[feat[0]]
|
| 96 |
+
return outdict
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def get_default_triple():
|
| 100 |
+
"""
|
| 101 |
+
Return the default target triple LLVM is configured to produce code for.
|
| 102 |
+
"""
|
| 103 |
+
with ffi.OutputString() as out:
|
| 104 |
+
ffi.lib.LLVMPY_GetDefaultTargetTriple(out)
|
| 105 |
+
return str(out)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def get_host_cpu_name():
|
| 109 |
+
"""
|
| 110 |
+
Get the name of the host's CPU, suitable for using with
|
| 111 |
+
:meth:`Target.create_target_machine()`.
|
| 112 |
+
"""
|
| 113 |
+
with ffi.OutputString() as out:
|
| 114 |
+
ffi.lib.LLVMPY_GetHostCPUName(out)
|
| 115 |
+
return str(out)
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
# Adapted from https://github.com/llvm/llvm-project/blob/release/15.x/llvm/include/llvm/ADT/Triple.h#L269 # noqa
|
| 119 |
+
llvm_version_major = llvm_version_info[0]
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
_object_formats = {
|
| 123 |
+
0: "Unknown",
|
| 124 |
+
1: "COFF",
|
| 125 |
+
2: "DXContainer",
|
| 126 |
+
3: "ELF",
|
| 127 |
+
4: "GOFF",
|
| 128 |
+
5: "MachO",
|
| 129 |
+
6: "SPIRV",
|
| 130 |
+
7: "Wasm",
|
| 131 |
+
8: "XCOFF",
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def get_object_format(triple=None):
|
| 136 |
+
"""
|
| 137 |
+
Get the object format for the given *triple* string (or the default
|
| 138 |
+
triple if omitted).
|
| 139 |
+
A string is returned
|
| 140 |
+
"""
|
| 141 |
+
if triple is None:
|
| 142 |
+
triple = get_default_triple()
|
| 143 |
+
res = ffi.lib.LLVMPY_GetTripleObjectFormat(_encode_string(triple))
|
| 144 |
+
return _object_formats[res]
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def create_target_data(layout):
|
| 148 |
+
"""
|
| 149 |
+
Create a TargetData instance for the given *layout* string.
|
| 150 |
+
"""
|
| 151 |
+
return TargetData(ffi.lib.LLVMPY_CreateTargetData(_encode_string(layout)))
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
class TargetData(ffi.ObjectRef):
|
| 155 |
+
"""
|
| 156 |
+
A TargetData provides structured access to a data layout.
|
| 157 |
+
Use :func:`create_target_data` to create instances.
|
| 158 |
+
"""
|
| 159 |
+
|
| 160 |
+
def __str__(self):
|
| 161 |
+
if self._closed:
|
| 162 |
+
return "<dead TargetData>"
|
| 163 |
+
with ffi.OutputString() as out:
|
| 164 |
+
ffi.lib.LLVMPY_CopyStringRepOfTargetData(self, out)
|
| 165 |
+
return str(out)
|
| 166 |
+
|
| 167 |
+
def _dispose(self):
|
| 168 |
+
self._capi.LLVMPY_DisposeTargetData(self)
|
| 169 |
+
|
| 170 |
+
def get_abi_size(self, ty):
|
| 171 |
+
"""
|
| 172 |
+
Get ABI size of LLVM type *ty*.
|
| 173 |
+
"""
|
| 174 |
+
return ffi.lib.LLVMPY_ABISizeOfType(self, ty)
|
| 175 |
+
|
| 176 |
+
def get_element_offset(self, ty, position):
|
| 177 |
+
"""
|
| 178 |
+
Get byte offset of type's ty element at the given position
|
| 179 |
+
"""
|
| 180 |
+
|
| 181 |
+
offset = ffi.lib.LLVMPY_OffsetOfElement(self, ty, position)
|
| 182 |
+
if offset == -1:
|
| 183 |
+
raise ValueError("Could not determined offset of {}th "
|
| 184 |
+
"element of the type '{}'. Is it a struct"
|
| 185 |
+
"type?".format(position, str(ty)))
|
| 186 |
+
return offset
|
| 187 |
+
|
| 188 |
+
def get_abi_alignment(self, ty):
|
| 189 |
+
"""
|
| 190 |
+
Get minimum ABI alignment of LLVM type *ty*.
|
| 191 |
+
"""
|
| 192 |
+
return ffi.lib.LLVMPY_ABIAlignmentOfType(self, ty)
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
RELOC = frozenset(['default', 'static', 'pic', 'dynamicnopic'])
|
| 196 |
+
CODEMODEL = frozenset(['default', 'jitdefault', 'small', 'kernel', 'medium',
|
| 197 |
+
'large'])
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
class Target(ffi.ObjectRef):
|
| 201 |
+
_triple = ''
|
| 202 |
+
|
| 203 |
+
# No _dispose() method since LLVMGetTargetFromTriple() returns a
|
| 204 |
+
# persistent object.
|
| 205 |
+
|
| 206 |
+
@classmethod
|
| 207 |
+
def from_default_triple(cls):
|
| 208 |
+
"""
|
| 209 |
+
Create a Target instance for the default triple.
|
| 210 |
+
"""
|
| 211 |
+
triple = get_default_triple()
|
| 212 |
+
return cls.from_triple(triple)
|
| 213 |
+
|
| 214 |
+
@classmethod
|
| 215 |
+
def from_triple(cls, triple):
|
| 216 |
+
"""
|
| 217 |
+
Create a Target instance for the given triple (a string).
|
| 218 |
+
"""
|
| 219 |
+
with ffi.OutputString() as outerr:
|
| 220 |
+
target = ffi.lib.LLVMPY_GetTargetFromTriple(triple.encode('utf8'),
|
| 221 |
+
outerr)
|
| 222 |
+
if not target:
|
| 223 |
+
raise RuntimeError(str(outerr))
|
| 224 |
+
target = cls(target)
|
| 225 |
+
target._triple = triple
|
| 226 |
+
return target
|
| 227 |
+
|
| 228 |
+
@property
|
| 229 |
+
def name(self):
|
| 230 |
+
s = ffi.lib.LLVMPY_GetTargetName(self)
|
| 231 |
+
return _decode_string(s)
|
| 232 |
+
|
| 233 |
+
@property
|
| 234 |
+
def description(self):
|
| 235 |
+
s = ffi.lib.LLVMPY_GetTargetDescription(self)
|
| 236 |
+
return _decode_string(s)
|
| 237 |
+
|
| 238 |
+
@property
|
| 239 |
+
def triple(self):
|
| 240 |
+
return self._triple
|
| 241 |
+
|
| 242 |
+
def __str__(self):
|
| 243 |
+
return "<Target {0} ({1})>".format(self.name, self.description)
|
| 244 |
+
|
| 245 |
+
def create_target_machine(self, cpu='', features='',
|
| 246 |
+
opt=2, reloc='default', codemodel='jitdefault',
|
| 247 |
+
printmc=False, jit=False, abiname=''):
|
| 248 |
+
"""
|
| 249 |
+
Create a new TargetMachine for this target and the given options.
|
| 250 |
+
|
| 251 |
+
Specifying codemodel='default' will result in the use of the "small"
|
| 252 |
+
code model. Specifying codemodel='jitdefault' will result in the code
|
| 253 |
+
model being picked based on platform bitness (32="small", 64="large").
|
| 254 |
+
|
| 255 |
+
The `printmc` option corresponds to llvm's `-print-machineinstrs`.
|
| 256 |
+
|
| 257 |
+
The `jit` option should be set when the target-machine is to be used
|
| 258 |
+
in a JIT engine.
|
| 259 |
+
|
| 260 |
+
The `abiname` option specifies the ABI. RISC-V targets with hard-float
|
| 261 |
+
needs to pass the ABI name to LLVM.
|
| 262 |
+
"""
|
| 263 |
+
assert 0 <= opt <= 3
|
| 264 |
+
assert reloc in RELOC
|
| 265 |
+
assert codemodel in CODEMODEL
|
| 266 |
+
triple = self._triple
|
| 267 |
+
# MCJIT under Windows only supports ELF objects, see
|
| 268 |
+
# http://lists.llvm.org/pipermail/llvm-dev/2013-December/068341.html
|
| 269 |
+
# Note we still want to produce regular COFF files in AOT mode.
|
| 270 |
+
if os.name == 'nt' and codemodel == 'jitdefault':
|
| 271 |
+
triple += '-elf'
|
| 272 |
+
tm = ffi.lib.LLVMPY_CreateTargetMachine(self,
|
| 273 |
+
_encode_string(triple),
|
| 274 |
+
_encode_string(cpu),
|
| 275 |
+
_encode_string(features),
|
| 276 |
+
opt,
|
| 277 |
+
_encode_string(reloc),
|
| 278 |
+
_encode_string(codemodel),
|
| 279 |
+
int(printmc),
|
| 280 |
+
int(jit),
|
| 281 |
+
_encode_string(abiname),
|
| 282 |
+
)
|
| 283 |
+
if tm:
|
| 284 |
+
return TargetMachine(tm)
|
| 285 |
+
else:
|
| 286 |
+
raise RuntimeError("Cannot create target machine")
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
class TargetMachine(ffi.ObjectRef):
|
| 290 |
+
|
| 291 |
+
def _dispose(self):
|
| 292 |
+
self._capi.LLVMPY_DisposeTargetMachine(self)
|
| 293 |
+
|
| 294 |
+
def add_analysis_passes(self, pm):
|
| 295 |
+
"""
|
| 296 |
+
Register analysis passes for this target machine with a pass manager.
|
| 297 |
+
"""
|
| 298 |
+
ffi.lib.LLVMPY_AddAnalysisPasses(self, pm)
|
| 299 |
+
|
| 300 |
+
def set_asm_verbosity(self, verbose):
|
| 301 |
+
"""
|
| 302 |
+
Set whether this target machine will emit assembly with human-readable
|
| 303 |
+
comments describing control flow, debug information, and so on.
|
| 304 |
+
"""
|
| 305 |
+
ffi.lib.LLVMPY_SetTargetMachineAsmVerbosity(self, verbose)
|
| 306 |
+
|
| 307 |
+
def emit_object(self, module):
|
| 308 |
+
"""
|
| 309 |
+
Represent the module as a code object, suitable for use with
|
| 310 |
+
the platform's linker. Returns a byte string.
|
| 311 |
+
"""
|
| 312 |
+
return self._emit_to_memory(module, use_object=True)
|
| 313 |
+
|
| 314 |
+
def emit_assembly(self, module):
|
| 315 |
+
"""
|
| 316 |
+
Return the raw assembler of the module, as a string.
|
| 317 |
+
|
| 318 |
+
llvm.initialize_native_asmprinter() must have been called first.
|
| 319 |
+
"""
|
| 320 |
+
return _decode_string(self._emit_to_memory(module, use_object=False))
|
| 321 |
+
|
| 322 |
+
def _emit_to_memory(self, module, use_object=False):
|
| 323 |
+
"""Returns bytes of object code of the module.
|
| 324 |
+
|
| 325 |
+
Args
|
| 326 |
+
----
|
| 327 |
+
use_object : bool
|
| 328 |
+
Emit object code or (if False) emit assembly code.
|
| 329 |
+
"""
|
| 330 |
+
with ffi.OutputString() as outerr:
|
| 331 |
+
mb = ffi.lib.LLVMPY_TargetMachineEmitToMemory(self, module,
|
| 332 |
+
int(use_object),
|
| 333 |
+
outerr)
|
| 334 |
+
if not mb:
|
| 335 |
+
raise RuntimeError(str(outerr))
|
| 336 |
+
|
| 337 |
+
bufptr = ffi.lib.LLVMPY_GetBufferStart(mb)
|
| 338 |
+
bufsz = ffi.lib.LLVMPY_GetBufferSize(mb)
|
| 339 |
+
try:
|
| 340 |
+
return string_at(bufptr, bufsz)
|
| 341 |
+
finally:
|
| 342 |
+
ffi.lib.LLVMPY_DisposeMemoryBuffer(mb)
|
| 343 |
+
|
| 344 |
+
@property
|
| 345 |
+
def target_data(self):
|
| 346 |
+
return TargetData(ffi.lib.LLVMPY_CreateTargetMachineData(self))
|
| 347 |
+
|
| 348 |
+
@property
|
| 349 |
+
def triple(self):
|
| 350 |
+
with ffi.OutputString() as out:
|
| 351 |
+
ffi.lib.LLVMPY_GetTargetMachineTriple(self, out)
|
| 352 |
+
return str(out)
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
# ============================================================================
|
| 356 |
+
# FFI
|
| 357 |
+
|
| 358 |
+
ffi.lib.LLVMPY_GetProcessTriple.argtypes = [POINTER(c_char_p)]
|
| 359 |
+
ffi.lib.LLVMPY_GetTripleParts.argtypes = [c_char_p, POINTER(c_char_p),
|
| 360 |
+
POINTER(c_char_p), POINTER(c_char_p),
|
| 361 |
+
POINTER(c_char_p)]
|
| 362 |
+
|
| 363 |
+
ffi.lib.LLVMPY_GetHostCPUFeatures.argtypes = [POINTER(c_char_p)]
|
| 364 |
+
ffi.lib.LLVMPY_GetHostCPUFeatures.restype = c_int
|
| 365 |
+
|
| 366 |
+
ffi.lib.LLVMPY_GetDefaultTargetTriple.argtypes = [POINTER(c_char_p)]
|
| 367 |
+
|
| 368 |
+
ffi.lib.LLVMPY_GetHostCPUName.argtypes = [POINTER(c_char_p)]
|
| 369 |
+
|
| 370 |
+
ffi.lib.LLVMPY_GetTripleObjectFormat.argtypes = [c_char_p]
|
| 371 |
+
ffi.lib.LLVMPY_GetTripleObjectFormat.restype = c_int
|
| 372 |
+
|
| 373 |
+
ffi.lib.LLVMPY_CreateTargetData.argtypes = [c_char_p]
|
| 374 |
+
ffi.lib.LLVMPY_CreateTargetData.restype = ffi.LLVMTargetDataRef
|
| 375 |
+
|
| 376 |
+
ffi.lib.LLVMPY_CopyStringRepOfTargetData.argtypes = [
|
| 377 |
+
ffi.LLVMTargetDataRef,
|
| 378 |
+
POINTER(c_char_p),
|
| 379 |
+
]
|
| 380 |
+
|
| 381 |
+
ffi.lib.LLVMPY_DisposeTargetData.argtypes = [
|
| 382 |
+
ffi.LLVMTargetDataRef,
|
| 383 |
+
]
|
| 384 |
+
|
| 385 |
+
ffi.lib.LLVMPY_ABISizeOfType.argtypes = [ffi.LLVMTargetDataRef,
|
| 386 |
+
ffi.LLVMTypeRef]
|
| 387 |
+
ffi.lib.LLVMPY_ABISizeOfType.restype = c_longlong
|
| 388 |
+
|
| 389 |
+
ffi.lib.LLVMPY_OffsetOfElement.argtypes = [ffi.LLVMTargetDataRef,
|
| 390 |
+
ffi.LLVMTypeRef,
|
| 391 |
+
c_int]
|
| 392 |
+
ffi.lib.LLVMPY_OffsetOfElement.restype = c_longlong
|
| 393 |
+
|
| 394 |
+
ffi.lib.LLVMPY_ABIAlignmentOfType.argtypes = [ffi.LLVMTargetDataRef,
|
| 395 |
+
ffi.LLVMTypeRef]
|
| 396 |
+
ffi.lib.LLVMPY_ABIAlignmentOfType.restype = c_longlong
|
| 397 |
+
|
| 398 |
+
ffi.lib.LLVMPY_GetTargetFromTriple.argtypes = [c_char_p, POINTER(c_char_p)]
|
| 399 |
+
ffi.lib.LLVMPY_GetTargetFromTriple.restype = ffi.LLVMTargetRef
|
| 400 |
+
|
| 401 |
+
ffi.lib.LLVMPY_GetTargetName.argtypes = [ffi.LLVMTargetRef]
|
| 402 |
+
ffi.lib.LLVMPY_GetTargetName.restype = c_char_p
|
| 403 |
+
|
| 404 |
+
ffi.lib.LLVMPY_GetTargetDescription.argtypes = [ffi.LLVMTargetRef]
|
| 405 |
+
ffi.lib.LLVMPY_GetTargetDescription.restype = c_char_p
|
| 406 |
+
|
| 407 |
+
ffi.lib.LLVMPY_CreateTargetMachine.argtypes = [
|
| 408 |
+
ffi.LLVMTargetRef,
|
| 409 |
+
# Triple
|
| 410 |
+
c_char_p,
|
| 411 |
+
# CPU
|
| 412 |
+
c_char_p,
|
| 413 |
+
# Features
|
| 414 |
+
c_char_p,
|
| 415 |
+
# OptLevel
|
| 416 |
+
c_int,
|
| 417 |
+
# Reloc
|
| 418 |
+
c_char_p,
|
| 419 |
+
# CodeModel
|
| 420 |
+
c_char_p,
|
| 421 |
+
# PrintMC
|
| 422 |
+
c_int,
|
| 423 |
+
# JIT
|
| 424 |
+
c_int,
|
| 425 |
+
# ABIName
|
| 426 |
+
c_char_p,
|
| 427 |
+
]
|
| 428 |
+
ffi.lib.LLVMPY_CreateTargetMachine.restype = ffi.LLVMTargetMachineRef
|
| 429 |
+
|
| 430 |
+
ffi.lib.LLVMPY_DisposeTargetMachine.argtypes = [ffi.LLVMTargetMachineRef]
|
| 431 |
+
|
| 432 |
+
ffi.lib.LLVMPY_GetTargetMachineTriple.argtypes = [ffi.LLVMTargetMachineRef,
|
| 433 |
+
POINTER(c_char_p)]
|
| 434 |
+
|
| 435 |
+
ffi.lib.LLVMPY_SetTargetMachineAsmVerbosity.argtypes = [
|
| 436 |
+
ffi.LLVMTargetMachineRef, c_int]
|
| 437 |
+
|
| 438 |
+
ffi.lib.LLVMPY_AddAnalysisPasses.argtypes = [
|
| 439 |
+
ffi.LLVMTargetMachineRef,
|
| 440 |
+
ffi.LLVMPassManagerRef,
|
| 441 |
+
]
|
| 442 |
+
|
| 443 |
+
ffi.lib.LLVMPY_TargetMachineEmitToMemory.argtypes = [
|
| 444 |
+
ffi.LLVMTargetMachineRef,
|
| 445 |
+
ffi.LLVMModuleRef,
|
| 446 |
+
c_int,
|
| 447 |
+
POINTER(c_char_p),
|
| 448 |
+
]
|
| 449 |
+
ffi.lib.LLVMPY_TargetMachineEmitToMemory.restype = ffi.LLVMMemoryBufferRef
|
| 450 |
+
|
| 451 |
+
ffi.lib.LLVMPY_GetBufferStart.argtypes = [ffi.LLVMMemoryBufferRef]
|
| 452 |
+
ffi.lib.LLVMPY_GetBufferStart.restype = c_void_p
|
| 453 |
+
|
| 454 |
+
ffi.lib.LLVMPY_GetBufferSize.argtypes = [ffi.LLVMMemoryBufferRef]
|
| 455 |
+
ffi.lib.LLVMPY_GetBufferSize.restype = c_size_t
|
| 456 |
+
|
| 457 |
+
ffi.lib.LLVMPY_DisposeMemoryBuffer.argtypes = [ffi.LLVMMemoryBufferRef]
|
| 458 |
+
|
| 459 |
+
ffi.lib.LLVMPY_CreateTargetMachineData.argtypes = [
|
| 460 |
+
ffi.LLVMTargetMachineRef,
|
| 461 |
+
]
|
| 462 |
+
ffi.lib.LLVMPY_CreateTargetMachineData.restype = ffi.LLVMTargetDataRef
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/typeref.py
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ctypes import c_int, c_bool, c_void_p, c_uint64, c_uint, POINTER
|
| 2 |
+
import enum
|
| 3 |
+
|
| 4 |
+
from llvmlite import ir
|
| 5 |
+
from llvmlite.binding import ffi
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class TypeKind(enum.IntEnum):
|
| 9 |
+
# The LLVMTypeKind enum from llvm-c/Core.h
|
| 10 |
+
|
| 11 |
+
void = 0
|
| 12 |
+
half = 1
|
| 13 |
+
float = 2
|
| 14 |
+
double = 3
|
| 15 |
+
x86_fp80 = 4
|
| 16 |
+
fp128 = 5
|
| 17 |
+
ppc_fp128 = 6
|
| 18 |
+
label = 7
|
| 19 |
+
integer = 8
|
| 20 |
+
function = 9
|
| 21 |
+
struct = 10
|
| 22 |
+
array = 11
|
| 23 |
+
pointer = 12
|
| 24 |
+
vector = 13
|
| 25 |
+
metadata = 14
|
| 26 |
+
x86_mmx = 15
|
| 27 |
+
token = 16
|
| 28 |
+
scalable_vector = 17
|
| 29 |
+
bfloat = 18
|
| 30 |
+
x86_amx = 19
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
_TypeKindToIRType = {
|
| 34 |
+
# All TypeKind here must have a TypeRef.as_ir() implementation
|
| 35 |
+
TypeKind.void: ir.VoidType,
|
| 36 |
+
TypeKind.half: ir.HalfType,
|
| 37 |
+
TypeKind.float: ir.FloatType,
|
| 38 |
+
TypeKind.double: ir.DoubleType,
|
| 39 |
+
TypeKind.integer: ir.IntType,
|
| 40 |
+
TypeKind.function: ir.FunctionType,
|
| 41 |
+
TypeKind.pointer: ir.PointerType,
|
| 42 |
+
TypeKind.array: ir.ArrayType,
|
| 43 |
+
TypeKind.vector: ir.VectorType,
|
| 44 |
+
TypeKind.struct: ir.LiteralStructType,
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class TypeRef(ffi.ObjectRef):
|
| 49 |
+
"""A weak reference to a LLVM type
|
| 50 |
+
"""
|
| 51 |
+
@property
|
| 52 |
+
def name(self):
|
| 53 |
+
"""
|
| 54 |
+
Get type name
|
| 55 |
+
"""
|
| 56 |
+
return ffi.ret_string(ffi.lib.LLVMPY_GetTypeName(self))
|
| 57 |
+
|
| 58 |
+
@property
|
| 59 |
+
def is_struct(self):
|
| 60 |
+
"""
|
| 61 |
+
Returns true if the type is a struct type.
|
| 62 |
+
"""
|
| 63 |
+
return ffi.lib.LLVMPY_TypeIsStruct(self)
|
| 64 |
+
|
| 65 |
+
@property
|
| 66 |
+
def is_pointer(self):
|
| 67 |
+
"""
|
| 68 |
+
Returns true if the type is a pointer type.
|
| 69 |
+
"""
|
| 70 |
+
return ffi.lib.LLVMPY_TypeIsPointer(self)
|
| 71 |
+
|
| 72 |
+
@property
|
| 73 |
+
def is_array(self):
|
| 74 |
+
"""
|
| 75 |
+
Returns true if the type is an array type.
|
| 76 |
+
"""
|
| 77 |
+
return ffi.lib.LLVMPY_TypeIsArray(self)
|
| 78 |
+
|
| 79 |
+
@property
|
| 80 |
+
def is_vector(self):
|
| 81 |
+
"""
|
| 82 |
+
Returns true if the type is a vector type.
|
| 83 |
+
"""
|
| 84 |
+
return ffi.lib.LLVMPY_TypeIsVector(self)
|
| 85 |
+
|
| 86 |
+
@property
|
| 87 |
+
def is_function(self):
|
| 88 |
+
"""
|
| 89 |
+
Returns true if the type is a function type.
|
| 90 |
+
"""
|
| 91 |
+
return ffi.lib.LLVMPY_TypeIsFunction(self)
|
| 92 |
+
|
| 93 |
+
@property
|
| 94 |
+
def is_function_vararg(self):
|
| 95 |
+
"""
|
| 96 |
+
Returns true if a function type accepts a variable number of arguments.
|
| 97 |
+
When the type is not a function, raises exception.
|
| 98 |
+
"""
|
| 99 |
+
if self.type_kind != TypeKind.function:
|
| 100 |
+
raise ValueError("Type {} is not a function".format(self))
|
| 101 |
+
return ffi.lib.LLVMPY_IsFunctionVararg(self)
|
| 102 |
+
|
| 103 |
+
@property
|
| 104 |
+
def elements(self):
|
| 105 |
+
"""
|
| 106 |
+
Returns iterator over enclosing types
|
| 107 |
+
"""
|
| 108 |
+
if self.is_pointer:
|
| 109 |
+
raise ValueError("Type {} doesn't contain elements.".format(self))
|
| 110 |
+
return _TypeListIterator(ffi.lib.LLVMPY_ElementIter(self))
|
| 111 |
+
|
| 112 |
+
@property
|
| 113 |
+
def element_count(self):
|
| 114 |
+
"""
|
| 115 |
+
Returns the number of elements in an array or a vector. For scalable
|
| 116 |
+
vectors, returns minimum number of elements. When the type is neither
|
| 117 |
+
an array nor a vector, raises exception.
|
| 118 |
+
"""
|
| 119 |
+
if not self.is_array and not self.is_vector:
|
| 120 |
+
raise ValueError("Type {} is not an array nor vector".format(self))
|
| 121 |
+
return ffi.lib.LLVMPY_GetTypeElementCount(self)
|
| 122 |
+
|
| 123 |
+
@property
|
| 124 |
+
def type_width(self):
|
| 125 |
+
"""
|
| 126 |
+
Return the basic size of this type if it is a primitive type. These are
|
| 127 |
+
fixed by LLVM and are not target-dependent.
|
| 128 |
+
This will return zero if the type does not have a size or is not a
|
| 129 |
+
primitive type.
|
| 130 |
+
|
| 131 |
+
If this is a scalable vector type, the scalable property will be set and
|
| 132 |
+
the runtime size will be a positive integer multiple of the base size.
|
| 133 |
+
|
| 134 |
+
Note that this may not reflect the size of memory allocated for an
|
| 135 |
+
instance of the type or the number of bytes that are written when an
|
| 136 |
+
instance of the type is stored to memory.
|
| 137 |
+
"""
|
| 138 |
+
return ffi.lib.LLVMPY_GetTypeBitWidth(self)
|
| 139 |
+
|
| 140 |
+
@property
|
| 141 |
+
def type_kind(self):
|
| 142 |
+
"""
|
| 143 |
+
Returns the LLVMTypeKind enumeration of this type.
|
| 144 |
+
"""
|
| 145 |
+
return TypeKind(ffi.lib.LLVMPY_GetTypeKind(self))
|
| 146 |
+
|
| 147 |
+
@property
|
| 148 |
+
def is_packed_struct(self):
|
| 149 |
+
return ffi.lib.LLVMPY_IsPackedStruct(self)
|
| 150 |
+
|
| 151 |
+
@property
|
| 152 |
+
def is_literal_struct(self):
|
| 153 |
+
return ffi.lib.LLVMPY_IsLiteralStruct(self)
|
| 154 |
+
|
| 155 |
+
@property
|
| 156 |
+
def is_opaque_struct(self):
|
| 157 |
+
return ffi.lib.LLVMPY_IsOpaqueStruct(self)
|
| 158 |
+
|
| 159 |
+
def get_function_parameters(self) -> tuple["TypeRef"]:
|
| 160 |
+
nparams = ffi.lib.LLVMPY_CountParamTypes(self)
|
| 161 |
+
if nparams > 0:
|
| 162 |
+
out_buffer = (ffi.LLVMTypeRef * nparams)(None)
|
| 163 |
+
ffi.lib.LLVMPY_GetParamTypes(self, out_buffer)
|
| 164 |
+
return tuple(map(TypeRef, out_buffer))
|
| 165 |
+
else:
|
| 166 |
+
return ()
|
| 167 |
+
|
| 168 |
+
def get_function_return(self) -> "TypeRef":
|
| 169 |
+
return TypeRef(ffi.lib.LLVMPY_GetReturnType(self))
|
| 170 |
+
|
| 171 |
+
def as_ir(self, ir_ctx: ir.Context) -> ir.Type:
|
| 172 |
+
"""Convert into a ``llvmlite.ir.Type``.
|
| 173 |
+
"""
|
| 174 |
+
try:
|
| 175 |
+
cls = _TypeKindToIRType[self.type_kind]
|
| 176 |
+
except KeyError:
|
| 177 |
+
msg = f"as_ir() unsupported for TypeRef of {self.type_kind}"
|
| 178 |
+
raise TypeError(msg)
|
| 179 |
+
else:
|
| 180 |
+
return cls.from_llvm(self, ir_ctx)
|
| 181 |
+
|
| 182 |
+
def __str__(self):
|
| 183 |
+
return ffi.ret_string(ffi.lib.LLVMPY_PrintType(self))
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
class _TypeIterator(ffi.ObjectRef):
|
| 187 |
+
|
| 188 |
+
def __next__(self):
|
| 189 |
+
vp = self._next()
|
| 190 |
+
if vp:
|
| 191 |
+
return TypeRef(vp)
|
| 192 |
+
else:
|
| 193 |
+
raise StopIteration
|
| 194 |
+
|
| 195 |
+
next = __next__
|
| 196 |
+
|
| 197 |
+
def __iter__(self):
|
| 198 |
+
return self
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
class _TypeListIterator(_TypeIterator):
|
| 202 |
+
|
| 203 |
+
def _dispose(self):
|
| 204 |
+
self._capi.LLVMPY_DisposeElementIter(self)
|
| 205 |
+
|
| 206 |
+
def _next(self):
|
| 207 |
+
return ffi.lib.LLVMPY_ElementIterNext(self)
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
# FFI
|
| 211 |
+
|
| 212 |
+
ffi.lib.LLVMPY_PrintType.argtypes = [ffi.LLVMTypeRef]
|
| 213 |
+
ffi.lib.LLVMPY_PrintType.restype = c_void_p
|
| 214 |
+
|
| 215 |
+
ffi.lib.LLVMPY_TypeIsPointer.argtypes = [ffi.LLVMTypeRef]
|
| 216 |
+
ffi.lib.LLVMPY_TypeIsPointer.restype = c_bool
|
| 217 |
+
|
| 218 |
+
ffi.lib.LLVMPY_TypeIsArray.argtypes = [ffi.LLVMTypeRef]
|
| 219 |
+
ffi.lib.LLVMPY_TypeIsArray.restype = c_bool
|
| 220 |
+
|
| 221 |
+
ffi.lib.LLVMPY_TypeIsVector.argtypes = [ffi.LLVMTypeRef]
|
| 222 |
+
ffi.lib.LLVMPY_TypeIsVector.restype = c_bool
|
| 223 |
+
|
| 224 |
+
ffi.lib.LLVMPY_TypeIsStruct.argtypes = [ffi.LLVMTypeRef]
|
| 225 |
+
ffi.lib.LLVMPY_TypeIsStruct.restype = c_bool
|
| 226 |
+
|
| 227 |
+
ffi.lib.LLVMPY_TypeIsFunction.argtypes = [ffi.LLVMTypeRef]
|
| 228 |
+
ffi.lib.LLVMPY_TypeIsFunction.restype = c_bool
|
| 229 |
+
|
| 230 |
+
ffi.lib.LLVMPY_IsPackedStruct.argtypes = [ffi.LLVMTypeRef]
|
| 231 |
+
ffi.lib.LLVMPY_IsPackedStruct.restype = c_bool
|
| 232 |
+
|
| 233 |
+
ffi.lib.LLVMPY_IsOpaqueStruct.argtypes = [ffi.LLVMTypeRef]
|
| 234 |
+
ffi.lib.LLVMPY_IsOpaqueStruct.restype = c_bool
|
| 235 |
+
|
| 236 |
+
ffi.lib.LLVMPY_IsLiteralStruct.argtypes = [ffi.LLVMTypeRef]
|
| 237 |
+
ffi.lib.LLVMPY_IsLiteralStruct.restype = c_bool
|
| 238 |
+
|
| 239 |
+
ffi.lib.LLVMPY_GetReturnType.argtypes = [ffi.LLVMTypeRef]
|
| 240 |
+
ffi.lib.LLVMPY_GetReturnType.restype = ffi.LLVMTypeRef
|
| 241 |
+
|
| 242 |
+
ffi.lib.LLVMPY_CountParamTypes.argtypes = [ffi.LLVMTypeRef]
|
| 243 |
+
ffi.lib.LLVMPY_CountParamTypes.restype = c_uint
|
| 244 |
+
|
| 245 |
+
ffi.lib.LLVMPY_GetParamTypes.argtypes = [ffi.LLVMTypeRef,
|
| 246 |
+
POINTER(ffi.LLVMTypeRef)]
|
| 247 |
+
ffi.lib.LLVMPY_GetParamTypes.restype = None
|
| 248 |
+
|
| 249 |
+
ffi.lib.LLVMPY_IsFunctionVararg.argtypes = [ffi.LLVMTypeRef]
|
| 250 |
+
ffi.lib.LLVMPY_IsFunctionVararg.restype = c_bool
|
| 251 |
+
|
| 252 |
+
ffi.lib.LLVMPY_GetTypeKind.argtypes = [ffi.LLVMTypeRef]
|
| 253 |
+
ffi.lib.LLVMPY_GetTypeKind.restype = c_int
|
| 254 |
+
|
| 255 |
+
ffi.lib.LLVMPY_GetTypeElementCount.argtypes = [ffi.LLVMTypeRef]
|
| 256 |
+
ffi.lib.LLVMPY_GetTypeElementCount.restype = c_int
|
| 257 |
+
|
| 258 |
+
ffi.lib.LLVMPY_GetTypeBitWidth.argtypes = [ffi.LLVMTypeRef]
|
| 259 |
+
ffi.lib.LLVMPY_GetTypeBitWidth.restype = c_uint64
|
| 260 |
+
|
| 261 |
+
ffi.lib.LLVMPY_ElementIter.argtypes = [ffi.LLVMTypeRef]
|
| 262 |
+
ffi.lib.LLVMPY_ElementIter.restype = ffi.LLVMElementIterator
|
| 263 |
+
|
| 264 |
+
ffi.lib.LLVMPY_ElementIterNext.argtypes = [ffi.LLVMElementIterator]
|
| 265 |
+
ffi.lib.LLVMPY_ElementIterNext.restype = ffi.LLVMTypeRef
|
| 266 |
+
|
| 267 |
+
ffi.lib.LLVMPY_DisposeElementIter.argtypes = [ffi.LLVMElementIterator]
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/binding/value.py
ADDED
|
@@ -0,0 +1,632 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ctypes import (POINTER, byref, cast, c_char_p, c_double, c_int, c_size_t,
|
| 2 |
+
c_uint, c_uint64, c_bool, c_void_p)
|
| 3 |
+
import enum
|
| 4 |
+
|
| 5 |
+
from llvmlite.binding import ffi
|
| 6 |
+
from llvmlite.binding.common import _decode_string, _encode_string
|
| 7 |
+
from llvmlite.binding.typeref import TypeRef
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class Linkage(enum.IntEnum):
|
| 11 |
+
# The LLVMLinkage enum from llvm-c/Core.h
|
| 12 |
+
|
| 13 |
+
external = 0
|
| 14 |
+
available_externally = 1
|
| 15 |
+
linkonce_any = 2
|
| 16 |
+
linkonce_odr = 3
|
| 17 |
+
linkonce_odr_autohide = 4
|
| 18 |
+
weak_any = 5
|
| 19 |
+
weak_odr = 6
|
| 20 |
+
appending = 7
|
| 21 |
+
internal = 8
|
| 22 |
+
private = 9
|
| 23 |
+
dllimport = 10
|
| 24 |
+
dllexport = 11
|
| 25 |
+
external_weak = 12
|
| 26 |
+
ghost = 13
|
| 27 |
+
common = 14
|
| 28 |
+
linker_private = 15
|
| 29 |
+
linker_private_weak = 16
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class Visibility(enum.IntEnum):
|
| 33 |
+
# The LLVMVisibility enum from llvm-c/Core.h
|
| 34 |
+
|
| 35 |
+
default = 0
|
| 36 |
+
hidden = 1
|
| 37 |
+
protected = 2
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class StorageClass(enum.IntEnum):
|
| 41 |
+
# The LLVMDLLStorageClass enum from llvm-c/Core.h
|
| 42 |
+
|
| 43 |
+
default = 0
|
| 44 |
+
dllimport = 1
|
| 45 |
+
dllexport = 2
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class ValueKind(enum.IntEnum):
|
| 49 |
+
# The LLVMValueKind enum from llvm-c/Core.h
|
| 50 |
+
|
| 51 |
+
argument = 0
|
| 52 |
+
basic_block = 1
|
| 53 |
+
memory_use = 2
|
| 54 |
+
memory_def = 3
|
| 55 |
+
memory_phi = 4
|
| 56 |
+
|
| 57 |
+
function = 5
|
| 58 |
+
global_alias = 6
|
| 59 |
+
global_ifunc = 7
|
| 60 |
+
global_variable = 8
|
| 61 |
+
block_address = 9
|
| 62 |
+
constant_expr = 10
|
| 63 |
+
constant_array = 11
|
| 64 |
+
constant_struct = 12
|
| 65 |
+
constant_vector = 13
|
| 66 |
+
|
| 67 |
+
undef_value = 14
|
| 68 |
+
constant_aggregate_zero = 15
|
| 69 |
+
constant_data_array = 16
|
| 70 |
+
constant_data_vector = 17
|
| 71 |
+
constant_int = 18
|
| 72 |
+
constant_fp = 19
|
| 73 |
+
constant_pointer_null = 20
|
| 74 |
+
constant_token_none = 21
|
| 75 |
+
|
| 76 |
+
metadata_as_value = 22
|
| 77 |
+
inline_asm = 23
|
| 78 |
+
|
| 79 |
+
instruction = 24
|
| 80 |
+
poison_value = 25
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
class ValueRef(ffi.ObjectRef):
|
| 84 |
+
"""A weak reference to a LLVM value.
|
| 85 |
+
"""
|
| 86 |
+
|
| 87 |
+
def __init__(self, ptr, kind, parents):
|
| 88 |
+
self._kind = kind
|
| 89 |
+
self._parents = parents
|
| 90 |
+
ffi.ObjectRef.__init__(self, ptr)
|
| 91 |
+
|
| 92 |
+
def __str__(self):
|
| 93 |
+
with ffi.OutputString() as outstr:
|
| 94 |
+
ffi.lib.LLVMPY_PrintValueToString(self, outstr)
|
| 95 |
+
return str(outstr)
|
| 96 |
+
|
| 97 |
+
@property
|
| 98 |
+
def module(self):
|
| 99 |
+
"""
|
| 100 |
+
The module this function or global variable value was obtained from.
|
| 101 |
+
"""
|
| 102 |
+
return self._parents.get('module')
|
| 103 |
+
|
| 104 |
+
@property
|
| 105 |
+
def function(self):
|
| 106 |
+
"""
|
| 107 |
+
The function this argument or basic block value was obtained from.
|
| 108 |
+
"""
|
| 109 |
+
return self._parents.get('function')
|
| 110 |
+
|
| 111 |
+
@property
|
| 112 |
+
def block(self):
|
| 113 |
+
"""
|
| 114 |
+
The block this instruction value was obtained from.
|
| 115 |
+
"""
|
| 116 |
+
return self._parents.get('block')
|
| 117 |
+
|
| 118 |
+
@property
|
| 119 |
+
def instruction(self):
|
| 120 |
+
"""
|
| 121 |
+
The instruction this operand value was obtained from.
|
| 122 |
+
"""
|
| 123 |
+
return self._parents.get('instruction')
|
| 124 |
+
|
| 125 |
+
@property
|
| 126 |
+
def is_global(self):
|
| 127 |
+
return self._kind == 'global'
|
| 128 |
+
|
| 129 |
+
@property
|
| 130 |
+
def is_function(self):
|
| 131 |
+
return self._kind == 'function'
|
| 132 |
+
|
| 133 |
+
@property
|
| 134 |
+
def is_block(self):
|
| 135 |
+
return self._kind == 'block'
|
| 136 |
+
|
| 137 |
+
@property
|
| 138 |
+
def is_argument(self):
|
| 139 |
+
return self._kind == 'argument'
|
| 140 |
+
|
| 141 |
+
@property
|
| 142 |
+
def is_instruction(self):
|
| 143 |
+
return self._kind == 'instruction'
|
| 144 |
+
|
| 145 |
+
@property
|
| 146 |
+
def is_operand(self):
|
| 147 |
+
return self._kind == 'operand'
|
| 148 |
+
|
| 149 |
+
@property
|
| 150 |
+
def is_constant(self):
|
| 151 |
+
return bool(ffi.lib.LLVMPY_IsConstant(self))
|
| 152 |
+
|
| 153 |
+
@property
|
| 154 |
+
def value_kind(self):
|
| 155 |
+
return ValueKind(ffi.lib.LLVMPY_GetValueKind(self))
|
| 156 |
+
|
| 157 |
+
@property
|
| 158 |
+
def name(self):
|
| 159 |
+
return _decode_string(ffi.lib.LLVMPY_GetValueName(self))
|
| 160 |
+
|
| 161 |
+
@name.setter
|
| 162 |
+
def name(self, val):
|
| 163 |
+
ffi.lib.LLVMPY_SetValueName(self, _encode_string(val))
|
| 164 |
+
|
| 165 |
+
@property
|
| 166 |
+
def linkage(self):
|
| 167 |
+
return Linkage(ffi.lib.LLVMPY_GetLinkage(self))
|
| 168 |
+
|
| 169 |
+
@linkage.setter
|
| 170 |
+
def linkage(self, value):
|
| 171 |
+
if not isinstance(value, Linkage):
|
| 172 |
+
value = Linkage[value]
|
| 173 |
+
ffi.lib.LLVMPY_SetLinkage(self, value)
|
| 174 |
+
|
| 175 |
+
@property
|
| 176 |
+
def visibility(self):
|
| 177 |
+
return Visibility(ffi.lib.LLVMPY_GetVisibility(self))
|
| 178 |
+
|
| 179 |
+
@visibility.setter
|
| 180 |
+
def visibility(self, value):
|
| 181 |
+
if not isinstance(value, Visibility):
|
| 182 |
+
value = Visibility[value]
|
| 183 |
+
ffi.lib.LLVMPY_SetVisibility(self, value)
|
| 184 |
+
|
| 185 |
+
@property
|
| 186 |
+
def storage_class(self):
|
| 187 |
+
return StorageClass(ffi.lib.LLVMPY_GetDLLStorageClass(self))
|
| 188 |
+
|
| 189 |
+
@storage_class.setter
|
| 190 |
+
def storage_class(self, value):
|
| 191 |
+
if not isinstance(value, StorageClass):
|
| 192 |
+
value = StorageClass[value]
|
| 193 |
+
ffi.lib.LLVMPY_SetDLLStorageClass(self, value)
|
| 194 |
+
|
| 195 |
+
def add_function_attribute(self, attr):
|
| 196 |
+
"""Only works on function value
|
| 197 |
+
|
| 198 |
+
Parameters
|
| 199 |
+
-----------
|
| 200 |
+
attr : str
|
| 201 |
+
attribute name
|
| 202 |
+
"""
|
| 203 |
+
if not self.is_function:
|
| 204 |
+
raise ValueError('expected function value, got %s' % (self._kind,))
|
| 205 |
+
attrname = str(attr)
|
| 206 |
+
attrval = ffi.lib.LLVMPY_GetEnumAttributeKindForName(
|
| 207 |
+
_encode_string(attrname), len(attrname))
|
| 208 |
+
if attrval == 0:
|
| 209 |
+
raise ValueError('no such attribute {!r}'.format(attrname))
|
| 210 |
+
ffi.lib.LLVMPY_AddFunctionAttr(self, attrval)
|
| 211 |
+
|
| 212 |
+
@property
|
| 213 |
+
def type(self):
|
| 214 |
+
"""
|
| 215 |
+
This value's LLVM type.
|
| 216 |
+
"""
|
| 217 |
+
# XXX what does this return?
|
| 218 |
+
return TypeRef(ffi.lib.LLVMPY_TypeOf(self))
|
| 219 |
+
|
| 220 |
+
@property
|
| 221 |
+
def global_value_type(self):
|
| 222 |
+
"""
|
| 223 |
+
Uses ``LLVMGlobalGetValueType()``.
|
| 224 |
+
Needed for opaque pointers in globals.
|
| 225 |
+
> For globals, use getValueType().
|
| 226 |
+
See https://llvm.org/docs/OpaquePointers.html#migration-instructions
|
| 227 |
+
"""
|
| 228 |
+
assert self.is_global or self.is_function
|
| 229 |
+
return TypeRef(ffi.lib.LLVMPY_GlobalGetValueType(self))
|
| 230 |
+
|
| 231 |
+
@property
|
| 232 |
+
def is_declaration(self):
|
| 233 |
+
"""
|
| 234 |
+
Whether this value (presumably global) is defined in the current
|
| 235 |
+
module.
|
| 236 |
+
"""
|
| 237 |
+
if not (self.is_global or self.is_function):
|
| 238 |
+
raise ValueError('expected global or function value, got %s'
|
| 239 |
+
% (self._kind,))
|
| 240 |
+
return ffi.lib.LLVMPY_IsDeclaration(self)
|
| 241 |
+
|
| 242 |
+
@property
|
| 243 |
+
def attributes(self):
|
| 244 |
+
"""
|
| 245 |
+
Return an iterator over this value's attributes.
|
| 246 |
+
The iterator will yield a string for each attribute.
|
| 247 |
+
"""
|
| 248 |
+
itr = iter(())
|
| 249 |
+
if self.is_function:
|
| 250 |
+
it = ffi.lib.LLVMPY_FunctionAttributesIter(self)
|
| 251 |
+
itr = _AttributeListIterator(it)
|
| 252 |
+
elif self.is_instruction:
|
| 253 |
+
if self.opcode == 'call':
|
| 254 |
+
it = ffi.lib.LLVMPY_CallInstAttributesIter(self)
|
| 255 |
+
itr = _AttributeListIterator(it)
|
| 256 |
+
elif self.opcode == 'invoke':
|
| 257 |
+
it = ffi.lib.LLVMPY_InvokeInstAttributesIter(self)
|
| 258 |
+
itr = _AttributeListIterator(it)
|
| 259 |
+
elif self.is_global:
|
| 260 |
+
it = ffi.lib.LLVMPY_GlobalAttributesIter(self)
|
| 261 |
+
itr = _AttributeSetIterator(it)
|
| 262 |
+
elif self.is_argument:
|
| 263 |
+
it = ffi.lib.LLVMPY_ArgumentAttributesIter(self)
|
| 264 |
+
itr = _AttributeSetIterator(it)
|
| 265 |
+
return itr
|
| 266 |
+
|
| 267 |
+
@property
|
| 268 |
+
def blocks(self):
|
| 269 |
+
"""
|
| 270 |
+
Return an iterator over this function's blocks.
|
| 271 |
+
The iterator will yield a ValueRef for each block.
|
| 272 |
+
"""
|
| 273 |
+
if not self.is_function:
|
| 274 |
+
raise ValueError('expected function value, got %s' % (self._kind,))
|
| 275 |
+
it = ffi.lib.LLVMPY_FunctionBlocksIter(self)
|
| 276 |
+
parents = self._parents.copy()
|
| 277 |
+
parents.update(function=self)
|
| 278 |
+
return _BlocksIterator(it, parents)
|
| 279 |
+
|
| 280 |
+
@property
|
| 281 |
+
def arguments(self):
|
| 282 |
+
"""
|
| 283 |
+
Return an iterator over this function's arguments.
|
| 284 |
+
The iterator will yield a ValueRef for each argument.
|
| 285 |
+
"""
|
| 286 |
+
if not self.is_function:
|
| 287 |
+
raise ValueError('expected function value, got %s' % (self._kind,))
|
| 288 |
+
it = ffi.lib.LLVMPY_FunctionArgumentsIter(self)
|
| 289 |
+
parents = self._parents.copy()
|
| 290 |
+
parents.update(function=self)
|
| 291 |
+
return _ArgumentsIterator(it, parents)
|
| 292 |
+
|
| 293 |
+
@property
|
| 294 |
+
def instructions(self):
|
| 295 |
+
"""
|
| 296 |
+
Return an iterator over this block's instructions.
|
| 297 |
+
The iterator will yield a ValueRef for each instruction.
|
| 298 |
+
"""
|
| 299 |
+
if not self.is_block:
|
| 300 |
+
raise ValueError('expected block value, got %s' % (self._kind,))
|
| 301 |
+
it = ffi.lib.LLVMPY_BlockInstructionsIter(self)
|
| 302 |
+
parents = self._parents.copy()
|
| 303 |
+
parents.update(block=self)
|
| 304 |
+
return _InstructionsIterator(it, parents)
|
| 305 |
+
|
| 306 |
+
@property
|
| 307 |
+
def operands(self):
|
| 308 |
+
"""
|
| 309 |
+
Return an iterator over this instruction's operands.
|
| 310 |
+
The iterator will yield a ValueRef for each operand.
|
| 311 |
+
"""
|
| 312 |
+
if not self.is_instruction:
|
| 313 |
+
raise ValueError('expected instruction value, got %s'
|
| 314 |
+
% (self._kind,))
|
| 315 |
+
it = ffi.lib.LLVMPY_InstructionOperandsIter(self)
|
| 316 |
+
parents = self._parents.copy()
|
| 317 |
+
parents.update(instruction=self)
|
| 318 |
+
return _OperandsIterator(it, parents)
|
| 319 |
+
|
| 320 |
+
@property
|
| 321 |
+
def opcode(self):
|
| 322 |
+
if not self.is_instruction:
|
| 323 |
+
raise ValueError('expected instruction value, got %s'
|
| 324 |
+
% (self._kind,))
|
| 325 |
+
return ffi.ret_string(ffi.lib.LLVMPY_GetOpcodeName(self))
|
| 326 |
+
|
| 327 |
+
@property
|
| 328 |
+
def incoming_blocks(self):
|
| 329 |
+
"""
|
| 330 |
+
Return an iterator over this phi instruction's incoming blocks.
|
| 331 |
+
The iterator will yield a ValueRef for each block.
|
| 332 |
+
"""
|
| 333 |
+
if not self.is_instruction or self.opcode != 'phi':
|
| 334 |
+
raise ValueError('expected phi instruction value, got %s'
|
| 335 |
+
% (self._kind,))
|
| 336 |
+
it = ffi.lib.LLVMPY_PhiIncomingBlocksIter(self)
|
| 337 |
+
parents = self._parents.copy()
|
| 338 |
+
parents.update(instruction=self)
|
| 339 |
+
return _IncomingBlocksIterator(it, parents)
|
| 340 |
+
|
| 341 |
+
def get_constant_value(self, signed_int=False, round_fp=False):
|
| 342 |
+
"""
|
| 343 |
+
Return the constant value, either as a literal (when supported)
|
| 344 |
+
or as a string.
|
| 345 |
+
|
| 346 |
+
Parameters
|
| 347 |
+
-----------
|
| 348 |
+
signed_int : bool
|
| 349 |
+
if True and the constant is an integer, returns a signed version
|
| 350 |
+
round_fp : bool
|
| 351 |
+
if True and the constant is a floating point value, rounds the
|
| 352 |
+
result upon accuracy loss (e.g., when querying an fp128 value).
|
| 353 |
+
By default, raises an exception on accuracy loss
|
| 354 |
+
"""
|
| 355 |
+
if not self.is_constant:
|
| 356 |
+
raise ValueError('expected constant value, got %s'
|
| 357 |
+
% (self._kind,))
|
| 358 |
+
|
| 359 |
+
if self.value_kind == ValueKind.constant_int:
|
| 360 |
+
# Python integers are also arbitrary-precision
|
| 361 |
+
little_endian = c_bool(False)
|
| 362 |
+
words = ffi.lib.LLVMPY_GetConstantIntNumWords(self)
|
| 363 |
+
ptr = ffi.lib.LLVMPY_GetConstantIntRawValue(
|
| 364 |
+
self, byref(little_endian))
|
| 365 |
+
asbytes = bytes(cast(ptr, POINTER(c_uint64 * words)).contents)
|
| 366 |
+
return int.from_bytes(
|
| 367 |
+
asbytes,
|
| 368 |
+
('little' if little_endian.value else 'big'),
|
| 369 |
+
signed=signed_int,
|
| 370 |
+
)
|
| 371 |
+
elif self.value_kind == ValueKind.constant_fp:
|
| 372 |
+
# Convert floating-point values to double-precision (Python float)
|
| 373 |
+
accuracy_loss = c_bool(False)
|
| 374 |
+
value = ffi.lib.LLVMPY_GetConstantFPValue(self,
|
| 375 |
+
byref(accuracy_loss))
|
| 376 |
+
if accuracy_loss.value and not round_fp:
|
| 377 |
+
raise ValueError(
|
| 378 |
+
'Accuracy loss encountered in conversion of constant '
|
| 379 |
+
f'value {str(self)}')
|
| 380 |
+
|
| 381 |
+
return value
|
| 382 |
+
|
| 383 |
+
# Otherwise, return the IR string
|
| 384 |
+
return str(self)
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
class _ValueIterator(ffi.ObjectRef):
|
| 388 |
+
|
| 389 |
+
kind = None # derived classes must specify the Value kind value
|
| 390 |
+
# as class attribute
|
| 391 |
+
|
| 392 |
+
def __init__(self, ptr, parents):
|
| 393 |
+
ffi.ObjectRef.__init__(self, ptr)
|
| 394 |
+
# Keep parent objects (module, function, etc) alive
|
| 395 |
+
self._parents = parents
|
| 396 |
+
if self.kind is None:
|
| 397 |
+
raise NotImplementedError('%s must specify kind attribute'
|
| 398 |
+
% (type(self).__name__,))
|
| 399 |
+
|
| 400 |
+
def __next__(self):
|
| 401 |
+
vp = self._next()
|
| 402 |
+
if vp:
|
| 403 |
+
return ValueRef(vp, self.kind, self._parents)
|
| 404 |
+
else:
|
| 405 |
+
raise StopIteration
|
| 406 |
+
|
| 407 |
+
next = __next__
|
| 408 |
+
|
| 409 |
+
def __iter__(self):
|
| 410 |
+
return self
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
class _AttributeIterator(ffi.ObjectRef):
|
| 414 |
+
|
| 415 |
+
def __next__(self):
|
| 416 |
+
vp = self._next()
|
| 417 |
+
if vp:
|
| 418 |
+
return vp
|
| 419 |
+
else:
|
| 420 |
+
raise StopIteration
|
| 421 |
+
|
| 422 |
+
next = __next__
|
| 423 |
+
|
| 424 |
+
def __iter__(self):
|
| 425 |
+
return self
|
| 426 |
+
|
| 427 |
+
|
| 428 |
+
class _AttributeListIterator(_AttributeIterator):
|
| 429 |
+
|
| 430 |
+
def _dispose(self):
|
| 431 |
+
self._capi.LLVMPY_DisposeAttributeListIter(self)
|
| 432 |
+
|
| 433 |
+
def _next(self):
|
| 434 |
+
return ffi.ret_bytes(ffi.lib.LLVMPY_AttributeListIterNext(self))
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
class _AttributeSetIterator(_AttributeIterator):
|
| 438 |
+
|
| 439 |
+
def _dispose(self):
|
| 440 |
+
self._capi.LLVMPY_DisposeAttributeSetIter(self)
|
| 441 |
+
|
| 442 |
+
def _next(self):
|
| 443 |
+
return ffi.ret_bytes(ffi.lib.LLVMPY_AttributeSetIterNext(self))
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
class _BlocksIterator(_ValueIterator):
|
| 447 |
+
|
| 448 |
+
kind = 'block'
|
| 449 |
+
|
| 450 |
+
def _dispose(self):
|
| 451 |
+
self._capi.LLVMPY_DisposeBlocksIter(self)
|
| 452 |
+
|
| 453 |
+
def _next(self):
|
| 454 |
+
return ffi.lib.LLVMPY_BlocksIterNext(self)
|
| 455 |
+
|
| 456 |
+
|
| 457 |
+
class _ArgumentsIterator(_ValueIterator):
|
| 458 |
+
|
| 459 |
+
kind = 'argument'
|
| 460 |
+
|
| 461 |
+
def _dispose(self):
|
| 462 |
+
self._capi.LLVMPY_DisposeArgumentsIter(self)
|
| 463 |
+
|
| 464 |
+
def _next(self):
|
| 465 |
+
return ffi.lib.LLVMPY_ArgumentsIterNext(self)
|
| 466 |
+
|
| 467 |
+
|
| 468 |
+
class _InstructionsIterator(_ValueIterator):
|
| 469 |
+
|
| 470 |
+
kind = 'instruction'
|
| 471 |
+
|
| 472 |
+
def _dispose(self):
|
| 473 |
+
self._capi.LLVMPY_DisposeInstructionsIter(self)
|
| 474 |
+
|
| 475 |
+
def _next(self):
|
| 476 |
+
return ffi.lib.LLVMPY_InstructionsIterNext(self)
|
| 477 |
+
|
| 478 |
+
|
| 479 |
+
class _OperandsIterator(_ValueIterator):
|
| 480 |
+
|
| 481 |
+
kind = 'operand'
|
| 482 |
+
|
| 483 |
+
def _dispose(self):
|
| 484 |
+
self._capi.LLVMPY_DisposeOperandsIter(self)
|
| 485 |
+
|
| 486 |
+
def _next(self):
|
| 487 |
+
return ffi.lib.LLVMPY_OperandsIterNext(self)
|
| 488 |
+
|
| 489 |
+
|
| 490 |
+
class _IncomingBlocksIterator(_ValueIterator):
|
| 491 |
+
|
| 492 |
+
kind = 'block'
|
| 493 |
+
|
| 494 |
+
def _dispose(self):
|
| 495 |
+
self._capi.LLVMPY_DisposeIncomingBlocksIter(self)
|
| 496 |
+
|
| 497 |
+
def _next(self):
|
| 498 |
+
return ffi.lib.LLVMPY_IncomingBlocksIterNext(self)
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
# FFI
|
| 502 |
+
|
| 503 |
+
ffi.lib.LLVMPY_PrintValueToString.argtypes = [
|
| 504 |
+
ffi.LLVMValueRef,
|
| 505 |
+
POINTER(c_char_p)
|
| 506 |
+
]
|
| 507 |
+
|
| 508 |
+
ffi.lib.LLVMPY_GetGlobalParent.argtypes = [ffi.LLVMValueRef]
|
| 509 |
+
ffi.lib.LLVMPY_GetGlobalParent.restype = ffi.LLVMModuleRef
|
| 510 |
+
|
| 511 |
+
ffi.lib.LLVMPY_GetValueName.argtypes = [ffi.LLVMValueRef]
|
| 512 |
+
ffi.lib.LLVMPY_GetValueName.restype = c_char_p
|
| 513 |
+
|
| 514 |
+
ffi.lib.LLVMPY_SetValueName.argtypes = [ffi.LLVMValueRef, c_char_p]
|
| 515 |
+
|
| 516 |
+
ffi.lib.LLVMPY_TypeOf.argtypes = [ffi.LLVMValueRef]
|
| 517 |
+
ffi.lib.LLVMPY_TypeOf.restype = ffi.LLVMTypeRef
|
| 518 |
+
|
| 519 |
+
ffi.lib.LLVMPY_GlobalGetValueType.argtypes = [ffi.LLVMValueRef]
|
| 520 |
+
ffi.lib.LLVMPY_GlobalGetValueType.restype = ffi.LLVMTypeRef
|
| 521 |
+
|
| 522 |
+
ffi.lib.LLVMPY_GetTypeName.argtypes = [ffi.LLVMTypeRef]
|
| 523 |
+
ffi.lib.LLVMPY_GetTypeName.restype = c_void_p
|
| 524 |
+
|
| 525 |
+
ffi.lib.LLVMPY_GetLinkage.argtypes = [ffi.LLVMValueRef]
|
| 526 |
+
ffi.lib.LLVMPY_GetLinkage.restype = c_int
|
| 527 |
+
|
| 528 |
+
ffi.lib.LLVMPY_SetLinkage.argtypes = [ffi.LLVMValueRef, c_int]
|
| 529 |
+
|
| 530 |
+
ffi.lib.LLVMPY_GetVisibility.argtypes = [ffi.LLVMValueRef]
|
| 531 |
+
ffi.lib.LLVMPY_GetVisibility.restype = c_int
|
| 532 |
+
|
| 533 |
+
ffi.lib.LLVMPY_SetVisibility.argtypes = [ffi.LLVMValueRef, c_int]
|
| 534 |
+
|
| 535 |
+
ffi.lib.LLVMPY_GetDLLStorageClass.argtypes = [ffi.LLVMValueRef]
|
| 536 |
+
ffi.lib.LLVMPY_GetDLLStorageClass.restype = c_int
|
| 537 |
+
|
| 538 |
+
ffi.lib.LLVMPY_SetDLLStorageClass.argtypes = [ffi.LLVMValueRef, c_int]
|
| 539 |
+
|
| 540 |
+
ffi.lib.LLVMPY_GetEnumAttributeKindForName.argtypes = [c_char_p, c_size_t]
|
| 541 |
+
ffi.lib.LLVMPY_GetEnumAttributeKindForName.restype = c_uint
|
| 542 |
+
|
| 543 |
+
ffi.lib.LLVMPY_AddFunctionAttr.argtypes = [ffi.LLVMValueRef, c_uint]
|
| 544 |
+
|
| 545 |
+
ffi.lib.LLVMPY_IsDeclaration.argtypes = [ffi.LLVMValueRef]
|
| 546 |
+
ffi.lib.LLVMPY_IsDeclaration.restype = c_int
|
| 547 |
+
|
| 548 |
+
ffi.lib.LLVMPY_FunctionAttributesIter.argtypes = [ffi.LLVMValueRef]
|
| 549 |
+
ffi.lib.LLVMPY_FunctionAttributesIter.restype = ffi.LLVMAttributeListIterator
|
| 550 |
+
|
| 551 |
+
ffi.lib.LLVMPY_CallInstAttributesIter.argtypes = [ffi.LLVMValueRef]
|
| 552 |
+
ffi.lib.LLVMPY_CallInstAttributesIter.restype = ffi.LLVMAttributeListIterator
|
| 553 |
+
|
| 554 |
+
ffi.lib.LLVMPY_InvokeInstAttributesIter.argtypes = [ffi.LLVMValueRef]
|
| 555 |
+
ffi.lib.LLVMPY_InvokeInstAttributesIter.restype = ffi.LLVMAttributeListIterator
|
| 556 |
+
|
| 557 |
+
ffi.lib.LLVMPY_GlobalAttributesIter.argtypes = [ffi.LLVMValueRef]
|
| 558 |
+
ffi.lib.LLVMPY_GlobalAttributesIter.restype = ffi.LLVMAttributeSetIterator
|
| 559 |
+
|
| 560 |
+
ffi.lib.LLVMPY_ArgumentAttributesIter.argtypes = [ffi.LLVMValueRef]
|
| 561 |
+
ffi.lib.LLVMPY_ArgumentAttributesIter.restype = ffi.LLVMAttributeSetIterator
|
| 562 |
+
|
| 563 |
+
ffi.lib.LLVMPY_FunctionBlocksIter.argtypes = [ffi.LLVMValueRef]
|
| 564 |
+
ffi.lib.LLVMPY_FunctionBlocksIter.restype = ffi.LLVMBlocksIterator
|
| 565 |
+
|
| 566 |
+
ffi.lib.LLVMPY_FunctionArgumentsIter.argtypes = [ffi.LLVMValueRef]
|
| 567 |
+
ffi.lib.LLVMPY_FunctionArgumentsIter.restype = ffi.LLVMArgumentsIterator
|
| 568 |
+
|
| 569 |
+
ffi.lib.LLVMPY_BlockInstructionsIter.argtypes = [ffi.LLVMValueRef]
|
| 570 |
+
ffi.lib.LLVMPY_BlockInstructionsIter.restype = ffi.LLVMInstructionsIterator
|
| 571 |
+
|
| 572 |
+
ffi.lib.LLVMPY_InstructionOperandsIter.argtypes = [ffi.LLVMValueRef]
|
| 573 |
+
ffi.lib.LLVMPY_InstructionOperandsIter.restype = ffi.LLVMOperandsIterator
|
| 574 |
+
|
| 575 |
+
ffi.lib.LLVMPY_PhiIncomingBlocksIter.argtypes = [ffi.LLVMValueRef]
|
| 576 |
+
ffi.lib.LLVMPY_PhiIncomingBlocksIter.restype = ffi.LLVMIncomingBlocksIterator
|
| 577 |
+
|
| 578 |
+
ffi.lib.LLVMPY_DisposeAttributeListIter.argtypes = [
|
| 579 |
+
ffi.LLVMAttributeListIterator]
|
| 580 |
+
|
| 581 |
+
ffi.lib.LLVMPY_DisposeAttributeSetIter.argtypes = [ffi.LLVMAttributeSetIterator]
|
| 582 |
+
|
| 583 |
+
ffi.lib.LLVMPY_DisposeBlocksIter.argtypes = [ffi.LLVMBlocksIterator]
|
| 584 |
+
|
| 585 |
+
ffi.lib.LLVMPY_DisposeInstructionsIter.argtypes = [ffi.LLVMInstructionsIterator]
|
| 586 |
+
|
| 587 |
+
ffi.lib.LLVMPY_DisposeOperandsIter.argtypes = [ffi.LLVMOperandsIterator]
|
| 588 |
+
|
| 589 |
+
ffi.lib.LLVMPY_DisposeIncomingBlocksIter.argtypes = [
|
| 590 |
+
ffi.LLVMIncomingBlocksIterator]
|
| 591 |
+
|
| 592 |
+
ffi.lib.LLVMPY_AttributeListIterNext.argtypes = [ffi.LLVMAttributeListIterator]
|
| 593 |
+
ffi.lib.LLVMPY_AttributeListIterNext.restype = c_void_p
|
| 594 |
+
|
| 595 |
+
ffi.lib.LLVMPY_AttributeSetIterNext.argtypes = [ffi.LLVMAttributeSetIterator]
|
| 596 |
+
ffi.lib.LLVMPY_AttributeSetIterNext.restype = c_void_p
|
| 597 |
+
|
| 598 |
+
ffi.lib.LLVMPY_BlocksIterNext.argtypes = [ffi.LLVMBlocksIterator]
|
| 599 |
+
ffi.lib.LLVMPY_BlocksIterNext.restype = ffi.LLVMValueRef
|
| 600 |
+
|
| 601 |
+
ffi.lib.LLVMPY_ArgumentsIterNext.argtypes = [ffi.LLVMArgumentsIterator]
|
| 602 |
+
ffi.lib.LLVMPY_ArgumentsIterNext.restype = ffi.LLVMValueRef
|
| 603 |
+
|
| 604 |
+
ffi.lib.LLVMPY_InstructionsIterNext.argtypes = [ffi.LLVMInstructionsIterator]
|
| 605 |
+
ffi.lib.LLVMPY_InstructionsIterNext.restype = ffi.LLVMValueRef
|
| 606 |
+
|
| 607 |
+
ffi.lib.LLVMPY_OperandsIterNext.argtypes = [ffi.LLVMOperandsIterator]
|
| 608 |
+
ffi.lib.LLVMPY_OperandsIterNext.restype = ffi.LLVMValueRef
|
| 609 |
+
|
| 610 |
+
ffi.lib.LLVMPY_IncomingBlocksIterNext.argtypes = [
|
| 611 |
+
ffi.LLVMIncomingBlocksIterator]
|
| 612 |
+
ffi.lib.LLVMPY_IncomingBlocksIterNext.restype = ffi.LLVMValueRef
|
| 613 |
+
|
| 614 |
+
ffi.lib.LLVMPY_GetOpcodeName.argtypes = [ffi.LLVMValueRef]
|
| 615 |
+
ffi.lib.LLVMPY_GetOpcodeName.restype = c_void_p
|
| 616 |
+
|
| 617 |
+
ffi.lib.LLVMPY_IsConstant.argtypes = [ffi.LLVMValueRef]
|
| 618 |
+
ffi.lib.LLVMPY_IsConstant.restype = c_bool
|
| 619 |
+
|
| 620 |
+
ffi.lib.LLVMPY_GetValueKind.argtypes = [ffi.LLVMValueRef]
|
| 621 |
+
ffi.lib.LLVMPY_GetValueKind.restype = c_int
|
| 622 |
+
|
| 623 |
+
ffi.lib.LLVMPY_GetConstantIntRawValue.argtypes = [ffi.LLVMValueRef,
|
| 624 |
+
POINTER(c_bool)]
|
| 625 |
+
ffi.lib.LLVMPY_GetConstantIntRawValue.restype = POINTER(c_uint64)
|
| 626 |
+
|
| 627 |
+
ffi.lib.LLVMPY_GetConstantIntNumWords.argtypes = [ffi.LLVMValueRef]
|
| 628 |
+
ffi.lib.LLVMPY_GetConstantIntNumWords.restype = c_uint
|
| 629 |
+
|
| 630 |
+
ffi.lib.LLVMPY_GetConstantFPValue.argtypes = [ffi.LLVMValueRef,
|
| 631 |
+
POINTER(c_bool)]
|
| 632 |
+
ffi.lib.LLVMPY_GetConstantFPValue.restype = c_double
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/ir/__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This subpackage implements the LLVM IR classes in pure python
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from .types import *
|
| 6 |
+
from .values import *
|
| 7 |
+
from .module import *
|
| 8 |
+
from .builder import *
|
| 9 |
+
from .instructions import *
|
| 10 |
+
from .transforms import *
|
| 11 |
+
from .context import Context, global_context
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/llvmlite/ir/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (556 Bytes). View file
|
|
|