From patchwork Sun Apr 7 21:37:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 32193 Received: (qmail 106966 invoked by alias); 7 Apr 2019 21:38:08 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 106918 invoked by uid 89); 7 Apr 2019 21:38:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-wm1-f42.google.com Received: from mail-wm1-f42.google.com (HELO mail-wm1-f42.google.com) (209.85.128.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 07 Apr 2019 21:38:06 +0000 Received: by mail-wm1-f42.google.com with SMTP id z11so12138875wmi.0 for ; Sun, 07 Apr 2019 14:38:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=rRQrOJAE3ex3BkPBVVub3MIz5BMsQHAaMRpSvOoKuBc=; b=ejKgLLda2DQkNbpRKAWHB1PdBsoKd2WO+b2mgMqEUhEKtCjl4cST3cG9TinUtiHH8+ P7Af6OC9q8O3yH00e8shASXBYJ+kGOhaxMsKTdwxa5eRjqNN8js2B8uZOoAgh2uHlAcC mkljgr4JHm5bvTyuI6lh7guZjfrVBpLwlKNCKiq829mF4yGabxg3oly3dpufqnyII4o1 /q+ClP1f9xnOA2TqHyyzridWn7IWZw26YCFYvFw3lMLUHE4wpyPdgrvYmiUOF37O3Zbg M4BTltsB0G7AnQFO0KlfZmfGPYRIPAffZMnYQDKrr9h/nOtS3oj093vOI29rhZjxfxPu h25A== Return-Path: Received: from localhost (host86-185-77-247.range86-185.btcentralplus.com. [86.185.77.247]) by smtp.gmail.com with ESMTPSA id t15sm25292411wrx.22.2019.04.07.14.38.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Apr 2019 14:38:03 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Jim Wilson , John Baldwin , Palmer Dabbelt , Tom Tromey , Andrew Burgess Subject: [PATCH 2/2] gdb/riscv: Remove riscv_type_alignment function Date: Sun, 7 Apr 2019 22:37:55 +0100 Message-Id: <39e3d1f6667eddb68b5c5df74197ea6461e3d858.1554672870.git.andrew.burgess@embecosm.com> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes Make use of the type_align function and remove riscv_type_alignment as it is no longer needed. I tested this against a number of RV32 and RV64 targets, and I also ran the tests with an assertion in place checking that the old riscv_type_alignment function gives the same answer as the common type_align function - it does, and all the tests still pass. gdb/ChangeLog: * riscv-tdep.c (riscv_type_align): New function. (riscv_type_alignment): Delete. (riscv_arg_location): Use 'type_align'. (riscv_gdbarch_init): Register riscv_type_align gdbarch function. --- gdb/ChangeLog | 7 +++++++ gdb/riscv-tdep.c | 60 ++++++++++++-------------------------------------------- 2 files changed, 19 insertions(+), 48 deletions(-) diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c index ff5f36e7621..ed75dc59951 100644 --- a/gdb/riscv-tdep.c +++ b/gdb/riscv-tdep.c @@ -1620,55 +1620,18 @@ riscv_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp, return sp; } -/* Compute the alignment of the type T. Used while setting up the - arguments for a dummy call. */ +/* Implement the gdbarch type alignment method, overrides the generic + alignment algorithm for anything that is RISC-V specific. */ -static int -riscv_type_alignment (struct type *t) +static ULONGEST +riscv_type_align (gdbarch *gdbarch, type *type) { - t = check_typedef (t); - switch (TYPE_CODE (t)) - { - default: - error (_("Could not compute alignment of type")); - - case TYPE_CODE_RANGE: - case TYPE_CODE_RVALUE_REF: - case TYPE_CODE_PTR: - case TYPE_CODE_ENUM: - case TYPE_CODE_INT: - case TYPE_CODE_FLT: - case TYPE_CODE_REF: - case TYPE_CODE_CHAR: - case TYPE_CODE_BOOL: - return TYPE_LENGTH (t); + type = check_typedef (type); + if (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type)) + return std::min (TYPE_LENGTH (type), (ULONGEST) BIGGEST_ALIGNMENT); - case TYPE_CODE_ARRAY: - if (TYPE_VECTOR (t)) - return std::min (TYPE_LENGTH (t), (ULONGEST) BIGGEST_ALIGNMENT); - /* FALLTHROUGH */ - - case TYPE_CODE_COMPLEX: - return riscv_type_alignment (TYPE_TARGET_TYPE (t)); - - case TYPE_CODE_STRUCT: - case TYPE_CODE_UNION: - { - int i; - int align = 1; - - for (i = 0; i < TYPE_NFIELDS (t); ++i) - { - if (TYPE_FIELD_LOC_KIND (t, i) == FIELD_LOC_KIND_BITPOS) - { - int a = riscv_type_alignment (TYPE_FIELD_TYPE (t, i)); - if (a > align) - align = a; - } - } - return align; - } - } + /* Anything else will be aligned by the generic code. */ + return 0; } /* Holds information about a single argument either being passed to an @@ -2231,7 +2194,7 @@ riscv_arg_location (struct gdbarch *gdbarch, { ainfo->type = type; ainfo->length = TYPE_LENGTH (ainfo->type); - ainfo->align = riscv_type_alignment (ainfo->type); + ainfo->align = type_align (ainfo->type); ainfo->is_unnamed = is_unnamed; ainfo->contents = nullptr; @@ -2255,7 +2218,7 @@ riscv_arg_location (struct gdbarch *gdbarch, } /* Recalculate the alignment requirement. */ - ainfo->align = riscv_type_alignment (ainfo->type); + ainfo->align = type_align (ainfo->type); riscv_call_arg_scalar_int (ainfo, cinfo); break; @@ -3156,6 +3119,7 @@ riscv_gdbarch_init (struct gdbarch_info info, set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad); set_gdbarch_ptr_bit (gdbarch, riscv_isa_xlen (gdbarch) * 8); set_gdbarch_char_signed (gdbarch, 0); + set_gdbarch_type_align (gdbarch, riscv_type_align); /* Information about the target architecture. */ set_gdbarch_return_value (gdbarch, riscv_return_value);