llvmlite 0.43.0rc1__cp311-cp311-win_amd64.whl → 0.44.0rc1__cp311-cp311-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of llvmlite might be problematic. Click here for more details.
- llvmlite/__init__.py +7 -0
- llvmlite/_version.py +2 -2
- llvmlite/binding/__init__.py +1 -0
- llvmlite/binding/context.py +12 -2
- llvmlite/binding/ffi.py +6 -1
- llvmlite/binding/llvmlite.dll +0 -0
- llvmlite/binding/newpassmanagers.py +357 -0
- llvmlite/binding/passmanagers.py +25 -18
- llvmlite/binding/targets.py +75 -5
- llvmlite/binding/typeref.py +88 -1
- llvmlite/binding/value.py +14 -0
- llvmlite/ir/builder.py +7 -6
- llvmlite/ir/context.py +2 -2
- llvmlite/ir/instructions.py +52 -25
- llvmlite/ir/types.py +137 -17
- llvmlite/ir/values.py +2 -2
- llvmlite/tests/test_binding.py +663 -40
- llvmlite/tests/test_ir.py +403 -146
- llvmlite/tests/test_refprune.py +179 -6
- {llvmlite-0.43.0rc1.dist-info → llvmlite-0.44.0rc1.dist-info}/METADATA +7 -6
- llvmlite-0.44.0rc1.dist-info/RECORD +46 -0
- {llvmlite-0.43.0rc1.dist-info → llvmlite-0.44.0rc1.dist-info}/WHEEL +1 -1
- llvmlite-0.43.0rc1.dist-info/RECORD +0 -45
- {llvmlite-0.43.0rc1.dist-info → llvmlite-0.44.0rc1.dist-info}/LICENSE +0 -0
- {llvmlite-0.43.0rc1.dist-info → llvmlite-0.44.0rc1.dist-info}/LICENSE.thirdparty +0 -0
- {llvmlite-0.43.0rc1.dist-info → llvmlite-0.44.0rc1.dist-info}/top_level.txt +0 -0
llvmlite/tests/test_ir.py
CHANGED
|
@@ -13,6 +13,9 @@ from . import TestCase
|
|
|
13
13
|
from llvmlite import ir
|
|
14
14
|
from llvmlite import binding as llvm
|
|
15
15
|
|
|
16
|
+
# FIXME: Remove me once typed pointers are no longer supported.
|
|
17
|
+
from llvmlite import opaque_pointers_enabled
|
|
18
|
+
|
|
16
19
|
|
|
17
20
|
int1 = ir.IntType(1)
|
|
18
21
|
int8 = ir.IntType(8)
|
|
@@ -120,7 +123,11 @@ class TestBase(TestCase):
|
|
|
120
123
|
|
|
121
124
|
class TestFunction(TestBase):
|
|
122
125
|
|
|
123
|
-
|
|
126
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
127
|
+
proto = \
|
|
128
|
+
"""i32 @"my_func"(i32 %".1", i32 %".2", double %".3", ptr %".4")""" \
|
|
129
|
+
if opaque_pointers_enabled else \
|
|
130
|
+
"""i32 @"my_func"(i32 %".1", i32 %".2", double %".3", i32* %".4")"""
|
|
124
131
|
|
|
125
132
|
def test_declare(self):
|
|
126
133
|
# A simple declaration
|
|
@@ -139,11 +146,19 @@ class TestFunction(TestBase):
|
|
|
139
146
|
pers = ir.Function(self.module(), tp_pers, '__gxx_personality_v0')
|
|
140
147
|
func.attributes.personality = pers
|
|
141
148
|
asm = self.descr(func).strip()
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
149
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
150
|
+
if opaque_pointers_enabled:
|
|
151
|
+
self.assertEqual(asm,
|
|
152
|
+
("declare %s alwaysinline convergent optsize "
|
|
153
|
+
"alignstack(16) "
|
|
154
|
+
"personality ptr @\"__gxx_personality_v0\"") %
|
|
155
|
+
self.proto)
|
|
156
|
+
else:
|
|
157
|
+
self.assertEqual(asm,
|
|
158
|
+
("declare %s alwaysinline convergent optsize "
|
|
159
|
+
"alignstack(16) personality "
|
|
160
|
+
"i8 (...)* @\"__gxx_personality_v0\"") %
|
|
161
|
+
self.proto)
|
|
147
162
|
# Check pickling
|
|
148
163
|
self.assert_pickle_correctly(func)
|
|
149
164
|
|
|
@@ -157,9 +172,15 @@ class TestFunction(TestBase):
|
|
|
157
172
|
func.args[3].add_attribute("nonnull")
|
|
158
173
|
func.return_value.add_attribute("noalias")
|
|
159
174
|
asm = self.descr(func).strip()
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
175
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
176
|
+
if opaque_pointers_enabled:
|
|
177
|
+
self.assertEqual(asm,
|
|
178
|
+
"""declare noalias i32 @"my_func"(i32 zeroext %".1", i32 dereferenceable(5) dereferenceable_or_null(10) %".2", double %".3", ptr nonnull align 4 %".4")""" # noqa E501
|
|
179
|
+
)
|
|
180
|
+
else:
|
|
181
|
+
self.assertEqual(asm,
|
|
182
|
+
"""declare noalias i32 @"my_func"(i32 zeroext %".1", i32 dereferenceable(5) dereferenceable_or_null(10) %".2", double %".3", i32* nonnull align 4 %".4")""" # noqa E501
|
|
183
|
+
)
|
|
163
184
|
# Check pickling
|
|
164
185
|
self.assert_pickle_correctly(func)
|
|
165
186
|
|
|
@@ -263,10 +284,17 @@ class TestFunction(TestBase):
|
|
|
263
284
|
assume = module.declare_intrinsic('llvm.assume')
|
|
264
285
|
self.check_descr(self.descr(powi).strip(), """\
|
|
265
286
|
declare double @"llvm.powi.f64"(double %".1", i32 %".2")""")
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
287
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
288
|
+
if opaque_pointers_enabled:
|
|
289
|
+
self.check_descr(self.descr(memset).strip(), """\
|
|
290
|
+
declare void @"llvm.memset.p0i8.i32"(ptr %".1", i8 %".2", i32 %".3", i1 %".4")""") # noqa E501
|
|
291
|
+
self.check_descr(self.descr(memcpy).strip(), """\
|
|
292
|
+
declare void @"llvm.memcpy.p0i8.p0i8.i32"(ptr %".1", ptr %".2", i32 %".3", i1 %".4")""") # noqa E501
|
|
293
|
+
else:
|
|
294
|
+
self.check_descr(self.descr(memset).strip(), """\
|
|
295
|
+
declare void @"llvm.memset.p0i8.i32"(i8* %".1", i8 %".2", i32 %".3", i1 %".4")""") # noqa E501
|
|
296
|
+
self.check_descr(self.descr(memcpy).strip(), """\
|
|
297
|
+
declare void @"llvm.memcpy.p0i8.p0i8.i32"(i8* %".1", i8* %".2", i32 %".3", i1 %".4")""") # noqa E501
|
|
270
298
|
self.check_descr(self.descr(assume).strip(), """\
|
|
271
299
|
declare void @"llvm.assume"(i1 %".1")""")
|
|
272
300
|
|
|
@@ -374,7 +402,11 @@ class TestIR(TestBase):
|
|
|
374
402
|
# A null metadata (typed) value
|
|
375
403
|
mod = self.module()
|
|
376
404
|
mod.add_metadata([int32.as_pointer()(None)])
|
|
377
|
-
|
|
405
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
406
|
+
if opaque_pointers_enabled:
|
|
407
|
+
self.assert_ir_line("!0 = !{ ptr null }", mod)
|
|
408
|
+
else:
|
|
409
|
+
self.assert_ir_line("!0 = !{ i32* null }", mod)
|
|
378
410
|
self.assert_valid_ir(mod)
|
|
379
411
|
# A null metadata (untyped) value
|
|
380
412
|
mod = self.module()
|
|
@@ -591,8 +623,14 @@ class TestGlobalValues(TestBase):
|
|
|
591
623
|
with self.assertRaises(KeyError):
|
|
592
624
|
mod.get_global('kkk')
|
|
593
625
|
# Globals should have a useful repr()
|
|
594
|
-
|
|
595
|
-
|
|
626
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
627
|
+
if opaque_pointers_enabled:
|
|
628
|
+
self.assertEqual(repr(globdouble),
|
|
629
|
+
"<ir.GlobalVariable 'globdouble' of type 'ptr'>")
|
|
630
|
+
else:
|
|
631
|
+
self.assertEqual(
|
|
632
|
+
repr(globdouble),
|
|
633
|
+
"<ir.GlobalVariable 'globdouble' of type 'double*'>")
|
|
596
634
|
|
|
597
635
|
def test_functions_global_values_access(self):
|
|
598
636
|
"""
|
|
@@ -997,21 +1035,39 @@ my_block:
|
|
|
997
1035
|
# Mismatching pointer type
|
|
998
1036
|
with self.assertRaises(TypeError) as cm:
|
|
999
1037
|
builder.store(b, e)
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1038
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
1039
|
+
if opaque_pointers_enabled:
|
|
1040
|
+
self.assertEqual(str(cm.exception),
|
|
1041
|
+
"cannot store i32 to ptr: mismatching types")
|
|
1042
|
+
self.check_block(block, """\
|
|
1043
|
+
my_block:
|
|
1044
|
+
%"c" = alloca i32
|
|
1045
|
+
%"d" = alloca i32, i32 42
|
|
1046
|
+
%"e" = alloca double, i32 %".1", align 8
|
|
1047
|
+
store double %".3", ptr %"e"
|
|
1048
|
+
store i32 %".2", ptr %"c"
|
|
1049
|
+
%"g" = load i32, ptr %"c"
|
|
1050
|
+
store i32 %".2", ptr %"c", align 1
|
|
1051
|
+
%"i" = load i32, ptr %"c", align 1
|
|
1052
|
+
store atomic i32 %".2", ptr %"c" seq_cst, align 4
|
|
1053
|
+
%"k" = load atomic i32, ptr %"c" seq_cst, align 4
|
|
1054
|
+
""")
|
|
1055
|
+
else:
|
|
1056
|
+
self.assertEqual(str(cm.exception),
|
|
1057
|
+
"cannot store i32 to double*: mismatching types")
|
|
1058
|
+
self.check_block(block, """\
|
|
1059
|
+
my_block:
|
|
1060
|
+
%"c" = alloca i32
|
|
1061
|
+
%"d" = alloca i32, i32 42
|
|
1062
|
+
%"e" = alloca double, i32 %".1", align 8
|
|
1063
|
+
store double %".3", double* %"e"
|
|
1064
|
+
store i32 %".2", i32* %"c"
|
|
1065
|
+
%"g" = load i32, i32* %"c"
|
|
1066
|
+
store i32 %".2", i32* %"c", align 1
|
|
1067
|
+
%"i" = load i32, i32* %"c", align 1
|
|
1068
|
+
store atomic i32 %".2", i32* %"c" seq_cst, align 4
|
|
1069
|
+
%"k" = load atomic i32, i32* %"c" seq_cst, align 4
|
|
1070
|
+
""")
|
|
1015
1071
|
|
|
1016
1072
|
def test_gep(self):
|
|
1017
1073
|
block = self.block(name='my_block')
|
|
@@ -1020,11 +1076,19 @@ my_block:
|
|
|
1020
1076
|
c = builder.alloca(ir.PointerType(int32), name='c')
|
|
1021
1077
|
d = builder.gep(c, [ir.Constant(int32, 5), a], name='d')
|
|
1022
1078
|
self.assertEqual(d.type, ir.PointerType(int32))
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1079
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
1080
|
+
if opaque_pointers_enabled:
|
|
1081
|
+
self.check_block(block, """\
|
|
1082
|
+
my_block:
|
|
1083
|
+
%"c" = alloca ptr
|
|
1084
|
+
%"d" = getelementptr ptr, ptr %"c", i32 5, i32 %".1"
|
|
1085
|
+
""")
|
|
1086
|
+
else:
|
|
1087
|
+
self.check_block(block, """\
|
|
1088
|
+
my_block:
|
|
1089
|
+
%"c" = alloca i32*
|
|
1090
|
+
%"d" = getelementptr i32*, i32** %"c", i32 5, i32 %".1"
|
|
1091
|
+
""")
|
|
1028
1092
|
# XXX test with more complex types
|
|
1029
1093
|
|
|
1030
1094
|
def test_gep_castinstr(self):
|
|
@@ -1038,11 +1102,19 @@ my_block:
|
|
|
1038
1102
|
d = builder.bitcast(a, ls.as_pointer(), name='d')
|
|
1039
1103
|
e = builder.gep(d, [ir.Constant(int32, x) for x in [0, 3]], name='e')
|
|
1040
1104
|
self.assertEqual(e.type, ir.PointerType(int8ptr))
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1105
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
1106
|
+
if opaque_pointers_enabled:
|
|
1107
|
+
self.check_block(block, """\
|
|
1108
|
+
my_block:
|
|
1109
|
+
%"d" = bitcast i32 %".1" to ptr
|
|
1110
|
+
%"e" = getelementptr {i64, ptr, ptr, ptr, i64}, ptr %"d", i32 0, i32 3
|
|
1111
|
+
""") # noqa E501
|
|
1112
|
+
else:
|
|
1113
|
+
self.check_block(block, """\
|
|
1114
|
+
my_block:
|
|
1115
|
+
%"d" = bitcast i32 %".1" to {i64, i8*, i8*, i8*, i64}*
|
|
1116
|
+
%"e" = getelementptr {i64, i8*, i8*, i8*, i64}, {i64, i8*, i8*, i8*, i64}* %"d", i32 0, i32 3
|
|
1117
|
+
""") # noqa E501
|
|
1046
1118
|
|
|
1047
1119
|
def test_gep_castinstr_addrspace(self):
|
|
1048
1120
|
# similar to:
|
|
@@ -1057,11 +1129,19 @@ my_block:
|
|
|
1057
1129
|
e = builder.gep(d, [ir.Constant(int32, x) for x in [0, 3]], name='e')
|
|
1058
1130
|
self.assertEqual(e.type.addrspace, addrspace)
|
|
1059
1131
|
self.assertEqual(e.type, ir.PointerType(int8ptr, addrspace=addrspace))
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1132
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
1133
|
+
if opaque_pointers_enabled:
|
|
1134
|
+
self.check_block(block, """\
|
|
1135
|
+
my_block:
|
|
1136
|
+
%"d" = bitcast i32 %".1" to ptr addrspace(4)
|
|
1137
|
+
%"e" = getelementptr {i64, ptr, ptr, ptr, i64}, ptr addrspace(4) %"d", i32 0, i32 3
|
|
1138
|
+
""") # noqa E501
|
|
1139
|
+
else:
|
|
1140
|
+
self.check_block(block, """\
|
|
1141
|
+
my_block:
|
|
1142
|
+
%"d" = bitcast i32 %".1" to {i64, i8*, i8*, i8*, i64} addrspace(4)*
|
|
1143
|
+
%"e" = getelementptr {i64, i8*, i8*, i8*, i64}, {i64, i8*, i8*, i8*, i64} addrspace(4)* %"d", i32 0, i32 3
|
|
1144
|
+
""") # noqa E501
|
|
1065
1145
|
|
|
1066
1146
|
def test_gep_addrspace(self):
|
|
1067
1147
|
block = self.block(name='my_block')
|
|
@@ -1069,18 +1149,31 @@ my_block:
|
|
|
1069
1149
|
a, b = builder.function.args[:2]
|
|
1070
1150
|
addrspace = 4
|
|
1071
1151
|
c = builder.alloca(ir.PointerType(int32, addrspace=addrspace), name='c')
|
|
1072
|
-
|
|
1152
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
1153
|
+
if opaque_pointers_enabled:
|
|
1154
|
+
self.assertEqual(str(c.type), 'ptr')
|
|
1155
|
+
else:
|
|
1156
|
+
self.assertEqual(str(c.type), 'i32 addrspace(4)**')
|
|
1073
1157
|
self.assertEqual(c.type.pointee.addrspace, addrspace)
|
|
1074
1158
|
d = builder.gep(c, [ir.Constant(int32, 5), a], name='d')
|
|
1075
1159
|
self.assertEqual(d.type.addrspace, addrspace)
|
|
1076
1160
|
e = builder.gep(d, [ir.Constant(int32, 10)], name='e')
|
|
1077
1161
|
self.assertEqual(e.type.addrspace, addrspace)
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1162
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
1163
|
+
if opaque_pointers_enabled:
|
|
1164
|
+
self.check_block(block, """\
|
|
1165
|
+
my_block:
|
|
1166
|
+
%"c" = alloca ptr addrspace(4)
|
|
1167
|
+
%"d" = getelementptr ptr addrspace(4), ptr %"c", i32 5, i32 %".1"
|
|
1168
|
+
%"e" = getelementptr i32, ptr addrspace(4) %"d", i32 10
|
|
1169
|
+
""") # noqa E501
|
|
1170
|
+
else:
|
|
1171
|
+
self.check_block(block, """\
|
|
1172
|
+
my_block:
|
|
1173
|
+
%"c" = alloca i32 addrspace(4)*
|
|
1174
|
+
%"d" = getelementptr i32 addrspace(4)*, i32 addrspace(4)** %"c", i32 5, i32 %".1"
|
|
1175
|
+
%"e" = getelementptr i32, i32 addrspace(4)* %"d", i32 10
|
|
1176
|
+
""") # noqa E501
|
|
1084
1177
|
|
|
1085
1178
|
def test_extract_insert_value(self):
|
|
1086
1179
|
block = self.block(name='my_block')
|
|
@@ -1128,20 +1221,37 @@ my_block:
|
|
|
1128
1221
|
# Replacement value has the wrong type
|
|
1129
1222
|
builder.insert_value(c_inner, a, 1)
|
|
1130
1223
|
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1224
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
1225
|
+
if opaque_pointers_enabled:
|
|
1226
|
+
self.check_block(block, """\
|
|
1227
|
+
my_block:
|
|
1228
|
+
%"c" = extractvalue {i32, i1} {i32 4, i1 true}, 0
|
|
1229
|
+
%"d" = insertvalue {i32, i1} {i32 4, i1 true}, i32 %".1", 0
|
|
1230
|
+
%"e" = insertvalue {i32, i1} %"d", i1 false, 1
|
|
1231
|
+
%"ptr" = alloca {i8, {i32, i1}}
|
|
1232
|
+
%"j" = load {i8, {i32, i1}}, ptr %"ptr"
|
|
1233
|
+
%"k" = extractvalue {i8, {i32, i1}} %"j", 0
|
|
1234
|
+
%"l" = extractvalue {i8, {i32, i1}} %"j", 1
|
|
1235
|
+
%"m" = extractvalue {i8, {i32, i1}} %"j", 1, 0
|
|
1236
|
+
%"n" = extractvalue {i8, {i32, i1}} %"j", 1, 1
|
|
1237
|
+
%"o" = insertvalue {i8, {i32, i1}} %"j", {i32, i1} %"l", 1
|
|
1238
|
+
%"p" = insertvalue {i8, {i32, i1}} %"j", i32 %".1", 1, 0
|
|
1239
|
+
""")
|
|
1240
|
+
else:
|
|
1241
|
+
self.check_block(block, """\
|
|
1242
|
+
my_block:
|
|
1243
|
+
%"c" = extractvalue {i32, i1} {i32 4, i1 true}, 0
|
|
1244
|
+
%"d" = insertvalue {i32, i1} {i32 4, i1 true}, i32 %".1", 0
|
|
1245
|
+
%"e" = insertvalue {i32, i1} %"d", i1 false, 1
|
|
1246
|
+
%"ptr" = alloca {i8, {i32, i1}}
|
|
1247
|
+
%"j" = load {i8, {i32, i1}}, {i8, {i32, i1}}* %"ptr"
|
|
1248
|
+
%"k" = extractvalue {i8, {i32, i1}} %"j", 0
|
|
1249
|
+
%"l" = extractvalue {i8, {i32, i1}} %"j", 1
|
|
1250
|
+
%"m" = extractvalue {i8, {i32, i1}} %"j", 1, 0
|
|
1251
|
+
%"n" = extractvalue {i8, {i32, i1}} %"j", 1, 1
|
|
1252
|
+
%"o" = insertvalue {i8, {i32, i1}} %"j", {i32, i1} %"l", 1
|
|
1253
|
+
%"p" = insertvalue {i8, {i32, i1}} %"j", i32 %".1", 1, 0
|
|
1254
|
+
""")
|
|
1145
1255
|
|
|
1146
1256
|
def test_cast_ops(self):
|
|
1147
1257
|
block = self.block(name='my_block')
|
|
@@ -1160,21 +1270,39 @@ my_block:
|
|
|
1160
1270
|
j = builder.inttoptr(i, ir.PointerType(int8), 'j') # noqa F841
|
|
1161
1271
|
k = builder.bitcast(a, flt, "k") # noqa F841
|
|
1162
1272
|
self.assertFalse(block.is_terminated)
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1273
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
1274
|
+
if opaque_pointers_enabled:
|
|
1275
|
+
self.check_block(block, """\
|
|
1276
|
+
my_block:
|
|
1277
|
+
%"c" = trunc i32 %".1" to i8
|
|
1278
|
+
%"d" = zext i8 %"c" to i32
|
|
1279
|
+
%"e" = sext i8 %"c" to i32
|
|
1280
|
+
%"fb" = fptrunc double %".3" to float
|
|
1281
|
+
%"fc" = fpext float %"fb" to double
|
|
1282
|
+
%"g" = fptoui double %".3" to i32
|
|
1283
|
+
%"h" = fptosi double %".3" to i8
|
|
1284
|
+
%"fd" = uitofp i32 %"g" to float
|
|
1285
|
+
%"fe" = sitofp i8 %"h" to double
|
|
1286
|
+
%"i" = ptrtoint ptr %".4" to i32
|
|
1287
|
+
%"j" = inttoptr i32 %"i" to ptr
|
|
1288
|
+
%"k" = bitcast i32 %".1" to float
|
|
1289
|
+
""")
|
|
1290
|
+
else:
|
|
1291
|
+
self.check_block(block, """\
|
|
1292
|
+
my_block:
|
|
1293
|
+
%"c" = trunc i32 %".1" to i8
|
|
1294
|
+
%"d" = zext i8 %"c" to i32
|
|
1295
|
+
%"e" = sext i8 %"c" to i32
|
|
1296
|
+
%"fb" = fptrunc double %".3" to float
|
|
1297
|
+
%"fc" = fpext float %"fb" to double
|
|
1298
|
+
%"g" = fptoui double %".3" to i32
|
|
1299
|
+
%"h" = fptosi double %".3" to i8
|
|
1300
|
+
%"fd" = uitofp i32 %"g" to float
|
|
1301
|
+
%"fe" = sitofp i8 %"h" to double
|
|
1302
|
+
%"i" = ptrtoint i32* %".4" to i32
|
|
1303
|
+
%"j" = inttoptr i32 %"i" to i8*
|
|
1304
|
+
%"k" = bitcast i32 %".1" to float
|
|
1305
|
+
""")
|
|
1178
1306
|
|
|
1179
1307
|
def test_atomicrmw(self):
|
|
1180
1308
|
block = self.block(name='my_block')
|
|
@@ -1183,11 +1311,19 @@ my_block:
|
|
|
1183
1311
|
c = builder.alloca(int32, name='c')
|
|
1184
1312
|
d = builder.atomic_rmw('add', c, a, 'monotonic', 'd')
|
|
1185
1313
|
self.assertEqual(d.type, int32)
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1314
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
1315
|
+
if opaque_pointers_enabled:
|
|
1316
|
+
self.check_block(block, """\
|
|
1317
|
+
my_block:
|
|
1318
|
+
%"c" = alloca i32
|
|
1319
|
+
%"d" = atomicrmw add ptr %"c", i32 %".1" monotonic
|
|
1320
|
+
""")
|
|
1321
|
+
else:
|
|
1322
|
+
self.check_block(block, """\
|
|
1323
|
+
my_block:
|
|
1324
|
+
%"c" = alloca i32
|
|
1325
|
+
%"d" = atomicrmw add i32* %"c", i32 %".1" monotonic
|
|
1326
|
+
""")
|
|
1191
1327
|
|
|
1192
1328
|
def test_branch(self):
|
|
1193
1329
|
block = self.block(name='my_block')
|
|
@@ -1238,10 +1374,17 @@ my_block:
|
|
|
1238
1374
|
indirectbr.add_destination(bb_1)
|
|
1239
1375
|
indirectbr.add_destination(bb_2)
|
|
1240
1376
|
self.assertTrue(block.is_terminated)
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1377
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
1378
|
+
if opaque_pointers_enabled:
|
|
1379
|
+
self.check_block(block, """\
|
|
1380
|
+
my_block:
|
|
1381
|
+
indirectbr ptr blockaddress(@"my_func", %"b_1"), [label %"b_1", label %"b_2"]
|
|
1382
|
+
""") # noqa E501
|
|
1383
|
+
else:
|
|
1384
|
+
self.check_block(block, """\
|
|
1385
|
+
my_block:
|
|
1386
|
+
indirectbr i8* blockaddress(@"my_func", %"b_1"), [label %"b_1", label %"b_2"]
|
|
1387
|
+
""") # noqa E501
|
|
1245
1388
|
|
|
1246
1389
|
def test_returns(self):
|
|
1247
1390
|
def check(block, expected_ir):
|
|
@@ -1354,11 +1497,19 @@ my_block:
|
|
|
1354
1497
|
a = builder.alloca(int32, name="a")
|
|
1355
1498
|
b = builder.module.add_metadata(())
|
|
1356
1499
|
builder.call(dbg_declare, (a, b, b))
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1500
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
1501
|
+
if opaque_pointers_enabled:
|
|
1502
|
+
self.check_block(block, """\
|
|
1503
|
+
my_block:
|
|
1504
|
+
%"a" = alloca i32
|
|
1505
|
+
call void @"llvm.dbg.declare"(metadata ptr %"a", metadata !0, metadata !0)
|
|
1506
|
+
""") # noqa E501
|
|
1507
|
+
else:
|
|
1508
|
+
self.check_block(block, """\
|
|
1509
|
+
my_block:
|
|
1510
|
+
%"a" = alloca i32
|
|
1511
|
+
call void @"llvm.dbg.declare"(metadata i32* %"a", metadata !0, metadata !0)
|
|
1512
|
+
""") # noqa E501
|
|
1362
1513
|
|
|
1363
1514
|
def test_call_attributes(self):
|
|
1364
1515
|
block = self.block(name='my_block')
|
|
@@ -1377,12 +1528,21 @@ my_block:
|
|
|
1377
1528
|
2: 'noalias'
|
|
1378
1529
|
}
|
|
1379
1530
|
)
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1531
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
1532
|
+
if opaque_pointers_enabled:
|
|
1533
|
+
self.check_block_regex(block, """\
|
|
1534
|
+
my_block:
|
|
1535
|
+
%"retval" = alloca i32
|
|
1536
|
+
%"other" = alloca i32
|
|
1537
|
+
call void @"fun"\\(ptr noalias sret(\\(i32\\))? %"retval", i32 42, ptr noalias %"other"\\)
|
|
1538
|
+
""") # noqa E501
|
|
1539
|
+
else:
|
|
1540
|
+
self.check_block_regex(block, """\
|
|
1541
|
+
my_block:
|
|
1542
|
+
%"retval" = alloca i32
|
|
1543
|
+
%"other" = alloca i32
|
|
1544
|
+
call void @"fun"\\(i32\\* noalias sret(\\(i32\\))? %"retval", i32 42, i32\\* noalias %"other"\\)
|
|
1545
|
+
""") # noqa E501
|
|
1386
1546
|
|
|
1387
1547
|
def test_call_tail(self):
|
|
1388
1548
|
block = self.block(name='my_block')
|
|
@@ -1460,13 +1620,23 @@ my_block:
|
|
|
1460
1620
|
2: 'noalias'
|
|
1461
1621
|
}
|
|
1462
1622
|
)
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1623
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
1624
|
+
if opaque_pointers_enabled:
|
|
1625
|
+
self.check_block_regex(block, """\
|
|
1626
|
+
my_block:
|
|
1627
|
+
%"retval" = alloca i32
|
|
1628
|
+
%"other" = alloca i32
|
|
1629
|
+
invoke fast fastcc void @"fun"\\(ptr noalias sret(\\(i32\\))? %"retval", i32 42, ptr noalias %"other"\\) noinline
|
|
1630
|
+
to label %"normal" unwind label %"unwind"
|
|
1631
|
+
""") # noqa E501
|
|
1632
|
+
else:
|
|
1633
|
+
self.check_block_regex(block, """\
|
|
1634
|
+
my_block:
|
|
1635
|
+
%"retval" = alloca i32
|
|
1636
|
+
%"other" = alloca i32
|
|
1637
|
+
invoke fast fastcc void @"fun"\\(i32\\* noalias sret(\\(i32\\))? %"retval", i32 42, i32\\* noalias %"other"\\) noinline
|
|
1638
|
+
to label %"normal" unwind label %"unwind"
|
|
1639
|
+
""") # noqa E501
|
|
1470
1640
|
|
|
1471
1641
|
def test_landingpad(self):
|
|
1472
1642
|
block = self.block(name='my_block')
|
|
@@ -1480,13 +1650,23 @@ my_block:
|
|
|
1480
1650
|
lp.add_clause(ir.FilterClause(ir.Constant(ir.ArrayType(
|
|
1481
1651
|
int_typeinfo.type, 1), [int_typeinfo])))
|
|
1482
1652
|
builder.resume(lp)
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1653
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
1654
|
+
if opaque_pointers_enabled:
|
|
1655
|
+
self.check_block(block, """\
|
|
1656
|
+
my_block:
|
|
1657
|
+
%"lp" = landingpad {i32, ptr}
|
|
1658
|
+
catch ptr @"_ZTIi"
|
|
1659
|
+
filter [1 x ptr] [ptr @"_ZTIi"]
|
|
1660
|
+
resume {i32, ptr} %"lp"
|
|
1661
|
+
""")
|
|
1662
|
+
else:
|
|
1663
|
+
self.check_block(block, """\
|
|
1664
|
+
my_block:
|
|
1665
|
+
%"lp" = landingpad {i32, i8*}
|
|
1666
|
+
catch i8** @"_ZTIi"
|
|
1667
|
+
filter [1 x i8**] [i8** @"_ZTIi"]
|
|
1668
|
+
resume {i32, i8*} %"lp"
|
|
1669
|
+
""")
|
|
1490
1670
|
|
|
1491
1671
|
def test_assume(self):
|
|
1492
1672
|
block = self.block(name='my_block')
|
|
@@ -2158,10 +2338,17 @@ class TestBuilderMisc(TestBase):
|
|
|
2158
2338
|
builder = ir.IRBuilder(block)
|
|
2159
2339
|
builder.debug_metadata = builder.module.add_metadata([])
|
|
2160
2340
|
builder.alloca(ir.PointerType(int32), name='c')
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2341
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
2342
|
+
if opaque_pointers_enabled:
|
|
2343
|
+
self.check_block(block, """\
|
|
2344
|
+
my_block:
|
|
2345
|
+
%"c" = alloca ptr, !dbg !0
|
|
2346
|
+
""")
|
|
2347
|
+
else:
|
|
2348
|
+
self.check_block(block, """\
|
|
2349
|
+
my_block:
|
|
2350
|
+
%"c" = alloca i32*, !dbg !0
|
|
2351
|
+
""")
|
|
2165
2352
|
|
|
2166
2353
|
|
|
2167
2354
|
class TestTypes(TestBase):
|
|
@@ -2236,18 +2423,36 @@ class TestTypes(TestBase):
|
|
|
2236
2423
|
'i1 (float, ...)')
|
|
2237
2424
|
self.assertEqual(str(ir.FunctionType(int1, (flt, dbl), var_arg=True)),
|
|
2238
2425
|
'i1 (float, double, ...)')
|
|
2239
|
-
|
|
2240
|
-
|
|
2426
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
2427
|
+
if opaque_pointers_enabled:
|
|
2428
|
+
self.assertEqual(str(ir.PointerType(int32)), 'ptr')
|
|
2429
|
+
self.assertEqual(str(ir.PointerType(ir.PointerType(int32))), 'ptr')
|
|
2430
|
+
else:
|
|
2431
|
+
self.assertEqual(str(ir.PointerType(int32)), 'i32*')
|
|
2432
|
+
self.assertEqual(str(ir.PointerType(ir.PointerType(int32))),
|
|
2433
|
+
'i32**')
|
|
2241
2434
|
self.assertEqual(str(ir.ArrayType(int1, 5)), '[5 x i1]')
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2435
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
2436
|
+
if opaque_pointers_enabled:
|
|
2437
|
+
self.assertEqual(str(ir.ArrayType(ir.PointerType(int1), 5)),
|
|
2438
|
+
'[5 x ptr]')
|
|
2439
|
+
self.assertEqual(str(ir.PointerType(ir.ArrayType(int1, 5))), 'ptr')
|
|
2440
|
+
else:
|
|
2441
|
+
self.assertEqual(str(ir.ArrayType(ir.PointerType(int1), 5)),
|
|
2442
|
+
'[5 x i1*]')
|
|
2443
|
+
self.assertEqual(str(ir.PointerType(ir.ArrayType(int1, 5))),
|
|
2444
|
+
'[5 x i1]*')
|
|
2246
2445
|
self.assertEqual(str(ir.LiteralStructType((int1,))), '{i1}')
|
|
2247
2446
|
self.assertEqual(str(ir.LiteralStructType((int1, flt))), '{i1, float}')
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2447
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
2448
|
+
if opaque_pointers_enabled:
|
|
2449
|
+
self.assertEqual(str(ir.LiteralStructType((
|
|
2450
|
+
ir.PointerType(int1), ir.LiteralStructType((int32, int8))))),
|
|
2451
|
+
'{ptr, {i32, i8}}')
|
|
2452
|
+
else:
|
|
2453
|
+
self.assertEqual(str(ir.LiteralStructType((
|
|
2454
|
+
ir.PointerType(int1), ir.LiteralStructType((int32, int8))))),
|
|
2455
|
+
'{i1*, {i32, i8}}')
|
|
2251
2456
|
self.assertEqual(str(ir.LiteralStructType((int1,), packed=True)),
|
|
2252
2457
|
'<{i1}>')
|
|
2253
2458
|
self.assertEqual(str(ir.LiteralStructType((int1, flt), packed=True)),
|
|
@@ -2338,6 +2543,20 @@ class TestTypes(TestBase):
|
|
|
2338
2543
|
self.assert_valid_ir(module)
|
|
2339
2544
|
self.assertNotEqual(oldstr, str(module))
|
|
2340
2545
|
|
|
2546
|
+
def test_identified_struct_packed(self):
|
|
2547
|
+
td = llvm.create_target_data("e-m:e-i64:64-f80:128-n8:16:32:64-S128")
|
|
2548
|
+
context = ir.Context()
|
|
2549
|
+
mytype = context.get_identified_type("MyType", True)
|
|
2550
|
+
module = ir.Module(context=context)
|
|
2551
|
+
self.assertTrue(mytype.is_opaque)
|
|
2552
|
+
self.assert_valid_ir(module)
|
|
2553
|
+
oldstr = str(module)
|
|
2554
|
+
mytype.set_body(ir.IntType(16), ir.IntType(64), ir.FloatType())
|
|
2555
|
+
self.assertEqual(mytype.get_element_offset(td, 1, context), 2)
|
|
2556
|
+
self.assertFalse(mytype.is_opaque)
|
|
2557
|
+
self.assert_valid_ir(module)
|
|
2558
|
+
self.assertNotEqual(oldstr, str(module))
|
|
2559
|
+
|
|
2341
2560
|
def test_target_data_non_default_context(self):
|
|
2342
2561
|
context = ir.Context()
|
|
2343
2562
|
mytype = context.get_identified_type("MyType")
|
|
@@ -2524,8 +2743,13 @@ class TestConstant(TestBase):
|
|
|
2524
2743
|
tp = ir.LiteralStructType((flt, int1))
|
|
2525
2744
|
gv = ir.GlobalVariable(m, tp, "myconstant")
|
|
2526
2745
|
c = gv.gep([ir.Constant(int32, x) for x in (0, 1)])
|
|
2527
|
-
|
|
2528
|
-
|
|
2746
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
2747
|
+
if opaque_pointers_enabled:
|
|
2748
|
+
self.assertEqual(str(c),
|
|
2749
|
+
'getelementptr ({float, i1}, ptr @"myconstant", i32 0, i32 1)') # noqa E501
|
|
2750
|
+
else:
|
|
2751
|
+
self.assertEqual(str(c),
|
|
2752
|
+
'getelementptr ({float, i1}, {float, i1}* @"myconstant", i32 0, i32 1)') # noqa E501
|
|
2529
2753
|
self.assertEqual(c.type, ir.PointerType(int1))
|
|
2530
2754
|
|
|
2531
2755
|
const = ir.Constant(tp, None)
|
|
@@ -2534,8 +2758,13 @@ class TestConstant(TestBase):
|
|
|
2534
2758
|
|
|
2535
2759
|
const_ptr = ir.Constant(tp.as_pointer(), None)
|
|
2536
2760
|
c2 = const_ptr.gep([ir.Constant(int32, 0)])
|
|
2537
|
-
|
|
2538
|
-
|
|
2761
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
2762
|
+
if opaque_pointers_enabled:
|
|
2763
|
+
self.assertEqual(str(c2),
|
|
2764
|
+
'getelementptr ({float, i1}, ptr null, i32 0)') # noqa E501
|
|
2765
|
+
else:
|
|
2766
|
+
self.assertEqual(str(c2),
|
|
2767
|
+
'getelementptr ({float, i1}, {float, i1}* null, i32 0)') # noqa E501
|
|
2539
2768
|
self.assertEqual(c.type, ir.PointerType(int1))
|
|
2540
2769
|
|
|
2541
2770
|
def test_gep_addrspace_globalvar(self):
|
|
@@ -2547,9 +2776,15 @@ class TestConstant(TestBase):
|
|
|
2547
2776
|
self.assertEqual(gv.addrspace, addrspace)
|
|
2548
2777
|
c = gv.gep([ir.Constant(int32, x) for x in (0, 1)])
|
|
2549
2778
|
self.assertEqual(c.type.addrspace, addrspace)
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2779
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
2780
|
+
if opaque_pointers_enabled:
|
|
2781
|
+
self.assertEqual(str(c),
|
|
2782
|
+
('getelementptr ({float, i1}, ptr '
|
|
2783
|
+
'addrspace(4) @"myconstant", i32 0, i32 1)'))
|
|
2784
|
+
else:
|
|
2785
|
+
self.assertEqual(str(c),
|
|
2786
|
+
('getelementptr ({float, i1}, {float, i1} '
|
|
2787
|
+
'addrspace(4)* @"myconstant", i32 0, i32 1)'))
|
|
2553
2788
|
self.assertEqual(c.type, ir.PointerType(int1, addrspace=addrspace))
|
|
2554
2789
|
|
|
2555
2790
|
def test_trunc(self):
|
|
@@ -2576,7 +2811,11 @@ class TestConstant(TestBase):
|
|
|
2576
2811
|
m = self.module()
|
|
2577
2812
|
gv = ir.GlobalVariable(m, int32, "myconstant")
|
|
2578
2813
|
c = gv.bitcast(int64.as_pointer())
|
|
2579
|
-
|
|
2814
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
2815
|
+
if opaque_pointers_enabled:
|
|
2816
|
+
self.assertEqual(str(c), 'bitcast (ptr @"myconstant" to ptr)')
|
|
2817
|
+
else:
|
|
2818
|
+
self.assertEqual(str(c), 'bitcast (i32* @"myconstant" to i64*)')
|
|
2580
2819
|
|
|
2581
2820
|
def test_fptoui(self):
|
|
2582
2821
|
c = ir.Constant(flt, 1).fptoui(int32)
|
|
@@ -2601,19 +2840,33 @@ class TestConstant(TestBase):
|
|
|
2601
2840
|
|
|
2602
2841
|
self.assertRaises(TypeError, one.ptrtoint, int64)
|
|
2603
2842
|
self.assertRaises(TypeError, ptr.ptrtoint, flt)
|
|
2604
|
-
|
|
2843
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
2844
|
+
if opaque_pointers_enabled:
|
|
2845
|
+
self.assertEqual(str(c), 'ptrtoint (ptr null to i32)')
|
|
2846
|
+
else:
|
|
2847
|
+
self.assertEqual(str(c), 'ptrtoint (i64* null to i32)')
|
|
2605
2848
|
|
|
2606
2849
|
def test_ptrtoint_2(self):
|
|
2607
2850
|
m = self.module()
|
|
2608
2851
|
gv = ir.GlobalVariable(m, int32, "myconstant")
|
|
2609
2852
|
c = gv.ptrtoint(int64)
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2853
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
2854
|
+
if opaque_pointers_enabled:
|
|
2855
|
+
self.assertEqual(str(c), 'ptrtoint (ptr @"myconstant" to i64)')
|
|
2856
|
+
|
|
2857
|
+
self.assertRaisesRegex(
|
|
2858
|
+
TypeError,
|
|
2859
|
+
r"can only ptrtoint\(\) to integer type, not 'ptr'",
|
|
2860
|
+
gv.ptrtoint,
|
|
2861
|
+
int64.as_pointer())
|
|
2862
|
+
else:
|
|
2863
|
+
self.assertEqual(str(c), 'ptrtoint (i32* @"myconstant" to i64)')
|
|
2864
|
+
|
|
2865
|
+
self.assertRaisesRegex(
|
|
2866
|
+
TypeError,
|
|
2867
|
+
r"can only ptrtoint\(\) to integer type, not 'i64\*'",
|
|
2868
|
+
gv.ptrtoint,
|
|
2869
|
+
int64.as_pointer())
|
|
2617
2870
|
|
|
2618
2871
|
c2 = ir.Constant(int32, 0)
|
|
2619
2872
|
self.assertRaisesRegex(
|
|
@@ -2629,7 +2882,11 @@ class TestConstant(TestBase):
|
|
|
2629
2882
|
|
|
2630
2883
|
self.assertRaises(TypeError, one.inttoptr, int64)
|
|
2631
2884
|
self.assertRaises(TypeError, pi.inttoptr, int64.as_pointer())
|
|
2632
|
-
|
|
2885
|
+
# FIXME: Remove `else' once TP are no longer supported.
|
|
2886
|
+
if opaque_pointers_enabled:
|
|
2887
|
+
self.assertEqual(str(c), 'inttoptr (i32 1 to ptr)')
|
|
2888
|
+
else:
|
|
2889
|
+
self.assertEqual(str(c), 'inttoptr (i32 1 to i64*)')
|
|
2633
2890
|
|
|
2634
2891
|
def test_neg(self):
|
|
2635
2892
|
one = ir.Constant(int32, 1)
|