MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / ComputeLoopRegisterPressure

Method ComputeLoopRegisterPressure

source/opt/register_pressure.cpp:287–334  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

285}
286
287void RegisterLiveness::ComputeLoopRegisterPressure(
288 const Loop& loop, RegionRegisterLiveness* loop_reg_pressure) const {
289 loop_reg_pressure->Clear();
290
291 const RegionRegisterLiveness* header_live_inout = Get(loop.GetHeaderBlock());
292 loop_reg_pressure->live_in_ = header_live_inout->live_in_;
293
294 std::unordered_set<uint32_t> exit_blocks;
295 loop.GetExitBlocks(&exit_blocks);
296
297 for (uint32_t bb_id : exit_blocks) {
298 const RegionRegisterLiveness* live_inout = Get(bb_id);
299 loop_reg_pressure->live_out_.insert(live_inout->live_in_.begin(),
300 live_inout->live_in_.end());
301 }
302
303 std::unordered_set<uint32_t> seen_insn;
304 for (Instruction* insn : loop_reg_pressure->live_out_) {
305 loop_reg_pressure->AddRegisterClass(insn);
306 seen_insn.insert(insn->result_id());
307 }
308 for (Instruction* insn : loop_reg_pressure->live_in_) {
309 if (!seen_insn.count(insn->result_id())) {
310 continue;
311 }
312 loop_reg_pressure->AddRegisterClass(insn);
313 seen_insn.insert(insn->result_id());
314 }
315
316 loop_reg_pressure->used_registers_ = 0;
317
318 for (uint32_t bb_id : loop.GetBlocks()) {
319 BasicBlock* bb = context_->cfg()->block(bb_id);
320
321 const RegionRegisterLiveness* live_inout = Get(bb_id);
322 assert(live_inout != nullptr && "Basic block not processed");
323 loop_reg_pressure->used_registers_ = std::max(
324 loop_reg_pressure->used_registers_, live_inout->used_registers_);
325
326 for (Instruction& insn : *bb) {
327 if (insn.opcode() == spv::Op::OpPhi || !CreatesRegisterUsage(&insn) ||
328 seen_insn.count(insn.result_id())) {
329 continue;
330 }
331 loop_reg_pressure->AddRegisterClass(&insn);
332 }
333 }
334}
335
336void RegisterLiveness::SimulateFusion(
337 const Loop& l1, const Loop& l2, RegionRegisterLiveness* sim_result) const {

Callers 2

ShouldSplitLoopMethod · 0.80
TEST_FFunction · 0.80

Calls 13

CreatesRegisterUsageFunction · 0.85
GetExitBlocksMethod · 0.80
ClearMethod · 0.45
GetHeaderBlockMethod · 0.45
insertMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
AddRegisterClassMethod · 0.45
result_idMethod · 0.45
countMethod · 0.45
blockMethod · 0.45
cfgMethod · 0.45

Tested by

no test coverage detected