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 |
11 // translator. | 11 // translator. |
12 // | 12 // |
13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
14 | 14 |
15 #include "llvm/ADT/SmallString.h" | 15 #include "llvm/ADT/SmallString.h" |
16 #include "llvm/Bitcode/NaCl/NaClBitcodeDecoders.h" | 16 #include "llvm/Bitcode/NaCl/NaClBitcodeDecoders.h" |
17 #include "llvm/Bitcode/NaCl/NaClBitcodeHeader.h" | 17 #include "llvm/Bitcode/NaCl/NaClBitcodeHeader.h" |
18 #include "llvm/Bitcode/NaCl/NaClBitcodeParser.h" | 18 #include "llvm/Bitcode/NaCl/NaClBitcodeParser.h" |
19 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" | 19 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" |
20 #include "llvm/IR/Constants.h" | |
21 #include "llvm/IR/LLVMContext.h" | 20 #include "llvm/IR/LLVMContext.h" |
22 #include "llvm/IR/Module.h" | 21 #include "llvm/IR/Module.h" |
23 #include "llvm/Support/Format.h" | 22 #include "llvm/Support/Format.h" |
24 #include "llvm/Support/MemoryBuffer.h" | 23 #include "llvm/Support/MemoryBuffer.h" |
25 #include "llvm/Support/raw_ostream.h" | 24 #include "llvm/Support/raw_ostream.h" |
26 | 25 |
| 26 #include "IceAPInt.h" |
| 27 #include "IceAPFloat.h" |
27 #include "IceCfg.h" | 28 #include "IceCfg.h" |
28 #include "IceCfgNode.h" | 29 #include "IceCfgNode.h" |
29 #include "IceClFlags.h" | 30 #include "IceClFlags.h" |
30 #include "IceDefs.h" | 31 #include "IceDefs.h" |
31 #include "IceGlobalInits.h" | 32 #include "IceGlobalInits.h" |
32 #include "IceInst.h" | 33 #include "IceInst.h" |
33 #include "IceOperand.h" | 34 #include "IceOperand.h" |
34 #include "IceTypeConverter.h" | 35 #include "IceTypeConverter.h" |
35 #include "PNaClTranslator.h" | 36 #include "PNaClTranslator.h" |
36 | 37 |
(...skipping 2144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2181 for (unsigned CaseIndex = 0; CaseIndex < NumCases; | 2182 for (unsigned CaseIndex = 0; CaseIndex < NumCases; |
2182 ++CaseIndex, ValCaseIndex += 4) { | 2183 ++CaseIndex, ValCaseIndex += 4) { |
2183 if (Values[ValCaseIndex] != 1 || Values[ValCaseIndex+1] != 1) { | 2184 if (Values[ValCaseIndex] != 1 || Values[ValCaseIndex+1] != 1) { |
2184 std::string Buffer; | 2185 std::string Buffer; |
2185 raw_string_ostream StrBuf(Buffer); | 2186 raw_string_ostream StrBuf(Buffer); |
2186 StrBuf << "Sequence [1, 1, value, label] expected for case entry " | 2187 StrBuf << "Sequence [1, 1, value, label] expected for case entry " |
2187 << "in switch record. (at index" << ValCaseIndex << ")"; | 2188 << "in switch record. (at index" << ValCaseIndex << ")"; |
2188 Error(StrBuf.str()); | 2189 Error(StrBuf.str()); |
2189 return; | 2190 return; |
2190 } | 2191 } |
2191 APInt Value(BitWidth, | 2192 Ice::APInt Value(BitWidth, |
2192 NaClDecodeSignRotatedValue(Values[ValCaseIndex + 2]), | 2193 NaClDecodeSignRotatedValue(Values[ValCaseIndex + 2])); |
2193 true); | |
2194 if (isIRGenDisabled) | 2194 if (isIRGenDisabled) |
2195 continue; | 2195 continue; |
2196 Ice::CfgNode *Label = getBranchBasicBlock(Values[ValCaseIndex + 3]); | 2196 Ice::CfgNode *Label = getBranchBasicBlock(Values[ValCaseIndex + 3]); |
2197 Switch->addBranch(CaseIndex, Value.getSExtValue(), Label); | 2197 Switch->addBranch(CaseIndex, Value.getSExtValue(), Label); |
2198 } | 2198 } |
2199 if (isIRGenDisabled) | 2199 if (isIRGenDisabled) |
2200 return; | 2200 return; |
2201 CurrentNode->appendInst(Switch); | 2201 CurrentNode->appendInst(Switch); |
2202 InstIsTerminating = true; | 2202 InstIsTerminating = true; |
2203 return; | 2203 return; |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2556 if (!isValidRecordSize(1, "integer")) | 2556 if (!isValidRecordSize(1, "integer")) |
2557 return; | 2557 return; |
2558 if (!isValidNextConstantType()) | 2558 if (!isValidNextConstantType()) |
2559 return; | 2559 return; |
2560 if (isIRGenerationDisabled()) { | 2560 if (isIRGenerationDisabled()) { |
2561 FuncParser->setNextConstantID(nullptr); | 2561 FuncParser->setNextConstantID(nullptr); |
2562 return; | 2562 return; |
2563 } | 2563 } |
2564 if (auto IType = dyn_cast<IntegerType>( | 2564 if (auto IType = dyn_cast<IntegerType>( |
2565 Context->convertToLLVMType(NextConstantType))) { | 2565 Context->convertToLLVMType(NextConstantType))) { |
2566 APInt Value(IType->getBitWidth(), NaClDecodeSignRotatedValue(Values[0])); | 2566 Ice::APInt Value(IType->getBitWidth(), |
| 2567 NaClDecodeSignRotatedValue(Values[0])); |
2567 if (Ice::Constant *C = getContext()->getConstantInt( | 2568 if (Ice::Constant *C = getContext()->getConstantInt( |
2568 NextConstantType, Value.getSExtValue())) { | 2569 NextConstantType, Value.getSExtValue())) { |
2569 FuncParser->setNextConstantID(C); | 2570 FuncParser->setNextConstantID(C); |
2570 return; | 2571 return; |
2571 } | 2572 } |
2572 } | 2573 } |
2573 std::string Buffer; | 2574 std::string Buffer; |
2574 raw_string_ostream StrBuf(Buffer); | 2575 raw_string_ostream StrBuf(Buffer); |
2575 StrBuf << "constant block integer record for non-integer type " | 2576 StrBuf << "constant block integer record for non-integer type " |
2576 << NextConstantType; | 2577 << NextConstantType; |
2577 Error(StrBuf.str()); | 2578 Error(StrBuf.str()); |
2578 return; | 2579 return; |
2579 } | 2580 } |
2580 case naclbitc::CST_CODE_FLOAT: { | 2581 case naclbitc::CST_CODE_FLOAT: { |
2581 // FLOAT: [fpval] | 2582 // FLOAT: [fpval] |
2582 if (!isValidRecordSize(1, "float")) | 2583 if (!isValidRecordSize(1, "float")) |
2583 return; | 2584 return; |
2584 if (!isValidNextConstantType()) | 2585 if (!isValidNextConstantType()) |
2585 return; | 2586 return; |
2586 if (isIRGenerationDisabled()) { | 2587 if (isIRGenerationDisabled()) { |
2587 FuncParser->setNextConstantID(nullptr); | 2588 FuncParser->setNextConstantID(nullptr); |
2588 return; | 2589 return; |
2589 } | 2590 } |
2590 switch (NextConstantType) { | 2591 switch (NextConstantType) { |
2591 case Ice::IceType_f32: { | 2592 case Ice::IceType_f32: { |
2592 APFloat Value(APFloat::IEEEsingle, | 2593 const Ice::APInt IntValue(32, static_cast<uint32_t>(Values[0])); |
2593 APInt(32, static_cast<uint32_t>(Values[0]))); | 2594 float FpValue = Ice::convertAPIntToFp<int32_t, float>(IntValue); |
2594 FuncParser->setNextConstantID( | 2595 FuncParser->setNextConstantID(getContext()->getConstantFloat(FpValue)); |
2595 getContext()->getConstantFloat(Value.convertToFloat())); | |
2596 return; | 2596 return; |
2597 } | 2597 } |
2598 case Ice::IceType_f64: { | 2598 case Ice::IceType_f64: { |
2599 APFloat Value(APFloat::IEEEdouble, APInt(64, Values[0])); | 2599 const Ice::APInt IntValue(64, Values[0]); |
2600 FuncParser->setNextConstantID( | 2600 double FpValue = Ice::convertAPIntToFp<uint64_t, double>(IntValue); |
2601 getContext()->getConstantDouble(Value.convertToDouble())); | 2601 FuncParser->setNextConstantID(getContext()->getConstantDouble(FpValue)); |
2602 return; | 2602 return; |
2603 } | 2603 } |
2604 default: { | 2604 default: { |
2605 std::string Buffer; | 2605 std::string Buffer; |
2606 raw_string_ostream StrBuf(Buffer); | 2606 raw_string_ostream StrBuf(Buffer); |
2607 StrBuf << "constant block float record for non-floating type " | 2607 StrBuf << "constant block float record for non-floating type " |
2608 << NextConstantType; | 2608 << NextConstantType; |
2609 Error(StrBuf.str()); | 2609 Error(StrBuf.str()); |
2610 return; | 2610 return; |
2611 } | 2611 } |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2938 | 2938 |
2939 if (TopLevelBlocks != 1) { | 2939 if (TopLevelBlocks != 1) { |
2940 errs() << IRFilename | 2940 errs() << IRFilename |
2941 << ": Contains more than one module. Found: " << TopLevelBlocks | 2941 << ": Contains more than one module. Found: " << TopLevelBlocks |
2942 << "\n"; | 2942 << "\n"; |
2943 ErrorStatus = true; | 2943 ErrorStatus = true; |
2944 } | 2944 } |
2945 } | 2945 } |
2946 | 2946 |
2947 } // end of namespace Ice | 2947 } // end of namespace Ice |
OLD | NEW |