Skip to content

Commit 603bace

Browse files
committed
Drop typed pointer support and bump LLVM release to 16.
At the LLVM level, typed pointers are no longer supported going forward. This patch removes typed pointer support at the LLVM binding layer and bumps the LLVM release used to LLVM 16.
1 parent 2677283 commit 603bace

File tree

11 files changed

+19
-183
lines changed

11 files changed

+19
-183
lines changed

ffi/build.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,8 @@ def main_posix(kind, library_ext):
188188
else:
189189
(version, _) = out.split('.', 1)
190190
version = int(version)
191-
if version == 16:
192-
msg = ("Building with LLVM 16; note that LLVM 16 support is "
193-
"presently experimental")
194-
show_warning(msg)
195-
elif version != 15:
196-
197-
msg = ("Building llvmlite requires LLVM 15, got "
191+
if version not in (15, 16):
192+
msg = ("Building llvmlite requires LLVM 15 or 16, got "
198193
"{!r}. Be sure to set LLVM_CONFIG to the right executable "
199194
"path.\nRead the documentation at "
200195
"http://llvmlite.pydata.org/ for more information about "

ffi/core.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,15 @@ LLVMPY_CreateByteString(const char *buf, size_t len) {
2020
API_EXPORT(void)
2121
LLVMPY_DisposeString(const char *msg) { free(const_cast<char *>(msg)); }
2222

23-
// FIXME: Remove `enableOpaquePointers' once typed pointers are removed.
2423
API_EXPORT(LLVMContextRef)
25-
LLVMPY_GetGlobalContext(bool enableOpaquePointers) {
24+
LLVMPY_GetGlobalContext() {
2625
auto context = LLVMGetGlobalContext();
27-
LLVMContextSetOpaquePointers(context, enableOpaquePointers);
2826
return context;
2927
}
3028

31-
// FIXME: Remove `enableOpaquePointers' once typed pointers are removed.
3229
API_EXPORT(LLVMContextRef)
33-
LLVMPY_ContextCreate(bool enableOpaquePointers) {
30+
LLVMPY_ContextCreate() {
3431
LLVMContextRef context = LLVMContextCreate();
35-
LLVMContextSetOpaquePointers(context, enableOpaquePointers);
3632
return context;
3733
}
3834

ffi/core.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ LLVMPY_CreateByteString(const char *buf, size_t len);
3131
API_EXPORT(void)
3232
LLVMPY_DisposeString(const char *msg);
3333

34-
// FIXME: Remove `enableOpaquePointers' once typed pointers are removed.
3534
API_EXPORT(LLVMContextRef)
36-
LLVMPY_GetGlobalContext(bool enableOpaquePointers);
35+
LLVMPY_GetGlobalContext();
3736

38-
// FIXME: Remove `enableOpaquePointers' once typed pointers are removed.
3937
API_EXPORT(LLVMContextRef)
40-
LLVMPY_ContextCreate(bool enableOpaquePointers);
38+
LLVMPY_ContextCreate();
4139

4240
} /* end extern "C" */
4341

ffi/targets.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -121,26 +121,6 @@ LLVMPY_ABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
121121
return (long long)LLVMABIAlignmentOfType(TD, Ty);
122122
}
123123

124-
// FIXME: Remove me once typed pointers are no longer supported.
125-
API_EXPORT(long long)
126-
LLVMPY_ABISizeOfElementType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
127-
llvm::Type *tp = llvm::unwrap(Ty);
128-
if (!tp->isPointerTy())
129-
return -1;
130-
tp = tp->getPointerElementType();
131-
return (long long)LLVMABISizeOfType(TD, llvm::wrap(tp));
132-
}
133-
134-
// FIXME: Remove me once typed pointers are no longer supported.
135-
API_EXPORT(long long)
136-
LLVMPY_ABIAlignmentOfElementType(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
137-
llvm::Type *tp = llvm::unwrap(Ty);
138-
if (!tp->isPointerTy())
139-
return -1;
140-
tp = tp->getPointerElementType();
141-
return (long long)LLVMABIAlignmentOfType(TD, llvm::wrap(tp));
142-
}
143-
144124
API_EXPORT(LLVMTargetRef)
145125
LLVMPY_GetTargetFromTriple(const char *Triple, const char **ErrOut) {
146126
char *ErrorMessage;

ffi/type.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -144,22 +144,7 @@ API_EXPORT(uint64_t)
144144
LLVMPY_GetTypeBitWidth(LLVMTypeRef type) {
145145
llvm::Type *unwrapped = llvm::unwrap(type);
146146
auto size = unwrapped->getPrimitiveSizeInBits();
147-
return size.getFixedSize();
148-
}
149-
150-
// FIXME: Remove me once typed pointers support is removed.
151-
API_EXPORT(LLVMTypeRef)
152-
LLVMPY_GetElementType(LLVMTypeRef type) {
153-
llvm::Type *unwrapped = llvm::unwrap(type);
154-
llvm::PointerType *ty = llvm::dyn_cast<llvm::PointerType>(unwrapped);
155-
if (ty != nullptr) {
156-
#if LLVM_VERSION_MAJOR < 14
157-
return llvm::wrap(ty->getElementType());
158-
#else
159-
return llvm::wrap(ty->getPointerElementType());
160-
#endif
161-
}
162-
return nullptr;
147+
return size.getFixedValue();
163148
}
164149

165150
API_EXPORT(LLVMTypeRef)

llvmlite/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
__version__ = get_versions()['version']
33
del get_versions
44

5-
# FIXME: Remove me once typed pointers are no longer supported.
6-
# Opaque pointers unconditionally required for later LLVM versions
7-
opaque_pointers_enabled = True
85
# We default to IR layer typed pointers being enabled, since they're needed in
96
# the most common usage scenarios with later LLVMs.
107
def _ir_layer_typed_pointers_enabled():

llvmlite/binding/context.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
from llvmlite.binding import ffi
22

3-
# FIXME: Remove me once typed pointers are no longer supported.
4-
from llvmlite import opaque_pointers_enabled
5-
from ctypes import c_bool
6-
73

84
def create_context():
95
return ContextRef(
10-
ffi.lib.LLVMPY_ContextCreate(opaque_pointers_enabled))
6+
ffi.lib.LLVMPY_ContextCreate())
117

128

139
def get_global_context():
1410
return GlobalContextRef(
15-
ffi.lib.LLVMPY_GetGlobalContext(opaque_pointers_enabled))
11+
ffi.lib.LLVMPY_GetGlobalContext())
1612

1713

1814
class ContextRef(ffi.ObjectRef):
@@ -28,12 +24,8 @@ def _dispose(self):
2824
pass
2925

3026

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

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

3931
ffi.lib.LLVMPY_ContextDispose.argtypes = [ffi.LLVMContextRef]

llvmlite/binding/targets.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
from llvmlite.binding.common import _decode_string, _encode_string
88
from collections import namedtuple
99

10-
# FIXME: Remove `opaque_pointers_enabled` once typed pointers are no longer
11-
# supported.
12-
from llvmlite import opaque_pointers_enabled
13-
1410
Triple = namedtuple('Triple', ['Arch', 'SubArch', 'Vendor',
1511
'OS', 'Env', 'ObjectFormat'])
1612

@@ -202,30 +198,6 @@ def get_abi_alignment(self, ty):
202198
"""
203199
return ffi.lib.LLVMPY_ABIAlignmentOfType(self, ty)
204200

205-
def get_pointee_abi_size(self, ty):
206-
"""
207-
Get ABI size of pointee type of LLVM pointer type *ty*.
208-
"""
209-
if opaque_pointers_enabled:
210-
raise RuntimeError("Cannot get pointee type in opaque pointer "
211-
"mode.")
212-
size = ffi.lib.LLVMPY_ABISizeOfElementType(self, ty)
213-
if size == -1:
214-
raise RuntimeError("Not a pointer type: %s" % (ty,))
215-
return size
216-
217-
def get_pointee_abi_alignment(self, ty):
218-
"""
219-
Get minimum ABI alignment of pointee type of LLVM pointer type *ty*.
220-
"""
221-
if opaque_pointers_enabled:
222-
raise RuntimeError("Cannot get pointee type in opaque pointer "
223-
"mode.")
224-
size = ffi.lib.LLVMPY_ABIAlignmentOfElementType(self, ty)
225-
if size == -1:
226-
raise RuntimeError("Not a pointer type: %s" % (ty,))
227-
return size
228-
229201

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

443-
# FIXME: Remove me once typed pointers are no longer supported.
444-
ffi.lib.LLVMPY_ABISizeOfElementType.argtypes = [ffi.LLVMTargetDataRef,
445-
ffi.LLVMTypeRef]
446-
ffi.lib.LLVMPY_ABISizeOfElementType.restype = c_longlong
447-
448-
# FIXME: Remove me once typed pointers are no longer supported.
449-
ffi.lib.LLVMPY_ABIAlignmentOfElementType.argtypes = [ffi.LLVMTargetDataRef,
450-
ffi.LLVMTypeRef]
451-
ffi.lib.LLVMPY_ABIAlignmentOfElementType.restype = c_longlong
452-
453415
ffi.lib.LLVMPY_GetTargetFromTriple.argtypes = [c_char_p, POINTER(c_char_p)]
454416
ffi.lib.LLVMPY_GetTargetFromTriple.restype = ffi.LLVMTargetRef
455417

llvmlite/binding/typeref.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
from llvmlite import ir
55
from llvmlite.binding import ffi
66

7-
# FIXME: Remove `opaque_pointers_enabled' when TP's are removed.
8-
from llvmlite import opaque_pointers_enabled
9-
107

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

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

229-
# FIXME: Remove me once typed pointers support is removed.
230-
ffi.lib.LLVMPY_GetElementType.argtypes = [ffi.LLVMTypeRef]
231-
ffi.lib.LLVMPY_GetElementType.restype = ffi.LLVMTypeRef
232-
233226
ffi.lib.LLVMPY_TypeIsPointer.argtypes = [ffi.LLVMTypeRef]
234227
ffi.lib.LLVMPY_TypeIsPointer.restype = c_bool
235228

llvmlite/tests/test_binding.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
from llvmlite.binding import ffi
1919
from llvmlite.tests import TestCase
2020

21-
# FIXME: Remove me once typed pointers are no longer supported.
22-
from llvmlite import opaque_pointers_enabled
23-
2421
# arvm7l needs extra ABI symbols to link successfully
2522
if platform.machine() == 'armv7l':
2623
llvm.load_library_permanently('libgcc_s.so.1')
@@ -1655,12 +1652,7 @@ def test_type_printing_struct(self):
16551652
mod = self.module()
16561653
st = mod.get_global_variable("glob_struct")
16571654
self.assertTrue(st.type.is_pointer)
1658-
# FIXME: Remove `else' once TP are no longer supported.
1659-
if opaque_pointers_enabled:
1660-
self.assertIsNotNone(re.match(r'ptr', str(st.type)))
1661-
else:
1662-
self.assertIsNotNone(re.match(r'%struct\.glob_type(\.[\d]+)?\*',
1663-
str(st.type)))
1655+
self.assertIsNotNone(re.match(r'ptr', str(st.type)))
16641656
self.assertIsNotNone(re.match(
16651657
r"%struct\.glob_type(\.[\d]+)? = type { i64, \[2 x i64\] }",
16661658
str(st.global_value_type)))
@@ -1849,11 +1841,7 @@ def test_constant_as_string(self):
18491841
inst = list(list(func.blocks)[0].instructions)[0]
18501842
arg = list(inst.operands)[0]
18511843
self.assertTrue(arg.is_constant)
1852-
# FIXME: Remove `else' once TP are no longer supported.
1853-
if opaque_pointers_enabled:
1854-
self.assertEqual(arg.get_constant_value(), 'ptr null')
1855-
else:
1856-
self.assertEqual(arg.get_constant_value(), 'i64* null')
1844+
self.assertEqual(arg.get_constant_value(), 'ptr null')
18571845

18581846
def test_incoming_phi_blocks(self):
18591847
mod = self.module(asm_phi_blocks)
@@ -1958,12 +1946,7 @@ def test_vararg_function(self):
19581946
self.assertTrue(func.type.is_pointer)
19591947
with self.assertRaises(ValueError) as raises:
19601948
func.type.is_function_vararg
1961-
# FIXME: Remove `else' once TP are no longer supported.
1962-
if opaque_pointers_enabled:
1963-
self.assertIn("Type ptr is not a function", str(raises.exception))
1964-
else:
1965-
self.assertIn("Type i32 (i32, i32)* is not a function",
1966-
str(raises.exception))
1949+
self.assertIn("Type ptr is not a function", str(raises.exception))
19671950

19681951
def test_function_typeref_as_ir(self):
19691952
mod = self.module()

0 commit comments

Comments
 (0)