From patchwork Tue Apr 23 22:58:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sriraman Tallam X-Patchwork-Id: 239022 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id BB7A22C00D1 for ; Wed, 24 Apr 2013 08:58:17 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=DOCD4y0GUP8h3STptMtoETK2hdAVCDgkrWLaI6lGLpfsZg t1KGySjV8KvlUdIH9kkNAIKFLqWGxoZv5ZBIa9i7b3zFDvN8GYiiatVwDeoKmS6y L/W8ZKgX3MYSl8k+F4v/eWdLxYHT5NCN6TFnMF45dracF3ZGNHMQNSyJSHNQ0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=/H7nLqKgguPOCoYYoYyHef15XmE=; b=azxhXuvCt/MXuID2xLxG +A+GtjdyjX6t5ojjqpmesDguEr1b64MKq5imjNhidh7523w/oM0ANE2+9Q/4hL8l D9LtNjObttPyjIAnHo+yayLHNEx2ED7AYdkWEKZAeUQ6+2T03W1C5PnwQwUj2av5 UOE7n3N7x4O3gppEMEFVIcY= Received: (qmail 10317 invoked by alias); 23 Apr 2013 22:58:10 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 10305 invoked by uid 89); 23 Apr 2013 22:58:09 -0000 X-Spam-SWARE-Status: No, score=-3.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.1 Received: from mail-ob0-f177.google.com (HELO mail-ob0-f177.google.com) (209.85.214.177) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 23 Apr 2013 22:58:08 +0000 Received: by mail-ob0-f177.google.com with SMTP id ef5so957085obb.8 for ; Tue, 23 Apr 2013 15:58:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type:x-gm-message-state; bh=5XorGykTeCIEcWDsx3ldHkB8QdByQVjkVCFreJ5mTUg=; b=kVvdvkCGD1KLjV/+Hv083ISLHj4XBC6DcdMKLeTYHnVu7Uf4UQ68B1JLZxbh3J3H0C z0wxT2iBhVD9qqmZn3CaYICD9jTb8OftHnlV4FndPrXwf/IqLXmZsP/PZe426QEy+gn1 RmEEAZof3eLQxt503wNR/6MfX3vDdwtFDiqRxco8y8xMU5TWvwsGjj6r3br4AX3yo8S1 MW9hRiICnY63CMaa9ar+EMl5N/dUQW71SuLcyT30Vkg1kIit4NJBTsz72+XIBqtbKalY 6n7futaFGqhsqIELI/Qy1ujSyq5zQvoY4UBr2/WbCuItPKC8pCBzk/DBRqDrOkqsV9v1 W2bA== MIME-Version: 1.0 X-Received: by 10.60.19.3 with SMTP id a3mr17795043oee.11.1366757886739; Tue, 23 Apr 2013 15:58:06 -0700 (PDT) Received: by 10.182.245.229 with HTTP; Tue, 23 Apr 2013 15:58:06 -0700 (PDT) Date: Tue, 23 Apr 2013 15:58:06 -0700 Message-ID: Subject: [PATCH] Generate a label for the split cold function while using -freorder-blocks-and-partition From: Sriraman Tallam To: GCC Patches , Teresa Johnson , David Li X-Gm-Message-State: ALoCoQkmt8hwZc7ZmXidv2xsLdswBUpt33fNM18QeoWO0mjRgXrehTRQB6Q0Xp0zGhwy7AbjpVdygvu4L8sLif5FRWC+zgLPnLdXsMB3sFytY2wCNKcKTAz4qLifVrK+oU4EJNGVE0QjtvMJTSLrv4TmXlqlhF94QoQ7/T0l0ZxycnSsmPQpJhamYeKy/ZNupxvBDqi0K0km X-Virus-Found: No X-IsSubscribed: yes Hi, This patch generates labels for cold function parts that are split when using the option -freorder-blocks-and-partition. The cold label name is generated by suffixing ".cold" to the assembler name of the hot function. This is useful when getting back traces from gdb when the cold function part does get executed. * final.c (final_scan_insn): Generate cold label name by suffixing ".cold" to function's assembler name. * gcc.dg/tree-prof/cold_partition_label.c: New test. Comments please. Thanks Sri Patch to generate labels for cold function parts that are split when using the option -freorder-blocks-and-partition. The cold label name is generated by suffixing ".cold" to the assembler name of the hot function. This is useful when getting back traces from gdb when the cold function part does get executed. * final.c (final_scan_insn): Generate cold label name by suffixing ".cold" to function's assembler name. * gcc.dg/tree-prof/cold_partition_label.c: New test. Index: final.c =================================================================== --- final.c (revision 198212) +++ final.c (working copy) @@ -2101,6 +2101,21 @@ final_scan_insn (rtx insn, FILE *file, int optimiz targetm.asm_out.function_switched_text_sections (asm_out_file, current_function_decl, in_cold_section_p); + /* Emit a label for the split cold section. Form label name by + suffixing ".cold" to the function's assembler name. */ + if (in_cold_section_p) + { + char *cold_function_name; + const char *mangled_function_name; + tree asm_name = DECL_ASSEMBLER_NAME (current_function_decl); + + mangled_function_name = IDENTIFIER_POINTER (asm_name); + cold_function_name = XNEWVEC (char, + strlen (mangled_function_name) + strlen (".cold") + 1); + sprintf (cold_function_name, "%s.cold", mangled_function_name); + ASM_OUTPUT_LABEL (asm_out_file, cold_function_name); + XDELETEVEC (cold_function_name); + } break; case NOTE_INSN_BASIC_BLOCK: Index: testsuite/gcc.dg/tree-prof/cold_partition_label.c =================================================================== --- testsuite/gcc.dg/tree-prof/cold_partition_label.c (revision 0) +++ testsuite/gcc.dg/tree-prof/cold_partition_label.c (revision 0) @@ -0,0 +1,39 @@ +/* Test case to check if function foo gets split and the cold function + gets a label. */ +/* { dg-require-effective-target freorder } */ +/* { dg-options "-O2 -freorder-blocks-and-partition --save-temps" } */ + +#define SIZE 10000 + +const char *sarr[SIZE]; +const char *buf_hot; +const char *buf_cold; + +__attribute__((noinline)) +void +foo (int path) +{ + int i; + if (path) + { + for (i = 0; i < SIZE; i++) + sarr[i] = buf_hot; + } + else + { + for (i = 0; i < SIZE; i++) + sarr[i] = buf_cold; + } +} + +int +main (int argc, char *argv[]) +{ + buf_hot = "hello"; + buf_cold = "world"; + foo (argc); + return 0; +} + +/* { dg-final-use { scan-assembler "foo.cold" } } */ +/* { dg-final-use { cleanup-saved-temps } } */