| 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 // This file implements the PNaCl bitcode file to Ice, to machine code | 10 // This file implements the PNaCl bitcode file to Ice, to machine code |
| (...skipping 1943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1954 // Note: we don't worry about downstream translation errors because | 1954 // Note: we don't worry about downstream translation errors because |
| 1955 // the function will not be translated if any errors occur. | 1955 // the function will not be translated if any errors occur. |
| 1956 if (Ty == Ice::IceType_void) | 1956 if (Ty == Ice::IceType_void) |
| 1957 return; | 1957 return; |
| 1958 Ice::Variable *Var = getNextInstVar(Ty); | 1958 Ice::Variable *Var = getNextInstVar(Ty); |
| 1959 CurrentNode->appendInst(Ice::InstAssign::create(Func.get(), Var, Var)); | 1959 CurrentNode->appendInst(Ice::InstAssign::create(Func.get(), Var, Var)); |
| 1960 } | 1960 } |
| 1961 }; | 1961 }; |
| 1962 | 1962 |
| 1963 void FunctionParser::ExitBlock() { | 1963 void FunctionParser::ExitBlock() { |
| 1964 if (isIRGenerationDisabled()) { | 1964 // Check if the last instruction in the function was terminating. |
| 1965 if (!InstIsTerminating) { |
| 1966 Error("Last instruction in function not terminator"); |
| 1967 if (isIRGenerationDisabled()) |
| 1968 return; |
| 1969 // Recover by inserting an unreachable instruction. |
| 1970 CurrentNode->appendInst(Ice::InstUnreachable::create(Func.get())); |
| 1971 } |
| 1972 if (isIRGenerationDisabled()) |
| 1965 return; | 1973 return; |
| 1966 } | |
| 1967 // Before translating, check for blocks without instructions, and | 1974 // Before translating, check for blocks without instructions, and |
| 1968 // insert unreachable. This shouldn't happen, but be safe. | 1975 // insert unreachable. This shouldn't happen, but be safe. |
| 1969 size_t Index = 0; | 1976 size_t Index = 0; |
| 1970 for (Ice::CfgNode *Node : Func->getNodes()) { | 1977 for (Ice::CfgNode *Node : Func->getNodes()) { |
| 1971 if (Node->getInsts().empty()) { | 1978 if (Node->getInsts().empty()) { |
| 1972 std::string Buffer; | 1979 std::string Buffer; |
| 1973 raw_string_ostream StrBuf(Buffer); | 1980 raw_string_ostream StrBuf(Buffer); |
| 1974 StrBuf << "Basic block " << Index << " contains no instructions"; | 1981 StrBuf << "Basic block " << Index << " contains no instructions"; |
| 1975 Error(StrBuf.str()); | 1982 Error(StrBuf.str()); |
| 1976 // TODO(kschimpf) Remove error recovery once implementation complete. | 1983 // TODO(kschimpf) Remove error recovery once implementation complete. |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2249 raw_string_ostream StrBuf(Buffer); | 2256 raw_string_ostream StrBuf(Buffer); |
| 2250 StrBuf << "Compare on type not understood: " << Op1Type; | 2257 StrBuf << "Compare on type not understood: " << Op1Type; |
| 2251 Error(StrBuf.str()); | 2258 Error(StrBuf.str()); |
| 2252 appendErrorInstruction(DestType); | 2259 appendErrorInstruction(DestType); |
| 2253 return; | 2260 return; |
| 2254 } | 2261 } |
| 2255 return; | 2262 return; |
| 2256 } | 2263 } |
| 2257 case naclbitc::FUNC_CODE_INST_RET: { | 2264 case naclbitc::FUNC_CODE_INST_RET: { |
| 2258 // RET: [opval?] | 2265 // RET: [opval?] |
| 2266 InstIsTerminating = true; |
| 2259 if (!isValidRecordSizeInRange(0, 1, "return")) | 2267 if (!isValidRecordSizeInRange(0, 1, "return")) |
| 2260 return; | 2268 return; |
| 2261 if (Values.empty()) { | 2269 if (Values.empty()) { |
| 2262 if (isIRGenerationDisabled()) | 2270 if (isIRGenerationDisabled()) |
| 2263 return; | 2271 return; |
| 2264 CurrentNode->appendInst(Ice::InstRet::create(Func.get())); | 2272 CurrentNode->appendInst(Ice::InstRet::create(Func.get())); |
| 2265 } else { | 2273 } else { |
| 2266 Ice::Operand *RetVal = getRelativeOperand(Values[0], BaseIndex); | 2274 Ice::Operand *RetVal = getRelativeOperand(Values[0], BaseIndex); |
| 2267 if (isIRGenerationDisabled()) { | 2275 if (isIRGenerationDisabled()) { |
| 2268 assert(RetVal == nullptr); | 2276 assert(RetVal == nullptr); |
| 2269 return; | 2277 return; |
| 2270 } | 2278 } |
| 2271 CurrentNode->appendInst(Ice::InstRet::create(Func.get(), RetVal)); | 2279 CurrentNode->appendInst(Ice::InstRet::create(Func.get(), RetVal)); |
| 2272 } | 2280 } |
| 2273 InstIsTerminating = true; | |
| 2274 return; | 2281 return; |
| 2275 } | 2282 } |
| 2276 case naclbitc::FUNC_CODE_INST_BR: { | 2283 case naclbitc::FUNC_CODE_INST_BR: { |
| 2284 InstIsTerminating = true; |
| 2277 if (Values.size() == 1) { | 2285 if (Values.size() == 1) { |
| 2278 // BR: [bb#] | 2286 // BR: [bb#] |
| 2279 if (isIRGenerationDisabled()) | 2287 if (isIRGenerationDisabled()) |
| 2280 return; | 2288 return; |
| 2281 Ice::CfgNode *Block = getBranchBasicBlock(Values[0]); | 2289 Ice::CfgNode *Block = getBranchBasicBlock(Values[0]); |
| 2282 if (Block == nullptr) | 2290 if (Block == nullptr) |
| 2283 return; | 2291 return; |
| 2284 CurrentNode->appendInst(Ice::InstBr::create(Func.get(), Block)); | 2292 CurrentNode->appendInst(Ice::InstBr::create(Func.get(), Block)); |
| 2285 } else { | 2293 } else { |
| 2286 // BR: [bb#, bb#, opval] | 2294 // BR: [bb#, bb#, opval] |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2299 Error(StrBuf.str()); | 2307 Error(StrBuf.str()); |
| 2300 return; | 2308 return; |
| 2301 } | 2309 } |
| 2302 Ice::CfgNode *ThenBlock = getBranchBasicBlock(Values[0]); | 2310 Ice::CfgNode *ThenBlock = getBranchBasicBlock(Values[0]); |
| 2303 Ice::CfgNode *ElseBlock = getBranchBasicBlock(Values[1]); | 2311 Ice::CfgNode *ElseBlock = getBranchBasicBlock(Values[1]); |
| 2304 if (ThenBlock == nullptr || ElseBlock == nullptr) | 2312 if (ThenBlock == nullptr || ElseBlock == nullptr) |
| 2305 return; | 2313 return; |
| 2306 CurrentNode->appendInst( | 2314 CurrentNode->appendInst( |
| 2307 Ice::InstBr::create(Func.get(), Cond, ThenBlock, ElseBlock)); | 2315 Ice::InstBr::create(Func.get(), Cond, ThenBlock, ElseBlock)); |
| 2308 } | 2316 } |
| 2309 InstIsTerminating = true; | |
| 2310 return; | 2317 return; |
| 2311 } | 2318 } |
| 2312 case naclbitc::FUNC_CODE_INST_SWITCH: { | 2319 case naclbitc::FUNC_CODE_INST_SWITCH: { |
| 2313 // SWITCH: [Condty, Cond, BbIndex, NumCases Case ...] | 2320 // SWITCH: [Condty, Cond, BbIndex, NumCases Case ...] |
| 2314 // where Case = [1, 1, Value, BbIndex]. | 2321 // where Case = [1, 1, Value, BbIndex]. |
| 2315 // | 2322 // |
| 2316 // Note: Unlike most instructions, we don't infer the type of | 2323 // Note: Unlike most instructions, we don't infer the type of |
| 2317 // Cond, but provide it as a separate field. There are also | 2324 // Cond, but provide it as a separate field. There are also |
| 2318 // unnecesary data fields (i.e. constants 1). These were not | 2325 // unnecesary data fields (i.e. constants 1). These were not |
| 2319 // cleaned up in PNaCl bitcode because the bitcode format was | 2326 // cleaned up in PNaCl bitcode because the bitcode format was |
| 2320 // already frozen when the problem was noticed. | 2327 // already frozen when the problem was noticed. |
| 2328 InstIsTerminating = true; |
| 2321 if (!isValidRecordSizeAtLeast(4, "switch")) | 2329 if (!isValidRecordSizeAtLeast(4, "switch")) |
| 2322 return; | 2330 return; |
| 2323 | 2331 |
| 2324 Ice::Type CondTy = Context->getSimpleTypeByID(Values[0]); | 2332 Ice::Type CondTy = Context->getSimpleTypeByID(Values[0]); |
| 2325 if (!Ice::isScalarIntegerType(CondTy)) { | 2333 if (!Ice::isScalarIntegerType(CondTy)) { |
| 2326 std::string Buffer; | 2334 std::string Buffer; |
| 2327 raw_string_ostream StrBuf(Buffer); | 2335 raw_string_ostream StrBuf(Buffer); |
| 2328 StrBuf << "Case condition must be non-wide integer. Found: " << CondTy; | 2336 StrBuf << "Case condition must be non-wide integer. Found: " << CondTy; |
| 2329 Error(StrBuf.str()); | 2337 Error(StrBuf.str()); |
| 2330 return; | 2338 return; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2376 Ice::APInt Value(BitWidth, | 2384 Ice::APInt Value(BitWidth, |
| 2377 NaClDecodeSignRotatedValue(Values[ValCaseIndex + 2])); | 2385 NaClDecodeSignRotatedValue(Values[ValCaseIndex + 2])); |
| 2378 if (isIRGenDisabled) | 2386 if (isIRGenDisabled) |
| 2379 continue; | 2387 continue; |
| 2380 Ice::CfgNode *Label = getBranchBasicBlock(Values[ValCaseIndex + 3]); | 2388 Ice::CfgNode *Label = getBranchBasicBlock(Values[ValCaseIndex + 3]); |
| 2381 Switch->addBranch(CaseIndex, Value.getSExtValue(), Label); | 2389 Switch->addBranch(CaseIndex, Value.getSExtValue(), Label); |
| 2382 } | 2390 } |
| 2383 if (isIRGenDisabled) | 2391 if (isIRGenDisabled) |
| 2384 return; | 2392 return; |
| 2385 CurrentNode->appendInst(Switch); | 2393 CurrentNode->appendInst(Switch); |
| 2386 InstIsTerminating = true; | |
| 2387 return; | 2394 return; |
| 2388 } | 2395 } |
| 2389 case naclbitc::FUNC_CODE_INST_UNREACHABLE: { | 2396 case naclbitc::FUNC_CODE_INST_UNREACHABLE: { |
| 2390 // UNREACHABLE: [] | 2397 // UNREACHABLE: [] |
| 2398 InstIsTerminating = true; |
| 2391 if (!isValidRecordSize(0, "unreachable")) | 2399 if (!isValidRecordSize(0, "unreachable")) |
| 2392 return; | 2400 return; |
| 2393 if (isIRGenerationDisabled()) | 2401 if (isIRGenerationDisabled()) |
| 2394 return; | 2402 return; |
| 2395 CurrentNode->appendInst(Ice::InstUnreachable::create(Func.get())); | 2403 CurrentNode->appendInst(Ice::InstUnreachable::create(Func.get())); |
| 2396 InstIsTerminating = true; | |
| 2397 return; | 2404 return; |
| 2398 } | 2405 } |
| 2399 case naclbitc::FUNC_CODE_INST_PHI: { | 2406 case naclbitc::FUNC_CODE_INST_PHI: { |
| 2400 // PHI: [ty, val1, bb1, ..., valN, bbN] for n >= 2. | 2407 // PHI: [ty, val1, bb1, ..., valN, bbN] for n >= 2. |
| 2401 if (!isValidRecordSizeAtLeast(3, "phi")) | 2408 if (!isValidRecordSizeAtLeast(3, "phi")) |
| 2402 return; | 2409 return; |
| 2403 Ice::Type Ty = Context->getSimpleTypeByID(Values[0]); | 2410 Ice::Type Ty = Context->getSimpleTypeByID(Values[0]); |
| 2404 if ((Values.size() & 0x1) == 0) { | 2411 if ((Values.size() & 0x1) == 0) { |
| 2405 // Not an odd number of values. | 2412 // Not an odd number of values. |
| 2406 std::string Buffer; | 2413 std::string Buffer; |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3100 } | 3107 } |
| 3101 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { | 3108 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { |
| 3102 ErrStream | 3109 ErrStream |
| 3103 << IRFilename | 3110 << IRFilename |
| 3104 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; | 3111 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; |
| 3105 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); | 3112 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); |
| 3106 } | 3113 } |
| 3107 } | 3114 } |
| 3108 | 3115 |
| 3109 } // end of namespace Ice | 3116 } // end of namespace Ice |
| OLD | NEW |