From patchwork Fri Apr 25 21:52:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 884502 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp4181119wrs; Fri, 25 Apr 2025 15:06:43 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXNBDnXg0hCxr2jdxJLjhWXUGuZbitS0+nHAoZhBRzsCf3Vk8CpxAyym5AWnu7RDGQfm4CKpw==@linaro.org X-Google-Smtp-Source: AGHT+IF3ioKsjUu2mscWh6rktn+Hbuheq71XMCHSMdPqp9nZwgomnvF1qejY47CLNrJphgbAa2Kz X-Received: by 2002:a05:620a:24c9:b0:7c9:4d96:24ce with SMTP id af79cd13be357-7c9607a7cbemr528348985a.44.1745618803544; Fri, 25 Apr 2025 15:06:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1745618803; cv=none; d=google.com; s=arc-20240605; b=Uufw3Yue4FmZvhkN9i574qhKQy9aYp2M5T0MDXnv6h2Sl8h6P0vMLyBrj6PWh21u5Z bVuG+Y/m0QDHRoc5br1Rsr/iK2W+YjLtYhqTriZ7hOPKu2IEmOlYQsbRwBMNqtFMIfOS hIZWe8Jmc34d0dBj+TxWvk8Ad88HO7XB6exlCcg63xGK7wSkInQeCYpFvq79PZSF5+yx BVeMJR4f9C2/3Q4q/8+UzVHvV9fKWUCarjT37A8Bpzr0Ccpe9XxMx48f7n9gEwOY1HhP PBfFi8hPt0U6BXO2kyjn1QCECI60Yzbba5IJUtF02SoPc3mg/VyX0nu4vTidMqx+4r33 vf7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to: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 :from:dkim-signature; bh=eO5DfNMHmibDzC5S7R129uJ9XbuwIQeM7aiNNCULxXU=; fh=D6FqPLU6GE0ldmgADbJ5dLNMSeh7MbgWcAv41ubRnOE=; b=Y9Z5aXF0gql87w3cRQX/9hp3K0ClXmI9BPpglYjwJGjtr6BfJlD4vWdF28Z6F2GuAa LxyB1oiyk4V5tNEhDXBi8Lvn2sU1fU9FflVzZ4X2uAzMJ5zePOFYElqB3jmMbg2WW9UA nXRY09MC+MXQ/VrRzK19oS+C0k1rQ45c7qO3Y1BEb9ILTq1IsLpMjN4EPyZR098OSiyK D/UPA/0R5mBqAdCKhEtaR1K9Ur3LlgGABU83boc89//363A+SDNkj8wBz/+XwBAxs3K1 WbtKCdFIr8WOPSjVIbpN30PgowliWikrTV7z5YEtxobtMQ54YoRSqnHU4HGw2OvZ3SOu zCXA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GFDSyLlm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7c958ea0ad3si448791085a.358.2025.04.25.15.06.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 25 Apr 2025 15:06:43 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GFDSyLlm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8R0n-0007HK-A1; Fri, 25 Apr 2025 17:55:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u8R0h-0007E7-AO for qemu-devel@nongnu.org; Fri, 25 Apr 2025 17:55:03 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u8R0f-0000IW-0x for qemu-devel@nongnu.org; Fri, 25 Apr 2025 17:55:02 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-736aaeed234so2394130b3a.0 for ; Fri, 25 Apr 2025 14:55:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745618099; x=1746222899; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eO5DfNMHmibDzC5S7R129uJ9XbuwIQeM7aiNNCULxXU=; b=GFDSyLlmnsv+mYUcuKdFBgTT6xxdvUoOi3eC/4rWUusPEdaz0/PfmLcEXpWGbi4G5z ASTUcxsD7RMI0BKiwsG82+hDxKyehxS3xABSSzek13o19gugUUY8kC14rC++gmQzaBws L9o8KaZSpKwrzSNK7jqT2YX7MzEseLuJUwYpK7FcUq8PmMrOqWMTAE9j7KkI9Zy5Ns+A BzrLFoxelOXGiiiBTx9MEgPLloRXSd/rHP0r58678uqFVFovtRFn6Y6opfSZ3lclxPvZ GZTz18MAZvMyGtBIHvuoVYgF1av1gRa3+kX7BxL0ox8Wa27b/clmBuUgZLXPen0l1TiB +Jdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745618099; x=1746222899; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eO5DfNMHmibDzC5S7R129uJ9XbuwIQeM7aiNNCULxXU=; b=gkqWaq/clT5CbquQh0VdyAN66OxvtnQxTQmF/jnD8/3tJ+GjGzt0vVELUScSwdLFuf lPhjhrrltCjqsXcx+RxvPxb75mtZeE12tScDGFuE/RYhgk+Q1NsABZ9dbW17N7B8u3ig HdR6z9YgPUgmhTrFzMFklhugEaiU7jbtPcqPUPOJvwIqhqWxxNJCkMTaXkmHGfzgIaUq mNdkWVCtspHPmkG1P1winlCevR0trQ0LRO6xQKqwmgklytWdJfe589gezkQ0eFrYLVPa LjFFSGWrMJCmK/TSuFubw401YNwcj6GESvsQRXNwXERkFOIS2pJ5TMfCcJfIRBSUcCps rofg== X-Gm-Message-State: AOJu0YwiUh1cZlXBOHeYp/ctq6dJRCKzlkAAYVUS8cstJ7X6KPRE80xT u6V9Hz//acN18lYxBf4Pf2e2ITh96HZag0lDdwBBjdxR68yDkNXPrAGNOqjIo6M20oaBa39yzK8 T X-Gm-Gg: ASbGncsz6l9YA5LPwk5KOaUgrjblhte+tz04oVDOC1hNP23/WKAm0K4HBPzdJPwUcoU ojqL8VHo2UieUG3GhcSSOD0CRPGTrx+Z8WODKM8RAmsbRuda3YkoK3soVkBhNqlOIi1O3ClpvFE E/Gog3WfxQNxFDXJ0qHafwyNycvQf5uHhSAC7bAWioIyFY5foGtztvatbUdfhm+Fn6BdpUr3kTM u2Oz3jIUWEdOtDT3EJThcOTxjX3i3ceJQUYFM9M22Ld6G1rmNyzUF9WFKhCTVZ3MR4Cqx1ESLlc Ew5K/a+J50tHL//AbDcGAn5Je/5HmkcCxyie3w9NUPnPg2dtOtADBoTG9H3IK27IA2IrM0A0aRU = X-Received: by 2002:a05:6a00:80f:b0:730:75b1:7219 with SMTP id d2e1a72fcca58-73fd74c7b87mr5018604b3a.12.1745618098864; Fri, 25 Apr 2025 14:54:58 -0700 (PDT) Received: from stoup.. (71-212-47-143.tukw.qwest.net. [71.212.47.143]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73e259414b0sm3664392b3a.48.2025.04.25.14.54.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 14:54:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= Subject: [PULL 005/159] tcg: Add all_outop[] Date: Fri, 25 Apr 2025 14:52:19 -0700 Message-ID: <20250425215454.886111-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250425215454.886111-1-richard.henderson@linaro.org> References: <20250425215454.886111-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Add infrastructure for more consolidated output of opcodes. The base structure allows for constraints to be either static or dynamic, and for the existence of those constraints to replace TCG_TARGET_HAS_* and the bulk of tcg_op_supported. Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- tcg/tcg.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 8 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index 198d6181d9..5090cdb3c6 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -861,6 +861,7 @@ static int tcg_out_pool_finalize(TCGContext *s) #define C_N1_O1_I4(O1, O2, I1, I2, I3, I4) C_PFX6(c_n1_o1_i4_, O1, O2, I1, I2, I3, I4), typedef enum { + C_Dynamic = -2, C_NotImplemented = -1, #include "tcg-target-con-set.h" } TCGConstraintSetIndex; @@ -954,6 +955,29 @@ static const TCGConstraintSet constraint_sets[] = { #define C_O2_I4(O1, O2, I1, I2, I3, I4) C_PFX6(c_o2_i4_, O1, O2, I1, I2, I3, I4) #define C_N1_O1_I4(O1, O2, I1, I2, I3, I4) C_PFX6(c_n1_o1_i4_, O1, O2, I1, I2, I3, I4) +/* + * TCGOutOp is the base class for a set of structures that describe how + * to generate code for a given TCGOpcode. + * + * @static_constraint: + * C_NotImplemented: The TCGOpcode is not supported by the backend. + * C_Dynamic: Use @dynamic_constraint to select a constraint set + * based on any of @type, @flags, or host isa. + * Otherwise: The register allocation constrains for the TCGOpcode. + * + * Subclasses of TCGOutOp will define a set of output routines that may + * be used. Such routines will often be selected by the set of registers + * and constants that come out of register allocation. The set of + * routines that are provided will guide the set of constraints that are + * legal. In particular, assume that tcg_optimize() has done its job in + * swapping commutative operands and folding operations for which all + * operands are constant. + */ +typedef struct TCGOutOp { + TCGConstraintSetIndex static_constraint; + TCGConstraintSetIndex (*dynamic_constraint)(TCGType type, unsigned flags); +} TCGOutOp; + #include "tcg-target.c.inc" #ifndef CONFIG_TCG_INTERPRETER @@ -963,6 +987,10 @@ QEMU_BUILD_BUG_ON((int)(offsetof(CPUNegativeOffsetState, tlb.f[0]) - < MIN_TLB_MASK_TABLE_OFS); #endif +/* Register allocation descriptions for every TCGOpcode. */ +static const TCGOutOp * const all_outop[NB_OPS] = { +}; + /* * All TCG threads except the parent (i.e. the one that called tcg_context_init * and registered the target's TCG globals) must register with this function @@ -2416,8 +2444,32 @@ bool tcg_op_supported(TCGOpcode op, TCGType type, unsigned flags) return has_type && TCG_TARGET_HAS_cmpsel_vec; default: - tcg_debug_assert(op > INDEX_op_last_generic && op < NB_OPS); + if (op < INDEX_op_last_generic) { + const TCGOutOp *outop; + TCGConstraintSetIndex con_set; + + if (!has_type) { + return false; + } + + outop = all_outop[op]; + tcg_debug_assert(outop != NULL); + + con_set = outop->static_constraint; + if (con_set == C_Dynamic) { + con_set = outop->dynamic_constraint(type, flags); + } + if (con_set >= 0) { + return true; + } + tcg_debug_assert(con_set == C_NotImplemented); + return false; + } + tcg_debug_assert(op < NB_OPS); return true; + + case INDEX_op_last_generic: + g_assert_not_reached(); } } @@ -3335,19 +3387,27 @@ static void process_constraint_sets(void) static const TCGArgConstraint *opcode_args_ct(const TCGOp *op) { - const TCGOpDef *def = &tcg_op_defs[op->opc]; + TCGOpcode opc = op->opc; + TCGType type = TCGOP_TYPE(op); + unsigned flags = TCGOP_FLAGS(op); + const TCGOpDef *def = &tcg_op_defs[opc]; + const TCGOutOp *outop = all_outop[opc]; TCGConstraintSetIndex con_set; -#ifdef CONFIG_DEBUG_TCG - assert(tcg_op_supported(op->opc, TCGOP_TYPE(op), TCGOP_FLAGS(op))); -#endif - if (def->flags & TCG_OPF_NOT_PRESENT) { return empty_cts; } - con_set = tcg_target_op_def(op->opc, TCGOP_TYPE(op), TCGOP_FLAGS(op)); - tcg_debug_assert(con_set >= 0 && con_set < ARRAY_SIZE(constraint_sets)); + if (outop) { + con_set = outop->static_constraint; + if (con_set == C_Dynamic) { + con_set = outop->dynamic_constraint(type, flags); + } + } else { + con_set = tcg_target_op_def(opc, type, flags); + } + tcg_debug_assert(con_set >= 0); + tcg_debug_assert(con_set < ARRAY_SIZE(constraint_sets)); /* The constraint arguments must match TCGOpcode arguments. */ tcg_debug_assert(constraint_sets[con_set].nb_oargs == def->nb_oargs);