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