| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 bool IsEmpty() const { return bits_ == 0; } | 51 bool IsEmpty() const { return bits_ == 0; } |
| 52 bool ContainsFlag(GVNFlag flag) const { | 52 bool ContainsFlag(GVNFlag flag) const { |
| 53 return (bits_ & MaskFlag(flag)) != 0; | 53 return (bits_ & MaskFlag(flag)) != 0; |
| 54 } | 54 } |
| 55 bool ContainsSpecial(int special) const { | 55 bool ContainsSpecial(int special) const { |
| 56 return (bits_ & MaskSpecial(special)) != 0; | 56 return (bits_ & MaskSpecial(special)) != 0; |
| 57 } | 57 } |
| 58 bool ContainsAnyOf(SideEffects set) const { return (bits_ & set.bits_) != 0; } | 58 bool ContainsAnyOf(SideEffects set) const { return (bits_ & set.bits_) != 0; } |
| 59 void Add(SideEffects set) { bits_ |= set.bits_; } | 59 void Add(SideEffects set) { bits_ |= set.bits_; } |
| 60 void AddSpecial(int special) { bits_ |= MaskSpecial(special); } | 60 void AddSpecial(int special) { bits_ |= MaskSpecial(special); } |
| 61 void AddAllSpecial() { bits_ |= ~static_cast<uint64_t>(0) << kNumberOfFlags; } | |
| 62 void RemoveFlag(GVNFlag flag) { bits_ &= ~MaskFlag(flag); } | 61 void RemoveFlag(GVNFlag flag) { bits_ &= ~MaskFlag(flag); } |
| 63 void RemoveAll() { bits_ = 0; } | 62 void RemoveAll() { bits_ = 0; } |
| 64 uint64_t ToIntegral() const { return bits_; } | 63 uint64_t ToIntegral() const { return bits_; } |
| 65 void PrintTo(StringStream* stream) const; | 64 void PrintTo(StringStream* stream) const; |
| 66 | 65 |
| 67 private: | 66 private: |
| 68 uint64_t MaskFlag(GVNFlag flag) const { | 67 uint64_t MaskFlag(GVNFlag flag) const { |
| 69 return static_cast<uint64_t>(1) << static_cast<unsigned>(flag); | 68 return static_cast<uint64_t>(1) << static_cast<unsigned>(flag); |
| 70 } | 69 } |
| 71 uint64_t MaskSpecial(int special) const { | 70 uint64_t MaskSpecial(int special) const { |
| 72 ASSERT(special >= 0); | 71 ASSERT(special >= 0); |
| 73 ASSERT(special < kNumberOfSpecials); | 72 ASSERT(special < kNumberOfSpecials); |
| 74 return static_cast<uint64_t>(1) << static_cast<unsigned>( | 73 return static_cast<uint64_t>(1) << static_cast<unsigned>( |
| 75 special + kNumberOfFlags); | 74 special + kNumberOfFlags); |
| 76 } | 75 } |
| 77 | 76 |
| 78 uint64_t bits_; | 77 uint64_t bits_; |
| 79 }; | 78 }; |
| 80 | 79 |
| 81 | 80 |
| 82 // Tracks inobject field loads/stores in a fine grained fashion, and represents | 81 // Tracks global variable and inobject field loads/stores in a fine grained |
| 83 // them using the "special" dynamic side effects of the SideEffects class (see | 82 // fashion, and represents them using the "special" dynamic side effects of the |
| 84 // above). This way unrelated inobject field stores don't prevent hoisting and | 83 // SideEffects class (see above). This way unrelated global variable/inobject |
| 85 // merging of inobject field loads. | 84 // field stores don't prevent hoisting and merging of global variable/inobject |
| 85 // field loads. |
| 86 class SideEffectsTracker V8_FINAL BASE_EMBEDDED { | 86 class SideEffectsTracker V8_FINAL BASE_EMBEDDED { |
| 87 public: | 87 public: |
| 88 SideEffectsTracker() : num_inobject_fields_(0) {} | 88 SideEffectsTracker() : num_global_vars_(0), num_inobject_fields_(0) {} |
| 89 SideEffects ComputeChanges(HInstruction* instr); | 89 SideEffects ComputeChanges(HInstruction* instr); |
| 90 SideEffects ComputeDependsOn(HInstruction* instr); | 90 SideEffects ComputeDependsOn(HInstruction* instr); |
| 91 void PrintSideEffectsTo(StringStream* stream, SideEffects side_effects) const; | 91 void PrintSideEffectsTo(StringStream* stream, SideEffects side_effects) const; |
| 92 | 92 |
| 93 private: | 93 private: |
| 94 bool ComputeGlobalVar(Unique<Cell> cell, int* index); |
| 94 bool ComputeInobjectField(HObjectAccess access, int* index); | 95 bool ComputeInobjectField(HObjectAccess access, int* index); |
| 95 | 96 |
| 96 HObjectAccess inobject_fields_[SideEffects::kNumberOfSpecials]; | 97 static int GlobalVar(int index) { |
| 98 ASSERT(index >= 0); |
| 99 ASSERT(index < kNumberOfGlobalVars); |
| 100 return index; |
| 101 } |
| 102 static int InobjectField(int index) { |
| 103 ASSERT(index >= 0); |
| 104 ASSERT(index < kNumberOfInobjectFields); |
| 105 return index + kNumberOfGlobalVars; |
| 106 } |
| 107 |
| 108 // Track up to four global vars. |
| 109 static const int kNumberOfGlobalVars = 4; |
| 110 Unique<Cell> global_vars_[kNumberOfGlobalVars]; |
| 111 int num_global_vars_; |
| 112 |
| 113 // Track up to n inobject fields. |
| 114 static const int kNumberOfInobjectFields = |
| 115 SideEffects::kNumberOfSpecials - kNumberOfGlobalVars; |
| 116 HObjectAccess inobject_fields_[kNumberOfInobjectFields]; |
| 97 int num_inobject_fields_; | 117 int num_inobject_fields_; |
| 98 }; | 118 }; |
| 99 | 119 |
| 100 | 120 |
| 101 // Perform common subexpression elimination and loop-invariant code motion. | 121 // Perform common subexpression elimination and loop-invariant code motion. |
| 102 class HGlobalValueNumberingPhase V8_FINAL : public HPhase { | 122 class HGlobalValueNumberingPhase V8_FINAL : public HPhase { |
| 103 public: | 123 public: |
| 104 explicit HGlobalValueNumberingPhase(HGraph* graph); | 124 explicit HGlobalValueNumberingPhase(HGraph* graph); |
| 105 | 125 |
| 106 void Run(); | 126 void Run(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 130 // Used when collecting side effects on paths from dominator to | 150 // Used when collecting side effects on paths from dominator to |
| 131 // dominated. | 151 // dominated. |
| 132 BitVector visited_on_paths_; | 152 BitVector visited_on_paths_; |
| 133 | 153 |
| 134 DISALLOW_COPY_AND_ASSIGN(HGlobalValueNumberingPhase); | 154 DISALLOW_COPY_AND_ASSIGN(HGlobalValueNumberingPhase); |
| 135 }; | 155 }; |
| 136 | 156 |
| 137 } } // namespace v8::internal | 157 } } // namespace v8::internal |
| 138 | 158 |
| 139 #endif // V8_HYDROGEN_GVN_H_ | 159 #endif // V8_HYDROGEN_GVN_H_ |
| OLD | NEW |