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
3 // found in the LICENSE file.
4 
5 #include "src/builtins/builtins-utils.h"
6 #include "src/builtins/builtins.h"
7 #include "src/ic/handler-compiler.h"
8 #include "src/ic/ic.h"
9 #include "src/ic/keyed-store-generic.h"
10 
11 namespace v8 {
12 namespace internal {
13 
Generate_KeyedLoadIC_Megamorphic_TF(CodeStubAssembler * assembler)14 void Builtins::Generate_KeyedLoadIC_Megamorphic_TF(
15     CodeStubAssembler* assembler) {
16   typedef compiler::Node Node;
17   typedef LoadWithVectorDescriptor Descriptor;
18 
19   Node* receiver = assembler->Parameter(Descriptor::kReceiver);
20   Node* name = assembler->Parameter(Descriptor::kName);
21   Node* slot = assembler->Parameter(Descriptor::kSlot);
22   Node* vector = assembler->Parameter(Descriptor::kVector);
23   Node* context = assembler->Parameter(Descriptor::kContext);
24 
25   CodeStubAssembler::LoadICParameters p(context, receiver, name, slot, vector);
26   assembler->KeyedLoadICGeneric(&p);
27 }
28 
Generate_KeyedLoadIC_Miss(MacroAssembler * masm)29 void Builtins::Generate_KeyedLoadIC_Miss(MacroAssembler* masm) {
30   KeyedLoadIC::GenerateMiss(masm);
31 }
Generate_KeyedLoadIC_Slow(MacroAssembler * masm)32 void Builtins::Generate_KeyedLoadIC_Slow(MacroAssembler* masm) {
33   KeyedLoadIC::GenerateRuntimeGetProperty(masm);
34 }
35 
Generate_KeyedStoreIC_Megamorphic(MacroAssembler * masm)36 void Builtins::Generate_KeyedStoreIC_Megamorphic(MacroAssembler* masm) {
37   KeyedStoreIC::GenerateMegamorphic(masm, SLOPPY);
38 }
39 
Generate_KeyedStoreIC_Megamorphic_Strict(MacroAssembler * masm)40 void Builtins::Generate_KeyedStoreIC_Megamorphic_Strict(MacroAssembler* masm) {
41   KeyedStoreIC::GenerateMegamorphic(masm, STRICT);
42 }
43 
KeyedStoreICMegamorphic(CodeStubAssembler * assembler,LanguageMode mode)44 void KeyedStoreICMegamorphic(CodeStubAssembler* assembler, LanguageMode mode) {
45   typedef compiler::Node Node;
46   typedef StoreWithVectorDescriptor Descriptor;
47 
48   Node* receiver = assembler->Parameter(Descriptor::kReceiver);
49   Node* name = assembler->Parameter(Descriptor::kName);
50   Node* value = assembler->Parameter(Descriptor::kValue);
51   Node* slot = assembler->Parameter(Descriptor::kSlot);
52   Node* vector = assembler->Parameter(Descriptor::kVector);
53   Node* context = assembler->Parameter(Descriptor::kContext);
54 
55   CodeStubAssembler::StoreICParameters p(context, receiver, name, value, slot,
56                                          vector);
57   KeyedStoreGenericGenerator::Generate(assembler, &p, mode);
58 }
59 
Generate_KeyedStoreIC_Megamorphic_TF(CodeStubAssembler * assembler)60 void Builtins::Generate_KeyedStoreIC_Megamorphic_TF(
61     CodeStubAssembler* assembler) {
62   KeyedStoreICMegamorphic(assembler, SLOPPY);
63 }
64 
Generate_KeyedStoreIC_Megamorphic_Strict_TF(CodeStubAssembler * assembler)65 void Builtins::Generate_KeyedStoreIC_Megamorphic_Strict_TF(
66     CodeStubAssembler* assembler) {
67   KeyedStoreICMegamorphic(assembler, STRICT);
68 }
69 
Generate_KeyedStoreIC_Miss(MacroAssembler * masm)70 void Builtins::Generate_KeyedStoreIC_Miss(MacroAssembler* masm) {
71   KeyedStoreIC::GenerateMiss(masm);
72 }
73 
Generate_KeyedStoreIC_Slow(MacroAssembler * masm)74 void Builtins::Generate_KeyedStoreIC_Slow(MacroAssembler* masm) {
75   KeyedStoreIC::GenerateSlow(masm);
76 }
77 
Generate_LoadGlobalIC_Miss(CodeStubAssembler * assembler)78 void Builtins::Generate_LoadGlobalIC_Miss(CodeStubAssembler* assembler) {
79   typedef compiler::Node Node;
80   typedef LoadGlobalWithVectorDescriptor Descriptor;
81 
82   Node* slot = assembler->Parameter(Descriptor::kSlot);
83   Node* vector = assembler->Parameter(Descriptor::kVector);
84   Node* context = assembler->Parameter(Descriptor::kContext);
85 
86   assembler->TailCallRuntime(Runtime::kLoadGlobalIC_Miss, context, slot,
87                              vector);
88 }
89 
Generate_LoadGlobalIC_Slow(CodeStubAssembler * assembler)90 void Builtins::Generate_LoadGlobalIC_Slow(CodeStubAssembler* assembler) {
91   typedef compiler::Node Node;
92   typedef LoadGlobalWithVectorDescriptor Descriptor;
93 
94   Node* slot = assembler->Parameter(Descriptor::kSlot);
95   Node* vector = assembler->Parameter(Descriptor::kVector);
96   Node* context = assembler->Parameter(Descriptor::kContext);
97 
98   assembler->TailCallRuntime(Runtime::kLoadGlobalIC_Slow, context, slot,
99                              vector);
100 }
101 
Generate_LoadIC_Getter_ForDeopt(MacroAssembler * masm)102 void Builtins::Generate_LoadIC_Getter_ForDeopt(MacroAssembler* masm) {
103   NamedLoadHandlerCompiler::GenerateLoadViaGetterForDeopt(masm);
104 }
105 
Generate_LoadIC_Miss(CodeStubAssembler * assembler)106 void Builtins::Generate_LoadIC_Miss(CodeStubAssembler* assembler) {
107   typedef compiler::Node Node;
108   typedef LoadWithVectorDescriptor Descriptor;
109 
110   Node* receiver = assembler->Parameter(Descriptor::kReceiver);
111   Node* name = assembler->Parameter(Descriptor::kName);
112   Node* slot = assembler->Parameter(Descriptor::kSlot);
113   Node* vector = assembler->Parameter(Descriptor::kVector);
114   Node* context = assembler->Parameter(Descriptor::kContext);
115 
116   assembler->TailCallRuntime(Runtime::kLoadIC_Miss, context, receiver, name,
117                              slot, vector);
118 }
119 
Generate_LoadIC_Normal(MacroAssembler * masm)120 void Builtins::Generate_LoadIC_Normal(MacroAssembler* masm) {
121   LoadIC::GenerateNormal(masm);
122 }
123 
Generate_LoadIC_Slow(CodeStubAssembler * assembler)124 void Builtins::Generate_LoadIC_Slow(CodeStubAssembler* assembler) {
125   typedef compiler::Node Node;
126   typedef LoadWithVectorDescriptor Descriptor;
127 
128   Node* receiver = assembler->Parameter(Descriptor::kReceiver);
129   Node* name = assembler->Parameter(Descriptor::kName);
130   Node* context = assembler->Parameter(Descriptor::kContext);
131 
132   assembler->TailCallRuntime(Runtime::kGetProperty, context, receiver, name);
133 }
134 
Generate_StoreIC_Miss(CodeStubAssembler * assembler)135 void Builtins::Generate_StoreIC_Miss(CodeStubAssembler* assembler) {
136   typedef compiler::Node Node;
137   typedef StoreWithVectorDescriptor Descriptor;
138 
139   Node* receiver = assembler->Parameter(Descriptor::kReceiver);
140   Node* name = assembler->Parameter(Descriptor::kName);
141   Node* value = assembler->Parameter(Descriptor::kValue);
142   Node* slot = assembler->Parameter(Descriptor::kSlot);
143   Node* vector = assembler->Parameter(Descriptor::kVector);
144   Node* context = assembler->Parameter(Descriptor::kContext);
145 
146   assembler->TailCallRuntime(Runtime::kStoreIC_Miss, context, value, slot,
147                              vector, receiver, name);
148 }
149 
Generate_StoreIC_Normal(MacroAssembler * masm)150 void Builtins::Generate_StoreIC_Normal(MacroAssembler* masm) {
151   StoreIC::GenerateNormal(masm);
152 }
153 
Generate_StoreIC_Setter_ForDeopt(MacroAssembler * masm)154 void Builtins::Generate_StoreIC_Setter_ForDeopt(MacroAssembler* masm) {
155   NamedStoreHandlerCompiler::GenerateStoreViaSetterForDeopt(masm);
156 }
157 
158 namespace {
Generate_StoreIC_Slow(CodeStubAssembler * assembler,LanguageMode language_mode)159 void Generate_StoreIC_Slow(CodeStubAssembler* assembler,
160                            LanguageMode language_mode) {
161   typedef compiler::Node Node;
162   typedef StoreWithVectorDescriptor Descriptor;
163 
164   Node* receiver = assembler->Parameter(Descriptor::kReceiver);
165   Node* name = assembler->Parameter(Descriptor::kName);
166   Node* value = assembler->Parameter(Descriptor::kValue);
167   Node* context = assembler->Parameter(Descriptor::kContext);
168   Node* lang_mode = assembler->SmiConstant(Smi::FromInt(language_mode));
169 
170   // The slow case calls into the runtime to complete the store without causing
171   // an IC miss that would otherwise cause a transition to the generic stub.
172   assembler->TailCallRuntime(Runtime::kSetProperty, context, receiver, name,
173                              value, lang_mode);
174 }
175 }  // anonymous namespace
176 
Generate_StoreIC_SlowSloppy(CodeStubAssembler * assembler)177 void Builtins::Generate_StoreIC_SlowSloppy(CodeStubAssembler* assembler) {
178   Generate_StoreIC_Slow(assembler, SLOPPY);
179 }
180 
Generate_StoreIC_SlowStrict(CodeStubAssembler * assembler)181 void Builtins::Generate_StoreIC_SlowStrict(CodeStubAssembler* assembler) {
182   Generate_StoreIC_Slow(assembler, STRICT);
183 }
184 
185 }  // namespace internal
186 }  // namespace v8
187