Chromium Code Reviews| 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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 | 331 |
| 332 /// Install names for all global values without names. Called after the global | 332 /// Install names for all global values without names. Called after the global |
| 333 /// value symbol table is processed, but before any function blocks are | 333 /// value symbol table is processed, but before any function blocks are |
| 334 /// processed. | 334 /// processed. |
| 335 void installGlobalNames() { | 335 void installGlobalNames() { |
| 336 assert(VariableDeclarations); | 336 assert(VariableDeclarations); |
| 337 installGlobalVarNames(); | 337 installGlobalVarNames(); |
| 338 installFunctionNames(); | 338 installFunctionNames(); |
| 339 } | 339 } |
| 340 | 340 |
| 341 void verifyFunctionTypeSignatures(); | |
| 342 | |
| 341 void createValueIDs() { | 343 void createValueIDs() { |
| 342 assert(VariableDeclarations); | 344 assert(VariableDeclarations); |
| 343 ValueIDConstants.reserve(VariableDeclarations->size() + | 345 ValueIDConstants.reserve(VariableDeclarations->size() + |
| 344 FunctionDeclarations.size()); | 346 FunctionDeclarations.size()); |
| 345 createValueIDsForFunctions(); | 347 createValueIDsForFunctions(); |
| 346 createValueIDsForGlobalVars(); | 348 createValueIDsForGlobalVars(); |
| 347 } | 349 } |
| 348 | 350 |
| 349 /// Returns the number of function declarations in the bitcode file. | 351 /// Returns the number of function declarations in the bitcode file. |
| 350 size_t getNumFunctionIDs() const { return FunctionDeclarations.size(); } | 352 size_t getNumFunctionIDs() const { return FunctionDeclarations.size(); } |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 } | 632 } |
| 631 | 633 |
| 632 Ice::Type TopLevelParser::convertToIceTypeError(Type *LLVMTy) { | 634 Ice::Type TopLevelParser::convertToIceTypeError(Type *LLVMTy) { |
| 633 std::string Buffer; | 635 std::string Buffer; |
| 634 raw_string_ostream StrBuf(Buffer); | 636 raw_string_ostream StrBuf(Buffer); |
| 635 StrBuf << "Invalid LLVM type: " << *LLVMTy; | 637 StrBuf << "Invalid LLVM type: " << *LLVMTy; |
| 636 Error(StrBuf.str()); | 638 Error(StrBuf.str()); |
| 637 return Ice::IceType_void; | 639 return Ice::IceType_void; |
| 638 } | 640 } |
| 639 | 641 |
| 642 void TopLevelParser::verifyFunctionTypeSignatures() { | |
| 643 const Ice::GlobalContext *Ctx = getTranslator().getContext(); | |
| 644 for (const auto FuncDecl : FunctionDeclarations) { | |
|
Jim Stichnoth
2016/01/14 22:59:08
I would use Ice::FunctionDeclaration* instead of a
Karl
2016/01/15 15:33:34
Done.
| |
| 645 if (!FuncDecl->validateTypeSignature(Ctx)) | |
| 646 Error(FuncDecl->getTypeSignatureError(Ctx)); | |
| 647 } | |
| 648 } | |
| 649 | |
| 640 // Base class for parsing blocks within the bitcode file. Note: Because this is | 650 // Base class for parsing blocks within the bitcode file. Note: Because this is |
| 641 // the base class of block parsers, we generate error messages if ParseBlock or | 651 // the base class of block parsers, we generate error messages if ParseBlock or |
| 642 // ParseRecord is not overridden in derived classes. | 652 // ParseRecord is not overridden in derived classes. |
| 643 class BlockParserBaseClass : public NaClBitcodeParser { | 653 class BlockParserBaseClass : public NaClBitcodeParser { |
| 644 BlockParserBaseClass() = delete; | 654 BlockParserBaseClass() = delete; |
| 645 BlockParserBaseClass(const BlockParserBaseClass &) = delete; | 655 BlockParserBaseClass(const BlockParserBaseClass &) = delete; |
| 646 BlockParserBaseClass &operator=(const BlockParserBaseClass &) = delete; | 656 BlockParserBaseClass &operator=(const BlockParserBaseClass &) = delete; |
| 647 | 657 |
| 648 public: | 658 public: |
| 649 // Constructor for the top-level module block parser. | 659 // Constructor for the top-level module block parser. |
| (...skipping 1991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2641 raw_string_ostream StrBuf(Buffer); | 2651 raw_string_ostream StrBuf(Buffer); |
| 2642 StrBuf << "Call to " << printName(Fcn) << " has " << NumParams | 2652 StrBuf << "Call to " << printName(Fcn) << " has " << NumParams |
| 2643 << " parameters. Signature expects: " << Signature->getNumArgs(); | 2653 << " parameters. Signature expects: " << Signature->getNumArgs(); |
| 2644 Error(StrBuf.str()); | 2654 Error(StrBuf.str()); |
| 2645 if (ReturnType != Ice::IceType_void) | 2655 if (ReturnType != Ice::IceType_void) |
| 2646 setNextLocalInstIndex(nullptr); | 2656 setNextLocalInstIndex(nullptr); |
| 2647 return; | 2657 return; |
| 2648 } | 2658 } |
| 2649 | 2659 |
| 2650 // Check if this direct call is to an Intrinsic (starts with "llvm.") | 2660 // Check if this direct call is to an Intrinsic (starts with "llvm.") |
| 2651 bool BadIntrinsic; | 2661 IntrinsicInfo = Fcn->getIntrinsicInfo(getTranslator().getContext()); |
| 2652 IntrinsicInfo = getTranslator().getContext()->getIntrinsicsInfo().find( | |
| 2653 Fcn->getName(), BadIntrinsic); | |
| 2654 if (BadIntrinsic) { | |
| 2655 std::string Buffer; | |
| 2656 raw_string_ostream StrBuf(Buffer); | |
| 2657 StrBuf << "Invalid PNaCl intrinsic call to " << Fcn->getName(); | |
| 2658 Error(StrBuf.str()); | |
| 2659 IntrinsicInfo = nullptr; | |
| 2660 } | |
| 2661 if (IntrinsicInfo && IntrinsicInfo->getNumArgs() != NumParams) { | 2662 if (IntrinsicInfo && IntrinsicInfo->getNumArgs() != NumParams) { |
| 2662 std::string Buffer; | 2663 std::string Buffer; |
| 2663 raw_string_ostream StrBuf(Buffer); | 2664 raw_string_ostream StrBuf(Buffer); |
| 2664 StrBuf << "Call to " << printName(Fcn) << " has " << NumParams | 2665 StrBuf << "Call to " << printName(Fcn) << " has " << NumParams |
| 2665 << " parameters. Intrinsic expects: " << Signature->getNumArgs(); | 2666 << " parameters. Intrinsic expects: " << Signature->getNumArgs(); |
| 2666 Error(StrBuf.str()); | 2667 Error(StrBuf.str()); |
| 2667 if (ReturnType != Ice::IceType_void) | 2668 if (ReturnType != Ice::IceType_void) |
| 2668 setNextLocalInstIndex(nullptr); | 2669 setNextLocalInstIndex(nullptr); |
| 2669 return; | 2670 return; |
| 2670 } | 2671 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2705 ReturnType = Ice::IceType_i32; | 2706 ReturnType = Ice::IceType_i32; |
| 2706 } | 2707 } |
| 2707 | 2708 |
| 2708 // Type check call parameters. | 2709 // Type check call parameters. |
| 2709 for (Ice::SizeT Index = 0; Index < Params.size(); ++Index) { | 2710 for (Ice::SizeT Index = 0; Index < Params.size(); ++Index) { |
| 2710 Ice::Operand *Op = Params[Index]; | 2711 Ice::Operand *Op = Params[Index]; |
| 2711 Ice::Type OpType = Op->getType(); | 2712 Ice::Type OpType = Op->getType(); |
| 2712 if (Signature) | 2713 if (Signature) |
| 2713 verifyCallArgTypeMatches(Fcn, Index, OpType, | 2714 verifyCallArgTypeMatches(Fcn, Index, OpType, |
| 2714 Signature->getArgType(Index)); | 2715 Signature->getArgType(Index)); |
| 2715 if (IntrinsicInfo) { | 2716 else if (!isCallParameterType(OpType)) { |
| 2716 verifyCallArgTypeMatches(Fcn, Index, OpType, | |
| 2717 IntrinsicInfo->getArgType(Index)); | |
| 2718 } else if (!isCallParameterType(OpType)) { | |
| 2719 std::string Buffer; | 2717 std::string Buffer; |
| 2720 raw_string_ostream StrBuf(Buffer); | 2718 raw_string_ostream StrBuf(Buffer); |
| 2721 StrBuf << "Argument " << *Op << " of " << printName(Fcn) | 2719 StrBuf << "Argument " << *Op << " of " << printName(Fcn) |
| 2722 << " has invalid type: " << Op->getType(); | 2720 << " has invalid type: " << Op->getType(); |
| 2723 Error(StrBuf.str()); | 2721 Error(StrBuf.str()); |
| 2724 appendErrorInstruction(ReturnType); | 2722 appendErrorInstruction(ReturnType); |
| 2723 return; | |
| 2725 } | 2724 } |
| 2726 } | 2725 } |
| 2727 | 2726 |
| 2728 // Extract call information. | 2727 // Extract call information. |
| 2729 uint64_t CCInfo = Values[0]; | 2728 uint64_t CCInfo = Values[0]; |
| 2730 CallingConv::ID CallingConv; | 2729 CallingConv::ID CallingConv; |
| 2731 if (!naclbitc::DecodeCallingConv(CCInfo >> 1, CallingConv)) { | 2730 if (!naclbitc::DecodeCallingConv(CCInfo >> 1, CallingConv)) { |
| 2732 std::string Buffer; | 2731 std::string Buffer; |
| 2733 raw_string_ostream StrBuf(Buffer); | 2732 raw_string_ostream StrBuf(Buffer); |
| 2734 StrBuf << "Function call calling convention value " << (CCInfo >> 1) | 2733 StrBuf << "Function call calling convention value " << (CCInfo >> 1) |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3000 bool FoundValuesymtab = false; | 2999 bool FoundValuesymtab = false; |
| 3001 | 3000 |
| 3002 // Generates names for unnamed global addresses (i.e. functions and global | 3001 // Generates names for unnamed global addresses (i.e. functions and global |
| 3003 // variables). Then lowers global variable declaration initializers to the | 3002 // variables). Then lowers global variable declaration initializers to the |
| 3004 // target. May be called multiple times. Only the first call will do the | 3003 // target. May be called multiple times. Only the first call will do the |
| 3005 // installation. | 3004 // installation. |
| 3006 void installGlobalNamesAndGlobalVarInitializers() { | 3005 void installGlobalNamesAndGlobalVarInitializers() { |
| 3007 if (!GlobalDeclarationNamesAndInitializersInstalled) { | 3006 if (!GlobalDeclarationNamesAndInitializersInstalled) { |
| 3008 Context->installGlobalNames(); | 3007 Context->installGlobalNames(); |
| 3009 Context->createValueIDs(); | 3008 Context->createValueIDs(); |
| 3009 Context->verifyFunctionTypeSignatures(); | |
| 3010 std::unique_ptr<Ice::VariableDeclarationList> Globals = | 3010 std::unique_ptr<Ice::VariableDeclarationList> Globals = |
| 3011 Context->getGlobalVariables(); | 3011 Context->getGlobalVariables(); |
| 3012 if (Globals) | 3012 if (Globals) |
| 3013 getTranslator().lowerGlobals(std::move(Globals)); | 3013 getTranslator().lowerGlobals(std::move(Globals)); |
| 3014 GlobalDeclarationNamesAndInitializersInstalled = true; | 3014 GlobalDeclarationNamesAndInitializersInstalled = true; |
| 3015 } | 3015 } |
| 3016 } | 3016 } |
| 3017 bool ParseBlock(unsigned BlockID) override; | 3017 bool ParseBlock(unsigned BlockID) override; |
| 3018 | 3018 |
| 3019 void ExitBlock() override { installGlobalNamesAndGlobalVarInitializers(); } | 3019 void ExitBlock() override { installGlobalNamesAndGlobalVarInitializers(); } |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3202 raw_string_ostream StrBuf(Buffer); | 3202 raw_string_ostream StrBuf(Buffer); |
| 3203 StrBuf << IRFilename << ": Does not contain a module!"; | 3203 StrBuf << IRFilename << ": Does not contain a module!"; |
| 3204 llvm::report_fatal_error(StrBuf.str()); | 3204 llvm::report_fatal_error(StrBuf.str()); |
| 3205 } | 3205 } |
| 3206 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { | 3206 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { |
| 3207 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); | 3207 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); |
| 3208 } | 3208 } |
| 3209 } | 3209 } |
| 3210 | 3210 |
| 3211 } // end of namespace Ice | 3211 } // end of namespace Ice |
| OLD | NEW |