i965: Remove cfg-invalidating parameter from invalidate_live_intervals.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_vec4_reg_allocate.cpp
index e7aab9d039365c70a9edb6764b007647ff823e81..1ebebe0a8914b847a0d6884be9e3a5b84ee286cb 100644 (file)
 
 extern "C" {
 #include "main/macros.h"
-#include "program/register_allocate.h"
+#include "util/register_allocate.h"
 } /* extern "C" */
 
 #include "brw_vec4.h"
 #include "brw_vs.h"
+#include "brw_cfg.h"
 
 using namespace brw;
 
 namespace brw {
 
 static void
-assign(unsigned int *reg_hw_locations, reg *reg)
+assign(unsigned int *reg_hw_locations, backend_reg *reg)
 {
    if (reg->file == GRF) {
       reg->reg = reg_hw_locations[reg->reg];
@@ -56,9 +57,7 @@ vec4_visitor::reg_allocate_trivial()
       virtual_grf_used[i] = false;
    }
 
-   foreach_list(node, &this->instructions) {
-      vec4_instruction *inst = (vec4_instruction *) node;
-
+   foreach_in_list(vec4_instruction, inst, &instructions) {
       if (inst->dst.file == GRF)
         virtual_grf_used[inst->dst.reg] = true;
 
@@ -78,9 +77,7 @@ vec4_visitor::reg_allocate_trivial()
    }
    prog_data->total_grf = next;
 
-   foreach_list(node, &this->instructions) {
-      vec4_instruction *inst = (vec4_instruction *) node;
-
+   foreach_in_list(vec4_instruction, inst, &instructions) {
       assign(hw_reg_mapping, &inst->dst);
       assign(hw_reg_mapping, &inst->src[0]);
       assign(hw_reg_mapping, &inst->src[1]);
@@ -97,9 +94,10 @@ vec4_visitor::reg_allocate_trivial()
 }
 
 extern "C" void
-brw_vec4_alloc_reg_set(struct brw_context *brw)
+brw_vec4_alloc_reg_set(struct intel_screen *screen)
 {
-   int base_reg_count = brw->gen >= 7 ? GEN7_MRF_HACK_START : BRW_MAX_GRF;
+   int base_reg_count =
+      screen->devinfo->gen >= 7 ? GEN7_MRF_HACK_START : BRW_MAX_GRF;
 
    /* After running split_virtual_grfs(), almost all VGRFs will be of size 1.
     * SEND-from-GRF sources cannot be split, so we also need classes for each
@@ -114,14 +112,14 @@ brw_vec4_alloc_reg_set(struct brw_context *brw)
       ra_reg_count += base_reg_count - (class_sizes[i] - 1);
    }
 
-   ralloc_free(brw->vec4.ra_reg_to_grf);
-   brw->vec4.ra_reg_to_grf = ralloc_array(brw, uint8_t, ra_reg_count);
-   ralloc_free(brw->vec4.regs);
-   brw->vec4.regs = ra_alloc_reg_set(brw, ra_reg_count);
-   if (brw->gen >= 6)
-      ra_set_allocate_round_robin(brw->vec4.regs);
-   ralloc_free(brw->vec4.classes);
-   brw->vec4.classes = ralloc_array(brw, int, class_count);
+   ralloc_free(screen->vec4_reg_set.ra_reg_to_grf);
+   screen->vec4_reg_set.ra_reg_to_grf = ralloc_array(screen, uint8_t, ra_reg_count);
+   ralloc_free(screen->vec4_reg_set.regs);
+   screen->vec4_reg_set.regs = ra_alloc_reg_set(screen, ra_reg_count);
+   if (screen->devinfo->gen >= 6)
+      ra_set_allocate_round_robin(screen->vec4_reg_set.regs);
+   ralloc_free(screen->vec4_reg_set.classes);
+   screen->vec4_reg_set.classes = ralloc_array(screen, int, class_count);
 
    /* Now, add the registers to their classes, and add the conflicts
     * between them and the base GRF registers (and also each other).
@@ -129,17 +127,17 @@ brw_vec4_alloc_reg_set(struct brw_context *brw)
    int reg = 0;
    for (int i = 0; i < class_count; i++) {
       int class_reg_count = base_reg_count - (class_sizes[i] - 1);
-      brw->vec4.classes[i] = ra_alloc_reg_class(brw->vec4.regs);
+      screen->vec4_reg_set.classes[i] = ra_alloc_reg_class(screen->vec4_reg_set.regs);
 
       for (int j = 0; j < class_reg_count; j++) {
-        ra_class_add_reg(brw->vec4.regs, brw->vec4.classes[i], reg);
+        ra_class_add_reg(screen->vec4_reg_set.regs, screen->vec4_reg_set.classes[i], reg);
 
-        brw->vec4.ra_reg_to_grf[reg] = j;
+        screen->vec4_reg_set.ra_reg_to_grf[reg] = j;
 
         for (int base_reg = j;
              base_reg < j + class_sizes[i];
              base_reg++) {
-           ra_add_transitive_reg_conflict(brw->vec4.regs, base_reg, reg);
+           ra_add_transitive_reg_conflict(screen->vec4_reg_set.regs, base_reg, reg);
         }
 
         reg++;
@@ -147,7 +145,7 @@ brw_vec4_alloc_reg_set(struct brw_context *brw)
    }
    assert(reg == ra_reg_count);
 
-   ra_set_finalize(brw->vec4.regs, NULL);
+   ra_set_finalize(screen->vec4_reg_set.regs, NULL);
 }
 
 void
@@ -177,6 +175,7 @@ vec4_visitor::setup_payload_interference(struct ra_graph *g,
 bool
 vec4_visitor::reg_allocate()
 {
+   struct intel_screen *screen = brw->intelScreen;
    unsigned int hw_reg_mapping[virtual_grf_count];
    int payload_reg_count = this->first_non_payload_grf;
 
@@ -192,13 +191,13 @@ vec4_visitor::reg_allocate()
    int first_payload_node = node_count;
    node_count += payload_reg_count;
    struct ra_graph *g =
-      ra_alloc_interference_graph(brw->vec4.regs, node_count);
+      ra_alloc_interference_graph(screen->vec4_reg_set.regs, node_count);
 
    for (int i = 0; i < virtual_grf_count; i++) {
       int size = this->virtual_grf_sizes[i];
       assert(size >= 1 && size <= 2 &&
              "Register allocation relies on split_virtual_grfs().");
-      ra_set_node_class(g, i, brw->vec4.classes[size - 1]);
+      ra_set_node_class(g, i, screen->vec4_reg_set.classes[size - 1]);
 
       for (int j = 0; j < i; j++) {
         if (virtual_grf_interferes(i, j)) {
@@ -209,7 +208,7 @@ vec4_visitor::reg_allocate()
 
    setup_payload_interference(g, first_payload_node, node_count);
 
-   if (!ra_allocate_no_spills(g)) {
+   if (!ra_allocate(g)) {
       /* Failed to allocate registers.  Spill a reg, and the caller will
        * loop back into here to try again.
        */
@@ -234,14 +233,12 @@ vec4_visitor::reg_allocate()
    for (int i = 0; i < virtual_grf_count; i++) {
       int reg = ra_get_node_reg(g, i);
 
-      hw_reg_mapping[i] = brw->vec4.ra_reg_to_grf[reg];
+      hw_reg_mapping[i] = screen->vec4_reg_set.ra_reg_to_grf[reg];
       prog_data->total_grf = MAX2(prog_data->total_grf,
                                  hw_reg_mapping[i] + virtual_grf_sizes[i]);
    }
 
-   foreach_list(node, &this->instructions) {
-      vec4_instruction *inst = (vec4_instruction *)node;
-
+   foreach_in_list(vec4_instruction, inst, &instructions) {
       assign(hw_reg_mapping, &inst->dst);
       assign(hw_reg_mapping, &inst->src[0]);
       assign(hw_reg_mapping, &inst->src[1]);
@@ -267,9 +264,7 @@ vec4_visitor::evaluate_spill_costs(float *spill_costs, bool *no_spill)
     * spill/unspill we'll have to do, and guess that the insides of
     * loops run 10 times.
     */
-   foreach_list(node, &this->instructions) {
-      vec4_instruction *inst = (vec4_instruction *) node;
-
+   foreach_in_list(vec4_instruction, inst, &instructions) {
       for (unsigned int i = 0; i < 3; i++) {
         if (inst->src[i].file == GRF) {
            spill_costs[inst->src[i].reg] += loop_scale;
@@ -332,10 +327,10 @@ vec4_visitor::spill_reg(int spill_reg_nr)
    assert(virtual_grf_sizes[spill_reg_nr] == 1);
    unsigned int spill_offset = c->last_scratch++;
 
-   /* Generate spill/unspill instructions for the objects being spilled. */
-   foreach_list(node, &this->instructions) {
-      vec4_instruction *inst = (vec4_instruction *) node;
+   calculate_cfg();
 
+   /* Generate spill/unspill instructions for the objects being spilled. */
+   foreach_block_and_inst(block, vec4_instruction, inst, cfg) {
       for (unsigned int i = 0; i < 3; i++) {
          if (inst->src[i].file == GRF && inst->src[i].reg == spill_reg_nr) {
             src_reg spill_reg = inst->src[i];
@@ -350,12 +345,12 @@ vec4_visitor::spill_reg(int spill_reg_nr)
                temp.writemask |= (1 << BRW_GET_SWZ(inst->src[i].swizzle, c));
             assert(temp.writemask != 0);
 
-            emit_scratch_read(inst, temp, spill_reg, spill_offset);
+            emit_scratch_read(block, inst, temp, spill_reg, spill_offset);
          }
       }
 
       if (inst->dst.file == GRF && inst->dst.reg == spill_reg_nr) {
-         emit_scratch_write(inst, spill_offset);
+         emit_scratch_write(block, inst, spill_offset);
       }
    }