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_LITHIUM_CODEGEN_H_ 6 #define V8_LITHIUM_CODEGEN_H_ 7 8 #include "src/v8.h" 9 10 #include "src/bailout-reason.h" 11 #include "src/compiler.h" 12 #include "src/deoptimizer.h" 13 14 namespace v8 { 15 namespace internal { 16 17 class LInstruction; 18 class LPlatformChunk; 19 20 class LCodeGenBase BASE_EMBEDDED { 21 public: 22 LCodeGenBase(LChunk* chunk, 23 MacroAssembler* assembler, 24 CompilationInfo* info); ~LCodeGenBase()25 virtual ~LCodeGenBase() {} 26 27 // Simple accessors. masm()28 MacroAssembler* masm() const { return masm_; } info()29 CompilationInfo* info() const { return info_; } isolate()30 Isolate* isolate() const { return info_->isolate(); } factory()31 Factory* factory() const { return isolate()->factory(); } heap()32 Heap* heap() const { return isolate()->heap(); } zone()33 Zone* zone() const { return zone_; } chunk()34 LPlatformChunk* chunk() const { return chunk_; } 35 HGraph* graph() const; 36 37 void FPRINTF_CHECKING Comment(const char* format, ...); 38 void DeoptComment(const Deoptimizer::Reason& reason); 39 40 bool GenerateBody(); GenerateBodyInstructionPre(LInstruction * instr)41 virtual void GenerateBodyInstructionPre(LInstruction* instr) {} GenerateBodyInstructionPost(LInstruction * instr)42 virtual void GenerateBodyInstructionPost(LInstruction* instr) {} 43 44 virtual void EnsureSpaceForLazyDeopt(int space_needed) = 0; 45 virtual void RecordAndWritePosition(int position) = 0; 46 47 int GetNextEmittedBlock() const; 48 49 void RegisterWeakObjectsInOptimizedCode(Handle<Code> code); 50 51 // Check that an environment assigned via AssignEnvironment is actually being 52 // used. Redundant assignments keep things alive longer than necessary, and 53 // consequently lead to worse code, so it's important to minimize this. 54 void CheckEnvironmentUsage(); 55 56 protected: 57 enum Status { 58 UNUSED, 59 GENERATING, 60 DONE, 61 ABORTED 62 }; 63 64 LPlatformChunk* const chunk_; 65 MacroAssembler* const masm_; 66 CompilationInfo* const info_; 67 Zone* zone_; 68 Status status_; 69 int current_block_; 70 int current_instruction_; 71 const ZoneList<LInstruction*>* instructions_; 72 int last_lazy_deopt_pc_; 73 is_unused()74 bool is_unused() const { return status_ == UNUSED; } is_generating()75 bool is_generating() const { return status_ == GENERATING; } is_done()76 bool is_done() const { return status_ == DONE; } is_aborted()77 bool is_aborted() const { return status_ == ABORTED; } 78 79 void Abort(BailoutReason reason); 80 void Retry(BailoutReason reason); 81 82 // Methods for code dependencies. 83 void AddDeprecationDependency(Handle<Map> map); 84 void AddStabilityDependency(Handle<Map> map); 85 }; 86 87 88 } } // namespace v8::internal 89 90 #endif // V8_LITHIUM_CODEGEN_H_ 91