Skip to content

Commit 9f9d2fa

Browse files
committed
Simplify 'constrained' example.
1 parent abf77b0 commit 9f9d2fa

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

examples/constrained.jl

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
using LLVM
1313
using LLVM.Interop
1414

15-
# TODO: select the right intrinsic overload (https://github.com/maleadt/LLVM.jl/issues/112)
16-
suffix(::Type{Float64}) = "f64"
17-
suffix(::Type{Float32}) = "f32"
18-
1915
# map Julia functions to llvm intrinsic
2016
func(::Type{typeof(+)}) = "fadd"
2117

@@ -45,15 +41,14 @@ meta(::Type{FPExceptStrict}) = "fpexcept.strict"
4541
mround = MDString(meta(round); ctx)
4642
mfpexcept = MDString(meta(fpexcept); ctx)
4743
mod = LLVM.parent(llvm_f)
48-
intrinsic_typ = LLVM.FunctionType(typ, [paramtyps..., mtyp, mtyp])
49-
intrinsic = LLVM.Function(mod, "llvm.experimental.constrained.$(func(F)).$(suffix(T))",
50-
intrinsic_typ)
44+
intrinsic = Intrinsic("llvm.experimental.constrained.$(func(F))")
45+
intrinsic_fun = LLVM.Function(mod, intrinsic, [typ])
5146

5247
# generate IR
5348
@dispose builder=Builder(ctx) begin
5449
entry = BasicBlock(llvm_f, "entry"; ctx)
5550
position!(builder, entry)
56-
val = call!(builder, intrinsic,
51+
val = call!(builder, intrinsic_fun,
5752
[parameters(llvm_f)..., Value(mround; ctx), Value(mfpexcept; ctx)])
5853
ret!(builder, val)
5954
end
@@ -69,7 +64,5 @@ using Test
6964
@test cadd(1.0, 2.0) == 3.0
7065

7166
using InteractiveUtils
72-
io = IOBuffer()
73-
code_llvm(io, cadd, (Float32, Float32))
74-
seekstart(io)
75-
@test occursin("@llvm.experimental.constrained.fadd.f32", String(take!(io)))
67+
ir = sprint(io->code_llvm(io, cadd, (Float32, Float32)))
68+
@test occursin("@llvm.experimental.constrained.fadd.f32", ir)

0 commit comments

Comments
 (0)