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