Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: test/cctest/test-types.cc

Issue 904863002: [turbofan] Separate representation type operations from the semantic types. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixes Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/compiler/test-typer.cc ('k') | test/cctest/types-fuzz.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 <vector> 5 #include <vector>
6 6
7 #include "src/hydrogen-types.h" 7 #include "src/hydrogen-types.h"
8 #include "src/isolate-inl.h" 8 #include "src/isolate-inl.h"
9 #include "src/types.h" 9 #include "src/types.h"
10 #include "test/cctest/cctest.h" 10 #include "test/cctest/cctest.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 102
103 Isolate* isolate; 103 Isolate* isolate;
104 HandleScope scope; 104 HandleScope scope;
105 Zone zone; 105 Zone zone;
106 TypesInstance T; 106 TypesInstance T;
107 107
108 Tests() 108 Tests()
109 : isolate(CcTest::i_isolate()), 109 : isolate(CcTest::i_isolate()),
110 scope(isolate), 110 scope(isolate),
111 zone(), 111 zone(),
112 T(Rep::ToRegion(&zone, isolate), isolate) {} 112 T(Rep::ToRegion(&zone, isolate), isolate,
113 isolate->random_number_generator()) {}
113 114
114 bool Equal(TypeHandle type1, TypeHandle type2) { 115 bool Equal(TypeHandle type1, TypeHandle type2) {
115 return 116 return
116 type1->Equals(type2) && 117 type1->Equals(type2) &&
117 this->IsBitset(type1) == this->IsBitset(type2) && 118 this->IsBitset(type1) == this->IsBitset(type2) &&
118 this->IsUnion(type1) == this->IsUnion(type2) && 119 this->IsUnion(type1) == this->IsUnion(type2) &&
119 type1->NumClasses() == type2->NumClasses() && 120 type1->NumClasses() == type2->NumClasses() &&
120 type1->NumConstants() == type2->NumConstants() && 121 type1->NumConstants() == type2->NumConstants() &&
121 (!this->IsBitset(type1) || 122 (!this->IsBitset(type1) ||
122 this->AsBitset(type1) == this->AsBitset(type2)) && 123 this->AsBitset(type1) == this->AsBitset(type2)) &&
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 this->AsBitset(union12)); 228 this->AsBitset(union12));
228 } 229 }
229 } 230 }
230 } 231 }
231 232
232 // Intersect(T1, T2) is bitwise conjunction for bitsets T1,T2 (modulo None) 233 // Intersect(T1, T2) is bitwise conjunction for bitsets T1,T2 (modulo None)
233 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 234 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
234 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 235 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
235 TypeHandle type1 = *it1; 236 TypeHandle type1 = *it1;
236 TypeHandle type2 = *it2; 237 TypeHandle type2 = *it2;
237 TypeHandle intersect12 = T.Intersect(type1, type2);
238 if (this->IsBitset(type1) && this->IsBitset(type2)) { 238 if (this->IsBitset(type1) && this->IsBitset(type2)) {
239 TypeHandle intersect12 = T.Intersect(type1, type2);
239 bitset bits = this->AsBitset(type1) & this->AsBitset(type2); 240 bitset bits = this->AsBitset(type1) & this->AsBitset(type2);
240 CHECK( 241 CHECK(bits == this->AsBitset(intersect12));
241 (Rep::BitsetType::IsInhabited(bits) ? bits : 0) ==
242 this->AsBitset(intersect12));
243 } 242 }
244 } 243 }
245 } 244 }
246 } 245 }
247 246
247 void PointwiseRepresentation() {
248 // Check we can decompose type into semantics and representation and
249 // then compose it back to get an equivalent type.
250 int counter = 0;
251 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
252 counter++;
253 printf("Counter: %i\n", counter);
254 fflush(stdout);
255 TypeHandle type1 = *it1;
256 TypeHandle representation = T.Representation(type1);
257 TypeHandle semantic = T.Semantic(type1);
258 TypeHandle composed = T.Union(representation, semantic);
259 CHECK(type1->Equals(composed));
260 }
261
262 // Pointwiseness of Union.
263 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
264 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
265 TypeHandle type1 = *it1;
266 TypeHandle type2 = *it2;
267 TypeHandle representation1 = T.Representation(type1);
268 TypeHandle semantic1 = T.Semantic(type1);
269 TypeHandle representation2 = T.Representation(type2);
270 TypeHandle semantic2 = T.Semantic(type2);
271 TypeHandle direct_union = T.Union(type1, type2);
272 TypeHandle representation_union =
273 T.Union(representation1, representation2);
274 TypeHandle semantic_union = T.Union(semantic1, semantic2);
275 TypeHandle composed_union =
276 T.Union(representation_union, semantic_union);
277 CHECK(direct_union->Equals(composed_union));
278 }
279 }
280
281 // Pointwiseness of Intersect.
282 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
283 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
284 TypeHandle type1 = *it1;
285 TypeHandle type2 = *it2;
286 TypeHandle representation1 = T.Representation(type1);
287 TypeHandle semantic1 = T.Semantic(type1);
288 TypeHandle representation2 = T.Representation(type2);
289 TypeHandle semantic2 = T.Semantic(type2);
290 TypeHandle direct_intersection = T.Intersect(type1, type2);
291 TypeHandle representation_intersection =
292 T.Intersect(representation1, representation2);
293 TypeHandle semantic_intersection = T.Intersect(semantic1, semantic2);
294 TypeHandle composed_intersection =
295 T.Union(representation_intersection, semantic_intersection);
296 CHECK(direct_intersection->Equals(composed_intersection));
297 }
298 }
299
300 // Pointwiseness of Is.
301 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
302 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
303 TypeHandle type1 = *it1;
304 TypeHandle type2 = *it2;
305 TypeHandle representation1 = T.Representation(type1);
306 TypeHandle semantic1 = T.Semantic(type1);
307 TypeHandle representation2 = T.Representation(type2);
308 TypeHandle semantic2 = T.Semantic(type2);
309 bool representation_is = representation1->Is(representation2);
310 bool semantic_is = semantic1->Is(semantic2);
311 bool direct_is = type1->Is(type2);
312 CHECK(direct_is == (semantic_is && representation_is));
313 }
314 }
315 }
316
248 void Class() { 317 void Class() {
249 // Constructor 318 // Constructor
250 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { 319 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) {
251 Handle<i::Map> map = *mt; 320 Handle<i::Map> map = *mt;
252 TypeHandle type = T.Class(map); 321 TypeHandle type = T.Class(map);
253 CHECK(type->IsClass()); 322 CHECK(type->IsClass());
254 } 323 }
255 324
256 // Map attribute 325 // Map attribute
257 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { 326 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) {
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 // Lub(Range(x,y))->Min() <= x and y <= Lub(Range(x,y))->Max() 719 // Lub(Range(x,y))->Min() <= x and y <= Lub(Range(x,y))->Max()
651 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 720 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
652 TypeHandle type = *it; 721 TypeHandle type = *it;
653 if (type->IsRange()) { 722 if (type->IsRange()) {
654 TypeHandle lub = Rep::BitsetType::New( 723 TypeHandle lub = Rep::BitsetType::New(
655 Rep::BitsetType::Lub(type), T.region()); 724 Rep::BitsetType::Lub(type), T.region());
656 CHECK(lub->Min() <= type->Min() && type->Max() <= lub->Max()); 725 CHECK(lub->Min() <= type->Min() && type->Max() <= lub->Max());
657 } 726 }
658 } 727 }
659 728
660 // Rangification: If T->Is(Range(-inf,+inf)) and !T->Is(None), then 729 // Rangification: If T->Is(Range(-inf,+inf)) and T is inhabited, then
661 // T->Is(Range(T->Min(), T->Max())). 730 // T->Is(Range(T->Min(), T->Max())).
662 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 731 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
663 TypeHandle type = *it; 732 TypeHandle type = *it;
664 CHECK(!(type->Is(T.Integer) && !type->Is(T.None)) || 733 CHECK(!type->Is(T.Integer) || !type->IsInhabited() ||
665 type->Is(T.Range(type->Min(), type->Max()))); 734 type->Is(T.Range(type->Min(), type->Max())));
666 } 735 }
667 } 736 }
668 737
669 void BitsetGlb() { 738 void BitsetGlb() {
670 // Lower: (T->BitsetGlb())->Is(T) 739 // Lower: (T->BitsetGlb())->Is(T)
671 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 740 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
672 TypeHandle type = *it; 741 TypeHandle type = *it;
673 TypeHandle glb = 742 TypeHandle glb =
674 Rep::BitsetType::New(Rep::BitsetType::Glb(type), T.region()); 743 Rep::BitsetType::New(Rep::BitsetType::Glb(type), T.region());
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 CHECK(!type1->Is(type2) || this->IsBitset(type2) || 863 CHECK(!type1->Is(type2) || this->IsBitset(type2) ||
795 this->IsUnion(type2) || this->IsUnion(type1) || 864 this->IsUnion(type2) || this->IsUnion(type1) ||
796 (type1->IsClass() && type2->IsClass()) || 865 (type1->IsClass() && type2->IsClass()) ||
797 (type1->IsConstant() && type2->IsConstant()) || 866 (type1->IsConstant() && type2->IsConstant()) ||
798 (type1->IsConstant() && type2->IsRange()) || 867 (type1->IsConstant() && type2->IsRange()) ||
799 (this->IsBitset(type1) && type2->IsRange()) || 868 (this->IsBitset(type1) && type2->IsRange()) ||
800 (type1->IsRange() && type2->IsRange()) || 869 (type1->IsRange() && type2->IsRange()) ||
801 (type1->IsContext() && type2->IsContext()) || 870 (type1->IsContext() && type2->IsContext()) ||
802 (type1->IsArray() && type2->IsArray()) || 871 (type1->IsArray() && type2->IsArray()) ||
803 (type1->IsFunction() && type2->IsFunction()) || 872 (type1->IsFunction() && type2->IsFunction()) ||
804 type1->Equals(T.None)); 873 !type1->IsInhabited());
805 } 874 }
806 } 875 }
807 } 876 }
808 877
809 void Is2() { 878 void Is2() {
810 // Class(M1)->Is(Class(M2)) iff M1 = M2 879 // Class(M1)->Is(Class(M2)) iff M1 = M2
811 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) { 880 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) {
812 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) { 881 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) {
813 Handle<i::Map> map1 = *mt1; 882 Handle<i::Map> map1 = *mt1;
814 Handle<i::Map> map2 = *mt2; 883 Handle<i::Map> map2 = *mt2;
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 CheckOverlap(T.NumberArray, T.Array); 1367 CheckOverlap(T.NumberArray, T.Array);
1299 CheckDisjoint(T.NumberArray, T.AnyArray); 1368 CheckDisjoint(T.NumberArray, T.AnyArray);
1300 CheckDisjoint(T.NumberArray, T.StringArray); 1369 CheckDisjoint(T.NumberArray, T.StringArray);
1301 CheckOverlap(T.MethodFunction, T.Object); 1370 CheckOverlap(T.MethodFunction, T.Object);
1302 CheckDisjoint(T.SignedFunction1, T.NumberFunction1); 1371 CheckDisjoint(T.SignedFunction1, T.NumberFunction1);
1303 CheckDisjoint(T.SignedFunction1, T.NumberFunction2); 1372 CheckDisjoint(T.SignedFunction1, T.NumberFunction2);
1304 CheckDisjoint(T.NumberFunction1, T.NumberFunction2); 1373 CheckDisjoint(T.NumberFunction1, T.NumberFunction2);
1305 CheckDisjoint(T.SignedFunction1, T.MethodFunction); 1374 CheckDisjoint(T.SignedFunction1, T.MethodFunction);
1306 CheckOverlap(T.ObjectConstant1, T.ObjectClass); // !!! 1375 CheckOverlap(T.ObjectConstant1, T.ObjectClass); // !!!
1307 CheckOverlap(T.ObjectConstant2, T.ObjectClass); // !!! 1376 CheckOverlap(T.ObjectConstant2, T.ObjectClass); // !!!
1308 CheckOverlap(T.NumberClass, T.Intersect(T.Number, T.Untagged)); // !!! 1377 CheckOverlap(T.NumberClass, T.Intersect(T.Number, T.Tagged)); // !!!
1309 } 1378 }
1310 1379
1311 void Union1() { 1380 void Union1() {
1312 // Identity: Union(T, None) = T 1381 // Identity: Union(T, None) = T
1313 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 1382 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
1314 TypeHandle type = *it; 1383 TypeHandle type = *it;
1315 TypeHandle union_type = T.Union(type, T.None); 1384 TypeHandle union_type = T.Union(type, T.None);
1316 CheckEqual(union_type, type); 1385 CheckEqual(union_type, type);
1317 } 1386 }
1318 1387
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1687 TypeHandle type3 = *it3; 1756 TypeHandle type3 = *it3;
1688 TypeHandle intersect23 = T.Intersect(type2, type3); 1757 TypeHandle intersect23 = T.Intersect(type2, type3);
1689 CHECK(!(type1->Is(type2) && type1->Is(type3)) || 1758 CHECK(!(type1->Is(type2) && type1->Is(type3)) ||
1690 type1->Is(intersect23)); 1759 type1->Is(intersect23));
1691 } 1760 }
1692 } 1761 }
1693 } 1762 }
1694 1763
1695 // Bitset-class 1764 // Bitset-class
1696 CheckEqual(T.Intersect(T.ObjectClass, T.Object), T.ObjectClass); 1765 CheckEqual(T.Intersect(T.ObjectClass, T.Object), T.ObjectClass);
1697 CheckEqual(T.Intersect(T.ObjectClass, T.Array), T.None); 1766 CheckEqual(T.Semantic(T.Intersect(T.ObjectClass, T.Array)), T.None);
1698 CheckEqual(T.Intersect(T.ObjectClass, T.Number), T.None); 1767 CheckEqual(T.Semantic(T.Intersect(T.ObjectClass, T.Number)), T.None);
1699 1768
1700 // Bitset-array 1769 // Bitset-array
1701 CheckEqual(T.Intersect(T.NumberArray, T.Object), T.NumberArray); 1770 CheckEqual(T.Intersect(T.NumberArray, T.Object), T.NumberArray);
1702 CheckEqual(T.Intersect(T.AnyArray, T.Proxy), T.None); 1771 CheckEqual(T.Semantic(T.Intersect(T.AnyArray, T.Proxy)), T.None);
1703 1772
1704 // Bitset-function 1773 // Bitset-function
1705 CheckEqual(T.Intersect(T.MethodFunction, T.Object), T.MethodFunction); 1774 CheckEqual(T.Intersect(T.MethodFunction, T.Object), T.MethodFunction);
1706 CheckEqual(T.Intersect(T.NumberFunction1, T.Proxy), T.None); 1775 CheckEqual(T.Semantic(T.Intersect(T.NumberFunction1, T.Proxy)), T.None);
1707 1776
1708 // Bitset-union 1777 // Bitset-union
1709 CheckEqual( 1778 CheckEqual(
1710 T.Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)), 1779 T.Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)),
1711 T.Union(T.ObjectConstant1, T.ObjectClass)); 1780 T.Union(T.ObjectConstant1, T.ObjectClass));
1712 CHECK( 1781 CheckEqual(T.Semantic(T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant1),
1713 !T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number) 1782 T.Number)),
1714 ->IsInhabited()); 1783 T.None);
1715 1784
1716 // Class-constant 1785 // Class-constant
1717 CHECK(T.Intersect(T.ObjectConstant1, T.ObjectClass)->IsInhabited()); // !!! 1786 CHECK(T.Intersect(T.ObjectConstant1, T.ObjectClass)->IsInhabited()); // !!!
1718 CHECK(!T.Intersect(T.ArrayClass, T.ObjectConstant2)->IsInhabited()); 1787 CHECK(!T.Intersect(T.ArrayClass, T.ObjectConstant2)->IsInhabited());
1719 1788
1720 // Array-union 1789 // Array-union
1721 CheckEqual( 1790 CheckEqual(
1722 T.Intersect(T.NumberArray, T.Union(T.NumberArray, T.ArrayClass)), 1791 T.Intersect(T.NumberArray, T.Union(T.NumberArray, T.ArrayClass)),
1723 T.NumberArray); 1792 T.NumberArray);
1724 CheckEqual( 1793 CheckEqual(
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 1929
1861 CHECK(type2->Min() == u->GetRange()->Min()); 1930 CHECK(type2->Min() == u->GetRange()->Min());
1862 CHECK(type2->Max() == u->GetRange()->Max()); 1931 CHECK(type2->Max() == u->GetRange()->Max());
1863 } 1932 }
1864 } 1933 }
1865 } 1934 }
1866 } 1935 }
1867 1936
1868 template<class Type2, class TypeHandle2, class Region2, class Rep2> 1937 template<class Type2, class TypeHandle2, class Region2, class Rep2>
1869 void Convert() { 1938 void Convert() {
1870 Types<Type2, TypeHandle2, Region2> T2( 1939 Types<Type2, TypeHandle2, Region2> T2(Rep2::ToRegion(&zone, isolate),
1871 Rep2::ToRegion(&zone, isolate), isolate); 1940 isolate,
1941 isolate->random_number_generator());
1872 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 1942 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
1873 TypeHandle type1 = *it; 1943 TypeHandle type1 = *it;
1874 TypeHandle2 type2 = T2.template Convert<Type>(type1); 1944 TypeHandle2 type2 = T2.template Convert<Type>(type1);
1875 TypeHandle type3 = T.template Convert<Type2>(type2); 1945 TypeHandle type3 = T.template Convert<Type2>(type2);
1876 CheckEqual(type1, type3); 1946 CheckEqual(type1, type3);
1877 } 1947 }
1878 } 1948 }
1879 1949
1880 void HTypeFromType() { 1950 void HTypeFromType() {
1881 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 1951 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
(...skipping 12 matching lines...) Expand all
1894 typedef Tests<HeapType, Handle<HeapType>, Isolate, HeapRep> HeapTests; 1964 typedef Tests<HeapType, Handle<HeapType>, Isolate, HeapRep> HeapTests;
1895 1965
1896 1966
1897 TEST(IsSomeType) { 1967 TEST(IsSomeType) {
1898 CcTest::InitializeVM(); 1968 CcTest::InitializeVM();
1899 ZoneTests().IsSomeType(); 1969 ZoneTests().IsSomeType();
1900 HeapTests().IsSomeType(); 1970 HeapTests().IsSomeType();
1901 } 1971 }
1902 1972
1903 1973
1974 TEST(PointwiseRepresentation) {
1975 CcTest::InitializeVM();
1976 // ZoneTests().PointwiseRepresentation();
1977 HeapTests().PointwiseRepresentation();
1978 }
1979
1980
1904 TEST(BitsetType) { 1981 TEST(BitsetType) {
1905 CcTest::InitializeVM(); 1982 CcTest::InitializeVM();
1906 ZoneTests().Bitset(); 1983 ZoneTests().Bitset();
1907 HeapTests().Bitset(); 1984 HeapTests().Bitset();
1908 } 1985 }
1909 1986
1910 1987
1911 TEST(ClassType) { 1988 TEST(ClassType) {
1912 CcTest::InitializeVM(); 1989 CcTest::InitializeVM();
1913 ZoneTests().Class(); 1990 ZoneTests().Class();
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
2076 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); 2153 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>();
2077 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); 2154 HeapTests().Convert<Type, Type*, Zone, ZoneRep>();
2078 } 2155 }
2079 2156
2080 2157
2081 TEST(HTypeFromType) { 2158 TEST(HTypeFromType) {
2082 CcTest::InitializeVM(); 2159 CcTest::InitializeVM();
2083 ZoneTests().HTypeFromType(); 2160 ZoneTests().HTypeFromType();
2084 HeapTests().HTypeFromType(); 2161 HeapTests().HTypeFromType();
2085 } 2162 }
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-typer.cc ('k') | test/cctest/types-fuzz.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698