maglev-graph-printer.h 2.12 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2022 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.

#ifndef V8_MAGLEV_MAGLEV_GRAPH_PRINTER_H_
#define V8_MAGLEV_MAGLEV_GRAPH_PRINTER_H_

8
#include <memory>
9 10 11 12 13 14 15 16 17 18 19
#include <ostream>
#include <set>
#include <vector>

namespace v8 {
namespace internal {
namespace maglev {

class BasicBlock;
class ControlNode;
class Graph;
20
class MaglevCompilationInfo;
21 22
class MaglevGraphLabeller;
class Node;
23
class NodeBase;
24 25 26 27 28 29 30
class Phi;
class ProcessingState;

class MaglevPrintingVisitor {
 public:
  explicit MaglevPrintingVisitor(std::ostream& os);

31 32 33
  void PreProcessGraph(MaglevCompilationInfo*, Graph* graph);
  void PostProcessGraph(MaglevCompilationInfo*, Graph* graph) {}
  void PreProcessBasicBlock(MaglevCompilationInfo*, BasicBlock* block);
34 35 36 37 38 39 40 41 42
  void Process(Phi* phi, const ProcessingState& state);
  void Process(Node* node, const ProcessingState& state);
  void Process(ControlNode* node, const ProcessingState& state);

  std::ostream& os() { return *os_for_additional_info_; }

 private:
  std::ostream& os_;
  std::unique_ptr<std::ostream> os_for_additional_info_;
43 44
  std::set<BasicBlock*> loop_headers_;
  std::vector<BasicBlock*> targets_;
45 46
};

47
void PrintGraph(std::ostream& os, MaglevCompilationInfo* compilation_info,
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
                Graph* const graph);

class PrintNode {
 public:
  PrintNode(MaglevGraphLabeller* graph_labeller, const NodeBase* node)
      : graph_labeller_(graph_labeller), node_(node) {}

  void Print(std::ostream& os) const;

 private:
  MaglevGraphLabeller* graph_labeller_;
  const NodeBase* node_;
};

std::ostream& operator<<(std::ostream& os, const PrintNode& printer);

class PrintNodeLabel {
 public:
  PrintNodeLabel(MaglevGraphLabeller* graph_labeller, const Node* node)
      : graph_labeller_(graph_labeller), node_(node) {}

  void Print(std::ostream& os) const;

 private:
  MaglevGraphLabeller* graph_labeller_;
  const Node* node_;
};

std::ostream& operator<<(std::ostream& os, const PrintNodeLabel& printer);

}  // namespace maglev
}  // namespace internal
}  // namespace v8

#endif  // V8_MAGLEV_MAGLEV_GRAPH_PRINTER_H_