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 754c00e723c43cce7bd7556fefb0e742d028d731..77dfc05ac86e403bd3d4ea8b14822e9a7197bc75 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -2405,9 +2405,9 @@ void AArch64CGFunc::SelectAddrof(Operand &result, StImmOperand &stImm, FieldID f Operand *srcOpnd = &result; if (!IsAfterRegAlloc()) { // Create a new vreg/preg for the upper bits of the address - PregIdx pregIdx = GetFunction().GetPregTab()->CreatePreg(LOWERED_PTR_TYPE); + PregIdx pregIdx = GetFunction().GetPregTab()->CreatePreg(PTY_a64); MIRPreg *tmpPreg = GetFunction().GetPregTab()->PregFromPregIdx(pregIdx); - regno_t vRegNO = NewVReg(kRegTyInt, GetPrimTypeSize(LOWERED_PTR_TYPE)); + regno_t vRegNO = NewVReg(kRegTyInt, GetPrimTypeSize(PTY_a64)); RegOperand &tmpreg = GetOrCreateVirtualRegisterOperand(vRegNO); // Register this vreg mapping @@ -3372,8 +3372,7 @@ Operand &AArch64CGFunc::SelectCGArrayElemAdd(BinaryNode &node, const BaseNode &p MIRSymbol &symbol = *mirModule.CurFunction()->GetLocalOrGlobalSymbol(addrofNode->GetStIdx()); ASSERT(addrofNode->GetFieldID() == 0, "For debug SelectCGArrayElemAdd."); - PrimType primType = addrofNode->GetPrimType(); - Operand &result = GetOrCreateResOperand(parent, primType); + Operand &result = GetOrCreateResOperand(parent, PTY_a64); /* OP_constval */ ConstvalNode *constvalNode = static_cast(opnd1); @@ -8236,7 +8235,7 @@ MemOperand &AArch64CGFunc::CreateNonExtendMemOpnd(PrimType ptype, const BaseNode ASSERT(constOfstNode->GetConstVal()->GetKind() == kConstInt, "expect MIRIntConst"); MIRIntConst *intOfst = safe_cast(constOfstNode->GetConstVal()); CHECK_FATAL(intOfst != nullptr, "just checking"); - offset = (addrExpr.GetOpCode() == OP_add) ? offset + intOfst->GetValue() : offset - intOfst->GetValue(); + offset = (addrExpr.GetOpCode() == OP_add) ? offset + intOfst->GetSXTValue() : offset - intOfst->GetSXTValue(); } else { addrOpnd = HandleExpr(parent, addrExpr); } diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_color_ra.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_color_ra.cpp index 859e968f706b56ad47cfeabbd76bf3bfad80a942..e47437aa808aed4a111936b50212a7c3ef023f61 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_color_ra.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_color_ra.cpp @@ -242,7 +242,8 @@ std::vector LiveRange::Rematerialize(AArch64CGFunc *cgFunc, kSizeOfPtr * kBitsPerByte, static_cast(®Op), nullptr, &offsetOp, nullptr); - insn = &cg->BuildInstruction(MOP_xldr, regOp, memOpnd); + MOperator ldOp = (memOpnd.GetSize() == k64BitSize) ? MOP_xldr : MOP_wldr; + insn = &cg->BuildInstruction(ldOp, regOp, memOpnd); insns.push_back(insn); if (offset > 0) { AArch64OfstOperand &ofstOpnd = cgFunc->GetOrCreateOfstOpnd(static_cast(offset), k32BitSize); diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_operand.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_operand.cpp index be6f5aaaccdcacd9586791e78ea674d182bc041b..3fb761948b2f2a4e7b920a7fc6a80c1ecfae86b6 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_operand.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_operand.cpp @@ -256,7 +256,7 @@ void AArch64MemOperand::Emit(Emitter &emitter, const OpndProp *opndProp) const { auto *baseReg = static_cast(GetBaseRegister()); ASSERT(baseReg != nullptr, "expect an AArch64RegOperand here"); uint32 baseSize = baseReg->GetSize(); - if (CGOptions::IsPIC() && (baseSize != k64BitSize)) { + if (baseSize != k64BitSize) { baseReg->SetSize(k64BitSize); } baseReg->Emit(emitter, nullptr); diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_prop.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_prop.cpp index 06fde8e3c93b1fa1ef9c18a275a83d2f4d15d985..3557ec087bc0f84629005f6560267819df811f63 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_prop.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_prop.cpp @@ -99,6 +99,8 @@ MOperator A64ConstProp::GetReversalMOP(MOperator arithMop) { return MOP_xsubrri12; case MOP_xsubrri12: return MOP_xaddrri12; + case MOP_wsubrri12: + return MOP_waddrri12; default: CHECK_FATAL(false, "NYI"); break; @@ -1592,10 +1594,9 @@ void FpSpConstProp::Optimize(Insn &insn) { PropInMem(*useInsnInfo.second, *useInsn); switch (useMop) { case MOP_xmovrr: + case MOP_wmovrr: PropInCopy(*useInsnInfo.second, *useInsn, insn.GetMachineOpcode()); break; - case MOP_wmovrr: - CHECK_FATAL(false, "NIY mov 32"); case MOP_xaddrri12: PropInArith(*useInsnInfo.second, *useInsn, kAArch64Add); break; diff --git a/src/mapleall/maple_be/src/cg/cg_phasemanager.cpp b/src/mapleall/maple_be/src/cg/cg_phasemanager.cpp index a7ae2e728043e065a6af55f7ff84de4ccaf80f0c..eebcdf4623b2deb9555336b8faab81d8a3f0eed9 100644 --- a/src/mapleall/maple_be/src/cg/cg_phasemanager.cpp +++ b/src/mapleall/maple_be/src/cg/cg_phasemanager.cpp @@ -45,6 +45,24 @@ namespace maplebe { } \ } while (0) +namespace { + +void DumpMIRFunc(MIRFunction &func, const char *msg, bool printAlways = false, const char* extraMsg = nullptr) { + bool dumpAll = (CGOptions::GetDumpPhases().find("*") != CGOptions::GetDumpPhases().end()); + bool dumpFunc = CGOptions::FuncFilter(func.GetName()); + + if (printAlways || (dumpAll && dumpFunc)) { + LogInfo::MapleLogger() << msg << '\n'; + func.Dump(); + + if (extraMsg) { + LogInfo::MapleLogger() << extraMsg << '\n'; + } + } +} + +} // anonymous namespace + void CgFuncPM::GenerateOutPutFile(MIRModule &m) { CHECK_FATAL(cg != nullptr, "cg is null"); CHECK_FATAL(cg->GetEmitter(), "emitter is null"); @@ -116,6 +134,7 @@ bool CgFuncPM::PhaseRun(MIRModule &m) { /* LowerIR. */ m.SetCurFunction(mirFunc); if (cg->DoConstFold()) { + DumpMIRFunc(*mirFunc, "************* before ConstantFold **************"); ConstantFold cf(m); (void)cf.Simplify(mirFunc->GetBody()); } @@ -249,20 +268,18 @@ void CgFuncPM::DoFuncCGLower(const MIRModule &m, MIRFunction &mirFunc) { if (m.GetFlavor() <= kFeProduced) { mirLower->SetLowerCG(); mirLower->SetMirFunc(&mirFunc); + + DumpMIRFunc(mirFunc, "************* before MIRLowerer **************"); mirLower->LowerFunc(mirFunc); } - bool dumpAll = (CGOptions::GetDumpPhases().find("*") != CGOptions::GetDumpPhases().end()); - bool dumpFunc = CGOptions::FuncFilter(mirFunc.GetName()); - if (!cg->IsQuiet() || (dumpAll && dumpFunc)) { - LogInfo::MapleLogger() << "************* before CGLowerer **************" << '\n'; - mirFunc.Dump(); - } + + bool isNotQuiet = !cg->IsQuiet(); + DumpMIRFunc(mirFunc, "************* before CGLowerer **************", isNotQuiet); + cgLower->LowerFunc(mirFunc); - if (!cg->IsQuiet() || (dumpAll && dumpFunc)) { - LogInfo::MapleLogger() << "************* after CGLowerer **************" << '\n'; - mirFunc.Dump(); - LogInfo::MapleLogger() << "************* end CGLowerer **************" << '\n'; - } + + DumpMIRFunc(mirFunc, "************* after CGLowerer **************", isNotQuiet, + "************* end CGLowerer **************"); } void CgFuncPM::EmitDuplicatedAsmFunc(MIRModule &m) const { diff --git a/src/mapleall/maple_ir/include/mir_const.h b/src/mapleall/maple_ir/include/mir_const.h index a8abffac8534c620edc957b196b537dbcd45fcc1..bd66b92894dde770f4f7dee611ae662ee7ee0c90 100644 --- a/src/mapleall/maple_ir/include/mir_const.h +++ b/src/mapleall/maple_ir/include/mir_const.h @@ -97,8 +97,6 @@ class MIRIntConst : public MIRConst { if (!IsPrimitiveDynType(type.GetPrimType())) { if (type.GetPrimType() == PTY_u128 || type.GetPrimType() == PTY_i128) { Trunc(64u); - } else if (type.GetPrimType() == PTY_a32) { - CHECK_FATAL(val <= INT32_MAX && val >= INT32_MIN, "address out of range"); } else { Trunc(GetPrimTypeBitSize(type.GetPrimType())); } @@ -141,6 +139,11 @@ class MIRIntConst : public MIRConst { return value; } + int64 GetSXTValue() const { + uint32 width = GetPrimTypeBitSize(GetType().GetPrimType()); + return static_cast(value << (64 - width)) >> (64 - width); + } + void SetValue(int64 val) const { (void)val; CHECK_FATAL(false, "Can't Use This Interface in This Object"); diff --git a/src/mapleall/maple_ir/include/prim_types.def b/src/mapleall/maple_ir/include/prim_types.def index 3d2324f0c5b8f14a58f71a95e0bb267f4848695e..5492f972bf234f2122952920c844411deb52e3a7 100644 --- a/src/mapleall/maple_ir/include/prim_types.def +++ b/src/mapleall/maple_ir/include/prim_types.def @@ -141,18 +141,29 @@ static const PrimitiveTypeProperty PTProperty_u16 = { /*isVector*/false }; +#ifdef ILP32 +#define IS_U32_PTR true +#define IS_U64_PTR false +#else +#define IS_U32_PTR false +#define IS_U64_PTR true +#endif + static const PrimitiveTypeProperty PTProperty_u32 = { - /*type=*/PTY_u32, /*isInteger=*/true, /*isUnsigned=*/true, /*isAddress=*/false, /*isFloat=*/false, - /*isPointer=*/false, /*isSimple=*/false, /*isDynamic=*/false, /*isDynamicAny=*/false, /*isDynamicNone=*/false, + /*type=*/PTY_u32, /*isInteger=*/true, /*isUnsigned=*/true, /*isAddress=*/IS_U32_PTR, /*isFloat=*/false, + /*isPointer=*/IS_U32_PTR, /*isSimple=*/false, /*isDynamic=*/false, /*isDynamicAny=*/false, /*isDynamicNone=*/false, /*isVector*/false }; static const PrimitiveTypeProperty PTProperty_u64 = { - /*type=*/PTY_u64, /*isInteger=*/true, /*isUnsigned=*/true, /*isAddress=*/true, /*isFloat=*/false, - /*isPointer=*/true, /*isSimple=*/false, /*isDynamic=*/false, /*isDynamicAny=*/false, /*isDynamicNone=*/false, + /*type=*/PTY_u64, /*isInteger=*/true, /*isUnsigned=*/true, /*isAddress=*/IS_U64_PTR, /*isFloat=*/false, + /*isPointer=*/IS_U64_PTR, /*isSimple=*/false, /*isDynamic=*/false, /*isDynamicAny=*/false, /*isDynamicNone=*/false, /*isVector*/false }; +#undef IS_U32_PTR +#undef IS_U64_PTR + static const PrimitiveTypeProperty PTProperty_u128 = { /*type=*/PTY_u128, /*isInteger=*/true, /*isUnsigned=*/true, /*isAddress=*/false, /*isFloat=*/false, /*isPointer=*/false, /*isSimple=*/false, /*isDynamic=*/false, /*isDynamicAny=*/false, /*isDynamicNone=*/false,