2 * Copyright © 2016 Broadcom Limited
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
28 fail_instr(struct vc4_compile
*c
, struct qinst
*inst
, const char *msg
)
30 fprintf(stderr
, "qir_validate: %s: ", msg
);
31 qir_dump_inst(c
, inst
);
32 fprintf(stderr
, "\n");
36 void qir_validate(struct vc4_compile
*c
)
38 bool already_assigned
[c
->num_temps
];
39 memset(&already_assigned
, 0, sizeof(already_assigned
));
41 /* We don't want to do validation in release builds, but we want to
42 * keep compiling the validation code to make sure it doesn't get
49 for (int i
= 0; i
< c
->num_temps
; i
++) {
50 struct qinst
*def
= c
->defs
[i
];
52 if (def
&& def
->cond
!= QPU_COND_ALWAYS
)
53 fail_instr(c
, def
, "SSA def with condition");
56 qir_for_each_inst_inorder(inst
, c
) {
57 switch (inst
->dst
.file
) {
59 if (inst
->dst
.index
>= c
->num_temps
)
60 fail_instr(c
, inst
, "bad temp index");
62 if (c
->defs
[inst
->dst
.index
] &&
63 already_assigned
[inst
->dst
.index
]) {
64 fail_instr(c
, inst
, "Re-assignment of SSA value");
66 already_assigned
[inst
->dst
.index
] = true;
71 case QFILE_TLB_COLOR_WRITE
:
72 case QFILE_TLB_COLOR_WRITE_MS
:
73 case QFILE_TLB_Z_WRITE
:
74 case QFILE_TLB_STENCIL_SETUP
:
81 case QFILE_FRAG_REV_FLAG
:
82 case QFILE_QPU_ELEMENT
:
85 fail_instr(c
, inst
, "Bad dest file");
89 for (int i
= 0; i
< qir_get_op_nsrc(inst
->op
); i
++) {
90 struct qreg src
= inst
->src
[i
];
94 if (src
.index
>= c
->num_temps
)
95 fail_instr(c
, inst
, "bad temp index");
102 case QFILE_QPU_ELEMENT
:
105 case QFILE_SMALL_IMM
:
106 if (qpu_encode_small_immediate(src
.index
) == ~0)
107 fail_instr(c
, inst
, "bad small immediate");
112 case QFILE_FRAG_REV_FLAG
:
113 if (c
->stage
!= QSTAGE_FRAG
)
114 fail_instr(c
, inst
, "frag access in VS/CS");
118 case QFILE_TLB_COLOR_WRITE
:
119 case QFILE_TLB_COLOR_WRITE_MS
:
120 case QFILE_TLB_Z_WRITE
:
121 case QFILE_TLB_STENCIL_SETUP
:
122 fail_instr(c
, inst
, "Bad src file");