public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* New feature: -fdump-gimple-nodes (once more, with feeling)
@ 2024-02-13 19:46 Robert Dubner
  2024-02-14  7:40 ` Andi Kleen
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Robert Dubner @ 2024-02-13 19:46 UTC (permalink / raw)
  To: 'GCC Mailing List'

I have not contributed to GCC before, so I am not totally sure how to go
about it.

So, I am letting you know what I want to do, so that I can get advice on a
good way to do it.  I have read https://gcc.gnu.org/contribute.html, and I
have reviewed the Gnu Coding Standards and the GCC additional coding
standards, so I have some idea of what's needed.  But there is a gulf
between theory and practice, and I am hoping for guidance.
 
Jim Lowden and I have been developing a COBOL front end for GCC.  He's
primarily been parsing the language.  It's been my task to generate the
GENERIC/GIMPLE trees for the parsed code.  We've been working at this for
a couple of years.  We have reached the point where we want to start
submitting patches for the community to evaluate.
 
I figured I would start small, where "small" means mainly one new source
code file of 1,580 lines.

When I first started trying to generate GIMPLE trees to implement
functions, it became clear to me that I needed to be able to
reverse-engineer known good trees generated by the C front end.  Oh, I
could see what other front ends were doing in their source code.  But I
didn't know what the goal was.  I wanted to see not just individual nodes,
but how they all related to each other.

There didn't seem to be any such functionality in GCC.  I found a routine
in print-tree.cc which printed out a single node, but I needed to
understand the entire tree of nodes for a function.  And I very quickly
got tired -- very tired -- of trying to figure out the relationships
between nodes, and I wanted more information than the print-tree routines
were providing.

So, I created the gcc/dump-gimple-nodes.cc source code, which implements
the dump_gimple_nodes() function, which is controlled by the new
-fdump-gimple-nodes GCC command-line option.  That option hooks into the
top of the gimplify_function_tree() function in gcc/gimplify.cc.

The dump_gimple_nodes() function does a depth-first walk of the specified
function_decl, outputting each node once in a readable format.  Each node
gets an arbitrary identifying number.  There are two output files; the
first, "func_name.nodes", is pure text.  After I got tired of endlessly
searching through the text file for the next node of interest, I created
the "func_name.nodes.html" file, which is the same information with
internal hyperlinks between the nodes.

Here are the first two nodes of a typical simple function:

***********************************This is NodeNumber0
(0x7f12e13b0d00) NodeNumber0
tree_code: function_decl
tree_code_class: tcc_declaration
base_flags: static public
type: NodeNumber1 function_type
name: NodeNumber6410 identifier_node "main"
context: NodeNumber107 translation_unit_decl "bigger.c"
source_location: bigger.c:7:5
uid: 3663
initial(bindings): NodeNumber6411 block
machine_mode: QI(15)
align: 8
warn_if_not_align: 0
pt_uid: 3663
raw_assembler_name: NodeNumber6410 identifier_node "main"
visibility: default
result: NodeNumber6412 result_decl
function(pointer): 0x7f12e135d508
arguments: NodeNumber6413 parm_decl "argc"
saved_tree(function_body): NodeNumber6417 statement_list
function_code: 0
function_flags: public no_instrument_function_entry_exit
***********************************This is NodeNumber1
(0x7f12e13b3d20) NodeNumber1
tree_code: function_type
tree_code_class: tcc_type
machine_mode: QI(15)
type: NodeNumber2 integer_type
address_space:0
size(in bits): NodeNumber55 uint128 8
size_unit(in bytes): NodeNumber12 uint64 1
uid: 1515
precision: 0
contains_placeholder: 0
align: 8
warn_if_not_align: 0
alias_set_type: -1
canonical: NodeNumber1 function_type
main_variant: NodeNumber1 function_type
values: NodeNumber6408 tree_list
***********************************

Note how even when an attribute points to another node, e.g.,

arguments: NodeNumber6413 parm_decl "argc"

the output routine goes down another level or two in an attempt to make it
more meaningful.  The attribute points just to NodeNumber6413, but the
output shows that node to be a parm_decl, and there is additional code
that recognizes that a parm_decl has an identifier_node with the value
"argc".

An example of a complete dump is available at
https://www.dubner.com/main.nodes.html.  The C source code that generated
it is available at the end of
https://cobolworx.com/pages/dump-gimple-nodes.html

I found this feature to be absolutely necessary when figuring out how
working front ends built valid GIMPLE trees for functions.  I am hopeful
other developers can see the utility.

Does this require any further discussion?  Or is my next step to start
developing the series of patches that will create the dump-gimple-nodes
source code, and that will modify Makefile.in, gimplify.cc, and common.opt
to incorporate it?

Thanks so much for any suggestions and guidance,

Bob Dubner


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-02-16 14:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-13 19:46 New feature: -fdump-gimple-nodes (once more, with feeling) Robert Dubner
2024-02-14  7:40 ` Andi Kleen
2024-02-14 14:10   ` David Malcolm
2024-02-16 14:42   ` Florian Weimer
2024-02-14 10:24 ` Richard Biener
2024-02-14 16:31 ` Dimitar Dimitrov
2024-02-14 21:41   ` Robert Dubner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).