blob: 60849e02386c80ba4643fa5d4b6dc31734ab2872 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// Copyright 2014 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_COMPILER_VERIFIER_H_
6#define V8_COMPILER_VERIFIER_H_
7
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008#include "src/base/macros.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009
10namespace v8 {
11namespace internal {
12namespace compiler {
13
14class Graph;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000015class Edge;
16class Node;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000017class Schedule;
18
19// Verifies properties of a graph, such as the well-formedness of inputs to
20// each node, etc.
21class Verifier {
22 public:
Emily Bernierd0a1eb72015-03-24 16:35:39 -040023 enum Typing { TYPED, UNTYPED };
Ben Murdochc5610432016-08-08 18:44:38 +010024 enum CheckInputs { kValuesOnly, kAll };
Emily Bernierd0a1eb72015-03-24 16:35:39 -040025
Ben Murdochc5610432016-08-08 18:44:38 +010026 static void Run(Graph* graph, Typing typing = TYPED,
27 CheckInputs check_inputs = kAll);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000028
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000029#ifdef DEBUG
30 // Verifies consistency of node inputs and uses:
31 // - node inputs should agree with the input count computed from
32 // the node's operator.
33 // - effect inputs should have effect outputs.
34 // - control inputs should have control outputs.
35 // - frame state inputs should be frame states.
36 // - if the node has control uses, it should produce control.
37 // - if the node has effect uses, it should produce effect.
38 // - if the node has frame state uses, it must be a frame state.
39 static void VerifyNode(Node* node);
40
41 // Verify that {replacement} has the required outputs
42 // (effect, control or frame state) to be used as an input for {edge}.
43 static void VerifyEdgeInputReplacement(const Edge& edge,
44 const Node* replacement);
45#else
46 static void VerifyNode(Node* node) {}
47 static void VerifyEdgeInputReplacement(const Edge& edge,
48 const Node* replacement) {}
49#endif // DEBUG
50
Ben Murdochb8a8cc12014-11-26 15:28:44 +000051 private:
52 class Visitor;
53 DISALLOW_COPY_AND_ASSIGN(Verifier);
54};
55
56// Verifies properties of a schedule, such as dominance, phi placement, etc.
57class ScheduleVerifier {
58 public:
59 static void Run(Schedule* schedule);
60};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000061} // namespace compiler
62} // namespace internal
63} // namespace v8
Ben Murdochb8a8cc12014-11-26 15:28:44 +000064
65#endif // V8_COMPILER_VERIFIER_H_