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

Side by Side Diff: src/codegen.cc

Issue 2575703003: Move TraceInlinedFunction from Hydrogen graph builder to CompilationInfo. (Closed)
Patch Set: Address comments Created 4 years 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
« no previous file with comments | « no previous file | src/compiler/graph-visualizer.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/codegen.h" 5 #include "src/codegen.h"
6 6
7 #if defined(V8_OS_AIX) 7 #if defined(V8_OS_AIX)
8 #include <fenv.h> // NOLINT(build/c++11) 8 #include <fenv.h> // NOLINT(build/c++11)
9 #endif 9 #endif
10 10
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 Handle<Code> code = isolate->factory()->NewCode( 130 Handle<Code> code = isolate->factory()->NewCode(
131 desc, flags, self_reference, false, is_crankshafted, 131 desc, flags, self_reference, false, is_crankshafted,
132 info->prologue_offset(), info->is_debug() && !is_crankshafted); 132 info->prologue_offset(), info->is_debug() && !is_crankshafted);
133 isolate->counters()->total_compiled_code_size()->Increment( 133 isolate->counters()->total_compiled_code_size()->Increment(
134 code->instruction_size()); 134 code->instruction_size());
135 isolate->heap()->IncrementCodeGeneratedBytes(is_crankshafted, 135 isolate->heap()->IncrementCodeGeneratedBytes(is_crankshafted,
136 code->instruction_size()); 136 code->instruction_size());
137 return code; 137 return code;
138 } 138 }
139 139
140 // Print function's source if it was not printed before.
141 // Return a sequential id under which this function was printed.
142 static int PrintFunctionSource(CompilationInfo* info,
143 std::vector<Handle<SharedFunctionInfo>>* printed,
144 int inlining_id,
145 Handle<SharedFunctionInfo> shared) {
146 // Outermost function has source id -1 and inlined functions take
147 // source ids starting from 0.
148 int source_id = -1;
149 if (inlining_id != SourcePosition::kNotInlined) {
150 for (unsigned i = 0; i < printed->size(); i++) {
151 if (printed->at(i).is_identical_to(shared)) {
152 return i;
153 }
154 }
155 source_id = static_cast<int>(printed->size());
156 printed->push_back(shared);
157 }
158
159 Isolate* isolate = info->isolate();
160 if (!shared->script()->IsUndefined(isolate)) {
161 Handle<Script> script(Script::cast(shared->script()), isolate);
162
163 if (!script->source()->IsUndefined(isolate)) {
164 CodeTracer::Scope tracing_scope(isolate->GetCodeTracer());
165 Object* source_name = script->name();
166 OFStream os(tracing_scope.file());
167 os << "--- FUNCTION SOURCE (";
168 if (source_name->IsString()) {
169 os << String::cast(source_name)->ToCString().get() << ":";
170 }
171 os << shared->DebugName()->ToCString().get() << ") id{";
172 os << info->optimization_id() << "," << source_id << "} start{";
173 os << shared->start_position() << "} ---\n";
174 {
175 DisallowHeapAllocation no_allocation;
176 int start = shared->start_position();
177 int len = shared->end_position() - start;
178 String::SubStringRange source(String::cast(script->source()), start,
179 len);
180 for (const auto& c : source) {
181 os << AsReversiblyEscapedUC16(c);
182 }
183 }
184
185 os << "\n--- END ---\n";
186 }
187 }
188
189 return source_id;
190 }
191
192 // Print information for the given inlining: which function was inlined and
193 // where the inlining occured.
194 static void PrintInlinedFunctionInfo(
195 CompilationInfo* info, int source_id, int inlining_id,
196 const CompilationInfo::InlinedFunctionHolder& h) {
197 CodeTracer::Scope tracing_scope(info->isolate()->GetCodeTracer());
198 OFStream os(tracing_scope.file());
199 os << "INLINE (" << h.shared_info->DebugName()->ToCString().get() << ") id{"
200 << info->optimization_id() << "," << source_id << "} AS " << inlining_id
201 << " AT ";
202 const SourcePosition position = h.position.position;
203 if (position.IsKnown()) {
204 os << "<" << position.InliningId() << ":" << position.ScriptOffset() << ">";
205 } else {
206 os << "<?>";
207 }
208 os << std::endl;
209 }
210
211 // Print the source of all functions that participated in this optimizing
212 // compilation. For inlined functions print source position of their inlining.
213 static void DumpParticipatingSource(CompilationInfo* info) {
214 AllowDeferredHandleDereference allow_deference_for_print_code;
215
216 std::vector<Handle<SharedFunctionInfo>> printed;
217 printed.reserve(info->inlined_functions().size());
218
219 PrintFunctionSource(info, &printed, SourcePosition::kNotInlined,
220 info->shared_info());
221 const auto& inlined = info->inlined_functions();
222 for (unsigned id = 0; id < inlined.size(); id++) {
223 const int source_id =
224 PrintFunctionSource(info, &printed, id, inlined[id].shared_info);
225 PrintInlinedFunctionInfo(info, source_id, id, inlined[id]);
226 }
227 }
140 228
141 void CodeGenerator::PrintCode(Handle<Code> code, CompilationInfo* info) { 229 void CodeGenerator::PrintCode(Handle<Code> code, CompilationInfo* info) {
230 if (FLAG_print_opt_source && info->IsOptimizing()) {
231 DumpParticipatingSource(info);
232 }
233
142 #ifdef ENABLE_DISASSEMBLER 234 #ifdef ENABLE_DISASSEMBLER
143 AllowDeferredHandleDereference allow_deference_for_print_code; 235 AllowDeferredHandleDereference allow_deference_for_print_code;
144 Isolate* isolate = info->isolate(); 236 Isolate* isolate = info->isolate();
145 bool print_code = 237 bool print_code =
146 isolate->bootstrapper()->IsActive() 238 isolate->bootstrapper()->IsActive()
147 ? FLAG_print_builtin_code 239 ? FLAG_print_builtin_code
148 : (FLAG_print_code || (info->IsStub() && FLAG_print_code_stubs) || 240 : (FLAG_print_code || (info->IsStub() && FLAG_print_code_stubs) ||
149 (info->IsOptimizing() && FLAG_print_opt_code && 241 (info->IsOptimizing() && FLAG_print_opt_code &&
150 info->shared_info()->PassesFilter(FLAG_print_opt_code_filter))); 242 info->shared_info()->PassesFilter(FLAG_print_opt_code_filter)));
151 if (print_code) { 243 if (print_code) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 os << "source_position = " << shared->start_position() << "\n"; 283 os << "source_position = " << shared->start_position() << "\n";
192 } 284 }
193 code->Disassemble(debug_name.get(), os); 285 code->Disassemble(debug_name.get(), os);
194 os << "--- End code ---\n"; 286 os << "--- End code ---\n";
195 } 287 }
196 #endif // ENABLE_DISASSEMBLER 288 #endif // ENABLE_DISASSEMBLER
197 } 289 }
198 290
199 } // namespace internal 291 } // namespace internal
200 } // namespace v8 292 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/compiler/graph-visualizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698