Print this page
new smatch

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/liveness.c
          +++ new/usr/src/tools/smatch/src/liveness.c
   1    1  /*
   2    2   * Register - track pseudo usage, maybe eventually try to do register
   3    3   * allocation.
   4    4   *
   5    5   * Copyright (C) 2004 Linus Torvalds
   6    6   */
   7    7  
   8    8  #include <assert.h>
   9    9  
       10 +#include "liveness.h"
  10   11  #include "parse.h"
  11   12  #include "expression.h"
  12   13  #include "linearize.h"
  13   14  #include "flow.h"
  14   15  
  15   16  static void phi_defines(struct instruction * phi_node, pseudo_t target,
  16   17          void (*defines)(struct basic_block *, pseudo_t))
  17   18  {
  18   19          pseudo_t phi;
  19   20          FOR_EACH_PTR(phi_node->phi_list, phi) {
↓ open down ↓ 26 lines elided ↑ open up ↑
  46   47          void (*def)(struct basic_block *, pseudo_t),
  47   48          void (*use)(struct basic_block *, pseudo_t))
  48   49  {
  49   50          pseudo_t pseudo;
  50   51  
  51   52          #define USES(x)         use(bb, insn->x)
  52   53          #define DEFINES(x)      def(bb, insn->x)
  53   54  
  54   55          switch (insn->opcode) {
  55   56          case OP_RET:
       57 +        case OP_COMPUTEDGOTO:
  56   58                  USES(src);
  57   59                  break;
  58   60  
  59   61          case OP_CBR:
  60   62          case OP_SWITCH:
  61   63                  USES(cond);
  62   64                  break;
  63   65  
  64      -        case OP_COMPUTEDGOTO:
  65      -                USES(target);
  66      -                break;
  67      -        
  68   66          /* Binary */
  69   67          case OP_BINARY ... OP_BINARY_END:
       68 +        case OP_FPCMP ... OP_FPCMP_END:
  70   69          case OP_BINCMP ... OP_BINCMP_END:
  71   70                  USES(src1); USES(src2); DEFINES(target);
  72   71                  break;
  73   72  
  74   73          /* Uni */
  75      -        case OP_NOT: case OP_NEG:
       74 +        case OP_UNOP ... OP_UNOP_END:
       75 +        case OP_SYMADDR:
  76   76                  USES(src1); DEFINES(target);
  77   77                  break;
  78   78  
  79   79          case OP_SEL:
  80   80                  USES(src1); USES(src2); USES(src3); DEFINES(target);
  81   81                  break;
  82   82          
  83   83          /* Memory */
  84   84          case OP_LOAD:
  85   85                  USES(src); DEFINES(target);
  86   86                  break;
  87   87  
  88   88          case OP_STORE:
  89   89                  USES(src); USES(target);
  90   90                  break;
  91   91  
  92   92          case OP_SETVAL:
       93 +        case OP_SETFVAL:
  93   94                  DEFINES(target);
  94   95                  break;
  95   96  
  96      -        case OP_SYMADDR:
  97      -                USES(symbol); DEFINES(target);
  98      -                break;
  99      -
 100   97          /* Other */
 101   98          case OP_PHI:
 102   99                  /* Phi-nodes are "backwards" nodes. Their def doesn't matter */
 103  100                  phi_defines(insn, insn->target, def);
 104  101                  break;
 105  102  
 106  103          case OP_PHISOURCE:
 107  104                  /*
 108  105                   * We don't care about the phi-source define, they get set
 109  106                   * up and expanded by the OP_PHI
 110  107                   */
 111  108                  USES(phi_src);
 112  109                  break;
 113  110  
 114      -        case OP_CAST:
 115      -        case OP_SCAST:
 116      -        case OP_FPCAST:
 117      -        case OP_PTRCAST:
 118      -                USES(src); DEFINES(target);
 119      -                break;
 120      -
 121  111          case OP_CALL:
 122  112                  USES(func);
 123  113                  if (insn->target != VOID)
 124  114                          DEFINES(target);
 125  115                  FOR_EACH_PTR(insn->arguments, pseudo) {
 126  116                          use(bb, pseudo);
 127  117                  } END_FOR_EACH_PTR(pseudo);
 128  118                  break;
 129  119  
 130  120          case OP_SLICE:
↓ open down ↓ 2 lines elided ↑ open up ↑
 133  123  
 134  124          case OP_ASM:
 135  125                  asm_liveness(bb, insn, def, use);
 136  126                  break;
 137  127  
 138  128          case OP_RANGE:
 139  129                  USES(src1); USES(src2); USES(src3);
 140  130                  break;
 141  131  
 142  132          case OP_BADOP:
 143      -        case OP_INVOKE:
 144      -        case OP_UNWIND:
 145      -        case OP_MALLOC:
 146      -        case OP_FREE:
 147      -        case OP_ALLOCA:
 148      -        case OP_GET_ELEMENT_PTR:
 149      -        case OP_VANEXT:
 150      -        case OP_VAARG:
 151      -        case OP_SNOP:
 152      -        case OP_LNOP:
 153  133          case OP_NOP:
 154  134          case OP_CONTEXT:
 155  135                  break;
 156  136          }
 157  137  }
 158  138  
 159      -int pseudo_in_list(struct pseudo_list *list, pseudo_t pseudo)
 160      -{
 161      -        pseudo_t old;
 162      -        FOR_EACH_PTR(list,old) {
 163      -                if (old == pseudo)
 164      -                        return 1;
 165      -        } END_FOR_EACH_PTR(old);   
 166      -        return 0;
 167      -}
 168  139  
 169  140  static int liveness_changed;
 170  141  
 171  142  static void add_pseudo_exclusive(struct pseudo_list **list, pseudo_t pseudo)
 172  143  {
 173  144          if (!pseudo_in_list(*list, pseudo)) {
 174  145                  liveness_changed = 1;
 175  146                  add_pseudo(list, pseudo);
 176  147          }
 177  148  }
↓ open down ↓ 91 lines elided ↑ open up ↑
 269  240  }
 270  241  
 271  242  static void merge_pseudo_list(struct pseudo_list *src, struct pseudo_list **dest)
 272  243  {
 273  244          pseudo_t pseudo;
 274  245          FOR_EACH_PTR(src, pseudo) {
 275  246                  add_pseudo_exclusive(dest, pseudo);
 276  247          } END_FOR_EACH_PTR(pseudo);
 277  248  }
 278  249  
 279      -void track_phi_uses(struct instruction *insn)
      250 +static void track_phi_uses(struct instruction *insn)
 280  251  {
 281  252          pseudo_t phi;
 282  253          FOR_EACH_PTR(insn->phi_list, phi) {
 283  254                  struct instruction *def;
 284  255                  if (phi == VOID || !phi->def)
 285  256                          continue;
 286  257                  def = phi->def;
 287  258                  assert(def->opcode == OP_PHISOURCE);
 288  259                  add_ptr_list(&def->phi_users, insn);
 289  260          } END_FOR_EACH_PTR(phi);
↓ open down ↓ 70 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX