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 2626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2637 return; | 2637 return; |
2638 } else { | 2638 } else { |
2639 if (!isValidRecordSizeAtLeast(3, "call indirect")) | 2639 if (!isValidRecordSizeAtLeast(3, "call indirect")) |
2640 return; | 2640 return; |
2641 ParamsStartIndex = 3; | 2641 ParamsStartIndex = 3; |
2642 } | 2642 } |
2643 | 2643 |
2644 // Extract out the called function and its return type. | 2644 // Extract out the called function and its return type. |
2645 uint32_t CalleeIndex = convertRelativeToAbsIndex(Values[1], BaseIndex); | 2645 uint32_t CalleeIndex = convertRelativeToAbsIndex(Values[1], BaseIndex); |
2646 Ice::Operand *Callee = getOperand(CalleeIndex); | 2646 Ice::Operand *Callee = getOperand(CalleeIndex); |
2647 const Ice::FuncSigType *Signature = nullptr; | |
2647 Ice::Type ReturnType = Ice::IceType_void; | 2648 Ice::Type ReturnType = Ice::IceType_void; |
2648 const Ice::Intrinsics::FullIntrinsicInfo *IntrinsicInfo = nullptr; | 2649 const Ice::Intrinsics::FullIntrinsicInfo *IntrinsicInfo = nullptr; |
2649 if (Record.GetCode() == naclbitc::FUNC_CODE_INST_CALL) { | 2650 if (Record.GetCode() == naclbitc::FUNC_CODE_INST_CALL) { |
2650 Ice::FunctionDeclaration *Fcn = Context->getFunctionByID(CalleeIndex); | 2651 Ice::FunctionDeclaration *Fcn = Context->getFunctionByID(CalleeIndex); |
2651 const Ice::FuncSigType &Signature = Fcn->getSignature(); | 2652 Signature = &Fcn->getSignature(); |
2652 ReturnType = Signature.getReturnType(); | 2653 ReturnType = Signature->getReturnType(); |
2653 | 2654 |
2654 // Check if this direct call is to an Intrinsic (starts with "llvm.") | 2655 // Check if this direct call is to an Intrinsic (starts with "llvm.") |
2655 bool BadIntrinsic; | 2656 bool BadIntrinsic; |
2656 const Ice::IceString &Name = Fcn->getName(); | 2657 const Ice::IceString &Name = Fcn->getName(); |
2657 IntrinsicInfo = getTranslator().getContext()->getIntrinsicsInfo().find( | 2658 IntrinsicInfo = getTranslator().getContext()->getIntrinsicsInfo().find( |
2658 Name, BadIntrinsic); | 2659 Name, BadIntrinsic); |
2659 if (BadIntrinsic) { | 2660 if (BadIntrinsic) { |
2660 std::string Buffer; | 2661 std::string Buffer; |
2661 raw_string_ostream StrBuf(Buffer); | 2662 raw_string_ostream StrBuf(Buffer); |
2662 StrBuf << "Invalid PNaCl intrinsic call to " << Name; | 2663 StrBuf << "Invalid PNaCl intrinsic call to " << Name; |
2663 Error(StrBuf.str()); | 2664 Error(StrBuf.str()); |
2664 appendErrorInstruction(ReturnType); | 2665 if (ReturnType != Ice::IceType_void) |
2666 appendErrorInstruction(ReturnType); | |
2665 return; | 2667 return; |
2666 } | 2668 } |
2667 } else { | 2669 } else { |
2668 ReturnType = Context->getSimpleTypeByID(Values[2]); | 2670 ReturnType = Context->getSimpleTypeByID(Values[2]); |
2669 } | 2671 } |
2670 | 2672 |
2671 // Extract call information. | 2673 // Extract call information. |
2672 uint64_t CCInfo = Values[0]; | 2674 uint64_t CCInfo = Values[0]; |
2673 CallingConv::ID CallingConv; | 2675 CallingConv::ID CallingConv; |
2674 if (!naclbitc::DecodeCallingConv(CCInfo >> 1, CallingConv)) { | 2676 if (!naclbitc::DecodeCallingConv(CCInfo >> 1, CallingConv)) { |
2675 std::string Buffer; | 2677 std::string Buffer; |
2676 raw_string_ostream StrBuf(Buffer); | 2678 raw_string_ostream StrBuf(Buffer); |
2677 StrBuf << "Function call calling convention value " << (CCInfo >> 1) | 2679 StrBuf << "Function call calling convention value " << (CCInfo >> 1) |
2678 << " not understood."; | 2680 << " not understood."; |
2679 Error(StrBuf.str()); | 2681 Error(StrBuf.str()); |
2680 appendErrorInstruction(ReturnType); | 2682 if (ReturnType != Ice::IceType_void) |
2683 appendErrorInstruction(ReturnType); | |
2681 return; | 2684 return; |
2682 } | 2685 } |
2683 bool IsTailCall = static_cast<bool>(CCInfo & 1); | 2686 bool IsTailCall = static_cast<bool>(CCInfo & 1); |
2684 Ice::SizeT NumParams = Values.size() - ParamsStartIndex; | 2687 Ice::SizeT NumParams = Values.size() - ParamsStartIndex; |
2685 | 2688 if (Signature && NumParams != Signature->getNumArgs()) { |
2689 std::string Buffer; | |
2690 raw_string_ostream StrBuf(Buffer); | |
2691 StrBuf << "Call has " << NumParams | |
2692 << " parameters. Signature expects: " << Signature->getNumArgs(); | |
2693 Error(StrBuf.str()); | |
2694 // Error recover by only checking parameters in both signature and call. | |
2695 NumParams = std::min(NumParams, Signature->getNumArgs()); | |
2696 } | |
2686 if (isIRGenerationDisabled()) { | 2697 if (isIRGenerationDisabled()) { |
2687 assert(Callee == nullptr); | 2698 assert(Callee == nullptr); |
2688 // Check that parameters are defined. | 2699 // Check that parameters are defined. |
2689 for (Ice::SizeT ParamIndex = 0; ParamIndex < NumParams; ++ParamIndex) { | 2700 for (Ice::SizeT ParamIndex = 0; ParamIndex < NumParams; ++ParamIndex) { |
2690 assert(getRelativeOperand(Values[ParamsStartIndex + ParamIndex], | 2701 assert(getRelativeOperand(Values[ParamsStartIndex + ParamIndex], |
2691 BaseIndex) == nullptr); | 2702 BaseIndex) == nullptr); |
2692 } | 2703 } |
2693 // Define value slot only if value returned. | 2704 // Define value slot only if value returned. |
2694 if (ReturnType != Ice::IceType_void) | 2705 if (ReturnType != Ice::IceType_void) |
2695 setNextLocalInstIndex(nullptr); | 2706 setNextLocalInstIndex(nullptr); |
2696 return; | 2707 return; |
2697 } | 2708 } |
2698 | 2709 |
2699 // Create the call instruction. | 2710 // Create the call instruction. |
2700 Ice::Variable *Dest = (ReturnType == Ice::IceType_void) | 2711 Ice::Variable *Dest = (ReturnType == Ice::IceType_void) |
Jim Stichnoth
2015/09/17 19:56:46
Before creating Dest, you should also check for
Karl
2015/09/18 17:22:49
Done.
| |
2701 ? nullptr | 2712 ? nullptr |
2702 : getNextInstVar(ReturnType); | 2713 : getNextInstVar(ReturnType); |
2703 Ice::InstCall *Inst = nullptr; | 2714 std::unique_ptr<Ice::InstCall> Inst; |
2704 if (IntrinsicInfo) { | 2715 if (IntrinsicInfo) { |
2705 Inst = Ice::InstIntrinsicCall::create(Func.get(), NumParams, Dest, Callee, | 2716 Inst.reset(Ice::InstIntrinsicCall::create(Func.get(), NumParams, Dest, |
2706 IntrinsicInfo->Info); | 2717 Callee, IntrinsicInfo->Info)); |
2707 } else { | 2718 } else { |
2708 Inst = Ice::InstCall::create(Func.get(), NumParams, Dest, Callee, | 2719 Inst.reset(Ice::InstCall::create(Func.get(), NumParams, Dest, Callee, |
2709 IsTailCall); | 2720 IsTailCall)); |
2710 } | 2721 } |
2711 | 2722 |
2712 // Add parameters. | 2723 // Add parameters. |
2713 for (Ice::SizeT ParamIndex = 0; ParamIndex < NumParams; ++ParamIndex) { | 2724 for (Ice::SizeT ParamIndex = 0; ParamIndex < NumParams; ++ParamIndex) { |
2714 Inst->addArg( | 2725 Ice::Operand *Op = |
2715 getRelativeOperand(Values[ParamsStartIndex + ParamIndex], BaseIndex)); | 2726 getRelativeOperand(Values[ParamsStartIndex + ParamIndex], BaseIndex); |
2727 if (Op == nullptr) { | |
2728 std::string Buffer; | |
2729 raw_string_ostream StrBuf(Buffer); | |
2730 StrBuf << "Parameter " << ParamIndex << " of call not defined"; | |
2731 Error(StrBuf.str()); | |
2732 if (ReturnType != Ice::IceType_void) | |
2733 appendErrorInstruction(ReturnType); | |
2734 return; | |
2735 } | |
2736 | |
2737 // Check that parameter type is valid. | |
2738 if (Signature) { | |
2739 if (Op->getType() != Signature->getArgType(ParamIndex)) { | |
2740 std::string Buffer; | |
2741 raw_string_ostream StrBuf(Buffer); | |
2742 StrBuf << "Call argument " << *Op << " expects " | |
2743 << Signature->getArgType(ParamIndex) | |
2744 << ". Found: " << Op->getType(); | |
2745 Error(StrBuf.str()); | |
2746 } else if (IntrinsicInfo == nullptr && | |
2747 !isCallParameterType(Op->getType())) { | |
2748 // TODO(kschimpf): Move this check to the function declaration, so | |
2749 // that it only needs to be checked once. | |
2750 std::string Buffer; | |
2751 raw_string_ostream StrBuf(Buffer); | |
2752 StrBuf << "Call argument " << *Op | |
2753 << " matches declaration but has invalid type: " | |
2754 << Op->getType(); | |
2755 Error(StrBuf.str()); | |
2756 } | |
2757 } else if (!isCallParameterType(Op->getType())) { | |
2758 std::string Buffer; | |
2759 raw_string_ostream StrBuf(Buffer); | |
2760 StrBuf << "Call argument " << *Op | |
2761 << " has invalid type: " << Op->getType(); | |
2762 Error(StrBuf.str()); | |
2763 } | |
2764 Inst->addArg(Op); | |
2716 } | 2765 } |
2717 | 2766 |
2718 // If intrinsic call, validate call signature. | 2767 // If intrinsic call, validate call signature. |
2719 if (IntrinsicInfo) { | 2768 if (IntrinsicInfo) { |
2720 Ice::SizeT ArgIndex = 0; | 2769 Ice::SizeT ArgIndex = 0; |
2721 switch (IntrinsicInfo->validateCall(Inst, ArgIndex)) { | 2770 switch (IntrinsicInfo->validateCall(Inst.get(), ArgIndex)) { |
2722 case Ice::Intrinsics::IsValidCall: | 2771 case Ice::Intrinsics::IsValidCall: |
2723 break; | 2772 break; |
2724 case Ice::Intrinsics::BadReturnType: { | 2773 case Ice::Intrinsics::BadReturnType: { |
2725 std::string Buffer; | 2774 std::string Buffer; |
2726 raw_string_ostream StrBuf(Buffer); | 2775 raw_string_ostream StrBuf(Buffer); |
2727 StrBuf << "Intrinsic call expects return type " | 2776 StrBuf << "Intrinsic call expects return type " |
2728 << IntrinsicInfo->getReturnType() | 2777 << IntrinsicInfo->getReturnType() |
2729 << ". Found: " << Inst->getReturnType(); | 2778 << ". Found: " << Inst->getReturnType(); |
2730 Error(StrBuf.str()); | 2779 Error(StrBuf.str()); |
2731 break; | 2780 break; |
(...skipping 11 matching lines...) Expand all Loading... | |
2743 raw_string_ostream StrBuf(Buffer); | 2792 raw_string_ostream StrBuf(Buffer); |
2744 StrBuf << "Intrinsic call argument " << ArgIndex << " expects type " | 2793 StrBuf << "Intrinsic call argument " << ArgIndex << " expects type " |
2745 << IntrinsicInfo->getArgType(ArgIndex) | 2794 << IntrinsicInfo->getArgType(ArgIndex) |
2746 << ". Found: " << Inst->getArg(ArgIndex)->getType(); | 2795 << ". Found: " << Inst->getArg(ArgIndex)->getType(); |
2747 Error(StrBuf.str()); | 2796 Error(StrBuf.str()); |
2748 break; | 2797 break; |
2749 } | 2798 } |
2750 } | 2799 } |
2751 } | 2800 } |
2752 | 2801 |
2753 CurrentNode->appendInst(Inst); | 2802 CurrentNode->appendInst(Inst.release()); |
2754 return; | 2803 return; |
2755 } | 2804 } |
2756 case naclbitc::FUNC_CODE_INST_FORWARDTYPEREF: { | 2805 case naclbitc::FUNC_CODE_INST_FORWARDTYPEREF: { |
2757 // FORWARDTYPEREF: [opval, ty] | 2806 // FORWARDTYPEREF: [opval, ty] |
2758 if (!isValidRecordSize(2, "forward type ref")) | 2807 if (!isValidRecordSize(2, "forward type ref")) |
2759 return; | 2808 return; |
2760 Ice::Type OpType = Context->getSimpleTypeByID(Values[1]); | 2809 Ice::Type OpType = Context->getSimpleTypeByID(Values[1]); |
2761 setOperand(Values[0], | 2810 setOperand(Values[0], |
2762 isIRGenerationDisabled() ? nullptr : createInstVar(OpType)); | 2811 isIRGenerationDisabled() ? nullptr : createInstVar(OpType)); |
2763 return; | 2812 return; |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3203 } | 3252 } |
3204 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { | 3253 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { |
3205 ErrStream | 3254 ErrStream |
3206 << IRFilename | 3255 << IRFilename |
3207 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; | 3256 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; |
3208 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); | 3257 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); |
3209 } | 3258 } |
3210 } | 3259 } |
3211 | 3260 |
3212 } // end of namespace Ice | 3261 } // end of namespace Ice |
OLD | NEW |