Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: src/hydrogen-representation-changes.cc

Issue 20070005: Adding Smi support to Add, Sub, Mul, and Bitwise (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed nit Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/hydrogen-minus-zero.cc ('k') | src/ia32/lithium-codegen-ia32.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 27 matching lines...) Expand all
38 if (use_value->IsPhi()) { 38 if (use_value->IsPhi()) {
39 next = use_value->block()->predecessors()->at(use_index)->end(); 39 next = use_value->block()->predecessors()->at(use_index)->end();
40 } else { 40 } else {
41 next = HInstruction::cast(use_value); 41 next = HInstruction::cast(use_value);
42 } 42 }
43 // For constants we try to make the representation change at compile 43 // For constants we try to make the representation change at compile
44 // time. When a representation change is not possible without loss of 44 // time. When a representation change is not possible without loss of
45 // information we treat constants like normal instructions and insert the 45 // information we treat constants like normal instructions and insert the
46 // change instructions for them. 46 // change instructions for them.
47 HInstruction* new_value = NULL; 47 HInstruction* new_value = NULL;
48 bool is_truncating = use_value->CheckFlag(HValue::kTruncatingToInt32); 48 bool is_truncating_to_smi = use_value->CheckFlag(HValue::kTruncatingToSmi);
49 bool is_truncating_to_int = use_value->CheckFlag(HValue::kTruncatingToInt32);
49 bool allow_undefined_as_nan = 50 bool allow_undefined_as_nan =
50 use_value->CheckFlag(HValue::kAllowUndefinedAsNaN); 51 use_value->CheckFlag(HValue::kAllowUndefinedAsNaN);
51 if (value->IsConstant()) { 52 if (value->IsConstant()) {
52 HConstant* constant = HConstant::cast(value); 53 HConstant* constant = HConstant::cast(value);
53 // Try to create a new copy of the constant with the new representation. 54 // Try to create a new copy of the constant with the new representation.
54 if (is_truncating && to.IsInteger32()) { 55 if (is_truncating_to_int && to.IsInteger32()) {
55 Maybe<HConstant*> res = constant->CopyToTruncatedInt32(graph()->zone()); 56 Maybe<HConstant*> res = constant->CopyToTruncatedInt32(graph()->zone());
56 if (res.has_value) new_value = res.value; 57 if (res.has_value) new_value = res.value;
57 } else { 58 } else {
58 new_value = constant->CopyToRepresentation(to, graph()->zone()); 59 new_value = constant->CopyToRepresentation(to, graph()->zone());
59 } 60 }
60 } 61 }
61 62
62 if (new_value == NULL) { 63 if (new_value == NULL) {
63 new_value = new(graph()->zone()) HChange(value, to, 64 new_value = new(graph()->zone()) HChange(value, to,
64 is_truncating, 65 is_truncating_to_smi,
66 is_truncating_to_int,
65 allow_undefined_as_nan); 67 allow_undefined_as_nan);
66 } 68 }
67 69
68 new_value->InsertBefore(next); 70 new_value->InsertBefore(next);
69 use_value->SetOperandAt(use_index, new_value); 71 use_value->SetOperandAt(use_index, new_value);
70 } 72 }
71 73
72 74
73 void HRepresentationChangesPhase::InsertRepresentationChangesForValue( 75 void HRepresentationChangesPhase::InsertRepresentationChangesForValue(
74 HValue* value) { 76 HValue* value) {
(...skipping 26 matching lines...) Expand all
101 // int32-phis allow truncation and iteratively remove the ones that 103 // int32-phis allow truncation and iteratively remove the ones that
102 // are used in an operation that does not allow a truncating 104 // are used in an operation that does not allow a truncating
103 // conversion. 105 // conversion.
104 ZoneList<HPhi*> worklist(8, zone()); 106 ZoneList<HPhi*> worklist(8, zone());
105 107
106 const ZoneList<HPhi*>* phi_list(graph()->phi_list()); 108 const ZoneList<HPhi*>* phi_list(graph()->phi_list());
107 for (int i = 0; i < phi_list->length(); i++) { 109 for (int i = 0; i < phi_list->length(); i++) {
108 HPhi* phi = phi_list->at(i); 110 HPhi* phi = phi_list->at(i);
109 if (phi->representation().IsInteger32()) { 111 if (phi->representation().IsInteger32()) {
110 phi->SetFlag(HValue::kTruncatingToInt32); 112 phi->SetFlag(HValue::kTruncatingToInt32);
113 } else if (phi->representation().IsSmi()) {
114 phi->SetFlag(HValue::kTruncatingToSmi);
111 } 115 }
112 } 116 }
113 117
114 for (int i = 0; i < phi_list->length(); i++) { 118 for (int i = 0; i < phi_list->length(); i++) {
115 HPhi* phi = phi_list->at(i); 119 HPhi* phi = phi_list->at(i);
116 for (HUseIterator it(phi->uses()); !it.Done(); it.Advance()) { 120 for (HUseIterator it(phi->uses()); !it.Done(); it.Advance()) {
117 // If a Phi is used as a non-truncating int32 or as a double, 121 // If a Phi is used as a non-truncating int32 or as a double,
118 // clear its "truncating" flag. 122 // clear its "truncating" flag.
119 HValue* use = it.value(); 123 HValue* use = it.value();
120 Representation input_representation = 124 Representation input_representation =
121 use->RequiredInputRepresentation(it.index()); 125 use->RequiredInputRepresentation(it.index());
122 if (!input_representation.IsInteger32() || 126 if ((phi->representation().IsInteger32() &&
123 !use->CheckFlag(HValue::kTruncatingToInt32)) { 127 !(input_representation.IsInteger32() &&
128 use->CheckFlag(HValue::kTruncatingToInt32))) ||
129 (phi->representation().IsSmi() &&
130 !(input_representation.IsSmi() ||
131 use->CheckFlag(HValue::kTruncatingToSmi)))) {
124 if (FLAG_trace_representation) { 132 if (FLAG_trace_representation) {
125 PrintF("#%d Phi is not truncating because of #%d %s\n", 133 PrintF("#%d Phi is not truncating because of #%d %s\n",
126 phi->id(), it.value()->id(), it.value()->Mnemonic()); 134 phi->id(), it.value()->id(), it.value()->Mnemonic());
127 } 135 }
128 phi->ClearFlag(HValue::kTruncatingToInt32); 136 phi->ClearFlag(HValue::kTruncatingToInt32);
137 phi->ClearFlag(HValue::kTruncatingToSmi);
129 worklist.Add(phi, zone()); 138 worklist.Add(phi, zone());
130 break; 139 break;
131 } 140 }
132 } 141 }
133 } 142 }
134 143
135 while (!worklist.is_empty()) { 144 while (!worklist.is_empty()) {
136 HPhi* current = worklist.RemoveLast(); 145 HPhi* current = worklist.RemoveLast();
137 for (int i = 0; i < current->OperandCount(); ++i) { 146 for (int i = 0; i < current->OperandCount(); ++i) {
138 HValue* input = current->OperandAt(i); 147 HValue* input = current->OperandAt(i);
139 if (input->IsPhi() && 148 if (input->IsPhi() &&
140 input->representation().IsInteger32() && 149 ((input->representation().IsInteger32() &&
141 input->CheckFlag(HValue::kTruncatingToInt32)) { 150 input->CheckFlag(HValue::kTruncatingToInt32)) ||
151 (input->representation().IsSmi() &&
152 input->CheckFlag(HValue::kTruncatingToSmi)))) {
142 if (FLAG_trace_representation) { 153 if (FLAG_trace_representation) {
143 PrintF("#%d Phi is not truncating because of #%d %s\n", 154 PrintF("#%d Phi is not truncating because of #%d %s\n",
144 input->id(), current->id(), current->Mnemonic()); 155 input->id(), current->id(), current->Mnemonic());
145 } 156 }
146 input->ClearFlag(HValue::kTruncatingToInt32); 157 input->ClearFlag(HValue::kTruncatingToInt32);
158 input->ClearFlag(HValue::kTruncatingToSmi);
147 worklist.Add(HPhi::cast(input), zone()); 159 worklist.Add(HPhi::cast(input), zone());
148 } 160 }
149 } 161 }
150 } 162 }
151 163
152 const ZoneList<HBasicBlock*>* blocks(graph()->blocks()); 164 const ZoneList<HBasicBlock*>* blocks(graph()->blocks());
153 for (int i = 0; i < blocks->length(); ++i) { 165 for (int i = 0; i < blocks->length(); ++i) {
154 // Process phi instructions first. 166 // Process phi instructions first.
155 const HBasicBlock* block(blocks->at(i)); 167 const HBasicBlock* block(blocks->at(i));
156 const ZoneList<HPhi*>* phis = block->phis(); 168 const ZoneList<HPhi*>* phis = block->phis();
157 for (int j = 0; j < phis->length(); j++) { 169 for (int j = 0; j < phis->length(); j++) {
158 InsertRepresentationChangesForValue(phis->at(j)); 170 InsertRepresentationChangesForValue(phis->at(j));
159 } 171 }
160 172
161 // Process normal instructions. 173 // Process normal instructions.
162 for (HInstruction* current = block->first(); current != NULL; ) { 174 for (HInstruction* current = block->first(); current != NULL; ) {
163 HInstruction* next = current->next(); 175 HInstruction* next = current->next();
164 InsertRepresentationChangesForValue(current); 176 InsertRepresentationChangesForValue(current);
165 current = next; 177 current = next;
166 } 178 }
167 } 179 }
168 } 180 }
169 181
170 } } // namespace v8::internal 182 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen-minus-zero.cc ('k') | src/ia32/lithium-codegen-ia32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698