1 // 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_GRAPH_UNITTEST_H_
6 #define V8_COMPILER_GRAPH_UNITTEST_H_
7 
8 #include "src/compiler/common-operator.h"
9 #include "src/compiler/graph.h"
10 #include "src/compiler/machine-operator.h"
11 #include "src/test/test-utils.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 // Forward declarations.
18 class HeapObject;
19 template <class T>
20 class Unique;
21 
22 namespace compiler {
23 
24 using ::testing::Matcher;
25 
26 
27 class GraphTest : public TestWithContext, public TestWithZone {
28  public:
29   explicit GraphTest(int parameters = 1);
30   virtual ~GraphTest();
31 
32  protected:
33   Node* Parameter(int32_t index);
34   Node* Float32Constant(volatile float value);
35   Node* Float64Constant(volatile double value);
36   Node* Int32Constant(int32_t value);
37   Node* Int64Constant(int64_t value);
38   Node* NumberConstant(volatile double value);
39   Node* HeapConstant(const Unique<HeapObject>& value);
40   Node* FalseConstant();
41   Node* TrueConstant();
42 
43   Matcher<Node*> IsFalseConstant();
44   Matcher<Node*> IsTrueConstant();
45 
common()46   CommonOperatorBuilder* common() { return &common_; }
graph()47   Graph* graph() { return &graph_; }
48 
49  private:
50   CommonOperatorBuilder common_;
51   Graph graph_;
52 };
53 
54 
55 Matcher<Node*> IsBranch(const Matcher<Node*>& value_matcher,
56                         const Matcher<Node*>& control_matcher);
57 Matcher<Node*> IsMerge(const Matcher<Node*>& control0_matcher,
58                        const Matcher<Node*>& control1_matcher);
59 Matcher<Node*> IsIfTrue(const Matcher<Node*>& control_matcher);
60 Matcher<Node*> IsIfFalse(const Matcher<Node*>& control_matcher);
61 Matcher<Node*> IsControlEffect(const Matcher<Node*>& control_matcher);
62 Matcher<Node*> IsValueEffect(const Matcher<Node*>& value_matcher);
63 Matcher<Node*> IsFinish(const Matcher<Node*>& value_matcher,
64                         const Matcher<Node*>& effect_matcher);
65 Matcher<Node*> IsExternalConstant(
66     const Matcher<ExternalReference>& value_matcher);
67 Matcher<Node*> IsHeapConstant(
68     const Matcher<Unique<HeapObject> >& value_matcher);
69 Matcher<Node*> IsFloat32Constant(const Matcher<float>& value_matcher);
70 Matcher<Node*> IsFloat64Constant(const Matcher<double>& value_matcher);
71 Matcher<Node*> IsInt32Constant(const Matcher<int32_t>& value_matcher);
72 Matcher<Node*> IsInt64Constant(const Matcher<int64_t>& value_matcher);
73 Matcher<Node*> IsNumberConstant(const Matcher<double>& value_matcher);
74 Matcher<Node*> IsPhi(const Matcher<MachineType>& type_matcher,
75                      const Matcher<Node*>& value0_matcher,
76                      const Matcher<Node*>& value1_matcher,
77                      const Matcher<Node*>& merge_matcher);
78 Matcher<Node*> IsProjection(const Matcher<size_t>& index_matcher,
79                             const Matcher<Node*>& base_matcher);
80 Matcher<Node*> IsCall(const Matcher<CallDescriptor*>& descriptor_matcher,
81                       const Matcher<Node*>& value0_matcher,
82                       const Matcher<Node*>& value1_matcher,
83                       const Matcher<Node*>& value2_matcher,
84                       const Matcher<Node*>& value3_matcher,
85                       const Matcher<Node*>& effect_matcher,
86                       const Matcher<Node*>& control_matcher);
87 
88 Matcher<Node*> IsNumberLessThan(const Matcher<Node*>& lhs_matcher,
89                                 const Matcher<Node*>& rhs_matcher);
90 
91 Matcher<Node*> IsLoad(const Matcher<LoadRepresentation>& rep_matcher,
92                       const Matcher<Node*>& base_matcher,
93                       const Matcher<Node*>& index_matcher,
94                       const Matcher<Node*>& effect_matcher);
95 Matcher<Node*> IsStore(const Matcher<MachineType>& type_matcher,
96                        const Matcher<WriteBarrierKind>& write_barrier_matcher,
97                        const Matcher<Node*>& base_matcher,
98                        const Matcher<Node*>& index_matcher,
99                        const Matcher<Node*>& value_matcher,
100                        const Matcher<Node*>& effect_matcher,
101                        const Matcher<Node*>& control_matcher);
102 Matcher<Node*> IsWord32And(const Matcher<Node*>& lhs_matcher,
103                            const Matcher<Node*>& rhs_matcher);
104 Matcher<Node*> IsWord32Sar(const Matcher<Node*>& lhs_matcher,
105                            const Matcher<Node*>& rhs_matcher);
106 Matcher<Node*> IsWord32Shl(const Matcher<Node*>& lhs_matcher,
107                            const Matcher<Node*>& rhs_matcher);
108 Matcher<Node*> IsWord32Ror(const Matcher<Node*>& lhs_matcher,
109                            const Matcher<Node*>& rhs_matcher);
110 Matcher<Node*> IsWord32Equal(const Matcher<Node*>& lhs_matcher,
111                              const Matcher<Node*>& rhs_matcher);
112 Matcher<Node*> IsWord64And(const Matcher<Node*>& lhs_matcher,
113                            const Matcher<Node*>& rhs_matcher);
114 Matcher<Node*> IsWord64Shl(const Matcher<Node*>& lhs_matcher,
115                            const Matcher<Node*>& rhs_matcher);
116 Matcher<Node*> IsWord64Sar(const Matcher<Node*>& lhs_matcher,
117                            const Matcher<Node*>& rhs_matcher);
118 Matcher<Node*> IsWord64Equal(const Matcher<Node*>& lhs_matcher,
119                              const Matcher<Node*>& rhs_matcher);
120 Matcher<Node*> IsInt32AddWithOverflow(const Matcher<Node*>& lhs_matcher,
121                                       const Matcher<Node*>& rhs_matcher);
122 Matcher<Node*> IsInt32Mul(const Matcher<Node*>& lhs_matcher,
123                           const Matcher<Node*>& rhs_matcher);
124 Matcher<Node*> IsUint32LessThanOrEqual(const Matcher<Node*>& lhs_matcher,
125                                        const Matcher<Node*>& rhs_matcher);
126 Matcher<Node*> IsChangeFloat64ToInt32(const Matcher<Node*>& input_matcher);
127 Matcher<Node*> IsChangeFloat64ToUint32(const Matcher<Node*>& input_matcher);
128 Matcher<Node*> IsChangeInt32ToFloat64(const Matcher<Node*>& input_matcher);
129 Matcher<Node*> IsChangeInt32ToInt64(const Matcher<Node*>& input_matcher);
130 Matcher<Node*> IsChangeUint32ToFloat64(const Matcher<Node*>& input_matcher);
131 Matcher<Node*> IsChangeUint32ToUint64(const Matcher<Node*>& input_matcher);
132 Matcher<Node*> IsTruncateFloat64ToInt32(const Matcher<Node*>& input_matcher);
133 Matcher<Node*> IsTruncateInt64ToInt32(const Matcher<Node*>& input_matcher);
134 Matcher<Node*> IsFloat64Sqrt(const Matcher<Node*>& input_matcher);
135 
136 }  //  namespace compiler
137 }  //  namespace internal
138 }  //  namespace v8
139 
140 #endif  // V8_COMPILER_GRAPH_UNITTEST_H_
141