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

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

Issue 10005010: Implement object allocation/construction as effect (no result), sequence labels and unchaining fro… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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_builder.h ('k') | no next file » | 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_builder.h" 5 #include "vm/flow_graph_builder.h"
6 6
7 #include "vm/ast_printer.h" 7 #include "vm/ast_printer.h"
8 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/flags.h" 9 #include "vm/flags.h"
10 #include "vm/intermediate_language.h" 10 #include "vm/intermediate_language.h"
(...skipping 1258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 void EffectGraphVisitor::VisitCloneContextNode(CloneContextNode* node) { 1269 void EffectGraphVisitor::VisitCloneContextNode(CloneContextNode* node) {
1270 AddInstruction(new BindInstr(temp_index(), new CurrentContextComp())); 1270 AddInstruction(new BindInstr(temp_index(), new CurrentContextComp()));
1271 TempVal* ctx = new TempVal(temp_index()); 1271 TempVal* ctx = new TempVal(temp_index());
1272 AddInstruction(new BindInstr(temp_index(), 1272 AddInstruction(new BindInstr(temp_index(),
1273 new CloneContextComp(node->id(), node->token_index(), ctx))); 1273 new CloneContextComp(node->id(), node->token_index(), ctx)));
1274 TempVal* cloned_ctx = new TempVal(temp_index()); 1274 TempVal* cloned_ctx = new TempVal(temp_index());
1275 ReturnComputation(new StoreContextComp(cloned_ctx)); 1275 ReturnComputation(new StoreContextComp(cloned_ctx));
1276 } 1276 }
1277 1277
1278 1278
1279 TempVal* EffectGraphVisitor::BuildObjectAllocation(ConstructorCallNode* node,
1280 int start_index) {
1281 const Class& cls = Class::ZoneHandle(node->constructor().owner());
1282 const bool requires_type_arguments = cls.HasTypeArguments();
1283
1284 ZoneGrowableArray<Value*>* allocate_arguments =
1285 new ZoneGrowableArray<Value*>();
1286 if (requires_type_arguments) {
1287 BuildConstructorTypeArguments(node, start_index, allocate_arguments);
1288 }
1289 AllocateObjectComp* alloc_comp =
1290 new AllocateObjectComp(node, allocate_arguments);
1291 AddInstruction(new BindInstr(start_index, alloc_comp));
1292 return new TempVal(start_index);
1293 }
1294
1295
1296 void EffectGraphVisitor::BuildConstructorCall(ConstructorCallNode* node,
1297 int start_index,
1298 Value* alloc_value) {
1299 ZoneGrowableArray<Value*>* values = new ZoneGrowableArray<Value*>();
1300 values->Add(alloc_value);
1301 const Smi& ctor_arg = Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll));
1302 TempVal* ctor_arg_value = new TempVal(start_index);
1303 AddInstruction(
1304 new BindInstr(ctor_arg_value->index(), new ConstantVal(ctor_arg)));
1305 values->Add(ctor_arg_value);
1306 TranslateArgumentList(*node->arguments(), start_index + 1, values);
1307 StaticCallComp* call =
1308 new StaticCallComp(node->token_index(),
1309 node->constructor(),
1310 node->arguments()->names(),
1311 values);
1312 AddInstruction(new DoInstr(call));
1313 }
1314
1315
1279 void EffectGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { 1316 void EffectGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) {
1280 if (node->constructor().IsFactory()) { 1317 if (node->constructor().IsFactory()) {
1281 ZoneGrowableArray<Value*>* factory_arguments = 1318 ZoneGrowableArray<Value*>* factory_arguments =
1282 new ZoneGrowableArray<Value*>(); 1319 new ZoneGrowableArray<Value*>();
1283 factory_arguments->Add(BuildFactoryTypeArguments(node, temp_index())); 1320 factory_arguments->Add(BuildFactoryTypeArguments(node, temp_index()));
1284 ASSERT(factory_arguments->length() == 1); 1321 ASSERT(factory_arguments->length() == 1);
1285 TranslateArgumentList(*node->arguments(), 1322 TranslateArgumentList(*node->arguments(),
1286 temp_index() + 1, 1323 temp_index() + 1,
1287 factory_arguments); 1324 factory_arguments);
1288 StaticCallComp* call = 1325 StaticCallComp* call =
1289 new StaticCallComp(node->token_index(), 1326 new StaticCallComp(node->token_index(),
1290 node->constructor(), 1327 node->constructor(),
1291 node->arguments()->names(), 1328 node->arguments()->names(),
1292 factory_arguments); 1329 factory_arguments);
1293 ReturnComputation(call); 1330 ReturnComputation(call);
1294 return; 1331 return;
1295 } 1332 }
1296 Bailout("EffectGraphVisitor::VisitConstructorCallNode"); 1333 // t_n contains the allocated and initialized object.
1334 // t_n <- AllocateObject(class)
1335 // t_n+1 <- ctor-arg
1336 // t_n+2... <- constructor arguments start here
1337 // StaticCall(constructor, t_n+1, t_n+2, ...)
1338 // No need to preserve allocated value (simpler than in ValueGraphVisitor).
1339 TempVal* alloc_value = BuildObjectAllocation(node, temp_index());
1340 BuildConstructorCall(node, alloc_value->index() + 1, alloc_value);
1297 } 1341 }
1298 1342
1299 1343
1300 Value* EffectGraphVisitor::BuildInstantiatorTypeArguments( 1344 Value* EffectGraphVisitor::BuildInstantiatorTypeArguments(
1301 intptr_t token_index, intptr_t start_index) { 1345 intptr_t token_index, intptr_t start_index) {
1302 const Class& instantiator_class = Class::Handle( 1346 const Class& instantiator_class = Class::Handle(
1303 owner()->parsed_function().function().owner()); 1347 owner()->parsed_function().function().owner());
1304 if (instantiator_class.NumTypeParameters() == 0) { 1348 if (instantiator_class.NumTypeParameters() == 0) {
1305 // The type arguments are compile time constants. 1349 // The type arguments are compile time constants.
1306 AbstractTypeArguments& type_arguments = AbstractTypeArguments::ZoneHandle(); 1350 AbstractTypeArguments& type_arguments = AbstractTypeArguments::ZoneHandle();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 args->Add(constructor_instantiator_value); 1448 args->Add(constructor_instantiator_value);
1405 } 1449 }
1406 1450
1407 1451
1408 void ValueGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { 1452 void ValueGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) {
1409 if (node->constructor().IsFactory()) { 1453 if (node->constructor().IsFactory()) {
1410 EffectGraphVisitor::VisitConstructorCallNode(node); 1454 EffectGraphVisitor::VisitConstructorCallNode(node);
1411 return; 1455 return;
1412 } 1456 }
1413 1457
1414 const Class& cls = Class::ZoneHandle(node->constructor().owner());
1415 const bool requires_type_arguments = cls.HasTypeArguments();
1416
1417 ZoneGrowableArray<Value*>* allocate_arguments =
1418 new ZoneGrowableArray<Value*>();
1419 if (requires_type_arguments) {
1420 BuildConstructorTypeArguments(node, temp_index(), allocate_arguments);
1421 }
1422 // t_n contains the allocated and initialized object. 1458 // t_n contains the allocated and initialized object.
1423 // t_n <- AllocateObject(class) 1459 // t_n <- AllocateObject(class)
1424 // t_n+1 <- Pick(t_n) 1460 // t_n+1 <- Pick(t_n)
1425 // t_n+2 <- ctor-arg 1461 // t_n+2 <- ctor-arg
1426 // t_n+3... <- constructor arguments start here 1462 // t_n+3... <- constructor arguments start here
1427 // StaticCall(constructor, t_n+1, t_n+2, ...) 1463 // StaticCall(constructor, t_n+1, t_n+2, ...)
1428 1464
1429 AllocateObjectComp* alloc_comp = 1465 TempVal* alloc_value = BuildObjectAllocation(node, temp_index());
1430 new AllocateObjectComp(node, allocate_arguments);
1431 AddInstruction(new BindInstr(temp_index(), alloc_comp));
1432 intptr_t result_index = AllocateTempIndex(); 1466 intptr_t result_index = AllocateTempIndex();
1433 TempVal* alloc_value = new TempVal(result_index); 1467
1434 TempVal* dup_alloc_value = new TempVal(result_index + 1); 1468 TempVal* dup_alloc_value = new TempVal(result_index + 1);
1435 TempVal* ctor_arg_value = new TempVal(result_index + 2);
1436 AddInstruction( 1469 AddInstruction(
1437 new PickTempInstr(dup_alloc_value->index(), alloc_value->index())); 1470 new PickTempInstr(dup_alloc_value->index(), alloc_value->index()));
1438 1471
1439 ZoneGrowableArray<Value*>* values = new ZoneGrowableArray<Value*>(); 1472 BuildConstructorCall(node, dup_alloc_value->index() + 1, dup_alloc_value);
1440 values->Add(dup_alloc_value);
1441 const Smi& ctor_arg = Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll));
1442 AddInstruction(
1443 new BindInstr(ctor_arg_value->index(), new ConstantVal(ctor_arg)));
1444 values->Add(ctor_arg_value);
1445 TranslateArgumentList(*node->arguments(), result_index + 3, values);
1446 StaticCallComp* call =
1447 new StaticCallComp(node->token_index(),
1448 node->constructor(),
1449 node->arguments()->names(),
1450 values);
1451 AddInstruction(new DoInstr(call));
1452 ReturnValue(alloc_value); 1473 ReturnValue(alloc_value);
1453 } 1474 }
1454 1475
1455 1476
1456 void EffectGraphVisitor::VisitInstanceGetterNode(InstanceGetterNode* node) { 1477 void EffectGraphVisitor::VisitInstanceGetterNode(InstanceGetterNode* node) {
1457 ArgumentGraphVisitor for_receiver(owner(), temp_index()); 1478 ArgumentGraphVisitor for_receiver(owner(), temp_index());
1458 node->receiver()->Visit(&for_receiver); 1479 node->receiver()->Visit(&for_receiver);
1459 Append(for_receiver); 1480 Append(for_receiver);
1460 ZoneGrowableArray<Value*>* arguments = new ZoneGrowableArray<Value*>(1); 1481 ZoneGrowableArray<Value*>* arguments = new ZoneGrowableArray<Value*>(1);
1461 arguments->Add(for_receiver.value()); 1482 arguments->Add(for_receiver.value());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 } 1536 }
1516 1537
1517 1538
1518 void EffectGraphVisitor::VisitNativeBodyNode(NativeBodyNode* node) { 1539 void EffectGraphVisitor::VisitNativeBodyNode(NativeBodyNode* node) {
1519 NativeCallComp* native_call = new NativeCallComp(node); 1540 NativeCallComp* native_call = new NativeCallComp(node);
1520 ReturnComputation(native_call); 1541 ReturnComputation(native_call);
1521 } 1542 }
1522 1543
1523 1544
1524 void EffectGraphVisitor::VisitPrimaryNode(PrimaryNode* node) { 1545 void EffectGraphVisitor::VisitPrimaryNode(PrimaryNode* node) {
1525 Bailout("EffectGraphVisitor::VisitPrimaryNode"); 1546 // PrimaryNodes are temporary during parsing.
1547 UNREACHABLE();
1526 } 1548 }
1527 1549
1528 1550
1529 // <Expression> ::= LoadLocal { local: LocalVariable } 1551 // <Expression> ::= LoadLocal { local: LocalVariable }
1530 void EffectGraphVisitor::VisitLoadLocalNode(LoadLocalNode* node) { 1552 void EffectGraphVisitor::VisitLoadLocalNode(LoadLocalNode* node) {
1531 return; 1553 return;
1532 } 1554 }
1533 1555
1534 1556
1535 void ValueGraphVisitor::VisitLoadLocalNode(LoadLocalNode* node) { 1557 void ValueGraphVisitor::VisitLoadLocalNode(LoadLocalNode* node) {
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1783 new LoadLocalComp(*owner()->parsed_function().saved_context_var(), 0); 1805 new LoadLocalComp(*owner()->parsed_function().saved_context_var(), 0);
1784 AddInstruction(new BindInstr(temp_index(), load_comp)); 1806 AddInstruction(new BindInstr(temp_index(), load_comp));
1785 TempVal* local_value = new TempVal(temp_index()); 1807 TempVal* local_value = new TempVal(temp_index());
1786 StoreContextComp* store_context = new StoreContextComp(local_value); 1808 StoreContextComp* store_context = new StoreContextComp(local_value);
1787 AddInstruction(new DoInstr(store_context)); 1809 AddInstruction(new DoInstr(store_context));
1788 } else if (num_context_variables > 0) { 1810 } else if (num_context_variables > 0) {
1789 UnchainContext(); 1811 UnchainContext();
1790 } 1812 }
1791 } 1813 }
1792 1814
1815 // No continue on sequence allowed.
1816 ASSERT((node->label() == NULL) ||
1817 (node->label()->join_for_continue() == NULL));
1793 // If this node sequence is labeled, a break out of the sequence will have 1818 // If this node sequence is labeled, a break out of the sequence will have
1794 // taken care of unchaining the context. 1819 // taken care of unchaining the context.
1795 if ((node->label() != NULL) && 1820 if ((node->label() != NULL) &&
1796 ((node->label()->join_for_break() != NULL) || 1821 (node->label()->join_for_break() != NULL)) {
1797 (node->label()->join_for_continue() != NULL))) { 1822 if (is_open()) {
1798 Bailout("Jump in SequenceNode"); 1823 AddInstruction(node->label()->join_for_break());
1824 } else {
1825 exit_ = node->label()->join_for_break();
1826 }
1799 } 1827 }
1800 1828
1801 if (node->label() != NULL) { 1829 // The outermost function sequence cannot contain a label.
1802 // TODO(srdjan): Check that the break label is bound? Is this a jump? 1830 ASSERT((node->label() == NULL) ||
1803 Bailout("VisitSequenceNode bind break and unchain CTX"); 1831 (node != owner()->parsed_function().node_sequence()));
1804 }
1805 owner()->set_context_level(previous_context_level); 1832 owner()->set_context_level(previous_context_level);
1806 } 1833 }
1807 1834
1808 1835
1809 void EffectGraphVisitor::VisitCatchClauseNode(CatchClauseNode* node) { 1836 void EffectGraphVisitor::VisitCatchClauseNode(CatchClauseNode* node) {
1810 Bailout("EffectGraphVisitor::VisitCatchClauseNode"); 1837 Bailout("EffectGraphVisitor::VisitCatchClauseNode");
1811 } 1838 }
1812 1839
1813 1840
1814 void EffectGraphVisitor::VisitTryCatchNode(TryCatchNode* node) { 1841 void EffectGraphVisitor::VisitTryCatchNode(TryCatchNode* node) {
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
2339 char* chars = reinterpret_cast<char*>( 2366 char* chars = reinterpret_cast<char*>(
2340 Isolate::Current()->current_zone()->Allocate(len)); 2367 Isolate::Current()->current_zone()->Allocate(len));
2341 OS::SNPrint(chars, len, kFormat, function_name, reason); 2368 OS::SNPrint(chars, len, kFormat, function_name, reason);
2342 const Error& error = Error::Handle( 2369 const Error& error = Error::Handle(
2343 LanguageError::New(String::Handle(String::New(chars)))); 2370 LanguageError::New(String::Handle(String::New(chars))));
2344 Isolate::Current()->long_jump_base()->Jump(1, error); 2371 Isolate::Current()->long_jump_base()->Jump(1, error);
2345 } 2372 }
2346 2373
2347 2374
2348 } // namespace dart 2375 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_builder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698