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

Side by Side Diff: runtime/vm/intermediate_language.h

Issue 10830339: Propagate class ids using existing type propagation framework. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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/il_printer.cc ('k') | runtime/vm/intermediate_language.cc » ('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 #ifndef VM_INTERMEDIATE_LANGUAGE_H_ 5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_
6 #define VM_INTERMEDIATE_LANGUAGE_H_ 6 #define VM_INTERMEDIATE_LANGUAGE_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/ast.h" 9 #include "vm/ast.h"
10 #include "vm/growable_array.h" 10 #include "vm/growable_array.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // Returns true, if this computation can deoptimize. 149 // Returns true, if this computation can deoptimize.
150 virtual bool CanDeoptimize() const = 0; 150 virtual bool CanDeoptimize() const = 0;
151 151
152 // Optimize this computation. Returns a replacement for the instruction 152 // Optimize this computation. Returns a replacement for the instruction
153 // that wraps this computation or NULL if nothing to replace. 153 // that wraps this computation or NULL if nothing to replace.
154 virtual Definition* TryReplace(BindInstr* instr) { return NULL; } 154 virtual Definition* TryReplace(BindInstr* instr) { return NULL; }
155 155
156 // Compile time type of the computation, which typically depends on the 156 // Compile time type of the computation, which typically depends on the
157 // compile time types (and possibly propagated types) of its inputs. 157 // compile time types (and possibly propagated types) of its inputs.
158 virtual RawAbstractType* CompileType() const = 0; 158 virtual RawAbstractType* CompileType() const = 0;
159 // TODO(srdjan): Make this abstract so that it gets correctly implemented
160 // in all computations.
161 virtual intptr_t ResultCid() const { return kDynamicCid; }
159 162
160 // Mutate assigned_vars to add the local variable index for all 163 // Mutate assigned_vars to add the local variable index for all
161 // frame-allocated locals assigned to by the computation. 164 // frame-allocated locals assigned to by the computation.
162 virtual void RecordAssignedVars(BitVector* assigned_vars, 165 virtual void RecordAssignedVars(BitVector* assigned_vars,
163 intptr_t fixed_parameter_count); 166 intptr_t fixed_parameter_count);
164 167
165 virtual const char* DebugName() const = 0; 168 virtual const char* DebugName() const = 0;
166 169
167 // Printing support. These functions are sometimes overridden for custom 170 // Printing support. These functions are sometimes overridden for custom
168 // formatting. Otherwise, it prints in the format "opcode(op1, op2, op3)". 171 // formatting. Otherwise, it prints in the format "opcode(op1, op2, op3)".
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 // Returns true if the value represents constant null. 364 // Returns true if the value represents constant null.
362 virtual bool BindsToConstantNull() const; 365 virtual bool BindsToConstantNull() const;
363 366
364 virtual bool CanDeoptimize() const { return false; } 367 virtual bool CanDeoptimize() const { return false; }
365 368
366 UseVal* next_use() const { return next_use_; } 369 UseVal* next_use() const { return next_use_; }
367 UseVal* previous_use() const { return previous_use_; } 370 UseVal* previous_use() const { return previous_use_; }
368 virtual void RemoveFromUseList(); 371 virtual void RemoveFromUseList();
369 virtual void RemoveInputUses() { RemoveFromUseList(); } 372 virtual void RemoveInputUses() { RemoveFromUseList(); }
370 373
374 virtual intptr_t ResultCid() const;
375
371 private: 376 private:
372 void AddToUseList(); 377 void AddToUseList();
373 Definition* definition_; 378 Definition* definition_;
374 UseVal* next_use_; 379 UseVal* next_use_;
375 UseVal* previous_use_; 380 UseVal* previous_use_;
376 381
377 friend class Definition; 382 friend class Definition;
378 383
379 DISALLOW_COPY_AND_ASSIGN(UseVal); 384 DISALLOW_COPY_AND_ASSIGN(UseVal);
380 }; 385 };
381 386
382 387
383 class ConstantVal: public Value { 388 class ConstantVal : public Value {
384 public: 389 public:
385 explicit ConstantVal(const Object& value) 390 explicit ConstantVal(const Object& value)
386 : value_(value) { 391 : value_(value) {
387 ASSERT(value.IsZoneHandle()); 392 ASSERT(value.IsZoneHandle());
388 ASSERT(value.IsSmi() || value.IsOld()); 393 ASSERT(value.IsSmi() || value.IsOld());
389 } 394 }
390 395
391 DECLARE_VALUE(Constant) 396 DECLARE_VALUE(Constant)
392 397
393 const Object& value() const { return value_; } 398 const Object& value() const { return value_; }
394 399
395 // Returns true if the value represents a constant. 400 // Returns true if the value represents a constant.
396 virtual bool BindsToConstant() const { return true; } 401 virtual bool BindsToConstant() const { return true; }
397 402
398 // Returns true if the value represents constant null. 403 // Returns true if the value represents constant null.
399 virtual bool BindsToConstantNull() const { return value().IsNull(); } 404 virtual bool BindsToConstantNull() const { return value().IsNull(); }
400 405
401 virtual bool CanDeoptimize() const { return false; } 406 virtual bool CanDeoptimize() const { return false; }
402 407
403 virtual void RemoveFromUseList() { } 408 virtual void RemoveFromUseList() { }
404 409
410 virtual intptr_t ResultCid() const;
411
405 private: 412 private:
406 const Object& value_; 413 const Object& value_;
407 414
408 DISALLOW_COPY_AND_ASSIGN(ConstantVal); 415 DISALLOW_COPY_AND_ASSIGN(ConstantVal);
409 }; 416 };
410 417
411 #undef DECLARE_VALUE 418 #undef DECLARE_VALUE
412 419
413 420
414 class AssertAssignableComp : public TemplateComputation<3> { 421 class AssertAssignableComp : public TemplateComputation<3> {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 } 499 }
493 void eliminate() { 500 void eliminate() {
494 ASSERT(!is_eliminated_); 501 ASSERT(!is_eliminated_);
495 is_eliminated_ = true; 502 is_eliminated_ = true;
496 } 503 }
497 504
498 virtual void PrintOperandsTo(BufferFormatter* f) const; 505 virtual void PrintOperandsTo(BufferFormatter* f) const;
499 506
500 virtual bool CanDeoptimize() const { return false; } 507 virtual bool CanDeoptimize() const { return false; }
501 508
509 virtual intptr_t ResultCid() const { return kBoolCid; }
510
502 private: 511 private:
503 const intptr_t token_pos_; 512 const intptr_t token_pos_;
504 const intptr_t try_index_; 513 const intptr_t try_index_;
505 bool is_eliminated_; 514 bool is_eliminated_;
506 515
507 DISALLOW_COPY_AND_ASSIGN(AssertBooleanComp); 516 DISALLOW_COPY_AND_ASSIGN(AssertBooleanComp);
508 }; 517 };
509 518
510 519
511 // Denotes the current context, normally held in a register. This is 520 // Denotes the current context, normally held in a register. This is
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 } 695 }
687 696
688 DECLARE_COMPUTATION(StrictCompare) 697 DECLARE_COMPUTATION(StrictCompare)
689 698
690 virtual void PrintOperandsTo(BufferFormatter* f) const; 699 virtual void PrintOperandsTo(BufferFormatter* f) const;
691 700
692 virtual bool CanDeoptimize() const { return false; } 701 virtual bool CanDeoptimize() const { return false; }
693 702
694 virtual Definition* TryReplace(BindInstr* instr); 703 virtual Definition* TryReplace(BindInstr* instr);
695 704
705 virtual intptr_t ResultCid() const { return kBoolCid; }
706
696 private: 707 private:
697 DISALLOW_COPY_AND_ASSIGN(StrictCompareComp); 708 DISALLOW_COPY_AND_ASSIGN(StrictCompareComp);
698 }; 709 };
699 710
700 711
701 class EqualityCompareComp : public ComparisonComp { 712 class EqualityCompareComp : public ComparisonComp {
702 public: 713 public:
703 EqualityCompareComp(intptr_t token_pos, 714 EqualityCompareComp(intptr_t token_pos,
704 intptr_t try_index, 715 intptr_t try_index,
705 Token::Kind kind, 716 Token::Kind kind,
(...skipping 12 matching lines...) Expand all
718 intptr_t try_index() const { return try_index_; } 729 intptr_t try_index() const { return try_index_; }
719 730
720 // Receiver class id is computed from collected ICData. 731 // Receiver class id is computed from collected ICData.
721 void set_receiver_class_id(intptr_t value) { receiver_class_id_ = value; } 732 void set_receiver_class_id(intptr_t value) { receiver_class_id_ = value; }
722 intptr_t receiver_class_id() const { return receiver_class_id_; } 733 intptr_t receiver_class_id() const { return receiver_class_id_; }
723 734
724 virtual void PrintOperandsTo(BufferFormatter* f) const; 735 virtual void PrintOperandsTo(BufferFormatter* f) const;
725 736
726 virtual bool CanDeoptimize() const { return true; } 737 virtual bool CanDeoptimize() const { return true; }
727 738
739 virtual intptr_t ResultCid() const { return kBoolCid; }
740
728 private: 741 private:
729 const intptr_t token_pos_; 742 const intptr_t token_pos_;
730 const intptr_t try_index_; 743 const intptr_t try_index_;
731 intptr_t receiver_class_id_; // Set by optimizer. 744 intptr_t receiver_class_id_; // Set by optimizer.
732 745
733 DISALLOW_COPY_AND_ASSIGN(EqualityCompareComp); 746 DISALLOW_COPY_AND_ASSIGN(EqualityCompareComp);
734 }; 747 };
735 748
736 749
737 class RelationalOpComp : public ComparisonComp { 750 class RelationalOpComp : public ComparisonComp {
(...skipping 20 matching lines...) Expand all
758 void set_operands_class_id(intptr_t value) { 771 void set_operands_class_id(intptr_t value) {
759 operands_class_id_ = value; 772 operands_class_id_ = value;
760 } 773 }
761 774
762 intptr_t operands_class_id() const { return operands_class_id_; } 775 intptr_t operands_class_id() const { return operands_class_id_; }
763 776
764 virtual void PrintOperandsTo(BufferFormatter* f) const; 777 virtual void PrintOperandsTo(BufferFormatter* f) const;
765 778
766 virtual bool CanDeoptimize() const { return true; } 779 virtual bool CanDeoptimize() const { return true; }
767 780
781 virtual intptr_t ResultCid() const { return kBoolCid; }
782
768 private: 783 private:
769 const intptr_t token_pos_; 784 const intptr_t token_pos_;
770 const intptr_t try_index_; 785 const intptr_t try_index_;
771 intptr_t operands_class_id_; // class id of both operands. 786 intptr_t operands_class_id_; // class id of both operands.
772 787
773 DISALLOW_COPY_AND_ASSIGN(RelationalOpComp); 788 DISALLOW_COPY_AND_ASSIGN(RelationalOpComp);
774 }; 789 };
775 790
776 791
777 class StaticCallComp : public TemplateComputation<0> { 792 class StaticCallComp : public TemplateComputation<0> {
(...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after
2368 }; 2383 };
2369 2384
2370 2385
2371 // Abstract super-class of all instructions that define a value (Bind, Phi). 2386 // Abstract super-class of all instructions that define a value (Bind, Phi).
2372 class Definition : public Instruction { 2387 class Definition : public Instruction {
2373 public: 2388 public:
2374 Definition() 2389 Definition()
2375 : temp_index_(-1), 2390 : temp_index_(-1),
2376 ssa_temp_index_(-1), 2391 ssa_temp_index_(-1),
2377 propagated_type_(AbstractType::Handle()), 2392 propagated_type_(AbstractType::Handle()),
2393 propagated_cid_(kIllegalCid),
2378 use_list_(NULL) { } 2394 use_list_(NULL) { }
2379 2395
2380 virtual bool IsDefinition() const { return true; } 2396 virtual bool IsDefinition() const { return true; }
2381 virtual Definition* AsDefinition() { return this; } 2397 virtual Definition* AsDefinition() { return this; }
2382 2398
2383 intptr_t temp_index() const { return temp_index_; } 2399 intptr_t temp_index() const { return temp_index_; }
2384 void set_temp_index(intptr_t index) { temp_index_ = index; } 2400 void set_temp_index(intptr_t index) { temp_index_ = index; }
2385 2401
2386 intptr_t ssa_temp_index() const { return ssa_temp_index_; } 2402 intptr_t ssa_temp_index() const { return ssa_temp_index_; }
2387 void set_ssa_temp_index(intptr_t index) { 2403 void set_ssa_temp_index(intptr_t index) {
(...skipping 18 matching lines...) Expand all
2406 if (propagated_type.IsNull()) { 2422 if (propagated_type.IsNull()) {
2407 // Not a typed definition, e.g. access to a VM field. 2423 // Not a typed definition, e.g. access to a VM field.
2408 return false; 2424 return false;
2409 } 2425 }
2410 const bool changed = 2426 const bool changed =
2411 propagated_type_.IsNull() || !propagated_type.Equals(propagated_type_); 2427 propagated_type_.IsNull() || !propagated_type.Equals(propagated_type_);
2412 propagated_type_ = propagated_type.raw(); 2428 propagated_type_ = propagated_type.raw();
2413 return changed; 2429 return changed;
2414 } 2430 }
2415 2431
2432 bool has_propagated_cid() const { return propagated_cid_ != kIllegalCid; }
2433 intptr_t propagated_cid() const { return propagated_cid_; }
2434 // May compute and set propagated cid.
2435 virtual intptr_t GetPropagatedCid() = 0;
2436
2437 // Returns true if the propagated cid has changed.
2438 bool SetPropagatedCid(intptr_t cid);
2439
2416 UseVal* use_list() { return use_list_; } 2440 UseVal* use_list() { return use_list_; }
2417 void set_use_list(UseVal* head) { 2441 void set_use_list(UseVal* head) {
2418 ASSERT(head == NULL || head->previous_use() == NULL); 2442 ASSERT(head == NULL || head->previous_use() == NULL);
2419 use_list_ = head; 2443 use_list_ = head;
2420 } 2444 }
2421 2445
2422 void ReplaceUsesWith(Definition* other); 2446 void ReplaceUsesWith(Definition* other);
2423 2447
2424 private: 2448 private:
2425 intptr_t temp_index_; 2449 intptr_t temp_index_;
2426 intptr_t ssa_temp_index_; 2450 intptr_t ssa_temp_index_;
2427 // TODO(regis): GrowableArray<const AbstractType*> propagated_types_; 2451 // TODO(regis): GrowableArray<const AbstractType*> propagated_types_;
2428 // For now: 2452 // For now:
2429 AbstractType& propagated_type_; 2453 AbstractType& propagated_type_;
2454 intptr_t propagated_cid_;
2430 UseVal* use_list_; 2455 UseVal* use_list_;
2431 2456
2432 DISALLOW_COPY_AND_ASSIGN(Definition); 2457 DISALLOW_COPY_AND_ASSIGN(Definition);
2433 }; 2458 };
2434 2459
2435 2460
2436 Definition* UseVal::definition() const { 2461 Definition* UseVal::definition() const {
2437 // Check that the definition is either a Phi or a linked in the the IR. 2462 // Check that the definition is either a Phi or a linked in the the IR.
2438 ASSERT(definition_ != NULL); 2463 ASSERT(definition_ != NULL);
2439 return definition_; 2464 return definition_;
(...skipping 22 matching lines...) Expand all
2462 computation()->SetInputAt(i, value); 2487 computation()->SetInputAt(i, value);
2463 } 2488 }
2464 2489
2465 virtual bool CanDeoptimize() const { return computation()->CanDeoptimize(); } 2490 virtual bool CanDeoptimize() const { return computation()->CanDeoptimize(); }
2466 2491
2467 Computation* computation() const { return computation_; } 2492 Computation* computation() const { return computation_; }
2468 void set_computation(Computation* value) { computation_ = value; } 2493 void set_computation(Computation* value) { computation_ = value; }
2469 bool is_used() const { return is_used_; } 2494 bool is_used() const { return is_used_; }
2470 2495
2471 virtual RawAbstractType* CompileType() const; 2496 virtual RawAbstractType* CompileType() const;
2497 virtual intptr_t GetPropagatedCid();
2472 2498
2473 virtual void RecordAssignedVars(BitVector* assigned_vars, 2499 virtual void RecordAssignedVars(BitVector* assigned_vars,
2474 intptr_t fixed_parameter_count); 2500 intptr_t fixed_parameter_count);
2475 2501
2476 virtual LocationSummary* locs() { 2502 virtual LocationSummary* locs() {
2477 return computation()->locs(); 2503 return computation()->locs();
2478 } 2504 }
2479 2505
2480 virtual void EmitNativeCode(FlowGraphCompiler* compiler); 2506 virtual void EmitNativeCode(FlowGraphCompiler* compiler);
2481 2507
(...skipping 10 matching lines...) Expand all
2492 class PhiInstr : public Definition { 2518 class PhiInstr : public Definition {
2493 public: 2519 public:
2494 explicit PhiInstr(intptr_t num_inputs) 2520 explicit PhiInstr(intptr_t num_inputs)
2495 : inputs_(num_inputs), is_alive_(false) { 2521 : inputs_(num_inputs), is_alive_(false) {
2496 for (intptr_t i = 0; i < num_inputs; ++i) { 2522 for (intptr_t i = 0; i < num_inputs; ++i) {
2497 inputs_.Add(NULL); 2523 inputs_.Add(NULL);
2498 } 2524 }
2499 } 2525 }
2500 2526
2501 virtual RawAbstractType* CompileType() const; 2527 virtual RawAbstractType* CompileType() const;
2528 virtual intptr_t GetPropagatedCid() { return propagated_cid(); }
2502 2529
2503 virtual intptr_t ArgumentCount() const { return 0; } 2530 virtual intptr_t ArgumentCount() const { return 0; }
2504 2531
2505 intptr_t InputCount() const { return inputs_.length(); } 2532 intptr_t InputCount() const { return inputs_.length(); }
2506 2533
2507 Value* InputAt(intptr_t i) const { return inputs_[i]; } 2534 Value* InputAt(intptr_t i) const { return inputs_[i]; }
2508 2535
2509 void SetInputAt(intptr_t i, Value* value) { inputs_[i] = value; } 2536 void SetInputAt(intptr_t i, Value* value) { inputs_[i] = value; }
2510 2537
2511 virtual bool CanDeoptimize() const { return false; } 2538 virtual bool CanDeoptimize() const { return false; }
(...skipping 25 matching lines...) Expand all
2537 class ParameterInstr : public Definition { 2564 class ParameterInstr : public Definition {
2538 public: 2565 public:
2539 explicit ParameterInstr(intptr_t index) : index_(index) { } 2566 explicit ParameterInstr(intptr_t index) : index_(index) { }
2540 2567
2541 DECLARE_INSTRUCTION(Parameter) 2568 DECLARE_INSTRUCTION(Parameter)
2542 2569
2543 intptr_t index() const { return index_; } 2570 intptr_t index() const { return index_; }
2544 2571
2545 // Compile type of the passed-in parameter. 2572 // Compile type of the passed-in parameter.
2546 virtual RawAbstractType* CompileType() const; 2573 virtual RawAbstractType* CompileType() const;
2574 // No known propagated cid for parameters.
2575 virtual intptr_t GetPropagatedCid() { return propagated_cid(); }
2547 2576
2548 virtual intptr_t ArgumentCount() const { return 0; } 2577 virtual intptr_t ArgumentCount() const { return 0; }
2549 2578
2550 intptr_t InputCount() const { return 0; } 2579 intptr_t InputCount() const { return 0; }
2551 Value* InputAt(intptr_t i) const { 2580 Value* InputAt(intptr_t i) const {
2552 UNREACHABLE(); 2581 UNREACHABLE();
2553 return NULL; 2582 return NULL;
2554 } 2583 }
2555 void SetInputAt(intptr_t i, Value* value) { UNREACHABLE(); } 2584 void SetInputAt(intptr_t i, Value* value) { UNREACHABLE(); }
2556 2585
(...skipping 22 matching lines...) Expand all
2579 return value_; 2608 return value_;
2580 } 2609 }
2581 void SetInputAt(intptr_t i, Value* value) { 2610 void SetInputAt(intptr_t i, Value* value) {
2582 ASSERT(i == 0); 2611 ASSERT(i == 0);
2583 value_ = value; 2612 value_ = value;
2584 } 2613 }
2585 2614
2586 virtual intptr_t ArgumentCount() const { return 0; } 2615 virtual intptr_t ArgumentCount() const { return 0; }
2587 2616
2588 virtual RawAbstractType* CompileType() const; 2617 virtual RawAbstractType* CompileType() const;
2618 virtual intptr_t GetPropagatedCid() { return propagated_cid(); }
2589 2619
2590 Value* value() const { return value_; } 2620 Value* value() const { return value_; }
2591 2621
2592 virtual LocationSummary* locs() { 2622 virtual LocationSummary* locs() {
2593 if (locs_ == NULL) { 2623 if (locs_ == NULL) {
2594 locs_ = MakeLocationSummary(); 2624 locs_ = MakeLocationSummary();
2595 } 2625 }
2596 return locs_; 2626 return locs_;
2597 } 2627 }
2598 2628
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
2930 ForwardInstructionIterator* current_iterator_; 2960 ForwardInstructionIterator* current_iterator_;
2931 2961
2932 private: 2962 private:
2933 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 2963 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
2934 }; 2964 };
2935 2965
2936 2966
2937 } // namespace dart 2967 } // namespace dart
2938 2968
2939 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 2969 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW
« no previous file with comments | « runtime/vm/il_printer.cc ('k') | runtime/vm/intermediate_language.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698