V8 Project
v8::internal::HInferRepresentationPhase Class Reference

#include <hydrogen-infer-representation.h>

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

Public Member Functions

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

Private Member Functions

 DISALLOW_COPY_AND_ASSIGN (HInferRepresentationPhase)
 

Private Attributes

ZoneList< HValue * > worklist_
 
BitVector in_worklist_
 

Additional Inherited Members

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

Detailed Description

Definition at line 14 of file hydrogen-infer-representation.h.

Constructor & Destructor Documentation

◆ HInferRepresentationPhase()

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

Definition at line 16 of file hydrogen-infer-representation.h.

17  : HPhase("H_Infer representations", graph),
18  worklist_(8, zone()),
19  in_worklist_(graph->GetMaximumValueID(), zone()) { }
HGraph * graph() const
Definition: hydrogen.h:2802
HPhase(const char *name, HGraph *graph)
Definition: hydrogen.h:2796

Member Function Documentation

◆ AddToWorklist()

void v8::internal::HInferRepresentationPhase::AddToWorklist ( HValue current)

Definition at line 10 of file hydrogen-infer-representation.cc.

10  {
11  if (current->representation().IsTagged()) return;
12  if (!current->CheckFlag(HValue::kFlexibleRepresentation)) return;
13  if (in_worklist_.Contains(current->id())) return;
14  worklist_.Add(current, zone());
15  in_worklist_.Add(current->id());
16 }
bool Contains(int i) const
Definition: data-flow.h:99

References v8::internal::BitVector::Add(), v8::internal::HValue::CheckFlag(), v8::internal::BitVector::Contains(), v8::internal::HValue::id(), in_worklist_, v8::internal::Representation::IsTagged(), v8::internal::HValue::kFlexibleRepresentation, v8::internal::HValue::representation(), and worklist_.

Referenced by v8::internal::HValue::AddDependantsToWorklist(), and Run().

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

◆ DISALLOW_COPY_AND_ASSIGN()

v8::internal::HInferRepresentationPhase::DISALLOW_COPY_AND_ASSIGN ( HInferRepresentationPhase  )
private

◆ Run()

void v8::internal::HInferRepresentationPhase::Run ( )

Definition at line 19 of file hydrogen-infer-representation.cc.

19  {
20  // (1) Initialize bit vectors and count real uses. Each phi gets a
21  // bit-vector of length <number of phis>.
22  const ZoneList<HPhi*>* phi_list = graph()->phi_list();
23  int phi_count = phi_list->length();
24  ZoneList<BitVector*> connected_phis(phi_count, zone());
25  for (int i = 0; i < phi_count; ++i) {
26  phi_list->at(i)->InitRealUses(i);
27  BitVector* connected_set = new(zone()) BitVector(phi_count, zone());
28  connected_set->Add(i);
29  connected_phis.Add(connected_set, zone());
30  }
31 
32  // (2) Do a fixed point iteration to find the set of connected phis. A
33  // phi is connected to another phi if its value is used either directly or
34  // indirectly through a transitive closure of the def-use relation.
35  bool change = true;
36  while (change) {
37  change = false;
38  // We normally have far more "forward edges" than "backward edges",
39  // so we terminate faster when we walk backwards.
40  for (int i = phi_count - 1; i >= 0; --i) {
41  HPhi* phi = phi_list->at(i);
42  for (HUseIterator it(phi->uses()); !it.Done(); it.Advance()) {
43  HValue* use = it.value();
44  if (use->IsPhi()) {
45  int id = HPhi::cast(use)->phi_id();
46  if (connected_phis[i]->UnionIsChanged(*connected_phis[id]))
47  change = true;
48  }
49  }
50  }
51  }
52 
53  // Set truncation flags for groups of connected phis. This is a conservative
54  // approximation; the flag will be properly re-computed after representations
55  // have been determined.
56  if (phi_count > 0) {
57  BitVector done(phi_count, zone());
58  for (int i = 0; i < phi_count; ++i) {
59  if (done.Contains(i)) continue;
60 
61  // Check if all uses of all connected phis in this group are truncating.
62  bool all_uses_everywhere_truncating_int32 = true;
63  bool all_uses_everywhere_truncating_smi = true;
64  for (BitVector::Iterator it(connected_phis[i]);
65  !it.Done();
66  it.Advance()) {
67  int index = it.Current();
68  all_uses_everywhere_truncating_int32 &=
69  phi_list->at(index)->CheckFlag(HInstruction::kTruncatingToInt32);
70  all_uses_everywhere_truncating_smi &=
71  phi_list->at(index)->CheckFlag(HInstruction::kTruncatingToSmi);
72  done.Add(index);
73  }
74 
75  if (!all_uses_everywhere_truncating_int32) {
76  // Clear truncation flag of this group of connected phis.
77  for (BitVector::Iterator it(connected_phis[i]);
78  !it.Done();
79  it.Advance()) {
80  int index = it.Current();
81  phi_list->at(index)->ClearFlag(HInstruction::kTruncatingToInt32);
82  }
83  }
84  if (!all_uses_everywhere_truncating_smi) {
85  // Clear truncation flag of this group of connected phis.
86  for (BitVector::Iterator it(connected_phis[i]);
87  !it.Done();
88  it.Advance()) {
89  int index = it.Current();
90  phi_list->at(index)->ClearFlag(HInstruction::kTruncatingToSmi);
91  }
92  }
93  }
94  }
95 
96  // Simplify constant phi inputs where possible.
97  // This step uses kTruncatingToInt32 flags of phis.
98  for (int i = 0; i < phi_count; ++i) {
99  phi_list->at(i)->SimplifyConstantInputs();
100  }
101 
102  // Use the phi reachability information from step 2 to
103  // sum up the non-phi use counts of all connected phis.
104  for (int i = 0; i < phi_count; ++i) {
105  HPhi* phi = phi_list->at(i);
106  for (BitVector::Iterator it(connected_phis[i]);
107  !it.Done();
108  it.Advance()) {
109  int index = it.Current();
110  HPhi* it_use = phi_list->at(index);
111  if (index != i) phi->AddNonPhiUsesFrom(it_use); // Don't count twice.
112  }
113  }
114 
115  // Initialize work list
116  for (int i = 0; i < graph()->blocks()->length(); ++i) {
117  HBasicBlock* block = graph()->blocks()->at(i);
118  const ZoneList<HPhi*>* phis = block->phis();
119  for (int j = 0; j < phis->length(); ++j) {
120  AddToWorklist(phis->at(j));
121  }
122 
123  for (HInstructionIterator it(block); !it.Done(); it.Advance()) {
124  HInstruction* current = it.Current();
125  AddToWorklist(current);
126  }
127  }
128 
129  // Do a fixed point iteration, trying to improve representations
130  while (!worklist_.is_empty()) {
131  HValue* current = worklist_.RemoveLast();
132  current->InferRepresentation(this);
133  in_worklist_.Remove(current->id());
134  }
135 
136  // Lastly: any instruction that we don't have representation information
137  // for defaults to Tagged.
138  for (int i = 0; i < graph()->blocks()->length(); ++i) {
139  HBasicBlock* block = graph()->blocks()->at(i);
140  const ZoneList<HPhi*>* phis = block->phis();
141  for (int j = 0; j < phis->length(); ++j) {
142  HPhi* phi = phis->at(j);
143  if (phi->representation().IsNone()) {
144  phi->ChangeRepresentation(Representation::Tagged());
145  }
146  }
147  for (HInstructionIterator it(block); !it.Done(); it.Advance()) {
148  HInstruction* current = it.Current();
149  if (current->representation().IsNone() &&
150  current->CheckFlag(HInstruction::kFlexibleRepresentation)) {
151  if (current->CheckFlag(HInstruction::kCannotBeTagged)) {
152  current->ChangeRepresentation(Representation::Double());
153  } else {
154  current->ChangeRepresentation(Representation::Tagged());
155  }
156  }
157  }
158  }
159 }
static Representation Double()
static Representation Tagged()
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 expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to use(in kBytes)") DEFINE_INT(max_stack_trace_source_length

References v8::internal::List< T, AllocationPolicy >::Add(), v8::internal::BitVector::Add(), AddToWorklist(), v8::internal::List< T, AllocationPolicy >::at(), v8::internal::HValue::ChangeRepresentation(), v8::internal::HValue::CheckFlag(), v8::internal::BitVector::Contains(), v8::internal::Representation::Double(), v8::internal::HPhase::graph(), v8::internal::HValue::id(), in_worklist_, v8::internal::HValue::InferRepresentation(), v8::internal::Representation::IsNone(), v8::internal::HValue::kCannotBeTagged, v8::internal::HValue::kFlexibleRepresentation, v8::internal::HValue::kTruncatingToInt32, v8::internal::HValue::kTruncatingToSmi, v8::internal::BitVector::Remove(), v8::internal::HValue::representation(), v8::internal::Representation::Tagged(), use(), and worklist_.

+ Here is the call graph for this function:

Member Data Documentation

◆ in_worklist_

BitVector v8::internal::HInferRepresentationPhase::in_worklist_
private

Definition at line 26 of file hydrogen-infer-representation.h.

Referenced by AddToWorklist(), and Run().

◆ worklist_

ZoneList<HValue*> v8::internal::HInferRepresentationPhase::worklist_
private

Definition at line 25 of file hydrogen-infer-representation.h.

Referenced by AddToWorklist(), and Run().


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