From patchwork Wed Aug 16 15:34:39 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: 9903985 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 61DA360231 for ; Wed, 16 Aug 2017 15:35:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53A0D22B27 for ; Wed, 16 Aug 2017 15:35:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 487D8286AC; Wed, 16 Aug 2017 15:35:34 +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 E8C3522B27 for ; Wed, 16 Aug 2017 15:35:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751678AbdHPPfd (ORCPT ); Wed, 16 Aug 2017 11:35:33 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:35486 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751637AbdHPPfd (ORCPT ); Wed, 16 Aug 2017 11:35:33 -0400 Received: by mail-wr0-f196.google.com with SMTP id w63so3696022wrc.2 for ; Wed, 16 Aug 2017 08:35:32 -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=zWAdQgmI9fF7z3S93euoOD2JdiGuzjBh0BC51SRUU40=; b=KCOTbQJihi3exftDFsAERWpGXrfGKbGyt3LD5kr8jLeTv2bCvfc42GgKABj9NiJmQs onhO2+l3btaHDbE5JSc+GjXxz00Qh2pZsWP+Wj20XGO8mEl2Yg18Bwv2K5QzH00XSSc2 3v8poO71xmThWxiuVNyqNzXk0CYZ5FbuPC0jZawI7rB87fbqDJE4nQTbYZSUTwSDbY21 z1xO/efgwWAzbTMkFFvYUyaMYrybd+K7j2JJ2udrU0ba+jyfKdpzcgY5k3LY/qI/oMW+ aAGhZAuL9apjeuSce1vnhOhqgjs8+14soH8mhI3zzxmv6XRd+uCRKbvvLsHiVHMbXfKX cQRg== 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=zWAdQgmI9fF7z3S93euoOD2JdiGuzjBh0BC51SRUU40=; b=HYwtDot9Zcna9ySZXpCSmOkC6XEMQXrM8JvKhVDxunWBGEfoZkOXGG/B2s2Ec71UgL GYj4/zvH72xk5NYkemFYRigss/OHNuKHpTbxzy+PD/piEsCnW5VA3+ZLgW1Zsn9Ls0Zh nYFc+nhGCfxm6TWayWGyBao98VqcElSnljye/3QMSUlK1kcM/CT+W3b4F4HvMYHdkRNo yPDjBnsxZGrLybpb9EsBbHUDJacK5+E9npd1YZVTttBkgMSzfQtXbhbKB4N4Zgh96pso mXlj1LhV6yf6RM4AYuKUj6N5o7jjoKOwbdy1h45Sr9S7WYXeN8kZXnYbci0TDHWL7pbl S9Ow== X-Gm-Message-State: AHYfb5jQC3vgUDKmGiCRDBDsq9TLH4zapNV4hojEeE53otXHMtlU0wvN uW50VrmsjgTsYcoB8bY= X-Received: by 10.80.206.7 with SMTP id y7mr767321edi.276.1502897731761; Wed, 16 Aug 2017 08:35:31 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4076:600:895a:bb88:13f:9772]) by smtp.gmail.com with ESMTPSA id y19sm690635edi.6.2017.08.16.08.35.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Aug 2017 08:35:31 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds , Christopher Li , Luc Van Oostenryck Subject: [PATCH 13/29] add insert_phi_node() Date: Wed, 16 Aug 2017 17:34:39 +0200 Message-Id: <20170816153455.97693-14-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.14.0 In-Reply-To: <20170816153455.97693-1-luc.vanoostenryck@gmail.com> References: <20170816153455.97693-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 This helper is used later during the SSA construction and is, as its name suggest, used to insert phi-nodes in the instruction stream. More exactly, the phi-node will be put at the begining of the specified BB, just after the others phi-nodes but before any other instructions. Signed-off-by: Luc Van Oostenryck --- linearize.c | 22 ++++++++++++++++++++++ linearize.h | 1 + 2 files changed, 23 insertions(+) diff --git a/linearize.c b/linearize.c index 3d14892cd..0af92a08e 100644 --- a/linearize.c +++ b/linearize.c @@ -852,6 +852,28 @@ pseudo_t alloc_phi(struct basic_block *source, pseudo_t pseudo, struct symbol *t return phi; } +pseudo_t insert_phi_node(struct basic_block *bb, struct symbol *type) +{ + struct instruction *phi_node = alloc_typed_instruction(OP_PHI, type); + struct instruction *insn; + pseudo_t phi; + + phi = alloc_pseudo(phi_node); + phi_node->target = phi; + phi_node->bb = bb; + + FOR_EACH_PTR(bb->insns, insn) { + enum opcode op = insn->opcode; + if (op == OP_ENTRY || op == OP_PHI) + continue; + INSERT_CURRENT(phi_node, insn); + return phi; + } END_FOR_EACH_PTR(insn); + + add_instruction(&bb->insns, phi_node); + return phi; +} + /* * We carry the "access_data" structure around for any accesses, * which simplifies things a lot. It contains all the access diff --git a/linearize.h b/linearize.h index 060d5f327..a67f5b3e7 100644 --- a/linearize.h +++ b/linearize.h @@ -332,6 +332,7 @@ struct entrypoint { extern void insert_select(struct basic_block *bb, struct instruction *br, struct instruction *phi, pseudo_t if_true, pseudo_t if_false); extern void insert_branch(struct basic_block *bb, struct instruction *br, struct basic_block *target); +pseudo_t insert_phi_node(struct basic_block *bb, struct symbol *type); pseudo_t alloc_phi(struct basic_block *source, pseudo_t pseudo, struct symbol *type); pseudo_t alloc_pseudo(struct instruction *def); pseudo_t value_pseudo(long long val);