Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1 | /* |
| 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 Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 19 | #include <map> |
Nicolas Geoffray | 7c5367b | 2014-12-17 10:13:46 +0000 | [diff] [blame] | 20 | #include <string> |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 21 | #include <sstream> |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 22 | |
Roland Levillain | 7e53b41 | 2014-09-23 10:50:22 +0100 | [diff] [blame] | 23 | #include "base/bit_vector-inl.h" |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 24 | #include "base/stringprintf.h" |
Roland Levillain | 7e53b41 | 2014-09-23 10:50:22 +0100 | [diff] [blame] | 25 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 26 | namespace art { |
| 27 | |
| 28 | void GraphChecker::VisitBasicBlock(HBasicBlock* block) { |
| 29 | current_block_ = block; |
| 30 | |
| 31 | // Check consistency with respect to predecessors of `block`. |
| 32 | const GrowableArray<HBasicBlock*>& predecessors = block->GetPredecessors(); |
| 33 | std::map<HBasicBlock*, size_t> predecessors_count; |
| 34 | for (size_t i = 0, e = predecessors.Size(); i < e; ++i) { |
| 35 | HBasicBlock* p = predecessors.Get(i); |
| 36 | ++predecessors_count[p]; |
| 37 | } |
| 38 | for (auto& pc : predecessors_count) { |
| 39 | HBasicBlock* p = pc.first; |
| 40 | size_t p_count_in_block_predecessors = pc.second; |
| 41 | const GrowableArray<HBasicBlock*>& p_successors = p->GetSuccessors(); |
| 42 | size_t block_count_in_p_successors = 0; |
| 43 | for (size_t j = 0, f = p_successors.Size(); j < f; ++j) { |
| 44 | if (p_successors.Get(j) == block) { |
| 45 | ++block_count_in_p_successors; |
| 46 | } |
| 47 | } |
| 48 | if (p_count_in_block_predecessors != block_count_in_p_successors) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 49 | AddError(StringPrintf( |
| 50 | "Block %d lists %zu occurrences of block %d in its predecessors, whereas " |
| 51 | "block %d lists %zu occurrences of block %d in its successors.", |
| 52 | block->GetBlockId(), p_count_in_block_predecessors, p->GetBlockId(), |
| 53 | p->GetBlockId(), block_count_in_p_successors, block->GetBlockId())); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
| 57 | // Check consistency with respect to successors of `block`. |
| 58 | const GrowableArray<HBasicBlock*>& successors = block->GetSuccessors(); |
| 59 | std::map<HBasicBlock*, size_t> successors_count; |
| 60 | for (size_t i = 0, e = successors.Size(); i < e; ++i) { |
| 61 | HBasicBlock* s = successors.Get(i); |
| 62 | ++successors_count[s]; |
| 63 | } |
| 64 | for (auto& sc : successors_count) { |
| 65 | HBasicBlock* s = sc.first; |
| 66 | size_t s_count_in_block_successors = sc.second; |
| 67 | const GrowableArray<HBasicBlock*>& s_predecessors = s->GetPredecessors(); |
| 68 | size_t block_count_in_s_predecessors = 0; |
| 69 | for (size_t j = 0, f = s_predecessors.Size(); j < f; ++j) { |
| 70 | if (s_predecessors.Get(j) == block) { |
| 71 | ++block_count_in_s_predecessors; |
| 72 | } |
| 73 | } |
| 74 | if (s_count_in_block_successors != block_count_in_s_predecessors) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 75 | AddError(StringPrintf( |
| 76 | "Block %d lists %zu occurrences of block %d in its successors, whereas " |
| 77 | "block %d lists %zu occurrences of block %d in its predecessors.", |
| 78 | block->GetBlockId(), s_count_in_block_successors, s->GetBlockId(), |
| 79 | s->GetBlockId(), block_count_in_s_predecessors, block->GetBlockId())); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
| 83 | // Ensure `block` ends with a branch instruction. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 84 | // This invariant is not enforced on non-SSA graphs. Graph built from DEX with |
| 85 | // dead code that falls out of the method will not end with a control-flow |
| 86 | // instruction. Such code is removed during the SSA-building DCE phase. |
| 87 | if (GetGraph()->IsInSsaForm() && !block->EndsWithControlFlowInstruction()) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 88 | AddError(StringPrintf("Block %d does not end with a branch instruction.", |
| 89 | block->GetBlockId())); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | // Visit this block's list of phis. |
| 93 | for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) { |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 94 | HInstruction* current = it.Current(); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 95 | // Ensure this block's list of phis contains only phis. |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 96 | if (!current->IsPhi()) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 97 | AddError(StringPrintf("Block %d has a non-phi in its phi list.", |
| 98 | current_block_->GetBlockId())); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 99 | } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 100 | if (current->GetNext() == nullptr && current != block->GetLastPhi()) { |
| 101 | AddError(StringPrintf("The recorded last phi of block %d does not match " |
| 102 | "the actual last phi %d.", |
| 103 | current_block_->GetBlockId(), |
| 104 | current->GetId())); |
| 105 | } |
| 106 | current->Accept(this); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | // Visit this block's list of instructions. |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 110 | for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) { |
| 111 | HInstruction* current = it.Current(); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 112 | // Ensure this block's list of instructions does not contains phis. |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 113 | if (current->IsPhi()) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 114 | AddError(StringPrintf("Block %d has a phi in its non-phi list.", |
| 115 | current_block_->GetBlockId())); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 116 | } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 117 | if (current->GetNext() == nullptr && current != block->GetLastInstruction()) { |
| 118 | AddError(StringPrintf("The recorded last instruction of block %d does not match " |
| 119 | "the actual last instruction %d.", |
| 120 | current_block_->GetBlockId(), |
| 121 | current->GetId())); |
| 122 | } |
| 123 | current->Accept(this); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 127 | void GraphChecker::VisitBoundsCheck(HBoundsCheck* check) { |
| 128 | if (!GetGraph()->HasBoundsChecks()) { |
| 129 | AddError(StringPrintf("Instruction %s:%d is a HBoundsCheck, " |
| 130 | "but HasBoundsChecks() returns false", |
| 131 | check->DebugName(), |
| 132 | check->GetId())); |
| 133 | } |
| 134 | |
| 135 | // Perform the instruction base checks too. |
| 136 | VisitInstruction(check); |
| 137 | } |
| 138 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 139 | void GraphChecker::VisitInstruction(HInstruction* instruction) { |
Nicolas Geoffray | 7c5367b | 2014-12-17 10:13:46 +0000 | [diff] [blame] | 140 | if (seen_ids_.IsBitSet(instruction->GetId())) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 141 | AddError(StringPrintf("Instruction id %d is duplicate in graph.", |
| 142 | instruction->GetId())); |
Nicolas Geoffray | 7c5367b | 2014-12-17 10:13:46 +0000 | [diff] [blame] | 143 | } else { |
| 144 | seen_ids_.SetBit(instruction->GetId()); |
| 145 | } |
| 146 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 147 | // Ensure `instruction` is associated with `current_block_`. |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 148 | if (instruction->GetBlock() == nullptr) { |
| 149 | AddError(StringPrintf("%s %d in block %d not associated with any block.", |
| 150 | instruction->IsPhi() ? "Phi" : "Instruction", |
| 151 | instruction->GetId(), |
| 152 | current_block_->GetBlockId())); |
| 153 | } else if (instruction->GetBlock() != current_block_) { |
| 154 | AddError(StringPrintf("%s %d in block %d associated with block %d.", |
| 155 | instruction->IsPhi() ? "Phi" : "Instruction", |
| 156 | instruction->GetId(), |
| 157 | current_block_->GetBlockId(), |
| 158 | instruction->GetBlock()->GetBlockId())); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 159 | } |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 160 | |
| 161 | // Ensure the inputs of `instruction` are defined in a block of the graph. |
| 162 | for (HInputIterator input_it(instruction); !input_it.Done(); |
| 163 | input_it.Advance()) { |
| 164 | HInstruction* input = input_it.Current(); |
| 165 | const HInstructionList& list = input->IsPhi() |
| 166 | ? input->GetBlock()->GetPhis() |
| 167 | : input->GetBlock()->GetInstructions(); |
| 168 | if (!list.Contains(input)) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 169 | AddError(StringPrintf("Input %d of instruction %d is not defined " |
| 170 | "in a basic block of the control-flow graph.", |
| 171 | input->GetId(), |
| 172 | instruction->GetId())); |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 176 | // Ensure the uses of `instruction` are defined in a block of the graph, |
| 177 | // and the entry in the use list is consistent. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 178 | for (HUseIterator<HInstruction*> use_it(instruction->GetUses()); |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 179 | !use_it.Done(); use_it.Advance()) { |
| 180 | HInstruction* use = use_it.Current()->GetUser(); |
| 181 | const HInstructionList& list = use->IsPhi() |
| 182 | ? use->GetBlock()->GetPhis() |
| 183 | : use->GetBlock()->GetInstructions(); |
| 184 | if (!list.Contains(use)) { |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 185 | AddError(StringPrintf("User %s:%d of instruction %d is not defined " |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 186 | "in a basic block of the control-flow graph.", |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 187 | use->DebugName(), |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 188 | use->GetId(), |
| 189 | instruction->GetId())); |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 190 | } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 191 | size_t use_index = use_it.Current()->GetIndex(); |
| 192 | if ((use_index >= use->InputCount()) || (use->InputAt(use_index) != instruction)) { |
| 193 | AddError(StringPrintf("User %s:%d of instruction %d has a wrong " |
| 194 | "UseListNode index.", |
| 195 | use->DebugName(), |
| 196 | use->GetId(), |
| 197 | instruction->GetId())); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | // Ensure the environment uses entries are consistent. |
| 202 | for (HUseIterator<HEnvironment*> use_it(instruction->GetEnvUses()); |
| 203 | !use_it.Done(); use_it.Advance()) { |
| 204 | HEnvironment* use = use_it.Current()->GetUser(); |
| 205 | size_t use_index = use_it.Current()->GetIndex(); |
| 206 | if ((use_index >= use->Size()) || (use->GetInstructionAt(use_index) != instruction)) { |
| 207 | AddError(StringPrintf("Environment user of %s:%d has a wrong " |
| 208 | "UseListNode index.", |
| 209 | instruction->DebugName(), |
| 210 | instruction->GetId())); |
| 211 | } |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 212 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 213 | |
| 214 | // Ensure 'instruction' has pointers to its inputs' use entries. |
| 215 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 216 | HUserRecord<HInstruction*> input_record = instruction->InputRecordAt(i); |
| 217 | HInstruction* input = input_record.GetInstruction(); |
| 218 | HUseListNode<HInstruction*>* use_node = input_record.GetUseNode(); |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 219 | size_t use_index = use_node->GetIndex(); |
| 220 | if ((use_node == nullptr) |
| 221 | || !input->GetUses().Contains(use_node) |
| 222 | || (use_index >= e) |
| 223 | || (use_index != i)) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 224 | AddError(StringPrintf("Instruction %s:%d has an invalid pointer to use entry " |
| 225 | "at input %u (%s:%d).", |
| 226 | instruction->DebugName(), |
| 227 | instruction->GetId(), |
| 228 | static_cast<unsigned>(i), |
| 229 | input->DebugName(), |
| 230 | input->GetId())); |
| 231 | } |
| 232 | } |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 233 | } |
| 234 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 235 | void GraphChecker::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 236 | VisitInstruction(invoke); |
| 237 | |
| 238 | if (invoke->IsStaticWithExplicitClinitCheck()) { |
| 239 | size_t last_input_index = invoke->InputCount() - 1; |
| 240 | HInstruction* last_input = invoke->InputAt(last_input_index); |
| 241 | if (last_input == nullptr) { |
| 242 | AddError(StringPrintf("Static invoke %s:%d marked as having an explicit clinit check " |
| 243 | "has a null pointer as last input.", |
| 244 | invoke->DebugName(), |
| 245 | invoke->GetId())); |
| 246 | } |
| 247 | if (!last_input->IsClinitCheck() && !last_input->IsLoadClass()) { |
| 248 | AddError(StringPrintf("Static invoke %s:%d marked as having an explicit clinit check " |
| 249 | "has a last instruction (%s:%d) which is neither a clinit check " |
| 250 | "nor a load class instruction.", |
| 251 | invoke->DebugName(), |
| 252 | invoke->GetId(), |
| 253 | last_input->DebugName(), |
| 254 | last_input->GetId())); |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 259 | void GraphChecker::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | f9a1995 | 2015-06-29 13:43:54 +0100 | [diff] [blame^] | 260 | VisitInstruction(ret); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 261 | if (!ret->GetBlock()->GetSingleSuccessor()->IsExitBlock()) { |
| 262 | AddError(StringPrintf("%s:%d does not jump to the exit block.", |
| 263 | ret->DebugName(), |
| 264 | ret->GetId())); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | void GraphChecker::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | f9a1995 | 2015-06-29 13:43:54 +0100 | [diff] [blame^] | 269 | VisitInstruction(ret); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 270 | if (!ret->GetBlock()->GetSingleSuccessor()->IsExitBlock()) { |
| 271 | AddError(StringPrintf("%s:%d does not jump to the exit block.", |
| 272 | ret->DebugName(), |
| 273 | ret->GetId())); |
| 274 | } |
| 275 | } |
| 276 | |
Nicolas Geoffray | f9a1995 | 2015-06-29 13:43:54 +0100 | [diff] [blame^] | 277 | void GraphChecker::VisitCheckCast(HCheckCast* check) { |
| 278 | VisitInstruction(check); |
| 279 | HInstruction* input = check->InputAt(1); |
| 280 | if (!input->IsLoadClass()) { |
| 281 | AddError(StringPrintf("%s:%d expects a HLoadClass as second input, not %s:%d.", |
| 282 | check->DebugName(), |
| 283 | check->GetId(), |
| 284 | input->DebugName(), |
| 285 | input->GetId())); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | void GraphChecker::VisitInstanceOf(HInstanceOf* instruction) { |
| 290 | VisitInstruction(instruction); |
| 291 | HInstruction* input = instruction->InputAt(1); |
| 292 | if (!input->IsLoadClass()) { |
| 293 | AddError(StringPrintf("%s:%d expects a HLoadClass as second input, not %s:%d.", |
| 294 | instruction->DebugName(), |
| 295 | instruction->GetId(), |
| 296 | input->DebugName(), |
| 297 | input->GetId())); |
| 298 | } |
| 299 | } |
| 300 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 301 | void SSAChecker::VisitBasicBlock(HBasicBlock* block) { |
| 302 | super_type::VisitBasicBlock(block); |
| 303 | |
| 304 | // Ensure there is no critical edge (i.e., an edge connecting a |
| 305 | // block with multiple successors to a block with multiple |
| 306 | // predecessors). |
| 307 | if (block->GetSuccessors().Size() > 1) { |
| 308 | for (size_t j = 0; j < block->GetSuccessors().Size(); ++j) { |
| 309 | HBasicBlock* successor = block->GetSuccessors().Get(j); |
| 310 | if (successor->GetPredecessors().Size() > 1) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 311 | AddError(StringPrintf("Critical edge between blocks %d and %d.", |
| 312 | block->GetBlockId(), |
| 313 | successor->GetBlockId())); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | } |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 317 | |
Calin Juravle | 1d8b49f | 2015-05-12 12:40:07 +0000 | [diff] [blame] | 318 | // Check Phi uniqueness (no two Phis with the same type refer to the same register). |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 319 | for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) { |
| 320 | HPhi* phi = it.Current()->AsPhi(); |
| 321 | if (phi->GetNextEquivalentPhiWithSameType() != nullptr) { |
| 322 | std::stringstream type_str; |
| 323 | type_str << phi->GetType(); |
| 324 | AddError(StringPrintf("Equivalent phi (%d) found for VReg %d with type: %s", |
| 325 | phi->GetId(), phi->GetRegNumber(), type_str.str().c_str())); |
| 326 | } |
| 327 | } |
| 328 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 329 | if (block->IsLoopHeader()) { |
| 330 | CheckLoop(block); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | void SSAChecker::CheckLoop(HBasicBlock* loop_header) { |
| 335 | int id = loop_header->GetBlockId(); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 336 | HLoopInformation* loop_information = loop_header->GetLoopInformation(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 337 | |
| 338 | // Ensure the pre-header block is first in the list of |
| 339 | // predecessors of a loop header. |
| 340 | if (!loop_header->IsLoopPreHeaderFirstPredecessor()) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 341 | AddError(StringPrintf( |
| 342 | "Loop pre-header is not the first predecessor of the loop header %d.", |
| 343 | id)); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 344 | } |
| 345 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 346 | // Ensure the loop header has only one incoming branch and the remaining |
| 347 | // predecessors are back edges. |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 348 | size_t num_preds = loop_header->GetPredecessors().Size(); |
| 349 | if (num_preds < 2) { |
| 350 | AddError(StringPrintf( |
| 351 | "Loop header %d has less than two predecessors: %zu.", |
| 352 | id, |
| 353 | num_preds)); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 354 | } else { |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 355 | HBasicBlock* first_predecessor = loop_header->GetPredecessors().Get(0); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 356 | if (loop_information->IsBackEdge(*first_predecessor)) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 357 | AddError(StringPrintf( |
| 358 | "First predecessor of loop header %d is a back edge.", |
| 359 | id)); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 360 | } |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 361 | for (size_t i = 1, e = loop_header->GetPredecessors().Size(); i < e; ++i) { |
| 362 | HBasicBlock* predecessor = loop_header->GetPredecessors().Get(i); |
| 363 | if (!loop_information->IsBackEdge(*predecessor)) { |
| 364 | AddError(StringPrintf( |
| 365 | "Loop header %d has multiple incoming (non back edge) blocks.", |
| 366 | id)); |
| 367 | } |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 368 | } |
| 369 | } |
| 370 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 371 | const ArenaBitVector& loop_blocks = loop_information->GetBlocks(); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 372 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 373 | // Ensure back edges belong to the loop. |
| 374 | size_t num_back_edges = loop_information->GetBackEdges().Size(); |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 375 | if (num_back_edges == 0) { |
| 376 | AddError(StringPrintf( |
| 377 | "Loop defined by header %d has no back edge.", |
| 378 | id)); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 379 | } else { |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 380 | for (size_t i = 0; i < num_back_edges; ++i) { |
| 381 | int back_edge_id = loop_information->GetBackEdges().Get(i)->GetBlockId(); |
| 382 | if (!loop_blocks.IsBitSet(back_edge_id)) { |
| 383 | AddError(StringPrintf( |
| 384 | "Loop defined by header %d has an invalid back edge %d.", |
| 385 | id, |
| 386 | back_edge_id)); |
| 387 | } |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 388 | } |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 389 | } |
Roland Levillain | 7e53b41 | 2014-09-23 10:50:22 +0100 | [diff] [blame] | 390 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 391 | // Ensure all blocks in the loop are live and dominated by the loop header. |
Roland Levillain | 7e53b41 | 2014-09-23 10:50:22 +0100 | [diff] [blame] | 392 | for (uint32_t i : loop_blocks.Indexes()) { |
| 393 | HBasicBlock* loop_block = GetGraph()->GetBlocks().Get(i); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 394 | if (loop_block == nullptr) { |
| 395 | AddError(StringPrintf("Loop defined by header %d contains a previously removed block %d.", |
| 396 | id, |
| 397 | i)); |
| 398 | } else if (!loop_header->Dominates(loop_block)) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 399 | AddError(StringPrintf("Loop block %d not dominated by loop header %d.", |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 400 | i, |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 401 | id)); |
Roland Levillain | 7e53b41 | 2014-09-23 10:50:22 +0100 | [diff] [blame] | 402 | } |
| 403 | } |
David Brazdil | 7d27537 | 2015-04-21 16:36:35 +0100 | [diff] [blame] | 404 | |
| 405 | // If this is a nested loop, ensure the outer loops contain a superset of the blocks. |
| 406 | for (HLoopInformationOutwardIterator it(*loop_header); !it.Done(); it.Advance()) { |
| 407 | HLoopInformation* outer_info = it.Current(); |
| 408 | if (!loop_blocks.IsSubsetOf(&outer_info->GetBlocks())) { |
| 409 | AddError(StringPrintf("Blocks of loop defined by header %d are not a subset of blocks of " |
| 410 | "an outer loop defined by header %d.", |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 411 | id, |
David Brazdil | 7d27537 | 2015-04-21 16:36:35 +0100 | [diff] [blame] | 412 | outer_info->GetHeader()->GetBlockId())); |
| 413 | } |
| 414 | } |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | void SSAChecker::VisitInstruction(HInstruction* instruction) { |
| 418 | super_type::VisitInstruction(instruction); |
| 419 | |
Roland Levillain | a8069ce | 2014-10-01 10:48:29 +0100 | [diff] [blame] | 420 | // Ensure an instruction dominates all its uses. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 421 | for (HUseIterator<HInstruction*> use_it(instruction->GetUses()); |
Roland Levillain | a8069ce | 2014-10-01 10:48:29 +0100 | [diff] [blame] | 422 | !use_it.Done(); use_it.Advance()) { |
| 423 | HInstruction* use = use_it.Current()->GetUser(); |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 424 | if (!use->IsPhi() && !instruction->StrictlyDominates(use)) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 425 | AddError(StringPrintf("Instruction %d in block %d does not dominate " |
| 426 | "use %d in block %d.", |
| 427 | instruction->GetId(), current_block_->GetBlockId(), |
| 428 | use->GetId(), use->GetBlock()->GetBlockId())); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 429 | } |
| 430 | } |
Roland Levillain | a8069ce | 2014-10-01 10:48:29 +0100 | [diff] [blame] | 431 | |
| 432 | // Ensure an instruction having an environment is dominated by the |
| 433 | // instructions contained in the environment. |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 434 | for (HEnvironment* environment = instruction->GetEnvironment(); |
| 435 | environment != nullptr; |
| 436 | environment = environment->GetParent()) { |
Roland Levillain | a8069ce | 2014-10-01 10:48:29 +0100 | [diff] [blame] | 437 | for (size_t i = 0, e = environment->Size(); i < e; ++i) { |
| 438 | HInstruction* env_instruction = environment->GetInstructionAt(i); |
| 439 | if (env_instruction != nullptr |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 440 | && !env_instruction->StrictlyDominates(instruction)) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 441 | AddError(StringPrintf("Instruction %d in environment of instruction %d " |
| 442 | "from block %d does not dominate instruction %d.", |
| 443 | env_instruction->GetId(), |
| 444 | instruction->GetId(), |
| 445 | current_block_->GetBlockId(), |
| 446 | instruction->GetId())); |
Roland Levillain | a8069ce | 2014-10-01 10:48:29 +0100 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | } |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 450 | } |
| 451 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 452 | static Primitive::Type PrimitiveKind(Primitive::Type type) { |
| 453 | switch (type) { |
| 454 | case Primitive::kPrimBoolean: |
| 455 | case Primitive::kPrimByte: |
| 456 | case Primitive::kPrimShort: |
| 457 | case Primitive::kPrimChar: |
| 458 | case Primitive::kPrimInt: |
| 459 | return Primitive::kPrimInt; |
| 460 | default: |
| 461 | return type; |
| 462 | } |
| 463 | } |
| 464 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 465 | void SSAChecker::VisitPhi(HPhi* phi) { |
| 466 | VisitInstruction(phi); |
| 467 | |
| 468 | // Ensure the first input of a phi is not itself. |
| 469 | if (phi->InputAt(0) == phi) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 470 | AddError(StringPrintf("Loop phi %d in block %d is its own first input.", |
| 471 | phi->GetId(), |
| 472 | phi->GetBlock()->GetBlockId())); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 473 | } |
| 474 | |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 475 | // Ensure the number of inputs of a phi is the same as the number of |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 476 | // its predecessors. |
| 477 | const GrowableArray<HBasicBlock*>& predecessors = |
| 478 | phi->GetBlock()->GetPredecessors(); |
| 479 | if (phi->InputCount() != predecessors.Size()) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 480 | AddError(StringPrintf( |
| 481 | "Phi %d in block %d has %zu inputs, " |
| 482 | "but block %d has %zu predecessors.", |
| 483 | phi->GetId(), phi->GetBlock()->GetBlockId(), phi->InputCount(), |
| 484 | phi->GetBlock()->GetBlockId(), predecessors.Size())); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 485 | } else { |
| 486 | // Ensure phi input at index I either comes from the Ith |
| 487 | // predecessor or from a block that dominates this predecessor. |
| 488 | for (size_t i = 0, e = phi->InputCount(); i < e; ++i) { |
| 489 | HInstruction* input = phi->InputAt(i); |
| 490 | HBasicBlock* predecessor = predecessors.Get(i); |
| 491 | if (!(input->GetBlock() == predecessor |
| 492 | || input->GetBlock()->Dominates(predecessor))) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 493 | AddError(StringPrintf( |
| 494 | "Input %d at index %zu of phi %d from block %d is not defined in " |
| 495 | "predecessor number %zu nor in a block dominating it.", |
| 496 | input->GetId(), i, phi->GetId(), phi->GetBlock()->GetBlockId(), |
| 497 | i)); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 501 | // Ensure that the inputs have the same primitive kind as the phi. |
| 502 | for (size_t i = 0, e = phi->InputCount(); i < e; ++i) { |
| 503 | HInstruction* input = phi->InputAt(i); |
| 504 | if (PrimitiveKind(input->GetType()) != PrimitiveKind(phi->GetType())) { |
| 505 | AddError(StringPrintf( |
| 506 | "Input %d at index %zu of phi %d from block %d does not have the " |
| 507 | "same type as the phi: %s versus %s", |
| 508 | input->GetId(), i, phi->GetId(), phi->GetBlock()->GetBlockId(), |
| 509 | Primitive::PrettyDescriptor(input->GetType()), |
| 510 | Primitive::PrettyDescriptor(phi->GetType()))); |
| 511 | } |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 512 | } |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 513 | if (phi->GetType() != HPhi::ToPhiType(phi->GetType())) { |
| 514 | AddError(StringPrintf("Phi %d in block %d does not have an expected phi type: %s", |
| 515 | phi->GetId(), |
| 516 | phi->GetBlock()->GetBlockId(), |
| 517 | Primitive::PrettyDescriptor(phi->GetType()))); |
| 518 | } |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 519 | } |
| 520 | |
David Brazdil | 13b4718 | 2015-04-15 16:29:32 +0100 | [diff] [blame] | 521 | void SSAChecker::HandleBooleanInput(HInstruction* instruction, size_t input_index) { |
| 522 | HInstruction* input = instruction->InputAt(input_index); |
Nicolas Geoffray | 9ee6618 | 2015-01-16 12:35:40 +0000 | [diff] [blame] | 523 | if (input->IsIntConstant()) { |
David Brazdil | 13b4718 | 2015-04-15 16:29:32 +0100 | [diff] [blame] | 524 | int32_t value = input->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 9ee6618 | 2015-01-16 12:35:40 +0000 | [diff] [blame] | 525 | if (value != 0 && value != 1) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 526 | AddError(StringPrintf( |
David Brazdil | 13b4718 | 2015-04-15 16:29:32 +0100 | [diff] [blame] | 527 | "%s instruction %d has a non-Boolean constant input %d whose value is: %d.", |
| 528 | instruction->DebugName(), |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 529 | instruction->GetId(), |
David Brazdil | 13b4718 | 2015-04-15 16:29:32 +0100 | [diff] [blame] | 530 | static_cast<int>(input_index), |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 531 | value)); |
Nicolas Geoffray | 9ee6618 | 2015-01-16 12:35:40 +0000 | [diff] [blame] | 532 | } |
David Brazdil | 2fa194b | 2015-04-20 10:14:42 +0100 | [diff] [blame] | 533 | } else if (input->GetType() == Primitive::kPrimInt |
| 534 | && (input->IsPhi() || input->IsAnd() || input->IsOr() || input->IsXor())) { |
| 535 | // TODO: We need a data-flow analysis to determine if the Phi or |
| 536 | // binary operation is actually Boolean. Allow for now. |
David Brazdil | 13b4718 | 2015-04-15 16:29:32 +0100 | [diff] [blame] | 537 | } else if (input->GetType() != Primitive::kPrimBoolean) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 538 | AddError(StringPrintf( |
David Brazdil | 13b4718 | 2015-04-15 16:29:32 +0100 | [diff] [blame] | 539 | "%s instruction %d has a non-Boolean input %d whose type is: %s.", |
| 540 | instruction->DebugName(), |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 541 | instruction->GetId(), |
David Brazdil | 13b4718 | 2015-04-15 16:29:32 +0100 | [diff] [blame] | 542 | static_cast<int>(input_index), |
| 543 | Primitive::PrettyDescriptor(input->GetType()))); |
Nicolas Geoffray | 9ee6618 | 2015-01-16 12:35:40 +0000 | [diff] [blame] | 544 | } |
| 545 | } |
| 546 | |
David Brazdil | 13b4718 | 2015-04-15 16:29:32 +0100 | [diff] [blame] | 547 | void SSAChecker::VisitIf(HIf* instruction) { |
| 548 | VisitInstruction(instruction); |
| 549 | HandleBooleanInput(instruction, 0); |
| 550 | } |
| 551 | |
| 552 | void SSAChecker::VisitBooleanNot(HBooleanNot* instruction) { |
| 553 | VisitInstruction(instruction); |
| 554 | HandleBooleanInput(instruction, 0); |
| 555 | } |
| 556 | |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 557 | void SSAChecker::VisitCondition(HCondition* op) { |
| 558 | VisitInstruction(op); |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 559 | if (op->GetType() != Primitive::kPrimBoolean) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 560 | AddError(StringPrintf( |
| 561 | "Condition %s %d has a non-Boolean result type: %s.", |
| 562 | op->DebugName(), op->GetId(), |
| 563 | Primitive::PrettyDescriptor(op->GetType()))); |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 564 | } |
Nicolas Geoffray | 9ee6618 | 2015-01-16 12:35:40 +0000 | [diff] [blame] | 565 | HInstruction* lhs = op->InputAt(0); |
| 566 | HInstruction* rhs = op->InputAt(1); |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 567 | if (PrimitiveKind(lhs->GetType()) != PrimitiveKind(rhs->GetType())) { |
| 568 | AddError(StringPrintf( |
| 569 | "Condition %s %d has inputs of different types: %s, and %s.", |
| 570 | op->DebugName(), op->GetId(), |
| 571 | Primitive::PrettyDescriptor(lhs->GetType()), |
| 572 | Primitive::PrettyDescriptor(rhs->GetType()))); |
| 573 | } |
| 574 | if (!op->IsEqual() && !op->IsNotEqual()) { |
| 575 | if ((lhs->GetType() == Primitive::kPrimNot)) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 576 | AddError(StringPrintf( |
| 577 | "Condition %s %d uses an object as left-hand side input.", |
| 578 | op->DebugName(), op->GetId())); |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 579 | } else if (rhs->GetType() == Primitive::kPrimNot) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 580 | AddError(StringPrintf( |
| 581 | "Condition %s %d uses an object as right-hand side input.", |
| 582 | op->DebugName(), op->GetId())); |
Roland Levillain | aecbd26 | 2015-01-19 12:44:01 +0000 | [diff] [blame] | 583 | } |
Nicolas Geoffray | 9ee6618 | 2015-01-16 12:35:40 +0000 | [diff] [blame] | 584 | } |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | void SSAChecker::VisitBinaryOperation(HBinaryOperation* op) { |
| 588 | VisitInstruction(op); |
| 589 | if (op->IsUShr() || op->IsShr() || op->IsShl()) { |
| 590 | if (PrimitiveKind(op->InputAt(1)->GetType()) != Primitive::kPrimInt) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 591 | AddError(StringPrintf( |
| 592 | "Shift operation %s %d has a non-int kind second input: " |
| 593 | "%s of type %s.", |
| 594 | op->DebugName(), op->GetId(), |
| 595 | op->InputAt(1)->DebugName(), |
| 596 | Primitive::PrettyDescriptor(op->InputAt(1)->GetType()))); |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 597 | } |
| 598 | } else { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 599 | if (PrimitiveKind(op->InputAt(0)->GetType()) != PrimitiveKind(op->InputAt(1)->GetType())) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 600 | AddError(StringPrintf( |
| 601 | "Binary operation %s %d has inputs of different types: " |
| 602 | "%s, and %s.", |
| 603 | op->DebugName(), op->GetId(), |
| 604 | Primitive::PrettyDescriptor(op->InputAt(0)->GetType()), |
| 605 | Primitive::PrettyDescriptor(op->InputAt(1)->GetType()))); |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 606 | } |
| 607 | } |
| 608 | |
| 609 | if (op->IsCompare()) { |
| 610 | if (op->GetType() != Primitive::kPrimInt) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 611 | AddError(StringPrintf( |
| 612 | "Compare operation %d has a non-int result type: %s.", |
| 613 | op->GetId(), |
| 614 | Primitive::PrettyDescriptor(op->GetType()))); |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 615 | } |
| 616 | } else { |
| 617 | // Use the first input, so that we can also make this check for shift operations. |
| 618 | if (PrimitiveKind(op->GetType()) != PrimitiveKind(op->InputAt(0)->GetType())) { |
Roland Levillain | 5c4405e | 2015-01-21 11:39:58 +0000 | [diff] [blame] | 619 | AddError(StringPrintf( |
| 620 | "Binary operation %s %d has a result type different " |
| 621 | "from its input type: %s vs %s.", |
| 622 | op->DebugName(), op->GetId(), |
| 623 | Primitive::PrettyDescriptor(op->GetType()), |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 624 | Primitive::PrettyDescriptor(op->InputAt(0)->GetType()))); |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | } |
| 628 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 629 | void SSAChecker::VisitConstant(HConstant* instruction) { |
| 630 | HBasicBlock* block = instruction->GetBlock(); |
| 631 | if (!block->IsEntryBlock()) { |
| 632 | AddError(StringPrintf( |
| 633 | "%s %d should be in the entry block but is in block %d.", |
| 634 | instruction->DebugName(), |
| 635 | instruction->GetId(), |
| 636 | block->GetBlockId())); |
| 637 | } |
| 638 | } |
| 639 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 640 | } // namespace art |