intel/compiler: Calculate num_instructions in O(1) during register pressure calculation
authorFrancisco Jerez <currojerez@riseup.net>
Sun, 13 Mar 2016 23:37:03 +0000 (16:37 -0700)
committerMatt Turner <mattst88@gmail.com>
Fri, 6 Mar 2020 18:21:13 +0000 (10:21 -0800)
And mark the variable declaration as const.

Reviewed-by: Matt Turner <mattst88@gmail.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4012>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4012>

src/intel/compiler/brw_fs.cpp

index 704088ab588600c1a170209bfd4a29f8e978ba19..0a6537478e0eb4047532db9bcf05370fb1520e13 100644 (file)
@@ -7362,9 +7362,8 @@ fs_visitor::setup_cs_payload()
 brw::register_pressure::register_pressure(const fs_visitor *v)
 {
    const fs_live_variables &live = v->live_analysis.require();
-   unsigned num_instructions = 0;
-   foreach_block(block, v->cfg)
-      num_instructions += block->instructions.length();
+   const unsigned num_instructions = v->cfg->num_blocks ?
+      v->cfg->blocks[v->cfg->num_blocks - 1]->end_ip + 1 : 0;
 
    regs_live_at_ip = new unsigned[num_instructions]();