| 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 18 matching lines...) Expand all Loading... |
| 29 #define V8_HYDROGEN_GVN_H_ | 29 #define V8_HYDROGEN_GVN_H_ |
| 30 | 30 |
| 31 #include "hydrogen.h" | 31 #include "hydrogen.h" |
| 32 #include "hydrogen-instructions.h" | 32 #include "hydrogen-instructions.h" |
| 33 #include "compiler.h" | 33 #include "compiler.h" |
| 34 #include "zone.h" | 34 #include "zone.h" |
| 35 | 35 |
| 36 namespace v8 { | 36 namespace v8 { |
| 37 namespace internal { | 37 namespace internal { |
| 38 | 38 |
| 39 // This class extends GVNFlagSet with additional "special" dynamic side effects, | |
| 40 // which can be used to represent side effects that cannot be expressed using | |
| 41 // the GVNFlags of an HInstruction. These special side effects are tracked by a | |
| 42 // SideEffectsTracker (see below). | |
| 43 class SideEffects V8_FINAL { | |
| 44 public: | |
| 45 static const int kNumberOfSpecials = 64 - kNumberOfFlags; | |
| 46 | |
| 47 SideEffects() : bits_(0) { | |
| 48 ASSERT(kNumberOfFlags + kNumberOfSpecials == sizeof(bits_) * CHAR_BIT); | |
| 49 } | |
| 50 explicit SideEffects(GVNFlagSet flags) : bits_(flags.ToIntegral()) {} | |
| 51 bool IsEmpty() const { return bits_ == 0; } | |
| 52 bool ContainsFlag(GVNFlag flag) const { | |
| 53 return (bits_ & MaskFlag(flag)) != 0; | |
| 54 } | |
| 55 bool ContainsSpecial(int special) const { | |
| 56 return (bits_ & MaskSpecial(special)) != 0; | |
| 57 } | |
| 58 bool ContainsAnyOf(SideEffects set) const { return (bits_ & set.bits_) != 0; } | |
| 59 void Add(SideEffects set) { bits_ |= set.bits_; } | |
| 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); } | |
| 63 void RemoveAll() { bits_ = 0; } | |
| 64 uint64_t ToIntegral() const { return bits_; } | |
| 65 void PrintTo(StringStream* stream) const; | |
| 66 | |
| 67 private: | |
| 68 uint64_t MaskFlag(GVNFlag flag) const { | |
| 69 return static_cast<uint64_t>(1) << static_cast<unsigned>(flag); | |
| 70 } | |
| 71 uint64_t MaskSpecial(int special) const { | |
| 72 ASSERT(special >= 0); | |
| 73 ASSERT(special < kNumberOfSpecials); | |
| 74 return static_cast<uint64_t>(1) << static_cast<unsigned>( | |
| 75 special + kNumberOfFlags); | |
| 76 } | |
| 77 | |
| 78 uint64_t bits_; | |
| 79 }; | |
| 80 | |
| 81 | |
| 82 // Tracks inobject field loads/stores in a fine grained fashion, and represents | |
| 83 // them using the "special" dynamic side effects of the SideEffects class (see | |
| 84 // above). This way unrelated inobject field stores don't prevent hoisting and | |
| 85 // merging of inobject field loads. | |
| 86 class SideEffectsTracker V8_FINAL BASE_EMBEDDED { | |
| 87 public: | |
| 88 SideEffectsTracker() : num_inobject_fields_(0) {} | |
| 89 SideEffects ComputeChanges(HInstruction* instr); | |
| 90 SideEffects ComputeDependsOn(HInstruction* instr); | |
| 91 void PrintSideEffectsTo(StringStream* stream, SideEffects side_effects) const; | |
| 92 | |
| 93 private: | |
| 94 bool ComputeInobjectField(HObjectAccess access, int* index); | |
| 95 | |
| 96 HObjectAccess inobject_fields_[SideEffects::kNumberOfSpecials]; | |
| 97 int num_inobject_fields_; | |
| 98 }; | |
| 99 | |
| 100 | |
| 101 // Perform common subexpression elimination and loop-invariant code motion. | 39 // Perform common subexpression elimination and loop-invariant code motion. |
| 102 class HGlobalValueNumberingPhase V8_FINAL : public HPhase { | 40 class HGlobalValueNumberingPhase : public HPhase { |
| 103 public: | 41 public: |
| 104 explicit HGlobalValueNumberingPhase(HGraph* graph); | 42 explicit HGlobalValueNumberingPhase(HGraph* graph); |
| 105 | 43 |
| 106 void Run(); | 44 void Run(); |
| 107 | 45 |
| 108 private: | 46 private: |
| 109 SideEffects CollectSideEffectsOnPathsToDominatedBlock( | 47 GVNFlagSet CollectSideEffectsOnPathsToDominatedBlock( |
| 110 HBasicBlock* dominator, | 48 HBasicBlock* dominator, |
| 111 HBasicBlock* dominated); | 49 HBasicBlock* dominated); |
| 112 void AnalyzeGraph(); | 50 void AnalyzeGraph(); |
| 113 void ComputeBlockSideEffects(); | 51 void ComputeBlockSideEffects(); |
| 114 void LoopInvariantCodeMotion(); | 52 void LoopInvariantCodeMotion(); |
| 115 void ProcessLoopBlock(HBasicBlock* block, | 53 void ProcessLoopBlock(HBasicBlock* block, |
| 116 HBasicBlock* before_loop, | 54 HBasicBlock* before_loop, |
| 117 SideEffects loop_kills); | 55 GVNFlagSet loop_kills); |
| 118 bool AllowCodeMotion(); | 56 bool AllowCodeMotion(); |
| 119 bool ShouldMove(HInstruction* instr, HBasicBlock* loop_header); | 57 bool ShouldMove(HInstruction* instr, HBasicBlock* loop_header); |
| 120 | 58 |
| 121 SideEffectsTracker side_effects_tracker_; | |
| 122 bool removed_side_effects_; | 59 bool removed_side_effects_; |
| 123 | 60 |
| 124 // A map of block IDs to their side effects. | 61 // A map of block IDs to their side effects. |
| 125 ZoneList<SideEffects> block_side_effects_; | 62 ZoneList<GVNFlagSet> block_side_effects_; |
| 126 | 63 |
| 127 // A map of loop header block IDs to their loop's side effects. | 64 // A map of loop header block IDs to their loop's side effects. |
| 128 ZoneList<SideEffects> loop_side_effects_; | 65 ZoneList<GVNFlagSet> loop_side_effects_; |
| 129 | 66 |
| 130 // Used when collecting side effects on paths from dominator to | 67 // Used when collecting side effects on paths from dominator to |
| 131 // dominated. | 68 // dominated. |
| 132 BitVector visited_on_paths_; | 69 BitVector visited_on_paths_; |
| 133 | 70 |
| 134 DISALLOW_COPY_AND_ASSIGN(HGlobalValueNumberingPhase); | 71 DISALLOW_COPY_AND_ASSIGN(HGlobalValueNumberingPhase); |
| 135 }; | 72 }; |
| 136 | 73 |
| 74 |
| 137 } } // namespace v8::internal | 75 } } // namespace v8::internal |
| 138 | 76 |
| 139 #endif // V8_HYDROGEN_GVN_H_ | 77 #endif // V8_HYDROGEN_GVN_H_ |
| OLD | NEW |