2014-06-26 23:07:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright © 2014 Broadcom
|
|
|
|
*
|
|
|
|
* 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 "util/u_memory.h"
|
2014-09-15 20:15:02 +01:00
|
|
|
#include "util/ralloc.h"
|
2014-06-26 23:07:39 +01:00
|
|
|
|
|
|
|
#include "vc4_qir.h"
|
|
|
|
#include "vc4_qpu.h"
|
|
|
|
|
|
|
|
struct qir_op_info {
|
|
|
|
const char *name;
|
|
|
|
uint8_t ndst, nsrc;
|
2014-07-04 17:48:23 +01:00
|
|
|
bool has_side_effects;
|
2014-06-26 23:07:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct qir_op_info qir_op_info[] = {
|
|
|
|
[QOP_MOV] = { "mov", 1, 1 },
|
2015-10-25 01:35:03 +01:00
|
|
|
[QOP_FMOV] = { "fmov", 1, 1 },
|
2015-10-26 20:45:06 +00:00
|
|
|
[QOP_MMOV] = { "mmov", 1, 1 },
|
2014-06-26 23:07:39 +01:00
|
|
|
[QOP_FADD] = { "fadd", 1, 2 },
|
|
|
|
[QOP_FSUB] = { "fsub", 1, 2 },
|
|
|
|
[QOP_FMUL] = { "fmul", 1, 2 },
|
2014-08-24 22:05:37 +01:00
|
|
|
[QOP_MUL24] = { "mul24", 1, 2 },
|
2015-01-09 02:07:15 +00:00
|
|
|
[QOP_V8MULD] = {"v8muld", 1, 2 },
|
|
|
|
[QOP_V8MIN] = {"v8min", 1, 2 },
|
|
|
|
[QOP_V8MAX] = {"v8max", 1, 2 },
|
|
|
|
[QOP_V8ADDS] = {"v8adds", 1, 2 },
|
|
|
|
[QOP_V8SUBS] = {"v8subs", 1, 2 },
|
2014-06-26 23:07:39 +01:00
|
|
|
[QOP_FMIN] = { "fmin", 1, 2 },
|
|
|
|
[QOP_FMAX] = { "fmax", 1, 2 },
|
|
|
|
[QOP_FMINABS] = { "fminabs", 1, 2 },
|
|
|
|
[QOP_FMAXABS] = { "fmaxabs", 1, 2 },
|
2014-08-24 22:05:37 +01:00
|
|
|
[QOP_FTOI] = { "ftoi", 1, 1 },
|
|
|
|
[QOP_ITOF] = { "itof", 1, 1 },
|
|
|
|
[QOP_ADD] = { "add", 1, 2 },
|
|
|
|
[QOP_SUB] = { "sub", 1, 2 },
|
|
|
|
[QOP_SHR] = { "shr", 1, 2 },
|
|
|
|
[QOP_ASR] = { "asr", 1, 2 },
|
|
|
|
[QOP_SHL] = { "shl", 1, 2 },
|
|
|
|
[QOP_MIN] = { "min", 1, 2 },
|
2017-02-07 01:30:59 +00:00
|
|
|
[QOP_MIN_NOIMM] = { "min_noimm", 1, 2 },
|
2014-08-24 22:05:37 +01:00
|
|
|
[QOP_MAX] = { "max", 1, 2 },
|
|
|
|
[QOP_AND] = { "and", 1, 2 },
|
|
|
|
[QOP_OR] = { "or", 1, 2 },
|
|
|
|
[QOP_XOR] = { "xor", 1, 2 },
|
|
|
|
[QOP_NOT] = { "not", 1, 1 },
|
2014-06-28 17:26:15 +01:00
|
|
|
|
2016-03-21 19:49:08 +00:00
|
|
|
[QOP_RCP] = { "rcp", 1, 1 },
|
|
|
|
[QOP_RSQ] = { "rsq", 1, 1 },
|
2016-05-06 03:19:39 +01:00
|
|
|
[QOP_EXP2] = { "exp2", 1, 1 },
|
|
|
|
[QOP_LOG2] = { "log2", 1, 1 },
|
2014-12-02 20:58:27 +00:00
|
|
|
[QOP_TLB_COLOR_READ] = { "tlb_color_read", 1, 0 },
|
2015-11-21 01:18:03 +00:00
|
|
|
[QOP_MS_MASK] = { "ms_mask", 0, 1, true },
|
2014-07-04 17:38:44 +01:00
|
|
|
[QOP_VARY_ADD_C] = { "vary_add_c", 1, 1 },
|
2014-07-15 20:29:32 +01:00
|
|
|
|
2014-08-05 22:24:29 +01:00
|
|
|
[QOP_FRAG_Z] = { "frag_z", 1, 0 },
|
2014-09-19 18:06:49 +01:00
|
|
|
[QOP_FRAG_W] = { "frag_w", 1, 0 },
|
2014-08-05 22:24:29 +01:00
|
|
|
|
2014-09-07 22:04:40 +01:00
|
|
|
[QOP_TEX_RESULT] = { "tex_result", 1, 0, true },
|
2016-05-06 02:04:14 +01:00
|
|
|
|
2016-11-10 23:23:19 +00:00
|
|
|
[QOP_THRSW] = { "thrsw", 0, 0, true },
|
|
|
|
|
2016-05-06 02:04:14 +01:00
|
|
|
[QOP_LOAD_IMM] = { "load_imm", 0, 1 },
|
2016-08-25 20:15:29 +01:00
|
|
|
[QOP_LOAD_IMM_U2] = { "load_imm_u2", 0, 1 },
|
|
|
|
[QOP_LOAD_IMM_I2] = { "load_imm_i2", 0, 1 },
|
2016-03-15 20:55:28 +00:00
|
|
|
|
2016-08-25 20:31:49 +01:00
|
|
|
[QOP_ROT_MUL] = { "rot_mul", 0, 2 },
|
|
|
|
|
2016-03-15 20:55:28 +00:00
|
|
|
[QOP_BRANCH] = { "branch", 0, 0, true },
|
2016-05-06 02:11:04 +01:00
|
|
|
[QOP_UNIFORMS_RESET] = { "uniforms_reset", 0, 2, true },
|
2014-06-26 23:07:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
qir_get_op_name(enum qop qop)
|
|
|
|
{
|
|
|
|
if (qop < ARRAY_SIZE(qir_op_info) && qir_op_info[qop].name)
|
|
|
|
return qir_op_info[qop].name;
|
|
|
|
else
|
|
|
|
return "???";
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-11-15 20:54:26 +00:00
|
|
|
qir_get_non_sideband_nsrc(struct qinst *inst)
|
2014-06-26 23:07:39 +01:00
|
|
|
{
|
2016-11-15 20:40:36 +00:00
|
|
|
assert(qir_op_info[inst->op].name);
|
|
|
|
return qir_op_info[inst->op].nsrc;
|
2014-06-26 23:07:39 +01:00
|
|
|
}
|
|
|
|
|
2016-11-15 20:54:26 +00:00
|
|
|
int
|
|
|
|
qir_get_nsrc(struct qinst *inst)
|
|
|
|
{
|
|
|
|
assert(qir_op_info[inst->op].name);
|
|
|
|
|
|
|
|
int nsrc = qir_get_non_sideband_nsrc(inst);
|
|
|
|
|
|
|
|
/* Normal (non-direct) texture coordinate writes also implicitly load
|
|
|
|
* a uniform for the texture parameters.
|
|
|
|
*/
|
|
|
|
if (qir_is_tex(inst) && inst->dst.file != QFILE_TEX_S_DIRECT)
|
|
|
|
nsrc++;
|
|
|
|
|
|
|
|
return nsrc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The sideband uniform for textures gets stored after the normal ALU
|
|
|
|
* arguments.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
qir_get_tex_uniform_src(struct qinst *inst)
|
|
|
|
{
|
|
|
|
return qir_get_nsrc(inst) - 1;
|
|
|
|
}
|
|
|
|
|
2014-10-24 15:03:04 +01:00
|
|
|
/**
|
|
|
|
* Returns whether the instruction has any side effects that must be
|
|
|
|
* preserved.
|
|
|
|
*/
|
2014-07-04 17:48:23 +01:00
|
|
|
bool
|
2014-10-24 15:03:04 +01:00
|
|
|
qir_has_side_effects(struct vc4_compile *c, struct qinst *inst)
|
2015-01-10 01:57:16 +00:00
|
|
|
{
|
2016-03-21 20:12:41 +00:00
|
|
|
switch (inst->dst.file) {
|
|
|
|
case QFILE_TLB_Z_WRITE:
|
|
|
|
case QFILE_TLB_COLOR_WRITE:
|
|
|
|
case QFILE_TLB_COLOR_WRITE_MS:
|
|
|
|
case QFILE_TLB_STENCIL_SETUP:
|
2016-11-15 20:54:26 +00:00
|
|
|
case QFILE_TEX_S_DIRECT:
|
|
|
|
case QFILE_TEX_S:
|
|
|
|
case QFILE_TEX_T:
|
|
|
|
case QFILE_TEX_R:
|
|
|
|
case QFILE_TEX_B:
|
2016-03-21 20:12:41 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-01-10 01:57:16 +00:00
|
|
|
return qir_op_info[inst->op].has_side_effects;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
qir_has_side_effect_reads(struct vc4_compile *c, struct qinst *inst)
|
2014-07-04 17:48:23 +01:00
|
|
|
{
|
2014-10-24 15:03:04 +01:00
|
|
|
/* We can dead-code eliminate varyings, because we only tell the VS
|
|
|
|
* about the live ones at the end. But we have to preserve the
|
|
|
|
* point/line coordinates reads, because they're generated by
|
|
|
|
* fixed-function hardware.
|
|
|
|
*/
|
2016-11-15 20:40:36 +00:00
|
|
|
for (int i = 0; i < qir_get_nsrc(inst); i++) {
|
2014-10-24 15:03:04 +01:00
|
|
|
if (inst->src[i].file == QFILE_VARY &&
|
2015-09-09 18:23:55 +01:00
|
|
|
c->input_slots[inst->src[i].index].slot == 0xff) {
|
2014-07-04 17:48:23 +01:00
|
|
|
return true;
|
2014-10-24 15:03:04 +01:00
|
|
|
}
|
2015-01-10 01:07:12 +00:00
|
|
|
|
|
|
|
if (inst->src[i].file == QFILE_VPM)
|
|
|
|
return true;
|
2014-07-04 17:48:23 +01:00
|
|
|
}
|
|
|
|
|
2014-12-18 04:23:57 +00:00
|
|
|
if (inst->dst.file == QFILE_VPM)
|
|
|
|
return true;
|
|
|
|
|
2015-01-10 01:57:16 +00:00
|
|
|
return false;
|
2014-07-04 17:48:23 +01:00
|
|
|
}
|
|
|
|
|
2016-11-15 22:48:43 +00:00
|
|
|
bool
|
|
|
|
qir_has_uniform_read(struct qinst *inst)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < qir_get_nsrc(inst); i++) {
|
|
|
|
if (inst->src[i].file == QFILE_UNIF)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-19 05:43:42 +01:00
|
|
|
bool
|
|
|
|
qir_is_mul(struct qinst *inst)
|
|
|
|
{
|
|
|
|
switch (inst->op) {
|
2015-10-26 20:45:06 +00:00
|
|
|
case QOP_MMOV:
|
2015-08-19 05:43:42 +01:00
|
|
|
case QOP_FMUL:
|
|
|
|
case QOP_MUL24:
|
2015-01-09 02:07:15 +00:00
|
|
|
case QOP_V8MULD:
|
|
|
|
case QOP_V8MIN:
|
|
|
|
case QOP_V8MAX:
|
|
|
|
case QOP_V8ADDS:
|
|
|
|
case QOP_V8SUBS:
|
2016-08-25 20:31:49 +01:00
|
|
|
case QOP_ROT_MUL:
|
2015-08-19 05:43:42 +01:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-26 20:17:33 +00:00
|
|
|
bool
|
|
|
|
qir_is_float_input(struct qinst *inst)
|
|
|
|
{
|
|
|
|
switch (inst->op) {
|
2015-10-25 01:35:03 +01:00
|
|
|
case QOP_FMOV:
|
2015-10-26 20:17:33 +00:00
|
|
|
case QOP_FMUL:
|
|
|
|
case QOP_FADD:
|
|
|
|
case QOP_FSUB:
|
|
|
|
case QOP_FMIN:
|
|
|
|
case QOP_FMAX:
|
|
|
|
case QOP_FMINABS:
|
|
|
|
case QOP_FMAXABS:
|
|
|
|
case QOP_FTOI:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-25 00:30:30 +01:00
|
|
|
bool
|
|
|
|
qir_is_raw_mov(struct qinst *inst)
|
|
|
|
{
|
2015-10-25 01:35:03 +01:00
|
|
|
return ((inst->op == QOP_MOV ||
|
2015-10-26 20:45:06 +00:00
|
|
|
inst->op == QOP_FMOV ||
|
|
|
|
inst->op == QOP_MMOV) &&
|
2016-02-15 22:43:38 +00:00
|
|
|
inst->cond == QPU_COND_ALWAYS &&
|
2015-10-25 00:30:30 +01:00
|
|
|
!inst->dst.pack &&
|
|
|
|
!inst->src[0].pack);
|
|
|
|
}
|
|
|
|
|
2015-02-19 20:58:53 +00:00
|
|
|
bool
|
|
|
|
qir_is_tex(struct qinst *inst)
|
|
|
|
{
|
2016-11-15 20:54:26 +00:00
|
|
|
switch (inst->dst.file) {
|
|
|
|
case QFILE_TEX_S_DIRECT:
|
|
|
|
case QFILE_TEX_S:
|
|
|
|
case QFILE_TEX_T:
|
|
|
|
case QFILE_TEX_R:
|
|
|
|
case QFILE_TEX_B:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
qir_has_implicit_tex_uniform(struct qinst *inst)
|
|
|
|
{
|
|
|
|
switch (inst->dst.file) {
|
|
|
|
case QFILE_TEX_S:
|
|
|
|
case QFILE_TEX_T:
|
|
|
|
case QFILE_TEX_R:
|
|
|
|
case QFILE_TEX_B:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2015-02-19 20:58:53 +00:00
|
|
|
}
|
|
|
|
|
2014-08-25 08:12:21 +01:00
|
|
|
bool
|
|
|
|
qir_depends_on_flags(struct qinst *inst)
|
|
|
|
{
|
2016-03-15 20:55:28 +00:00
|
|
|
if (inst->op == QOP_BRANCH) {
|
|
|
|
return inst->cond != QPU_COND_BRANCH_ALWAYS;
|
|
|
|
} else {
|
|
|
|
return (inst->cond != QPU_COND_ALWAYS &&
|
|
|
|
inst->cond != QPU_COND_NEVER);
|
|
|
|
}
|
2014-08-25 08:12:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
qir_writes_r4(struct qinst *inst)
|
|
|
|
{
|
|
|
|
switch (inst->op) {
|
|
|
|
case QOP_TEX_RESULT:
|
|
|
|
case QOP_TLB_COLOR_READ:
|
|
|
|
case QOP_RCP:
|
|
|
|
case QOP_RSQ:
|
|
|
|
case QOP_EXP2:
|
|
|
|
case QOP_LOG2:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-10 20:53:57 +00:00
|
|
|
uint8_t
|
|
|
|
qir_channels_written(struct qinst *inst)
|
|
|
|
{
|
|
|
|
if (qir_is_mul(inst)) {
|
|
|
|
switch (inst->dst.pack) {
|
|
|
|
case QPU_PACK_MUL_NOP:
|
|
|
|
case QPU_PACK_MUL_8888:
|
|
|
|
return 0xf;
|
|
|
|
case QPU_PACK_MUL_8A:
|
|
|
|
return 0x1;
|
|
|
|
case QPU_PACK_MUL_8B:
|
|
|
|
return 0x2;
|
|
|
|
case QPU_PACK_MUL_8C:
|
|
|
|
return 0x4;
|
|
|
|
case QPU_PACK_MUL_8D:
|
|
|
|
return 0x8;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (inst->dst.pack) {
|
|
|
|
case QPU_PACK_A_NOP:
|
|
|
|
case QPU_PACK_A_8888:
|
|
|
|
case QPU_PACK_A_8888_SAT:
|
|
|
|
case QPU_PACK_A_32_SAT:
|
|
|
|
return 0xf;
|
|
|
|
case QPU_PACK_A_8A:
|
|
|
|
case QPU_PACK_A_8A_SAT:
|
|
|
|
return 0x1;
|
|
|
|
case QPU_PACK_A_8B:
|
|
|
|
case QPU_PACK_A_8B_SAT:
|
|
|
|
return 0x2;
|
|
|
|
case QPU_PACK_A_8C:
|
|
|
|
case QPU_PACK_A_8C_SAT:
|
|
|
|
return 0x4;
|
|
|
|
case QPU_PACK_A_8D:
|
|
|
|
case QPU_PACK_A_8D_SAT:
|
|
|
|
return 0x8;
|
|
|
|
case QPU_PACK_A_16A:
|
|
|
|
case QPU_PACK_A_16A_SAT:
|
|
|
|
return 0x3;
|
|
|
|
case QPU_PACK_A_16B:
|
|
|
|
case QPU_PACK_A_16B_SAT:
|
|
|
|
return 0xc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unreachable("Bad pack field");
|
|
|
|
}
|
|
|
|
|
2014-06-26 23:07:39 +01:00
|
|
|
static void
|
2015-01-30 19:23:26 +00:00
|
|
|
qir_print_reg(struct vc4_compile *c, struct qreg reg, bool write)
|
2014-06-26 23:07:39 +01:00
|
|
|
{
|
2014-12-10 22:56:46 +00:00
|
|
|
static const char *files[] = {
|
2014-06-26 23:07:39 +01:00
|
|
|
[QFILE_TEMP] = "t",
|
|
|
|
[QFILE_VARY] = "v",
|
|
|
|
[QFILE_UNIF] = "u",
|
2016-03-21 20:12:41 +00:00
|
|
|
[QFILE_TLB_COLOR_WRITE] = "tlb_c",
|
|
|
|
[QFILE_TLB_COLOR_WRITE_MS] = "tlb_c_ms",
|
|
|
|
[QFILE_TLB_Z_WRITE] = "tlb_z",
|
|
|
|
[QFILE_TLB_STENCIL_SETUP] = "tlb_stencil",
|
2016-03-21 21:11:10 +00:00
|
|
|
[QFILE_FRAG_X] = "frag_x",
|
|
|
|
[QFILE_FRAG_Y] = "frag_y",
|
|
|
|
[QFILE_FRAG_REV_FLAG] = "frag_rev_flag",
|
2016-08-25 21:48:21 +01:00
|
|
|
[QFILE_QPU_ELEMENT] = "elem",
|
2016-11-15 20:54:26 +00:00
|
|
|
[QFILE_TEX_S_DIRECT] = "tex_s_direct",
|
|
|
|
[QFILE_TEX_S] = "tex_s",
|
|
|
|
[QFILE_TEX_T] = "tex_t",
|
|
|
|
[QFILE_TEX_R] = "tex_r",
|
|
|
|
[QFILE_TEX_B] = "tex_b",
|
2014-06-26 23:07:39 +01:00
|
|
|
};
|
|
|
|
|
2016-03-21 20:12:41 +00:00
|
|
|
switch (reg.file) {
|
|
|
|
|
|
|
|
case QFILE_NULL:
|
2014-06-26 23:07:39 +01:00
|
|
|
fprintf(stderr, "null");
|
2016-03-21 20:12:41 +00:00
|
|
|
break;
|
|
|
|
|
2016-05-06 02:04:14 +01:00
|
|
|
case QFILE_LOAD_IMM:
|
|
|
|
fprintf(stderr, "0x%08x (%f)", reg.index, uif(reg.index));
|
|
|
|
break;
|
|
|
|
|
2016-03-21 20:12:41 +00:00
|
|
|
case QFILE_SMALL_IMM:
|
2014-12-10 22:56:46 +00:00
|
|
|
if ((int)reg.index >= -16 && (int)reg.index <= 15)
|
|
|
|
fprintf(stderr, "%d", reg.index);
|
|
|
|
else
|
|
|
|
fprintf(stderr, "%f", uif(reg.index));
|
2016-03-21 20:12:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QFILE_VPM:
|
2015-01-30 19:23:26 +00:00
|
|
|
if (write) {
|
|
|
|
fprintf(stderr, "vpm");
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "vpm%d.%d",
|
|
|
|
reg.index / 4, reg.index % 4);
|
|
|
|
}
|
2016-03-21 20:12:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QFILE_TLB_COLOR_WRITE:
|
|
|
|
case QFILE_TLB_COLOR_WRITE_MS:
|
|
|
|
case QFILE_TLB_Z_WRITE:
|
|
|
|
case QFILE_TLB_STENCIL_SETUP:
|
2016-11-15 20:54:26 +00:00
|
|
|
case QFILE_TEX_S_DIRECT:
|
|
|
|
case QFILE_TEX_S:
|
|
|
|
case QFILE_TEX_T:
|
|
|
|
case QFILE_TEX_R:
|
|
|
|
case QFILE_TEX_B:
|
2016-03-21 20:12:41 +00:00
|
|
|
fprintf(stderr, "%s", files[reg.file]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-06-26 23:07:39 +01:00
|
|
|
fprintf(stderr, "%s%d", files[reg.file], reg.index);
|
2016-03-21 20:12:41 +00:00
|
|
|
break;
|
2014-12-10 22:56:46 +00:00
|
|
|
}
|
2014-09-25 06:03:06 +01:00
|
|
|
|
|
|
|
if (reg.file == QFILE_UNIF &&
|
|
|
|
c->uniform_contents[reg.index] == QUNIFORM_CONSTANT) {
|
|
|
|
fprintf(stderr, " (0x%08x / %f)",
|
|
|
|
c->uniform_data[reg.index],
|
|
|
|
uif(c->uniform_data[reg.index]));
|
|
|
|
}
|
2014-06-26 23:07:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-25 06:03:06 +01:00
|
|
|
qir_dump_inst(struct vc4_compile *c, struct qinst *inst)
|
2014-06-26 23:07:39 +01:00
|
|
|
{
|
2016-03-15 21:15:51 +00:00
|
|
|
fprintf(stderr, "%s", qir_get_op_name(inst->op));
|
2016-03-15 20:55:28 +00:00
|
|
|
if (inst->op == QOP_BRANCH)
|
|
|
|
vc4_qpu_disasm_cond_branch(stderr, inst->cond);
|
|
|
|
else
|
|
|
|
vc4_qpu_disasm_cond(stderr, inst->cond);
|
2016-03-15 21:15:51 +00:00
|
|
|
if (inst->sf)
|
|
|
|
fprintf(stderr, ".sf");
|
|
|
|
fprintf(stderr, " ");
|
2014-06-26 23:07:39 +01:00
|
|
|
|
2016-03-15 20:55:28 +00:00
|
|
|
if (inst->op != QOP_BRANCH) {
|
|
|
|
qir_print_reg(c, inst->dst, true);
|
2015-08-21 08:04:36 +01:00
|
|
|
if (inst->dst.pack) {
|
2016-03-15 20:55:28 +00:00
|
|
|
if (inst->dst.pack) {
|
|
|
|
if (qir_is_mul(inst))
|
|
|
|
vc4_qpu_disasm_pack_mul(stderr, inst->dst.pack);
|
|
|
|
else
|
|
|
|
vc4_qpu_disasm_pack_a(stderr, inst->dst.pack);
|
|
|
|
}
|
2015-08-19 05:26:05 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-15 20:55:28 +00:00
|
|
|
|
2016-11-15 20:40:36 +00:00
|
|
|
for (int i = 0; i < qir_get_nsrc(inst); i++) {
|
2014-06-26 23:07:39 +01:00
|
|
|
fprintf(stderr, ", ");
|
2015-01-30 19:23:26 +00:00
|
|
|
qir_print_reg(c, inst->src[i], false);
|
2015-10-25 01:33:30 +01:00
|
|
|
vc4_qpu_disasm_unpack(stderr, inst->src[i].pack);
|
2014-06-26 23:07:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-08-13 21:41:22 +01:00
|
|
|
qir_dump(struct vc4_compile *c)
|
2014-06-26 23:07:39 +01:00
|
|
|
{
|
2016-07-06 20:49:52 +01:00
|
|
|
int ip = 0;
|
2016-11-07 18:16:45 +00:00
|
|
|
int pressure = 0;
|
2016-07-06 20:49:52 +01:00
|
|
|
|
2016-07-08 23:42:15 +01:00
|
|
|
qir_for_each_block(block, c) {
|
|
|
|
fprintf(stderr, "BLOCK %d:\n", block->index);
|
|
|
|
qir_for_each_inst(inst, block) {
|
2016-07-06 20:49:52 +01:00
|
|
|
if (c->temp_start) {
|
|
|
|
bool first = true;
|
|
|
|
|
2016-11-07 18:16:45 +00:00
|
|
|
fprintf(stderr, "%3d ", pressure);
|
|
|
|
|
2016-07-06 20:49:52 +01:00
|
|
|
for (int i = 0; i < c->num_temps; i++) {
|
|
|
|
if (c->temp_start[i] != ip)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, ", ");
|
|
|
|
}
|
|
|
|
fprintf(stderr, "S%4d", i);
|
2016-11-07 18:16:45 +00:00
|
|
|
pressure++;
|
2016-07-06 20:49:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (first)
|
|
|
|
fprintf(stderr, " ");
|
|
|
|
else
|
|
|
|
fprintf(stderr, " ");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c->temp_end) {
|
|
|
|
bool first = true;
|
|
|
|
|
|
|
|
for (int i = 0; i < c->num_temps; i++) {
|
|
|
|
if (c->temp_end[i] != ip)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, ", ");
|
|
|
|
}
|
|
|
|
fprintf(stderr, "E%4d", i);
|
2016-11-07 18:16:45 +00:00
|
|
|
pressure--;
|
2016-07-06 20:49:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (first)
|
|
|
|
fprintf(stderr, " ");
|
|
|
|
else
|
|
|
|
fprintf(stderr, " ");
|
|
|
|
}
|
|
|
|
|
2016-07-08 23:42:15 +01:00
|
|
|
qir_dump_inst(c, inst);
|
|
|
|
fprintf(stderr, "\n");
|
2016-07-06 20:49:52 +01:00
|
|
|
ip++;
|
2016-07-08 23:42:15 +01:00
|
|
|
}
|
2016-03-15 20:55:28 +00:00
|
|
|
if (block->successors[1]) {
|
|
|
|
fprintf(stderr, "-> BLOCK %d, %d\n",
|
|
|
|
block->successors[0]->index,
|
|
|
|
block->successors[1]->index);
|
|
|
|
} else if (block->successors[0]) {
|
|
|
|
fprintf(stderr, "-> BLOCK %d\n",
|
|
|
|
block->successors[0]->index);
|
|
|
|
}
|
2014-06-26 23:07:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct qreg
|
2014-08-13 21:41:22 +01:00
|
|
|
qir_get_temp(struct vc4_compile *c)
|
2014-06-26 23:07:39 +01:00
|
|
|
{
|
|
|
|
struct qreg reg;
|
|
|
|
|
|
|
|
reg.file = QFILE_TEMP;
|
|
|
|
reg.index = c->num_temps++;
|
2015-08-26 12:52:50 +01:00
|
|
|
reg.pack = 0;
|
2014-06-26 23:07:39 +01:00
|
|
|
|
2015-02-19 21:22:31 +00:00
|
|
|
if (c->num_temps > c->defs_array_size) {
|
|
|
|
uint32_t old_size = c->defs_array_size;
|
|
|
|
c->defs_array_size = MAX2(old_size * 2, 16);
|
|
|
|
c->defs = reralloc(c, c->defs, struct qinst *,
|
|
|
|
c->defs_array_size);
|
|
|
|
memset(&c->defs[old_size], 0,
|
|
|
|
sizeof(c->defs[0]) * (c->defs_array_size - old_size));
|
|
|
|
}
|
|
|
|
|
2014-06-26 23:07:39 +01:00
|
|
|
return reg;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct qinst *
|
|
|
|
qir_inst(enum qop op, struct qreg dst, struct qreg src0, struct qreg src1)
|
|
|
|
{
|
|
|
|
struct qinst *inst = CALLOC_STRUCT(qinst);
|
|
|
|
|
|
|
|
inst->op = op;
|
|
|
|
inst->dst = dst;
|
|
|
|
inst->src[0] = src0;
|
|
|
|
inst->src[1] = src1;
|
2015-12-22 21:37:36 +00:00
|
|
|
inst->cond = QPU_COND_ALWAYS;
|
2014-06-26 23:07:39 +01:00
|
|
|
|
|
|
|
return inst;
|
|
|
|
}
|
|
|
|
|
2016-06-26 03:49:07 +01:00
|
|
|
static void
|
2014-08-13 21:41:22 +01:00
|
|
|
qir_emit(struct vc4_compile *c, struct qinst *inst)
|
2014-06-26 23:07:39 +01:00
|
|
|
{
|
2016-07-08 23:42:15 +01:00
|
|
|
list_addtail(&inst->link, &c->cur_block->instructions);
|
2016-06-26 03:49:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Updates inst to write to a new temporary, emits it, and notes the def. */
|
|
|
|
struct qreg
|
|
|
|
qir_emit_def(struct vc4_compile *c, struct qinst *inst)
|
|
|
|
{
|
|
|
|
assert(inst->dst.file == QFILE_NULL);
|
|
|
|
|
|
|
|
inst->dst = qir_get_temp(c);
|
|
|
|
|
2015-02-19 21:22:31 +00:00
|
|
|
if (inst->dst.file == QFILE_TEMP)
|
|
|
|
c->defs[inst->dst.index] = inst;
|
|
|
|
|
2016-06-26 03:49:07 +01:00
|
|
|
qir_emit(c, inst);
|
|
|
|
|
|
|
|
return inst->dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct qinst *
|
|
|
|
qir_emit_nondef(struct vc4_compile *c, struct qinst *inst)
|
|
|
|
{
|
|
|
|
if (inst->dst.file == QFILE_TEMP)
|
|
|
|
c->defs[inst->dst.index] = NULL;
|
|
|
|
|
|
|
|
qir_emit(c, inst);
|
|
|
|
|
|
|
|
return inst;
|
2014-06-26 23:07:39 +01:00
|
|
|
}
|
|
|
|
|
2014-07-03 21:18:49 +01:00
|
|
|
bool
|
|
|
|
qir_reg_equals(struct qreg a, struct qreg b)
|
|
|
|
{
|
2016-06-04 01:09:14 +01:00
|
|
|
return a.file == b.file && a.index == b.index && a.pack == b.pack;
|
2014-07-03 21:18:49 +01:00
|
|
|
}
|
|
|
|
|
2016-07-08 23:42:15 +01:00
|
|
|
struct qblock *
|
|
|
|
qir_new_block(struct vc4_compile *c)
|
|
|
|
{
|
|
|
|
struct qblock *block = rzalloc(c, struct qblock);
|
|
|
|
|
|
|
|
list_inithead(&block->instructions);
|
2016-03-16 00:53:36 +00:00
|
|
|
list_inithead(&block->qpu_inst_list);
|
2016-07-08 23:42:15 +01:00
|
|
|
|
|
|
|
block->predecessors = _mesa_set_create(block,
|
|
|
|
_mesa_hash_pointer,
|
|
|
|
_mesa_key_pointer_equal);
|
|
|
|
|
|
|
|
block->index = c->next_block_index++;
|
|
|
|
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
qir_set_emit_block(struct vc4_compile *c, struct qblock *block)
|
|
|
|
{
|
|
|
|
c->cur_block = block;
|
|
|
|
list_addtail(&block->link, &c->blocks);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct qblock *
|
|
|
|
qir_entry_block(struct vc4_compile *c)
|
|
|
|
{
|
|
|
|
return list_first_entry(&c->blocks, struct qblock, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct qblock *
|
|
|
|
qir_exit_block(struct vc4_compile *c)
|
|
|
|
{
|
|
|
|
return list_last_entry(&c->blocks, struct qblock, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
qir_link_blocks(struct qblock *predecessor, struct qblock *successor)
|
|
|
|
{
|
|
|
|
_mesa_set_add(successor->predecessors, predecessor);
|
|
|
|
if (predecessor->successors[0]) {
|
|
|
|
assert(!predecessor->successors[1]);
|
|
|
|
predecessor->successors[1] = successor;
|
|
|
|
} else {
|
|
|
|
predecessor->successors[0] = successor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-13 21:41:22 +01:00
|
|
|
struct vc4_compile *
|
2014-06-26 23:07:39 +01:00
|
|
|
qir_compile_init(void)
|
|
|
|
{
|
2014-09-15 20:15:02 +01:00
|
|
|
struct vc4_compile *c = rzalloc(NULL, struct vc4_compile);
|
2014-06-26 23:07:39 +01:00
|
|
|
|
2016-07-08 23:42:15 +01:00
|
|
|
list_inithead(&c->blocks);
|
|
|
|
qir_set_emit_block(c, qir_new_block(c));
|
2017-02-24 20:00:38 +00:00
|
|
|
c->last_top_block = c->cur_block;
|
2014-06-26 23:07:39 +01:00
|
|
|
|
2014-09-16 20:55:16 +01:00
|
|
|
c->output_position_index = -1;
|
|
|
|
c->output_color_index = -1;
|
2014-10-15 15:25:57 +01:00
|
|
|
c->output_point_size_index = -1;
|
2015-11-21 01:18:03 +00:00
|
|
|
c->output_sample_mask_index = -1;
|
2014-09-16 20:55:16 +01:00
|
|
|
|
2014-10-30 19:51:47 +00:00
|
|
|
c->def_ht = _mesa_hash_table_create(c, _mesa_hash_pointer,
|
|
|
|
_mesa_key_pointer_equal);
|
|
|
|
|
2014-06-26 23:07:39 +01:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2014-09-15 20:19:28 +01:00
|
|
|
void
|
2015-02-19 21:22:31 +00:00
|
|
|
qir_remove_instruction(struct vc4_compile *c, struct qinst *qinst)
|
2014-09-15 20:19:28 +01:00
|
|
|
{
|
2015-02-19 21:22:31 +00:00
|
|
|
if (qinst->dst.file == QFILE_TEMP)
|
|
|
|
c->defs[qinst->dst.index] = NULL;
|
|
|
|
|
2015-05-30 02:19:42 +01:00
|
|
|
list_del(&qinst->link);
|
2014-09-15 20:19:28 +01:00
|
|
|
free(qinst);
|
|
|
|
}
|
|
|
|
|
2014-12-10 23:37:07 +00:00
|
|
|
struct qreg
|
2015-02-19 21:22:31 +00:00
|
|
|
qir_follow_movs(struct vc4_compile *c, struct qreg reg)
|
2014-12-10 23:37:07 +00:00
|
|
|
{
|
2015-12-11 06:23:10 +00:00
|
|
|
int pack = reg.pack;
|
|
|
|
|
2015-08-04 03:25:47 +01:00
|
|
|
while (reg.file == QFILE_TEMP &&
|
|
|
|
c->defs[reg.index] &&
|
2015-12-11 06:23:10 +00:00
|
|
|
(c->defs[reg.index]->op == QOP_MOV ||
|
|
|
|
c->defs[reg.index]->op == QOP_FMOV ||
|
|
|
|
c->defs[reg.index]->op == QOP_MMOV)&&
|
|
|
|
!c->defs[reg.index]->dst.pack &&
|
|
|
|
!c->defs[reg.index]->src[0].pack) {
|
2015-02-19 21:22:31 +00:00
|
|
|
reg = c->defs[reg.index]->src[0];
|
2015-08-04 03:25:47 +01:00
|
|
|
}
|
2014-12-10 23:37:07 +00:00
|
|
|
|
2015-12-11 06:23:10 +00:00
|
|
|
reg.pack = pack;
|
2014-12-10 23:37:07 +00:00
|
|
|
return reg;
|
|
|
|
}
|
|
|
|
|
2014-06-26 23:07:39 +01:00
|
|
|
void
|
2014-08-13 21:41:22 +01:00
|
|
|
qir_compile_destroy(struct vc4_compile *c)
|
2014-06-26 23:07:39 +01:00
|
|
|
{
|
2016-07-08 23:42:15 +01:00
|
|
|
qir_for_each_block(block, c) {
|
|
|
|
while (!list_empty(&block->instructions)) {
|
|
|
|
struct qinst *qinst =
|
|
|
|
list_first_entry(&block->instructions,
|
|
|
|
struct qinst, link);
|
|
|
|
qir_remove_instruction(c, qinst);
|
|
|
|
}
|
2014-09-15 20:19:28 +01:00
|
|
|
}
|
|
|
|
|
2014-09-15 20:15:02 +01:00
|
|
|
ralloc_free(c);
|
2014-06-26 23:07:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
qir_get_stage_name(enum qstage stage)
|
|
|
|
{
|
|
|
|
static const char *names[] = {
|
|
|
|
[QSTAGE_FRAG] = "FS",
|
|
|
|
[QSTAGE_VERT] = "VS",
|
|
|
|
[QSTAGE_COORD] = "CS",
|
|
|
|
};
|
|
|
|
|
|
|
|
return names[stage];
|
|
|
|
}
|
2014-07-03 21:18:49 +01:00
|
|
|
|
2015-02-19 20:19:44 +00:00
|
|
|
struct qreg
|
|
|
|
qir_uniform(struct vc4_compile *c,
|
|
|
|
enum quniform_contents contents,
|
|
|
|
uint32_t data)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < c->num_uniforms; i++) {
|
|
|
|
if (c->uniform_contents[i] == contents &&
|
|
|
|
c->uniform_data[i] == data) {
|
2016-03-21 21:17:45 +00:00
|
|
|
return qir_reg(QFILE_UNIF, i);
|
2015-02-19 20:19:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t uniform = c->num_uniforms++;
|
|
|
|
|
|
|
|
if (uniform >= c->uniform_array_size) {
|
|
|
|
c->uniform_array_size = MAX2(MAX2(16, uniform + 1),
|
|
|
|
c->uniform_array_size * 2);
|
|
|
|
|
|
|
|
c->uniform_data = reralloc(c, c->uniform_data,
|
|
|
|
uint32_t,
|
|
|
|
c->uniform_array_size);
|
|
|
|
c->uniform_contents = reralloc(c, c->uniform_contents,
|
|
|
|
enum quniform_contents,
|
|
|
|
c->uniform_array_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
c->uniform_contents[uniform] = contents;
|
|
|
|
c->uniform_data[uniform] = data;
|
|
|
|
|
2016-03-21 21:17:45 +00:00
|
|
|
return qir_reg(QFILE_UNIF, uniform);
|
2015-02-19 20:19:44 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 22:17:21 +00:00
|
|
|
void
|
|
|
|
qir_SF(struct vc4_compile *c, struct qreg src)
|
|
|
|
{
|
2015-02-19 20:58:53 +00:00
|
|
|
struct qinst *last_inst = NULL;
|
2016-07-08 23:42:15 +01:00
|
|
|
|
|
|
|
if (!list_empty(&c->cur_block->instructions))
|
|
|
|
last_inst = (struct qinst *)c->cur_block->instructions.prev;
|
2015-02-19 20:58:53 +00:00
|
|
|
|
2016-03-16 01:57:20 +00:00
|
|
|
/* We don't have any way to guess which kind of MOV is implied. */
|
|
|
|
assert(!src.pack);
|
|
|
|
|
2016-01-04 21:56:39 +00:00
|
|
|
if (src.file != QFILE_TEMP ||
|
|
|
|
!c->defs[src.index] ||
|
2016-03-21 19:49:08 +00:00
|
|
|
last_inst != c->defs[src.index]) {
|
2016-03-21 21:17:45 +00:00
|
|
|
last_inst = qir_MOV_dest(c, qir_reg(QFILE_NULL, 0), src);
|
2016-07-08 23:42:15 +01:00
|
|
|
last_inst = (struct qinst *)c->cur_block->instructions.prev;
|
2015-02-12 22:17:21 +00:00
|
|
|
}
|
|
|
|
last_inst->sf = true;
|
|
|
|
}
|
|
|
|
|
2014-07-03 21:18:49 +01:00
|
|
|
#define OPTPASS(func) \
|
|
|
|
do { \
|
|
|
|
bool stage_progress = func(c); \
|
|
|
|
if (stage_progress) { \
|
|
|
|
progress = true; \
|
|
|
|
if (print_opt_debug) { \
|
|
|
|
fprintf(stderr, \
|
|
|
|
"QIR opt pass %2d: %s progress\n", \
|
|
|
|
pass, #func); \
|
|
|
|
} \
|
2016-05-02 20:21:45 +01:00
|
|
|
qir_validate(c); \
|
2014-07-03 21:18:49 +01:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
void
|
2014-08-13 21:41:22 +01:00
|
|
|
qir_optimize(struct vc4_compile *c)
|
2014-07-03 21:18:49 +01:00
|
|
|
{
|
|
|
|
bool print_opt_debug = false;
|
|
|
|
int pass = 1;
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
bool progress = false;
|
|
|
|
|
|
|
|
OPTPASS(qir_opt_algebraic);
|
2015-03-30 18:38:21 +01:00
|
|
|
OPTPASS(qir_opt_constant_folding);
|
2014-07-04 18:59:42 +01:00
|
|
|
OPTPASS(qir_opt_copy_propagation);
|
2016-06-03 22:36:04 +01:00
|
|
|
OPTPASS(qir_opt_peephole_sf);
|
2014-07-04 17:48:23 +01:00
|
|
|
OPTPASS(qir_opt_dead_code);
|
2014-12-10 22:56:46 +00:00
|
|
|
OPTPASS(qir_opt_small_immediates);
|
2016-03-07 19:31:59 +00:00
|
|
|
OPTPASS(qir_opt_vpm);
|
2016-11-15 22:24:25 +00:00
|
|
|
OPTPASS(qir_opt_coalesce_ff_writes);
|
2014-07-03 21:18:49 +01:00
|
|
|
|
|
|
|
if (!progress)
|
|
|
|
break;
|
|
|
|
|
|
|
|
pass++;
|
|
|
|
}
|
|
|
|
}
|