void GenerateGenericStubBitNot(MacroAssembler* masm);
void GenerateGenericCodeFallback(MacroAssembler* masm);
- virtual int GetCodeKind() { return Code::UNARY_OP_IC; }
+ virtual Code::Kind GetCodeKind() const { return Code::UNARY_OP_IC; }
virtual InlineCacheState GetICState() {
return UnaryOpIC::ToState(operand_type_);
static Handle<Code> DoGenerateCode(Stub* stub) {
CodeStubGraphBuilder<Stub> builder(stub);
LChunk* chunk = OptimizeGraph(builder.CreateGraph());
- return chunk->Codegen(Code::COMPILED_STUB);
+ return chunk->Codegen();
}
Handle<Code> FastCloneShallowArrayStub::GenerateCode() {
CodeStubGraphBuilder<FastCloneShallowArrayStub> builder(this);
LChunk* chunk = OptimizeGraph(builder.CreateGraph());
- return chunk->Codegen(Code::COMPILED_STUB);
+ return chunk->Codegen();
}
}
-int CodeStub::GetCodeKind() {
+Code::Kind CodeStub::GetCodeKind() const {
return Code::STUB;
}
// Copy the generated code into a heap object.
Code::Flags flags = Code::ComputeFlags(
- static_cast<Code::Kind>(GetCodeKind()),
+ GetCodeKind(),
GetICState(),
GetExtraICState(),
GetStubType(),
bool ICCompareStub::FindCodeInSpecialCache(Code** code_out, Isolate* isolate) {
Factory* factory = isolate->factory();
Code::Flags flags = Code::ComputeFlags(
- static_cast<Code::Kind>(GetCodeKind()),
+ GetCodeKind(),
UNINITIALIZED);
ASSERT(op_ == Token::EQ || op_ == Token::EQ_STRICT);
Handle<Object> probe(
virtual Major MajorKey() = 0;
virtual int MinorKey() = 0;
- protected:
- static bool CanUseFPRegisters();
-
- // Generates the assembler code for the stub.
- virtual Handle<Code> GenerateCode() = 0;
-
- // BinaryOpStub needs to override this.
virtual InlineCacheState GetICState() {
return UNINITIALIZED;
}
virtual Code::ExtraICState GetExtraICState() {
return Code::kNoExtraICState;
}
+
+ protected:
+ static bool CanUseFPRegisters();
+
+ // Generates the assembler code for the stub.
+ virtual Handle<Code> GenerateCode() = 0;
+
virtual Code::StubType GetStubType() {
return Code::NORMAL;
}
virtual void Activate(Code* code) { }
// BinaryOpStub needs to override this.
- virtual int GetCodeKind();
+ virtual Code::Kind GetCodeKind() const;
// Add the code to a specialized cache, specific to an individual
// stub type. Please note, this method must add the code object to a
// Retrieve the code for the stub. Generate the code if needed.
virtual Handle<Code> GenerateCode();
- virtual int GetCodeKind() { return Code::STUB; }
+ virtual Code::Kind GetCodeKind() const { return Code::STUB; }
virtual int GetStubFlags() { return -1; }
protected:
// Retrieve the code for the stub. Generate the code if needed.
virtual Handle<Code> GenerateCode() = 0;
- virtual int GetCodeKind() { return Code::COMPILED_STUB; }
+ virtual Code::Kind GetCodeKind() const { return Code::STUB; }
CodeStubInterfaceDescriptor* GetInterfaceDescriptor(Isolate* isolate) {
return isolate->code_stub_interface_descriptor(MajorKey());
class ICStub: public PlatformCodeStub {
public:
explicit ICStub(Code::Kind kind) : kind_(kind) { }
- virtual int GetCodeKind() { return kind_; }
+ virtual Code::Kind GetCodeKind() const { return kind_; }
virtual InlineCacheState GetICState() { return MONOMORPHIC; }
bool Describes(Code* code) {
class HandlerStub: public ICStub {
public:
explicit HandlerStub(Code::Kind kind) : ICStub(kind) { }
- virtual int GetCodeKind() { return Code::STUB; }
+ virtual Code::Kind GetCodeKind() const { return Code::STUB; }
virtual int GetStubFlags() { return kind(); }
};
// Entirely platform-specific methods are defined as static helper
// functions in the <arch>/code-stubs-<arch>.cc files.
- virtual int GetCodeKind() { return Code::BINARY_OP_IC; }
+ virtual Code::Kind GetCodeKind() const { return Code::BINARY_OP_IC; }
virtual InlineCacheState GetICState() {
return BinaryOpIC::ToState(Max(left_type_, right_type_));
virtual CodeStub::Major MajorKey() { return CompareIC; }
virtual int MinorKey();
- virtual int GetCodeKind() { return Code::COMPARE_IC; }
+ virtual Code::Kind GetCodeKind() const { return Code::COMPARE_IC; }
void GenerateSmis(MacroAssembler* masm);
void GenerateNumbers(MacroAssembler* masm);
: tos_(tos), types_(types) { }
void Generate(MacroAssembler* masm);
- virtual int GetCodeKind() { return Code::TO_BOOLEAN_IC; }
+ virtual Code::Kind GetCodeKind() const { return Code::TO_BOOLEAN_IC; }
virtual void PrintName(StringStream* stream);
virtual bool SometimesSetsUpAFrame() { return false; }
// Allocate and install the code.
CodeDesc desc;
+ bool is_crankshafted =
+ Code::ExtractKindFromFlags(flags) == Code::OPTIMIZED_FUNCTION ||
+ info->IsStub();
masm->GetCode(&desc);
Handle<Code> code =
- isolate->factory()->NewCode(desc, flags, masm->CodeObject());
-
+ isolate->factory()->NewCode(desc, flags, masm->CodeObject(),
+ false, is_crankshafted);
if (!code.is_null()) {
isolate->counters()->total_compiled_code_size()->Increment(
code->instruction_size());
if (print_code) {
// Print the source code if available.
FunctionLiteral* function = info->function();
- if (code->kind() != Code::COMPILED_STUB) {
+ if (code->kind() == Code::OPTIMIZED_FUNCTION) {
Handle<Script> script = info->script();
if (!script->IsUndefined() && !script->source()->IsUndefined()) {
PrintF("--- Raw source ---\n");
Code::Flags CompilationInfo::flags() const {
if (IsStub()) {
- return Code::ComputeFlags(Code::COMPILED_STUB);
+ return Code::ComputeFlags(code_stub()->GetCodeKind(),
+ code_stub()->GetICState(),
+ code_stub()->GetExtraICState(),
+ Code::NORMAL,
+ 0);
} else {
return Code::ComputeFlags(Code::OPTIMIZED_FUNCTION);
}
Timer timer(this, &time_taken_to_codegen_);
ASSERT(chunk_ != NULL);
ASSERT(graph_ != NULL);
- Handle<Code> optimized_code = chunk_->Codegen(Code::OPTIMIZED_FUNCTION);
+ Handle<Code> optimized_code = chunk_->Codegen();
if (optimized_code.is_null()) {
info()->set_bailout_reason("code generation failed");
return AbortOptimization();
Handle<JSFunction> closure() const { return closure_; }
Handle<SharedFunctionInfo> shared_info() const { return shared_info_; }
Handle<Script> script() const { return script_; }
- HydrogenCodeStub* code_stub() {return code_stub_; }
+ HydrogenCodeStub* code_stub() const {return code_stub_; }
v8::Extension* extension() const { return extension_; }
ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; }
Handle<Context> context() const { return context_; }
// reg = JSFunction context
//
- ASSERT(compiled_code_->kind() == Code::COMPILED_STUB);
+ ASSERT(compiled_code_->is_crankshafted() &&
+ compiled_code_->kind() != Code::OPTIMIZED_FUNCTION);
int major_key = compiled_code_->major_key();
CodeStubInterfaceDescriptor* descriptor =
isolate_->code_stub_interface_descriptor(major_key);
// size matches with the stack height we can compute based on the
// environment at the OSR entry. The code for that his built into
// the DoComputeOsrOutputFrame function for now.
- } else if (compiled_code_->kind() != Code::COMPILED_STUB) {
+ } else if (compiled_code_->kind() == Code::OPTIMIZED_FUNCTION) {
unsigned stack_slots = compiled_code_->stack_slots();
unsigned outgoing_size = ComputeOutgoingArgumentSize();
ASSERT(result == fixed_size + (stack_slots * kPointerSize) + outgoing_size);
// Called by Code::CodePrint.
void Disassembler::Decode(FILE* f, Code* code) {
Isolate* isolate = code->GetIsolate();
- int decode_size = (code->kind() == Code::OPTIMIZED_FUNCTION ||
- code->kind() == Code::COMPILED_STUB)
+ int decode_size = code->is_crankshafted()
? static_cast<int>(code->safepoint_table_offset())
: code->instruction_size();
// If there might be a back edge table, stop before reaching it.
-// Copyright 2012 the V8 project authors. All rights reserved.
+// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
Handle<Code> Factory::NewCode(const CodeDesc& desc,
Code::Flags flags,
Handle<Object> self_ref,
- bool immovable) {
+ bool immovable,
+ bool crankshafted) {
CALL_HEAP_FUNCTION(isolate(),
isolate()->heap()->CreateCode(
- desc, flags, self_ref, immovable),
+ desc, flags, self_ref, immovable, crankshafted),
Code);
}
Handle<Code> NewCode(const CodeDesc& desc,
Code::Flags flags,
Handle<Object> self_reference,
- bool immovable = false);
+ bool immovable = false,
+ bool crankshafted = false);
Handle<Code> CopyCode(Handle<Code> code);
MaybeObject* Heap::CreateCode(const CodeDesc& desc,
Code::Flags flags,
Handle<Object> self_reference,
- bool immovable) {
+ bool immovable,
+ bool crankshafted) {
// Allocate ByteArray before the Code object, so that we do not risk
// leaving uninitialized Code object (and breaking the heap).
ByteArray* reloc_info;
if (code->is_call_stub() || code->is_keyed_call_stub()) {
code->set_check_type(RECEIVER_MAP_CHECK);
}
+ code->set_is_crankshafted(crankshafted);
code->set_deoptimization_data(empty_fixed_array(), SKIP_WRITE_BARRIER);
code->InitializeTypeFeedbackInfoNoWriteBarrier(undefined_value());
code->set_handler_table(empty_fixed_array(), SKIP_WRITE_BARRIER);
MUST_USE_RESULT MaybeObject* CreateCode(const CodeDesc& desc,
Code::Flags flags,
Handle<Object> self_reference,
- bool immovable = false);
+ bool immovable = false,
+ bool crankshafted = false);
MUST_USE_RESULT MaybeObject* CopyCode(Code* code);
void GenerateGenericStubBitNot(MacroAssembler* masm);
void GenerateGenericCodeFallback(MacroAssembler* masm);
- virtual int GetCodeKind() { return Code::UNARY_OP_IC; }
+ virtual Code::Kind GetCodeKind() const { return Code::UNARY_OP_IC; }
virtual InlineCacheState GetICState() {
return UnaryOpIC::ToState(operand_type_);
}
-Handle<Code> LChunk::Codegen(Code::Kind kind) {
+Handle<Code> LChunk::Codegen() {
MacroAssembler assembler(info()->isolate(), NULL, 0);
LOG_CODE_EVENT(info()->isolate(),
CodeStartLinePosInfoRecordEvent(
PrintF("Crankshaft Compiler - ");
}
CodeGenerator::MakeCodePrologue(info());
- Code::Flags flags = Code::ComputeFlags(kind);
+ Code::Flags flags = info()->flags();
Handle<Code> code =
CodeGenerator::MakeCodeEpilogue(&assembler, flags, info());
generator.FinishCode(code);
-
+ code->set_is_crankshafted(true);
if (!code.is_null()) {
void* jit_handler_data =
assembler.positions_recorder()->DetachJITHandlerData();
Zone* zone() const { return info_->zone(); }
- Handle<Code> Codegen(Code::Kind kind);
+ Handle<Code> Codegen();
void set_allocated_double_registers(BitVector* allocated_registers);
BitVector* allocated_double_registers() {
case Code::BINARY_OP_IC: // fall through
case Code::COMPARE_IC: // fall through
case Code::TO_BOOLEAN_IC: // fall through
- case Code::COMPILED_STUB: // fall through
case Code::STUB:
description =
CodeStub::MajorName(CodeStub::GetMajorKey(code_object), true);
void GenerateGenericStubBitNot(MacroAssembler* masm);
void GenerateGenericCodeFallback(MacroAssembler* masm);
- virtual int GetCodeKind() { return Code::UNARY_OP_IC; }
+ virtual Code::Kind GetCodeKind() const { return Code::UNARY_OP_IC; }
virtual InlineCacheState GetICState() {
return UnaryOpIC::ToState(operand_type_);
}
+inline bool Code::is_crankshafted() {
+ return IsCrankshaftedField::decode(
+ READ_UINT32_FIELD(this, kKindSpecificFlags2Offset));
+}
+
+
+inline void Code::set_is_crankshafted(bool value) {
+ int previous = READ_UINT32_FIELD(this, kKindSpecificFlags2Offset);
+ int updated = IsCrankshaftedField::update(previous, value);
+ WRITE_UINT32_FIELD(this, kKindSpecificFlags2Offset, updated);
+}
+
+
int Code::major_key() {
ASSERT(kind() == STUB ||
- kind() == COMPILED_STUB ||
kind() == UNARY_OP_IC ||
kind() == BINARY_OP_IC ||
kind() == COMPARE_IC ||
void Code::set_major_key(int major) {
ASSERT(kind() == STUB ||
- kind() == COMPILED_STUB ||
kind() == UNARY_OP_IC ||
kind() == BINARY_OP_IC ||
kind() == COMPARE_IC ||
unsigned Code::stack_slots() {
- ASSERT(kind() == OPTIMIZED_FUNCTION || kind() == COMPILED_STUB);
+ ASSERT(is_crankshafted());
return StackSlotsField::decode(
READ_UINT32_FIELD(this, kKindSpecificFlags1Offset));
}
void Code::set_stack_slots(unsigned slots) {
CHECK(slots <= (1 << kStackSlotsBitCount));
- ASSERT(kind() == OPTIMIZED_FUNCTION || kind() == COMPILED_STUB);
+ ASSERT(is_crankshafted());
int previous = READ_UINT32_FIELD(this, kKindSpecificFlags1Offset);
int updated = StackSlotsField::update(previous, slots);
WRITE_UINT32_FIELD(this, kKindSpecificFlags1Offset, updated);
unsigned Code::safepoint_table_offset() {
- ASSERT(kind() == OPTIMIZED_FUNCTION || kind() == COMPILED_STUB);
+ ASSERT(is_crankshafted());
return SafepointTableOffsetField::decode(
READ_UINT32_FIELD(this, kKindSpecificFlags2Offset));
}
void Code::set_safepoint_table_offset(unsigned offset) {
CHECK(offset <= (1 << kSafepointTableOffsetBitCount));
- ASSERT(kind() == OPTIMIZED_FUNCTION || kind() == COMPILED_STUB);
+ ASSERT(is_crankshafted());
ASSERT(IsAligned(offset, static_cast<unsigned>(kIntSize)));
int previous = READ_UINT32_FIELD(this, kKindSpecificFlags2Offset);
int updated = SafepointTableOffsetField::update(previous, offset);
switch (kind) {
case FUNCTION: return "FUNCTION";
case OPTIMIZED_FUNCTION: return "OPTIMIZED_FUNCTION";
- case COMPILED_STUB: return "COMPILED_STUB";
case STUB: return "STUB";
case BUILTIN: return "BUILTIN";
case LOAD_IC: return "LOAD_IC";
}
PrintF("\n");
- if (kind() == OPTIMIZED_FUNCTION || kind() == COMPILED_STUB) {
+ if (is_crankshafted()) {
SafepointTable table(this);
PrintF(out, "Safepoints (size = %u)\n", table.size());
for (unsigned i = 0; i < table.length(); i++) {
V(FUNCTION) \
V(OPTIMIZED_FUNCTION) \
V(STUB) \
- V(COMPILED_STUB) \
V(BUILTIN) \
V(LOAD_IC) \
V(KEYED_LOAD_IC) \
inline int major_key();
inline void set_major_key(int value);
+ // For kind STUB or ICs, tells whether or not a code object was generated by
+ // the optimizing compiler (but it may not be an optimized function).
+ bool is_crankshafted();
+ inline void set_is_crankshafted(bool value);
+
// For stubs, tells whether they should always exist, so that they can be
// called from other stubs.
inline bool is_pregenerated();
kMarkedForDeoptimizationFirstBit,
kMarkedForDeoptimizationBitCount> {}; // NOLINT
+ // KindSpecificFlags2 layout (ALL)
+ static const int kIsCrankshaftedBit = 0;
+ class IsCrankshaftedField: public BitField<bool,
+ kIsCrankshaftedBit, 1> {}; // NOLINT
+
// KindSpecificFlags2 layout (STUB and OPTIMIZED_FUNCTION)
- static const int kStubMajorKeyFirstBit = 0;
+ static const int kStubMajorKeyFirstBit = kIsCrankshaftedBit + 1;
static const int kSafepointTableOffsetFirstBit =
kStubMajorKeyFirstBit + kStubMajorKeyBits;
- static const int kSafepointTableOffsetBitCount = 26;
+ static const int kSafepointTableOffsetBitCount = 25;
STATIC_ASSERT(kStubMajorKeyFirstBit + kStubMajorKeyBits <= 32);
STATIC_ASSERT(kSafepointTableOffsetFirstBit +
kSafepointTableOffsetBitCount <= 32);
+ STATIC_ASSERT(1 + kStubMajorKeyBits +
+ kSafepointTableOffsetBitCount <= 32);
class SafepointTableOffsetField: public BitField<int,
kSafepointTableOffsetFirstBit,
kStubMajorKeyFirstBit, kStubMajorKeyBits> {}; // NOLINT
// KindSpecificFlags2 layout (FUNCTION)
- class BackEdgeTableOffsetField: public BitField<int, 0, 31> {};
- class BackEdgesPatchedForOSRField: public BitField<bool, 31, 1> {};
+ class BackEdgeTableOffsetField: public BitField<int,
+ kIsCrankshaftedBit + 1, 29> {}; // NOLINT
+ class BackEdgesPatchedForOSRField: public BitField<bool,
+ kIsCrankshaftedBit + 1 + 29, 1> {}; // NOLINT
// Signed field cannot be encoded using the BitField class.
static const int kArgumentsCountShift = 17;
ASSERT(args.length() == 0);
Deoptimizer* deoptimizer = Deoptimizer::Grab(isolate);
ASSERT(isolate->heap()->IsAllocationAllowed());
- ASSERT(deoptimizer->compiled_code_kind() == Code::COMPILED_STUB);
delete deoptimizer;
return isolate->heap()->undefined_value();
}
Deoptimizer* deoptimizer = Deoptimizer::Grab(isolate);
ASSERT(isolate->heap()->IsAllocationAllowed());
- ASSERT(deoptimizer->compiled_code_kind() != Code::COMPILED_STUB);
+ ASSERT(deoptimizer->compiled_code_kind() == Code::OPTIMIZED_FUNCTION);
// Make sure to materialize objects before causing any allocation.
JavaScriptFrameIterator it(isolate);
SafepointTable::SafepointTable(Code* code) {
- ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION ||
- code->kind() == Code::COMPILED_STUB);
+ ASSERT(code->is_crankshafted());
code_ = code;
Address header = code->instruction_start() + code->safepoint_table_offset();
length_ = Memory::uint32_at(header + kLengthOffset);
CASE(FUNCTION);
CASE(OPTIMIZED_FUNCTION);
CASE(STUB);
- CASE(COMPILED_STUB);
CASE(BUILTIN);
CASE(LOAD_IC);
CASE(KEYED_LOAD_IC);
void GenerateGenericStubBitNot(MacroAssembler* masm);
void GenerateGenericCodeFallback(MacroAssembler* masm);
- virtual int GetCodeKind() { return Code::UNARY_OP_IC; }
+ virtual Code::Kind GetCodeKind() const { return Code::UNARY_OP_IC; }
virtual InlineCacheState GetICState() {
return UnaryOpIC::ToState(operand_type_);