Lines Matching defs:block

178    Block* block = &ctx.program->blocks[block_idx];
182 /* to compute the next use distance at the beginning of the block, we have to add the block's
187 it->second.second = it->second.second + block->instructions.size();
189 int idx = block->instructions.size() - 1;
191 aco_ptr<Instruction>& instr = block->instructions[idx];
216 aco_ptr<Instruction>& instr = block->instructions[idx];
230 instr->opcode == aco_opcode::p_phi ? block->logical_preds[i] : block->linear_preds[i];
252 std::vector<unsigned>& preds = temp.is_linear() ? block->linear_preds : block->logical_preds;
254 if (ctx.program->blocks[pred_idx].loop_nest_depth > block->loop_nest_depth)
365 for (Block& block : ctx.program->blocks) {
367 for (aco_ptr<Instruction>& instr : block.instructions) {
385 update_local_next_uses(spill_ctx& ctx, Block* block,
388 if (local_next_uses.size() < block->instructions.size()) {
391 local_next_uses.resize(block->instructions.size());
394 local_next_uses[block->instructions.size() - 1].clear();
396 ctx.next_use_distances_end[block->index]) {
397 local_next_uses[block->instructions.size() - 1].push_back(std::make_pair<Temp, uint32_t>(
398 (Temp)pair.first, pair.second.second + block->instructions.size()));
401 for (int idx = block->instructions.size() - 1; idx >= 0; idx--) {
402 aco_ptr<Instruction>& instr = block->instructions[idx];
408 if (idx != (int)block->instructions.size() - 1) {
457 Block& block = ctx.program->blocks[block_idx];
458 for (aco_ptr<Instruction>& phi : block.instructions) {
464 * the block they're in. Since the loops below are both to control
465 * pressure of the start of this block and the ends of it's
476 for (unsigned pred : block.linear_preds)
484 init_live_in_vars(spill_ctx& ctx, Block* block, unsigned block_idx)
488 /* first block, nothing was spilled before */
492 /* next use distances at the beginning of the current block */
495 /* loop header block */
496 if (block->loop_nest_depth > ctx.program->blocks[block_idx - 1].loop_nest_depth) {
497 assert(block->linear_preds[0] == block_idx - 1);
498 assert(block->logical_preds[0] == block_idx - 1);
501 ctx.loop_header.emplace(block);
507 while (ctx.program->blocks[i].loop_nest_depth >= block->loop_nest_depth) {
600 /* branch block */
601 if (block->linear_preds.size() == 1 && !(block->kind & block_kind_loop_exit)) {
602 /* keep variables spilled if they are alive and not used in the current block */
603 unsigned pred_idx = block->linear_preds[0];
615 if (block->logical_preds.size() == 1) {
616 pred_idx = block->logical_preds[0];
631 * and process the block */
632 if (block->register_demand.sgpr - spilled_registers.sgpr > ctx.target_pressure.sgpr) {
633 pred_idx = block->linear_preds[0];
641 if (block->register_demand.vgpr - spilled_registers.vgpr > ctx.target_pressure.vgpr &&
642 block->logical_preds.size() == 1) {
643 pred_idx = block->logical_preds[0];
655 /* else: merge block */
661 pair.first.is_linear() ? block->linear_preds : block->logical_preds;
697 for (aco_ptr<Instruction>& phi : block->instructions) {
704 phi->opcode == aco_opcode::p_phi ? block->logical_preds : block->linear_preds;
756 add_coupling_code(spill_ctx& ctx, Block* block, unsigned block_idx)
759 if (block->linear_preds.size() == 0)
763 /* branch block: TODO take other branch into consideration */
764 if (block->linear_preds.size() == 1 &&
765 !(block->kind & (block_kind_loop_exit | block_kind_loop_header))) {
766 assert(ctx.processed[block->linear_preds[0]]);
767 assert(ctx.register_demand[block_idx].size() == block->instructions.size());
774 const unsigned pred_idx = block->linear_preds[0];
791 /* variable is spilled at predecessor and live at current block: create reload instruction */
799 if (block->logical_preds.size() == 1) {
801 assert(insert_idx < block->instructions.size());
802 instructions.emplace_back(std::move(block->instructions[insert_idx]));
807 unsigned pred_idx = block->logical_preds[0];
825 /* variable is spilled at predecessor and live at current block:
836 /* combine new reload instructions with original block */
839 std::next(ctx.register_demand[block->index].begin(), insert_idx),
840 ctx.register_demand[block->index].end());
844 std::next(block->instructions.begin(), insert_idx)),
846 block->instructions.end()));
847 block->instructions = std::move(instructions);
853 for (ASSERTED unsigned pred : block->linear_preds)
857 for (aco_ptr<Instruction>& phi : block->instructions) {
869 phi->opcode == aco_opcode::p_phi ? block->logical_preds : block->linear_preds;
937 pair.first.is_linear() ? block->linear_preds : block->logical_preds;
992 phi->opcode == aco_opcode::p_phi ? block->logical_preds : block->linear_preds;
1016 /* reload phi operand at end of predecessor block */
1045 // TODO: reload at current block if variable is spilled on all predecessors
1052 pair.first.is_linear() ? block->linear_preds : block->logical_preds;
1137 while (!block->instructions[idx]) {
1142 assert(!(block->kind & block_kind_loop_header));
1144 ctx.register_demand[block->index].erase(ctx.register_demand[block->index].begin(),
1145 ctx.register_demand[block->index].begin() + idx);
1146 ctx.register_demand[block->index].insert(ctx.register_demand[block->index].begin(),
1150 std::vector<aco_ptr<Instruction>>::iterator start = std::next(block->instructions.begin(), idx);
1153 std::move_iterator<std::vector<aco_ptr<Instruction>>::iterator>(block->instructions.end()));
1154 block->instructions = std::move(instructions);
1158 process_block(spill_ctx& ctx, unsigned block_idx, Block* block, RegisterDemand spilled_registers)
1166 while (block->instructions[idx]->opcode == aco_opcode::p_phi ||
1167 block->instructions[idx]->opcode == aco_opcode::p_linear_phi) {
1168 instructions.emplace_back(std::move(block->instructions[idx++]));
1171 if (block->register_demand.exceeds(ctx.target_pressure)) {
1172 update_local_next_uses(ctx, block, ctx.local_next_use_distance);
1179 while (idx < block->instructions.size()) {
1180 aco_ptr<Instruction>& instr = block->instructions[idx];
1212 if (block->register_demand.exceeds(ctx.target_pressure)) {
1277 block->instructions = std::move(instructions);
1283 Block* block = &ctx.program->blocks[block_idx];
1285 /* determine set of variables which are spilled at the beginning of the block */
1286 RegisterDemand spilled_registers = init_live_in_vars(ctx, block, block_idx);
1295 bool is_loop_header = block->loop_nest_depth && ctx.loop_header.top()->index == block_idx;
1298 add_coupling_code(ctx, block, block_idx);
1303 /* check conditions to process this block */
1304 bool process = (block->register_demand - spilled_registers).exceeds(ctx.target_pressure) ||
1315 process_block(ctx, block_idx, block, spilled_registers);
1320 /* check if the next block leaves the current loop */
1321 if (block->loop_nest_depth == 0 ||
1322 ctx.program->blocks[block_idx + 1].loop_nest_depth >= block->loop_nest_depth)
1327 /* preserve original renames at end of loop header block */
1361 /* variable is not live at beginning of this block */
1365 /* if the variable is live at the block's exit, add rename */
1369 /* rename all uses in this block */
1378 /* we can stop with this block as soon as the variable is spilled */
1393 load_scratch_resource(spill_ctx& ctx, Temp& scratch_offset, Block& block,
1397 if (block.kind & block_kind_top_level) {
1400 for (int block_idx = block.index; block_idx >= 0; block_idx--) {
1448 setup_vgpr_spill_reload(spill_ctx& ctx, Block& block,
1462 load_scratch_resource(ctx, scratch_offset, block, instructions, saddr);
1476 load_scratch_resource(ctx, scratch_offset, block, instructions, rsrc_offset);
1482 spill_vgpr(spill_ctx& ctx, Block& block, std::vector<aco_ptr<Instruction>>& instructions,
1491 setup_vgpr_spill_reload(ctx, block, instructions, spill_slot, &offset);
1528 reload_vgpr(spill_ctx& ctx, Block& block, std::vector<aco_ptr<Instruction>>& instructions,
1535 setup_vgpr_spill_reload(ctx, block, instructions, spill_slot, &offset);
1713 for (Block& block : ctx.program->blocks) {
1716 if (block.loop_nest_depth == 0) {
1733 std::vector<aco_ptr<Instruction>>::iterator it = block.instructions.begin();
1736 block.instructions.insert(it, std::move(destr));
1740 if (block.kind & block_kind_top_level && !block.linear_preds.empty()) {
1741 last_top_level_block_idx = block.index;
1749 for (std::pair<Temp, uint32_t> pair : ctx.spills_entry[block.index]) {
1764 instructions.reserve(block.instructions.size());
1766 for (it = block.instructions.begin(); it != block.instructions.end(); ++it) {
1776 spill_vgpr(ctx, block, instructions, *it, slots);
1790 if (last_top_level_block_idx == block.index) {
1794 assert(last_top_level_block_idx < block.index);
1795 /* insert before the branch at last top level block */
1818 reload_vgpr(ctx, block, instructions, *it, slots);
1821 reload_in_loop[spill_slot / ctx.wave_size] = block.loop_nest_depth > 0;
1831 if (last_top_level_block_idx == block.index) {
1835 assert(last_top_level_block_idx < block.index);
1836 /* insert before the branch at last top level block */
1855 block.instructions = std::move(instructions);
1868 for (Block& block : ctx.program->blocks) {
1870 if (block.logical_preds.size() <= 1)
1874 for (aco_ptr<Instruction>& instr : block.instructions) {
1886 for (unsigned pred_idx : block.logical_preds) {
1908 std::vector<aco_ptr<Instruction>>::iterator it = block.instructions.begin();
1911 block.instructions.insert(it, std::move(destr));