Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: src/PNaClTranslator.cpp

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

Powered by Google App Engine
This is Rietveld 408576698