From 8440958502f07fdd0a5d46d9c63622958b470f50 Mon Sep 17 00:00:00 2001 From: William Chen Date: Fri, 12 Mar 2021 13:10:07 -0800 Subject: [PATCH 1/5] Fix typo in lowering of bits deposit where size is incorrect --- src/mapleall/maple_be/src/be/lower.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mapleall/maple_be/src/be/lower.cpp b/src/mapleall/maple_be/src/be/lower.cpp index ea07f81155..05a926edcf 100644 --- a/src/mapleall/maple_be/src/be/lower.cpp +++ b/src/mapleall/maple_be/src/be/lower.cpp @@ -829,7 +829,7 @@ StmtNode *CGLowerer::LowerIassignBitfield(IassignNode &iassign, BlockNode &newBl DepositbitsNode *depositBits = mirModule.CurFuncCodeMemPool()->New(); depositBits->SetPrimType(GetRegPrimType(fType->GetPrimType())); depositBits->SetBitsOffset(byteBitOffsets.second); - depositBits->SetBitsOffset(static_cast(fType)->GetFieldSize()); + depositBits->SetBitsSize(static_cast(fType)->GetFieldSize()); depositBits->SetBOpnd(ireadNode, 0); depositBits->SetBOpnd(iassign.GetRHS(), 1); -- Gitee From 1cf7c8c93d9b5da0c3e80ee3e21d03273aa9006b Mon Sep 17 00:00:00 2001 From: William Chen Date: Fri, 12 Mar 2021 13:11:10 -0800 Subject: [PATCH 2/5] Change label to L for label prefix --- src/mapleall/maple_be/src/cg/aarch64/aarch64_insn.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_insn.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_insn.cpp index c4bf2b1669..ce16ce9f72 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_insn.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_insn.cpp @@ -741,7 +741,7 @@ void AArch64Insn::EmitAdrpLabel(Emitter &emitter) const { emitter.Emit(", "); const char *idx; idx = strdup(std::to_string(Globals::GetInstance()->GetBECommon()->GetMIRModule().CurFunction()->GetPuidx()).c_str()); - emitter.Emit(".label.").Emit(idx).Emit("__").Emit(lidx).Emit("\n"); + emitter.Emit(".L.").Emit(idx).Emit("__").Emit(lidx).Emit("\n"); /* add xd, xd, #lo12:label */ emitter.Emit("\tadd\t"); @@ -749,7 +749,7 @@ void AArch64Insn::EmitAdrpLabel(Emitter &emitter) const { emitter.Emit(", "); opnd0->Emit(emitter, prop0); emitter.Emit(", "); - emitter.Emit(":lo12:").Emit(".label.").Emit(idx).Emit("__").Emit(lidx).Emit("\n"); + emitter.Emit(":lo12:").Emit(".L.").Emit(idx).Emit("__").Emit(lidx).Emit("\n"); emitter.Emit("\n"); } -- Gitee From 764cba21384ef468646483a69f3abce6025e642b Mon Sep 17 00:00:00 2001 From: William Chen Date: Fri, 12 Mar 2021 14:26:42 -0800 Subject: [PATCH 3/5] Update type table for C when new type is created --- src/mapleall/maple_be/include/be/becommon.h | 2 +- src/mapleall/maple_be/src/be/becommon.cpp | 17 ++++++++++------- src/mapleall/maple_be/src/be/lower.cpp | 1 - 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/mapleall/maple_be/include/be/becommon.h b/src/mapleall/maple_be/include/be/becommon.h index 89092fc5db..baceed351c 100644 --- a/src/mapleall/maple_be/include/be/becommon.h +++ b/src/mapleall/maple_be/include/be/becommon.h @@ -143,7 +143,7 @@ class BECommon { } /* Global type table might be updated during lowering for C/C++. */ - void FinalizeTypeTable(); + void FinalizeTypeTable(MIRType &ty); uint32 GetFieldIdxIncrement(const MIRType &ty) const { if (ty.GetKind() == kTypeClass) { diff --git a/src/mapleall/maple_be/src/be/becommon.cpp b/src/mapleall/maple_be/src/be/becommon.cpp index 28b83f1374..2179f1e1d7 100644 --- a/src/mapleall/maple_be/src/be/becommon.cpp +++ b/src/mapleall/maple_be/src/be/becommon.cpp @@ -608,7 +608,7 @@ bool BECommon::TyIsInSizeAlignTable(const MIRType &ty) const { } void BECommon::AddAndComputeSizeAlign(MIRType &ty) { - CHECK_FATAL(ty.GetTypeIndex() == typeSizeTable.size(), "make sure the ty idx is exactly the table size"); + FinalizeTypeTable(ty); typeAlignTable.emplace_back(mirModule.IsCModule()); typeSizeTable.emplace_back(0); ComputeTypeSizesAligns(ty); @@ -643,12 +643,15 @@ MIRType *BECommon::BeGetOrCreateFunctionType(TyIdx tyIdx, const std::vector GetSizeOfTypeSizeTable())) { - for (uint32 i = GetSizeOfTypeSizeTable(); i < GlobalTables::GetTypeTable().GetTypeTableSize(); ++i) { - MIRType *ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(i); - AddAndComputeSizeAlign(*ty); +void BECommon::FinalizeTypeTable(MIRType &ty) { + if (ty.GetTypeIndex() > GetSizeOfTypeSizeTable()) { + if (mirModule.GetSrcLang() == kSrcLangC) { + for (uint32 i = GetSizeOfTypeSizeTable(); i < ty.GetTypeIndex(); ++i) { + MIRType *ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(i); + AddAndComputeSizeAlign(*ty); + } + } else { + CHECK_FATAL(ty.GetTypeIndex() == typeSizeTable.size(), "make sure the ty idx is exactly the table size"); } } } diff --git a/src/mapleall/maple_be/src/be/lower.cpp b/src/mapleall/maple_be/src/be/lower.cpp index 05a926edcf..1b171ad463 100644 --- a/src/mapleall/maple_be/src/be/lower.cpp +++ b/src/mapleall/maple_be/src/be/lower.cpp @@ -3019,7 +3019,6 @@ void CGLowerer::LowerFunc(MIRFunction &func) { CHECK_FATAL(origBody != nullptr, "origBody should not be nullptr"); BlockNode *newBody = LowerBlock(*origBody); - beCommon.FinalizeTypeTable(); func.SetBody(newBody); if (needBranchCleanup) { CleanupBranches(func); -- Gitee From 2de5fecf26c51ee1904d56e056ca210d57307819 Mon Sep 17 00:00:00 2001 From: William Chen Date: Fri, 12 Mar 2021 17:09:43 -0800 Subject: [PATCH 4/5] Check for union when emit agg constvec --- src/mapleall/maple_be/src/cg/emit.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mapleall/maple_be/src/cg/emit.cpp b/src/mapleall/maple_be/src/cg/emit.cpp index 6d8e497b2d..0260ee5692 100644 --- a/src/mapleall/maple_be/src/cg/emit.cpp +++ b/src/mapleall/maple_be/src/cg/emit.cpp @@ -1504,6 +1504,9 @@ void Emitter::EmitStructConstant(MIRConst &mirConst) { /* total size of emitted elements size. */ uint32 size = Globals::GetInstance()->GetBECommon()->GetTypeSize(structType.GetTypeIndex()); uint32 fieldIdx = 1; + if (structType.GetKind() == kTypeUnion) { + fieldIdx = structCt.GetConstVecItem(0)->GetFieldId(); + } for (uint32 i = 0; i < num; ++i) { if (((i + 1) == num) && cg->GetMIRModule()->GetSrcLang() == kSrcLangC) { isFlexibleArray = Globals::GetInstance()->GetBECommon()->GetHasFlexibleArray(mirType.GetTypeIndex().GetIdx()); -- Gitee From 847654b79896a776780a7796f8b685ab885fe380 Mon Sep 17 00:00:00 2001 From: William Chen Date: Fri, 12 Mar 2021 17:30:39 -0800 Subject: [PATCH 5/5] Fix mir importer for int const table. --- src/mapleall/maple_ir/src/mir_parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mapleall/maple_ir/src/mir_parser.cpp b/src/mapleall/maple_ir/src/mir_parser.cpp index 0f0392eec4..6cc71d5540 100644 --- a/src/mapleall/maple_ir/src/mir_parser.cpp +++ b/src/mapleall/maple_ir/src/mir_parser.cpp @@ -2606,7 +2606,7 @@ bool MIRParser::ParseScalarValue(MIRConstPtr &stype, MIRType &type) { Error("constant value incompatible with integer type at "); return false; } - stype = GlobalTables::GetIntConstTable().GetOrCreateIntConst(lexer.GetTheIntVal(), type); + stype = mod.GetMemPool()->New(lexer.GetTheIntVal(), type); } else if (ptp == PTY_f32) { if (lexer.GetTokenKind() != TK_floatconst) { Error("constant value incompatible with single-precision float type at "); -- Gitee