Chromium Code Reviews| Index: vm/intermediate_language.h |
| =================================================================== |
| --- vm/intermediate_language.h (revision 8546) |
| +++ vm/intermediate_language.h (working copy) |
| @@ -282,18 +282,23 @@ |
| virtual void PrintTo(BufferFormatter* f) const; |
| +class Definition; |
| class BindInstr; |
| +class PhiInstr; |
| class UseVal : public Value { |
| public: |
| - explicit UseVal(BindInstr* definition) : definition_(definition) {} |
| + explicit UseVal(Definition* definition) : definition_(definition) {} |
| DECLARE_VALUE(Use) |
| - BindInstr* definition() const { return definition_; } |
| + Definition* definition() const { return definition_; } |
| + void set_definition(Definition* definition) { |
| + definition_ = definition; |
| + } |
|
srdjan
2012/06/12 17:34:37
Why do you need set_defintion?
Florian Schneider
2012/06/13 10:53:40
Renaming. I could leave it out for this CL. Left-o
|
| private: |
| - BindInstr* definition_; |
| + Definition* definition_; |
| DISALLOW_COPY_AND_ASSIGN(UseVal); |
| }; |
| @@ -1482,6 +1487,8 @@ |
| DECLARE_COMPUTATION(NumberNegate) |
| + void InsertPhi(intptr_t variable_index) { } |
|
srdjan
2012/06/12 17:34:37
Why is this needed?
Florian Schneider
2012/06/13 10:53:40
Accidental edit.
|
| + |
| private: |
| InstanceCallComp* instance_call_; |
| @@ -1542,6 +1549,7 @@ |
| M(TargetEntry) \ |
| M(Do) \ |
| M(Bind) \ |
| + M(Phi) \ |
| M(Return) \ |
| M(Throw) \ |
| M(ReThrow) \ |
| @@ -1563,6 +1571,7 @@ |
| virtual bool Is##type() const { return true; } \ |
| virtual type##Instr* As##type() { return this; } \ |
| virtual intptr_t InputCount() const; \ |
| + virtual Value* InputAt(intptr_t i) const; \ |
| virtual const char* DebugName() const { return #type; } \ |
| virtual void PrintTo(BufferFormatter* f) const; \ |
| virtual void PrintToVisualizer(BufferFormatter* f) const; |
| @@ -1586,12 +1595,11 @@ |
| BlockEntryInstr* AsBlockEntry() { |
| return IsBlockEntry() ? reinterpret_cast<BlockEntryInstr*>(this) : NULL; |
| } |
| - virtual bool IsBindInstr() const { return false; } |
| - virtual BindInstr* AsBindInstr() { |
| - return NULL; |
| - } |
| + virtual bool IsDefinition() const { return false; } |
| + virtual Definition* AsDefinition() { return NULL; } |
| virtual intptr_t InputCount() const = 0; |
| + virtual Value* InputAt(intptr_t i) const = 0; |
| // Visiting support. |
| virtual Instruction* Accept(FlowGraphVisitor* visitor) = 0; |
| @@ -1718,6 +1726,11 @@ |
| BlockEntryInstr* dominator() const { return dominator_; } |
| void set_dominator(BlockEntryInstr* instr) { dominator_ = instr; } |
| + // TODO(fschneider): Optimize the case of one child to save space. |
| + GrowableArray<BlockEntryInstr*>* dominated_blocks() { |
| + return &dominated_blocks_; |
| + } |
|
srdjan
2012/06/12 17:34:37
Instead of returning a modifieable array, better a
Florian Schneider
2012/06/13 10:53:40
Done.
|
| + |
| Instruction* last_instruction() const { return last_instruction_; } |
| void set_last_instruction(Instruction* instr) { last_instruction_ = instr; } |
| @@ -1735,6 +1748,7 @@ |
| postorder_number_(-1), |
| block_id_(-1), |
| dominator_(NULL), |
| + dominated_blocks_(1), |
| last_instruction_(NULL) { } |
| private: |
| @@ -1742,6 +1756,7 @@ |
| intptr_t postorder_number_; |
| intptr_t block_id_; |
| BlockEntryInstr* dominator_; // Immediate dominator, NULL for graph entry. |
| + GrowableArray<BlockEntryInstr*> dominated_blocks_; |
| Instruction* last_instruction_; |
| DISALLOW_COPY_AND_ASSIGN(BlockEntryInstr); |
| @@ -1793,7 +1808,9 @@ |
| JoinEntryInstr() |
| : BlockEntryInstr(), |
| predecessors_(2), // Two is the assumed to be the common case. |
| - successor_(NULL) { } |
| + successor_(NULL), |
| + phis_(NULL), |
| + phi_count_(0) { } |
| DECLARE_INSTRUCTION(JoinEntry) |
| @@ -1813,11 +1830,19 @@ |
| successor_ = instr; |
| } |
| + ZoneGrowableArray<PhiInstr*>* phis() const { return phis_; } |
|
srdjan
2012/06/12 17:34:37
const ZoneGrowableArray<...>& ?
Florian Schneider
2012/06/13 10:53:40
phis_ can be NULL.
|
| + |
| virtual void PrepareEntry(FlowGraphCompiler* compiler); |
| + void InsertPhi(intptr_t var_index, intptr_t var_count); |
|
srdjan
2012/06/12 17:34:37
Get rid of var_count, it is used only to allocate
Florian Schneider
2012/06/13 10:53:40
Growable arrays incur a high cost when not used wi
srdjan
2012/06/13 18:45:26
Yes, but the 'var_count' looks weird in the API, a
|
| + |
| + intptr_t phi_count() const { return phi_count_; } |
| + |
| private: |
| ZoneGrowableArray<BlockEntryInstr*> predecessors_; |
| Instruction* successor_; |
| + ZoneGrowableArray<PhiInstr*>* phis_; |
| + intptr_t phi_count_; |
| DISALLOW_COPY_AND_ASSIGN(JoinEntryInstr); |
| }; |
| @@ -1920,22 +1945,33 @@ |
| }; |
| -class BindInstr : public Instruction { |
| +class Definition : public Instruction { |
| public: |
| + Definition() : temp_index_(-1) { } |
| + |
| + virtual bool IsDefinition() const { return true; } |
| + virtual Definition* AsDefinition() { return this; } |
| + |
| + intptr_t temp_index() const { return temp_index_; } |
| + void set_temp_index(intptr_t index) { temp_index_ = index; } |
|
srdjan
2012/06/12 17:34:37
Add a comment to something like that this is the c
Florian Schneider
2012/06/13 10:53:40
Done.
|
| + |
| + private: |
| + intptr_t temp_index_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Definition); |
| +}; |
| + |
| + |
| +class BindInstr : public Definition { |
| + public: |
| explicit BindInstr(Computation* computation) |
| - : temp_index_(-1), computation_(computation), successor_(NULL) { |
| + : computation_(computation), successor_(NULL) { |
| ASSERT(computation != NULL); |
| computation->set_instr(this); |
| } |
| DECLARE_INSTRUCTION(Bind) |
| - virtual bool IsBindInstr() const { return true; } |
| - virtual BindInstr* AsBindInstr() { return this; } |
| - |
| - intptr_t temp_index() const { return temp_index_; } |
| - void set_temp_index(intptr_t index) { temp_index_ = index; } |
| - |
| Computation* computation() const { return computation_; } |
| virtual void replace_computation(Computation* value) { computation_ = value; } |
| @@ -1962,7 +1998,6 @@ |
| virtual void EmitNativeCode(FlowGraphCompiler* compiler); |
| private: |
| - intptr_t temp_index_; |
| Computation* computation_; |
| Instruction* successor_; |
| @@ -1970,6 +2005,32 @@ |
| }; |
| +class PhiInstr: public Definition { |
| + public: |
| + explicit PhiInstr(intptr_t num_inputs) : inputs_(num_inputs) { |
| + for (intptr_t i = 0; i < num_inputs; ++i) { |
| + inputs_.Add(NULL); |
| + } |
| + } |
| + |
| + DECLARE_INSTRUCTION(Phi) |
| + |
| + void SetInputAt(intptr_t i, Value* value) { |
| + inputs_[i] = value; |
| + } |
| + |
| + virtual Instruction* StraightLineSuccessor() const { return NULL; } |
| + virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); } |
| + |
| + private: |
| + GrowableArray<Value*> inputs_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PhiInstr); |
| +}; |
| + |
| + |
| + |
| + |
| class ReturnInstr : public InstructionWithInputs { |
| public: |
| ReturnInstr(intptr_t token_index, Value* value) |