Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Mesa 3-D graphics library
  3.  *
  4.  * Copyright (C) 2012-2013 LunarG, Inc.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the "Software"),
  8.  * to deal in the Software without restriction, including without limitation
  9.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10.  * and/or sell copies of the Software, and to permit persons to whom the
  11.  * Software is furnished to do so, subject to the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice shall be included
  14.  * in all copies or substantial portions of the Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  19.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22.  * DEALINGS IN THE SOFTWARE.
  23.  *
  24.  * Authors:
  25.  *    Chia-I Wu <olv@lunarg.com>
  26.  */
  27.  
  28. #include "toy_compiler.h"
  29. #include "toy_tgsi.h"
  30. #include "toy_optimize.h"
  31.  
  32. /**
  33.  * This just eliminates instructions with null dst so far.
  34.  */
  35. static void
  36. eliminate_dead_code(struct toy_compiler *tc)
  37. {
  38.    struct toy_inst *inst;
  39.  
  40.    tc_head(tc);
  41.    while ((inst = tc_next(tc)) != NULL) {
  42.       switch (inst->opcode) {
  43.       case BRW_OPCODE_IF:
  44.       case BRW_OPCODE_ELSE:
  45.       case BRW_OPCODE_ENDIF:
  46.       case BRW_OPCODE_WHILE:
  47.       case BRW_OPCODE_BREAK:
  48.       case BRW_OPCODE_CONTINUE:
  49.       case BRW_OPCODE_SEND:
  50.       case BRW_OPCODE_SENDC:
  51.       case BRW_OPCODE_NOP:
  52.          /* never eliminated */
  53.          break;
  54.       default:
  55.          if (tdst_is_null(inst->dst) || !inst->dst.writemask) {
  56.             /* math is always BRW_CONDITIONAL_NONE */
  57.             if ((inst->opcode == BRW_OPCODE_MATH ||
  58.                  inst->cond_modifier == BRW_CONDITIONAL_NONE) &&
  59.                 !inst->acc_wr_ctrl)
  60.                tc_discard_inst(tc, inst);
  61.          }
  62.          break;
  63.       }
  64.    }
  65. }
  66.  
  67. void
  68. toy_compiler_optimize(struct toy_compiler *tc)
  69. {
  70.    eliminate_dead_code(tc);
  71. }
  72.