[Mesa-dev] [PATCH] i965: Replace default case with list of enum values.

Matt Turner mattst88 at gmail.com
Thu Oct 29 17:52:33 PDT 2015


If we add a new file type, we'd like to get warnings if it's not
handled.

Unfortuately, gcc seems to have bugs (see the XXX).
---
 src/mesa/drivers/dri/i965/brw_fs.cpp                  | 16 +++++-----------
 src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp |  7 ++++---
 src/mesa/drivers/dri/i965/brw_fs_generator.cpp        | 11 ++++++++---
 src/mesa/drivers/dri/i965/brw_ir_fs.h                 |  7 ++++---
 src/mesa/drivers/dri/i965/brw_vec4.cpp                | 19 +++++++++++--------
 5 files changed, 32 insertions(+), 28 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index c40ca91..0258633 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -88,8 +88,6 @@ fs_inst::init(enum opcode opcode, uint8_t exec_size, const fs_reg &dst,
    case IMM:
    case UNIFORM:
       unreachable("Invalid destination register file");
-   default:
-      unreachable("Invalid register file");
    }
 
    this->writes_accumulator = false;
@@ -839,10 +837,10 @@ fs_inst::regs_read(int arg) const
                           src[arg].component_size(exec_size),
                           REG_SIZE);
    case MRF:
-      unreachable("MRF registers are not allowed as sources");
-   default:
-      unreachable("Invalid register file");
+      break;
    }
+   /* XXX: gcc warns if this is in the switch */
+   unreachable("MRF registers are not allowed as sources");
 }
 
 bool
@@ -4501,9 +4499,8 @@ fs_visitor::dump_instruction(backend_instruction *be_inst, FILE *file)
       if (inst->dst.fixed_hw_reg.subnr)
          fprintf(file, "+%d", inst->dst.fixed_hw_reg.subnr);
       break;
-   default:
-      fprintf(file, "???");
-      break;
+   case IMM:
+      unreachable("not reached");
    }
    fprintf(file, ":%s, ", brw_reg_type_letters(inst->dst.type));
 
@@ -4596,9 +4593,6 @@ fs_visitor::dump_instruction(backend_instruction *be_inst, FILE *file)
          if (inst->src[i].fixed_hw_reg.abs)
             fprintf(file, "|");
          break;
-      default:
-         fprintf(file, "???");
-         break;
       }
       if (inst->src[i].abs)
          fprintf(file, "|");
diff --git a/src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp b/src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp
index 97e206d..2620482 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp
@@ -416,9 +416,10 @@ fs_visitor::try_copy_propagate(fs_inst *inst, int arg, acp_entry *entry)
          inst->src[arg].subreg_offset = offset % 32;
       }
       break;
-   default:
-      unreachable("Invalid register file");
-      break;
+
+   case MRF:
+   case IMM:
+      unreachable("not reached");
    }
 
    if (has_source_modifiers) {
diff --git a/src/mesa/drivers/dri/i965/brw_fs_generator.cpp b/src/mesa/drivers/dri/i965/brw_fs_generator.cpp
index 139d1dd..4ef86dd 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_generator.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_generator.cpp
@@ -42,9 +42,13 @@ static uint32_t brw_file_from_reg(fs_reg *reg)
       return BRW_MESSAGE_REGISTER_FILE;
    case IMM:
       return BRW_IMMEDIATE_VALUE;
-   default:
-      unreachable("not reached");
+   case BAD_FILE:
+   case HW_REG:
+   case ATTR:
+   case UNIFORM:
+      break;
    }
+   unreachable("not reached"); /* XXX: gcc warns if this is in the switch */
 }
 
 static struct brw_reg
@@ -116,7 +120,8 @@ brw_reg_from_fs_reg(fs_inst *inst, fs_reg *reg, unsigned gen)
       /* Probably unused. */
       brw_reg = brw_null_reg();
       break;
-   default:
+   case ATTR:
+   case UNIFORM:
       unreachable("not reached");
    }
    if (reg->abs)
diff --git a/src/mesa/drivers/dri/i965/brw_ir_fs.h b/src/mesa/drivers/dri/i965/brw_ir_fs.h
index 7726e4b..4417555 100644
--- a/src/mesa/drivers/dri/i965/brw_ir_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_ir_fs.h
@@ -97,7 +97,9 @@ byte_offset(fs_reg reg, unsigned delta)
    case MRF:
       reg.reg += delta / 32;
       break;
-   default:
+   case IMM:
+   case HW_REG:
+   case UNIFORM:
       assert(delta == 0);
    }
    reg.subreg_offset += delta % 32;
@@ -119,7 +121,7 @@ horiz_offset(fs_reg reg, unsigned delta)
    case MRF:
    case ATTR:
       return byte_offset(reg, delta * reg.stride * type_sz(reg.type));
-   default:
+   case HW_REG:
       assert(delta == 0);
    }
    return reg;
@@ -163,7 +165,6 @@ half(fs_reg reg, unsigned idx)
 
    case ATTR:
    case HW_REG:
-   default:
       unreachable("Cannot take half of this register type");
    }
    return reg;
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.cpp b/src/mesa/drivers/dri/i965/brw_vec4.cpp
index 3353e1e..01eb158 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4.cpp
@@ -1427,9 +1427,10 @@ vec4_visitor::dump_instruction(backend_instruction *be_inst, FILE *file)
    case BAD_FILE:
       fprintf(file, "(null)");
       break;
-   default:
-      fprintf(file, "???");
-      break;
+   case IMM:
+   case ATTR:
+   case UNIFORM:
+      unreachable("not reached");
    }
    if (inst->dst.writemask != WRITEMASK_XYZW) {
       fprintf(file, ".");
@@ -1521,9 +1522,8 @@ vec4_visitor::dump_instruction(backend_instruction *be_inst, FILE *file)
       case BAD_FILE:
          fprintf(file, "(null)");
          break;
-      default:
-         fprintf(file, "???");
-         break;
+      case MRF:
+         unreachable("not reached");
       }
 
       /* Don't print .0; and only VGRFs have reg_offsets and sizes */
@@ -1839,7 +1839,8 @@ vec4_visitor::convert_to_hw_regs()
             reg = brw_null_reg();
             break;
 
-         default:
+         case MRF:
+         case ATTR:
             unreachable("not reached");
          }
          src.fixed_hw_reg = reg;
@@ -1871,7 +1872,9 @@ vec4_visitor::convert_to_hw_regs()
          reg = brw_null_reg();
          break;
 
-      default:
+      case IMM:
+      case ATTR:
+      case UNIFORM:
          unreachable("not reached");
       }
 
-- 
2.4.9



More information about the mesa-dev mailing list