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 2142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2179 for (unsigned CaseIndex = 0; CaseIndex < NumCases; | 2180 for (unsigned CaseIndex = 0; CaseIndex < NumCases; |
2180 ++CaseIndex, ValCaseIndex += 4) { | 2181 ++CaseIndex, ValCaseIndex += 4) { |
2181 if (Values[ValCaseIndex] != 1 || Values[ValCaseIndex+1] != 1) { | 2182 if (Values[ValCaseIndex] != 1 || Values[ValCaseIndex+1] != 1) { |
2182 std::string Buffer; | 2183 std::string Buffer; |
2183 raw_string_ostream StrBuf(Buffer); | 2184 raw_string_ostream StrBuf(Buffer); |
2184 StrBuf << "Sequence [1, 1, value, label] expected for case entry " | 2185 StrBuf << "Sequence [1, 1, value, label] expected for case entry " |
2185 << "in switch record. (at index" << ValCaseIndex << ")"; | 2186 << "in switch record. (at index" << ValCaseIndex << ")"; |
2186 Error(StrBuf.str()); | 2187 Error(StrBuf.str()); |
2187 return; | 2188 return; |
2188 } | 2189 } |
2189 APInt Value(BitWidth, | 2190 Ice::APInt Value(BitWidth, |
2190 NaClDecodeSignRotatedValue(Values[ValCaseIndex + 2]), | 2191 NaClDecodeSignRotatedValue(Values[ValCaseIndex + 2])); |
2191 true); | |
2192 if (isIRGenDisabled) | 2192 if (isIRGenDisabled) |
2193 continue; | 2193 continue; |
2194 Ice::CfgNode *Label = getBranchBasicBlock(Values[ValCaseIndex + 3]); | 2194 Ice::CfgNode *Label = getBranchBasicBlock(Values[ValCaseIndex + 3]); |
2195 Switch->addBranch(CaseIndex, Value.getSExtValue(), Label); | 2195 Switch->addBranch(CaseIndex, Value.getSExtValue(), Label); |
2196 } | 2196 } |
2197 if (isIRGenDisabled) | 2197 if (isIRGenDisabled) |
2198 return; | 2198 return; |
2199 CurrentNode->appendInst(Switch); | 2199 CurrentNode->appendInst(Switch); |
2200 InstIsTerminating = true; | 2200 InstIsTerminating = true; |
2201 return; | 2201 return; |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2554 if (!isValidRecordSize(1, "integer")) | 2554 if (!isValidRecordSize(1, "integer")) |
2555 return; | 2555 return; |
2556 if (!isValidNextConstantType()) | 2556 if (!isValidNextConstantType()) |
2557 return; | 2557 return; |
2558 if (isIRGenerationDisabled()) { | 2558 if (isIRGenerationDisabled()) { |
2559 FuncParser->setNextConstantID(nullptr); | 2559 FuncParser->setNextConstantID(nullptr); |
2560 return; | 2560 return; |
2561 } | 2561 } |
2562 if (auto IType = dyn_cast<IntegerType>( | 2562 if (auto IType = dyn_cast<IntegerType>( |
2563 Context->convertToLLVMType(NextConstantType))) { | 2563 Context->convertToLLVMType(NextConstantType))) { |
2564 APInt Value(IType->getBitWidth(), NaClDecodeSignRotatedValue(Values[0])); | 2564 Ice::APInt Value(IType->getBitWidth(), |
| 2565 NaClDecodeSignRotatedValue(Values[0])); |
2565 if (Ice::Constant *C = getContext()->getConstantInt( | 2566 if (Ice::Constant *C = getContext()->getConstantInt( |
2566 NextConstantType, Value.getSExtValue())) { | 2567 NextConstantType, Value.getSExtValue())) { |
2567 FuncParser->setNextConstantID(C); | 2568 FuncParser->setNextConstantID(C); |
2568 return; | 2569 return; |
2569 } | 2570 } |
2570 } | 2571 } |
2571 std::string Buffer; | 2572 std::string Buffer; |
2572 raw_string_ostream StrBuf(Buffer); | 2573 raw_string_ostream StrBuf(Buffer); |
2573 StrBuf << "constant block integer record for non-integer type " | 2574 StrBuf << "constant block integer record for non-integer type " |
2574 << NextConstantType; | 2575 << NextConstantType; |
2575 Error(StrBuf.str()); | 2576 Error(StrBuf.str()); |
2576 return; | 2577 return; |
2577 } | 2578 } |
2578 case naclbitc::CST_CODE_FLOAT: { | 2579 case naclbitc::CST_CODE_FLOAT: { |
2579 // FLOAT: [fpval] | 2580 // FLOAT: [fpval] |
2580 if (!isValidRecordSize(1, "float")) | 2581 if (!isValidRecordSize(1, "float")) |
2581 return; | 2582 return; |
2582 if (!isValidNextConstantType()) | 2583 if (!isValidNextConstantType()) |
2583 return; | 2584 return; |
2584 if (isIRGenerationDisabled()) { | 2585 if (isIRGenerationDisabled()) { |
2585 FuncParser->setNextConstantID(nullptr); | 2586 FuncParser->setNextConstantID(nullptr); |
2586 return; | 2587 return; |
2587 } | 2588 } |
2588 switch (NextConstantType) { | 2589 switch (NextConstantType) { |
2589 case Ice::IceType_f32: { | 2590 case Ice::IceType_f32: { |
2590 APFloat Value(APFloat::IEEEsingle, | 2591 const Ice::APInt IntValue(32, static_cast<uint32_t>(Values[0])); |
2591 APInt(32, static_cast<uint32_t>(Values[0]))); | 2592 float FpValue = Ice::convertAPIntToFp<int32_t, float>(IntValue); |
2592 FuncParser->setNextConstantID( | 2593 FuncParser->setNextConstantID(getContext()->getConstantFloat(FpValue)); |
2593 getContext()->getConstantFloat(Value.convertToFloat())); | |
2594 return; | 2594 return; |
2595 } | 2595 } |
2596 case Ice::IceType_f64: { | 2596 case Ice::IceType_f64: { |
2597 APFloat Value(APFloat::IEEEdouble, APInt(64, Values[0])); | 2597 const Ice::APInt IntValue(64, Values[0]); |
2598 FuncParser->setNextConstantID( | 2598 double FpValue = Ice::convertAPIntToFp<uint64_t, double>(IntValue); |
2599 getContext()->getConstantDouble(Value.convertToDouble())); | 2599 FuncParser->setNextConstantID(getContext()->getConstantDouble(FpValue)); |
2600 return; | 2600 return; |
2601 } | 2601 } |
2602 default: { | 2602 default: { |
2603 std::string Buffer; | 2603 std::string Buffer; |
2604 raw_string_ostream StrBuf(Buffer); | 2604 raw_string_ostream StrBuf(Buffer); |
2605 StrBuf << "constant block float record for non-floating type " | 2605 StrBuf << "constant block float record for non-floating type " |
2606 << NextConstantType; | 2606 << NextConstantType; |
2607 Error(StrBuf.str()); | 2607 Error(StrBuf.str()); |
2608 return; | 2608 return; |
2609 } | 2609 } |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2939 | 2939 |
2940 if (TopLevelBlocks != 1) { | 2940 if (TopLevelBlocks != 1) { |
2941 errs() << IRFilename | 2941 errs() << IRFilename |
2942 << ": Contains more than one module. Found: " << TopLevelBlocks | 2942 << ": Contains more than one module. Found: " << TopLevelBlocks |
2943 << "\n"; | 2943 << "\n"; |
2944 ErrorStatus = true; | 2944 ErrorStatus = true; |
2945 } | 2945 } |
2946 } | 2946 } |
2947 | 2947 |
2948 } // end of namespace Ice | 2948 } // end of namespace Ice |
OLD | NEW |