1 /* The common simulator framework for GDB, the GNU Debugger.
3 Copyright 2002-2024 Free Software Foundation, Inc.
5 Contributed by Andrew Cagney and Red Hat.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 /* INLINE CODE SELECTION:
30 GCC -O3 attempts to inline any function or procedure in scope. The
31 options below facilitate finer grained control over what is and
32 what is not inlined. In particular, it allows the selection of
33 modules for inlining. Doing this allows the compiler to both
34 eliminate the overhead of function calls and (as a consequence)
35 also eliminate further dead code.
37 On a CISC (x86) I've found that I can achieve an order of magnitude
38 speed improvement (x3-x5). In the case of RISC (sparc) while the
39 performance gain isn't as great it is still significant.
41 Each module is controlled by the macro <module>_INLINE which can
42 have the values described below
46 Do not inline any thing for the given module
48 The following bit fields values can be combined:
53 Include the C file for the module into the file being
54 compiled. The actual inlining is controlled separatly.
56 While of no apparent benefit, this makes it possible for the
57 included module, when compiled, to inline its calls to what
58 would otherwize be external functions.
60 {C_,H_} Determines where the module is inlined. A
61 H_REVEALS_MODULE will be included everywhere.
65 Make external functions within the module `inline'. Thus if
66 the module is included into a file being compiled, calls to
67 the included modules funtions can be eliminated. INLINE_MODULE
68 implies REVEAL_MODULE.
72 Make internal (static) functions within the module `inline'.
77 The inline ability is enabled by specifying every data and function
78 declaration and definition using one of the following methods:
81 GLOBAL INLINE FUNCTIONS:
83 Such functions are small and used heavily. Inlining them
84 will eliminate an unnecessary function call overhead.
86 .h: INLINE_OURPKG (void) ourpkg_func
90 .c: INLINE_OURPKG (void)
98 GLOBAL INLINE VARIABLES:
100 This doesn't make much sense.
103 GLOBAL NON-INLINE (EXTERN) FUNCTIONS AND VARIABLES:
105 These include functions with varargs parameters. It can
106 also include large rarely used functions that contribute
109 .h: extern int ourpkg_print
111 extern int a_global_variable;
113 .c: #if EXTERN_OURPKG_P
115 ourpkg_print (char *fmt,
122 int a_global_variable = 1;
126 LOCAL (STATIC) FUNCTIONS:
128 These can either be marked inline or just static static vis:
130 .h: STATIC_INLINE_OURPKG (int) ourpkg_staticf (void);
131 .c: STATIC_INLINE_OURPKG (int)
132 ourpkg_staticf (void)
137 .h: STATIC_OURPKG (int) ourpkg_staticf (void);
138 .c: STATIC_OURPKG (int)
139 ourpkg_staticf (void)
148 All modules must wrap their .h code in the following:
155 In addition, modules that want to allow global inlining must
156 include the lines (below) at the end of the .h file. (FIXME:
157 Shouldn't be needed).
159 #if H_REVEALS_MODULE_P (OURPKG_INLINE)
166 All modules must wrap their .c code in the following
178 Since no inlining is defined. All macro's get standard defaults
179 (extern, static, ...).
183 H_REVEALS_MODULE (alt includes our):
186 altprog.c defines ALTPROG_C and then includes sim-inline.h.
188 In sim-inline.h the expression `` H_REVEALS_MODULE_P
189 (OURPROG_INLINE) && ! defined (OURPROG_C) && REVEAL_MODULE_P
190 (OURPROG_INLINE) '' is TRUE so it defines *_OURPROG as static
191 and EXTERN_OURPROG_P as FALSE.
193 altprog.c includes ourprog.h.
195 In ourprog.h the expression ``H_REVEALS_MODULE_P
196 (OURPROG_INLINE)'' is TRUE so it includes ourprog.c.
198 Consequently, all the code in ourprog.c is visible and static in
203 H_REVEALS_MODULE (our includes our):
206 ourprog.c defines OURPROG_C and then includes sim-inline.h.
208 In sim-inline.h the term `` ! defined (OURPROG_C) '' is FALSE so
209 it defines *_OURPROG as non-static and EXTERN_OURPROG_P as TRUE.
211 ourprog.c includes ourprog.h.
213 In ourprog.h the expression ``H_REVEALS_MODULE_P
214 (OURPROG_INLINE)'' is true so it includes ourprog.c.
216 In ourprog.c (second include) the expression defined (OURPROG_C)
217 and so the body is not re-included.
219 Consequently, ourprog.o will contain a non-static copy of all
220 the exported symbols.
224 C_REVEALS_MODULE (alt includes our):
227 altprog.c defines ALTPROG_C and then includes sim-inline.c
229 sim-inline.c defines C_INLINE_C and then includes sim-inline.h
231 In sim-inline.h the expression `` defined (SIM_INLINE) && !
232 defined (OURPROG_C) && REVEAL_MODULE_P (OURPROG_INLINE) '' is
233 true so it defines *_OURPROG as static and EXTERN_OURPROG_P as
236 In sim-inline.c the expression ``C_REVEALS_MODULE_P
237 (OURPROG_INLINE)'' is true so it includes ourprog.c.
239 Consequently, all the code in ourprog.c is visible and static in
244 C_REVEALS_MODULE (our includes our):
247 ourprog.c defines OURPROG_C and then includes sim-inline.c
249 sim-inline.c defines C_INLINE_C and then includes sim-inline.h
251 In sim-inline.h the term `` ! defined (OURPROG_C) '' is FALSE
252 so it defines *_OURPROG as non-static and EXTERN_OURPROG_P as
255 Consequently, ourprog.o will contain a non-static copy of all
256 the exported symbols.
262 This is not for the faint hearted. I've seen GCC get up to 500mb
263 trying to compile what this can create. */
265 #define H_REVEALS_MODULE 1
266 #define C_REVEALS_MODULE 2
267 #define INLINE_GLOBALS 4
268 #define INLINE_LOCALS 8
270 #define ALL_H_INLINE (H_REVEALS_MODULE | INLINE_GLOBALS | INLINE_LOCALS)
271 #define ALL_C_INLINE (C_REVEALS_MODULE | INLINE_GLOBALS | INLINE_LOCALS)
274 /* Default macro to simplify control several of key the inlines */
276 #ifndef DEFAULT_INLINE
277 #define DEFAULT_INLINE INLINE_LOCALS
280 #define REVEAL_MODULE_P(X) (X & (H_REVEALS_MODULE | C_REVEALS_MODULE))
281 #define H_REVEALS_MODULE_P(X) ((X & H_REVEALS_MODULE))
282 #define C_REVEALS_MODULE_P(X) ((X & C_REVEALS_MODULE))
292 /* Your compilers inline prefix */
295 #if defined (__GNUC__) && defined (__OPTIMIZE__)
296 #define INLINE __inline__
298 #define INLINE /*inline*/
302 /* ??? Temporary, pending decision to always use extern inline and do a vast
303 cleanup of inline support. */
305 #if defined (__GNUC_GNU_INLINE__) || defined (__GNUC_STDC_INLINE__)
306 #define INLINE2 __inline__ __attribute__ ((__gnu_inline__))
307 #elif defined (__GNUC__)
308 #define INLINE2 __inline__
310 #define INLINE2 /*inline*/
315 /* Your compiler's static inline prefix */
317 #ifndef STATIC_INLINE
318 #define STATIC_INLINE static INLINE
322 /* Your compiler's extern inline prefix */
324 #ifndef EXTERN_INLINE
325 #define EXTERN_INLINE extern INLINE2
329 /* Your compilers's unused reserved word */
331 #if !defined (UNUSED)
332 #define UNUSED ATTRIBUTE_UNUSED
341 #if !defined (SIM_ARANGE_INLINE) && (DEFAULT_INLINE)
342 # define SIM_ARANGE_INLINE (ALL_H_INLINE)
345 #if ((H_REVEALS_MODULE_P (SIM_ARANGE_INLINE) || defined (SIM_INLINE_C)) \
346 && !defined (SIM_ARANGE_C) \
347 && (REVEAL_MODULE_P (SIM_ARANGE_INLINE)))
348 # if (SIM_ARANGE_INLINE & INLINE_GLOBALS)
349 # define INLINE_SIM_ARANGE(TYPE) static INLINE UNUSED TYPE
350 # define EXTERN_SIM_ARANGE_P 0
352 # define INLINE_SIM_ARANGE(TYPE) static UNUSED TYPE
353 # define EXTERN_SIM_ARANGE_P 0
356 # define INLINE_SIM_ARANGE(TYPE) TYPE
357 # define EXTERN_SIM_ARANGE_P 1
360 #if (SIM_ARANGE_INLINE & INLINE_LOCALS)
361 # define STATIC_INLINE_SIM_ARANGE(TYPE) static INLINE TYPE
363 # define STATIC_INLINE_SIM_ARANGE(TYPE) static TYPE
366 #define STATIC_SIM_ARANGE(TYPE) static TYPE
371 sim-bits and sim-endian are treated differently from the rest
372 of the modules below. Their default value is ALL_H_INLINE.
373 The rest are ALL_C_INLINE. Don't blink, you'll miss it!
379 #if !defined (SIM_BITS_INLINE) && (DEFAULT_INLINE)
380 # define SIM_BITS_INLINE (ALL_H_INLINE)
383 #if ((H_REVEALS_MODULE_P (SIM_BITS_INLINE) || defined (SIM_INLINE_C)) \
384 && !defined (SIM_BITS_C) \
385 && (REVEAL_MODULE_P (SIM_BITS_INLINE)))
386 # if (SIM_BITS_INLINE & INLINE_GLOBALS)
387 # define INLINE_SIM_BITS(TYPE) static INLINE UNUSED TYPE
388 # define EXTERN_SIM_BITS_P 0
390 # define INLINE_SIM_BITS(TYPE) static UNUSED TYPE
391 # define EXTERN_SIM_BITS_P 0
394 # define INLINE_SIM_BITS(TYPE) TYPE
395 # define EXTERN_SIM_BITS_P 1
398 #if (SIM_BITS_INLINE & INLINE_LOCALS)
399 # define STATIC_INLINE_SIM_BITS(TYPE) static INLINE TYPE
401 # define STATIC_INLINE_SIM_BITS(TYPE) static TYPE
404 #define STATIC_SIM_BITS(TYPE) static TYPE
410 #if !defined (SIM_CORE_INLINE) && (DEFAULT_INLINE)
411 # define SIM_CORE_INLINE ALL_C_INLINE
414 #if ((H_REVEALS_MODULE_P (SIM_CORE_INLINE) || defined (SIM_INLINE_C)) \
415 && !defined (SIM_CORE_C) \
416 && (REVEAL_MODULE_P (SIM_CORE_INLINE)))
417 # if (SIM_CORE_INLINE & INLINE_GLOBALS)
418 # define INLINE_SIM_CORE(TYPE) static INLINE UNUSED TYPE
419 # define EXTERN_SIM_CORE_P 0
421 # define INLINE_SIM_CORE(TYPE) static UNUSED TYPE
422 # define EXTERN_SIM_CORE_P 0
425 # define INLINE_SIM_CORE(TYPE) TYPE
426 # define EXTERN_SIM_CORE_P 1
429 #if (SIM_CORE_INLINE & INLINE_LOCALS)
430 # define STATIC_INLINE_SIM_CORE(TYPE) static INLINE TYPE
432 # define STATIC_INLINE_SIM_CORE(TYPE) static TYPE
435 #define STATIC_SIM_CORE(TYPE) static TYPE
441 #if !defined (SIM_ENDIAN_INLINE) && (DEFAULT_INLINE)
442 # define SIM_ENDIAN_INLINE ALL_H_INLINE
445 #if ((H_REVEALS_MODULE_P (SIM_ENDIAN_INLINE) || defined (SIM_INLINE_C)) \
446 && !defined (SIM_ENDIAN_C) \
447 && (REVEAL_MODULE_P (SIM_ENDIAN_INLINE)))
448 # if (SIM_ENDIAN_INLINE & INLINE_GLOBALS)
449 # define INLINE_SIM_ENDIAN(TYPE) static INLINE UNUSED TYPE
450 # define EXTERN_SIM_ENDIAN_P 0
452 # define INLINE_SIM_ENDIAN(TYPE) static UNUSED TYPE
453 # define EXTERN_SIM_ENDIAN_P 0
456 # define INLINE_SIM_ENDIAN(TYPE) TYPE
457 # define EXTERN_SIM_ENDIAN_P 1
460 #if (SIM_ENDIAN_INLINE & INLINE_LOCALS)
461 # define STATIC_INLINE_SIM_ENDIAN(TYPE) static INLINE TYPE
463 # define STATIC_INLINE_SIM_ENDIAN(TYPE) static TYPE
466 #define STATIC_SIM_ENDIAN(TYPE) static TYPE
472 #if !defined (SIM_EVENTS_INLINE) && (DEFAULT_INLINE)
473 # define SIM_EVENTS_INLINE ALL_C_INLINE
476 #if ((H_REVEALS_MODULE_P (SIM_EVENTS_INLINE) || defined (SIM_INLINE_C)) \
477 && !defined (SIM_EVENTS_C) \
478 && (REVEAL_MODULE_P (SIM_EVENTS_INLINE)))
479 # if (SIM_EVENTS_INLINE & INLINE_GLOBALS)
480 # define INLINE_SIM_EVENTS(TYPE) static INLINE UNUSED TYPE
481 # define EXTERN_SIM_EVENTS_P 0
483 # define INLINE_SIM_EVENTS(TYPE) static UNUSED TYPE
484 # define EXTERN_SIM_EVENTS_P 0
487 # define INLINE_SIM_EVENTS(TYPE) TYPE
488 # define EXTERN_SIM_EVENTS_P 1
491 #if (SIM_EVENTS_INLINE & INLINE_LOCALS)
492 # define STATIC_INLINE_SIM_EVENTS(TYPE) static INLINE TYPE
494 # define STATIC_INLINE_SIM_EVENTS(TYPE) static TYPE
497 #define STATIC_SIM_EVENTS(TYPE) static TYPE
503 #if !defined (SIM_FPU_INLINE) && (DEFAULT_INLINE)
504 # define SIM_FPU_INLINE ALL_C_INLINE
507 #if ((H_REVEALS_MODULE_P (SIM_FPU_INLINE) || defined (SIM_INLINE_C)) \
508 && !defined (SIM_FPU_C) \
509 && (REVEAL_MODULE_P (SIM_FPU_INLINE)))
510 # if (SIM_FPU_INLINE & INLINE_GLOBALS)
511 # define INLINE_SIM_FPU(TYPE) static INLINE UNUSED TYPE
512 # define EXTERN_SIM_FPU_P 0
514 # define INLINE_SIM_FPU(TYPE) static UNUSED TYPE
515 # define EXTERN_SIM_FPU_P 0
518 # define INLINE_SIM_FPU(TYPE) TYPE
519 # define EXTERN_SIM_FPU_P 1
522 #if (SIM_FPU_INLINE & INLINE_LOCALS)
523 # define STATIC_INLINE_SIM_FPU(TYPE) static INLINE TYPE
525 # define STATIC_INLINE_SIM_FPU(TYPE) static TYPE
528 #define STATIC_SIM_FPU(TYPE) static TYPE
534 #if ((H_REVEALS_MODULE_P (SIM_TYPES_INLINE) || defined (SIM_INLINE_C)) \
535 && !defined (SIM_TYPES_C) \
536 && (REVEAL_MODULE_P (SIM_TYPES_INLINE)))
537 # if (SIM_TYPES_INLINE & INLINE_GLOBALS)
538 # define INLINE_SIM_TYPES(TYPE) static INLINE UNUSED TYPE
539 # define EXTERN_SIM_TYPES_P 0
541 # define INLINE_SIM_TYPES(TYPE) static UNUSED TYPE
542 # define EXTERN_SIM_TYPES_P 0
545 # define INLINE_SIM_TYPES(TYPE) TYPE
546 # define EXTERN_SIM_TYPES_P 1
549 #if (SIM_TYPES_INLINE & INLINE_LOCALS)
550 # define STATIC_INLINE_SIM_TYPES(TYPE) static INLINE TYPE
552 # define STATIC_INLINE_SIM_TYPES(TYPE) static TYPE
555 #define STATIC_SIM_TYPES(TYPE) static TYPE
561 #if !defined (SIM_MAIN_INLINE) && (DEFAULT_INLINE)
562 # define SIM_MAIN_INLINE (ALL_C_INLINE)
565 #if ((H_REVEALS_MODULE_P (SIM_MAIN_INLINE) || defined (SIM_INLINE_C)) \
566 && !defined (SIM_MAIN_C) \
567 && (REVEAL_MODULE_P (SIM_MAIN_INLINE)))
568 # if (SIM_MAIN_INLINE & INLINE_GLOBALS)
569 # define INLINE_SIM_MAIN(TYPE) static INLINE UNUSED TYPE
570 # define EXTERN_SIM_MAIN_P 0
572 # define INLINE_SIM_MAIN(TYPE) static UNUSED TYPE
573 # define EXTERN_SIM_MAIN_P 0
576 # define INLINE_SIM_MAIN(TYPE) TYPE
577 # define EXTERN_SIM_MAIN_P 1
580 #if (SIM_MAIN_INLINE & INLINE_LOCALS)
581 # define STATIC_INLINE_SIM_MAIN(TYPE) static INLINE TYPE
583 # define STATIC_INLINE_SIM_MAIN(TYPE) static TYPE
586 #define STATIC_SIM_MAIN(TYPE) static TYPE
590 #if ((H_REVEALS_MODULE_P (ENGINE_INLINE) || defined (SIM_INLINE_C)) \
591 && !defined (ENGINE_C) \
592 && (REVEAL_MODULE_P (ENGINE_INLINE)))
593 # if (ENGINE_INLINE & INLINE_GLOBALS)
594 # define INLINE_ENGINE(TYPE) static INLINE UNUSED TYPE
595 # define EXTERN_ENGINE_P 0
597 # define INLINE_ENGINE(TYPE) static UNUSED TYPE
598 # define EXTERN_ENGINE_P 0
601 # define INLINE_ENGINE(TYPE) TYPE
602 # define EXTERN_ENGINE_P 1
605 #if (ENGINE_INLINE & INLINE_LOCALS)
606 # define STATIC_INLINE_ENGINE(TYPE) static INLINE TYPE
608 # define STATIC_INLINE_ENGINE(TYPE) static TYPE
611 #define STATIC_ENGINE(TYPE) static TYPE
617 #if ((H_REVEALS_MODULE_P (ICACHE_INLINE) || defined (SIM_INLINE_C)) \
618 && !defined (ICACHE_C) \
619 && (REVEAL_MODULE_P (ICACHE_INLINE)))
620 # if (ICACHE_INLINE & INLINE_GLOBALS)
621 # define INLINE_ICACHE(TYPE) static INLINE UNUSED TYPE
622 # define EXTERN_ICACHE_P 0
624 # define INLINE_ICACHE(TYPE) static UNUSED TYPE
625 # define EXTERN_ICACHE_P 0
628 # define INLINE_ICACHE(TYPE) TYPE
629 # define EXTERN_ICACHE_P 1
632 #if (ICACHE_INLINE & INLINE_LOCALS)
633 # define STATIC_INLINE_ICACHE(TYPE) static INLINE TYPE
635 # define STATIC_INLINE_ICACHE(TYPE) static TYPE
638 #define STATIC_ICACHE(TYPE) static TYPE
644 #if ((H_REVEALS_MODULE_P (IDECODE_INLINE) || defined (SIM_INLINE_C)) \
645 && !defined (IDECODE_C) \
646 && (REVEAL_MODULE_P (IDECODE_INLINE)))
647 # if (IDECODE_INLINE & INLINE_GLOBALS)
648 # define INLINE_IDECODE(TYPE) static INLINE UNUSED TYPE
649 # define EXTERN_IDECODE_P 0
651 # define INLINE_IDECODE(TYPE) static UNUSED TYPE
652 # define EXTERN_IDECODE_P 0
655 # define INLINE_IDECODE(TYPE) TYPE
656 # define EXTERN_IDECODE_P 1
659 #if (IDECODE_INLINE & INLINE_LOCALS)
660 # define STATIC_INLINE_IDECODE(TYPE) static INLINE TYPE
662 # define STATIC_INLINE_IDECODE(TYPE) static TYPE
665 #define STATIC_IDECODE(TYPE) static TYPE
671 #if ((H_REVEALS_MODULE_P (SEMANTICS_INLINE) || defined (SIM_INLINE_C)) \
672 && !defined (SEMANTICS_C) \
673 && (REVEAL_MODULE_P (SEMANTICS_INLINE)))
674 # if (SEMANTICS_INLINE & INLINE_GLOBALS)
675 # define INLINE_SEMANTICS(TYPE) static INLINE UNUSED TYPE
676 # define EXTERN_SEMANTICS_P 0
678 # define INLINE_SEMANTICS(TYPE) static UNUSED TYPE
679 # define EXTERN_SEMANTICS_P 0
682 # define INLINE_SEMANTICS(TYPE) TYPE
683 # define EXTERN_SEMANTICS_P 1
686 #if EXTERN_SEMANTICS_P
687 # define EXTERN_SEMANTICS(TYPE) TYPE
689 # define EXTERN_SEMANTICS(TYPE) static UNUSED TYPE
692 #if (SEMANTICS_INLINE & INLINE_LOCALS)
693 # define STATIC_INLINE_SEMANTICS(TYPE) static INLINE TYPE
695 # define STATIC_INLINE_SEMANTICS(TYPE) static TYPE
698 #define STATIC_SEMANTICS(TYPE) static TYPE
704 #if !defined (SUPPORT_INLINE) && (DEFAULT_INLINE)
705 # define SUPPORT_INLINE ALL_C_INLINE
708 #if ((H_REVEALS_MODULE_P (SUPPORT_INLINE) || defined (SIM_INLINE_C)) \
709 && !defined (SUPPORT_C) \
710 && (REVEAL_MODULE_P (SUPPORT_INLINE)))
711 # if (SUPPORT_INLINE & INLINE_GLOBALS)
712 # define INLINE_SUPPORT(TYPE) static INLINE UNUSED TYPE
713 # define EXTERN_SUPPORT_P 0
715 # define INLINE_SUPPORT(TYPE) static UNUSED TYPE
716 # define EXTERN_SUPPORT_P 0
719 # define INLINE_SUPPORT(TYPE) TYPE
720 # define EXTERN_SUPPORT_P 1
723 #if (SUPPORT_INLINE & INLINE_LOCALS)
724 # define STATIC_INLINE_SUPPORT(TYPE) static INLINE TYPE
726 # define STATIC_INLINE_SUPPORT(TYPE) static TYPE
729 #define STATIC_SUPPORT(TYPE) static TYPE