blob: 4e1cafee6658c3036667a82d6a3c680b91618989 [file] [log] [blame]
Roland Levillainccc07a92014-09-16 14:48: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 "graph_checker.h"
18
Roland Levillainccc07a92014-09-16 14:48:16 +010019#include <map>
Nicolas Geoffray7c5367b2014-12-17 10:13:46 +000020#include <string>
Calin Juravlea4f88312015-04-16 12:57:19 +010021#include <sstream>
Roland Levillainccc07a92014-09-16 14:48:16 +010022
Roland Levillain7e53b412014-09-23 10:50:22 +010023#include "base/bit_vector-inl.h"
Roland Levillain5c4405e2015-01-21 11:39:58 +000024#include "base/stringprintf.h"
Roland Levillain7e53b412014-09-23 10:50:22 +010025
Roland Levillainccc07a92014-09-16 14:48:16 +010026namespace art {
27
28void GraphChecker::VisitBasicBlock(HBasicBlock* block) {
29 current_block_ = block;
30
31 // Check consistency with respect to predecessors of `block`.
Roland Levillainccc07a92014-09-16 14:48:16 +010032 std::map<HBasicBlock*, size_t> predecessors_count;
Vladimir Marko60584552015-09-03 13:35:12 +000033 for (HBasicBlock* p : block->GetPredecessors()) {
Roland Levillainccc07a92014-09-16 14:48:16 +010034 ++predecessors_count[p];
35 }
36 for (auto& pc : predecessors_count) {
37 HBasicBlock* p = pc.first;
38 size_t p_count_in_block_predecessors = pc.second;
Roland Levillainccc07a92014-09-16 14:48:16 +010039 size_t block_count_in_p_successors = 0;
Vladimir Marko60584552015-09-03 13:35:12 +000040 for (HBasicBlock* p_successor : p->GetSuccessors()) {
41 if (p_successor == block) {
Roland Levillainccc07a92014-09-16 14:48:16 +010042 ++block_count_in_p_successors;
43 }
44 }
45 if (p_count_in_block_predecessors != block_count_in_p_successors) {
Roland Levillain5c4405e2015-01-21 11:39:58 +000046 AddError(StringPrintf(
47 "Block %d lists %zu occurrences of block %d in its predecessors, whereas "
48 "block %d lists %zu occurrences of block %d in its successors.",
49 block->GetBlockId(), p_count_in_block_predecessors, p->GetBlockId(),
50 p->GetBlockId(), block_count_in_p_successors, block->GetBlockId()));
Roland Levillainccc07a92014-09-16 14:48:16 +010051 }
52 }
53
54 // Check consistency with respect to successors of `block`.
Roland Levillainccc07a92014-09-16 14:48:16 +010055 std::map<HBasicBlock*, size_t> successors_count;
Vladimir Marko60584552015-09-03 13:35:12 +000056 for (HBasicBlock* s : block->GetSuccessors()) {
Roland Levillainccc07a92014-09-16 14:48:16 +010057 ++successors_count[s];
58 }
59 for (auto& sc : successors_count) {
60 HBasicBlock* s = sc.first;
61 size_t s_count_in_block_successors = sc.second;
Roland Levillainccc07a92014-09-16 14:48:16 +010062 size_t block_count_in_s_predecessors = 0;
Vladimir Marko60584552015-09-03 13:35:12 +000063 for (HBasicBlock* s_predecessor : s->GetPredecessors()) {
64 if (s_predecessor == block) {
Roland Levillainccc07a92014-09-16 14:48:16 +010065 ++block_count_in_s_predecessors;
66 }
67 }
68 if (s_count_in_block_successors != block_count_in_s_predecessors) {
Roland Levillain5c4405e2015-01-21 11:39:58 +000069 AddError(StringPrintf(
70 "Block %d lists %zu occurrences of block %d in its successors, whereas "
71 "block %d lists %zu occurrences of block %d in its predecessors.",
72 block->GetBlockId(), s_count_in_block_successors, s->GetBlockId(),
73 s->GetBlockId(), block_count_in_s_predecessors, block->GetBlockId()));
Roland Levillainccc07a92014-09-16 14:48:16 +010074 }
75 }
76
77 // Ensure `block` ends with a branch instruction.
David Brazdilfc6a86a2015-06-26 10:33:45 +000078 // This invariant is not enforced on non-SSA graphs. Graph built from DEX with
79 // dead code that falls out of the method will not end with a control-flow
80 // instruction. Such code is removed during the SSA-building DCE phase.
81 if (GetGraph()->IsInSsaForm() && !block->EndsWithControlFlowInstruction()) {
Roland Levillain5c4405e2015-01-21 11:39:58 +000082 AddError(StringPrintf("Block %d does not end with a branch instruction.",
83 block->GetBlockId()));
Roland Levillainccc07a92014-09-16 14:48:16 +010084 }
85
David Brazdil29fc0082015-08-18 17:17:38 +010086 // Ensure that only Return(Void) and Throw jump to Exit. An exiting
David Brazdilb618ade2015-07-29 10:31:29 +010087 // TryBoundary may be between a Throw and the Exit if the Throw is in a try.
88 if (block->IsExitBlock()) {
Vladimir Marko60584552015-09-03 13:35:12 +000089 for (HBasicBlock* predecessor : block->GetPredecessors()) {
David Brazdilb618ade2015-07-29 10:31:29 +010090 if (predecessor->IsSingleTryBoundary()
91 && !predecessor->GetLastInstruction()->AsTryBoundary()->IsEntry()) {
92 HBasicBlock* real_predecessor = predecessor->GetSinglePredecessor();
93 HInstruction* last_instruction = real_predecessor->GetLastInstruction();
94 if (!last_instruction->IsThrow()) {
95 AddError(StringPrintf("Unexpected TryBoundary between %s:%d and Exit.",
96 last_instruction->DebugName(),
97 last_instruction->GetId()));
98 }
99 } else {
100 HInstruction* last_instruction = predecessor->GetLastInstruction();
101 if (!last_instruction->IsReturn()
102 && !last_instruction->IsReturnVoid()
103 && !last_instruction->IsThrow()) {
104 AddError(StringPrintf("Unexpected instruction %s:%d jumps into the exit block.",
105 last_instruction->DebugName(),
106 last_instruction->GetId()));
107 }
108 }
109 }
110 }
111
Roland Levillainccc07a92014-09-16 14:48:16 +0100112 // Visit this block's list of phis.
113 for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) {
David Brazdilc3d743f2015-04-22 13:40:50 +0100114 HInstruction* current = it.Current();
Roland Levillainccc07a92014-09-16 14:48:16 +0100115 // Ensure this block's list of phis contains only phis.
David Brazdilc3d743f2015-04-22 13:40:50 +0100116 if (!current->IsPhi()) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000117 AddError(StringPrintf("Block %d has a non-phi in its phi list.",
118 current_block_->GetBlockId()));
Roland Levillainccc07a92014-09-16 14:48:16 +0100119 }
David Brazdilc3d743f2015-04-22 13:40:50 +0100120 if (current->GetNext() == nullptr && current != block->GetLastPhi()) {
121 AddError(StringPrintf("The recorded last phi of block %d does not match "
122 "the actual last phi %d.",
123 current_block_->GetBlockId(),
124 current->GetId()));
125 }
126 current->Accept(this);
Roland Levillainccc07a92014-09-16 14:48:16 +0100127 }
128
129 // Visit this block's list of instructions.
David Brazdilc3d743f2015-04-22 13:40:50 +0100130 for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) {
131 HInstruction* current = it.Current();
Roland Levillainccc07a92014-09-16 14:48:16 +0100132 // Ensure this block's list of instructions does not contains phis.
David Brazdilc3d743f2015-04-22 13:40:50 +0100133 if (current->IsPhi()) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000134 AddError(StringPrintf("Block %d has a phi in its non-phi list.",
135 current_block_->GetBlockId()));
Roland Levillainccc07a92014-09-16 14:48:16 +0100136 }
David Brazdilc3d743f2015-04-22 13:40:50 +0100137 if (current->GetNext() == nullptr && current != block->GetLastInstruction()) {
138 AddError(StringPrintf("The recorded last instruction of block %d does not match "
139 "the actual last instruction %d.",
140 current_block_->GetBlockId(),
141 current->GetId()));
142 }
143 current->Accept(this);
Roland Levillainccc07a92014-09-16 14:48:16 +0100144 }
145}
146
Mark Mendell1152c922015-04-24 17:06:35 -0400147void GraphChecker::VisitBoundsCheck(HBoundsCheck* check) {
148 if (!GetGraph()->HasBoundsChecks()) {
149 AddError(StringPrintf("Instruction %s:%d is a HBoundsCheck, "
150 "but HasBoundsChecks() returns false",
151 check->DebugName(),
152 check->GetId()));
153 }
154
155 // Perform the instruction base checks too.
156 VisitInstruction(check);
157}
158
David Brazdilffee3d32015-07-06 11:48:53 +0100159void GraphChecker::VisitTryBoundary(HTryBoundary* try_boundary) {
160 // Ensure that all exception handlers are catch blocks and that handlers
161 // are not listed multiple times.
162 // Note that a normal-flow successor may be a catch block before CFG
163 // simplification. We only test normal-flow successors in SsaChecker.
164 for (HExceptionHandlerIterator it(*try_boundary); !it.Done(); it.Advance()) {
165 HBasicBlock* handler = it.Current();
166 if (!handler->IsCatchBlock()) {
167 AddError(StringPrintf("Block %d with %s:%d has exceptional successor %d which "
168 "is not a catch block.",
169 current_block_->GetBlockId(),
170 try_boundary->DebugName(),
171 try_boundary->GetId(),
172 handler->GetBlockId()));
173 }
Vladimir Marko60584552015-09-03 13:35:12 +0000174 if (current_block_->HasSuccessor(handler, it.CurrentSuccessorIndex() + 1)) {
David Brazdilffee3d32015-07-06 11:48:53 +0100175 AddError(StringPrintf("Exception handler block %d of %s:%d is listed multiple times.",
176 handler->GetBlockId(),
177 try_boundary->DebugName(),
178 try_boundary->GetId()));
179 }
180 }
181
182 VisitInstruction(try_boundary);
183}
184
Roland Levillainccc07a92014-09-16 14:48:16 +0100185void GraphChecker::VisitInstruction(HInstruction* instruction) {
Nicolas Geoffray7c5367b2014-12-17 10:13:46 +0000186 if (seen_ids_.IsBitSet(instruction->GetId())) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000187 AddError(StringPrintf("Instruction id %d is duplicate in graph.",
188 instruction->GetId()));
Nicolas Geoffray7c5367b2014-12-17 10:13:46 +0000189 } else {
190 seen_ids_.SetBit(instruction->GetId());
191 }
192
Roland Levillainccc07a92014-09-16 14:48:16 +0100193 // Ensure `instruction` is associated with `current_block_`.
Roland Levillain5c4405e2015-01-21 11:39:58 +0000194 if (instruction->GetBlock() == nullptr) {
195 AddError(StringPrintf("%s %d in block %d not associated with any block.",
196 instruction->IsPhi() ? "Phi" : "Instruction",
197 instruction->GetId(),
198 current_block_->GetBlockId()));
199 } else if (instruction->GetBlock() != current_block_) {
200 AddError(StringPrintf("%s %d in block %d associated with block %d.",
201 instruction->IsPhi() ? "Phi" : "Instruction",
202 instruction->GetId(),
203 current_block_->GetBlockId(),
204 instruction->GetBlock()->GetBlockId()));
Roland Levillainccc07a92014-09-16 14:48:16 +0100205 }
Roland Levillain6b469232014-09-25 10:10:38 +0100206
207 // Ensure the inputs of `instruction` are defined in a block of the graph.
208 for (HInputIterator input_it(instruction); !input_it.Done();
209 input_it.Advance()) {
210 HInstruction* input = input_it.Current();
211 const HInstructionList& list = input->IsPhi()
212 ? input->GetBlock()->GetPhis()
213 : input->GetBlock()->GetInstructions();
214 if (!list.Contains(input)) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000215 AddError(StringPrintf("Input %d of instruction %d is not defined "
216 "in a basic block of the control-flow graph.",
217 input->GetId(),
218 instruction->GetId()));
Roland Levillain6b469232014-09-25 10:10:38 +0100219 }
220 }
221
Nicolas Geoffray5d7b7f82015-04-28 00:52:43 +0100222 // Ensure the uses of `instruction` are defined in a block of the graph,
223 // and the entry in the use list is consistent.
David Brazdiled596192015-01-23 10:39:45 +0000224 for (HUseIterator<HInstruction*> use_it(instruction->GetUses());
Roland Levillain6b469232014-09-25 10:10:38 +0100225 !use_it.Done(); use_it.Advance()) {
226 HInstruction* use = use_it.Current()->GetUser();
227 const HInstructionList& list = use->IsPhi()
228 ? use->GetBlock()->GetPhis()
229 : use->GetBlock()->GetInstructions();
230 if (!list.Contains(use)) {
Nicolas Geoffray276d9da2015-02-02 18:24:11 +0000231 AddError(StringPrintf("User %s:%d of instruction %d is not defined "
Roland Levillain5c4405e2015-01-21 11:39:58 +0000232 "in a basic block of the control-flow graph.",
Nicolas Geoffray276d9da2015-02-02 18:24:11 +0000233 use->DebugName(),
Roland Levillain5c4405e2015-01-21 11:39:58 +0000234 use->GetId(),
235 instruction->GetId()));
Roland Levillain6b469232014-09-25 10:10:38 +0100236 }
Nicolas Geoffray5d7b7f82015-04-28 00:52:43 +0100237 size_t use_index = use_it.Current()->GetIndex();
238 if ((use_index >= use->InputCount()) || (use->InputAt(use_index) != instruction)) {
239 AddError(StringPrintf("User %s:%d of instruction %d has a wrong "
240 "UseListNode index.",
241 use->DebugName(),
242 use->GetId(),
243 instruction->GetId()));
244 }
245 }
246
247 // Ensure the environment uses entries are consistent.
248 for (HUseIterator<HEnvironment*> use_it(instruction->GetEnvUses());
249 !use_it.Done(); use_it.Advance()) {
250 HEnvironment* use = use_it.Current()->GetUser();
251 size_t use_index = use_it.Current()->GetIndex();
252 if ((use_index >= use->Size()) || (use->GetInstructionAt(use_index) != instruction)) {
253 AddError(StringPrintf("Environment user of %s:%d has a wrong "
254 "UseListNode index.",
255 instruction->DebugName(),
256 instruction->GetId()));
257 }
Roland Levillain6b469232014-09-25 10:10:38 +0100258 }
David Brazdil1abb4192015-02-17 18:33:36 +0000259
260 // Ensure 'instruction' has pointers to its inputs' use entries.
261 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
262 HUserRecord<HInstruction*> input_record = instruction->InputRecordAt(i);
263 HInstruction* input = input_record.GetInstruction();
264 HUseListNode<HInstruction*>* use_node = input_record.GetUseNode();
Nicolas Geoffray5d7b7f82015-04-28 00:52:43 +0100265 size_t use_index = use_node->GetIndex();
266 if ((use_node == nullptr)
267 || !input->GetUses().Contains(use_node)
268 || (use_index >= e)
269 || (use_index != i)) {
David Brazdil1abb4192015-02-17 18:33:36 +0000270 AddError(StringPrintf("Instruction %s:%d has an invalid pointer to use entry "
271 "at input %u (%s:%d).",
272 instruction->DebugName(),
273 instruction->GetId(),
274 static_cast<unsigned>(i),
275 input->DebugName(),
276 input->GetId()));
277 }
278 }
Roland Levillainccc07a92014-09-16 14:48:16 +0100279}
280
Roland Levillain4c0eb422015-04-24 16:43:49 +0100281void GraphChecker::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
282 VisitInstruction(invoke);
283
284 if (invoke->IsStaticWithExplicitClinitCheck()) {
285 size_t last_input_index = invoke->InputCount() - 1;
286 HInstruction* last_input = invoke->InputAt(last_input_index);
287 if (last_input == nullptr) {
288 AddError(StringPrintf("Static invoke %s:%d marked as having an explicit clinit check "
289 "has a null pointer as last input.",
290 invoke->DebugName(),
291 invoke->GetId()));
292 }
293 if (!last_input->IsClinitCheck() && !last_input->IsLoadClass()) {
294 AddError(StringPrintf("Static invoke %s:%d marked as having an explicit clinit check "
295 "has a last instruction (%s:%d) which is neither a clinit check "
296 "nor a load class instruction.",
297 invoke->DebugName(),
298 invoke->GetId(),
299 last_input->DebugName(),
300 last_input->GetId()));
301 }
302 }
303}
304
David Brazdilfc6a86a2015-06-26 10:33:45 +0000305void GraphChecker::VisitReturn(HReturn* ret) {
Nicolas Geoffrayf9a19952015-06-29 13:43:54 +0100306 VisitInstruction(ret);
David Brazdilfc6a86a2015-06-26 10:33:45 +0000307 if (!ret->GetBlock()->GetSingleSuccessor()->IsExitBlock()) {
308 AddError(StringPrintf("%s:%d does not jump to the exit block.",
309 ret->DebugName(),
310 ret->GetId()));
311 }
312}
313
314void GraphChecker::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffrayf9a19952015-06-29 13:43:54 +0100315 VisitInstruction(ret);
David Brazdilfc6a86a2015-06-26 10:33:45 +0000316 if (!ret->GetBlock()->GetSingleSuccessor()->IsExitBlock()) {
317 AddError(StringPrintf("%s:%d does not jump to the exit block.",
318 ret->DebugName(),
319 ret->GetId()));
320 }
321}
322
Nicolas Geoffrayf9a19952015-06-29 13:43:54 +0100323void GraphChecker::VisitCheckCast(HCheckCast* check) {
324 VisitInstruction(check);
325 HInstruction* input = check->InputAt(1);
326 if (!input->IsLoadClass()) {
327 AddError(StringPrintf("%s:%d expects a HLoadClass as second input, not %s:%d.",
328 check->DebugName(),
329 check->GetId(),
330 input->DebugName(),
331 input->GetId()));
332 }
333}
334
335void GraphChecker::VisitInstanceOf(HInstanceOf* instruction) {
336 VisitInstruction(instruction);
337 HInstruction* input = instruction->InputAt(1);
338 if (!input->IsLoadClass()) {
339 AddError(StringPrintf("%s:%d expects a HLoadClass as second input, not %s:%d.",
340 instruction->DebugName(),
341 instruction->GetId(),
342 input->DebugName(),
343 input->GetId()));
344 }
345}
346
Roland Levillainccc07a92014-09-16 14:48:16 +0100347void SSAChecker::VisitBasicBlock(HBasicBlock* block) {
348 super_type::VisitBasicBlock(block);
349
David Brazdilffee3d32015-07-06 11:48:53 +0100350 // Ensure that catch blocks are not normal successors, and normal blocks are
351 // never exceptional successors.
352 const size_t num_normal_successors = block->NumberOfNormalSuccessors();
353 for (size_t j = 0; j < num_normal_successors; ++j) {
Vladimir Marko60584552015-09-03 13:35:12 +0000354 HBasicBlock* successor = block->GetSuccessor(j);
David Brazdilffee3d32015-07-06 11:48:53 +0100355 if (successor->IsCatchBlock()) {
356 AddError(StringPrintf("Catch block %d is a normal successor of block %d.",
357 successor->GetBlockId(),
358 block->GetBlockId()));
359 }
360 }
Vladimir Marko60584552015-09-03 13:35:12 +0000361 for (size_t j = num_normal_successors, e = block->GetSuccessors().size(); j < e; ++j) {
362 HBasicBlock* successor = block->GetSuccessor(j);
David Brazdilffee3d32015-07-06 11:48:53 +0100363 if (!successor->IsCatchBlock()) {
364 AddError(StringPrintf("Normal block %d is an exceptional successor of block %d.",
365 successor->GetBlockId(),
366 block->GetBlockId()));
367 }
368 }
369
Roland Levillainccc07a92014-09-16 14:48:16 +0100370 // Ensure there is no critical edge (i.e., an edge connecting a
371 // block with multiple successors to a block with multiple
David Brazdilffee3d32015-07-06 11:48:53 +0100372 // predecessors). Exceptional edges are synthesized and hence
373 // not accounted for.
374 if (block->NumberOfNormalSuccessors() > 1) {
375 for (size_t j = 0, e = block->NumberOfNormalSuccessors(); j < e; ++j) {
Vladimir Marko60584552015-09-03 13:35:12 +0000376 HBasicBlock* successor = block->GetSuccessor(j);
377 if (successor->GetPredecessors().size() > 1) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000378 AddError(StringPrintf("Critical edge between blocks %d and %d.",
379 block->GetBlockId(),
380 successor->GetBlockId()));
Roland Levillainccc07a92014-09-16 14:48:16 +0100381 }
382 }
383 }
Roland Levillain6b879dd2014-09-22 17:13:44 +0100384
David Brazdilffee3d32015-07-06 11:48:53 +0100385 // Ensure try membership information is consistent.
David Brazdilffee3d32015-07-06 11:48:53 +0100386 if (block->IsCatchBlock()) {
David Brazdilec16f792015-08-19 15:04:01 +0100387 if (block->IsTryBlock()) {
388 const HTryBoundary& try_entry = block->GetTryCatchInformation()->GetTryEntry();
David Brazdilffee3d32015-07-06 11:48:53 +0100389 AddError(StringPrintf("Catch blocks should not be try blocks but catch block %d "
390 "has try entry %s:%d.",
391 block->GetBlockId(),
David Brazdilec16f792015-08-19 15:04:01 +0100392 try_entry.DebugName(),
393 try_entry.GetId()));
David Brazdilffee3d32015-07-06 11:48:53 +0100394 }
395
396 if (block->IsLoopHeader()) {
397 AddError(StringPrintf("Catch blocks should not be loop headers but catch block %d is.",
398 block->GetBlockId()));
399 }
400 } else {
Vladimir Marko60584552015-09-03 13:35:12 +0000401 for (HBasicBlock* predecessor : block->GetPredecessors()) {
David Brazdilec16f792015-08-19 15:04:01 +0100402 const HTryBoundary* incoming_try_entry = predecessor->ComputeTryEntryOfSuccessors();
403 if (block->IsTryBlock()) {
404 const HTryBoundary& stored_try_entry = block->GetTryCatchInformation()->GetTryEntry();
405 if (incoming_try_entry == nullptr) {
406 AddError(StringPrintf("Block %d has try entry %s:%d but no try entry follows "
David Brazdilffee3d32015-07-06 11:48:53 +0100407 "from predecessor %d.",
408 block->GetBlockId(),
David Brazdilec16f792015-08-19 15:04:01 +0100409 stored_try_entry.DebugName(),
410 stored_try_entry.GetId(),
411 predecessor->GetBlockId()));
412 } else if (!incoming_try_entry->HasSameExceptionHandlersAs(stored_try_entry)) {
413 AddError(StringPrintf("Block %d has try entry %s:%d which is not consistent "
414 "with %s:%d that follows from predecessor %d.",
415 block->GetBlockId(),
416 stored_try_entry.DebugName(),
417 stored_try_entry.GetId(),
David Brazdilffee3d32015-07-06 11:48:53 +0100418 incoming_try_entry->DebugName(),
419 incoming_try_entry->GetId(),
420 predecessor->GetBlockId()));
421 }
David Brazdilec16f792015-08-19 15:04:01 +0100422 } else if (incoming_try_entry != nullptr) {
423 AddError(StringPrintf("Block %d is not a try block but try entry %s:%d follows "
David Brazdilffee3d32015-07-06 11:48:53 +0100424 "from predecessor %d.",
425 block->GetBlockId(),
David Brazdilffee3d32015-07-06 11:48:53 +0100426 incoming_try_entry->DebugName(),
427 incoming_try_entry->GetId(),
428 predecessor->GetBlockId()));
429 }
430 }
431 }
432
Roland Levillain6b879dd2014-09-22 17:13:44 +0100433 if (block->IsLoopHeader()) {
434 CheckLoop(block);
435 }
436}
437
438void SSAChecker::CheckLoop(HBasicBlock* loop_header) {
439 int id = loop_header->GetBlockId();
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100440 HLoopInformation* loop_information = loop_header->GetLoopInformation();
Roland Levillain6b879dd2014-09-22 17:13:44 +0100441
442 // Ensure the pre-header block is first in the list of
443 // predecessors of a loop header.
444 if (!loop_header->IsLoopPreHeaderFirstPredecessor()) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000445 AddError(StringPrintf(
446 "Loop pre-header is not the first predecessor of the loop header %d.",
447 id));
Roland Levillain6b879dd2014-09-22 17:13:44 +0100448 }
449
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100450 // Ensure the loop header has only one incoming branch and the remaining
451 // predecessors are back edges.
Vladimir Marko60584552015-09-03 13:35:12 +0000452 size_t num_preds = loop_header->GetPredecessors().size();
Roland Levillain5c4405e2015-01-21 11:39:58 +0000453 if (num_preds < 2) {
454 AddError(StringPrintf(
455 "Loop header %d has less than two predecessors: %zu.",
456 id,
457 num_preds));
Roland Levillain6b879dd2014-09-22 17:13:44 +0100458 } else {
Vladimir Marko60584552015-09-03 13:35:12 +0000459 HBasicBlock* first_predecessor = loop_header->GetPredecessor(0);
David Brazdil46e2a392015-03-16 17:31:52 +0000460 if (loop_information->IsBackEdge(*first_predecessor)) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000461 AddError(StringPrintf(
462 "First predecessor of loop header %d is a back edge.",
463 id));
Roland Levillain6b879dd2014-09-22 17:13:44 +0100464 }
Vladimir Marko60584552015-09-03 13:35:12 +0000465 for (size_t i = 1, e = loop_header->GetPredecessors().size(); i < e; ++i) {
466 HBasicBlock* predecessor = loop_header->GetPredecessor(i);
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100467 if (!loop_information->IsBackEdge(*predecessor)) {
468 AddError(StringPrintf(
469 "Loop header %d has multiple incoming (non back edge) blocks.",
470 id));
471 }
Roland Levillain6b879dd2014-09-22 17:13:44 +0100472 }
473 }
474
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100475 const ArenaBitVector& loop_blocks = loop_information->GetBlocks();
David Brazdil2d7352b2015-04-20 14:52:42 +0100476
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100477 // Ensure back edges belong to the loop.
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100478 if (loop_information->NumberOfBackEdges() == 0) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000479 AddError(StringPrintf(
480 "Loop defined by header %d has no back edge.",
481 id));
David Brazdil2d7352b2015-04-20 14:52:42 +0100482 } else {
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100483 for (HBasicBlock* back_edge : loop_information->GetBackEdges()) {
484 int back_edge_id = back_edge->GetBlockId();
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100485 if (!loop_blocks.IsBitSet(back_edge_id)) {
486 AddError(StringPrintf(
487 "Loop defined by header %d has an invalid back edge %d.",
488 id,
489 back_edge_id));
490 }
David Brazdil2d7352b2015-04-20 14:52:42 +0100491 }
Roland Levillain6b879dd2014-09-22 17:13:44 +0100492 }
Roland Levillain7e53b412014-09-23 10:50:22 +0100493
David Brazdil2d7352b2015-04-20 14:52:42 +0100494 // Ensure all blocks in the loop are live and dominated by the loop header.
Roland Levillain7e53b412014-09-23 10:50:22 +0100495 for (uint32_t i : loop_blocks.Indexes()) {
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100496 HBasicBlock* loop_block = GetGraph()->GetBlock(i);
David Brazdil2d7352b2015-04-20 14:52:42 +0100497 if (loop_block == nullptr) {
498 AddError(StringPrintf("Loop defined by header %d contains a previously removed block %d.",
499 id,
500 i));
501 } else if (!loop_header->Dominates(loop_block)) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000502 AddError(StringPrintf("Loop block %d not dominated by loop header %d.",
David Brazdil2d7352b2015-04-20 14:52:42 +0100503 i,
Roland Levillain5c4405e2015-01-21 11:39:58 +0000504 id));
Roland Levillain7e53b412014-09-23 10:50:22 +0100505 }
506 }
David Brazdil7d275372015-04-21 16:36:35 +0100507
508 // If this is a nested loop, ensure the outer loops contain a superset of the blocks.
509 for (HLoopInformationOutwardIterator it(*loop_header); !it.Done(); it.Advance()) {
510 HLoopInformation* outer_info = it.Current();
511 if (!loop_blocks.IsSubsetOf(&outer_info->GetBlocks())) {
512 AddError(StringPrintf("Blocks of loop defined by header %d are not a subset of blocks of "
513 "an outer loop defined by header %d.",
David Brazdil2d7352b2015-04-20 14:52:42 +0100514 id,
David Brazdil7d275372015-04-21 16:36:35 +0100515 outer_info->GetHeader()->GetBlockId()));
516 }
517 }
Roland Levillainccc07a92014-09-16 14:48:16 +0100518}
519
520void SSAChecker::VisitInstruction(HInstruction* instruction) {
521 super_type::VisitInstruction(instruction);
522
Roland Levillaina8069ce2014-10-01 10:48:29 +0100523 // Ensure an instruction dominates all its uses.
David Brazdiled596192015-01-23 10:39:45 +0000524 for (HUseIterator<HInstruction*> use_it(instruction->GetUses());
Roland Levillaina8069ce2014-10-01 10:48:29 +0100525 !use_it.Done(); use_it.Advance()) {
526 HInstruction* use = use_it.Current()->GetUser();
Roland Levillain6c82d402014-10-13 16:10:27 +0100527 if (!use->IsPhi() && !instruction->StrictlyDominates(use)) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000528 AddError(StringPrintf("Instruction %d in block %d does not dominate "
529 "use %d in block %d.",
530 instruction->GetId(), current_block_->GetBlockId(),
531 use->GetId(), use->GetBlock()->GetBlockId()));
Roland Levillainccc07a92014-09-16 14:48:16 +0100532 }
533 }
Roland Levillaina8069ce2014-10-01 10:48:29 +0100534
535 // Ensure an instruction having an environment is dominated by the
536 // instructions contained in the environment.
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100537 for (HEnvironment* environment = instruction->GetEnvironment();
538 environment != nullptr;
539 environment = environment->GetParent()) {
Roland Levillaina8069ce2014-10-01 10:48:29 +0100540 for (size_t i = 0, e = environment->Size(); i < e; ++i) {
541 HInstruction* env_instruction = environment->GetInstructionAt(i);
542 if (env_instruction != nullptr
Roland Levillain6c82d402014-10-13 16:10:27 +0100543 && !env_instruction->StrictlyDominates(instruction)) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000544 AddError(StringPrintf("Instruction %d in environment of instruction %d "
545 "from block %d does not dominate instruction %d.",
546 env_instruction->GetId(),
547 instruction->GetId(),
548 current_block_->GetBlockId(),
549 instruction->GetId()));
Roland Levillaina8069ce2014-10-01 10:48:29 +0100550 }
551 }
552 }
Roland Levillainccc07a92014-09-16 14:48:16 +0100553}
554
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000555static Primitive::Type PrimitiveKind(Primitive::Type type) {
556 switch (type) {
557 case Primitive::kPrimBoolean:
558 case Primitive::kPrimByte:
559 case Primitive::kPrimShort:
560 case Primitive::kPrimChar:
561 case Primitive::kPrimInt:
562 return Primitive::kPrimInt;
563 default:
564 return type;
565 }
566}
567
David Brazdil77a48ae2015-09-15 12:34:04 +0000568static bool IsSameSizeConstant(HInstruction* insn1, HInstruction* insn2) {
569 return insn1->IsConstant()
570 && insn2->IsConstant()
571 && Primitive::Is64BitType(insn1->GetType()) == Primitive::Is64BitType(insn2->GetType());
572}
573
574static bool IsConstantEquivalent(HInstruction* insn1, HInstruction* insn2, BitVector* visited) {
575 if (insn1->IsPhi() &&
576 insn1->AsPhi()->IsVRegEquivalentOf(insn2) &&
577 insn1->InputCount() == insn2->InputCount()) {
578 // Testing only one of the two inputs for recursion is sufficient.
579 if (visited->IsBitSet(insn1->GetId())) {
580 return true;
581 }
582 visited->SetBit(insn1->GetId());
583
584 for (size_t i = 0, e = insn1->InputCount(); i < e; ++i) {
585 if (!IsConstantEquivalent(insn1->InputAt(i), insn2->InputAt(i), visited)) {
586 return false;
587 }
588 }
589 return true;
590 } else if (IsSameSizeConstant(insn1, insn2)) {
591 return insn1->AsConstant()->GetValueAsUint64() == insn2->AsConstant()->GetValueAsUint64();
592 } else {
593 return false;
594 }
595}
596
Roland Levillain6b879dd2014-09-22 17:13:44 +0100597void SSAChecker::VisitPhi(HPhi* phi) {
598 VisitInstruction(phi);
599
600 // Ensure the first input of a phi is not itself.
601 if (phi->InputAt(0) == phi) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000602 AddError(StringPrintf("Loop phi %d in block %d is its own first input.",
603 phi->GetId(),
604 phi->GetBlock()->GetBlockId()));
Roland Levillain6b879dd2014-09-22 17:13:44 +0100605 }
606
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000607 // Ensure that the inputs have the same primitive kind as the phi.
608 for (size_t i = 0, e = phi->InputCount(); i < e; ++i) {
609 HInstruction* input = phi->InputAt(i);
610 if (PrimitiveKind(input->GetType()) != PrimitiveKind(phi->GetType())) {
611 AddError(StringPrintf(
612 "Input %d at index %zu of phi %d from block %d does not have the "
613 "same type as the phi: %s versus %s",
614 input->GetId(), i, phi->GetId(), phi->GetBlock()->GetBlockId(),
615 Primitive::PrettyDescriptor(input->GetType()),
616 Primitive::PrettyDescriptor(phi->GetType())));
617 }
Nicolas Geoffray31596742014-11-24 15:28:45 +0000618 }
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +0000619 if (phi->GetType() != HPhi::ToPhiType(phi->GetType())) {
620 AddError(StringPrintf("Phi %d in block %d does not have an expected phi type: %s",
621 phi->GetId(),
622 phi->GetBlock()->GetBlockId(),
623 Primitive::PrettyDescriptor(phi->GetType())));
624 }
David Brazdilffee3d32015-07-06 11:48:53 +0100625
626 if (phi->IsCatchPhi()) {
David Brazdil3eaa32f2015-09-18 10:58:32 +0100627 // The number of inputs of a catch phi should be the total number of throwing
628 // instructions caught by this catch block. We do not enforce this, however,
629 // because we do not remove the corresponding inputs when we prove that an
630 // instruction cannot throw. Instead, we at least test that all phis have the
631 // same, non-zero number of inputs (b/24054676).
632 size_t input_count_this = phi->InputCount();
633 if (input_count_this == 0u) {
634 AddError(StringPrintf("Phi %d in catch block %d has zero inputs.",
635 phi->GetId(),
636 phi->GetBlock()->GetBlockId()));
637 } else {
638 HInstruction* next_phi = phi->GetNext();
639 if (next_phi != nullptr) {
640 size_t input_count_next = next_phi->InputCount();
641 if (input_count_this != input_count_next) {
642 AddError(StringPrintf("Phi %d in catch block %d has %zu inputs, "
643 "but phi %d has %zu inputs.",
644 phi->GetId(),
645 phi->GetBlock()->GetBlockId(),
646 input_count_this,
647 next_phi->GetId(),
648 input_count_next));
649 }
650 }
651 }
David Brazdilffee3d32015-07-06 11:48:53 +0100652 } else {
653 // Ensure the number of inputs of a non-catch phi is the same as the number
654 // of its predecessors.
Vladimir Marko60584552015-09-03 13:35:12 +0000655 const ArenaVector<HBasicBlock*>& predecessors = phi->GetBlock()->GetPredecessors();
656 if (phi->InputCount() != predecessors.size()) {
David Brazdilffee3d32015-07-06 11:48:53 +0100657 AddError(StringPrintf(
658 "Phi %d in block %d has %zu inputs, "
659 "but block %d has %zu predecessors.",
660 phi->GetId(), phi->GetBlock()->GetBlockId(), phi->InputCount(),
Vladimir Marko60584552015-09-03 13:35:12 +0000661 phi->GetBlock()->GetBlockId(), predecessors.size()));
David Brazdilffee3d32015-07-06 11:48:53 +0100662 } else {
663 // Ensure phi input at index I either comes from the Ith
664 // predecessor or from a block that dominates this predecessor.
665 for (size_t i = 0, e = phi->InputCount(); i < e; ++i) {
666 HInstruction* input = phi->InputAt(i);
Vladimir Marko60584552015-09-03 13:35:12 +0000667 HBasicBlock* predecessor = predecessors[i];
David Brazdilffee3d32015-07-06 11:48:53 +0100668 if (!(input->GetBlock() == predecessor
669 || input->GetBlock()->Dominates(predecessor))) {
670 AddError(StringPrintf(
671 "Input %d at index %zu of phi %d from block %d is not defined in "
672 "predecessor number %zu nor in a block dominating it.",
673 input->GetId(), i, phi->GetId(), phi->GetBlock()->GetBlockId(),
674 i));
675 }
676 }
677 }
678 }
David Brazdil77a48ae2015-09-15 12:34:04 +0000679
680 // Ensure that catch phis are sorted by their vreg number, as required by
681 // the register allocator and code generator. This does not apply to normal
682 // phis which can be constructed artifically.
683 if (phi->IsCatchPhi()) {
684 HInstruction* next_phi = phi->GetNext();
685 if (next_phi != nullptr && phi->GetRegNumber() > next_phi->AsPhi()->GetRegNumber()) {
686 AddError(StringPrintf("Catch phis %d and %d in block %d are not sorted by their "
687 "vreg numbers.",
688 phi->GetId(),
689 next_phi->GetId(),
690 phi->GetBlock()->GetBlockId()));
691 }
692 }
693
694 // Test phi equivalents. There should not be two of the same type and they
695 // should only be created for constants which were untyped in DEX.
696 for (HInstructionIterator phi_it(phi->GetBlock()->GetPhis()); !phi_it.Done(); phi_it.Advance()) {
697 HPhi* other_phi = phi_it.Current()->AsPhi();
698 if (phi != other_phi && phi->GetRegNumber() == other_phi->GetRegNumber()) {
699 if (phi->GetType() == other_phi->GetType()) {
700 std::stringstream type_str;
701 type_str << phi->GetType();
702 AddError(StringPrintf("Equivalent phi (%d) found for VReg %d with type: %s.",
703 phi->GetId(),
704 phi->GetRegNumber(),
705 type_str.str().c_str()));
706 } else {
707 ArenaBitVector visited(GetGraph()->GetArena(), 0, /* expandable */ true);
708 if (!IsConstantEquivalent(phi, other_phi, &visited)) {
709 AddError(StringPrintf("Two phis (%d and %d) found for VReg %d but they "
710 "are not equivalents of constants.",
711 phi->GetId(),
712 other_phi->GetId(),
713 phi->GetRegNumber()));
714 }
715 }
716 }
717 }
Nicolas Geoffray31596742014-11-24 15:28:45 +0000718}
719
David Brazdil13b47182015-04-15 16:29:32 +0100720void SSAChecker::HandleBooleanInput(HInstruction* instruction, size_t input_index) {
721 HInstruction* input = instruction->InputAt(input_index);
Nicolas Geoffray9ee66182015-01-16 12:35:40 +0000722 if (input->IsIntConstant()) {
David Brazdil13b47182015-04-15 16:29:32 +0100723 int32_t value = input->AsIntConstant()->GetValue();
Nicolas Geoffray9ee66182015-01-16 12:35:40 +0000724 if (value != 0 && value != 1) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000725 AddError(StringPrintf(
David Brazdil13b47182015-04-15 16:29:32 +0100726 "%s instruction %d has a non-Boolean constant input %d whose value is: %d.",
727 instruction->DebugName(),
Roland Levillain5c4405e2015-01-21 11:39:58 +0000728 instruction->GetId(),
David Brazdil13b47182015-04-15 16:29:32 +0100729 static_cast<int>(input_index),
Roland Levillain5c4405e2015-01-21 11:39:58 +0000730 value));
Nicolas Geoffray9ee66182015-01-16 12:35:40 +0000731 }
David Brazdil2fa194b2015-04-20 10:14:42 +0100732 } else if (input->GetType() == Primitive::kPrimInt
733 && (input->IsPhi() || input->IsAnd() || input->IsOr() || input->IsXor())) {
734 // TODO: We need a data-flow analysis to determine if the Phi or
735 // binary operation is actually Boolean. Allow for now.
David Brazdil13b47182015-04-15 16:29:32 +0100736 } else if (input->GetType() != Primitive::kPrimBoolean) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000737 AddError(StringPrintf(
David Brazdil13b47182015-04-15 16:29:32 +0100738 "%s instruction %d has a non-Boolean input %d whose type is: %s.",
739 instruction->DebugName(),
Roland Levillain5c4405e2015-01-21 11:39:58 +0000740 instruction->GetId(),
David Brazdil13b47182015-04-15 16:29:32 +0100741 static_cast<int>(input_index),
742 Primitive::PrettyDescriptor(input->GetType())));
Nicolas Geoffray9ee66182015-01-16 12:35:40 +0000743 }
744}
745
Mark Mendellfe57faa2015-09-18 09:26:15 -0400746void SSAChecker::VisitPackedSwitch(HPackedSwitch* instruction) {
747 VisitInstruction(instruction);
748 // Check that the number of block successors matches the switch count plus
749 // one for the default block.
750 HBasicBlock* block = instruction->GetBlock();
751 if (instruction->GetNumEntries() + 1u != block->GetSuccessors().size()) {
752 AddError(StringPrintf(
753 "%s instruction %d in block %d expects %u successors to the block, but found: %zu.",
754 instruction->DebugName(),
755 instruction->GetId(),
756 block->GetBlockId(),
757 instruction->GetNumEntries() + 1u,
758 block->GetSuccessors().size()));
759 }
760}
761
David Brazdil13b47182015-04-15 16:29:32 +0100762void SSAChecker::VisitIf(HIf* instruction) {
763 VisitInstruction(instruction);
764 HandleBooleanInput(instruction, 0);
765}
766
767void SSAChecker::VisitBooleanNot(HBooleanNot* instruction) {
768 VisitInstruction(instruction);
769 HandleBooleanInput(instruction, 0);
770}
771
Nicolas Geoffray31596742014-11-24 15:28:45 +0000772void SSAChecker::VisitCondition(HCondition* op) {
773 VisitInstruction(op);
Nicolas Geoffray31596742014-11-24 15:28:45 +0000774 if (op->GetType() != Primitive::kPrimBoolean) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000775 AddError(StringPrintf(
776 "Condition %s %d has a non-Boolean result type: %s.",
777 op->DebugName(), op->GetId(),
778 Primitive::PrettyDescriptor(op->GetType())));
Nicolas Geoffray31596742014-11-24 15:28:45 +0000779 }
Nicolas Geoffray9ee66182015-01-16 12:35:40 +0000780 HInstruction* lhs = op->InputAt(0);
781 HInstruction* rhs = op->InputAt(1);
Calin Juravlea4f88312015-04-16 12:57:19 +0100782 if (PrimitiveKind(lhs->GetType()) != PrimitiveKind(rhs->GetType())) {
783 AddError(StringPrintf(
784 "Condition %s %d has inputs of different types: %s, and %s.",
785 op->DebugName(), op->GetId(),
786 Primitive::PrettyDescriptor(lhs->GetType()),
787 Primitive::PrettyDescriptor(rhs->GetType())));
788 }
789 if (!op->IsEqual() && !op->IsNotEqual()) {
790 if ((lhs->GetType() == Primitive::kPrimNot)) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000791 AddError(StringPrintf(
792 "Condition %s %d uses an object as left-hand side input.",
793 op->DebugName(), op->GetId()));
Calin Juravlea4f88312015-04-16 12:57:19 +0100794 } else if (rhs->GetType() == Primitive::kPrimNot) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000795 AddError(StringPrintf(
796 "Condition %s %d uses an object as right-hand side input.",
797 op->DebugName(), op->GetId()));
Roland Levillainaecbd262015-01-19 12:44:01 +0000798 }
Nicolas Geoffray9ee66182015-01-16 12:35:40 +0000799 }
Nicolas Geoffray31596742014-11-24 15:28:45 +0000800}
801
802void SSAChecker::VisitBinaryOperation(HBinaryOperation* op) {
803 VisitInstruction(op);
804 if (op->IsUShr() || op->IsShr() || op->IsShl()) {
805 if (PrimitiveKind(op->InputAt(1)->GetType()) != Primitive::kPrimInt) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000806 AddError(StringPrintf(
807 "Shift operation %s %d has a non-int kind second input: "
808 "%s of type %s.",
809 op->DebugName(), op->GetId(),
810 op->InputAt(1)->DebugName(),
811 Primitive::PrettyDescriptor(op->InputAt(1)->GetType())));
Nicolas Geoffray31596742014-11-24 15:28:45 +0000812 }
813 } else {
Roland Levillain4c0eb422015-04-24 16:43:49 +0100814 if (PrimitiveKind(op->InputAt(0)->GetType()) != PrimitiveKind(op->InputAt(1)->GetType())) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000815 AddError(StringPrintf(
816 "Binary operation %s %d has inputs of different types: "
817 "%s, and %s.",
818 op->DebugName(), op->GetId(),
819 Primitive::PrettyDescriptor(op->InputAt(0)->GetType()),
820 Primitive::PrettyDescriptor(op->InputAt(1)->GetType())));
Nicolas Geoffray31596742014-11-24 15:28:45 +0000821 }
822 }
823
824 if (op->IsCompare()) {
825 if (op->GetType() != Primitive::kPrimInt) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000826 AddError(StringPrintf(
827 "Compare operation %d has a non-int result type: %s.",
828 op->GetId(),
829 Primitive::PrettyDescriptor(op->GetType())));
Nicolas Geoffray31596742014-11-24 15:28:45 +0000830 }
831 } else {
832 // Use the first input, so that we can also make this check for shift operations.
833 if (PrimitiveKind(op->GetType()) != PrimitiveKind(op->InputAt(0)->GetType())) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000834 AddError(StringPrintf(
835 "Binary operation %s %d has a result type different "
836 "from its input type: %s vs %s.",
837 op->DebugName(), op->GetId(),
838 Primitive::PrettyDescriptor(op->GetType()),
Roland Levillain4c0eb422015-04-24 16:43:49 +0100839 Primitive::PrettyDescriptor(op->InputAt(0)->GetType())));
Nicolas Geoffray31596742014-11-24 15:28:45 +0000840 }
841 }
842}
843
David Brazdil8d5b8b22015-03-24 10:51:52 +0000844void SSAChecker::VisitConstant(HConstant* instruction) {
845 HBasicBlock* block = instruction->GetBlock();
846 if (!block->IsEntryBlock()) {
847 AddError(StringPrintf(
848 "%s %d should be in the entry block but is in block %d.",
849 instruction->DebugName(),
850 instruction->GetId(),
851 block->GetBlockId()));
852 }
853}
854
Roland Levillainccc07a92014-09-16 14:48:16 +0100855} // namespace art