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

Side by Side Diff: src/IceOperand.h

Issue 1318553003: Compute the loop nest depth of each CfgNode and weight Variables by it. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « src/IceLoopAnalyzer.cpp ('k') | src/IceOperand.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 314
315 /// RegWeight is a wrapper for a uint32_t weight value, with a 315 /// RegWeight is a wrapper for a uint32_t weight value, with a
316 /// special value that represents infinite weight, and an addWeight() 316 /// special value that represents infinite weight, and an addWeight()
317 /// method that ensures that W+infinity=infinity. 317 /// method that ensures that W+infinity=infinity.
318 class RegWeight { 318 class RegWeight {
319 public: 319 public:
320 RegWeight() = default; 320 RegWeight() = default;
321 explicit RegWeight(uint32_t Weight) : Weight(Weight) {} 321 explicit RegWeight(uint32_t Weight) : Weight(Weight) {}
322 RegWeight(const RegWeight &) = default; 322 RegWeight(const RegWeight &) = default;
323 RegWeight &operator=(const RegWeight &) = default; 323 RegWeight &operator=(const RegWeight &) = default;
324 const static uint32_t Inf = ~0; /// Force regalloc to give a register 324 const static uint32_t Inf = ~0; /// Force regalloc to give a register
325 const static uint32_t Zero = 0; /// Force regalloc NOT to give a register 325 const static uint32_t Zero = 0; /// Force regalloc NOT to give a register
326 const static uint32_t Max = Inf - 1; /// Max natural weight.
326 void addWeight(uint32_t Delta) { 327 void addWeight(uint32_t Delta) {
327 if (Delta == Inf) 328 if (Delta == Inf)
328 Weight = Inf; 329 Weight = Inf;
329 else if (Weight != Inf) 330 else if (Weight != Inf)
330 Weight += Delta; 331 if (Utils::add_overflow(Weight, Delta, &Weight) || Weight == Inf)
332 Weight = Max;
331 } 333 }
332 void addWeight(const RegWeight &Other) { addWeight(Other.Weight); } 334 void addWeight(const RegWeight &Other) { addWeight(Other.Weight); }
333 void setWeight(uint32_t Val) { Weight = Val; } 335 void setWeight(uint32_t Val) { Weight = Val; }
334 uint32_t getWeight() const { return Weight; } 336 uint32_t getWeight() const { return Weight; }
335 337
336 private: 338 private:
337 uint32_t Weight = 0; 339 uint32_t Weight = 0;
338 }; 340 };
339 Ostream &operator<<(Ostream &Str, const RegWeight &W); 341 Ostream &operator<<(Ostream &Str, const RegWeight &W);
340 bool operator<(const RegWeight &A, const RegWeight &B); 342 bool operator<(const RegWeight &A, const RegWeight &B);
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 }; 574 };
573 enum MultiBlockState { MBS_Unknown, MBS_SingleBlock, MBS_MultiBlock }; 575 enum MultiBlockState { MBS_Unknown, MBS_SingleBlock, MBS_MultiBlock };
574 VariableTracking() = default; 576 VariableTracking() = default;
575 VariableTracking(const VariableTracking &) = default; 577 VariableTracking(const VariableTracking &) = default;
576 MultiDefState getMultiDef() const { return MultiDef; } 578 MultiDefState getMultiDef() const { return MultiDef; }
577 MultiBlockState getMultiBlock() const { return MultiBlock; } 579 MultiBlockState getMultiBlock() const { return MultiBlock; }
578 const Inst *getFirstDefinition() const; 580 const Inst *getFirstDefinition() const;
579 const Inst *getSingleDefinition() const; 581 const Inst *getSingleDefinition() const;
580 const InstDefList &getLatterDefinitions() const { return Definitions; } 582 const InstDefList &getLatterDefinitions() const { return Definitions; }
581 CfgNode *getNode() const { return SingleUseNode; } 583 CfgNode *getNode() const { return SingleUseNode; }
582 uint32_t getUseWeight() const { return UseWeight; } 584 RegWeight getUseWeight() const { return UseWeight; }
583 void markUse(MetadataKind TrackingKind, const Inst *Instr, CfgNode *Node, 585 void markUse(MetadataKind TrackingKind, const Inst *Instr, CfgNode *Node,
584 bool IsImplicit); 586 bool IsImplicit);
585 void markDef(MetadataKind TrackingKind, const Inst *Instr, CfgNode *Node); 587 void markDef(MetadataKind TrackingKind, const Inst *Instr, CfgNode *Node);
586 588
587 private: 589 private:
588 MultiDefState MultiDef = MDS_Unknown; 590 MultiDefState MultiDef = MDS_Unknown;
589 MultiBlockState MultiBlock = MBS_Unknown; 591 MultiBlockState MultiBlock = MBS_Unknown;
590 CfgNode *SingleUseNode = nullptr; 592 CfgNode *SingleUseNode = nullptr;
591 CfgNode *SingleDefNode = nullptr; 593 CfgNode *SingleDefNode = nullptr;
592 /// All definitions of the variable are collected here, in increasing 594 /// All definitions of the variable are collected here, in increasing
593 /// order of instruction number. 595 /// order of instruction number.
594 InstDefList Definitions; /// Only used if Kind==VMK_All 596 InstDefList Definitions; /// Only used if Kind==VMK_All
595 const Inst *FirstOrSingleDefinition = 597 const Inst *FirstOrSingleDefinition =
596 nullptr; /// Is a copy of Definitions[0] if Kind==VMK_All 598 nullptr; /// Is a copy of Definitions[0] if Kind==VMK_All
597 uint32_t UseWeight = 0; 599 RegWeight UseWeight;
598 }; 600 };
599 601
600 /// VariablesMetadata analyzes and summarizes the metadata for the complete set 602 /// VariablesMetadata analyzes and summarizes the metadata for the complete set
601 /// of Variables. 603 /// of Variables.
602 class VariablesMetadata { 604 class VariablesMetadata {
603 VariablesMetadata() = delete; 605 VariablesMetadata() = delete;
604 VariablesMetadata(const VariablesMetadata &) = delete; 606 VariablesMetadata(const VariablesMetadata &) = delete;
605 VariablesMetadata &operator=(const VariablesMetadata &) = delete; 607 VariablesMetadata &operator=(const VariablesMetadata &) = delete;
606 608
607 public: 609 public:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 /// coalescing. As a special case, function arguments are always 644 /// coalescing. As a special case, function arguments are always
643 /// considered multi-block because they are live coming into the 645 /// considered multi-block because they are live coming into the
644 /// entry block. 646 /// entry block.
645 bool isMultiBlock(const Variable *Var) const; 647 bool isMultiBlock(const Variable *Var) const;
646 /// Returns the node that the given Variable is used in, assuming 648 /// Returns the node that the given Variable is used in, assuming
647 /// isMultiBlock() returns false. Otherwise, nullptr is returned. 649 /// isMultiBlock() returns false. Otherwise, nullptr is returned.
648 CfgNode *getLocalUseNode(const Variable *Var) const; 650 CfgNode *getLocalUseNode(const Variable *Var) const;
649 651
650 /// Returns the total use weight computed as the sum of uses multiplied by a 652 /// Returns the total use weight computed as the sum of uses multiplied by a
651 /// loop nest depth factor for each use. 653 /// loop nest depth factor for each use.
652 uint32_t getUseWeight(const Variable *Var) const; 654 RegWeight getUseWeight(const Variable *Var) const;
653 655
654 private: 656 private:
655 const Cfg *Func; 657 const Cfg *Func;
656 MetadataKind Kind; 658 MetadataKind Kind;
657 std::vector<VariableTracking> Metadata; 659 std::vector<VariableTracking> Metadata;
658 const static InstDefList NoDefinitions; 660 const static InstDefList NoDefinitions;
659 }; 661 };
660 662
661 } // end of namespace Ice 663 } // end of namespace Ice
662 664
663 #endif // SUBZERO_SRC_ICEOPERAND_H 665 #endif // SUBZERO_SRC_ICEOPERAND_H
OLDNEW
« no previous file with comments | « src/IceLoopAnalyzer.cpp ('k') | src/IceOperand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698