summaryrefslogtreecommitdiff
path: root/compiler/optimizing/graph_visualizer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/optimizing/graph_visualizer.cc')
-rw-r--r--compiler/optimizing/graph_visualizer.cc103
1 files changed, 55 insertions, 48 deletions
diff --git a/compiler/optimizing/graph_visualizer.cc b/compiler/optimizing/graph_visualizer.cc
index 0fb4737db2..d7dcb4c5db 100644
--- a/compiler/optimizing/graph_visualizer.cc
+++ b/compiler/optimizing/graph_visualizer.cc
@@ -17,7 +17,6 @@
#include "graph_visualizer.h"
#include "code_generator.h"
-#include "driver/dex_compilation_unit.h"
#include "nodes.h"
#include "ssa_liveness_analysis.h"
@@ -31,10 +30,12 @@ class HGraphVisualizerPrinter : public HGraphVisitor {
HGraphVisualizerPrinter(HGraph* graph,
std::ostream& output,
const char* pass_name,
+ bool is_after_pass,
const CodeGenerator& codegen)
: HGraphVisitor(graph),
output_(output),
pass_name_(pass_name),
+ is_after_pass_(is_after_pass),
codegen_(codegen),
indent_(0) {}
@@ -67,7 +68,7 @@ class HGraphVisualizerPrinter : public HGraphVisitor {
void PrintTime(const char* name) {
AddIndent();
- output_ << name << " " << time(NULL) << std::endl;
+ output_ << name << " " << time(nullptr) << std::endl;
}
void PrintInt(const char* name, int value) {
@@ -120,13 +121,11 @@ class HGraphVisualizerPrinter : public HGraphVisitor {
output_<< std::endl;
}
- void DumpLocation(Location location, Primitive::Type type) {
+ void DumpLocation(Location location) {
if (location.IsRegister()) {
- if (type == Primitive::kPrimDouble || type == Primitive::kPrimFloat) {
- codegen_.DumpFloatingPointRegister(output_, location.reg().RegId());
- } else {
- codegen_.DumpCoreRegister(output_, location.reg().RegId());
- }
+ codegen_.DumpCoreRegister(output_, location.reg());
+ } else if (location.IsFpuRegister()) {
+ codegen_.DumpFloatingPointRegister(output_, location.reg());
} else if (location.IsConstant()) {
output_ << "constant";
HConstant* constant = location.GetConstant();
@@ -139,29 +138,54 @@ class HGraphVisualizerPrinter : public HGraphVisitor {
output_ << "invalid";
} else if (location.IsStackSlot()) {
output_ << location.GetStackIndex() << "(sp)";
+ } else if (location.IsFpuRegisterPair()) {
+ codegen_.DumpFloatingPointRegister(output_, location.low());
+ output_ << " and ";
+ codegen_.DumpFloatingPointRegister(output_, location.high());
+ } else if (location.IsRegisterPair()) {
+ codegen_.DumpCoreRegister(output_, location.low());
+ output_ << " and ";
+ codegen_.DumpCoreRegister(output_, location.high());
} else {
DCHECK(location.IsDoubleStackSlot());
output_ << "2x" << location.GetStackIndex() << "(sp)";
}
}
- void VisitParallelMove(HParallelMove* instruction) {
- output_ << instruction->DebugName();
+ void VisitParallelMove(HParallelMove* instruction) OVERRIDE {
output_ << " (";
for (size_t i = 0, e = instruction->NumMoves(); i < e; ++i) {
MoveOperands* move = instruction->MoveOperandsAt(i);
- DumpLocation(move->GetSource(), Primitive::kPrimInt);
+ DumpLocation(move->GetSource());
output_ << " -> ";
- DumpLocation(move->GetDestination(), Primitive::kPrimInt);
+ DumpLocation(move->GetDestination());
if (i + 1 != e) {
output_ << ", ";
}
}
output_ << ")";
+ output_ << " (liveness: " << instruction->GetLifetimePosition() << ")";
+ }
+
+ void VisitIntConstant(HIntConstant* instruction) OVERRIDE {
+ output_ << " " << instruction->GetValue();
+ }
+
+ void VisitLongConstant(HLongConstant* instruction) OVERRIDE {
+ output_ << " " << instruction->GetValue();
}
- void VisitInstruction(HInstruction* instruction) {
+ void VisitFloatConstant(HFloatConstant* instruction) OVERRIDE {
+ output_ << " " << instruction->GetValue();
+ }
+
+ void VisitDoubleConstant(HDoubleConstant* instruction) OVERRIDE {
+ output_ << " " << instruction->GetValue();
+ }
+
+ void PrintInstruction(HInstruction* instruction) {
output_ << instruction->DebugName();
+ instruction->Accept(this);
if (instruction->InputCount() > 0) {
output_ << " [ ";
for (HInputIterator inputs(instruction); !inputs.Done(); inputs.Advance()) {
@@ -182,15 +206,16 @@ class HGraphVisualizerPrinter : public HGraphVisitor {
if (locations != nullptr) {
output_ << " ( ";
for (size_t i = 0; i < instruction->InputCount(); ++i) {
- DumpLocation(locations->InAt(i), instruction->InputAt(i)->GetType());
+ DumpLocation(locations->InAt(i));
output_ << " ";
}
output_ << ")";
if (locations->Out().IsValid()) {
output_ << " -> ";
- DumpLocation(locations->Out(), instruction->GetType());
+ DumpLocation(locations->Out());
}
}
+ output_ << " (liveness: " << instruction->GetLifetimePosition() << ")";
}
}
@@ -202,19 +227,20 @@ class HGraphVisualizerPrinter : public HGraphVisitor {
int bci = 0;
output_ << bci << " " << instruction->NumberOfUses()
<< " " << GetTypeId(instruction->GetType()) << instruction->GetId() << " ";
- instruction->Accept(this);
+ PrintInstruction(instruction);
output_ << kEndInstructionMarker << std::endl;
}
}
void Run() {
StartTag("cfg");
- PrintProperty("name", pass_name_);
+ std::string pass_desc = std::string(pass_name_) + (is_after_pass_ ? " (after)" : " (before)");
+ PrintProperty("name", pass_desc.c_str());
VisitInsertionOrder();
EndTag("cfg");
}
- void VisitBasicBlock(HBasicBlock* block) {
+ void VisitBasicBlock(HBasicBlock* block) OVERRIDE {
StartTag("block");
PrintProperty("name", "B", block->GetBlockId());
if (block->GetLifetimeStart() != kNoLifetime) {
@@ -260,6 +286,7 @@ class HGraphVisualizerPrinter : public HGraphVisitor {
private:
std::ostream& output_;
const char* pass_name_;
+ const bool is_after_pass_;
const CodeGenerator& codegen_;
size_t indent_;
@@ -270,49 +297,29 @@ HGraphVisualizer::HGraphVisualizer(std::ostream* output,
HGraph* graph,
const char* string_filter,
const CodeGenerator& codegen,
- const DexCompilationUnit& cu)
- : output_(output), graph_(graph), codegen_(codegen), is_enabled_(false) {
+ const char* method_name)
+ : output_(output), graph_(graph), codegen_(codegen), is_enabled_(false) {
if (output == nullptr) {
return;
}
- std::string pretty_name = PrettyMethod(cu.GetDexMethodIndex(), *cu.GetDexFile());
- if (pretty_name.find(string_filter) == std::string::npos) {
- return;
- }
-
- is_enabled_ = true;
- HGraphVisualizerPrinter printer(graph, *output_, "", codegen_);
- printer.StartTag("compilation");
- printer.PrintProperty("name", pretty_name.c_str());
- printer.PrintProperty("method", pretty_name.c_str());
- printer.PrintTime("date");
- printer.EndTag("compilation");
-}
-
-HGraphVisualizer::HGraphVisualizer(std::ostream* output,
- HGraph* graph,
- const CodeGenerator& codegen,
- const char* name)
- : output_(output), graph_(graph), codegen_(codegen), is_enabled_(false) {
- if (output == nullptr) {
+ if (strstr(method_name, string_filter) == nullptr) {
return;
}
is_enabled_ = true;
- HGraphVisualizerPrinter printer(graph, *output_, "", codegen_);
+ HGraphVisualizerPrinter printer(graph_, *output_, "", true, codegen_);
printer.StartTag("compilation");
- printer.PrintProperty("name", name);
- printer.PrintProperty("method", name);
+ printer.PrintProperty("name", method_name);
+ printer.PrintProperty("method", method_name);
printer.PrintTime("date");
printer.EndTag("compilation");
}
-void HGraphVisualizer::DumpGraph(const char* pass_name) {
- if (!is_enabled_) {
- return;
+void HGraphVisualizer::DumpGraph(const char* pass_name, bool is_after_pass) const {
+ if (is_enabled_) {
+ HGraphVisualizerPrinter printer(graph_, *output_, pass_name, is_after_pass, codegen_);
+ printer.Run();
}
- HGraphVisualizerPrinter printer(graph_, *output_, pass_name, codegen_);
- printer.Run();
}
} // namespace art