src/hotspot/share/c1/c1_CFGPrinter.cpp
author pliden
Mon, 14 May 2018 15:42:59 +0200
changeset 50102 454fa295105c
parent 47765 b7c7428eaab9
permissions -rw-r--r--
8202976: Add C1 lea patching support for x86 Reviewed-by: kvn, neliasso
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46560
388aa8d67c80 8181449: Fix debug.hpp / globalDefinitions.hpp dependency inversion
kbarrett
parents: 46526
diff changeset
     2
 * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
1
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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6745
diff changeset
    25
#include "precompiled.hpp"
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    26
#include "jvm.h"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6745
diff changeset
    27
#include "c1/c1_CFGPrinter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6745
diff changeset
    28
#include "c1/c1_IR.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6745
diff changeset
    29
#include "c1/c1_InstructionPrinter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6745
diff changeset
    30
#include "c1/c1_LIR.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6745
diff changeset
    31
#include "c1/c1_LinearScan.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6745
diff changeset
    32
#include "c1/c1_ValueStack.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
void CFGPrinter::print_compilation(Compilation* compilation) {
46526
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    37
  CFGPrinterOutput* output = compilation->cfg_printer_output();
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    38
  output->print_compilation();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
void CFGPrinter::print_cfg(BlockList* blocks, const char* name, bool do_print_HIR, bool do_print_LIR) {
46526
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    42
  CFGPrinterOutput* output = Compilation::current()->cfg_printer_output();
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    43
  output->set_print_flags(do_print_HIR, do_print_LIR);
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    44
  output->print_cfg(blocks, name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
void CFGPrinter::print_cfg(IR* blocks, const char* name, bool do_print_HIR, bool do_print_LIR) {
46526
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    48
  CFGPrinterOutput* output = Compilation::current()->cfg_printer_output();
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    49
  output->set_print_flags(do_print_HIR, do_print_LIR);
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    50
  output->print_cfg(blocks, name);
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    51
}
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    52
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    53
void CFGPrinter::print_intervals(IntervalList* intervals, const char* name) {
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    54
  CFGPrinterOutput* output = Compilation::current()->cfg_printer_output();
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    55
  output->print_intervals(intervals, name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
46526
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    59
CFGPrinterOutput::CFGPrinterOutput(Compilation* compilation)
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    60
 : _output(NULL),
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    61
   _compilation(compilation),
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    62
   _do_print_HIR(false),
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    63
   _do_print_LIR(false)
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    64
{
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    65
  char file_name[O_BUFLEN];
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    66
  jio_snprintf(file_name, sizeof(file_name), "output_tid" UINTX_FORMAT "_pid%u.cfg",
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    67
               os::current_thread_id(), os::current_process_id());
519f1fbec7af 8181644: C1 crashes with -XX:+PrintCFGToFile
thartmann
parents: 31592
diff changeset
    68
  _output = new(ResourceObj::C_HEAP, mtCompiler) fileStream(file_name, "at");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
void CFGPrinterOutput::inc_indent() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  output()->inc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  output()->inc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
void CFGPrinterOutput::dec_indent() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  output()->dec();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  output()->dec();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
void CFGPrinterOutput::print(const char* format, ...) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  output()->indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  va_list ap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  va_start(ap, format);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  output()->vprint_cr(format, ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  va_end(ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
void CFGPrinterOutput::print_begin(const char* tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  output()->indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  output()->print_cr("begin_%s", tag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  inc_indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
void CFGPrinterOutput::print_end(const char* tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  dec_indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  output()->indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  output()->print_cr("end_%s", tag);
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
char* CFGPrinterOutput::method_name(ciMethod* method, bool short_name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  stringStream name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  if (short_name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    method->print_short_name(&name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    method->print_name(&name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  return name.as_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
}
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::print_compilation() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  print_begin("compilation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  print("name \"%s\"", method_name(_compilation->method(), true));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  print("method \"%s\"", method_name(_compilation->method()));
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 24424
diff changeset
   120
  print("date " INT64_FORMAT, (int64_t) os::javaTimeMillis());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  print_end("compilation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
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_state(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  print_begin("states");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  InstructionPrinter ip(true, output());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  ValueStack* state = block->state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  int index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  Value value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  for_each_state(state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    print_begin("locals");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    print("size %d", state->locals_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    print("method \"%s\"", method_name(state->scope()->method()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    for_each_local_value(state, index, value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      ip.print_phi(index, value, block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      print_operand(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      output()->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    print_end("locals");
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   149
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   150
    if (state->stack_size() > 0) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   151
      print_begin("stack");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   152
      print("size %d", state->stack_size());
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   153
      print("method \"%s\"", method_name(state->scope()->method()));
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   154
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   155
      for_each_stack_value(state, index, value) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   156
        ip.print_phi(index, value, block);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   157
        print_operand(value);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   158
        output()->cr();
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   159
      }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   160
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   161
      print_end("stack");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   162
    }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   163
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   164
    if (state->locks_size() > 0) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   165
      print_begin("locks");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   166
      print("size %d", state->locks_size());
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   167
      print("method \"%s\"", method_name(state->scope()->method()));
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   168
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   169
      for_each_lock_value(state, index, value) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   170
        ip.print_phi(index, value, block);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   171
        print_operand(value);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   172
        output()->cr();
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   173
      }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   174
      print_end("locks");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   175
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  print_end("states");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
void CFGPrinterOutput::print_operand(Value instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  if (instr->operand()->is_virtual()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    output()->print(" \"");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    instr->operand()->print(output());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    output()->print("\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
void CFGPrinterOutput::print_HIR(Value instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  InstructionPrinter ip(true, output());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  if (instr->is_pinned()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    output()->put('.');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  }
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   196
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   197
  output()->print("%d %d ", instr->printable_bci(), instr->use_count());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  print_operand(instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  ip.print_temp(instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  output()->print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  ip.print_instr(instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  output()->print_cr(" <|@");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
void CFGPrinterOutput::print_HIR(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  print_begin("HIR");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  Value cur = block->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  while (cur != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    print_HIR(cur);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    cur = cur->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  print_end("HIR");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
void CFGPrinterOutput::print_LIR(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  print_begin("LIR");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  for (int i = 0; i < block->lir()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    block->lir()->at(i)->print_on(output());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    output()->print_cr(" <|@ ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  print_end("LIR");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
void CFGPrinterOutput::print_block(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  print_begin("block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  print("name \"B%d\"", block->block_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  print("from_bci %d", block->bci());
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5547
diff changeset
   238
  print("to_bci %d", (block->end() == NULL ? -1 : block->end()->printable_bci()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  output()->indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  output()->print("predecessors ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  for (i = 0; i < block->number_of_preds(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    output()->print("\"B%d\" ", block->pred_at(i)->block_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  output()->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  output()->indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  output()->print("successors ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  for (i = 0; i < block->number_of_sux(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    output()->print("\"B%d\" ", block->sux_at(i)->block_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  output()->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  output()->indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  output()->print("xhandlers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  for (i = 0; i < block->number_of_exception_handlers(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    output()->print("\"B%d\" ", block->exception_handler_at(i)->block_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  output()->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  output()->indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  output()->print("flags ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  if (block->is_set(BlockBegin::std_entry_flag))                output()->print("\"std\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  if (block->is_set(BlockBegin::osr_entry_flag))                output()->print("\"osr\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  if (block->is_set(BlockBegin::exception_entry_flag))          output()->print("\"ex\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  if (block->is_set(BlockBegin::subroutine_entry_flag))         output()->print("\"sr\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  if (block->is_set(BlockBegin::backward_branch_target_flag))   output()->print("\"bb\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  if (block->is_set(BlockBegin::parser_loop_header_flag))       output()->print("\"plh\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  if (block->is_set(BlockBegin::critical_edge_split_flag))      output()->print("\"ces\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  if (block->is_set(BlockBegin::linear_scan_loop_header_flag))  output()->print("\"llh\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  if (block->is_set(BlockBegin::linear_scan_loop_end_flag))     output()->print("\"lle\" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  output()->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  if (block->dominator() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    print("dominator \"B%d\"", block->dominator()->block_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  if (block->loop_index() != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    print("loop_index %d", block->loop_index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    print("loop_depth %d", block->loop_depth());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  if (block->first_lir_instruction_id() != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    print("first_lir_id %d", block->first_lir_instruction_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    print("last_lir_id %d", block->last_lir_instruction_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  if (_do_print_HIR) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    print_state(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    print_HIR(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  if (_do_print_LIR) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    print_LIR(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  print_end("block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
void CFGPrinterOutput::print_cfg(BlockList* blocks, const char* name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  print_begin("cfg");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  print("name \"%s\"", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  PrintBlockClosure print_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  blocks->iterate_forward(&print_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  print_end("cfg");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  output()->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
void CFGPrinterOutput::print_cfg(IR* blocks, const char* name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  print_begin("cfg");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  print("name \"%s\"", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  PrintBlockClosure print_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  blocks->iterate_preorder(&print_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  print_end("cfg");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  output()->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
void CFGPrinterOutput::print_intervals(IntervalList* intervals, const char* name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  print_begin("intervals");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  print("name \"%s\"", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  for (int i = 0; i < intervals->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    if (intervals->at(i) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
      intervals->at(i)->print(output());
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
  print_end("intervals");
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
#endif