Skip to content

Commit

Permalink
Drop typed pointer support and bump LLVM release to 16.
Browse files Browse the repository at this point in the history
At the LLVM level, typed pointers are no longer supported going forward.

This ticket removes typed pointer support at the LLVM binding layer and
bumps the LLVM release used to LLVM 16.

This builds on top of numba#1159.
  • Loading branch information
rj-jesus committed Feb 20, 2025
1 parent f8b24e1 commit b6efca6
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 181 deletions.
9 changes: 2 additions & 7 deletions ffi/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,8 @@ def main_posix(kind, library_ext):
else:
(version, _) = out.split('.', 1)
version = int(version)
if version == 16:
msg = ("Building with LLVM 16; note that LLVM 16 support is "
"presently experimental")
show_warning(msg)
elif version != 15:

msg = ("Building llvmlite requires LLVM 15, got "
if version not in (15, 16):
msg = ("Building llvmlite requires LLVM 15 or 16, got "
"{!r}. Be sure to set LLVM_CONFIG to the right executable "
"path.\nRead the documentation at "
"http://llvmlite.pydata.org/ for more information about "
Expand Down
8 changes: 2 additions & 6 deletions ffi/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,15 @@ LLVMPY_CreateByteString(const char *buf, size_t len) {
API_EXPORT(void)
LLVMPY_DisposeString(const char *msg) { free(const_cast<char *>(msg)); }

// FIXME: Remove `enableOpaquePointers' once typed pointers are removed.
API_EXPORT(LLVMContextRef)
LLVMPY_GetGlobalContext(bool enableOpaquePointers) {
LLVMPY_GetGlobalContext() {
auto context = LLVMGetGlobalContext();
LLVMContextSetOpaquePointers(context, enableOpaquePointers);
return context;
}

// FIXME: Remove `enableOpaquePointers' once typed pointers are removed.
API_EXPORT(LLVMContextRef)
LLVMPY_ContextCreate(bool enableOpaquePointers) {
LLVMPY_ContextCreate() {
LLVMContextRef context = LLVMContextCreate();
LLVMContextSetOpaquePointers(context, enableOpaquePointers);
return context;
}

Expand Down
6 changes: 2 additions & 4 deletions ffi/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ LLVMPY_CreateByteString(const char *buf, size_t len);
API_EXPORT(void)
LLVMPY_DisposeString(const char *msg);

// FIXME: Remove `enableOpaquePointers' once typed pointers are removed.
API_EXPORT(LLVMContextRef)
LLVMPY_GetGlobalContext(bool enableOpaquePointers);
LLVMPY_GetGlobalContext();

// FIXME: Remove `enableOpaquePointers' once typed pointers are removed.
API_EXPORT(LLVMContextRef)
LLVMPY_ContextCreate(bool enableOpaquePointers);
LLVMPY_ContextCreate();

} /* end extern "C" */

Expand Down
20 changes: 0 additions & 20 deletions ffi/targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,6 @@ LLVMPY_ABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
return (long long)LLVMABIAlignmentOfType(TD, Ty);
}

// FIXME: Remove me once typed pointers are no longer supported.
API_EXPORT(long long)
LLVMPY_ABISizeOfElementType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
llvm::Type *tp = llvm::unwrap(Ty);
if (!tp->isPointerTy())
return -1;
tp = tp->getPointerElementType();
return (long long)LLVMABISizeOfType(TD, llvm::wrap(tp));
}

// FIXME: Remove me once typed pointers are no longer supported.
API_EXPORT(long long)
LLVMPY_ABIAlignmentOfElementType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
llvm::Type *tp = llvm::unwrap(Ty);
if (!tp->isPointerTy())
return -1;
tp = tp->getPointerElementType();
return (long long)LLVMABIAlignmentOfType(TD, llvm::wrap(tp));
}

API_EXPORT(LLVMTargetRef)
LLVMPY_GetTargetFromTriple(const char *Triple, const char **ErrOut) {
char *ErrorMessage;
Expand Down
17 changes: 1 addition & 16 deletions ffi/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,7 @@ API_EXPORT(uint64_t)
LLVMPY_GetTypeBitWidth(LLVMTypeRef type) {
llvm::Type *unwrapped = llvm::unwrap(type);
auto size = unwrapped->getPrimitiveSizeInBits();
return size.getFixedSize();
}

// FIXME: Remove me once typed pointers support is removed.
API_EXPORT(LLVMTypeRef)
LLVMPY_GetElementType(LLVMTypeRef type) {
llvm::Type *unwrapped = llvm::unwrap(type);
llvm::PointerType *ty = llvm::dyn_cast<llvm::PointerType>(unwrapped);
if (ty != nullptr) {
#if LLVM_VERSION_MAJOR < 14
return llvm::wrap(ty->getElementType());
#else
return llvm::wrap(ty->getPointerElementType());
#endif
}
return nullptr;
return size.getFixedValue();
}

API_EXPORT(LLVMTypeRef)
Expand Down
3 changes: 0 additions & 3 deletions llvmlite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
__version__ = get_versions()['version']
del get_versions

# FIXME: Remove me once typed pointers are no longer supported.
# Let's enable opaque pointers unconditionally.
opaque_pointers_enabled = True
# Note: We should probably default to lazy opaque pointers disabled, but I want
# us to be able to test with Numba directly.
def _lazy_opaque_pointers_enabled():
Expand Down
10 changes: 2 additions & 8 deletions llvmlite/binding/context.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
from llvmlite.binding import ffi

# FIXME: Remove me once typed pointers are no longer supported.
from llvmlite import opaque_pointers_enabled
from ctypes import c_bool


def create_context():
return ContextRef(
ffi.lib.LLVMPY_ContextCreate(opaque_pointers_enabled))
ffi.lib.LLVMPY_ContextCreate())


def get_global_context():
return GlobalContextRef(
ffi.lib.LLVMPY_GetGlobalContext(opaque_pointers_enabled))
ffi.lib.LLVMPY_GetGlobalContext())


class ContextRef(ffi.ObjectRef):
Expand All @@ -28,12 +26,8 @@ def _dispose(self):
pass


# FIXME: Remove argtypes once typed pointers are no longer supported.
ffi.lib.LLVMPY_GetGlobalContext.argtypes = [c_bool]
ffi.lib.LLVMPY_GetGlobalContext.restype = ffi.LLVMContextRef

# FIXME: Remove argtypes once typed pointers are no longer supported.
ffi.lib.LLVMPY_ContextCreate.argtypes = [c_bool]
ffi.lib.LLVMPY_ContextCreate.restype = ffi.LLVMContextRef

ffi.lib.LLVMPY_ContextDispose.argtypes = [ffi.LLVMContextRef]
38 changes: 0 additions & 38 deletions llvmlite/binding/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
from llvmlite.binding.common import _decode_string, _encode_string
from collections import namedtuple

# FIXME: Remove `opaque_pointers_enabled` once typed pointers are no longer
# supported.
from llvmlite import opaque_pointers_enabled

Triple = namedtuple('Triple', ['Arch', 'SubArch', 'Vendor',
'OS', 'Env', 'ObjectFormat'])

Expand Down Expand Up @@ -202,30 +198,6 @@ def get_abi_alignment(self, ty):
"""
return ffi.lib.LLVMPY_ABIAlignmentOfType(self, ty)

def get_pointee_abi_size(self, ty):
"""
Get ABI size of pointee type of LLVM pointer type *ty*.
"""
if opaque_pointers_enabled:
raise RuntimeError("Cannot get pointee type in opaque pointer "
"mode.")
size = ffi.lib.LLVMPY_ABISizeOfElementType(self, ty)
if size == -1:
raise RuntimeError("Not a pointer type: %s" % (ty,))
return size

def get_pointee_abi_alignment(self, ty):
"""
Get minimum ABI alignment of pointee type of LLVM pointer type *ty*.
"""
if opaque_pointers_enabled:
raise RuntimeError("Cannot get pointee type in opaque pointer "
"mode.")
size = ffi.lib.LLVMPY_ABIAlignmentOfElementType(self, ty)
if size == -1:
raise RuntimeError("Not a pointer type: %s" % (ty,))
return size


RELOC = frozenset(['default', 'static', 'pic', 'dynamicnopic'])
CODEMODEL = frozenset(['default', 'jitdefault', 'small', 'kernel', 'medium',
Expand Down Expand Up @@ -440,16 +412,6 @@ def has_svml():
ffi.LLVMTypeRef]
ffi.lib.LLVMPY_ABIAlignmentOfType.restype = c_longlong

# FIXME: Remove me once typed pointers are no longer supported.
ffi.lib.LLVMPY_ABISizeOfElementType.argtypes = [ffi.LLVMTargetDataRef,
ffi.LLVMTypeRef]
ffi.lib.LLVMPY_ABISizeOfElementType.restype = c_longlong

# FIXME: Remove me once typed pointers are no longer supported.
ffi.lib.LLVMPY_ABIAlignmentOfElementType.argtypes = [ffi.LLVMTargetDataRef,
ffi.LLVMTypeRef]
ffi.lib.LLVMPY_ABIAlignmentOfElementType.restype = c_longlong

ffi.lib.LLVMPY_GetTargetFromTriple.argtypes = [c_char_p, POINTER(c_char_p)]
ffi.lib.LLVMPY_GetTargetFromTriple.restype = ffi.LLVMTargetRef

Expand Down
9 changes: 1 addition & 8 deletions llvmlite/binding/typeref.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
from llvmlite import ir
from llvmlite.binding import ffi

# FIXME: Remove `opaque_pointers_enabled' when TP's are removed.
from llvmlite import opaque_pointers_enabled


class TypeKind(enum.IntEnum):
# The LLVMTypeKind enum from llvm-c/Core.h
Expand Down Expand Up @@ -108,7 +105,7 @@ def elements(self):
"""
Returns iterator over enclosing types
"""
if self.is_pointer and opaque_pointers_enabled:
if self.is_pointer:
raise ValueError("Type {} doesn't contain elements.".format(self))
return _TypeListIterator(ffi.lib.LLVMPY_ElementIter(self))

Expand Down Expand Up @@ -226,10 +223,6 @@ def _next(self):
ffi.lib.LLVMPY_PrintType.argtypes = [ffi.LLVMTypeRef]
ffi.lib.LLVMPY_PrintType.restype = c_void_p

# FIXME: Remove me once typed pointers support is removed.
ffi.lib.LLVMPY_GetElementType.argtypes = [ffi.LLVMTypeRef]
ffi.lib.LLVMPY_GetElementType.restype = ffi.LLVMTypeRef

ffi.lib.LLVMPY_TypeIsPointer.argtypes = [ffi.LLVMTypeRef]
ffi.lib.LLVMPY_TypeIsPointer.restype = c_bool

Expand Down
23 changes: 3 additions & 20 deletions llvmlite/tests/test_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
from llvmlite.binding import ffi
from llvmlite.tests import TestCase

# FIXME: Remove me once typed pointers are no longer supported.
from llvmlite import opaque_pointers_enabled

# arvm7l needs extra ABI symbols to link successfully
if platform.machine() == 'armv7l':
llvm.load_library_permanently('libgcc_s.so.1')
Expand Down Expand Up @@ -1655,12 +1652,7 @@ def test_type_printing_struct(self):
mod = self.module()
st = mod.get_global_variable("glob_struct")
self.assertTrue(st.type.is_pointer)
# FIXME: Remove `else' once TP are no longer supported.
if opaque_pointers_enabled:
self.assertIsNotNone(re.match(r'ptr', str(st.type)))
else:
self.assertIsNotNone(re.match(r'%struct\.glob_type(\.[\d]+)?\*',
str(st.type)))
self.assertIsNotNone(re.match(r'ptr', str(st.type)))
self.assertIsNotNone(re.match(
r"%struct\.glob_type(\.[\d]+)? = type { i64, \[2 x i64\] }",
str(st.global_value_type)))
Expand Down Expand Up @@ -1849,11 +1841,7 @@ def test_constant_as_string(self):
inst = list(list(func.blocks)[0].instructions)[0]
arg = list(inst.operands)[0]
self.assertTrue(arg.is_constant)
# FIXME: Remove `else' once TP are no longer supported.
if opaque_pointers_enabled:
self.assertEqual(arg.get_constant_value(), 'ptr null')
else:
self.assertEqual(arg.get_constant_value(), 'i64* null')
self.assertEqual(arg.get_constant_value(), 'ptr null')

def test_incoming_phi_blocks(self):
mod = self.module(asm_phi_blocks)
Expand Down Expand Up @@ -1958,12 +1946,7 @@ def test_vararg_function(self):
self.assertTrue(func.type.is_pointer)
with self.assertRaises(ValueError) as raises:
func.type.is_function_vararg
# FIXME: Remove `else' once TP are no longer supported.
if opaque_pointers_enabled:
self.assertIn("Type ptr is not a function", str(raises.exception))
else:
self.assertIn("Type i32 (i32, i32)* is not a function",
str(raises.exception))
self.assertIn("Type ptr is not a function", str(raises.exception))

def test_function_typeref_as_ir(self):
mod = self.module()
Expand Down
Loading

0 comments on commit b6efca6

Please sign in to comment.