V8 Project
v8::internal::HDeadCodeEliminationPhase Class Reference

#include <hydrogen-dce.h>

+ Inheritance diagram for v8::internal::HDeadCodeEliminationPhase:
+ Collaboration diagram for v8::internal::HDeadCodeEliminationPhase:

Public Member Functions

 HDeadCodeEliminationPhase (HGraph *graph)
 
void Run ()
 
- Public Member Functions inherited from v8::internal::HPhase
 HPhase (const char *name, HGraph *graph)
 
 ~HPhase ()
 

Private Member Functions

void MarkLive (HValue *instr, ZoneList< HValue * > *worklist)
 
void PrintLive (HValue *ref, HValue *instr)
 
void MarkLiveInstructions ()
 
void RemoveDeadInstructions ()
 

Additional Inherited Members

- Protected Member Functions inherited from v8::internal::HPhase
HGraph * graph () const
 

Detailed Description

Definition at line 14 of file hydrogen-dce.h.

Constructor & Destructor Documentation

◆ HDeadCodeEliminationPhase()

v8::internal::HDeadCodeEliminationPhase::HDeadCodeEliminationPhase ( HGraph *  graph)
inlineexplicit

Definition at line 16 of file hydrogen-dce.h.

17  : HPhase("H_Dead code elimination", graph) { }
HGraph * graph() const
Definition: hydrogen.h:2802
HPhase(const char *name, HGraph *graph)
Definition: hydrogen.h:2796

Member Function Documentation

◆ MarkLive()

void v8::internal::HDeadCodeEliminationPhase::MarkLive ( HValue instr,
ZoneList< HValue * > *  worklist 
)
private

Definition at line 11 of file hydrogen-dce.cc.

12  {
13  if (instr->CheckFlag(HValue::kIsLive)) return; // Already live.
14 
15  if (FLAG_trace_dead_code_elimination) PrintLive(NULL, instr);
16 
17  // Transitively mark all inputs of live instructions live.
18  worklist->Add(instr, zone());
19  while (!worklist->is_empty()) {
20  HValue* instr = worklist->RemoveLast();
21  instr->SetFlag(HValue::kIsLive);
22  for (int i = 0; i < instr->OperandCount(); ++i) {
23  HValue* input = instr->OperandAt(i);
24  if (!input->CheckFlag(HValue::kIsLive)) {
25  input->SetFlag(HValue::kIsLive);
26  worklist->Add(input, zone());
27  if (FLAG_trace_dead_code_elimination) PrintLive(instr, input);
28  }
29  }
30  }
31 }
void PrintLive(HValue *ref, HValue *instr)
Definition: hydrogen-dce.cc:34
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL

References v8::internal::List< T, AllocationPolicy >::Add(), v8::internal::HValue::CheckFlag(), v8::internal::HValue::kIsLive, NULL, v8::internal::HValue::OperandAt(), v8::internal::HValue::OperandCount(), PrintLive(), and v8::internal::HValue::SetFlag().

Referenced by MarkLiveInstructions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MarkLiveInstructions()

void v8::internal::HDeadCodeEliminationPhase::MarkLiveInstructions ( )
private

Definition at line 46 of file hydrogen-dce.cc.

46  {
47  ZoneList<HValue*> worklist(10, zone());
48 
49  // Transitively mark all live instructions, starting from roots.
50  for (int i = 0; i < graph()->blocks()->length(); ++i) {
51  HBasicBlock* block = graph()->blocks()->at(i);
52  for (HInstructionIterator it(block); !it.Done(); it.Advance()) {
53  HInstruction* instr = it.Current();
54  if (instr->CannotBeEliminated()) MarkLive(instr, &worklist);
55  }
56  for (int j = 0; j < block->phis()->length(); j++) {
57  HPhi* phi = block->phis()->at(j);
58  if (phi->CannotBeEliminated()) MarkLive(phi, &worklist);
59  }
60  }
61 
62  DCHECK(worklist.is_empty()); // Should have processed everything.
63 }
void MarkLive(HValue *instr, ZoneList< HValue * > *worklist)
Definition: hydrogen-dce.cc:11
#define DCHECK(condition)
Definition: logging.h:205

References v8::internal::HValue::CannotBeEliminated(), DCHECK, v8::internal::HPhase::graph(), and MarkLive().

Referenced by Run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PrintLive()

void v8::internal::HDeadCodeEliminationPhase::PrintLive ( HValue ref,
HValue instr 
)
private

Definition at line 34 of file hydrogen-dce.cc.

34  {
35  OFStream os(stdout);
36  os << "[MarkLive ";
37  if (ref != NULL) {
38  os << *ref;
39  } else {
40  os << "root ";
41  }
42  os << " -> " << *instr << "]" << endl;
43 }
OStream & endl(OStream &os)
Definition: ostreams.cc:112

References v8::internal::endl(), and NULL.

Referenced by MarkLive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RemoveDeadInstructions()

void v8::internal::HDeadCodeEliminationPhase::RemoveDeadInstructions ( )
private

Definition at line 66 of file hydrogen-dce.cc.

66  {
67  ZoneList<HPhi*> worklist(graph()->blocks()->length(), zone());
68 
69  // Remove any instruction not marked kIsLive.
70  for (int i = 0; i < graph()->blocks()->length(); ++i) {
71  HBasicBlock* block = graph()->blocks()->at(i);
72  for (HInstructionIterator it(block); !it.Done(); it.Advance()) {
73  HInstruction* instr = it.Current();
74  if (!instr->CheckFlag(HValue::kIsLive)) {
75  // Instruction has not been marked live, so remove it.
76  instr->DeleteAndReplaceWith(NULL);
77  } else {
78  // Clear the liveness flag to leave the graph clean for the next DCE.
79  instr->ClearFlag(HValue::kIsLive);
80  }
81  }
82  // Collect phis that are dead and remove them in the next pass.
83  for (int j = 0; j < block->phis()->length(); j++) {
84  HPhi* phi = block->phis()->at(j);
85  if (!phi->CheckFlag(HValue::kIsLive)) {
86  worklist.Add(phi, zone());
87  } else {
88  phi->ClearFlag(HValue::kIsLive);
89  }
90  }
91  }
92 
93  // Process phis separately to avoid simultaneously mutating the phi list.
94  while (!worklist.is_empty()) {
95  HPhi* phi = worklist.RemoveLast();
96  HBasicBlock* block = phi->block();
97  phi->DeleteAndReplaceWith(NULL);
98  if (phi->HasMergedIndex()) {
99  block->RecordDeletedPhi(phi->merged_index());
100  }
101  }
102 }

References v8::internal::List< T, AllocationPolicy >::Add(), v8::internal::HValue::CheckFlag(), v8::internal::HValue::ClearFlag(), v8::internal::HValue::DeleteAndReplaceWith(), v8::internal::HPhase::graph(), v8::internal::HValue::kIsLive, and NULL.

Referenced by Run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Run()

void v8::internal::HDeadCodeEliminationPhase::Run ( )
inline

Definition at line 19 of file hydrogen-dce.h.

References MarkLiveInstructions(), and RemoveDeadInstructions().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: