]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ir.cpp
c++: ir_block::m_exits
[xonotic/gmqcc.git] / ir.cpp
diff --git a/ir.cpp b/ir.cpp
index 3b78c35a7096a81fd7daa240df505f4890dc0ee1..17bd997cc83faf03d30cb84e6924c8bfa8b0b4de 100644 (file)
--- a/ir.cpp
+++ b/ir.cpp
@@ -235,15 +235,14 @@ static bool GMQCC_WARN vec_ir_value_find(std::vector<ir_value *> &vec, const ir_
     return false;
 }
 
-static bool GMQCC_WARN vec_ir_block_find(ir_block **vec, ir_block *what, size_t *idx)
+static bool GMQCC_WARN vec_ir_block_find(std::vector<ir_block *> &vec, ir_block *what, size_t *idx)
 {
-    size_t i;
-    size_t len = vec_size(vec);
-    for (i = 0; i < len; ++i) {
-        if (vec[i] == what) {
-            if (idx) *idx = i;
-            return true;
-        }
+    for (auto &it : vec) {
+        if (it != what)
+            continue;
+        if (idx)
+            *idx = &it - &vec[0];
+        return true;
     }
     return false;
 }
@@ -638,7 +637,7 @@ bool ir_function_finalize(ir_function *self)
             // claiming it's unused, otherwise skip the vector entierly
             if (v->m_vtype == TYPE_VECTOR)
             {
-                size_t mask = (1 << 0) | (1 << 1) | (1 << 2), bits = 0;
+                size_t mask = (1 << 3) - 1, bits = 0;
                 for (size_t i = 0; i < 3; i++)
                     if (!v->m_members[i] || (v->m_members[i]->m_reads.empty()
                         && v->m_members[i]->m_writes.size()))
@@ -656,8 +655,7 @@ bool ir_function_finalize(ir_function *self)
                             return false;
             }
             // just a standard variable
-            else if (v->m_name[0] != '#'
-                && irwarning(v->m_context, WARN_UNUSED_VARIABLE,
+            else if (irwarning(v->m_context, WARN_UNUSED_VARIABLE,
                     "unused variable: `%s`", v->m_name.c_str())) return false;
         }
     }
@@ -747,8 +745,6 @@ ir_block::~ir_block()
     for (size_t i = 0; i != vec_size(m_instr); ++i)
         delete m_instr[i];
     vec_free(m_instr);
-    vec_free(m_entries);
-    vec_free(m_exits);
 }
 
 static void ir_block_delete_quick(ir_block* self)
@@ -1382,10 +1378,10 @@ bool ir_block_create_if(ir_block *self, lex_ctx_t ctx, ir_value *v,
 
     vec_push(self->m_instr, in);
 
-    vec_push(self->m_exits, ontrue);
-    vec_push(self->m_exits, onfalse);
-    vec_push(ontrue->m_entries,  self);
-    vec_push(onfalse->m_entries, self);
+    self->m_exits.push_back(ontrue);
+    self->m_exits.push_back(onfalse);
+    ontrue->m_entries.push_back(self);
+    onfalse->m_entries.push_back(self);
     return true;
 }
 
@@ -1402,8 +1398,8 @@ bool ir_block_create_jump(ir_block *self, lex_ctx_t ctx, ir_block *to)
     in->m_bops[0] = to;
     vec_push(self->m_instr, in);
 
-    vec_push(self->m_exits, to);
-    vec_push(to->m_entries, self);
+    self->m_exits.push_back(to);
+    to->m_entries.push_back(self);
     return true;
 }
 
@@ -2148,15 +2144,13 @@ static bool ir_block_life_propagate(ir_block *self, bool *changed)
 {
     ir_instr *instr;
     ir_value *value;
-    size_t i, o, p, mem;
+    size_t i, o, mem;
     // bitmasks which operands are read from or written to
     size_t read, write;
 
     self->m_living.clear();
 
-    p = vec_size(self->m_exits);
-    for (i = 0; i < p; ++i) {
-        ir_block *prev = self->m_exits[i];
+    for (auto &prev : self->m_exits) {
         for (auto &it : prev->m_living)
             if (!vec_ir_value_find(self->m_living, it, nullptr))
                 self->m_living.push_back(it);