2014-05-19 10:17:51 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2014 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "brw_cfg.h"
|
2014-06-28 20:37:56 -07:00
|
|
|
#include "brw_eu.h"
|
2024-01-24 22:43:58 -08:00
|
|
|
#include "brw_disasm.h"
|
2017-11-16 11:43:51 -08:00
|
|
|
#include "brw_disasm_info.h"
|
2021-04-05 10:44:41 -07:00
|
|
|
#include "dev/intel_debug.h"
|
2016-01-18 12:54:03 +02:00
|
|
|
#include "compiler/nir/nir.h"
|
2014-05-19 10:17:51 -07:00
|
|
|
|
|
|
|
|
void
|
2019-06-03 14:55:23 +03:00
|
|
|
dump_assembly(void *assembly, int start_offset, int end_offset,
|
|
|
|
|
struct disasm_info *disasm, const unsigned *block_latency)
|
2014-05-19 10:17:51 -07:00
|
|
|
{
|
2022-06-29 14:13:31 -07:00
|
|
|
const struct brw_isa_info *isa = disasm->isa;
|
2014-05-19 10:17:51 -07:00
|
|
|
const char *last_annotation_string = NULL;
|
|
|
|
|
|
2019-06-03 14:55:23 +03:00
|
|
|
void *mem_ctx = ralloc_context(NULL);
|
|
|
|
|
const struct brw_label *root_label =
|
2022-06-29 14:13:31 -07:00
|
|
|
brw_label_assembly(isa, assembly, start_offset, end_offset, mem_ctx);
|
2019-06-03 14:55:23 +03:00
|
|
|
|
2017-11-15 17:08:42 -08:00
|
|
|
foreach_list_typed(struct inst_group, group, link, &disasm->group_list) {
|
|
|
|
|
struct exec_node *next_node = exec_node_get_next(&group->link);
|
|
|
|
|
if (exec_node_is_tail_sentinel(next_node))
|
|
|
|
|
break;
|
2014-05-19 10:17:51 -07:00
|
|
|
|
2017-11-15 17:08:42 -08:00
|
|
|
struct inst_group *next =
|
|
|
|
|
exec_node_data(struct inst_group, next_node, link);
|
|
|
|
|
|
|
|
|
|
int start_offset = group->offset;
|
|
|
|
|
int end_offset = next->offset;
|
|
|
|
|
|
|
|
|
|
if (group->block_start) {
|
|
|
|
|
fprintf(stderr, " START B%d", group->block_start->num);
|
2014-05-19 10:17:51 -07:00
|
|
|
foreach_list_typed(struct bblock_link, predecessor_link, link,
|
2017-11-15 17:08:42 -08:00
|
|
|
&group->block_start->parents) {
|
2014-05-19 10:17:51 -07:00
|
|
|
struct bblock_t *predecessor_block = predecessor_link->block;
|
2014-07-11 22:31:39 -07:00
|
|
|
fprintf(stderr, " <-B%d", predecessor_block->num);
|
2014-05-19 10:17:51 -07:00
|
|
|
}
|
2020-04-02 17:42:57 -07:00
|
|
|
if (block_latency)
|
|
|
|
|
fprintf(stderr, " (%u cycles)",
|
|
|
|
|
block_latency[group->block_start->num]);
|
|
|
|
|
fprintf(stderr, "\n");
|
2014-05-19 10:17:51 -07:00
|
|
|
}
|
|
|
|
|
|
2017-11-15 17:08:42 -08:00
|
|
|
if (last_annotation_string != group->annotation) {
|
|
|
|
|
last_annotation_string = group->annotation;
|
2014-05-19 10:17:51 -07:00
|
|
|
if (last_annotation_string)
|
|
|
|
|
fprintf(stderr, " %s\n", last_annotation_string);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-29 14:13:31 -07:00
|
|
|
brw_disassemble(isa, assembly, start_offset, end_offset,
|
2019-06-03 14:55:23 +03:00
|
|
|
root_label, stderr);
|
2014-05-19 10:17:51 -07:00
|
|
|
|
2017-11-15 17:08:42 -08:00
|
|
|
if (group->error) {
|
|
|
|
|
fputs(group->error, stderr);
|
2015-10-21 15:23:10 -07:00
|
|
|
}
|
|
|
|
|
|
2017-11-15 17:08:42 -08:00
|
|
|
if (group->block_end) {
|
|
|
|
|
fprintf(stderr, " END B%d", group->block_end->num);
|
2014-05-19 10:17:51 -07:00
|
|
|
foreach_list_typed(struct bblock_link, successor_link, link,
|
2017-11-15 17:08:42 -08:00
|
|
|
&group->block_end->children) {
|
2014-05-19 10:17:51 -07:00
|
|
|
struct bblock_t *successor_block = successor_link->block;
|
2014-07-11 22:31:39 -07:00
|
|
|
fprintf(stderr, " ->B%d", successor_block->num);
|
2014-05-19 10:17:51 -07:00
|
|
|
}
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fprintf(stderr, "\n");
|
2019-06-03 14:55:23 +03:00
|
|
|
|
|
|
|
|
ralloc_free(mem_ctx);
|
2014-05-19 10:17:51 -07:00
|
|
|
}
|
2014-06-29 18:11:29 -07:00
|
|
|
|
2017-11-15 17:08:42 -08:00
|
|
|
struct disasm_info *
|
2022-06-29 14:13:31 -07:00
|
|
|
disasm_initialize(const struct brw_isa_info *isa,
|
2017-11-15 17:08:42 -08:00
|
|
|
const struct cfg_t *cfg)
|
2014-06-29 18:11:29 -07:00
|
|
|
{
|
2017-11-15 17:08:42 -08:00
|
|
|
struct disasm_info *disasm = ralloc(NULL, struct disasm_info);
|
|
|
|
|
exec_list_make_empty(&disasm->group_list);
|
2022-06-29 14:13:31 -07:00
|
|
|
disasm->isa = isa;
|
2017-11-15 17:08:42 -08:00
|
|
|
disasm->cfg = cfg;
|
|
|
|
|
disasm->cur_block = 0;
|
|
|
|
|
disasm->use_tail = false;
|
|
|
|
|
return disasm;
|
2015-10-21 15:23:10 -07:00
|
|
|
}
|
|
|
|
|
|
2017-11-15 17:08:42 -08:00
|
|
|
struct inst_group *
|
2024-02-29 17:53:53 -08:00
|
|
|
disasm_new_inst_group(struct disasm_info *disasm, int next_inst_offset)
|
2015-10-21 15:23:10 -07:00
|
|
|
{
|
2024-02-29 17:53:53 -08:00
|
|
|
assert(next_inst_offset >= 0);
|
2017-11-15 17:08:42 -08:00
|
|
|
struct inst_group *tail = rzalloc(disasm, struct inst_group);
|
|
|
|
|
tail->offset = next_inst_offset;
|
|
|
|
|
exec_list_push_tail(&disasm->group_list, &tail->link);
|
|
|
|
|
return tail;
|
|
|
|
|
}
|
2015-10-21 15:23:10 -07:00
|
|
|
|
2017-11-15 17:08:42 -08:00
|
|
|
void
|
|
|
|
|
disasm_annotate(struct disasm_info *disasm,
|
2024-02-28 15:19:38 -08:00
|
|
|
fs_inst *inst, int offset)
|
2017-11-15 17:08:42 -08:00
|
|
|
{
|
|
|
|
|
const struct cfg_t *cfg = disasm->cfg;
|
|
|
|
|
|
|
|
|
|
struct inst_group *group;
|
|
|
|
|
if (!disasm->use_tail) {
|
|
|
|
|
group = disasm_new_inst_group(disasm, offset);
|
|
|
|
|
} else {
|
2018-01-31 11:09:36 -08:00
|
|
|
disasm->use_tail = false;
|
2017-11-15 17:08:42 -08:00
|
|
|
group = exec_node_data(struct inst_group,
|
|
|
|
|
exec_list_get_tail_raw(&disasm->group_list), link);
|
|
|
|
|
}
|
2015-10-21 15:23:10 -07:00
|
|
|
|
2024-08-23 10:46:13 -07:00
|
|
|
#ifndef NDEBUG
|
2021-10-13 11:21:41 +02:00
|
|
|
if (INTEL_DEBUG(DEBUG_ANNOTATION)) {
|
2017-11-15 17:08:42 -08:00
|
|
|
group->annotation = inst->annotation;
|
2014-06-29 18:11:29 -07:00
|
|
|
}
|
2024-08-23 10:46:13 -07:00
|
|
|
#endif
|
2014-06-29 18:11:29 -07:00
|
|
|
|
2017-11-15 17:08:42 -08:00
|
|
|
if (bblock_start(cfg->blocks[disasm->cur_block]) == inst) {
|
|
|
|
|
group->block_start = cfg->blocks[disasm->cur_block];
|
2014-06-29 18:11:29 -07:00
|
|
|
}
|
|
|
|
|
|
2021-03-29 15:46:12 -07:00
|
|
|
/* There is no hardware DO instruction on Gfx6+, so since DO always
|
2014-06-29 18:11:29 -07:00
|
|
|
* starts a basic block, we need to set the .block_start of the next
|
|
|
|
|
* instruction's annotation with a pointer to the bblock started by
|
|
|
|
|
* the DO.
|
|
|
|
|
*
|
|
|
|
|
* There's also only complication from emitting an annotation without
|
|
|
|
|
* a corresponding hardware instruction to disassemble.
|
|
|
|
|
*/
|
2024-02-15 01:22:30 -08:00
|
|
|
if (inst->opcode == BRW_OPCODE_DO) {
|
2017-11-15 17:08:42 -08:00
|
|
|
disasm->use_tail = true;
|
2014-06-29 18:11:29 -07:00
|
|
|
}
|
2015-11-19 00:45:49 -08:00
|
|
|
|
2017-11-15 17:08:42 -08:00
|
|
|
if (bblock_end(cfg->blocks[disasm->cur_block]) == inst) {
|
|
|
|
|
group->block_end = cfg->blocks[disasm->cur_block];
|
|
|
|
|
disasm->cur_block++;
|
2014-06-29 18:11:29 -07:00
|
|
|
}
|
|
|
|
|
}
|
2015-10-21 15:23:10 -07:00
|
|
|
|
|
|
|
|
void
|
2024-02-29 17:53:53 -08:00
|
|
|
disasm_insert_error(struct disasm_info *disasm, int offset,
|
|
|
|
|
int inst_size, const char *error)
|
2015-10-21 15:23:10 -07:00
|
|
|
{
|
2017-11-15 17:08:42 -08:00
|
|
|
foreach_list_typed(struct inst_group, cur, link, &disasm->group_list) {
|
|
|
|
|
struct exec_node *next_node = exec_node_get_next(&cur->link);
|
|
|
|
|
if (exec_node_is_tail_sentinel(next_node))
|
|
|
|
|
break;
|
2015-11-13 12:13:14 -08:00
|
|
|
|
2017-11-15 17:08:42 -08:00
|
|
|
struct inst_group *next =
|
|
|
|
|
exec_node_data(struct inst_group, next_node, link);
|
2015-10-21 15:23:10 -07:00
|
|
|
|
|
|
|
|
if (next->offset <= offset)
|
|
|
|
|
continue;
|
|
|
|
|
|
2022-07-19 00:27:29 -07:00
|
|
|
if (offset + inst_size != next->offset) {
|
2024-02-29 17:53:53 -08:00
|
|
|
struct inst_group *new_group = ralloc(disasm, struct inst_group);
|
|
|
|
|
memcpy(new_group, cur, sizeof(struct inst_group));
|
2017-11-15 17:08:42 -08:00
|
|
|
|
2015-10-21 15:23:10 -07:00
|
|
|
cur->error = NULL;
|
|
|
|
|
cur->error_length = 0;
|
|
|
|
|
cur->block_end = NULL;
|
2017-11-15 17:08:42 -08:00
|
|
|
|
2024-02-29 17:53:53 -08:00
|
|
|
new_group->offset = offset + inst_size;
|
|
|
|
|
new_group->block_start = NULL;
|
2017-11-15 17:08:42 -08:00
|
|
|
|
2024-02-29 17:53:53 -08:00
|
|
|
exec_node_insert_after(&cur->link, &new_group->link);
|
2015-10-21 15:23:10 -07:00
|
|
|
}
|
|
|
|
|
|
2017-11-16 13:42:41 -08:00
|
|
|
if (cur->error)
|
|
|
|
|
ralloc_strcat(&cur->error, error);
|
|
|
|
|
else
|
2017-11-15 17:08:42 -08:00
|
|
|
cur->error = ralloc_strdup(disasm, error);
|
2017-11-16 13:42:41 -08:00
|
|
|
return;
|
|
|
|
|
}
|
2015-10-21 15:23:10 -07:00
|
|
|
}
|