Home | History | Annotate | Download | only in crankshaft
      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_HYDROGEN_ENVIRONMENT_LIVENESS_H_
      6 #define V8_CRANKSHAFT_HYDROGEN_ENVIRONMENT_LIVENESS_H_
      7 
      8 #include "src/crankshaft/hydrogen.h"
      9 
     10 namespace v8 {
     11 namespace internal {
     12 
     13 
     14 // Trims live ranges of environment slots by doing explicit liveness analysis.
     15 // Values in the environment are kept alive by every subsequent LInstruction
     16 // that is assigned an LEnvironment, which creates register pressure and
     17 // unnecessary spill slot moves. Therefore it is beneficial to trim the
     18 // live ranges of environment slots by zapping them with a constant after
     19 // the last lookup that refers to them.
     20 // Slots are identified by their index and only affected if whitelisted in
     21 // HOptimizedGraphBuilder::IsEligibleForEnvironmentLivenessAnalysis().
     22 class HEnvironmentLivenessAnalysisPhase : public HPhase {
     23  public:
     24   explicit HEnvironmentLivenessAnalysisPhase(HGraph* graph);
     25 
     26   void Run();
     27 
     28  private:
     29   void ZapEnvironmentSlot(int index, HSimulate* simulate);
     30   void ZapEnvironmentSlotsInSuccessors(HBasicBlock* block, BitVector* live);
     31   void ZapEnvironmentSlotsForInstruction(HEnvironmentMarker* marker);
     32   void UpdateLivenessAtBlockEnd(HBasicBlock* block, BitVector* live);
     33   void UpdateLivenessAtInstruction(HInstruction* instr, BitVector* live);
     34 #ifdef DEBUG
     35   bool VerifyClosures(Handle<JSFunction> a, Handle<JSFunction> b);
     36 #endif
     37 
     38   int block_count_;
     39 
     40   // Largest number of local variables in any environment in the graph
     41   // (including inlined environments).
     42   int maximum_environment_size_;
     43 
     44   // Per-block data. All these lists are indexed by block_id.
     45   ZoneList<BitVector*> live_at_block_start_;
     46   ZoneList<HSimulate*> first_simulate_;
     47   ZoneList<BitVector*> first_simulate_invalid_for_index_;
     48 
     49   // List of all HEnvironmentMarker instructions for quick iteration/deletion.
     50   // It is populated during the first pass over the graph, controlled by
     51   // |collect_markers_|.
     52   ZoneList<HEnvironmentMarker*> markers_;
     53   bool collect_markers_;
     54 
     55   // Keeps track of the last simulate seen, as well as the environment slots
     56   // for which a new live range has started since (so they must not be zapped
     57   // in that simulate when the end of another live range of theirs is found).
     58   HSimulate* last_simulate_;
     59   BitVector went_live_since_last_simulate_;
     60 
     61   DISALLOW_COPY_AND_ASSIGN(HEnvironmentLivenessAnalysisPhase);
     62 };
     63 
     64 
     65 }  // namespace internal
     66 }  // namespace v8
     67 
     68 #endif  // V8_CRANKSHAFT_HYDROGEN_ENVIRONMENT_LIVENESS_H_
     69