From patchwork Tue Nov 15 04:52:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsukasa OI X-Patchwork-Id: 20195 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a40e:b0:83:7221:86ba with SMTP id ck14csp3426472dyb; Mon, 14 Nov 2022 21:05:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf5RW89DI+cXqaiY8yMgMGEJajeza5exDkfba1vYqOc4YD7zc7jqIcjyFdATs4fzikxQuD1Y X-Received: by 2002:a17:906:4dc2:b0:7ae:50c6:fd0a with SMTP id f2-20020a1709064dc200b007ae50c6fd0amr12311133ejw.184.1668488735163; Mon, 14 Nov 2022 21:05:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668488735; cv=none; d=google.com; s=arc-20160816; b=sNSuUlhooPvLk0i44NS3wq/Gmh/F3mthcaPIgynHqVopY/KlnqYlE50mQscmd/g5mo f+nWhrLzLdntExqBEYOAjr3dDD0rsGIY/fgz92jAExhp7Q4uMpAfYxjcij2LF2Nnvr+1 paDQI40JaVA7UrFC0IY2CPT9c9WY3a64vauViF9uaPl7TqGHo+hg0aX9u0e6ga3231mt fbKmz8V/X29JJlMYNnZWYAToyHvmctXH0hWRGRAriJEiG7gZ3b09J3RLrK5P6etTcny8 zWrBVz/yeancrFROWMMSy5Lv7CJGm74qV9eKK0C0uBawvTxTC92RYOJIUe+7A7Zje8q4 yxeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=HUteqaulL0ixHyMs7sxLR6+4V+OSDyOvDkVzmxPXq6o=; b=O9duD6TSU5N3US7hs2EA1QZYqMa5SJkHsAZ8sZbUKu1xIEr1aqrlBBlubWYa/+dhmE akVte8+bTGguitTHVc5kjYcW3LpyNaASyxxdBibeE3F1OBfxBKdz+tX1h9syYullehq0 s0gFyIHnnlRFT+iAg7KPIp1VuqYGdlGo19hz0TNk+8E8aE57GGgjUbsFqr7nbqXd1yN3 56k7bfYC88bnl8fudly/b8EbIOv2I28LljcOVRwsQIagXjCGKc4Ma94DrNJRUHAP8mlV MwwQa1AMup2Eq3oVDkwXhb++mtrFLGIgwur5BqSNp5+RSOo52zlU+T1mrPurkSYYAWKL KwhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=D2dRKmBD; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c12-20020a50d64c000000b00458cbb6b6easi9776981edj.167.2022.11.14.21.05.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 21:05:35 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=D2dRKmBD; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5054038AA246 for ; Tue, 15 Nov 2022 05:03:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5054038AA246 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668488592; bh=HUteqaulL0ixHyMs7sxLR6+4V+OSDyOvDkVzmxPXq6o=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=D2dRKmBDpf1LjjUTzF+/R46iQOeoeQsOMA/HzhcHzvl/qLjQh69vcudIFVXannZ9k 25RlwOdLuKZNAVd+Hyuwr/g7FaxKThW99XMs02KSvyKx7Kfl10W1N+hu6sunU3jtxM jeaa0ytByhZOxY/TUD3Brszs2lpFNl/2aVQUudR0= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-sender-0.a4lg.com (mail-sender-0.a4lg.com [IPv6:2401:2500:203:30b:4000:6bfe:4757:0]) by sourceware.org (Postfix) with ESMTPS id 8CE1F3889E0B for ; Tue, 15 Nov 2022 04:59:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8CE1F3889E0B Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id DB4B0300089; Tue, 15 Nov 2022 04:59:28 +0000 (UTC) To: Tsukasa OI , Nelson Chu , Kito Cheng , Palmer Dabbelt Cc: binutils@sourceware.org Subject: [PATCH 11/11] RISC-V: Move disassembler private data initialization Date: Tue, 15 Nov 2022 04:52:54 +0000 Message-Id: In-Reply-To: References: Mime-Version: 1.0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tsukasa OI via Binutils From: Tsukasa OI Reply-To: Tsukasa OI Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749537243984054289?= X-GMAIL-MSGID: =?utf-8?q?1749537243984054289?= Because disassemble_info.private_data could be used not only by riscv_disassemble_insn, this commit splits the initialization of the private data to a separate function. This commit now allows storing mapping symbol and/or section-related information to riscv_private_data. In performance perspective, it also has a penalty. However, it can be easily paid back by other optimizations and it makes implementing some optimizations easier. opcodes/ChangeLog: * riscv-dis.c (init_riscv_dis_private_data): New. (riscv_disassemble_insn): Move private data initialization to init_riscv_dis_private_data. (print_insn_riscv): Start initializing the private data instead of instruction only riscv_disassemble_insn function. --- opcodes/riscv-dis.c | 51 +++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c index a57f4208f68..80eb8cbbea4 100644 --- a/opcodes/riscv-dis.c +++ b/opcodes/riscv-dis.c @@ -219,6 +219,29 @@ init_riscv_dis_state_for_arch_and_options (void) is_arch_changed = false; } +/* Initialize private data of the disassemble_info. */ + +static void +init_riscv_dis_private_data (struct disassemble_info *info) +{ + struct riscv_private_data *pd; + + pd = info->private_data = xcalloc (1, sizeof (struct riscv_private_data)); + pd->gp = 0; + pd->print_addr = 0; + for (int i = 0; i < (int)ARRAY_SIZE (pd->hi_addr); i++) + pd->hi_addr[i] = -1; + pd->to_print_addr = false; + pd->has_gp = false; + + for (int i = 0; i < info->symtab_size; i++) + if (strcmp (bfd_asymbol_name (info->symtab[i]), RISCV_GP_SYMBOL) == 0) + { + pd->gp = bfd_asymbol_value (info->symtab[i]); + pd->has_gp = true; + } +} + /* Update architecture for disassembler with its context. Call initialization functions if either: - the architecture for current context is changed or @@ -806,7 +829,7 @@ riscv_disassemble_insn (bfd_vma memaddr, insn_t word, disassemble_info *info) const struct riscv_opcode *op, *matched_op; static bool init = false; static const struct riscv_opcode *riscv_hash[OP_MASK_OP + 1]; - struct riscv_private_data *pd; + struct riscv_private_data *pd = info->private_data; int insnlen; #define OP_HASH_IDX(i) ((i) & (riscv_insn_length (i) == 2 ? 0x3 : OP_MASK_OP)) @@ -821,28 +844,6 @@ riscv_disassemble_insn (bfd_vma memaddr, insn_t word, disassemble_info *info) init = true; } - if (info->private_data == NULL) - { - int i; - - pd = info->private_data = xcalloc (1, sizeof (struct riscv_private_data)); - pd->gp = 0; - pd->print_addr = 0; - for (i = 0; i < (int)ARRAY_SIZE (pd->hi_addr); i++) - pd->hi_addr[i] = -1; - pd->to_print_addr = false; - pd->has_gp = false; - - for (i = 0; i < info->symtab_size; i++) - if (strcmp (bfd_asymbol_name (info->symtab[i]), RISCV_GP_SYMBOL) == 0) - { - pd->gp = bfd_asymbol_value (info->symtab[i]); - pd->has_gp = true; - } - } - else - pd = info->private_data; - insnlen = riscv_insn_length (word); /* RISC-V instructions are always little-endian. */ @@ -1215,6 +1216,10 @@ print_insn_riscv (bfd_vma memaddr, struct disassemble_info *info) enum riscv_seg_mstate mstate; int (*riscv_disassembler) (bfd_vma, insn_t, struct disassemble_info *); + /* Initialize the private data. */ + if (info->private_data == NULL) + init_riscv_dis_private_data (info); + /* Guess and update XLEN if we haven't determined it yet. */ if (xlen == 0) update_riscv_dis_xlen (info);