diff --git a/src/mapleall/maple_ir/include/global_tables.h b/src/mapleall/maple_ir/include/global_tables.h index 6fdf9cd7f72a7fc2aabaecc5ab80c0e1cda6ce86..3563ed0952b0eb81611be75ec4ce44b510d85028 100644 --- a/src/mapleall/maple_ir/include/global_tables.h +++ b/src/mapleall/maple_ir/include/global_tables.h @@ -503,8 +503,8 @@ class FPConstTable { FPConstTable &operator=(const FPConstTable &p) = delete; ~FPConstTable(); - MIRFloatConst *GetOrCreateFloatConst(float); // get the const from floatConstTable or create a new one - MIRDoubleConst *GetOrCreateDoubleConst(double); // get the const from doubleConstTable or create a new one + MIRFloatConst *GetOrCreateFloatConst(float fval, uint32 fieldID); // get the const from floatConstTable or create a new one + MIRDoubleConst *GetOrCreateDoubleConst(double fval, uint32 fieldID); // get the const from doubleConstTable or create a new one static std::unique_ptr Create() { auto p = std::unique_ptr(new FPConstTable()); diff --git a/src/mapleall/maple_ir/src/bin_mpl_import.cpp b/src/mapleall/maple_ir/src/bin_mpl_import.cpp index 00dd9679d485d8d249cc9f3056adfd8d43d7d8cd..2ac33c8b175d7737052f81f717c5e0501244482f 100644 --- a/src/mapleall/maple_ir/src/bin_mpl_import.cpp +++ b/src/mapleall/maple_ir/src/bin_mpl_import.cpp @@ -163,7 +163,7 @@ MIRConst *BinaryMplImport::ImportConst(MIRFunction *func) { } value; value.ivalue = ReadNum(); - return GlobalTables::GetFpConstTable().GetOrCreateFloatConst(value.fvalue); + return GlobalTables::GetFpConstTable().GetOrCreateFloatConst(value.fvalue, fieldID); } case kBinKindConstDouble: { union { @@ -172,7 +172,7 @@ MIRConst *BinaryMplImport::ImportConst(MIRFunction *func) { } value; value.ivalue = ReadNum(); - return GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(value.dvalue); + return GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(value.dvalue, fieldID); } case kBinKindConstAgg: { MIRAggConst *aggConst = mod.GetMemPool()->New(mod, *type, fieldID); diff --git a/src/mapleall/maple_ir/src/global_tables.cpp b/src/mapleall/maple_ir/src/global_tables.cpp index d8e20f082dba9492a33bb734112c528cc96118ef..b00ba892bb7910c780ba08a43c65389236081a1b 100644 --- a/src/mapleall/maple_ir/src/global_tables.cpp +++ b/src/mapleall/maple_ir/src/global_tables.cpp @@ -299,7 +299,11 @@ IntConstTable::~IntConstTable() { } } -MIRFloatConst *FPConstTable::GetOrCreateFloatConst(float floatVal) { +MIRFloatConst *FPConstTable::GetOrCreateFloatConst(float floatVal, uint32 fieldID) { + if (fieldID != 0) { + MIRFloatConst *fconst = new MIRFloatConst(floatVal, *GlobalTables::GetTypeTable().GetTypeFromTyIdx((TyIdx)PTY_f32), fieldID); + return fconst; + } if (std::isnan(floatVal)) { return nanFloatConst; } @@ -341,7 +345,11 @@ MIRFloatConst *FPConstTable::DoGetOrCreateFloatConstThreadSafe(float floatVal) { return floatConst; } -MIRDoubleConst *FPConstTable::GetOrCreateDoubleConst(double doubleVal) { +MIRDoubleConst *FPConstTable::GetOrCreateDoubleConst(double doubleVal, uint32 fieldID) { + if (fieldID != 0) { + MIRDoubleConst *dconst = new MIRDoubleConst(doubleVal, *GlobalTables::GetTypeTable().GetTypeFromTyIdx((TyIdx)PTY_f64), fieldID); + return dconst; + } if (std::isnan(doubleVal)) { return nanDoubleConst; } diff --git a/src/mapleall/maple_ir/src/mir_parser.cpp b/src/mapleall/maple_ir/src/mir_parser.cpp index 351cfa0d9ab73aa24603a7251ef09a27d5e462c1..a7c5b5980145d35df759ce23e9d903a94913f8eb 100644 --- a/src/mapleall/maple_ir/src/mir_parser.cpp +++ b/src/mapleall/maple_ir/src/mir_parser.cpp @@ -2613,14 +2613,14 @@ bool MIRParser::ParseScalarValue(MIRConstPtr &stype, MIRType &type, uint32 field Error("constant value incompatible with single-precision float type at "); return false; } - MIRFloatConst *fConst = GlobalTables::GetFpConstTable().GetOrCreateFloatConst(lexer.GetTheFloatVal()); + MIRFloatConst *fConst = GlobalTables::GetFpConstTable().GetOrCreateFloatConst(lexer.GetTheFloatVal(), fieldID); stype = fConst; } else if (ptp == PTY_f64) { if (lexer.GetTokenKind() != TK_doubleconst && lexer.GetTokenKind() != TK_intconst) { Error("constant value incompatible with double-precision float type at "); return false; } - MIRDoubleConst *dconst = GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(lexer.GetTheDoubleVal()); + MIRDoubleConst *dconst = GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(lexer.GetTheDoubleVal(), fieldID); stype = dconst; } else { return false; diff --git a/src/mapleall/mpl2mpl/src/constantfold.cpp b/src/mapleall/mpl2mpl/src/constantfold.cpp index 42221c47c671864fc7db995b21f6bbbd6f3a4cd8..1c9b4bf295d4fc81f2a11cda8322a59c25d39908 100644 --- a/src/mapleall/mpl2mpl/src/constantfold.cpp +++ b/src/mapleall/mpl2mpl/src/constantfold.cpp @@ -743,9 +743,9 @@ ConstvalNode *ConstantFold::FoldFPConstBinary(Opcode opcode, PrimType resultType break; } if (resultType == PTY_f64) { - resultConst->SetConstVal(GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(constValueDouble)); + resultConst->SetConstVal(GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(constValueDouble, 0)); } else { - resultConst->SetConstVal(GlobalTables::GetFpConstTable().GetOrCreateFloatConst(constValueFloat)); + resultConst->SetConstVal(GlobalTables::GetFpConstTable().GetOrCreateFloatConst(constValueFloat, 0)); } return resultConst; } @@ -1029,9 +1029,9 @@ ConstvalNode *ConstantFold::FoldFPConstUnary(Opcode opcode, PrimType resultType, auto *resultConst = mirModule->CurFuncCodeMemPool()->New(); resultConst->SetPrimType(resultType); if (resultType == PTY_f32) { - resultConst->SetConstVal(GlobalTables::GetFpConstTable().GetOrCreateFloatConst(constValue)); + resultConst->SetConstVal(GlobalTables::GetFpConstTable().GetOrCreateFloatConst(constValue, 0)); } else { - resultConst->SetConstVal(GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(constValue)); + resultConst->SetConstVal(GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(constValue, 0)); } return resultConst; } @@ -1261,13 +1261,13 @@ MIRConst *ConstantFold::FoldRoundMIRConst(const MIRConst &cst, PrimType fromType int64 fromValue = constValue.GetValue(); float floatValue = round(static_cast(fromValue)); if (static_cast(floatValue) == fromValue) { - return GlobalTables::GetFpConstTable().GetOrCreateFloatConst(floatValue); + return GlobalTables::GetFpConstTable().GetOrCreateFloatConst(floatValue, 0); } } else { uint64 fromValue = static_cast(constValue.GetValue()); float floatValue = round(static_cast(fromValue)); if (static_cast(floatValue) == fromValue) { - return GlobalTables::GetFpConstTable().GetOrCreateFloatConst(floatValue); + return GlobalTables::GetFpConstTable().GetOrCreateFloatConst(floatValue, 0); } } } else if (toType == PTY_f64 && IsPrimitiveInteger(fromType)) { @@ -1276,13 +1276,13 @@ MIRConst *ConstantFold::FoldRoundMIRConst(const MIRConst &cst, PrimType fromType int64 fromValue = constValue.GetValue(); double doubleValue = round(static_cast(fromValue)); if (static_cast(doubleValue) == fromValue) { - return GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(doubleValue); + return GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(doubleValue, 0); } } else { uint64 fromValue = static_cast(constValue.GetValue()); double doubleValue = round(static_cast(fromValue)); if (static_cast(doubleValue) == fromValue) { - return GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(doubleValue); + return GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(doubleValue, 0); } } } @@ -1353,14 +1353,14 @@ MIRConst *ConstantFold::FoldTypeCvtMIRConst(const MIRConst &cst, PrimType fromTy const MIRDoubleConst *fromValue = safe_cast(cst); ASSERT_NOT_NULL(fromValue); float floutValue = static_cast(fromValue->GetValue()); - MIRFloatConst *toValue = GlobalTables::GetFpConstTable().GetOrCreateFloatConst(floutValue); + MIRFloatConst *toValue = GlobalTables::GetFpConstTable().GetOrCreateFloatConst(floutValue, 0); toConst = toValue; } else { ASSERT(GetPrimTypeBitSize(toType) == 64, "We suppot F32 and F64"); const MIRFloatConst *fromValue = safe_cast(cst); ASSERT_NOT_NULL(fromValue); double doubleValue = static_cast(fromValue->GetValue()); - MIRDoubleConst *toValue = GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(doubleValue); + MIRDoubleConst *toValue = GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(doubleValue, 0); toConst = toValue; } return toConst;