diff --git a/src/irbuilder.jl b/src/irbuilder.jl index da9d0b50..6dc13d53 100644 --- a/src/irbuilder.jl +++ b/src/irbuilder.jl @@ -50,7 +50,7 @@ debuglocation!(builder::Builder, inst::Instruction) = # NOTE: we can't use type information for differentiating eg. add! and fadd! based on args, # as ArgumentKind (LLVM's way of referring to contained function arguments) is untyped -export unreachable!, ret!, add!, fadd!, br!, alloca!, call! +export unreachable!, ret!, add!, fadd!, icmp!, br!, alloca!, call! unreachable!(builder::Builder) = Instruction(API.LLVMBuildUnreachable(ref(builder))) @@ -69,6 +69,10 @@ fadd!(builder::Builder, lhs::Value, rhs::Value, name::String="") = Instruction(API.LLVMBuildFAdd(ref(builder), ref(lhs), ref(rhs), name)) +icmp!(builder::Builder, op::API.LLVMIntPredicate, rhs::Value, + lhs::Value, name::String="") = + Instruction(API.LLVMBuildICmp(ref(builder), op, ref(rhs), ref(lhs), name)) + br!(builder::Builder, dest::BasicBlock) = Instruction(API.LLVMBuildBr(ref(builder), blockref(dest))) diff --git a/test/irbuilder.jl b/test/irbuilder.jl index 64371008..0d027cbb 100644 --- a/test/irbuilder.jl +++ b/test/irbuilder.jl @@ -44,12 +44,15 @@ LLVM.Module("SomeModule", ctx) do mod insert!(builder, retinst2) @test collect(instructions(entry)) == [unrinst, addinst, retinst2, retinst] + position!(builder, retinst) + icmpinst = icmp!(builder, LLVM.API.LLVMIntEQ, addinst, ConstantInt(LLVM.Int32Type(), 1)) + allocinst1 = alloca!(builder, LLVM.Int32Type(), "foo") allocinst2 = Instruction(allocinst1) @test name(allocinst2) == "" insert!(builder, allocinst2, "bar") @test name(allocinst2) == "bar" - @test collect(instructions(entry)) == [unrinst, addinst, retinst2, allocinst1, allocinst2, retinst] + @test collect(instructions(entry)) == [unrinst, addinst, retinst2, icmpinst, allocinst1, allocinst2, retinst] trap = LLVM.Function(mod, "llvm.trap", LLVM.FunctionType(LLVM.VoidType(ctx))) call!(builder, trap)