| 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 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1566 const auto *C = dyn_cast<Ice::ConstantInteger32>(Index); | 1566 const auto *C = dyn_cast<Ice::ConstantInteger32>(Index); |
| 1567 if (C == nullptr) | 1567 if (C == nullptr) |
| 1568 return VectorIndexNotConstant; | 1568 return VectorIndexNotConstant; |
| 1569 if (static_cast<size_t>(C->getValue()) >= typeNumElements(VecType)) | 1569 if (static_cast<size_t>(C->getValue()) >= typeNumElements(VecType)) |
| 1570 return VectorIndexNotInRange; | 1570 return VectorIndexNotInRange; |
| 1571 if (Index->getType() != Ice::IceType_i32) | 1571 if (Index->getType() != Ice::IceType_i32) |
| 1572 return VectorIndexNotI32; | 1572 return VectorIndexNotI32; |
| 1573 return VectorIndexValid; | 1573 return VectorIndexValid; |
| 1574 } | 1574 } |
| 1575 | 1575 |
| 1576 // Returns true if the Str begins with Prefix. | |
| 1577 bool isStringPrefix(const Ice::IceString &Str, const Ice::IceString &Prefix) { | |
| 1578 const size_t PrefixSize = Prefix.size(); | |
| 1579 if (Str.size() < PrefixSize) | |
| 1580 return false; | |
| 1581 for (size_t i = 0; i < PrefixSize; ++i) { | |
| 1582 if (Str[i] != Prefix[i]) | |
| 1583 return false; | |
| 1584 } | |
| 1585 return true; | |
| 1586 } | |
| 1587 | |
| 1588 // Takes the PNaCl bitcode binary operator Opcode, and the opcode | 1576 // Takes the PNaCl bitcode binary operator Opcode, and the opcode |
| 1589 // type Ty, and sets Op to the corresponding ICE binary | 1577 // type Ty, and sets Op to the corresponding ICE binary |
| 1590 // opcode. Returns true if able to convert, false otherwise. | 1578 // opcode. Returns true if able to convert, false otherwise. |
| 1591 bool convertBinopOpcode(unsigned Opcode, Ice::Type Ty, | 1579 bool convertBinopOpcode(unsigned Opcode, Ice::Type Ty, |
| 1592 Ice::InstArithmetic::OpKind &Op) { | 1580 Ice::InstArithmetic::OpKind &Op) { |
| 1593 switch (Opcode) { | 1581 switch (Opcode) { |
| 1594 default: { | 1582 default: { |
| 1595 std::string Buffer; | 1583 std::string Buffer; |
| 1596 raw_string_ostream StrBuf(Buffer); | 1584 raw_string_ostream StrBuf(Buffer); |
| 1597 StrBuf << "Binary opcode " << Opcode << "not understood for type " << Ty; | 1585 StrBuf << "Binary opcode " << Opcode << "not understood for type " << Ty; |
| (...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2504 uint32_t CalleeIndex = convertRelativeToAbsIndex(Values[1], BaseIndex); | 2492 uint32_t CalleeIndex = convertRelativeToAbsIndex(Values[1], BaseIndex); |
| 2505 Ice::Operand *Callee = getOperand(CalleeIndex); | 2493 Ice::Operand *Callee = getOperand(CalleeIndex); |
| 2506 Ice::Type ReturnType = Ice::IceType_void; | 2494 Ice::Type ReturnType = Ice::IceType_void; |
| 2507 const Ice::Intrinsics::FullIntrinsicInfo *IntrinsicInfo = nullptr; | 2495 const Ice::Intrinsics::FullIntrinsicInfo *IntrinsicInfo = nullptr; |
| 2508 if (Record.GetCode() == naclbitc::FUNC_CODE_INST_CALL) { | 2496 if (Record.GetCode() == naclbitc::FUNC_CODE_INST_CALL) { |
| 2509 Ice::FunctionDeclaration *Fcn = Context->getFunctionByID(CalleeIndex); | 2497 Ice::FunctionDeclaration *Fcn = Context->getFunctionByID(CalleeIndex); |
| 2510 const Ice::FuncSigType &Signature = Fcn->getSignature(); | 2498 const Ice::FuncSigType &Signature = Fcn->getSignature(); |
| 2511 ReturnType = Signature.getReturnType(); | 2499 ReturnType = Signature.getReturnType(); |
| 2512 | 2500 |
| 2513 // Check if this direct call is to an Intrinsic (starts with "llvm.") | 2501 // Check if this direct call is to an Intrinsic (starts with "llvm.") |
| 2514 static Ice::IceString LLVMPrefix("llvm."); | 2502 bool BadIntrinsic; |
| 2515 const Ice::IceString &Name = Fcn->getName(); | 2503 const Ice::IceString &Name = Fcn->getName(); |
| 2516 if (isStringPrefix(Name, LLVMPrefix)) { | 2504 IntrinsicInfo = getTranslator().getContext()->getIntrinsicsInfo().find( |
| 2517 Ice::IceString Suffix = Name.substr(LLVMPrefix.size()); | 2505 Name, BadIntrinsic); |
| 2518 IntrinsicInfo = | 2506 if (BadIntrinsic) { |
| 2519 getTranslator().getContext()->getIntrinsicsInfo().find(Suffix); | 2507 std::string Buffer; |
| 2520 if (!IntrinsicInfo) { | 2508 raw_string_ostream StrBuf(Buffer); |
| 2521 std::string Buffer; | 2509 StrBuf << "Invalid PNaCl intrinsic call to " << Name; |
| 2522 raw_string_ostream StrBuf(Buffer); | 2510 Error(StrBuf.str()); |
| 2523 StrBuf << "Invalid PNaCl intrinsic call to " << Name; | 2511 appendErrorInstruction(ReturnType); |
| 2524 Error(StrBuf.str()); | 2512 return; |
| 2525 appendErrorInstruction(ReturnType); | |
| 2526 return; | |
| 2527 } | |
| 2528 } | 2513 } |
| 2529 } else { | 2514 } else { |
| 2530 if (getFlags().getStubConstantCalls() && | 2515 if (getFlags().getStubConstantCalls() && |
| 2531 llvm::isa<Ice::ConstantInteger32>(Callee)) { | 2516 llvm::isa<Ice::ConstantInteger32>(Callee)) { |
| 2532 Callee = Context->getStubbedConstCallValue(Callee); | 2517 Callee = Context->getStubbedConstCallValue(Callee); |
| 2533 } | 2518 } |
| 2534 ReturnType = Context->getSimpleTypeByID(Values[2]); | 2519 ReturnType = Context->getSimpleTypeByID(Values[2]); |
| 2535 } | 2520 } |
| 2536 | 2521 |
| 2537 // Extract call information. | 2522 // Extract call information. |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3066 | 3051 |
| 3067 if (TopLevelBlocks != 1) { | 3052 if (TopLevelBlocks != 1) { |
| 3068 errs() << IRFilename | 3053 errs() << IRFilename |
| 3069 << ": Contains more than one module. Found: " << TopLevelBlocks | 3054 << ": Contains more than one module. Found: " << TopLevelBlocks |
| 3070 << "\n"; | 3055 << "\n"; |
| 3071 ErrorStatus.assign(EC_Bitcode); | 3056 ErrorStatus.assign(EC_Bitcode); |
| 3072 } | 3057 } |
| 3073 } | 3058 } |
| 3074 | 3059 |
| 3075 } // end of namespace Ice | 3060 } // end of namespace Ice |
| OLD | NEW |