2 * Copyright © 2014 Broadcom
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
25 * @file vc4_opt_vpm_writes.c
27 * This modifies instructions that generate the value consumed by a VPM write
28 * to write directly into the VPM.
34 qir_opt_vpm_writes(struct vc4_compile
*c
)
36 if (c
->stage
== QSTAGE_FRAG
)
39 bool progress
= false;
40 struct qinst
*vpm_writes
[64] = { 0 };
41 uint32_t use_count
[c
->num_temps
];
42 uint32_t vpm_write_count
= 0;
43 memset(&use_count
, 0, sizeof(use_count
));
45 list_for_each_entry(struct qinst
, inst
, &c
->instructions
, link
) {
46 switch (inst
->dst
.file
) {
48 vpm_writes
[vpm_write_count
++] = inst
;
54 for (int i
= 0; i
< qir_get_op_nsrc(inst
->op
); i
++) {
55 if (inst
->src
[i
].file
== QFILE_TEMP
)
56 use_count
[inst
->src
[i
].index
]++;
60 for (int i
= 0; i
< vpm_write_count
; i
++) {
61 if (vpm_writes
[i
]->op
!= QOP_MOV
||
62 vpm_writes
[i
]->src
[0].file
!= QFILE_TEMP
) {
66 uint32_t temp
= vpm_writes
[i
]->src
[0].index
;
67 if (use_count
[temp
] != 1)
70 struct qinst
*inst
= c
->defs
[temp
];
71 if (!inst
|| qir_is_multi_instruction(inst
))
74 if (qir_depends_on_flags(inst
) || inst
->sf
)
77 if (qir_has_side_effects(c
, inst
) ||
78 qir_has_side_effect_reads(c
, inst
)) {
82 /* Move the generating instruction to the end of the program
83 * to maintain the order of the VPM writes.
85 assert(!vpm_writes
[i
]->sf
);
86 list_del(&inst
->link
);
87 list_addtail(&inst
->link
, &vpm_writes
[i
]->link
);
88 qir_remove_instruction(c
, vpm_writes
[i
]);
90 c
->defs
[inst
->dst
.index
] = NULL
;
91 inst
->dst
.file
= QFILE_VPM
;