blob: 248ec5ce5d78cfc392ad935122fcd74f5b49cdb0 [file] [log] [blame]
verwaest@chromium.orgd4be0f02013-06-05 13:39:03 +00001// Copyright 2013 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_HYDROGEN_ENVIRONMENT_LIVENESS_H_
29#define V8_HYDROGEN_ENVIRONMENT_LIVENESS_H_
30
31
32#include "hydrogen.h"
33
34namespace v8 {
35namespace internal {
36
37
38// Trims live ranges of environment slots by doing explicit liveness analysis.
39// Values in the environment are kept alive by every subsequent LInstruction
40// that is assigned an LEnvironment, which creates register pressure and
41// unnecessary spill slot moves. Therefore it is beneficial to trim the
42// live ranges of environment slots by zapping them with a constant after
43// the last lookup that refers to them.
44// Slots are identified by their index and only affected if whitelisted in
45// HOptimizedGraphBuilder::IsEligibleForEnvironmentLivenessAnalysis().
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +000046class HEnvironmentLivenessAnalysisPhase : public HPhase {
verwaest@chromium.orgd4be0f02013-06-05 13:39:03 +000047 public:
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +000048 explicit HEnvironmentLivenessAnalysisPhase(HGraph* graph);
verwaest@chromium.orgd4be0f02013-06-05 13:39:03 +000049
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +000050 void Run();
verwaest@chromium.orgd4be0f02013-06-05 13:39:03 +000051
52 private:
53 void ZapEnvironmentSlot(int index, HSimulate* simulate);
54 void ZapEnvironmentSlotsInSuccessors(HBasicBlock* block, BitVector* live);
55 void ZapEnvironmentSlotsForInstruction(HEnvironmentMarker* marker);
56 void UpdateLivenessAtBlockEnd(HBasicBlock* block, BitVector* live);
57 void UpdateLivenessAtInstruction(HInstruction* instr, BitVector* live);
58
verwaest@chromium.orgd4be0f02013-06-05 13:39:03 +000059 int block_count_;
60
61 // Largest number of local variables in any environment in the graph
62 // (including inlined environments).
63 int maximum_environment_size_;
64
65 // Per-block data. All these lists are indexed by block_id.
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +000066 ZoneList<BitVector*> live_at_block_start_;
67 ZoneList<HSimulate*> first_simulate_;
68 ZoneList<BitVector*> first_simulate_invalid_for_index_;
verwaest@chromium.orgd4be0f02013-06-05 13:39:03 +000069
70 // List of all HEnvironmentMarker instructions for quick iteration/deletion.
71 // It is populated during the first pass over the graph, controlled by
72 // |collect_markers_|.
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +000073 ZoneList<HEnvironmentMarker*> markers_;
verwaest@chromium.orgd4be0f02013-06-05 13:39:03 +000074 bool collect_markers_;
75
76 // Keeps track of the last simulate seen, as well as the environment slots
77 // for which a new live range has started since (so they must not be zapped
78 // in that simulate when the end of another live range of theirs is found).
79 HSimulate* last_simulate_;
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +000080 BitVector went_live_since_last_simulate_;
81
82 DISALLOW_COPY_AND_ASSIGN(HEnvironmentLivenessAnalysisPhase);
verwaest@chromium.orgd4be0f02013-06-05 13:39:03 +000083};
84
85
86} } // namespace v8::internal
87
88#endif /* V8_HYDROGEN_ENVIRONMENT_LIVENESS_H_ */