1// Copyright 2013 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef V8_CRANKSHAFT_LITHIUM_CODEGEN_H_ 6#define V8_CRANKSHAFT_LITHIUM_CODEGEN_H_ 7 8#include "src/bailout-reason.h" 9#include "src/compiler.h" 10#include "src/deoptimizer.h" 11 12namespace v8 { 13namespace internal { 14 15class HGraph; 16class LChunk; 17class LEnvironment; 18class LInstruction; 19class LPlatformChunk; 20 21class LCodeGenBase BASE_EMBEDDED { 22 public: 23 LCodeGenBase(LChunk* chunk, 24 MacroAssembler* assembler, 25 CompilationInfo* info); 26 virtual ~LCodeGenBase() {} 27 28 // Simple accessors. 29 MacroAssembler* masm() const { return masm_; } 30 CompilationInfo* info() const { return info_; } 31 Isolate* isolate() const { return info_->isolate(); } 32 Factory* factory() const { return isolate()->factory(); } 33 Heap* heap() const { return isolate()->heap(); } 34 Zone* zone() const { return zone_; } 35 LPlatformChunk* chunk() const { return chunk_; } 36 HGraph* graph() const; 37 38 void PRINTF_FORMAT(2, 3) Comment(const char* format, ...); 39 void DeoptComment(const Deoptimizer::DeoptInfo& deopt_info); 40 static Deoptimizer::DeoptInfo MakeDeoptInfo( 41 LInstruction* instr, Deoptimizer::DeoptReason deopt_reason, int deopt_id); 42 43 bool GenerateBody(); 44 virtual void GenerateBodyInstructionPre(LInstruction* instr) {} 45 virtual void GenerateBodyInstructionPost(LInstruction* instr) {} 46 47 virtual void EnsureSpaceForLazyDeopt(int space_needed) = 0; 48 virtual void RecordAndWritePosition(int position) = 0; 49 50 int GetNextEmittedBlock() const; 51 52 void RegisterWeakObjectsInOptimizedCode(Handle<Code> code); 53 54 void WriteTranslationFrame(LEnvironment* environment, 55 Translation* translation); 56 int DefineDeoptimizationLiteral(Handle<Object> literal); 57 58 void PopulateDeoptimizationData(Handle<Code> code); 59 void PopulateDeoptimizationLiteralsWithInlinedFunctions(); 60 61 // Check that an environment assigned via AssignEnvironment is actually being 62 // used. Redundant assignments keep things alive longer than necessary, and 63 // consequently lead to worse code, so it's important to minimize this. 64 void CheckEnvironmentUsage(); 65 66 protected: 67 enum Status { 68 UNUSED, 69 GENERATING, 70 DONE, 71 ABORTED 72 }; 73 74 LPlatformChunk* const chunk_; 75 MacroAssembler* const masm_; 76 CompilationInfo* const info_; 77 Zone* zone_; 78 Status status_; 79 int current_block_; 80 int current_instruction_; 81 const ZoneList<LInstruction*>* instructions_; 82 ZoneList<LEnvironment*> deoptimizations_; 83 ZoneList<Handle<Object> > deoptimization_literals_; 84 TranslationBuffer translations_; 85 int inlined_function_count_; 86 int last_lazy_deopt_pc_; 87 int osr_pc_offset_; 88 89 bool is_unused() const { return status_ == UNUSED; } 90 bool is_generating() const { return status_ == GENERATING; } 91 bool is_done() const { return status_ == DONE; } 92 bool is_aborted() const { return status_ == ABORTED; } 93 94 void Abort(BailoutReason reason); 95 void Retry(BailoutReason reason); 96 97 // Methods for code dependencies. 98 void AddDeprecationDependency(Handle<Map> map); 99 void AddStabilityDependency(Handle<Map> map); 100}; 101 102 103} // namespace internal 104} // namespace v8 105 106#endif // V8_CRANKSHAFT_LITHIUM_CODEGEN_H_ 107