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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 bool blockError(const std::string &Message); | 243 bool blockError(const std::string &Message); |
244 | 244 |
245 /// Returns the number of errors found while parsing the bitcode file. | 245 /// Returns the number of errors found while parsing the bitcode file. |
246 unsigned getNumErrors() const { return NumErrors; } | 246 unsigned getNumErrors() const { return NumErrors; } |
247 | 247 |
248 /// Changes the size of the type list to the given size. | 248 /// Changes the size of the type list to the given size. |
249 void resizeTypeIDValues(size_t NewSize) { TypeIDValues.resize(NewSize); } | 249 void resizeTypeIDValues(size_t NewSize) { TypeIDValues.resize(NewSize); } |
250 | 250 |
251 size_t getNumTypeIDValues() const { return TypeIDValues.size(); } | 251 size_t getNumTypeIDValues() const { return TypeIDValues.size(); } |
252 | 252 |
253 /// Returns true if generation of Subzero IR is disabled. | |
254 bool isIRGenerationDisabled() const { | |
255 return Translator.getFlags().getDisableIRGeneration(); | |
256 } | |
257 | |
258 /// Returns the undefined type associated with type ID. Note: Returns extended | 253 /// Returns the undefined type associated with type ID. Note: Returns extended |
259 /// type ready to be defined. | 254 /// type ready to be defined. |
260 ExtendedType *getTypeByIDForDefining(NaClBcIndexSize_t ID) { | 255 ExtendedType *getTypeByIDForDefining(NaClBcIndexSize_t ID) { |
261 // Get corresponding element, verifying the value is still undefined (and | 256 // Get corresponding element, verifying the value is still undefined (and |
262 // hence allowed to be defined). | 257 // hence allowed to be defined). |
263 ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::Undefined); | 258 ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::Undefined); |
264 if (Ty) | 259 if (Ty) |
265 return Ty; | 260 return Ty; |
266 if (ID >= TypeIDValues.size()) { | 261 if (ID >= TypeIDValues.size()) { |
267 if (ID >= NaClBcIndexSize_t_Max) { | 262 if (ID >= NaClBcIndexSize_t_Max) { |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 Error(StrBuf.str()); | 523 Error(StrBuf.str()); |
529 } | 524 } |
530 | 525 |
531 // Converts function declarations into constant value IDs. | 526 // Converts function declarations into constant value IDs. |
532 void createValueIDsForFunctions() { | 527 void createValueIDsForFunctions() { |
533 Ice::GlobalContext *Ctx = getTranslator().getContext(); | 528 Ice::GlobalContext *Ctx = getTranslator().getContext(); |
534 for (const Ice::FunctionDeclaration *Func : FunctionDeclarations) { | 529 for (const Ice::FunctionDeclaration *Func : FunctionDeclarations) { |
535 if (!Func->verifyLinkageCorrect(Ctx)) | 530 if (!Func->verifyLinkageCorrect(Ctx)) |
536 reportLinkageError("Function", *Func); | 531 reportLinkageError("Function", *Func); |
537 Ice::Constant *C = nullptr; | 532 Ice::Constant *C = nullptr; |
538 if (!isIRGenerationDisabled()) { | 533 C = getConstantSym(Func->getName(), Func->getSuppressMangling(), |
Jim Stichnoth
2015/12/12 04:11:02
Combine this with the previous statement.
rkotlerimgtec
2015/12/12 05:33:03
Done.
| |
539 C = getConstantSym(Func->getName(), Func->getSuppressMangling(), | 534 Func->isProto()); |
540 Func->isProto()); | |
541 } | |
542 ValueIDConstants.push_back(C); | 535 ValueIDConstants.push_back(C); |
543 } | 536 } |
544 } | 537 } |
545 | 538 |
546 // Converts global variable declarations into constant value IDs. | 539 // Converts global variable declarations into constant value IDs. |
547 void createValueIDsForGlobalVars() { | 540 void createValueIDsForGlobalVars() { |
548 Ice::GlobalContext *Ctx = getTranslator().getContext(); | 541 Ice::GlobalContext *Ctx = getTranslator().getContext(); |
549 for (const Ice::VariableDeclaration *Decl : *VariableDeclarations) { | 542 for (const Ice::VariableDeclaration *Decl : *VariableDeclarations) { |
550 if (!Decl->verifyLinkageCorrect(Ctx)) | 543 if (!Decl->verifyLinkageCorrect(Ctx)) |
551 reportLinkageError("Global", *Decl); | 544 reportLinkageError("Global", *Decl); |
552 Ice::Constant *C = nullptr; | 545 Ice::Constant *C = nullptr; |
553 if (!isIRGenerationDisabled()) { | 546 C = getConstantSym(Decl->getName(), Decl->getSuppressMangling(), |
Jim Stichnoth
2015/12/12 04:11:02
Combine this with the previous statement.
rkotlerimgtec
2015/12/12 05:33:03
Done.
| |
554 C = getConstantSym(Decl->getName(), Decl->getSuppressMangling(), | 547 !Decl->hasInitializer()); |
555 !Decl->hasInitializer()); | |
556 } | |
557 ValueIDConstants.push_back(C); | 548 ValueIDConstants.push_back(C); |
558 } | 549 } |
559 } | 550 } |
560 | 551 |
561 // Reports that type ID is undefined, or not of the WantedType. | 552 // Reports that type ID is undefined, or not of the WantedType. |
562 void reportBadTypeIDAs(NaClBcIndexSize_t ID, const ExtendedType *Ty, | 553 void reportBadTypeIDAs(NaClBcIndexSize_t ID, const ExtendedType *Ty, |
563 ExtendedType::TypeKind WantedType); | 554 ExtendedType::TypeKind WantedType); |
564 | 555 |
565 // Reports that there is no function declaration for ID. Returns an error | 556 // Reports that there is no function declaration for ID. Returns an error |
566 // recovery value to use. | 557 // recovery value to use. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
674 // Constructor for nested block parsers. | 665 // Constructor for nested block parsers. |
675 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 666 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
676 : NaClBitcodeParser(BlockID, EnclosingParser), | 667 : NaClBitcodeParser(BlockID, EnclosingParser), |
677 Context(EnclosingParser->Context) {} | 668 Context(EnclosingParser->Context) {} |
678 | 669 |
679 // Gets the translator associated with the bitcode parser. | 670 // Gets the translator associated with the bitcode parser. |
680 Ice::Translator &getTranslator() const { return Context->getTranslator(); } | 671 Ice::Translator &getTranslator() const { return Context->getTranslator(); } |
681 | 672 |
682 const Ice::ClFlags &getFlags() const { return getTranslator().getFlags(); } | 673 const Ice::ClFlags &getFlags() const { return getTranslator().getFlags(); } |
683 | 674 |
684 bool isIRGenerationDisabled() const { | |
685 return getTranslator().getFlags().getDisableIRGeneration(); | |
686 } | |
687 | |
688 // Default implementation. Reports that block is unknown and skips its | 675 // Default implementation. Reports that block is unknown and skips its |
689 // contents. | 676 // contents. |
690 bool ParseBlock(unsigned BlockID) override; | 677 bool ParseBlock(unsigned BlockID) override; |
691 | 678 |
692 // Default implementation. Reports that the record is not understood. | 679 // Default implementation. Reports that the record is not understood. |
693 void ProcessRecord() override; | 680 void ProcessRecord() override; |
694 | 681 |
695 // Checks if the size of the record is Size. Return true if valid. Otherwise | 682 // Checks if the size of the record is Size. Return true if valid. Otherwise |
696 // generates an error and returns false. | 683 // generates an error and returns false. |
697 bool isValidRecordSize(size_t Size, const char *RecordName) { | 684 bool isValidRecordSize(size_t Size, const char *RecordName) { |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1138 // VAR: [align, isconst] | 1125 // VAR: [align, isconst] |
1139 if (!isValidRecordSize(2, "variable")) | 1126 if (!isValidRecordSize(2, "variable")) |
1140 return; | 1127 return; |
1141 verifyNoMissingInitializers(); | 1128 verifyNoMissingInitializers(); |
1142 // Always build the global variable, even if IR generation is turned off. | 1129 // Always build the global variable, even if IR generation is turned off. |
1143 // This is needed because we need a placeholder in the top-level context | 1130 // This is needed because we need a placeholder in the top-level context |
1144 // when no IR is generated. | 1131 // when no IR is generated. |
1145 uint32_t Alignment = | 1132 uint32_t Alignment = |
1146 Context->extractAlignment(this, "Global variable", Values[0]); | 1133 Context->extractAlignment(this, "Global variable", Values[0]); |
1147 CurGlobalVar = getGlobalVarByID(NextGlobalID); | 1134 CurGlobalVar = getGlobalVarByID(NextGlobalID); |
1148 if (!isIRGenerationDisabled()) { | 1135 InitializersNeeded = 1; |
1149 InitializersNeeded = 1; | 1136 CurGlobalVar->setAlignment(Alignment); |
1150 CurGlobalVar->setAlignment(Alignment); | 1137 CurGlobalVar->setIsConstant(Values[1] != 0); |
1151 CurGlobalVar->setIsConstant(Values[1] != 0); | |
1152 } | |
1153 ++NextGlobalID; | 1138 ++NextGlobalID; |
1154 return; | 1139 return; |
1155 } | 1140 } |
1156 case naclbitc::GLOBALVAR_COMPOUND: | 1141 case naclbitc::GLOBALVAR_COMPOUND: |
1157 // COMPOUND: [size] | 1142 // COMPOUND: [size] |
1158 if (!isValidRecordSize(1, "compound")) | 1143 if (!isValidRecordSize(1, "compound")) |
1159 return; | 1144 return; |
1160 if (!CurGlobalVar->getInitializers().empty()) { | 1145 if (!CurGlobalVar->getInitializers().empty()) { |
1161 Error("Globals compound record not first initializer"); | 1146 Error("Globals compound record not first initializer"); |
1162 return; | 1147 return; |
1163 } | 1148 } |
1164 if (Values[0] < 2) { | 1149 if (Values[0] < 2) { |
1165 std::string Buffer; | 1150 std::string Buffer; |
1166 raw_string_ostream StrBuf(Buffer); | 1151 raw_string_ostream StrBuf(Buffer); |
1167 StrBuf << getBlockName() | 1152 StrBuf << getBlockName() |
1168 << " compound record size invalid. Found: " << Values[0]; | 1153 << " compound record size invalid. Found: " << Values[0]; |
1169 Error(StrBuf.str()); | 1154 Error(StrBuf.str()); |
1170 return; | 1155 return; |
1171 } | 1156 } |
1172 if (isIRGenerationDisabled()) | |
1173 return; | |
1174 InitializersNeeded = Values[0]; | 1157 InitializersNeeded = Values[0]; |
1175 return; | 1158 return; |
1176 case naclbitc::GLOBALVAR_ZEROFILL: { | 1159 case naclbitc::GLOBALVAR_ZEROFILL: { |
1177 // ZEROFILL: [size] | 1160 // ZEROFILL: [size] |
1178 if (!isValidRecordSize(1, "zerofill")) | 1161 if (!isValidRecordSize(1, "zerofill")) |
1179 return; | 1162 return; |
1180 if (isIRGenerationDisabled()) | |
1181 return; | |
1182 CurGlobalVar->addInitializer( | 1163 CurGlobalVar->addInitializer( |
1183 Ice::VariableDeclaration::ZeroInitializer::create(Values[0])); | 1164 Ice::VariableDeclaration::ZeroInitializer::create(Values[0])); |
1184 return; | 1165 return; |
1185 } | 1166 } |
1186 case naclbitc::GLOBALVAR_DATA: { | 1167 case naclbitc::GLOBALVAR_DATA: { |
1187 // DATA: [b0, b1, ...] | 1168 // DATA: [b0, b1, ...] |
1188 if (!isValidRecordSizeAtLeast(1, "data")) | 1169 if (!isValidRecordSizeAtLeast(1, "data")) |
1189 return; | 1170 return; |
1190 if (isIRGenerationDisabled()) | |
1191 return; | |
1192 CurGlobalVar->addInitializer( | 1171 CurGlobalVar->addInitializer( |
1193 Ice::VariableDeclaration::DataInitializer::create(Values)); | 1172 Ice::VariableDeclaration::DataInitializer::create(Values)); |
1194 return; | 1173 return; |
1195 } | 1174 } |
1196 case naclbitc::GLOBALVAR_RELOC: { | 1175 case naclbitc::GLOBALVAR_RELOC: { |
1197 // RELOC: [val, [addend]] | 1176 // RELOC: [val, [addend]] |
1198 if (!isValidRecordSizeInRange(1, 2, "reloc")) | 1177 if (!isValidRecordSizeInRange(1, 2, "reloc")) |
1199 return; | 1178 return; |
1200 if (isIRGenerationDisabled()) | |
1201 return; | |
1202 NaClBcIndexSize_t Index = Values[0]; | 1179 NaClBcIndexSize_t Index = Values[0]; |
1203 NaClBcIndexSize_t IndexLimit = SpecifiedNumberVars + NumFunctionIDs; | 1180 NaClBcIndexSize_t IndexLimit = SpecifiedNumberVars + NumFunctionIDs; |
1204 if (Index >= IndexLimit) { | 1181 if (Index >= IndexLimit) { |
1205 std::string Buffer; | 1182 std::string Buffer; |
1206 raw_string_ostream StrBuf(Buffer); | 1183 raw_string_ostream StrBuf(Buffer); |
1207 StrBuf << "Relocation index " << Index << " to big. Expect index < " | 1184 StrBuf << "Relocation index " << Index << " to big. Expect index < " |
1208 << IndexLimit; | 1185 << IndexLimit; |
1209 Error(StrBuf.str()); | 1186 Error(StrBuf.str()); |
1210 } | 1187 } |
1211 uint64_t Offset = 0; | 1188 uint64_t Offset = 0; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1358 } | 1335 } |
1359 | 1336 |
1360 // Note: The Cfg is created, even when IR generation is disabled. This is | 1337 // Note: The Cfg is created, even when IR generation is disabled. This is |
1361 // done to install a CfgLocalAllocator for various internal containers. | 1338 // done to install a CfgLocalAllocator for various internal containers. |
1362 Func = Ice::Cfg::create(getTranslator().getContext(), | 1339 Func = Ice::Cfg::create(getTranslator().getContext(), |
1363 getTranslator().getNextSequenceNumber()); | 1340 getTranslator().getNextSequenceNumber()); |
1364 Ice::Cfg::setCurrentCfg(Func.get()); | 1341 Ice::Cfg::setCurrentCfg(Func.get()); |
1365 | 1342 |
1366 // TODO(kschimpf) Clean up API to add a function signature to a CFG. | 1343 // TODO(kschimpf) Clean up API to add a function signature to a CFG. |
1367 const Ice::FuncSigType &Signature = FuncDecl->getSignature(); | 1344 const Ice::FuncSigType &Signature = FuncDecl->getSignature(); |
1368 if (isIRGenerationDisabled()) { | 1345 |
1369 CurrentNode = nullptr; | 1346 Func->setFunctionName(FuncDecl->getName()); |
1370 for (Ice::Type ArgType : Signature.getArgList()) { | 1347 Func->setReturnType(Signature.getReturnType()); |
1371 (void)ArgType; | 1348 Func->setInternal(FuncDecl->getLinkage() == GlobalValue::InternalLinkage); |
1372 setNextLocalInstIndex(nullptr); | 1349 CurrentNode = installNextBasicBlock(); |
1373 } | 1350 Func->setEntryNode(CurrentNode); |
1374 } else { | 1351 for (Ice::Type ArgType : Signature.getArgList()) { |
1375 Func->setFunctionName(FuncDecl->getName()); | 1352 Func->addArg(getNextInstVar(ArgType)); |
1376 Func->setReturnType(Signature.getReturnType()); | |
1377 Func->setInternal(FuncDecl->getLinkage() == GlobalValue::InternalLinkage); | |
1378 CurrentNode = installNextBasicBlock(); | |
1379 Func->setEntryNode(CurrentNode); | |
1380 for (Ice::Type ArgType : Signature.getArgList()) { | |
1381 Func->addArg(getNextInstVar(ArgType)); | |
1382 } | |
1383 } | 1353 } |
1354 | |
1384 bool ParserResult = ParseThisBlock(); | 1355 bool ParserResult = ParseThisBlock(); |
1385 | 1356 |
1386 // Temporarily end per-function timing, which will be resumed by the | 1357 // Temporarily end per-function timing, which will be resumed by the |
1387 // translator function. This is because translation may be done | 1358 // translator function. This is because translation may be done |
1388 // asynchronously in a separate thread. | 1359 // asynchronously in a separate thread. |
1389 if (TimeThisFunction) | 1360 if (TimeThisFunction) |
1390 getTranslator().getContext()->popTimer(TimerID, StackID); | 1361 getTranslator().getContext()->popTimer(TimerID, StackID); |
1391 | 1362 |
1392 Ice::Cfg::setCurrentCfg(nullptr); | 1363 Ice::Cfg::setCurrentCfg(nullptr); |
1393 // Note: Once any errors have been found, we turn off all translation of | 1364 // Note: Once any errors have been found, we turn off all translation of |
(...skipping 23 matching lines...) Expand all Loading... | |
1417 } | 1388 } |
1418 | 1389 |
1419 // Set the next constant ID to the given constant C. | 1390 // Set the next constant ID to the given constant C. |
1420 void setNextConstantID(Ice::Constant *C) { setNextLocalInstIndex(C); } | 1391 void setNextConstantID(Ice::Constant *C) { setNextLocalInstIndex(C); } |
1421 | 1392 |
1422 // Returns the value referenced by the given value Index. | 1393 // Returns the value referenced by the given value Index. |
1423 Ice::Operand *getOperand(NaClBcIndexSize_t Index) { | 1394 Ice::Operand *getOperand(NaClBcIndexSize_t Index) { |
1424 if (Index < CachedNumGlobalValueIDs) { | 1395 if (Index < CachedNumGlobalValueIDs) { |
1425 return Context->getGlobalConstantByID(Index); | 1396 return Context->getGlobalConstantByID(Index); |
1426 } | 1397 } |
1427 if (isIRGenerationDisabled()) | |
1428 return nullptr; | |
1429 NaClBcIndexSize_t LocalIndex = Index - CachedNumGlobalValueIDs; | 1398 NaClBcIndexSize_t LocalIndex = Index - CachedNumGlobalValueIDs; |
1430 if (LocalIndex >= LocalOperands.size()) | 1399 if (LocalIndex >= LocalOperands.size()) |
1431 reportGetOperandUndefined(Index); | 1400 reportGetOperandUndefined(Index); |
1432 Ice::Operand *Op = LocalOperands[LocalIndex]; | 1401 Ice::Operand *Op = LocalOperands[LocalIndex]; |
1433 if (Op == nullptr) | 1402 if (Op == nullptr) |
1434 reportGetOperandUndefined(Index); | 1403 reportGetOperandUndefined(Index); |
1435 return Op; | 1404 return Op; |
1436 } | 1405 } |
1437 | 1406 |
1438 private: | 1407 private: |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1473 // Note: Bitstream defines words as 32-bit values. | 1442 // Note: Bitstream defines words as 32-bit values. |
1474 NumBytesDefiningFunction = NumWords * sizeof(uint32_t); | 1443 NumBytesDefiningFunction = NumWords * sizeof(uint32_t); |
1475 // We know that all records are minimally defined by a two-bit abreviation. | 1444 // We know that all records are minimally defined by a two-bit abreviation. |
1476 MaxRecordsInBlock = NumBytesDefiningFunction * (CHAR_BIT >> 1); | 1445 MaxRecordsInBlock = NumBytesDefiningFunction * (CHAR_BIT >> 1); |
1477 } | 1446 } |
1478 | 1447 |
1479 void ExitBlock() override; | 1448 void ExitBlock() override; |
1480 | 1449 |
1481 // Creates and appends a new basic block to the list of basic blocks. | 1450 // Creates and appends a new basic block to the list of basic blocks. |
1482 Ice::CfgNode *installNextBasicBlock() { | 1451 Ice::CfgNode *installNextBasicBlock() { |
1483 assert(!isIRGenerationDisabled()); | |
1484 Ice::CfgNode *Node = Func->makeNode(); | 1452 Ice::CfgNode *Node = Func->makeNode(); |
1485 return Node; | 1453 return Node; |
1486 } | 1454 } |
1487 | 1455 |
1488 // Returns the Index-th basic block in the list of basic blocks. | 1456 // Returns the Index-th basic block in the list of basic blocks. |
1489 Ice::CfgNode *getBasicBlock(NaClBcIndexSize_t Index) { | 1457 Ice::CfgNode *getBasicBlock(NaClBcIndexSize_t Index) { |
1490 assert(!isIRGenerationDisabled()); | |
1491 if (Index >= Func->getNumNodes()) { | 1458 if (Index >= Func->getNumNodes()) { |
1492 std::string Buffer; | 1459 std::string Buffer; |
1493 raw_string_ostream StrBuf(Buffer); | 1460 raw_string_ostream StrBuf(Buffer); |
1494 StrBuf << "Reference to basic block " << Index | 1461 StrBuf << "Reference to basic block " << Index |
1495 << " not found. Must be less than " << Func->getNumNodes(); | 1462 << " not found. Must be less than " << Func->getNumNodes(); |
1496 Error(StrBuf.str()); | 1463 Error(StrBuf.str()); |
1497 Index = 0; | 1464 Index = 0; |
1498 } | 1465 } |
1499 return Func->getNodes()[Index]; | 1466 return Func->getNodes()[Index]; |
1500 } | 1467 } |
1501 | 1468 |
1502 // Returns the Index-th basic block in the list of basic blocks. Assumes | 1469 // Returns the Index-th basic block in the list of basic blocks. Assumes |
1503 // Index corresponds to a branch instruction. Hence, if the branch references | 1470 // Index corresponds to a branch instruction. Hence, if the branch references |
1504 // the entry block, it also generates a corresponding error. | 1471 // the entry block, it also generates a corresponding error. |
1505 Ice::CfgNode *getBranchBasicBlock(NaClBcIndexSize_t Index) { | 1472 Ice::CfgNode *getBranchBasicBlock(NaClBcIndexSize_t Index) { |
1506 assert(!isIRGenerationDisabled()); | |
1507 if (Index == 0) { | 1473 if (Index == 0) { |
1508 Error("Branch to entry block not allowed"); | 1474 Error("Branch to entry block not allowed"); |
1509 } | 1475 } |
1510 return getBasicBlock(Index); | 1476 return getBasicBlock(Index); |
1511 } | 1477 } |
1512 | 1478 |
1513 // Generate an instruction variable with type Ty. | 1479 // Generate an instruction variable with type Ty. |
1514 Ice::Variable *createInstVar(Ice::Type Ty) { | 1480 Ice::Variable *createInstVar(Ice::Type Ty) { |
1515 assert(!isIRGenerationDisabled()); | |
1516 if (Ty == Ice::IceType_void) { | 1481 if (Ty == Ice::IceType_void) { |
1517 Error("Can't define instruction value using type void"); | 1482 Error("Can't define instruction value using type void"); |
1518 // Recover since we can't throw an exception. | 1483 // Recover since we can't throw an exception. |
1519 Ty = Ice::IceType_i32; | 1484 Ty = Ice::IceType_i32; |
1520 } | 1485 } |
1521 return Func->makeVariable(Ty); | 1486 return Func->makeVariable(Ty); |
1522 } | 1487 } |
1523 | 1488 |
1524 // Generates the next available local variable using the given type. | 1489 // Generates the next available local variable using the given type. |
1525 Ice::Variable *getNextInstVar(Ice::Type Ty) { | 1490 Ice::Variable *getNextInstVar(Ice::Type Ty) { |
1526 assert(!isIRGenerationDisabled()); | |
1527 assert(NextLocalInstIndex >= CachedNumGlobalValueIDs); | 1491 assert(NextLocalInstIndex >= CachedNumGlobalValueIDs); |
1528 // Before creating one, see if a forwardtyperef has already defined it. | 1492 // Before creating one, see if a forwardtyperef has already defined it. |
1529 NaClBcIndexSize_t LocalIndex = NextLocalInstIndex - CachedNumGlobalValueIDs; | 1493 NaClBcIndexSize_t LocalIndex = NextLocalInstIndex - CachedNumGlobalValueIDs; |
1530 if (LocalIndex < LocalOperands.size()) { | 1494 if (LocalIndex < LocalOperands.size()) { |
1531 Ice::Operand *Op = LocalOperands[LocalIndex]; | 1495 Ice::Operand *Op = LocalOperands[LocalIndex]; |
1532 if (Op != nullptr) { | 1496 if (Op != nullptr) { |
1533 if (auto *Var = dyn_cast<Ice::Variable>(Op)) { | 1497 if (auto *Var = dyn_cast<Ice::Variable>(Op)) { |
1534 if (Var->getType() == Ty) { | 1498 if (Var->getType() == Ty) { |
1535 ++NextLocalInstIndex; | 1499 ++NextLocalInstIndex; |
1536 return Var; | 1500 return Var; |
(...skipping 22 matching lines...) Expand all Loading... | |
1559 StrBuf << "Invalid relative value id: " << Id | 1523 StrBuf << "Invalid relative value id: " << Id |
1560 << " (must be <= " << BaseIndex << ")"; | 1524 << " (must be <= " << BaseIndex << ")"; |
1561 Error(StrBuf.str()); | 1525 Error(StrBuf.str()); |
1562 return 0; | 1526 return 0; |
1563 } | 1527 } |
1564 return BaseIndex - Id; | 1528 return BaseIndex - Id; |
1565 } | 1529 } |
1566 | 1530 |
1567 // Sets element Index (in the local operands list) to Op. | 1531 // Sets element Index (in the local operands list) to Op. |
1568 void setOperand(NaClBcIndexSize_t Index, Ice::Operand *Op) { | 1532 void setOperand(NaClBcIndexSize_t Index, Ice::Operand *Op) { |
1569 assert(Op || isIRGenerationDisabled()); | 1533 assert(Op); |
1570 // Check if simple push works. | 1534 // Check if simple push works. |
1571 NaClBcIndexSize_t LocalIndex = Index - CachedNumGlobalValueIDs; | 1535 NaClBcIndexSize_t LocalIndex = Index - CachedNumGlobalValueIDs; |
1572 if (LocalIndex == LocalOperands.size()) { | 1536 if (LocalIndex == LocalOperands.size()) { |
1573 LocalOperands.push_back(Op); | 1537 LocalOperands.push_back(Op); |
1574 return; | 1538 return; |
1575 } | 1539 } |
1576 | 1540 |
1577 // Must be forward reference, expand vector to accommodate. | 1541 // Must be forward reference, expand vector to accommodate. |
1578 if (LocalIndex >= LocalOperands.size()) { | 1542 if (LocalIndex >= LocalOperands.size()) { |
1579 if (LocalIndex > MaxRecordsInBlock) { | 1543 if (LocalIndex > MaxRecordsInBlock) { |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2127 if (Fcn) | 2091 if (Fcn) |
2128 return Fcn->getName(); | 2092 return Fcn->getName(); |
2129 return "function"; | 2093 return "function"; |
2130 } | 2094 } |
2131 }; | 2095 }; |
2132 | 2096 |
2133 void FunctionParser::ExitBlock() { | 2097 void FunctionParser::ExitBlock() { |
2134 // Check if the last instruction in the function was terminating. | 2098 // Check if the last instruction in the function was terminating. |
2135 if (!InstIsTerminating) { | 2099 if (!InstIsTerminating) { |
2136 Error("Last instruction in function not terminator"); | 2100 Error("Last instruction in function not terminator"); |
2137 if (isIRGenerationDisabled()) | |
2138 return; | |
2139 // Recover by inserting an unreachable instruction. | 2101 // Recover by inserting an unreachable instruction. |
2140 CurrentNode->appendInst(Ice::InstUnreachable::create(Func.get())); | 2102 CurrentNode->appendInst(Ice::InstUnreachable::create(Func.get())); |
2141 } | 2103 } |
2142 ++CurrentBbIndex; | 2104 ++CurrentBbIndex; |
2143 if (CurrentBbIndex != DeclaredNumberBbs) { | 2105 if (CurrentBbIndex != DeclaredNumberBbs) { |
2144 std::string Buffer; | 2106 std::string Buffer; |
2145 raw_string_ostream StrBuf(Buffer); | 2107 raw_string_ostream StrBuf(Buffer); |
2146 StrBuf << "Function declared " << DeclaredNumberBbs | 2108 StrBuf << "Function declared " << DeclaredNumberBbs |
2147 << " basic blocks, but defined " << CurrentBbIndex << "."; | 2109 << " basic blocks, but defined " << CurrentBbIndex << "."; |
2148 Error(StrBuf.str()); | 2110 Error(StrBuf.str()); |
2149 } | 2111 } |
2150 if (isIRGenerationDisabled()) | |
2151 return; | |
2152 // Before translating, check for blocks without instructions, and insert | 2112 // Before translating, check for blocks without instructions, and insert |
2153 // unreachable. This shouldn't happen, but be safe. | 2113 // unreachable. This shouldn't happen, but be safe. |
2154 size_t Index = 0; | 2114 size_t Index = 0; |
2155 for (Ice::CfgNode *Node : Func->getNodes()) { | 2115 for (Ice::CfgNode *Node : Func->getNodes()) { |
2156 if (Node->getInsts().empty()) { | 2116 if (Node->getInsts().empty()) { |
2157 std::string Buffer; | 2117 std::string Buffer; |
2158 raw_string_ostream StrBuf(Buffer); | 2118 raw_string_ostream StrBuf(Buffer); |
2159 StrBuf << "Basic block " << Index << " contains no instructions"; | 2119 StrBuf << "Basic block " << Index << " contains no instructions"; |
2160 Error(StrBuf.str()); | 2120 Error(StrBuf.str()); |
2161 Node->appendInst(Ice::InstUnreachable::create(Func.get())); | 2121 Node->appendInst(Ice::InstUnreachable::create(Func.get())); |
(...skipping 14 matching lines...) Expand all Loading... | |
2176 | 2136 |
2177 void FunctionParser::ProcessRecord() { | 2137 void FunctionParser::ProcessRecord() { |
2178 // Note: To better separate parse/IR generation times, when IR generation is | 2138 // Note: To better separate parse/IR generation times, when IR generation is |
2179 // disabled we do the following: | 2139 // disabled we do the following: |
2180 // 1) Delay exiting until after we extract operands. | 2140 // 1) Delay exiting until after we extract operands. |
2181 // 2) return before we access operands, since all operands will be a nullptr. | 2141 // 2) return before we access operands, since all operands will be a nullptr. |
2182 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 2142 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
2183 if (InstIsTerminating) { | 2143 if (InstIsTerminating) { |
2184 InstIsTerminating = false; | 2144 InstIsTerminating = false; |
2185 ++CurrentBbIndex; | 2145 ++CurrentBbIndex; |
2186 if (!isIRGenerationDisabled()) | 2146 CurrentNode = getBasicBlock(CurrentBbIndex); |
2187 CurrentNode = getBasicBlock(CurrentBbIndex); | |
2188 } | 2147 } |
2189 // The base index for relative indexing. | 2148 // The base index for relative indexing. |
2190 NaClBcIndexSize_t BaseIndex = getNextInstIndex(); | 2149 NaClBcIndexSize_t BaseIndex = getNextInstIndex(); |
2191 switch (Record.GetCode()) { | 2150 switch (Record.GetCode()) { |
2192 case naclbitc::FUNC_CODE_DECLAREBLOCKS: { | 2151 case naclbitc::FUNC_CODE_DECLAREBLOCKS: { |
2193 // DECLAREBLOCKS: [n] | 2152 // DECLAREBLOCKS: [n] |
2194 if (!isValidRecordSize(1, "count")) | 2153 if (!isValidRecordSize(1, "count")) |
2195 return; | 2154 return; |
2196 if (DeclaredNumberBbs > 0) { | 2155 if (DeclaredNumberBbs > 0) { |
2197 Error("Duplicate function block count record"); | 2156 Error("Duplicate function block count record"); |
(...skipping 12 matching lines...) Expand all Loading... | |
2210 Error(StrBuf.str()); | 2169 Error(StrBuf.str()); |
2211 NumBbs = MaxRecordsInBlock; | 2170 NumBbs = MaxRecordsInBlock; |
2212 } | 2171 } |
2213 | 2172 |
2214 if (NumBbs == 0) { | 2173 if (NumBbs == 0) { |
2215 Error("Functions must contain at least one basic block."); | 2174 Error("Functions must contain at least one basic block."); |
2216 NumBbs = 1; | 2175 NumBbs = 1; |
2217 } | 2176 } |
2218 | 2177 |
2219 DeclaredNumberBbs = NumBbs; | 2178 DeclaredNumberBbs = NumBbs; |
2220 if (isIRGenerationDisabled()) | |
2221 return; | |
2222 // Install the basic blocks, skipping bb0 which was created in the | 2179 // Install the basic blocks, skipping bb0 which was created in the |
2223 // constructor. | 2180 // constructor. |
2224 for (size_t i = 1; i < NumBbs; ++i) | 2181 for (size_t i = 1; i < NumBbs; ++i) |
2225 installNextBasicBlock(); | 2182 installNextBasicBlock(); |
2226 return; | 2183 return; |
2227 } | 2184 } |
2228 case naclbitc::FUNC_CODE_INST_BINOP: { | 2185 case naclbitc::FUNC_CODE_INST_BINOP: { |
2229 // BINOP: [opval, opval, opcode] | 2186 // BINOP: [opval, opval, opcode] |
2230 if (!isValidRecordSize(3, "binop")) | 2187 if (!isValidRecordSize(3, "binop")) |
2231 return; | 2188 return; |
2232 Ice::Operand *Op1 = getRelativeOperand(Values[0], BaseIndex); | 2189 Ice::Operand *Op1 = getRelativeOperand(Values[0], BaseIndex); |
2233 Ice::Operand *Op2 = getRelativeOperand(Values[1], BaseIndex); | 2190 Ice::Operand *Op2 = getRelativeOperand(Values[1], BaseIndex); |
2234 if (isIRGenerationDisabled()) { | |
2235 assert(Op1 == nullptr && Op2 == nullptr); | |
2236 setNextLocalInstIndex(nullptr); | |
2237 return; | |
2238 } | |
2239 Ice::Type Type1 = Op1->getType(); | 2191 Ice::Type Type1 = Op1->getType(); |
2240 Ice::Type Type2 = Op2->getType(); | 2192 Ice::Type Type2 = Op2->getType(); |
2241 if (Type1 != Type2) { | 2193 if (Type1 != Type2) { |
2242 std::string Buffer; | 2194 std::string Buffer; |
2243 raw_string_ostream StrBuf(Buffer); | 2195 raw_string_ostream StrBuf(Buffer); |
2244 StrBuf << "Binop argument types differ: " << Type1 << " and " << Type2; | 2196 StrBuf << "Binop argument types differ: " << Type1 << " and " << Type2; |
2245 Error(StrBuf.str()); | 2197 Error(StrBuf.str()); |
2246 appendErrorInstruction(Type1); | 2198 appendErrorInstruction(Type1); |
2247 return; | 2199 return; |
2248 } | 2200 } |
2249 | 2201 |
2250 Ice::InstArithmetic::OpKind Opcode; | 2202 Ice::InstArithmetic::OpKind Opcode; |
2251 if (!convertBinopOpcode(Values[2], Type1, Opcode)) { | 2203 if (!convertBinopOpcode(Values[2], Type1, Opcode)) { |
2252 appendErrorInstruction(Type1); | 2204 appendErrorInstruction(Type1); |
2253 return; | 2205 return; |
2254 } | 2206 } |
2255 CurrentNode->appendInst(Ice::InstArithmetic::create( | 2207 CurrentNode->appendInst(Ice::InstArithmetic::create( |
2256 Func.get(), Opcode, getNextInstVar(Type1), Op1, Op2)); | 2208 Func.get(), Opcode, getNextInstVar(Type1), Op1, Op2)); |
2257 return; | 2209 return; |
2258 } | 2210 } |
2259 case naclbitc::FUNC_CODE_INST_CAST: { | 2211 case naclbitc::FUNC_CODE_INST_CAST: { |
2260 // CAST: [opval, destty, castopc] | 2212 // CAST: [opval, destty, castopc] |
2261 if (!isValidRecordSize(3, "cast")) | 2213 if (!isValidRecordSize(3, "cast")) |
2262 return; | 2214 return; |
2263 Ice::Operand *Src = getRelativeOperand(Values[0], BaseIndex); | 2215 Ice::Operand *Src = getRelativeOperand(Values[0], BaseIndex); |
2264 Ice::Type CastType = Context->getSimpleTypeByID(Values[1]); | 2216 Ice::Type CastType = Context->getSimpleTypeByID(Values[1]); |
2265 Ice::InstCast::OpKind CastKind; | 2217 Ice::InstCast::OpKind CastKind; |
2266 if (isIRGenerationDisabled()) { | |
2267 assert(Src == nullptr); | |
2268 setNextLocalInstIndex(nullptr); | |
2269 return; | |
2270 } | |
2271 if (!convertCastOpToIceOp(Values[2], Src->getType(), CastType, CastKind)) { | 2218 if (!convertCastOpToIceOp(Values[2], Src->getType(), CastType, CastKind)) { |
2272 appendErrorInstruction(CastType); | 2219 appendErrorInstruction(CastType); |
2273 return; | 2220 return; |
2274 } | 2221 } |
2275 CurrentNode->appendInst(Ice::InstCast::create( | 2222 CurrentNode->appendInst(Ice::InstCast::create( |
2276 Func.get(), CastKind, getNextInstVar(CastType), Src)); | 2223 Func.get(), CastKind, getNextInstVar(CastType), Src)); |
2277 return; | 2224 return; |
2278 } | 2225 } |
2279 case naclbitc::FUNC_CODE_INST_VSELECT: { | 2226 case naclbitc::FUNC_CODE_INST_VSELECT: { |
2280 // VSELECT: [opval, opval, pred] | 2227 // VSELECT: [opval, opval, pred] |
2281 if (!isValidRecordSize(3, "select")) | 2228 if (!isValidRecordSize(3, "select")) |
2282 return; | 2229 return; |
2283 Ice::Operand *ThenVal = getRelativeOperand(Values[0], BaseIndex); | 2230 Ice::Operand *ThenVal = getRelativeOperand(Values[0], BaseIndex); |
2284 Ice::Operand *ElseVal = getRelativeOperand(Values[1], BaseIndex); | 2231 Ice::Operand *ElseVal = getRelativeOperand(Values[1], BaseIndex); |
2285 Ice::Operand *CondVal = getRelativeOperand(Values[2], BaseIndex); | 2232 Ice::Operand *CondVal = getRelativeOperand(Values[2], BaseIndex); |
2286 if (isIRGenerationDisabled()) { | |
2287 assert(ThenVal == nullptr && ElseVal == nullptr && CondVal == nullptr); | |
2288 setNextLocalInstIndex(nullptr); | |
2289 return; | |
2290 } | |
2291 Ice::Type ThenType = ThenVal->getType(); | 2233 Ice::Type ThenType = ThenVal->getType(); |
2292 Ice::Type ElseType = ElseVal->getType(); | 2234 Ice::Type ElseType = ElseVal->getType(); |
2293 if (ThenType != ElseType) { | 2235 if (ThenType != ElseType) { |
2294 std::string Buffer; | 2236 std::string Buffer; |
2295 raw_string_ostream StrBuf(Buffer); | 2237 raw_string_ostream StrBuf(Buffer); |
2296 StrBuf << "Select operands not same type. Found " << ThenType << " and " | 2238 StrBuf << "Select operands not same type. Found " << ThenType << " and " |
2297 << ElseType; | 2239 << ElseType; |
2298 Error(StrBuf.str()); | 2240 Error(StrBuf.str()); |
2299 appendErrorInstruction(ThenType); | 2241 appendErrorInstruction(ThenType); |
2300 return; | 2242 return; |
(...skipping 23 matching lines...) Expand all Loading... | |
2324 CurrentNode->appendInst(Ice::InstSelect::create( | 2266 CurrentNode->appendInst(Ice::InstSelect::create( |
2325 Func.get(), getNextInstVar(ThenType), CondVal, ThenVal, ElseVal)); | 2267 Func.get(), getNextInstVar(ThenType), CondVal, ThenVal, ElseVal)); |
2326 return; | 2268 return; |
2327 } | 2269 } |
2328 case naclbitc::FUNC_CODE_INST_EXTRACTELT: { | 2270 case naclbitc::FUNC_CODE_INST_EXTRACTELT: { |
2329 // EXTRACTELT: [opval, opval] | 2271 // EXTRACTELT: [opval, opval] |
2330 if (!isValidRecordSize(2, "extract element")) | 2272 if (!isValidRecordSize(2, "extract element")) |
2331 return; | 2273 return; |
2332 Ice::Operand *Vec = getRelativeOperand(Values[0], BaseIndex); | 2274 Ice::Operand *Vec = getRelativeOperand(Values[0], BaseIndex); |
2333 Ice::Operand *Index = getRelativeOperand(Values[1], BaseIndex); | 2275 Ice::Operand *Index = getRelativeOperand(Values[1], BaseIndex); |
2334 if (isIRGenerationDisabled()) { | |
2335 assert(Vec == nullptr && Index == nullptr); | |
2336 setNextLocalInstIndex(nullptr); | |
2337 return; | |
2338 } | |
2339 Ice::Type VecType = Vec->getType(); | 2276 Ice::Type VecType = Vec->getType(); |
2340 VectorIndexCheckValue IndexCheckValue = validateVectorIndex(Vec, Index); | 2277 VectorIndexCheckValue IndexCheckValue = validateVectorIndex(Vec, Index); |
2341 if (IndexCheckValue != VectorIndexValid) { | 2278 if (IndexCheckValue != VectorIndexValid) { |
2342 std::string Buffer; | 2279 std::string Buffer; |
2343 raw_string_ostream StrBuf(Buffer); | 2280 raw_string_ostream StrBuf(Buffer); |
2344 dumpVectorIndexCheckValue(StrBuf, IndexCheckValue); | 2281 dumpVectorIndexCheckValue(StrBuf, IndexCheckValue); |
2345 StrBuf << ": extractelement " << VecType << " " << *Vec << ", " | 2282 StrBuf << ": extractelement " << VecType << " " << *Vec << ", " |
2346 << Index->getType() << " " << *Index; | 2283 << Index->getType() << " " << *Index; |
2347 Error(StrBuf.str()); | 2284 Error(StrBuf.str()); |
2348 appendErrorInstruction(VecType); | 2285 appendErrorInstruction(VecType); |
2349 return; | 2286 return; |
2350 } | 2287 } |
2351 CurrentNode->appendInst(Ice::InstExtractElement::create( | 2288 CurrentNode->appendInst(Ice::InstExtractElement::create( |
2352 Func.get(), getNextInstVar(typeElementType(VecType)), Vec, Index)); | 2289 Func.get(), getNextInstVar(typeElementType(VecType)), Vec, Index)); |
2353 return; | 2290 return; |
2354 } | 2291 } |
2355 case naclbitc::FUNC_CODE_INST_INSERTELT: { | 2292 case naclbitc::FUNC_CODE_INST_INSERTELT: { |
2356 // INSERTELT: [opval, opval, opval] | 2293 // INSERTELT: [opval, opval, opval] |
2357 if (!isValidRecordSize(3, "insert element")) | 2294 if (!isValidRecordSize(3, "insert element")) |
2358 return; | 2295 return; |
2359 Ice::Operand *Vec = getRelativeOperand(Values[0], BaseIndex); | 2296 Ice::Operand *Vec = getRelativeOperand(Values[0], BaseIndex); |
2360 Ice::Operand *Elt = getRelativeOperand(Values[1], BaseIndex); | 2297 Ice::Operand *Elt = getRelativeOperand(Values[1], BaseIndex); |
2361 Ice::Operand *Index = getRelativeOperand(Values[2], BaseIndex); | 2298 Ice::Operand *Index = getRelativeOperand(Values[2], BaseIndex); |
2362 if (isIRGenerationDisabled()) { | |
2363 assert(Vec == nullptr && Elt == nullptr && Index == nullptr); | |
2364 setNextLocalInstIndex(nullptr); | |
2365 return; | |
2366 } | |
2367 Ice::Type VecType = Vec->getType(); | 2299 Ice::Type VecType = Vec->getType(); |
2368 VectorIndexCheckValue IndexCheckValue = validateVectorIndex(Vec, Index); | 2300 VectorIndexCheckValue IndexCheckValue = validateVectorIndex(Vec, Index); |
2369 if (IndexCheckValue != VectorIndexValid) { | 2301 if (IndexCheckValue != VectorIndexValid) { |
2370 std::string Buffer; | 2302 std::string Buffer; |
2371 raw_string_ostream StrBuf(Buffer); | 2303 raw_string_ostream StrBuf(Buffer); |
2372 dumpVectorIndexCheckValue(StrBuf, IndexCheckValue); | 2304 dumpVectorIndexCheckValue(StrBuf, IndexCheckValue); |
2373 StrBuf << ": insertelement " << VecType << " " << *Vec << ", " | 2305 StrBuf << ": insertelement " << VecType << " " << *Vec << ", " |
2374 << Elt->getType() << " " << *Elt << ", " << Index->getType() << " " | 2306 << Elt->getType() << " " << *Elt << ", " << Index->getType() << " " |
2375 << *Index; | 2307 << *Index; |
2376 Error(StrBuf.str()); | 2308 Error(StrBuf.str()); |
(...skipping 13 matching lines...) Expand all Loading... | |
2390 CurrentNode->appendInst(Ice::InstInsertElement::create( | 2322 CurrentNode->appendInst(Ice::InstInsertElement::create( |
2391 Func.get(), getNextInstVar(VecType), Vec, Elt, Index)); | 2323 Func.get(), getNextInstVar(VecType), Vec, Elt, Index)); |
2392 return; | 2324 return; |
2393 } | 2325 } |
2394 case naclbitc::FUNC_CODE_INST_CMP2: { | 2326 case naclbitc::FUNC_CODE_INST_CMP2: { |
2395 // CMP2: [opval, opval, pred] | 2327 // CMP2: [opval, opval, pred] |
2396 if (!isValidRecordSize(3, "compare")) | 2328 if (!isValidRecordSize(3, "compare")) |
2397 return; | 2329 return; |
2398 Ice::Operand *Op1 = getRelativeOperand(Values[0], BaseIndex); | 2330 Ice::Operand *Op1 = getRelativeOperand(Values[0], BaseIndex); |
2399 Ice::Operand *Op2 = getRelativeOperand(Values[1], BaseIndex); | 2331 Ice::Operand *Op2 = getRelativeOperand(Values[1], BaseIndex); |
2400 if (isIRGenerationDisabled()) { | |
2401 assert(Op1 == nullptr && Op2 == nullptr); | |
2402 setNextLocalInstIndex(nullptr); | |
2403 return; | |
2404 } | |
2405 Ice::Type Op1Type = Op1->getType(); | 2332 Ice::Type Op1Type = Op1->getType(); |
2406 Ice::Type Op2Type = Op2->getType(); | 2333 Ice::Type Op2Type = Op2->getType(); |
2407 Ice::Type DestType = getCompareResultType(Op1Type); | 2334 Ice::Type DestType = getCompareResultType(Op1Type); |
2408 if (Op1Type != Op2Type) { | 2335 if (Op1Type != Op2Type) { |
2409 std::string Buffer; | 2336 std::string Buffer; |
2410 raw_string_ostream StrBuf(Buffer); | 2337 raw_string_ostream StrBuf(Buffer); |
2411 StrBuf << "Compare argument types differ: " << Op1Type << " and " | 2338 StrBuf << "Compare argument types differ: " << Op1Type << " and " |
2412 << Op2Type; | 2339 << Op2Type; |
2413 Error(StrBuf.str()); | 2340 Error(StrBuf.str()); |
2414 appendErrorInstruction(DestType); | 2341 appendErrorInstruction(DestType); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2456 return; | 2383 return; |
2457 } | 2384 } |
2458 return; | 2385 return; |
2459 } | 2386 } |
2460 case naclbitc::FUNC_CODE_INST_RET: { | 2387 case naclbitc::FUNC_CODE_INST_RET: { |
2461 // RET: [opval?] | 2388 // RET: [opval?] |
2462 InstIsTerminating = true; | 2389 InstIsTerminating = true; |
2463 if (!isValidRecordSizeInRange(0, 1, "return")) | 2390 if (!isValidRecordSizeInRange(0, 1, "return")) |
2464 return; | 2391 return; |
2465 if (Values.empty()) { | 2392 if (Values.empty()) { |
2466 if (isIRGenerationDisabled()) | |
2467 return; | |
2468 CurrentNode->appendInst(Ice::InstRet::create(Func.get())); | 2393 CurrentNode->appendInst(Ice::InstRet::create(Func.get())); |
2469 } else { | 2394 } else { |
2470 Ice::Operand *RetVal = getRelativeOperand(Values[0], BaseIndex); | 2395 Ice::Operand *RetVal = getRelativeOperand(Values[0], BaseIndex); |
2471 if (isIRGenerationDisabled()) { | |
2472 assert(RetVal == nullptr); | |
2473 return; | |
2474 } | |
2475 CurrentNode->appendInst(Ice::InstRet::create(Func.get(), RetVal)); | 2396 CurrentNode->appendInst(Ice::InstRet::create(Func.get(), RetVal)); |
2476 } | 2397 } |
2477 return; | 2398 return; |
2478 } | 2399 } |
2479 case naclbitc::FUNC_CODE_INST_BR: { | 2400 case naclbitc::FUNC_CODE_INST_BR: { |
2480 InstIsTerminating = true; | 2401 InstIsTerminating = true; |
2481 if (Values.size() == 1) { | 2402 if (Values.size() == 1) { |
2482 // BR: [bb#] | 2403 // BR: [bb#] |
2483 if (isIRGenerationDisabled()) | |
2484 return; | |
2485 Ice::CfgNode *Block = getBranchBasicBlock(Values[0]); | 2404 Ice::CfgNode *Block = getBranchBasicBlock(Values[0]); |
2486 if (Block == nullptr) | 2405 if (Block == nullptr) |
2487 return; | 2406 return; |
2488 CurrentNode->appendInst(Ice::InstBr::create(Func.get(), Block)); | 2407 CurrentNode->appendInst(Ice::InstBr::create(Func.get(), Block)); |
2489 } else { | 2408 } else { |
2490 // BR: [bb#, bb#, opval] | 2409 // BR: [bb#, bb#, opval] |
2491 if (!isValidRecordSize(3, "branch")) | 2410 if (!isValidRecordSize(3, "branch")) |
2492 return; | 2411 return; |
2493 Ice::Operand *Cond = getRelativeOperand(Values[2], BaseIndex); | 2412 Ice::Operand *Cond = getRelativeOperand(Values[2], BaseIndex); |
2494 if (isIRGenerationDisabled()) { | |
2495 assert(Cond == nullptr); | |
2496 return; | |
2497 } | |
2498 if (Cond->getType() != Ice::IceType_i1) { | 2413 if (Cond->getType() != Ice::IceType_i1) { |
2499 std::string Buffer; | 2414 std::string Buffer; |
2500 raw_string_ostream StrBuf(Buffer); | 2415 raw_string_ostream StrBuf(Buffer); |
2501 StrBuf << "Branch condition " << *Cond | 2416 StrBuf << "Branch condition " << *Cond |
2502 << " not i1. Found: " << Cond->getType(); | 2417 << " not i1. Found: " << Cond->getType(); |
2503 Error(StrBuf.str()); | 2418 Error(StrBuf.str()); |
2504 return; | 2419 return; |
2505 } | 2420 } |
2506 Ice::CfgNode *ThenBlock = getBranchBasicBlock(Values[0]); | 2421 Ice::CfgNode *ThenBlock = getBranchBasicBlock(Values[0]); |
2507 Ice::CfgNode *ElseBlock = getBranchBasicBlock(Values[1]); | 2422 Ice::CfgNode *ElseBlock = getBranchBasicBlock(Values[1]); |
(...skipping 20 matching lines...) Expand all Loading... | |
2528 if (!Ice::isScalarIntegerType(CondTy)) { | 2443 if (!Ice::isScalarIntegerType(CondTy)) { |
2529 std::string Buffer; | 2444 std::string Buffer; |
2530 raw_string_ostream StrBuf(Buffer); | 2445 raw_string_ostream StrBuf(Buffer); |
2531 StrBuf << "Case condition must be non-wide integer. Found: " << CondTy; | 2446 StrBuf << "Case condition must be non-wide integer. Found: " << CondTy; |
2532 Error(StrBuf.str()); | 2447 Error(StrBuf.str()); |
2533 return; | 2448 return; |
2534 } | 2449 } |
2535 Ice::SizeT BitWidth = Ice::getScalarIntBitWidth(CondTy); | 2450 Ice::SizeT BitWidth = Ice::getScalarIntBitWidth(CondTy); |
2536 Ice::Operand *Cond = getRelativeOperand(Values[1], BaseIndex); | 2451 Ice::Operand *Cond = getRelativeOperand(Values[1], BaseIndex); |
2537 | 2452 |
2538 const bool isIRGenDisabled = isIRGenerationDisabled(); | 2453 |
2539 if (isIRGenDisabled) { | 2454 if (CondTy != Cond->getType()) { |
2540 assert(Cond == nullptr); | |
2541 } else if (CondTy != Cond->getType()) { | |
2542 std::string Buffer; | 2455 std::string Buffer; |
2543 raw_string_ostream StrBuf(Buffer); | 2456 raw_string_ostream StrBuf(Buffer); |
2544 StrBuf << "Case condition expects type " << CondTy | 2457 StrBuf << "Case condition expects type " << CondTy |
2545 << ". Found: " << Cond->getType(); | 2458 << ". Found: " << Cond->getType(); |
2546 Error(StrBuf.str()); | 2459 Error(StrBuf.str()); |
2547 return; | 2460 return; |
2548 } | 2461 } |
2549 Ice::CfgNode *DefaultLabel = | 2462 Ice::CfgNode *DefaultLabel = getBranchBasicBlock(Values[2]); |
2550 isIRGenDisabled ? nullptr : getBranchBasicBlock(Values[2]); | |
2551 if (DefaultLabel == nullptr) | 2463 if (DefaultLabel == nullptr) |
2552 return; | 2464 return; |
2553 uint64_t NumCasesRaw = Values[3]; | 2465 uint64_t NumCasesRaw = Values[3]; |
2554 if (NumCasesRaw > std::numeric_limits<uint32_t>::max()) { | 2466 if (NumCasesRaw > std::numeric_limits<uint32_t>::max()) { |
2555 std::string Buffer; | 2467 std::string Buffer; |
2556 raw_string_ostream StrBuf(Buffer); | 2468 raw_string_ostream StrBuf(Buffer); |
2557 StrBuf << "Too many cases specified in switch: " << NumCasesRaw; | 2469 StrBuf << "Too many cases specified in switch: " << NumCasesRaw; |
2558 Error(StrBuf.str()); | 2470 Error(StrBuf.str()); |
2559 NumCasesRaw = std::numeric_limits<uint32_t>::max(); | 2471 NumCasesRaw = std::numeric_limits<uint32_t>::max(); |
2560 } | 2472 } |
2561 uint32_t NumCases = NumCasesRaw; | 2473 uint32_t NumCases = NumCasesRaw; |
2562 | 2474 |
2563 // Now recognize each of the cases. | 2475 // Now recognize each of the cases. |
2564 if (!isValidRecordSize(4 + NumCases * 4, "switch")) | 2476 if (!isValidRecordSize(4 + NumCases * 4, "switch")) |
2565 return; | 2477 return; |
2566 std::unique_ptr<Ice::InstSwitch> Switch( | 2478 std::unique_ptr<Ice::InstSwitch> Switch( |
2567 isIRGenDisabled ? nullptr | 2479 Ice::InstSwitch::create(Func.get(), NumCases, Cond, |
2568 : Ice::InstSwitch::create(Func.get(), NumCases, Cond, | |
2569 DefaultLabel)); | 2480 DefaultLabel)); |
2570 unsigned ValCaseIndex = 4; // index to beginning of case entry. | 2481 unsigned ValCaseIndex = 4; // index to beginning of case entry. |
2571 for (uint32_t CaseIndex = 0; CaseIndex < NumCases; | 2482 for (uint32_t CaseIndex = 0; CaseIndex < NumCases; |
2572 ++CaseIndex, ValCaseIndex += 4) { | 2483 ++CaseIndex, ValCaseIndex += 4) { |
2573 if (Values[ValCaseIndex] != 1 || Values[ValCaseIndex + 1] != 1) { | 2484 if (Values[ValCaseIndex] != 1 || Values[ValCaseIndex + 1] != 1) { |
2574 std::string Buffer; | 2485 std::string Buffer; |
2575 raw_string_ostream StrBuf(Buffer); | 2486 raw_string_ostream StrBuf(Buffer); |
2576 StrBuf << "Sequence [1, 1, value, label] expected for case entry " | 2487 StrBuf << "Sequence [1, 1, value, label] expected for case entry " |
2577 << "in switch record. (at index" << ValCaseIndex << ")"; | 2488 << "in switch record. (at index" << ValCaseIndex << ")"; |
2578 Error(StrBuf.str()); | 2489 Error(StrBuf.str()); |
2579 return; | 2490 return; |
2580 } | 2491 } |
2581 BitcodeInt Value(BitWidth, | 2492 BitcodeInt Value(BitWidth, |
2582 NaClDecodeSignRotatedValue(Values[ValCaseIndex + 2])); | 2493 NaClDecodeSignRotatedValue(Values[ValCaseIndex + 2])); |
2583 if (isIRGenDisabled) | |
2584 continue; | |
2585 Ice::CfgNode *Label = getBranchBasicBlock(Values[ValCaseIndex + 3]); | 2494 Ice::CfgNode *Label = getBranchBasicBlock(Values[ValCaseIndex + 3]); |
2586 if (Label == nullptr) | 2495 if (Label == nullptr) |
2587 return; | 2496 return; |
2588 Switch->addBranch(CaseIndex, Value.getSExtValue(), Label); | 2497 Switch->addBranch(CaseIndex, Value.getSExtValue(), Label); |
2589 } | 2498 } |
2590 if (isIRGenDisabled) | |
2591 return; | |
2592 CurrentNode->appendInst(Switch.release()); | 2499 CurrentNode->appendInst(Switch.release()); |
2593 return; | 2500 return; |
2594 } | 2501 } |
2595 case naclbitc::FUNC_CODE_INST_UNREACHABLE: { | 2502 case naclbitc::FUNC_CODE_INST_UNREACHABLE: { |
2596 // UNREACHABLE: [] | 2503 // UNREACHABLE: [] |
2597 InstIsTerminating = true; | 2504 InstIsTerminating = true; |
2598 if (!isValidRecordSize(0, "unreachable")) | 2505 if (!isValidRecordSize(0, "unreachable")) |
2599 return; | 2506 return; |
2600 if (isIRGenerationDisabled()) | |
2601 return; | |
2602 CurrentNode->appendInst(Ice::InstUnreachable::create(Func.get())); | 2507 CurrentNode->appendInst(Ice::InstUnreachable::create(Func.get())); |
2603 return; | 2508 return; |
2604 } | 2509 } |
2605 case naclbitc::FUNC_CODE_INST_PHI: { | 2510 case naclbitc::FUNC_CODE_INST_PHI: { |
2606 // PHI: [ty, val1, bb1, ..., valN, bbN] for n >= 2. | 2511 // PHI: [ty, val1, bb1, ..., valN, bbN] for n >= 2. |
2607 if (!isValidRecordSizeAtLeast(3, "phi")) | 2512 if (!isValidRecordSizeAtLeast(3, "phi")) |
2608 return; | 2513 return; |
2609 Ice::Type Ty = Context->getSimpleTypeByID(Values[0]); | 2514 Ice::Type Ty = Context->getSimpleTypeByID(Values[0]); |
2610 if ((Values.size() & 0x1) == 0) { | 2515 if ((Values.size() & 0x1) == 0) { |
2611 // Not an odd number of values. | 2516 // Not an odd number of values. |
2612 std::string Buffer; | 2517 std::string Buffer; |
2613 raw_string_ostream StrBuf(Buffer); | 2518 raw_string_ostream StrBuf(Buffer); |
2614 StrBuf << "function block phi record size not valid: " << Values.size(); | 2519 StrBuf << "function block phi record size not valid: " << Values.size(); |
2615 Error(StrBuf.str()); | 2520 Error(StrBuf.str()); |
2616 appendErrorInstruction(Ty); | 2521 appendErrorInstruction(Ty); |
2617 return; | 2522 return; |
2618 } | 2523 } |
2619 if (Ty == Ice::IceType_void) { | 2524 if (Ty == Ice::IceType_void) { |
2620 Error("Phi record using type void not allowed"); | 2525 Error("Phi record using type void not allowed"); |
2621 return; | 2526 return; |
2622 } | 2527 } |
2623 if (isIRGenerationDisabled()) { | |
2624 // Verify arguments are defined before quitting. | |
2625 for (unsigned i = 1; i < Values.size(); i += 2) { | |
2626 assert(getRelativeOperand(NaClDecodeSignRotatedValue(Values[i]), | |
2627 BaseIndex) == nullptr); | |
2628 } | |
2629 setNextLocalInstIndex(nullptr); | |
2630 return; | |
2631 } | |
2632 Ice::Variable *Dest = getNextInstVar(Ty); | 2528 Ice::Variable *Dest = getNextInstVar(Ty); |
2633 Ice::InstPhi *Phi = | 2529 Ice::InstPhi *Phi = |
2634 Ice::InstPhi::create(Func.get(), Values.size() >> 1, Dest); | 2530 Ice::InstPhi::create(Func.get(), Values.size() >> 1, Dest); |
2635 for (size_t i = 1; i < Values.size(); i += 2) { | 2531 for (size_t i = 1; i < Values.size(); i += 2) { |
2636 Ice::Operand *Op = | 2532 Ice::Operand *Op = |
2637 getRelativeOperand(NaClDecodeSignRotatedValue(Values[i]), BaseIndex); | 2533 getRelativeOperand(NaClDecodeSignRotatedValue(Values[i]), BaseIndex); |
2638 if (Op->getType() != Ty) { | 2534 if (Op->getType() != Ty) { |
2639 std::string Buffer; | 2535 std::string Buffer; |
2640 raw_string_ostream StrBuf(Buffer); | 2536 raw_string_ostream StrBuf(Buffer); |
2641 StrBuf << "Value " << *Op << " not type " << Ty | 2537 StrBuf << "Value " << *Op << " not type " << Ty |
2642 << " in phi instruction. Found: " << Op->getType(); | 2538 << " in phi instruction. Found: " << Op->getType(); |
2643 Error(StrBuf.str()); | 2539 Error(StrBuf.str()); |
2644 appendErrorInstruction(Ty); | 2540 appendErrorInstruction(Ty); |
2645 return; | 2541 return; |
2646 } | 2542 } |
2647 Phi->addArgument(Op, getBasicBlock(Values[i + 1])); | 2543 Phi->addArgument(Op, getBasicBlock(Values[i + 1])); |
2648 } | 2544 } |
2649 CurrentNode->appendInst(Phi); | 2545 CurrentNode->appendInst(Phi); |
2650 return; | 2546 return; |
2651 } | 2547 } |
2652 case naclbitc::FUNC_CODE_INST_ALLOCA: { | 2548 case naclbitc::FUNC_CODE_INST_ALLOCA: { |
2653 // ALLOCA: [Size, align] | 2549 // ALLOCA: [Size, align] |
2654 if (!isValidRecordSize(2, "alloca")) | 2550 if (!isValidRecordSize(2, "alloca")) |
2655 return; | 2551 return; |
2656 Ice::Operand *ByteCount = getRelativeOperand(Values[0], BaseIndex); | 2552 Ice::Operand *ByteCount = getRelativeOperand(Values[0], BaseIndex); |
2657 uint32_t Alignment = Context->extractAlignment(this, "Alloca", Values[1]); | 2553 uint32_t Alignment = Context->extractAlignment(this, "Alloca", Values[1]); |
2658 if (isIRGenerationDisabled()) { | |
2659 assert(ByteCount == nullptr); | |
2660 setNextLocalInstIndex(nullptr); | |
2661 return; | |
2662 } | |
2663 Ice::Type PtrTy = Ice::getPointerType(); | 2554 Ice::Type PtrTy = Ice::getPointerType(); |
2664 if (ByteCount->getType() != Ice::IceType_i32) { | 2555 if (ByteCount->getType() != Ice::IceType_i32) { |
2665 std::string Buffer; | 2556 std::string Buffer; |
2666 raw_string_ostream StrBuf(Buffer); | 2557 raw_string_ostream StrBuf(Buffer); |
2667 StrBuf << "Alloca on non-i32 value. Found: " << *ByteCount; | 2558 StrBuf << "Alloca on non-i32 value. Found: " << *ByteCount; |
2668 Error(StrBuf.str()); | 2559 Error(StrBuf.str()); |
2669 appendErrorInstruction(PtrTy); | 2560 appendErrorInstruction(PtrTy); |
2670 return; | 2561 return; |
2671 } | 2562 } |
2672 CurrentNode->appendInst(Ice::InstAlloca::create( | 2563 CurrentNode->appendInst(Ice::InstAlloca::create( |
2673 Func.get(), getNextInstVar(PtrTy), ByteCount, Alignment)); | 2564 Func.get(), getNextInstVar(PtrTy), ByteCount, Alignment)); |
2674 return; | 2565 return; |
2675 } | 2566 } |
2676 case naclbitc::FUNC_CODE_INST_LOAD: { | 2567 case naclbitc::FUNC_CODE_INST_LOAD: { |
2677 // LOAD: [address, align, ty] | 2568 // LOAD: [address, align, ty] |
2678 if (!isValidRecordSize(3, "load")) | 2569 if (!isValidRecordSize(3, "load")) |
2679 return; | 2570 return; |
2680 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); | 2571 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); |
2681 Ice::Type Ty = Context->getSimpleTypeByID(Values[2]); | 2572 Ice::Type Ty = Context->getSimpleTypeByID(Values[2]); |
2682 uint32_t Alignment = Context->extractAlignment(this, "Load", Values[1]); | 2573 uint32_t Alignment = Context->extractAlignment(this, "Load", Values[1]); |
2683 if (isIRGenerationDisabled()) { | |
2684 assert(Address == nullptr); | |
2685 setNextLocalInstIndex(nullptr); | |
2686 return; | |
2687 } | |
2688 if (!isValidPointerType(Address, "Load")) { | 2574 if (!isValidPointerType(Address, "Load")) { |
2689 appendErrorInstruction(Ty); | 2575 appendErrorInstruction(Ty); |
2690 return; | 2576 return; |
2691 } | 2577 } |
2692 if (!isValidLoadStoreAlignment(Alignment, Ty, "Load")) { | 2578 if (!isValidLoadStoreAlignment(Alignment, Ty, "Load")) { |
2693 appendErrorInstruction(Ty); | 2579 appendErrorInstruction(Ty); |
2694 return; | 2580 return; |
2695 } | 2581 } |
2696 CurrentNode->appendInst(Ice::InstLoad::create( | 2582 CurrentNode->appendInst(Ice::InstLoad::create( |
2697 Func.get(), getNextInstVar(Ty), Address, Alignment)); | 2583 Func.get(), getNextInstVar(Ty), Address, Alignment)); |
2698 return; | 2584 return; |
2699 } | 2585 } |
2700 case naclbitc::FUNC_CODE_INST_STORE: { | 2586 case naclbitc::FUNC_CODE_INST_STORE: { |
2701 // STORE: [address, value, align] | 2587 // STORE: [address, value, align] |
2702 if (!isValidRecordSize(3, "store")) | 2588 if (!isValidRecordSize(3, "store")) |
2703 return; | 2589 return; |
2704 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); | 2590 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); |
2705 Ice::Operand *Value = getRelativeOperand(Values[1], BaseIndex); | 2591 Ice::Operand *Value = getRelativeOperand(Values[1], BaseIndex); |
2706 uint32_t Alignment = Context->extractAlignment(this, "Store", Values[2]); | 2592 uint32_t Alignment = Context->extractAlignment(this, "Store", Values[2]); |
2707 if (isIRGenerationDisabled()) { | |
2708 assert(Address == nullptr && Value == nullptr); | |
2709 return; | |
2710 } | |
2711 if (!isValidPointerType(Address, "Store")) | 2593 if (!isValidPointerType(Address, "Store")) |
2712 return; | 2594 return; |
2713 if (!isValidLoadStoreAlignment(Alignment, Value->getType(), "Store")) | 2595 if (!isValidLoadStoreAlignment(Alignment, Value->getType(), "Store")) |
2714 return; | 2596 return; |
2715 CurrentNode->appendInst( | 2597 CurrentNode->appendInst( |
2716 Ice::InstStore::create(Func.get(), Value, Address, Alignment)); | 2598 Ice::InstStore::create(Func.get(), Value, Address, Alignment)); |
2717 return; | 2599 return; |
2718 } | 2600 } |
2719 case naclbitc::FUNC_CODE_INST_CALL: | 2601 case naclbitc::FUNC_CODE_INST_CALL: |
2720 case naclbitc::FUNC_CODE_INST_CALL_INDIRECT: { | 2602 case naclbitc::FUNC_CODE_INST_CALL_INDIRECT: { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2778 StrBuf << "Call to " << printName(Fcn) << " has " << NumParams | 2660 StrBuf << "Call to " << printName(Fcn) << " has " << NumParams |
2779 << " parameters. Intrinsic expects: " << Signature->getNumArgs(); | 2661 << " parameters. Intrinsic expects: " << Signature->getNumArgs(); |
2780 Error(StrBuf.str()); | 2662 Error(StrBuf.str()); |
2781 if (ReturnType != Ice::IceType_void) | 2663 if (ReturnType != Ice::IceType_void) |
2782 setNextLocalInstIndex(nullptr); | 2664 setNextLocalInstIndex(nullptr); |
2783 return; | 2665 return; |
2784 } | 2666 } |
2785 } else { // Record.GetCode() == naclbitc::FUNC_CODE_INST_CALL_INDIRECT | 2667 } else { // Record.GetCode() == naclbitc::FUNC_CODE_INST_CALL_INDIRECT |
2786 // There is no signature. Assume defined by parameter types. | 2668 // There is no signature. Assume defined by parameter types. |
2787 ReturnType = Context->getSimpleTypeByID(Values[2]); | 2669 ReturnType = Context->getSimpleTypeByID(Values[2]); |
2788 if (!isIRGenerationDisabled() && Callee != nullptr) | 2670 if (Callee != nullptr) |
2789 isValidPointerType(Callee, "Call indirect"); | 2671 isValidPointerType(Callee, "Call indirect"); |
2790 } | 2672 } |
2791 | 2673 |
2792 if (Callee == nullptr && !isIRGenerationDisabled()) | 2674 if (Callee == nullptr) |
2793 return; | 2675 return; |
2794 | 2676 |
2795 // Extract out the the call parameters. | 2677 // Extract out the the call parameters. |
2796 SmallVector<Ice::Operand *, 8> Params; | 2678 SmallVector<Ice::Operand *, 8> Params; |
2797 for (Ice::SizeT Index = ParamsStartIndex; Index < Values.size(); ++Index) { | 2679 for (Ice::SizeT Index = ParamsStartIndex; Index < Values.size(); ++Index) { |
2798 Ice::Operand *Op = getRelativeOperand(Values[Index], BaseIndex); | 2680 Ice::Operand *Op = getRelativeOperand(Values[Index], BaseIndex); |
2799 if (isIRGenerationDisabled()) | |
2800 continue; | |
2801 if (Op == nullptr) { | 2681 if (Op == nullptr) { |
2802 std::string Buffer; | 2682 std::string Buffer; |
2803 raw_string_ostream StrBuf(Buffer); | 2683 raw_string_ostream StrBuf(Buffer); |
2804 StrBuf << "Parameter " << (Index - ParamsStartIndex + 1) << " of " | 2684 StrBuf << "Parameter " << (Index - ParamsStartIndex + 1) << " of " |
2805 << printName(Fcn) << " is not defined"; | 2685 << printName(Fcn) << " is not defined"; |
2806 Error(StrBuf.str()); | 2686 Error(StrBuf.str()); |
2807 if (ReturnType != Ice::IceType_void) | 2687 if (ReturnType != Ice::IceType_void) |
2808 setNextLocalInstIndex(nullptr); | 2688 setNextLocalInstIndex(nullptr); |
2809 return; | 2689 return; |
2810 } | 2690 } |
2811 Params.push_back(Op); | 2691 Params.push_back(Op); |
2812 } | 2692 } |
2813 | 2693 |
2814 // Check return type. | 2694 // Check return type. |
2815 if (IntrinsicInfo == nullptr && !isCallReturnType(ReturnType)) { | 2695 if (IntrinsicInfo == nullptr && !isCallReturnType(ReturnType)) { |
2816 std::string Buffer; | 2696 std::string Buffer; |
2817 raw_string_ostream StrBuf(Buffer); | 2697 raw_string_ostream StrBuf(Buffer); |
2818 StrBuf << "Return type of " << printName(Fcn) | 2698 StrBuf << "Return type of " << printName(Fcn) |
2819 << " is invalid: " << ReturnType; | 2699 << " is invalid: " << ReturnType; |
2820 Error(StrBuf.str()); | 2700 Error(StrBuf.str()); |
2821 ReturnType = Ice::IceType_i32; | 2701 ReturnType = Ice::IceType_i32; |
2822 } | 2702 } |
2823 | 2703 |
2824 if (isIRGenerationDisabled()) { | |
2825 if (ReturnType != Ice::IceType_void) | |
2826 setNextLocalInstIndex(nullptr); | |
2827 return; | |
2828 } | |
2829 | 2704 |
2830 // Type check call parameters. | 2705 // Type check call parameters. |
2831 for (Ice::SizeT Index = 0; Index < Params.size(); ++Index) { | 2706 for (Ice::SizeT Index = 0; Index < Params.size(); ++Index) { |
2832 Ice::Operand *Op = Params[Index]; | 2707 Ice::Operand *Op = Params[Index]; |
2833 Ice::Type OpType = Op->getType(); | 2708 Ice::Type OpType = Op->getType(); |
2834 if (Signature) | 2709 if (Signature) |
2835 verifyCallArgTypeMatches(Fcn, Index, OpType, | 2710 verifyCallArgTypeMatches(Fcn, Index, OpType, |
2836 Signature->getArgType(Index)); | 2711 Signature->getArgType(Index)); |
2837 if (IntrinsicInfo) { | 2712 if (IntrinsicInfo) { |
2838 verifyCallArgTypeMatches(Fcn, Index, OpType, | 2713 verifyCallArgTypeMatches(Fcn, Index, OpType, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2876 for (Ice::Operand *Param : Params) | 2751 for (Ice::Operand *Param : Params) |
2877 Inst->addArg(Param); | 2752 Inst->addArg(Param); |
2878 CurrentNode->appendInst(Inst.release()); | 2753 CurrentNode->appendInst(Inst.release()); |
2879 return; | 2754 return; |
2880 } | 2755 } |
2881 case naclbitc::FUNC_CODE_INST_FORWARDTYPEREF: { | 2756 case naclbitc::FUNC_CODE_INST_FORWARDTYPEREF: { |
2882 // FORWARDTYPEREF: [opval, ty] | 2757 // FORWARDTYPEREF: [opval, ty] |
2883 if (!isValidRecordSize(2, "forward type ref")) | 2758 if (!isValidRecordSize(2, "forward type ref")) |
2884 return; | 2759 return; |
2885 Ice::Type OpType = Context->getSimpleTypeByID(Values[1]); | 2760 Ice::Type OpType = Context->getSimpleTypeByID(Values[1]); |
2886 setOperand(Values[0], | 2761 setOperand(Values[0], createInstVar(OpType)); |
2887 isIRGenerationDisabled() ? nullptr : createInstVar(OpType)); | |
2888 return; | 2762 return; |
2889 } | 2763 } |
2890 default: | 2764 default: |
2891 // Generate error message! | 2765 // Generate error message! |
2892 BlockParserBaseClass::ProcessRecord(); | 2766 BlockParserBaseClass::ProcessRecord(); |
2893 return; | 2767 return; |
2894 } | 2768 } |
2895 } | 2769 } |
2896 | 2770 |
2897 /// Parses constants within a function block. | 2771 /// Parses constants within a function block. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2942 if (NextConstantType == Ice::IceType_void) | 2816 if (NextConstantType == Ice::IceType_void) |
2943 Error("constants block set type not allowed for void type"); | 2817 Error("constants block set type not allowed for void type"); |
2944 return; | 2818 return; |
2945 } | 2819 } |
2946 case naclbitc::CST_CODE_UNDEF: { | 2820 case naclbitc::CST_CODE_UNDEF: { |
2947 // UNDEF | 2821 // UNDEF |
2948 if (!isValidRecordSize(0, "undef")) | 2822 if (!isValidRecordSize(0, "undef")) |
2949 return; | 2823 return; |
2950 if (!isValidNextConstantType()) | 2824 if (!isValidNextConstantType()) |
2951 return; | 2825 return; |
2952 if (isIRGenerationDisabled()) { | |
2953 FuncParser->setNextConstantID(nullptr); | |
2954 return; | |
2955 } | |
2956 FuncParser->setNextConstantID( | 2826 FuncParser->setNextConstantID( |
2957 getContext()->getConstantUndef(NextConstantType)); | 2827 getContext()->getConstantUndef(NextConstantType)); |
2958 return; | 2828 return; |
2959 } | 2829 } |
2960 case naclbitc::CST_CODE_INTEGER: { | 2830 case naclbitc::CST_CODE_INTEGER: { |
2961 // INTEGER: [intval] | 2831 // INTEGER: [intval] |
2962 if (!isValidRecordSize(1, "integer")) | 2832 if (!isValidRecordSize(1, "integer")) |
2963 return; | 2833 return; |
2964 if (!isValidNextConstantType()) | 2834 if (!isValidNextConstantType()) |
2965 return; | 2835 return; |
2966 if (isIRGenerationDisabled()) { | |
2967 FuncParser->setNextConstantID(nullptr); | |
2968 return; | |
2969 } | |
2970 if (Ice::isScalarIntegerType(NextConstantType)) { | 2836 if (Ice::isScalarIntegerType(NextConstantType)) { |
2971 BitcodeInt Value(Ice::getScalarIntBitWidth(NextConstantType), | 2837 BitcodeInt Value(Ice::getScalarIntBitWidth(NextConstantType), |
2972 NaClDecodeSignRotatedValue(Values[0])); | 2838 NaClDecodeSignRotatedValue(Values[0])); |
2973 if (Ice::Constant *C = getContext()->getConstantInt( | 2839 if (Ice::Constant *C = getContext()->getConstantInt( |
2974 NextConstantType, Value.getSExtValue())) { | 2840 NextConstantType, Value.getSExtValue())) { |
2975 FuncParser->setNextConstantID(C); | 2841 FuncParser->setNextConstantID(C); |
2976 return; | 2842 return; |
2977 } | 2843 } |
2978 } | 2844 } |
2979 std::string Buffer; | 2845 std::string Buffer; |
2980 raw_string_ostream StrBuf(Buffer); | 2846 raw_string_ostream StrBuf(Buffer); |
2981 StrBuf << "constant block integer record for non-integer type " | 2847 StrBuf << "constant block integer record for non-integer type " |
2982 << NextConstantType; | 2848 << NextConstantType; |
2983 Error(StrBuf.str()); | 2849 Error(StrBuf.str()); |
2984 return; | 2850 return; |
2985 } | 2851 } |
2986 case naclbitc::CST_CODE_FLOAT: { | 2852 case naclbitc::CST_CODE_FLOAT: { |
2987 // FLOAT: [fpval] | 2853 // FLOAT: [fpval] |
2988 if (!isValidRecordSize(1, "float")) | 2854 if (!isValidRecordSize(1, "float")) |
2989 return; | 2855 return; |
2990 if (!isValidNextConstantType()) | 2856 if (!isValidNextConstantType()) |
2991 return; | 2857 return; |
2992 if (isIRGenerationDisabled()) { | |
2993 FuncParser->setNextConstantID(nullptr); | |
2994 return; | |
2995 } | |
2996 switch (NextConstantType) { | 2858 switch (NextConstantType) { |
2997 case Ice::IceType_f32: { | 2859 case Ice::IceType_f32: { |
2998 const BitcodeInt Value(32, static_cast<uint32_t>(Values[0])); | 2860 const BitcodeInt Value(32, static_cast<uint32_t>(Values[0])); |
2999 float FpValue = Value.convertToFp<int32_t, float>(); | 2861 float FpValue = Value.convertToFp<int32_t, float>(); |
3000 FuncParser->setNextConstantID(getContext()->getConstantFloat(FpValue)); | 2862 FuncParser->setNextConstantID(getContext()->getConstantFloat(FpValue)); |
3001 return; | 2863 return; |
3002 } | 2864 } |
3003 case Ice::IceType_f64: { | 2865 case Ice::IceType_f64: { |
3004 const BitcodeInt Value(64, Values[0]); | 2866 const BitcodeInt Value(64, Values[0]); |
3005 double FpValue = Value.convertToFp<uint64_t, double>(); | 2867 double FpValue = Value.convertToFp<uint64_t, double>(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3060 }; | 2922 }; |
3061 | 2923 |
3062 void FunctionValuesymtabParser::setValueName(NaClBcIndexSize_t Index, | 2924 void FunctionValuesymtabParser::setValueName(NaClBcIndexSize_t Index, |
3063 StringType &Name) { | 2925 StringType &Name) { |
3064 // Note: We check when Index is too small, so that we can error recover | 2926 // Note: We check when Index is too small, so that we can error recover |
3065 // (FP->getOperand will create fatal error). | 2927 // (FP->getOperand will create fatal error). |
3066 if (Index < getFunctionParser()->getNumGlobalIDs()) { | 2928 if (Index < getFunctionParser()->getNumGlobalIDs()) { |
3067 reportUnableToAssign("Global value", Index, Name); | 2929 reportUnableToAssign("Global value", Index, Name); |
3068 return; | 2930 return; |
3069 } | 2931 } |
3070 if (isIRGenerationDisabled()) | |
3071 return; | |
3072 Ice::Operand *Op = getFunctionParser()->getOperand(Index); | 2932 Ice::Operand *Op = getFunctionParser()->getOperand(Index); |
3073 if (auto *V = dyn_cast<Ice::Variable>(Op)) { | 2933 if (auto *V = dyn_cast<Ice::Variable>(Op)) { |
3074 if (Ice::BuildDefs::dump()) { | 2934 if (Ice::BuildDefs::dump()) { |
3075 std::string Nm(Name.data(), Name.size()); | 2935 std::string Nm(Name.data(), Name.size()); |
3076 V->setName(getFunctionParser()->getFunc(), Nm); | 2936 V->setName(getFunctionParser()->getFunc(), Nm); |
3077 } | 2937 } |
3078 } else { | 2938 } else { |
3079 reportUnableToAssign("Local value", Index, Name); | 2939 reportUnableToAssign("Local value", Index, Name); |
3080 } | 2940 } |
3081 } | 2941 } |
3082 | 2942 |
3083 void FunctionValuesymtabParser::setBbName(NaClBcIndexSize_t Index, | 2943 void FunctionValuesymtabParser::setBbName(NaClBcIndexSize_t Index, |
3084 StringType &Name) { | 2944 StringType &Name) { |
3085 if (!Ice::BuildDefs::dump()) | 2945 if (!Ice::BuildDefs::dump()) |
3086 return; | 2946 return; |
3087 if (isIRGenerationDisabled()) | |
3088 return; | |
3089 if (Index >= getFunctionParser()->getFunc()->getNumNodes()) { | 2947 if (Index >= getFunctionParser()->getFunc()->getNumNodes()) { |
3090 reportUnableToAssign("Basic block", Index, Name); | 2948 reportUnableToAssign("Basic block", Index, Name); |
3091 return; | 2949 return; |
3092 } | 2950 } |
3093 std::string Nm(Name.data(), Name.size()); | 2951 std::string Nm(Name.data(), Name.size()); |
3094 if (Ice::BuildDefs::dump()) | 2952 if (Ice::BuildDefs::dump()) |
3095 getFunctionParser()->getFunc()->getNodes()[Index]->setName(Nm); | 2953 getFunctionParser()->getFunc()->getNodes()[Index]->setName(Nm); |
3096 } | 2954 } |
3097 | 2955 |
3098 bool FunctionParser::ParseBlock(unsigned BlockID) { | 2956 bool FunctionParser::ParseBlock(unsigned BlockID) { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3341 raw_string_ostream StrBuf(Buffer); | 3199 raw_string_ostream StrBuf(Buffer); |
3342 StrBuf << IRFilename << ": Does not contain a module!"; | 3200 StrBuf << IRFilename << ": Does not contain a module!"; |
3343 llvm::report_fatal_error(StrBuf.str()); | 3201 llvm::report_fatal_error(StrBuf.str()); |
3344 } | 3202 } |
3345 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { | 3203 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { |
3346 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); | 3204 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); |
3347 } | 3205 } |
3348 } | 3206 } |
3349 | 3207 |
3350 } // end of namespace Ice | 3208 } // end of namespace Ice |
OLD | NEW |