Path: blob/21.2-virgl/src/intel/compiler/brw_disasm_info.c
4550 views
/*1* Copyright © 2014 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include "brw_cfg.h"24#include "brw_eu.h"25#include "brw_disasm_info.h"26#include "dev/intel_debug.h"27#include "compiler/nir/nir.h"2829__attribute__((weak)) void nir_print_instr(UNUSED const nir_instr *instr,30UNUSED FILE *fp) {}3132void33dump_assembly(void *assembly, int start_offset, int end_offset,34struct disasm_info *disasm, const unsigned *block_latency)35{36const struct intel_device_info *devinfo = disasm->devinfo;37const char *last_annotation_string = NULL;38const void *last_annotation_ir = NULL;3940void *mem_ctx = ralloc_context(NULL);41const struct brw_label *root_label =42brw_label_assembly(devinfo, assembly, start_offset, end_offset, mem_ctx);4344foreach_list_typed(struct inst_group, group, link, &disasm->group_list) {45struct exec_node *next_node = exec_node_get_next(&group->link);46if (exec_node_is_tail_sentinel(next_node))47break;4849struct inst_group *next =50exec_node_data(struct inst_group, next_node, link);5152int start_offset = group->offset;53int end_offset = next->offset;5455if (group->block_start) {56fprintf(stderr, " START B%d", group->block_start->num);57foreach_list_typed(struct bblock_link, predecessor_link, link,58&group->block_start->parents) {59struct bblock_t *predecessor_block = predecessor_link->block;60fprintf(stderr, " <-B%d", predecessor_block->num);61}62if (block_latency)63fprintf(stderr, " (%u cycles)",64block_latency[group->block_start->num]);65fprintf(stderr, "\n");66}6768if (last_annotation_ir != group->ir) {69last_annotation_ir = group->ir;70if (last_annotation_ir) {71fprintf(stderr, " ");72nir_print_instr(group->ir, stderr);73fprintf(stderr, "\n");74}75}7677if (last_annotation_string != group->annotation) {78last_annotation_string = group->annotation;79if (last_annotation_string)80fprintf(stderr, " %s\n", last_annotation_string);81}8283brw_disassemble(devinfo, assembly, start_offset, end_offset,84root_label, stderr);8586if (group->error) {87fputs(group->error, stderr);88}8990if (group->block_end) {91fprintf(stderr, " END B%d", group->block_end->num);92foreach_list_typed(struct bblock_link, successor_link, link,93&group->block_end->children) {94struct bblock_t *successor_block = successor_link->block;95fprintf(stderr, " ->B%d", successor_block->num);96}97fprintf(stderr, "\n");98}99}100fprintf(stderr, "\n");101102ralloc_free(mem_ctx);103}104105struct disasm_info *106disasm_initialize(const struct intel_device_info *devinfo,107const struct cfg_t *cfg)108{109struct disasm_info *disasm = ralloc(NULL, struct disasm_info);110exec_list_make_empty(&disasm->group_list);111disasm->devinfo = devinfo;112disasm->cfg = cfg;113disasm->cur_block = 0;114disasm->use_tail = false;115return disasm;116}117118struct inst_group *119disasm_new_inst_group(struct disasm_info *disasm, unsigned next_inst_offset)120{121struct inst_group *tail = rzalloc(disasm, struct inst_group);122tail->offset = next_inst_offset;123exec_list_push_tail(&disasm->group_list, &tail->link);124return tail;125}126127void128disasm_annotate(struct disasm_info *disasm,129struct backend_instruction *inst, unsigned offset)130{131const struct intel_device_info *devinfo = disasm->devinfo;132const struct cfg_t *cfg = disasm->cfg;133134struct inst_group *group;135if (!disasm->use_tail) {136group = disasm_new_inst_group(disasm, offset);137} else {138disasm->use_tail = false;139group = exec_node_data(struct inst_group,140exec_list_get_tail_raw(&disasm->group_list), link);141}142143if ((INTEL_DEBUG & DEBUG_ANNOTATION) != 0) {144group->ir = inst->ir;145group->annotation = inst->annotation;146}147148if (bblock_start(cfg->blocks[disasm->cur_block]) == inst) {149group->block_start = cfg->blocks[disasm->cur_block];150}151152/* There is no hardware DO instruction on Gfx6+, so since DO always153* starts a basic block, we need to set the .block_start of the next154* instruction's annotation with a pointer to the bblock started by155* the DO.156*157* There's also only complication from emitting an annotation without158* a corresponding hardware instruction to disassemble.159*/160if (devinfo->ver >= 6 && inst->opcode == BRW_OPCODE_DO) {161disasm->use_tail = true;162}163164if (bblock_end(cfg->blocks[disasm->cur_block]) == inst) {165group->block_end = cfg->blocks[disasm->cur_block];166disasm->cur_block++;167}168}169170void171disasm_insert_error(struct disasm_info *disasm, unsigned offset,172const char *error)173{174foreach_list_typed(struct inst_group, cur, link, &disasm->group_list) {175struct exec_node *next_node = exec_node_get_next(&cur->link);176if (exec_node_is_tail_sentinel(next_node))177break;178179struct inst_group *next =180exec_node_data(struct inst_group, next_node, link);181182if (next->offset <= offset)183continue;184185if (offset + sizeof(brw_inst) != next->offset) {186struct inst_group *new = ralloc(disasm, struct inst_group);187memcpy(new, cur, sizeof(struct inst_group));188189cur->error = NULL;190cur->error_length = 0;191cur->block_end = NULL;192193new->offset = offset + sizeof(brw_inst);194new->block_start = NULL;195196exec_node_insert_after(&cur->link, &new->link);197}198199if (cur->error)200ralloc_strcat(&cur->error, error);201else202cur->error = ralloc_strdup(disasm, error);203return;204}205}206207208