summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMaximilian Stemmer-Grabow <mail@mxsg.de>2021-06-07 18:46:12 +0200
committerAndreas Fried <andreas.fried@kit.edu>2021-12-02 12:57:28 +0100
commit85af3d8e2a6637f2fc2683ad5672331ab5410446 (patch)
treec0374a442411fd0f7a36e2caae97cb8825c7f178
parent498a3dc16579340972e6958e4bd6ce7c7caeedc0 (diff)
Allow multiple text notes to be added to nodes by the backend
These notes are emitted as part of the debugging info included in verbose ASM output
-rw-r--r--ir/be/begnuas.c63
-rw-r--r--ir/be/beinfo.c25
-rw-r--r--ir/be/beinfo.h6
-rw-r--r--ir/be/riscv/riscv_emitter.c10
4 files changed, 68 insertions, 36 deletions
diff --git a/ir/be/begnuas.c b/ir/be/begnuas.c
index 88d31fc..39ba846 100644
--- a/ir/be/begnuas.c
+++ b/ir/be/begnuas.c
@@ -1673,36 +1673,53 @@ void be_gas_end_compilation_unit(const be_main_env_t *env)
be_dwarf_close();
}
+static void be_emit_irn_notes(const ir_node *node)
+{
+ backend_info_t *be_info = be_get_info(node);
+ if (!be_info) {
+ return;
+ }
+
+ char** notes = be_info->notes;
+
+ if (notes && ARR_LEN(notes)) {
+ // Add a space, right space is added in iteration
+ be_emit_cstring("{ ");
+
+ for (size_t i = 0; i < ARR_LEN(notes); i++) {
+ be_emit_irprintf("%s ", notes[i]);
+ }
+
+ be_emit_cstring("}");
+ }
+}
+
+static void be_emit_dbg_info(const ir_node *node)
+{
+ dbg_info *const dbg = get_irn_dbg_info(node);
+ src_loc_t const loc = ir_retrieve_dbg_info(dbg);
+
+ char const *const fmt =
+ !loc.file ? "%+F" :
+ loc.line == 0 ? "%+F %s" :
+ loc.column == 0 ? "%+F %s:%u" :
+ /* */ "%+F %s:%u:%u";
+
+ be_emit_irprintf(fmt, node, loc.file, loc.line, loc.column);
+}
+
void be_emit_finish_line_gas(const ir_node *node)
{
if (node && be_options.verbose_asm) {
be_emit_pad_comment();
- char* note = NULL;
- backend_info_t *be_info = be_get_info(node);
- if (be_info) {
- note = be_info->note;
- }
+ be_emit_cstring("/* ");
- dbg_info *const dbg = get_irn_dbg_info(node);
- src_loc_t const loc = ir_retrieve_dbg_info(dbg);
+ be_emit_dbg_info(node);
+ be_emit_cstring(" ");
+ be_emit_irn_notes(node);
- if (note) {
- char const *const fmt =
- !loc.file ? "/* %+F %s */\n" :
- loc.line == 0 ? "/* %+F %s %s */\n" :
- loc.column == 0 ? "/* %+F %s %s:%u */\n" :
- /* */ "/* %+F %s %s:%u:%u */\n";
- be_emit_irprintf(fmt, node, note, loc.file, loc.line, loc.column);
- }
- else {
- char const *const fmt =
- !loc.file ? "/* %+F */\n" :
- loc.line == 0 ? "/* %+F %s */\n" :
- loc.column == 0 ? "/* %+F %s:%u */\n" :
- /* */ "/* %+F %s:%u:%u */\n";
- be_emit_irprintf(fmt, node, loc.file, loc.line, loc.column);
- }
+ be_emit_cstring(" */\n");
} else {
be_emit_char('\n');
}
diff --git a/ir/be/beinfo.c b/ir/be/beinfo.c
index be23eba..3f5ed82 100644
--- a/ir/be/beinfo.c
+++ b/ir/be/beinfo.c
@@ -117,21 +117,36 @@ int attrs_equal_be_node(const ir_node *node1, const ir_node *node2)
return true;
}
-void be_info_set_note(ir_graph *irg, const ir_node *node, const char* note)
+void be_info_add_note(const ir_node *node, const char *note)
{
+ // Proj nodes do not have associated backend info
if(is_Proj(node)) return;
- struct obstack *obst = be_get_be_obst(irg);
+ backend_info_t *info = be_get_info(node);
+ struct obstack *obst = be_get_be_obst(node->irg);
+
size_t len = strlen(note) + 1;
char *backend_note = (char*)obstack_alloc(obst, len);
memcpy(backend_note, note, len);
- backend_info_t *info = be_get_info(node);
- info->note = backend_note;
+ // @Todo This copies the full array every time a new note is appended, fix this
+ if (!info->notes) {
+ // Create the array if no notes have been set before
+ info->notes = NEW_ARR_D(char*, obst, 1);
+ info->notes[0] = backend_note;
+ } else {
+ size_t prev_len = ARR_LEN(info->notes);
+ char **prev_notes = info->notes;
+
+ info->notes = NEW_ARR_D(char*, obst, prev_len + 1);
+ for (size_t i = 0; i < prev_len; i++) {
+ info->notes[i] = prev_notes[i];
+ }
+ info->notes[prev_len] = backend_note;
+ }
}
-
static void init_walker(ir_node *node, void *data)
{
ir_graph *irg = get_irn_irg(node);
diff --git a/ir/be/beinfo.h b/ir/be/beinfo.h
index e66b8cc..09f240b 100644
--- a/ir/be/beinfo.h
+++ b/ir/be/beinfo.h
@@ -39,8 +39,8 @@ struct backend_info_t {
reg_out_info_t *out_infos;
arch_irn_flags_t flags;
- /** A text note for the node that can be set by the backend for debugging */
- char *note;
+ /** An array of text notes that can be set by the backend for debugging */
+ char **notes;
#ifndef NDEBUG
char const *orig_node;
@@ -62,6 +62,6 @@ void be_info_init_irn(ir_node *node, arch_irn_flags_t flags, arch_register_req_t
int attrs_equal_be_node(const ir_node *node1, const ir_node *node2);
-void be_info_set_note(ir_graph *irg, const ir_node *node1, const char *note);
+void be_info_add_note(const ir_node *node, const char *note);
#endif
diff --git a/ir/be/riscv/riscv_emitter.c b/ir/be/riscv/riscv_emitter.c
index a1d0026..781de2f 100644
--- a/ir/be/riscv/riscv_emitter.c
+++ b/ir/be/riscv/riscv_emitter.c
@@ -333,7 +333,7 @@ static void riscv_register_emitters(void)
be_set_emitter(op_riscv_switch, emit_riscv_switch);
}
-static void riscv_add_compressibility_info(ir_graph *const irg, ir_node *const node)
+static void riscv_add_compressibility_info(ir_node *const node)
{
struct backend_info_t *be_info = be_get_info(node);
@@ -341,11 +341,11 @@ static void riscv_add_compressibility_info(ir_graph *const irg, ir_node *const n
const char* note = compressible ? "compr=true" : "compr=false";
if (be_info) {
- be_info_set_note(irg, node, note);
+ be_info_add_note(node, note);
}
}
-static void riscv_gen_block(ir_graph *const irg, ir_node *const block)
+static void riscv_gen_block(ir_node *const block)
{
be_gas_begin_block(block);
@@ -353,7 +353,7 @@ static void riscv_gen_block(ir_graph *const irg, ir_node *const block)
// @Todo Move this to a more appropriate place
// Also, this should not need the graph as a parameter otherwise
// Set compressibility information for every block
- riscv_add_compressibility_info(irg, node);
+ riscv_add_compressibility_info(node);
// Actually emit the node
be_emit_node(node);
@@ -373,7 +373,7 @@ void riscv_emit_function(ir_graph *const irg)
be_emit_init_cf_links(blk_sched);
for (size_t i = 0, n_blocks = ARR_LEN(blk_sched); i != n_blocks; ++i) {
- riscv_gen_block(irg, blk_sched[i]);
+ riscv_gen_block(blk_sched[i]);
}
ir_free_resources(irg, IR_RESOURCE_IRN_LINK);