blob: 16c23c8df5b1d05401016e410b07e59ad980ae14 [file] [log] [blame]
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "ssa_builder.h"
Nicolas Geoffray184d6402014-06-09 14:06:02 +010018
Nicolas Geoffray0846a8f2018-09-12 15:21:07 +010019#include "base/arena_bit_vector.h"
20#include "base/bit_vector-inl.h"
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010021#include "data_type-inl.h"
David Sehr312f3b22018-03-19 08:39:26 -070022#include "dex/bytecode_utils.h"
Andreas Gampe90b936d2017-01-31 08:58:55 -080023#include "mirror/class-inl.h"
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +010024#include "nodes.h"
David Brazdil4833f5a2015-12-16 10:37:39 +000025#include "reference_type_propagation.h"
Andreas Gampe90b936d2017-01-31 08:58:55 -080026#include "scoped_thread_state_change-inl.h"
Nicolas Geoffray31596742014-11-24 15:28:45 +000027#include "ssa_phi_elimination.h"
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +010028
29namespace art {
30
Calin Juravlea4f88312015-04-16 12:57:19 +010031void SsaBuilder::FixNullConstantType() {
32 // The order doesn't matter here.
Vladimir Marko2c45bc92016-10-25 16:54:12 +010033 for (HBasicBlock* block : graph_->GetReversePostOrder()) {
34 for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) {
Calin Juravlea4f88312015-04-16 12:57:19 +010035 HInstruction* equality_instr = it.Current();
36 if (!equality_instr->IsEqual() && !equality_instr->IsNotEqual()) {
37 continue;
38 }
39 HInstruction* left = equality_instr->InputAt(0);
40 HInstruction* right = equality_instr->InputAt(1);
Nicolas Geoffray51d400d2015-06-15 09:01:08 +010041 HInstruction* int_operand = nullptr;
Calin Juravlea4f88312015-04-16 12:57:19 +010042
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010043 if ((left->GetType() == DataType::Type::kReference) &&
44 (right->GetType() == DataType::Type::kInt32)) {
Nicolas Geoffray51d400d2015-06-15 09:01:08 +010045 int_operand = right;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010046 } else if ((right->GetType() == DataType::Type::kReference) &&
47 (left->GetType() == DataType::Type::kInt32)) {
Nicolas Geoffray51d400d2015-06-15 09:01:08 +010048 int_operand = left;
Calin Juravlea4f88312015-04-16 12:57:19 +010049 } else {
50 continue;
51 }
52
53 // If we got here, we are comparing against a reference and the int constant
54 // should be replaced with a null constant.
Nicolas Geoffray51d400d2015-06-15 09:01:08 +010055 // Both type propagation and redundant phi elimination ensure `int_operand`
56 // can only be the 0 constant.
Nicolas Geoffray15bd2282016-01-05 15:55:41 +000057 DCHECK(int_operand->IsIntConstant()) << int_operand->DebugName();
Nicolas Geoffray51d400d2015-06-15 09:01:08 +010058 DCHECK_EQ(0, int_operand->AsIntConstant()->GetValue());
David Brazdildee58d62016-04-07 09:54:26 +000059 equality_instr->ReplaceInput(graph_->GetNullConstant(), int_operand == right ? 1 : 0);
Calin Juravlea4f88312015-04-16 12:57:19 +010060 }
61 }
62}
63
64void SsaBuilder::EquivalentPhisCleanup() {
65 // The order doesn't matter here.
Vladimir Marko2c45bc92016-10-25 16:54:12 +010066 for (HBasicBlock* block : graph_->GetReversePostOrder()) {
67 for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) {
Calin Juravlea4f88312015-04-16 12:57:19 +010068 HPhi* phi = it.Current()->AsPhi();
69 HPhi* next = phi->GetNextEquivalentPhiWithSameType();
70 if (next != nullptr) {
David Brazdil4833f5a2015-12-16 10:37:39 +000071 // Make sure we do not replace a live phi with a dead phi. A live phi
72 // has been handled by the type propagation phase, unlike a dead phi.
Nicolas Geoffray4230e182015-06-29 14:34:46 +010073 if (next->IsLive()) {
74 phi->ReplaceWith(next);
David Brazdil4833f5a2015-12-16 10:37:39 +000075 phi->SetDead();
Nicolas Geoffray4230e182015-06-29 14:34:46 +010076 } else {
77 next->ReplaceWith(phi);
78 }
Calin Juravlea4f88312015-04-16 12:57:19 +010079 DCHECK(next->GetNextEquivalentPhiWithSameType() == nullptr)
80 << "More then one phi equivalent with type " << phi->GetType()
81 << " found for phi" << phi->GetId();
82 }
83 }
84 }
85}
86
David Brazdil4833f5a2015-12-16 10:37:39 +000087void SsaBuilder::FixEnvironmentPhis() {
Vladimir Marko2c45bc92016-10-25 16:54:12 +010088 for (HBasicBlock* block : graph_->GetReversePostOrder()) {
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +000089 for (HInstructionIterator it_phis(block->GetPhis()); !it_phis.Done(); it_phis.Advance()) {
90 HPhi* phi = it_phis.Current()->AsPhi();
91 // If the phi is not dead, or has no environment uses, there is nothing to do.
92 if (!phi->IsDead() || !phi->HasEnvironmentUses()) continue;
93 HInstruction* next = phi->GetNext();
David Brazdild0180f92015-09-22 14:39:58 +010094 if (!phi->IsVRegEquivalentOf(next)) continue;
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +000095 if (next->AsPhi()->IsDead()) {
96 // If the phi equivalent is dead, check if there is another one.
97 next = next->GetNext();
David Brazdild0180f92015-09-22 14:39:58 +010098 if (!phi->IsVRegEquivalentOf(next)) continue;
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +000099 // There can be at most two phi equivalents.
David Brazdild0180f92015-09-22 14:39:58 +0100100 DCHECK(!phi->IsVRegEquivalentOf(next->GetNext()));
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +0000101 if (next->AsPhi()->IsDead()) continue;
102 }
103 // We found a live phi equivalent. Update the environment uses of `phi` with it.
104 phi->ReplaceWith(next);
105 }
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000106 }
David Brazdil4833f5a2015-12-16 10:37:39 +0000107}
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000108
David Brazdil4833f5a2015-12-16 10:37:39 +0000109static void AddDependentInstructionsToWorklist(HInstruction* instruction,
Vladimir Marko69d310e2017-10-09 14:12:23 +0100110 ScopedArenaVector<HPhi*>* worklist) {
David Brazdil4833f5a2015-12-16 10:37:39 +0000111 // If `instruction` is a dead phi, type conflict was just identified. All its
112 // live phi users, and transitively users of those users, therefore need to be
113 // marked dead/conflicting too, so we add them to the worklist. Otherwise we
114 // add users whose type does not match and needs to be updated.
115 bool add_all_live_phis = instruction->IsPhi() && instruction->AsPhi()->IsDead();
Vladimir Marko46817b82016-03-29 12:21:58 +0100116 for (const HUseListNode<HInstruction*>& use : instruction->GetUses()) {
117 HInstruction* user = use.GetUser();
David Brazdil4833f5a2015-12-16 10:37:39 +0000118 if (user->IsPhi() && user->AsPhi()->IsLive()) {
119 if (add_all_live_phis || user->GetType() != instruction->GetType()) {
120 worklist->push_back(user->AsPhi());
121 }
122 }
123 }
124}
125
126// Find a candidate primitive type for `phi` by merging the type of its inputs.
127// Return false if conflict is identified.
128static bool TypePhiFromInputs(HPhi* phi) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100129 DataType::Type common_type = phi->GetType();
David Brazdil4833f5a2015-12-16 10:37:39 +0000130
Vladimir Marko372f10e2016-05-17 16:30:10 +0100131 for (HInstruction* input : phi->GetInputs()) {
David Brazdil4833f5a2015-12-16 10:37:39 +0000132 if (input->IsPhi() && input->AsPhi()->IsDead()) {
133 // Phis are constructed live so if an input is a dead phi, it must have
134 // been made dead due to type conflict. Mark this phi conflicting too.
135 return false;
136 }
137
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100138 DataType::Type input_type = HPhi::ToPhiType(input->GetType());
David Brazdil4833f5a2015-12-16 10:37:39 +0000139 if (common_type == input_type) {
140 // No change in type.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100141 } else if (DataType::Is64BitType(common_type) != DataType::Is64BitType(input_type)) {
David Brazdil4833f5a2015-12-16 10:37:39 +0000142 // Types are of different sizes, e.g. int vs. long. Must be a conflict.
143 return false;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100144 } else if (DataType::IsIntegralType(common_type)) {
David Brazdil4833f5a2015-12-16 10:37:39 +0000145 // Previous inputs were integral, this one is not but is of the same size.
146 // This does not imply conflict since some bytecode instruction types are
147 // ambiguous. TypeInputsOfPhi will either type them or detect a conflict.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100148 DCHECK(DataType::IsFloatingPointType(input_type) ||
149 input_type == DataType::Type::kReference);
David Brazdil4833f5a2015-12-16 10:37:39 +0000150 common_type = input_type;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100151 } else if (DataType::IsIntegralType(input_type)) {
David Brazdil4833f5a2015-12-16 10:37:39 +0000152 // Input is integral, common type is not. Same as in the previous case, if
153 // there is a conflict, it will be detected during TypeInputsOfPhi.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100154 DCHECK(DataType::IsFloatingPointType(common_type) ||
155 common_type == DataType::Type::kReference);
David Brazdil4833f5a2015-12-16 10:37:39 +0000156 } else {
157 // Combining float and reference types. Clearly a conflict.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100158 DCHECK(
159 (common_type == DataType::Type::kFloat32 && input_type == DataType::Type::kReference) ||
160 (common_type == DataType::Type::kReference && input_type == DataType::Type::kFloat32));
David Brazdil4833f5a2015-12-16 10:37:39 +0000161 return false;
162 }
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +0000163 }
164
David Brazdil4833f5a2015-12-16 10:37:39 +0000165 // We have found a candidate type for the phi. Set it and return true. We may
166 // still discover conflict whilst typing the individual inputs in TypeInputsOfPhi.
167 phi->SetType(common_type);
168 return true;
169}
David Brazdild9510df2015-11-04 23:30:22 +0000170
David Brazdil4833f5a2015-12-16 10:37:39 +0000171// Replace inputs of `phi` to match its type. Return false if conflict is identified.
Vladimir Marko69d310e2017-10-09 14:12:23 +0100172bool SsaBuilder::TypeInputsOfPhi(HPhi* phi, ScopedArenaVector<HPhi*>* worklist) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100173 DataType::Type common_type = phi->GetType();
174 if (DataType::IsIntegralType(common_type)) {
Nicolas Geoffray50a9ed02016-09-23 15:40:41 +0100175 // We do not need to retype ambiguous inputs because they are always constructed
176 // with the integral type candidate.
David Brazdil4833f5a2015-12-16 10:37:39 +0000177 if (kIsDebugBuild) {
Vladimir Marko372f10e2016-05-17 16:30:10 +0100178 for (HInstruction* input : phi->GetInputs()) {
Nicolas Geoffray50a9ed02016-09-23 15:40:41 +0100179 DCHECK(HPhi::ToPhiType(input->GetType()) == common_type);
David Brazdil4833f5a2015-12-16 10:37:39 +0000180 }
181 }
182 // Inputs did not need to be replaced, hence no conflict. Report success.
183 return true;
184 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100185 DCHECK(common_type == DataType::Type::kReference ||
186 DataType::IsFloatingPointType(common_type));
Vladimir Markoe9004912016-06-16 16:50:52 +0100187 HInputsRef inputs = phi->GetInputs();
Vladimir Marko372f10e2016-05-17 16:30:10 +0100188 for (size_t i = 0; i < inputs.size(); ++i) {
189 HInstruction* input = inputs[i];
David Brazdil4833f5a2015-12-16 10:37:39 +0000190 if (input->GetType() != common_type) {
191 // Input type does not match phi's type. Try to retype the input or
192 // generate a suitably typed equivalent.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100193 HInstruction* equivalent = (common_type == DataType::Type::kReference)
David Brazdil4833f5a2015-12-16 10:37:39 +0000194 ? GetReferenceTypeEquivalent(input)
195 : GetFloatOrDoubleEquivalent(input, common_type);
196 if (equivalent == nullptr) {
197 // Input could not be typed. Report conflict.
198 return false;
199 }
200 // Make sure the input did not change its type and we do not need to
201 // update its users.
202 DCHECK_NE(input, equivalent);
203
204 phi->ReplaceInput(equivalent, i);
205 if (equivalent->IsPhi()) {
206 worklist->push_back(equivalent->AsPhi());
207 }
208 }
209 }
210 // All inputs either matched the type of the phi or we successfully replaced
211 // them with a suitable equivalent. Report success.
212 return true;
213 }
214}
215
216// Attempt to set the primitive type of `phi` to match its inputs. Return whether
217// it was changed by the algorithm or not.
Vladimir Marko69d310e2017-10-09 14:12:23 +0100218bool SsaBuilder::UpdatePrimitiveType(HPhi* phi, ScopedArenaVector<HPhi*>* worklist) {
David Brazdil4833f5a2015-12-16 10:37:39 +0000219 DCHECK(phi->IsLive());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100220 DataType::Type original_type = phi->GetType();
David Brazdil4833f5a2015-12-16 10:37:39 +0000221
222 // Try to type the phi in two stages:
223 // (1) find a candidate type for the phi by merging types of all its inputs,
224 // (2) try to type the phi's inputs to that candidate type.
225 // Either of these stages may detect a type conflict and fail, in which case
226 // we immediately abort.
227 if (!TypePhiFromInputs(phi) || !TypeInputsOfPhi(phi, worklist)) {
228 // Conflict detected. Mark the phi dead and return true because it changed.
229 phi->SetDead();
230 return true;
231 }
232
233 // Return true if the type of the phi has changed.
234 return phi->GetType() != original_type;
235}
236
237void SsaBuilder::RunPrimitiveTypePropagation() {
Vladimir Marko69d310e2017-10-09 14:12:23 +0100238 ScopedArenaVector<HPhi*> worklist(local_allocator_->Adapter(kArenaAllocGraphBuilder));
David Brazdil4833f5a2015-12-16 10:37:39 +0000239
Vladimir Marko2c45bc92016-10-25 16:54:12 +0100240 for (HBasicBlock* block : graph_->GetReversePostOrder()) {
David Brazdil4833f5a2015-12-16 10:37:39 +0000241 if (block->IsLoopHeader()) {
242 for (HInstructionIterator phi_it(block->GetPhis()); !phi_it.Done(); phi_it.Advance()) {
243 HPhi* phi = phi_it.Current()->AsPhi();
244 if (phi->IsLive()) {
245 worklist.push_back(phi);
246 }
247 }
248 } else {
249 for (HInstructionIterator phi_it(block->GetPhis()); !phi_it.Done(); phi_it.Advance()) {
250 // Eagerly compute the type of the phi, for quicker convergence. Note
251 // that we don't need to add users to the worklist because we are
252 // doing a reverse post-order visit, therefore either the phi users are
253 // non-loop phi and will be visited later in the visit, or are loop-phis,
254 // and they are already in the work list.
255 HPhi* phi = phi_it.Current()->AsPhi();
256 if (phi->IsLive()) {
257 UpdatePrimitiveType(phi, &worklist);
258 }
259 }
260 }
261 }
262
263 ProcessPrimitiveTypePropagationWorklist(&worklist);
264 EquivalentPhisCleanup();
265}
266
Vladimir Marko69d310e2017-10-09 14:12:23 +0100267void SsaBuilder::ProcessPrimitiveTypePropagationWorklist(ScopedArenaVector<HPhi*>* worklist) {
David Brazdil4833f5a2015-12-16 10:37:39 +0000268 // Process worklist
269 while (!worklist->empty()) {
270 HPhi* phi = worklist->back();
271 worklist->pop_back();
272 // The phi could have been made dead as a result of conflicts while in the
273 // worklist. If it is now dead, there is no point in updating its type.
274 if (phi->IsLive() && UpdatePrimitiveType(phi, worklist)) {
275 AddDependentInstructionsToWorklist(phi, worklist);
276 }
277 }
278}
279
280static HArrayGet* FindFloatOrDoubleEquivalentOfArrayGet(HArrayGet* aget) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100281 DataType::Type type = aget->GetType();
282 DCHECK(DataType::IsIntOrLongType(type));
David Brazdildee58d62016-04-07 09:54:26 +0000283 HInstruction* next = aget->GetNext();
284 if (next != nullptr && next->IsArrayGet()) {
285 HArrayGet* next_aget = next->AsArrayGet();
286 if (next_aget->IsEquivalentOf(aget)) {
287 return next_aget;
288 }
289 }
290 return nullptr;
David Brazdil4833f5a2015-12-16 10:37:39 +0000291}
292
293static HArrayGet* CreateFloatOrDoubleEquivalentOfArrayGet(HArrayGet* aget) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100294 DataType::Type type = aget->GetType();
295 DCHECK(DataType::IsIntOrLongType(type));
David Brazdil4833f5a2015-12-16 10:37:39 +0000296 DCHECK(FindFloatOrDoubleEquivalentOfArrayGet(aget) == nullptr);
297
Vladimir Markoca6fff82017-10-03 14:49:14 +0100298 HArrayGet* equivalent = new (aget->GetBlock()->GetGraph()->GetAllocator()) HArrayGet(
David Brazdil4833f5a2015-12-16 10:37:39 +0000299 aget->GetArray(),
300 aget->GetIndex(),
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100301 type == DataType::Type::kInt32 ? DataType::Type::kFloat32 : DataType::Type::kFloat64,
David Brazdil4833f5a2015-12-16 10:37:39 +0000302 aget->GetDexPc());
303 aget->GetBlock()->InsertInstructionAfter(equivalent, aget);
304 return equivalent;
305}
306
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100307static DataType::Type GetPrimitiveArrayComponentType(HInstruction* array)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700308 REQUIRES_SHARED(Locks::mutator_lock_) {
David Brazdil15693bf2015-12-16 10:30:45 +0000309 ReferenceTypeInfo array_type = array->GetReferenceTypeInfo();
David Brazdil4833f5a2015-12-16 10:37:39 +0000310 DCHECK(array_type.IsPrimitiveArrayClass());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100311 return DataTypeFromPrimitive(
312 array_type.GetTypeHandle()->GetComponentType()->GetPrimitiveType());
David Brazdil4833f5a2015-12-16 10:37:39 +0000313}
314
David Brazdil15693bf2015-12-16 10:30:45 +0000315bool SsaBuilder::FixAmbiguousArrayOps() {
316 if (ambiguous_agets_.empty() && ambiguous_asets_.empty()) {
David Brazdil4833f5a2015-12-16 10:37:39 +0000317 return true;
318 }
319
320 // The wrong ArrayGet equivalent may still have Phi uses coming from ArraySet
321 // uses (because they are untyped) and environment uses (if --debuggable).
322 // After resolving all ambiguous ArrayGets, we will re-run primitive type
323 // propagation on the Phis which need to be updated.
Vladimir Marko69d310e2017-10-09 14:12:23 +0100324 ScopedArenaVector<HPhi*> worklist(local_allocator_->Adapter(kArenaAllocGraphBuilder));
David Brazdil4833f5a2015-12-16 10:37:39 +0000325
326 {
327 ScopedObjectAccess soa(Thread::Current());
328
329 for (HArrayGet* aget_int : ambiguous_agets_) {
David Brazdil15693bf2015-12-16 10:30:45 +0000330 HInstruction* array = aget_int->GetArray();
331 if (!array->GetReferenceTypeInfo().IsPrimitiveArrayClass()) {
David Brazdil4833f5a2015-12-16 10:37:39 +0000332 // RTP did not type the input array. Bail.
Nicolas Geoffraydbb9aef2017-11-23 10:44:11 +0000333 VLOG(compiler) << "Not compiled: Could not infer an array type for array operation at "
334 << aget_int->GetDexPc();
David Brazdil4833f5a2015-12-16 10:37:39 +0000335 return false;
336 }
337
338 HArrayGet* aget_float = FindFloatOrDoubleEquivalentOfArrayGet(aget_int);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100339 DataType::Type array_type = GetPrimitiveArrayComponentType(array);
340 DCHECK_EQ(DataType::Is64BitType(aget_int->GetType()), DataType::Is64BitType(array_type));
David Brazdil15693bf2015-12-16 10:30:45 +0000341
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100342 if (DataType::IsIntOrLongType(array_type)) {
David Brazdil4833f5a2015-12-16 10:37:39 +0000343 if (aget_float != nullptr) {
344 // There is a float/double equivalent. We must replace it and re-run
345 // primitive type propagation on all dependent instructions.
346 aget_float->ReplaceWith(aget_int);
347 aget_float->GetBlock()->RemoveInstruction(aget_float);
348 AddDependentInstructionsToWorklist(aget_int, &worklist);
349 }
350 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100351 DCHECK(DataType::IsFloatingPointType(array_type));
David Brazdil4833f5a2015-12-16 10:37:39 +0000352 if (aget_float == nullptr) {
353 // This is a float/double ArrayGet but there were no typed uses which
354 // would create the typed equivalent. Create it now.
355 aget_float = CreateFloatOrDoubleEquivalentOfArrayGet(aget_int);
356 }
357 // Replace the original int/long instruction. Note that it may have phi
358 // uses, environment uses, as well as real uses (from untyped ArraySets).
359 // We need to re-run primitive type propagation on its dependent instructions.
360 aget_int->ReplaceWith(aget_float);
361 aget_int->GetBlock()->RemoveInstruction(aget_int);
362 AddDependentInstructionsToWorklist(aget_float, &worklist);
363 }
364 }
David Brazdil4833f5a2015-12-16 10:37:39 +0000365
David Brazdil15693bf2015-12-16 10:30:45 +0000366 // Set a flag stating that types of ArrayGets have been resolved. Requesting
367 // equivalent of the wrong type with GetFloatOrDoubleEquivalentOfArrayGet
368 // will fail from now on.
369 agets_fixed_ = true;
370
371 for (HArraySet* aset : ambiguous_asets_) {
372 HInstruction* array = aset->GetArray();
373 if (!array->GetReferenceTypeInfo().IsPrimitiveArrayClass()) {
374 // RTP did not type the input array. Bail.
Nicolas Geoffraydbb9aef2017-11-23 10:44:11 +0000375 VLOG(compiler) << "Not compiled: Could not infer an array type for array operation at "
376 << aset->GetDexPc();
David Brazdil15693bf2015-12-16 10:30:45 +0000377 return false;
378 }
379
380 HInstruction* value = aset->GetValue();
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100381 DataType::Type value_type = value->GetType();
382 DataType::Type array_type = GetPrimitiveArrayComponentType(array);
383 DCHECK_EQ(DataType::Is64BitType(value_type), DataType::Is64BitType(array_type));
David Brazdil15693bf2015-12-16 10:30:45 +0000384
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100385 if (DataType::IsFloatingPointType(array_type)) {
386 if (!DataType::IsFloatingPointType(value_type)) {
387 DCHECK(DataType::IsIntegralType(value_type));
David Brazdil15693bf2015-12-16 10:30:45 +0000388 // Array elements are floating-point but the value has not been replaced
389 // with its floating-point equivalent. The replacement must always
390 // succeed in code validated by the verifier.
391 HInstruction* equivalent = GetFloatOrDoubleEquivalent(value, array_type);
392 DCHECK(equivalent != nullptr);
393 aset->ReplaceInput(equivalent, /* input_index */ 2);
394 if (equivalent->IsPhi()) {
395 // Returned equivalent is a phi which may not have had its inputs
396 // replaced yet. We need to run primitive type propagation on it.
397 worklist.push_back(equivalent->AsPhi());
398 }
399 }
Aart Bik18b36ab2016-04-13 16:41:35 -0700400 // Refine the side effects of this floating point aset. Note that we do this even if
401 // no replacement occurs, since the right-hand-side may have been corrected already.
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100402 aset->SetSideEffects(HArraySet::ComputeSideEffects(aset->GetComponentType()));
David Brazdil15693bf2015-12-16 10:30:45 +0000403 } else {
404 // Array elements are integral and the value assigned to it initially
405 // was integral too. Nothing to do.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100406 DCHECK(DataType::IsIntegralType(array_type));
407 DCHECK(DataType::IsIntegralType(value_type));
David Brazdil15693bf2015-12-16 10:30:45 +0000408 }
409 }
410 }
David Brazdil4833f5a2015-12-16 10:37:39 +0000411
412 if (!worklist.empty()) {
413 ProcessPrimitiveTypePropagationWorklist(&worklist);
414 EquivalentPhisCleanup();
415 }
416
417 return true;
418}
419
Nicolas Geoffray0846a8f2018-09-12 15:21:07 +0100420bool SsaBuilder::HasAliasInEnvironments(HInstruction* instruction) {
421 ScopedArenaHashSet<size_t> seen_users(
422 local_allocator_->Adapter(kArenaAllocGraphBuilder));
Vladimir Marko46817b82016-03-29 12:21:58 +0100423 for (const HUseListNode<HEnvironment*>& use : instruction->GetEnvUses()) {
424 DCHECK(use.GetUser() != nullptr);
Nicolas Geoffray0846a8f2018-09-12 15:21:07 +0100425 size_t id = use.GetUser()->GetHolder()->GetId();
426 if (seen_users.find(id) != seen_users.end()) {
Nicolas Geoffray98e6ce42016-02-16 18:42:15 +0000427 return true;
428 }
Nicolas Geoffray0846a8f2018-09-12 15:21:07 +0100429 seen_users.insert(id);
Nicolas Geoffray98e6ce42016-02-16 18:42:15 +0000430 }
431 return false;
432}
433
Nicolas Geoffray639f2792018-09-25 00:39:48 +0100434bool SsaBuilder::ReplaceUninitializedStringPhis() {
Nicolas Geoffray0846a8f2018-09-12 15:21:07 +0100435 for (HInvoke* invoke : uninitialized_string_phis_) {
436 HInstruction* str = invoke->InputAt(invoke->InputCount() - 1);
437 if (str->IsPhi()) {
438 // If after redundant phi and dead phi elimination, it's still a phi that feeds
439 // the invoke, then we must be compiling a method with irreducible loops. Just bail.
440 DCHECK(graph_->HasIrreducibleLoops());
Nicolas Geoffray639f2792018-09-25 00:39:48 +0100441 return false;
442 }
Nicolas Geoffray0846a8f2018-09-12 15:21:07 +0100443 DCHECK(str->IsNewInstance());
444 AddUninitializedString(str->AsNewInstance());
445 str->ReplaceUsesDominatedBy(invoke, invoke);
446 str->ReplaceEnvUsesDominatedBy(invoke, invoke);
447 invoke->RemoveInputAt(invoke->InputCount() - 1);
Nicolas Geoffray8a62a4c2018-07-03 09:39:07 +0100448 }
Nicolas Geoffray639f2792018-09-25 00:39:48 +0100449 return true;
Nicolas Geoffray8a62a4c2018-07-03 09:39:07 +0100450}
451
David Brazdil65902e82016-01-15 09:35:13 +0000452void SsaBuilder::RemoveRedundantUninitializedStrings() {
David Brazdildee58d62016-04-07 09:54:26 +0000453 if (graph_->IsDebuggable()) {
David Brazdil65902e82016-01-15 09:35:13 +0000454 // Do not perform the optimization for consistency with the interpreter
455 // which always allocates an object for new-instance of String.
456 return;
457 }
458
459 for (HNewInstance* new_instance : uninitialized_strings_) {
Aart Bikeda31402016-03-24 15:38:56 -0700460 DCHECK(new_instance->IsInBlock());
David Brazdildee58d62016-04-07 09:54:26 +0000461 DCHECK(new_instance->IsStringAlloc());
462
David Brazdil65902e82016-01-15 09:35:13 +0000463 // Replace NewInstance of String with NullConstant if not used prior to
Nicolas Geoffray0846a8f2018-09-12 15:21:07 +0100464 // calling StringFactory. We check for alias environments in case of deoptimization.
465 // The interpreter is expected to skip null check on the `this` argument of the
466 // StringFactory call.
Nicolas Geoffray98e6ce42016-02-16 18:42:15 +0000467 if (!new_instance->HasNonEnvironmentUses() && !HasAliasInEnvironments(new_instance)) {
David Brazdildee58d62016-04-07 09:54:26 +0000468 new_instance->ReplaceWith(graph_->GetNullConstant());
David Brazdil65902e82016-01-15 09:35:13 +0000469 new_instance->GetBlock()->RemoveInstruction(new_instance);
470
471 // Remove LoadClass if not needed any more.
Nicolas Geoffray5e08e362016-02-15 15:56:11 +0000472 HInstruction* input = new_instance->InputAt(0);
473 HLoadClass* load_class = nullptr;
474
475 // If the class was not present in the dex cache at the point of building
476 // the graph, the builder inserted a HClinitCheck in between. Since the String
477 // class is always initialized at the point of running Java code, we can remove
478 // that check.
479 if (input->IsClinitCheck()) {
480 load_class = input->InputAt(0)->AsLoadClass();
481 input->ReplaceWith(load_class);
482 input->GetBlock()->RemoveInstruction(input);
483 } else {
484 load_class = input->AsLoadClass();
485 DCHECK(new_instance->IsStringAlloc());
486 DCHECK(!load_class->NeedsAccessCheck()) << "String class is always accessible";
487 }
David Brazdil65902e82016-01-15 09:35:13 +0000488 DCHECK(load_class != nullptr);
David Brazdil65902e82016-01-15 09:35:13 +0000489 if (!load_class->HasUses()) {
Nicolas Geoffray5e08e362016-02-15 15:56:11 +0000490 // Even if the HLoadClass needs access check, we can remove it, as we know the
491 // String class does not need it.
David Brazdil65902e82016-01-15 09:35:13 +0000492 load_class->GetBlock()->RemoveInstruction(load_class);
493 }
494 }
495 }
496}
497
Nicolas Geoffray15bd2282016-01-05 15:55:41 +0000498GraphAnalysisResult SsaBuilder::BuildSsa() {
David Brazdildee58d62016-04-07 09:54:26 +0000499 DCHECK(!graph_->IsInSsaForm());
David Brazdilbadd8262016-02-02 16:28:56 +0000500
Nicolas Geoffray8a62a4c2018-07-03 09:39:07 +0100501 // Propagate types of phis. At this point, phis are typed void in the general
David Brazdil4833f5a2015-12-16 10:37:39 +0000502 // case, or float/double/reference if we created an equivalent phi. So we need
503 // to propagate the types across phis to give them a correct type. If a type
504 // conflict is detected in this stage, the phi is marked dead.
505 RunPrimitiveTypePropagation();
506
Nicolas Geoffray8a62a4c2018-07-03 09:39:07 +0100507 // Now that the correct primitive types have been assigned, we can get rid
David Brazdil4833f5a2015-12-16 10:37:39 +0000508 // of redundant phis. Note that we cannot do this phase before type propagation,
509 // otherwise we could get rid of phi equivalents, whose presence is a requirement
510 // for the type propagation phase. Note that this is to satisfy statement (a)
511 // of the SsaBuilder (see ssa_builder.h).
David Brazdildee58d62016-04-07 09:54:26 +0000512 SsaRedundantPhiElimination(graph_).Run();
David Brazdil4833f5a2015-12-16 10:37:39 +0000513
Nicolas Geoffray8a62a4c2018-07-03 09:39:07 +0100514 // Fix the type for null constants which are part of an equality comparison.
David Brazdil4833f5a2015-12-16 10:37:39 +0000515 // We need to do this after redundant phi elimination, to ensure the only cases
516 // that we can see are reference comparison against 0. The redundant phi
517 // elimination ensures we do not see a phi taking two 0 constants in a HEqual
518 // or HNotEqual.
519 FixNullConstantType();
520
Nicolas Geoffray8a62a4c2018-07-03 09:39:07 +0100521 // Compute type of reference type instructions. The pass assumes that
David Brazdil4833f5a2015-12-16 10:37:39 +0000522 // NullConstant has been fixed up.
Vladimir Marko8d6768d2017-03-14 10:13:21 +0000523 ReferenceTypePropagation(graph_,
524 class_loader_,
525 dex_cache_,
526 handles_,
527 /* is_first_run */ true).Run();
David Brazdil4833f5a2015-12-16 10:37:39 +0000528
Nicolas Geoffray8a62a4c2018-07-03 09:39:07 +0100529 // HInstructionBuilder duplicated ArrayGet instructions with ambiguous type
David Brazdildee58d62016-04-07 09:54:26 +0000530 // (int/float or long/double) and marked ArraySets with ambiguous input type.
531 // Now that RTP computed the type of the array input, the ambiguity can be
532 // resolved and the correct equivalents kept.
David Brazdil15693bf2015-12-16 10:30:45 +0000533 if (!FixAmbiguousArrayOps()) {
Nicolas Geoffray15bd2282016-01-05 15:55:41 +0000534 return kAnalysisFailAmbiguousArrayOp;
David Brazdil4833f5a2015-12-16 10:37:39 +0000535 }
536
Nicolas Geoffray8a62a4c2018-07-03 09:39:07 +0100537 // Mark dead phis. This will mark phis which are not used by instructions
David Brazdil4833f5a2015-12-16 10:37:39 +0000538 // or other live phis. If compiling as debuggable code, phis will also be kept
539 // live if they have an environment use.
David Brazdildee58d62016-04-07 09:54:26 +0000540 SsaDeadPhiElimination dead_phi_elimimation(graph_);
David Brazdil4833f5a2015-12-16 10:37:39 +0000541 dead_phi_elimimation.MarkDeadPhis();
542
Nicolas Geoffray8a62a4c2018-07-03 09:39:07 +0100543 // Make sure environments use the right phi equivalent: a phi marked dead
David Brazdil4833f5a2015-12-16 10:37:39 +0000544 // can have a phi equivalent that is not dead. In that case we have to replace
545 // it with the live equivalent because deoptimization and try/catch rely on
546 // environments containing values of all live vregs at that point. Note that
547 // there can be multiple phis for the same Dex register that are live
548 // (for example when merging constants), in which case it is okay for the
549 // environments to just reference one.
550 FixEnvironmentPhis();
551
Nicolas Geoffray8a62a4c2018-07-03 09:39:07 +0100552 // Now that the right phis are used for the environments, we can eliminate
David Brazdil4833f5a2015-12-16 10:37:39 +0000553 // phis we do not need. Regardless of the debuggable status, this phase is
554 /// necessary for statement (b) of the SsaBuilder (see ssa_builder.h), as well
555 // as for the code generation, which does not deal with phis of conflicting
556 // input types.
557 dead_phi_elimimation.EliminateDeadPhis();
558
Nicolas Geoffray0846a8f2018-09-12 15:21:07 +0100559 // Replace Phis that feed in a String.<init> during instruction building. We
560 // run this after redundant and dead phi elimination to make sure the phi will have
561 // been replaced by the actual allocation. Only with an irreducible loop
562 // a phi can still be the input, in which case we bail.
563 if (!ReplaceUninitializedStringPhis()) {
564 return kAnalysisFailIrreducibleLoopAndStringInit;
565 }
566
Nicolas Geoffray8a62a4c2018-07-03 09:39:07 +0100567 // HInstructionBuidler replaced uses of NewInstances of String with the
David Brazdildee58d62016-04-07 09:54:26 +0000568 // results of their corresponding StringFactory calls. Unless the String
569 // objects are used before they are initialized, they can be replaced with
570 // NullConstant. Note that this optimization is valid only if unsimplified
571 // code does not use the uninitialized value because we assume execution can
572 // be deoptimized at any safepoint. We must therefore perform it before any
573 // other optimizations.
David Brazdil65902e82016-01-15 09:35:13 +0000574 RemoveRedundantUninitializedStrings();
575
David Brazdildee58d62016-04-07 09:54:26 +0000576 graph_->SetInSsaForm();
Nicolas Geoffray15bd2282016-01-05 15:55:41 +0000577 return kAnalysisSuccess;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100578}
579
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100580/**
581 * Constants in the Dex format are not typed. So the builder types them as
582 * integers, but when doing the SSA form, we might realize the constant
583 * is used for floating point operations. We create a floating-point equivalent
584 * constant to make the operations correctly typed.
585 */
David Brazdil8d5b8b22015-03-24 10:51:52 +0000586HFloatConstant* SsaBuilder::GetFloatEquivalent(HIntConstant* constant) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100587 // We place the floating point constant next to this constant.
588 HFloatConstant* result = constant->GetNext()->AsFloatConstant();
589 if (result == nullptr) {
David Brazdildee58d62016-04-07 09:54:26 +0000590 float value = bit_cast<float, int32_t>(constant->GetValue());
Vladimir Markoca6fff82017-10-03 14:49:14 +0100591 result = new (graph_->GetAllocator()) HFloatConstant(value);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100592 constant->GetBlock()->InsertInstructionBefore(result, constant->GetNext());
David Brazdildee58d62016-04-07 09:54:26 +0000593 graph_->CacheFloatConstant(result);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100594 } else {
595 // If there is already a constant with the expected type, we know it is
596 // the floating point equivalent of this constant.
Roland Levillainda4d79b2015-03-24 14:36:11 +0000597 DCHECK_EQ((bit_cast<int32_t, float>(result->GetValue())), constant->GetValue());
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100598 }
599 return result;
600}
601
602/**
603 * Wide constants in the Dex format are not typed. So the builder types them as
604 * longs, but when doing the SSA form, we might realize the constant
605 * is used for floating point operations. We create a floating-point equivalent
606 * constant to make the operations correctly typed.
607 */
David Brazdil8d5b8b22015-03-24 10:51:52 +0000608HDoubleConstant* SsaBuilder::GetDoubleEquivalent(HLongConstant* constant) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100609 // We place the floating point constant next to this constant.
610 HDoubleConstant* result = constant->GetNext()->AsDoubleConstant();
611 if (result == nullptr) {
David Brazdildee58d62016-04-07 09:54:26 +0000612 double value = bit_cast<double, int64_t>(constant->GetValue());
Vladimir Markoca6fff82017-10-03 14:49:14 +0100613 result = new (graph_->GetAllocator()) HDoubleConstant(value);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100614 constant->GetBlock()->InsertInstructionBefore(result, constant->GetNext());
David Brazdildee58d62016-04-07 09:54:26 +0000615 graph_->CacheDoubleConstant(result);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100616 } else {
617 // If there is already a constant with the expected type, we know it is
618 // the floating point equivalent of this constant.
Roland Levillainda4d79b2015-03-24 14:36:11 +0000619 DCHECK_EQ((bit_cast<int64_t, double>(result->GetValue())), constant->GetValue());
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100620 }
621 return result;
622}
623
624/**
625 * Because of Dex format, we might end up having the same phi being
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000626 * used for non floating point operations and floating point / reference operations.
627 * Because we want the graph to be correctly typed (and thereafter avoid moves between
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100628 * floating point registers and core registers), we need to create a copy of the
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000629 * phi with a floating point / reference type.
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100630 */
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100631HPhi* SsaBuilder::GetFloatDoubleOrReferenceEquivalentOfPhi(HPhi* phi, DataType::Type type) {
David Brazdil4833f5a2015-12-16 10:37:39 +0000632 DCHECK(phi->IsLive()) << "Cannot get equivalent of a dead phi since it would create a live one.";
633
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000634 // We place the floating point /reference phi next to this phi.
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100635 HInstruction* next = phi->GetNext();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000636 if (next != nullptr
637 && next->AsPhi()->GetRegNumber() == phi->GetRegNumber()
638 && next->GetType() != type) {
639 // Move to the next phi to see if it is the one we are looking for.
640 next = next->GetNext();
641 }
642
643 if (next == nullptr
644 || (next->AsPhi()->GetRegNumber() != phi->GetRegNumber())
645 || (next->GetType() != type)) {
Vladimir Markoca6fff82017-10-03 14:49:14 +0100646 ArenaAllocator* allocator = graph_->GetAllocator();
Vladimir Markoe9004912016-06-16 16:50:52 +0100647 HInputsRef inputs = phi->GetInputs();
Vladimir Marko69d310e2017-10-09 14:12:23 +0100648 HPhi* new_phi = new (allocator) HPhi(allocator, phi->GetRegNumber(), inputs.size(), type);
Vladimir Marko372f10e2016-05-17 16:30:10 +0100649 // Copy the inputs. Note that the graph may not be correctly typed
650 // by doing this copy, but the type propagation phase will fix it.
651 ArrayRef<HUserRecord<HInstruction*>> new_input_records = new_phi->GetInputRecords();
652 for (size_t i = 0; i < inputs.size(); ++i) {
653 new_input_records[i] = HUserRecord<HInstruction*>(inputs[i]);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100654 }
655 phi->GetBlock()->InsertPhiAfter(new_phi, phi);
David Brazdil4833f5a2015-12-16 10:37:39 +0000656 DCHECK(new_phi->IsLive());
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100657 return new_phi;
658 } else {
David Brazdil4833f5a2015-12-16 10:37:39 +0000659 // An existing equivalent was found. If it is dead, conflict was previously
660 // identified and we return nullptr instead.
David Brazdil809d70f2015-11-19 10:29:39 +0000661 HPhi* next_phi = next->AsPhi();
662 DCHECK_EQ(next_phi->GetType(), type);
David Brazdil4833f5a2015-12-16 10:37:39 +0000663 return next_phi->IsLive() ? next_phi : nullptr;
David Brazdild9510df2015-11-04 23:30:22 +0000664 }
665}
666
David Brazdil4833f5a2015-12-16 10:37:39 +0000667HArrayGet* SsaBuilder::GetFloatOrDoubleEquivalentOfArrayGet(HArrayGet* aget) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100668 DCHECK(DataType::IsIntegralType(aget->GetType()));
David Brazdil4833f5a2015-12-16 10:37:39 +0000669
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100670 if (!DataType::IsIntOrLongType(aget->GetType())) {
David Brazdil4833f5a2015-12-16 10:37:39 +0000671 // Cannot type boolean, char, byte, short to float/double.
672 return nullptr;
673 }
674
675 DCHECK(ContainsElement(ambiguous_agets_, aget));
676 if (agets_fixed_) {
677 // This used to be an ambiguous ArrayGet but its type has been resolved to
678 // int/long. Requesting a float/double equivalent should lead to a conflict.
679 if (kIsDebugBuild) {
680 ScopedObjectAccess soa(Thread::Current());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100681 DCHECK(DataType::IsIntOrLongType(GetPrimitiveArrayComponentType(aget->GetArray())));
David Brazdil4833f5a2015-12-16 10:37:39 +0000682 }
683 return nullptr;
684 } else {
685 // This is an ambiguous ArrayGet which has not been resolved yet. Return an
686 // equivalent float/double instruction to use until it is resolved.
687 HArrayGet* equivalent = FindFloatOrDoubleEquivalentOfArrayGet(aget);
688 return (equivalent == nullptr) ? CreateFloatOrDoubleEquivalentOfArrayGet(aget) : equivalent;
689 }
690}
691
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100692HInstruction* SsaBuilder::GetFloatOrDoubleEquivalent(HInstruction* value, DataType::Type type) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100693 if (value->IsArrayGet()) {
David Brazdil4833f5a2015-12-16 10:37:39 +0000694 return GetFloatOrDoubleEquivalentOfArrayGet(value->AsArrayGet());
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100695 } else if (value->IsLongConstant()) {
696 return GetDoubleEquivalent(value->AsLongConstant());
697 } else if (value->IsIntConstant()) {
698 return GetFloatEquivalent(value->AsIntConstant());
699 } else if (value->IsPhi()) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000700 return GetFloatDoubleOrReferenceEquivalentOfPhi(value->AsPhi(), type);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100701 } else {
David Brazdil4833f5a2015-12-16 10:37:39 +0000702 return nullptr;
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100703 }
704}
705
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000706HInstruction* SsaBuilder::GetReferenceTypeEquivalent(HInstruction* value) {
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +0000707 if (value->IsIntConstant() && value->AsIntConstant()->GetValue() == 0) {
David Brazdildee58d62016-04-07 09:54:26 +0000708 return graph_->GetNullConstant();
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +0000709 } else if (value->IsPhi()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100710 return GetFloatDoubleOrReferenceEquivalentOfPhi(value->AsPhi(), DataType::Type::kReference);
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +0000711 } else {
712 return nullptr;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000713 }
714}
715
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100716} // namespace art