V8 Project
v8::internal::HRepresentationChangesPhase Class Reference

#include <hydrogen-representation-changes.h>

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

Public Member Functions

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

Private Member Functions

void InsertRepresentationChangeForUse (HValue *value, HValue *use_value, int use_index, Representation to)
 
void InsertRepresentationChangesForValue (HValue *value)
 

Additional Inherited Members

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

Detailed Description

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

Constructor & Destructor Documentation

◆ HRepresentationChangesPhase()

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

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

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

Member Function Documentation

◆ InsertRepresentationChangeForUse()

void v8::internal::HRepresentationChangesPhase::InsertRepresentationChangeForUse ( HValue value,
HValue use_value,
int  use_index,
Representation  to 
)
private

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

11  {
12  // Insert the representation change right before its use. For phi-uses we
13  // insert at the end of the corresponding predecessor.
14  HInstruction* next = NULL;
15  if (use_value->IsPhi()) {
16  next = use_value->block()->predecessors()->at(use_index)->end();
17  } else {
18  next = HInstruction::cast(use_value);
19  }
20  // For constants we try to make the representation change at compile
21  // time. When a representation change is not possible without loss of
22  // information we treat constants like normal instructions and insert the
23  // change instructions for them.
24  HInstruction* new_value = NULL;
25  bool is_truncating_to_smi = use_value->CheckFlag(HValue::kTruncatingToSmi);
26  bool is_truncating_to_int = use_value->CheckFlag(HValue::kTruncatingToInt32);
27  if (value->IsConstant()) {
28  HConstant* constant = HConstant::cast(value);
29  // Try to create a new copy of the constant with the new representation.
30  if (is_truncating_to_int && to.IsInteger32()) {
31  Maybe<HConstant*> res = constant->CopyToTruncatedInt32(graph()->zone());
32  if (res.has_value) new_value = res.value;
33  } else {
34  new_value = constant->CopyToRepresentation(to, graph()->zone());
35  }
36  }
37 
38  if (new_value == NULL) {
39  new_value = new(graph()->zone()) HChange(
40  value, to, is_truncating_to_smi, is_truncating_to_int);
41  if (!use_value->operand_position(use_index).IsUnknown()) {
42  new_value->set_position(use_value->operand_position(use_index));
43  } else {
44  DCHECK(!FLAG_hydrogen_track_positions ||
45  !graph()->info()->IsOptimizing());
46  }
47  }
48 
49  new_value->InsertBefore(next);
50  use_value->SetOperandAt(use_index, new_value);
51 }
static HValue * cast(HValue *value)
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 maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes to(mksnapshot only)") DEFINE_STRING(raw_context_file
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
#define DCHECK(condition)
Definition: logging.h:205

References v8::internal::HValue::block(), v8::internal::HValue::cast(), v8::internal::HValue::CheckFlag(), DCHECK, v8::internal::HPhase::graph(), v8::Maybe< T >::has_value, v8::internal::HInstruction::InsertBefore(), v8::internal::HValue::IsPhi(), v8::internal::HSourcePosition::IsUnknown(), v8::internal::HValue::kTruncatingToInt32, v8::internal::HValue::kTruncatingToSmi, NULL, v8::internal::HValue::operand_position(), v8::internal::HInstruction::set_position(), v8::internal::HValue::SetOperandAt(), to(), and v8::Maybe< T >::value.

Referenced by InsertRepresentationChangesForValue().

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

◆ InsertRepresentationChangesForValue()

void v8::internal::HRepresentationChangesPhase::InsertRepresentationChangesForValue ( HValue value)
private

Definition at line 63 of file hydrogen-representation-changes.cc.

64  {
65  Representation r = value->representation();
66  if (r.IsNone()) return;
67  if (value->HasNoUses()) {
68  if (value->IsForceRepresentation()) value->DeleteAndReplaceWith(NULL);
69  return;
70  }
71 
72  for (HUseIterator it(value->uses()); !it.Done(); it.Advance()) {
73  HValue* use_value = it.value();
74  int use_index = it.index();
75  Representation req = use_value->RequiredInputRepresentation(use_index);
76  if (req.IsNone() || req.Equals(r)) continue;
77 
78  // If this is an HForceRepresentation instruction, and an HChange has been
79  // inserted above it, examine the input representation of the HChange. If
80  // that's int32, and this HForceRepresentation use is int32, and int32 to
81  // smi changes can't cause deoptimisation, set the input of the use to the
82  // input of the HChange.
83  if (value->IsForceRepresentation()) {
84  HValue* input = HForceRepresentation::cast(value)->value();
85  if (input->IsChange()) {
86  HChange* change = HChange::cast(input);
87  if (change->from().Equals(req) && IsNonDeoptingIntToSmiChange(change)) {
88  use_value->SetOperandAt(use_index, change->value());
89  continue;
90  }
91  }
92  }
93  InsertRepresentationChangeForUse(value, use_value, use_index, req);
94  }
95  if (value->HasNoUses()) {
96  DCHECK(value->IsConstant() || value->IsForceRepresentation());
97  value->DeleteAndReplaceWith(NULL);
98  } else {
99  // The only purpose of a HForceRepresentation is to represent the value
100  // after the (possible) HChange instruction. We make it disappear.
101  if (value->IsForceRepresentation()) {
102  value->DeleteAndReplaceWith(HForceRepresentation::cast(value)->value());
103  }
104  }
105 }
void InsertRepresentationChangeForUse(HValue *value, HValue *use_value, int use_index, Representation to)
static bool IsNonDeoptingIntToSmiChange(HChange *change)

References DCHECK, v8::internal::HValue::DeleteAndReplaceWith(), v8::internal::Representation::Equals(), v8::internal::HValue::HasNoUses(), InsertRepresentationChangeForUse(), v8::internal::IsNonDeoptingIntToSmiChange(), v8::internal::Representation::IsNone(), NULL, v8::internal::HValue::representation(), v8::internal::HValue::RequiredInputRepresentation(), v8::internal::HValue::SetOperandAt(), and v8::internal::HValue::uses().

Referenced by Run().

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

◆ Run()

void v8::internal::HRepresentationChangesPhase::Run ( )

Definition at line 108 of file hydrogen-representation-changes.cc.

108  {
109  // Compute truncation flag for phis: Initially assume that all
110  // int32-phis allow truncation and iteratively remove the ones that
111  // are used in an operation that does not allow a truncating
112  // conversion.
113  ZoneList<HPhi*> int_worklist(8, zone());
114  ZoneList<HPhi*> smi_worklist(8, zone());
115 
116  const ZoneList<HPhi*>* phi_list(graph()->phi_list());
117  for (int i = 0; i < phi_list->length(); i++) {
118  HPhi* phi = phi_list->at(i);
119  if (phi->representation().IsInteger32()) {
120  phi->SetFlag(HValue::kTruncatingToInt32);
121  } else if (phi->representation().IsSmi()) {
122  phi->SetFlag(HValue::kTruncatingToSmi);
123  phi->SetFlag(HValue::kTruncatingToInt32);
124  }
125  }
126 
127  for (int i = 0; i < phi_list->length(); i++) {
128  HPhi* phi = phi_list->at(i);
129  HValue* value = NULL;
130  if (phi->representation().IsSmiOrInteger32() &&
131  !phi->CheckUsesForFlag(HValue::kTruncatingToInt32, &value)) {
132  int_worklist.Add(phi, zone());
133  phi->ClearFlag(HValue::kTruncatingToInt32);
134  if (FLAG_trace_representation) {
135  PrintF("#%d Phi is not truncating Int32 because of #%d %s\n",
136  phi->id(), value->id(), value->Mnemonic());
137  }
138  }
139 
140  if (phi->representation().IsSmi() &&
141  !phi->CheckUsesForFlag(HValue::kTruncatingToSmi, &value)) {
142  smi_worklist.Add(phi, zone());
143  phi->ClearFlag(HValue::kTruncatingToSmi);
144  if (FLAG_trace_representation) {
145  PrintF("#%d Phi is not truncating Smi because of #%d %s\n",
146  phi->id(), value->id(), value->Mnemonic());
147  }
148  }
149  }
150 
151  while (!int_worklist.is_empty()) {
152  HPhi* current = int_worklist.RemoveLast();
153  for (int i = 0; i < current->OperandCount(); ++i) {
154  HValue* input = current->OperandAt(i);
155  if (input->IsPhi() &&
156  input->representation().IsSmiOrInteger32() &&
157  input->CheckFlag(HValue::kTruncatingToInt32)) {
158  if (FLAG_trace_representation) {
159  PrintF("#%d Phi is not truncating Int32 because of #%d %s\n",
160  input->id(), current->id(), current->Mnemonic());
161  }
162  input->ClearFlag(HValue::kTruncatingToInt32);
163  int_worklist.Add(HPhi::cast(input), zone());
164  }
165  }
166  }
167 
168  while (!smi_worklist.is_empty()) {
169  HPhi* current = smi_worklist.RemoveLast();
170  for (int i = 0; i < current->OperandCount(); ++i) {
171  HValue* input = current->OperandAt(i);
172  if (input->IsPhi() &&
173  input->representation().IsSmi() &&
174  input->CheckFlag(HValue::kTruncatingToSmi)) {
175  if (FLAG_trace_representation) {
176  PrintF("#%d Phi is not truncating Smi because of #%d %s\n",
177  input->id(), current->id(), current->Mnemonic());
178  }
179  input->ClearFlag(HValue::kTruncatingToSmi);
180  smi_worklist.Add(HPhi::cast(input), zone());
181  }
182  }
183  }
184 
185  const ZoneList<HBasicBlock*>* blocks(graph()->blocks());
186  for (int i = 0; i < blocks->length(); ++i) {
187  // Process phi instructions first.
188  const HBasicBlock* block(blocks->at(i));
189  const ZoneList<HPhi*>* phis = block->phis();
190  for (int j = 0; j < phis->length(); j++) {
192  }
193 
194  // Process normal instructions.
195  for (HInstruction* current = block->first(); current != NULL; ) {
196  HInstruction* next = current->next();
198  current = next;
199  }
200  }
201 }
void PrintF(const char *format,...)
Definition: utils.cc:80

References v8::internal::List< T, AllocationPolicy >::Add(), v8::internal::List< T, AllocationPolicy >::at(), v8::internal::HValue::CheckFlag(), v8::internal::HValue::ClearFlag(), v8::internal::HPhase::graph(), v8::internal::HValue::id(), InsertRepresentationChangesForValue(), v8::internal::HValue::IsPhi(), v8::internal::Representation::IsSmi(), v8::internal::Representation::IsSmiOrInteger32(), v8::internal::HValue::kTruncatingToInt32, v8::internal::HValue::kTruncatingToSmi, v8::internal::HValue::Mnemonic(), v8::internal::HInstruction::next(), NULL, v8::internal::HValue::OperandAt(), v8::internal::PrintF(), and v8::internal::HValue::representation().

+ Here is the call graph for this function:

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