hotspot/src/share/vm/c1/c1_CFGPrinter.cpp
author xdono
Mon, 15 Dec 2008 16:55:11 -0800
changeset 1623 a0dd9009e992
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6785258: Update copyright year Summary: Update copyright for files that have been modified starting July 2008 to Dec 2008 Reviewed-by: katleman, ohair, tbell
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 2005-2006 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/_c1_CFGPrinter.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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
class CFGPrinterOutput : public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  outputStream* _output;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  Compilation*  _compilation;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  bool _do_print_HIR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  bool _do_print_LIR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  class PrintBlockClosure: public BlockClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    void block_do(BlockBegin* block) { if (block != NULL) CFGPrinter::output()->print_block(block); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  outputStream* output() { assert(_output != NULL, ""); return _output; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  void inc_indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  void dec_indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  void print(const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  void print_begin(const char* tag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  void print_end(const char* tag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  char* method_name(ciMethod* method, bool short_name = false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  CFGPrinterOutput();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  void set_compilation(Compilation* compilation) { _compilation = compilation; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  void set_print_flags(bool do_print_HIR, bool do_print_LIR) { _do_print_HIR = do_print_HIR; _do_print_LIR = do_print_LIR; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  void print_compilation();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  void print_intervals(IntervalList* intervals, const char* name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  void print_state(BlockBegin* block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  void print_operand(Value instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  void print_HIR(Value instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  void print_HIR(BlockBegin* block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  void print_LIR(BlockBegin* block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  void print_block(BlockBegin* block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  void print_cfg(BlockList* blocks, const char* name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  void print_cfg(IR* blocks, const char* name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
CFGPrinterOutput* CFGPrinter::_output = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
void CFGPrinter::print_compilation(Compilation* compilation) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  if (_output == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    _output = new CFGPrinterOutput();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  output()->set_compilation(compilation);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  output()->print_compilation();
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 CFGPrinter::print_cfg(BlockList* blocks, const char* name, bool do_print_HIR, bool do_print_LIR) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  output()->set_print_flags(do_print_HIR, do_print_LIR);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  output()->print_cfg(blocks, name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
void CFGPrinter::print_cfg(IR* blocks, const char* name, bool do_print_HIR, bool do_print_LIR) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  output()->set_print_flags(do_print_HIR, do_print_LIR);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  output()->print_cfg(blocks, name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
void CFGPrinter::print_intervals(IntervalList* intervals, const char* name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  output()->print_intervals(intervals, name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
CFGPrinterOutput::CFGPrinterOutput()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
 : _output(new(ResourceObj::C_HEAP) fileStream("output.cfg"))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
void CFGPrinterOutput::inc_indent() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  output()->inc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  output()->inc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
void CFGPrinterOutput::dec_indent() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  output()->dec();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  output()->dec();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
void CFGPrinterOutput::print(const char* format, ...) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  output()->indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  va_list ap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  va_start(ap, format);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  output()->vprint_cr(format, ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  va_end(ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
void CFGPrinterOutput::print_begin(const char* tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  output()->indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  output()->print_cr("begin_%s", tag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  inc_indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
void CFGPrinterOutput::print_end(const char* tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  dec_indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  output()->indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  output()->print_cr("end_%s", tag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
char* CFGPrinterOutput::method_name(ciMethod* method, bool short_name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  stringStream name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  if (short_name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    method->print_short_name(&name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    method->print_name(&name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  return name.as_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
void CFGPrinterOutput::print_compilation() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  print_begin("compilation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  print("name \"%s\"", method_name(_compilation->method(), true));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  print("method \"%s\"", method_name(_compilation->method()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  print("date "INT64_FORMAT, os::javaTimeMillis());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  print_end("compilation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
void CFGPrinterOutput::print_state(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  print_begin("states");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  InstructionPrinter ip(true, output());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  ValueStack* state = block->state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  int index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  Value value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  if (state->stack_size() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    print_begin("stack");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    print("size %d", state->stack_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    for_each_stack_value(state, index, value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
      ip.print_phi(index, value, block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      print_operand(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
      output()->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    print_end("stack");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  if (state->locks_size() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    print_begin("locks");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    print("size %d", state->locks_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    for_each_lock_value(state, index, value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
      ip.print_phi(index, value, block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
      print_operand(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
      output()->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    print_end("locks");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  for_each_state(state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    print_begin("locals");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    print("size %d", state->locals_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    print("method \"%s\"", method_name(state->scope()->method()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    for_each_local_value(state, index, value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
      ip.print_phi(index, value, block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
      print_operand(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
      output()->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    print_end("locals");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  print_end("states");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
void CFGPrinterOutput::print_operand(Value instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  if (instr->operand()->is_virtual()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    output()->print(" \"");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    instr->operand()->print(output());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    output()->print("\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
void CFGPrinterOutput::print_HIR(Value instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  InstructionPrinter ip(true, output());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  if (instr->is_pinned()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    output()->put('.');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  output()->print("%d %d ", instr->bci(), instr->use_count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  print_operand(instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  ip.print_temp(instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  output()->print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  ip.print_instr(instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  output()->print_cr(" <|@");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
void CFGPrinterOutput::print_HIR(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  print_begin("HIR");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  Value cur = block->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  while (cur != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    print_HIR(cur);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    cur = cur->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  print_end("HIR");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
void CFGPrinterOutput::print_LIR(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  print_begin("LIR");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  for (int i = 0; i < block->lir()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    block->lir()->at(i)->print_on(output());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    output()->print_cr(" <|@ ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  print_end("LIR");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
void CFGPrinterOutput::print_block(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  print_begin("block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  print("name \"B%d\"", block->block_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  print("from_bci %d", block->bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  print("to_bci %d", (block->end() == NULL ? -1 : block->end()->bci()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  output()->indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  output()->print("predecessors ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  for (i = 0; i < block->number_of_preds(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    output()->print("\"B%d\" ", block->pred_at(i)->block_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  output()->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  output()->indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  output()->print("successors ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  for (i = 0; i < block->number_of_sux(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    output()->print("\"B%d\" ", block->sux_at(i)->block_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  output()->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  output()->indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  output()->print("xhandlers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  for (i = 0; i < block->number_of_exception_handlers(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    output()->print("\"B%d\" ", block->exception_handler_at(i)->block_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  output()->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  output()->indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  output()->print("flags ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  if (block->is_set(BlockBegin::std_entry_flag))                output()->print("\"std\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  if (block->is_set(BlockBegin::osr_entry_flag))                output()->print("\"osr\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  if (block->is_set(BlockBegin::exception_entry_flag))          output()->print("\"ex\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  if (block->is_set(BlockBegin::subroutine_entry_flag))         output()->print("\"sr\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  if (block->is_set(BlockBegin::backward_branch_target_flag))   output()->print("\"bb\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  if (block->is_set(BlockBegin::parser_loop_header_flag))       output()->print("\"plh\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  if (block->is_set(BlockBegin::critical_edge_split_flag))      output()->print("\"ces\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  if (block->is_set(BlockBegin::linear_scan_loop_header_flag))  output()->print("\"llh\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  if (block->is_set(BlockBegin::linear_scan_loop_end_flag))     output()->print("\"lle\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  output()->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  if (block->dominator() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    print("dominator \"B%d\"", block->dominator()->block_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  if (block->loop_index() != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    print("loop_index %d", block->loop_index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    print("loop_depth %d", block->loop_depth());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  if (block->first_lir_instruction_id() != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    print("first_lir_id %d", block->first_lir_instruction_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    print("last_lir_id %d", block->last_lir_instruction_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  if (_do_print_HIR) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    print_state(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    print_HIR(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  if (_do_print_LIR) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    print_LIR(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  print_end("block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
}
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
void CFGPrinterOutput::print_cfg(BlockList* blocks, const char* name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  print_begin("cfg");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  print("name \"%s\"", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  PrintBlockClosure print_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  blocks->iterate_forward(&print_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  print_end("cfg");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  output()->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
void CFGPrinterOutput::print_cfg(IR* blocks, const char* name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  print_begin("cfg");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  print("name \"%s\"", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  PrintBlockClosure print_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  blocks->iterate_preorder(&print_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  print_end("cfg");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  output()->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
void CFGPrinterOutput::print_intervals(IntervalList* intervals, const char* name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  print_begin("intervals");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  print("name \"%s\"", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  for (int i = 0; i < intervals->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    if (intervals->at(i) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
      intervals->at(i)->print(output());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  print_end("intervals");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  output()->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
#endif