From patchwork Fri Aug 16 03:56:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 1973048 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=bDvF2iUo; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WlSqb4YFLz1yYl for ; Fri, 16 Aug 2024 13:57:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 74F5B385828E for ; Fri, 16 Aug 2024 03:57:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 555633858C3A for ; Fri, 16 Aug 2024 03:56:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 555633858C3A Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 555633858C3A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::329 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723780612; cv=none; b=N2v//ywIZomAspbOWrUewUdo1t+zp3CGBXm3MIqtX7hfKUC/YTt8FQ4uMvZeecJRxb/PKoLoVI3wA/sT6tJDEUsQqH3t0lY17cUIrhPbfXwaXpXIFZn89kDjKx1belxkJLTUk6sa0l+qNHsECOxNBpyE7jaj+EDJsI8dEKOSE94= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723780612; c=relaxed/simple; bh=PM8zmUFEO4tshTUVGMXV8udV5NQ6Rj2PrOVWJP23fpw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=i8Ha9p0nxQuUh5whIOrOEif5vdK8XUP765jA76iS8lOpHKyZQUuLfVDnDVVd6TA4v2nRnocUOpjDZo7Al5MRHARZlvO/ZdO1/dGIxfDR82MoPKA5Gj95N9jHXpwGJWmDNQbu987IBPbNyaTaHfvH/kOa488Llprm+HLHURB+n70= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-70936061d0dso1097308a34.2 for ; Thu, 15 Aug 2024 20:56:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1723780609; x=1724385409; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:date:organization:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=sqNk2oVDS15EU0S689ZnXmbEqQvpkOoX/nzGYS4qM8A=; b=bDvF2iUo3iZwEhxroMLxRqLQfETQxyuFgGNyLuwsM4Tpw1BZBNrC5y483LUIio35j5 YELZLEbnjovUhgNFwX+JyCGkFb7gYRvLjUxnnXokpYwTs/M+neyHAoRn4sEYehnyjmvz 43GM+2u1nCzMdaW/G2YR5IPMJ/QBtXc9sxaHh2EHcB09OoGdmNj71asxXwCJzY5bUdsS kflvgEKcFrfzkm8aLCWNefmcvrznC7Lcfw3Xzkq0CbBIs1thoLFuYVwrP0H49TJTQT83 qcS7jNXqGba/TWNX4kOFnGYvDC36Bf/H4dydh1Uno5vtWXWl1MJWWDTylU0+WF6yhnkh BvTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723780609; x=1724385409; h=mime-version:user-agent:message-id:date:organization:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sqNk2oVDS15EU0S689ZnXmbEqQvpkOoX/nzGYS4qM8A=; b=T2AHfdpC976kYJI+Pxf9sDe7kxdmCaCxTeF1ifmKvePmBlRlbQf6NBah+gbithzy7C ZIVqiTeiR4zTpjP1xFcA//j96eeBMIrE1nQaVJZjh6POhm5lDrrf2doTMnmTs4wJeMMw VLvBlAy2KnbfKdZs7oIhIdp7L9CVcG1vaD42a/TAD500SSm5IWTP5TloqeHGpfetakdd Y55cnrYoOcdZPCfoHzufbkOaKalNgOfrysMPxc+qYLCKfmZRpgRydNC95ukQ+tj0hAiU QsW68UrEwVP3vyfKfFi+jgkEDoYoQsKt2QPu29Y9feXoyF46ELhkWGkUmoXj10XVnW3w ob3w== X-Gm-Message-State: AOJu0YwKntCtu1/FefUtej2S2LXjIMDiNF+yNlihhuc6tQa3BM10YFSj hM0XoiRhZClwYf3m895s7WpQQeL00eqyq1nqSNSwwLRFop/fu7RAEnXnr+PVQPdEU20YSH5RnmC 8Uw== X-Google-Smtp-Source: AGHT+IGSa1DLzjUtaSTKY64nqK9gQqWRTqZ64vISks2k/7lh7FYTJRGm/dpkuCRyuTbYS/jLXgV+3Q== X-Received: by 2002:a05:6830:6c17:b0:709:410c:2c96 with SMTP id 46e09a7af769-70cac842cfemr1647198a34.10.1723780609287; Thu, 15 Aug 2024 20:56:49 -0700 (PDT) Received: from free.home ([2804:7f1:218b:fb3:deed:d05e:1601:303a]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7c6b61a6cffsm1973938a12.2.2024.08.15.20.56.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 20:56:48 -0700 (PDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 47G3ud521696300 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 16 Aug 2024 00:56:39 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: [PATCH] Dump aliases in -fcallgraph-info Organization: Free thinker, does not speak for AdaCore Date: Fri, 16 Aug 2024 00:56:39 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, WEIRD_QUOTING 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Dump ICF-unified decls, thunks, aliases and whatnot along with their ultimate targets, with edges from the alias to the target. Add support for dropping the source file's suffix when forming from dump-base, so that auxiliary files can be scanned, such as the .ci files generated by -fcallgraph-info, as in the testcase. Regstrapped on x86_64-linux-gnu. Ok to install? for gcc/ChangeLog * toplev.cc (dump_final_alias_vcg): New. (dump_final_node_vcg): Dump aliases along with node. for gcc/testsuite/ChangeLog * lib/scandump.exp (dump-base): Support {} in dump base suffix to drop it. * gcc.dg/callgraph-info-1.c: New. --- gcc/testsuite/gcc.dg/callgraph-info-1.c | 7 ++++++ gcc/testsuite/lib/scandump.exp | 4 +++ gcc/toplev.cc | 37 +++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/callgraph-info-1.c diff --git a/gcc/testsuite/gcc.dg/callgraph-info-1.c b/gcc/testsuite/gcc.dg/callgraph-info-1.c new file mode 100644 index 0000000000000..853ff9554eeb0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/callgraph-info-1.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-fcallgraph-info" } */ + +void f() {} +void g() __attribute__ ((__alias__ ("f"))); + +/* { dg-final { scan-dump-times "ci" "triangle" 1 "ci" {{}} } } */ diff --git a/gcc/testsuite/lib/scandump.exp b/gcc/testsuite/lib/scandump.exp index 14536ae7379b6..adf9886b61c96 100644 --- a/gcc/testsuite/lib/scandump.exp +++ b/gcc/testsuite/lib/scandump.exp @@ -37,6 +37,10 @@ proc dump-base { args } { # gcc-defs to base compilation dumps only on the source basename. set dumpbase $src if { [string length $dumpbase_suf] != 0 } { + # Accept {} as dump base suffix to drop the source suffix entirely. + if { "$dumpbase_suf" == "{}" } { + set dumpbase_suf "" + } regsub {[.][^.]*$} $src $dumpbase_suf dumpbase } return $dumpbase diff --git a/gcc/toplev.cc b/gcc/toplev.cc index eee4805b504a5..f308fb151083e 100644 --- a/gcc/toplev.cc +++ b/gcc/toplev.cc @@ -914,6 +914,37 @@ dump_final_callee_vcg (FILE *f, location_t location, tree callee) fputs ("\" }\n", f); } +/* Callback for cgraph_node::call_for_symbol_thunks_and_aliases to dump to F_ a + node and an edge from ALIAS->DECL to CURRENT_FUNCTION_DECL. */ + +static bool +dump_final_alias_vcg (cgraph_node *alias, void *f_) +{ + FILE *f = (FILE *)f_; + + if (alias->decl == current_function_decl) + return false; + + dump_final_node_vcg_start (f, alias->decl); + fputs ("\" shape : triangle }\n", f); + + fputs ("edge: { sourcename: \"", f); + print_decl_identifier (f, alias->decl, PRINT_DECL_UNIQUE_NAME); + fputs ("\" targetname: \"", f); + print_decl_identifier (f, current_function_decl, PRINT_DECL_UNIQUE_NAME); + location_t location = DECL_SOURCE_LOCATION (alias->decl); + if (LOCATION_LOCUS (location) != UNKNOWN_LOCATION) + { + expanded_location loc; + fputs ("\" label: \"", f); + loc = expand_location (location); + fprintf (f, "%s:%d:%d", loc.file, loc.line, loc.column); + } + fputs ("\" }\n", f); + + return false; +} + /* Dump final cgraph node in VCG format. */ static void @@ -950,6 +981,12 @@ dump_final_node_vcg (FILE *f) dump_final_callee_vcg (f, c->location, c->decl); vec_free (cfun->su->callees); cfun->su->callees = NULL; + + cgraph_node *node = cgraph_node::get (current_function_decl); + if (!node) + return; + node->call_for_symbol_thunks_and_aliases (dump_final_alias_vcg, f, + true, false); } /* Output stack usage and callgraph info, as requested. */