Skip to content

Commit

Permalink
Fix some nits
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaraldi committed Mar 20, 2023
1 parent df60e18 commit e2ec2f3
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 35 deletions.
2 changes: 0 additions & 2 deletions deps/LLVMExtra/include/LLVMExtra.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ void LLVMExtraAddNamedMetadataOperand2(LLVMNamedMDNodeRef NMD, LLVMMetadataRef V

LLVMTypeRef LLVMGetFunctionType(LLVMValueRef Fn);

LLVMTypeRef LLVMGetType(LLVMValueRef V);

#if LLVM_VERSION_MAJOR >= 12
void LLVMAddCFGSimplificationPass2(LLVMPassManagerRef PM,
int BonusInstThreshold,
Expand Down
4 changes: 0 additions & 4 deletions deps/LLVMExtra/lib/llvm-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,6 @@ LLVMValueRef LLVMConstDataArray(LLVMTypeRef ElementTy, const void *Data, unsigne
return wrap(ConstantDataArray::getRaw(S, NumElements, unwrap(ElementTy)));
}

LLVMTypeRef LLVMGetType(LLVMValueRef V) {
return wrap(unwrap(V)->getType());
}

LLVMTypeRef LLVMGetFunctionType(LLVMValueRef Fn) {
auto Ftype = unwrap<Function>(Fn)->getFunctionType();
return wrap(Ftype);
Expand Down
6 changes: 1 addition & 5 deletions lib/libLLVM_extra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,6 @@ function LLVMGetFunctionType(Fn)
ccall((:LLVMGetFunctionType,libLLVMExtra), LLVMTypeRef, (LLVMValueRef,), Fn)
end

function LLVMGetType(V)
ccall((:LLVMGetType, libLLVMExtra), LLVMTypeRef, (LLVMValueRef,), V)
end

function LLVMGetBuilderContext(B)
ccall((:LLVMGetBuilderContext, libLLVMExtra), LLVMContextRef, (LLVMBuilderRef,), B)
end
end
19 changes: 9 additions & 10 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ end
eltyp = LLVM.Int32Type(ctx)

ptrtyp = LLVM.PointerType(eltyp)

if LLVM.supports_typed_pointers(ctx)
if supports_typed_ptrs
@test eltype(ptrtyp) == eltyp
end

Expand Down Expand Up @@ -548,7 +547,7 @@ end
@testset "constant expressions" begin

# inline assembly
if LLVM.supports_typed_pointers(ctx)
if supports_typed_ptrs
let
ft = LLVM.FunctionType(LLVM.VoidType(ctx))
asm = InlineAsm(ft, "nop", "", false)
Expand Down Expand Up @@ -590,7 +589,7 @@ end
ce = f(val, other_val)::LLVM.Constant
@check_ir ce "i32 84"
end
if LLVM.version() < v"15"
if supports_typed_ptrs
for f in [const_udiv, const_sdiv]
ce = f(val, other_val)::LLVM.Constant
@check_ir ce "i32 21"
Expand All @@ -604,7 +603,7 @@ end
@check_ir ce "i32 0"
end
end

ce = const_and(val, other_val)::LLVM.Constant
@check_ir ce "i32 2"

Expand Down Expand Up @@ -658,7 +657,7 @@ end
@check_ir ce "float -4.200000e+01"

other_val = LLVM.ConstantFP(Float32(2.); ctx)
if LLVM.version() < v"15"
if supports_typed_ptrs
ce = const_fadd(val, other_val)::LLVM.Constant
@check_ir ce "float 4.400000e+01"

Expand Down Expand Up @@ -701,15 +700,15 @@ end
@check_ir ce "i32 0"

ce = const_inttoptr(ce, llvmtype(ptr))::LLVM.Constant
if LLVM.supports_typed_pointers(ctx)
if supports_typed_ptrs
@check_ir ce "i32* null"
else
@check_ir ce "ptr null"
end
@test isempty(uses(ptr))
for f in [const_addrspacecast, const_pointercast]
ce = f(ptr, LLVM.PointerType(LLVM.Int32Type(ctx), 1))::LLVM.Constant
if LLVM.supports_typed_pointers(ctx)
if supports_typed_ptrs
@check_ir ce "i32 addrspace(1)* addrspacecast (i32* null to i32 addrspace(1)*)"
else
@check_ir ce "ptr addrspace(1) addrspacecast (ptr null to ptr addrspace(1))"
Expand Down Expand Up @@ -1167,7 +1166,7 @@ end
fn = LLVM.Function(mod, intr)
@test fn isa LLVM.Function

if LLVM.supports_typed_pointers(ctx)
if supports_typed_ptrs
@test llvmeltype(fn) == ft
end
@test isintrinsic(fn)
Expand All @@ -1194,7 +1193,7 @@ end

fn = LLVM.Function(mod, intr, [LLVM.DoubleType(ctx)])
@test fn isa LLVM.Function
if LLVM.supports_typed_pointers(ctx)
if supports_typed_ptrs
@test llvmeltype(fn) == ft
end
@test isintrinsic(fn)
Expand Down
6 changes: 6 additions & 0 deletions test/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ macro check_ir(inst, str)
@test occursin($(str), inst)
end
end

const supports_typed_ptrs = begin
@dispose ctx=Context() begin
LLVM.supports_typed_pointers(ctx)
end
end
16 changes: 8 additions & 8 deletions test/instructions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
array_allocainst = array_alloca!(builder, LLVM.Int32Type(ctx), int1)
@check_ir array_allocainst "alloca i32, i32 %0"

if LLVM.supports_typed_pointers(ctx)
if supports_typed_ptrs
mallocinst = malloc!(builder, LLVM.Int32Type(ctx))
@check_ir mallocinst r"bitcast i8\* %.+ to i32\*"
@check_ir operands(mallocinst)[1] r"call i8\* @malloc\(.+\)"
Expand Down Expand Up @@ -256,22 +256,22 @@
@check_ir fpextinst "fpext float %2 to double"

ptrtointinst = ptrtoint!(builder, parameters(fn)[5], LLVM.Int32Type(ctx))
if LLVM.supports_typed_pointers(ctx)
if supports_typed_ptrs
@check_ir ptrtointinst "ptrtoint i32* %4 to i32"
else
@check_ir ptrtointinst "ptrtoint ptr %4 to i32"
end

inttoptrinst = inttoptr!(builder, int1, LLVM.PointerType(LLVM.Int32Type(ctx)))
if LLVM.supports_typed_pointers(ctx)
if supports_typed_ptrs
@check_ir inttoptrinst "inttoptr i32 %0 to i32*"
else
@check_ir inttoptrinst "inttoptr i32 %0 to ptr"
end

bitcastinst = bitcast!(builder, int1, LLVM.FloatType(ctx))
@check_ir bitcastinst "bitcast i32 %0 to float"
if LLVM.supports_typed_pointers(ctx)
if supports_typed_ptrs
i32ptr1 = parameters(fn)[5]
i32ptr1typ = llvmtype(i32ptr1)
i32ptr1typ2 = LLVM.PointerType(eltype(i32ptr1typ), 2)
Expand All @@ -296,7 +296,7 @@
castinst = cast!(builder, LLVM.API.LLVMBitCast, int1, LLVM.FloatType(ctx))
@check_ir castinst "bitcast i32 %0 to float"

if LLVM.supports_typed_pointers(ctx)
if supports_typed_ptrs
floatptrtyp = LLVM.PointerType(LLVM.FloatType(ctx))

pointercastinst = pointercast!(builder, i32ptr1, floatptrtyp)
Expand All @@ -323,7 +323,7 @@

trap = LLVM.Function(mod, "llvm.trap", LLVM.FunctionType(LLVM.VoidType(ctx)))

if LLVM.supports_typed_pointers(ctx)
if supports_typed_ptrs
callinst = call!(builder, trap)
else
callinst = call!(builder, LLVM.FunctionType(LLVM.VoidType(ctx)), trap)
Expand Down Expand Up @@ -351,7 +351,7 @@
@check_ir strinst "private unnamed_addr constant [7 x i8] c\"foobar\\00\""

strptrinst = globalstring_ptr!(builder, "foobar")
if LLVM.supports_typed_pointers(ctx)
if supports_typed_ptrs
@check_ir strptrinst "i8* getelementptr inbounds ([7 x i8], [7 x i8]* @1, i32 0, i32 0)"
else
@check_ir strptrinst "private unnamed_addr constant [7 x i8] c\"foobar\\00\""
Expand All @@ -364,7 +364,7 @@
@check_ir isnotnullinst "icmp ne i32 %0, 0"


if LLVM.supports_typed_pointers(ctx)
if supports_typed_ptrs
i32ptr1 = parameters(fn)[5]
i32ptr2 = parameters(fn)[6]
ptrdiffinst = ptrdiff!(builder, i32ptr1, i32ptr2)
Expand Down
10 changes: 5 additions & 5 deletions test/interop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,19 @@ end
# FIXME: Win32 nightly emits a i64*, even though bitstype_to_llvm uses T_int8
@test_broken contains(ir, r"@julia_unsafe_load_\d+\(i8\*")
else
if LLVM.version() < v"15"
if supports_typed_ptrs
@test contains(ir, r"@julia_unsafe_load_\d+\(i8\*")
else
@test contains(ir, r"@julia_unsafe_load_\d+\(ptr")
end
end
if LLVM.version() < v"15"
if supports_typed_ptrs
@test contains(ir, r"load i64, i64\* %\d+, align 1")
else
@test contains(ir, r"load i64, ptr %\d+, align 1")
end
ir = sprint(io->code_llvm(io, unsafe_load, Tuple{typeof(ptr), Int, Val{4}}))
if LLVM.version() < v"15"
if supports_typed_ptrs
@test contains(ir, r"load i64, i64\* %\d+, align 4")
else
@test contains(ir, r"load i64, ptr %\d+, align 4")
Expand All @@ -218,7 +218,7 @@ end
for eltype_dest in (Int64, Int32), AS_dest in (4, 3)
T_dest = Core.LLVMPtr{eltype_dest, AS_dest}
ir = sprint(io->code_llvm(io, LLVM.Interop.addrspacecast, Tuple{Type{T_dest}, typeof(ptr)}))
if LLVM.version() < v"15"
if supports_typed_ptrs
if AS_dest == 3
@test contains(ir, r"addrspacecast i8 addrspace\(4\)\* %\d+ to i8 addrspace\(3\)\*")
else
Expand Down Expand Up @@ -271,7 +271,7 @@ end
@test !occursin("\bstore\b", ir)
end

if LLVM.version() < v"15"
if supports_typed_ptrs
@testset "type-preserving ccall" begin
# NOTE: the auto-upgrader will remangle these intrinsics, but only if they were
# specified in the first place (`if Name.startswith("ptr.annotation.")`)
Expand Down
2 changes: 1 addition & 1 deletion test/transform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ end
speculative_execution_if_has_branch_divergence!(pm)
simple_loop_unroll!(pm)
inductive_range_check_elimination!(pm)
if LLVM.version() < v"15"
if supports_typed_ptrs
argument_promotion!(pm)
end
constant_merge!(pm)
Expand Down

0 comments on commit e2ec2f3

Please sign in to comment.