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

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 // Merges the cids:
2419 // - overwrite if not set before.
2420 // - if cid-s differ set to kDynamicCid.
regis 2012/08/16 01:07:44 The code is correct, but the comment is not.
srdjan 2012/08/16 01:21:28 Done.
2421 bool SetPropagatedCid(intptr_t cid) {
2422 ASSERT(cid != 1);
2423 ASSERT(cid != kIllegalCid);
2424 if (propagated_cid_ == kIllegalCid) {
2425 // First setting, nothing has changed.
2426 propagated_cid_ = cid;
2427 return false;
2428 }
2429 bool has_changed = (propagated_cid_ != cid);
2430 propagated_cid_ = cid;
2431 return has_changed;
2432 }
2433
2396 UseVal* use_list() { return use_list_; } 2434 UseVal* use_list() { return use_list_; }
2397 void set_use_list(UseVal* head) { 2435 void set_use_list(UseVal* head) {
2398 ASSERT(head == NULL || head->previous_use() == NULL); 2436 ASSERT(head == NULL || head->previous_use() == NULL);
2399 use_list_ = head; 2437 use_list_ = head;
2400 } 2438 }
2401 2439
2402 void ReplaceUsesWith(Definition* other); 2440 void ReplaceUsesWith(Definition* other);
2403 2441
2404 private: 2442 private:
2405 intptr_t temp_index_; 2443 intptr_t temp_index_;
2406 intptr_t ssa_temp_index_; 2444 intptr_t ssa_temp_index_;
2407 // TODO(regis): GrowableArray<const AbstractType*> propagated_types_; 2445 // TODO(regis): GrowableArray<const AbstractType*> propagated_types_;
2408 // For now: 2446 // For now:
2409 AbstractType& propagated_type_; 2447 AbstractType& propagated_type_;
2448 intptr_t propagated_cid_;
2410 UseVal* use_list_; 2449 UseVal* use_list_;
2411 2450
2412 DISALLOW_COPY_AND_ASSIGN(Definition); 2451 DISALLOW_COPY_AND_ASSIGN(Definition);
2413 }; 2452 };
2414 2453
2415 2454
2416 Definition* UseVal::definition() const { 2455 Definition* UseVal::definition() const {
2417 // Check that the definition is either a Phi or a linked in the the IR. 2456 // Check that the definition is either a Phi or a linked in the the IR.
2418 ASSERT(definition_ != NULL); 2457 ASSERT(definition_ != NULL);
2419 return definition_; 2458 return definition_;
(...skipping 22 matching lines...) Expand all
2442 computation()->SetInputAt(i, value); 2481 computation()->SetInputAt(i, value);
2443 } 2482 }
2444 2483
2445 virtual bool CanDeoptimize() const { return computation()->CanDeoptimize(); } 2484 virtual bool CanDeoptimize() const { return computation()->CanDeoptimize(); }
2446 2485
2447 Computation* computation() const { return computation_; } 2486 Computation* computation() const { return computation_; }
2448 void set_computation(Computation* value) { computation_ = value; } 2487 void set_computation(Computation* value) { computation_ = value; }
2449 bool is_used() const { return is_used_; } 2488 bool is_used() const { return is_used_; }
2450 2489
2451 virtual RawAbstractType* CompileType() const; 2490 virtual RawAbstractType* CompileType() const;
2491 virtual intptr_t GetPropagatedCid();
2452 2492
2453 virtual void RecordAssignedVars(BitVector* assigned_vars, 2493 virtual void RecordAssignedVars(BitVector* assigned_vars,
2454 intptr_t fixed_parameter_count); 2494 intptr_t fixed_parameter_count);
2455 2495
2456 virtual LocationSummary* locs() { 2496 virtual LocationSummary* locs() {
2457 return computation()->locs(); 2497 return computation()->locs();
2458 } 2498 }
2459 2499
2460 virtual void EmitNativeCode(FlowGraphCompiler* compiler); 2500 virtual void EmitNativeCode(FlowGraphCompiler* compiler);
2461 2501
(...skipping 10 matching lines...) Expand all
2472 class PhiInstr : public Definition { 2512 class PhiInstr : public Definition {
2473 public: 2513 public:
2474 explicit PhiInstr(intptr_t num_inputs) 2514 explicit PhiInstr(intptr_t num_inputs)
2475 : inputs_(num_inputs), is_alive_(false) { 2515 : inputs_(num_inputs), is_alive_(false) {
2476 for (intptr_t i = 0; i < num_inputs; ++i) { 2516 for (intptr_t i = 0; i < num_inputs; ++i) {
2477 inputs_.Add(NULL); 2517 inputs_.Add(NULL);
2478 } 2518 }
2479 } 2519 }
2480 2520
2481 virtual RawAbstractType* CompileType() const; 2521 virtual RawAbstractType* CompileType() const;
2522 virtual intptr_t GetPropagatedCid() { return propagated_cid(); }
2482 2523
2483 virtual intptr_t ArgumentCount() const { return 0; } 2524 virtual intptr_t ArgumentCount() const { return 0; }
2484 2525
2485 intptr_t InputCount() const { return inputs_.length(); } 2526 intptr_t InputCount() const { return inputs_.length(); }
2486 2527
2487 Value* InputAt(intptr_t i) const { return inputs_[i]; } 2528 Value* InputAt(intptr_t i) const { return inputs_[i]; }
2488 2529
2489 void SetInputAt(intptr_t i, Value* value) { inputs_[i] = value; } 2530 void SetInputAt(intptr_t i, Value* value) { inputs_[i] = value; }
2490 2531
2491 virtual bool CanDeoptimize() const { return false; } 2532 virtual bool CanDeoptimize() const { return false; }
(...skipping 25 matching lines...) Expand all
2517 class ParameterInstr : public Definition { 2558 class ParameterInstr : public Definition {
2518 public: 2559 public:
2519 explicit ParameterInstr(intptr_t index) : index_(index) { } 2560 explicit ParameterInstr(intptr_t index) : index_(index) { }
2520 2561
2521 DECLARE_INSTRUCTION(Parameter) 2562 DECLARE_INSTRUCTION(Parameter)
2522 2563
2523 intptr_t index() const { return index_; } 2564 intptr_t index() const { return index_; }
2524 2565
2525 // Compile type of the passed-in parameter. 2566 // Compile type of the passed-in parameter.
2526 virtual RawAbstractType* CompileType() const; 2567 virtual RawAbstractType* CompileType() const;
2568 // No known propagated cid for parameters.
2569 virtual intptr_t GetPropagatedCid() { return kDynamicCid; }
2527 2570
2528 virtual intptr_t ArgumentCount() const { return 0; } 2571 virtual intptr_t ArgumentCount() const { return 0; }
2529 2572
2530 intptr_t InputCount() const { return 0; } 2573 intptr_t InputCount() const { return 0; }
2531 Value* InputAt(intptr_t i) const { 2574 Value* InputAt(intptr_t i) const {
2532 UNREACHABLE(); 2575 UNREACHABLE();
2533 return NULL; 2576 return NULL;
2534 } 2577 }
2535 void SetInputAt(intptr_t i, Value* value) { UNREACHABLE(); } 2578 void SetInputAt(intptr_t i, Value* value) { UNREACHABLE(); }
2536 2579
(...skipping 22 matching lines...) Expand all
2559 return value_; 2602 return value_;
2560 } 2603 }
2561 void SetInputAt(intptr_t i, Value* value) { 2604 void SetInputAt(intptr_t i, Value* value) {
2562 ASSERT(i == 0); 2605 ASSERT(i == 0);
2563 value_ = value; 2606 value_ = value;
2564 } 2607 }
2565 2608
2566 virtual intptr_t ArgumentCount() const { return 0; } 2609 virtual intptr_t ArgumentCount() const { return 0; }
2567 2610
2568 virtual RawAbstractType* CompileType() const; 2611 virtual RawAbstractType* CompileType() const;
2612 virtual intptr_t GetPropagatedCid() { return propagated_cid(); }
2569 2613
2570 Value* value() const { return value_; } 2614 Value* value() const { return value_; }
2571 2615
2572 virtual LocationSummary* locs() { 2616 virtual LocationSummary* locs() {
2573 if (locs_ == NULL) { 2617 if (locs_ == NULL) {
2574 locs_ = MakeLocationSummary(); 2618 locs_ = MakeLocationSummary();
2575 } 2619 }
2576 return locs_; 2620 return locs_;
2577 } 2621 }
2578 2622
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
2905 const GrowableArray<BlockEntryInstr*>& block_order_; 2949 const GrowableArray<BlockEntryInstr*>& block_order_;
2906 2950
2907 private: 2951 private:
2908 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 2952 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
2909 }; 2953 };
2910 2954
2911 2955
2912 } // namespace dart 2956 } // namespace dart
2913 2957
2914 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 2958 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698