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 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
858 raw_string_ostream StrBuf(Buffer); | 858 raw_string_ostream StrBuf(Buffer); |
859 StrBuf << "Reference to basic block " << Index | 859 StrBuf << "Reference to basic block " << Index |
860 << " not found. Must be less than " << Nodes.size(); | 860 << " not found. Must be less than " << Nodes.size(); |
861 Error(StrBuf.str()); | 861 Error(StrBuf.str()); |
862 // TODO(kschimpf) Remove error recovery once implementation complete. | 862 // TODO(kschimpf) Remove error recovery once implementation complete. |
863 Index = 0; | 863 Index = 0; |
864 } | 864 } |
865 return Nodes[Index]; | 865 return Nodes[Index]; |
866 } | 866 } |
867 | 867 |
868 // Returns the Index-th basic block in the list of basic blocks. | |
869 // Assumes Index corresponds to a branch instruction. Hence, if | |
870 // the branch references the entry block, it also generates a | |
871 // corresponding error. | |
872 Ice::CfgNode *getBranchBasicBlock(uint32_t Index) { | |
873 if (Index == 0) { | |
874 Error("Branch to entry block not allowed"); | |
875 // TODO(kschimpf) Remove error recovery once implementation complete. | |
Jim Stichnoth
2014/09/04 21:58:17
Maybe "return NULL;" here, to help propagate the e
Karl
2014/09/05 15:33:08
The only block we always know we can recover to is
| |
876 } | |
877 return GetBasicBlock(Index); | |
878 } | |
879 | |
868 // Generates the next available local variable using the given | 880 // Generates the next available local variable using the given |
869 // type. Note: if Ty is void, this function returns NULL. | 881 // type. Note: if Ty is void, this function returns NULL. |
870 Ice::Variable *NextInstVar(Ice::Type Ty) { | 882 Ice::Variable *NextInstVar(Ice::Type Ty) { |
871 if (Ty == Ice::IceType_void) | 883 if (Ty == Ice::IceType_void) |
872 return NULL; | 884 return NULL; |
873 Ice::Variable *Var = Func->makeVariable(Ty, CurrentNode); | 885 Ice::Variable *Var = Func->makeVariable(Ty, CurrentNode); |
874 LocalOperands.push_back(Var); | 886 LocalOperands.push_back(Var); |
875 return Var; | 887 return Var; |
876 } | 888 } |
877 | 889 |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1286 Error(StrBuf.str()); | 1298 Error(StrBuf.str()); |
1287 } | 1299 } |
1288 // TODO(kschimpf): Restrict index to a legal constant index (once | 1300 // TODO(kschimpf): Restrict index to a legal constant index (once |
1289 // constants can be defined). | 1301 // constants can be defined). |
1290 Ice::Variable *Dest = NextInstVar(EltType); | 1302 Ice::Variable *Dest = NextInstVar(EltType); |
1291 Inst = Ice::InstInsertElement::create(Func, Dest, Vec, Elt, Index); | 1303 Inst = Ice::InstInsertElement::create(Func, Dest, Vec, Elt, Index); |
1292 break; | 1304 break; |
1293 } | 1305 } |
1294 case naclbitc::FUNC_CODE_INST_RET: { | 1306 case naclbitc::FUNC_CODE_INST_RET: { |
1295 // RET: [opval?] | 1307 // RET: [opval?] |
1296 InstIsTerminating = true; | |
1297 if (!isValidRecordSizeInRange(0, 1, "function block ret")) | 1308 if (!isValidRecordSizeInRange(0, 1, "function block ret")) |
1298 return; | 1309 return; |
1299 if (Values.size() == 0) { | 1310 if (Values.size() == 0) { |
1300 Inst = Ice::InstRet::create(Func); | 1311 Inst = Ice::InstRet::create(Func); |
1301 } else { | 1312 } else { |
1302 Inst = Ice::InstRet::create(Func, getRelativeOperand(Values[0])); | 1313 Inst = Ice::InstRet::create(Func, getRelativeOperand(Values[0])); |
1303 } | 1314 } |
1315 InstIsTerminating = true; | |
1316 break; | |
1317 } | |
1318 case naclbitc::FUNC_CODE_INST_BR: { | |
1319 if (Values.size() == 1) { | |
1320 // BR: [bb#] | |
1321 Ice::CfgNode *Block = getBranchBasicBlock(Values[0]); | |
1322 if (Block == NULL) return; | |
Jim Stichnoth
2014/09/04 21:58:17
return statement on separate line
Karl
2014/09/05 15:33:08
Done.
| |
1323 Inst = Ice::InstBr::create(Func, Block); | |
1324 } else { | |
1325 // BR: [bb#, bb#, opval] | |
1326 if (!isValidRecordSize(3, "function block branch")) | |
1327 return; | |
1328 Ice::Operand *Cond = getRelativeOperand(Values[2]); | |
1329 if (Cond->getType() != Ice::IceType_i1) { | |
1330 std::string Buffer; | |
1331 raw_string_ostream StrBuf(Buffer); | |
1332 StrBuf << "Branch condition not i1"; | |
1333 Error(StrBuf.str()); | |
1334 return; | |
1335 } | |
1336 Ice::CfgNode *ThenBlock = getBranchBasicBlock(Values[0]); | |
1337 Ice::CfgNode *ElseBlock = getBranchBasicBlock(Values[1]); | |
1338 if (ThenBlock == 0 || ElseBlock == 0) return; | |
Jim Stichnoth
2014/09/04 21:58:17
return on separate line. Also, NULL instead of 0.
Karl
2014/09/05 15:33:08
Done.
| |
1339 Inst = Ice::InstBr::create(Func, Cond, ThenBlock, ElseBlock); | |
1340 } | |
1341 InstIsTerminating = true; | |
1304 break; | 1342 break; |
1305 } | 1343 } |
1306 default: | 1344 default: |
1307 // Generate error message! | 1345 // Generate error message! |
1308 BlockParserBaseClass::ProcessRecord(); | 1346 BlockParserBaseClass::ProcessRecord(); |
1309 break; | 1347 break; |
1310 } | 1348 } |
1311 if (Inst) | 1349 if (Inst) |
1312 CurrentNode->appendInst(Inst); | 1350 CurrentNode->appendInst(Inst); |
1313 } | 1351 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1470 if (TopLevelBlocks != 1) { | 1508 if (TopLevelBlocks != 1) { |
1471 errs() << IRFilename | 1509 errs() << IRFilename |
1472 << ": Contains more than one module. Found: " << TopLevelBlocks | 1510 << ": Contains more than one module. Found: " << TopLevelBlocks |
1473 << "\n"; | 1511 << "\n"; |
1474 ErrorStatus = true; | 1512 ErrorStatus = true; |
1475 } | 1513 } |
1476 return; | 1514 return; |
1477 } | 1515 } |
1478 | 1516 |
1479 } // end of namespace Ice | 1517 } // end of namespace Ice |
OLD | NEW |