OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/interface-descriptors.h" | 5 #include "src/interface-descriptors.h" |
6 #include "src/isolate.h" | 6 #include "src/isolate.h" |
7 #include "test/cctest/compiler/function-tester.h" | 7 #include "test/cctest/compiler/function-tester.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); | 113 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); |
114 Node* a = m.SmiTag(m.Int32Constant(2)); | 114 Node* a = m.SmiTag(m.Int32Constant(2)); |
115 Node* b = m.SmiTag(m.Int32Constant(4)); | 115 Node* b = m.SmiTag(m.Int32Constant(4)); |
116 m.TailCallRuntime(Runtime::kMathPow, context, a, b); | 116 m.TailCallRuntime(Runtime::kMathPow, context, a, b); |
117 Handle<Code> code = m.GenerateCode(); | 117 Handle<Code> code = m.GenerateCode(); |
118 FunctionTester ft(descriptor, code); | 118 FunctionTester ft(descriptor, code); |
119 MaybeHandle<Object> result = ft.Call(); | 119 MaybeHandle<Object> result = ft.Call(); |
120 CHECK_EQ(16, Handle<Smi>::cast(result.ToHandleChecked())->value()); | 120 CHECK_EQ(16, Handle<Smi>::cast(result.ToHandleChecked())->value()); |
121 } | 121 } |
122 | 122 |
| 123 TEST(VariableMerge1) { |
| 124 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 125 VoidDescriptor descriptor(isolate); |
| 126 CodeStubAssemblerTester m(isolate, descriptor); |
| 127 CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged); |
| 128 CodeStubAssembler::Label l1(&m), l2(&m), merge(&m); |
| 129 Node* temp = m.Int32Constant(0); |
| 130 var1.Bind(temp); |
| 131 m.Branch(m.Int32Constant(1), &l1, &l2); |
| 132 m.Bind(&l1); |
| 133 CHECK_EQ(var1.value(), temp); |
| 134 m.Goto(&merge); |
| 135 m.Bind(&l2); |
| 136 CHECK_EQ(var1.value(), temp); |
| 137 m.Goto(&merge); |
| 138 m.Bind(&merge); |
| 139 CHECK_EQ(var1.value(), temp); |
| 140 } |
| 141 |
| 142 TEST(VariableMerge2) { |
| 143 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 144 VoidDescriptor descriptor(isolate); |
| 145 CodeStubAssemblerTester m(isolate, descriptor); |
| 146 CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged); |
| 147 CodeStubAssembler::Label l1(&m), l2(&m), merge(&m); |
| 148 Node* temp = m.Int32Constant(0); |
| 149 var1.Bind(temp); |
| 150 m.Branch(m.Int32Constant(1), &l1, &l2); |
| 151 m.Bind(&l1); |
| 152 CHECK_EQ(var1.value(), temp); |
| 153 m.Goto(&merge); |
| 154 m.Bind(&l2); |
| 155 Node* temp2 = m.Int32Constant(2); |
| 156 var1.Bind(temp2); |
| 157 CHECK_EQ(var1.value(), temp2); |
| 158 m.Goto(&merge); |
| 159 m.Bind(&merge); |
| 160 CHECK_NE(var1.value(), temp); |
| 161 } |
| 162 |
| 163 TEST(VariableMerge3) { |
| 164 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 165 VoidDescriptor descriptor(isolate); |
| 166 CodeStubAssemblerTester m(isolate, descriptor); |
| 167 CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged); |
| 168 CodeStubAssembler::Variable var2(&m, MachineRepresentation::kTagged); |
| 169 CodeStubAssembler::Label l1(&m), l2(&m), merge(&m); |
| 170 Node* temp = m.Int32Constant(0); |
| 171 var1.Bind(temp); |
| 172 var2.Bind(temp); |
| 173 m.Branch(m.Int32Constant(1), &l1, &l2); |
| 174 m.Bind(&l1); |
| 175 CHECK_EQ(var1.value(), temp); |
| 176 m.Goto(&merge); |
| 177 m.Bind(&l2); |
| 178 Node* temp2 = m.Int32Constant(2); |
| 179 var1.Bind(temp2); |
| 180 CHECK_EQ(var1.value(), temp2); |
| 181 m.Goto(&merge); |
| 182 m.Bind(&merge); |
| 183 CHECK_NE(var1.value(), temp); |
| 184 CHECK_NE(var1.value(), temp2); |
| 185 CHECK_EQ(var2.value(), temp); |
| 186 } |
| 187 |
| 188 TEST(VariableMergeBindFirst) { |
| 189 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 190 VoidDescriptor descriptor(isolate); |
| 191 CodeStubAssemblerTester m(isolate, descriptor); |
| 192 CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged); |
| 193 CodeStubAssembler::Label l1(&m), l2(&m), merge(&m, &var1), end(&m); |
| 194 Node* temp = m.Int32Constant(0); |
| 195 var1.Bind(temp); |
| 196 m.Branch(m.Int32Constant(1), &l1, &l2); |
| 197 m.Bind(&l1); |
| 198 CHECK_EQ(var1.value(), temp); |
| 199 m.Goto(&merge); |
| 200 m.Bind(&merge); |
| 201 CHECK(var1.value() != temp); |
| 202 CHECK(var1.value() != nullptr); |
| 203 m.Goto(&end); |
| 204 m.Bind(&l2); |
| 205 Node* temp2 = m.Int32Constant(2); |
| 206 var1.Bind(temp2); |
| 207 CHECK_EQ(var1.value(), temp2); |
| 208 m.Goto(&merge); |
| 209 m.Bind(&end); |
| 210 CHECK(var1.value() != temp); |
| 211 CHECK(var1.value() != nullptr); |
| 212 } |
| 213 |
| 214 TEST(VariableMergeSwitch) { |
| 215 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 216 VoidDescriptor descriptor(isolate); |
| 217 CodeStubAssemblerTester m(isolate, descriptor); |
| 218 CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged); |
| 219 CodeStubAssembler::Label l1(&m), l2(&m), default_label(&m); |
| 220 CodeStubAssembler::Label* labels[] = {&l1, &l2}; |
| 221 int32_t values[] = {1, 2}; |
| 222 Node* temp = m.Int32Constant(0); |
| 223 var1.Bind(temp); |
| 224 m.Switch(m.Int32Constant(2), &default_label, values, labels, 2); |
| 225 m.Bind(&l1); |
| 226 DCHECK_EQ(temp, var1.value()); |
| 227 m.Return(temp); |
| 228 m.Bind(&l2); |
| 229 DCHECK_EQ(temp, var1.value()); |
| 230 m.Return(temp); |
| 231 m.Bind(&default_label); |
| 232 DCHECK_EQ(temp, var1.value()); |
| 233 m.Return(temp); |
| 234 } |
| 235 |
| 236 TEST(FixedArrayAccessSmiIndex) { |
| 237 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 238 VoidDescriptor descriptor(isolate); |
| 239 CodeStubAssemblerTester m(isolate, descriptor); |
| 240 Handle<FixedArray> array = isolate->factory()->NewFixedArray(5); |
| 241 array->set(4, Smi::FromInt(733)); |
| 242 m.Return(m.LoadFixedArrayElementSmiIndex(m.HeapConstant(array), |
| 243 m.SmiTag(m.Int32Constant(4)))); |
| 244 Handle<Code> code = m.GenerateCode(); |
| 245 FunctionTester ft(descriptor, code); |
| 246 MaybeHandle<Object> result = ft.Call(); |
| 247 CHECK_EQ(733, Handle<Smi>::cast(result.ToHandleChecked())->value()); |
| 248 } |
| 249 |
123 } // namespace compiler | 250 } // namespace compiler |
124 } // namespace internal | 251 } // namespace internal |
125 } // namespace v8 | 252 } // namespace v8 |
OLD | NEW |