OLD | NEW |
1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===// | 1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 /// | 9 /// |
10 /// \file | 10 /// \file |
(...skipping 2397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2408 } else if (CondTy != Cond->getType()) { | 2408 } else if (CondTy != Cond->getType()) { |
2409 std::string Buffer; | 2409 std::string Buffer; |
2410 raw_string_ostream StrBuf(Buffer); | 2410 raw_string_ostream StrBuf(Buffer); |
2411 StrBuf << "Case condition expects type " << CondTy | 2411 StrBuf << "Case condition expects type " << CondTy |
2412 << ". Found: " << Cond->getType(); | 2412 << ". Found: " << Cond->getType(); |
2413 Error(StrBuf.str()); | 2413 Error(StrBuf.str()); |
2414 return; | 2414 return; |
2415 } | 2415 } |
2416 Ice::CfgNode *DefaultLabel = | 2416 Ice::CfgNode *DefaultLabel = |
2417 isIRGenDisabled ? nullptr : getBranchBasicBlock(Values[2]); | 2417 isIRGenDisabled ? nullptr : getBranchBasicBlock(Values[2]); |
| 2418 if (DefaultLabel == nullptr) |
| 2419 return; |
2418 uint64_t NumCasesRaw = Values[3]; | 2420 uint64_t NumCasesRaw = Values[3]; |
2419 if (NumCasesRaw > std::numeric_limits<uint32_t>::max()) { | 2421 if (NumCasesRaw > std::numeric_limits<uint32_t>::max()) { |
2420 std::string Buffer; | 2422 std::string Buffer; |
2421 raw_string_ostream StrBuf(Buffer); | 2423 raw_string_ostream StrBuf(Buffer); |
2422 StrBuf << "Too many cases specified in switch: " << NumCasesRaw; | 2424 StrBuf << "Too many cases specified in switch: " << NumCasesRaw; |
2423 Error(StrBuf.str()); | 2425 Error(StrBuf.str()); |
2424 NumCasesRaw = std::numeric_limits<uint32_t>::max(); | 2426 NumCasesRaw = std::numeric_limits<uint32_t>::max(); |
2425 } | 2427 } |
2426 uint32_t NumCases = NumCasesRaw; | 2428 uint32_t NumCases = NumCasesRaw; |
2427 | 2429 |
2428 // Now recognize each of the cases. | 2430 // Now recognize each of the cases. |
2429 if (!isValidRecordSize(4 + NumCases * 4, "switch")) | 2431 if (!isValidRecordSize(4 + NumCases * 4, "switch")) |
2430 return; | 2432 return; |
2431 Ice::InstSwitch *Switch = | 2433 std::unique_ptr<Ice::InstSwitch> Switch( |
2432 isIRGenDisabled | 2434 isIRGenDisabled ? nullptr |
2433 ? nullptr | 2435 : Ice::InstSwitch::create(Func.get(), NumCases, Cond, |
2434 : Ice::InstSwitch::create(Func.get(), NumCases, Cond, DefaultLabel); | 2436 DefaultLabel)); |
2435 unsigned ValCaseIndex = 4; // index to beginning of case entry. | 2437 unsigned ValCaseIndex = 4; // index to beginning of case entry. |
2436 for (uint32_t CaseIndex = 0; CaseIndex < NumCases; | 2438 for (uint32_t CaseIndex = 0; CaseIndex < NumCases; |
2437 ++CaseIndex, ValCaseIndex += 4) { | 2439 ++CaseIndex, ValCaseIndex += 4) { |
2438 if (Values[ValCaseIndex] != 1 || Values[ValCaseIndex + 1] != 1) { | 2440 if (Values[ValCaseIndex] != 1 || Values[ValCaseIndex + 1] != 1) { |
2439 std::string Buffer; | 2441 std::string Buffer; |
2440 raw_string_ostream StrBuf(Buffer); | 2442 raw_string_ostream StrBuf(Buffer); |
2441 StrBuf << "Sequence [1, 1, value, label] expected for case entry " | 2443 StrBuf << "Sequence [1, 1, value, label] expected for case entry " |
2442 << "in switch record. (at index" << ValCaseIndex << ")"; | 2444 << "in switch record. (at index" << ValCaseIndex << ")"; |
2443 Error(StrBuf.str()); | 2445 Error(StrBuf.str()); |
2444 return; | 2446 return; |
2445 } | 2447 } |
2446 Ice::APInt Value(BitWidth, | 2448 Ice::APInt Value(BitWidth, |
2447 NaClDecodeSignRotatedValue(Values[ValCaseIndex + 2])); | 2449 NaClDecodeSignRotatedValue(Values[ValCaseIndex + 2])); |
2448 if (isIRGenDisabled) | 2450 if (isIRGenDisabled) |
2449 continue; | 2451 continue; |
2450 Ice::CfgNode *Label = getBranchBasicBlock(Values[ValCaseIndex + 3]); | 2452 Ice::CfgNode *Label = getBranchBasicBlock(Values[ValCaseIndex + 3]); |
| 2453 if (Label == nullptr) |
| 2454 return; |
2451 Switch->addBranch(CaseIndex, Value.getSExtValue(), Label); | 2455 Switch->addBranch(CaseIndex, Value.getSExtValue(), Label); |
2452 } | 2456 } |
2453 if (isIRGenDisabled) | 2457 if (isIRGenDisabled) |
2454 return; | 2458 return; |
2455 CurrentNode->appendInst(Switch); | 2459 CurrentNode->appendInst(Switch.release()); |
2456 return; | 2460 return; |
2457 } | 2461 } |
2458 case naclbitc::FUNC_CODE_INST_UNREACHABLE: { | 2462 case naclbitc::FUNC_CODE_INST_UNREACHABLE: { |
2459 // UNREACHABLE: [] | 2463 // UNREACHABLE: [] |
2460 InstIsTerminating = true; | 2464 InstIsTerminating = true; |
2461 if (!isValidRecordSize(0, "unreachable")) | 2465 if (!isValidRecordSize(0, "unreachable")) |
2462 return; | 2466 return; |
2463 if (isIRGenerationDisabled()) | 2467 if (isIRGenerationDisabled()) |
2464 return; | 2468 return; |
2465 CurrentNode->appendInst(Ice::InstUnreachable::create(Func.get())); | 2469 CurrentNode->appendInst(Ice::InstUnreachable::create(Func.get())); |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3167 } | 3171 } |
3168 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { | 3172 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { |
3169 ErrStream | 3173 ErrStream |
3170 << IRFilename | 3174 << IRFilename |
3171 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; | 3175 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; |
3172 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); | 3176 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); |
3173 } | 3177 } |
3174 } | 3178 } |
3175 | 3179 |
3176 } // end of namespace Ice | 3180 } // end of namespace Ice |
OLD | NEW |