lithium-codegen.h 3.4 KB
Newer Older
1
// Copyright 2013 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_CRANKSHAFT_LITHIUM_CODEGEN_H_
#define V8_CRANKSHAFT_LITHIUM_CODEGEN_H_
7

8
#include "src/bailout-reason.h"
9
#include "src/deoptimizer.h"
10
#include "src/source-position-table.h"
11 12 13 14

namespace v8 {
namespace internal {

15
class CompilationInfo;
16 17
class HGraph;
class LChunk;
18
class LEnvironment;
19 20 21 22 23 24 25 26 27 28 29 30 31
class LInstruction;
class LPlatformChunk;

class LCodeGenBase BASE_EMBEDDED {
 public:
  LCodeGenBase(LChunk* chunk,
               MacroAssembler* assembler,
               CompilationInfo* info);
  virtual ~LCodeGenBase() {}

  // Simple accessors.
  MacroAssembler* masm() const { return masm_; }
  CompilationInfo* info() const { return info_; }
32
  Isolate* isolate() const;
33 34 35 36 37
  Factory* factory() const { return isolate()->factory(); }
  Heap* heap() const { return isolate()->heap(); }
  Zone* zone() const { return zone_; }
  LPlatformChunk* chunk() const { return chunk_; }
  HGraph* graph() const;
38 39 40
  SourcePositionTableBuilder* source_position_table_builder() {
    return &source_position_table_builder_;
  }
41

jfb's avatar
jfb committed
42
  void PRINTF_FORMAT(2, 3) Comment(const char* format, ...);
43
  void DeoptComment(const Deoptimizer::DeoptInfo& deopt_info);
44 45 46
  static Deoptimizer::DeoptInfo MakeDeoptInfo(LInstruction* instr,
                                              DeoptimizeReason deopt_reason,
                                              int deopt_id);
47 48 49 50 51 52

  bool GenerateBody();
  virtual void GenerateBodyInstructionPre(LInstruction* instr) {}
  virtual void GenerateBodyInstructionPost(LInstruction* instr) {}

  virtual void EnsureSpaceForLazyDeopt(int space_needed) = 0;
53
  void RecordAndWritePosition(SourcePosition position);
54 55 56

  int GetNextEmittedBlock() const;

57 58 59 60
  void WriteTranslationFrame(LEnvironment* environment,
                             Translation* translation);
  int DefineDeoptimizationLiteral(Handle<Object> literal);

61 62 63
  void PopulateDeoptimizationData(Handle<Code> code);
  void PopulateDeoptimizationLiteralsWithInlinedFunctions();

64 65 66 67 68
  // Check that an environment assigned via AssignEnvironment is actually being
  // used. Redundant assignments keep things alive longer than necessary, and
  // consequently lead to worse code, so it's important to minimize this.
  void CheckEnvironmentUsage();

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
 protected:
  enum Status {
    UNUSED,
    GENERATING,
    DONE,
    ABORTED
  };

  LPlatformChunk* const chunk_;
  MacroAssembler* const masm_;
  CompilationInfo* const info_;
  Zone* zone_;
  Status status_;
  int current_block_;
  int current_instruction_;
  const ZoneList<LInstruction*>* instructions_;
85
  ZoneList<LEnvironment*> deoptimizations_;
86
  ZoneList<Handle<Object> > deoptimization_literals_;
87 88
  TranslationBuffer translations_;
  int inlined_function_count_;
89
  int last_lazy_deopt_pc_;
90
  int osr_pc_offset_;
91
  SourcePositionTableBuilder source_position_table_builder_;
92 93 94 95 96

  bool is_unused() const { return status_ == UNUSED; }
  bool is_generating() const { return status_ == GENERATING; }
  bool is_done() const { return status_ == DONE; }
  bool is_aborted() const { return status_ == ABORTED; }
97 98

  void Abort(BailoutReason reason);
99
  void Retry(BailoutReason reason);
100 101

  // Methods for code dependencies.
102
  void AddDeprecationDependency(Handle<Map> map);
103
  void AddStabilityDependency(Handle<Map> map);
104 105 106
};


107 108
}  // namespace internal
}  // namespace v8
109

110
#endif  // V8_CRANKSHAFT_LITHIUM_CODEGEN_H_