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