From patchwork Sat May 18 17:52:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?J=2E_Neusch=C3=A4fer?= X-Patchwork-Id: 2589111 Return-Path: X-Original-To: patchwork-linux-sparse@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id E44B33FE81 for ; Sat, 18 May 2013 17:52:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752169Ab3ERRwp (ORCPT ); Sat, 18 May 2013 13:52:45 -0400 Received: from mout.gmx.net ([212.227.15.18]:58937 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751912Ab3ERRwm (ORCPT ); Sat, 18 May 2013 13:52:42 -0400 Received: from mailout-de.gmx.net ([10.1.76.10]) by mrigmx.server.lan (mrigmx001) with ESMTP (Nemesis) id 0Lg2yr-1UA8aB3gHD-00pav4 for ; Sat, 18 May 2013 19:52:40 +0200 Received: (qmail invoked by alias); 18 May 2013 17:52:40 -0000 Received: from dslb-084-060-248-207.pools.arcor-ip.net (EHLO debian.debian) [84.60.248.207] by mail.gmx.net (mp010) with SMTP; 18 May 2013 19:52:40 +0200 X-Authenticated: #41721828 X-Provags-ID: V01U2FsdGVkX1+FbFV45zaFfGw8bo21utNwqPED7OElLkCXGLtAjx z6cgI/HvvFb9Fm From: =?UTF-8?q?Jonathan=20Neusch=C3=A4fer?= To: linux-sparse@vger.kernel.org Cc: =?UTF-8?q?Jonathan=20Neusch=C3=A4fer?= , Pekka Enberg , Christopher Li , Jeff Garzik , Linus Torvalds , Xi Wang Subject: [PATCH 2/4] sparse, llvm: de-duplicate load/store address calculation code Date: Sat, 18 May 2013 19:52:05 +0200 Message-Id: <1368899527-2350-2-git-send-email-j.neuschaefer@gmx.net> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1368899527-2350-1-git-send-email-j.neuschaefer@gmx.net> References: <1368899527-2350-1-git-send-email-j.neuschaefer@gmx.net> MIME-Version: 1.0 X-Y-GMX-Trusted: 0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Cc: Pekka Enberg Cc: Christopher Li Cc: Jeff Garzik Cc: Linus Torvalds Cc: Xi Wang Signed-off-by: Jonathan Neuschäfer --- sparse-llvm.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/sparse-llvm.c b/sparse-llvm.c index 837a96f..8573eda 100644 --- a/sparse-llvm.c +++ b/sparse-llvm.c @@ -598,10 +598,10 @@ static void output_op_ret(struct function *fn, struct instruction *insn) LLVMBuildRetVoid(fn->builder); } -static void output_op_load(struct function *fn, struct instruction *insn) +static LLVMValueRef calc_memop_addr(struct function *fn, struct instruction *insn) { LLVMTypeRef int_type; - LLVMValueRef src_p, src_i, ofs_i, addr_i, addr, target; + LLVMValueRef src_p, src_i, ofs_i, addr_i, addr; /* int type large enough to hold a pointer */ int_type = LLVMIntType(bits_in_pointer); @@ -617,6 +617,16 @@ static void output_op_load(struct function *fn, struct instruction *insn) addr = LLVMBuildIntToPtr(fn->builder, addr_i, LLVMTypeOf(src_p), "addr"); + return addr; +} + + +static void output_op_load(struct function *fn, struct instruction *insn) +{ + LLVMValueRef addr, target; + + addr = calc_memop_addr(fn, insn); + /* perform load */ target = LLVMBuildLoad(fn->builder, addr, "load_target"); @@ -625,22 +635,9 @@ static void output_op_load(struct function *fn, struct instruction *insn) static void output_op_store(struct function *fn, struct instruction *insn) { - LLVMTypeRef int_type; - LLVMValueRef src_p, src_i, ofs_i, addr_i, addr, target, target_in; - - /* int type large enough to hold a pointer */ - int_type = LLVMIntType(bits_in_pointer); - - /* convert to integer, add src + offset */ - src_p = pseudo_to_value(fn, insn, insn->src); - src_i = LLVMBuildPtrToInt(fn->builder, src_p, int_type, "src_i"); + LLVMValueRef addr, target, target_in; - ofs_i = LLVMConstInt(int_type, insn->offset, 0); - addr_i = LLVMBuildAdd(fn->builder, src_i, ofs_i, "addr_i"); - - /* convert address back to pointer */ - addr = LLVMBuildIntToPtr(fn->builder, addr_i, - LLVMTypeOf(src_p), "addr"); + addr = calc_memop_addr(fn, insn); target_in = pseudo_to_value(fn, insn, insn->target);