So, basically I’m trying to compile LLVM code in Python that does sum two fp128 numbers. However the code keeps exiting with error Segmentation fault (core dumped)
. It’s a bit frustrating, because when I change fp128 to double everything works fine. I’m not sure where to look for the solution could smn pls help me. thanks.
#!/usr/bin/env python
# coding=utf-8
from __future__ import print_function
from ctypes import CFUNCTYPE, c_longdouble, c_double
import llvmlite.binding as llvm
llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmprinter()
strmod = """
; ModuleID = "fdadd"
target triple = "unknown-unknown-unknown"
target datalayout = ""
define double @"fpadd"(fp128 %a, fp128 %b)
{
entry:
%c = fadd fp128 %a, %b
ret double %c
}
"""
print("-----------------------------------------")
#assembly llvm ir
assmod = llvm.parse_assembly(strmod)
assmod.verify()
print("--parse assembly")
target = llvm.Target.from_default_triple()
target_machine = target.create_target_machine()
engine = llvm.create_mcjit_compiler(assmod, target_machine)
engine.finalize_object()
print(engine)
# Look up the function pointer (a Python int)
#llvm execution engine call llvm IR function(or dsl function)
func_ptr = engine.get_function_address("fpadd")
print('func_ptr is:',func_ptr)
el_type = c_longdouble
# Run the function via ctypes
cfunc = CFUNCTYPE(c_double, el_type, el_type)(func_ptr)
print (cfunc.argtypes)
print (cfunc.restype)
a = el_type(22)
t = cfunc(a,a) # Segmentation fault (core dumped)
print(t)