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

Side by Side Diff: runtime/vm/flow_graph_optimizer.cc

Issue 11694003: In unoptimized code use call for instanceof instead of inlined checks. This allows us to collect ty… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | runtime/vm/intermediate_language.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 4
5 #include "vm/flow_graph_optimizer.h" 5 #include "vm/flow_graph_optimizer.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/cha.h" 8 #include "vm/cha.h"
9 #include "vm/flow_graph_builder.h" 9 #include "vm/flow_graph_builder.h"
10 #include "vm/flow_graph_compiler.h" 10 #include "vm/flow_graph_compiler.h"
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 } 1242 }
1243 call->ReplaceWith(d2i_instr, current_iterator()); 1243 call->ReplaceWith(d2i_instr, current_iterator());
1244 RemovePushArguments(call); 1244 RemovePushArguments(call);
1245 return true; 1245 return true;
1246 } 1246 }
1247 1247
1248 return false; 1248 return false;
1249 } 1249 }
1250 1250
1251 1251
1252 // TODO(srdjan): Use ICData to check if always true or false.
1253 void FlowGraphOptimizer::ReplaceWithInstanceOf(InstanceCallInstr* call) {
1254 ASSERT(Token::IsTypeTestOperator(call->token_kind()));
1255 Value* left_val = call->ArgumentAt(0)->value();
1256 Value* instantiator_val = call->ArgumentAt(1)->value();
1257 Value* type_args_val = call->ArgumentAt(2)->value();
1258 const AbstractType& type =
1259 AbstractType::Cast(call->ArgumentAt(3)->value()->BoundConstant());
1260 const Bool& negate =
1261 Bool::Cast(call->ArgumentAt(4)->value()->BoundConstant());
1262 InstanceOfInstr* instance_of =
1263 new InstanceOfInstr(call->token_pos(),
1264 left_val,
1265 instantiator_val,
1266 type_args_val,
1267 type,
1268 negate.value());
1269 call->ReplaceWith(instance_of, current_iterator());
1270 RemovePushArguments(call);
1271 }
1272
1273
1252 // Tries to optimize instance call by replacing it with a faster instruction 1274 // Tries to optimize instance call by replacing it with a faster instruction
1253 // (e.g, binary op, field load, ..). 1275 // (e.g, binary op, field load, ..).
1254 void FlowGraphOptimizer::VisitInstanceCall(InstanceCallInstr* instr) { 1276 void FlowGraphOptimizer::VisitInstanceCall(InstanceCallInstr* instr) {
1255 if (!instr->HasICData() || (instr->ic_data()->NumberOfChecks() == 0)) { 1277 if (!instr->HasICData() || (instr->ic_data()->NumberOfChecks() == 0)) {
1256 // An instance call without ICData will trigger deoptimization. 1278 // An instance call without ICData will trigger deoptimization.
1257 return; 1279 return;
1258 } 1280 }
1259 1281
1282 const Token::Kind op_kind = instr->token_kind();
1283 // Type test is special as it always gets converted into inlined code.
1284 if (Token::IsTypeTestOperator(op_kind)) {
1285 ReplaceWithInstanceOf(instr);
1286 return;
1287 }
1288
1260 const ICData& unary_checks = 1289 const ICData& unary_checks =
1261 ICData::ZoneHandle(instr->ic_data()->AsUnaryClassChecks()); 1290 ICData::ZoneHandle(instr->ic_data()->AsUnaryClassChecks());
1262 if ((unary_checks.NumberOfChecks() > FLAG_max_polymorphic_checks) && 1291 if ((unary_checks.NumberOfChecks() > FLAG_max_polymorphic_checks) &&
1263 InstanceCallNeedsClassCheck(instr)) { 1292 InstanceCallNeedsClassCheck(instr)) {
1264 // Too many checks, it will be megamorphic which needs unary checks. 1293 // Too many checks, it will be megamorphic which needs unary checks.
1265 instr->set_ic_data(&unary_checks); 1294 instr->set_ic_data(&unary_checks);
1266 return; 1295 return;
1267 } 1296 }
1268 1297
1269 const Token::Kind op_kind = instr->token_kind();
1270 if ((op_kind == Token::kASSIGN_INDEX) && 1298 if ((op_kind == Token::kASSIGN_INDEX) &&
1271 TryReplaceWithStoreIndexed(instr)) { 1299 TryReplaceWithStoreIndexed(instr)) {
1272 return; 1300 return;
1273 } 1301 }
1274 if ((op_kind == Token::kINDEX) && TryReplaceWithLoadIndexed(instr)) { 1302 if ((op_kind == Token::kINDEX) && TryReplaceWithLoadIndexed(instr)) {
1275 return; 1303 return;
1276 } 1304 }
1277 if (Token::IsBinaryOperator(op_kind) && 1305 if (Token::IsBinaryOperator(op_kind) &&
1278 TryReplaceWithBinaryOp(instr, op_kind)) { 1306 TryReplaceWithBinaryOp(instr, op_kind)) {
1279 return; 1307 return;
(...skipping 3069 matching lines...) Expand 10 before | Expand all | Expand 10 after
4349 4377
4350 if (FLAG_trace_constant_propagation) { 4378 if (FLAG_trace_constant_propagation) {
4351 OS::Print("\n==== After constant propagation ====\n"); 4379 OS::Print("\n==== After constant propagation ====\n");
4352 FlowGraphPrinter printer(*graph_); 4380 FlowGraphPrinter printer(*graph_);
4353 printer.PrintBlocks(); 4381 printer.PrintBlocks();
4354 } 4382 }
4355 } 4383 }
4356 4384
4357 4385
4358 } // namespace dart 4386 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | runtime/vm/intermediate_language.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698