Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: src/hydrogen-escape-analysis.h

Issue 21055011: First implementation of allocation elimination in Hydrogen. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Minor cleanup. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 20 matching lines...) Expand all
31 #include "allocation.h" 31 #include "allocation.h"
32 #include "hydrogen.h" 32 #include "hydrogen.h"
33 33
34 namespace v8 { 34 namespace v8 {
35 namespace internal { 35 namespace internal {
36 36
37 37
38 class HEscapeAnalysisPhase : public HPhase { 38 class HEscapeAnalysisPhase : public HPhase {
39 public: 39 public:
40 explicit HEscapeAnalysisPhase(HGraph* graph) 40 explicit HEscapeAnalysisPhase(HGraph* graph)
41 : HPhase("H_Escape analysis", graph), captured_(0, zone()) { } 41 : HPhase("H_Escape analysis", graph),
42 captured_(0, zone()),
43 number_of_values_(0),
44 cumulative_values_(0),
45 backwards_branch_stack_(NULL),
46 block_states_(graph->blocks()->length(), zone()),
47 loops_affected_by_stores_(graph->blocks()->length(), zone()) { }
42 48
43 void Run() { 49 void Run() {
44 CollectCapturedValues(); 50 CollectCapturedValues();
51 PerformScalarReplacement();
45 } 52 }
46 53
47 private: 54 private:
48 void CollectCapturedValues(); 55 void CollectCapturedValues();
49 void CollectIfNoEscapingUses(HInstruction* instr); 56 void CollectIfNoEscapingUses(HInstruction* instr);
57 void PerformScalarReplacement();
58 void AnalyzeDataFlow(HInstruction* instr);
59 void AnalyzeLoopHeaders(HInstruction* instr);
50 60
51 ZoneList<HValue*> captured_; 61 HCapturedObject* NewState(HInstruction* previous) {
titzer 2013/08/01 17:11:50 Not sure why these New* methods are in the header.
Michael Starzinger 2013/08/05 15:13:00 Done. Moved their implementation into the .cc file
62 Zone* zone = graph()->zone();
63 HCapturedObject* state = new(zone) HCapturedObject(number_of_values_, zone);
64 state->InsertAfter(previous);
65 return state;
66 }
67
68 HCapturedObject* NewStateWithUndefined(HInstruction* previous) {
69 HConstant* undefined = graph()->GetConstantUndefined();
70 HCapturedObject* state = NewState(previous);
71 for (int index = 0; index < number_of_values_; index++) {
72 state->SetOperandAt(index, undefined);
73 }
74 return state;
75 }
76
77 HCapturedObject* NewStateWithPhis(HInstruction* previous,
78 HBasicBlock* block) {
79 Zone* zone = graph()->zone();
80 HCapturedObject* state = NewState(previous);
81 HBasicBlock* pred = block->predecessors()->first();
82 int phi_index = pred->last_environment()->length() + cumulative_values_;
83 for (int index = 0; index < number_of_values_; index++) {
84 HPhi* phi = new(zone) HPhi(phi_index + index, zone);
85 block->AddPhi(phi);
86 state->SetOperandAt(index, phi);
87 }
88 return state;
89 }
90
91 HCapturedObject* NewStateWithCopy(HInstruction* previous,
92 HCapturedObject* old_state) {
93 HCapturedObject* state = NewState(previous);
94 for (int index = 0; index < number_of_values_; index++) {
95 state->SetOperandAt(index, old_state->OperandAt(index));
96 }
97 return state;
98 }
99
100 HCapturedObject* StateAt(HBasicBlock* block) {
101 return block_states_.at(block->block_id());
102 }
103
104 void SetStateAt(HBasicBlock* block, HCapturedObject* state) {
105 block_states_.Set(block->block_id(), state);
106 }
107
108 // Stack entry of a backwards branch to be post-processed.
109 struct BackwardsBranch : public ZoneObject {
110 HBasicBlock* block_; // Predecessor of backwards branch.
111 HCapturedObject* state_; // Block state at loop header entry.
112 BackwardsBranch* previous_; // Link to previous entry on stack.
113 };
114
115 void PushBackwardsBranch(HBasicBlock* block, HCapturedObject* state) {
116 BackwardsBranch* entry = new(zone()) BackwardsBranch();
117 entry->block_ = block;
118 entry->state_ = state;
119 entry->previous_ = backwards_branch_stack_;
120 backwards_branch_stack_ = entry;
121 }
122
123 bool PopBackwardsBranch(BackwardsBranch** branch) {
124 BackwardsBranch* entry = *branch = backwards_branch_stack_;
125 backwards_branch_stack_ = entry != NULL ? entry->previous_ : NULL;
126 return entry != NULL;
127 }
128
129 // List of allocations captured during collection phase.
130 ZoneList<HInstruction*> captured_;
131
132 // Number of scalar values tracked during scalar replacement phase.
133 int number_of_values_;
134 int cumulative_values_;
135
136 // Stack of backwards branches to be post-processed after data-flow
137 // analysis finished during the scalar replacement phase.
138 BackwardsBranch* backwards_branch_stack_;
139
140 // Map of block IDs to the data-flow state at block exit during the
141 // scalar replacement phase.
142 ZoneList<HCapturedObject*> block_states_;
143
144 // Vector of loop header block IDs that contain stores into captured
145 // allocations discovered during the scalar replacement phase.
146 BitVector loops_affected_by_stores_;
titzer 2013/08/01 17:11:50 As I understand it, you were going to track which
Michael Starzinger 2013/08/05 15:13:00 Done. Ooops, that is a leftover from a previous im
52 }; 147 };
53 148
54 149
55 } } // namespace v8::internal 150 } } // namespace v8::internal
56 151
57 #endif // V8_HYDROGEN_ESCAPE_ANALYSIS_H_ 152 #endif // V8_HYDROGEN_ESCAPE_ANALYSIS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698