From patchwork Mon Mar 27 17:33:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9647229 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9E1D4601D7 for ; Mon, 27 Mar 2017 17:38:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FDD628409 for ; Mon, 27 Mar 2017 17:38:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84B3A2840B; Mon, 27 Mar 2017 17:38:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 070C528409 for ; Mon, 27 Mar 2017 17:38:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751686AbdC0Rh1 (ORCPT ); Mon, 27 Mar 2017 13:37:27 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:33055 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751364AbdC0RhN (ORCPT ); Mon, 27 Mar 2017 13:37:13 -0400 Received: by mail-wr0-f193.google.com with SMTP id 20so15304347wrx.0 for ; Mon, 27 Mar 2017 10:36:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jZn5yXNEmkptIPPbnJzL27PTJumKlwSs7DONYVQbd6I=; b=ZYgNPYJGLNAsdDP1wCbJYeTG+6p3x5j9TQm26Z3VVXGCNcxfthXQz9bns9Zx8gVene BAflQQ0KlKWgMw3hJqTk3WJGdD9mISg14uZ21TiNNDk8JBwSuSaegYrl/eOGzBrC9Cdu UIhDQcZQ5zAKs+KGb8hzt2nRN2sL6Wtf2ddOqi3oYn8X7OdKObnY5lx4rQpPf+CLb5s1 51MPO3NM+FKYvJrX0XyJACHC1/Dprh+0u+sRmK0D7oh2Jhv7GSCxvIbUhOkxBk1rBUnp FGl4BF5PAg/A3suG9iSwJYM/cdGq3ZM1pt9ivAF+myO+MrPrjOmqzDqkbsAdZOlJqbpY DYqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jZn5yXNEmkptIPPbnJzL27PTJumKlwSs7DONYVQbd6I=; b=f2zq2s7M0qUh8E7ymjWl05w54OpSz5oiKcFfnwV3+nfD6aAh6uIitPWeRymaWCrdHc +NG92zJiHUoxNupaIWEtJdW0yFyCRUkwtV2up0b8NuhbonV+6PnBIos5tKmLB5OxArJN XNsEK8X5GMK1/tRjaWnCA+yBarPG5cUUK5gWqdmaCj1xCrHvAUsACek09TWdQ83Xqlkx g1ODU24ffYjDiDe9x8bdEnOQBA/AuL0COAjmfgPYySudKQHSnO3xOXHsVKXgPLsjUupI 63e3Q9DwzZJaPZnR6Ker/fsA0HgZjqAE+3Km0BDThESCa0yFu26TdrbzMZEbNs61vXRJ bW3Q== X-Gm-Message-State: AFeK/H1Ggm1kWTuFpkyYMXDWzZVm0WCRHKnKX8tMil925tZbdDyWIamEk8WkXxIdtm3XKg== X-Received: by 10.223.171.239 with SMTP id s102mr20874690wrc.23.1490636175007; Mon, 27 Mar 2017 10:36:15 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:802:b00:496:ae63:aebb:a034]) by smtp.gmail.com with ESMTPSA id e72sm304116wma.5.2017.03.27.10.36.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Mar 2017 10:36:14 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Luc Van Oostenryck Subject: [PATCH v6 02/15] add table to "negate" some opcode Date: Mon, 27 Mar 2017 19:33:52 +0200 Message-Id: <20170327173405.11405-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170327173405.11405-1-luc.vanoostenryck@gmail.com> References: <20170327173405.11405-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some optimizations transform an instruction opcode into another. For example, it may be needed to know the opcode corresponding to the negation of a comparison. This patch make this easy and flexible by adding a table for the relation between opcodes. Signed-off-by: Luc Van Oostenryck --- Makefile | 1 + linearize.h | 3 +++ opcode.c | 36 ++++++++++++++++++++++++++++++++++++ opcode.h | 9 +++++++++ 4 files changed, 49 insertions(+) create mode 100644 opcode.c create mode 100644 opcode.h diff --git a/Makefile b/Makefile index 76902b75e..3ac100744 100644 --- a/Makefile +++ b/Makefile @@ -106,6 +106,7 @@ LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \ expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \ char.o sort.o allocate.o compat-$(OS).o ptrlist.o \ builtin.o \ + opcode.o \ flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o LIB_FILE= libsparse.a diff --git a/linearize.h b/linearize.h index bac82d7ff..5ae78f596 100644 --- a/linearize.h +++ b/linearize.h @@ -4,6 +4,7 @@ #include "lib.h" #include "allocate.h" #include "token.h" +#include "opcode.h" #include "parse.h" #include "symbol.h" @@ -217,6 +218,8 @@ enum opcode { /* Needed to translate SSA back to normal form */ OP_COPY, + + OP_LAST, /* keep this one last! */ }; struct basic_block_list; diff --git a/opcode.c b/opcode.c new file mode 100644 index 000000000..0aed1ca1f --- /dev/null +++ b/opcode.c @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2017 Luc Van Oostenryck + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "linearize.h" + +const struct opcode_table opcode_table[OP_LAST] = { + [OP_SET_EQ] = { .negate = OP_SET_NE, }, + [OP_SET_NE] = { .negate = OP_SET_EQ, }, + [OP_SET_LT] = { .negate = OP_SET_GE, }, + [OP_SET_LE] = { .negate = OP_SET_GT, }, + [OP_SET_GE] = { .negate = OP_SET_LT, }, + [OP_SET_GT] = { .negate = OP_SET_LE, }, + [OP_SET_B ] = { .negate = OP_SET_AE, }, + [OP_SET_BE] = { .negate = OP_SET_A , }, + [OP_SET_AE] = { .negate = OP_SET_B , }, + [OP_SET_A ] = { .negate = OP_SET_BE, }, +}; diff --git a/opcode.h b/opcode.h new file mode 100644 index 000000000..3a89de05e --- /dev/null +++ b/opcode.h @@ -0,0 +1,9 @@ +#ifndef OPCODE_H +#define OPCODE_H + + +extern const struct opcode_table { + int negate:8; +} opcode_table[]; + +#endif