From b3f220a1d2c0a6f325ec0375eecaa6f689531bb0 Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Wed, 3 May 2023 15:28:22 +0300 Subject: [PATCH] sparse-llvm: Update function calls to use LLVM API changes This patch updates sparse-llvm to use the newer LLVM API functions, replacing the deprecated functions with their updated counterparts: - Replace LLVMConstGEP with LLVMConstGEP2 - Replace LLVMBuildInBoundsGEP with LLVMBuildInBoundsGEP2 - Replace LLVMBuildLoad with LLVMBuildLoad2 - Replace LLVMBuildCall with LLVMBuildCall2 The patch also ensures that the correct element types are passed to the new functions as required. Signed-off-by: Gleb Chesnokov --- sparse-llvm.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sparse-llvm.c b/sparse-llvm.c index 9ceb19a9..21b2e57f 100644 --- a/sparse-llvm.c +++ b/sparse-llvm.c @@ -296,13 +296,14 @@ static LLVMValueRef get_sym_value(LLVMModuleRef module, struct symbol *sym) const char *s = expr->string->data; LLVMValueRef indices[] = { LLVMConstInt(LLVMInt64Type(), 0, 0), LLVMConstInt(LLVMInt64Type(), 0, 0) }; LLVMValueRef data; + LLVMTypeRef gepType = LLVMPointerType(LLVMInt8Type(), 0); data = LLVMAddGlobal(module, LLVMArrayType(LLVMInt8Type(), strlen(s) + 1), ".str"); LLVMSetLinkage(data, LLVMPrivateLinkage); LLVMSetGlobalConstant(data, 1); LLVMSetInitializer(data, LLVMConstString(strdup(s), strlen(s) + 1, true)); - result = LLVMConstGEP(data, indices, ARRAY_SIZE(indices)); + result = LLVMConstGEP2(gepType, data, indices, ARRAY_SIZE(indices)); return result; } default: @@ -479,13 +480,14 @@ static LLVMValueRef calc_gep(LLVMBuilderRef builder, LLVMValueRef base, LLVMValu LLVMTypeRef type = LLVMTypeOf(base); unsigned int as = LLVMGetPointerAddressSpace(type); LLVMTypeRef bytep = LLVMPointerType(LLVMInt8Type(), as); + LLVMTypeRef elementType = LLVMGetElementType(bytep); LLVMValueRef addr; const char *name = LLVMGetValueName(off); /* convert base to char* type */ base = LLVMBuildPointerCast(builder, base, bytep, name); /* addr = base + off */ - addr = LLVMBuildInBoundsGEP(builder, base, &off, 1, name); + addr = LLVMBuildInBoundsGEP2(builder, elementType, base, &off, 1, name); /* convert back to the actual pointer type */ addr = LLVMBuildPointerCast(builder, addr, type, name); return addr; @@ -706,12 +708,14 @@ static void output_op_load(struct function *fn, struct instruction *insn) { LLVMValueRef addr, target; char name[MAX_PSEUDO_NAME]; + LLVMTypeRef elementType; addr = calc_memop_addr(fn, insn); + elementType = LLVMGetElementType(LLVMTypeOf(addr)); /* perform load */ pseudo_name(insn->target, name); - target = LLVMBuildLoad(fn->builder, addr, name); + target = LLVMBuildLoad2(fn->builder, elementType, addr, name); insn->target->priv = target; } @@ -797,6 +801,7 @@ static void output_op_switch(struct function *fn, struct instruction *insn) static void output_op_call(struct function *fn, struct instruction *insn) { LLVMValueRef target, func; + LLVMTypeRef funcType; struct symbol *ctype; int n_arg = 0, i; struct pseudo *arg; @@ -811,6 +816,9 @@ static void output_op_call(struct function *fn, struct instruction *insn) func = get_operand(fn, ctype, insn->func); else func = pseudo_to_value(fn, ctype, insn->func); + + funcType = LLVMGetElementType(LLVMTypeOf(func)); + i = 0; FOR_EACH_PTR(insn->arguments, arg) { NEXT_PTR_LIST(ctype); @@ -819,7 +827,7 @@ static void output_op_call(struct function *fn, struct instruction *insn) FINISH_PTR_LIST(ctype); pseudo_name(insn->target, name); - target = LLVMBuildCall(fn->builder, func, args, n_arg, name); + target = LLVMBuildCall2(fn->builder, funcType, func, args, n_arg, name); insn->target->priv = target; }