diff --git a/src/mapleall/maple_me/src/irmap_emit.cpp b/src/mapleall/maple_me/src/irmap_emit.cpp index cfbb04f203667d742ca609c6570829bcd9af5172..8b82ec408b1bfaab26fa8e9921e281798cfe5db4 100644 --- a/src/mapleall/maple_me/src/irmap_emit.cpp +++ b/src/mapleall/maple_me/src/irmap_emit.cpp @@ -572,12 +572,16 @@ StmtNode &AssertMeStmt::EmitStmt(SSATab &ssaTab) { } void BB::EmitBB(SSATab &ssaTab, BlockNode &curblk, bool needAnotherPass) { + StmtNode *bbFirstStmt = nullptr; + StmtNode *bbLastStmt = nullptr; // emit head. label LabelIdx labidx = GetBBLabel(); if (labidx != 0) { LabelNode *lbnode = ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(); lbnode->SetLabelIdx(labidx); curblk.AddStatement(lbnode); + bbFirstStmt = lbnode; + bbLastStmt = lbnode; } auto &meStmts = GetMeStmts(); for (auto &meStmt : meStmts) { @@ -588,16 +592,28 @@ void BB::EmitBB(SSATab &ssaTab, BlockNode &curblk, bool needAnotherPass) { meStmt.SetOp(OP_icallassigned); } } - StmtNode &stmt = meStmt.EmitStmt(ssaTab); - curblk.AddStatement(&stmt); + StmtNode *stmt = &meStmt.EmitStmt(ssaTab); + curblk.AddStatement(stmt); + if (bbFirstStmt == nullptr) { + bbFirstStmt = stmt; + } + bbLastStmt = stmt; + if (&meStmt == &(meStmts.back())) { - ssaTab.GetModule().CurFunction()->SetFreqMap(stmt.GetStmtID(), GetFrequency()); + ssaTab.GetModule().CurFunction()->SetFreqMap(stmt->GetStmtID(), GetFrequency()); } } if (GetAttributes(kBBAttrIsTryEnd)) { // generate op_endtry StmtNode *endtry = ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(OP_endtry); curblk.AddStatement(endtry); + if (bbFirstStmt == nullptr) { + bbFirstStmt = endtry; + } + bbLastStmt = endtry; } + stmtNodeList.set_first(bbFirstStmt); + stmtNodeList.set_last(bbLastStmt); } + } // namespace maple diff --git a/src/mapleall/maple_util/include/ptr_list_ref.h b/src/mapleall/maple_util/include/ptr_list_ref.h index 9b5a68bb67dcead1b7d113f68f407581fc8bada9..c7791be6f1af6033962c238c02e7c1e4983a9a96 100644 --- a/src/mapleall/maple_util/include/ptr_list_ref.h +++ b/src/mapleall/maple_util/include/ptr_list_ref.h @@ -437,6 +437,14 @@ class PtrListRef { return this->erase(const_iterator(_Where)); } + void set_first(T *f) { + this->first = f; + } + + void set_last(T *f) { + this->last = f; + } + private: T *first = nullptr; T *last = nullptr;