diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index 5e14ddc51ae05d079b9d0e13cbb8692be8ad1949..bb3307c1fd4c2d3f729e75d9984f1fa763a6b41c 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index 87c4a23d60a6038e948f2706e93efe2fa26917cd..3fa9c14954f102ba836e4e2107a7fb8fc091fb73 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/bin/mplcg b/src/bin/mplcg index 0cde5feb50cb471e985d482b234ca9973458c259..da4f4f49f66c50361747779084637e0206b90d19 100755 Binary files a/src/bin/mplcg and b/src/bin/mplcg differ diff --git a/src/deplibs/libmaple_driverutil.a b/src/deplibs/libmaple_driverutil.a index 4e03a45eed804d987a77e4395f3b4e8690e29368..f285ac96ea3dd87017a244c61065b93393f6fc10 100644 Binary files a/src/deplibs/libmaple_driverutil.a and b/src/deplibs/libmaple_driverutil.a differ diff --git a/src/deplibs/libmplutil.a b/src/deplibs/libmplutil.a index 60b222cc866e817616d7167b2d4b0aafc1afd520..535b71c5d353a7e3ba5836d06637859cc1c3af34 100644 Binary files a/src/deplibs/libmplutil.a and b/src/deplibs/libmplutil.a differ diff --git a/src/maple_driver/src/file_utils.cpp b/src/maple_driver/src/file_utils.cpp index 4ace696857cb8bf8853155ed01e405ee8ccc6899..c571f176efea4467a27309e1c46f7fb30811e25c 100644 --- a/src/maple_driver/src/file_utils.cpp +++ b/src/maple_driver/src/file_utils.cpp @@ -30,6 +30,9 @@ const std::string kFileSeperatorStr = kFileSeperatorLinuxStyleStr; std::string FileUtils::GetFileName(const std::string &filePath, bool isWithExtension) { std::string fullFileName = StringUtils::GetStrAfterLast(filePath, kFileSeperatorStr); +#ifdef _WIN32 + fullFileName = StringUtils::GetStrAfterLast(fullFileName, kFileSeperatorLinuxStyleStr); +#endif if (isWithExtension) { return fullFileName; } @@ -42,12 +45,14 @@ std::string FileUtils::GetFileExtension(const std::string &filePath) { std::string FileUtils::GetFileFolder(const std::string &filePath) { std::string folder = StringUtils::GetStrBeforeLast(filePath, kFileSeperatorStr, true); + std::string curSlashType = kFileSeperatorStr; #ifdef _WIN32 if (folder.empty()) { - folder = StringUtils::GetStrBeforeLast(filePath, kFileSeperatorWindowsStyleStr, true); + curSlashType = kFileSeperatorLinuxStyleStr; + folder = StringUtils::GetStrBeforeLast(filePath, curSlashType, true); } #endif - return folder.empty() ? ("." + kFileSeperatorStr) : (folder + kFileSeperatorStr); + return folder.empty() ? ("." + curSlashType) : (folder + curSlashType); } int FileUtils::Remove(const std::string &filePath) { diff --git a/src/maple_ir/include/ir_safe_cast_traits.def b/src/maple_ir/include/ir_safe_cast_traits.def new file mode 100644 index 0000000000000000000000000000000000000000..1360c6f1311d2002b2955ff74abd875e2d18f88d --- /dev/null +++ b/src/maple_ir/include/ir_safe_cast_traits.def @@ -0,0 +1,68 @@ +/* + * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + */ +#include + +namespace maple { +#ifdef LOAD_SAFE_CAST_FOR_MIR_CONST +#undef LOAD_SAFE_CAST_FOR_MIR_CONST +inline MIRConstKind safe_cast_traits(const MIRConst &mirConst) { + return mirConst.GetKind(); +}; + +template <> struct ExtractCode { + enum {value = kConstInt}; +}; + +template <> struct ExtractCode { + enum {value = kConstAddrof}; +}; + +template <> struct ExtractCode { + enum {value = kConstAddrofFunc}; +}; + +template <> struct ExtractCode { + enum {value = kConstLblConst}; +}; + +template <> struct ExtractCode { + enum {value = kConstStrConst}; +}; + +template <> struct ExtractCode { + enum {value = kConstStr16Const}; +}; + +template <> struct ExtractCode { + enum {value = kConstFloatConst}; +}; + +template <> struct ExtractCode { + enum {value = kConstDoubleConst}; +}; + +template <> struct ExtractCode { + enum {value = kConstFloat128Const}; +}; + +template <> struct ExtractCode { + enum {value = kConstAggConst}; +}; + +template <> struct ExtractCode { + enum {value = kConstStConst}; +}; +#endif +} diff --git a/src/maple_ir/include/metadata_layout.h b/src/maple_ir/include/metadata_layout.h index 60ba9221082747bdea38d48890e8753854cca934..d6e8bd49f1e82616e18163e75c21891cde2824d0 100644 --- a/src/maple_ir/include/metadata_layout.h +++ b/src/maple_ir/include/metadata_layout.h @@ -107,6 +107,34 @@ struct DataRef { inline void SetDataRef(void *ref, DataRefFormat format = kDataRefIsDirect); }; +/* GctibRef aims to represent a reference to gctib in maple file, which is an offset by default. + GctibRef is meant to have pointer size and aligned to at least 4 bytes. + GctibRef allows 2 formats of value: + 0. "label_name - . + 0" for reference in offset format + 1. "indirect.label_name - . + 1" for indirect reference + this format aims to support lld which does not support expression "global_symbol - ." + GctibRef is self-decoded by also encoding the format and is defined for binary compatibility. + If no compatibility problem is involved, DataRef is preferred. + */ +enum GctibRefFormat { + kGctibRefIsOffset = 0, // default + kGctibRefIsIndirect = 1, + kGctibRefBitMask = 3 +}; + +struct GctibRef32 { + // be careful when *refVal* is treated as an offset which is a signed integer actually. + uint32_t refVal; + inline void *GetGctibRef() const; + inline void SetGctibRef(void *ref, GctibRefFormat format = kGctibRefIsOffset); +}; + +struct GctibRef { + void *refVal; + inline void *GetGctibRef() const; + inline void SetGctibRef(void *ref, GctibRefFormat format = kGctibRefIsOffset); +}; + // MByteRef is meant to represent a reference to data defined in maple file. It is a direct reference or an offset. // MByteRef is self-encoded/decoded and aligned to 1 byte. // Unlike DataRef, the format of MByteRef is determined by its value. @@ -239,7 +267,7 @@ struct ClassMetadata { DataRef iTable; // iTable of current class, used for virtual call, will insert the content into classinfo DataRef vTable; // vTable of current class, used for interface call, will insert the content into classinfo - void *gctib; // for rc + GctibRef gctib; // for rc union { DataRef classinforo64; // ifndef USE_32BIT_REF diff --git a/src/maple_ir/include/mir_const.h b/src/maple_ir/include/mir_const.h index 55073678de06f18244bc5e497adb763772350060..5edc57b15da5ebfa0050c60e27b24e5913160034 100644 --- a/src/maple_ir/include/mir_const.h +++ b/src/maple_ir/include/mir_const.h @@ -39,7 +39,8 @@ enum MIRConstKind { class MIRConst { public: - explicit MIRConst(MIRType &type, uint32 fieldID = 0) : type(type), fieldID(fieldID) {} + explicit MIRConst(MIRType &type, MIRConstKind constKind = kConstInvalid, uint32 fieldID = 0) + : type(type), kind(constKind), fieldID(fieldID) {} virtual ~MIRConst() = default; @@ -72,14 +73,12 @@ class MIRConst { return &rhs == this; } + virtual MIRConst *Clone(MemPool &memPool) const = 0; + MIRConstKind GetKind() const { return kind; } - void SetKind(MIRConstKind ind) { - kind = ind; - } - MIRType &GetType() { return type; } @@ -89,61 +88,27 @@ class MIRConst { } private: - MIRConstKind kind = kConstInvalid; MIRType &type; + MIRConstKind kind; uint32 fieldID; }; class MIRIntConst : public MIRConst { public: using value_type = int64; - MIRIntConst(int64 val, MIRType &type, uint32 fieldID = 0) : MIRConst(type, fieldID), value(val) { + MIRIntConst(int64 val, MIRType &type, uint32 fieldID = 0) : MIRConst(type, kConstInt, fieldID), value(val) { if (!IsPrimitiveDynType(type.GetPrimType())) { Trunc(GetPrimTypeBitSize(type.GetPrimType())); } - SetKind(kConstInt); } ~MIRIntConst() = default; - uint8 GetBitWidth() const { - if (value == 0) { - return 1; - } - uint8 width = 0; - uint64 tmp = value < 0 ? -(value + 1) : value; - while (tmp != 0) { - ++width; - tmp = tmp >> 1u; - } - return width; - } + uint8 GetBitWidth() const; - void Trunc(uint8 width) { - int32 shiftBitNum = 64u - width; - if (shiftBitNum < 0) { - CHECK_FATAL(false, "shiftBitNum should not be less than zero"); - } - auto unsignShiftBitNum = static_cast(shiftBitNum); - if (IsSignedInteger(GetType().GetPrimType())) { - value = (value << unsignShiftBitNum) >> unsignShiftBitNum; - } else { - value = ((static_cast(value)) << unsignShiftBitNum) >> unsignShiftBitNum; - } - } + void Trunc(uint8 width); - int64 GetValueUnderType() const { - uint32 bitSize = GetPrimTypeBitSize(GetNonDynType(GetType().GetPrimType())); - int32 shiftBitNum = 64u - bitSize; - if (shiftBitNum < 0) { - CHECK_FATAL(false, "shiftBitNum should not be less than zero"); - } - if (IsSignedInteger(GetType().GetPrimType())) { - return static_cast(((value) << shiftBitNum) >> shiftBitNum); - } - auto unsignedVal = static_cast(value); - return static_cast((unsignedVal << shiftBitNum) >> shiftBitNum); - } + int64 GetValueUnderType() const; void Dump() const override; bool IsZero() const override { @@ -154,6 +119,7 @@ class MIRIntConst : public MIRConst { return value == 1 && IsPrimitiveInteger(GetType().GetPrimType()); }; bool IsMagicNum() const override { + // use INIT_INST_TABLE defined 50 OPs for inst_processor_table constexpr int64 kMagicNum = 51; return value == kMagicNum && IsPrimitiveInteger(GetType().GetPrimType()); }; @@ -174,15 +140,17 @@ class MIRIntConst : public MIRConst { bool operator==(const MIRConst &rhs) const override; + MIRIntConst *Clone(MemPool &memPool) const override { + return memPool.New(*this); + } + private: int64 value; }; class MIRAddrofConst : public MIRConst { public: - MIRAddrofConst(StIdx sy, FieldID fi, MIRType &ty) : MIRConst(ty), stIdx(sy), fldID(fi) { - SetKind(kConstAddrof); - } + MIRAddrofConst(StIdx sy, FieldID fi, MIRType &ty) : MIRConst(ty, kConstAddrof), stIdx(sy), fldID(fi) {} ~MIRAddrofConst() = default; @@ -198,6 +166,10 @@ class MIRAddrofConst : public MIRConst { bool operator==(const MIRConst &rhs) const override; + MIRAddrofConst *Clone(MemPool &memPool) const override { + return memPool.New(*this); + } + private: StIdx stIdx; FieldID fldID; @@ -205,9 +177,8 @@ class MIRAddrofConst : public MIRConst { class MIRAddroffuncConst : public MIRConst { public: - MIRAddroffuncConst(PUIdx idx, MIRType &ty, uint32 fieldID = 0) : MIRConst(ty, fieldID), puIdx(idx) { - SetKind(kConstAddrofFunc); - } + MIRAddroffuncConst(PUIdx idx, MIRType &ty, uint32 fieldID = 0) + : MIRConst(ty, kConstAddrofFunc, fieldID), puIdx(idx) {} ~MIRAddroffuncConst() = default; @@ -219,20 +190,26 @@ class MIRAddroffuncConst : public MIRConst { bool operator==(const MIRConst &rhs) const override; + MIRAddroffuncConst *Clone(MemPool &memPool) const override { + return memPool.New(*this); + } + private: PUIdx puIdx; }; class MIRLblConst : public MIRConst { public: - MIRLblConst(LabelIdx val, MIRType &type) : MIRConst(type), value(val) { - SetKind(kConstLblConst); - } + MIRLblConst(LabelIdx val, MIRType &type) : MIRConst(type, kConstLblConst), value(val) {} ~MIRLblConst() = default; bool operator==(const MIRConst &rhs) const override; + MIRLblConst *Clone(MemPool &memPool) const override { + return memPool.New(*this); + } + LabelIdx GetValue() const { return value; } @@ -243,9 +220,7 @@ class MIRLblConst : public MIRConst { class MIRStrConst : public MIRConst { public: - MIRStrConst(UStrIdx val, MIRType &type, uint32 fieldID = 0) : MIRConst(type, fieldID), value(val) { - SetKind(kConstStrConst); - } + MIRStrConst(UStrIdx val, MIRType &type, uint32 fieldID = 0) : MIRConst(type, kConstStrConst, fieldID), value(val) {} MIRStrConst(const std::string &str, MIRType &type); @@ -253,6 +228,11 @@ class MIRStrConst : public MIRConst { void Dump() const override; bool operator==(const MIRConst &rhs) const override; + + MIRStrConst *Clone(MemPool &memPool) const override { + return memPool.New(*this); + } + UStrIdx GetValue() const { return value; } @@ -268,9 +248,7 @@ class MIRStrConst : public MIRConst { class MIRStr16Const : public MIRConst { public: - MIRStr16Const(U16StrIdx val, MIRType &type) : MIRConst(type), value(val) { - SetKind(kConstStr16Const); - } + MIRStr16Const(U16StrIdx val, MIRType &type) : MIRConst(type, kConstStr16Const), value(val) {} MIRStr16Const(const std::u16string &str, MIRType &type); @@ -282,6 +260,11 @@ class MIRStr16Const : public MIRConst { void Dump() const override; bool operator==(const MIRConst &rhs) const override; + + MIRStr16Const *Clone(MemPool &memPool) const override { + return memPool.New(*this); + } + U16StrIdx GetValue() const { return value; } @@ -294,9 +277,8 @@ class MIRStr16Const : public MIRConst { class MIRFloatConst : public MIRConst { public: using value_type = float; - MIRFloatConst(float val, MIRType &type) : MIRConst(type) { + MIRFloatConst(float val, MIRType &type) : MIRConst(type, kConstFloatConst) { value.floatValue = val; - SetKind(kConstFloatConst); } ~MIRFloatConst() = default; @@ -338,6 +320,10 @@ class MIRFloatConst : public MIRConst { bool operator==(const MIRConst &rhs) const override; + MIRFloatConst *Clone(MemPool &memPool) const override { + return memPool.New(*this); + } + private: static const PrimType kPrimType = PTY_f32; union { @@ -349,9 +335,8 @@ class MIRFloatConst : public MIRConst { class MIRDoubleConst : public MIRConst { public: using value_type = double; - MIRDoubleConst(double val, MIRType &type) : MIRConst(type) { + MIRDoubleConst(double val, MIRType &type) : MIRConst(type, kConstDoubleConst) { value.dValue = val; - SetKind(kConstDoubleConst); } ~MIRDoubleConst() = default; @@ -395,6 +380,10 @@ class MIRDoubleConst : public MIRConst { bool operator==(const MIRConst &rhs) const override; + MIRDoubleConst *Clone(MemPool &memPool) const override { + return memPool.New(*this); + } + private: static const PrimType kPrimType = PTY_f64; union { @@ -405,9 +394,8 @@ class MIRDoubleConst : public MIRConst { class MIRFloat128Const : public MIRConst { public: - MIRFloat128Const(const uint64 &val, MIRType &type) : MIRConst(type) { + MIRFloat128Const(const uint64 &val, MIRType &type) : MIRConst(type, kConstFloat128Const) { value = &val; - SetKind(kConstFloat128Const); } ~MIRFloat128Const() = default; @@ -434,6 +422,12 @@ class MIRFloat128Const : public MIRConst { return (value[0] == 0xffffffffffffffff && value[1] == 0xffffffffffffffff); }; bool operator==(const MIRConst &rhs) const override; + + MIRFloat128Const *Clone(MemPool &memPool) const override { + auto *res = memPool.New(*this); + return res; + } + void Dump() const override; private: @@ -445,22 +439,15 @@ class MIRFloat128Const : public MIRConst { class MIRAggConst : public MIRConst { public: MIRAggConst(MIRModule &mod, MIRType &type) - : MIRConst(type), constVec(mod.GetMPAllocator().Adapter()) { - SetKind(kConstAggConst); - } + : MIRConst(type, kConstAggConst), constVec(mod.GetMPAllocator().Adapter()) {} ~MIRAggConst() = default; MIRConst *GetAggConstElement(unsigned int fieldidx) { - for (size_t i = 0; i < constVec.size(); ++i) { - if (constVec[i] == nullptr) { - CHECK_FATAL(false, "exist nullptr in constVec"); - } - if (fieldidx == constVec[i]->GetFieldId()) { - return constVec[i]; - } - } - return nullptr; + CHECK_FATAL(fieldidx < constVec.size() + 1, "invalid index for constVec"); + CHECK_FATAL(constVec[fieldidx - 1] != nullptr, "exist nullptr in constVec"); + CHECK_FATAL(constVec[fieldidx - 1]->GetFieldId() == fieldidx, "fieldidx unmatched"); + return constVec[fieldidx - 1]; } const MapleVector &GetConstVec() const { @@ -492,6 +479,10 @@ class MIRAggConst : public MIRConst { void Dump() const override; bool operator==(const MIRConst &rhs) const override; + MIRAggConst *Clone(MemPool &memPool) const override { + return memPool.New(*this); + } + private: MapleVector constVec; }; @@ -500,9 +491,8 @@ class MIRAggConst : public MIRConst { class MIRStConst : public MIRConst { public: MIRStConst(MIRModule &mod, MIRType &type) - : MIRConst(type), stVec(mod.GetMPAllocator().Adapter()), stOffsetVec(mod.GetMPAllocator().Adapter()) { - SetKind(kConstStConst); - } + : MIRConst(type, kConstStConst), stVec(mod.GetMPAllocator().Adapter()), + stOffsetVec(mod.GetMPAllocator().Adapter()) {} const MapleVector &GetStVec() const { return stVec; @@ -528,6 +518,11 @@ class MIRStConst : public MIRConst { return stOffsetVec[index]; } + MIRStConst *Clone(MemPool &memPool) const override { + auto *res = memPool.New(*this); + return res; + } + ~MIRStConst() = default; private: @@ -536,4 +531,6 @@ class MIRStConst : public MIRConst { }; #endif // MIR_FEATURE_FULL } // namespace maple +#define LOAD_SAFE_CAST_FOR_MIR_CONST +#include "ir_safe_cast_traits.def" #endif // MAPLE_IR_INCLUDE_MIR_CONST_H diff --git a/src/maple_ir/include/opcodes.h b/src/maple_ir/include/opcodes.h index 6af2017ca4c6e3f13b5fc944cc66737241285912..e85f42f914e63c24897fc7d22c17ab8f565cd1c6 100644 --- a/src/maple_ir/include/opcodes.h +++ b/src/maple_ir/include/opcodes.h @@ -42,6 +42,25 @@ inline constexpr bool IsBranch(Opcode opcode) { return (opcode == OP_goto || opcode == OP_brtrue || opcode == OP_brfalse || opcode == OP_switch); } +constexpr bool IsCommutative(Opcode opcode) { + switch (opcode) { + case OP_add: + case OP_mul: + case OP_max: + case OP_min: + case OP_band: + case OP_bior: + case OP_bxor: + case OP_eq: + case OP_ne: + case OP_land: + case OP_lior: + return true; + default: + return false; + } +} + constexpr bool IsStmtMustRequire(Opcode opcode) { switch (opcode) { case OP_jstry: diff --git a/src/maple_ir/src/mir_const.cpp b/src/maple_ir/src/mir_const.cpp index 36c292884e6a9d627bbefdc948d73a31cc42388a..823969af826524e4b34920e393180fbaa4ee0a71 100644 --- a/src/maple_ir/src/mir_const.cpp +++ b/src/maple_ir/src/mir_const.cpp @@ -48,6 +48,45 @@ bool MIRIntConst::operator==(const MIRConst &rhs) const { return ((&intConst.GetType() == &GetType()) && (intConst.value == value)); } +uint8 MIRIntConst::GetBitWidth() const { + if (value == 0) { + return 1; + } + uint8 width = 0; + uint64 tmp = value < 0 ? -(value + 1) : value; + while (tmp != 0) { + ++width; + tmp = tmp >> 1u; + } + return width; +} + +void MIRIntConst::Trunc(uint8 width) { + int32 shiftBitNum = 64u - width; + if (shiftBitNum < 0) { + CHECK_FATAL(false, "shiftBitNum should not be less than zero"); + } + auto unsignShiftBitNum = static_cast(shiftBitNum); + if (IsSignedInteger(GetType().GetPrimType())) { + value = (value << unsignShiftBitNum) >> unsignShiftBitNum; + } else { + value = ((static_cast(value)) << unsignShiftBitNum) >> unsignShiftBitNum; + } +} + +int64 MIRIntConst::GetValueUnderType() const { + uint32 bitSize = GetPrimTypeBitSize(GetNonDynType(GetType().GetPrimType())); + int32 shiftBitNum = 64u - bitSize; + if (shiftBitNum < 0) { + CHECK_FATAL(false, "shiftBitNum should not be less than zero"); + } + if (IsSignedInteger(GetType().GetPrimType())) { + return static_cast(((value) << shiftBitNum) >> shiftBitNum); + } + auto unsignedVal = static_cast(value); + return static_cast((unsignedVal << shiftBitNum) >> shiftBitNum); +} + void MIRAddrofConst::Dump() const { MIRConst::Dump(); LogInfo::MapleLogger() << "addrof " << GetPrimTypeName(PTY_ptr); @@ -203,9 +242,7 @@ void MIRAggConst::Dump() const { } MIRStrConst::MIRStrConst(const std::string &str, MIRType &type) - : MIRConst(type), value(GlobalTables::GetUStrTable().GetOrCreateStrIdxFromName(str)) { - SetKind(kConstStrConst); -} + : MIRConst(type, kConstStrConst), value(GlobalTables::GetUStrTable().GetOrCreateStrIdxFromName(str)) {} void MIRStrConst::Dump() const { MIRConst::Dump(); @@ -226,9 +263,7 @@ bool MIRStrConst::operator==(const MIRConst &rhs) const { } MIRStr16Const::MIRStr16Const(const std::u16string &str, MIRType &type) - : MIRConst(type), value(GlobalTables::GetU16StrTable().GetOrCreateStrIdxFromName(str)) { - SetKind(kConstStr16Const); -} + : MIRConst(type, kConstStr16Const), value(GlobalTables::GetU16StrTable().GetOrCreateStrIdxFromName(str)) {} void MIRStr16Const::Dump() const { MIRConst::Dump(); diff --git a/src/maple_ir/src/mir_nodes.cpp b/src/maple_ir/src/mir_nodes.cpp index 96c2515876bcd1b12e1f0be692e2e61f7d1d7c91..2959111734e7a98dc3b7e2ed80386043a9c6f5f0 100644 --- a/src/maple_ir/src/mir_nodes.cpp +++ b/src/maple_ir/src/mir_nodes.cpp @@ -422,7 +422,7 @@ MIRType *ArrayNode::GetArrayType(const TypeTable &tt) { const BaseNode *ArrayNode::GetDim(const MIRModule &mod, TypeTable &tt, int i) const { const auto *arrayType = static_cast(GetArrayType(tt)); - auto *mirConst = mod.CurFuncCodeMemPool()->New(*tt.GetTypeFromTyIdx(arrayType->GetElemTyIdx())); + auto *mirConst = mod.CurFuncCodeMemPool()->New(i, *tt.GetTypeFromTyIdx(arrayType->GetElemTyIdx())); return mod.CurFuncCodeMemPool()->New(mirConst); } BaseNode *ArrayNode::GetDim(const MIRModule &mod, TypeTable &tt, int i) { diff --git a/src/maple_me/include/me_ir.h b/src/maple_me/include/me_ir.h index a1b4e87ddf9bb524193b6f07cca58c1128ca879d..83d5996463d1fc013b484e08b87491669bf8f076 100644 --- a/src/maple_me/include/me_ir.h +++ b/src/maple_me/include/me_ir.h @@ -603,19 +603,19 @@ class ConstMeExpr : public MeExpr { uint32 GetHashIndex() const override { if (constVal->GetKind() == kConstInt) { - auto *intConst = static_cast(constVal); + auto *intConst = safe_cast(constVal); return intConst->GetValue(); } if (constVal->GetKind() == kConstFloatConst) { - auto *floatConst = static_cast(constVal); + auto *floatConst = safe_cast(constVal); return floatConst->GetIntValue(); } if (constVal->GetKind() == kConstDoubleConst) { - auto *doubleConst = static_cast(constVal); + auto *doubleConst = safe_cast(constVal); return doubleConst->GetIntValue(); } if (constVal->GetKind() == kConstLblConst) { - auto *lblConst = static_cast(constVal); + auto *lblConst = safe_cast(constVal); return lblConst->GetValue(); } ASSERT(false, "ComputeHash: const type not yet implemented"); @@ -827,6 +827,8 @@ class OpMeExpr : public MeExpr { OpMeExpr &operator=(const OpMeExpr&) = delete; bool IsIdentical(const OpMeExpr &meexpr) const; + bool IsAllOpndsIdentical(const OpMeExpr &meExpr) const; + bool IsCompareIdentical(const OpMeExpr &meExpr) const; void Dump(IRMap*, int32 indent = 0) const override; bool IsUseSameSymbol(const MeExpr&) const override; MeExpr *GetIdenticalExpr(MeExpr &expr) const override; diff --git a/src/maple_me/include/me_safe_cast_traits.def b/src/maple_me/include/me_safe_cast_traits.def index b392d16e2d334341df6aa360815446872f008a64..06a84154cb1f2ccde62f99760a6c354df43d505e 100644 --- a/src/maple_me/include/me_safe_cast_traits.def +++ b/src/maple_me/include/me_safe_cast_traits.def @@ -12,48 +12,48 @@ * FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v1 for more details. */ -#include - -namespace maple { -#ifdef LOAD_SAFE_CAST_FOR_ME_EXPR -#undef LOAD_SAFE_CAST_FOR_ME_EXPR -inline MeExprOp safe_cast_traits(const MeExpr &expr) { - return expr.GetMeOp(); -}; - -template <> struct ExtractCode { - enum {value = kMeOpVar}; -}; - -template <> struct ExtractCode { - enum {value = kMeOpOp}; -}; - -template <> struct ExtractCode { - enum {value = kMeOpNary}; -}; - -template <> struct ExtractCode { - enum {value = kMeOpIvar}; -}; -#endif - -#ifdef LOAD_SAFE_CAST_FOR_ME_STMT -#undef LOAD_SAFE_CAST_FOR_ME_STMT -inline Opcode safe_cast_traits(const MeStmt &stmt) { - return stmt.GetOp(); -} - -template <> struct ExtractCode { - enum {value = OP_dassign}; -}; - -template <> struct ExtractCode { - enum {value = OP_maydassign}; -}; - -template <> struct ExtractCode { - enum {value = OP_iassign}; -}; -#endif -} +#include + +namespace maple { +#ifdef LOAD_SAFE_CAST_FOR_ME_EXPR +#undef LOAD_SAFE_CAST_FOR_ME_EXPR +inline MeExprOp safe_cast_traits(const MeExpr &expr) { + return expr.GetMeOp(); +}; + +template <> struct ExtractCode { + enum {value = kMeOpVar}; +}; + +template <> struct ExtractCode { + enum {value = kMeOpOp}; +}; + +template <> struct ExtractCode { + enum {value = kMeOpNary}; +}; + +template <> struct ExtractCode { + enum {value = kMeOpIvar}; +}; +#endif + +#ifdef LOAD_SAFE_CAST_FOR_ME_STMT +#undef LOAD_SAFE_CAST_FOR_ME_STMT +inline Opcode safe_cast_traits(const MeStmt &stmt) { + return stmt.GetOp(); +} + +template <> struct ExtractCode { + enum {value = OP_dassign}; +}; + +template <> struct ExtractCode { + enum {value = OP_maydassign}; +}; + +template <> struct ExtractCode { + enum {value = OP_iassign}; +}; +#endif +} diff --git a/src/maple_me/src/alias_class.cpp b/src/maple_me/src/alias_class.cpp index d97ef4c24ca812445bcdc13a03e2f3dc9e200f32..f96ae7a2efdf371d4b6451df25aeda483f741ede 100644 --- a/src/maple_me/src/alias_class.cpp +++ b/src/maple_me/src/alias_class.cpp @@ -131,12 +131,10 @@ AliasElem *AliasClass::CreateAliasElemsExpr(BaseNode &expr) { AliasElem *aliasElem = FindOrCreateExtraLevAliasElem(*iread.Opnd(0), iread.GetTyIdx(), iread.GetFieldID()); return &FindOrCreateAliasElemOfAddrofOSt(aliasElem->GetOriginalSt()); } - case OP_malloc: - case OP_gcmalloc: - return nullptr; case OP_add: case OP_sub: - case OP_array: { + case OP_array: + case OP_retype: { for (size_t i = 1; i < expr.NumOpnds(); ++i) { CreateAliasElemsExpr(*expr.Opnd(i)); } diff --git a/src/maple_me/src/irmap_emit.cpp b/src/maple_me/src/irmap_emit.cpp index 33554fb9c6596129528c70e9cfeb25c7e9621d85..1fc0e91ebe92ec844ab63f58e68911c7ca73166a 100644 --- a/src/maple_me/src/irmap_emit.cpp +++ b/src/maple_me/src/irmap_emit.cpp @@ -56,7 +56,7 @@ BaseNode &ConstMeExpr::EmitExpr(SSATab &ssaTab) { ssaTab.GetModule().CurFunction()->GetCodeMempool()->New(PrimType(GetPrimType()), constVal); // if int const has been promoted from dyn int const, remove the type tag if (IsPrimitiveInteger(exprConst->GetPrimType())) { - auto *intConst = static_cast(exprConst->GetConstVal()); + auto *intConst = safe_cast(exprConst->GetConstVal()); intConst->SetValue(intConst->GetValueUnderType()); } return *exprConst; diff --git a/src/maple_me/src/me_ir.cpp b/src/maple_me/src/me_ir.cpp index e7aec5d7893adfbfbb3c8e3cbf2e69141ee31739..9b54a3e89e82870dcf3bb1a48a6d4ba39faa89f9 100644 --- a/src/maple_me/src/me_ir.cpp +++ b/src/maple_me/src/me_ir.cpp @@ -277,6 +277,46 @@ bool MeExpr::IsAllOpndsIdentical(const MeExpr &meExpr) const { return true; } +bool OpMeExpr::IsAllOpndsIdentical(const OpMeExpr &meExpr) const { + // add/mul/or/xor/and/etc..., need not to consider opnd order + if (IsCommutative(meExpr.GetOp())) { + ASSERT(meExpr.GetNumOpnds() == 2, "not supported opcode: %d", meExpr.GetOp()); + return (meExpr.GetOpnd(0) == this->GetOpnd(0) && meExpr.GetOpnd(1) == this->GetOpnd(1)) || + (meExpr.GetOpnd(1) == this->GetOpnd(0) && meExpr.GetOpnd(0) == this->GetOpnd(1)); + } + return MeExpr::IsAllOpndsIdentical(meExpr); +} + +bool OpMeExpr::IsCompareIdentical(const OpMeExpr &meExpr) const { + // x > y <==> y < x; x <= y <==> y >= x; + switch (meExpr.GetOp()) { + case OP_ge: + if (this->GetOp() != OP_le) { + return false; + } + break; + case OP_le: + if (this->GetOp() != OP_ge) { + return false; + } + break; + case OP_gt: + if (this->GetOp() != OP_lt) { + return false; + } + break; + case OP_lt: + if (this->GetOp() != OP_gt) { + return false; + } + break; + default: + return false; + } + + return (meExpr.GetOpnd(1) == this->GetOpnd(0)) && (meExpr.GetOpnd(0) == this->GetOpnd(1)); +} + bool OpMeExpr::IsIdentical(const OpMeExpr &meExpr) const { if (meExpr.GetOp() != GetOp()) { return false; @@ -285,7 +325,15 @@ bool OpMeExpr::IsIdentical(const OpMeExpr &meExpr) const { meExpr.bitsSize != bitsSize || meExpr.tyIdx != tyIdx || meExpr.fieldID != fieldID) { return false; } - return IsAllOpndsIdentical(meExpr); + if (IsAllOpndsIdentical(meExpr)) { + return true; + } + + if (IsCompareIdentical(meExpr)) { + return true; + } + + return false; } bool NaryMeExpr::IsIdentical(NaryMeExpr &meExpr) const { @@ -515,7 +563,7 @@ bool ConstMeExpr::GtZero() const { if (constVal->GetKind() != kConstInt) { return false; } - return (static_cast(constVal)->GetValue() > 0); + return (safe_cast(constVal)->GetValue() > 0); } bool ConstMeExpr::IsZero() const { @@ -526,12 +574,12 @@ bool ConstMeExpr::IsOne() const { if (constVal->GetKind() != kConstInt) { return false; } - return (static_cast(constVal)->GetValue() == 1); + return (safe_cast(constVal)->GetValue() == 1); } int64 ConstMeExpr::GetIntValue() const { CHECK_FATAL(constVal->GetKind() == kConstInt, "expect int const"); - return static_cast(constVal)->GetValue(); + return safe_cast(constVal)->GetValue(); } MeExpr *ConstMeExpr::GetIdenticalExpr(MeExpr &expr) const { diff --git a/src/maple_util/include/mpl_number.h b/src/maple_util/include/mpl_number.h index 3ff2d5423fdd52e793c460d4182c4edafb0d8b31..c362b1e8ab011ab685d4711173af17d07ba8f4ee 100644 --- a/src/maple_util/include/mpl_number.h +++ b/src/maple_util/include/mpl_number.h @@ -16,7 +16,7 @@ #define MAPLE_UTIL_INCLUDE_MPL_NUMBER_H #include #include -#include "meta.h" +#include "utils/meta.h" namespace maple { namespace utils { @@ -175,7 +175,7 @@ inline Number operator+(const Number &lhs, const Number template inline Number operator-(const Number &lhs, const Number &rhs) { - return Number(lhs.get() + rhs.get()); + return Number(lhs.get() - rhs.get()); } template operator+(const U &lhs, const Number &rhs) { template ::value>> inline Number operator-(const Number &lhs, const U &rhs) { - return Number(lhs.get() + rhs); + return Number(lhs.get() - rhs); } template ::value>> inline Number operator-(const U &lhs, const Number &rhs) { - return Number(lhs + rhs.get()); + return Number(lhs - rhs.get()); } template diff --git a/src/maple_util/include/muid.h b/src/maple_util/include/muid.h index 37b286d547430203df868da0604f3d5aef1a5fc7..41664c06c8c8fba4447dc21fed7c334fb4230ebe 100644 --- a/src/maple_util/include/muid.h +++ b/src/maple_util/include/muid.h @@ -30,12 +30,6 @@ constexpr unsigned int kSystemNamespace = 0xc0; constexpr unsigned int kApkNamespace = 0x80; constexpr unsigned int kBitMask = 0x3f; -// For Lazy decoupling load -const uint32_t kMplLazyLoadMagicNumber = 0x1a2; // For trigger SIGSEGV -const uint32_t kMplStaticLazyLoadMagicNumber = 0x1a1; // For static lazy load trigger SIGSEGV -const uint64_t kMplLazyLoadSentryNumber = 0x1a27b10d10810ade; // Sentry for offset table -const uint64_t kMplStaticLazyLoadSentryNumber = 0x1a27b10d10810ad1; // Sentry for static offset table - #ifdef USE_64BIT_MUID #undef MUID_LENGTH #define MUID_LENGTH 8 diff --git a/src/maple_util/include/name_mangler.h b/src/maple_util/include/name_mangler.h index f334dcc254068790d2c13f445702fbea0be4369f..9f13e4ac9178a63e3f372f23d896f0b2868ec628 100644 --- a/src/maple_util/include/name_mangler.h +++ b/src/maple_util/include/name_mangler.h @@ -34,6 +34,7 @@ namespace NameMangler { #define PRIMITIVECLASSINFO_PREFIX __pinf_ #define CLASS_INIT_BRIDGE_PREFIX __ClassInitBridge__ #define GCTIB_PREFIX MCC_GCTIB__ +#define REF_PREFIX REF_ #define JARRAY_PREFIX A #define VTAB_PREFIX_STR TO_STR(VTAB_PREFIX) @@ -45,6 +46,7 @@ namespace NameMangler { #define PRIMITIVECLASSINFO_PREFIX_STR TO_STR(PRIMITIVECLASSINFO_PREFIX) #define CLASS_INIT_BRIDGE_PREFIX_STR TO_STR(CLASS_INIT_BRIDGE_PREFIX) #define GCTIB_PREFIX_STR TO_STR(GCTIB_PREFIX) +#define REF_PREFIX_STR TO_STR(REF_PREFIX) #define JARRAY_PREFIX_STR TO_STR(JARRAY_PREFIX) // Names of all compiler-generated tables and accessed by runtime diff --git a/src/maple_util/include/utils.h b/src/maple_util/include/utils.h index c0f9c78f9360b87c7603e191813d7043ef4dae42..04d2673286cd508df0ed233f0f0acd5de0f11f35 100644 --- a/src/maple_util/include/utils.h +++ b/src/maple_util/include/utils.h @@ -15,44 +15,32 @@ #ifndef MAPLE_UTIL_INCLUDE_UTILS_H #define MAPLE_UTIL_INCLUDE_UTILS_H #include +#include #include "mpl_logging.h" namespace maple { namespace utils { // Operations on char -inline constexpr bool IsDigit(char c) { +constexpr bool IsDigit(char c) { return (c >= '0' && c <= '9'); } -inline constexpr bool IsLower(char c) { +constexpr bool IsLower(char c) { return (c >= 'a' && c <= 'z'); } -inline constexpr bool IsUpper(char c) { +constexpr bool IsUpper(char c) { return (c >= 'A' && c <= 'Z'); } -inline constexpr bool IsAlpha(char c) { +constexpr bool IsAlpha(char c) { return (IsLower(c) || IsUpper(c)); } -inline constexpr bool IsAlnum(char c) { +constexpr bool IsAlnum(char c) { return (IsAlpha(c) || IsDigit(c)); } namespace __ToDigitImpl { -template -struct TypeMax {}; - -template <> -struct TypeMax { - enum {value = UINT8_MAX}; -}; - -template <> -struct TypeMax { - enum {value = INT32_MAX}; -}; - template struct ToDigitImpl {}; @@ -62,7 +50,7 @@ struct ToDigitImpl<10, T> { if (utils::IsDigit(c)) { return c - '0'; } - return TypeMax::value; + return std::numeric_limits::max(); } }; @@ -72,7 +60,7 @@ struct ToDigitImpl<8, T> { if (c >= '0' && c < '8') { return c - '0'; } - return TypeMax::value; + return std::numeric_limits::max(); } }; @@ -88,13 +76,13 @@ struct ToDigitImpl<16, T> { if (c >= 'A' && c <= 'F') { return c - 'A' + 10; } - return TypeMax::value; + return std::numeric_limits::max(); } }; } template -inline constexpr T ToDigit(char c) { +constexpr T ToDigit(char c) { return __ToDigitImpl::ToDigitImpl::DoIt(c); } diff --git a/src/maple_util/include/meta.h b/src/maple_util/include/utils/meta.h similarity index 43% rename from src/maple_util/include/meta.h rename to src/maple_util/include/utils/meta.h index 0b13debc524a603c17418b43b793b4b774645852..cb98f8d3a2f416899a1916908ab26831eee1301e 100644 --- a/src/maple_util/include/meta.h +++ b/src/maple_util/include/utils/meta.h @@ -17,9 +17,10 @@ #include namespace maple { namespace utils { + template struct meta_and - : public std::conditional_t {}; + : public std::conditional_t {}; template struct meta_or @@ -27,22 +28,18 @@ struct meta_or template struct meta_not - : public std::integral_constant {}; + : public std::integral_constant(T::value)>::type {}; template struct is_signed; -template <> -struct is_signed<> - : public std::true_type {}; - template struct is_signed - : public std::is_signed {}; + : public std::is_signed::type {}; template struct is_signed - : public meta_and, std::is_signed> {}; + : public meta_and, std::is_signed>::type {}; template constexpr bool is_signed_v = is_signed::value; @@ -50,27 +47,68 @@ constexpr bool is_signed_v = is_signed::value; template struct is_unsigned; -template <> -struct is_unsigned<> - : public std::true_type {}; - template struct is_unsigned - : public std::is_unsigned {}; + : public std::is_unsigned::type {}; template struct is_unsigned - : public meta_and, std::is_unsigned> {}; + : public meta_and, std::is_unsigned>::type {}; template constexpr bool is_unsigned_v = is_unsigned::value; template struct is_same_sign - : public meta_or, is_unsigned> {}; + : public meta_or, is_unsigned>::type {}; template struct is_diff_sign - : public meta_not> {}; + : public meta_not>::type {}; + +template +struct is_pointer; + +template +struct is_pointer + : std::is_pointer::type {}; + +template +struct is_pointer + : meta_and, is_pointer>::type {}; + +template +constexpr bool is_pointer_v = is_pointer::value; + +template +struct const_of + : meta_and, std::is_same, U>>::type {}; + +template +constexpr bool const_of_v = const_of::value; + +template +struct is_ncv_same + : std::is_same, std::remove_cv_t>::type {}; + +template +constexpr bool is_ncv_same_v = is_ncv_same::value; + +namespace ptr { +template >> +struct const_of + : utils::const_of, std::remove_pointer_t>::type {}; + +template >> +constexpr bool const_of_v = const_of::value; + +template >> +struct is_ncv_same + : utils::is_ncv_same, std::remove_pointer_t>::type {}; + +template >> +constexpr bool is_ncv_same_v = is_ncv_same::value; +} + }} -#endif //MAPLE_UTIL_INCLUDE_META_H +#endif //MAPLE_UTIL_INCLUDE_UTILS_META_H diff --git a/src/maple_util/include/version.h b/src/maple_util/include/version.h index c9cbaca24c481d8c91bf7726cc4e3e6d9ea21c18..4524cfebf077786192fc3316192606acbe2322ee 100644 --- a/src/maple_util/include/version.h +++ b/src/maple_util/include/version.h @@ -17,7 +17,7 @@ namespace Version { -static constexpr const int kMajorMplVersion = 2; +static constexpr const int kMajorMplVersion = 3; static constexpr const int kMinorCompilerVersion = 0; static constexpr const int kMinorRuntimeVersion = 0; diff --git a/src/mpl2mpl/include/vtable_analysis.h b/src/mpl2mpl/include/vtable_analysis.h index 975593914a6335baf7989f30f1ff9db57c88e31a..075bf7f34cfbee9351680d12f368279a2d04afec 100644 --- a/src/mpl2mpl/include/vtable_analysis.h +++ b/src/mpl2mpl/include/vtable_analysis.h @@ -20,8 +20,10 @@ namespace maple { #ifdef USE_32BIT_REF constexpr unsigned int kTabEntrySize = 4; +constexpr unsigned int kShiftCountBit = 4 * 4; // Get the low 16bit #else // !USE_32BIT_REF constexpr unsigned int kTabEntrySize = 8; +constexpr unsigned int kShiftCountBit = 8 * 4; // Get the low 32bit #endif // USE_32BIT_REF class VtableAnalysis : public FuncOptimizeImpl { diff --git a/src/mpl2mpl/src/java_eh_lower.cpp b/src/mpl2mpl/src/java_eh_lower.cpp index 14442589a259f4af7aaf58d40ee0f259de99d175..3c56ff4ee5ec91ef17705f82f26b0438ba6ca910 100644 --- a/src/mpl2mpl/src/java_eh_lower.cpp +++ b/src/mpl2mpl/src/java_eh_lower.cpp @@ -191,7 +191,7 @@ BlockNode *JavaEHLowerer::DoLowerBlock(BlockNode &block) { BaseNode *opnd0 = DoLowerExpr(*(tstmt->Opnd(0)), *newBlock); if (opnd0->GetOpCode() == OP_constval) { CHECK_FATAL(IsPrimitiveInteger(opnd0->GetPrimType()), "must be integer or something wrong"); - auto *intConst = static_cast(static_cast(opnd0)->GetConstVal()); + auto *intConst = safe_cast(static_cast(opnd0)->GetConstVal()); CHECK_FATAL(intConst->IsZero(), "can only be zero"); MIRFunction *func = GetMIRModule().GetMIRBuilder()->GetOrCreateFunction(strMCCThrowNullPointerException, TyIdx(PTY_void)); diff --git a/src/mpl2mpl/src/muid_replacement.cpp b/src/mpl2mpl/src/muid_replacement.cpp index 4b5a4da7db7a074708b175f4b86deeea7bb1b26a..df6f541a604849d99985fe3eb7705118d530aca3 100644 --- a/src/mpl2mpl/src/muid_replacement.cpp +++ b/src/mpl2mpl/src/muid_replacement.cpp @@ -315,12 +315,12 @@ void MUIDReplacement::GenerateFuncDefTable() { // Use the left 1 bit of muidIdx to mark whether the function is weak or not. 1 is for weak uint32 muidIdx = iter->second.second; constexpr uint32 weakFuncFlag = 0x80000000; // 0b10000000 00000000 00000000 00000000 - auto *indexConst = static_cast(muidIdxTabConst->GetConstVecItem(muidIdx)); + auto *indexConst = safe_cast(muidIdxTabConst->GetConstVecItem(muidIdx)); uint32 tempIdx = (static_cast(indexConst->GetValue()) & weakFuncFlag) | idx; indexConst = GetMIRModule().GetMemPool()->New(tempIdx, *GlobalTables::GetTypeTable().GetUInt32()); muidIdxTabConst->SetConstVecItem(muidIdx, *indexConst); if (reflectionList.find(mirFunc->GetName()) != reflectionList.end()) { - auto *tempConst = static_cast(muidIdxTabConst->GetConstVecItem(idx)); + auto *tempConst = safe_cast(muidIdxTabConst->GetConstVecItem(idx)); tempIdx = weakFuncFlag | static_cast(tempConst->GetValue()); tempConst = GetMIRModule().GetMemPool()->New(tempIdx, *GlobalTables::GetTypeTable().GetUInt32()); muidIdxTabConst->SetConstVecItem(idx, *tempConst); @@ -395,8 +395,8 @@ void MUIDReplacement::ReplaceMethodMetaFuncAddr(MIRSymbol &funcSymbol, int64 ind GlobalTables::GetStrTable().GetStrIdxFromName(NameMangler::kMethodAddrDataPrefixStr + symbolName)); CHECK_FATAL(methodAddrDataSt != nullptr, "methodAddrDataSt symbol is null."); MIRConst *mirConst = methodAddrDataSt->GetKonst(); - MIRAggConst *aggConst = static_cast(mirConst); - MIRAggConst *agg = static_cast(aggConst->GetConstVecItem(0)); + MIRAggConst *aggConst = safe_cast(mirConst); + MIRAggConst *agg = safe_cast(aggConst->GetConstVecItem(0)); MIRConst *elem = agg->GetConstVecItem(0); if (elem->GetKind() == kConstAddrofFunc) { MIRType &type = elem->GetType(); @@ -487,8 +487,8 @@ void MUIDReplacement::ReplaceFieldMetaStaticAddr(MIRSymbol &mirSymbol, int64 ind } return; } - MIRAggConst *aggConst = static_cast(fieldOffsetDataSt->GetKonst()); - MIRAggConst *agg = static_cast(aggConst->GetConstVecItem(0)); + MIRAggConst *aggConst = safe_cast(fieldOffsetDataSt->GetKonst()); + MIRAggConst *agg = safe_cast(aggConst->GetConstVecItem(0)); MIRConst *elem = agg->GetConstVecItem(0); CHECK_FATAL(elem->GetKind() == kConstAddrof, "static field must kConstAddrof."); @@ -741,7 +741,7 @@ void MUIDReplacement::ClearVtabItab(const std::string &name) { if (oldConst == nullptr || oldConst->GetKind() != kConstAggConst) { return; } - static_cast(oldConst)->GetConstVec().clear(); + safe_cast(oldConst)->GetConstVec().clear(); } void MUIDReplacement::ReplaceFuncTable(const std::string &name) { @@ -757,9 +757,9 @@ void MUIDReplacement::ReplaceFuncTable(const std::string &name) { if (tabSym->GetName().find(VTAB_PREFIX_STR) == 0) { isVtab = true; } - for (auto *&oldTabEntry : static_cast(oldConst)->GetConstVec()) { + for (auto *&oldTabEntry : safe_cast(oldConst)->GetConstVec()) { if (oldTabEntry->GetKind() == kConstAggConst) { - auto *aggrC = static_cast(oldTabEntry); + auto *aggrC = safe_cast(oldTabEntry); for (size_t i = 0; i < aggrC->GetConstVec().size(); ++i) { ReplaceAddroffuncConst(aggrC->GetConstVecItem(i), i + 1, isVtab); } @@ -774,7 +774,7 @@ void MUIDReplacement::ReplaceAddroffuncConst(MIRConst *&entry, uint32 fieldID, b return; } MIRType &voidType = *GlobalTables::GetTypeTable().GetVoidPtr(); - auto *funcAddr = static_cast(entry); + auto *funcAddr = safe_cast(entry); MIRFunction *func = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(funcAddr->GetValue()); uint64 offset = 0; MIRIntConst *constNode = nullptr; @@ -810,14 +810,14 @@ void MUIDReplacement::ReplaceDataTable(const std::string &name) { if (tabSym == nullptr) { return; } - auto *oldConst = static_cast(tabSym->GetKonst()); + auto *oldConst = safe_cast(tabSym->GetKonst()); if (oldConst == nullptr) { return; } for (MIRConst *&oldTabEntry : oldConst->GetConstVec()) { ASSERT(oldTabEntry != nullptr, "null ptr check!"); if (oldTabEntry->GetKind() == kConstAggConst) { - auto *aggrC = static_cast(oldTabEntry); + auto *aggrC = safe_cast(oldTabEntry); for (size_t i = 0; i < aggrC->GetConstVec().size(); ++i) { ASSERT(aggrC->GetConstVecItem(i) != nullptr, "null ptr check!"); ReplaceAddrofConst(aggrC->GetConstVecItem(i)); @@ -836,11 +836,11 @@ void MUIDReplacement::ReplaceDecoupleKeyTable(MIRAggConst* oldConst) { for (MIRConst *&oldTabEntry : oldConst->GetConstVec()) { ASSERT(oldTabEntry != nullptr, "null ptr check!"); if (oldTabEntry->GetKind() == kConstAggConst) { - auto *aggrC = static_cast(oldTabEntry); + auto *aggrC = safe_cast(oldTabEntry); for (size_t i = 0; i < aggrC->GetConstVec().size(); ++i) { ASSERT(aggrC->GetConstVecItem(i) != nullptr, "null ptr check!"); if (aggrC->GetConstVecItem(i)->GetKind() == kConstAggConst) { - ReplaceDecoupleKeyTable(static_cast(aggrC->GetConstVecItem(i))); + ReplaceDecoupleKeyTable(safe_cast(aggrC->GetConstVecItem(i))); } else { ReplaceAddrofConst(aggrC->GetConstVecItem(i)); aggrC->GetConstVecItem(i)->SetFieldID(i + 1); @@ -857,7 +857,7 @@ void MUIDReplacement::ReplaceAddrofConst(MIRConst *&entry) { return; } MIRType &voidType = *GlobalTables::GetTypeTable().GetVoidPtr(); - auto *addr = static_cast(entry); + auto *addr = safe_cast(entry); MIRSymbol *addrSym = GlobalTables::GetGsymTable().GetSymbolFromStidx(addr->GetSymbolIndex().Idx()); ASSERT(addrSym != nullptr, "Invalid MIRSymbol"); if (!addrSym->IsReflectionClassInfo() && !addrSym->IsStatic()) { @@ -1252,4 +1252,4 @@ void MUIDReplacement::GenerateTables() { ReplaceDataTable(NameMangler::kGcRootList); GenerateCompilerVersionNum(); } -} // namespace maple \ No newline at end of file +} // namespace maple diff --git a/src/mpl2mpl/src/reflection_analysis.cpp b/src/mpl2mpl/src/reflection_analysis.cpp index 8e49b87ee400aafb32705a436554033e834687b2..8df81da752a254cf5c61c4d92c20e59b68fce54b 100644 --- a/src/mpl2mpl/src/reflection_analysis.cpp +++ b/src/mpl2mpl/src/reflection_analysis.cpp @@ -1390,7 +1390,7 @@ void ReflectionAnalysis::GenClassMetaData(Klass &klass) { if (!hasAdded) { MIRSymbol *fieldsSt = GenFieldsMetaData(klass); if (fieldsSt != nullptr) { - numOfFields = static_cast(fieldsSt->GetKonst())->GetConstVec().size(); + numOfFields = safe_cast(fieldsSt->GetKonst())->GetConstVec().size(); // All meta data will be weak if dummy constructors. mirBuilder.AddAddrofFieldConst(classMetadataROType, *newConst, fieldID++, *fieldsSt); } else { @@ -1402,7 +1402,7 @@ void ReflectionAnalysis::GenClassMetaData(Klass &klass) { MIRSymbol *methodsSt; methodsSt = GenMethodsMetaData(klass); if (methodsSt != nullptr) { - numOfMethods = static_cast(methodsSt->GetKonst())->GetConstVec().size(); + numOfMethods = safe_cast(methodsSt->GetKonst())->GetConstVec().size(); mirBuilder.AddAddrofFieldConst(classMetadataROType, *newConst, fieldID++, *methodsSt); } else { mirBuilder.AddIntFieldConst(classMetadataROType, *newConst, fieldID++, 0); diff --git a/src/mpl2mpl/src/vtable_analysis.cpp b/src/mpl2mpl/src/vtable_analysis.cpp index e53cc6dbd5f27da68c35f37b00f41cca5d2ec817..5fb5cefd038eb7572a2aeb1394b0f875ac200e21 100644 --- a/src/mpl2mpl/src/vtable_analysis.cpp +++ b/src/mpl2mpl/src/vtable_analysis.cpp @@ -254,7 +254,7 @@ void VtableAnalysis::GenItableDefinition(const Klass &klass) { std::vector secondItab(kItabSecondHashSize, nullptr); std::vector secondConflictFlag(kItabSecondHashSize, false); std::vector secondConflictList; - uint32 count = 0; + uint64 count = 0; for (MIRFunction *func : firstConflictList) { ASSERT(func != nullptr, "null ptr check!"); uint32 secondHashCode = GetSecondHashIndex(DecodeBaseNameWithType(*func).c_str()); @@ -295,6 +295,7 @@ void VtableAnalysis::GenItableDefinition(const Klass &klass) { if (count != 0) { auto *secondItabEmitArray = GetMIRModule().GetMemPool()->New(GetMIRModule(), *voidPtrType); // remember count in secondItabVec + count = ((secondConflictList.size() | (1UL << (kShiftCountBit - 1))) << kShiftCountBit) + count; secondItabEmitArray->PushBack(GetMIRModule().GetMemPool()->New(count, *voidPtrType)); secondItabEmitArray->PushBack(oneConst); // padding for (uint32 i = 0; i < kItabSecondHashSize; ++i) {