| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Class for intrinsifying functions. | 4 // Class for intrinsifying functions. |
| 5 | 5 |
| 6 #include "vm/assembler.h" | 6 #include "vm/assembler.h" |
| 7 #include "vm/compiler.h" | 7 #include "vm/compiler.h" |
| 8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
| 9 #include "vm/flow_graph.h" | 9 #include "vm/flow_graph.h" |
| 10 #include "vm/flow_graph_compiler.h" | 10 #include "vm/flow_graph_compiler.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 // Setup all dart:developer lib functions that can be intrinsified. | 88 // Setup all dart:developer lib functions that can be intrinsified. |
| 89 lib = Library::DeveloperLibrary(); | 89 lib = Library::DeveloperLibrary(); |
| 90 ASSERT(!lib.IsNull()); | 90 ASSERT(!lib.IsNull()); |
| 91 DEVELOPER_LIB_INTRINSIC_LIST(SETUP_FUNCTION); | 91 DEVELOPER_LIB_INTRINSIC_LIST(SETUP_FUNCTION); |
| 92 | 92 |
| 93 #undef SETUP_FUNCTION | 93 #undef SETUP_FUNCTION |
| 94 } | 94 } |
| 95 #endif // defined(DART_NO_SNAPSHOT). | 95 #endif // defined(DART_NO_SNAPSHOT). |
| 96 | 96 |
| 97 | 97 |
| 98 // DBC does not use graph intrinsics. |
| 99 #if !defined(TARGET_ARCH_DBC) |
| 98 static void EmitCodeFor(FlowGraphCompiler* compiler, | 100 static void EmitCodeFor(FlowGraphCompiler* compiler, |
| 99 FlowGraph* graph) { | 101 FlowGraph* graph) { |
| 100 // The FlowGraph here is constructed by the intrinsics builder methods, and | 102 // The FlowGraph here is constructed by the intrinsics builder methods, and |
| 101 // is different from compiler->flow_graph(), the original method's flow graph. | 103 // is different from compiler->flow_graph(), the original method's flow graph. |
| 102 compiler->assembler()->Comment("Graph intrinsic"); | 104 compiler->assembler()->Comment("Graph intrinsic"); |
| 103 for (intptr_t i = 0; i < graph->reverse_postorder().length(); i++) { | 105 for (intptr_t i = 0; i < graph->reverse_postorder().length(); i++) { |
| 104 BlockEntryInstr* block = graph->reverse_postorder()[i]; | 106 BlockEntryInstr* block = graph->reverse_postorder()[i]; |
| 105 if (block->IsGraphEntry()) continue; // No code for graph entry needed. | 107 if (block->IsGraphEntry()) continue; // No code for graph entry needed. |
| 106 | 108 |
| 107 if (block->HasParallelMove()) { | 109 if (block->HasParallelMove()) { |
| 108 compiler->parallel_move_resolver()->EmitNativeCode( | 110 compiler->parallel_move_resolver()->EmitNativeCode( |
| 109 block->parallel_move()); | 111 block->parallel_move()); |
| 110 } | 112 } |
| 111 | 113 |
| 112 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { | 114 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { |
| 113 Instruction* instr = it.Current(); | 115 Instruction* instr = it.Current(); |
| 114 if (FLAG_code_comments) compiler->EmitComment(instr); | 116 if (FLAG_code_comments) compiler->EmitComment(instr); |
| 115 if (instr->IsParallelMove()) { | 117 if (instr->IsParallelMove()) { |
| 116 compiler->parallel_move_resolver()->EmitNativeCode( | 118 compiler->parallel_move_resolver()->EmitNativeCode( |
| 117 instr->AsParallelMove()); | 119 instr->AsParallelMove()); |
| 118 } else { | 120 } else { |
| 119 ASSERT(instr->locs() != NULL); | 121 ASSERT(instr->locs() != NULL); |
| 120 // Calls are not supported in intrinsics code. | 122 // Calls are not supported in intrinsics code. |
| 121 ASSERT(!instr->locs()->always_calls()); | 123 ASSERT(!instr->locs()->always_calls()); |
| 122 instr->EmitNativeCode(compiler); | 124 instr->EmitNativeCode(compiler); |
| 123 } | 125 } |
| 124 } | 126 } |
| 125 } | 127 } |
| 126 } | 128 } |
| 129 #endif |
| 127 | 130 |
| 128 | 131 |
| 129 bool Intrinsifier::GraphIntrinsify(const ParsedFunction& parsed_function, | 132 bool Intrinsifier::GraphIntrinsify(const ParsedFunction& parsed_function, |
| 130 FlowGraphCompiler* compiler) { | 133 FlowGraphCompiler* compiler) { |
| 134 #if defined(TARGET_ARCH_DBC) |
| 135 return false; |
| 136 #else |
| 131 ZoneGrowableArray<const ICData*>* ic_data_array = | 137 ZoneGrowableArray<const ICData*>* ic_data_array = |
| 132 new ZoneGrowableArray<const ICData*>(); | 138 new ZoneGrowableArray<const ICData*>(); |
| 133 FlowGraphBuilder builder(parsed_function, | 139 FlowGraphBuilder builder(parsed_function, |
| 134 *ic_data_array, | 140 *ic_data_array, |
| 135 NULL, // NULL = not inlining. | 141 NULL, // NULL = not inlining. |
| 136 Compiler::kNoOSRDeoptId); | 142 Compiler::kNoOSRDeoptId); |
| 137 | 143 |
| 138 intptr_t block_id = builder.AllocateBlockId(); | 144 intptr_t block_id = builder.AllocateBlockId(); |
| 139 TargetEntryInstr* normal_entry = | 145 TargetEntryInstr* normal_entry = |
| 140 new TargetEntryInstr(block_id, | 146 new TargetEntryInstr(block_id, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 167 allocator.AllocateRegisters(); | 173 allocator.AllocateRegisters(); |
| 168 | 174 |
| 169 if (FLAG_support_il_printer && | 175 if (FLAG_support_il_printer && |
| 170 FLAG_print_flow_graph && FlowGraphPrinter::ShouldPrint(function)) { | 176 FLAG_print_flow_graph && FlowGraphPrinter::ShouldPrint(function)) { |
| 171 THR_Print("Intrinsic graph after\n"); | 177 THR_Print("Intrinsic graph after\n"); |
| 172 FlowGraphPrinter printer(*graph); | 178 FlowGraphPrinter printer(*graph); |
| 173 printer.PrintBlocks(); | 179 printer.PrintBlocks(); |
| 174 } | 180 } |
| 175 EmitCodeFor(compiler, graph); | 181 EmitCodeFor(compiler, graph); |
| 176 return true; | 182 return true; |
| 183 #endif |
| 177 } | 184 } |
| 178 | 185 |
| 179 | 186 |
| 180 void Intrinsifier::Intrinsify(const ParsedFunction& parsed_function, | 187 void Intrinsifier::Intrinsify(const ParsedFunction& parsed_function, |
| 181 FlowGraphCompiler* compiler) { | 188 FlowGraphCompiler* compiler) { |
| 182 const Function& function = parsed_function.function(); | 189 const Function& function = parsed_function.function(); |
| 183 if (!CanIntrinsify(function)) { | 190 if (!CanIntrinsify(function)) { |
| 184 return; | 191 return; |
| 185 } | 192 } |
| 186 | 193 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 198 switch (function.recognized_kind()) { | 205 switch (function.recognized_kind()) { |
| 199 ALL_INTRINSICS_NO_INTEGER_LIB_LIST(EMIT_CASE); | 206 ALL_INTRINSICS_NO_INTEGER_LIB_LIST(EMIT_CASE); |
| 200 default: | 207 default: |
| 201 break; | 208 break; |
| 202 } | 209 } |
| 203 switch (function.recognized_kind()) { | 210 switch (function.recognized_kind()) { |
| 204 CORE_INTEGER_LIB_INTRINSIC_LIST(EMIT_CASE) | 211 CORE_INTEGER_LIB_INTRINSIC_LIST(EMIT_CASE) |
| 205 default: | 212 default: |
| 206 break; | 213 break; |
| 207 } | 214 } |
| 215 |
| 216 // On DBC all graph intrinsics are handled in the same way as non-graph |
| 217 // intrinsics. |
| 218 #if defined(TARGET_ARCH_DBC) |
| 219 switch (function.recognized_kind()) { |
| 220 GRAPH_INTRINSICS_LIST(EMIT_CASE) |
| 221 default: |
| 222 break; |
| 223 } |
| 224 #endif |
| 225 |
| 208 #undef EMIT_INTRINSIC | 226 #undef EMIT_INTRINSIC |
| 209 } | 227 } |
| 210 | 228 |
| 211 | 229 |
| 230 #if !defined(TARGET_ARCH_DBC) |
| 212 static intptr_t CidForRepresentation(Representation rep) { | 231 static intptr_t CidForRepresentation(Representation rep) { |
| 213 switch (rep) { | 232 switch (rep) { |
| 214 case kUnboxedDouble: | 233 case kUnboxedDouble: |
| 215 return kDoubleCid; | 234 return kDoubleCid; |
| 216 case kUnboxedFloat32x4: | 235 case kUnboxedFloat32x4: |
| 217 return kFloat32x4Cid; | 236 return kFloat32x4Cid; |
| 218 case kUnboxedUint32: | 237 case kUnboxedUint32: |
| 219 return kDynamicCid; // smi or mint. | 238 return kDynamicCid; // smi or mint. |
| 220 default: | 239 default: |
| 221 UNREACHABLE(); | 240 UNREACHABLE(); |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 builder.AddUnboxInstr(kUnboxedDouble, new Value(receiver)); | 894 builder.AddUnboxInstr(kUnboxedDouble, new Value(receiver)); |
| 876 Definition* unboxed_result = builder.AddDefinition( | 895 Definition* unboxed_result = builder.AddDefinition( |
| 877 new UnaryDoubleOpInstr(Token::kNEGATE, | 896 new UnaryDoubleOpInstr(Token::kNEGATE, |
| 878 new Value(unboxed_value), | 897 new Value(unboxed_value), |
| 879 Thread::kNoDeoptId)); | 898 Thread::kNoDeoptId)); |
| 880 Definition* result = builder.AddDefinition( | 899 Definition* result = builder.AddDefinition( |
| 881 BoxInstr::Create(kUnboxedDouble, new Value(unboxed_result))); | 900 BoxInstr::Create(kUnboxedDouble, new Value(unboxed_result))); |
| 882 builder.AddIntrinsicReturn(new Value(result)); | 901 builder.AddIntrinsicReturn(new Value(result)); |
| 883 return true; | 902 return true; |
| 884 } | 903 } |
| 904 #endif |
| 885 | 905 |
| 886 } // namespace dart | 906 } // namespace dart |
| OLD | NEW |