Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
numba
GitHub Repository: numba/llvmlite
Path: blob/main/examples/opaque_pointers/llvmir.py
1154 views
1
import llvmlite
2
llvmlite.ir_layer_typed_pointers_enabled = False
3
4
import llvmlite.ir as ll
5
6
fntype = ll.FunctionType(ll.IntType(32), [ll.IntType(32), ll.IntType(32)])
7
8
module = ll.Module()
9
10
func = ll.Function(module, fntype, name='foo')
11
bb_entry = func.append_basic_block()
12
13
builder = ll.IRBuilder()
14
builder.position_at_end(bb_entry)
15
16
stackint = builder.alloca(ll.IntType(32))
17
# Instead of stackint.type.pointee we can access stackint.allocated_type
18
# directly.
19
builder.store(ll.Constant(stackint.allocated_type, 123), stackint)
20
myint = builder.load(stackint)
21
22
addinstr = builder.add(func.args[0], func.args[1])
23
mulinstr = builder.mul(addinstr, ll.Constant(ll.IntType(32), 123))
24
pred = builder.icmp_signed('<', addinstr, mulinstr)
25
builder.ret(mulinstr)
26
27
bb_block = func.append_basic_block()
28
builder.position_at_end(bb_block)
29
30
bb_exit = func.append_basic_block()
31
32
pred = builder.trunc(addinstr, ll.IntType(1))
33
builder.cbranch(pred, bb_block, bb_exit)
34
35
builder.position_at_end(bb_exit)
36
builder.ret(myint)
37
38
print(module)
39
40