4717bafd341c8bd45c8484bed64c23bd34493c46
2 * Copyright © 2014 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 #include "brw_context.h"
27 #include "intel_debug.h"
28 #include "intel_asm_annotation.h"
29 #include "program/prog_print.h"
30 #include "program/prog_instruction.h"
31 #include "main/macros.h"
34 dump_assembly(void *assembly
, int num_annotations
, struct annotation
*annotation
,
35 struct brw_context
*brw
, const struct gl_program
*prog
)
37 const char *last_annotation_string
= NULL
;
38 const void *last_annotation_ir
= NULL
;
40 for (int i
= 0; i
< num_annotations
; i
++) {
41 int start_offset
= annotation
[i
].offset
;
42 int end_offset
= annotation
[i
+ 1].offset
;
44 if (annotation
[i
].block_start
) {
45 fprintf(stderr
, " START B%d", annotation
[i
].block_start
->block_num
);
46 foreach_list_typed(struct bblock_link
, predecessor_link
, link
,
47 &annotation
[i
].block_start
->parents
) {
48 struct bblock_t
*predecessor_block
= predecessor_link
->block
;
49 fprintf(stderr
, " <-B%d", predecessor_block
->block_num
);
51 fprintf(stderr
, "\n");
54 if (last_annotation_ir
!= annotation
[i
].ir
) {
55 last_annotation_ir
= annotation
[i
].ir
;
56 if (last_annotation_ir
) {
58 if (!prog
->Instructions
)
59 fprint_ir(stderr
, annotation
[i
].ir
);
61 const struct prog_instruction
*pi
=
62 (const struct prog_instruction
*)annotation
[i
].ir
;
63 fprintf(stderr
, "%d: ",
64 (int)(pi
- prog
->Instructions
));
65 _mesa_fprint_instruction_opt(stderr
,
67 0, PROG_PRINT_DEBUG
, NULL
);
69 fprintf(stderr
, "\n");
73 if (last_annotation_string
!= annotation
[i
].annotation
) {
74 last_annotation_string
= annotation
[i
].annotation
;
75 if (last_annotation_string
)
76 fprintf(stderr
, " %s\n", last_annotation_string
);
79 brw_disassemble(brw
, assembly
, start_offset
, end_offset
, stderr
);
81 if (annotation
[i
].block_end
) {
82 fprintf(stderr
, " END B%d", annotation
[i
].block_end
->block_num
);
83 foreach_list_typed(struct bblock_link
, successor_link
, link
,
84 &annotation
[i
].block_end
->children
) {
85 struct bblock_t
*successor_block
= successor_link
->block
;
86 fprintf(stderr
, " ->B%d", successor_block
->block_num
);
88 fprintf(stderr
, "\n");
91 fprintf(stderr
, "\n");
94 void annotate(struct brw_context
*brw
,
95 struct annotation_info
*annotation
, struct cfg_t
*cfg
,
96 struct backend_instruction
*inst
, unsigned offset
)
98 if (annotation
->ann_size
<= annotation
->ann_count
) {
99 annotation
->ann_size
= MAX2(1024, annotation
->ann_size
* 2);
100 annotation
->ann
= reralloc(annotation
->mem_ctx
, annotation
->ann
,
101 struct annotation
, annotation
->ann_size
);
102 if (!annotation
->ann
)
106 struct annotation
*ann
= &annotation
->ann
[annotation
->ann_count
++];
107 ann
->offset
= offset
;
108 if ((INTEL_DEBUG
& DEBUG_NO_ANNOTATION
) == 0) {
110 ann
->annotation
= inst
->annotation
;
113 if (cfg
->blocks
[annotation
->cur_block
]->start
== inst
) {
114 ann
->block_start
= cfg
->blocks
[annotation
->cur_block
];
117 /* There is no hardware DO instruction on Gen6+, so since DO always
118 * starts a basic block, we need to set the .block_start of the next
119 * instruction's annotation with a pointer to the bblock started by
122 * There's also only complication from emitting an annotation without
123 * a corresponding hardware instruction to disassemble.
125 if (brw
->gen
>= 6 && inst
->opcode
== BRW_OPCODE_DO
) {
126 annotation
->ann_count
--;
129 if (cfg
->blocks
[annotation
->cur_block
]->end
== inst
) {
130 ann
->block_end
= cfg
->blocks
[annotation
->cur_block
];
131 annotation
->cur_block
++;
136 annotation_finalize(struct annotation_info
*annotation
,
137 unsigned next_inst_offset
)
139 if (!annotation
->ann_count
)
142 if (annotation
->ann_count
== annotation
->ann_size
) {
143 annotation
->ann
= reralloc(annotation
->mem_ctx
, annotation
->ann
,
144 struct annotation
, annotation
->ann_size
+ 1);
146 annotation
->ann
[annotation
->ann_count
].offset
= next_inst_offset
;