From 91a5cc2bf981161ff18d0cada6b726978426f953 Mon Sep 17 00:00:00 2001 From: William Chen Date: Tue, 23 Feb 2021 11:14:52 -0800 Subject: [PATCH 1/2] Support ceil(), floor(), round() lib calls. --- .../include/cg/aarch64/aarch64_cgfunc.h | 1 + .../src/cg/aarch64/aarch64_cgfunc.cpp | 32 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h b/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h index 9740e68bf3..7b16939fd0 100644 --- a/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h +++ b/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h @@ -596,6 +596,7 @@ class AArch64CGFunc : public CGFunc { bool is64Bits, bool IsBitmaskImmediate, bool isBitNumLessThan16) const; Operand *SelectMinOrMax(bool isMin, const BinaryNode &node, Operand &opnd0, Operand &opnd1); void SelectMinOrMax(bool isMin, Operand &resOpnd, Operand &opnd0, Operand &opnd1, PrimType primType); + Operand *SelectRoundLibCall(RoundType roundType, const TypeCvtNode &node, Operand &opnd0); Operand *SelectRoundOperator(RoundType roundType, const TypeCvtNode &node, Operand &opnd0); int64 GetOrCreatSpillRegLocation(regno_t vrNum) { AArch64SymbolAlloc *symLoc = static_cast(GetMemlayout()->GetLocOfSpillRegister(vrNum)); diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp index 0da590fac9..13e5eb0d74 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -3534,9 +3534,39 @@ void AArch64CGFunc::SelectCvtInt2Float(Operand &resOpnd, Operand &origOpnd0, Pri GetCurBB()->AppendInsn(GetCG()->BuildInstruction(mOp, resOpnd, *srcOpnd)); } -Operand *AArch64CGFunc::SelectRoundOperator(RoundType roundType, const TypeCvtNode &node, Operand &opnd0) { +Operand *AArch64CGFunc::SelectRoundLibCall(RoundType roundType, const TypeCvtNode &node, Operand &opnd0) { PrimType ftype = node.FromType(); + PrimType rtype = node.GetPrimType(); + bool is64Bits = (ftype == PTY_f64); + std::vector opndVec; + RegOperand *resOpnd; + if (is64Bits) { + resOpnd = &GetOrCreatePhysicalRegisterOperand(D0, k64BitSize, kRegTyFloat); + } else { + resOpnd = &GetOrCreatePhysicalRegisterOperand(S0, k32BitSize, kRegTyFloat); + } + opndVec.push_back(resOpnd); + RegOperand ®Opnd0 = LoadIntoRegister(opnd0, ftype); + opndVec.push_back(®Opnd0); + std::string libName; + if (roundType == kCeil) { + libName.assign(is64Bits ? "ceil" : "ceilf"); + } else if (roundType == kFloor) { + libName.assign(is64Bits ? "floor" : "floorf"); + } else { + libName.assign(is64Bits ? "round" : "roundf"); + } + SelectLibCall(libName, opndVec, ftype, rtype); + + return resOpnd; +} + +Operand *AArch64CGFunc::SelectRoundOperator(RoundType roundType, const TypeCvtNode &node, Operand &opnd0) { PrimType itype = node.GetPrimType(); + if ((mirModule.GetSrcLang() == kSrcLangC) && ((itype == PTY_f64) || (itype == PTY_f32))) { + SelectRoundLibCall(roundType, node, opnd0); + } + PrimType ftype = node.FromType(); ASSERT(((ftype == PTY_f64) || (ftype == PTY_f32)), "wrong float type"); bool is64Bits = (ftype == PTY_f64); RegOperand &resOpnd = CreateRegisterOperandOfType(itype); -- Gitee From 0798c9f70b75b856f677eec62e92085baac6b5b6 Mon Sep 17 00:00:00 2001 From: William Chen Date: Tue, 23 Feb 2021 15:43:44 -0800 Subject: [PATCH 2/2] for O0, must rematerialize stack computation for all instances O0 register allocator relies on register liveness not crossing bb boundaries. --- src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp index 13e5eb0d74..1a8f23272c 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -6403,7 +6403,12 @@ MemOperand *AArch64CGFunc::GetOrCreatSpillMem(regno_t vrNum) { } MemOperand *AArch64CGFunc::GetPseudoRegisterSpillMemoryOperand(PregIdx i) { - auto p = pRegSpillMemOperands.find(i); + MapleUnorderedMap::iterator p; + if (GetCG()->GetOptimizeLevel() == CGOptions::kLevel0) { + p = pRegSpillMemOperands.end(); + } else { + p = pRegSpillMemOperands.find(i); + } if (p != pRegSpillMemOperands.end()) { return p->second; } -- Gitee