From 4d0ac784ff3e11d08890fe48440b4d745f1b46a4 Mon Sep 17 00:00:00 2001 From: Wen HU Date: Mon, 27 Jun 2022 07:14:09 -0700 Subject: [PATCH 1/8] link ExprLoc for alias variables --- src/mapleall/maple_ir/include/debug_info.h | 12 ++++++++++++ src/mapleall/maple_ir/src/debug_info.cpp | 20 ++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/mapleall/maple_ir/include/debug_info.h b/src/mapleall/maple_ir/include/debug_info.h index 06820d844a..bfd953a972 100644 --- a/src/mapleall/maple_ir/include/debug_info.h +++ b/src/mapleall/maple_ir/include/debug_info.h @@ -462,6 +462,16 @@ class DBGDie { return subDieVec[i]; } + // link ExprLoc to die's + void LinkExprLoc(DBGDie *die) { + for (auto &at : attrVec) { + if (at->GetDwAt() == DW_AT_location) { + DBGExprLoc *loc = die->GetExprLoc(); + at->SetPtr(loc); + } + } + } + private: MIRModule *module; DwTag tag; @@ -625,6 +635,8 @@ class DebugInfo { void BuildAbbrev(); uint32 GetAbbrevId(DBGAbbrevEntryVec *vec, DBGAbbrevEntry *entry); + DBGDie *GetGlobalDie(GStrIdx strIdx); + void SetLocalDie(GStrIdx strIdx, const DBGDie *die); void SetLocalDie(MIRFunction *func, GStrIdx strIdx, const DBGDie *die); DBGDie *GetLocalDie(GStrIdx strIdx); diff --git a/src/mapleall/maple_ir/src/debug_info.cpp b/src/mapleall/maple_ir/src/debug_info.cpp index d6a1c040bb..88e6a3ba2c 100644 --- a/src/mapleall/maple_ir/src/debug_info.cpp +++ b/src/mapleall/maple_ir/src/debug_info.cpp @@ -302,15 +302,22 @@ void DebugInfo::AddAliasDies(MapleMap &aliasMap) { for (auto &i : aliasMap) { // maple var MIRSymbol *var = nullptr; + GStrIdx mplIdx = i.second.mplStrIdx; if (i.second.isLocal) { - var = func->GetSymTab()->GetSymbolFromStrIdx(i.second.mplStrIdx); + var = func->GetSymTab()->GetSymbolFromStrIdx(mplIdx); } else { - var = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(i.second.mplStrIdx); + var = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(mplIdx); } ASSERT(var, "can not find symbol"); // create alias die using maple var except name DBGDie *vdie = CreateVarDie(var, i.first); + // maple var die + DBGDie *mdie = (var->IsGlobal()) ? GetGlobalDie(mplIdx) : GetLocalDie(mplIdx); + ASSERT(mdie, "can not find maple mdie"); + + // link vdie's ExprLoc to mdie's + vdie->LinkExprLoc(mdie); GetParentDie()->AddSubVec(vdie); @@ -409,6 +416,15 @@ void DebugInfo::SetLocalDie(MIRFunction *func, GStrIdx strIdx, const DBGDie *die (funcLstrIdxDieIdMap[func])[strIdx.GetIdx()] = die->GetId(); } +DBGDie *DebugInfo::GetGlobalDie(GStrIdx strIdx) { + unsigned idx = strIdx.GetIdx(); + if (stridxDieIdMap.find(idx) != stridxDieIdMap.end()) { + uint32 id = stridxDieIdMap[idx]; + return idDieMap[id]; + } + return nullptr; +} + DBGDie *DebugInfo::GetLocalDie(MIRFunction *func, GStrIdx strIdx) { uint32 id = (funcLstrIdxDieIdMap[func])[strIdx.GetIdx()]; return idDieMap[id]; -- Gitee From 5b456640d2fb95dde51e5d8b458091e392944a5e Mon Sep 17 00:00:00 2001 From: Wen HU Date: Mon, 27 Jun 2022 07:14:36 -0700 Subject: [PATCH 2/8] skip dwarf for maple local variables for C --- src/mapleall/maple_be/src/cg/emit.cpp | 5 ++++- src/mapleall/maple_ir/include/debug_info.h | 9 +++++++++ src/mapleall/maple_ir/src/debug_info.cpp | 12 +++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/mapleall/maple_be/src/cg/emit.cpp b/src/mapleall/maple_be/src/cg/emit.cpp index f4023e2d37..779790702d 100644 --- a/src/mapleall/maple_be/src/cg/emit.cpp +++ b/src/mapleall/maple_be/src/cg/emit.cpp @@ -3282,6 +3282,9 @@ void Emitter::EmitDIDebugInfoSection(DebugInfo *mirdi) { emitter->Emit("\t.byte 0x0\n"); return; } + if (!die->GetKeep()) { + return; + } bool verbose = emitter->GetCG()->GenerateVerboseAsm(); if (verbose) { emitter->Emit("\n"); @@ -3479,7 +3482,7 @@ void Emitter::SetupDBGInfo(DebugInfo *mirdi) { Emitter *emitter = this; MapleVector &abbrevVec = mirdi->GetAbbrevVec(); ApplyInPrefixOrder(mirdi->GetCompUnit(), [&abbrevVec, &emitter](DBGDie *die) { - if (!die) { + if (!die || !die->GetKeep()) { return; } diff --git a/src/mapleall/maple_ir/include/debug_info.h b/src/mapleall/maple_ir/include/debug_info.h index bfd953a972..d1a56e4bca 100644 --- a/src/mapleall/maple_ir/include/debug_info.h +++ b/src/mapleall/maple_ir/include/debug_info.h @@ -382,6 +382,14 @@ class DBGDie { withChildren = val; } + bool GetKeep() const { + return keep; + } + + void SetKeep(bool val) { + keep = val; + } + DBGDie *GetParent() const { return parent; } @@ -477,6 +485,7 @@ class DBGDie { DwTag tag; uint32 id; // starts from 1 which is root die compUnit bool withChildren; + bool keep; // whether emit into .s DBGDie *parent; DBGDie *sibling; DBGDie *firstChild; diff --git a/src/mapleall/maple_ir/src/debug_info.cpp b/src/mapleall/maple_ir/src/debug_info.cpp index 88e6a3ba2c..1e76e17d3a 100644 --- a/src/mapleall/maple_ir/src/debug_info.cpp +++ b/src/mapleall/maple_ir/src/debug_info.cpp @@ -41,6 +41,7 @@ DBGDie::DBGDie(MIRModule *m, DwTag tag) tag(tag), id(m->GetDbgInfo()->GetMaxId()), withChildren(false), + keep(true), sibling(nullptr), firstChild(nullptr), abbrevId(0), @@ -662,7 +663,13 @@ DBGDie *DebugInfo::GetOrCreateFuncDefDie(MIRFunction *func, uint32 lnum) { for (uint32 i = 1; i < func->GetSymTab()->GetSymbolTableSize(); i++) { MIRSymbol *var = func->GetSymTab()->GetSymbolFromStIdx(i); DBGDie *vdie = CreateVarDie(var); - die->AddSubVec(vdie); + if (vdie) { + die->AddSubVec(vdie); + // for C, source variable names will be used instead of mangloed maple variables + if (module->IsCModule()) { + vdie->SetKeep(false); + } + } } } @@ -1288,6 +1295,9 @@ void DebugInfo::ComputeSizeAndOffsets() { // Compute the size and offset of a DIE. The Offset is relative to start of the CU. // It returns the offset after laying out the DIE. void DebugInfo::ComputeSizeAndOffset(DBGDie *die, uint32 &cuOffset) { + if (!die->GetKeep()) { + return; + } uint32 cuOffsetOrg = cuOffset; die->SetOffset(cuOffset); -- Gitee From 470d6da6cfb55add989b659a812fc1bef7de90dc Mon Sep 17 00:00:00 2001 From: Wen HU Date: Fri, 24 Jun 2022 10:33:04 -0700 Subject: [PATCH 3/8] add unique id for scopes --- src/hir2mpl/common/src/fe_function.cpp | 3 +-- src/mapleall/maple_ir/include/mir_function.h | 3 ++- src/mapleall/maple_ir/include/mir_scope.h | 10 ++++++++-- src/mapleall/maple_ir/src/mir_scope.cpp | 4 ++++ src/mapleall/maple_ir/src/parser.cpp | 6 ++---- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/hir2mpl/common/src/fe_function.cpp b/src/hir2mpl/common/src/fe_function.cpp index 4bdc3002c4..048b41766a 100644 --- a/src/hir2mpl/common/src/fe_function.cpp +++ b/src/hir2mpl/common/src/fe_function.cpp @@ -795,8 +795,7 @@ void FEFunction::PushFuncScope(const SrcPosition &startOfScope, const SrcPositio UniqueFEIRScope feirScope = std::make_unique(); if (FEOptions::GetInstance().IsDbgFriendly()) { MIRScope *mockedScope = mirFunction.GetScope(); - MIRScope *mirScope = mirFunction.GetModule()->GetMemPool()->New( - mirFunction.GetModule(), 1); // func scope start level is 1 + MIRScope *mirScope = mirFunction.GetModule()->GetMemPool()->New(mirFunction.GetModule()); mirScope->SetRange(startOfScope, endOfScope); mockedScope->AddScope(mirScope); feirScope->SetMIRScope(mirScope); diff --git a/src/mapleall/maple_ir/include/mir_function.h b/src/mapleall/maple_ir/include/mir_function.h index 4465363c64..3e87313d69 100644 --- a/src/mapleall/maple_ir/include/mir_function.h +++ b/src/mapleall/maple_ir/include/mir_function.h @@ -69,7 +69,8 @@ class MIRFunction { MIRFunction(MIRModule *mod, StIdx idx) : module(mod), symbolTableIdx(idx) { - scope = module->GetMemPool()->New(mod); + // function scope is of level 0 + scope = module->GetMemPool()->New(module, 0); } ~MIRFunction() = default; diff --git a/src/mapleall/maple_ir/include/mir_scope.h b/src/mapleall/maple_ir/include/mir_scope.h index 0b7667ab66..846b77a164 100644 --- a/src/mapleall/maple_ir/include/mir_scope.h +++ b/src/mapleall/maple_ir/include/mir_scope.h @@ -29,8 +29,8 @@ struct MIRAliasVars { class MIRScope { public: - explicit MIRScope(MIRModule *mod) : module(mod) {} - MIRScope(MIRModule *mod, unsigned l) : module(mod), level(l) {} + // default to level 1, function scope is level 0 which is created by MIRFunction constructor + MIRScope(MIRModule *mod, unsigned l = 1); ~MIRScope() = default; bool NeedEmitAliasInfo() const { @@ -45,6 +45,10 @@ class MIRScope { return level; } + unsigned GetId() const { + return id; + } + const SrcPosition &GetRangeLow() const { return range.first; } @@ -85,9 +89,11 @@ class MIRScope { private: MIRModule *module; unsigned level = 0; + unsigned id; std::pair range; // source to maple variable alias MapleMap aliasVarMap { module->GetMPAllocator().Adapter() }; + // subscopes' range should be disjoint MapleVector subScopes { module->GetMPAllocator().Adapter() }; }; } // namespace maple diff --git a/src/mapleall/maple_ir/src/mir_scope.cpp b/src/mapleall/maple_ir/src/mir_scope.cpp index c80a4aab47..733a74d82c 100644 --- a/src/mapleall/maple_ir/src/mir_scope.cpp +++ b/src/mapleall/maple_ir/src/mir_scope.cpp @@ -18,6 +18,10 @@ namespace maple { +static unsigned scopeId = 0; + +MIRScope::MIRScope(MIRModule *mod, unsigned l) : module(mod), level(l), id(scopeId++) {} + // scp is a sub scope // (low (scp.low, scp.high] high] bool MIRScope::IsSubScope(const MIRScope *scp) const { diff --git a/src/mapleall/maple_ir/src/parser.cpp b/src/mapleall/maple_ir/src/parser.cpp index e9a8fec8dd..a10e84a1db 100644 --- a/src/mapleall/maple_ir/src/parser.cpp +++ b/src/mapleall/maple_ir/src/parser.cpp @@ -2464,8 +2464,7 @@ bool MIRParser::ParseOneScope(MIRScope &scope) { break; } case TK_SCOPE: { - // initial level 1 - MIRScope *scp = mod.GetMemPool()->New(&mod, 1); + MIRScope *scp = mod.GetMemPool()->New(&mod); status = ParseOneScope(*scp); if (status) { scope.AddScope(scp); @@ -2491,8 +2490,7 @@ bool MIRParser::ParseOneScope(MIRScope &scope) { } bool MIRParser::ParseScope(StmtNodePtr &stmt) { - // initial level 1 - MIRScope *scp = mod.GetMemPool()->New(&mod, 1); + MIRScope *scp = mod.GetMemPool()->New(&mod); bool status = ParseOneScope(*scp); if (status) { mod.CurFunction()->GetScope()->AddScope(scp); -- Gitee From d2657711df07ecd7c43dbb83cb5844a7f31b9331 Mon Sep 17 00:00:00 2001 From: Wen HU Date: Tue, 28 Jun 2022 10:48:41 -0700 Subject: [PATCH 4/8] update dwarf for MIRScope with scope begin/end labels in .s --- src/hir2mpl/common/src/fe_function.cpp | 6 +- src/mapleall/maple_be/include/cg/cgfunc.h | 3 +- src/mapleall/maple_be/include/cg/dbg.def | 1 + .../src/cg/aarch64/aarch64_emitter.cpp | 24 +++++-- src/mapleall/maple_be/src/cg/cgfunc.cpp | 72 +++++++++++++------ src/mapleall/maple_be/src/cg/emit.cpp | 6 ++ src/mapleall/maple_ir/include/debug_info.h | 18 +++++ src/mapleall/maple_ir/include/mir_function.h | 3 +- src/mapleall/maple_ir/include/mir_scope.h | 8 +-- src/mapleall/maple_ir/include/src_position.h | 29 ++++++-- src/mapleall/maple_ir/src/debug_info.cpp | 52 ++++++++++++-- src/mapleall/maple_ir/src/mir_scope.cpp | 53 +++++--------- src/mapleall/maple_ir/src/parser.cpp | 9 +-- 13 files changed, 193 insertions(+), 91 deletions(-) diff --git a/src/hir2mpl/common/src/fe_function.cpp b/src/hir2mpl/common/src/fe_function.cpp index 048b41766a..c8d06ef5a5 100644 --- a/src/hir2mpl/common/src/fe_function.cpp +++ b/src/hir2mpl/common/src/fe_function.cpp @@ -794,10 +794,8 @@ void FEFunction::AddLocForStmt(const FEIRStmt &stmt, std::list &mirSt void FEFunction::PushFuncScope(const SrcPosition &startOfScope, const SrcPosition &endOfScope) { UniqueFEIRScope feirScope = std::make_unique(); if (FEOptions::GetInstance().IsDbgFriendly()) { - MIRScope *mockedScope = mirFunction.GetScope(); - MIRScope *mirScope = mirFunction.GetModule()->GetMemPool()->New(mirFunction.GetModule()); + MIRScope *mirScope = mirFunction.GetScope(); mirScope->SetRange(startOfScope, endOfScope); - mockedScope->AddScope(mirScope); feirScope->SetMIRScope(mirScope); } stmtsScopeStack.push(std::move(feirScope)); @@ -808,7 +806,7 @@ void FEFunction::PushStmtScope(const SrcPosition &startOfScope, const SrcPositio if (FEOptions::GetInstance().IsDbgFriendly()) { MIRScope *parentMIRScope = GetTopStmtMIRScope(); MIRScope *mirScope = mirFunction.GetModule()->GetMemPool()->New( - mirFunction.GetModule(), parentMIRScope->GetLevel()); + mirFunction.GetModule()); mirScope->SetRange(startOfScope, endOfScope); parentMIRScope->AddScope(mirScope); feirScope->SetMIRScope(mirScope); diff --git a/src/mapleall/maple_be/include/cg/cgfunc.h b/src/mapleall/maple_be/include/cg/cgfunc.h index 4a8ee93eb8..92a1d74e2e 100644 --- a/src/mapleall/maple_be/include/cg/cgfunc.h +++ b/src/mapleall/maple_be/include/cg/cgfunc.h @@ -161,7 +161,8 @@ class CGFunc { virtual void AssignLmbcFormalParams() = 0; LmbcFormalParamInfo *GetLmbcFormalParamInfo(uint32 offset); virtual void LmbcGenSaveSpForAlloca() = 0; - void GenerateLoc(StmtNode *stmt, unsigned &lastSrcLoc, unsigned &lastMplLoc); + void GenerateLoc(StmtNode *stmt, SrcPosition &lastSrcPos, SrcPosition &lastMplPos); + void GenerateScopeLabel(StmtNode *stmt, SrcPosition &lastSrcPos); int32 GetFreqFromStmt(uint32 stmtId); void GenerateInstruction(); bool MemBarOpt(const StmtNode &membar); diff --git a/src/mapleall/maple_be/include/cg/dbg.def b/src/mapleall/maple_be/include/cg/dbg.def index 9c8a9fa94f..b49c9093cb 100644 --- a/src/mapleall/maple_be/include/cg/dbg.def +++ b/src/mapleall/maple_be/include/cg/dbg.def @@ -14,3 +14,4 @@ */ /* .loc fileNum lineNum */ DBG_DEFINE(loc, , 2, Immediate, Immediate, Undef) +DBG_DEFINE(scope, , 2, Immediate, Immediate, Undef) diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_emitter.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_emitter.cpp index 7b109e6970..70d6161e65 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_emitter.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_emitter.cpp @@ -2096,11 +2096,25 @@ static DbgDescr dbgDescrTable[mpldbg::kOpDbgLast + 1] = { void AArch64AsmEmitter::EmitAArch64DbgInsn(Emitter &emitter, const Insn &insn) const { MOperator mOp = insn.GetMachineOpcode(); DbgDescr &dbgDescr = dbgDescrTable[mOp]; - (void)emitter.Emit("\t.").Emit(dbgDescr.name); - for (uint32 i = 0; i < dbgDescr.opndCount; ++i) { - (void)emitter.Emit(" "); - Operand &curOperand = insn.GetOperand(i); - curOperand.Emit(emitter, nullptr); + switch (mOp) { + case mpldbg::OP_DBG_scope: + { + unsigned val = (unsigned)(static_cast(insn.GetOperand(0)).GetValue()); + emitter.Emit(".LScp." + std::to_string(val)); + val = (unsigned)(static_cast(insn.GetOperand(1)).GetValue()); + emitter.Emit((val == 0) ? "B:" : "E:"); + break; + } + default: + { + (void)emitter.Emit("\t.").Emit(dbgDescr.name); + for (uint32 i = 0; i < dbgDescr.opndCount; ++i) { + (void)emitter.Emit(" "); + Operand &curOperand = insn.GetOperand(i); + curOperand.Emit(emitter, nullptr); + } + break; + } } (void)emitter.Emit("\n"); } diff --git a/src/mapleall/maple_be/src/cg/cgfunc.cpp b/src/mapleall/maple_be/src/cg/cgfunc.cpp index 9676b442fd..04de1f0e2b 100644 --- a/src/mapleall/maple_be/src/cg/cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/cgfunc.cpp @@ -1503,34 +1503,62 @@ bool CGFunc::CheckSkipMembarOp(const StmtNode &stmt) { return false; } -void CGFunc::GenerateLoc(StmtNode *stmt, unsigned &lastSrcLoc, unsigned &lastMplLoc) { +void CGFunc::GenerateLoc(StmtNode *stmt, SrcPosition &lastSrcPos, SrcPosition &lastMplPos) { /* insert Insn for .loc before cg for the stmt */ if (cg->GetCGOptions().WithLoc() && stmt->op != OP_label && stmt->op != OP_comment) { /* if original src file location info is availiable for this stmt, * use it and skip mpl file location info for this stmt */ bool hasLoc = false; - unsigned newSrcLoc = cg->GetCGOptions().WithSrc() ? stmt->GetSrcPos().LineNum() : 0; - if (newSrcLoc != 0 && newSrcLoc != lastSrcLoc) { + SrcPosition &newSrcPos = stmt->GetSrcPos(); + if (cg->GetCGOptions().WithSrc() && lastSrcPos.IsBf(newSrcPos)) { /* .loc for original src file */ - unsigned fileid = stmt->GetSrcPos().FileNum(); - Operand *o0 = CreateDbgImmOperand(fileid); - Operand *o1 = CreateDbgImmOperand(newSrcLoc); - Insn &loc = cg->BuildInstruction(mpldbg::OP_DBG_loc, *o0, *o1); + Operand *o0 = CreateDbgImmOperand(newSrcPos.FileNum()); + Operand *o1 = CreateDbgImmOperand(newSrcPos.LineNum()); + Operand *o2 = CreateDbgImmOperand(newSrcPos.Column()); + Insn &loc = cg->BuildInstruction(mpldbg::OP_DBG_loc, *o0, *o1, *o2); curBB->AppendInsn(loc); - lastSrcLoc = newSrcLoc; + lastSrcPos.UpdateWith(newSrcPos); hasLoc = true; } /* .loc for mpl file, skip if already has .loc from src for this stmt */ - unsigned newMplLoc = cg->GetCGOptions().WithMpl() ? stmt->GetSrcPos().MplLineNum() : 0; - if (newMplLoc != 0 && newMplLoc != lastMplLoc && !hasLoc) { - unsigned fileid = 1; - Operand *o0 = CreateDbgImmOperand(fileid); - Operand *o1 = CreateDbgImmOperand(newMplLoc); + if (cg->GetCGOptions().WithMpl() && !hasLoc && lastMplPos.IsBfMpl(newSrcPos)) { + Operand *o0 = CreateDbgImmOperand(1); + Operand *o1 = CreateDbgImmOperand(newSrcPos.MplLineNum()); Insn &loc = cg->BuildInstruction(mpldbg::OP_DBG_loc, *o0, *o1); curBB->AppendInsn(loc); - lastMplLoc = newMplLoc; + lastMplPos.UpdateWith(newSrcPos); + } + } +} + +void CGFunc::GenerateScopeLabel(StmtNode *stmt, SrcPosition &lastSrcPos) { + /* insert lable for scope begin and end .LScp.1B .LScp.1E */ + MIRFunction &func = GetFunction(); + DebugInfo *dbgInfo = GetMirModule().GetDbgInfo(); + if (cg->GetCGOptions().WithDwarf() && stmt->op != OP_label && stmt->op != OP_comment) { + SrcPosition newSrcPos = stmt->GetSrcPos(); + if (newSrcPos.FileNum() == 0) { + return; + } + std::unordered_set idSet; + idSet.clear(); + dbgInfo->GetCrossScopeId(&func, idSet, false, lastSrcPos, newSrcPos); + for (auto it : idSet) { + Operand *o0 = CreateDbgImmOperand(it); + Operand *o1 = CreateDbgImmOperand(1); + Insn &scope = cg->BuildInstruction(mpldbg::OP_DBG_scope, *o0, *o1); + curBB->AppendInsn(scope); + } + idSet.clear(); + dbgInfo->GetCrossScopeId(&func, idSet, true, lastSrcPos, newSrcPos); + for (auto it : idSet) { + Operand *o0 = CreateDbgImmOperand(it); + Operand *o1 = CreateDbgImmOperand(0); + Insn &scope = cg->BuildInstruction(mpldbg::OP_DBG_scope, *o0, *o1); + curBB->AppendInsn(scope); } + lastSrcPos.UpdateWith(newSrcPos); } } @@ -1671,12 +1699,19 @@ void CGFunc::GenerateInstruction() { /* First Pass: Creates the doubly-linked list of BBs (next,prev) */ volReleaseInsn = nullptr; - unsigned lastSrcLoc = 0; - unsigned lastMplLoc = 0; + SrcPosition lastLocPos = GetFunction().GetScope()->GetRangeLow(); + SrcPosition lastScpPos = GetFunction().GetScope()->GetRangeLow(); + SrcPosition lastMplPos = GetFunction().GetScope()->GetRangeLow(); + SrcPosition lastStmtPos = GetFunction().GetScope()->GetRangeLow(); std::set bbFreqSet; for (StmtNode *stmt = secondStmt; stmt != nullptr; stmt = stmt->GetNext()) { + /* insert Insn for scope begin/end labels */ + if (lastStmtPos.IsBf(stmt->GetSrcPos())) { + GenerateScopeLabel(stmt, lastScpPos); + lastStmtPos = stmt->GetSrcPos(); + } /* insert Insn for .loc before cg for the stmt */ - GenerateLoc(stmt, lastSrcLoc, lastMplLoc); + GenerateLoc(stmt, lastLocPos, lastMplPos); BB *tmpBB = curBB; isVolLoad = false; if (CheckSkipMembarOp(*stmt)) { @@ -1723,9 +1758,6 @@ void CGFunc::GenerateInstruction() { isVolStore = false; } } - if (curBB != tmpBB) { - lastSrcLoc = 0; - } } /* Set lastbb's frequency */ diff --git a/src/mapleall/maple_be/src/cg/emit.cpp b/src/mapleall/maple_be/src/cg/emit.cpp index 779790702d..9991f82a6a 100644 --- a/src/mapleall/maple_be/src/cg/emit.cpp +++ b/src/mapleall/maple_be/src/cg/emit.cpp @@ -3122,6 +3122,9 @@ void Emitter::EmitDIAttrValue(DBGDie *die, DBGDieAttr *attr, DwAt attrName, DwTa CHECK_FATAL(lowpc != nullptr, "lowpc is null in Emitter::EmitDIAttrValue"); EmitLabelRef(lowpc->GetId()); /* maybe deadbeef */ } + } else if (tagName == DW_TAG_lexical_block) { + unsigned i = attr->GetU(); + Emit(".LScp." + std::to_string(i) + "E-.LScp." + std::to_string(i) + "B"); } } else { EmitHexUnsigned(static_cast(static_cast(attr->GetI()))); @@ -3172,6 +3175,9 @@ void Emitter::EmitDIAttrValue(DBGDie *die, DBGDieAttr *attr, DwAt attrName, DwTa const std::string &fnameStr = GlobalTables::GetStrTable().GetStringFromStrIdx(fnameAttr->GetId()); LabelOperand *res = memPool->New(fnameStr.c_str(), labelIdx); res->Emit(*this, nullptr); + } else if (tagName == DW_TAG_lexical_block) { + unsigned i = attr->GetU(); + Emit(".LScp." + std::to_string(i) + "B"); } } else if (attrName == DW_AT_high_pc) { if (tagName == DW_TAG_compile_unit) { diff --git a/src/mapleall/maple_ir/include/debug_info.h b/src/mapleall/maple_ir/include/debug_info.h index d1a56e4bca..616ddfad12 100644 --- a/src/mapleall/maple_ir/include/debug_info.h +++ b/src/mapleall/maple_ir/include/debug_info.h @@ -16,6 +16,7 @@ #ifndef MAPLE_IR_INCLUDE_DBG_INFO_H #define MAPLE_IR_INCLUDE_DBG_INFO_H #include +#include #include "mpl_logging.h" #include "types_def.h" @@ -569,6 +570,11 @@ class DBGAbbrevEntryVec { MapleVector entryVec; }; +struct ScopePos { + uint32 id; + SrcPosition pos; +}; + class DebugInfo { public: DebugInfo(MIRModule *m) @@ -593,6 +599,8 @@ class DebugInfo { pointedPointerMap(std::less(), m->GetMPAllocator().Adapter()), funcLstrIdxDieIdMap(std::less(), m->GetMPAllocator().Adapter()), funcLstrIdxLabIdxMap(std::less(), m->GetMPAllocator().Adapter()), + funcScopeLows(std::less(), m->GetMPAllocator().Adapter()), + funcScopeHighs(std::less(), m->GetMPAllocator().Adapter()), strps(std::less(), m->GetMPAllocator().Adapter()) { /* valid entry starting from index 1 as abbrevid starting from 1 as well */ abbrevVec.push_back(nullptr); @@ -751,6 +759,12 @@ class DebugInfo { void AddAliasDies(MapleMap &aliasMap); void AddScopeDie(MIRScope *scope); + void CollectScopePos(MIRFunction *func, MIRScope *scope); + void GetCrossScopeId(MIRFunction *func, + std::unordered_set &idSet, + bool isLow, + SrcPosition &oldSrcPos, + SrcPosition &newSrcPos); // Functions for calculating the size and offset of each DW_TAG_xxx and DW_AT_xxx void ComputeSizeAndOffsets(); @@ -783,6 +797,10 @@ class DebugInfo { MapleMap pointedPointerMap; MapleMap> funcLstrIdxDieIdMap; MapleMap> funcLstrIdxLabIdxMap; + + MapleMap> funcScopeLows; + MapleMap> funcScopeHighs; + MapleSet strps; std::string varPtrPrefix; }; diff --git a/src/mapleall/maple_ir/include/mir_function.h b/src/mapleall/maple_ir/include/mir_function.h index 3e87313d69..92198ba3d0 100644 --- a/src/mapleall/maple_ir/include/mir_function.h +++ b/src/mapleall/maple_ir/include/mir_function.h @@ -69,8 +69,7 @@ class MIRFunction { MIRFunction(MIRModule *mod, StIdx idx) : module(mod), symbolTableIdx(idx) { - // function scope is of level 0 - scope = module->GetMemPool()->New(module, 0); + scope = module->GetMemPool()->New(module); } ~MIRFunction() = default; diff --git a/src/mapleall/maple_ir/include/mir_scope.h b/src/mapleall/maple_ir/include/mir_scope.h index 846b77a164..06a7c7e342 100644 --- a/src/mapleall/maple_ir/include/mir_scope.h +++ b/src/mapleall/maple_ir/include/mir_scope.h @@ -29,8 +29,7 @@ struct MIRAliasVars { class MIRScope { public: - // default to level 1, function scope is level 0 which is created by MIRFunction constructor - MIRScope(MIRModule *mod, unsigned l = 1); + MIRScope(MIRModule *mod); ~MIRScope() = default; bool NeedEmitAliasInfo() const { @@ -41,10 +40,6 @@ class MIRScope { bool HasJoinScope(const MIRScope *scp1, const MIRScope *scp2) const; bool HasSameRange(const MIRScope *s1, const MIRScope *s2) const; - unsigned GetLevel() const { - return level; - } - unsigned GetId() const { return id; } @@ -88,7 +83,6 @@ class MIRScope { private: MIRModule *module; - unsigned level = 0; unsigned id; std::pair range; // source to maple variable alias diff --git a/src/mapleall/maple_ir/include/src_position.h b/src/mapleall/maple_ir/include/src_position.h index 231aab8ff5..949a4c0389 100644 --- a/src/mapleall/maple_ir/include/src_position.h +++ b/src/mapleall/maple_ir/include/src_position.h @@ -75,17 +75,38 @@ class SrcPosition { u.fileColumn.fileNum = i != 0 ? i : n; } - // as you read: this->IsBfOrEq(pos) - bool IsBfOrEq(SrcPosition pos) const { + void UpdateWith(const SrcPosition pos) { + u.fileColumn.fileNum = pos.FileNum(); + u.fileColumn.column = pos.Column(); + lineNum = pos.LineNum(); + mplLineNum = pos.MplLineNum(); + } + + // as you read: pos0->IsBf(pos) "pos0 Is Before pos" + bool IsBf(SrcPosition pos) const { return (pos.FileNum() == FileNum() && ((LineNum() < pos.LineNum()) || - ((LineNum() == pos.LineNum()) && (Column() <= pos.Column())))); + ((LineNum() == pos.LineNum()) && (Column() < pos.Column())))); + } + + bool IsBfMpl(SrcPosition pos) const { + return (pos.FileNum() == FileNum() && + ((MplLineNum() < pos.MplLineNum()) || + ((MplLineNum() == pos.MplLineNum()) && (Column() < pos.Column())))); } - bool IsSrcPostionEq(SrcPosition pos) const { + bool IsEq(SrcPosition pos) const { return FileNum() == pos.FileNum() && LineNum() == pos.LineNum() && Column() == pos.Column(); } + bool IsBfOrEq(SrcPosition pos) const { + return IsBf(pos) || IsEq(pos); + } + + bool IsEqMpl(SrcPosition pos) const { + return MplLineNum() == pos.MplLineNum(); + } + void DumpLoc(uint32 &lastLineNum, uint16 &lastColumnNum) const { if (FileNum() != 0 && LineNum() != 0) { if (Column() != 0 && (LineNum() != lastLineNum || Column() != lastColumnNum)) { diff --git a/src/mapleall/maple_ir/src/debug_info.cpp b/src/mapleall/maple_ir/src/debug_info.cpp index 1e76e17d3a..69ed11aae3 100644 --- a/src/mapleall/maple_ir/src/debug_info.cpp +++ b/src/mapleall/maple_ir/src/debug_info.cpp @@ -272,10 +272,11 @@ void DebugInfo::AddScopeDie(MIRScope *scope) { return; } - if (scope->GetLevel() != 0) { + MIRFunction *func = GetCurFunction(); + if (scope != func->GetScope()) { DBGDie *die = module->GetMemPool()->New(module, DW_TAG_lexical_block); - die->AddAttr(DW_AT_low_pc, DW_FORM_addr, kDbgDefaultVal); - die->AddAttr(DW_AT_high_pc, DW_FORM_data8, kDbgDefaultVal); + die->AddAttr(DW_AT_low_pc, DW_FORM_addr, scope->GetId()); + die->AddAttr(DW_AT_high_pc, DW_FORM_data8, scope->GetId()); // add die to parent GetParentDie()->AddSubVec(die); @@ -293,7 +294,7 @@ void DebugInfo::AddScopeDie(MIRScope *scope) { } } - if (scope->GetLevel() != 0) { + if (scope != func->GetScope()) { PopParentDie(); } } @@ -327,6 +328,48 @@ void DebugInfo::AddAliasDies(MapleMap &aliasMap) { } } +void DebugInfo::CollectScopePos(MIRFunction *func, MIRScope *scope) { + if (scope != func->GetScope()) { + ScopePos plow; + plow.id = scope->GetId(); + plow.pos = scope->GetRangeLow(); + funcScopeLows[func].push_back(plow); + + ScopePos phigh; + phigh.id = scope->GetId(); + phigh.pos = scope->GetRangeHigh(); + funcScopeHighs[func].push_back(phigh); + } + + if (scope->GetSubScopes().size() > 0) { + for (auto it : scope->GetSubScopes()) { + CollectScopePos(func, it); + } + } +} + +// result is in idSet, +// a set of scope ids which are crossed from oldSrcPos to newSrcPos +void DebugInfo::GetCrossScopeId(MIRFunction *func, + std::unordered_set &idSet, + bool isLow, + SrcPosition &oldSrcPos, + SrcPosition &newSrcPos) { + if (isLow) { + for (auto &it : funcScopeLows[func]) { + if (oldSrcPos.IsBf(it.pos) && (it.pos).IsBfOrEq(newSrcPos)) { + idSet.insert(it.id); + } + } + } else { + for (auto &it : funcScopeHighs[func]) { + if (oldSrcPos.IsBf(it.pos) && (it.pos).IsBfOrEq(newSrcPos)) { + idSet.insert(it.id); + } + } + } +} + void DebugInfo::Finish() { SetupCU(); FillTypeAttrWithDieId(); @@ -675,6 +718,7 @@ DBGDie *DebugInfo::GetOrCreateFuncDefDie(MIRFunction *func, uint32 lnum) { // add scope die AddScopeDie(func->GetScope()); + CollectScopePos(func, func->GetScope()); PopParentDie(); diff --git a/src/mapleall/maple_ir/src/mir_scope.cpp b/src/mapleall/maple_ir/src/mir_scope.cpp index 733a74d82c..ef246d23b9 100644 --- a/src/mapleall/maple_ir/src/mir_scope.cpp +++ b/src/mapleall/maple_ir/src/mir_scope.cpp @@ -20,15 +20,11 @@ namespace maple { static unsigned scopeId = 0; -MIRScope::MIRScope(MIRModule *mod, unsigned l) : module(mod), level(l), id(scopeId++) {} +MIRScope::MIRScope(MIRModule *mod) : module(mod), id(scopeId++) {} // scp is a sub scope // (low (scp.low, scp.high] high] bool MIRScope::IsSubScope(const MIRScope *scp) const { - // special case for function level scope which might not have range specified - if (level == 0) { - return true; - } auto &l = GetRangeLow(); auto &l1 = scp->GetRangeLow(); // allow included file @@ -57,14 +53,7 @@ bool MIRScope::HasSameRange(const MIRScope *scp1, const MIRScope *scp2) const { auto &h1 = scp1->GetRangeHigh(); auto &l2 = scp2->GetRangeLow(); auto &h2 = scp2->GetRangeHigh(); - return l1.IsSrcPostionEq(l2) && h1.IsSrcPostionEq(h2); -} - -void MIRScope::IncLevel() { - level++; - for (auto *s : subScopes) { - s->IncLevel(); - } + return l1.IsEq(l2) && h1.IsEq(h2); } @@ -84,32 +73,24 @@ bool MIRScope::AddScope(MIRScope *scope) { s->GetRangeHigh().DumpLocWithColToString().c_str()); } } - if (this != module->CurFunction()->GetScope()) { - // skip level incremental if this is function-scope, of level 0, - // as scope is aready starting from 1 - scope->IncLevel(); - } subScopes.push_back(scope); return true; } void MIRScope::Dump(int32 indent) const { - int32 ind = static_cast(level != 0); - if (level != 0) { - SrcPosition low = range.first; - SrcPosition high = range.second; - PrintIndentation(indent); - LogInfo::MapleLogger() << "SCOPE <(" << - low.FileNum() << ", " << - low.LineNum() << ", " << - low.Column() << "), (" << - high.FileNum() << ", " << - high.LineNum() << ", " << - high.Column() << ")> {\n"; - } + SrcPosition low = range.first; + SrcPosition high = range.second; + PrintIndentation(indent); + LogInfo::MapleLogger() << "SCOPE <(" << + low.FileNum() << ", " << + low.LineNum() << ", " << + low.Column() << "), (" << + high.FileNum() << ", " << + high.LineNum() << ", " << + high.Column() << ")> {\n"; for (auto it : aliasVarMap) { - PrintIndentation(indent + ind); + PrintIndentation(indent + 1); LogInfo::MapleLogger() << "ALIAS %" << GlobalTables::GetStrTable().GetStringFromStrIdx(it.first) << ((it.second.isLocal) ? " %" : " $") << GlobalTables::GetStrTable().GetStringFromStrIdx(it.second.mplStrIdx) << " "; @@ -122,14 +103,12 @@ void MIRScope::Dump(int32 indent) const { for (auto it : subScopes) { if (it->NeedEmitAliasInfo()) { - it->Dump(indent + ind); + it->Dump(indent + 1); } } - if (level != 0) { - PrintIndentation(indent); - LogInfo::MapleLogger() << "}\n"; - } + PrintIndentation(indent); + LogInfo::MapleLogger() << "}\n"; } void MIRScope::Dump() const { diff --git a/src/mapleall/maple_ir/src/parser.cpp b/src/mapleall/maple_ir/src/parser.cpp index a10e84a1db..83dee0cc39 100644 --- a/src/mapleall/maple_ir/src/parser.cpp +++ b/src/mapleall/maple_ir/src/parser.cpp @@ -2490,14 +2490,9 @@ bool MIRParser::ParseOneScope(MIRScope &scope) { } bool MIRParser::ParseScope(StmtNodePtr &stmt) { - MIRScope *scp = mod.GetMemPool()->New(&mod); + MIRScope *scp = mod.CurFunction()->GetScope(); bool status = ParseOneScope(*scp); - if (status) { - mod.CurFunction()->GetScope()->AddScope(scp); - } else { - delete scp; - } - return true; + return status; } bool MIRParser::ParseOneAlias(GStrIdx &strIdx, MIRAliasVars &aliasVar) { -- Gitee From 740b3894da0d21c7ba5295199c50711fd8374028 Mon Sep 17 00:00:00 2001 From: Wen HU Date: Wed, 29 Jun 2022 14:55:27 -0700 Subject: [PATCH 5/8] check src position validity; set fileNum and column in SrcPosition constructor --- src/mapleall/maple_be/src/cg/cgfunc.cpp | 21 +++++++++++++------- src/mapleall/maple_ir/include/src_position.h | 6 ++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/mapleall/maple_be/src/cg/cgfunc.cpp b/src/mapleall/maple_be/src/cg/cgfunc.cpp index 04de1f0e2b..e9ed041fe3 100644 --- a/src/mapleall/maple_be/src/cg/cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/cgfunc.cpp @@ -1511,7 +1511,10 @@ void CGFunc::GenerateLoc(StmtNode *stmt, SrcPosition &lastSrcPos, SrcPosition &l */ bool hasLoc = false; SrcPosition &newSrcPos = stmt->GetSrcPos(); - if (cg->GetCGOptions().WithSrc() && lastSrcPos.IsBf(newSrcPos)) { + if (!newSrcPos.IsValid()) { + return; + } + if (cg->GetCGOptions().WithSrc() && !lastSrcPos.IsEq(newSrcPos)) { /* .loc for original src file */ Operand *o0 = CreateDbgImmOperand(newSrcPos.FileNum()); Operand *o1 = CreateDbgImmOperand(newSrcPos.LineNum()); @@ -1522,7 +1525,7 @@ void CGFunc::GenerateLoc(StmtNode *stmt, SrcPosition &lastSrcPos, SrcPosition &l hasLoc = true; } /* .loc for mpl file, skip if already has .loc from src for this stmt */ - if (cg->GetCGOptions().WithMpl() && !hasLoc && lastMplPos.IsBfMpl(newSrcPos)) { + if (cg->GetCGOptions().WithMpl() && !hasLoc && !lastMplPos.IsEqMpl(newSrcPos)) { Operand *o0 = CreateDbgImmOperand(1); Operand *o1 = CreateDbgImmOperand(newSrcPos.MplLineNum()); Insn &loc = cg->BuildInstruction(mpldbg::OP_DBG_loc, *o0, *o1); @@ -1538,7 +1541,7 @@ void CGFunc::GenerateScopeLabel(StmtNode *stmt, SrcPosition &lastSrcPos) { DebugInfo *dbgInfo = GetMirModule().GetDbgInfo(); if (cg->GetCGOptions().WithDwarf() && stmt->op != OP_label && stmt->op != OP_comment) { SrcPosition newSrcPos = stmt->GetSrcPos(); - if (newSrcPos.FileNum() == 0) { + if (!newSrcPos.IsValid()) { return; } std::unordered_set idSet; @@ -1699,10 +1702,14 @@ void CGFunc::GenerateInstruction() { /* First Pass: Creates the doubly-linked list of BBs (next,prev) */ volReleaseInsn = nullptr; - SrcPosition lastLocPos = GetFunction().GetScope()->GetRangeLow(); - SrcPosition lastScpPos = GetFunction().GetScope()->GetRangeLow(); - SrcPosition lastMplPos = GetFunction().GetScope()->GetRangeLow(); - SrcPosition lastStmtPos = GetFunction().GetScope()->GetRangeLow(); + SrcPosition pos = GetFunction().GetScope()->GetRangeLow(); + if (!pos.IsValid()) { + pos = GetFunction().GetSrcPosition(); + } + SrcPosition lastScpPos = pos; + SrcPosition lastStmtPos = pos; + SrcPosition lastLocPos = SrcPosition(); + SrcPosition lastMplPos = SrcPosition(); std::set bbFreqSet; for (StmtNode *stmt = secondStmt; stmt != nullptr; stmt = stmt->GetNext()) { /* insert Insn for scope begin/end labels */ diff --git a/src/mapleall/maple_ir/include/src_position.h b/src/mapleall/maple_ir/include/src_position.h index 949a4c0389..e9ee6ede0b 100644 --- a/src/mapleall/maple_ir/include/src_position.h +++ b/src/mapleall/maple_ir/include/src_position.h @@ -21,6 +21,8 @@ namespace maple { class SrcPosition { public: SrcPosition() : lineNum(0), mplLineNum(0) { + u.fileColumn.fileNum = 0; + u.fileColumn.column = 0; u.word0 = 0; } @@ -107,6 +109,10 @@ class SrcPosition { return MplLineNum() == pos.MplLineNum(); } + bool IsValid() const { + return FileNum() != 0; + } + void DumpLoc(uint32 &lastLineNum, uint16 &lastColumnNum) const { if (FileNum() != 0 && LineNum() != 0) { if (Column() != 0 && (LineNum() != lastLineNum || Column() != lastColumnNum)) { -- Gitee From b61bc2b6afee647d542f47716fd877d39f1bcf7f Mon Sep 17 00:00:00 2001 From: Wen HU Date: Thu, 30 Jun 2022 15:07:16 -0700 Subject: [PATCH 6/8] fix while stmt scpoe end label issue --- src/mapleall/maple_ir/include/mir_scope.h | 3 ++- src/mapleall/maple_ir/src/mir_scope.cpp | 13 +++++++++++++ src/mapleall/maple_me/src/pme_mir_lower.cpp | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/mapleall/maple_ir/include/mir_scope.h b/src/mapleall/maple_ir/include/mir_scope.h index 06a7c7e342..49874f47f4 100644 --- a/src/mapleall/maple_ir/include/mir_scope.h +++ b/src/mapleall/maple_ir/include/mir_scope.h @@ -76,7 +76,8 @@ class MIRScope { return subScopes; } - void IncLevel(); + SrcPosition GetScopeEndPos(SrcPosition pos); + bool AddScope(MIRScope *scope); void Dump(int32 indent) const; void Dump() const; diff --git a/src/mapleall/maple_ir/src/mir_scope.cpp b/src/mapleall/maple_ir/src/mir_scope.cpp index ef246d23b9..eb2c3a5b1f 100644 --- a/src/mapleall/maple_ir/src/mir_scope.cpp +++ b/src/mapleall/maple_ir/src/mir_scope.cpp @@ -56,6 +56,19 @@ bool MIRScope::HasSameRange(const MIRScope *scp1, const MIRScope *scp2) const { return l1.IsEq(l2) && h1.IsEq(h2); } +SrcPosition MIRScope::GetScopeEndPos(SrcPosition pos) { + if (pos.IsEq(GetRangeLow())) { + return GetRangeHigh(); + } + SrcPosition result = SrcPosition(); + for (auto *s : subScopes) { + result = s->GetScopeEndPos(pos); + if (result.IsValid()) { + return result; + } + } + return result; +} bool MIRScope::AddScope(MIRScope *scope) { // check first if it is valid with parent scope and sibling sub scopes diff --git a/src/mapleall/maple_me/src/pme_mir_lower.cpp b/src/mapleall/maple_me/src/pme_mir_lower.cpp index 7b5eafec9e..6c1a5ab338 100644 --- a/src/mapleall/maple_me/src/pme_mir_lower.cpp +++ b/src/mapleall/maple_me/src/pme_mir_lower.cpp @@ -51,6 +51,8 @@ BlockNode *PreMeMIRLower::LowerWhileStmt(WhileStmtNode &whilestmt) { CHECK_FATAL(whilestmt.GetBody(), "null ptr check"); blk->AppendStatementsFromBlock(*whilestmt.GetBody()); GotoNode *whilegotonode = mirbuilder->CreateStmtGoto(OP_goto, whilelblidx); + SrcPosition pos = func->GetMirFunc()->GetScope()->GetScopeEndPos(whilestmt.GetSrcPos()); + whilegotonode->SetSrcPos(pos); if (GetFuncProfData() && blk->GetLast()) { ASSERT(GetFuncProfData()->GetStmtFreq(blk->GetLast()->GetStmtID()) >= 0, "last stmt of while body should has freq"); -- Gitee From 3433cbef1c3a7409a4fcc1efb3572bd09be6b97f Mon Sep 17 00:00:00 2001 From: Wen HU Date: Tue, 5 Jul 2022 17:44:37 -0700 Subject: [PATCH 7/8] handle block scope end labels --- src/mapleall/maple_be/include/cg/cgfunc.h | 4 +- src/mapleall/maple_be/src/cg/cgfunc.cpp | 56 ++++++++++++++++---- src/mapleall/maple_ir/include/mir_function.h | 4 +- src/mapleall/maple_ir/include/mir_scope.h | 22 ++++++-- src/mapleall/maple_ir/include/src_position.h | 13 +++-- src/mapleall/maple_ir/src/debug_info.cpp | 7 ++- src/mapleall/maple_ir/src/mir_lower.cpp | 1 + src/mapleall/maple_ir/src/mir_parser.cpp | 25 +++++++-- src/mapleall/maple_ir/src/mir_scope.cpp | 29 +++++++--- src/mapleall/maple_ir/src/parser.cpp | 23 ++++++-- src/mapleall/maple_me/src/pme_mir_lower.cpp | 17 +++++- 11 files changed, 160 insertions(+), 41 deletions(-) diff --git a/src/mapleall/maple_be/include/cg/cgfunc.h b/src/mapleall/maple_be/include/cg/cgfunc.h index 92a1d74e2e..8445c3861a 100644 --- a/src/mapleall/maple_be/include/cg/cgfunc.h +++ b/src/mapleall/maple_be/include/cg/cgfunc.h @@ -162,12 +162,13 @@ class CGFunc { LmbcFormalParamInfo *GetLmbcFormalParamInfo(uint32 offset); virtual void LmbcGenSaveSpForAlloca() = 0; void GenerateLoc(StmtNode *stmt, SrcPosition &lastSrcPos, SrcPosition &lastMplPos); - void GenerateScopeLabel(StmtNode *stmt, SrcPosition &lastSrcPos); + void GenerateScopeLabel(StmtNode *stmt, SrcPosition &lastSrcPos, bool &posDone); int32 GetFreqFromStmt(uint32 stmtId); void GenerateInstruction(); bool MemBarOpt(const StmtNode &membar); void UpdateCallBBFrequency(); void HandleFunction(); + void MakeupScopeLabels(BB &bb); void ProcessExitBBVec(); void AddCommonExitBB(); virtual void MergeReturn() = 0; @@ -1272,6 +1273,7 @@ class CGFunc { #endif /* TARGARM32 */ MapleVector loops; MapleVector lmbcParamVec; + std::set scpIdSet; int32 lmbcIntArgs = 0; int32 lmbcFpArgs = 0; uint32 lmbcTotalArgs = 0; diff --git a/src/mapleall/maple_be/src/cg/cgfunc.cpp b/src/mapleall/maple_be/src/cg/cgfunc.cpp index e9ed041fe3..205e9f2f30 100644 --- a/src/mapleall/maple_be/src/cg/cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/cgfunc.cpp @@ -1535,33 +1535,49 @@ void CGFunc::GenerateLoc(StmtNode *stmt, SrcPosition &lastSrcPos, SrcPosition &l } } -void CGFunc::GenerateScopeLabel(StmtNode *stmt, SrcPosition &lastSrcPos) { +void CGFunc::GenerateScopeLabel(StmtNode *stmt, SrcPosition &lastSrcPos, bool &posDone) { /* insert lable for scope begin and end .LScp.1B .LScp.1E */ MIRFunction &func = GetFunction(); DebugInfo *dbgInfo = GetMirModule().GetDbgInfo(); - if (cg->GetCGOptions().WithDwarf() && stmt->op != OP_label && stmt->op != OP_comment) { + if (cg->GetCGOptions().WithDwarf() && stmt->op != OP_comment) { SrcPosition newSrcPos = stmt->GetSrcPos(); if (!newSrcPos.IsValid()) { return; } - std::unordered_set idSet; - idSet.clear(); - dbgInfo->GetCrossScopeId(&func, idSet, false, lastSrcPos, newSrcPos); - for (auto it : idSet) { + // check if newSrcPos is done + if (posDone && lastSrcPos.IsEq(newSrcPos)) { + return; + } + std::unordered_set idSetB; + std::unordered_set idSetE; + idSetB.clear(); + idSetE.clear(); + dbgInfo->GetCrossScopeId(&func, idSetB, true, lastSrcPos, newSrcPos); + dbgInfo->GetCrossScopeId(&func, idSetE, false, lastSrcPos, newSrcPos); + for (auto it : idSetE) { + // skip if begin label is not in yet + if (scpIdSet.find(it) == scpIdSet.end()) { + continue; + } Operand *o0 = CreateDbgImmOperand(it); Operand *o1 = CreateDbgImmOperand(1); Insn &scope = cg->BuildInstruction(mpldbg::OP_DBG_scope, *o0, *o1); curBB->AppendInsn(scope); + scpIdSet.erase(it); } - idSet.clear(); - dbgInfo->GetCrossScopeId(&func, idSet, true, lastSrcPos, newSrcPos); - for (auto it : idSet) { + for (auto it : idSetB) { + // skip if begin label is already in + if (scpIdSet.find(it) != scpIdSet.end()) { + continue; + } Operand *o0 = CreateDbgImmOperand(it); Operand *o1 = CreateDbgImmOperand(0); Insn &scope = cg->BuildInstruction(mpldbg::OP_DBG_scope, *o0, *o1); curBB->AppendInsn(scope); + scpIdSet.insert(it); } lastSrcPos.UpdateWith(newSrcPos); + posDone = false; } } @@ -1711,10 +1727,12 @@ void CGFunc::GenerateInstruction() { SrcPosition lastLocPos = SrcPosition(); SrcPosition lastMplPos = SrcPosition(); std::set bbFreqSet; + bool posDone = false; + scpIdSet.clear(); for (StmtNode *stmt = secondStmt; stmt != nullptr; stmt = stmt->GetNext()) { /* insert Insn for scope begin/end labels */ - if (lastStmtPos.IsBf(stmt->GetSrcPos())) { - GenerateScopeLabel(stmt, lastScpPos); + if (lastStmtPos.IsBfOrEq(stmt->GetSrcPos())) { + GenerateScopeLabel(stmt, lastScpPos, posDone); lastStmtPos = stmt->GetSrcPos(); } /* insert Insn for .loc before cg for the stmt */ @@ -2006,12 +2024,26 @@ bool CGFunc::MemBarOpt(const StmtNode &membar) { return stmt->GetOpCode() == OP_membarrelease; } +void CGFunc::MakeupScopeLabels(BB &bb) { + /* insert leftover scope-end labels */ + if (!scpIdSet.empty()) { + std::set::reverse_iterator rit; + for (rit=scpIdSet.rbegin(); rit != scpIdSet.rend(); ++rit) { + Operand *o0 = CreateDbgImmOperand(*rit); + Operand *o1 = CreateDbgImmOperand(1); + Insn &scope = cg->BuildInstruction(mpldbg::OP_DBG_scope, *o0, *o1); + bb.AppendInsn(scope); + } + } +} + void CGFunc::ProcessExitBBVec() { if (exitBBVec.empty()) { LabelIdx newLabelIdx = CreateLabel(); BB *retBB = CreateNewBB(newLabelIdx, cleanupBB->IsUnreachable(), BB::kBBReturn, cleanupBB->GetFrequency()); cleanupBB->PrependBB(*retBB); exitBBVec.emplace_back(retBB); + MakeupScopeLabels(*retBB); return; } /* split an empty exitBB */ @@ -2034,7 +2066,9 @@ void CGFunc::ProcessExitBBVec() { LabelIdx newLabelIdx = CreateLabel(); bb->AddLabel(newLabelIdx); lab2BBMap[newLabelIdx] = bb; + curBB = bb; } + MakeupScopeLabels(*bb); } void CGFunc::AddCommonExitBB() { diff --git a/src/mapleall/maple_ir/include/mir_function.h b/src/mapleall/maple_ir/include/mir_function.h index 92198ba3d0..c60e529308 100644 --- a/src/mapleall/maple_ir/include/mir_function.h +++ b/src/mapleall/maple_ir/include/mir_function.h @@ -69,7 +69,7 @@ class MIRFunction { MIRFunction(MIRModule *mod, StIdx idx) : module(mod), symbolTableIdx(idx) { - scope = module->GetMemPool()->New(module); + scope = module->GetMemPool()->New(module, this); } ~MIRFunction() = default; @@ -727,7 +727,7 @@ class MIRFunction { } bool NeedEmitAliasInfo() const { - return scope->NeedEmitAliasInfo(); + return !scope->IsEmpty(); } MapleMap &GetAliasVarMap() { diff --git a/src/mapleall/maple_ir/include/mir_scope.h b/src/mapleall/maple_ir/include/mir_scope.h index 49874f47f4..234003ed2a 100644 --- a/src/mapleall/maple_ir/include/mir_scope.h +++ b/src/mapleall/maple_ir/include/mir_scope.h @@ -14,6 +14,7 @@ */ #ifndef MAPLE_IR_INCLUDE_MIR_SCOPE_H #define MAPLE_IR_INCLUDE_MIR_SCOPE_H +#include #include "mir_module.h" #include "mir_type.h" #include "src_position.h" @@ -29,11 +30,11 @@ struct MIRAliasVars { class MIRScope { public: - MIRScope(MIRModule *mod); + MIRScope(MIRModule *mod, MIRFunction *f = nullptr); ~MIRScope() = default; - bool NeedEmitAliasInfo() const { - return aliasVarMap.size() != 0 || subScopes.size() != 0; + bool IsEmpty() const { + return aliasVarMap.size() == 0 && subScopes.size() == 0; } bool IsSubScope(const MIRScope *scp) const; @@ -44,6 +45,10 @@ class MIRScope { return id; } + void SetId(unsigned i) { + id = i; + } + const SrcPosition &GetRangeLow() const { return range.first; } @@ -76,20 +81,31 @@ class MIRScope { return subScopes; } + void AddTuple(SrcPosition pos, SrcPosition posB, SrcPosition posE) { + if (pos.LineNum() == 0 || posB.LineNum() == 0 || posE.LineNum() == 0) { + return; + } + std::tuple t(pos,posB,posE); + BlkSrcPos.push_back(t); + } + SrcPosition GetScopeEndPos(SrcPosition pos); bool AddScope(MIRScope *scope); + void Dump(int32 indent) const; void Dump() const; private: MIRModule *module; + MIRFunction *func; unsigned id; std::pair range; // source to maple variable alias MapleMap aliasVarMap { module->GetMPAllocator().Adapter() }; // subscopes' range should be disjoint MapleVector subScopes { module->GetMPAllocator().Adapter() }; + std::vector> BlkSrcPos; }; } // namespace maple #endif // MAPLE_IR_INCLUDE_MIR_SCOPE_H diff --git a/src/mapleall/maple_ir/include/src_position.h b/src/mapleall/maple_ir/include/src_position.h index e9ee6ede0b..db56418a88 100644 --- a/src/mapleall/maple_ir/include/src_position.h +++ b/src/mapleall/maple_ir/include/src_position.h @@ -25,6 +25,11 @@ class SrcPosition { u.fileColumn.column = 0; u.word0 = 0; } + explicit SrcPosition(uint32 fnum, uint32 lnum, uint32 cnum, uint32 mlnum) + : lineNum(lnum), mplLineNum(mlnum) { + u.fileColumn.fileNum = fnum; + u.fileColumn.column = cnum; + } virtual ~SrcPosition() = default; @@ -116,21 +121,21 @@ class SrcPosition { void DumpLoc(uint32 &lastLineNum, uint16 &lastColumnNum) const { if (FileNum() != 0 && LineNum() != 0) { if (Column() != 0 && (LineNum() != lastLineNum || Column() != lastColumnNum)) { - DumpLocWithCol(); + Dump(); lastLineNum = LineNum(); lastColumnNum = Column(); } else if (LineNum() != lastLineNum) { - DumpLocWithLine(); + DumpLine(); lastLineNum = LineNum(); } } } - void DumpLocWithLine() const { + void DumpLine() const { LogInfo::MapleLogger() << "LOC " << FileNum() << " " << LineNum() << '\n'; } - void DumpLocWithCol() const { + void Dump() const { LogInfo::MapleLogger() << "LOC " << FileNum() << " " << LineNum() << " " << Column() << '\n'; } diff --git a/src/mapleall/maple_ir/src/debug_info.cpp b/src/mapleall/maple_ir/src/debug_info.cpp index 69ed11aae3..f95293ceb4 100644 --- a/src/mapleall/maple_ir/src/debug_info.cpp +++ b/src/mapleall/maple_ir/src/debug_info.cpp @@ -268,7 +268,7 @@ void DebugInfo::SetupCU() { } void DebugInfo::AddScopeDie(MIRScope *scope) { - if (!scope->NeedEmitAliasInfo()) { + if (scope->IsEmpty()) { return; } @@ -362,8 +362,11 @@ void DebugInfo::GetCrossScopeId(MIRFunction *func, } } } else { + if (oldSrcPos.IsEq(newSrcPos)) { + return; + } for (auto &it : funcScopeHighs[func]) { - if (oldSrcPos.IsBf(it.pos) && (it.pos).IsBfOrEq(newSrcPos)) { + if (oldSrcPos.IsBfOrEq(it.pos) && (it.pos).IsBf(newSrcPos)) { idSet.insert(it.id); } } diff --git a/src/mapleall/maple_ir/src/mir_lower.cpp b/src/mapleall/maple_ir/src/mir_lower.cpp index ce085e6d1a..30e318f630 100644 --- a/src/mapleall/maple_ir/src/mir_lower.cpp +++ b/src/mapleall/maple_ir/src/mir_lower.cpp @@ -512,6 +512,7 @@ BlockNode *MIRLower::LowerDowhileStmt(WhileStmtNode &doWhileStmt) { BlockNode *MIRLower::LowerBlock(BlockNode &block) { auto *newBlock = mirModule.CurFuncCodeMemPool()->New(); + newBlock->SetSrcPos(block.GetSrcPos()); BlockNode *tmp = nullptr; if (block.GetFirst() == nullptr) { newBlock->SetStmtID(block.GetStmtID()); // keep original block stmtid diff --git a/src/mapleall/maple_ir/src/mir_parser.cpp b/src/mapleall/maple_ir/src/mir_parser.cpp index 407e4e6c01..fc6364dfde 100755 --- a/src/mapleall/maple_ir/src/mir_parser.cpp +++ b/src/mapleall/maple_ir/src/mir_parser.cpp @@ -423,6 +423,7 @@ bool MIRParser::ParseStmtIf(StmtNodePtr &stmt) { return false; } ifStmt->SetThenPart(thenBlock); + BlockNode *elseBlock = nullptr; if (lexer.GetTokenKind() == TK_else) { // has else part @@ -1861,19 +1862,22 @@ bool MIRParser::ParseStatement(StmtNodePtr &stmt) { /* parse the statements enclosed by { and } */ bool MIRParser::ParseStmtBlock(BlockNodePtr &blk) { + bool retval = false; if (lexer.GetTokenKind() != TK_lbrace) { Error("expect { for func body but get "); return false; } + SrcPosition posB(lastFileNum, lastLineNum, lastColumnNum, lexer.GetLineNum()); blk = mod.CurFuncCodeMemPool()->New(); MIRFunction *fn = mod.CurFunction(); paramCurrFuncForParseStmtBlock = fn; lexer.NextToken(); + bool first = true; // Insert _mcount for PI. if (mod.GetWithProfileInfo()) { StmtNode *stmtt = nullptr; if (!ParseStmtCallMcount(stmtt)) { - return false; + goto tupleSetup; } blk->AddStatement(stmtt); } @@ -1882,14 +1886,20 @@ bool MIRParser::ParseStmtBlock(BlockNodePtr &blk) { // calculate the mpl file line number mplNum here to get accurate result uint32 mplNum = lexer.GetLineNum(); if (IsStatement(stmtTk)) { + ParseStmtBlockForSeenComment(blk, mplNum); StmtNode *stmt = nullptr; if (!ParseStatement(stmt)) { Error("ParseStmtBlock failed when parsing a statement"); - return false; + goto tupleSetup; } if (stmt != nullptr) { // stmt is nullptr if it is a LOC blk->AddStatement(stmt); + // set blk src position + if (first) { + blk->SetSrcPos(stmt->GetSrcPos()); + first = false; + } } } else { std::map::iterator itFuncPtr = funcPtrMapForParseStmtBlock.find(stmtTk); @@ -1897,18 +1907,23 @@ bool MIRParser::ParseStmtBlock(BlockNodePtr &blk) { if (stmtTk == TK_rbrace) { ParseStmtBlockForSeenComment(blk, mplNum); lexer.NextToken(); - return true; + retval = true; + goto tupleSetup; } else { Error("expect } or var or statement for func body but get "); - return false; + goto tupleSetup; } } else { if (!(this->*(itFuncPtr->second))()) { - return false; + goto tupleSetup; } } } } +tupleSetup: + SrcPosition posE(lastFileNum, lastLineNum, lastColumnNum, lexer.GetLineNum()); + mod.CurFunction()->GetScope()->AddTuple(blk->GetSrcPos(), posB, posE); + return retval; } void MIRParser::ParseStmtBlockForSeenComment(BlockNodePtr blk, uint32 mplNum) { diff --git a/src/mapleall/maple_ir/src/mir_scope.cpp b/src/mapleall/maple_ir/src/mir_scope.cpp index eb2c3a5b1f..8f30c2fc5c 100644 --- a/src/mapleall/maple_ir/src/mir_scope.cpp +++ b/src/mapleall/maple_ir/src/mir_scope.cpp @@ -18,9 +18,10 @@ namespace maple { -static unsigned scopeId = 0; +static unsigned scopeId = 1; -MIRScope::MIRScope(MIRModule *mod) : module(mod), id(scopeId++) {} +MIRScope::MIRScope(MIRModule *mod, MIRFunction *f) + : module(mod), func(f), id(scopeId++) {} // scp is a sub scope // (low (scp.low, scp.high] high] @@ -57,8 +58,23 @@ bool MIRScope::HasSameRange(const MIRScope *scp1, const MIRScope *scp2) const { } SrcPosition MIRScope::GetScopeEndPos(SrcPosition pos) { - if (pos.IsEq(GetRangeLow())) { - return GetRangeHigh(); + SrcPosition low = GetRangeLow(); + SrcPosition high = GetRangeHigh(); + if (pos.IsEq(low)) { + return high; + } + for (auto it : func->GetScope()->BlkSrcPos) { + SrcPosition p = std::get<0>(it); + SrcPosition pB = std::get<1>(it); + SrcPosition pE = std::get<2>(it); + if (pos.IsEq(p)) { + // pB < low < p < pE < high + if (pB.IsBfOrEq(low) && + low.IsBfOrEq(p) && + pE.IsBfOrEq(high)) { + return high; + } + } } SrcPosition result = SrcPosition(); for (auto *s : subScopes) { @@ -94,7 +110,8 @@ void MIRScope::Dump(int32 indent) const { SrcPosition low = range.first; SrcPosition high = range.second; PrintIndentation(indent); - LogInfo::MapleLogger() << "SCOPE <(" << + LogInfo::MapleLogger() << "SCOPE " << + id << " <(" << low.FileNum() << ", " << low.LineNum() << ", " << low.Column() << "), (" << @@ -115,7 +132,7 @@ void MIRScope::Dump(int32 indent) const { } for (auto it : subScopes) { - if (it->NeedEmitAliasInfo()) { + if (!it->IsEmpty()) { it->Dump(indent + 1); } } diff --git a/src/mapleall/maple_ir/src/parser.cpp b/src/mapleall/maple_ir/src/parser.cpp index 83dee0cc39..efbc2297bd 100644 --- a/src/mapleall/maple_ir/src/parser.cpp +++ b/src/mapleall/maple_ir/src/parser.cpp @@ -2420,6 +2420,11 @@ bool MIRParser::ParseOneScope(MIRScope &scope) { return false; } nameTk = lexer.NextToken(); + if (nameTk == TK_intconst) { + uint32 i = static_cast(lexer.GetTheIntVal()); + scope.SetId(i); + nameTk = lexer.NextToken(); + } if (nameTk != TK_langle) { Error("expect < in SCOPE but get "); return false; @@ -2464,12 +2469,20 @@ bool MIRParser::ParseOneScope(MIRScope &scope) { break; } case TK_SCOPE: { - MIRScope *scp = mod.GetMemPool()->New(&mod); + MIRScope *scp = mod.GetMemPool()->New(&mod, mod.CurFunction()); status = ParseOneScope(*scp); - if (status) { - scope.AddScope(scp); - } else { - delete scp; + if (status && !scp->IsEmpty()) { + if (scope.GetRangeLow().IsEq(scp->GetRangeLow()) && + scope.GetRangeHigh().IsEq(scp->GetRangeHigh())) { + for (auto it : scp->GetAliasVarMap()) { + scope.AddAliasVarMap(it.first, it.second); + } + for (auto it : scp->GetSubScopes()) { + scope.AddScope(it); + } + } else { + scope.AddScope(scp); + } } break; } diff --git a/src/mapleall/maple_me/src/pme_mir_lower.cpp b/src/mapleall/maple_me/src/pme_mir_lower.cpp index 6c1a5ab338..1b46c4f6d8 100644 --- a/src/mapleall/maple_me/src/pme_mir_lower.cpp +++ b/src/mapleall/maple_me/src/pme_mir_lower.cpp @@ -51,8 +51,6 @@ BlockNode *PreMeMIRLower::LowerWhileStmt(WhileStmtNode &whilestmt) { CHECK_FATAL(whilestmt.GetBody(), "null ptr check"); blk->AppendStatementsFromBlock(*whilestmt.GetBody()); GotoNode *whilegotonode = mirbuilder->CreateStmtGoto(OP_goto, whilelblidx); - SrcPosition pos = func->GetMirFunc()->GetScope()->GetScopeEndPos(whilestmt.GetSrcPos()); - whilegotonode->SetSrcPos(pos); if (GetFuncProfData() && blk->GetLast()) { ASSERT(GetFuncProfData()->GetStmtFreq(blk->GetLast()->GetStmtID()) >= 0, "last stmt of while body should has freq"); @@ -66,6 +64,11 @@ BlockNode *PreMeMIRLower::LowerWhileStmt(WhileStmtNode &whilestmt) { LabelNode *endlblstmt = mirModule.CurFuncCodeMemPool()->New(); endlblstmt->SetLabelIdx(endlblidx); brfalsestmt->SetOffset(endlblidx); + SrcPosition pos = func->GetMirFunc()->GetScope()->GetScopeEndPos(whilestmt.GetBody()->GetSrcPos()); + if (!pos.IsValid()) { + pos = func->GetMirFunc()->GetScope()->GetScopeEndPos(whilestmt.GetSrcPos()); + } + endlblstmt->SetSrcPos(pos); blk->AddStatement(endlblstmt); if (GetFuncProfData()) { int64_t freq = GetFuncProfData()->GetStmtFreq(whilestmt.GetStmtID()) - @@ -145,6 +148,8 @@ BlockNode *PreMeMIRLower::LowerIfStmt(IfStmtNode &ifstmt, bool recursive) { if (canRaiseBack) { preMeFunc->label2IfInfo.insert(std::make_pair(endlabelidx, ifInfo)); } + SrcPosition pos = func->GetMirFunc()->GetScope()->GetScopeEndPos(ifstmt.GetThenPart()->GetSrcPos()); + labstmt->SetSrcPos(pos); blk->AddStatement(labstmt); // set stmtfreqs if (GetFuncProfData()) { @@ -180,6 +185,8 @@ BlockNode *PreMeMIRLower::LowerIfStmt(IfStmtNode &ifstmt, bool recursive) { if (canRaiseBack) { preMeFunc->label2IfInfo.insert(std::make_pair(endlabelidx, ifInfo)); } + SrcPosition pos = func->GetMirFunc()->GetScope()->GetScopeEndPos(ifstmt.GetElsePart()->GetSrcPos()); + labstmt->SetSrcPos(pos); blk->AddStatement(labstmt); // set stmtfreqs if (GetFuncProfData()) { @@ -236,6 +243,8 @@ BlockNode *PreMeMIRLower::LowerIfStmt(IfStmtNode &ifstmt, bool recursive) { LabelNode *labstmt = mirModule.CurFuncCodeMemPool()->New(); labstmt->SetLabelIdx(elselabelidx); + SrcPosition pos = func->GetMirFunc()->GetScope()->GetScopeEndPos(ifstmt.GetThenPart()->GetSrcPos()); + labstmt->SetSrcPos(pos); blk->AddStatement(labstmt); blk->AppendStatementsFromBlock(*ifstmt.GetElsePart()); @@ -243,6 +252,8 @@ BlockNode *PreMeMIRLower::LowerIfStmt(IfStmtNode &ifstmt, bool recursive) { if (fallthru_from_then) { labstmt = mirModule.CurFuncCodeMemPool()->New(); labstmt->SetLabelIdx(endlabelidx); + SrcPosition pos = func->GetMirFunc()->GetScope()->GetScopeEndPos(ifstmt.GetElsePart()->GetSrcPos()); + labstmt->SetSrcPos(pos); blk->AddStatement(labstmt); // set stmtfreqs if (GetFuncProfData()) { @@ -255,6 +266,8 @@ BlockNode *PreMeMIRLower::LowerIfStmt(IfStmtNode &ifstmt, bool recursive) { preMeFunc->SetIfLabelCreatedByPreMe(endlabelidx); } LabelNode *endlabelnode = mirbuilder->CreateStmtLabel(endlabelidx); + SrcPosition pos = func->GetMirFunc()->GetScope()->GetScopeEndPos(ifstmt.GetElsePart()->GetSrcPos()); + endlabelnode->SetSrcPos(pos); blk->AddStatement(endlabelnode); // set stmtfreqs if (GetFuncProfData()) { -- Gitee From 75ad7521d6c2500bc42a04fbed9f771c623a53bf Mon Sep 17 00:00:00 2001 From: Wen HU Date: Tue, 5 Jul 2022 19:02:18 -0700 Subject: [PATCH 8/8] create DBGDie for extern var --- src/mapleall/maple_ir/src/debug_info.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mapleall/maple_ir/src/debug_info.cpp b/src/mapleall/maple_ir/src/debug_info.cpp index f95293ceb4..5c0fd8b838 100644 --- a/src/mapleall/maple_ir/src/debug_info.cpp +++ b/src/mapleall/maple_ir/src/debug_info.cpp @@ -414,8 +414,7 @@ void DebugInfo::BuildDebugInfo() { for (size_t i = 0; i < GlobalTables::GetGsymTable().GetSymbolTableSize(); ++i) { MIRSymbol *mirSymbol = GlobalTables::GetGsymTable().GetSymbolFromStidx(static_cast(i)); - if (mirSymbol == nullptr || mirSymbol->IsDeleted() || mirSymbol->GetStorageClass() == kScUnused || - mirSymbol->GetStorageClass() == kScExtern) { + if (mirSymbol == nullptr || mirSymbol->IsDeleted() || mirSymbol->GetStorageClass() == kScUnused) { continue; } if (module->IsCModule() && mirSymbol->IsGlobal() && mirSymbol->IsVar()) { -- Gitee