• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2015 Intel Corporation
3  *
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:
10  *
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
13  * Software.
14  *
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
21  * IN THE SOFTWARE.
22  */
23 
24 /** @file brw_fs_validate.cpp
25  *
26  * Implements a pass that validates various invariants of the IR.  The current
27  * pass only validates that GRF's uses are sane.  More can be added later.
28  */
29 
30 #include "brw_fs.h"
31 #include "brw_cfg.h"
32 
33 #define fsv_assert(cond) \
34    if (!(cond)) { \
35       fprintf(stderr, "ASSERT: Scalar %s validation failed!\n", stage_abbrev); \
36       dump_instruction(inst, stderr); \
37       fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, #cond); \
38       abort(); \
39    }
40 
41 void
validate()42 fs_visitor::validate()
43 {
44 #ifndef NDEBUG
45    foreach_block_and_inst (block, fs_inst, inst, cfg) {
46       if (inst->opcode == SHADER_OPCODE_URB_WRITE_LOGICAL) {
47          const unsigned header_size = 1 +
48             unsigned(inst->src[URB_LOGICAL_SRC_PER_SLOT_OFFSETS].file != BAD_FILE) +
49             unsigned(inst->src[URB_LOGICAL_SRC_CHANNEL_MASK].file != BAD_FILE);
50 
51          unsigned data_size = 0;
52          for (unsigned i = header_size, j = 0; i < inst->mlen; i++, j++) {
53             fsv_assert(type_sz(offset(inst->src[URB_LOGICAL_SRC_DATA], bld, j).type) == 4);
54             data_size++;
55          }
56 
57          fsv_assert(header_size + data_size == inst->mlen);
58       }
59 
60       if (inst->dst.file == VGRF) {
61          fsv_assert(inst->dst.offset / REG_SIZE + regs_written(inst) <=
62                     alloc.sizes[inst->dst.nr]);
63       }
64 
65       for (unsigned i = 0; i < inst->sources; i++) {
66          if (inst->src[i].file == VGRF) {
67             fsv_assert(inst->src[i].offset / REG_SIZE + regs_read(inst, i) <=
68                        alloc.sizes[inst->src[i].nr]);
69          }
70       }
71    }
72 #endif
73 }
74