summaryrefslogtreecommitdiff
path: root/deps/v8/src/compiler/schedule.cc
blob: a3b5ed383b6c6d621f302ad08a5ad5af96ef4933 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2013 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/compiler/node.h"
#include "src/compiler/node-properties.h"
#include "src/compiler/node-properties-inl.h"
#include "src/compiler/schedule.h"
#include "src/ostreams.h"

namespace v8 {
namespace internal {
namespace compiler {

OStream& operator<<(OStream& os, const BasicBlockData::Control& c) {
  switch (c) {
    case BasicBlockData::kNone:
      return os << "none";
    case BasicBlockData::kGoto:
      return os << "goto";
    case BasicBlockData::kBranch:
      return os << "branch";
    case BasicBlockData::kReturn:
      return os << "return";
    case BasicBlockData::kThrow:
      return os << "throw";
  }
  UNREACHABLE();
  return os;
}


OStream& operator<<(OStream& os, const Schedule& s) {
  // TODO(svenpanne) Const-correct the RPO stuff/iterators.
  BasicBlockVector* rpo = const_cast<Schedule*>(&s)->rpo_order();
  for (BasicBlockVectorIter i = rpo->begin(); i != rpo->end(); ++i) {
    BasicBlock* block = *i;
    os << "--- BLOCK B" << block->id();
    if (block->PredecessorCount() != 0) os << " <- ";
    BasicBlock::Predecessors predecessors = block->predecessors();
    bool comma = false;
    for (BasicBlock::Predecessors::iterator j = predecessors.begin();
         j != predecessors.end(); ++j) {
      if (comma) os << ", ";
      comma = true;
      os << "B" << (*j)->id();
    }
    os << " ---\n";
    for (BasicBlock::const_iterator j = block->begin(); j != block->end();
         ++j) {
      Node* node = *j;
      os << "  " << *node;
      if (!NodeProperties::IsControl(node)) {
        Bounds bounds = NodeProperties::GetBounds(node);
        os << " : ";
        bounds.lower->PrintTo(os);
        if (!bounds.upper->Is(bounds.lower)) {
          os << "..";
          bounds.upper->PrintTo(os);
        }
      }
      os << "\n";
    }
    BasicBlock::Control control = block->control_;
    if (control != BasicBlock::kNone) {
      os << "  ";
      if (block->control_input_ != NULL) {
        os << *block->control_input_;
      } else {
        os << "Goto";
      }
      os << " -> ";
      BasicBlock::Successors successors = block->successors();
      comma = false;
      for (BasicBlock::Successors::iterator j = successors.begin();
           j != successors.end(); ++j) {
        if (comma) os << ", ";
        comma = true;
        os << "B" << (*j)->id();
      }
      os << "\n";
    }
  }
  return os;
}
}  // namespace compiler
}  // namespace internal
}  // namespace v8