From 295fda7c995013b4826ac4c581ed3ffddff6d46a Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Thu, 8 Jul 2021 01:29:35 -0700 Subject: [PATCH 1/2] be lowerer converts expression operands of asm to temps --- src/mapleall/maple_be/include/be/lower.h | 2 ++ src/mapleall/maple_be/src/be/lower.cpp | 27 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/mapleall/maple_be/include/be/lower.h b/src/mapleall/maple_be/include/be/lower.h index 5585a496e1..43e457e027 100644 --- a/src/mapleall/maple_be/include/be/lower.h +++ b/src/mapleall/maple_be/include/be/lower.h @@ -176,6 +176,8 @@ class CGLowerer { StmtNode *LowerDassignBitfield(DassignNode &dassign, BlockNode &block); StmtNode *LowerIassignBitfield(IassignNode &iassign, BlockNode &block); + void LowerAsmStmt(AsmNode *asmNode, BlockNode *blk); + bool ShouldOptarray() const { ASSERT(mirModule.CurFunction() != nullptr, "nullptr check"); return MIRLower::ShouldOptArrayMrt(*mirModule.CurFunction()); diff --git a/src/mapleall/maple_be/src/be/lower.cpp b/src/mapleall/maple_be/src/be/lower.cpp index e65758e882..f5d26815a2 100644 --- a/src/mapleall/maple_be/src/be/lower.cpp +++ b/src/mapleall/maple_be/src/be/lower.cpp @@ -1000,6 +1000,29 @@ void CGLowerer::LowerIassign(IassignNode &iassign, BlockNode &newBlk) { newBlk.AddStatement(newStmt); } +static GStrIdx NewAsmTempStrIdx() { + static uint32 strIdxCount = 0; // to create unique temporary symbol names + std::string asmTempStr("asm_tempvar"); + (void)asmTempStr.append(std::to_string(++strIdxCount)); + return GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(asmTempStr); +} + +void CGLowerer::LowerAsmStmt(AsmNode *asmNode, BlockNode *newBlk) { + for (size_t i = 0; i < asmNode->NumOpnds(); i++) { + BaseNode *opnd = asmNode->Opnd(i); + if (opnd->NumOpnds() == 0) { + continue; + } + // introduce a temporary to store the expression tree operand + MIRSymbol *st = mirModule.GetMIRBuilder()->CreateSymbol((TyIdx)opnd->GetPrimType(), NewAsmTempStrIdx(), + kStVar, kScAuto, mirModule.CurFunction(), kScopeLocal); + DassignNode *dass = mirModule.GetMIRBuilder()->CreateStmtDassign(*st, 0, opnd); + newBlk->AddStatement(dass); + asmNode->SetOpnd(mirModule.GetMIRBuilder()->CreateExprDread(*st), i); + } + newBlk->AddStatement(asmNode); +} + DassignNode *CGLowerer::SaveReturnValueInLocal(StIdx stIdx, uint16 fieldID) { MIRSymbol *var; if (stIdx.IsGlobal()) { @@ -1559,6 +1582,10 @@ BlockNode *CGLowerer::LowerBlock(BlockNode &block) { LowerResetStmt(*stmt, *newBlk); break; } + case OP_asm: { + LowerAsmStmt(static_cast(stmt), newBlk); + break; + } default: LowerStmt(*stmt, *newBlk); newBlk->AddStatement(stmt); -- Gitee From ec64731ce8936f5da1cd197470baa350bf20e65e Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Thu, 8 Jul 2021 11:12:31 -0700 Subject: [PATCH 2/2] added call to lower each operand of AsmNode --- src/mapleall/maple_be/src/be/lower.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mapleall/maple_be/src/be/lower.cpp b/src/mapleall/maple_be/src/be/lower.cpp index f5d26815a2..16f80e8827 100644 --- a/src/mapleall/maple_be/src/be/lower.cpp +++ b/src/mapleall/maple_be/src/be/lower.cpp @@ -1009,8 +1009,9 @@ static GStrIdx NewAsmTempStrIdx() { void CGLowerer::LowerAsmStmt(AsmNode *asmNode, BlockNode *newBlk) { for (size_t i = 0; i < asmNode->NumOpnds(); i++) { - BaseNode *opnd = asmNode->Opnd(i); + BaseNode *opnd = LowerExpr(*asmNode, *asmNode->Opnd(i), *newBlk); if (opnd->NumOpnds() == 0) { + asmNode->SetOpnd(opnd, i); continue; } // introduce a temporary to store the expression tree operand -- Gitee