From e2ec2f3f493fe5edc2ef90f3632080dac6e95ff2 Mon Sep 17 00:00:00 2001 From: Gabriel Baraldi Date: Mon, 20 Mar 2023 09:55:13 -0300 Subject: [PATCH] Fix some nits --- deps/LLVMExtra/include/LLVMExtra.h | 2 -- deps/LLVMExtra/lib/llvm-api.cpp | 4 ---- lib/libLLVM_extra.jl | 6 +----- test/core.jl | 19 +++++++++---------- test/helpers.jl | 6 ++++++ test/instructions.jl | 16 ++++++++-------- test/interop.jl | 10 +++++----- test/transform.jl | 2 +- 8 files changed, 30 insertions(+), 35 deletions(-) diff --git a/deps/LLVMExtra/include/LLVMExtra.h b/deps/LLVMExtra/include/LLVMExtra.h index d5ae8472..b06730a3 100644 --- a/deps/LLVMExtra/include/LLVMExtra.h +++ b/deps/LLVMExtra/include/LLVMExtra.h @@ -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, diff --git a/deps/LLVMExtra/lib/llvm-api.cpp b/deps/LLVMExtra/lib/llvm-api.cpp index 0a5ba211..e9d613ee 100644 --- a/deps/LLVMExtra/lib/llvm-api.cpp +++ b/deps/LLVMExtra/lib/llvm-api.cpp @@ -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(Fn)->getFunctionType(); return wrap(Ftype); diff --git a/lib/libLLVM_extra.jl b/lib/libLLVM_extra.jl index d5a2337a..97d695f1 100644 --- a/lib/libLLVM_extra.jl +++ b/lib/libLLVM_extra.jl @@ -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 \ No newline at end of file +end diff --git a/test/core.jl b/test/core.jl index 772c30f7..2b24bb4c 100644 --- a/test/core.jl +++ b/test/core.jl @@ -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 @@ -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) @@ -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" @@ -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" @@ -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" @@ -701,7 +700,7 @@ 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" @@ -709,7 +708,7 @@ 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))" @@ -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) @@ -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) diff --git a/test/helpers.jl b/test/helpers.jl index bf5b1ef6..f087907f 100644 --- a/test/helpers.jl +++ b/test/helpers.jl @@ -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 \ No newline at end of file diff --git a/test/instructions.jl b/test/instructions.jl index cfc85c1e..dd292852 100644 --- a/test/instructions.jl +++ b/test/instructions.jl @@ -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\(.+\)" @@ -256,14 +256,14 @@ @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" @@ -271,7 +271,7 @@ 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) @@ -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) @@ -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) @@ -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\"" @@ -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) diff --git a/test/interop.jl b/test/interop.jl index af185fb5..75b7259e 100644 --- a/test/interop.jl +++ b/test/interop.jl @@ -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") @@ -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 @@ -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.")`) diff --git a/test/transform.jl b/test/transform.jl index 549c24d9..d8cffac7 100644 --- a/test/transform.jl +++ b/test/transform.jl @@ -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)