Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/flow_graph.h" | 5 #include "vm/flow_graph.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/cha.h" | 8 #include "vm/cha.h" |
| 9 #include "vm/flow_graph_builder.h" | 9 #include "vm/flow_graph_builder.h" |
| 10 #include "vm/flow_graph_compiler.h" | 10 #include "vm/flow_graph_compiler.h" |
| (...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1073 Instruction* current = it.Current(); | 1073 Instruction* current = it.Current(); |
| 1074 | 1074 |
| 1075 // Attach current environment to the instructions that need it. | 1075 // Attach current environment to the instructions that need it. |
| 1076 if (current->NeedsEnvironment()) { | 1076 if (current->NeedsEnvironment()) { |
| 1077 AttachEnvironment(current, env); | 1077 AttachEnvironment(current, env); |
| 1078 } | 1078 } |
| 1079 | 1079 |
| 1080 // 2a. Handle uses: | 1080 // 2a. Handle uses: |
| 1081 // Update the expression stack renaming environment for each use by | 1081 // Update the expression stack renaming environment for each use by |
| 1082 // removing the renamed value. | 1082 // removing the renamed value. |
| 1083 // For each use of a LoadLocal, StoreLocal, or Constant: Replace it with | 1083 // For each use of a LoadLocal, StoreLocal, DropTemps or Constant: Replace |
| 1084 // the renamed value. | 1084 // it with the renamed value. |
| 1085 for (intptr_t i = current->InputCount() - 1; i >= 0; --i) { | 1085 for (intptr_t i = current->InputCount() - 1; i >= 0; --i) { |
| 1086 Value* v = current->InputAt(i); | 1086 Value* v = current->InputAt(i); |
| 1087 // Update expression stack. | 1087 // Update expression stack. |
| 1088 ASSERT(env->length() > variable_count()); | 1088 ASSERT(env->length() > variable_count()); |
| 1089 | 1089 |
| 1090 Definition* reaching_defn = env->RemoveLast(); | 1090 Definition* reaching_defn = env->RemoveLast(); |
| 1091 Definition* input_defn = v->definition(); | 1091 Definition* input_defn = v->definition(); |
| 1092 if (input_defn->IsLoadLocal() || | 1092 if (input_defn->IsLoadLocal() || |
| 1093 input_defn->IsStoreLocal() || | 1093 input_defn->IsStoreLocal() || |
| 1094 input_defn->IsPushTemp() || | |
| 1095 input_defn->IsDropTemps() || | 1094 input_defn->IsDropTemps() || |
| 1096 input_defn->IsConstant()) { | 1095 input_defn->IsConstant()) { |
| 1097 // Remove the load/store from the graph. | |
| 1098 input_defn->RemoveFromGraph(); | |
| 1099 // Assert we are not referencing nulls in the initial environment. | 1096 // Assert we are not referencing nulls in the initial environment. |
| 1100 ASSERT(reaching_defn->ssa_temp_index() != -1); | 1097 ASSERT(reaching_defn->ssa_temp_index() != -1); |
| 1101 v->set_definition(reaching_defn); | 1098 v->set_definition(reaching_defn); |
| 1102 input_defn = reaching_defn; | 1099 input_defn = reaching_defn; |
| 1103 } | 1100 } |
|
Vyacheslav Egorov (Google)
2016/05/03 20:04:51
I think this can be rewritten as:
if (input_defn
Florian Schneider
2016/05/09 14:47:20
This should work - it's a little subtle. I'll add
| |
| 1104 input_defn->AddInputUse(v); | 1101 input_defn->AddInputUse(v); |
| 1105 } | 1102 } |
| 1106 | 1103 |
| 1107 // Drop pushed arguments for calls. | 1104 // Drop pushed arguments for calls. |
| 1108 for (intptr_t j = 0; j < current->ArgumentCount(); j++) { | 1105 for (intptr_t j = 0; j < current->ArgumentCount(); j++) { |
| 1109 env->RemoveLast(); | 1106 env->RemoveLast(); |
| 1110 } | 1107 } |
| 1111 | 1108 |
| 1112 // 2b. Handle LoadLocal, StoreLocal, and Constant. | 1109 // 2b. Handle LoadLocal, StoreLocal, DropTemps and Constant. |
| 1113 Definition* definition = current->AsDefinition(); | 1110 Definition* definition = current->AsDefinition(); |
| 1114 if (definition != NULL) { | 1111 if (definition != NULL) { |
| 1115 LoadLocalInstr* load = definition->AsLoadLocal(); | 1112 LoadLocalInstr* load = definition->AsLoadLocal(); |
| 1116 StoreLocalInstr* store = definition->AsStoreLocal(); | 1113 StoreLocalInstr* store = definition->AsStoreLocal(); |
| 1117 PushTempInstr* push = definition->AsPushTemp(); | |
| 1118 DropTempsInstr* drop = definition->AsDropTemps(); | 1114 DropTempsInstr* drop = definition->AsDropTemps(); |
| 1119 ConstantInstr* constant = definition->AsConstant(); | 1115 ConstantInstr* constant = definition->AsConstant(); |
| 1120 if ((load != NULL) || | 1116 if ((load != NULL) || |
| 1121 (store != NULL) || | 1117 (store != NULL) || |
| 1122 (push != NULL) || | |
| 1123 (drop != NULL) || | 1118 (drop != NULL) || |
| 1124 (constant != NULL)) { | 1119 (constant != NULL)) { |
| 1125 Definition* result = NULL; | 1120 Definition* result = NULL; |
| 1126 if (store != NULL) { | 1121 if (store != NULL) { |
| 1127 // Update renaming environment. | 1122 // Update renaming environment. |
| 1128 intptr_t index = store->local().BitIndexIn(num_non_copied_params_); | 1123 intptr_t index = store->local().BitIndexIn(num_non_copied_params_); |
| 1129 result = store->value()->definition(); | 1124 result = store->value()->definition(); |
| 1130 | 1125 |
| 1131 if (!FLAG_prune_dead_locals || | 1126 if (!FLAG_prune_dead_locals || |
| 1132 variable_liveness->IsStoreAlive(block_entry, store)) { | 1127 variable_liveness->IsStoreAlive(block_entry, store)) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1151 variable_liveness->IsLastLoad(block_entry, load)) { | 1146 variable_liveness->IsLastLoad(block_entry, load)) { |
| 1152 (*env)[index] = constant_dead(); | 1147 (*env)[index] = constant_dead(); |
| 1153 } | 1148 } |
| 1154 | 1149 |
| 1155 // Record captured parameters so that they can be skipped when | 1150 // Record captured parameters so that they can be skipped when |
| 1156 // emitting sync code inside optimized try-blocks. | 1151 // emitting sync code inside optimized try-blocks. |
| 1157 if (load->local().is_captured_parameter()) { | 1152 if (load->local().is_captured_parameter()) { |
| 1158 intptr_t index = load->local().BitIndexIn(num_non_copied_params_); | 1153 intptr_t index = load->local().BitIndexIn(num_non_copied_params_); |
| 1159 captured_parameters_->Add(index); | 1154 captured_parameters_->Add(index); |
| 1160 } | 1155 } |
| 1161 | |
| 1162 } else if (push != NULL) { | |
| 1163 result = push->value()->definition(); | |
| 1164 env->Add(result); | |
| 1165 it.RemoveCurrentFromGraph(); | |
| 1166 continue; | |
| 1167 } else if (drop != NULL) { | 1156 } else if (drop != NULL) { |
| 1168 // Drop temps from the environment. | 1157 // Drop temps from the environment. |
| 1169 for (intptr_t j = 0; j < drop->num_temps(); j++) { | 1158 for (intptr_t j = 0; j < drop->num_temps(); j++) { |
| 1170 env->RemoveLast(); | 1159 env->RemoveLast(); |
| 1171 } | 1160 } |
| 1172 if (drop->value() != NULL) { | 1161 if (drop->value() != NULL) { |
| 1173 result = drop->value()->definition(); | 1162 result = drop->value()->definition(); |
| 1174 } | 1163 } |
| 1175 ASSERT((drop->value() != NULL) || !drop->HasTemp()); | 1164 ASSERT((drop->value() != NULL) || !drop->HasTemp()); |
| 1176 } else { | 1165 } else { |
| 1177 ASSERT(definition->HasTemp()); | 1166 ASSERT(definition->HasTemp()); |
| 1178 result = GetConstant(constant->value()); | 1167 result = GetConstant(constant->value()); |
| 1179 } | 1168 } |
| 1180 // Update expression stack or remove from graph. | 1169 // Update expression stack or remove from graph. |
| 1181 if (definition->HasTemp()) { | 1170 if (definition->HasTemp()) { |
| 1182 ASSERT(result != NULL); | 1171 ASSERT(result != NULL); |
| 1183 env->Add(result); | 1172 env->Add(result); |
| 1184 // We remove load/store/constant instructions when we find their | |
| 1185 // use in 2a. | |
| 1186 } else { | |
| 1187 it.RemoveCurrentFromGraph(); | |
| 1188 } | 1173 } |
| 1174 it.RemoveCurrentFromGraph(); | |
| 1189 } else { | 1175 } else { |
| 1190 // Not a load, store, or constant. | 1176 // Not a load, store, drop or constant. |
| 1191 if (definition->HasTemp()) { | 1177 if (definition->HasTemp()) { |
| 1192 // Assign fresh SSA temporary and update expression stack. | 1178 // Assign fresh SSA temporary and update expression stack. |
| 1193 AllocateSSAIndexes(definition); | 1179 AllocateSSAIndexes(definition); |
| 1194 env->Add(definition); | 1180 env->Add(definition); |
| 1195 } | 1181 } |
| 1196 } | 1182 } |
| 1197 } | 1183 } |
| 1198 | 1184 |
| 1199 // 2c. Handle pushed argument. | 1185 // 2c. Handle pushed argument. |
| 1200 PushArgumentInstr* push = current->AsPushArgument(); | 1186 PushArgumentInstr* push = current->AsPushArgument(); |
| (...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2060 ReplaceCurrentInstruction(&it, current, replacement); | 2046 ReplaceCurrentInstruction(&it, current, replacement); |
| 2061 changed = true; | 2047 changed = true; |
| 2062 } | 2048 } |
| 2063 } | 2049 } |
| 2064 } | 2050 } |
| 2065 return changed; | 2051 return changed; |
| 2066 } | 2052 } |
| 2067 | 2053 |
| 2068 | 2054 |
| 2069 } // namespace dart | 2055 } // namespace dart |
| OLD | NEW |