Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: src/PNaClTranslator.cpp

Issue 545623005: Add alloca instruction to Subzero bitcode reader. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix nits. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests_lit/reader_tests/alloca.ll » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 // The corresponding LLVM function. 838 // The corresponding LLVM function.
839 Function *LLVMFunc; 839 Function *LLVMFunc;
840 // Holds operands local to the function block, based on indices 840 // Holds operands local to the function block, based on indices
841 // defined in the bitcode file. 841 // defined in the bitcode file.
842 std::vector<Ice::Operand *> LocalOperands; 842 std::vector<Ice::Operand *> LocalOperands;
843 // Holds the dividing point between local and global absolute value indices. 843 // Holds the dividing point between local and global absolute value indices.
844 uint32_t CachedNumGlobalValueIDs; 844 uint32_t CachedNumGlobalValueIDs;
845 // True if the last processed instruction was a terminating 845 // True if the last processed instruction was a terminating
846 // instruction. 846 // instruction.
847 bool InstIsTerminating; 847 bool InstIsTerminating;
848 // Upper limit of alignment power allowed by LLVM
849 static const uint64_t AlignPowerLimit = 29;
848 850
849 virtual bool ParseBlock(unsigned BlockID) LLVM_OVERRIDE; 851 virtual bool ParseBlock(unsigned BlockID) LLVM_OVERRIDE;
850 852
851 virtual void ProcessRecord() LLVM_OVERRIDE; 853 virtual void ProcessRecord() LLVM_OVERRIDE;
852 854
853 virtual void ExitBlock() LLVM_OVERRIDE; 855 virtual void ExitBlock() LLVM_OVERRIDE;
854 856
855 // Creates and appends a new basic block to the list of basic blocks. 857 // Creates and appends a new basic block to the list of basic blocks.
856 Ice::CfgNode *InstallNextBasicBlock() { return Func->makeNode(); } 858 Ice::CfgNode *InstallNextBasicBlock() { return Func->makeNode(); }
857 859
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 } 1510 }
1509 Ice::CfgNode *ThenBlock = getBranchBasicBlock(Values[0]); 1511 Ice::CfgNode *ThenBlock = getBranchBasicBlock(Values[0]);
1510 Ice::CfgNode *ElseBlock = getBranchBasicBlock(Values[1]); 1512 Ice::CfgNode *ElseBlock = getBranchBasicBlock(Values[1]);
1511 if (ThenBlock == NULL || ElseBlock == NULL) 1513 if (ThenBlock == NULL || ElseBlock == NULL)
1512 return; 1514 return;
1513 Inst = Ice::InstBr::create(Func, Cond, ThenBlock, ElseBlock); 1515 Inst = Ice::InstBr::create(Func, Cond, ThenBlock, ElseBlock);
1514 } 1516 }
1515 InstIsTerminating = true; 1517 InstIsTerminating = true;
1516 break; 1518 break;
1517 } 1519 }
1520 case naclbitc::FUNC_CODE_INST_ALLOCA: {
1521 // ALLOCA: [Size, align]
1522 if (!isValidRecordSize(2, "function block alloca"))
1523 return;
1524 Ice::Operand *ByteCount = getRelativeOperand(Values[0]);
1525 if (ByteCount->getType() != Ice::IceType_i32) {
1526 std::string Buffer;
1527 raw_string_ostream StrBuf(Buffer);
1528 StrBuf << "Alloca on non-i32 value. Found: " << ByteCount;
1529 Error(StrBuf.str());
1530 return;
1531 }
1532 uint64_t AlignPower = Values[1];
1533 unsigned Alignment = 1;
1534 if (AlignPower <= AlignPowerLimit) {
1535 Alignment = (1 << static_cast<unsigned>(AlignPower)) >> 1;
1536 } else {
1537 std::string Buffer;
1538 raw_string_ostream StrBuf(Buffer);
1539 StrBuf << "Alloca on alignment greater than 2**" << AlignPowerLimit
1540 << ". Found: 2**" << AlignPower;
1541 Error(StrBuf.str());
1542 // TODO(kschimpf) Remove error recovery once implementation complete.
1543 }
1544 Ice::Variable *Dest = NextInstVar(Context->getIcePointerType());
1545 Inst = Ice::InstAlloca::create(Func, ByteCount, Alignment, Dest);
1546 break;
1547 }
1518 default: 1548 default:
1519 // Generate error message! 1549 // Generate error message!
1520 BlockParserBaseClass::ProcessRecord(); 1550 BlockParserBaseClass::ProcessRecord();
1521 break; 1551 break;
1522 } 1552 }
1523 if (Inst) 1553 if (Inst)
1524 CurrentNode->appendInst(Inst); 1554 CurrentNode->appendInst(Inst);
1525 } 1555 }
1526 1556
1527 /// Parses constants within a function block. 1557 /// Parses constants within a function block.
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 if (TopLevelBlocks != 1) { 1836 if (TopLevelBlocks != 1) {
1807 errs() << IRFilename 1837 errs() << IRFilename
1808 << ": Contains more than one module. Found: " << TopLevelBlocks 1838 << ": Contains more than one module. Found: " << TopLevelBlocks
1809 << "\n"; 1839 << "\n";
1810 ErrorStatus = true; 1840 ErrorStatus = true;
1811 } 1841 }
1812 return; 1842 return;
1813 } 1843 }
1814 1844
1815 } // end of namespace Ice 1845 } // end of namespace Ice
OLDNEW
« no previous file with comments | « no previous file | tests_lit/reader_tests/alloca.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698