From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ff82986c79efd148 X-Google-Attributes: gid103376,public From: dewar@cs.nyu.edu (Robert Dewar) Subject: Re: Q: inlining Date: 1996/06/16 Message-ID: #1/1 X-Deja-AN: 161181451 references: organization: Courant Institute of Mathematical Sciences newsgroups: comp.lang.ada Date: 1996-06-16T00:00:00+00:00 List-Id: Jon Anthony said (of inter-unit inlining): "It can, yes. I'm not sure if this is working in GNAT 3.05 yet or not." Certainly it is! Once again Robert consults his secret source of GNAT information (namely the standard documentation in gnatinfo.txt :-) and provides the full answer: Inlining of Subprograms ----------------------- A call to a subprogram in the current unit is inlined if all the following conditions are met: o The optimization level is at least -O1 o The called subprogram is suitable for inlining. It must be small enough and not contain nested subprograms or anything else that GCC cannot support in inlined subprograms. o The call occurs after the definition of the body of the subprogram. o Either pragma Inline applies to the subprogram, or it is very small and automatic inlining (optimization level -O3) is specified. Calls to subprograms in with'ed units are normally not inlined. To achieve this level of inlining, the following conditions must be true. o The optimization level is at least -O1 o The called subprogram is suitable for inlining. It must be small enough and not contain nested subprograms or anything else that GCC cannot support in inlined subprograms. o The call appears in a body (not in a package spec). o There is a pragma Inline for the subprogram o The -gnatn switch is used in the GCC command line Note that specifying the -gnatn switch causes additional compilation dependencies. Consider the following: package R is procedure Q; pragma Inline Q; end R; package body R is ... end R; with R; procedure Main is begin ... R.Q; end Main; With the default behavior (no -gnatn switch specified), the compilation of the Main procedure depends only on its own source, main.adb, and the spec of the package in file r.ads. This means that editing the body of R does not require recompiling Main. On the other hand, the call R.Q is not inlined under these circumstances. If the -gnatn switch is present when Main is compiled, then the call will be inlined if the body of Q is small enough, but now Main depends on the body of R in r.adb as well as the spec. This means that if the body is edited, then the main program must be recompiled. Note that this extra dependency occurs whether or not the call is in fact inlined by GCC. Note: the GCC switch -fno-inline can be used to prevent all inlining. This switch overrides all other conditions, and ensures that no inlining occurs. The extra dependencies resulting from -gnatn will still be active, even if the -fno-inline switch is used. ------------------ All this is in the section: PERFORMANCE CONSIDERATIONS which contains lots of useful stuff. In fact there is all sorts of useful stuff in gnatinfo.txt, recommended reading for all GNAT users!