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

Side by Side Diff: src/IceTargetLoweringMIPS32.cpp

Issue 2425673002: [Subzero][MIPS32] Account for variable alloca alignment bytes in addProlog (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Addressed review comments Created 4 years, 2 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 | « src/IceTargetLoweringMIPS32.h ('k') | tests_lit/llvm2ice_tests/alloc.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 // 1 //
2 // The Subzero Code Generator 2 // The Subzero Code Generator
3 // 3 //
4 // This file is distributed under the University of Illinois Open Source 4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details. 5 // License. See LICENSE.TXT for details.
6 // 6 //
7 //===----------------------------------------------------------------------===// 7 //===----------------------------------------------------------------------===//
8 /// 8 ///
9 /// \file 9 /// \file
10 /// \brief Implements the TargetLoweringMIPS32 class, which consists almost 10 /// \brief Implements the TargetLoweringMIPS32 class, which consists almost
(...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 GlobalsSize, LocalsSlotsAlignmentBytes, 1371 GlobalsSize, LocalsSlotsAlignmentBytes,
1372 &SpillAreaPaddingBytes, &LocalsSlotsPaddingBytes); 1372 &SpillAreaPaddingBytes, &LocalsSlotsPaddingBytes);
1373 SpillAreaSizeBytes += SpillAreaPaddingBytes + LocalsSlotsPaddingBytes; 1373 SpillAreaSizeBytes += SpillAreaPaddingBytes + LocalsSlotsPaddingBytes;
1374 uint32_t GlobalsAndSubsequentPaddingSize = 1374 uint32_t GlobalsAndSubsequentPaddingSize =
1375 GlobalsSize + LocalsSlotsPaddingBytes; 1375 GlobalsSize + LocalsSlotsPaddingBytes;
1376 1376
1377 // Adds the out args space to the stack, and align SP if necessary. 1377 // Adds the out args space to the stack, and align SP if necessary.
1378 if (!NeedsStackAlignment) { 1378 if (!NeedsStackAlignment) {
1379 SpillAreaSizeBytes += MaxOutArgsSizeBytes * (VariableAllocaUsed ? 0 : 1); 1379 SpillAreaSizeBytes += MaxOutArgsSizeBytes * (VariableAllocaUsed ? 0 : 1);
1380 } else { 1380 } else {
1381 uint32_t StackOffset = PreservedRegsSizeBytes; 1381 SpillAreaSizeBytes = applyStackAlignment(
1382 uint32_t StackSize = applyStackAlignment(StackOffset + SpillAreaSizeBytes); 1382 SpillAreaSizeBytes +
1383 if (!VariableAllocaUsed) 1383 (VariableAllocaUsed ? VariableAllocaAlignBytes : MaxOutArgsSizeBytes));
1384 StackSize = applyStackAlignment(StackSize + MaxOutArgsSizeBytes);
1385 SpillAreaSizeBytes = StackSize - StackOffset;
1386 } 1384 }
1387 1385
1388 // Combine fixed alloca with SpillAreaSize. 1386 // Combine fixed alloca with SpillAreaSize.
1389 SpillAreaSizeBytes += FixedAllocaSizeBytes; 1387 SpillAreaSizeBytes += FixedAllocaSizeBytes;
1390 1388
1391 TotalStackSizeBytes = PreservedRegsSizeBytes + SpillAreaSizeBytes; 1389 TotalStackSizeBytes = PreservedRegsSizeBytes + SpillAreaSizeBytes;
1392 1390
1393 // Generate "addiu sp, sp, -TotalStackSizeBytes" 1391 // Generate "addiu sp, sp, -TotalStackSizeBytes"
1394 if (TotalStackSizeBytes) { 1392 if (TotalStackSizeBytes) {
1395 // Use the scratch register if needed to legalize the immediate. 1393 // Use the scratch register if needed to legalize the immediate.
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
1783 if (!OperandMIPS32Mem::canHoldOffset(Mem->getType(), SignExt, Offset)) { 1781 if (!OperandMIPS32Mem::canHoldOffset(Mem->getType(), SignExt, Offset)) {
1784 Base = newBaseRegister(Base, Offset, Target->getReservedTmpReg()); 1782 Base = newBaseRegister(Base, Offset, Target->getReservedTmpReg());
1785 Offset = 0; 1783 Offset = 0;
1786 } 1784 }
1787 1785
1788 return OperandMIPS32Mem::create( 1786 return OperandMIPS32Mem::create(
1789 Target->Func, Mem->getType(), Base, 1787 Target->Func, Mem->getType(), Base,
1790 llvm::cast<ConstantInteger32>(Target->Ctx->getConstantInt32(Offset))); 1788 llvm::cast<ConstantInteger32>(Target->Ctx->getConstantInt32(Offset)));
1791 } 1789 }
1792 1790
1791 Variable *TargetMIPS32::PostLoweringLegalizer::legalizeImmediate(int32_t Imm) {
1792 Variable *Reg = nullptr;
1793 if (!((std::numeric_limits<int16_t>::min() <= Imm) &&
1794 (Imm <= std::numeric_limits<int16_t>::max()))) {
1795 const uint32_t UpperBits = (Imm >> 16) & 0xFFFF;
1796 const uint32_t LowerBits = Imm & 0xFFFF;
1797 Variable *TReg = Target->makeReg(IceType_i32, Target->getReservedTmpReg());
1798 Reg = Target->makeReg(IceType_i32, Target->getReservedTmpReg());
1799 if (LowerBits) {
1800 Target->_lui(TReg, Target->Ctx->getConstantInt32(UpperBits));
1801 Target->_ori(Reg, TReg, LowerBits);
1802 } else {
1803 Target->_lui(Reg, Target->Ctx->getConstantInt32(UpperBits));
1804 }
1805 }
1806 return Reg;
1807 }
1808
1793 void TargetMIPS32::postLowerLegalization() { 1809 void TargetMIPS32::postLowerLegalization() {
1794 Func->dump("Before postLowerLegalization"); 1810 Func->dump("Before postLowerLegalization");
1795 assert(hasComputedFrame()); 1811 assert(hasComputedFrame());
1796 for (CfgNode *Node : Func->getNodes()) { 1812 for (CfgNode *Node : Func->getNodes()) {
1797 Context.init(Node); 1813 Context.init(Node);
1798 PostLoweringLegalizer Legalizer(this); 1814 PostLoweringLegalizer Legalizer(this);
1799 while (!Context.atEnd()) { 1815 while (!Context.atEnd()) {
1800 PostIncrLoweringContext PostIncrement(Context); 1816 PostIncrLoweringContext PostIncrement(Context);
1801 Inst *CurInstr = iteratorToInst(Context.getCur()); 1817 Inst *CurInstr = iteratorToInst(Context.getCur());
1802 const SizeT NumSrcs = CurInstr->getSrcSize(); 1818 const SizeT NumSrcs = CurInstr->getSrcSize();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 } 1861 }
1846 continue; 1862 continue;
1847 } 1863 }
1848 if (llvm::isa<InstMIPS32Ldc1>(CurInstr)) { 1864 if (llvm::isa<InstMIPS32Ldc1>(CurInstr)) {
1849 if (auto *LegalMem = Legalizer.legalizeMemOperand(Src0M)) { 1865 if (auto *LegalMem = Legalizer.legalizeMemOperand(Src0M)) {
1850 _ldc1(Dst, LegalMem); 1866 _ldc1(Dst, LegalMem);
1851 CurInstr->setDeleted(); 1867 CurInstr->setDeleted();
1852 } 1868 }
1853 continue; 1869 continue;
1854 } 1870 }
1871 if (auto *AddiuInstr = llvm::dyn_cast<InstMIPS32Addiu>(CurInstr)) {
1872 if (auto *LegalImm = Legalizer.legalizeImmediate(
1873 static_cast<int32_t>(AddiuInstr->getImmediateValue()))) {
1874 _addu(Dst, Src0V, LegalImm);
1875 CurInstr->setDeleted();
1876 }
1877 continue;
1878 }
1855 } 1879 }
1856 } 1880 }
1857 } 1881 }
1858 1882
1859 Operand *TargetMIPS32::loOperand(Operand *Operand) { 1883 Operand *TargetMIPS32::loOperand(Operand *Operand) {
1860 assert(Operand->getType() == IceType_i64); 1884 assert(Operand->getType() == IceType_i64);
1861 if (auto *Var64On32 = llvm::dyn_cast<Variable64On32>(Operand)) 1885 if (auto *Var64On32 = llvm::dyn_cast<Variable64On32>(Operand))
1862 return Var64On32->getLo(); 1886 return Var64On32->getLo();
1863 if (auto *Const = llvm::dyn_cast<ConstantInteger64>(Operand)) { 1887 if (auto *Const = llvm::dyn_cast<ConstantInteger64>(Operand)) {
1864 return Ctx->getConstantInt32(static_cast<uint32_t>(Const->getValue())); 1888 return Ctx->getConstantInt32(static_cast<uint32_t>(Const->getValue()));
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
2036 auto *T = I32Reg(); 2060 auto *T = I32Reg();
2037 _addiu(T, SP, CurrentAllocaOffset); 2061 _addiu(T, SP, CurrentAllocaOffset);
2038 _mov(Dest, T); 2062 _mov(Dest, T);
2039 CurrentAllocaOffset += Value; 2063 CurrentAllocaOffset += Value;
2040 return; 2064 return;
2041 2065
2042 } else { 2066 } else {
2043 // Non-constant sizes need to be adjusted to the next highest multiple of 2067 // Non-constant sizes need to be adjusted to the next highest multiple of
2044 // the required alignment at runtime. 2068 // the required alignment at runtime.
2045 VariableAllocaUsed = true; 2069 VariableAllocaUsed = true;
2070 VariableAllocaAlignBytes = AlignmentParam;
2046 Variable *AlignAmount; 2071 Variable *AlignAmount;
2047 auto *TotalSizeR = legalizeToReg(TotalSize, Legal_Reg); 2072 auto *TotalSizeR = legalizeToReg(TotalSize, Legal_Reg);
2048 auto *T1 = I32Reg(); 2073 auto *T1 = I32Reg();
2049 auto *T2 = I32Reg(); 2074 auto *T2 = I32Reg();
2050 auto *T3 = I32Reg(); 2075 auto *T3 = I32Reg();
2051 auto *T4 = I32Reg(); 2076 auto *T4 = I32Reg();
2052 auto *T5 = I32Reg(); 2077 auto *T5 = I32Reg();
2053 _addiu(T1, TotalSizeR, MIPS32_STACK_ALIGNMENT_BYTES - 1); 2078 _addiu(T1, TotalSizeR, MIPS32_STACK_ALIGNMENT_BYTES - 1);
2054 _addiu(T2, getZero(), -MIPS32_STACK_ALIGNMENT_BYTES); 2079 _addiu(T2, getZero(), -MIPS32_STACK_ALIGNMENT_BYTES);
2055 _and(T3, T1, T2); 2080 _and(T3, T1, T2);
(...skipping 3058 matching lines...) Expand 10 before | Expand all | Expand 10 after
5114 Str << "\t.set\t" 5139 Str << "\t.set\t"
5115 << "nomips16\n"; 5140 << "nomips16\n";
5116 } 5141 }
5117 5142
5118 SmallBitVector TargetMIPS32::TypeToRegisterSet[RCMIPS32_NUM]; 5143 SmallBitVector TargetMIPS32::TypeToRegisterSet[RCMIPS32_NUM];
5119 SmallBitVector TargetMIPS32::TypeToRegisterSetUnfiltered[RCMIPS32_NUM]; 5144 SmallBitVector TargetMIPS32::TypeToRegisterSetUnfiltered[RCMIPS32_NUM];
5120 SmallBitVector TargetMIPS32::RegisterAliases[RegMIPS32::Reg_NUM]; 5145 SmallBitVector TargetMIPS32::RegisterAliases[RegMIPS32::Reg_NUM];
5121 5146
5122 } // end of namespace MIPS32 5147 } // end of namespace MIPS32
5123 } // end of namespace Ice 5148 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceTargetLoweringMIPS32.h ('k') | tests_lit/llvm2ice_tests/alloc.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698