30 #include "c1/c1_LinearScan.hpp" |
30 #include "c1/c1_LinearScan.hpp" |
31 #include "c1/c1_ValueStack.hpp" |
31 #include "c1/c1_ValueStack.hpp" |
32 |
32 |
33 #ifndef PRODUCT |
33 #ifndef PRODUCT |
34 |
34 |
35 |
|
36 class CFGPrinterOutput : public CHeapObj<mtCompiler> { |
|
37 private: |
|
38 outputStream* _output; |
|
39 |
|
40 Compilation* _compilation; |
|
41 bool _do_print_HIR; |
|
42 bool _do_print_LIR; |
|
43 |
|
44 class PrintBlockClosure: public BlockClosure { |
|
45 void block_do(BlockBegin* block) { if (block != NULL) CFGPrinter::output()->print_block(block); } |
|
46 }; |
|
47 |
|
48 |
|
49 outputStream* output() { assert(_output != NULL, ""); return _output; } |
|
50 |
|
51 void inc_indent(); |
|
52 void dec_indent(); |
|
53 void print(const char* format, ...) ATTRIBUTE_PRINTF(2, 3); |
|
54 void print_begin(const char* tag); |
|
55 void print_end(const char* tag); |
|
56 |
|
57 char* method_name(ciMethod* method, bool short_name = false); |
|
58 |
|
59 public: |
|
60 CFGPrinterOutput(); |
|
61 |
|
62 void set_compilation(Compilation* compilation) { _compilation = compilation; } |
|
63 void set_print_flags(bool do_print_HIR, bool do_print_LIR) { _do_print_HIR = do_print_HIR; _do_print_LIR = do_print_LIR; } |
|
64 |
|
65 void print_compilation(); |
|
66 void print_intervals(IntervalList* intervals, const char* name); |
|
67 |
|
68 void print_state(BlockBegin* block); |
|
69 void print_operand(Value instr); |
|
70 void print_HIR(Value instr); |
|
71 void print_HIR(BlockBegin* block); |
|
72 void print_LIR(BlockBegin* block); |
|
73 void print_block(BlockBegin* block); |
|
74 void print_cfg(BlockList* blocks, const char* name); |
|
75 void print_cfg(IR* blocks, const char* name); |
|
76 }; |
|
77 |
|
78 CFGPrinterOutput* CFGPrinter::_output = NULL; |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 void CFGPrinter::print_compilation(Compilation* compilation) { |
35 void CFGPrinter::print_compilation(Compilation* compilation) { |
84 if (_output == NULL) { |
36 CFGPrinterOutput* output = compilation->cfg_printer_output(); |
85 _output = new CFGPrinterOutput(); |
37 output->print_compilation(); |
86 } |
|
87 output()->set_compilation(compilation); |
|
88 output()->print_compilation(); |
|
89 } |
38 } |
90 |
39 |
91 void CFGPrinter::print_cfg(BlockList* blocks, const char* name, bool do_print_HIR, bool do_print_LIR) { |
40 void CFGPrinter::print_cfg(BlockList* blocks, const char* name, bool do_print_HIR, bool do_print_LIR) { |
92 output()->set_print_flags(do_print_HIR, do_print_LIR); |
41 CFGPrinterOutput* output = Compilation::current()->cfg_printer_output(); |
93 output()->print_cfg(blocks, name); |
42 output->set_print_flags(do_print_HIR, do_print_LIR); |
|
43 output->print_cfg(blocks, name); |
94 } |
44 } |
95 |
45 |
96 void CFGPrinter::print_cfg(IR* blocks, const char* name, bool do_print_HIR, bool do_print_LIR) { |
46 void CFGPrinter::print_cfg(IR* blocks, const char* name, bool do_print_HIR, bool do_print_LIR) { |
97 output()->set_print_flags(do_print_HIR, do_print_LIR); |
47 CFGPrinterOutput* output = Compilation::current()->cfg_printer_output(); |
98 output()->print_cfg(blocks, name); |
48 output->set_print_flags(do_print_HIR, do_print_LIR); |
99 } |
49 output->print_cfg(blocks, name); |
100 |
50 } |
101 |
51 |
102 void CFGPrinter::print_intervals(IntervalList* intervals, const char* name) { |
52 void CFGPrinter::print_intervals(IntervalList* intervals, const char* name) { |
103 output()->print_intervals(intervals, name); |
53 CFGPrinterOutput* output = Compilation::current()->cfg_printer_output(); |
104 } |
54 output->print_intervals(intervals, name); |
105 |
55 } |
106 |
56 |
107 |
57 |
108 CFGPrinterOutput::CFGPrinterOutput() |
58 CFGPrinterOutput::CFGPrinterOutput(Compilation* compilation) |
109 : _output(new(ResourceObj::C_HEAP, mtCompiler) fileStream("output.cfg")) |
59 : _output(NULL), |
|
60 _compilation(compilation), |
|
61 _do_print_HIR(false), |
|
62 _do_print_LIR(false) |
110 { |
63 { |
111 } |
64 char file_name[O_BUFLEN]; |
112 |
65 jio_snprintf(file_name, sizeof(file_name), "output_tid" UINTX_FORMAT "_pid%u.cfg", |
113 |
66 os::current_thread_id(), os::current_process_id()); |
|
67 _output = new(ResourceObj::C_HEAP, mtCompiler) fileStream(file_name, "at"); |
|
68 } |
114 |
69 |
115 void CFGPrinterOutput::inc_indent() { |
70 void CFGPrinterOutput::inc_indent() { |
116 output()->inc(); |
71 output()->inc(); |
117 output()->inc(); |
72 output()->inc(); |
118 } |
73 } |