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

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
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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 inline Definition* definition() const; 350 inline Definition* definition() const;
348 void SetDefinition(Definition* definition); 351 void SetDefinition(Definition* definition);
349 352
350 virtual bool CanDeoptimize() const { return false; } 353 virtual bool CanDeoptimize() const { return false; }
351 354
352 UseVal* next_use() const { return next_use_; } 355 UseVal* next_use() const { return next_use_; }
353 UseVal* previous_use() const { return previous_use_; } 356 UseVal* previous_use() const { return previous_use_; }
354 virtual void RemoveFromUseList(); 357 virtual void RemoveFromUseList();
355 virtual void RemoveInputUses() { RemoveFromUseList(); } 358 virtual void RemoveInputUses() { RemoveFromUseList(); }
356 359
360 virtual intptr_t ResultCid() const;
361
357 private: 362 private:
358 void AddToUseList(); 363 void AddToUseList();
359 Definition* definition_; 364 Definition* definition_;
360 UseVal* next_use_; 365 UseVal* next_use_;
361 UseVal* previous_use_; 366 UseVal* previous_use_;
362 367
363 friend class Definition; 368 friend class Definition;
364 369
365 DISALLOW_COPY_AND_ASSIGN(UseVal); 370 DISALLOW_COPY_AND_ASSIGN(UseVal);
366 }; 371 };
367 372
368 373
369 class ConstantVal: public Value { 374 class ConstantVal : public Value {
370 public: 375 public:
371 explicit ConstantVal(const Object& value) 376 explicit ConstantVal(const Object& value)
372 : value_(value) { 377 : value_(value) {
373 ASSERT(value.IsZoneHandle()); 378 ASSERT(value.IsZoneHandle());
374 ASSERT(value.IsSmi() || value.IsOld()); 379 ASSERT(value.IsSmi() || value.IsOld());
375 } 380 }
376 381
377 DECLARE_VALUE(Constant) 382 DECLARE_VALUE(Constant)
378 383
379 const Object& value() const { return value_; } 384 const Object& value() const { return value_; }
380 385
381 virtual bool CanDeoptimize() const { return false; } 386 virtual bool CanDeoptimize() const { return false; }
382 387
383 virtual void RemoveFromUseList() { } 388 virtual void RemoveFromUseList() { }
384 389
390 virtual intptr_t ResultCid() const;
391
385 private: 392 private:
386 const Object& value_; 393 const Object& value_;
387 394
388 DISALLOW_COPY_AND_ASSIGN(ConstantVal); 395 DISALLOW_COPY_AND_ASSIGN(ConstantVal);
389 }; 396 };
390 397
391 #undef DECLARE_VALUE 398 #undef DECLARE_VALUE
392 399
393 400
394 class AssertAssignableComp : public TemplateComputation<3> { 401 class AssertAssignableComp : public TemplateComputation<3> {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 } 479 }
473 void eliminate() { 480 void eliminate() {
474 ASSERT(!is_eliminated_); 481 ASSERT(!is_eliminated_);
475 is_eliminated_ = true; 482 is_eliminated_ = true;
476 } 483 }
477 484
478 virtual void PrintOperandsTo(BufferFormatter* f) const; 485 virtual void PrintOperandsTo(BufferFormatter* f) const;
479 486
480 virtual bool CanDeoptimize() const { return false; } 487 virtual bool CanDeoptimize() const { return false; }
481 488
489 virtual intptr_t ResultCid() const { return kBoolCid; }
490
482 private: 491 private:
483 const intptr_t token_pos_; 492 const intptr_t token_pos_;
484 const intptr_t try_index_; 493 const intptr_t try_index_;
485 bool is_eliminated_; 494 bool is_eliminated_;
486 495
487 DISALLOW_COPY_AND_ASSIGN(AssertBooleanComp); 496 DISALLOW_COPY_AND_ASSIGN(AssertBooleanComp);
488 }; 497 };
489 498
490 499
491 // Denotes the current context, normally held in a register. This is 500 // Denotes the current context, normally held in a register. This is
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 } 675 }
667 676
668 DECLARE_COMPUTATION(StrictCompare) 677 DECLARE_COMPUTATION(StrictCompare)
669 678
670 virtual void PrintOperandsTo(BufferFormatter* f) const; 679 virtual void PrintOperandsTo(BufferFormatter* f) const;
671 680
672 virtual bool CanDeoptimize() const { return false; } 681 virtual bool CanDeoptimize() const { return false; }
673 682
674 virtual Definition* TryReplace(BindInstr* instr); 683 virtual Definition* TryReplace(BindInstr* instr);
675 684
685 virtual intptr_t ResultCid() const { return kBoolCid; }
686
676 private: 687 private:
677 DISALLOW_COPY_AND_ASSIGN(StrictCompareComp); 688 DISALLOW_COPY_AND_ASSIGN(StrictCompareComp);
678 }; 689 };
679 690
680 691
681 class EqualityCompareComp : public ComparisonComp { 692 class EqualityCompareComp : public ComparisonComp {
682 public: 693 public:
683 EqualityCompareComp(intptr_t token_pos, 694 EqualityCompareComp(intptr_t token_pos,
684 intptr_t try_index, 695 intptr_t try_index,
685 Token::Kind kind, 696 Token::Kind kind,
(...skipping 12 matching lines...) Expand all
698 intptr_t try_index() const { return try_index_; } 709 intptr_t try_index() const { return try_index_; }
699 710
700 // Receiver class id is computed from collected ICData. 711 // Receiver class id is computed from collected ICData.
701 void set_receiver_class_id(intptr_t value) { receiver_class_id_ = value; } 712 void set_receiver_class_id(intptr_t value) { receiver_class_id_ = value; }
702 intptr_t receiver_class_id() const { return receiver_class_id_; } 713 intptr_t receiver_class_id() const { return receiver_class_id_; }
703 714
704 virtual void PrintOperandsTo(BufferFormatter* f) const; 715 virtual void PrintOperandsTo(BufferFormatter* f) const;
705 716
706 virtual bool CanDeoptimize() const { return true; } 717 virtual bool CanDeoptimize() const { return true; }
707 718
719 virtual intptr_t ResultCid() const { return kBoolCid; }
720
708 private: 721 private:
709 const intptr_t token_pos_; 722 const intptr_t token_pos_;
710 const intptr_t try_index_; 723 const intptr_t try_index_;
711 intptr_t receiver_class_id_; // Set by optimizer. 724 intptr_t receiver_class_id_; // Set by optimizer.
712 725
713 DISALLOW_COPY_AND_ASSIGN(EqualityCompareComp); 726 DISALLOW_COPY_AND_ASSIGN(EqualityCompareComp);
714 }; 727 };
715 728
716 729
717 class RelationalOpComp : public ComparisonComp { 730 class RelationalOpComp : public ComparisonComp {
(...skipping 20 matching lines...) Expand all
738 void set_operands_class_id(intptr_t value) { 751 void set_operands_class_id(intptr_t value) {
739 operands_class_id_ = value; 752 operands_class_id_ = value;
740 } 753 }
741 754
742 intptr_t operands_class_id() const { return operands_class_id_; } 755 intptr_t operands_class_id() const { return operands_class_id_; }
743 756
744 virtual void PrintOperandsTo(BufferFormatter* f) const; 757 virtual void PrintOperandsTo(BufferFormatter* f) const;
745 758
746 virtual bool CanDeoptimize() const { return true; } 759 virtual bool CanDeoptimize() const { return true; }
747 760
761 virtual intptr_t ResultCid() const { return kBoolCid; }
762
748 private: 763 private:
749 const intptr_t token_pos_; 764 const intptr_t token_pos_;
750 const intptr_t try_index_; 765 const intptr_t try_index_;
751 intptr_t operands_class_id_; // class id of both operands. 766 intptr_t operands_class_id_; // class id of both operands.
752 767
753 DISALLOW_COPY_AND_ASSIGN(RelationalOpComp); 768 DISALLOW_COPY_AND_ASSIGN(RelationalOpComp);
754 }; 769 };
755 770
756 771
757 class StaticCallComp : public TemplateComputation<0> { 772 class StaticCallComp : public TemplateComputation<0> {
(...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after
2348 }; 2363 };
2349 2364
2350 2365
2351 // Abstract super-class of all instructions that define a value (Bind, Phi). 2366 // Abstract super-class of all instructions that define a value (Bind, Phi).
2352 class Definition : public Instruction { 2367 class Definition : public Instruction {
2353 public: 2368 public:
2354 Definition() 2369 Definition()
2355 : temp_index_(-1), 2370 : temp_index_(-1),
2356 ssa_temp_index_(-1), 2371 ssa_temp_index_(-1),
2357 propagated_type_(AbstractType::Handle()), 2372 propagated_type_(AbstractType::Handle()),
2373 propagated_cid_(kIllegalCid),
2358 use_list_(NULL) { } 2374 use_list_(NULL) { }
2359 2375
2360 virtual bool IsDefinition() const { return true; } 2376 virtual bool IsDefinition() const { return true; }
2361 virtual Definition* AsDefinition() { return this; } 2377 virtual Definition* AsDefinition() { return this; }
2362 2378
2363 intptr_t temp_index() const { return temp_index_; } 2379 intptr_t temp_index() const { return temp_index_; }
2364 void set_temp_index(intptr_t index) { temp_index_ = index; } 2380 void set_temp_index(intptr_t index) { temp_index_ = index; }
2365 2381
2366 intptr_t ssa_temp_index() const { return ssa_temp_index_; } 2382 intptr_t ssa_temp_index() const { return ssa_temp_index_; }
2367 void set_ssa_temp_index(intptr_t index) { 2383 void set_ssa_temp_index(intptr_t index) {
(...skipping 18 matching lines...) Expand all
2386 if (propagated_type.IsNull()) { 2402 if (propagated_type.IsNull()) {
2387 // Not a typed definition, e.g. access to a VM field. 2403 // Not a typed definition, e.g. access to a VM field.
2388 return false; 2404 return false;
2389 } 2405 }
2390 const bool changed = 2406 const bool changed =
2391 propagated_type_.IsNull() || !propagated_type.Equals(propagated_type_); 2407 propagated_type_.IsNull() || !propagated_type.Equals(propagated_type_);
2392 propagated_type_ = propagated_type.raw(); 2408 propagated_type_ = propagated_type.raw();
2393 return changed; 2409 return changed;
2394 } 2410 }
2395 2411
2412 bool has_propagated_cid() const { return propagated_cid_ != kIllegalCid; }
2413 intptr_t propagated_cid() const { return propagated_cid_; }
2414 // May compute and set propagated cid.
2415 virtual intptr_t GetPropagatedCid() = 0;
2416
2417 // Returns true if the propagated cid has changed.
2418 bool SetPropagatedCid(intptr_t cid);
2419
2396 UseVal* use_list() { return use_list_; } 2420 UseVal* use_list() { return use_list_; }
2397 void set_use_list(UseVal* head) { 2421 void set_use_list(UseVal* head) {
2398 ASSERT(head == NULL || head->previous_use() == NULL); 2422 ASSERT(head == NULL || head->previous_use() == NULL);
2399 use_list_ = head; 2423 use_list_ = head;
2400 } 2424 }
2401 2425
2402 void ReplaceUsesWith(Definition* other); 2426 void ReplaceUsesWith(Definition* other);
2403 2427
2404 private: 2428 private:
2405 intptr_t temp_index_; 2429 intptr_t temp_index_;
2406 intptr_t ssa_temp_index_; 2430 intptr_t ssa_temp_index_;
2407 // TODO(regis): GrowableArray<const AbstractType*> propagated_types_; 2431 // TODO(regis): GrowableArray<const AbstractType*> propagated_types_;
2408 // For now: 2432 // For now:
2409 AbstractType& propagated_type_; 2433 AbstractType& propagated_type_;
2434 intptr_t propagated_cid_;
2410 UseVal* use_list_; 2435 UseVal* use_list_;
2411 2436
2412 DISALLOW_COPY_AND_ASSIGN(Definition); 2437 DISALLOW_COPY_AND_ASSIGN(Definition);
2413 }; 2438 };
2414 2439
2415 2440
2416 Definition* UseVal::definition() const { 2441 Definition* UseVal::definition() const {
2417 // Check that the definition is either a Phi or a linked in the the IR. 2442 // Check that the definition is either a Phi or a linked in the the IR.
2418 ASSERT(definition_ != NULL); 2443 ASSERT(definition_ != NULL);
2419 return definition_; 2444 return definition_;
(...skipping 22 matching lines...) Expand all
2442 computation()->SetInputAt(i, value); 2467 computation()->SetInputAt(i, value);
2443 } 2468 }
2444 2469
2445 virtual bool CanDeoptimize() const { return computation()->CanDeoptimize(); } 2470 virtual bool CanDeoptimize() const { return computation()->CanDeoptimize(); }
2446 2471
2447 Computation* computation() const { return computation_; } 2472 Computation* computation() const { return computation_; }
2448 void set_computation(Computation* value) { computation_ = value; } 2473 void set_computation(Computation* value) { computation_ = value; }
2449 bool is_used() const { return is_used_; } 2474 bool is_used() const { return is_used_; }
2450 2475
2451 virtual RawAbstractType* CompileType() const; 2476 virtual RawAbstractType* CompileType() const;
2477 virtual intptr_t GetPropagatedCid();
2452 2478
2453 virtual void RecordAssignedVars(BitVector* assigned_vars, 2479 virtual void RecordAssignedVars(BitVector* assigned_vars,
2454 intptr_t fixed_parameter_count); 2480 intptr_t fixed_parameter_count);
2455 2481
2456 virtual LocationSummary* locs() { 2482 virtual LocationSummary* locs() {
2457 return computation()->locs(); 2483 return computation()->locs();
2458 } 2484 }
2459 2485
2460 virtual void EmitNativeCode(FlowGraphCompiler* compiler); 2486 virtual void EmitNativeCode(FlowGraphCompiler* compiler);
2461 2487
(...skipping 10 matching lines...) Expand all
2472 class PhiInstr : public Definition { 2498 class PhiInstr : public Definition {
2473 public: 2499 public:
2474 explicit PhiInstr(intptr_t num_inputs) 2500 explicit PhiInstr(intptr_t num_inputs)
2475 : inputs_(num_inputs), is_alive_(false) { 2501 : inputs_(num_inputs), is_alive_(false) {
2476 for (intptr_t i = 0; i < num_inputs; ++i) { 2502 for (intptr_t i = 0; i < num_inputs; ++i) {
2477 inputs_.Add(NULL); 2503 inputs_.Add(NULL);
2478 } 2504 }
2479 } 2505 }
2480 2506
2481 virtual RawAbstractType* CompileType() const; 2507 virtual RawAbstractType* CompileType() const;
2508 virtual intptr_t GetPropagatedCid() { return propagated_cid(); }
2482 2509
2483 virtual intptr_t ArgumentCount() const { return 0; } 2510 virtual intptr_t ArgumentCount() const { return 0; }
2484 2511
2485 intptr_t InputCount() const { return inputs_.length(); } 2512 intptr_t InputCount() const { return inputs_.length(); }
2486 2513
2487 Value* InputAt(intptr_t i) const { return inputs_[i]; } 2514 Value* InputAt(intptr_t i) const { return inputs_[i]; }
2488 2515
2489 void SetInputAt(intptr_t i, Value* value) { inputs_[i] = value; } 2516 void SetInputAt(intptr_t i, Value* value) { inputs_[i] = value; }
2490 2517
2491 virtual bool CanDeoptimize() const { return false; } 2518 virtual bool CanDeoptimize() const { return false; }
(...skipping 25 matching lines...) Expand all
2517 class ParameterInstr : public Definition { 2544 class ParameterInstr : public Definition {
2518 public: 2545 public:
2519 explicit ParameterInstr(intptr_t index) : index_(index) { } 2546 explicit ParameterInstr(intptr_t index) : index_(index) { }
2520 2547
2521 DECLARE_INSTRUCTION(Parameter) 2548 DECLARE_INSTRUCTION(Parameter)
2522 2549
2523 intptr_t index() const { return index_; } 2550 intptr_t index() const { return index_; }
2524 2551
2525 // Compile type of the passed-in parameter. 2552 // Compile type of the passed-in parameter.
2526 virtual RawAbstractType* CompileType() const; 2553 virtual RawAbstractType* CompileType() const;
2554 // No known propagated cid for parameters.
2555 virtual intptr_t GetPropagatedCid() { return propagated_cid(); }
2527 2556
2528 virtual intptr_t ArgumentCount() const { return 0; } 2557 virtual intptr_t ArgumentCount() const { return 0; }
2529 2558
2530 intptr_t InputCount() const { return 0; } 2559 intptr_t InputCount() const { return 0; }
2531 Value* InputAt(intptr_t i) const { 2560 Value* InputAt(intptr_t i) const {
2532 UNREACHABLE(); 2561 UNREACHABLE();
2533 return NULL; 2562 return NULL;
2534 } 2563 }
2535 void SetInputAt(intptr_t i, Value* value) { UNREACHABLE(); } 2564 void SetInputAt(intptr_t i, Value* value) { UNREACHABLE(); }
2536 2565
(...skipping 22 matching lines...) Expand all
2559 return value_; 2588 return value_;
2560 } 2589 }
2561 void SetInputAt(intptr_t i, Value* value) { 2590 void SetInputAt(intptr_t i, Value* value) {
2562 ASSERT(i == 0); 2591 ASSERT(i == 0);
2563 value_ = value; 2592 value_ = value;
2564 } 2593 }
2565 2594
2566 virtual intptr_t ArgumentCount() const { return 0; } 2595 virtual intptr_t ArgumentCount() const { return 0; }
2567 2596
2568 virtual RawAbstractType* CompileType() const; 2597 virtual RawAbstractType* CompileType() const;
2598 virtual intptr_t GetPropagatedCid() { return propagated_cid(); }
2569 2599
2570 Value* value() const { return value_; } 2600 Value* value() const { return value_; }
2571 2601
2572 virtual LocationSummary* locs() { 2602 virtual LocationSummary* locs() {
2573 if (locs_ == NULL) { 2603 if (locs_ == NULL) {
2574 locs_ = MakeLocationSummary(); 2604 locs_ = MakeLocationSummary();
2575 } 2605 }
2576 return locs_; 2606 return locs_;
2577 } 2607 }
2578 2608
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
2905 const GrowableArray<BlockEntryInstr*>& block_order_; 2935 const GrowableArray<BlockEntryInstr*>& block_order_;
2906 2936
2907 private: 2937 private:
2908 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 2938 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
2909 }; 2939 };
2910 2940
2911 2941
2912 } // namespace dart 2942 } // namespace dart
2913 2943
2914 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 2944 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698