OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. |
6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
7 | 7 |
8 #include "vm/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
9 | 9 |
10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
(...skipping 2033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2044 locs->set_in(0, Location::RegisterLocation(RAX)); | 2044 locs->set_in(0, Location::RegisterLocation(RAX)); |
2045 locs->set_out(Location::RegisterLocation(RAX)); | 2045 locs->set_out(Location::RegisterLocation(RAX)); |
2046 return locs; | 2046 return locs; |
2047 } | 2047 } |
2048 | 2048 |
2049 | 2049 |
2050 void InstantiateTypeArgumentsInstr::EmitNativeCode( | 2050 void InstantiateTypeArgumentsInstr::EmitNativeCode( |
2051 FlowGraphCompiler* compiler) { | 2051 FlowGraphCompiler* compiler) { |
2052 Register instantiator_reg = locs()->in(0).reg(); | 2052 Register instantiator_reg = locs()->in(0).reg(); |
2053 Register result_reg = locs()->out().reg(); | 2053 Register result_reg = locs()->out().reg(); |
| 2054 ASSERT(instantiator_reg == RAX); |
| 2055 ASSERT(instantiator_reg == result_reg); |
2054 | 2056 |
2055 // 'instantiator_reg' is the instantiator TypeArguments object (or null). | 2057 // 'instantiator_reg' is the instantiator TypeArguments object (or null). |
2056 ASSERT(!type_arguments().IsUninstantiatedIdentity() && | 2058 ASSERT(!type_arguments().IsUninstantiatedIdentity() && |
2057 !type_arguments().CanShareInstantiatorTypeArguments( | 2059 !type_arguments().CanShareInstantiatorTypeArguments( |
2058 instantiator_class())); | 2060 instantiator_class())); |
2059 // If the instantiator is null and if the type argument vector | 2061 // If the instantiator is null and if the type argument vector |
2060 // instantiated from null becomes a vector of dynamic, then use null as | 2062 // instantiated from null becomes a vector of dynamic, then use null as |
2061 // the type arguments. | 2063 // the type arguments. |
2062 Label type_arguments_instantiated; | 2064 Label type_arguments_instantiated; |
2063 const intptr_t len = type_arguments().Length(); | 2065 const intptr_t len = type_arguments().Length(); |
2064 if (type_arguments().IsRawInstantiatedRaw(len)) { | 2066 if (type_arguments().IsRawInstantiatedRaw(len)) { |
2065 __ CompareObject(instantiator_reg, Object::null_object(), PP); | 2067 __ CompareObject(instantiator_reg, Object::null_object(), PP); |
2066 __ j(EQUAL, &type_arguments_instantiated, Assembler::kNearJump); | 2068 __ j(EQUAL, &type_arguments_instantiated, Assembler::kNearJump); |
2067 } | 2069 } |
| 2070 |
| 2071 // Lookup cache before calling runtime. |
| 2072 // TODO(fschneider): Consider moving this into a shared stub to reduce |
| 2073 // generated code size. |
| 2074 __ LoadObject(RDI, type_arguments(), PP); |
| 2075 __ movq(RDI, FieldAddress(RDI, TypeArguments::instantiations_offset())); |
| 2076 __ movq(RBX, FieldAddress(RDI, Array::length_offset())); |
| 2077 __ leaq(RDI, FieldAddress(RDI, Array::data_offset())); |
| 2078 __ leaq(RBX, Address(RDI, RBX, TIMES_2, 0)); // RBX is smi. |
| 2079 Label loop, found, slow_case; |
| 2080 __ Bind(&loop); |
| 2081 __ cmpq(RDI, RBX); |
| 2082 __ j(ABOVE_EQUAL, &slow_case); |
| 2083 __ movq(RDX, Address(RDI, 0 * kWordSize)); // Cached instantiator. |
| 2084 __ cmpq(RDX, RAX); |
| 2085 __ j(EQUAL, &found, Assembler::kNearJump); |
| 2086 __ cmpq(RDX, Immediate(Smi::RawValue(StubCode::kNoInstantiator))); |
| 2087 __ j(EQUAL, &slow_case); |
| 2088 __ addq(RDI, Immediate(2 * kWordSize)); |
| 2089 __ jmp(&loop, Assembler::kNearJump); |
| 2090 __ Bind(&found); |
| 2091 __ movq(RAX, Address(RDI, 1 * kWordSize)); // Cached instantiated args. |
| 2092 __ jmp(&type_arguments_instantiated); |
| 2093 |
| 2094 __ Bind(&slow_case); |
2068 // Instantiate non-null type arguments. | 2095 // Instantiate non-null type arguments. |
2069 // A runtime call to instantiate the type arguments is required. | 2096 // A runtime call to instantiate the type arguments is required. |
2070 __ PushObject(Object::ZoneHandle(), PP); // Make room for the result. | 2097 __ PushObject(Object::ZoneHandle(), PP); // Make room for the result. |
2071 __ PushObject(type_arguments(), PP); | 2098 __ PushObject(type_arguments(), PP); |
2072 __ pushq(instantiator_reg); // Push instantiator type arguments. | 2099 __ pushq(instantiator_reg); // Push instantiator type arguments. |
2073 compiler->GenerateRuntimeCall(token_pos(), | 2100 compiler->GenerateRuntimeCall(token_pos(), |
2074 deopt_id(), | 2101 deopt_id(), |
2075 kInstantiateTypeArgumentsRuntimeEntry, | 2102 kInstantiateTypeArgumentsRuntimeEntry, |
2076 2, | 2103 2, |
2077 locs()); | 2104 locs()); |
2078 __ Drop(2); // Drop instantiator and uninstantiated type arguments. | 2105 __ Drop(2); // Drop instantiator and uninstantiated type arguments. |
2079 __ popq(result_reg); // Pop instantiated type arguments. | 2106 __ popq(result_reg); // Pop instantiated type arguments. |
2080 __ Bind(&type_arguments_instantiated); | 2107 __ Bind(&type_arguments_instantiated); |
2081 ASSERT(instantiator_reg == result_reg); | 2108 ASSERT(instantiator_reg == result_reg); |
2082 } | 2109 } |
2083 | 2110 |
2084 | 2111 |
2085 LocationSummary* | |
2086 ExtractConstructorTypeArgumentsInstr::MakeLocationSummary(bool opt) const { | |
2087 const intptr_t kNumInputs = 1; | |
2088 const intptr_t kNumTemps = 0; | |
2089 LocationSummary* locs = | |
2090 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); | |
2091 locs->set_in(0, Location::RequiresRegister()); | |
2092 locs->set_out(Location::SameAsFirstInput()); | |
2093 return locs; | |
2094 } | |
2095 | |
2096 | |
2097 void ExtractConstructorTypeArgumentsInstr::EmitNativeCode( | |
2098 FlowGraphCompiler* compiler) { | |
2099 Register instantiator_reg = locs()->in(0).reg(); | |
2100 Register result_reg = locs()->out().reg(); | |
2101 ASSERT(instantiator_reg == result_reg); | |
2102 | |
2103 // instantiator_reg is the instantiator type argument vector, | |
2104 // i.e. a TypeArguments object (or null). | |
2105 ASSERT(!type_arguments().IsUninstantiatedIdentity() && | |
2106 !type_arguments().CanShareInstantiatorTypeArguments( | |
2107 instantiator_class())); | |
2108 // If the instantiator is null and if the type argument vector | |
2109 // instantiated from null becomes a vector of dynamic, then use null as | |
2110 // the type arguments. | |
2111 Label type_arguments_instantiated; | |
2112 ASSERT(type_arguments().IsRawInstantiatedRaw(type_arguments().Length())); | |
2113 | |
2114 __ CompareObject(instantiator_reg, Object::null_object(), PP); | |
2115 __ j(EQUAL, &type_arguments_instantiated, Assembler::kNearJump); | |
2116 // Instantiate non-null type arguments. | |
2117 // In the non-factory case, we rely on the allocation stub to | |
2118 // instantiate the type arguments. | |
2119 __ LoadObject(result_reg, type_arguments(), PP); | |
2120 // result_reg: uninstantiated type arguments. | |
2121 | |
2122 __ Bind(&type_arguments_instantiated); | |
2123 // result_reg: uninstantiated or instantiated type arguments. | |
2124 } | |
2125 | |
2126 | |
2127 LocationSummary* | |
2128 ExtractConstructorInstantiatorInstr::MakeLocationSummary(bool opt) const { | |
2129 const intptr_t kNumInputs = 1; | |
2130 const intptr_t kNumTemps = 0; | |
2131 LocationSummary* locs = | |
2132 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); | |
2133 locs->set_in(0, Location::RequiresRegister()); | |
2134 locs->set_out(Location::SameAsFirstInput()); | |
2135 return locs; | |
2136 } | |
2137 | |
2138 | |
2139 void ExtractConstructorInstantiatorInstr::EmitNativeCode( | |
2140 FlowGraphCompiler* compiler) { | |
2141 Register instantiator_reg = locs()->in(0).reg(); | |
2142 ASSERT(locs()->out().reg() == instantiator_reg); | |
2143 | |
2144 // instantiator_reg is the instantiator TypeArguments object (or null). | |
2145 ASSERT(!type_arguments().IsUninstantiatedIdentity() && | |
2146 !type_arguments().CanShareInstantiatorTypeArguments( | |
2147 instantiator_class())); | |
2148 | |
2149 // If the instantiator is null and if the type argument vector | |
2150 // instantiated from null becomes a vector of dynamic, then use null as | |
2151 // the type arguments and do not pass the instantiator. | |
2152 ASSERT(type_arguments().IsRawInstantiatedRaw(type_arguments().Length())); | |
2153 | |
2154 Label instantiator_not_null; | |
2155 __ CompareObject(instantiator_reg, Object::null_object(), PP); | |
2156 __ j(NOT_EQUAL, &instantiator_not_null, Assembler::kNearJump); | |
2157 // Null was used in VisitExtractConstructorTypeArguments as the | |
2158 // instantiated type arguments, no proper instantiator needed. | |
2159 __ LoadImmediate(instantiator_reg, | |
2160 Immediate(Smi::RawValue(StubCode::kNoInstantiator)), PP); | |
2161 __ Bind(&instantiator_not_null); | |
2162 // instantiator_reg: instantiator or kNoInstantiator. | |
2163 } | |
2164 | |
2165 | |
2166 LocationSummary* AllocateContextInstr::MakeLocationSummary(bool opt) const { | 2112 LocationSummary* AllocateContextInstr::MakeLocationSummary(bool opt) const { |
2167 const intptr_t kNumInputs = 0; | 2113 const intptr_t kNumInputs = 0; |
2168 const intptr_t kNumTemps = 1; | 2114 const intptr_t kNumTemps = 1; |
2169 LocationSummary* locs = | 2115 LocationSummary* locs = |
2170 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kCall); | 2116 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kCall); |
2171 locs->set_temp(0, Location::RegisterLocation(R10)); | 2117 locs->set_temp(0, Location::RegisterLocation(R10)); |
2172 locs->set_out(Location::RegisterLocation(RAX)); | 2118 locs->set_out(Location::RegisterLocation(RAX)); |
2173 return locs; | 2119 return locs; |
2174 } | 2120 } |
2175 | 2121 |
(...skipping 2870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5046 PcDescriptors::kOther, | 4992 PcDescriptors::kOther, |
5047 locs()); | 4993 locs()); |
5048 __ Drop(2); // Discard type arguments and receiver. | 4994 __ Drop(2); // Discard type arguments and receiver. |
5049 } | 4995 } |
5050 | 4996 |
5051 } // namespace dart | 4997 } // namespace dart |
5052 | 4998 |
5053 #undef __ | 4999 #undef __ |
5054 | 5000 |
5055 #endif // defined TARGET_ARCH_X64 | 5001 #endif // defined TARGET_ARCH_X64 |
OLD | NEW |