blob: 8ddd39945610a9b58395f503f381048914cd3ca2 [file] [log] [blame]
Roland Levillainccc07a92014-09-16 14:48:16 +01001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_COMPILER_OPTIMIZING_GRAPH_CHECKER_H_
18#define ART_COMPILER_OPTIMIZING_GRAPH_CHECKER_H_
19
20#include "nodes.h"
21
22namespace art {
23
24// A control-flow graph visitor performing various checks.
25class GraphChecker : public HGraphVisitor {
26 public:
27 GraphChecker(ArenaAllocator* allocator, HGraph* graph)
28 : HGraphVisitor(graph),
29 allocator_(allocator),
30 errors_(allocator, 0) {}
31
32 // Check `block`.
33 virtual void VisitBasicBlock(HBasicBlock* block) OVERRIDE;
34
35 // Check `instruction`.
36 virtual void VisitInstruction(HInstruction* instruction) OVERRIDE;
37
38 // Was the last visit of the graph valid?
39 bool IsValid() const {
40 return errors_.IsEmpty();
41 }
42
43 // Get the list of detected errors.
44 const GrowableArray<std::string>& GetErrors() const {
45 return errors_;
46 }
47
48 protected:
49 ArenaAllocator* const allocator_;
50 // The block currently visited.
51 HBasicBlock* current_block_ = nullptr;
52 // Errors encountered while checking the graph.
53 GrowableArray<std::string> errors_;
54
55 private:
56 DISALLOW_COPY_AND_ASSIGN(GraphChecker);
57};
58
59
60// An SSA graph visitor performing various checks.
61class SSAChecker : public GraphChecker {
62 public:
63 typedef GraphChecker super_type;
64
65 SSAChecker(ArenaAllocator* allocator, HGraph* graph)
66 : GraphChecker(allocator, graph) {}
67
68 // Perform SSA form checks on `block`.
69 virtual void VisitBasicBlock(HBasicBlock* block) OVERRIDE;
70
71 // Perform SSA form checks on `instruction`.
72 virtual void VisitInstruction(HInstruction* instruction) OVERRIDE;
73
74 private:
75 DISALLOW_COPY_AND_ASSIGN(SSAChecker);
76};
77
78} // namespace art
79
80#endif // ART_COMPILER_OPTIMIZING_GRAPH_CHECKER_H_