V8 Project
v8::internal::CodeGenerator Class Reference

#include <codegen.h>

+ Collaboration diagram for v8::internal::CodeGenerator:

Static Public Member Functions

static void MakeCodePrologue (CompilationInfo *info, const char *kind)
 
static Handle< CodeMakeCodeEpilogue (MacroAssembler *masm, Code::Flags flags, CompilationInfo *info)
 
static void PrintCode (Handle< Code > code, CompilationInfo *info)
 
static bool RecordPositions (MacroAssembler *masm, int pos, bool right_here=false)
 

Private Member Functions

 DISALLOW_COPY_AND_ASSIGN (CodeGenerator)
 

Detailed Description

Definition at line 73 of file codegen.h.

Member Function Documentation

◆ DISALLOW_COPY_AND_ASSIGN()

v8::internal::CodeGenerator::DISALLOW_COPY_AND_ASSIGN ( CodeGenerator  )
private

◆ MakeCodeEpilogue()

Handle< Code > v8::internal::CodeGenerator::MakeCodeEpilogue ( MacroAssembler masm,
Code::Flags  flags,
CompilationInfo info 
)
static

Definition at line 139 of file codegen.cc.

141  {
142  Isolate* isolate = info->isolate();
143 
144  // Allocate and install the code.
145  CodeDesc desc;
146  bool is_crankshafted =
147  Code::ExtractKindFromFlags(flags) == Code::OPTIMIZED_FUNCTION ||
148  info->IsStub();
149  masm->GetCode(&desc);
150  Handle<Code> code =
151  isolate->factory()->NewCode(desc, flags, masm->CodeObject(),
152  false, is_crankshafted,
153  info->prologue_offset(),
154  info->is_debug() && !is_crankshafted);
155  isolate->counters()->total_compiled_code_size()->Increment(
156  code->instruction_size());
157  isolate->heap()->IncrementCodeGeneratedBytes(is_crankshafted,
158  code->instruction_size());
159  return code;
160 }
static Kind ExtractKindFromFlags(Flags flags)
Definition: objects-inl.h:4981

References v8::internal::MacroAssembler::CodeObject(), v8::internal::Isolate::counters(), v8::internal::Isolate::factory(), v8::internal::anonymous_namespace{flags.cc}::flags, v8::internal::Assembler::GetCode(), v8::internal::Isolate::heap(), v8::internal::Heap::IncrementCodeGeneratedBytes(), v8::internal::CompilationInfo::is_debug(), v8::internal::CompilationInfo::isolate(), v8::internal::CompilationInfo::IsStub(), and v8::internal::CompilationInfo::prologue_offset().

Referenced by v8::internal::LChunk::Codegen(), and v8::internal::FullCodeGenerator::MakeCode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MakeCodePrologue()

void v8::internal::CodeGenerator::MakeCodePrologue ( CompilationInfo info,
const char *  kind 
)
static

Definition at line 97 of file codegen.cc.

97  {
98  bool print_source = false;
99  bool print_ast = false;
100  const char* ftype;
101 
102  if (info->isolate()->bootstrapper()->IsActive()) {
103  print_source = FLAG_print_builtin_source;
104  print_ast = FLAG_print_builtin_ast;
105  ftype = "builtin";
106  } else {
107  print_source = FLAG_print_source;
108  print_ast = FLAG_print_ast;
109  ftype = "user-defined";
110  }
111 
112  if (FLAG_trace_codegen || print_source || print_ast) {
113  PrintF("[generating %s code for %s function: ", kind, ftype);
114  if (info->IsStub()) {
115  const char* name =
116  CodeStub::MajorName(info->code_stub()->MajorKey(), true);
117  PrintF("%s", name == NULL ? "<unknown>" : name);
118  } else {
119  AllowDeferredHandleDereference allow_deference_for_trace;
120  PrintF("%s", info->function()->debug_name()->ToCString().get());
121  }
122  PrintF("]\n");
123  }
124 
125 #ifdef DEBUG
126  if (!info->IsStub() && print_source) {
127  PrintF("--- Source from AST ---\n%s\n",
128  PrettyPrinter(info->zone()).PrintProgram(info->function()));
129  }
130 
131  if (!info->IsStub() && print_ast) {
132  PrintF("--- AST ---\n%s\n",
133  AstPrinter(info->zone()).PrintProgram(info->function()));
134  }
135 #endif // DEBUG
136 }
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
void PrintF(const char *format,...)
Definition: utils.cc:80
PerThreadAssertScopeDebugOnly< DEFERRED_HANDLE_DEREFERENCE_ASSERT, true > AllowDeferredHandleDereference
Definition: assert-scope.h:130

References v8::internal::Isolate::bootstrapper(), v8::internal::CompilationInfo::code_stub(), v8::internal::CompilationInfo::function(), v8::internal::CompilationInfo::isolate(), v8::internal::CompilationInfo::IsStub(), name, NULL, v8::internal::PrintF(), and v8::internal::CompilationInfo::zone().

Referenced by v8::internal::LChunk::Codegen(), and v8::internal::FullCodeGenerator::MakeCode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PrintCode()

void v8::internal::CodeGenerator::PrintCode ( Handle< Code code,
CompilationInfo info 
)
static

Definition at line 163 of file codegen.cc.

163  {
164 #ifdef ENABLE_DISASSEMBLER
165  AllowDeferredHandleDereference allow_deference_for_print_code;
166  bool print_code = info->isolate()->bootstrapper()->IsActive()
167  ? FLAG_print_builtin_code
168  : (FLAG_print_code ||
169  (info->IsStub() && FLAG_print_code_stubs) ||
170  (info->IsOptimizing() && FLAG_print_opt_code));
171  if (print_code) {
172  // Print the source code if available.
173  FunctionLiteral* function = info->function();
174  bool print_source = code->kind() == Code::OPTIMIZED_FUNCTION ||
175  code->kind() == Code::FUNCTION;
176 
177  CodeTracer::Scope tracing_scope(info->isolate()->GetCodeTracer());
178  OFStream os(tracing_scope.file());
179  if (print_source) {
180  Handle<Script> script = info->script();
181  if (!script->IsUndefined() && !script->source()->IsUndefined()) {
182  os << "--- Raw source ---\n";
183  ConsStringIteratorOp op;
184  StringCharacterStream stream(String::cast(script->source()),
185  &op,
186  function->start_position());
187  // fun->end_position() points to the last character in the stream. We
188  // need to compensate by adding one to calculate the length.
189  int source_len =
190  function->end_position() - function->start_position() + 1;
191  for (int i = 0; i < source_len; i++) {
192  if (stream.HasMore()) {
193  os << AsReversiblyEscapedUC16(stream.GetNext());
194  }
195  }
196  os << "\n\n";
197  }
198  }
199  if (info->IsOptimizing()) {
200  if (FLAG_print_unopt_code) {
201  os << "--- Unoptimized code ---\n";
202  info->closure()->shared()->code()->Disassemble(
203  function->debug_name()->ToCString().get(), os);
204  }
205  os << "--- Optimized code ---\n"
206  << "optimization_id = " << info->optimization_id() << "\n";
207  } else {
208  os << "--- Code ---\n";
209  }
210  if (print_source) {
211  os << "source_position = " << function->start_position() << "\n";
212  }
213  if (info->IsStub()) {
214  CodeStub::Major major_key = info->code_stub()->MajorKey();
215  code->Disassemble(CodeStub::MajorName(major_key, false), os);
216  } else {
217  code->Disassemble(function->debug_name()->ToCString().get(), os);
218  }
219  os << "--- End code ---\n";
220  }
221 #endif // ENABLE_DISASSEMBLER
222 }

References v8::internal::Isolate::bootstrapper(), v8::internal::CompilationInfo::closure(), v8::internal::CompilationInfo::code_stub(), v8::internal::CompilationInfo::function(), v8::internal::Isolate::GetCodeTracer(), v8::internal::StringCharacterStream::GetNext(), v8::internal::StringCharacterStream::HasMore(), v8::internal::CompilationInfo::isolate(), v8::internal::CompilationInfo::IsOptimizing(), v8::internal::CompilationInfo::IsStub(), v8::internal::CompilationInfo::optimization_id(), and v8::internal::CompilationInfo::script().

Referenced by v8::internal::LChunk::Codegen(), v8::internal::compiler::Pipeline::GenerateCode(), and v8::internal::FullCodeGenerator::MakeCode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RecordPositions()

bool v8::internal::CodeGenerator::RecordPositions ( MacroAssembler masm,
int  pos,
bool  right_here = false 
)
static

Definition at line 225 of file codegen.cc.

227  {
228  if (pos != RelocInfo::kNoPosition) {
229  masm->positions_recorder()->RecordStatementPosition(pos);
230  masm->positions_recorder()->RecordPosition(pos);
231  if (right_here) {
232  return masm->positions_recorder()->WriteRecordedPositions();
233  }
234  }
235  return false;
236 }
static const int kNoPosition
Definition: assembler.h:317

References v8::internal::Assembler::positions_recorder().

Referenced by v8::internal::FullCodeGenerator::SetExpressionPosition(), v8::internal::FullCodeGenerator::SetFunctionPosition(), v8::internal::FullCodeGenerator::SetReturnPosition(), and v8::internal::FullCodeGenerator::SetStatementPosition().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: