Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / v8 / src / lithium.h
1 // Copyright 2012 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_H_
6 #define V8_LITHIUM_H_
7
8 #include <set>
9
10 #include "allocation.h"
11 #include "hydrogen.h"
12 #include "safepoint-table.h"
13 #include "zone-allocator.h"
14
15 namespace v8 {
16 namespace internal {
17
18 #define LITHIUM_OPERAND_LIST(V)                     \
19   V(ConstantOperand,    CONSTANT_OPERAND,     128)  \
20   V(StackSlot,          STACK_SLOT,           128)  \
21   V(DoubleStackSlot,    DOUBLE_STACK_SLOT,    128)  \
22   V(Float32x4StackSlot, FLOAT32x4_STACK_SLOT, 128)  \
23   V(Float64x2StackSlot, FLOAT64x2_STACK_SLOT, 128)  \
24   V(Int32x4StackSlot,   INT32x4_STACK_SLOT,   128)  \
25   V(Register,           REGISTER,             16)   \
26   V(DoubleRegister,     DOUBLE_REGISTER,      16)   \
27   V(Float32x4Register,  FLOAT32x4_REGISTER,   16)   \
28   V(Float64x2Register,  FLOAT64x2_REGISTER,   16)   \
29   V(Int32x4Register,    INT32x4_REGISTER,     16)
30
31
32 class LOperand : public ZoneObject {
33  public:
34   enum Kind {
35     INVALID,
36     UNALLOCATED,
37     CONSTANT_OPERAND,
38     STACK_SLOT,
39     DOUBLE_STACK_SLOT,
40     FLOAT32x4_STACK_SLOT,
41     FLOAT64x2_STACK_SLOT,
42     INT32x4_STACK_SLOT,
43     REGISTER,
44     DOUBLE_REGISTER,
45     FLOAT32x4_REGISTER,
46     FLOAT64x2_REGISTER,
47     INT32x4_REGISTER
48   };
49
50   LOperand() : value_(KindField::encode(INVALID)) { }
51
52   Kind kind() const { return KindField::decode(value_); }
53   int index() const { return static_cast<int>(value_) >> kKindFieldWidth; }
54 #define LITHIUM_OPERAND_PREDICATE(name, type, number) \
55   bool Is##name() const { return kind() == type; }
56   LITHIUM_OPERAND_LIST(LITHIUM_OPERAND_PREDICATE)
57   LITHIUM_OPERAND_PREDICATE(Unallocated, UNALLOCATED, 0)
58   LITHIUM_OPERAND_PREDICATE(Ignored, INVALID, 0)
59 #undef LITHIUM_OPERAND_PREDICATE
60   bool IsSIMD128Register() const {
61     return kind() == FLOAT32x4_REGISTER || kind() == FLOAT64x2_REGISTER ||
62            kind() == INT32x4_REGISTER;
63   }
64   bool IsSIMD128StackSlot() const {
65     return kind() == FLOAT32x4_STACK_SLOT || kind() == FLOAT64x2_STACK_SLOT ||
66            kind() == INT32x4_STACK_SLOT;
67   }
68   bool Equals(LOperand* other) const {
69     return value_ == other->value_ || (index() == other->index() &&
70         ((IsSIMD128Register() && other->IsSIMD128Register()) ||
71          (IsSIMD128StackSlot() && other->IsSIMD128StackSlot())));
72   }
73
74   void PrintTo(StringStream* stream);
75   void ConvertTo(Kind kind, int index) {
76     value_ = KindField::encode(kind);
77     value_ |= index << kKindFieldWidth;
78     ASSERT(this->index() == index);
79   }
80
81   // Calls SetUpCache()/TearDownCache() for each subclass.
82   static void SetUpCaches();
83   static void TearDownCaches();
84
85  protected:
86   static const int kKindFieldWidth = 4;
87   class KindField : public BitField<Kind, 0, kKindFieldWidth> { };
88
89   LOperand(Kind kind, int index) { ConvertTo(kind, index); }
90
91   unsigned value_;
92 };
93
94
95 class LUnallocated : public LOperand {
96  public:
97   enum BasicPolicy {
98     FIXED_SLOT,
99     EXTENDED_POLICY
100   };
101
102   enum ExtendedPolicy {
103     NONE,
104     ANY,
105     FIXED_REGISTER,
106     FIXED_DOUBLE_REGISTER,
107     MUST_HAVE_REGISTER,
108     WRITABLE_REGISTER,
109     SAME_AS_FIRST_INPUT
110   };
111
112   // Lifetime of operand inside the instruction.
113   enum Lifetime {
114     // USED_AT_START operand is guaranteed to be live only at
115     // instruction start. Register allocator is free to assign the same register
116     // to some other operand used inside instruction (i.e. temporary or
117     // output).
118     USED_AT_START,
119
120     // USED_AT_END operand is treated as live until the end of
121     // instruction. This means that register allocator will not reuse it's
122     // register for any other operand inside instruction.
123     USED_AT_END
124   };
125
126   explicit LUnallocated(ExtendedPolicy policy) : LOperand(UNALLOCATED, 0) {
127     value_ |= BasicPolicyField::encode(EXTENDED_POLICY);
128     value_ |= ExtendedPolicyField::encode(policy);
129     value_ |= LifetimeField::encode(USED_AT_END);
130   }
131
132   LUnallocated(BasicPolicy policy, int index) : LOperand(UNALLOCATED, 0) {
133     ASSERT(policy == FIXED_SLOT);
134     value_ |= BasicPolicyField::encode(policy);
135     value_ |= index << FixedSlotIndexField::kShift;
136     ASSERT(this->fixed_slot_index() == index);
137   }
138
139   LUnallocated(ExtendedPolicy policy, int index) : LOperand(UNALLOCATED, 0) {
140     ASSERT(policy == FIXED_REGISTER || policy == FIXED_DOUBLE_REGISTER);
141     value_ |= BasicPolicyField::encode(EXTENDED_POLICY);
142     value_ |= ExtendedPolicyField::encode(policy);
143     value_ |= LifetimeField::encode(USED_AT_END);
144     value_ |= FixedRegisterField::encode(index);
145   }
146
147   LUnallocated(ExtendedPolicy policy, Lifetime lifetime)
148       : LOperand(UNALLOCATED, 0) {
149     value_ |= BasicPolicyField::encode(EXTENDED_POLICY);
150     value_ |= ExtendedPolicyField::encode(policy);
151     value_ |= LifetimeField::encode(lifetime);
152   }
153
154   LUnallocated* CopyUnconstrained(Zone* zone) {
155     LUnallocated* result = new(zone) LUnallocated(ANY);
156     result->set_virtual_register(virtual_register());
157     return result;
158   }
159
160   static LUnallocated* cast(LOperand* op) {
161     ASSERT(op->IsUnallocated());
162     return reinterpret_cast<LUnallocated*>(op);
163   }
164
165   // The encoding used for LUnallocated operands depends on the policy that is
166   // stored within the operand. The FIXED_SLOT policy uses a compact encoding
167   // because it accommodates a larger pay-load.
168   //
169   // For FIXED_SLOT policy:
170   //     +-------------------------------------------+
171   //     |       slot_index      |  vreg  | 0 | 0001 |
172   //     +-------------------------------------------+
173   //
174   // For all other (extended) policies:
175   //     +-------------------------------------------+
176   //     |  reg_index  | L | PPP |  vreg  | 1 | 0001 |    L ... Lifetime
177   //     +-------------------------------------------+    P ... Policy
178   //
179   // The slot index is a signed value which requires us to decode it manually
180   // instead of using the BitField utility class.
181
182   // The superclass has a KindField.
183   STATIC_ASSERT(kKindFieldWidth == 4);
184
185   // BitFields for all unallocated operands.
186   class BasicPolicyField     : public BitField<BasicPolicy,     4,  1> {};
187   class VirtualRegisterField : public BitField<unsigned,        5, 18> {};
188
189   // BitFields specific to BasicPolicy::FIXED_SLOT.
190   class FixedSlotIndexField  : public BitField<int,            23,  9> {};
191
192   // BitFields specific to BasicPolicy::EXTENDED_POLICY.
193   class ExtendedPolicyField  : public BitField<ExtendedPolicy, 23,  3> {};
194   class LifetimeField        : public BitField<Lifetime,       26,  1> {};
195   class FixedRegisterField   : public BitField<int,            27,  5> {};
196
197   static const int kMaxVirtualRegisters = VirtualRegisterField::kMax + 1;
198   static const int kFixedSlotIndexWidth = FixedSlotIndexField::kSize;
199   static const int kMaxFixedSlotIndex = (1 << (kFixedSlotIndexWidth - 1)) - 1;
200   static const int kMinFixedSlotIndex = -(1 << (kFixedSlotIndexWidth - 1));
201
202   // Predicates for the operand policy.
203   bool HasAnyPolicy() const {
204     return basic_policy() == EXTENDED_POLICY &&
205         extended_policy() == ANY;
206   }
207   bool HasFixedPolicy() const {
208     return basic_policy() == FIXED_SLOT ||
209         extended_policy() == FIXED_REGISTER ||
210         extended_policy() == FIXED_DOUBLE_REGISTER;
211   }
212   bool HasRegisterPolicy() const {
213     return basic_policy() == EXTENDED_POLICY && (
214         extended_policy() == WRITABLE_REGISTER ||
215         extended_policy() == MUST_HAVE_REGISTER);
216   }
217   bool HasSameAsInputPolicy() const {
218     return basic_policy() == EXTENDED_POLICY &&
219         extended_policy() == SAME_AS_FIRST_INPUT;
220   }
221   bool HasFixedSlotPolicy() const {
222     return basic_policy() == FIXED_SLOT;
223   }
224   bool HasFixedRegisterPolicy() const {
225     return basic_policy() == EXTENDED_POLICY &&
226         extended_policy() == FIXED_REGISTER;
227   }
228   bool HasFixedDoubleRegisterPolicy() const {
229     return basic_policy() == EXTENDED_POLICY &&
230         extended_policy() == FIXED_DOUBLE_REGISTER;
231   }
232   bool HasWritableRegisterPolicy() const {
233     return basic_policy() == EXTENDED_POLICY &&
234         extended_policy() == WRITABLE_REGISTER;
235   }
236
237   // [basic_policy]: Distinguish between FIXED_SLOT and all other policies.
238   BasicPolicy basic_policy() const {
239     return BasicPolicyField::decode(value_);
240   }
241
242   // [extended_policy]: Only for non-FIXED_SLOT. The finer-grained policy.
243   ExtendedPolicy extended_policy() const {
244     ASSERT(basic_policy() == EXTENDED_POLICY);
245     return ExtendedPolicyField::decode(value_);
246   }
247
248   // [fixed_slot_index]: Only for FIXED_SLOT.
249   int fixed_slot_index() const {
250     ASSERT(HasFixedSlotPolicy());
251     return static_cast<int>(value_) >> FixedSlotIndexField::kShift;
252   }
253
254   // [fixed_register_index]: Only for FIXED_REGISTER or FIXED_DOUBLE_REGISTER.
255   int fixed_register_index() const {
256     ASSERT(HasFixedRegisterPolicy() || HasFixedDoubleRegisterPolicy());
257     return FixedRegisterField::decode(value_);
258   }
259
260   // [virtual_register]: The virtual register ID for this operand.
261   int virtual_register() const {
262     return VirtualRegisterField::decode(value_);
263   }
264   void set_virtual_register(unsigned id) {
265     value_ = VirtualRegisterField::update(value_, id);
266   }
267
268   // [lifetime]: Only for non-FIXED_SLOT.
269   bool IsUsedAtStart() {
270     ASSERT(basic_policy() == EXTENDED_POLICY);
271     return LifetimeField::decode(value_) == USED_AT_START;
272   }
273 };
274
275
276 class LMoveOperands V8_FINAL BASE_EMBEDDED {
277  public:
278   LMoveOperands(LOperand* source, LOperand* destination)
279       : source_(source), destination_(destination) {
280   }
281
282   LOperand* source() const { return source_; }
283   void set_source(LOperand* operand) { source_ = operand; }
284
285   LOperand* destination() const { return destination_; }
286   void set_destination(LOperand* operand) { destination_ = operand; }
287
288   // The gap resolver marks moves as "in-progress" by clearing the
289   // destination (but not the source).
290   bool IsPending() const {
291     return destination_ == NULL && source_ != NULL;
292   }
293
294   // True if this move a move into the given destination operand.
295   bool Blocks(LOperand* operand) const {
296     return !IsEliminated() && source()->Equals(operand);
297   }
298
299   // A move is redundant if it's been eliminated, if its source and
300   // destination are the same, or if its destination is unneeded.
301   bool IsRedundant() const {
302     return IsEliminated() || source_->Equals(destination_) || IsIgnored();
303   }
304
305   bool IsIgnored() const {
306     return destination_ != NULL && destination_->IsIgnored();
307   }
308
309   // We clear both operands to indicate move that's been eliminated.
310   void Eliminate() { source_ = destination_ = NULL; }
311   bool IsEliminated() const {
312     ASSERT(source_ != NULL || destination_ == NULL);
313     return source_ == NULL;
314   }
315
316  private:
317   LOperand* source_;
318   LOperand* destination_;
319 };
320
321
322 template<LOperand::Kind kOperandKind, int kNumCachedOperands>
323 class LSubKindOperand V8_FINAL : public LOperand {
324  public:
325   static LSubKindOperand* Create(int index, Zone* zone) {
326     ASSERT(index >= 0);
327     if (index < kNumCachedOperands) return &cache[index];
328     return new(zone) LSubKindOperand(index);
329   }
330
331   static LSubKindOperand* cast(LOperand* op) {
332     ASSERT(op->kind() == kOperandKind);
333     return reinterpret_cast<LSubKindOperand*>(op);
334   }
335
336   static void SetUpCache();
337   static void TearDownCache();
338
339  private:
340   static LSubKindOperand* cache;
341
342   LSubKindOperand() : LOperand() { }
343   explicit LSubKindOperand(int index) : LOperand(kOperandKind, index) { }
344 };
345
346
347 #define LITHIUM_TYPEDEF_SUBKIND_OPERAND_CLASS(name, type, number)   \
348 typedef LSubKindOperand<LOperand::type, number> L##name;
349 LITHIUM_OPERAND_LIST(LITHIUM_TYPEDEF_SUBKIND_OPERAND_CLASS)
350 #undef LITHIUM_TYPEDEF_SUBKIND_OPERAND_CLASS
351
352
353 class LParallelMove V8_FINAL : public ZoneObject {
354  public:
355   explicit LParallelMove(Zone* zone) : move_operands_(4, zone) { }
356
357   void AddMove(LOperand* from, LOperand* to, Zone* zone) {
358     move_operands_.Add(LMoveOperands(from, to), zone);
359   }
360
361   bool IsRedundant() const;
362
363   const ZoneList<LMoveOperands>* move_operands() const {
364     return &move_operands_;
365   }
366
367   void PrintDataTo(StringStream* stream) const;
368
369  private:
370   ZoneList<LMoveOperands> move_operands_;
371 };
372
373
374 class LPointerMap V8_FINAL : public ZoneObject {
375  public:
376   explicit LPointerMap(Zone* zone)
377       : pointer_operands_(8, zone),
378         untagged_operands_(0, zone),
379         lithium_position_(-1) { }
380
381   const ZoneList<LOperand*>* GetNormalizedOperands() {
382     for (int i = 0; i < untagged_operands_.length(); ++i) {
383       RemovePointer(untagged_operands_[i]);
384     }
385     untagged_operands_.Clear();
386     return &pointer_operands_;
387   }
388   int lithium_position() const { return lithium_position_; }
389
390   void set_lithium_position(int pos) {
391     ASSERT(lithium_position_ == -1);
392     lithium_position_ = pos;
393   }
394
395   void RecordPointer(LOperand* op, Zone* zone);
396   void RemovePointer(LOperand* op);
397   void RecordUntagged(LOperand* op, Zone* zone);
398   void PrintTo(StringStream* stream);
399
400  private:
401   ZoneList<LOperand*> pointer_operands_;
402   ZoneList<LOperand*> untagged_operands_;
403   int lithium_position_;
404 };
405
406
407 class LEnvironment V8_FINAL : public ZoneObject {
408  public:
409   LEnvironment(Handle<JSFunction> closure,
410                FrameType frame_type,
411                BailoutId ast_id,
412                int parameter_count,
413                int argument_count,
414                int value_count,
415                LEnvironment* outer,
416                HEnterInlined* entry,
417                Zone* zone)
418       : closure_(closure),
419         frame_type_(frame_type),
420         arguments_stack_height_(argument_count),
421         deoptimization_index_(Safepoint::kNoDeoptimizationIndex),
422         translation_index_(-1),
423         ast_id_(ast_id),
424         translation_size_(value_count),
425         parameter_count_(parameter_count),
426         pc_offset_(-1),
427         values_(value_count, zone),
428         is_tagged_(value_count, zone),
429         is_uint32_(value_count, zone),
430         object_mapping_(0, zone),
431         outer_(outer),
432         entry_(entry),
433         zone_(zone),
434         has_been_used_(false) { }
435
436   Handle<JSFunction> closure() const { return closure_; }
437   FrameType frame_type() const { return frame_type_; }
438   int arguments_stack_height() const { return arguments_stack_height_; }
439   int deoptimization_index() const { return deoptimization_index_; }
440   int translation_index() const { return translation_index_; }
441   BailoutId ast_id() const { return ast_id_; }
442   int translation_size() const { return translation_size_; }
443   int parameter_count() const { return parameter_count_; }
444   int pc_offset() const { return pc_offset_; }
445   const ZoneList<LOperand*>* values() const { return &values_; }
446   LEnvironment* outer() const { return outer_; }
447   HEnterInlined* entry() { return entry_; }
448   Zone* zone() const { return zone_; }
449
450   bool has_been_used() const { return has_been_used_; }
451   void set_has_been_used() { has_been_used_ = true; }
452
453   void AddValue(LOperand* operand,
454                 Representation representation,
455                 bool is_uint32) {
456     values_.Add(operand, zone());
457     if (representation.IsSmiOrTagged()) {
458       ASSERT(!is_uint32);
459       is_tagged_.Add(values_.length() - 1, zone());
460     }
461
462     if (is_uint32) {
463       is_uint32_.Add(values_.length() - 1, zone());
464     }
465   }
466
467   bool HasTaggedValueAt(int index) const {
468     return is_tagged_.Contains(index);
469   }
470
471   bool HasUint32ValueAt(int index) const {
472     return is_uint32_.Contains(index);
473   }
474
475   void AddNewObject(int length, bool is_arguments) {
476     uint32_t encoded = LengthOrDupeField::encode(length) |
477                        IsArgumentsField::encode(is_arguments) |
478                        IsDuplicateField::encode(false);
479     object_mapping_.Add(encoded, zone());
480   }
481
482   void AddDuplicateObject(int dupe_of) {
483     uint32_t encoded = LengthOrDupeField::encode(dupe_of) |
484                        IsDuplicateField::encode(true);
485     object_mapping_.Add(encoded, zone());
486   }
487
488   int ObjectDuplicateOfAt(int index) {
489     ASSERT(ObjectIsDuplicateAt(index));
490     return LengthOrDupeField::decode(object_mapping_[index]);
491   }
492
493   int ObjectLengthAt(int index) {
494     ASSERT(!ObjectIsDuplicateAt(index));
495     return LengthOrDupeField::decode(object_mapping_[index]);
496   }
497
498   bool ObjectIsArgumentsAt(int index) {
499     ASSERT(!ObjectIsDuplicateAt(index));
500     return IsArgumentsField::decode(object_mapping_[index]);
501   }
502
503   bool ObjectIsDuplicateAt(int index) {
504     return IsDuplicateField::decode(object_mapping_[index]);
505   }
506
507   void Register(int deoptimization_index,
508                 int translation_index,
509                 int pc_offset) {
510     ASSERT(!HasBeenRegistered());
511     deoptimization_index_ = deoptimization_index;
512     translation_index_ = translation_index;
513     pc_offset_ = pc_offset;
514   }
515   bool HasBeenRegistered() const {
516     return deoptimization_index_ != Safepoint::kNoDeoptimizationIndex;
517   }
518
519   void PrintTo(StringStream* stream);
520
521   // Marker value indicating a de-materialized object.
522   static LOperand* materialization_marker() { return NULL; }
523
524   // Encoding used for the object_mapping map below.
525   class LengthOrDupeField : public BitField<int,   0, 30> { };
526   class IsArgumentsField  : public BitField<bool, 30,  1> { };
527   class IsDuplicateField  : public BitField<bool, 31,  1> { };
528
529  private:
530   Handle<JSFunction> closure_;
531   FrameType frame_type_;
532   int arguments_stack_height_;
533   int deoptimization_index_;
534   int translation_index_;
535   BailoutId ast_id_;
536   int translation_size_;
537   int parameter_count_;
538   int pc_offset_;
539
540   // Value array: [parameters] [locals] [expression stack] [de-materialized].
541   //              |>--------- translation_size ---------<|
542   ZoneList<LOperand*> values_;
543   GrowableBitVector is_tagged_;
544   GrowableBitVector is_uint32_;
545
546   // Map with encoded information about materialization_marker operands.
547   ZoneList<uint32_t> object_mapping_;
548
549   LEnvironment* outer_;
550   HEnterInlined* entry_;
551   Zone* zone_;
552   bool has_been_used_;
553 };
554
555
556 // Iterates over the non-null, non-constant operands in an environment.
557 class ShallowIterator V8_FINAL BASE_EMBEDDED {
558  public:
559   explicit ShallowIterator(LEnvironment* env)
560       : env_(env),
561         limit_(env != NULL ? env->values()->length() : 0),
562         current_(0) {
563     SkipUninteresting();
564   }
565
566   bool Done() { return current_ >= limit_; }
567
568   LOperand* Current() {
569     ASSERT(!Done());
570     ASSERT(env_->values()->at(current_) != NULL);
571     return env_->values()->at(current_);
572   }
573
574   void Advance() {
575     ASSERT(!Done());
576     ++current_;
577     SkipUninteresting();
578   }
579
580   LEnvironment* env() { return env_; }
581
582  private:
583   bool ShouldSkip(LOperand* op) {
584     return op == NULL || op->IsConstantOperand();
585   }
586
587   // Skip until something interesting, beginning with and including current_.
588   void SkipUninteresting() {
589     while (current_ < limit_ && ShouldSkip(env_->values()->at(current_))) {
590       ++current_;
591     }
592   }
593
594   LEnvironment* env_;
595   int limit_;
596   int current_;
597 };
598
599
600 // Iterator for non-null, non-constant operands incl. outer environments.
601 class DeepIterator V8_FINAL BASE_EMBEDDED {
602  public:
603   explicit DeepIterator(LEnvironment* env)
604       : current_iterator_(env) {
605     SkipUninteresting();
606   }
607
608   bool Done() { return current_iterator_.Done(); }
609
610   LOperand* Current() {
611     ASSERT(!current_iterator_.Done());
612     ASSERT(current_iterator_.Current() != NULL);
613     return current_iterator_.Current();
614   }
615
616   void Advance() {
617     current_iterator_.Advance();
618     SkipUninteresting();
619   }
620
621  private:
622   void SkipUninteresting() {
623     while (current_iterator_.env() != NULL && current_iterator_.Done()) {
624       current_iterator_ = ShallowIterator(current_iterator_.env()->outer());
625     }
626   }
627
628   ShallowIterator current_iterator_;
629 };
630
631
632 class LPlatformChunk;
633 class LGap;
634 class LLabel;
635
636 // Superclass providing data and behavior common to all the
637 // arch-specific LPlatformChunk classes.
638 class LChunk : public ZoneObject {
639  public:
640   static LChunk* NewChunk(HGraph* graph);
641
642   void AddInstruction(LInstruction* instruction, HBasicBlock* block);
643   LConstantOperand* DefineConstantOperand(HConstant* constant);
644   HConstant* LookupConstant(LConstantOperand* operand) const;
645   Representation LookupLiteralRepresentation(LConstantOperand* operand) const;
646
647   int ParameterAt(int index);
648   int GetParameterStackSlot(int index) const;
649   int spill_slot_count() const { return spill_slot_count_; }
650   CompilationInfo* info() const { return info_; }
651   HGraph* graph() const { return graph_; }
652   Isolate* isolate() const { return graph_->isolate(); }
653   const ZoneList<LInstruction*>* instructions() const { return &instructions_; }
654   void AddGapMove(int index, LOperand* from, LOperand* to);
655   LGap* GetGapAt(int index) const;
656   bool IsGapAt(int index) const;
657   int NearestGapPos(int index) const;
658   void MarkEmptyBlocks();
659   const ZoneList<LPointerMap*>* pointer_maps() const { return &pointer_maps_; }
660   LLabel* GetLabel(int block_id) const;
661   int LookupDestination(int block_id) const;
662   Label* GetAssemblyLabel(int block_id) const;
663
664   const ZoneList<Handle<JSFunction> >* inlined_closures() const {
665     return &inlined_closures_;
666   }
667
668   void AddInlinedClosure(Handle<JSFunction> closure) {
669     inlined_closures_.Add(closure, zone());
670   }
671
672   void AddDeprecationDependency(Handle<Map> map) {
673     ASSERT(!map->is_deprecated());
674     if (!map->CanBeDeprecated()) return;
675     ASSERT(!info_->IsStub());
676     deprecation_dependencies_.insert(map);
677   }
678
679   void AddStabilityDependency(Handle<Map> map) {
680     ASSERT(map->is_stable());
681     if (!map->CanTransition()) return;
682     ASSERT(!info_->IsStub());
683     stability_dependencies_.insert(map);
684   }
685
686   Zone* zone() const { return info_->zone(); }
687
688   Handle<Code> Codegen();
689
690   void set_allocated_double_registers(BitVector* allocated_registers);
691   BitVector* allocated_double_registers() {
692     return allocated_double_registers_;
693   }
694
695  protected:
696   LChunk(CompilationInfo* info, HGraph* graph);
697
698   int spill_slot_count_;
699
700  private:
701   typedef std::less<Handle<Map> > MapLess;
702   typedef zone_allocator<Handle<Map> > MapAllocator;
703   typedef std::set<Handle<Map>, MapLess, MapAllocator> MapSet;
704
705   void CommitDependencies(Handle<Code> code) const;
706
707   CompilationInfo* info_;
708   HGraph* const graph_;
709   BitVector* allocated_double_registers_;
710   ZoneList<LInstruction*> instructions_;
711   ZoneList<LPointerMap*> pointer_maps_;
712   ZoneList<Handle<JSFunction> > inlined_closures_;
713   MapSet deprecation_dependencies_;
714   MapSet stability_dependencies_;
715 };
716
717
718 class LChunkBuilderBase BASE_EMBEDDED {
719  public:
720   explicit LChunkBuilderBase(Zone* zone)
721       : argument_count_(0),
722         zone_(zone) { }
723
724   virtual ~LChunkBuilderBase() { }
725
726  protected:
727   // An input operand in register, stack slot or a constant operand.
728   // Will not be moved to a register even if one is freely available.
729   virtual MUST_USE_RESULT LOperand* UseAny(HValue* value) = 0;
730
731   LEnvironment* CreateEnvironment(HEnvironment* hydrogen_env,
732                                   int* argument_index_accumulator,
733                                   ZoneList<HValue*>* objects_to_materialize);
734   void AddObjectToMaterialize(HValue* value,
735                               ZoneList<HValue*>* objects_to_materialize,
736                               LEnvironment* result);
737
738   Zone* zone() const { return zone_; }
739
740   int argument_count_;
741
742  private:
743   Zone* zone_;
744 };
745
746
747 int StackSlotOffset(int index);
748
749 enum NumberUntagDMode {
750   NUMBER_CANDIDATE_IS_SMI,
751   NUMBER_CANDIDATE_IS_ANY_TAGGED
752 };
753
754
755 class LPhase : public CompilationPhase {
756  public:
757   LPhase(const char* name, LChunk* chunk)
758       : CompilationPhase(name, chunk->info()),
759         chunk_(chunk) { }
760   ~LPhase();
761
762  private:
763   LChunk* chunk_;
764
765   DISALLOW_COPY_AND_ASSIGN(LPhase);
766 };
767
768
769 } }  // namespace v8::internal
770
771 #endif  // V8_LITHIUM_H_