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

Side by Side Diff: src/IceOperand.h

Issue 2172313002: Subzero : Live Range Splitting after initial Register Allocation (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Format Created 4 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
OLDNEW
1 //===- subzero/src/IceOperand.h - High-level operands -----------*- C++ -*-===// 1 //===- subzero/src/IceOperand.h - High-level operands -----------*- C++ -*-===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 /// 9 ///
10 /// \file 10 /// \file
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 bool operator<(const RegWeight &A, const RegWeight &B); 596 bool operator<(const RegWeight &A, const RegWeight &B);
597 bool operator<=(const RegWeight &A, const RegWeight &B); 597 bool operator<=(const RegWeight &A, const RegWeight &B);
598 bool operator==(const RegWeight &A, const RegWeight &B); 598 bool operator==(const RegWeight &A, const RegWeight &B);
599 599
600 /// LiveRange is a set of instruction number intervals representing a variable's 600 /// LiveRange is a set of instruction number intervals representing a variable's
601 /// live range. Generally there is one interval per basic block where the 601 /// live range. Generally there is one interval per basic block where the
602 /// variable is live, but adjacent intervals get coalesced into a single 602 /// variable is live, but adjacent intervals get coalesced into a single
603 /// interval. 603 /// interval.
604 class LiveRange { 604 class LiveRange {
605 public: 605 public:
606 using RangeElementType = std::pair<InstNumberT, InstNumberT>;
607 /// RangeType is arena-allocated from the Cfg's allocator.
608 using RangeType = CfgVector<RangeElementType>;
606 LiveRange() = default; 609 LiveRange() = default;
607 /// Special constructor for building a kill set. The advantage is that we can 610 /// Special constructor for building a kill set. The advantage is that we can
608 /// reserve the right amount of space in advance. 611 /// reserve the right amount of space in advance.
609 explicit LiveRange(const CfgVector<InstNumberT> &Kills) { 612 explicit LiveRange(const CfgVector<InstNumberT> &Kills) {
610 Range.reserve(Kills.size()); 613 Range.reserve(Kills.size());
611 for (InstNumberT I : Kills) 614 for (InstNumberT I : Kills)
612 addSegment(I, I); 615 addSegment(I, I);
613 } 616 }
614 LiveRange(const LiveRange &) = default; 617 LiveRange(const LiveRange &) = default;
615 LiveRange &operator=(const LiveRange &) = default; 618 LiveRange &operator=(const LiveRange &) = default;
616 619
617 void reset() { 620 void reset() {
618 Range.clear(); 621 Range.clear();
619 untrim(); 622 untrim();
620 } 623 }
621 void addSegment(InstNumberT Start, InstNumberT End); 624 void addSegment(InstNumberT Start, InstNumberT End, CfgNode *Node = nullptr);
625 void addSegment(RangeElementType Segment, CfgNode *Node = nullptr) {
626 addSegment(Segment.first, Segment.second, Node);
627 }
622 628
623 bool endsBefore(const LiveRange &Other) const; 629 bool endsBefore(const LiveRange &Other) const;
624 bool overlaps(const LiveRange &Other, bool UseTrimmed = false) const; 630 bool overlaps(const LiveRange &Other, bool UseTrimmed = false) const;
625 bool overlapsInst(InstNumberT OtherBegin, bool UseTrimmed = false) const; 631 bool overlapsInst(InstNumberT OtherBegin, bool UseTrimmed = false) const;
626 bool containsValue(InstNumberT Value, bool IsDest) const; 632 bool containsValue(InstNumberT Value, bool IsDest) const;
627 bool isEmpty() const { return Range.empty(); } 633 bool isEmpty() const { return Range.empty(); }
628 InstNumberT getStart() const { 634 InstNumberT getStart() const {
629 return Range.empty() ? -1 : Range.begin()->first; 635 return Range.empty() ? -1 : Range.begin()->first;
630 } 636 }
631 InstNumberT getEnd() const { 637 InstNumberT getEnd() const {
632 return Range.empty() ? -1 : Range.rbegin()->second; 638 return Range.empty() ? -1 : Range.rbegin()->second;
633 } 639 }
634 640
635 void untrim() { TrimmedBegin = Range.begin(); } 641 void untrim() { TrimmedBegin = Range.begin(); }
636 void trim(InstNumberT Lower); 642 void trim(InstNumberT Lower);
637 643
638 void dump(Ostream &Str) const; 644 void dump(Ostream &Str) const;
639 645
646 SizeT getNumSegments() const { return Range.size(); }
647
648 const RangeType &getSegments() const { return Range; }
649 CfgNode *getNodeForSegment(InstNumberT Begin) { return NodeMap[Begin]; }
Jim Stichnoth 2016/08/02 05:57:50 Should probably assert that NodeMap contains Begin
manasijm 2016/08/02 21:41:58 Done.
650
640 private: 651 private:
641 using RangeElementType = std::pair<InstNumberT, InstNumberT>;
642 /// RangeType is arena-allocated from the Cfg's allocator.
643 using RangeType = CfgVector<RangeElementType>;
644 RangeType Range; 652 RangeType Range;
653 CfgUnorderedMap<InstNumberT, CfgNode *> NodeMap;
645 /// TrimmedBegin is an optimization for the overlaps() computation. Since the 654 /// TrimmedBegin is an optimization for the overlaps() computation. Since the
646 /// linear-scan algorithm always calls it as overlaps(Cur) and Cur advances 655 /// linear-scan algorithm always calls it as overlaps(Cur) and Cur advances
647 /// monotonically according to live range start, we can optimize overlaps() by 656 /// monotonically according to live range start, we can optimize overlaps() by
648 /// ignoring all segments that end before the start of Cur's range. The 657 /// ignoring all segments that end before the start of Cur's range. The
649 /// linear-scan code enables this by calling trim() on the ranges of interest 658 /// linear-scan code enables this by calling trim() on the ranges of interest
650 /// as Cur advances. Note that linear-scan also has to initialize TrimmedBegin 659 /// as Cur advances. Note that linear-scan also has to initialize TrimmedBegin
651 /// at the beginning by calling untrim(). 660 /// at the beginning by calling untrim().
652 RangeType::const_iterator TrimmedBegin; 661 RangeType::const_iterator TrimmedBegin;
653 }; 662 };
654 663
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 } 746 }
738 bool isRematerializable() const { return IsRematerializable; } 747 bool isRematerializable() const { return IsRematerializable; }
739 748
740 void setRegClass(uint8_t RC) { RegisterClass = static_cast<RegClass>(RC); } 749 void setRegClass(uint8_t RC) { RegisterClass = static_cast<RegClass>(RC); }
741 RegClass getRegClass() const { return RegisterClass; } 750 RegClass getRegClass() const { return RegisterClass; }
742 751
743 LiveRange &getLiveRange() { return Live; } 752 LiveRange &getLiveRange() { return Live; }
744 const LiveRange &getLiveRange() const { return Live; } 753 const LiveRange &getLiveRange() const { return Live; }
745 void setLiveRange(const LiveRange &Range) { Live = Range; } 754 void setLiveRange(const LiveRange &Range) { Live = Range; }
746 void resetLiveRange() { Live.reset(); } 755 void resetLiveRange() { Live.reset(); }
747 void addLiveRange(InstNumberT Start, InstNumberT End) { 756 void addLiveRange(InstNumberT Start, InstNumberT End,
757 CfgNode *Node = nullptr) {
748 assert(!getIgnoreLiveness()); 758 assert(!getIgnoreLiveness());
749 Live.addSegment(Start, End); 759 Live.addSegment(Start, End, Node);
750 } 760 }
751 void trimLiveRange(InstNumberT Start) { Live.trim(Start); } 761 void trimLiveRange(InstNumberT Start) { Live.trim(Start); }
752 void untrimLiveRange() { Live.untrim(); } 762 void untrimLiveRange() { Live.untrim(); }
753 bool rangeEndsBefore(const Variable *Other) const { 763 bool rangeEndsBefore(const Variable *Other) const {
754 return Live.endsBefore(Other->Live); 764 return Live.endsBefore(Other->Live);
755 } 765 }
756 bool rangeOverlaps(const Variable *Other) const { 766 bool rangeOverlaps(const Variable *Other) const {
757 constexpr bool UseTrimmed = true; 767 constexpr bool UseTrimmed = true;
758 return Live.overlaps(Other->Live, UseTrimmed); 768 return Live.overlaps(Other->Live, UseTrimmed);
759 } 769 }
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 return Operand->getKind() == kVariableBoolean; 1054 return Operand->getKind() == kVariableBoolean;
1045 } 1055 }
1046 1056
1047 private: 1057 private:
1048 Variable *BoolSource = nullptr; 1058 Variable *BoolSource = nullptr;
1049 }; 1059 };
1050 1060
1051 } // end of namespace Ice 1061 } // end of namespace Ice
1052 1062
1053 #endif // SUBZERO_SRC_ICEOPERAND_H 1063 #endif // SUBZERO_SRC_ICEOPERAND_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698