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"
|
2017-03-01 11:20:25 -08:00
|
|
|
#include "common/gen_debug.h"
|
2014-06-29 18:09:35 -07:00
|
|
|
#include "intel_asm_annotation.h"
|
2016-01-18 12:54:03 +02:00
|
|
|
#include "compiler/nir/nir.h"
|
2014-05-19 10:17:51 -07:00
|
|
|
|
2017-05-01 11:43:07 -07:00
|
|
|
__attribute__((weak)) void nir_print_instr(const nir_instr *instr, FILE *fp) {}
|
|
|
|
|
|
2014-05-19 10:17:51 -07:00
|
|
|
void
|
|
|
|
|
dump_assembly(void *assembly, int num_annotations, struct annotation *annotation,
|
2016-08-22 15:01:08 -07:00
|
|
|
const struct gen_device_info *devinfo)
|
2014-05-19 10:17:51 -07:00
|
|
|
{
|
|
|
|
|
const char *last_annotation_string = NULL;
|
|
|
|
|
const void *last_annotation_ir = NULL;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < num_annotations; i++) {
|
|
|
|
|
int start_offset = annotation[i].offset;
|
|
|
|
|
int end_offset = annotation[i + 1].offset;
|
|
|
|
|
|
|
|
|
|
if (annotation[i].block_start) {
|
2014-07-11 22:31:39 -07:00
|
|
|
fprintf(stderr, " START B%d", annotation[i].block_start->num);
|
2014-05-19 10:17:51 -07:00
|
|
|
foreach_list_typed(struct bblock_link, predecessor_link, link,
|
|
|
|
|
&annotation[i].block_start->parents) {
|
|
|
|
|
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
|
|
|
}
|
2016-12-10 22:13:05 -08:00
|
|
|
fprintf(stderr, " (%u cycles)\n", annotation[i].block_start->cycle_count);
|
2014-05-19 10:17:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (last_annotation_ir != annotation[i].ir) {
|
|
|
|
|
last_annotation_ir = annotation[i].ir;
|
|
|
|
|
if (last_annotation_ir) {
|
|
|
|
|
fprintf(stderr, " ");
|
2015-10-05 15:49:34 -07:00
|
|
|
nir_print_instr(annotation[i].ir, stderr);
|
2014-05-19 10:17:51 -07:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (last_annotation_string != annotation[i].annotation) {
|
|
|
|
|
last_annotation_string = annotation[i].annotation;
|
|
|
|
|
if (last_annotation_string)
|
|
|
|
|
fprintf(stderr, " %s\n", last_annotation_string);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-15 15:01:25 -07:00
|
|
|
brw_disassemble(devinfo, assembly, start_offset, end_offset, stderr);
|
2014-05-19 10:17:51 -07:00
|
|
|
|
2015-10-21 15:23:10 -07:00
|
|
|
if (annotation[i].error) {
|
|
|
|
|
fputs(annotation[i].error, stderr);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-19 10:17:51 -07:00
|
|
|
if (annotation[i].block_end) {
|
2014-07-11 22:31:39 -07:00
|
|
|
fprintf(stderr, " END B%d", annotation[i].block_end->num);
|
2014-05-19 10:17:51 -07:00
|
|
|
foreach_list_typed(struct bblock_link, successor_link, link,
|
|
|
|
|
&annotation[i].block_end->children) {
|
|
|
|
|
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");
|
|
|
|
|
}
|
2014-06-29 18:11:29 -07:00
|
|
|
|
2015-10-21 15:23:10 -07:00
|
|
|
static bool
|
|
|
|
|
annotation_array_ensure_space(struct annotation_info *annotation)
|
2014-06-29 18:11:29 -07:00
|
|
|
{
|
|
|
|
|
if (annotation->ann_size <= annotation->ann_count) {
|
2014-07-08 16:50:28 -07:00
|
|
|
int old_size = annotation->ann_size;
|
2014-06-29 18:11:29 -07:00
|
|
|
annotation->ann_size = MAX2(1024, annotation->ann_size * 2);
|
|
|
|
|
annotation->ann = reralloc(annotation->mem_ctx, annotation->ann,
|
|
|
|
|
struct annotation, annotation->ann_size);
|
|
|
|
|
if (!annotation->ann)
|
2015-10-21 15:23:10 -07:00
|
|
|
return false;
|
2014-07-08 16:50:28 -07:00
|
|
|
|
|
|
|
|
memset(annotation->ann + old_size, 0,
|
|
|
|
|
(annotation->ann_size - old_size) * sizeof(struct annotation));
|
2014-06-29 18:11:29 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-21 15:23:10 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-22 15:01:08 -07:00
|
|
|
void annotate(const struct gen_device_info *devinfo,
|
2015-10-21 15:23:10 -07:00
|
|
|
struct annotation_info *annotation, const struct cfg_t *cfg,
|
|
|
|
|
struct backend_instruction *inst, unsigned offset)
|
|
|
|
|
{
|
|
|
|
|
if (annotation->mem_ctx == NULL)
|
|
|
|
|
annotation->mem_ctx = ralloc_context(NULL);
|
|
|
|
|
|
|
|
|
|
if (!annotation_array_ensure_space(annotation))
|
|
|
|
|
return;
|
|
|
|
|
|
2014-06-29 18:11:29 -07:00
|
|
|
struct annotation *ann = &annotation->ann[annotation->ann_count++];
|
|
|
|
|
ann->offset = offset;
|
2014-11-13 10:40:01 -08:00
|
|
|
if ((INTEL_DEBUG & DEBUG_ANNOTATION) != 0) {
|
2014-06-29 18:11:29 -07:00
|
|
|
ann->ir = inst->ir;
|
|
|
|
|
ann->annotation = inst->annotation;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-01 15:01:23 -07:00
|
|
|
if (bblock_start(cfg->blocks[annotation->cur_block]) == inst) {
|
2014-06-29 18:11:29 -07:00
|
|
|
ann->block_start = cfg->blocks[annotation->cur_block];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* There is no hardware DO instruction on Gen6+, so since DO always
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2015-04-15 15:01:25 -07:00
|
|
|
if (devinfo->gen >= 6 && inst->opcode == BRW_OPCODE_DO) {
|
2014-06-29 18:11:29 -07:00
|
|
|
annotation->ann_count--;
|
|
|
|
|
}
|
2015-11-19 00:45:49 -08:00
|
|
|
|
|
|
|
|
if (bblock_end(cfg->blocks[annotation->cur_block]) == inst) {
|
|
|
|
|
ann->block_end = cfg->blocks[annotation->cur_block];
|
|
|
|
|
annotation->cur_block++;
|
|
|
|
|
}
|
2014-06-29 18:11:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
annotation_finalize(struct annotation_info *annotation,
|
|
|
|
|
unsigned next_inst_offset)
|
|
|
|
|
{
|
|
|
|
|
if (!annotation->ann_count)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (annotation->ann_count == annotation->ann_size) {
|
|
|
|
|
annotation->ann = reralloc(annotation->mem_ctx, annotation->ann,
|
|
|
|
|
struct annotation, annotation->ann_size + 1);
|
|
|
|
|
}
|
|
|
|
|
annotation->ann[annotation->ann_count].offset = next_inst_offset;
|
|
|
|
|
}
|
2015-10-21 15:23:10 -07:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
annotation_insert_error(struct annotation_info *annotation, unsigned offset,
|
|
|
|
|
const char *error)
|
|
|
|
|
{
|
|
|
|
|
if (!annotation->ann_count)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* We may have to split an annotation, so ensure we have enough space
|
|
|
|
|
* allocated for that case up front.
|
|
|
|
|
*/
|
|
|
|
|
if (!annotation_array_ensure_space(annotation))
|
|
|
|
|
return;
|
|
|
|
|
|
2015-11-13 12:13:14 -08:00
|
|
|
assume(annotation->ann_count > 0);
|
|
|
|
|
|
2015-10-21 15:23:10 -07:00
|
|
|
for (int i = 0; i < annotation->ann_count; i++) {
|
|
|
|
|
struct annotation *cur = &annotation->ann[i];
|
|
|
|
|
struct annotation *next = &annotation->ann[i + 1];
|
|
|
|
|
|
|
|
|
|
if (next->offset <= offset)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (offset + sizeof(brw_inst) != next->offset) {
|
|
|
|
|
memmove(next, cur,
|
|
|
|
|
(annotation->ann_count - i + 2) * sizeof(struct annotation));
|
|
|
|
|
cur->error = NULL;
|
|
|
|
|
cur->error_length = 0;
|
|
|
|
|
cur->block_end = NULL;
|
|
|
|
|
next->offset = offset + sizeof(brw_inst);
|
|
|
|
|
next->block_start = NULL;
|
|
|
|
|
annotation->ann_count++;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-16 13:42:41 -08:00
|
|
|
if (cur->error)
|
|
|
|
|
ralloc_strcat(&cur->error, error);
|
|
|
|
|
else
|
|
|
|
|
cur->error = ralloc_strdup(annotation->mem_ctx, error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-10-21 15:23:10 -07:00
|
|
|
}
|