Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef V8_COMPILER_BYTECODE_BASIC_BLOCK_ANALYSIS_H_ | |
| 6 #define V8_COMPILER_BYTECODE_BASIC_BLOCK_ANALYSIS_H_ | |
| 7 | |
| 8 #include "src/bit-vector.h" | |
| 9 #include "src/compiler.h" | |
| 10 #include "src/zone-containers.h" | |
| 11 | |
| 12 namespace v8 { | |
| 13 namespace internal { | |
| 14 namespace compiler { | |
| 15 | |
| 16 class BytecodeBasicBlock; | |
| 17 | |
| 18 class BytecodeBasicBlockAnalysis { | |
| 19 public: | |
| 20 BytecodeBasicBlockAnalysis(Zone* zone, Handle<BytecodeArray> bytecode_array); | |
| 21 const ZoneVector<BytecodeBasicBlock*>* Analyze(); | |
| 22 | |
| 23 private: | |
| 24 void CreateBasicBlock(int start, int end); | |
| 25 void SplitBasicBlock(int offset); | |
| 26 void CreateBasicBlocks(); | |
| 27 void LinkBasicBlocks(); | |
| 28 void AssignRpoOrder(); | |
| 29 void FindDominators(); | |
| 30 void FindDependencyOrder(); | |
| 31 void Dump(); | |
| 32 | |
| 33 Zone* zone() const { return zone_; } | |
| 34 BytecodeBasicBlock* start() { return block_map_[0]; } | |
| 35 BytecodeBasicBlock* exit() { return block_map_[bytecode_array_->length()]; } | |
| 36 | |
| 37 Zone* zone_; | |
| 38 ZoneMap<int, BytecodeBasicBlock*> block_map_; | |
| 39 ZoneVector<BytecodeBasicBlock*> rpo_order_; | |
| 40 ZoneVector<BytecodeBasicBlock*> dependency_order_; | |
| 41 Handle<BytecodeArray> bytecode_array_; | |
| 42 | |
| 43 DISALLOW_COPY_AND_ASSIGN(BytecodeBasicBlockAnalysis); | |
| 44 }; | |
| 45 | |
| 46 class BytecodeBasicBlock final : public ZoneObject { | |
| 47 public: | |
| 48 const int kInvalidOffset = -1; | |
| 49 static const int kUnassignedId = -1; | |
| 50 | |
| 51 BytecodeBasicBlock(Zone* zone, int start, int end) | |
| 52 : start_(start), | |
| 53 end_(end), | |
| 54 last_bytecode_offset_(kInvalidOffset), | |
| 55 if_true_(nullptr), | |
| 56 if_false_(nullptr), | |
| 57 incoming_(zone), | |
| 58 rpo_id_(kUnassignedId), | |
| 59 dominator_rpo_ids_(nullptr) {} | |
| 60 | |
| 61 int rpo_id() const { return rpo_id_; } | |
| 62 int start() const { return start_; } | |
| 63 int end() const { return end_; } | |
| 64 int last_bytecode_offset() const { return last_bytecode_offset_; } | |
| 65 BytecodeBasicBlock* if_true() const { return if_true_; } | |
| 66 BytecodeBasicBlock* if_false() const { return if_false_; } | |
| 67 | |
| 68 bool ends_with_conditional_jump() const { | |
| 69 return if_true_ != nullptr && if_false_ != nullptr; | |
| 70 } | |
| 71 | |
| 72 bool is_exit() const { return if_true_ == nullptr && if_false_ == nullptr; } | |
| 73 | |
| 74 bool is_dominated_by(const BytecodeBasicBlock* block) const { | |
| 75 return dominator_rpo_ids_->Contains(block->rpo_id()); | |
| 76 } | |
| 77 | |
| 78 const BytecodeBasicBlock* incoming(size_t index) const { | |
| 79 return incoming_[index]; | |
| 80 } | |
| 81 const size_t incoming_count() const { return incoming_.size(); } | |
|
rmcilroy
2015/12/08 13:25:07
nit - newline above
oth
2015/12/09 11:26:45
Done.
| |
| 82 | |
| 83 private: | |
| 84 ZoneVector<BytecodeBasicBlock*>* incoming() { return &incoming_; } | |
| 85 void add_incoming(BytecodeBasicBlock* incoming) { | |
|
rmcilroy
2015/12/08 13:25:07
nit - newlines between all these functions down to
oth
2015/12/09 11:26:45
Done.
| |
| 86 incoming_.push_back(incoming); | |
| 87 } | |
| 88 void set_end(int end) { | |
| 89 DCHECK_GT(end, start_); | |
| 90 DCHECK_LE(end, end_); | |
| 91 end_ = end; | |
| 92 } | |
| 93 void set_last_bytecode_offset(int offset) { last_bytecode_offset_ = offset; } | |
| 94 void end_with_conditional_jump(BytecodeBasicBlock* if_true, | |
| 95 BytecodeBasicBlock* if_false) { | |
| 96 DCHECK_NOT_NULL(if_true); | |
| 97 DCHECK_NULL(if_true_); | |
| 98 DCHECK_NOT_NULL(if_false); | |
| 99 DCHECK_NULL(if_false_); | |
| 100 if_true_ = if_true; | |
| 101 if_false_ = if_false; | |
| 102 if_true->add_incoming(this); | |
| 103 if_false->add_incoming(this); | |
| 104 } | |
| 105 void end_with_block(BytecodeBasicBlock* if_true) { | |
| 106 DCHECK_NOT_NULL(if_true); | |
| 107 DCHECK_NULL(if_true_); | |
| 108 DCHECK_NULL(if_false_); | |
| 109 if_true_ = if_true; | |
| 110 if_true->add_incoming(this); | |
| 111 } | |
| 112 | |
| 113 void set_rpo_id(int rpo_id) { rpo_id_ = rpo_id; } | |
| 114 BitVector* dominator_rpo_ids() { return dominator_rpo_ids_; } | |
| 115 void set_dominator_rpo_ids(BitVector* ids) { dominator_rpo_ids_ = ids; } | |
| 116 | |
| 117 int start_; | |
| 118 int end_; | |
| 119 int last_bytecode_offset_; | |
| 120 BytecodeBasicBlock* if_true_; | |
| 121 BytecodeBasicBlock* if_false_; | |
| 122 ZoneVector<BytecodeBasicBlock*> incoming_; | |
| 123 int rpo_id_; | |
| 124 BitVector* dominator_rpo_ids_; | |
| 125 | |
| 126 friend class BytecodeBasicBlockAnalysis; | |
| 127 }; | |
| 128 | |
| 129 } // namespace compiler | |
| 130 } // namespace internal | |
| 131 } // namespace v8 | |
| 132 | |
| 133 #endif // V8_COMPILER_BYTECODE_BASIC_BLOCK_ANALYSIS_H_ | |
| OLD | NEW |