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