diff --git a/src/mapleall/maple_ir/include/mir_builder.h b/src/mapleall/maple_ir/include/mir_builder.h index be6e53c06e1be2351c7251979f30d4cad3b8e474..1cc176d6722cc0d94207f7ae7cf08e20d088560d 100644 --- a/src/mapleall/maple_ir/include/mir_builder.h +++ b/src/mapleall/maple_ir/include/mir_builder.h @@ -149,6 +149,7 @@ class MIRBuilder { MIRStorageClass sc = kScGlobal); MIRSymbol *GetOrCreateDeclInFunc(const std::string &str, const MIRType &type, MIRFunction &func); // for creating Expression + ConstvalNode *CreateConstval(MIRConst *constVal); ConstvalNode *CreateIntConst(int64, PrimType); ConstvalNode *CreateFloatConst(float val); ConstvalNode *CreateDoubleConst(double val); @@ -285,6 +286,7 @@ class MIRBuilder { AddrofNode *CreateDread(const MIRSymbol &st, PrimType pty); virtual MemPool *GetCurrentFuncCodeMp(); virtual MapleAllocator *GetCurrentFuncCodeMpAllocator(); + virtual MemPool *GetCurrentFuncDataMp(); virtual void GlobalLock() {} virtual void GlobalUnlock() {} diff --git a/src/mapleall/maple_ir/src/mir_builder.cpp b/src/mapleall/maple_ir/src/mir_builder.cpp index b6f232a3a4261cae95954c2b7255edb951b6f203..67da936926b92a4274391caa78cf8d54535660ab 100644 --- a/src/mapleall/maple_ir/src/mir_builder.cpp +++ b/src/mapleall/maple_ir/src/mir_builder.cpp @@ -468,6 +468,10 @@ MIRSymbol *MIRBuilder::CreatePregFormalSymbol(TyIdx tyIdx, PregIdx pRegIdx, MIRF return MIRSymbolBuilder::Instance().CreatePregFormalSymbol(tyIdx, pRegIdx, func); } +ConstvalNode *MIRBuilder::CreateConstval(MIRConst *mirConst) { + return GetCurrentFuncCodeMp()->New(mirConst->GetType().GetPrimType(), mirConst); +} + ConstvalNode *MIRBuilder::CreateIntConst(int64 val, PrimType pty) { auto *mirConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(val, *GlobalTables::GetTypeTable().GetPrimType(pty)); @@ -475,22 +479,19 @@ ConstvalNode *MIRBuilder::CreateIntConst(int64 val, PrimType pty) { } ConstvalNode *MIRBuilder::CreateFloatConst(float val) { - MIRFunction *currentFunctionInner = GetCurrentFunctionNotNull(); - auto *mirConst = currentFunctionInner->GetDataMemPool()->New( + auto *mirConst = GetCurrentFuncDataMp()->New( val, *GlobalTables::GetTypeTable().GetPrimType(PTY_f32)); return GetCurrentFuncCodeMp()->New(PTY_f32, mirConst); } ConstvalNode *MIRBuilder::CreateDoubleConst(double val) { - MIRFunction *currentFunctionInner = GetCurrentFunctionNotNull(); - auto *mirConst = currentFunctionInner->GetDataMemPool()->New( + auto *mirConst = GetCurrentFuncDataMp()->New( val, *GlobalTables::GetTypeTable().GetPrimType(PTY_f64)); return GetCurrentFuncCodeMp()->New(PTY_f64, mirConst); } ConstvalNode *MIRBuilder::CreateFloat128Const(const uint64 *val) { - MIRFunction *currentFunctionInner = GetCurrentFunctionNotNull(); - auto *mirConst = currentFunctionInner->GetDataMemPool()->New( + auto *mirConst = GetCurrentFuncDataMp()->New( *val, *GlobalTables::GetTypeTable().GetPrimType(PTY_f128)); return GetCurrentFuncCodeMp()->New(PTY_f128, mirConst); } @@ -1011,11 +1012,24 @@ void MIRBuilder::AddStmtInCurrentFunctionBody(StmtNode &stmt) { } MemPool *MIRBuilder::GetCurrentFuncCodeMp() { - return mirModule->CurFuncCodeMemPool(); + if (MIRFunction *curFunction = GetCurrentFunction()) { + return curFunction->GetCodeMemPool(); + } + return mirModule->GetMemPool(); } MapleAllocator *MIRBuilder::GetCurrentFuncCodeMpAllocator() { - return mirModule->CurFuncCodeMemPoolAllocator(); + if (MIRFunction *curFunction = GetCurrentFunction()) { + return &curFunction->GetCodeMPAllocator(); + } + return &mirModule->GetMPAllocator(); +} + +MemPool *MIRBuilder::GetCurrentFuncDataMp() { + if (MIRFunction *curFunction = GetCurrentFunction()) { + return curFunction->GetDataMemPool(); + } + return mirModule->GetMemPool(); } MIRBuilderExt::MIRBuilderExt(MIRModule *module, pthread_mutex_t *mutex) : MIRBuilder(module), mutex(mutex) {}