From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id 0027A3838208 for ; Thu, 26 May 2022 19:14:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0027A3838208 Received: from [10.10.3.121] (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTPS id BC4CD40755E5; Thu, 26 May 2022 19:14:37 +0000 (UTC) Date: Thu, 26 May 2022 22:14:37 +0300 (MSK) From: Alexander Monakov To: "Yitschak, Yehuda" cc: "gcc-help@gcc.gnu.org" Subject: Re: FDO for optimal linker map In-Reply-To: <76b462cb3dab454ca4382fa5eb7d9ae0@EX13D07EUA001.ant.amazon.com> Message-ID: References: <76b462cb3dab454ca4382fa5eb7d9ae0@EX13D07EUA001.ant.amazon.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 May 2022 19:14:43 -0000 On Thu, 26 May 2022, Yitschak, Yehuda via Gcc-help wrote: > Hello > > I am learned about GCC FDO capabilities but AFAICT it doesn't effect the > function layout which the linker generates > My intention is to use the feedback data to create an optimal function layout > to minimize I-cache misses. > Meaning to group the most frequently accessed functions together and perhaps > even order them to utilize cache prefetch better. > > Is there anyway to achieve that in GCC ? Yes. The compiler can select some order of functions, and place functions in separate sections named .text.sorted.NNNN, and then the linker can emit the sections in desired order (new Binutils linker handles .text.sorted.N automatically, for older linkers you can pass --sort-section=name). As you probably know, coming up with a good reordering is the hard part. There is an experimental GCC patch that implements C3 reordering algorithm: https://gcc.gnu.org/legacy-ml/gcc-patches/2019-09/msg01142.html Alexander