| OLD | NEW |
| 1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===// | 1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This file implements the PNaCl bitcode file to Ice, to machine code | 10 // This file implements the PNaCl bitcode file to Ice, to machine code |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 TopLevelParser(const TopLevelParser &) = delete; | 156 TopLevelParser(const TopLevelParser &) = delete; |
| 157 TopLevelParser &operator=(const TopLevelParser &) = delete; | 157 TopLevelParser &operator=(const TopLevelParser &) = delete; |
| 158 | 158 |
| 159 public: | 159 public: |
| 160 typedef std::vector<Ice::FunctionDeclaration *> FunctionDeclarationListType; | 160 typedef std::vector<Ice::FunctionDeclaration *> FunctionDeclarationListType; |
| 161 | 161 |
| 162 TopLevelParser(Ice::Translator &Translator, NaClBitcodeHeader &Header, | 162 TopLevelParser(Ice::Translator &Translator, NaClBitcodeHeader &Header, |
| 163 NaClBitstreamCursor &Cursor, Ice::ErrorCode &ErrorStatus) | 163 NaClBitstreamCursor &Cursor, Ice::ErrorCode &ErrorStatus) |
| 164 : NaClBitcodeParser(Cursor), Translator(Translator), Header(Header), | 164 : NaClBitcodeParser(Cursor), Translator(Translator), Header(Header), |
| 165 ErrorStatus(ErrorStatus), NumErrors(0), NextDefiningFunctionID(0), | 165 ErrorStatus(ErrorStatus), NumErrors(0), NextDefiningFunctionID(0), |
| 166 BlockParser(nullptr) {} | 166 BlockParser(nullptr), StubbedConstCallValue(nullptr) {} |
| 167 | 167 |
| 168 ~TopLevelParser() override {} | 168 ~TopLevelParser() override {} |
| 169 | 169 |
| 170 Ice::Translator &getTranslator() { return Translator; } | 170 Ice::Translator &getTranslator() { return Translator; } |
| 171 | 171 |
| 172 void setBlockParser(BlockParserBaseClass *NewBlockParser) { | 172 void setBlockParser(BlockParserBaseClass *NewBlockParser) { |
| 173 BlockParser = NewBlockParser; | 173 BlockParser = NewBlockParser; |
| 174 } | 174 } |
| 175 | 175 |
| 176 // Generates error with given Message. Always returns true. | 176 // Generates error with given Message. Always returns true. |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 C = getTranslator().getContext()->getConstantExternSym(Name); | 312 C = getTranslator().getContext()->getConstantExternSym(Name); |
| 313 else { | 313 else { |
| 314 const Ice::RelocOffsetT Offset = 0; | 314 const Ice::RelocOffsetT Offset = 0; |
| 315 C = getTranslator().getContext()->getConstantSym(Offset, Name, | 315 C = getTranslator().getContext()->getConstantSym(Offset, Name, |
| 316 SuppressMangling); | 316 SuppressMangling); |
| 317 } | 317 } |
| 318 ValueIDConstants[ID] = C; | 318 ValueIDConstants[ID] = C; |
| 319 return C; | 319 return C; |
| 320 } | 320 } |
| 321 | 321 |
| 322 /// Returns a defined function reference to be used in place of |
| 323 /// called constant addresses. Returns the corresponding operand |
| 324 /// to replace the calling address with. Reports an error if |
| 325 /// a stub could not be found, returning the CallValue. |
| 326 Ice::Operand *getStubbedConstCallValue(Ice::Operand *CallValue) { |
| 327 if (StubbedConstCallValue) |
| 328 return StubbedConstCallValue; |
| 329 for (unsigned i = 0; i < getNumFunctionIDs(); ++i) { |
| 330 Ice::FunctionDeclaration *Func = getFunctionByID(i); |
| 331 if (!Func->isProto()) { |
| 332 StubbedConstCallValue = getOrCreateGlobalConstantByID(i); |
| 333 return StubbedConstCallValue; |
| 334 } |
| 335 } |
| 336 Error("Unable to find function definition to stub constant calls with"); |
| 337 return CallValue; |
| 338 } |
| 339 |
| 322 /// Returns the number of function declarations in the bitcode file. | 340 /// Returns the number of function declarations in the bitcode file. |
| 323 unsigned getNumFunctionIDs() const { return FunctionDeclarationList.size(); } | 341 unsigned getNumFunctionIDs() const { return FunctionDeclarationList.size(); } |
| 324 | 342 |
| 325 /// Returns the number of global declarations (i.e. IDs) defined in | 343 /// Returns the number of global declarations (i.e. IDs) defined in |
| 326 /// the bitcode file. | 344 /// the bitcode file. |
| 327 unsigned getNumGlobalIDs() const { | 345 unsigned getNumGlobalIDs() const { |
| 328 return FunctionDeclarationList.size() + VariableDeclarations.size(); | 346 return FunctionDeclarationList.size() + VariableDeclarations.size(); |
| 329 } | 347 } |
| 330 | 348 |
| 331 /// Creates Count global variable declarations. | 349 /// Creates Count global variable declarations. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 size_t NextDefiningFunctionID; | 404 size_t NextDefiningFunctionID; |
| 387 // The set of global variables. | 405 // The set of global variables. |
| 388 Ice::VariableDeclarationList VariableDeclarations; | 406 Ice::VariableDeclarationList VariableDeclarations; |
| 389 // Relocatable constants associated with global declarations. | 407 // Relocatable constants associated with global declarations. |
| 390 std::vector<Ice::Constant *> ValueIDConstants; | 408 std::vector<Ice::Constant *> ValueIDConstants; |
| 391 // Error recovery value to use when getFuncSigTypeByID fails. | 409 // Error recovery value to use when getFuncSigTypeByID fails. |
| 392 Ice::FuncSigType UndefinedFuncSigType; | 410 Ice::FuncSigType UndefinedFuncSigType; |
| 393 // The block parser currently being applied. Used for error | 411 // The block parser currently being applied. Used for error |
| 394 // reporting. | 412 // reporting. |
| 395 BlockParserBaseClass *BlockParser; | 413 BlockParserBaseClass *BlockParser; |
| 414 // Value to use to stub constant calls. |
| 415 Ice::Operand *StubbedConstCallValue; |
| 396 | 416 |
| 397 bool ParseBlock(unsigned BlockID) override; | 417 bool ParseBlock(unsigned BlockID) override; |
| 398 | 418 |
| 399 // Gets extended type associated with the given index, assuming the | 419 // Gets extended type associated with the given index, assuming the |
| 400 // extended type is of the WantedKind. Generates error message if | 420 // extended type is of the WantedKind. Generates error message if |
| 401 // corresponding extended type of WantedKind can't be found, and | 421 // corresponding extended type of WantedKind can't be found, and |
| 402 // returns nullptr. | 422 // returns nullptr. |
| 403 ExtendedType *getTypeByIDAsKind(unsigned ID, | 423 ExtendedType *getTypeByIDAsKind(unsigned ID, |
| 404 ExtendedType::TypeKind WantedKind) { | 424 ExtendedType::TypeKind WantedKind) { |
| 405 ExtendedType *Ty = nullptr; | 425 ExtendedType *Ty = nullptr; |
| (...skipping 2028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2434 if (!IntrinsicInfo) { | 2454 if (!IntrinsicInfo) { |
| 2435 std::string Buffer; | 2455 std::string Buffer; |
| 2436 raw_string_ostream StrBuf(Buffer); | 2456 raw_string_ostream StrBuf(Buffer); |
| 2437 StrBuf << "Invalid PNaCl intrinsic call to " << Name; | 2457 StrBuf << "Invalid PNaCl intrinsic call to " << Name; |
| 2438 Error(StrBuf.str()); | 2458 Error(StrBuf.str()); |
| 2439 appendErrorInstruction(ReturnType); | 2459 appendErrorInstruction(ReturnType); |
| 2440 return; | 2460 return; |
| 2441 } | 2461 } |
| 2442 } | 2462 } |
| 2443 } else { | 2463 } else { |
| 2464 if (getFlags().StubConstantCalls && |
| 2465 llvm::isa<Ice::ConstantInteger32>(Callee)) { |
| 2466 Callee = Context->getStubbedConstCallValue(Callee); |
| 2467 } |
| 2444 ReturnType = Context->getSimpleTypeByID(Values[2]); | 2468 ReturnType = Context->getSimpleTypeByID(Values[2]); |
| 2445 } | 2469 } |
| 2446 | 2470 |
| 2447 // Extract call information. | 2471 // Extract call information. |
| 2448 uint64_t CCInfo = Values[0]; | 2472 uint64_t CCInfo = Values[0]; |
| 2449 CallingConv::ID CallingConv; | 2473 CallingConv::ID CallingConv; |
| 2450 if (!naclbitc::DecodeCallingConv(CCInfo >> 1, CallingConv)) { | 2474 if (!naclbitc::DecodeCallingConv(CCInfo >> 1, CallingConv)) { |
| 2451 std::string Buffer; | 2475 std::string Buffer; |
| 2452 raw_string_ostream StrBuf(Buffer); | 2476 raw_string_ostream StrBuf(Buffer); |
| 2453 StrBuf << "Function call calling convention value " << (CCInfo >> 1) | 2477 StrBuf << "Function call calling convention value " << (CCInfo >> 1) |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2997 | 3021 |
| 2998 if (TopLevelBlocks != 1) { | 3022 if (TopLevelBlocks != 1) { |
| 2999 errs() << IRFilename | 3023 errs() << IRFilename |
| 3000 << ": Contains more than one module. Found: " << TopLevelBlocks | 3024 << ": Contains more than one module. Found: " << TopLevelBlocks |
| 3001 << "\n"; | 3025 << "\n"; |
| 3002 ErrorStatus.assign(EC_Bitcode); | 3026 ErrorStatus.assign(EC_Bitcode); |
| 3003 } | 3027 } |
| 3004 } | 3028 } |
| 3005 | 3029 |
| 3006 } // end of namespace Ice | 3030 } // end of namespace Ice |
| OLD | NEW |