blob: ef10428c0f9e656cbe7b2d131e69da3722e904ba [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>
Roland Levillainccc07a92014-09-16 14:48:16 +010021
Roland Levillain7e53b412014-09-23 10:50:22 +010022#include "base/bit_vector-inl.h"
Roland Levillain5c4405e2015-01-21 11:39:58 +000023#include "base/stringprintf.h"
Roland Levillain7e53b412014-09-23 10:50:22 +010024
Roland Levillainccc07a92014-09-16 14:48:16 +010025namespace art {
26
27void GraphChecker::VisitBasicBlock(HBasicBlock* block) {
28 current_block_ = block;
29
30 // Check consistency with respect to predecessors of `block`.
31 const GrowableArray<HBasicBlock*>& predecessors = block->GetPredecessors();
32 std::map<HBasicBlock*, size_t> predecessors_count;
33 for (size_t i = 0, e = predecessors.Size(); i < e; ++i) {
34 HBasicBlock* p = predecessors.Get(i);
35 ++predecessors_count[p];
36 }
37 for (auto& pc : predecessors_count) {
38 HBasicBlock* p = pc.first;
39 size_t p_count_in_block_predecessors = pc.second;
40 const GrowableArray<HBasicBlock*>& p_successors = p->GetSuccessors();
41 size_t block_count_in_p_successors = 0;
42 for (size_t j = 0, f = p_successors.Size(); j < f; ++j) {
43 if (p_successors.Get(j) == block) {
44 ++block_count_in_p_successors;
45 }
46 }
47 if (p_count_in_block_predecessors != block_count_in_p_successors) {
Roland Levillain5c4405e2015-01-21 11:39:58 +000048 AddError(StringPrintf(
49 "Block %d lists %zu occurrences of block %d in its predecessors, whereas "
50 "block %d lists %zu occurrences of block %d in its successors.",
51 block->GetBlockId(), p_count_in_block_predecessors, p->GetBlockId(),
52 p->GetBlockId(), block_count_in_p_successors, block->GetBlockId()));
Roland Levillainccc07a92014-09-16 14:48:16 +010053 }
54 }
55
56 // Check consistency with respect to successors of `block`.
57 const GrowableArray<HBasicBlock*>& successors = block->GetSuccessors();
58 std::map<HBasicBlock*, size_t> successors_count;
59 for (size_t i = 0, e = successors.Size(); i < e; ++i) {
60 HBasicBlock* s = successors.Get(i);
61 ++successors_count[s];
62 }
63 for (auto& sc : successors_count) {
64 HBasicBlock* s = sc.first;
65 size_t s_count_in_block_successors = sc.second;
66 const GrowableArray<HBasicBlock*>& s_predecessors = s->GetPredecessors();
67 size_t block_count_in_s_predecessors = 0;
68 for (size_t j = 0, f = s_predecessors.Size(); j < f; ++j) {
69 if (s_predecessors.Get(j) == block) {
70 ++block_count_in_s_predecessors;
71 }
72 }
73 if (s_count_in_block_successors != block_count_in_s_predecessors) {
Roland Levillain5c4405e2015-01-21 11:39:58 +000074 AddError(StringPrintf(
75 "Block %d lists %zu occurrences of block %d in its successors, whereas "
76 "block %d lists %zu occurrences of block %d in its predecessors.",
77 block->GetBlockId(), s_count_in_block_successors, s->GetBlockId(),
78 s->GetBlockId(), block_count_in_s_predecessors, block->GetBlockId()));
Roland Levillainccc07a92014-09-16 14:48:16 +010079 }
80 }
81
82 // Ensure `block` ends with a branch instruction.
83 HInstruction* last_inst = block->GetLastInstruction();
84 if (last_inst == nullptr || !last_inst->IsControlFlow()) {
Roland Levillain5c4405e2015-01-21 11:39:58 +000085 AddError(StringPrintf("Block %d does not end with a branch instruction.",
86 block->GetBlockId()));
Roland Levillainccc07a92014-09-16 14:48:16 +010087 }
88
89 // Visit this block's list of phis.
90 for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) {
91 // Ensure this block's list of phis contains only phis.
92 if (!it.Current()->IsPhi()) {
Roland Levillain5c4405e2015-01-21 11:39:58 +000093 AddError(StringPrintf("Block %d has a non-phi in its phi list.",
94 current_block_->GetBlockId()));
Roland Levillainccc07a92014-09-16 14:48:16 +010095 }
96 it.Current()->Accept(this);
97 }
98
99 // Visit this block's list of instructions.
100 for (HInstructionIterator it(block->GetInstructions()); !it.Done();
101 it.Advance()) {
102 // Ensure this block's list of instructions does not contains phis.
103 if (it.Current()->IsPhi()) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000104 AddError(StringPrintf("Block %d has a phi in its non-phi list.",
105 current_block_->GetBlockId()));
Roland Levillainccc07a92014-09-16 14:48:16 +0100106 }
107 it.Current()->Accept(this);
108 }
109}
110
111void GraphChecker::VisitInstruction(HInstruction* instruction) {
Nicolas Geoffray7c5367b2014-12-17 10:13:46 +0000112 if (seen_ids_.IsBitSet(instruction->GetId())) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000113 AddError(StringPrintf("Instruction id %d is duplicate in graph.",
114 instruction->GetId()));
Nicolas Geoffray7c5367b2014-12-17 10:13:46 +0000115 } else {
116 seen_ids_.SetBit(instruction->GetId());
117 }
118
Roland Levillainccc07a92014-09-16 14:48:16 +0100119 // Ensure `instruction` is associated with `current_block_`.
Roland Levillain5c4405e2015-01-21 11:39:58 +0000120 if (instruction->GetBlock() == nullptr) {
121 AddError(StringPrintf("%s %d in block %d not associated with any block.",
122 instruction->IsPhi() ? "Phi" : "Instruction",
123 instruction->GetId(),
124 current_block_->GetBlockId()));
125 } else if (instruction->GetBlock() != current_block_) {
126 AddError(StringPrintf("%s %d in block %d associated with block %d.",
127 instruction->IsPhi() ? "Phi" : "Instruction",
128 instruction->GetId(),
129 current_block_->GetBlockId(),
130 instruction->GetBlock()->GetBlockId()));
Roland Levillainccc07a92014-09-16 14:48:16 +0100131 }
Roland Levillain6b469232014-09-25 10:10:38 +0100132
133 // Ensure the inputs of `instruction` are defined in a block of the graph.
134 for (HInputIterator input_it(instruction); !input_it.Done();
135 input_it.Advance()) {
136 HInstruction* input = input_it.Current();
137 const HInstructionList& list = input->IsPhi()
138 ? input->GetBlock()->GetPhis()
139 : input->GetBlock()->GetInstructions();
140 if (!list.Contains(input)) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000141 AddError(StringPrintf("Input %d of instruction %d is not defined "
142 "in a basic block of the control-flow graph.",
143 input->GetId(),
144 instruction->GetId()));
Roland Levillain6b469232014-09-25 10:10:38 +0100145 }
146 }
147
148 // Ensure the uses of `instruction` are defined in a block of the graph.
David Brazdiled596192015-01-23 10:39:45 +0000149 for (HUseIterator<HInstruction*> use_it(instruction->GetUses());
Roland Levillain6b469232014-09-25 10:10:38 +0100150 !use_it.Done(); use_it.Advance()) {
151 HInstruction* use = use_it.Current()->GetUser();
152 const HInstructionList& list = use->IsPhi()
153 ? use->GetBlock()->GetPhis()
154 : use->GetBlock()->GetInstructions();
155 if (!list.Contains(use)) {
Nicolas Geoffray276d9da2015-02-02 18:24:11 +0000156 AddError(StringPrintf("User %s:%d of instruction %d is not defined "
Roland Levillain5c4405e2015-01-21 11:39:58 +0000157 "in a basic block of the control-flow graph.",
Nicolas Geoffray276d9da2015-02-02 18:24:11 +0000158 use->DebugName(),
Roland Levillain5c4405e2015-01-21 11:39:58 +0000159 use->GetId(),
160 instruction->GetId()));
Roland Levillain6b469232014-09-25 10:10:38 +0100161 }
162 }
Roland Levillainccc07a92014-09-16 14:48:16 +0100163}
164
165void SSAChecker::VisitBasicBlock(HBasicBlock* block) {
166 super_type::VisitBasicBlock(block);
167
168 // Ensure there is no critical edge (i.e., an edge connecting a
169 // block with multiple successors to a block with multiple
170 // predecessors).
171 if (block->GetSuccessors().Size() > 1) {
172 for (size_t j = 0; j < block->GetSuccessors().Size(); ++j) {
173 HBasicBlock* successor = block->GetSuccessors().Get(j);
174 if (successor->GetPredecessors().Size() > 1) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000175 AddError(StringPrintf("Critical edge between blocks %d and %d.",
176 block->GetBlockId(),
177 successor->GetBlockId()));
Roland Levillainccc07a92014-09-16 14:48:16 +0100178 }
179 }
180 }
Roland Levillain6b879dd2014-09-22 17:13:44 +0100181
182 if (block->IsLoopHeader()) {
183 CheckLoop(block);
184 }
185}
186
187void SSAChecker::CheckLoop(HBasicBlock* loop_header) {
188 int id = loop_header->GetBlockId();
189
190 // Ensure the pre-header block is first in the list of
191 // predecessors of a loop header.
192 if (!loop_header->IsLoopPreHeaderFirstPredecessor()) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000193 AddError(StringPrintf(
194 "Loop pre-header is not the first predecessor of the loop header %d.",
195 id));
Roland Levillain6b879dd2014-09-22 17:13:44 +0100196 }
197
198 // Ensure the loop header has only two predecessors and that only the
199 // second one is a back edge.
Roland Levillain5c4405e2015-01-21 11:39:58 +0000200 size_t num_preds = loop_header->GetPredecessors().Size();
201 if (num_preds < 2) {
202 AddError(StringPrintf(
203 "Loop header %d has less than two predecessors: %zu.",
204 id,
205 num_preds));
206 } else if (num_preds > 2) {
207 AddError(StringPrintf(
208 "Loop header %d has more than two predecessors: %zu.",
209 id,
210 num_preds));
Roland Levillain6b879dd2014-09-22 17:13:44 +0100211 } else {
212 HLoopInformation* loop_information = loop_header->GetLoopInformation();
213 HBasicBlock* first_predecessor = loop_header->GetPredecessors().Get(0);
214 if (loop_information->IsBackEdge(first_predecessor)) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000215 AddError(StringPrintf(
216 "First predecessor of loop header %d is a back edge.",
217 id));
Roland Levillain6b879dd2014-09-22 17:13:44 +0100218 }
219 HBasicBlock* second_predecessor = loop_header->GetPredecessors().Get(1);
220 if (!loop_information->IsBackEdge(second_predecessor)) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000221 AddError(StringPrintf(
222 "Second predecessor of loop header %d is not a back edge.",
223 id));
Roland Levillain6b879dd2014-09-22 17:13:44 +0100224 }
225 }
226
227 // Ensure there is only one back edge per loop.
228 size_t num_back_edges =
229 loop_header->GetLoopInformation()->GetBackEdges().Size();
Roland Levillain5c4405e2015-01-21 11:39:58 +0000230 if (num_back_edges == 0) {
231 AddError(StringPrintf(
232 "Loop defined by header %d has no back edge.",
233 id));
234 } else if (num_back_edges > 1) {
235 AddError(StringPrintf(
236 "Loop defined by header %d has several back edges: %zu.",
237 id,
238 num_back_edges));
Roland Levillain6b879dd2014-09-22 17:13:44 +0100239 }
Roland Levillain7e53b412014-09-23 10:50:22 +0100240
241 // Ensure all blocks in the loop are dominated by the loop header.
242 const ArenaBitVector& loop_blocks =
243 loop_header->GetLoopInformation()->GetBlocks();
244 for (uint32_t i : loop_blocks.Indexes()) {
245 HBasicBlock* loop_block = GetGraph()->GetBlocks().Get(i);
246 if (!loop_header->Dominates(loop_block)) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000247 AddError(StringPrintf("Loop block %d not dominated by loop header %d.",
248 loop_block->GetBlockId(),
249 id));
Roland Levillain7e53b412014-09-23 10:50:22 +0100250 }
251 }
Roland Levillainccc07a92014-09-16 14:48:16 +0100252}
253
254void SSAChecker::VisitInstruction(HInstruction* instruction) {
255 super_type::VisitInstruction(instruction);
256
Roland Levillaina8069ce2014-10-01 10:48:29 +0100257 // Ensure an instruction dominates all its uses.
David Brazdiled596192015-01-23 10:39:45 +0000258 for (HUseIterator<HInstruction*> use_it(instruction->GetUses());
Roland Levillaina8069ce2014-10-01 10:48:29 +0100259 !use_it.Done(); use_it.Advance()) {
260 HInstruction* use = use_it.Current()->GetUser();
Roland Levillain6c82d402014-10-13 16:10:27 +0100261 if (!use->IsPhi() && !instruction->StrictlyDominates(use)) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000262 AddError(StringPrintf("Instruction %d in block %d does not dominate "
263 "use %d in block %d.",
264 instruction->GetId(), current_block_->GetBlockId(),
265 use->GetId(), use->GetBlock()->GetBlockId()));
Roland Levillainccc07a92014-09-16 14:48:16 +0100266 }
267 }
Roland Levillaina8069ce2014-10-01 10:48:29 +0100268
269 // Ensure an instruction having an environment is dominated by the
270 // instructions contained in the environment.
271 HEnvironment* environment = instruction->GetEnvironment();
272 if (environment != nullptr) {
273 for (size_t i = 0, e = environment->Size(); i < e; ++i) {
274 HInstruction* env_instruction = environment->GetInstructionAt(i);
275 if (env_instruction != nullptr
Roland Levillain6c82d402014-10-13 16:10:27 +0100276 && !env_instruction->StrictlyDominates(instruction)) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000277 AddError(StringPrintf("Instruction %d in environment of instruction %d "
278 "from block %d does not dominate instruction %d.",
279 env_instruction->GetId(),
280 instruction->GetId(),
281 current_block_->GetBlockId(),
282 instruction->GetId()));
Roland Levillaina8069ce2014-10-01 10:48:29 +0100283 }
284 }
285 }
Roland Levillainccc07a92014-09-16 14:48:16 +0100286}
287
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000288static Primitive::Type PrimitiveKind(Primitive::Type type) {
289 switch (type) {
290 case Primitive::kPrimBoolean:
291 case Primitive::kPrimByte:
292 case Primitive::kPrimShort:
293 case Primitive::kPrimChar:
294 case Primitive::kPrimInt:
295 return Primitive::kPrimInt;
296 default:
297 return type;
298 }
299}
300
Roland Levillain6b879dd2014-09-22 17:13:44 +0100301void SSAChecker::VisitPhi(HPhi* phi) {
302 VisitInstruction(phi);
303
304 // Ensure the first input of a phi is not itself.
305 if (phi->InputAt(0) == phi) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000306 AddError(StringPrintf("Loop phi %d in block %d is its own first input.",
307 phi->GetId(),
308 phi->GetBlock()->GetBlockId()));
Roland Levillain6b879dd2014-09-22 17:13:44 +0100309 }
310
Roland Levillain5c4405e2015-01-21 11:39:58 +0000311 // Ensure the number of inputs of a phi is the same as the number of
Roland Levillain6b879dd2014-09-22 17:13:44 +0100312 // its predecessors.
313 const GrowableArray<HBasicBlock*>& predecessors =
314 phi->GetBlock()->GetPredecessors();
315 if (phi->InputCount() != predecessors.Size()) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000316 AddError(StringPrintf(
317 "Phi %d in block %d has %zu inputs, "
318 "but block %d has %zu predecessors.",
319 phi->GetId(), phi->GetBlock()->GetBlockId(), phi->InputCount(),
320 phi->GetBlock()->GetBlockId(), predecessors.Size()));
Roland Levillain6b879dd2014-09-22 17:13:44 +0100321 } else {
322 // Ensure phi input at index I either comes from the Ith
323 // predecessor or from a block that dominates this predecessor.
324 for (size_t i = 0, e = phi->InputCount(); i < e; ++i) {
325 HInstruction* input = phi->InputAt(i);
326 HBasicBlock* predecessor = predecessors.Get(i);
327 if (!(input->GetBlock() == predecessor
328 || input->GetBlock()->Dominates(predecessor))) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000329 AddError(StringPrintf(
330 "Input %d at index %zu of phi %d from block %d is not defined in "
331 "predecessor number %zu nor in a block dominating it.",
332 input->GetId(), i, phi->GetId(), phi->GetBlock()->GetBlockId(),
333 i));
Roland Levillain6b879dd2014-09-22 17:13:44 +0100334 }
335 }
336 }
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000337 // Ensure that the inputs have the same primitive kind as the phi.
338 for (size_t i = 0, e = phi->InputCount(); i < e; ++i) {
339 HInstruction* input = phi->InputAt(i);
340 if (PrimitiveKind(input->GetType()) != PrimitiveKind(phi->GetType())) {
341 AddError(StringPrintf(
342 "Input %d at index %zu of phi %d from block %d does not have the "
343 "same type as the phi: %s versus %s",
344 input->GetId(), i, phi->GetId(), phi->GetBlock()->GetBlockId(),
345 Primitive::PrettyDescriptor(input->GetType()),
346 Primitive::PrettyDescriptor(phi->GetType())));
347 }
Nicolas Geoffray31596742014-11-24 15:28:45 +0000348 }
349}
350
Nicolas Geoffray9ee66182015-01-16 12:35:40 +0000351void SSAChecker::VisitIf(HIf* instruction) {
352 VisitInstruction(instruction);
353 HInstruction* input = instruction->InputAt(0);
354 if (input->IsIntConstant()) {
355 int value = input->AsIntConstant()->GetValue();
356 if (value != 0 && value != 1) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000357 AddError(StringPrintf(
358 "If instruction %d has a non-Boolean constant input "
359 "whose value is: %d.",
360 instruction->GetId(),
361 value));
Nicolas Geoffray9ee66182015-01-16 12:35:40 +0000362 }
363 } else if (instruction->InputAt(0)->GetType() != Primitive::kPrimBoolean) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000364 AddError(StringPrintf(
365 "If instruction %d has a non-Boolean input type: %s.",
366 instruction->GetId(),
367 Primitive::PrettyDescriptor(instruction->InputAt(0)->GetType())));
Nicolas Geoffray9ee66182015-01-16 12:35:40 +0000368 }
369}
370
Nicolas Geoffray31596742014-11-24 15:28:45 +0000371void SSAChecker::VisitCondition(HCondition* op) {
372 VisitInstruction(op);
Nicolas Geoffray31596742014-11-24 15:28:45 +0000373 if (op->GetType() != Primitive::kPrimBoolean) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000374 AddError(StringPrintf(
375 "Condition %s %d has a non-Boolean result type: %s.",
376 op->DebugName(), op->GetId(),
377 Primitive::PrettyDescriptor(op->GetType())));
Nicolas Geoffray31596742014-11-24 15:28:45 +0000378 }
Nicolas Geoffray9ee66182015-01-16 12:35:40 +0000379 HInstruction* lhs = op->InputAt(0);
380 HInstruction* rhs = op->InputAt(1);
Roland Levillainaecbd262015-01-19 12:44:01 +0000381 if (lhs->GetType() == Primitive::kPrimNot) {
382 if (!op->IsEqual() && !op->IsNotEqual()) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000383 AddError(StringPrintf(
384 "Condition %s %d uses an object as left-hand side input.",
385 op->DebugName(), op->GetId()));
Roland Levillainaecbd262015-01-19 12:44:01 +0000386 }
387 if (rhs->IsIntConstant() && rhs->AsIntConstant()->GetValue() != 0) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000388 AddError(StringPrintf(
389 "Condition %s %d compares an object with a non-zero integer: %d.",
390 op->DebugName(), op->GetId(),
391 rhs->AsIntConstant()->GetValue()));
Nicolas Geoffray9ee66182015-01-16 12:35:40 +0000392 }
Roland Levillainaecbd262015-01-19 12:44:01 +0000393 } else if (rhs->GetType() == Primitive::kPrimNot) {
394 if (!op->IsEqual() && !op->IsNotEqual()) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000395 AddError(StringPrintf(
396 "Condition %s %d uses an object as right-hand side input.",
397 op->DebugName(), op->GetId()));
Roland Levillainaecbd262015-01-19 12:44:01 +0000398 }
399 if (lhs->IsIntConstant() && lhs->AsIntConstant()->GetValue() != 0) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000400 AddError(StringPrintf(
401 "Condition %s %d compares a non-zero integer with an object: %d.",
402 op->DebugName(), op->GetId(),
403 lhs->AsIntConstant()->GetValue()));
Nicolas Geoffray9ee66182015-01-16 12:35:40 +0000404 }
405 } else if (PrimitiveKind(lhs->GetType()) != PrimitiveKind(rhs->GetType())) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000406 AddError(StringPrintf(
407 "Condition %s %d has inputs of different types: "
408 "%s, and %s.",
409 op->DebugName(), op->GetId(),
410 Primitive::PrettyDescriptor(lhs->GetType()),
411 Primitive::PrettyDescriptor(rhs->GetType())));
Nicolas Geoffray9ee66182015-01-16 12:35:40 +0000412 }
Nicolas Geoffray31596742014-11-24 15:28:45 +0000413}
414
415void SSAChecker::VisitBinaryOperation(HBinaryOperation* op) {
416 VisitInstruction(op);
417 if (op->IsUShr() || op->IsShr() || op->IsShl()) {
418 if (PrimitiveKind(op->InputAt(1)->GetType()) != Primitive::kPrimInt) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000419 AddError(StringPrintf(
420 "Shift operation %s %d has a non-int kind second input: "
421 "%s of type %s.",
422 op->DebugName(), op->GetId(),
423 op->InputAt(1)->DebugName(),
424 Primitive::PrettyDescriptor(op->InputAt(1)->GetType())));
Nicolas Geoffray31596742014-11-24 15:28:45 +0000425 }
426 } else {
427 if (PrimitiveKind(op->InputAt(1)->GetType()) != PrimitiveKind(op->InputAt(0)->GetType())) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000428 AddError(StringPrintf(
429 "Binary operation %s %d has inputs of different types: "
430 "%s, and %s.",
431 op->DebugName(), op->GetId(),
432 Primitive::PrettyDescriptor(op->InputAt(0)->GetType()),
433 Primitive::PrettyDescriptor(op->InputAt(1)->GetType())));
Nicolas Geoffray31596742014-11-24 15:28:45 +0000434 }
435 }
436
437 if (op->IsCompare()) {
438 if (op->GetType() != Primitive::kPrimInt) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000439 AddError(StringPrintf(
440 "Compare operation %d has a non-int result type: %s.",
441 op->GetId(),
442 Primitive::PrettyDescriptor(op->GetType())));
Nicolas Geoffray31596742014-11-24 15:28:45 +0000443 }
444 } else {
445 // Use the first input, so that we can also make this check for shift operations.
446 if (PrimitiveKind(op->GetType()) != PrimitiveKind(op->InputAt(0)->GetType())) {
Roland Levillain5c4405e2015-01-21 11:39:58 +0000447 AddError(StringPrintf(
448 "Binary operation %s %d has a result type different "
449 "from its input type: %s vs %s.",
450 op->DebugName(), op->GetId(),
451 Primitive::PrettyDescriptor(op->GetType()),
452 Primitive::PrettyDescriptor(op->InputAt(1)->GetType())));
Nicolas Geoffray31596742014-11-24 15:28:45 +0000453 }
454 }
455}
456
Roland Levillainccc07a92014-09-16 14:48:16 +0100457} // namespace art