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 class SideEffects V8_FINAL { | |
Michael Starzinger
2014/02/10 14:50:07
A comment that this is merely a GVNFlagSet plus "s
Benedikt Meurer
2014/02/11 06:40:54
Done.
| |
40 public: | |
41 static const int kNumberOfSpecials = 64 - kNumberOfFlags; | |
42 | |
43 SideEffects() : bits_(0) {} | |
44 explicit SideEffects(GVNFlagSet flags) : bits_(flags.ToIntegral()) {} | |
45 bool IsEmpty() const { return bits_ == 0; } | |
46 bool ContainsFlag(GVNFlag flag) const { | |
47 return (bits_ & MaskFlag(flag)) != 0; | |
48 } | |
49 bool ContainsSpecial(int special) const { | |
50 return (bits_ & MaskSpecial(special)) != 0; | |
51 } | |
52 bool ContainsAnyOf(SideEffects set) const { return (bits_ & set.bits_) != 0; } | |
53 void Add(SideEffects set) { bits_ |= set.bits_; } | |
54 void AddSpecial(int special) { bits_ |= MaskSpecial(special); } | |
55 void AddAllSpecial() { bits_ |= ~static_cast<uint64_t>(0) << kNumberOfFlags; } | |
56 void RemoveFlag(GVNFlag flag) { bits_ &= ~MaskFlag(flag); } | |
57 void RemoveAll() { bits_ = 0; } | |
58 uint64_t ToIntegral() const { return bits_; } | |
59 void PrintTo(StringStream* stream) const; | |
60 | |
61 private: | |
62 uint64_t MaskFlag(GVNFlag flag) const { | |
63 return static_cast<uint64_t>(1) << static_cast<unsigned>(flag); | |
64 } | |
65 uint64_t MaskSpecial(int special) const { | |
66 ASSERT(special >= 0); | |
67 ASSERT(special < kNumberOfSpecials); | |
68 return static_cast<uint64_t>(1) << static_cast<unsigned>( | |
69 special + kNumberOfFlags); | |
70 } | |
71 | |
72 uint64_t bits_; | |
73 STATIC_ASSERT(kNumberOfFlags + kNumberOfSpecials == sizeof(bits_) * CHAR_BIT); | |
74 }; | |
75 | |
76 | |
77 class SideEffectsScope V8_FINAL BASE_EMBEDDED { | |
Michael Starzinger
2014/02/10 14:50:07
Can we have a few comments above this class to exp
Benedikt Meurer
2014/02/11 06:40:54
Done.
Went for SideEffectsTracker, because we alr
| |
78 public: | |
79 SideEffectsScope() : num_inobject_fields_(0) {} | |
80 SideEffects ComputeChanges(HInstruction* instr); | |
81 SideEffects ComputeDependsOn(HInstruction* instr); | |
82 void PrintSideEffectsTo(StringStream* stream, SideEffects side_effects) const; | |
83 | |
84 private: | |
85 bool ComputeInobjectField(HObjectAccess access, int* index); | |
86 | |
87 HObjectAccess inobject_fields_[SideEffects::kNumberOfSpecials]; | |
88 int num_inobject_fields_; | |
89 }; | |
90 | |
91 | |
39 // Perform common subexpression elimination and loop-invariant code motion. | 92 // Perform common subexpression elimination and loop-invariant code motion. |
40 class HGlobalValueNumberingPhase : public HPhase { | 93 class HGlobalValueNumberingPhase V8_FINAL : public HPhase { |
41 public: | 94 public: |
42 explicit HGlobalValueNumberingPhase(HGraph* graph); | 95 explicit HGlobalValueNumberingPhase(HGraph* graph); |
43 | 96 |
44 void Run(); | 97 void Run(); |
45 | 98 |
46 private: | 99 private: |
47 GVNFlagSet CollectSideEffectsOnPathsToDominatedBlock( | 100 SideEffects CollectSideEffectsOnPathsToDominatedBlock( |
48 HBasicBlock* dominator, | 101 HBasicBlock* dominator, |
49 HBasicBlock* dominated); | 102 HBasicBlock* dominated); |
50 void AnalyzeGraph(); | 103 void AnalyzeGraph(); |
51 void ComputeBlockSideEffects(); | 104 void ComputeBlockSideEffects(); |
52 void LoopInvariantCodeMotion(); | 105 void LoopInvariantCodeMotion(); |
53 void ProcessLoopBlock(HBasicBlock* block, | 106 void ProcessLoopBlock(HBasicBlock* block, |
54 HBasicBlock* before_loop, | 107 HBasicBlock* before_loop, |
55 GVNFlagSet loop_kills); | 108 SideEffects loop_kills); |
56 bool AllowCodeMotion(); | 109 bool AllowCodeMotion(); |
57 bool ShouldMove(HInstruction* instr, HBasicBlock* loop_header); | 110 bool ShouldMove(HInstruction* instr, HBasicBlock* loop_header); |
58 | 111 |
112 SideEffectsScope side_effects_scope_; | |
59 bool removed_side_effects_; | 113 bool removed_side_effects_; |
60 | 114 |
61 // A map of block IDs to their side effects. | 115 // A map of block IDs to their side effects. |
62 ZoneList<GVNFlagSet> block_side_effects_; | 116 ZoneList<SideEffects> block_side_effects_; |
63 | 117 |
64 // A map of loop header block IDs to their loop's side effects. | 118 // A map of loop header block IDs to their loop's side effects. |
65 ZoneList<GVNFlagSet> loop_side_effects_; | 119 ZoneList<SideEffects> loop_side_effects_; |
66 | 120 |
67 // Used when collecting side effects on paths from dominator to | 121 // Used when collecting side effects on paths from dominator to |
68 // dominated. | 122 // dominated. |
69 BitVector visited_on_paths_; | 123 BitVector visited_on_paths_; |
70 | 124 |
71 DISALLOW_COPY_AND_ASSIGN(HGlobalValueNumberingPhase); | 125 DISALLOW_COPY_AND_ASSIGN(HGlobalValueNumberingPhase); |
72 }; | 126 }; |
73 | 127 |
74 | |
75 } } // namespace v8::internal | 128 } } // namespace v8::internal |
76 | 129 |
77 #endif // V8_HYDROGEN_GVN_H_ | 130 #endif // V8_HYDROGEN_GVN_H_ |
OLD | NEW |