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

Side by Side Diff: src/hydrogen.cc

Issue 18758003: Turn canonicalization into a proper HPhase. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 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
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-canonicalize.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 16 matching lines...) Expand all
27 27
28 #include "hydrogen.h" 28 #include "hydrogen.h"
29 29
30 #include <algorithm> 30 #include <algorithm>
31 31
32 #include "v8.h" 32 #include "v8.h"
33 #include "codegen.h" 33 #include "codegen.h"
34 #include "full-codegen.h" 34 #include "full-codegen.h"
35 #include "hashmap.h" 35 #include "hashmap.h"
36 #include "hydrogen-bce.h" 36 #include "hydrogen-bce.h"
37 #include "hydrogen-canonicalize.h"
37 #include "hydrogen-dce.h" 38 #include "hydrogen-dce.h"
38 #include "hydrogen-environment-liveness.h" 39 #include "hydrogen-environment-liveness.h"
39 #include "hydrogen-escape-analysis.h" 40 #include "hydrogen-escape-analysis.h"
40 #include "hydrogen-infer-representation.h" 41 #include "hydrogen-infer-representation.h"
41 #include "hydrogen-infer-types.h" 42 #include "hydrogen-infer-types.h"
42 #include "hydrogen-gvn.h" 43 #include "hydrogen-gvn.h"
43 #include "hydrogen-minus-zero.h" 44 #include "hydrogen-minus-zero.h"
44 #include "hydrogen-osr.h" 45 #include "hydrogen-osr.h"
45 #include "hydrogen-range-analysis.h" 46 #include "hydrogen-range-analysis.h"
46 #include "hydrogen-redundant-phi.h" 47 #include "hydrogen-redundant-phi.h"
(...skipping 2036 matching lines...) Expand 10 before | Expand all | Expand 10 after
2083 DisallowHeapAllocation no_gc; 2084 DisallowHeapAllocation no_gc;
2084 ASSERT(!isolate()->optimizing_compiler_thread()->IsOptimizerThread()); 2085 ASSERT(!isolate()->optimizing_compiler_thread()->IsOptimizerThread());
2085 for (int i = 0; i < blocks()->length(); ++i) { 2086 for (int i = 0; i < blocks()->length(); ++i) {
2086 for (HInstructionIterator it(blocks()->at(i)); !it.Done(); it.Advance()) { 2087 for (HInstructionIterator it(blocks()->at(i)); !it.Done(); it.Advance()) {
2087 it.Current()->FinalizeUniqueValueId(); 2088 it.Current()->FinalizeUniqueValueId();
2088 } 2089 }
2089 } 2090 }
2090 } 2091 }
2091 2092
2092 2093
2093 void HGraph::Canonicalize() {
2094 HPhase phase("H_Canonicalize", this);
2095 // Before removing no-op instructions, save their semantic value.
2096 // We must be careful not to set the flag unnecessarily, because GVN
2097 // cannot identify two instructions when their flag value differs.
2098 for (int i = 0; i < blocks()->length(); ++i) {
2099 for (HInstructionIterator it(blocks()->at(i)); !it.Done(); it.Advance()) {
2100 HInstruction* instr = it.Current();
2101 if (instr->IsArithmeticBinaryOperation() &&
2102 instr->representation().IsInteger32() &&
2103 instr->HasAtLeastOneUseWithFlagAndNoneWithout(
2104 HInstruction::kTruncatingToInt32)) {
2105 instr->SetFlag(HInstruction::kAllUsesTruncatingToInt32);
2106 }
2107 }
2108 }
2109 // Perform actual Canonicalization pass.
2110 for (int i = 0; i < blocks()->length(); ++i) {
2111 for (HInstructionIterator it(blocks()->at(i)); !it.Done(); it.Advance()) {
2112 HInstruction* instr = it.Current();
2113 HValue* value = instr->Canonicalize();
2114 if (value != instr) instr->DeleteAndReplaceWith(value);
2115 }
2116 }
2117 }
2118
2119
2120 // Block ordering was implemented with two mutually recursive methods, 2094 // Block ordering was implemented with two mutually recursive methods,
2121 // HGraph::Postorder and HGraph::PostorderLoopBlocks. 2095 // HGraph::Postorder and HGraph::PostorderLoopBlocks.
2122 // The recursion could lead to stack overflow so the algorithm has been 2096 // The recursion could lead to stack overflow so the algorithm has been
2123 // implemented iteratively. 2097 // implemented iteratively.
2124 // At a high level the algorithm looks like this: 2098 // At a high level the algorithm looks like this:
2125 // 2099 //
2126 // Postorder(block, loop_header) : { 2100 // Postorder(block, loop_header) : {
2127 // if (block has already been visited or is of another loop) return; 2101 // if (block has already been visited or is of another loop) return;
2128 // mark block as visited; 2102 // mark block as visited;
2129 // if (block is a loop header) { 2103 // if (block is a loop header) {
(...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after
3142 MarkDeoptimizeOnUndefined(); 3116 MarkDeoptimizeOnUndefined();
3143 Run<HRepresentationChangesPhase>(); 3117 Run<HRepresentationChangesPhase>();
3144 3118
3145 Run<HInferTypesPhase>(); 3119 Run<HInferTypesPhase>();
3146 3120
3147 // Must be performed before canonicalization to ensure that Canonicalize 3121 // Must be performed before canonicalization to ensure that Canonicalize
3148 // will not remove semantically meaningful ToInt32 operations e.g. BIT_OR with 3122 // will not remove semantically meaningful ToInt32 operations e.g. BIT_OR with
3149 // zero. 3123 // zero.
3150 if (FLAG_opt_safe_uint32_operations) Run<HUint32AnalysisPhase>(); 3124 if (FLAG_opt_safe_uint32_operations) Run<HUint32AnalysisPhase>();
3151 3125
3152 if (FLAG_use_canonicalizing) Canonicalize(); 3126 if (FLAG_use_canonicalizing) Run<HCanonicalizePhase>();
3153 3127
3154 if (FLAG_use_escape_analysis) Run<HEscapeAnalysisPhase>(); 3128 if (FLAG_use_escape_analysis) Run<HEscapeAnalysisPhase>();
3155 3129
3156 if (FLAG_use_gvn) Run<HGlobalValueNumberingPhase>(); 3130 if (FLAG_use_gvn) Run<HGlobalValueNumberingPhase>();
3157 3131
3158 if (FLAG_use_range) Run<HRangeAnalysisPhase>(); 3132 if (FLAG_use_range) Run<HRangeAnalysisPhase>();
3159 3133
3160 Run<HComputeMinusZeroChecksPhase>(); 3134 Run<HComputeMinusZeroChecksPhase>();
3161 3135
3162 // Eliminate redundant stack checks on backwards branches. 3136 // Eliminate redundant stack checks on backwards branches.
(...skipping 7013 matching lines...) Expand 10 before | Expand all | Expand 10 after
10176 if (ShouldProduceTraceOutput()) { 10150 if (ShouldProduceTraceOutput()) {
10177 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 10151 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
10178 } 10152 }
10179 10153
10180 #ifdef DEBUG 10154 #ifdef DEBUG
10181 graph_->Verify(false); // No full verify. 10155 graph_->Verify(false); // No full verify.
10182 #endif 10156 #endif
10183 } 10157 }
10184 10158
10185 } } // namespace v8::internal 10159 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-canonicalize.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698