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

Unified Diff: src/hydrogen.cc

Issue 17914002: First simplistic implementation of escape analysis. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/flag-definitions.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index b03bf699389be7864587415c6143280159f27979..94ff56d373ffe73b4fbecf862ce6e1c04f64e4b4 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -2613,6 +2613,62 @@ void HGraph::InferTypes(ZoneList<HValue*>* worklist) {
}
+class HEscapeAnalysis BASE_EMBEDDED {
+ public:
+ explicit HEscapeAnalysis(HGraph* graph)
+ : graph_(graph), zone_(graph->zone()), captured_(0, zone_) { }
+
+ void Analyze();
+
+ private:
+ void CollectCapturedValues();
+ void CollectIfNoEscapingUses(HInstruction* instr);
+
+ HGraph* graph_;
+ Zone* zone_;
+ ZoneList<HValue*> captured_;
+};
+
+
+void HEscapeAnalysis::CollectIfNoEscapingUses(HInstruction* instr) {
+ for (HUseIterator it(instr->uses()); !it.Done(); it.Advance()) {
+ HValue* use = it.value();
+ if (use->HasEscapingOperandAt(it.index())) {
+ if (FLAG_trace_escape_analysis) {
+ PrintF("#%d (%s) escapes through #%d (%s) @%d\n", instr->id(),
+ instr->Mnemonic(), use->id(), use->Mnemonic(), it.index());
+ }
+ return;
+ }
+ }
+ if (FLAG_trace_escape_analysis) {
+ PrintF("#%d (%s) is being captured\n", instr->id(), instr->Mnemonic());
+ }
+ captured_.Add(instr, zone_);
+}
+
+
+void HEscapeAnalysis::CollectCapturedValues() {
+ int block_count = graph_->blocks()->length();
+ for (int i = 0; i < block_count; ++i) {
+ HBasicBlock* block = graph_->blocks()->at(i);
+ HInstruction* instr = block->first();
+ while (instr != block->end()) {
Sven Panne 2013/06/27 07:18:23 A for-loop would be more readable. We really need
Michael Starzinger 2013/06/27 08:17:13 Done. You want an iterator? I give you an iterator
+ if (instr->IsAllocate() || instr->IsAllocateObject()) {
+ CollectIfNoEscapingUses(instr);
+ }
+ instr = instr->next();
+ }
+ }
+}
+
+
+void HEscapeAnalysis::Analyze() {
+ HPhase phase("H_Escape analysis", graph_);
+ CollectCapturedValues();
+}
+
+
class HRangeAnalysis BASE_EMBEDDED {
public:
explicit HRangeAnalysis(HGraph* graph) :
@@ -3983,6 +4039,7 @@ bool HGraph::Optimize(SmartArrayPointer<char>* bailout_reason) {
}
PropagateDeoptimizingMark();
+
if (!CheckConstPhiUses()) {
*bailout_reason = SmartArrayPointer<char>(StrDup(
"Unsupported phi use of const variable"));
@@ -4029,6 +4086,11 @@ bool HGraph::Optimize(SmartArrayPointer<char>* bailout_reason) {
if (FLAG_use_canonicalizing) Canonicalize();
+ if (FLAG_use_escape_analysis) {
+ HEscapeAnalysis escapeAnalysis(this);
+ escapeAnalysis.Analyze();
+ }
+
if (FLAG_use_gvn) GlobalValueNumbering();
if (FLAG_use_range) {
« no previous file with comments | « src/flag-definitions.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698