1*38fd1498Szrj /* Print RTL for GCC. 2*38fd1498Szrj Copyright (C) 1987-2018 Free Software Foundation, Inc. 3*38fd1498Szrj 4*38fd1498Szrj This file is part of GCC. 5*38fd1498Szrj 6*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under 7*38fd1498Szrj the terms of the GNU General Public License as published by the Free 8*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later 9*38fd1498Szrj version. 10*38fd1498Szrj 11*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or 13*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14*38fd1498Szrj for more details. 15*38fd1498Szrj 16*38fd1498Szrj You should have received a copy of the GNU General Public License 17*38fd1498Szrj along with GCC; see the file COPYING3. If not see 18*38fd1498Szrj <http://www.gnu.org/licenses/>. */ 19*38fd1498Szrj 20*38fd1498Szrj #ifndef GCC_PRINT_RTL_H 21*38fd1498Szrj #define GCC_PRINT_RTL_H 22*38fd1498Szrj 23*38fd1498Szrj #ifndef GENERATOR_FILE 24*38fd1498Szrj #include "bitmap.h" 25*38fd1498Szrj #endif /* #ifndef GENERATOR_FILE */ 26*38fd1498Szrj 27*38fd1498Szrj class rtx_reuse_manager; 28*38fd1498Szrj 29*38fd1498Szrj /* A class for writing rtx to a FILE *. */ 30*38fd1498Szrj 31*38fd1498Szrj class rtx_writer 32*38fd1498Szrj { 33*38fd1498Szrj public: 34*38fd1498Szrj rtx_writer (FILE *outfile, int ind, bool simple, bool compact, 35*38fd1498Szrj rtx_reuse_manager *reuse_manager); 36*38fd1498Szrj 37*38fd1498Szrj void print_rtx (const_rtx in_rtx); 38*38fd1498Szrj void print_rtl (const_rtx rtx_first); 39*38fd1498Szrj int print_rtl_single_with_indent (const_rtx x, int ind); 40*38fd1498Szrj 41*38fd1498Szrj void finish_directive (); 42*38fd1498Szrj 43*38fd1498Szrj private: 44*38fd1498Szrj void print_rtx_operand_code_0 (const_rtx in_rtx, int idx); 45*38fd1498Szrj void print_rtx_operand_code_e (const_rtx in_rtx, int idx); 46*38fd1498Szrj void print_rtx_operand_codes_E_and_V (const_rtx in_rtx, int idx); 47*38fd1498Szrj void print_rtx_operand_code_i (const_rtx in_rtx, int idx); 48*38fd1498Szrj void print_rtx_operand_code_r (const_rtx in_rtx); 49*38fd1498Szrj void print_rtx_operand_code_u (const_rtx in_rtx, int idx); 50*38fd1498Szrj void print_rtx_operand (const_rtx in_rtx, int idx); 51*38fd1498Szrj bool operand_has_default_value_p (const_rtx in_rtx, int idx); 52*38fd1498Szrj 53*38fd1498Szrj private: 54*38fd1498Szrj FILE *m_outfile; 55*38fd1498Szrj int m_sawclose; 56*38fd1498Szrj int m_indent; 57*38fd1498Szrj bool m_in_call_function_usage; 58*38fd1498Szrj 59*38fd1498Szrj /* True means use simplified format without flags, modes, etc. */ 60*38fd1498Szrj bool m_simple; 61*38fd1498Szrj 62*38fd1498Szrj /* If true, use compact dump format: 63*38fd1498Szrj - PREV/NEXT_INSN UIDs are omitted 64*38fd1498Szrj - INSN_CODEs are omitted, 65*38fd1498Szrj - register numbers are omitted for hard and virtual regs, and 66*38fd1498Szrj non-virtual pseudos are offset relative to the first such reg, and 67*38fd1498Szrj printed with a '%' sigil e.g. "%0" for (LAST_VIRTUAL_REGISTER + 1), 68*38fd1498Szrj - insn names are prefixed with "c" (e.g. "cinsn", "cnote", etc). */ 69*38fd1498Szrj bool m_compact; 70*38fd1498Szrj 71*38fd1498Szrj /* An optional instance of rtx_reuse_manager. */ 72*38fd1498Szrj rtx_reuse_manager *m_rtx_reuse_manager; 73*38fd1498Szrj }; 74*38fd1498Szrj 75*38fd1498Szrj #ifdef BUFSIZ 76*38fd1498Szrj extern void print_rtl (FILE *, const_rtx); 77*38fd1498Szrj #endif 78*38fd1498Szrj extern void print_rtx_insn_vec (FILE *file, const vec<rtx_insn *> &vec); 79*38fd1498Szrj 80*38fd1498Szrj extern void dump_value_slim (FILE *, const_rtx, int); 81*38fd1498Szrj extern void dump_insn_slim (FILE *, const rtx_insn *); 82*38fd1498Szrj extern void dump_rtl_slim (FILE *, const rtx_insn *, const rtx_insn *, 83*38fd1498Szrj int, int); 84*38fd1498Szrj extern void print_value (pretty_printer *, const_rtx, int); 85*38fd1498Szrj extern void print_pattern (pretty_printer *, const_rtx, int); 86*38fd1498Szrj extern void print_insn (pretty_printer *pp, const rtx_insn *x, int verbose); 87*38fd1498Szrj 88*38fd1498Szrj extern void rtl_dump_bb_for_graph (pretty_printer *, basic_block); 89*38fd1498Szrj extern const char *str_pattern_slim (const_rtx); 90*38fd1498Szrj 91*38fd1498Szrj extern void print_rtx_function (FILE *file, function *fn, bool compact); 92*38fd1498Szrj 93*38fd1498Szrj #ifndef GENERATOR_FILE 94*38fd1498Szrj 95*38fd1498Szrj /* For some rtx codes (such as SCRATCH), instances are defined to only be 96*38fd1498Szrj equal for pointer equality: two distinct SCRATCH instances are non-equal. 97*38fd1498Szrj copy_rtx preserves this equality by reusing the SCRATCH instance. 98*38fd1498Szrj 99*38fd1498Szrj For example, in this x86 instruction: 100*38fd1498Szrj 101*38fd1498Szrj (cinsn (set (mem/v:BLK (scratch:DI) [0 A8]) 102*38fd1498Szrj (unspec:BLK [ 103*38fd1498Szrj (mem/v:BLK (scratch:DI) [0 A8]) 104*38fd1498Szrj ] UNSPEC_MEMORY_BLOCKAGE)) "test.c":2 105*38fd1498Szrj (nil)) 106*38fd1498Szrj 107*38fd1498Szrj the two instances of "(scratch:DI)" are actually the same underlying 108*38fd1498Szrj rtx pointer (and thus "equal"), and the insn will only be recognized 109*38fd1498Szrj (as "*memory_blockage") if this pointer-equality is preserved. 110*38fd1498Szrj 111*38fd1498Szrj To be able to preserve this pointer-equality when round-tripping 112*38fd1498Szrj through dumping/loading the rtl, we need some syntax. The first 113*38fd1498Szrj time a reused rtx is encountered in the dump, we prefix it with 114*38fd1498Szrj a reuse ID: 115*38fd1498Szrj 116*38fd1498Szrj (0|scratch:DI) 117*38fd1498Szrj 118*38fd1498Szrj Subsequent references to the rtx in the dump can be expressed using 119*38fd1498Szrj "reuse_rtx" e.g.: 120*38fd1498Szrj 121*38fd1498Szrj (reuse_rtx 0) 122*38fd1498Szrj 123*38fd1498Szrj This class is responsible for tracking a set of reuse IDs during a dump. 124*38fd1498Szrj 125*38fd1498Szrj Dumping with reuse-support is done in two passes: 126*38fd1498Szrj 127*38fd1498Szrj (a) a first pass in which "preprocess" is called on each top-level rtx 128*38fd1498Szrj to be seen in the dump. This traverses the rtx and its descendents, 129*38fd1498Szrj identifying rtx that will be seen more than once in the actual dump, 130*38fd1498Szrj and assigning them reuse IDs. 131*38fd1498Szrj 132*38fd1498Szrj (b) the actual dump, via print_rtx etc. print_rtx detect the presence 133*38fd1498Szrj of a live rtx_reuse_manager and uses it if there is one. Any rtx 134*38fd1498Szrj that were assigned reuse IDs will be printed with it the first time 135*38fd1498Szrj that they are seen, and then printed as "(reuse_rtx ID)" subsequently. 136*38fd1498Szrj 137*38fd1498Szrj The first phase is needed since otherwise there would be no way to tell 138*38fd1498Szrj if an rtx will be reused when first encountering it. */ 139*38fd1498Szrj 140*38fd1498Szrj class rtx_reuse_manager 141*38fd1498Szrj { 142*38fd1498Szrj public: 143*38fd1498Szrj rtx_reuse_manager (); 144*38fd1498Szrj 145*38fd1498Szrj /* The first pass. */ 146*38fd1498Szrj void preprocess (const_rtx x); 147*38fd1498Szrj 148*38fd1498Szrj /* The second pass (within print_rtx). */ 149*38fd1498Szrj bool has_reuse_id (const_rtx x, int *out); 150*38fd1498Szrj bool seen_def_p (int reuse_id); 151*38fd1498Szrj void set_seen_def (int reuse_id); 152*38fd1498Szrj 153*38fd1498Szrj private: 154*38fd1498Szrj hash_map<const_rtx, int> m_rtx_occurrence_count; 155*38fd1498Szrj hash_map<const_rtx, int> m_rtx_reuse_ids; 156*38fd1498Szrj auto_bitmap m_defs_seen; 157*38fd1498Szrj int m_next_id; 158*38fd1498Szrj }; 159*38fd1498Szrj 160*38fd1498Szrj #endif /* #ifndef GENERATOR_FILE */ 161*38fd1498Szrj 162*38fd1498Szrj #endif // GCC_PRINT_RTL_H 163