| Index: src/hydrogen-phases.h
|
| diff --git a/src/hydrogen-phases.h b/src/hydrogen-phases.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1a439e310ffbd4545d1b69f299303e0b2e208b9c
|
| --- /dev/null
|
| +++ b/src/hydrogen-phases.h
|
| @@ -0,0 +1,396 @@
|
| +// Copyright 2013 the V8 project authors. All rights reserved.
|
| +// Redistribution and use in source and binary forms, with or without
|
| +// modification, are permitted provided that the following conditions are
|
| +// met:
|
| +//
|
| +// * Redistributions of source code must retain the above copyright
|
| +// notice, this list of conditions and the following disclaimer.
|
| +// * Redistributions in binary form must reproduce the above
|
| +// copyright notice, this list of conditions and the following
|
| +// disclaimer in the documentation and/or other materials provided
|
| +// with the distribution.
|
| +// * Neither the name of Google Inc. nor the names of its
|
| +// contributors may be used to endorse or promote products derived
|
| +// from this software without specific prior written permission.
|
| +//
|
| +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| +
|
| +#ifndef V8_HYDROGEN_PHASES_H_
|
| +#define V8_HYDROGEN_PHASES_H_
|
| +
|
| +#include "hydrogen.h"
|
| +
|
| +namespace v8 {
|
| +namespace internal {
|
| +
|
| +
|
| +class BoundsCheckBbData;
|
| +class BoundsCheckKey;
|
| +class BoundsCheckTable : private ZoneHashMap {
|
| + public:
|
| + explicit BoundsCheckTable(Zone* zone);
|
| +
|
| + INLINE(BoundsCheckBbData** LookupOrInsert(BoundsCheckKey* key, Zone* zone));
|
| + INLINE(void Insert(BoundsCheckKey* key, BoundsCheckBbData* data, Zone* zone));
|
| + INLINE(void Delete(BoundsCheckKey* key));
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(BoundsCheckTable);
|
| +};
|
| +
|
| +
|
| +class HBoundsCheckEliminationPhase : public HPhase {
|
| + public:
|
| + explicit HBoundsCheckEliminationPhase(HGraph* graph)
|
| + : HPhase("H_Bounds checks elimination", graph), table_(zone()) { }
|
| +
|
| + void Run() { EliminateRedundantBoundsChecks(graph()->entry_block()); }
|
| +
|
| + private:
|
| + void EliminateRedundantBoundsChecks(HBasicBlock* bb);
|
| +
|
| + BoundsCheckTable table_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(HBoundsCheckEliminationPhase);
|
| +};
|
| +
|
| +
|
| +class HCanonicalizePhase : public HPhase {
|
| + public:
|
| + explicit HCanonicalizePhase(HGraph* graph)
|
| + : HPhase("H_Canonicalize", graph) { }
|
| +
|
| + void Run();
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(HCanonicalizePhase);
|
| +};
|
| +
|
| +
|
| +class HDeadCodeEliminationPhase : public HPhase {
|
| + public:
|
| + explicit HDeadCodeEliminationPhase(HGraph* graph)
|
| + : HPhase("H_Dead code elimination", graph) { }
|
| +
|
| + void Run() {
|
| + MarkLiveInstructions();
|
| + RemoveDeadInstructions();
|
| + }
|
| +
|
| + private:
|
| + bool MarkLive(HValue* ref, HValue* instr);
|
| + void MarkLiveInstructions();
|
| + void RemoveDeadInstructions();
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(HDeadCodeEliminationPhase);
|
| +};
|
| +
|
| +
|
| +class HDehoistIndexComputationsPhase : public HPhase {
|
| + public:
|
| + explicit HDehoistIndexComputationsPhase(HGraph* graph)
|
| + : HPhase("H_Dehoist index computations", graph) { }
|
| +
|
| + void Run();
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(HDehoistIndexComputationsPhase);
|
| +};
|
| +
|
| +
|
| +// Mark all blocks that are dominated by an unconditional soft deoptimize to
|
| +// prevent code motion across those blocks.
|
| +class HPropagateDeoptimizingMarkPhase : public HPhase {
|
| + public:
|
| + explicit HPropagateDeoptimizingMarkPhase(HGraph* graph)
|
| + : HPhase("H_Propagate deoptimizing mark", graph) { }
|
| +
|
| + void Run();
|
| +
|
| + private:
|
| + void MarkAsDeoptimizing();
|
| + void NullifyUnreachableInstructions();
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(HPropagateDeoptimizingMarkPhase);
|
| +};
|
| +
|
| +
|
| +// Trims live ranges of environment slots by doing explicit liveness analysis.
|
| +// Values in the environment are kept alive by every subsequent LInstruction
|
| +// that is assigned an LEnvironment, which creates register pressure and
|
| +// unnecessary spill slot moves. Therefore it is beneficial to trim the
|
| +// live ranges of environment slots by zapping them with a constant after
|
| +// the last lookup that refers to them.
|
| +// Slots are identified by their index and only affected if whitelisted in
|
| +// HOptimizedGraphBuilder::IsEligibleForEnvironmentLivenessAnalysis().
|
| +class HEnvironmentLivenessAnalysisPhase : public HPhase {
|
| + public:
|
| + explicit HEnvironmentLivenessAnalysisPhase(HGraph* graph);
|
| +
|
| + void Run();
|
| +
|
| + private:
|
| + void ZapEnvironmentSlot(int index, HSimulate* simulate);
|
| + void ZapEnvironmentSlotsInSuccessors(HBasicBlock* block, BitVector* live);
|
| + void ZapEnvironmentSlotsForInstruction(HEnvironmentMarker* marker);
|
| + void UpdateLivenessAtBlockEnd(HBasicBlock* block, BitVector* live);
|
| + void UpdateLivenessAtInstruction(HInstruction* instr, BitVector* live);
|
| +
|
| + int block_count_;
|
| +
|
| + // Largest number of local variables in any environment in the graph
|
| + // (including inlined environments).
|
| + int maximum_environment_size_;
|
| +
|
| + // Per-block data. All these lists are indexed by block_id.
|
| + ZoneList<BitVector*> live_at_block_start_;
|
| + ZoneList<HSimulate*> first_simulate_;
|
| + ZoneList<BitVector*> first_simulate_invalid_for_index_;
|
| +
|
| + // List of all HEnvironmentMarker instructions for quick iteration/deletion.
|
| + // It is populated during the first pass over the graph, controlled by
|
| + // |collect_markers_|.
|
| + ZoneList<HEnvironmentMarker*> markers_;
|
| + bool collect_markers_;
|
| +
|
| + // Keeps track of the last simulate seen, as well as the environment slots
|
| + // for which a new live range has started since (so they must not be zapped
|
| + // in that simulate when the end of another live range of theirs is found).
|
| + HSimulate* last_simulate_;
|
| + BitVector went_live_since_last_simulate_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(HEnvironmentLivenessAnalysisPhase);
|
| +};
|
| +
|
| +
|
| +class HEscapeAnalysisPhase : public HPhase {
|
| + public:
|
| + explicit HEscapeAnalysisPhase(HGraph* graph)
|
| + : HPhase("H_Escape analysis", graph), captured_(0, zone()) { }
|
| +
|
| + void Run() { CollectCapturedValues(); }
|
| +
|
| + private:
|
| + void CollectCapturedValues();
|
| + void CollectIfNoEscapingUses(HInstruction* instr);
|
| +
|
| + ZoneList<HValue*> captured_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(HEscapeAnalysisPhase);
|
| +};
|
| +
|
| +
|
| +class HInferRepresentationPhase : public HPhase {
|
| + public:
|
| + explicit HInferRepresentationPhase(HGraph* graph)
|
| + : HPhase("H_Infer representations", graph),
|
| + worklist_(8, zone()),
|
| + in_worklist_(graph->GetMaximumValueID(), zone()) { }
|
| +
|
| + void Run();
|
| + void AddToWorklist(HValue* current);
|
| +
|
| + private:
|
| + ZoneList<HValue*> worklist_;
|
| + BitVector in_worklist_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(HInferRepresentationPhase);
|
| +};
|
| +
|
| +
|
| +class HInferTypesPhase : public HPhase {
|
| + public:
|
| + explicit HInferTypesPhase(HGraph* graph)
|
| + : HPhase("H_Inferring types", graph), worklist_(8, zone()),
|
| + in_worklist_(graph->GetMaximumValueID(), zone()) { }
|
| +
|
| + void Run() { InferTypes(0, graph()->blocks()->length() - 1); }
|
| +
|
| + private:
|
| + void InferTypes(int from_inclusive, int to_inclusive);
|
| +
|
| + ZoneList<HValue*> worklist_;
|
| + BitVector in_worklist_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(HInferTypesPhase);
|
| +};
|
| +
|
| +
|
| +// Perform common subexpression elimination and loop-invariant code motion.
|
| +class HGlobalValueNumberingPhase : public HPhase {
|
| + public:
|
| + explicit HGlobalValueNumberingPhase(HGraph* graph);
|
| +
|
| + void Run() {
|
| + Analyze();
|
| + // Trigger a second analysis pass to further eliminate duplicate values
|
| + // that could only be discovered by removing side-effect-generating
|
| + // instructions during the first pass.
|
| + if (FLAG_smi_only_arrays && removed_side_effects_) {
|
| + Analyze();
|
| + ASSERT(!removed_side_effects_);
|
| + }
|
| + }
|
| +
|
| + private:
|
| + void Analyze();
|
| + GVNFlagSet CollectSideEffectsOnPathsToDominatedBlock(
|
| + HBasicBlock* dominator,
|
| + HBasicBlock* dominated);
|
| + void AnalyzeGraph();
|
| + void ComputeBlockSideEffects();
|
| + void LoopInvariantCodeMotion();
|
| + void ProcessLoopBlock(HBasicBlock* block,
|
| + HBasicBlock* before_loop,
|
| + GVNFlagSet loop_kills,
|
| + GVNFlagSet* accumulated_first_time_depends,
|
| + GVNFlagSet* accumulated_first_time_changes);
|
| + bool AllowCodeMotion();
|
| + bool ShouldMove(HInstruction* instr, HBasicBlock* loop_header);
|
| +
|
| + bool removed_side_effects_;
|
| +
|
| + // A map of block IDs to their side effects.
|
| + ZoneList<GVNFlagSet> block_side_effects_;
|
| +
|
| + // A map of loop header block IDs to their loop's side effects.
|
| + ZoneList<GVNFlagSet> loop_side_effects_;
|
| +
|
| + // Used when collecting side effects on paths from dominator to
|
| + // dominated.
|
| + BitVector visited_on_paths_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(HGlobalValueNumberingPhase);
|
| +};
|
| +
|
| +
|
| +class HComputeMinusZeroChecksPhase : public HPhase {
|
| + public:
|
| + explicit HComputeMinusZeroChecksPhase(HGraph* graph)
|
| + : HPhase("H_Compute minus zero checks", graph),
|
| + visited_(graph->GetMaximumValueID(), zone()) { }
|
| +
|
| + void Run();
|
| +
|
| + private:
|
| + void PropagateMinusZeroChecks(HValue* value);
|
| +
|
| + BitVector visited_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(HComputeMinusZeroChecksPhase);
|
| +};
|
| +
|
| +
|
| +class HRangeAnalysisPhase : public HPhase {
|
| + public:
|
| + explicit HRangeAnalysisPhase(HGraph* graph)
|
| + : HPhase("H_Range analysis", graph), changed_ranges_(16, zone()) { }
|
| +
|
| + void Run();
|
| +
|
| + private:
|
| + void TraceRange(const char* msg, ...);
|
| + void InferControlFlowRange(HCompareNumericAndBranch* test,
|
| + HBasicBlock* dest);
|
| + void UpdateControlFlowRange(Token::Value op, HValue* value, HValue* other);
|
| + void InferRange(HValue* value);
|
| + void RollBackTo(int index);
|
| + void AddRange(HValue* value, Range* range);
|
| +
|
| + ZoneList<HValue*> changed_ranges_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(HRangeAnalysisPhase);
|
| +};
|
| +
|
| +
|
| +// Replace all phis consisting of a single non-loop operand plus any number of
|
| +// loop operands by that single non-loop operand.
|
| +class HRedundantPhiEliminationPhase : public HPhase {
|
| + public:
|
| + explicit HRedundantPhiEliminationPhase(HGraph* graph)
|
| + : HPhase("H_Redundant phi elimination", graph) { }
|
| +
|
| + void Run();
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(HRedundantPhiEliminationPhase);
|
| +};
|
| +
|
| +
|
| +class HMergeRemovableSimulatesPhase : public HPhase {
|
| + public:
|
| + explicit HMergeRemovableSimulatesPhase(HGraph* graph)
|
| + : HPhase("H_Merge removable simulates", graph) { }
|
| +
|
| + void Run();
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(HMergeRemovableSimulatesPhase);
|
| +};
|
| +
|
| +
|
| +class HRepresentationChangesPhase : public HPhase {
|
| + public:
|
| + explicit HRepresentationChangesPhase(HGraph* graph)
|
| + : HPhase("H_Representation changes", graph) { }
|
| +
|
| + void Run();
|
| +
|
| + private:
|
| + void InsertRepresentationChangeForUse(HValue* value,
|
| + HValue* use_value,
|
| + int use_index,
|
| + Representation to);
|
| + void InsertRepresentationChangesForValue(HValue* value);
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(HRepresentationChangesPhase);
|
| +};
|
| +
|
| +
|
| +class HStackCheckEliminationPhase : public HPhase {
|
| + public:
|
| + explicit HStackCheckEliminationPhase(HGraph* graph)
|
| + : HPhase("H_Stack check elimination", graph) { }
|
| +
|
| + void Run();
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(HStackCheckEliminationPhase);
|
| +};
|
| +
|
| +
|
| +// Discover instructions that can be marked with kUint32 flag allowing
|
| +// them to produce full range uint32 values.
|
| +class HUint32AnalysisPhase : public HPhase {
|
| + public:
|
| + explicit HUint32AnalysisPhase(HGraph* graph)
|
| + : HPhase("H_Compute safe UInt32 operations", graph), phis_(4, zone()) { }
|
| +
|
| + void Run();
|
| +
|
| + private:
|
| + INLINE(bool IsSafeUint32Use(HValue* val, HValue* use));
|
| + INLINE(bool Uint32UsesAreSafe(HValue* uint32val));
|
| + INLINE(bool CheckPhiOperands(HPhi* phi));
|
| + INLINE(void UnmarkPhi(HPhi* phi, ZoneList<HPhi*>* worklist));
|
| + INLINE(void UnmarkUnsafePhis());
|
| +
|
| + ZoneList<HPhi*> phis_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(HUint32AnalysisPhase);
|
| +};
|
| +
|
| +
|
| +} } // namespace v8::internal
|
| +
|
| +#endif // V8_HYDROGEN_PHASES_H_
|
|
|