i965/cfg: Add functions to combine basic blocks.
authorMatt Turner <mattst88@gmail.com>
Tue, 15 Jul 2014 21:51:43 +0000 (14:51 -0700)
committerMatt Turner <mattst88@gmail.com>
Fri, 22 Aug 2014 17:23:34 +0000 (10:23 -0700)
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
src/mesa/drivers/dri/i965/brw_cfg.cpp
src/mesa/drivers/dri/i965/brw_cfg.h

index 3895469b0559e35320d8d1cfeb3833230bd51bee..8714b682be0b681c12814f1c9d25a822597a27f7 100644 (file)
@@ -92,6 +92,58 @@ bblock_t::is_successor_of(const bblock_t *block) const
    return false;
 }
 
+static bool
+ends_block(const backend_instruction *inst)
+{
+   enum opcode op = inst->opcode;
+
+   return op == BRW_OPCODE_IF ||
+          op == BRW_OPCODE_ELSE ||
+          op == BRW_OPCODE_CONTINUE ||
+          op == BRW_OPCODE_BREAK ||
+          op == BRW_OPCODE_WHILE;
+}
+
+static bool
+starts_block(const backend_instruction *inst)
+{
+   enum opcode op = inst->opcode;
+
+   return op == BRW_OPCODE_DO ||
+          op == BRW_OPCODE_ENDIF;
+}
+
+bool
+bblock_t::can_combine_with(const bblock_t *that) const
+{
+   if ((const bblock_t *)this->link.next != that)
+      return false;
+
+   if (ends_block(this->end) ||
+       starts_block(that->start))
+      return false;
+
+   return true;
+}
+
+void
+bblock_t::combine_with(bblock_t *that)
+{
+   assert(this->can_combine_with(that));
+   foreach_list_typed (bblock_link, link, link, &this->children) {
+      assert(link->block == that);
+   }
+   foreach_list_typed (bblock_link, link, link, &that->parents) {
+      assert(link->block == this);
+   }
+
+   this->end_ip = that->end_ip;
+   this->end = that->end;
+   this->else_block = that->else_block;
+
+   this->cfg->remove_block(that);
+}
+
 void
 bblock_t::dump(backend_visitor *v)
 {
index ecbb996244e8481408a8b9638b2108f323449150..ca6a2ac2d66e576c4372afd893fa91a6717ecac3 100644 (file)
@@ -60,6 +60,8 @@ struct bblock_t {
    void add_successor(void *mem_ctx, bblock_t *successor);
    bool is_predecessor_of(const bblock_t *block) const;
    bool is_successor_of(const bblock_t *block) const;
+   bool can_combine_with(const bblock_t *that) const;
+   void combine_with(bblock_t *that);
    void dump(backend_visitor *v);
 #endif