hotspot/src/share/vm/opto/idealGraphPrinter.cpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 768 d0bebc7eefc2
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2007 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_idealGraphPrinter.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// Constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// Keep consistent with Java constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
const char *IdealGraphPrinter::INDENT = "  ";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
const char *IdealGraphPrinter::TOP_ELEMENT = "graphDocument";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
const char *IdealGraphPrinter::GROUP_ELEMENT = "group";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
const char *IdealGraphPrinter::GRAPH_ELEMENT = "graph";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
const char *IdealGraphPrinter::PROPERTIES_ELEMENT = "properties";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
const char *IdealGraphPrinter::EDGES_ELEMENT = "edges";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
const char *IdealGraphPrinter::PROPERTY_ELEMENT = "p";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
const char *IdealGraphPrinter::EDGE_ELEMENT = "edge";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
const char *IdealGraphPrinter::NODE_ELEMENT = "node";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
const char *IdealGraphPrinter::NODES_ELEMENT = "nodes";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
const char *IdealGraphPrinter::REMOVE_EDGE_ELEMENT = "removeEdge";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
const char *IdealGraphPrinter::REMOVE_NODE_ELEMENT = "removeNode";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
const char *IdealGraphPrinter::METHOD_NAME_PROPERTY = "name";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
const char *IdealGraphPrinter::METHOD_IS_PUBLIC_PROPERTY = "public";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
const char *IdealGraphPrinter::METHOD_IS_STATIC_PROPERTY = "static";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
const char *IdealGraphPrinter::TRUE_VALUE = "true";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
const char *IdealGraphPrinter::NODE_NAME_PROPERTY = "name";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
const char *IdealGraphPrinter::EDGE_NAME_PROPERTY = "name";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
const char *IdealGraphPrinter::NODE_ID_PROPERTY = "id";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
const char *IdealGraphPrinter::FROM_PROPERTY = "from";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
const char *IdealGraphPrinter::TO_PROPERTY = "to";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
const char *IdealGraphPrinter::PROPERTY_NAME_PROPERTY = "name";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
const char *IdealGraphPrinter::GRAPH_NAME_PROPERTY = "name";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
const char *IdealGraphPrinter::INDEX_PROPERTY = "index";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
const char *IdealGraphPrinter::METHOD_ELEMENT = "method";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
const char *IdealGraphPrinter::INLINE_ELEMENT = "inline";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
const char *IdealGraphPrinter::BYTECODES_ELEMENT = "bytecodes";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
const char *IdealGraphPrinter::METHOD_BCI_PROPERTY = "bci";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
const char *IdealGraphPrinter::METHOD_SHORT_NAME_PROPERTY = "shortName";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
const char *IdealGraphPrinter::CONTROL_FLOW_ELEMENT = "controlFlow";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
const char *IdealGraphPrinter::BLOCK_NAME_PROPERTY = "name";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
const char *IdealGraphPrinter::BLOCK_DOMINATOR_PROPERTY = "dom";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
const char *IdealGraphPrinter::BLOCK_ELEMENT = "block";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
const char *IdealGraphPrinter::SUCCESSORS_ELEMENT = "successors";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
const char *IdealGraphPrinter::SUCCESSOR_ELEMENT = "successor";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
const char *IdealGraphPrinter::ASSEMBLY_ELEMENT = "assembly";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
int IdealGraphPrinter::_file_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
IdealGraphPrinter *IdealGraphPrinter::printer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  if (PrintIdealGraphLevel == 0) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  JavaThread *thread = JavaThread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  if (!thread->is_Compiler_thread()) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  CompilerThread *compiler_thread = (CompilerThread *)thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  if (compiler_thread->ideal_graph_printer() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    IdealGraphPrinter *printer = new IdealGraphPrinter();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    compiler_thread->set_ideal_graph_printer(printer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  return compiler_thread->ideal_graph_printer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
void IdealGraphPrinter::clean_up() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  JavaThread *p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  for (p = Threads::first(); p; p = p->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    if (p->is_Compiler_thread()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
      CompilerThread *c = (CompilerThread *)p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      IdealGraphPrinter *printer = c->ideal_graph_printer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      if (printer) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
        delete printer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      c->set_ideal_graph_printer(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
// Constructor, either file or network output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
IdealGraphPrinter::IdealGraphPrinter() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  _traverse_outs = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  _should_send_method = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  _output = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  buffer[0] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  _depth = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  _current_method = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  assert(!_current_method, "current method must be initialized to NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  _arena = new Arena();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  _stream = new (ResourceObj::C_HEAP) networkStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  if (PrintIdealGraphFile != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    ThreadCritical tc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    // User wants all output to go to files
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    if (_file_count != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      stringStream st;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      const char* dot = strrchr(PrintIdealGraphFile, '.');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      if (dot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
        st.write(PrintIdealGraphFile, dot - PrintIdealGraphFile);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
        st.print("%d%s", _file_count, dot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
        st.print("%s%d", PrintIdealGraphFile, _file_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      _output = new (ResourceObj::C_HEAP) fileStream(st.as_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      _output = new (ResourceObj::C_HEAP) fileStream(PrintIdealGraphFile);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    _file_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    // Try to connect to visualizer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    if (_stream->connect(PrintIdealGraphAddress, PrintIdealGraphPort)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      char c = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      _stream->read(&c, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      if (c != 'y') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
        tty->print_cr("Client available, but does not want to receive data!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
        _stream->close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
        delete _stream;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
        _stream = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      _output = _stream;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      // It would be nice if we could shut down cleanly but it should
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      // be an error if we can't connect to the visualizer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      fatal2("Couldn't connect to visualizer at %s:%d", PrintIdealGraphAddress, PrintIdealGraphPort);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  start_element(TOP_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
// Destructor, close file or network stream
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
IdealGraphPrinter::~IdealGraphPrinter() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  end_element(TOP_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  if (_stream) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    delete _stream;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    if (_stream == _output) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
      _output = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    _stream = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  if (_output) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    delete _output;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    _output = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
void IdealGraphPrinter::print_ifg(PhaseIFG* ifg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  // Code to print an interference graph to tty, currently not used
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  if (!_current_method) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
   // Remove neighbor colors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  for (uint i = 0; i < ifg._maxlrg; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    IndexSet *s = ifg.neighbors(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    IndexSetIterator elements(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    uint neighbor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    while ((neighbor = elements.next()) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
        tty->print_cr("Edge between %d and %d\n", i, neighbor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  for (uint i = 0; i < ifg._maxlrg; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    LRG &l = ifg.lrgs(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    if (l._def) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
      OptoReg::Name name = l.reg();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
      tty->print("OptoReg::dump: ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
      OptoReg::dump(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
      tty->print_cr("");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      tty->print_cr("name=%d\n", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      if (name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
        if (OptoReg::is_stack(name)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
          tty->print_cr("Stack number %d\n", OptoReg::reg2stack(name));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
        } else if (!OptoReg::is_valid(name)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
          tty->print_cr("BAD!!!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
          if (OptoReg::is_reg(name)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
          tty->print_cr(OptoReg::regname(name));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
            int x = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
        int x = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
      if (l._def == NodeSentinel) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
        tty->print("multiple mapping from %d: ", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
        for (int j=0; j<l._defs->length(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
          tty->print("%d ", l._defs->at(j)->_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
        tty->print_cr("");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
        tty->print_cr("mapping between %d and %d\n", i, l._def->_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  }*/
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
void IdealGraphPrinter::print_method(ciMethod *method, int bci, InlineTree *tree) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  Properties properties;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  stringStream str;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  method->print_name(&str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  stringStream shortStr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  method->print_short_name(&shortStr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  properties.add(new Property(METHOD_NAME_PROPERTY, str.as_string()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  properties.add(new Property(METHOD_SHORT_NAME_PROPERTY, shortStr.as_string()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  properties.add(new Property(METHOD_BCI_PROPERTY, bci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  start_element(METHOD_ELEMENT, &properties);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  start_element(BYTECODES_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  output()->print_cr("<![CDATA[");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  method->print_codes_on(output());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  output()->print_cr("]]>");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  end_element(BYTECODES_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  start_element(INLINE_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  if (tree != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    GrowableArray<InlineTree *> subtrees = tree->subtrees();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    for (int i = 0; i < subtrees.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
      print_inline_tree(subtrees.at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  end_element(INLINE_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  end_element(METHOD_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  output()->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
void IdealGraphPrinter::print_inline_tree(InlineTree *tree) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  if (tree == NULL) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  ciMethod *method = tree->method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  print_method(tree->method(), tree->caller_bci(), tree);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
void IdealGraphPrinter::clear_nodes() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
 // for (int i = 0; i < _nodes.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
 //   _nodes.at(i)->clear_node();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
 // }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
void IdealGraphPrinter::print_inlining(Compile* compile) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  // Print inline tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  if (_should_send_method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    InlineTree *inlineTree = compile->ilt();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    if (inlineTree != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
      print_inline_tree(inlineTree);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
      // print this method only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
// Has to be called whenever a method is compiled
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
void IdealGraphPrinter::begin_method(Compile* compile) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  ciMethod *method = compile->method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  assert(_output, "output stream must exist!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  assert(method, "null methods are not allowed!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  assert(!_current_method, "current method must be null!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  _arena->destruct_contents();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  start_element(GROUP_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  // Print properties
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  Properties properties;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  // Add method name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  stringStream strStream;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  method->print_name(&strStream);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  properties.add(new Property(METHOD_NAME_PROPERTY, strStream.as_string()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  if (method->flags().is_public()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    properties.add(new Property(METHOD_IS_PUBLIC_PROPERTY, TRUE_VALUE));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  if (method->flags().is_static()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    properties.add(new Property(METHOD_IS_STATIC_PROPERTY, TRUE_VALUE));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  properties.print(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  if (_stream) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    char answer = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    _stream->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    int result = _stream->read(&answer, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
    _should_send_method = (answer == 'y');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  this->_nodes = GrowableArray<NodeDescription *>(_arena, 2, 0, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  this->_edges = GrowableArray< EdgeDescription * >(_arena, 2, 0, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  this->_current_method = method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  _output->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
// Has to be called whenever a method has finished compilation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
void IdealGraphPrinter::end_method() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
//  if (finish && !in_method) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  nmethod* method = (nmethod*)this->_current_method->code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  start_element(ASSEMBLY_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
 // Disassembler::decode(method, _output);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  end_element(ASSEMBLY_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  end_element(GROUP_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  _current_method = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  _output->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  for (int i = 0; i < _nodes.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    NodeDescription *desc = _nodes.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    if (desc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
      delete desc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
      _nodes.at_put(i, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  this->_nodes.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  for (int i = 0; i < _edges.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
   // for (int j=0; j<_edges.at(i)->length(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
      EdgeDescription *conn = _edges.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
      conn->print(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
      if (conn) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
        delete conn;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
        _edges.at_put(i, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
    //}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    //_edges.at(i)->clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    //delete _edges.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    //_edges.at_put(i, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  this->_edges.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
//  in_method = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
// Outputs an XML start element
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
void IdealGraphPrinter::start_element(const char *s, Properties *properties /* = NULL */, bool print_indent /* = false */, bool print_return /* = true */) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  start_element_helper(s, properties, false, print_indent, print_return);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  _depth++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
// Outputs an XML start element without body
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
void IdealGraphPrinter::simple_element(const char *s, Properties *properties /* = NULL */, bool print_indent /* = false */) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  start_element_helper(s, properties, true, print_indent, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
// Outputs an XML start element. If outputEnd is true, the element has no body.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
void IdealGraphPrinter::start_element_helper(const char *s, Properties *properties, bool outputEnd, bool print_indent /* = false */, bool print_return /* = true */) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  assert(_output, "output stream must exist!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  if (print_indent) this->print_indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  _output->print("<");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  _output->print(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  if (properties) properties->print_as_attributes(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  if (outputEnd) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
    _output->print("/");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  _output->print(">");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  if (print_return) _output->print_cr("");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
// Print indent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
void IdealGraphPrinter::print_indent() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  for (int i = 0; i < _depth; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    _output->print(INDENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
// Outputs an XML end element
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
void IdealGraphPrinter::end_element(const char *s, bool print_indent /* = true */, bool print_return /* = true */) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  assert(_output, "output stream must exist!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  _depth--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  if (print_indent) this->print_indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  _output->print("</");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  _output->print(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  _output->print(">");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  if (print_return) _output->print_cr("");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
bool IdealGraphPrinter::traverse_outs() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  return _traverse_outs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
void IdealGraphPrinter::set_traverse_outs(bool b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  _traverse_outs = b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
void IdealGraphPrinter::walk(Node *start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  VectorSet visited(Thread::current()->resource_area());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  GrowableArray<Node *> nodeStack(Thread::current()->resource_area(), 0, 0, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  nodeStack.push(start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  visited.test_set(start->_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  while(nodeStack.length() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    Node *n = nodeStack.pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
    IdealGraphPrinter::pre_node(n, this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
    if (_traverse_outs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
      for (DUIterator i = n->outs(); n->has_out(i); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
        Node* p = n->out(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
        if (!visited.test_set(p->_idx)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
          nodeStack.push(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    for ( uint i = 0; i < n->len(); i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
      if ( n->in(i) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
        if (!visited.test_set(n->in(i)->_idx)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
          nodeStack.push(n->in(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
void IdealGraphPrinter::compress(int index, GrowableArray<Block>* blocks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  Block *block = blocks->adr_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  int ancestor = block->ancestor();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  assert(ancestor != -1, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  Block *ancestor_block = blocks->adr_at(ancestor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  if (ancestor_block->ancestor() != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
    compress(ancestor, blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    int label = block->label();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    Block *label_block = blocks->adr_at(label);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    int ancestor_label = ancestor_block->label();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
    Block *ancestor_label_block = blocks->adr_at(label);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
    if (ancestor_label_block->semi() < label_block->semi()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
      block->set_label(ancestor_label);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    block->set_ancestor(ancestor_block->ancestor());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
int IdealGraphPrinter::eval(int index, GrowableArray<Block>* blocks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  Block *block = blocks->adr_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  if (block->ancestor() == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    return index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    compress(index, blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
    return block->label();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
void IdealGraphPrinter::link(int index1, int index2, GrowableArray<Block>* blocks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
  Block *block2 = blocks->adr_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
  block2->set_ancestor(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
void IdealGraphPrinter::build_dominators(GrowableArray<Block>* blocks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  if (blocks->length() == 0) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  GrowableArray<int> stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  stack.append(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  GrowableArray<Block *> array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  assert(blocks->length() > 0, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  blocks->adr_at(0)->set_dominator(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
  int n = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  while(!stack.is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
    int index = stack.pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
    Block *block = blocks->adr_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
    block->set_semi(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    array.append(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
    n = n + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
    for (int i = 0; i < block->succs()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
      int succ_index = block->succs()->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
      Block *succ = blocks->adr_at(succ_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
      if (succ->semi() == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
        succ->set_parent(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
        stack.push(succ_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
      succ->add_pred(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  for (int i=n-1; i>0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
    Block *block = array.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
    int block_index = block->index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
    for (int j=0; j<block->pred()->length(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
      int pred_index = block->pred()->at(j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
      int cur_index = eval(pred_index, blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
      Block *cur_block = blocks->adr_at(cur_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
      if (cur_block->semi() < block->semi()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
        block->set_semi(cur_block->semi());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
    int semi_index = block->semi();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
    Block *semi_block = array.at(semi_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    semi_block->add_to_bucket(block_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
    link(block->parent(), block_index, blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
    Block *parent_block = blocks->adr_at(block->parent());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
    for (int j=0; j<parent_block->bucket()->length(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
      int cur_index = parent_block->bucket()->at(j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
      int new_index = eval(cur_index, blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
      Block *cur_block = blocks->adr_at(cur_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
      Block *new_block = blocks->adr_at(new_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
      int dom = block->parent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
      if (new_block->semi() < cur_block->semi()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
        dom = new_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
      cur_block->set_dominator(dom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
    parent_block->clear_bucket();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  for (int i=1; i < n; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
    Block *block = array.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
    int block_index = block->index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
    int semi_index = block->semi();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
    Block *semi_block = array.at(semi_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
    if (block->dominator() != semi_block->index()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
      int new_dom = blocks->adr_at(block->dominator())->dominator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
      block->set_dominator(new_dom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
  for (int i = 0; i < blocks->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
    if (blocks->adr_at(i)->dominator() == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
      blocks->adr_at(i)->set_dominator(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  // Build dominates array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
  for (int i=1; i < blocks->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
    Block *block = blocks->adr_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
    int dominator = block->dominator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
    Block *dom_block = blocks->adr_at(dominator);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
    dom_block->add_dominates(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
    dom_block->add_child(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
    while(dominator != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
      dominator = dom_block->dominator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
      dom_block = blocks->adr_at(dominator);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
      dom_block->add_child(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
void IdealGraphPrinter::build_common_dominator(int **common_dominator, int index, GrowableArray<Block>* blocks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
  common_dominator[index][index] = index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
  Block *block = blocks->adr_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
  for (int i = 0; i < block->dominates()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
    Block *dominated = blocks->adr_at(block->dominates()->at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
    for (int j=0; j<dominated->children()->length(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
      Block *child = blocks->adr_at(dominated->children()->at(j));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
      common_dominator[index][child->index()] = common_dominator[child->index()][index] = index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
      for (int k=0; k<i; k++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
        Block *other_dominated = blocks->adr_at(block->dominates()->at(k));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
        common_dominator[child->index()][other_dominated->index()] = common_dominator[other_dominated->index()][child->index()] = index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
        for (int l=0 ; l<other_dominated->children()->length(); l++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
          Block *other_child = blocks->adr_at(other_dominated->children()->at(l));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
          common_dominator[child->index()][other_child->index()] = common_dominator[other_child->index()][child->index()] = index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
    build_common_dominator(common_dominator, dominated->index(), blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
void IdealGraphPrinter::schedule_latest(int **common_dominator, GrowableArray<Block>* blocks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
  int queue_size = _nodes.length() + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  NodeDescription **queue = NEW_RESOURCE_ARRAY(NodeDescription *, queue_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
  int queue_start = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
  int queue_end = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
  Arena *a = new Arena();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  VectorSet on_queue(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  for (int i = 0; i < _nodes.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
    NodeDescription *desc = _nodes.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
    if (desc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
      desc->init_succs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
  for (int i = 0; i < _nodes.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
    NodeDescription *desc = _nodes.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
    if (desc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
      for (uint j=0; j<desc->node()->len(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
        Node *n = desc->node()->in(j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
        if (n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
          NodeDescription *other_desc = _nodes.at(n->_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
          other_desc->add_succ(desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
  for (int i = 0; i < _nodes.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
    NodeDescription *desc = _nodes.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
    if (desc && desc->block_index() == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
      // Put Phi into same block as region
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
      if (desc->node()->is_Phi() && desc->node()->in(0) && _nodes.at(desc->node()->in(0)->_idx)->block_index() != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
        int index = _nodes.at(desc->node()->in(0)->_idx)->block_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
        desc->set_block_index(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
        blocks->adr_at(index)->add_node(desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
      // Put Projections to same block as parent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
      } else if (desc->node()->is_block_proj() && _nodes.at(desc->node()->is_block_proj()->_idx)->block_index() != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
        int index = _nodes.at(desc->node()->is_block_proj()->_idx)->block_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
        desc->set_block_index(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
        blocks->adr_at(index)->add_node(desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
        queue[queue_end] = desc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
        queue_end++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
        on_queue.set(desc->node()->_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  int z = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
  while(queue_start != queue_end && z < 10000) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
    NodeDescription *desc = queue[queue_start];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
    queue_start = (queue_start + 1) % queue_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
    on_queue >>= desc->node()->_idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
    Node* node = desc->node();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
    if (desc->succs()->length() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
      int x = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
    int block_index = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
    if (desc->succs()->length() != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
      for (int i = 0; i < desc->succs()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
          NodeDescription *cur_desc = desc->succs()->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
          if (cur_desc != desc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
            if (cur_desc->succs()->length() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
              // Ignore nodes with 0 successors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
            } else if (cur_desc->block_index() == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
              // Let this node schedule first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
              block_index = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
              break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
            } else if (cur_desc->node()->is_Phi()){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
              // Special treatment for Phi functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
              PhiNode *phi = cur_desc->node()->as_Phi();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
              assert(phi->in(0) && phi->in(0)->is_Region(), "Must have region node in first input");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
              RegionNode *region = phi->in(0)->as_Region();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
              for (uint j=1; j<phi->len(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
                Node *cur_phi_input = phi->in(j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
                if (cur_phi_input == desc->node() && region->in(j)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
                  NodeDescription *cur_region_input = _nodes.at(region->in(j)->_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
                  if (cur_region_input->block_index() == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
                    // Let this node schedule first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
                    block_index = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
                    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
                  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
                    if (block_index == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
                      block_index = cur_region_input->block_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
                    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
                      block_index = common_dominator[block_index][cur_region_input->block_index()];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
                  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
              if (block_index == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
                block_index = cur_desc->block_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
              } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
                block_index = common_dominator[block_index][cur_desc->block_index()];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
    if (block_index == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
      queue[queue_end] = desc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
      queue_end = (queue_end + 1) % queue_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
      on_queue.set(desc->node()->_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
      z++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
      assert(desc->block_index() == -1, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
      desc->set_block_index(block_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
      blocks->adr_at(block_index)->add_node(desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
      z = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
  for (int i = 0; i < _nodes.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
    NodeDescription *desc = _nodes.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
    if (desc && desc->block_index() == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
      //if (desc->node()->is_Proj() || desc->node()->is_Con()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
        Node *parent = desc->node()->in(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
        uint cur = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
        while(!parent && cur < desc->node()->len()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
          parent = desc->node()->in(cur);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
          cur++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
        if (parent && _nodes.at(parent->_idx)->block_index() != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
          int index = _nodes.at(parent->_idx)->block_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
          desc->set_block_index(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
          blocks->adr_at(index)->add_node(desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
          desc->set_block_index(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
          blocks->adr_at(0)->add_node(desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
          //ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
      //}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
      /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
      if (desc->node()->is_block_proj() && _nodes.at(desc->node()->is_block_proj()->_idx)->block_index() != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
        int index = _nodes.at(desc->node()->is_block_proj()->_idx)->block_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
        desc->set_block_index(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
        blocks->adr_at(index)->add_node(desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
      } */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
  for (int i = 0; i < _nodes.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
    NodeDescription *desc = _nodes.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
    if (desc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
      desc->clear_succs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
  for (int i = 0; i < _nodes.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
    NodeDescription *desc = _nodes.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
    if (desc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
      int block_index = desc->block_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
      assert(block_index >= 0 && block_index < blocks->length(), "Block index must be in range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
      assert(blocks->adr_at(block_index)->nodes()->contains(desc), "Node must be child of block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
  a->destruct_contents();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
void IdealGraphPrinter::build_blocks(Node *root) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
  Arena *a = new Arena();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
  Node_Stack stack(a, 100);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
  VectorSet visited(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
  stack.push(root, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
  GrowableArray<Block> blocks(a, 2, 0, Block(0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
  for (int i = 0; i < _nodes.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
    if (_nodes.at(i)) _nodes.at(i)->set_block_index(-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
  // Order nodes such that node index is equal to idx
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
  for (int i = 0; i < _nodes.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
    if (_nodes.at(i)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
      NodeDescription *node = _nodes.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
      int index = node->node()->_idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
      if (index != i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
        _nodes.at_grow(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
        NodeDescription *tmp = _nodes.at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
        *(_nodes.adr_at(index)) = node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
        *(_nodes.adr_at(i)) = tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
        i--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
  for (int i = 0; i < _nodes.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
    NodeDescription *node = _nodes.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
    if (node) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
      assert(node->node()->_idx == (uint)i, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
  while(stack.is_nonempty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
    //Node *n = stack.node();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
    //int index = stack.index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
    Node *proj = stack.node();//n->in(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
    const Node *parent = proj->is_block_proj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
    if (parent == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
      parent = proj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
    if (!visited.test_set(parent->_idx)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
      NodeDescription *end_desc = _nodes.at(parent->_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
      int block_index = blocks.length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
      Block block(block_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
      blocks.append(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
      Block *b = blocks.adr_at(block_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
      b->set_start(end_desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
     // assert(end_desc->block_index() == -1, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
      end_desc->set_block_index(block_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
      b->add_node(end_desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
      // Skip any control-pinned middle'in stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
      Node *p = proj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
      NodeDescription *start_desc = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
      do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
        proj = p;                   // Update pointer to last Control
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
        if (p->in(0) == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
          start_desc = end_desc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
        p = p->in(0);               // Move control forward
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
        start_desc = _nodes.at(p->_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
        assert(start_desc, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
        if (start_desc != end_desc && start_desc->block_index() == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
          assert(start_desc->block_index() == -1, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
          assert(block_index < blocks.length(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
          start_desc->set_block_index(block_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
          b->add_node(start_desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
     } while( !p->is_block_proj() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
               !p->is_block_start() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
      for (uint i = 0; i < start_desc->node()->len(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
          Node *pred_node = start_desc->node()->in(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
          if (pred_node && pred_node != start_desc->node()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
            const Node *cur_parent = pred_node->is_block_proj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
            if (cur_parent != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
              pred_node = (Node *)cur_parent;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
            NodeDescription *pred_node_desc = _nodes.at(pred_node->_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
            if (pred_node_desc->block_index() != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
              blocks.adr_at(pred_node_desc->block_index())->add_succ(block_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
      for (DUIterator_Fast dmax, i = end_desc->node()->fast_outs(dmax); i < dmax; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
        Node* cur_succ = end_desc->node()->fast_out(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
        NodeDescription *cur_succ_desc = _nodes.at(cur_succ->_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
        DUIterator_Fast dmax2, i2 = cur_succ->fast_outs(dmax2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
        if (cur_succ->is_block_proj() && i2 < dmax2 && !cur_succ->is_Root()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
          for (; i2<dmax2; i2++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
            Node *cur_succ2 = cur_succ->fast_out(i2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
            if (cur_succ2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
              cur_succ_desc = _nodes.at(cur_succ2->_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
              if (cur_succ_desc == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
                // dead node so skip it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
                continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
              if (cur_succ2 != end_desc->node() && cur_succ_desc->block_index() != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
                b->add_succ(cur_succ_desc->block_index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
          if (cur_succ != end_desc->node() && cur_succ_desc && cur_succ_desc->block_index() != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
            b->add_succ(cur_succ_desc->block_index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
      int num_preds = p->len();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
      int bottom = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
      if (p->is_Region() || p->is_Phi()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
        bottom = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
      int pushed = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
      for (int i=num_preds - 1; i > bottom; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
        if (p->in(i) != NULL && p->in(i) != p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
          stack.push(p->in(i), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
          pushed++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
      if (pushed == 0 && p->is_Root() && !_matcher) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
        // Special case when backedges to root are not yet built
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
        for (int i = 0; i < _nodes.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
          if (_nodes.at(i) && _nodes.at(i)->node()->is_SafePoint() && _nodes.at(i)->node()->outcnt() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
            stack.push(_nodes.at(i)->node(), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
      stack.pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
  build_dominators(&blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  int **common_dominator = NEW_RESOURCE_ARRAY(int *, blocks.length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
  for (int i = 0; i < blocks.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
    int *cur = NEW_RESOURCE_ARRAY(int, blocks.length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
    common_dominator[i] = cur;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
    for (int j=0; j<blocks.length(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
      cur[j] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
  for (int i = 0; i < blocks.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
    blocks.adr_at(i)->add_child(blocks.adr_at(i)->index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
  build_common_dominator(common_dominator, 0, &blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
  schedule_latest(common_dominator, &blocks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
  start_element(CONTROL_FLOW_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
  for (int i = 0; i < blocks.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
    Block *block = blocks.adr_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
    Properties props;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
    props.add(new Property(BLOCK_NAME_PROPERTY, i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
    props.add(new Property(BLOCK_DOMINATOR_PROPERTY, block->dominator()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
    start_element(BLOCK_ELEMENT, &props);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
    if (block->succs()->length() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
      start_element(SUCCESSORS_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
      for (int j=0; j<block->succs()->length(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
        int cur_index = block->succs()->at(j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
        if (cur_index != 0 /* start_block has must not have inputs */) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
          Properties properties;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
          properties.add(new Property(BLOCK_NAME_PROPERTY, cur_index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
          simple_element(SUCCESSOR_ELEMENT, &properties);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
      end_element(SUCCESSORS_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
    start_element(NODES_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
    for (int j=0; j<block->nodes()->length(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
      NodeDescription *n = block->nodes()->at(j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
      Properties properties;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
      properties.add(new Property(NODE_ID_PROPERTY, n->id()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
      simple_element(NODE_ELEMENT, &properties);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
    end_element(NODES_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
    end_element(BLOCK_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
  end_element(CONTROL_FLOW_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
  a->destruct_contents();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
void IdealGraphPrinter::print_method(Compile* compile, const char *name, int level, bool clear_nodes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
  print(compile, name, (Node *)compile->root(), level, clear_nodes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
// Print current ideal graph
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
void IdealGraphPrinter::print(Compile* compile, const char *name, Node *node, int level, bool clear_nodes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
//  if (finish && !in_method) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
  if (!_current_method || !_should_send_method || level > PrintIdealGraphLevel) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
  assert(_current_method, "newMethod has to be called first!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
  if (clear_nodes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
    int x = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
  _clear_nodes = clear_nodes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
  // Warning, unsafe cast?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
  _chaitin = (PhaseChaitin *)compile->regalloc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
  _matcher = compile->matcher();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
  // Update nodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
  for (int i = 0; i < _nodes.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
    NodeDescription *desc = _nodes.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
    if (desc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
      desc->set_state(Invalid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
  Node *n = node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
  walk(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
  // Update edges
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
  for (int i = 0; i < _edges.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
      _edges.at(i)->set_state(Invalid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
  for (int i = 0; i < _nodes.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
    NodeDescription *desc = _nodes.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
    if (desc && desc->state() != Invalid) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
      int to = desc->id();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
      uint len = desc->node()->len();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
      for (uint j=0; j<len; j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
        Node *n = desc->node()->in(j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
        if (n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
          intptr_t from = (intptr_t)n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
          // Assert from node is valid
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
          /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
          bool ok = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
          for (int k=0; k<_nodes.length(); k++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
            NodeDescription *desc = _nodes.at(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
            if (desc && desc->id() == from) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
              assert(desc->state() != Invalid, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
              ok = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
          assert(ok, "");*/
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
          uint index = j;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
          if (index >= desc->node()->req()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
            index = desc->node()->req();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
          print_edge(from, to, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
  bool is_different = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
  for (int i = 0; i < _nodes.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
    NodeDescription *desc = _nodes.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
    if (desc && desc->state() != Valid) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
      is_different = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
  if (!is_different) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
    for (int i = 0; i < _edges.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
      EdgeDescription *conn = _edges.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
      if (conn && conn->state() != Valid) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
        is_different = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
  // No changes -> do not print graph
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
  if (!is_different) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
  Properties properties;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
  properties.add(new Property(GRAPH_NAME_PROPERTY, (const char *)name));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
  start_element(GRAPH_ELEMENT, &properties);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
  start_element(NODES_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
  for (int i = 0; i < _nodes.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
    NodeDescription *desc = _nodes.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
    if (desc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
      desc->print(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
      if (desc->state() == Invalid) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
        delete desc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
        _nodes.at_put(i, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
        desc->set_state(Valid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
  end_element(NODES_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
  build_blocks(node);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
  start_element(EDGES_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
  for (int i = 0; i < _edges.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
    EdgeDescription *conn = _edges.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
    // Assert from and to nodes are valid
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
    /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
    if (!conn->state() == Invalid) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
      bool ok1 = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
      bool ok2 = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
      for (int j=0; j<_nodes.length(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
        NodeDescription *desc = _nodes.at(j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
        if (desc && desc->id() == conn->from()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
          ok1 = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
        if (desc && desc->id() == conn->to()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
          ok2 = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
      assert(ok1, "from node not found!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
      assert(ok2, "to node not found!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
    }*/
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
    conn->print(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
    if (conn->state() == Invalid) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
      _edges.remove_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
      delete conn;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
      i--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
  end_element(EDGES_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
  end_element(GRAPH_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
  _output->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
// Print edge
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
void IdealGraphPrinter::print_edge(int from, int to, int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
  EdgeDescription *conn = new EdgeDescription(from, to, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
  for (int i = 0; i < _edges.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
    if (_edges.at(i)->equals(conn)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
      conn->set_state(Valid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
      delete _edges.at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
      _edges.at_put(i, conn);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
  _edges.append(conn);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
extern const char *NodeClassNames[];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
// Create node description
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
IdealGraphPrinter::NodeDescription *IdealGraphPrinter::create_node_description(Node* node) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
  node->_in_dump_cnt++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
  NodeDescription *desc = new NodeDescription(node);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
  desc->properties()->add(new Property(NODE_NAME_PROPERTY, (const char *)node->Name()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
  const Type *t = node->bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
  desc->properties()->add(new Property("type", (const char *)Type::msg[t->base()]));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
  desc->properties()->add(new Property("idx", node->_idx));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
  desc->properties()->add(new Property("debug_idx", node->_debug_idx));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
  const jushort flags = node->flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
  if (flags & Node::Flag_is_Copy) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
    desc->properties()->add(new Property("is_copy", "true"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
  if (flags & Node::Flag_is_Call) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
    desc->properties()->add(new Property("is_call", "true"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
  if (flags & Node::Flag_rematerialize) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
    desc->properties()->add(new Property("rematerialize", "true"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
  if (flags & Node::Flag_needs_anti_dependence_check) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
    desc->properties()->add(new Property("needs_anti_dependence_check", "true"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
  if (flags & Node::Flag_is_macro) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
    desc->properties()->add(new Property("is_macro", "true"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
  if (flags & Node::Flag_is_Con) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
    desc->properties()->add(new Property("is_con", "true"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
  if (flags & Node::Flag_is_cisc_alternate) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
    desc->properties()->add(new Property("is_cisc_alternate", "true"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
  if (flags & Node::Flag_is_Branch) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
    desc->properties()->add(new Property("is_branch", "true"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
  if (flags & Node::Flag_is_block_start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
    desc->properties()->add(new Property("is_block_start", "true"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
  if (flags & Node::Flag_is_Goto) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
    desc->properties()->add(new Property("is_goto", "true"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
  if (flags & Node::Flag_is_dead_loop_safe) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
    desc->properties()->add(new Property("is_dead_loop_safe", "true"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
  if (flags & Node::Flag_may_be_short_branch) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
    desc->properties()->add(new Property("may_be_short_branch", "true"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
  if (flags & Node::Flag_is_safepoint_node) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
    desc->properties()->add(new Property("is_safepoint_node", "true"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
  if (flags & Node::Flag_is_pc_relative) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
    desc->properties()->add(new Property("is_pc_relative", "true"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
  if (_matcher) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
    if (_matcher->is_shared(desc->node())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
      desc->properties()->add(new Property("is_shared", "true"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
      desc->properties()->add(new Property("is_shared", "false"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
    if (_matcher->is_dontcare(desc->node())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
      desc->properties()->add(new Property("is_dontcare", "true"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
      desc->properties()->add(new Property("is_dontcare", "false"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
  if (node->is_Proj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
    desc->properties()->add(new Property("con", (int)node->as_Proj()->_con));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
  if (node->is_Mach()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
    desc->properties()->add(new Property("idealOpcode", (const char *)NodeClassNames[node->as_Mach()->ideal_Opcode()]));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
  outputStream *oldTty = tty;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
  buffer[0] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
  stringStream s2(buffer, sizeof(buffer) - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
  node->dump_spec(&s2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
  assert(s2.size() < sizeof(buffer), "size in range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
  desc->properties()->add(new Property("dump_spec", buffer));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
  if (node->is_block_proj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
    desc->properties()->add(new Property("is_block_proj", "true"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
  if (node->is_block_start()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
    desc->properties()->add(new Property("is_block_start", "true"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
  const char *short_name = "short_name";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
  if (strcmp(node->Name(), "Parm") == 0 && node->as_Proj()->_con >= TypeFunc::Parms) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
      int index = node->as_Proj()->_con - TypeFunc::Parms;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
      if (index >= 10) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
        desc->properties()->add(new Property(short_name, "PA"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
        sprintf(buffer, "P%d", index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
        desc->properties()->add(new Property(short_name, buffer));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
  } else if (strcmp(node->Name(), "IfTrue") == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
     desc->properties()->add(new Property(short_name, "T"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
  } else if (strcmp(node->Name(), "IfFalse") == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
     desc->properties()->add(new Property(short_name, "F"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
  } else if ((node->is_Con() && node->is_Type()) || node->is_Proj()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
    if (t->base() == Type::Int && t->is_int()->is_con()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
      const TypeInt *typeInt = t->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
      assert(typeInt->is_con(), "must be constant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
      jint value = typeInt->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
      // max. 2 chars allowed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
      if (value >= -9 && value <= 99) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
        sprintf(buffer, "%d", value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
        desc->properties()->add(new Property(short_name, buffer));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
      else
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
        desc->properties()->add(new Property(short_name, "I"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
    } else if (t == Type::TOP) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
      desc->properties()->add(new Property(short_name, "^"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
    } else if (t->base() == Type::Long && t->is_long()->is_con()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
      const TypeLong *typeLong = t->is_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
      assert(typeLong->is_con(), "must be constant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
      jlong value = typeLong->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
      // max. 2 chars allowed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
      if (value >= -9 && value <= 99) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
        sprintf(buffer, "%d", value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
        desc->properties()->add(new Property(short_name, buffer));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
      else
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
        desc->properties()->add(new Property(short_name, "L"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
    } else if (t->base() == Type::KlassPtr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
      const TypeKlassPtr *typeKlass = t->is_klassptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
      desc->properties()->add(new Property(short_name, "CP"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
    } else if (t->base() == Type::Control) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
      desc->properties()->add(new Property(short_name, "C"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
    } else if (t->base() == Type::Memory) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
      desc->properties()->add(new Property(short_name, "M"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
    } else if (t->base() == Type::Abio) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
      desc->properties()->add(new Property(short_name, "IO"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
    } else if (t->base() == Type::Return_Address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
      desc->properties()->add(new Property(short_name, "RA"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
    } else if (t->base() == Type::AnyPtr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
      desc->properties()->add(new Property(short_name, "P"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
    } else if (t->base() == Type::RawPtr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
      desc->properties()->add(new Property(short_name, "RP"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
    } else if (t->base() == Type::AryPtr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
      desc->properties()->add(new Property(short_name, "AP"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
  if (node->is_SafePoint()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
    SafePointNode *safePointNode = node->as_SafePoint();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
    if (safePointNode->jvms()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
      stringStream bciStream;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
      bciStream.print("%d ", safePointNode->jvms()->bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
      JVMState *caller = safePointNode->jvms()->caller();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
      while(caller) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
        bciStream.print("%d ", caller->bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
        caller = caller->caller();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
      desc->properties()->add(new Property("bci", bciStream.as_string()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
  if (_chaitin && _chaitin != (PhaseChaitin *)0xdeadbeef) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
    buffer[0] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
    _chaitin->dump_register(node, buffer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
    desc->properties()->add(new Property("reg", buffer));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
    desc->properties()->add(new Property("lrg", _chaitin->n2lidx(node)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
  node->_in_dump_cnt--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
  return desc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
void IdealGraphPrinter::pre_node(Node* node, void *env) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
  IdealGraphPrinter *printer = (IdealGraphPrinter *)env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
  NodeDescription *newDesc = printer->create_node_description(node);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
  if (printer->_clear_nodes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
    printer->_nodes.append(newDesc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
    NodeDescription *desc = printer->_nodes.at_grow(node->_idx, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
    if (desc && desc->equals(newDesc)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
      //desc->set_state(Valid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
      //desc->set_node(node);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
      delete desc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
      printer->_nodes.at_put(node->_idx, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
      newDesc->set_state(Valid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
      //printer->_nodes.at_put(node->_idx, newDesc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
      if (desc && desc->id() == newDesc->id()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
        delete desc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
        printer->_nodes.at_put(node->_idx, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
        newDesc->set_state(New);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
      //if (desc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
      //  delete desc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
      //}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
      //printer->_nodes.at_put(node->_idx, newDesc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
    printer->_nodes.append(newDesc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
void IdealGraphPrinter::post_node(Node* node, void *env) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
outputStream *IdealGraphPrinter::output() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
  return _output;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
IdealGraphPrinter::Description::Description() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
  _state = New;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
void IdealGraphPrinter::Description::print(IdealGraphPrinter *printer) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
  if (_state == Invalid) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
    print_removed(printer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
  } else if (_state == New) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
    print_changed(printer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
void IdealGraphPrinter::Description::set_state(State s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
  _state = s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
IdealGraphPrinter::State IdealGraphPrinter::Description::state() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
  return _state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
void IdealGraphPrinter::Block::set_proj(NodeDescription *n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
  _proj = n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
void IdealGraphPrinter::Block::set_start(NodeDescription *n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
  _start = n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
int IdealGraphPrinter::Block::semi() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
  return _semi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1496
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
int IdealGraphPrinter::Block::parent() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
  return _parent;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
GrowableArray<int>* IdealGraphPrinter::Block::bucket() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
  return &_bucket;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1504
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
GrowableArray<int>* IdealGraphPrinter::Block::children() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
  return &_children;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1507
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
void IdealGraphPrinter::Block::add_child(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
  _children.append(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1513
GrowableArray<int>* IdealGraphPrinter::Block::dominates() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1514
  return &_dominates;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
void IdealGraphPrinter::Block::add_dominates(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
  _dominates.append(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
void IdealGraphPrinter::Block::add_to_bucket(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
  _bucket.append(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1525
void IdealGraphPrinter::Block::clear_bucket() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
  _bucket.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1527
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1528
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
void IdealGraphPrinter::Block::set_dominator(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
  _dominator = i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1531
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
void IdealGraphPrinter::Block::set_label(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
  _label = i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1535
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
int IdealGraphPrinter::Block::label() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1538
  return _label;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1539
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1540
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
int IdealGraphPrinter::Block::ancestor() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1542
  return _ancestor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1543
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1544
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1545
void IdealGraphPrinter::Block::set_ancestor(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
  _ancestor = i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
int IdealGraphPrinter::Block::dominator() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
  return _dominator;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1552
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
int IdealGraphPrinter::Block::index() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
  return _index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
void IdealGraphPrinter::Block::set_parent(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
  _parent = i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
GrowableArray<int>* IdealGraphPrinter::Block::pred() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
  return &_pred;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
void IdealGraphPrinter::Block::set_semi(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
  _semi = i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
IdealGraphPrinter::Block::Block() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
IdealGraphPrinter::Block::Block(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
  _index = index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
  _label = index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
  _semi = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
  _ancestor = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
  _dominator = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
void IdealGraphPrinter::Block::add_pred(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
  _pred.append(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
IdealGraphPrinter::NodeDescription *IdealGraphPrinter::Block::proj() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
  return _proj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
IdealGraphPrinter::NodeDescription *IdealGraphPrinter::Block::start() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
  return _start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
GrowableArray<int>* IdealGraphPrinter::Block::succs() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
  return &_succs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
void IdealGraphPrinter::Block::add_succ(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
  if (this->_index == 16 && index == 15) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
    int x = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
  if (!_succs.contains(index)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
    _succs.append(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
void IdealGraphPrinter::Block::add_node(NodeDescription *n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
  if (!_nodes.contains(n)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
    _nodes.append(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
GrowableArray<IdealGraphPrinter::NodeDescription *>* IdealGraphPrinter::Block::nodes() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
  return &_nodes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
int IdealGraphPrinter::NodeDescription::count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
IdealGraphPrinter::NodeDescription::NodeDescription(Node* node) : _node(node) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
  _id = (intptr_t)(node);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
  _block_index = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1624
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
IdealGraphPrinter::NodeDescription::~NodeDescription() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
  _properties.clean();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
// void IdealGraphPrinter::NodeDescription::set_node(Node* node) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
//   //this->_node = node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
// }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
int IdealGraphPrinter::NodeDescription::block_index() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
  return _block_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1638
GrowableArray<IdealGraphPrinter::NodeDescription *>* IdealGraphPrinter::NodeDescription::succs() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
  return &_succs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
void IdealGraphPrinter::NodeDescription::clear_succs() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
  _succs.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
void IdealGraphPrinter::NodeDescription::init_succs() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
  _succs = GrowableArray<NodeDescription *>();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
void IdealGraphPrinter::NodeDescription::add_succ(NodeDescription *desc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
  _succs.append(desc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1653
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
void IdealGraphPrinter::NodeDescription::set_block_index(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
  _block_index = i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
bool IdealGraphPrinter::NodeDescription::equals(NodeDescription *desc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
  if (desc == NULL) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
  if (desc->id() != id()) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
  return properties()->equals(desc->properties());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
Node* IdealGraphPrinter::NodeDescription::node() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
  return _node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
IdealGraphPrinter::Properties* IdealGraphPrinter::NodeDescription::properties() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
  return &_properties;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1671
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1672
uint IdealGraphPrinter::NodeDescription::id() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1673
  return _id;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1674
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1675
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1676
void IdealGraphPrinter::NodeDescription::print_changed(IdealGraphPrinter *printer) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1677
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
  Properties properties;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
  properties.add(new Property(NODE_ID_PROPERTY, id()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1681
  printer->start_element(NODE_ELEMENT, &properties);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1682
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1683
  this->properties()->print(printer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1684
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1685
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1686
  printer->end_element(NODE_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1687
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1688
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1689
void IdealGraphPrinter::NodeDescription::print_removed(IdealGraphPrinter *printer) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1690
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1691
  Properties properties;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1692
  properties.add(new Property(NODE_ID_PROPERTY, id()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
  printer->simple_element(REMOVE_NODE_ELEMENT, &properties);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1696
IdealGraphPrinter::EdgeDescription::EdgeDescription(int from, int to, int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
  this->_from = from;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
  this->_to = to;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
  this->_index = index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1701
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1702
IdealGraphPrinter::EdgeDescription::~EdgeDescription() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1703
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1704
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1705
int IdealGraphPrinter::EdgeDescription::from() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
  return _from;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
int IdealGraphPrinter::EdgeDescription::to() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1710
  return _to;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1712
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1713
void IdealGraphPrinter::EdgeDescription::print_changed(IdealGraphPrinter *printer) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1714
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1715
  Properties properties;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1716
  properties.add(new Property(INDEX_PROPERTY, _index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1717
  properties.add(new Property(FROM_PROPERTY, _from));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1718
  properties.add(new Property(TO_PROPERTY, _to));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1719
  printer->simple_element(EDGE_ELEMENT, &properties);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1720
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1721
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1722
void IdealGraphPrinter::EdgeDescription::print_removed(IdealGraphPrinter *printer) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1723
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
  Properties properties;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
  properties.add(new Property(INDEX_PROPERTY, _index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1726
  properties.add(new Property(FROM_PROPERTY, _from));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
  properties.add(new Property(TO_PROPERTY, _to));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
  printer->simple_element(REMOVE_EDGE_ELEMENT, &properties);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1729
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1730
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1731
bool IdealGraphPrinter::EdgeDescription::equals(IdealGraphPrinter::EdgeDescription *desc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1732
  if (desc == NULL) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
  return (_from == desc->_from && _to == desc->_to && _index == desc->_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1734
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1735
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1736
IdealGraphPrinter::Properties::Properties() : list(new (ResourceObj::C_HEAP) GrowableArray<Property *>(2, 0, NULL, true)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1737
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1739
IdealGraphPrinter::Properties::~Properties() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
  clean();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1741
  delete list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1742
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1744
void IdealGraphPrinter::Properties::add(Property *p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1745
  assert(p != NULL, "Property not NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1746
  list->append(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1747
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1748
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1749
void IdealGraphPrinter::Properties::print(IdealGraphPrinter *printer) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
  printer->start_element(PROPERTIES_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1751
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1752
  for (int i = 0; i < list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1753
    list->at(i)->print(printer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1754
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1755
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1756
  printer->end_element(PROPERTIES_ELEMENT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1757
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1758
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1759
void IdealGraphPrinter::Properties::clean() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1760
  for (int i = 0; i < list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1761
    delete list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1762
    list->at_put(i, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1763
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1764
  list->clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1765
  assert(list->length() == 0, "List cleared");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1766
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1767
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1768
void IdealGraphPrinter::Properties::remove(const char *name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1769
  for (int i = 0; i < list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1770
    if (strcmp(list->at(i)->name(), name) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1771
      delete list->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
      list->remove_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
      i--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1774
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1775
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1776
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
void IdealGraphPrinter::Properties::print_as_attributes(IdealGraphPrinter *printer) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1780
  for (int i = 0; i < list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
    assert(list->at(i) != NULL, "Property not null!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
    printer->output()->print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
    list->at(i)->print_as_attribute(printer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1784
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1785
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1787
bool IdealGraphPrinter::Properties::equals(Properties* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1788
  if (p->list->length() != this->list->length()) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1789
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
  for (int i = 0; i < list->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
    assert(list->at(i) != NULL, "Property not null!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
    if (!list->at(i)->equals(p->list->at(i))) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1793
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1795
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
IdealGraphPrinter::Property::Property() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
  _name = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
  _value = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1801
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
const char *IdealGraphPrinter::Property::name() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1804
  return _name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1805
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1806
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1807
IdealGraphPrinter::Property::Property(const Property* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
  this->_name = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1810
  this->_value = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
  if (p->_name != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
    _name = dup(p->_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
  if (p->_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
    _value = dup(p->_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1819
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
IdealGraphPrinter::Property::~Property() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1822
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
  clean();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
IdealGraphPrinter::Property::Property(const char *name, const char *value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1827
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1828
  assert(name, "Name must not be null!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1829
  assert(value, "Value must not be null!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1830
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1831
  _name = dup(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1832
  _value = dup(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1833
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1834
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1835
IdealGraphPrinter::Property::Property(const char *name, int intValue) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1836
  _name = dup(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1837
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1838
  stringStream stream;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1839
  stream.print("%d", intValue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1840
  _value = dup(stream.as_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1841
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1842
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1843
void IdealGraphPrinter::Property::clean() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1844
  if (_name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1845
    delete _name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1846
    _name = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1847
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1848
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1849
  if (_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1850
    delete _value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1851
    _value = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1852
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1853
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1854
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1855
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1856
bool IdealGraphPrinter::Property::is_null() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1857
  return _name == NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1858
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1859
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1860
void IdealGraphPrinter::Property::print(IdealGraphPrinter *printer) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1861
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1862
  assert(!is_null(), "null properties cannot be printed!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1863
  Properties properties;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1864
  properties.add(new Property(PROPERTY_NAME_PROPERTY, _name));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1865
  printer->start_element(PROPERTY_ELEMENT, &properties, false, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1866
  printer->print_xml(_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1867
  printer->end_element(PROPERTY_ELEMENT, false, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1868
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1869
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1870
void IdealGraphPrinter::Property::print_as_attribute(IdealGraphPrinter *printer) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1871
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1872
  printer->output()->print(_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1873
  printer->output()->print("=\"");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1874
  printer->print_xml(_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1875
  printer->output()->print("\"");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1876
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1877
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1878
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1879
bool IdealGraphPrinter::Property::equals(Property* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1880
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1881
  if (is_null() && p->is_null()) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1882
  if (is_null()) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1883
  if (p->is_null()) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1884
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1885
  int cmp1 = strcmp(p->_name, _name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1886
  if (cmp1 != 0) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1887
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1888
  int cmp2 = strcmp(p->_value, _value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1889
  if (cmp2 != 0) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1890
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1891
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1892
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1893
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1894
void IdealGraphPrinter::print_xml(const char *value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1895
  size_t len = strlen(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1896
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1897
  char buf[2];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1898
  buf[1] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1899
  for (size_t i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1900
    char c = value[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1901
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1902
    switch(c) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1903
      case '<':
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1904
        output()->print("&lt;");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1905
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1906
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1907
      case '>':
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1908
        output()->print("&gt;");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1909
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1910
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1911
      default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1912
        buf[0] = c;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1913
        output()->print(buf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1914
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1915
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1916
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1917
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1918
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1919
#endif