Skip to content

Commit

Permalink
Remove unavailable constant expression functions on LLVM 19
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed Jan 21, 2025
1 parent da34b1f commit baaf7f5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
28 changes: 17 additions & 11 deletions src/core/value/constant.jl
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ export ConstantExpr,

const_neg, const_nswneg, const_nuwneg, const_not, const_add,
const_nswadd, const_nuwadd, const_sub, const_nswsub, const_nuwsub, const_mul,
const_nswmul, const_nuwmul, const_xor, const_icmp, const_fcmp,
const_shl, const_gep, const_inbounds_gep, const_trunc,
const_nswmul, const_nuwmul, const_xor,
const_gep, const_inbounds_gep, const_trunc,
const_ptrtoint, const_inttoptr, const_bitcast,
const_addrspacecast, const_truncorbitcast,
const_pointercast, const_shufflevector
Expand Down Expand Up @@ -590,15 +590,6 @@ const_nuwmul(lhs::Constant, rhs::Constant) =
const_xor(lhs::Constant, rhs::Constant) =
Value(API.LLVMConstXor(lhs, rhs))

const_icmp(Predicate::API.LLVMIntPredicate, lhs::Constant, rhs::Constant) =
Value(API.LLVMConstICmp(Predicate, lhs, rhs))

const_fcmp(Predicate::API.LLVMRealPredicate, lhs::Constant, rhs::Constant) =
Value(API.LLVMConstFCmp(Predicate, lhs, rhs))

const_shl(lhs::Constant, rhs::Constant) =
Value(API.LLVMConstShl(lhs, rhs))

function const_gep(Ty::LLVMType, val::Constant, Indices::Vector{<:Constant})
Value(API.LLVMConstGEP2(Ty, val, Indices, length(Indices)))
end
Expand Down Expand Up @@ -743,6 +734,21 @@ const_sextorbitcast(val::Constant, ToType::LLVMType) =

end

if version() < v"19"

export const_icmp, const_fcmp, const_shl

const_icmp(Predicate::API.LLVMIntPredicate, lhs::Constant, rhs::Constant) =
Value(API.LLVMConstICmp(Predicate, lhs, rhs))

const_fcmp(Predicate::API.LLVMRealPredicate, lhs::Constant, rhs::Constant) =
Value(API.LLVMConstFCmp(Predicate, lhs, rhs))

const_shl(lhs::Constant, rhs::Constant) =
Value(API.LLVMConstShl(lhs, rhs))

end

# TODO: alignof, sizeof, block_address


Expand Down
16 changes: 10 additions & 6 deletions test/core_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,13 @@ end
ce = const_xor(val, other_val)::LLVM.Constant
@check_ir ce "i32 40"

ce = const_icmp(LLVM.API.LLVMIntUGT, val, other_val)::LLVM.Constant
@check_ir ce "i1 true"
if LLVM.version() < v"19"
ce = const_icmp(LLVM.API.LLVMIntUGT, val, other_val)::LLVM.Constant
@check_ir ce "i1 true"

ce = const_shl(val, other_val)::LLVM.Constant
@check_ir ce "i32 168"
ce = const_shl(val, other_val)::LLVM.Constant
@check_ir ce "i32 168"
end

for f in [const_trunc, const_truncorbitcast]
ce = const_trunc(val, LLVM.Int16Type())::LLVM.Constant
Expand Down Expand Up @@ -684,8 +686,10 @@ end
val = LLVM.ConstantFP(Float32(42.); )

other_val = LLVM.ConstantFP(Float32(2.))
ce = const_fcmp(LLVM.API.LLVMRealUGT, val, other_val)::LLVM.Constant
@check_ir ce "i1 true"
if LLVM.version() < v"19"
ce = const_fcmp(LLVM.API.LLVMRealUGT, val, other_val)::LLVM.Constant
@check_ir ce "i1 true"
end

if LLVM.version() < v"15"
other_val = LLVM.ConstantFP(Float32(2.))
Expand Down

0 comments on commit baaf7f5

Please sign in to comment.