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

Side by Side Diff: src/compiler/typer.cc

Issue 2107783004: [turbofan] Disallow typing for change/checked operators. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@TurboFan_RepresentationSelection_Typer
Patch Set: ReferenceEqual foo Created 4 years, 5 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
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 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 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/compiler/typer.h" 5 #include "src/compiler/typer.h"
6 6
7 #include "src/base/flags.h" 7 #include "src/base/flags.h"
8 #include "src/bootstrapper.h" 8 #include "src/bootstrapper.h"
9 #include "src/compilation-dependencies.h" 9 #include "src/compilation-dependencies.h"
10 #include "src/compiler/common-operator.h" 10 #include "src/compiler/common-operator.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 JS_SIMPLE_BINOP_LIST(DECLARE_CASE) 90 JS_SIMPLE_BINOP_LIST(DECLARE_CASE)
91 #undef DECLARE_CASE 91 #undef DECLARE_CASE
92 92
93 #define DECLARE_CASE(x) \ 93 #define DECLARE_CASE(x) \
94 case IrOpcode::k##x: \ 94 case IrOpcode::k##x: \
95 return UpdateType(node, Type##x(node)); 95 return UpdateType(node, Type##x(node));
96 DECLARE_CASE(Start) 96 DECLARE_CASE(Start)
97 DECLARE_CASE(IfException) 97 DECLARE_CASE(IfException)
98 // VALUE_OP_LIST without JS_SIMPLE_BINOP_LIST: 98 // VALUE_OP_LIST without JS_SIMPLE_BINOP_LIST:
99 COMMON_OP_LIST(DECLARE_CASE) 99 COMMON_OP_LIST(DECLARE_CASE)
100 SIMPLIFIED_OP_LIST(DECLARE_CASE) 100 SIMPLIFIED_COMPARE_BINOP_LIST(DECLARE_CASE)
101 SIMPLIFIED_OTHER_OP_LIST(DECLARE_CASE)
101 MACHINE_OP_LIST(DECLARE_CASE) 102 MACHINE_OP_LIST(DECLARE_CASE)
102 MACHINE_SIMD_OP_LIST(DECLARE_CASE) 103 MACHINE_SIMD_OP_LIST(DECLARE_CASE)
103 JS_SIMPLE_UNOP_LIST(DECLARE_CASE) 104 JS_SIMPLE_UNOP_LIST(DECLARE_CASE)
104 JS_OBJECT_OP_LIST(DECLARE_CASE) 105 JS_OBJECT_OP_LIST(DECLARE_CASE)
105 JS_CONTEXT_OP_LIST(DECLARE_CASE) 106 JS_CONTEXT_OP_LIST(DECLARE_CASE)
106 JS_OTHER_OP_LIST(DECLARE_CASE) 107 JS_OTHER_OP_LIST(DECLARE_CASE)
107 #undef DECLARE_CASE 108 #undef DECLARE_CASE
108 109
109 #define DECLARE_CASE(x) case IrOpcode::k##x: 110 #define DECLARE_CASE(x) case IrOpcode::k##x:
110 DECLARE_CASE(Loop) 111 DECLARE_CASE(Loop)
111 DECLARE_CASE(Branch) 112 DECLARE_CASE(Branch)
112 DECLARE_CASE(IfTrue) 113 DECLARE_CASE(IfTrue)
113 DECLARE_CASE(IfFalse) 114 DECLARE_CASE(IfFalse)
114 DECLARE_CASE(IfSuccess) 115 DECLARE_CASE(IfSuccess)
115 DECLARE_CASE(Switch) 116 DECLARE_CASE(Switch)
116 DECLARE_CASE(IfValue) 117 DECLARE_CASE(IfValue)
117 DECLARE_CASE(IfDefault) 118 DECLARE_CASE(IfDefault)
118 DECLARE_CASE(Merge) 119 DECLARE_CASE(Merge)
119 DECLARE_CASE(Deoptimize) 120 DECLARE_CASE(Deoptimize)
120 DECLARE_CASE(DeoptimizeIf) 121 DECLARE_CASE(DeoptimizeIf)
121 DECLARE_CASE(DeoptimizeUnless) 122 DECLARE_CASE(DeoptimizeUnless)
122 DECLARE_CASE(Return) 123 DECLARE_CASE(Return)
123 DECLARE_CASE(TailCall) 124 DECLARE_CASE(TailCall)
124 DECLARE_CASE(Terminate) 125 DECLARE_CASE(Terminate)
125 DECLARE_CASE(OsrNormalEntry) 126 DECLARE_CASE(OsrNormalEntry)
126 DECLARE_CASE(OsrLoopEntry) 127 DECLARE_CASE(OsrLoopEntry)
127 DECLARE_CASE(Throw) 128 DECLARE_CASE(Throw)
128 DECLARE_CASE(End) 129 DECLARE_CASE(End)
130 SIMPLIFIED_CHANGE_OP_LIST(DECLARE_CASE)
131 SIMPLIFIED_CHECKED_OP_LIST(DECLARE_CASE)
129 #undef DECLARE_CASE 132 #undef DECLARE_CASE
130 break; 133 break;
131 } 134 }
132 return NoChange(); 135 return NoChange();
133 } 136 }
134 137
135 Type* TypeNode(Node* node) { 138 Type* TypeNode(Node* node) {
136 switch (node->opcode()) { 139 switch (node->opcode()) {
137 #define DECLARE_CASE(x) \ 140 #define DECLARE_CASE(x) \
138 case IrOpcode::k##x: return TypeBinaryOp(node, x##Typer); 141 case IrOpcode::k##x: return TypeBinaryOp(node, x##Typer);
139 JS_SIMPLE_BINOP_LIST(DECLARE_CASE) 142 JS_SIMPLE_BINOP_LIST(DECLARE_CASE)
140 #undef DECLARE_CASE 143 #undef DECLARE_CASE
141 144
142 #define DECLARE_CASE(x) case IrOpcode::k##x: return Type##x(node); 145 #define DECLARE_CASE(x) case IrOpcode::k##x: return Type##x(node);
143 DECLARE_CASE(Start) 146 DECLARE_CASE(Start)
144 DECLARE_CASE(IfException) 147 DECLARE_CASE(IfException)
145 // VALUE_OP_LIST without JS_SIMPLE_BINOP_LIST: 148 // VALUE_OP_LIST without JS_SIMPLE_BINOP_LIST:
146 COMMON_OP_LIST(DECLARE_CASE) 149 COMMON_OP_LIST(DECLARE_CASE)
147 SIMPLIFIED_OP_LIST(DECLARE_CASE) 150 SIMPLIFIED_COMPARE_BINOP_LIST(DECLARE_CASE)
151 SIMPLIFIED_OTHER_OP_LIST(DECLARE_CASE)
148 MACHINE_OP_LIST(DECLARE_CASE) 152 MACHINE_OP_LIST(DECLARE_CASE)
149 MACHINE_SIMD_OP_LIST(DECLARE_CASE) 153 MACHINE_SIMD_OP_LIST(DECLARE_CASE)
150 JS_SIMPLE_UNOP_LIST(DECLARE_CASE) 154 JS_SIMPLE_UNOP_LIST(DECLARE_CASE)
151 JS_OBJECT_OP_LIST(DECLARE_CASE) 155 JS_OBJECT_OP_LIST(DECLARE_CASE)
152 JS_CONTEXT_OP_LIST(DECLARE_CASE) 156 JS_CONTEXT_OP_LIST(DECLARE_CASE)
153 JS_OTHER_OP_LIST(DECLARE_CASE) 157 JS_OTHER_OP_LIST(DECLARE_CASE)
154 #undef DECLARE_CASE 158 #undef DECLARE_CASE
155 159
156 #define DECLARE_CASE(x) case IrOpcode::k##x: 160 #define DECLARE_CASE(x) case IrOpcode::k##x:
157 DECLARE_CASE(Loop) 161 DECLARE_CASE(Loop)
158 DECLARE_CASE(Branch) 162 DECLARE_CASE(Branch)
159 DECLARE_CASE(IfTrue) 163 DECLARE_CASE(IfTrue)
160 DECLARE_CASE(IfFalse) 164 DECLARE_CASE(IfFalse)
161 DECLARE_CASE(IfSuccess) 165 DECLARE_CASE(IfSuccess)
162 DECLARE_CASE(Switch) 166 DECLARE_CASE(Switch)
163 DECLARE_CASE(IfValue) 167 DECLARE_CASE(IfValue)
164 DECLARE_CASE(IfDefault) 168 DECLARE_CASE(IfDefault)
165 DECLARE_CASE(Merge) 169 DECLARE_CASE(Merge)
166 DECLARE_CASE(Deoptimize) 170 DECLARE_CASE(Deoptimize)
167 DECLARE_CASE(DeoptimizeIf) 171 DECLARE_CASE(DeoptimizeIf)
168 DECLARE_CASE(DeoptimizeUnless) 172 DECLARE_CASE(DeoptimizeUnless)
169 DECLARE_CASE(Return) 173 DECLARE_CASE(Return)
170 DECLARE_CASE(TailCall) 174 DECLARE_CASE(TailCall)
171 DECLARE_CASE(Terminate) 175 DECLARE_CASE(Terminate)
172 DECLARE_CASE(OsrNormalEntry) 176 DECLARE_CASE(OsrNormalEntry)
173 DECLARE_CASE(OsrLoopEntry) 177 DECLARE_CASE(OsrLoopEntry)
174 DECLARE_CASE(Throw) 178 DECLARE_CASE(Throw)
175 DECLARE_CASE(End) 179 DECLARE_CASE(End)
180 SIMPLIFIED_CHANGE_OP_LIST(DECLARE_CASE)
181 SIMPLIFIED_CHECKED_OP_LIST(DECLARE_CASE)
176 #undef DECLARE_CASE 182 #undef DECLARE_CASE
177 break; 183 break;
178 } 184 }
179 UNREACHABLE(); 185 UNREACHABLE();
180 return nullptr; 186 return nullptr;
181 } 187 }
182 188
183 Type* TypeConstant(Handle<Object> value); 189 Type* TypeConstant(Handle<Object> value);
184 190
185 private: 191 private:
186 Typer* typer_; 192 Typer* typer_;
187 ZoneSet<NodeId> weakened_nodes_; 193 ZoneSet<NodeId> weakened_nodes_;
188 194
189 #define DECLARE_METHOD(x) inline Type* Type##x(Node* node); 195 #define DECLARE_METHOD(x) inline Type* Type##x(Node* node);
190 DECLARE_METHOD(Start) 196 DECLARE_METHOD(Start)
191 DECLARE_METHOD(IfException) 197 DECLARE_METHOD(IfException)
192 VALUE_OP_LIST(DECLARE_METHOD) 198 COMMON_OP_LIST(DECLARE_METHOD)
199 SIMPLIFIED_COMPARE_BINOP_LIST(DECLARE_METHOD)
200 SIMPLIFIED_OTHER_OP_LIST(DECLARE_METHOD)
201 MACHINE_OP_LIST(DECLARE_METHOD)
202 MACHINE_SIMD_OP_LIST(DECLARE_METHOD)
203 JS_OP_LIST(DECLARE_METHOD)
193 #undef DECLARE_METHOD 204 #undef DECLARE_METHOD
194 205
195 Type* TypeOrNone(Node* node) { 206 Type* TypeOrNone(Node* node) {
196 return NodeProperties::IsTyped(node) ? NodeProperties::GetType(node) 207 return NodeProperties::IsTyped(node) ? NodeProperties::GetType(node)
197 : Type::None(); 208 : Type::None();
198 } 209 }
199 210
200 Type* Operand(Node* node, int i) { 211 Type* Operand(Node* node, int i) {
201 Node* operand_node = NodeProperties::GetValueInput(node, i); 212 Node* operand_node = NodeProperties::GetValueInput(node, i);
202 return TypeOrNone(operand_node); 213 return TypeOrNone(operand_node);
(...skipping 1515 matching lines...) Expand 10 before | Expand all | Expand 10 after
1718 } 1729 }
1719 1730
1720 Type* Typer::Visitor::TypeStringFromCharCode(Node* node) { 1731 Type* Typer::Visitor::TypeStringFromCharCode(Node* node) {
1721 return TypeUnaryOp(node, StringFromCharCodeTyper); 1732 return TypeUnaryOp(node, StringFromCharCodeTyper);
1722 } 1733 }
1723 1734
1724 Type* Typer::Visitor::TypeStringToNumber(Node* node) { 1735 Type* Typer::Visitor::TypeStringToNumber(Node* node) {
1725 return TypeUnaryOp(node, ToNumber); 1736 return TypeUnaryOp(node, ToNumber);
1726 } 1737 }
1727 1738
1728 namespace {
1729
1730 Type* ChangeRepresentation(Type* type, Type* rep, Zone* zone) {
1731 return Type::Union(Type::Semantic(type, zone),
1732 Type::Representation(rep, zone), zone);
1733 }
1734
1735 } // namespace
1736
1737 Type* Typer::Visitor::TypeChangeTaggedSignedToInt32(Node* node) {
1738 Type* arg = Operand(node, 0);
1739 // TODO(jarin): DCHECK(arg->Is(Type::Signed32()));
1740 // Many tests fail this check.
1741 return ChangeRepresentation(arg, Type::UntaggedIntegral32(), zone());
1742 }
1743
1744 Type* Typer::Visitor::TypeChangeTaggedToInt32(Node* node) {
1745 Type* arg = Operand(node, 0);
1746 DCHECK(arg->Is(Type::Signed32()));
1747 return ChangeRepresentation(arg, Type::UntaggedIntegral32(), zone());
1748 }
1749
1750
1751 Type* Typer::Visitor::TypeChangeTaggedToUint32(Node* node) {
1752 Type* arg = Operand(node, 0);
1753 DCHECK(arg->Is(Type::Unsigned32()));
1754 return ChangeRepresentation(arg, Type::UntaggedIntegral32(), zone());
1755 }
1756
1757
1758 Type* Typer::Visitor::TypeChangeTaggedToFloat64(Node* node) {
1759 Type* arg = Operand(node, 0);
1760 DCHECK(arg->Is(Type::Number()));
1761 return ChangeRepresentation(arg, Type::UntaggedFloat64(), zone());
1762 }
1763
1764 Type* Typer::Visitor::TypeTruncateTaggedToFloat64(Node* node) {
1765 Type* arg = Operand(node, 0);
1766 // TODO(jarin) This DCHECK does not work because of speculative feedback.
1767 // Re-enable once we record the speculative feedback in types.
1768 // DCHECK(arg->Is(Type::NumberOrOddball()));
1769 return ChangeRepresentation(arg, Type::UntaggedFloat64(), zone());
1770 }
1771
1772 Type* Typer::Visitor::TypeChangeInt31ToTaggedSigned(Node* node) {
1773 Type* arg = Operand(node, 0);
1774 // TODO(jarin): DCHECK(arg->Is(Type::Signed31()));
1775 // Some mjsunit/asm and mjsunit/wasm tests fail this check.
1776 // For instance, asm/int32-umod fails with Signed32/UntaggedIntegral32 in
1777 // simplified-lowering (after propagation).
1778 Type* rep =
1779 arg->Is(Type::SignedSmall()) ? Type::TaggedSigned() : Type::Tagged();
1780 return ChangeRepresentation(arg, rep, zone());
1781 }
1782
1783 Type* Typer::Visitor::TypeChangeInt32ToTagged(Node* node) {
1784 Type* arg = Operand(node, 0);
1785 // TODO(jarin): DCHECK(arg->Is(Type::Signed32()));
1786 // Two tests fail this check: mjsunit/asm/sqlite3/sqlite-safe-heap and
1787 // mjsunit/wasm/embenchen/lua_binarytrees. The first one fails with Any/Any in
1788 // simplified-lowering (after propagation).
1789 Type* rep =
1790 arg->Is(Type::SignedSmall()) ? Type::TaggedSigned() : Type::Tagged();
1791 return ChangeRepresentation(arg, rep, zone());
1792 }
1793
1794 Type* Typer::Visitor::TypeChangeUint32ToTagged(Node* node) {
1795 Type* arg = Operand(node, 0);
1796 // TODO(jarin): DCHECK(arg->Is(Type::Unsigned32()));
1797 // This fails in benchmarks/octane/mandreel (--turbo).
1798 return ChangeRepresentation(arg, Type::Tagged(), zone());
1799 }
1800
1801 Type* Typer::Visitor::TypeChangeFloat64ToTagged(Node* node) {
1802 Type* arg = Operand(node, 0);
1803 // TODO(jarin): DCHECK(arg->Is(Type::Number()));
1804 // Some (or all) mjsunit/wasm/embenchen/ tests fail this check when run with
1805 // --turbo and --always-opt.
1806 return ChangeRepresentation(arg, Type::Tagged(), zone());
1807 }
1808
1809 Type* Typer::Visitor::TypeChangeTaggedToBit(Node* node) {
1810 Type* arg = Operand(node, 0);
1811 DCHECK(arg->Is(Type::Boolean()));
1812 return ChangeRepresentation(arg, Type::UntaggedBit(), zone());
1813 }
1814
1815 Type* Typer::Visitor::TypeChangeBitToTagged(Node* node) {
1816 Type* arg = Operand(node, 0);
1817 return ChangeRepresentation(arg, Type::TaggedPointer(), zone());
1818 }
1819
1820 Type* Typer::Visitor::TypeCheckBounds(Node* node) { 1739 Type* Typer::Visitor::TypeCheckBounds(Node* node) {
1821 // TODO(bmeurer): We could do better here based on the limit. 1740 // TODO(bmeurer): We could do better here based on the limit.
1822 return Type::Unsigned31(); 1741 return Type::Unsigned31();
1823 } 1742 }
1824 1743
1825 Type* Typer::Visitor::TypeCheckNumber(Node* node) { 1744 Type* Typer::Visitor::TypeCheckNumber(Node* node) {
1826 Type* arg = Operand(node, 0); 1745 Type* arg = Operand(node, 0);
1827 return Type::Intersect(arg, Type::Number(), zone()); 1746 return Type::Intersect(arg, Type::Number(), zone());
1828 } 1747 }
1829 1748
1830 Type* Typer::Visitor::TypeCheckTaggedPointer(Node* node) { 1749 Type* Typer::Visitor::TypeCheckTaggedPointer(Node* node) {
1831 Type* arg = Operand(node, 0); 1750 Type* arg = Operand(node, 0);
1832 return Type::Intersect(arg, Type::TaggedPointer(), zone()); 1751 return Type::Intersect(arg, Type::TaggedPointer(), zone());
1833 } 1752 }
1834 1753
1835 Type* Typer::Visitor::TypeCheckTaggedSigned(Node* node) { 1754 Type* Typer::Visitor::TypeCheckTaggedSigned(Node* node) {
1836 Type* arg = Operand(node, 0); 1755 Type* arg = Operand(node, 0);
1837 return Type::Intersect(arg, typer_->cache_.kSmi, zone()); 1756 return Type::Intersect(arg, typer_->cache_.kSmi, zone());
1838 } 1757 }
1839 1758
1840 Type* Typer::Visitor::TypeCheckedInt32Add(Node* node) {
1841 return Type::Integral32();
1842 }
1843
1844 Type* Typer::Visitor::TypeCheckedInt32Sub(Node* node) {
1845 return Type::Integral32();
1846 }
1847
1848 Type* Typer::Visitor::TypeCheckedUint32ToInt32(Node* node) {
1849 return Type::Signed32();
1850 }
1851
1852 Type* Typer::Visitor::TypeCheckedFloat64ToInt32(Node* node) {
1853 return Type::Signed32();
1854 }
1855
1856 Type* Typer::Visitor::TypeCheckedTaggedToInt32(Node* node) {
1857 return Type::Signed32();
1858 }
1859
1860 Type* Typer::Visitor::TypeCheckedTaggedToFloat64(Node* node) {
1861 return Type::Number();
1862 }
1863
1864 Type* Typer::Visitor::TypeCheckFloat64Hole(Node* node) { 1759 Type* Typer::Visitor::TypeCheckFloat64Hole(Node* node) {
1865 Type* type = Operand(node, 0); 1760 Type* type = Operand(node, 0);
1866 return type; 1761 return type;
1867 } 1762 }
1868 1763
1869 Type* Typer::Visitor::TypeCheckTaggedHole(Node* node) { 1764 Type* Typer::Visitor::TypeCheckTaggedHole(Node* node) {
1870 CheckTaggedHoleMode mode = CheckTaggedHoleModeOf(node->op()); 1765 CheckTaggedHoleMode mode = CheckTaggedHoleModeOf(node->op());
1871 Type* type = Operand(node, 0); 1766 Type* type = Operand(node, 0);
1872 type = Type::Intersect(type, Type::NonInternal(), zone()); 1767 type = Type::Intersect(type, Type::NonInternal(), zone());
1873 switch (mode) { 1768 switch (mode) {
1874 case CheckTaggedHoleMode::kConvertHoleToUndefined: { 1769 case CheckTaggedHoleMode::kConvertHoleToUndefined: {
1875 // The hole is turned into undefined. 1770 // The hole is turned into undefined.
1876 type = Type::Union(type, Type::Undefined(), zone()); 1771 type = Type::Union(type, Type::Undefined(), zone());
1877 break; 1772 break;
1878 } 1773 }
1879 case CheckTaggedHoleMode::kNeverReturnHole: { 1774 case CheckTaggedHoleMode::kNeverReturnHole: {
1880 // We deoptimize in case of the hole. 1775 // We deoptimize in case of the hole.
1881 break; 1776 break;
1882 } 1777 }
1883 } 1778 }
1884 return type; 1779 return type;
1885 } 1780 }
1886 1781
1887 Type* Typer::Visitor::TypeTruncateTaggedToWord32(Node* node) {
1888 Type* arg = Operand(node, 0);
1889 // TODO(jarin): DCHECK(arg->Is(Type::NumberOrUndefined()));
1890 // Several mjsunit and cctest tests fail this check. For instance,
1891 // mjsunit/compiler/regress-607493 fails with Any/Any in simplified-lowering
1892 // (after propagation).
1893 return ChangeRepresentation(arg, Type::UntaggedIntegral32(), zone());
1894 }
1895
1896 Type* Typer::Visitor::TypeAllocate(Node* node) { return Type::TaggedPointer(); } 1782 Type* Typer::Visitor::TypeAllocate(Node* node) { return Type::TaggedPointer(); }
1897 1783
1898 1784
1899 namespace { 1785 namespace {
1900 1786
1901 MaybeHandle<Map> GetStableMapFromObjectType(Type* object_type) { 1787 MaybeHandle<Map> GetStableMapFromObjectType(Type* object_type) {
1902 if (object_type->IsConstant() && 1788 if (object_type->IsConstant() &&
1903 object_type->AsConstant()->Value()->IsHeapObject()) { 1789 object_type->AsConstant()->Value()->IsHeapObject()) {
1904 Handle<Map> object_map( 1790 Handle<Map> object_map(
1905 Handle<HeapObject>::cast(object_type->AsConstant()->Value())->map()); 1791 Handle<HeapObject>::cast(object_type->AsConstant()->Value())->map());
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
2618 } 2504 }
2619 if (Type::IsInteger(*value)) { 2505 if (Type::IsInteger(*value)) {
2620 return Type::Range(value->Number(), value->Number(), zone()); 2506 return Type::Range(value->Number(), value->Number(), zone());
2621 } 2507 }
2622 return Type::Constant(value, zone()); 2508 return Type::Constant(value, zone());
2623 } 2509 }
2624 2510
2625 } // namespace compiler 2511 } // namespace compiler
2626 } // namespace internal 2512 } // namespace internal
2627 } // namespace v8 2513 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/simplified-operator-reducer.cc ('k') | test/cctest/compiler/test-simplified-lowering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698