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

Side by Side Diff: src/code-stub-assembler.h

Issue 2847923003: [csa] Add assertions to CSA (Closed)
Patch Set: Address comments Created 3 years, 7 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 | « no previous file | src/code-stub-assembler.cc » ('j') | src/code-stub-assembler.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 #ifndef V8_CODE_STUB_ASSEMBLER_H_ 5 #ifndef V8_CODE_STUB_ASSEMBLER_H_
6 #define V8_CODE_STUB_ASSEMBLER_H_ 6 #define V8_CODE_STUB_ASSEMBLER_H_
7 7
8 #include <functional> 8 #include <functional>
9 9
10 #include "src/compiler/code-assembler.h" 10 #include "src/compiler/code-assembler.h"
11 #include "src/globals.h" 11 #include "src/globals.h"
12 #include "src/objects.h" 12 #include "src/objects.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 16
17 class CallInterfaceDescriptor; 17 class CallInterfaceDescriptor;
18 class CodeStubArguments; 18 class CodeStubArguments;
19 class StatsCounter; 19 class StatsCounter;
20 class StubCache; 20 class StubCache;
21 21
22 #if defined(DEBUG) || defined(ENABLE_SLOW_DCHECKS)
23 #define CSA_ASSERT(csa, x) \
24 (csa)->Assert([&] { return (x); }, #x, __FILE__, __LINE__)
25 #define CSA_ASSERT_JS_ARGC_OP(csa, Op, op, expected) \
26 (csa)->Assert( \
27 [&] { \
28 compiler::Node* const argc = \
29 (csa)->Parameter(Descriptor::kActualArgumentsCount); \
30 return (csa)->Op(argc, (csa)->Int32Constant(expected)); \
31 }, \
32 "argc " #op " " #expected, __FILE__, __LINE__)
33
34 #define CSA_ASSERT_JS_ARGC_EQ(csa, expected) \
35 CSA_ASSERT_JS_ARGC_OP(csa, Word32Equal, ==, expected)
36
37 #define BIND(label) Bind(label, {#label, __FILE__, __LINE__})
38 #define VARIABLE(name, ...) \
39 Variable name(this, {#name, __FILE__, __LINE__}, __VA_ARGS__);
40
41 #else // DEBUG
42 #define CSA_ASSERT(csa, x) ((void)0)
43 #define CSA_ASSERT_JS_ARGC_EQ(csa, expected) ((void)0)
44 #define BIND(label) Bind(label);
45 #define VARIABLE(name, ...) Variable name(this, __VA_ARGS__);
46 #endif // DEBUG
47
48 #ifdef ENABLE_SLOW_DCHECKS
49 #define CSA_SLOW_ASSERT(csa, x) \
50 if (FLAG_enable_slow_asserts) { \
51 (csa)->Assert([&] { return (x); }, #x, __FILE__, __LINE__); \
52 }
53 #else
54 #define CSA_SLOW_ASSERT(csa, x) ((void)0)
55 #endif
56
22 enum class PrimitiveType { kBoolean, kNumber, kString, kSymbol }; 57 enum class PrimitiveType { kBoolean, kNumber, kString, kSymbol };
23 58
24 #define HEAP_CONSTANT_LIST(V) \ 59 #define HEAP_CONSTANT_LIST(V) \
25 V(AccessorInfoMap, AccessorInfoMap) \ 60 V(AccessorInfoMap, AccessorInfoMap) \
26 V(AccessorPairMap, AccessorPairMap) \ 61 V(AccessorPairMap, AccessorPairMap) \
27 V(AllocationSiteMap, AllocationSiteMap) \ 62 V(AllocationSiteMap, AllocationSiteMap) \
28 V(BooleanMap, BooleanMap) \ 63 V(BooleanMap, BooleanMap) \
29 V(CodeMap, CodeMap) \ 64 V(CodeMap, CodeMap) \
65 V(EmptyFixedArray, EmptyFixedArray) \
30 V(empty_string, EmptyString) \ 66 V(empty_string, EmptyString) \
31 V(length_string, LengthString) \
32 V(prototype_string, PrototypeString) \
33 V(EmptyFixedArray, EmptyFixedArray) \
34 V(FalseValue, False) \ 67 V(FalseValue, False) \
35 V(FixedArrayMap, FixedArrayMap) \ 68 V(FixedArrayMap, FixedArrayMap) \
36 V(FixedCOWArrayMap, FixedCOWArrayMap) \ 69 V(FixedCOWArrayMap, FixedCOWArrayMap) \
37 V(FixedDoubleArrayMap, FixedDoubleArrayMap) \ 70 V(FixedDoubleArrayMap, FixedDoubleArrayMap) \
38 V(FunctionTemplateInfoMap, FunctionTemplateInfoMap) \ 71 V(FunctionTemplateInfoMap, FunctionTemplateInfoMap) \
72 V(GlobalPropertyCellMap, PropertyCellMap) \
39 V(has_instance_symbol, HasInstanceSymbol) \ 73 V(has_instance_symbol, HasInstanceSymbol) \
40 V(HeapNumberMap, HeapNumberMap) \ 74 V(HeapNumberMap, HeapNumberMap) \
41 V(NoClosuresCellMap, NoClosuresCellMap) \ 75 V(length_string, LengthString) \
42 V(OneClosureCellMap, OneClosureCellMap) \
43 V(ManyClosuresCellMap, ManyClosuresCellMap) \ 76 V(ManyClosuresCellMap, ManyClosuresCellMap) \
77 V(MetaMap, MetaMap) \
44 V(MinusZeroValue, MinusZero) \ 78 V(MinusZeroValue, MinusZero) \
45 V(NanValue, Nan) \ 79 V(NanValue, Nan) \
80 V(NoClosuresCellMap, NoClosuresCellMap) \
46 V(NullValue, Null) \ 81 V(NullValue, Null) \
47 V(GlobalPropertyCellMap, PropertyCellMap) \ 82 V(OneClosureCellMap, OneClosureCellMap) \
83 V(prototype_string, PrototypeString) \
48 V(SymbolMap, SymbolMap) \ 84 V(SymbolMap, SymbolMap) \
49 V(TheHoleValue, TheHole) \ 85 V(TheHoleValue, TheHole) \
50 V(TrueValue, True) \ 86 V(TrueValue, True) \
51 V(Tuple2Map, Tuple2Map) \ 87 V(Tuple2Map, Tuple2Map) \
52 V(Tuple3Map, Tuple3Map) \ 88 V(Tuple3Map, Tuple3Map) \
53 V(UndefinedValue, Undefined) \ 89 V(UndefinedValue, Undefined) \
54 V(WeakCellMap, WeakCellMap) 90 V(WeakCellMap, WeakCellMap)
55 91
56 // Provides JavaScript-specific "macro-assembler" functionality on top of the 92 // Provides JavaScript-specific "macro-assembler" functionality on top of the
57 // CodeAssembler. By factoring the JavaScript-isms out of the CodeAssembler, 93 // CodeAssembler. By factoring the JavaScript-isms out of the CodeAssembler,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 Node* ParameterToTagged(Node* value, ParameterMode mode) { 143 Node* ParameterToTagged(Node* value, ParameterMode mode) {
108 if (mode != SMI_PARAMETERS) value = SmiTag(value); 144 if (mode != SMI_PARAMETERS) value = SmiTag(value);
109 return value; 145 return value;
110 } 146 }
111 147
112 Node* TaggedToParameter(Node* value, ParameterMode mode) { 148 Node* TaggedToParameter(Node* value, ParameterMode mode) {
113 if (mode != SMI_PARAMETERS) value = SmiUntag(value); 149 if (mode != SMI_PARAMETERS) value = SmiUntag(value);
114 return value; 150 return value;
115 } 151 }
116 152
153 Node* MatchesParameterMode(Node* value, ParameterMode mode);
154
117 #define PARAMETER_BINOP(OpName, IntPtrOpName, SmiOpName) \ 155 #define PARAMETER_BINOP(OpName, IntPtrOpName, SmiOpName) \
118 Node* OpName(Node* a, Node* b, ParameterMode mode) { \ 156 Node* OpName(Node* a, Node* b, ParameterMode mode) { \
119 if (mode == SMI_PARAMETERS) { \ 157 if (mode == SMI_PARAMETERS) { \
120 return SmiOpName(a, b); \ 158 return SmiOpName(a, b); \
121 } else { \ 159 } else { \
122 DCHECK_EQ(INTPTR_PARAMETERS, mode); \ 160 DCHECK_EQ(INTPTR_PARAMETERS, mode); \
123 return IntPtrOpName(a, b); \ 161 return IntPtrOpName(a, b); \
124 } \ 162 } \
125 } 163 }
126 PARAMETER_BINOP(IntPtrOrSmiMin, IntPtrMin, SmiMin) 164 PARAMETER_BINOP(IntPtrOrSmiMin, IntPtrMin, SmiMin)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // Smi conversions. 213 // Smi conversions.
176 Node* SmiToFloat64(Node* value); 214 Node* SmiToFloat64(Node* value);
177 Node* SmiFromWord(Node* value) { return SmiTag(value); } 215 Node* SmiFromWord(Node* value) { return SmiTag(value); }
178 Node* SmiFromWord32(Node* value); 216 Node* SmiFromWord32(Node* value);
179 Node* SmiToWord(Node* value) { return SmiUntag(value); } 217 Node* SmiToWord(Node* value) { return SmiUntag(value); }
180 Node* SmiToWord32(Node* value); 218 Node* SmiToWord32(Node* value);
181 219
182 // Smi operations. 220 // Smi operations.
183 #define SMI_ARITHMETIC_BINOP(SmiOpName, IntPtrOpName) \ 221 #define SMI_ARITHMETIC_BINOP(SmiOpName, IntPtrOpName) \
184 Node* SmiOpName(Node* a, Node* b) { \ 222 Node* SmiOpName(Node* a, Node* b) { \
223 CSA_SLOW_ASSERT(this, TaggedIsSmi(a)); \
224 CSA_SLOW_ASSERT(this, TaggedIsSmi(b)); \
185 return BitcastWordToTaggedSigned( \ 225 return BitcastWordToTaggedSigned( \
186 IntPtrOpName(BitcastTaggedToWord(a), BitcastTaggedToWord(b))); \ 226 IntPtrOpName(BitcastTaggedToWord(a), BitcastTaggedToWord(b))); \
187 } 227 }
188 SMI_ARITHMETIC_BINOP(SmiAdd, IntPtrAdd) 228 SMI_ARITHMETIC_BINOP(SmiAdd, IntPtrAdd)
189 SMI_ARITHMETIC_BINOP(SmiSub, IntPtrSub) 229 SMI_ARITHMETIC_BINOP(SmiSub, IntPtrSub)
190 SMI_ARITHMETIC_BINOP(SmiAnd, WordAnd) 230 SMI_ARITHMETIC_BINOP(SmiAnd, WordAnd)
191 SMI_ARITHMETIC_BINOP(SmiOr, WordOr) 231 SMI_ARITHMETIC_BINOP(SmiOr, WordOr)
192 #undef SMI_ARITHMETIC_BINOP 232 #undef SMI_ARITHMETIC_BINOP
193 233
194 Node* SmiShl(Node* a, int shift) { 234 Node* SmiShl(Node* a, int shift) {
235 CSA_SLOW_ASSERT(this, TaggedIsSmi(a));
195 return BitcastWordToTaggedSigned(WordShl(BitcastTaggedToWord(a), shift)); 236 return BitcastWordToTaggedSigned(WordShl(BitcastTaggedToWord(a), shift));
196 } 237 }
197 238
198 Node* SmiShr(Node* a, int shift) { 239 Node* SmiShr(Node* a, int shift) {
240 CSA_SLOW_ASSERT(this, TaggedIsSmi(a));
199 return BitcastWordToTaggedSigned( 241 return BitcastWordToTaggedSigned(
200 WordAnd(WordShr(BitcastTaggedToWord(a), shift), 242 WordAnd(WordShr(BitcastTaggedToWord(a), shift),
201 BitcastTaggedToWord(SmiConstant(-1)))); 243 BitcastTaggedToWord(SmiConstant(-1))));
202 } 244 }
203 245
204 Node* WordOrSmiShl(Node* a, int shift, ParameterMode mode) { 246 Node* WordOrSmiShl(Node* a, int shift, ParameterMode mode) {
205 if (mode == SMI_PARAMETERS) { 247 if (mode == SMI_PARAMETERS) {
206 return SmiShl(a, shift); 248 return SmiShl(a, shift);
207 } else { 249 } else {
208 DCHECK_EQ(INTPTR_PARAMETERS, mode); 250 DCHECK_EQ(INTPTR_PARAMETERS, mode);
209 return WordShl(a, shift); 251 return WordShl(a, shift);
210 } 252 }
211 } 253 }
212 254
213 Node* WordOrSmiShr(Node* a, int shift, ParameterMode mode) { 255 Node* WordOrSmiShr(Node* a, int shift, ParameterMode mode) {
214 if (mode == SMI_PARAMETERS) { 256 if (mode == SMI_PARAMETERS) {
215 return SmiShr(a, shift); 257 return SmiShr(a, shift);
216 } else { 258 } else {
217 DCHECK_EQ(INTPTR_PARAMETERS, mode); 259 DCHECK_EQ(INTPTR_PARAMETERS, mode);
218 return WordShr(a, shift); 260 return WordShr(a, shift);
219 } 261 }
220 } 262 }
221 263
222 #define SMI_COMPARISON_OP(SmiOpName, IntPtrOpName) \ 264 #define SMI_COMPARISON_OP(SmiOpName, IntPtrOpName) \
223 Node* SmiOpName(Node* a, Node* b) { \ 265 Node* SmiOpName(Node* a, Node* b) { \
266 CSA_SLOW_ASSERT(this, TaggedIsSmi(a)); \
267 CSA_SLOW_ASSERT(this, TaggedIsSmi(b)); \
224 return IntPtrOpName(BitcastTaggedToWord(a), BitcastTaggedToWord(b)); \ 268 return IntPtrOpName(BitcastTaggedToWord(a), BitcastTaggedToWord(b)); \
225 } 269 }
226 SMI_COMPARISON_OP(SmiEqual, WordEqual) 270 SMI_COMPARISON_OP(SmiEqual, WordEqual)
227 SMI_COMPARISON_OP(SmiNotEqual, WordNotEqual) 271 SMI_COMPARISON_OP(SmiNotEqual, WordNotEqual)
228 SMI_COMPARISON_OP(SmiAbove, UintPtrGreaterThan) 272 SMI_COMPARISON_OP(SmiAbove, UintPtrGreaterThan)
229 SMI_COMPARISON_OP(SmiAboveOrEqual, UintPtrGreaterThanOrEqual) 273 SMI_COMPARISON_OP(SmiAboveOrEqual, UintPtrGreaterThanOrEqual)
230 SMI_COMPARISON_OP(SmiBelow, UintPtrLessThan) 274 SMI_COMPARISON_OP(SmiBelow, UintPtrLessThan)
231 SMI_COMPARISON_OP(SmiLessThan, IntPtrLessThan) 275 SMI_COMPARISON_OP(SmiLessThan, IntPtrLessThan)
232 SMI_COMPARISON_OP(SmiLessThanOrEqual, IntPtrLessThanOrEqual) 276 SMI_COMPARISON_OP(SmiLessThanOrEqual, IntPtrLessThanOrEqual)
233 SMI_COMPARISON_OP(SmiGreaterThan, IntPtrGreaterThan) 277 SMI_COMPARISON_OP(SmiGreaterThan, IntPtrGreaterThan)
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 Node* IsHeapNumber(Node* object); 798 Node* IsHeapNumber(Node* object);
755 Node* IsName(Node* object); 799 Node* IsName(Node* object);
756 Node* IsSymbol(Node* object); 800 Node* IsSymbol(Node* object);
757 Node* IsPrivateSymbol(Node* object); 801 Node* IsPrivateSymbol(Node* object);
758 Node* IsJSValueInstanceType(Node* instance_type); 802 Node* IsJSValueInstanceType(Node* instance_type);
759 Node* IsJSValue(Node* object); 803 Node* IsJSValue(Node* object);
760 Node* IsJSValueMap(Node* map); 804 Node* IsJSValueMap(Node* map);
761 Node* IsJSArrayInstanceType(Node* instance_type); 805 Node* IsJSArrayInstanceType(Node* instance_type);
762 Node* IsJSArray(Node* object); 806 Node* IsJSArray(Node* object);
763 Node* IsJSArrayMap(Node* object); 807 Node* IsJSArrayMap(Node* object);
808 Node* IsFixedArray(Node* object);
809 Node* IsFixedArrayWithKind(Node* object, ElementsKind kind);
764 Node* IsNativeContext(Node* object); 810 Node* IsNativeContext(Node* object);
765 Node* IsWeakCell(Node* object); 811 Node* IsWeakCell(Node* object);
766 Node* IsFixedDoubleArray(Node* object); 812 Node* IsFixedDoubleArray(Node* object);
767 Node* IsHashTable(Node* object); 813 Node* IsHashTable(Node* object);
768 Node* IsDictionary(Node* object); 814 Node* IsDictionary(Node* object);
769 Node* IsUnseededNumberDictionary(Node* object); 815 Node* IsUnseededNumberDictionary(Node* object);
770 Node* IsConstructorMap(Node* map); 816 Node* IsConstructorMap(Node* map);
771 Node* IsJSFunctionInstanceType(Node* instance_type); 817 Node* IsJSFunctionInstanceType(Node* instance_type);
772 Node* IsJSFunction(Node* object); 818 Node* IsJSFunction(Node* object);
773 Node* IsJSFunctionMap(Node* object); 819 Node* IsJSFunctionMap(Node* object);
(...skipping 22 matching lines...) Expand all
796 // Return the single character string with only {code}. 842 // Return the single character string with only {code}.
797 Node* StringFromCharCode(Node* code); 843 Node* StringFromCharCode(Node* code);
798 // Return a new string object which holds a substring containing the range 844 // Return a new string object which holds a substring containing the range
799 // [from,to[ of string. |from| and |to| are expected to be tagged. 845 // [from,to[ of string. |from| and |to| are expected to be tagged.
800 Node* SubString(Node* context, Node* string, Node* from, Node* to); 846 Node* SubString(Node* context, Node* string, Node* from, Node* to);
801 847
802 // Return a new string object produced by concatenating |first| with |second|. 848 // Return a new string object produced by concatenating |first| with |second|.
803 Node* StringAdd(Node* context, Node* first, Node* second, 849 Node* StringAdd(Node* context, Node* first, Node* second,
804 AllocationFlags flags = kNone); 850 AllocationFlags flags = kNone);
805 851
806 // Unpack the external string, returning a pointer that (offset-wise) looks
807 // like a sequential string.
808 // Note that this pointer is not tagged and does not point to a real
809 // sequential string instance, and may only be used to access the string
810 // data. The pointer is GC-safe as long as a reference to the container
811 // ExternalString is live.
812 // |string| must be an external string. Bailout for short external strings.
813 Node* TryDerefExternalString(Node* const string, Node* const instance_type,
814 Label* if_bailout);
815
816 // Check if |var_string| has an indirect (thin or flat cons) string type, 852 // Check if |var_string| has an indirect (thin or flat cons) string type,
817 // and unpack it if so. 853 // and unpack it if so.
818 void MaybeDerefIndirectString(Variable* var_string, Node* instance_type, 854 void MaybeDerefIndirectString(Variable* var_string, Node* instance_type,
819 Variable* var_did_something); 855 Variable* var_did_something);
820 // Check if |var_left| or |var_right| has an indirect (thin or flat cons) 856 // Check if |var_left| or |var_right| has an indirect (thin or flat cons)
821 // string type, and unpack it/them if so. Fall through if nothing was done. 857 // string type, and unpack it/them if so. Fall through if nothing was done.
822 void MaybeDerefIndirectStrings(Variable* var_left, Node* left_instance_type, 858 void MaybeDerefIndirectStrings(Variable* var_left, Node* left_instance_type,
823 Variable* var_right, Node* right_instance_type, 859 Variable* var_right, Node* right_instance_type,
824 Label* did_something); 860 Label* did_something);
825 861
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 1585
1550 private: 1586 private:
1551 Node* TryToSequential(StringPointerKind ptr_kind, Label* if_bailout); 1587 Node* TryToSequential(StringPointerKind ptr_kind, Label* if_bailout);
1552 1588
1553 Variable var_string_; 1589 Variable var_string_;
1554 Variable var_instance_type_; 1590 Variable var_instance_type_;
1555 Variable var_offset_; 1591 Variable var_offset_;
1556 Variable var_is_external_; 1592 Variable var_is_external_;
1557 }; 1593 };
1558 1594
1559 #ifdef DEBUG
1560 #define CSA_ASSERT(csa, x) \
1561 (csa)->Assert([&] { return (x); }, #x, __FILE__, __LINE__)
1562 #define CSA_ASSERT_JS_ARGC_OP(csa, Op, op, expected) \
1563 (csa)->Assert( \
1564 [&] { \
1565 compiler::Node* const argc = \
1566 (csa)->Parameter(Descriptor::kActualArgumentsCount); \
1567 return (csa)->Op(argc, (csa)->Int32Constant(expected)); \
1568 }, \
1569 "argc " #op " " #expected, __FILE__, __LINE__)
1570
1571 #define CSA_ASSERT_JS_ARGC_EQ(csa, expected) \
1572 CSA_ASSERT_JS_ARGC_OP(csa, Word32Equal, ==, expected)
1573
1574 #define BIND(label) Bind(label, {#label, __FILE__, __LINE__})
1575 #define VARIABLE(name, ...) \
1576 Variable name(this, {#name, __FILE__, __LINE__}, __VA_ARGS__);
1577
1578 #else // DEBUG
1579 #define CSA_ASSERT(csa, x) ((void)0)
1580 #define CSA_ASSERT_JS_ARGC_EQ(csa, expected) ((void)0)
1581 #define BIND(label) Bind(label);
1582 #define VARIABLE(name, ...) Variable name(this, __VA_ARGS__);
1583 #endif // DEBUG
1584
1585 #ifdef ENABLE_SLOW_DCHECKS
1586 #define CSA_SLOW_ASSERT(csa, x) \
1587 if (FLAG_enable_slow_asserts) { \
1588 (csa)->Assert([&] { return (x); }, #x, __FILE__, __LINE__); \
1589 }
1590 #else
1591 #define CSA_SLOW_ASSERT(csa, x) ((void)0)
1592 #endif
1593
1594 DEFINE_OPERATORS_FOR_FLAGS(CodeStubAssembler::AllocationFlags); 1595 DEFINE_OPERATORS_FOR_FLAGS(CodeStubAssembler::AllocationFlags);
1595 1596
1596 } // namespace internal 1597 } // namespace internal
1597 } // namespace v8 1598 } // namespace v8
1598 #endif // V8_CODE_STUB_ASSEMBLER_H_ 1599 #endif // V8_CODE_STUB_ASSEMBLER_H_
OLDNEW
« no previous file with comments | « no previous file | src/code-stub-assembler.cc » ('j') | src/code-stub-assembler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698