From patchwork Sat Apr 8 21:18:56 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: 9671317 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 C15E760365 for ; Sat, 8 Apr 2017 21:19:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B22B228387 for ; Sat, 8 Apr 2017 21:19:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A721528421; Sat, 8 Apr 2017 21:19:15 +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 4889D28387 for ; Sat, 8 Apr 2017 21:19:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752071AbdDHVTO (ORCPT ); Sat, 8 Apr 2017 17:19:14 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36684 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752002AbdDHVTO (ORCPT ); Sat, 8 Apr 2017 17:19:14 -0400 Received: by mail-wm0-f68.google.com with SMTP id q125so3594246wmd.3 for ; Sat, 08 Apr 2017 14:19:13 -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=2ZxDIWZfBKqPp+pCthFYF+XA4lFxVyHn7V/Gwl5dijQ=; b=SnZcZwjY0myl4M4eVBpecGJcl7y36Bs8SIQvCrRg8soDZ92Jq1zwTtASXnBilPiPf3 iWGzZ61Gq6fABoga2SUwD4qUGeTMQSCBtRCm2cb6Bx/ODd/Ip5nChITBzbc5J639vaMx W1XSHC5Glee0+aQZD305m2s+cuFN4/0lP3UExkavzyslLJoAo/9UP8H1OYH97WjF6ktI A9CCv+ZT3LCqhFSF22FFhiZ7jTPUL/U/o+a3WdOLVpI3lSH86L4STqpH8S0yqipFzzos mQ6Na9pIyUQc9kaPCb2lkucDaHa7hHWDW1ryYL+Shr6TAWkwz1h/gmqQ2WJ0OPhsFT2T EsLQ== 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=2ZxDIWZfBKqPp+pCthFYF+XA4lFxVyHn7V/Gwl5dijQ=; b=toRtUotDmbCfREZoyQnSIrZm69Qv8zgqcm6hGRwPxpunmXDvaFVqtyfe7w1q/ShK48 i/AEkqHxPJGqTrVDjGp4UO7PgdWpTzalAJ7IqOodyshUFPW5IP6t40RP6WqOnTMvo/y3 UPoGmA6OyonPxk7PxYw5jhXAZS1gFBqOQLfU6AHcfasRR88qmTnqWgK99xlAtOZDOA59 D1wGR7eJCSPsQdNfLClHeWjnzQfqXTsngRYf/uLihRv2NndTw46GPMA21dIy7ul8igcp /TKrvUW3lNfl+mJX6mHWRfI7MLAUrUm592KDOvAlHU75XroY71jx+203eGAusHBmAInn 2SAA== X-Gm-Message-State: AN3rC/7faKA+84ixXCjN7mDLvpDTgUm7oNHVdAq1IPwq5bFUS3hqBjhM8mEVluuxBooUFQ== X-Received: by 10.28.234.84 with SMTP id i81mr4150873wmh.80.1491686352630; Sat, 08 Apr 2017 14:19:12 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:88d:1900:3d63:d6f1:4c06:8f0f]) by smtp.gmail.com with ESMTPSA id n5sm4032362wmf.14.2017.04.08.14.19.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Apr 2017 14:19:12 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH v2 1/6] add support for a new flag: -fdump-linearize[=only] Date: Sat, 8 Apr 2017 23:18:56 +0200 Message-Id: <20170408211901.40507-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170408211901.40507-1-luc.vanoostenryck@gmail.com> References: <20170408211901.40507-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 The effect of this flag is to dump the IR just after the linearization, before any simplification, and to stop further processing if '=only' is given as argument. The motivation of this flag is of course for debugging, to be able to inspect the raw result of the linearization, undisturbed by an simplification. Signed-off-by: Luc Van Oostenryck --- lib.c | 23 +++++++++++++++++++++++ lib.h | 2 ++ linearize.c | 6 ++++++ sparse.1 | 7 +++++++ 4 files changed, 38 insertions(+) diff --git a/lib.c b/lib.c index 272d2c88a..ca8ff2d17 100644 --- a/lib.c +++ b/lib.c @@ -250,6 +250,8 @@ int Wvla = 1; int dbg_entry = 0; int dbg_dead = 0; +int fdump_linearize; + int preprocess_only; static enum { STANDARD_C89, @@ -645,12 +647,33 @@ static char **handle_switch_ftabstop(char *arg, char **next) return next; } +static char **handle_switch_fdump(char *arg, char **next) +{ + if (!strncmp(arg, "linearize", 9)) { + arg += 9; + if (*arg == '\0') + fdump_linearize = 1; + else if (!strcmp(arg, "=only")) + fdump_linearize = 2; + else + goto err; + } + + /* ignore others flags */ + return next; + +err: + die("error: unknown flag \"-fdump-%s\"", arg); +} + static char **handle_switch_f(char *arg, char **next) { arg++; if (!strncmp(arg, "tabstop=", 8)) return handle_switch_ftabstop(arg+8, next); + if (!strncmp(arg, "dump-", 5)) + return handle_switch_fdump(arg+5, next); /* handle switches w/ arguments above, boolean and only boolean below */ diff --git a/lib.h b/lib.h index 134e56040..fb612d154 100644 --- a/lib.h +++ b/lib.h @@ -136,6 +136,8 @@ extern int Wvla; extern int dbg_entry; extern int dbg_dead; +extern int fdump_linearize; + extern int arch_m64; extern void declare_builtin_functions(void); diff --git a/linearize.c b/linearize.c index 2f850fb7e..61c804333 100644 --- a/linearize.c +++ b/linearize.c @@ -2171,6 +2171,12 @@ static struct entrypoint *linearize_fn(struct symbol *sym, struct symbol *base_t add_one_insn(ep, insn); } + if (fdump_linearize) { + if (fdump_linearize == 2) + return ep; + show_entry(ep); + } + /* * Do trivial flow simplification - branches to * branches, kill dead basicblocks etc diff --git a/sparse.1 b/sparse.1 index 85d6e646b..525d3ded5 100644 --- a/sparse.1 +++ b/sparse.1 @@ -344,6 +344,13 @@ Look for system headers in the multiarch subdirectory \fIdir\fR. The \fIdir\fR name would normally take the form of the target's normalized GNU triplet. (e.g. i386-linux-gnu). . +.SH DEBUG OPTIONS +.TP +.B \-fdump-linearize[=only] +Dump the IR code of a function directly after its linearization, +before any simplifications is made. If the argument \fB=only\fR is +also given no further processing is done on the function. +. .SH OTHER OPTIONS .TP .B \-ftabstop=WIDTH