diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn index 3e88d9f85bd835bbbad9a9c39321c9f0d782ed35..455c055bf2eea4ea22cd456840bd4d90674cd5e2 100644 --- a/build/config/BUILDCONFIG.gn +++ b/build/config/BUILDCONFIG.gn @@ -50,16 +50,24 @@ cflags = [] cflags_cc = [] cflags_c = [] if (GN_BUILD_TYPE == "RELEASE") { - cflags_cc += [ "-O2" ] - cflags_c += [ "-O2" ] + cflags_cc += [ + "-O2", + "-D_FORTIFY_SOURCE=2", + ] + cflags_c += [ + "-O2", + "-D_FORTIFY_SOURCE=2", + ] } else if (GN_BUILD_TYPE == "DEBUG") { cflags_cc += [ "-O0", "-g3", + "-fstack-check", ] cflags_c += [ "-O0", "-g3", + "-fstack-check", ] } else { cflags_cc += [ @@ -77,12 +85,14 @@ cflags_c += [ "-fstack-protector-strong", "-fPIC", "-fPIE", + "-fvisibility=hidden", ] cflags_cc += [ "-Wall", "-fstack-protector-strong", "-fPIC", "-fPIE", + "-fvisibility=hidden", ] if (HOST_ARCH == 64) { diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index 713f66180775ced14e066f7ad5cf57384279aa61..8cf35911375409c7a31cc1e449919aab9c43d5a0 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index 33d2c01e25116adf68821a76ffef63b6f88c9768..1e08905dd87656f0a22e3844b1690fd3c98277c0 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/deplibs/libmempool.a b/src/deplibs/libmempool.a index 5e9b75bfaf73fb004915be4a57fc6cb13e3987b2..f159c7b97a6eff3cc2447aa99d6d5edeac8c7d93 100644 Binary files a/src/deplibs/libmempool.a and b/src/deplibs/libmempool.a differ diff --git a/src/deplibs/libmplphase.a b/src/deplibs/libmplphase.a index a8ccd99e11d4dad6b8c90aa1e7c7213135ea6206..8928cdf1607e362a00bcda42ed7f4bfbc6d4887a 100644 Binary files a/src/deplibs/libmplphase.a and b/src/deplibs/libmplphase.a differ diff --git a/src/deplibs/libmplutil.a b/src/deplibs/libmplutil.a index d20f2bc4298f9facef2c2b15c20b718a655e0839..2da22b326b0d18630c511621742ff61b5308fb65 100644 Binary files a/src/deplibs/libmplutil.a and b/src/deplibs/libmplutil.a differ diff --git a/src/maple_driver/src/maple.cpp b/src/maple_driver/src/maple.cpp index 80821562ad6d444892ab0c42096a2f32b1a3333c..c531983f62c9a4301ed7bd062d065274691bfc1e 100644 --- a/src/maple_driver/src/maple.cpp +++ b/src/maple_driver/src/maple.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. @@ -18,36 +18,6 @@ #include "mpl_logging.h" using namespace maple; -void PrintErrorMessage(int ret) { - switch (ret) { - case kErrorNoError: - case kErrorExitHelp: - break; - case kErrorExit: - ERR(kLncErr, "Error Exit!"); - break; - case kErrorInvalidParameter: - ERR(kLncErr, "Invalid Parameter!"); - break; - case kErrorInitFail: - ERR(kLncErr, "Init Fail!"); - break; - case kErrorFileNotFound: - ERR(kLncErr, "File Not Found!"); - break; - case kErrorToolNotFound: - ERR(kLncErr, "Tool Not Found!"); - break; - case kErrorCompileFail: - ERR(kLncErr, "Compile Fail!"); - break; - case kErrorNotImplement: - ERR(kLncErr, "Not Implement!"); - break; - default: - break; - } -} int main(int argc, char **argv) { MplOptions mplOptions; diff --git a/src/maple_ipa/src/callgraph.cpp b/src/maple_ipa/src/callgraph.cpp index 14b82d1abb7cae799544860b9e92e1d7b1126075..571b6e864f5346a1f19fff11227e5564396e67d0 100644 --- a/src/maple_ipa/src/callgraph.cpp +++ b/src/maple_ipa/src/callgraph.cpp @@ -183,6 +183,7 @@ bool CGNode::IsCalleeOf(CGNode *func) { } void CallGraph::DelNode(CGNode *node) { + ASSERT_NOT_NULL(node); if (!node->GetMIRFunction()) { return; } @@ -533,7 +534,7 @@ void CallGraph::HandleBody(MIRFunction *func, BlockNode *body, CGNode *node, uin if (cands == nullptr) { for (Klass *implinterface : klass->GetImplInterfaces()) { cands = implinterface->GetCandidates(calleeFunc->GetBaseFuncNameWithTypeStrIdx()); - if (cands && !cands->empty()) { + if (cands != nullptr && !cands->empty()) { break; } } @@ -568,6 +569,7 @@ void CallGraph::HandleBody(MIRFunction *func, BlockNode *body, CGNode *node, uin } void CallGraph::UpdateCallGraphNode(CGNode *node) { + ASSERT_NOT_NULL(node); node->Reset(); MIRFunction *func = node->GetMIRFunction(); BlockNode *body = func->GetBody(); @@ -1050,7 +1052,7 @@ void DoDevirtual(const Klass *klass, const KlassHierarchy *klassh) { tmpKlass = klassh->GetKlassFromTyIdx(tmpType->GetTypeIndex()); } if (tmpKlass == nullptr && !isCurrVtabScalar) { - CHECK_FATAL(tmpKlass != nullptr, "null ptr check"); + CHECK_FATAL(false, "null ptr check"); } if (isCalleeScalar || isCurrVtabScalar) { if (isFindMethod) { @@ -1632,6 +1634,7 @@ void CallGraph::SCCTopologicalSort(std::vector &sccNodes) { void CGNode::AddCandsForCallNode(const KlassHierarchy *kh) { /* already set vcall candidates information */ + ASSERT_NOT_NULL(kh); if (HasSetVCallCandidates()) { return; } diff --git a/src/maple_ir/include/global_tables.h b/src/maple_ir/include/global_tables.h index 2b752cd58f07da6753cd7e017b9a2c08ee34a231..8f48e409ea021d5915b546cd56d97edf14453b00 100644 --- a/src/maple_ir/include/global_tables.h +++ b/src/maple_ir/include/global_tables.h @@ -191,6 +191,28 @@ class TypeTable { return typeTable.at(PTY_ptr); } +#ifdef USE_ARM32_MACRO + MIRType *GetUIntType() const { + ASSERT(PTY_u32 < typeTable.size(), "array index out of range"); + return typeTable.at(PTY_u32); + } + + MIRType *GetPtrType() const { + ASSERT(PTY_u32 < typeTable.size(), "array index out of range"); + return typeTable.at(PTY_u32); + } +#else + MIRType *GetUIntType() const { + ASSERT(PTY_u64 < typeTable.size(), "array index out of range"); + return typeTable.at(PTY_u64); + } + + MIRType *GetPtrType() const { + ASSERT(PTY_ptr < typeTable.size(), "array index out of range"); + return typeTable.at(PTY_ptr); + } +#endif + #ifdef USE_32BIT_REF MIRType *GetCompactPtr() const { ASSERT(PTY_u32 < typeTable.size(), "array index out of range"); diff --git a/src/maple_ir/include/metadata_layout.h b/src/maple_ir/include/metadata_layout.h index beb8a402f36c9dbf040a15d820853429335ff8e8..016518f22b8af930cd4569d2e32760db0b040ae0 100644 --- a/src/maple_ir/include/metadata_layout.h +++ b/src/maple_ir/include/metadata_layout.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. @@ -17,7 +17,6 @@ #include // metadata layout is shared between maple compiler and runtime, thus not in namespace maplert - // some of the reference field of metadata is stored as relative offset // for example, declaring class of Fields/Methods // which can be negative @@ -26,33 +25,6 @@ using MetaRef = uint32_t; // consistent with reffield_t in address.h #else using MetaRef = uintptr_t; // consistent iwth reffield_t in address.h #endif // USE_32BIT_REF - -static inline void *DecodeValueAsRelOffset32(const int32_t *addr) { - intptr_t realAddr = reinterpret_cast(addr) + *addr; - return reinterpret_cast(realAddr); -} - -static inline void *DecodeValueAsRelOffset64(const int64_t *addr) { - intptr_t realAddr = reinterpret_cast(addr) + *addr; - return reinterpret_cast(realAddr); -} - -static inline void EncodeValueAsRelOffset32(const void *value, int32_t *addr) { - int32_t offset = reinterpret_cast(value) - reinterpret_cast(addr); - *addr = offset; - if (DecodeValueAsRelOffset32(addr) != value) { - std::abort(); - } -} - -static inline void EncodeValueAsRelOffset64(const void *value, int64_t *addr) { - int64_t offset = reinterpret_cast(value) - reinterpret_cast(addr); - *addr = offset; - if (DecodeValueAsRelOffset64(addr) != value) { - std::abort(); - } -} - // DataRefOffset aims to represent a reference to data in maple file, which is already an offset. // DataRefOffset is meant to have pointer size and aligned to at least 4 bytes. struct DataRefOffset32 { @@ -102,7 +74,6 @@ struct DataRefOffset { DataRef is self-decoded by also encoding the format and is defined for binary compatibility. If no compatibility problem is involved, DataRefOffset64 is preferred. */ - enum DataRefFormat { kDataRefIsDirect = 0, // must be 0 kDataRefIsCompact = 1, // read-only @@ -211,7 +182,6 @@ struct MByteRef32 { // MethodMeta defined in MethodMeta.h // FieldMeta defined in FieldMeta.h - // MethodDesc contains MethodMetadata and stack map struct MethodDesc { // relative offset for method metadata relative to current PC. diff --git a/src/maple_ir/include/mir_function.h b/src/maple_ir/include/mir_function.h index 6209b2cd039efd663aa9a6e61aa085b035629225..8369293ba90f06bac00f186e8b468d5e6383907a 100644 --- a/src/maple_ir/include/mir_function.h +++ b/src/maple_ir/include/mir_function.h @@ -119,9 +119,11 @@ class MIRFunction { return GetReturnType()->GetPrimType() == PTY_void; } TyIdx GetReturnTyIdx() const { + CHECK_FATAL(funcType != nullptr, "funcType is nullptr"); return funcType->GetRetTyIdx(); } void SetReturnTyIdx(TyIdx tyidx) { + CHECK_FATAL(funcType != nullptr, "funcType is nullptr"); funcType->SetRetTyIdx(tyidx); } @@ -137,9 +139,11 @@ class MIRFunction { } size_t GetParamSize() const { + CHECK_FATAL(funcType != nullptr, "funcType is nullptr"); return funcType->GetParamTypeList().size(); } const MapleVector &GetParamTypes() const { + CHECK_FATAL(funcType != nullptr, "funcType is nullptr"); return funcType->GetParamTypeList(); } TyIdx GetNthParamTyIdx(size_t i) const { @@ -149,28 +153,33 @@ class MIRFunction { const MIRType *GetNthParamType(size_t i) const; MIRType *GetNthParamType(size_t i); const TypeAttrs &GetNthParamAttr(size_t i) const { + CHECK_FATAL(funcType != nullptr, "funcType is nullptr"); ASSERT(i < funcType->GetParamAttrsList().size(), "array index out of range"); return funcType->GetNthParamAttrs(i); } void SetNthParamAttr(size_t i, TypeAttrs attrs) { + CHECK_FATAL(funcType != nullptr, "funcType is nullptr"); ASSERT(i < funcType->GetParamAttrsList().size(), "array index out of range"); funcType->SetNthParamAttrs(i, attrs); } void SetNthParamAttrKind(size_t i, AttrKind x) const { + CHECK_FATAL(funcType != nullptr, "funcType is nullptr"); CHECK_FATAL(i < funcType->GetParamAttrsList().size(), "array index out of range"); funcType->GetNthParamAttrs(i).SetAttr(x); } void AddArgument(MIRSymbol *symbol) { formals.push_back(symbol); + CHECK_FATAL(funcType != nullptr, "funcType is nullptr"); funcType->GetParamTypeList().push_back(symbol->GetTyIdx()); funcType->GetParamAttrsList().push_back(symbol->GetAttrs()); } LabelIdx GetOrCreateLableIdxFromName(const std::string &name); GStrIdx GetLabelStringIndex(LabelIdx labelIdx) const { + CHECK_FATAL(labelTab != nullptr, "labelTab is nullptr"); ASSERT(labelIdx < labelTab->Size(), "index out of range in GetLabelStringIndex"); return labelTab->GetSymbolFromStIdx(labelIdx); } @@ -465,16 +474,20 @@ class MIRFunction { return typeNameTab != nullptr; } const MapleMap &GetGStrIdxToTyIdxMap() const { + CHECK_FATAL(typeNameTab != nullptr, "typeNameTab is nullptr"); return typeNameTab->GetGStrIdxToTyIdxMap(); } TyIdx GetTyIdxFromGStrIdx(GStrIdx idx) const { + CHECK_FATAL(typeNameTab != nullptr, "typeNameTab is nullptr"); return typeNameTab->GetTyIdxFromGStrIdx(idx); } void SetGStrIdxToTyIdx(GStrIdx gStrIdx, TyIdx tyIdx) { + CHECK_FATAL(typeNameTab != nullptr, "typeNameTab is nullptr"); typeNameTab->SetGStrIdxToTyIdx(gStrIdx, tyIdx); } const std::string &GetLabelTabItem(LabelIdx labelIdx) const { + CHECK_FATAL(labelTab != nullptr, "labelTab is nullptr"); return labelTab->GetName(labelIdx); } @@ -707,6 +720,7 @@ class MIRFunction { } size_t GetSymbolTabSize() const { + ASSERT(symTab != nullptr, "symTab is nullptr"); return symTab->GetSymbolTableSize(); } MIRSymbol *GetSymbolTabItem(uint32 idx, bool checkFirst = false) const { diff --git a/src/maple_ir/include/mir_module.h b/src/maple_ir/include/mir_module.h index 7352fdf255c00884ec922956cea25eb6b83abec9..ef7be317573905876633fb0e0c8b0b9b091d9aed 100644 --- a/src/maple_ir/include/mir_module.h +++ b/src/maple_ir/include/mir_module.h @@ -261,6 +261,10 @@ class MIRModule { return srcLang == kSrcLangC || srcLang == kSrcLangCPlusPlus; } + bool IsCharModule() const { + return false; + } + void addSuperCall(const std::string &func) { superCallSet.insert(func); } diff --git a/src/maple_ir/include/mir_pragma.h b/src/maple_ir/include/mir_pragma.h index 2e3599189091aabb5238a258da35cb1754f23447..5c5647a1865030e860e022c2ffbf220a8317615e 100644 --- a/src/maple_ir/include/mir_pragma.h +++ b/src/maple_ir/include/mir_pragma.h @@ -73,7 +73,7 @@ class MIRPragmaElement { explicit MIRPragmaElement(MIRModule &m) : MIRPragmaElement(m.GetPragmaMPAllocator()) {} explicit MIRPragmaElement(MapleAllocator &subElemAllocator) - : val{.u = 0}, subElemVec(subElemAllocator.Adapter()) { + : val{ 0 }, subElemVec(subElemAllocator.Adapter()) { subElemVec.clear(); } diff --git a/src/maple_ir/include/mir_preg.h b/src/maple_ir/include/mir_preg.h index d3a5f3bca2c355a923449cc9685bdba99293ed0a..53d308aa6a19c3a926875e7ff1488832a6cb15a0 100644 --- a/src/maple_ir/include/mir_preg.h +++ b/src/maple_ir/include/mir_preg.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. @@ -114,7 +114,7 @@ class MIRPregTable { uint32 index = pregIndex++; MIRPreg *preg = mAllocator->GetMemPool()->New(index); preg->SetPrimType(primType); - PregIdx idx = pregTable.size(); + PregIdx idx = static_cast(pregTable.size()); ASSERT(idx < USHRT_MAX, "will has problem if over 16 bits"); pregTable.push_back(preg); pregNoToPregIdxMap[index] = idx; @@ -135,7 +135,7 @@ class MIRPregTable { preg->SetPrimType(mirPreg.GetPrimType()); preg->SetMIRType(mirPreg.GetMIRType()); preg->SetNeedRC(mirPreg.NeedRC()); - PregIdx idx = pregTable.size(); + PregIdx idx = static_cast(pregTable.size()); ASSERT(idx < USHRT_MAX, "will has problem if over 16 bits"); pregTable.push_back(preg); pregNoToPregIdxMap[index] = idx; @@ -162,7 +162,7 @@ class MIRPregTable { void AddPreg(MIRPreg *preg) { CHECK_FATAL(preg != nullptr, "invalid nullptr in AddPreg"); - PregIdx idx = pregTable.size(); + PregIdx idx = static_cast(pregTable.size()); pregTable.push_back(preg); ASSERT(pregNoToPregIdxMap.find(preg->GetPregNo()) == pregNoToPregIdxMap.end(), "The same pregno is already taken"); pregNoToPregIdxMap[preg->GetPregNo()] = idx; diff --git a/src/maple_ir/include/types_def.h b/src/maple_ir/include/types_def.h index 0d3a3089f0bf32a5a5c49b4445589289ba880438..3d9be38a1b3bd6d4a69e80385e5ba8cb8bd179c1 100644 --- a/src/maple_ir/include/types_def.h +++ b/src/maple_ir/include/types_def.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. diff --git a/src/maple_ir/src/bin_mpl_import.cpp b/src/maple_ir/src/bin_mpl_import.cpp index 5794557e12ee919ad3e8999829a111d0d80655ca..feee24529cca4f4357fd6333acc118522c3ff8e5 100644 --- a/src/maple_ir/src/bin_mpl_import.cpp +++ b/src/maple_ir/src/bin_mpl_import.cpp @@ -86,16 +86,19 @@ void BinaryMplImport::ReadFileAt(const std::string &name, int32 offset) { CHECK_FATAL(seekRet == 0, "call fseek failed"); buf.resize(size); - long result = fread(&buf[0], sizeof(uint8), size, f); + size_t result = fread(&buf[0], sizeof(uint8), size, f); fclose(f); - CHECK_FATAL(result == size, "Error while reading the binary file: %s", name.c_str()); + CHECK_FATAL(result == static_cast(size), "Error while reading the binary file: %s", name.c_str()); } void BinaryMplImport::ImportConstBase(MIRConstKind &kind, MIRTypePtr &type, uint32 &fieldID) { kind = static_cast(ReadNum()); TyIdx tyidx = ImportType(); type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyidx); - fieldID = ReadNum(); + int64 tmp = ReadNum(); + CHECK_FATAL(tmp <= INT_MAX, "num out of range"); + CHECK_FATAL(tmp >= INT_MIN, "num out of range"); + fieldID = static_cast(tmp); } MIRConst *BinaryMplImport::ImportConst(MIRFunction *func) { @@ -874,7 +877,7 @@ void BinaryMplImport::ReadContentField() { } void BinaryMplImport::Jump2NextField() { - uint32 totalSize = ReadInt(); + uint32 totalSize = static_cast(ReadInt()); bufI += (totalSize - sizeof(uint32)); ReadNum(); // skip end tag for this field } diff --git a/src/maple_ir/src/mir_const.cpp b/src/maple_ir/src/mir_const.cpp index 823969af826524e4b34920e393180fbaa4ee0a71..3749c4a220dcc87332807b93d2ef0e5a7a0c53e7 100644 --- a/src/maple_ir/src/mir_const.cpp +++ b/src/maple_ir/src/mir_const.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. @@ -62,7 +62,7 @@ uint8 MIRIntConst::GetBitWidth() const { } void MIRIntConst::Trunc(uint8 width) { - int32 shiftBitNum = 64u - width; + const int32 shiftBitNum = 64u - width; if (shiftBitNum < 0) { CHECK_FATAL(false, "shiftBitNum should not be less than zero"); } @@ -76,7 +76,7 @@ void MIRIntConst::Trunc(uint8 width) { int64 MIRIntConst::GetValueUnderType() const { uint32 bitSize = GetPrimTypeBitSize(GetNonDynType(GetType().GetPrimType())); - int32 shiftBitNum = 64u - bitSize; + const int32 shiftBitNum = 64u - bitSize; if (shiftBitNum < 0) { CHECK_FATAL(false, "shiftBitNum should not be less than zero"); } diff --git a/src/maple_ir/src/mir_function.cpp b/src/maple_ir/src/mir_function.cpp index b2abce61eeba6f611c4723aedc12bdbc5f31e65d..d81f7dd7a09996f4be68a047c82ed947d07143d8 100644 --- a/src/maple_ir/src/mir_function.cpp +++ b/src/maple_ir/src/mir_function.cpp @@ -75,6 +75,7 @@ const std::string &MIRFunction::GetSignature() const { } const MIRType *MIRFunction::GetReturnType() const { + CHECK_FATAL(funcType != nullptr, "funcType should not be nullptr"); return GlobalTables::GetTypeTable().GetTypeFromTyIdx(funcType->GetRetTyIdx()); } MIRType *MIRFunction::GetReturnType() { @@ -84,6 +85,7 @@ const MIRType *MIRFunction::GetClassType() const { return GlobalTables::GetTypeTable().GetTypeFromTyIdx(classTyIdx); } const MIRType *MIRFunction::GetNthParamType(size_t i) const { + CHECK_FATAL(funcType != nullptr, "funcType should not be nullptr"); ASSERT(i < funcType->GetParamTypeList().size(), "array index out of range"); return GlobalTables::GetTypeTable().GetTypeFromTyIdx(funcType->GetParamTypeList()[i]); } diff --git a/src/maple_ir/src/mir_module.cpp b/src/maple_ir/src/mir_module.cpp index 3a18b35a0943eca5e4882775d896ed1353dc65ee..8ae10a7b4af298efa068e84c08d188ddf6fce3a7 100644 --- a/src/maple_ir/src/mir_module.cpp +++ b/src/maple_ir/src/mir_module.cpp @@ -67,10 +67,12 @@ MemPool *MIRModule::CurFuncCodeMemPool() const { } MapleAllocator *MIRModule::CurFuncCodeMemPoolAllocator() const { + CHECK_FATAL(curFunction != nullptr, "curFunction is null"); return &curFunction->GetCodeMempoolAllocator(); } MapleAllocator &MIRModule::GetCurFuncCodeMPAllocator() const { + CHECK_FATAL(curFunction != nullptr, "curFunction is null"); return curFunction->GetCodeMPAllocator(); } diff --git a/src/maple_ir/src/mir_nodes.cpp b/src/maple_ir/src/mir_nodes.cpp index 5ea835ce80c978816401993c90e16577fa7c6687..2a1b62b4950b1fda5e9902daec25f423cc046087 100644 --- a/src/maple_ir/src/mir_nodes.cpp +++ b/src/maple_ir/src/mir_nodes.cpp @@ -447,6 +447,7 @@ void ArrayNode::Dump(int32 indent) const { } bool ArrayNode::IsSameBase(ArrayNode *arry) { + ASSERT(arry != nullptr, "null ptr check"); if (arry == this) { return true; } @@ -922,7 +923,7 @@ void DumpCallReturns(const MIRModule &mod, CallReturnVector nrets, int32 indent) if (!regFieldPair.IsReg()) { const MIRSymbol *st = mirFunc->GetLocalOrGlobalSymbol(stIdx); ASSERT(st != nullptr, "st is null"); - uint16 fieldID = regFieldPair.GetFieldID(); + FieldID fieldID = regFieldPair.GetFieldID(); LogInfo::MapleLogger() << " { dassign "; LogInfo::MapleLogger() << (stIdx.Islocal() ? "%" : "$"); LogInfo::MapleLogger() << st->GetName() << " " << fieldID << " }\n"; @@ -943,7 +944,7 @@ void DumpCallReturns(const MIRModule &mod, CallReturnVector nrets, int32 indent) StIdx stIdx = (it)->first; RegFieldPair regFieldPair = it->second; if (!regFieldPair.IsReg()) { - uint16 fieldID = regFieldPair.GetFieldID(); + FieldID fieldID = regFieldPair.GetFieldID(); LogInfo::MapleLogger() << "dassign"; const MIRSymbol *st = mirFunc->GetLocalOrGlobalSymbol(stIdx); ASSERT(st != nullptr, "st is null"); diff --git a/src/maple_ir/src/parser.cpp b/src/maple_ir/src/parser.cpp index 72c88e915b64a6c56214278ce5f1f655cb2496e6..075f7fb74c4ca4014f3a417f041eda9767b6678a 100644 --- a/src/maple_ir/src/parser.cpp +++ b/src/maple_ir/src/parser.cpp @@ -114,7 +114,9 @@ PregIdx MIRParser::LookupOrCreatePregIdx(uint32 pregNo, bool isRef, MIRFunction if (isRef) { preg->SetPrimType(PTY_ref); } - idx = pRegTab->GetPregTable().size(); + size_t pregIndex = pRegTab->GetPregTable().size(); + CHECK_FATAL(pregIndex <= INT_MAX, "pregIndex out of range"); + idx = static_cast(pregIndex); pRegTab->GetPregTable().push_back(preg); pRegTab->SetPregNoToPregIdxMapItem(pregNo, idx); } @@ -224,12 +226,12 @@ const std::string &MIRParser::GetWarning() const { bool MIRParser::ParseSpecialReg(PregIdx &pRegIdx) { const std::string &lexName = lexer.GetName(); - int32 lexSize = lexName.size(); - int32 retValSize = strlen(kLexerStringRetval); + size_t lexSize = lexName.size(); + size_t retValSize = strlen(kLexerStringRetval); if (strncmp(lexName.c_str(), kLexerStringRetval, retValSize) == 0 && (lexSize > retValSize) && isdigit(lexName[retValSize])) { int32 retValNo = lexName[retValSize] - '0'; - for (int32 i = retValSize + 1; (i < lexSize) && isdigit(lexName[i]); ++i) { + for (size_t i = retValSize + 1; (i < lexSize) && isdigit(lexName[i]); ++i) { retValNo = retValNo * 10 + lexName[i] - '0'; } pRegIdx = -kSregRetval0 - retValNo; @@ -315,7 +317,7 @@ bool MIRParser::ParseFarrayType(TyIdx &arrayTyIdx) { return false; } ASSERT(tyIdx != 0u, "error encountered parsing flexible array element type "); - if (mod.IsJavaModule()) { + if (mod.IsJavaModule() || mod.IsCharModule()) { MIRJarrayType jarrayType(tyIdx); arrayTyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&jarrayType); } else { @@ -517,7 +519,7 @@ bool MIRParser::ParsePragmaElementForAnnotation(MIRPragmaElement &elem) { Error("parsing pragma error: expecting , but get "); return false; } - for (int i = 0; i < size; ++i) { + for (int64 i = 0; i < size; ++i) { auto *e0 = mod.GetMemPool()->New(mod); tk = lexer.NextToken(); if (tk != TK_label) { diff --git a/src/maple_me/include/me_inequality_graph.h b/src/maple_me/include/me_inequality_graph.h index b9b437125bbf81950e58deb3bba17660d8faccd5..795630dc9458a689fdd1537ff2298789f365b420 100644 --- a/src/maple_me/include/me_inequality_graph.h +++ b/src/maple_me/include/me_inequality_graph.h @@ -366,6 +366,7 @@ class ABCD { } return kFalse; } + static ProveResult Min(ProveResult res1, ProveResult res2) { if (res1 == kFalse || res2 == kFalse) { return kFalse; @@ -375,10 +376,11 @@ class ABCD { } return kReduced; } + bool DemandProve(ESSABaseNode &firstNode, ESSABaseNode &secondNode, EdgeType edgeType); ProveResult Prove(ESSABaseNode &a, ESSABaseNode &b, InequalEdge &e); ProveResult UpdateCacheResult(ESSABaseNode &a, ESSABaseNode &b, InequalEdge &e, MeetFunction meet); - void PrintTracing(); + void PrintTracing() const; InequalityGraph *inequalityGraph; std::map active; std::vector tracing; diff --git a/src/maple_me/include/me_ir.h b/src/maple_me/include/me_ir.h index aa13c90ddc27202f82bcf2c604b4417cdac127ac..f12d59f0c75a8e3cede89295aefc910d758691a7 100644 --- a/src/maple_me/include/me_ir.h +++ b/src/maple_me/include/me_ir.h @@ -637,20 +637,25 @@ class ConstMeExpr : public MeExpr { MeExpr *GetIdenticalExpr(MeExpr &expr) const override; uint32 GetHashIndex() const override { + CHECK_FATAL(constVal != nullptr, "constVal is null"); if (constVal->GetKind() == kConstInt) { auto *intConst = safe_cast(constVal); + CHECK_NULL_FATAL(intConst); return intConst->GetValue(); } if (constVal->GetKind() == kConstFloatConst) { auto *floatConst = safe_cast(constVal); + CHECK_NULL_FATAL(floatConst); return floatConst->GetIntValue(); } if (constVal->GetKind() == kConstDoubleConst) { auto *doubleConst = safe_cast(constVal); + CHECK_NULL_FATAL(doubleConst); return doubleConst->GetIntValue(); } if (constVal->GetKind() == kConstLblConst) { auto *lblConst = safe_cast(constVal); + CHECK_NULL_FATAL(lblConst); return lblConst->GetValue(); } ASSERT(false, "ComputeHash: const type not yet implemented"); diff --git a/src/maple_me/include/me_loop_analysis.h b/src/maple_me/include/me_loop_analysis.h index 83e30becb85892582742732e148372f662737bd4..2ec728e19999cf9f258d6c4ca92de1da9a081b48 100644 --- a/src/maple_me/include/me_loop_analysis.h +++ b/src/maple_me/include/me_loop_analysis.h @@ -62,7 +62,7 @@ class IdentifyLoops : public AnalysisResult { void SetLoopParent4BB(const BB &bb, LoopDesc &loopDesc); void ProcessBB(BB *bb); void MarkBB(); - void Dump(); + void Dump() const; private: MemPool *meLoopMemPool; diff --git a/src/maple_me/include/me_ssa_lpre.h b/src/maple_me/include/me_ssa_lpre.h index 480439ca989e9c75c857662fa4974c2fcfdd837b..d0927f187886892bc8f01ac60c8d475e0ccc7358 100644 --- a/src/maple_me/include/me_ssa_lpre.h +++ b/src/maple_me/include/me_ssa_lpre.h @@ -82,7 +82,6 @@ class MeSSALPre : public SSAPre { class MeDoSSALPre : public MeFuncPhase { public: explicit MeDoSSALPre(MePhaseID id) : MeFuncPhase(id) {} - virtual ~MeDoSSALPre() = default; AnalysisResult *Run(MeFunction *irFunc, MeFuncResultMgr *funcMgr, ModuleResultMgr *moduleMgr) override; std::string PhaseName() const override { diff --git a/src/maple_me/include/occur.h b/src/maple_me/include/occur.h index f589be93b089f0e10bc21b28753bd2a8e6771262..724549849b093b268aa14c32fb4ccfd03e896910 100644 --- a/src/maple_me/include/occur.h +++ b/src/maple_me/include/occur.h @@ -480,8 +480,8 @@ class MePhiOcc : public MeOccur { bool isExtraneous; bool isRemoved; // during finalize2, marked this phiocc is removed or not MapleVector phiOpnds; - MeRegPhiNode *regPhi; // the reg phi being inserted. TODO: maybe can delete it later - MeVarPhiNode *varPhi; // the Var phi being inserted. TODO: maybe can delete it later + MeRegPhiNode *regPhi; // the reg phi being inserted, maybe can delete it later + MeVarPhiNode *varPhi; // the Var phi being inserted, maybe can delete it later }; // each singly linked list repersents each bucket in workCandHashTable diff --git a/src/maple_me/include/orig_symbol.h b/src/maple_me/include/orig_symbol.h index cc7b2bd5280488ef8b506fae5433c1495b2ab3a7..fe3edd9ad34b4f6ba5d4760ab8dc9d191ea0b150 100644 --- a/src/maple_me/include/orig_symbol.h +++ b/src/maple_me/include/orig_symbol.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. @@ -54,6 +54,7 @@ class OriginalSt { ASSERT(ostType == kSymbolOst, "OriginalSt must be SymbolOst"); return symOrPreg.mirSt; } + MIRSymbol *GetMIRSymbol() { ASSERT(ostType == kSymbolOst, "OriginalSt must be SymbolOst"); return symOrPreg.mirSt; @@ -228,6 +229,39 @@ class OriginalSt { PUIdx puIdx; }; +class SymbolFieldPair { + public: + SymbolFieldPair(uint32 stIndex, FieldID fld) : stIdx(stIndex), fldID(fld) {} + ~SymbolFieldPair() = default; + bool operator==(const SymbolFieldPair& pairA) const { + return (pairA.stIdx == stIdx) && (pairA.fldID == fldID); + } + + uint32 GetSymbolIndex() const { + return stIdx; + } + + FieldID GetFieldID() const { + return fldID; + } + private: + uint32 stIdx; + FieldID fldID; +}; + +struct HashSymbolFieldPair { + size_t operator()(const SymbolFieldPair& symbolFldID) const { + return symbolFldID.GetSymbolIndex(); + } +}; + +struct EqualSymbolFieldPair { + bool operator()(const SymbolFieldPair& symbolFldIDA, const SymbolFieldPair& symbolFldIDB) const { + return symbolFldIDA.GetSymbolIndex() == symbolFldIDB.GetSymbolIndex() && + symbolFldIDA.GetFieldID() == symbolFldIDB.GetFieldID(); + } +}; + // This Table is for original symobols only. There is no SSA info attached and SSA is built based on this table. class OriginalStTable { public: @@ -304,7 +338,7 @@ class OriginalStTable { MIRModule &mirModule; MapleVector originalStVector; // the vector that map a OriginalSt's index to its pointer // mir symbol to original table, this only exists for no-original variables. - MapleUnorderedMap mirSt2Ost; + MapleUnorderedMap mirSt2Ost; MapleUnorderedMap preg2Ost; // mir type to virtual variables in original table. this only exists for no-original variables. MapleMap pType2Ost; diff --git a/src/maple_me/include/ssa_mir_nodes.h b/src/maple_me/include/ssa_mir_nodes.h index 3939e5c83cb416fbcf7c3bdee7b9997cd7f7da15..31b680ef197d7e4396c31164e5ff0800c3bbf92f 100644 --- a/src/maple_me/include/ssa_mir_nodes.h +++ b/src/maple_me/include/ssa_mir_nodes.h @@ -188,6 +188,7 @@ class AccessSSANodes { } virtual void InsertMayDefNode(VersionSt *vst, StmtNode *stmtNode) { + CHECK_FATAL(vst != nullptr, "null ptr check"); GetMayDefNodes().insert(std::make_pair(vst->GetOrigSt()->GetIndex(), MayDefNode(vst, stmtNode))); } diff --git a/src/maple_me/src/alias_class.cpp b/src/maple_me/src/alias_class.cpp index 150b53ac910e5840813f306a75a381da874c51e6..227ed66af90b37bffaa5fbf10a84b1c31ef61791 100644 --- a/src/maple_me/src/alias_class.cpp +++ b/src/maple_me/src/alias_class.cpp @@ -406,6 +406,7 @@ void AliasClass::UnionForNotAllDefsSeen() { } } + // fabricate the imaginary not_all_def_seen AliasElem AliasElem *AliasClass::FindOrCreateDummyNADSAe() { MIRSymbol *dummySym = mirModule.GetMIRBuilder()->GetOrCreateSymbol(TyIdx(PTY_i32), "__nads_dummysym__", kStVar, @@ -720,13 +721,15 @@ void AliasClass::InsertMayUseAll(const StmtNode &stmt) { void AliasClass::CollectMayDefForDassign(const StmtNode &stmt, std::set &mayDefOsts) { AliasElem *lhsAe = osym2Elem.at(ssaTab.GetStmtsSSAPart().GetAssignedVarOf(stmt)->GetOrigIdx()); + FieldID fldIDA = lhsAe->GetOriginalSt().GetFieldID(); ASSERT(lhsAe != nullptr, "aliaselem of lhs should not be null"); if (lhsAe->GetClassSet() != nullptr) { for (unsigned int elemID : *(lhsAe->GetClassSet())) { if (elemID != lhsAe->GetClassID()) { OriginalSt &ostOfAliasAE = id2Elem[elemID]->GetOriginalSt(); - if (ostOfAliasAE.GetTyIdx() == lhsAe->GetOriginalSt().GetMIRSymbol()->GetTyIdx()) { - mayDefOsts.insert(&ostOfAliasAE); + FieldID fldIDB = ostOfAliasAE.GetFieldID(); + if (fldIDA == fldIDB || fldIDA == 0 || fldIDB == 0) { + (void)mayDefOsts.insert(&ostOfAliasAE); } } } diff --git a/src/maple_me/src/bb.cpp b/src/maple_me/src/bb.cpp index 70aab5c5b61465098db873a981faf0f56f91a4e3..28eaeebe246cf945347b2d2770127362cd3c7613 100644 --- a/src/maple_me/src/bb.cpp +++ b/src/maple_me/src/bb.cpp @@ -147,6 +147,7 @@ int BB::RemoveBBFromVector(MapleVector &bbVec) const { } void BB::RemoveBBFromPred(BB *bb) { + CHECK_NULL_FATAL(bb); int index = bb->RemoveBBFromVector(pred); ASSERT(index != -1, "-1 is a very large number in BB::RemoveBBFromPred"); for (auto &phi : phiList) { @@ -164,6 +165,7 @@ void BB::RemoveBBFromPred(BB *bb) { } void BB::RemoveBBFromSucc(BB *bb) { + CHECK_NULL_FATAL(bb); bb->RemoveBBFromVector(succ); } diff --git a/src/maple_me/src/dse.cpp b/src/maple_me/src/dse.cpp index 8caa9052e5a8de4ee35a8fc3afdebfa5eb1f48a1..5a74d9d2b6083f578876f048933823a2729378f1 100644 --- a/src/maple_me/src/dse.cpp +++ b/src/maple_me/src/dse.cpp @@ -201,9 +201,9 @@ void DSE::PropagateUseLive(const VersionSt &vst) { MarkStmtRequired(ToRef(mayDef->GetStmt()), ToRef(dfBB)); AddToWorkList(verSt); } else { - const MustDefNode *mustdef = vst.GetMustDef(); - ASSERT(mustdef->GetResult() == &vst, "MarkVst: wrong corresponding version st in mustdef"); - MarkStmtRequired(ToRef(mustdef->GetStmt()), ToRef(dfBB)); + const MustDefNode *mustDef = vst.GetMustDef(); + ASSERT(mustDef->GetResult() == &vst, "MarkVst: wrong corresponding version st in mustDef"); + MarkStmtRequired(ToRef(mustDef->GetStmt()), ToRef(dfBB)); } } diff --git a/src/maple_me/src/me_alias_class.cpp b/src/maple_me/src/me_alias_class.cpp index 5b76df69275adb4ae8ab84781809f555b1f6ab60..4441f0fee4c337a02915b4dfe05c27a0660a3135 100644 --- a/src/maple_me/src/me_alias_class.cpp +++ b/src/maple_me/src/me_alias_class.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. @@ -58,7 +58,7 @@ void MeAliasClass::DoAliasAnalysis() { UnionForNotAllDefsSeen(); } // TBAA - if (!MeOption::noTBAA) { + if (!MeOption::noTBAA && mirModule.IsJavaModule()) { ReconstructAliasGroups(); } CreateClassSets(); diff --git a/src/maple_me/src/me_bypath_eh.cpp b/src/maple_me/src/me_bypath_eh.cpp index 72128b8c3e18e78c48a5ded9bff56ce809bd984f..c66989d35e6554c4f4be3803c891365eefa2a28e 100644 --- a/src/maple_me/src/me_bypath_eh.cpp +++ b/src/maple_me/src/me_bypath_eh.cpp @@ -127,7 +127,7 @@ StmtNode *MeDoBypathEH::IsSyncExit(BB &syncBB, MeFunction &func, LabelIdx second break; } } - if (stmt->GetOpCode() != OP_dassign) { + if (stmt == nullptr || stmt->GetOpCode() != OP_dassign) { return nullptr; } auto *dassignNode = static_cast(stmt); diff --git a/src/maple_me/src/me_function.cpp b/src/maple_me/src/me_function.cpp index 743ae038c3c8226f4bf470160b16d244da4b05b6..0b2b904e4dfd634f9f16a023081235c7f62ef49e 100644 --- a/src/maple_me/src/me_function.cpp +++ b/src/maple_me/src/me_function.cpp @@ -420,6 +420,7 @@ void MeFunction::Prepare(unsigned long rangeNum) { } void MeFunction::Verify() const { + CHECK_FATAL(theCFG != nullptr, "theCFG is null"); theCFG->Verify(); theCFG->VerifyLabels(); } diff --git a/src/maple_me/src/me_inequality_graph.cpp b/src/maple_me/src/me_inequality_graph.cpp index 7f272513c80f0354ec2bc53010364beaf1345554..41e41f6340bed03b4bdf6e121434e4d86729b5c2 100644 --- a/src/maple_me/src/me_inequality_graph.cpp +++ b/src/maple_me/src/me_inequality_graph.cpp @@ -15,417 +15,399 @@ #include "me_inequality_graph.h" namespace maple { - ESSAConstNode *InequalityGraph::GetOrCreateConstNode(int value) { - if (HasNode(value)) { - return static_cast(constNodes[value].get()); - } - std::unique_ptr newConstNode = std::make_unique(GetValidID(), value); - CHECK_FATAL(newConstNode != nullptr, "new failed"); - ESSAConstNode *newConst = newConstNode.get(); - constNodes[value] = std::move(newConstNode); - return newConst; +ESSAConstNode *InequalityGraph::GetOrCreateConstNode(int value) { + if (HasNode(value)) { + return static_cast(constNodes[value].get()); } + std::unique_ptr newConstNode = std::make_unique(GetValidID(), value); + CHECK_FATAL(newConstNode != nullptr, "new failed"); + ESSAConstNode *newConst = newConstNode.get(); + constNodes[value] = std::move(newConstNode); + return newConst; +} - ESSAVarNode *InequalityGraph::GetOrCreateVarNode(MeExpr &meExpr) { - if (HasNode(meExpr)) { - return static_cast(varNodes[meExpr.GetExprID()].get()); - } - CHECK_FATAL(meExpr.GetMeOp() == kMeOpVar || meExpr.GetMeOp() == kMeOpIvar, "meExpr must be VarMeExpr"); - std::unique_ptr newVarNode = std::make_unique(GetValidID(), meExpr); - CHECK_FATAL(newVarNode != nullptr, "new failed"); - ESSAVarNode *newVar = newVarNode.get(); - varNodes[meExpr.GetExprID()] = std::move(newVarNode); - return newVar; +ESSAVarNode *InequalityGraph::GetOrCreateVarNode(MeExpr &meExpr) { + if (HasNode(meExpr)) { + return static_cast(varNodes[meExpr.GetExprID()].get()); } + CHECK_FATAL(meExpr.GetMeOp() == kMeOpVar || meExpr.GetMeOp() == kMeOpIvar, "meExpr must be VarMeExpr"); + std::unique_ptr newVarNode = std::make_unique(GetValidID(), meExpr); + CHECK_FATAL(newVarNode != nullptr, "new failed"); + ESSAVarNode *newVar = newVarNode.get(); + varNodes[meExpr.GetExprID()] = std::move(newVarNode); + return newVar; +} - ESSAPhiNode *InequalityGraph::GetOrCreatePhiNode(MeVarPhiNode &phiNode) { - MeExpr *expr = phiNode.GetLHS(); - CHECK_FATAL(expr != nullptr, "meExpr phiNode must has lhs"); - if (HasNode(*expr)) { - return static_cast(varNodes[expr->GetExprID()].get()); - } - CHECK_FATAL(expr->GetMeOp() == kMeOpVar, "meExpr must be VarMeExpr"); - std::unique_ptr newPhiNode = std::make_unique(GetValidID(), *expr); - CHECK_FATAL(newPhiNode != nullptr, "new failed"); - newPhiNode->SetPhiOpnds(phiNode.GetOpnds()); - ESSAPhiNode *newPhi = newPhiNode.get(); - varNodes[expr->GetExprID()] = std::move(newPhiNode); - for (VarMeExpr *phiRHS : phiNode.GetOpnds()) { - ESSABaseNode *rhs = nullptr; - if (phiRHS->GetDefBy() != kDefByPhi) { - rhs = GetOrCreateVarNode(*phiRHS); - } else { - MeVarPhiNode *defPhi = &(phiRHS->GetDefPhi()); - rhs = GetOrCreatePhiNode(*defPhi); - } - AddPhiEdge(*rhs, *newPhi, EdgeType::kUpper); - AddPhiEdge(*newPhi, *rhs, EdgeType::kLower); - } - CHECK_FATAL(newPhi->GetPhiOpnds().size() == newPhi->GetInPhiEdgeMap().size(), "must be"); - return newPhi; +ESSAPhiNode *InequalityGraph::GetOrCreatePhiNode(MeVarPhiNode &phiNode) { + MeExpr *expr = phiNode.GetLHS(); + CHECK_FATAL(expr != nullptr, "meExpr phiNode must has lhs"); + if (HasNode(*expr)) { + return static_cast(varNodes[expr->GetExprID()].get()); } - - ESSAArrayNode *InequalityGraph::GetOrCreateArrayNode(MeExpr &meExpr) { - if (HasNode(meExpr)) { - return static_cast(varNodes[meExpr.GetExprID()].get()); + CHECK_FATAL(expr->GetMeOp() == kMeOpVar, "meExpr must be VarMeExpr"); + std::unique_ptr newPhiNode = std::make_unique(GetValidID(), *expr); + CHECK_FATAL(newPhiNode != nullptr, "new failed"); + newPhiNode->SetPhiOpnds(phiNode.GetOpnds()); + ESSAPhiNode *newPhi = newPhiNode.get(); + varNodes[expr->GetExprID()] = std::move(newPhiNode); + for (VarMeExpr *phiRHS : phiNode.GetOpnds()) { + ESSABaseNode *rhs = nullptr; + if (phiRHS->GetDefBy() != kDefByPhi) { + rhs = GetOrCreateVarNode(*phiRHS); + } else { + MeVarPhiNode *defPhi = &(phiRHS->GetDefPhi()); + rhs = GetOrCreatePhiNode(*defPhi); } - CHECK_FATAL(meExpr.GetMeOp() == kMeOpVar, "meExpr must be VarMeExpr"); - std::unique_ptr newArrayNode = std::make_unique(GetValidID(), meExpr); - CHECK_FATAL(newArrayNode != nullptr, "new failed"); - ESSAArrayNode *newArray = newArrayNode.get(); - varNodes[meExpr.GetExprID()] = std::move(newArrayNode); - return newArray; + AddPhiEdge(*rhs, *newPhi, EdgeType::kUpper); + AddPhiEdge(*newPhi, *rhs, EdgeType::kLower); } + CHECK_FATAL(newPhi->GetPhiOpnds().size() == newPhi->GetInPhiEdgeMap().size(), "must be"); + return newPhi; +} - InequalEdge *InequalityGraph::AddEdge(ESSABaseNode &from, ESSABaseNode &to, int value, EdgeType type) { - InequalEdge tmpEdge = InequalEdge(value, type); - InequalEdge *edge = HasEdge(from, to, tmpEdge); - if (edge != nullptr) { - return edge; - } - std::unique_ptr e = std::make_unique(value, type); - InequalEdge *ePtr = e.get(); - CHECK_FATAL(e != nullptr, "new failed"); - from.InsertOutWithConstEdgeMap(to, *e); - to.InsertInWithConstEdgeMap(from, *e); - from.InsertEdges(std::move(e)); - return ePtr; +ESSAArrayNode *InequalityGraph::GetOrCreateArrayNode(MeExpr &meExpr) { + if (HasNode(meExpr)) { + return static_cast(varNodes[meExpr.GetExprID()].get()); } + CHECK_FATAL(meExpr.GetMeOp() == kMeOpVar, "meExpr must be VarMeExpr"); + std::unique_ptr newArrayNode = std::make_unique(GetValidID(), meExpr); + CHECK_FATAL(newArrayNode != nullptr, "new failed"); + ESSAArrayNode *newArray = newArrayNode.get(); + varNodes[meExpr.GetExprID()] = std::move(newArrayNode); + return newArray; +} - void InequalityGraph::AddPhiEdge(ESSABaseNode &from, ESSABaseNode &to, EdgeType type) { - std::unique_ptr edge = std::make_unique(0, type); - CHECK_FATAL(edge != nullptr, "new failed"); - if (type == EdgeType::kUpper) { - from.InsertOutWithConstEdgeMap(to, *edge); - CHECK_FATAL(to.GetKind() == kPhiNode, "must be"); - static_cast(to).InsertInPhiEdgeMap(from, *edge); - from.InsertEdges(std::move(edge)); - } else { - CHECK_FATAL(from.GetKind() == kPhiNode, "must be"); - static_cast(from).InsertOutPhiEdgeMap(to, *edge); - to.InsertInWithConstEdgeMap(from, *edge); - from.InsertEdges(std::move(edge)); - } +InequalEdge *InequalityGraph::AddEdge(ESSABaseNode &from, ESSABaseNode &to, int value, EdgeType type) { + InequalEdge tmpEdge = InequalEdge(value, type); + InequalEdge *edge = HasEdge(from, to, tmpEdge); + if (edge != nullptr) { + return edge; } + std::unique_ptr e = std::make_unique(value, type); + InequalEdge *ePtr = e.get(); + CHECK_FATAL(e != nullptr, "new failed"); + from.InsertOutWithConstEdgeMap(to, *e); + to.InsertInWithConstEdgeMap(from, *e); + from.InsertEdges(std::move(e)); + return ePtr; +} - void InequalityGraph::AddEdge(ESSABaseNode &from, ESSABaseNode &to, MeExpr &value, bool positive, EdgeType type) { - InequalEdge tmpEdge = InequalEdge(value, positive, type); - if (HasEdge(from, to, tmpEdge)) { - return; - } - std::unique_ptr edge = std::make_unique(value, positive, type); - CHECK_FATAL(edge != nullptr, "new failed"); - from.InsertOutWithVarEdgeMap(to, *edge); - to.InsertInWithVarEdgeMap(from, *edge); +void InequalityGraph::AddPhiEdge(ESSABaseNode &from, ESSABaseNode &to, EdgeType type) { + std::unique_ptr edge = std::make_unique(0, type); + CHECK_FATAL(edge != nullptr, "new failed"); + if (type == EdgeType::kUpper) { + from.InsertOutWithConstEdgeMap(to, *edge); + CHECK_FATAL(to.GetKind() == kPhiNode, "must be"); + static_cast(to).InsertInPhiEdgeMap(from, *edge); + from.InsertEdges(std::move(edge)); + } else { + CHECK_FATAL(from.GetKind() == kPhiNode, "must be"); + static_cast(from).InsertOutPhiEdgeMap(to, *edge); + to.InsertInWithConstEdgeMap(from, *edge); from.InsertEdges(std::move(edge)); } +} - bool InequalityGraph::HasNode(const MeExpr &meExpr) const { - return varNodes.find(meExpr.GetExprID()) != varNodes.end(); +void InequalityGraph::AddEdge(ESSABaseNode &from, ESSABaseNode &to, MeExpr &value, bool positive, EdgeType type) { + InequalEdge tmpEdge = InequalEdge(value, positive, type); + if (HasEdge(from, to, tmpEdge)) { + return; } + std::unique_ptr edge = std::make_unique(value, positive, type); + CHECK_FATAL(edge != nullptr, "new failed"); + from.InsertOutWithVarEdgeMap(to, *edge); + to.InsertInWithVarEdgeMap(from, *edge); + from.InsertEdges(std::move(edge)); +} - bool InequalityGraph::HasNode(int32 value) const { - return constNodes.find(value) != constNodes.end(); - } +bool InequalityGraph::HasNode(const MeExpr &meExpr) const { + return varNodes.find(meExpr.GetExprID()) != varNodes.end(); +} - void InequalityGraph::ConnectTrivalEdge() { - int32 prevValue = 0; - ESSABaseNode* prevNode = nullptr; - for (auto &pair : constNodes) { - int32 value = pair.first; - ESSABaseNode* node = pair.second.get(); - if (prevNode == nullptr) { - prevValue = value; - prevNode = node; - continue; - } - CHECK_FATAL(value > prevValue, "must be"); - InequalEdge *pairEdge1 = AddEdge(*node, *prevNode, prevValue - value, EdgeType::kNone); - InequalEdge *pairEdge2 = AddEdge(*prevNode, *node, value - prevValue, EdgeType::kNone); - pairEdge1->SetPairEdge(*pairEdge2); - pairEdge2->SetPairEdge(*pairEdge1); +bool InequalityGraph::HasNode(int32 value) const { + return constNodes.find(value) != constNodes.end(); +} + +void InequalityGraph::ConnectTrivalEdge() { + int32 prevValue = 0; + ESSABaseNode* prevNode = nullptr; + for (auto &pair : constNodes) { + int32 value = pair.first; + ESSABaseNode* node = pair.second.get(); + if (prevNode == nullptr) { prevValue = value; prevNode = node; + continue; } + CHECK_FATAL(value > prevValue, "must be"); + InequalEdge *pairEdge1 = AddEdge(*node, *prevNode, prevValue - value, EdgeType::kNone); + InequalEdge *pairEdge2 = AddEdge(*prevNode, *node, value - prevValue, EdgeType::kNone); + pairEdge1->SetPairEdge(*pairEdge2); + pairEdge2->SetPairEdge(*pairEdge1); + prevValue = value; + prevNode = node; } +} - ESSABaseNode &InequalityGraph::GetNode(const MeExpr &meExpr) { - CHECK_FATAL(HasNode(meExpr), "node is not created"); - return *varNodes[meExpr.GetExprID()]; - } +ESSABaseNode &InequalityGraph::GetNode(const MeExpr &meExpr) { + CHECK_FATAL(HasNode(meExpr), "node is not created"); + return *varNodes[meExpr.GetExprID()]; +} - ESSABaseNode &InequalityGraph::GetNode(int32 value) { - CHECK_FATAL(HasNode(value), "node is not created"); - return *constNodes[value]; - } +ESSABaseNode &InequalityGraph::GetNode(int32 value) { + CHECK_FATAL(HasNode(value), "node is not created"); + return *constNodes[value]; +} - InequalEdge *InequalityGraph::HasEdge(ESSABaseNode &from, ESSABaseNode &to, InequalEdge &type) const { - auto miter = from.GetOutWithConstEdgeMap().equal_range(&to); - for (auto it = miter.first; it != miter.second; ++it) { - if (it->second->IsSame(type)) { - return it->second; - } +InequalEdge *InequalityGraph::HasEdge(ESSABaseNode &from, ESSABaseNode &to, InequalEdge &type) const { + auto miter = from.GetOutWithConstEdgeMap().equal_range(&to); + for (auto it = miter.first; it != miter.second; ++it) { + if (it->second->IsSame(type)) { + return it->second; } - miter = from.GetOutWithVarEdgeMap().equal_range(&to); - for (auto it = miter.first; it != miter.second; ++it) { - if (it->second->IsSame(type)) { - return it->second; - } + } + miter = from.GetOutWithVarEdgeMap().equal_range(&to); + for (auto it = miter.first; it != miter.second; ++it) { + if (it->second->IsSame(type)) { + return it->second; } - return nullptr; } + return nullptr; +} - std::string InequalityGraph::GetName(const MeExpr &meExpr, IRMap &irMap) const { - std::string name; - MeExprOp meOp = meExpr.GetMeOp(); - CHECK_FATAL(meOp == kMeOpVar, "must be VarMeExpr"); - const auto *varMeExpr = static_cast(&meExpr); - MIRSymbol *sym = irMap.GetSSATab().GetMIRSymbolFromID(varMeExpr->GetOStIdx()); - name = sym->GetName() + "\\nmx" + std::to_string(meExpr.GetExprID()); - return name; - } +std::string InequalityGraph::GetName(const MeExpr &meExpr, IRMap &irMap) const { + std::string name; + MeExprOp meOp = meExpr.GetMeOp(); + CHECK_FATAL(meOp == kMeOpVar, "must be VarMeExpr"); + const auto *varMeExpr = static_cast(&meExpr); + MIRSymbol *sym = irMap.GetSSATab().GetMIRSymbolFromID(varMeExpr->GetOStIdx()); + name = sym->GetName() + "\\nmx" + std::to_string(meExpr.GetExprID()); + return name; +} - std::string InequalityGraph::GetName(ESSABaseNode &node, IRMap &irMap) const { - std::string name; - if (node.GetKind() == kConstNode) { - return std::to_string((*static_cast(&node)).GetValue()); - } - const MeExpr *meExpr = &(node.GetMeExpr()); - CHECK_FATAL(meExpr != nullptr, "meExpr is nullptr"); - const VarMeExpr *varMeExpr = nullptr; - if (meExpr->GetMeOp() == kMeOpVar) { - varMeExpr = static_cast(meExpr); - } else if (meExpr->GetMeOp() == kMeOpIvar) { - const auto *ivarMeExpr = static_cast(meExpr); - const MeExpr *base = ivarMeExpr->GetBase(); - if (base->GetMeOp() == kMeOpVar) { - varMeExpr = static_cast(base); - } else { - name = "ivar" + std::to_string(ivarMeExpr->GetExprID()); - return name; - } +std::string InequalityGraph::GetName(ESSABaseNode &node, IRMap &irMap) const { + std::string name; + if (node.GetKind() == kConstNode) { + return std::to_string((*static_cast(&node)).GetValue()); + } + const MeExpr *meExpr = &(node.GetMeExpr()); + CHECK_FATAL(meExpr != nullptr, "meExpr is nullptr"); + const VarMeExpr *varMeExpr = nullptr; + if (meExpr->GetMeOp() == kMeOpVar) { + varMeExpr = static_cast(meExpr); + } else if (meExpr->GetMeOp() == kMeOpIvar) { + const auto *ivarMeExpr = static_cast(meExpr); + const MeExpr *base = ivarMeExpr->GetBase(); + if (base->GetMeOp() == kMeOpVar) { + varMeExpr = static_cast(base); + } else { + name = "ivar" + std::to_string(ivarMeExpr->GetExprID()); + return name; } - MIRSymbol *sym = irMap.GetSSATab().GetMIRSymbolFromID(varMeExpr->GetOStIdx()); - name = sym->GetName() + "\\nmx" + std::to_string(meExpr->GetExprID()); - if (node.GetKind() == kArrayNode) { - name += ".length"; - } else if (node.GetKind() == kPhiNode) { - name += " = phi("; - for (auto iter = (*static_cast(&node)).GetPhiOpnds().begin(); - iter != (*static_cast(&node)).GetPhiOpnds().end(); ++iter) { - name += "mx" + std::to_string((*iter)->GetExprID()) + ", "; - } - name += ")"; + } + MIRSymbol *sym = irMap.GetSSATab().GetMIRSymbolFromID(varMeExpr->GetOStIdx()); + name = sym->GetName() + "\\nmx" + std::to_string(meExpr->GetExprID()); + if (node.GetKind() == kArrayNode) { + name += ".length"; + } else if (node.GetKind() == kPhiNode) { + name += " = phi("; + for (auto iter = (*static_cast(&node)).GetPhiOpnds().begin(); + iter != (*static_cast(&node)).GetPhiOpnds().end(); ++iter) { + name += "mx" + std::to_string((*iter)->GetExprID()) + ", "; } - name += "\\nID: " + std::to_string(node.GetID()); - return name; + name += ")"; } + name += "\\nID: " + std::to_string(node.GetID()); + return name; +} - std::string InequalityGraph::GetColor(EdgeType type) const { - switch (type) { - case kUpper: - return "color = red"; - case kUpperInvalid: - return "color = red, style=dashed"; - case kLower: - return "color = blue"; - case kLowerInvalid: - return "color = blue, style=dashed"; - case kNone: - return "color = black"; - case kNoneInValid: - return "color = black, style=dashed"; - } +std::string InequalityGraph::GetColor(EdgeType type) const { + switch (type) { + case kUpper: + return "color = red"; + case kUpperInvalid: + return "color = red, style=dashed"; + case kLower: + return "color = blue"; + case kLowerInvalid: + return "color = blue, style=dashed"; + case kNone: + return "color = black"; + case kNoneInValid: + return "color = black, style=dashed"; } +} - void InequalityGraph::DumpDotEdges(IRMap &irMap, const std::pair &map, - std::ostream &out, std::string &from) const { - if (map.second->IsVarValue()) { - std::string to = GetName(*(map.first), irMap); - std::string positive = map.second->GetVarValue().IsPositive() ? "" : "-"; - std::string color = GetColor(map.second->GetEdgeType()); - out << "\"" << from << "\" -> \"" << to << "\" "; - out << "[label=\"" << positive << GetName(map.second->GetVarValue().GetVarMeExpr(), irMap) - << "\" " << color << "];\n"; - } else { - std::string to = GetName(*(map.first), irMap); - std::string color = GetColor(map.second->GetEdgeType()); - out << "\"" << from << "\" -> \"" << to << "\" "; - out << "[label=\"" << map.second->GetConstValue() << "\" " << color << "];\n"; - } +void InequalityGraph::DumpDotEdges(IRMap &irMap, const std::pair &map, + std::ostream &out, std::string &from) const { + if (map.second->IsVarValue()) { + std::string to = GetName(*(map.first), irMap); + std::string positive = map.second->GetVarValue().IsPositive() ? "" : "-"; + std::string color = GetColor(map.second->GetEdgeType()); + out << "\"" << from << "\" -> \"" << to << "\" "; + out << "[label=\"" << positive << GetName(map.second->GetVarValue().GetVarMeExpr(), irMap) + << "\" " << color << "];\n"; + } else { + std::string to = GetName(*(map.first), irMap); + std::string color = GetColor(map.second->GetEdgeType()); + out << "\"" << from << "\" -> \"" << to << "\" "; + out << "[label=\"" << map.second->GetConstValue() << "\" " << color << "];\n"; } +} - void InequalityGraph::DumpDotNodes(IRMap &irMap, std::ostream &out, DumpType dumpType, - const std::map> &nodes) const { - for (auto iter = nodes.begin(); iter != nodes.end(); ++iter) { - std::string from = GetName(*(iter->second), irMap); - out << "\"" << from << "\";\n"; - for (auto iterConstEdges = iter->second.get()->GetOutWithConstEdgeMap().begin(); - iterConstEdges != iter->second.get()->GetOutWithConstEdgeMap().end(); ++iterConstEdges) { +void InequalityGraph::DumpDotNodes(IRMap &irMap, std::ostream &out, DumpType dumpType, + const std::map> &nodes) const { + for (auto iter = nodes.begin(); iter != nodes.end(); ++iter) { + std::string from = GetName(*(iter->second), irMap); + out << "\"" << from << "\";\n"; + for (auto iterConstEdges = iter->second.get()->GetOutWithConstEdgeMap().begin(); + iterConstEdges != iter->second.get()->GetOutWithConstEdgeMap().end(); ++iterConstEdges) { + EdgeType edgeType = iterConstEdges->second->GetEdgeType(); + if (dumpType == kDumpNone) { + DumpDotEdges(irMap, *iterConstEdges, out, from); + } else if ((dumpType == kDumpUpperAndNone) && + (edgeType == kUpper || edgeType == kNone || edgeType == kUpperInvalid || edgeType == kNoneInValid)) { + DumpDotEdges(irMap, *iterConstEdges, out, from); + } else if ((dumpType == kDumpLowerAndNone) && + (edgeType == kLower || edgeType == kNone || edgeType == kLowerInvalid || edgeType == kNoneInValid)) { + DumpDotEdges(irMap, *iterConstEdges, out, from); + } + } + if (iter->second.get()->GetKind() == kPhiNode) { + auto *phiNode = static_cast(iter->second.get()); + for (auto iterConstEdges = phiNode->GetOutPhiEdgeMap().begin(); + iterConstEdges != phiNode->GetOutPhiEdgeMap().end(); ++iterConstEdges) { EdgeType edgeType = iterConstEdges->second->GetEdgeType(); if (dumpType == kDumpNone) { DumpDotEdges(irMap, *iterConstEdges, out, from); } else if ((dumpType == kDumpUpperAndNone) && - (edgeType == kUpper || edgeType == kNone || edgeType == kUpperInvalid || edgeType == kNoneInValid)) { + (edgeType == kUpper || edgeType == kNone || + edgeType == kUpperInvalid || edgeType == kNoneInValid)) { DumpDotEdges(irMap, *iterConstEdges, out, from); } else if ((dumpType == kDumpLowerAndNone) && - (edgeType == kLower || edgeType == kNone || edgeType == kLowerInvalid || edgeType == kNoneInValid)) { + (edgeType == kLower || edgeType == kNone || + edgeType == kLowerInvalid || edgeType == kNoneInValid)) { DumpDotEdges(irMap, *iterConstEdges, out, from); } } - if (iter->second.get()->GetKind() == kPhiNode) { - auto *phiNode = static_cast(iter->second.get()); - for (auto iterConstEdges = phiNode->GetOutPhiEdgeMap().begin(); - iterConstEdges != phiNode->GetOutPhiEdgeMap().end(); ++iterConstEdges) { - EdgeType edgeType = iterConstEdges->second->GetEdgeType(); - if (dumpType == kDumpNone) { - DumpDotEdges(irMap, *iterConstEdges, out, from); - } else if ((dumpType == kDumpUpperAndNone) && - (edgeType == kUpper || edgeType == kNone || - edgeType == kUpperInvalid || edgeType == kNoneInValid)) { - DumpDotEdges(irMap, *iterConstEdges, out, from); - } else if ((dumpType == kDumpLowerAndNone) && - (edgeType == kLower || edgeType == kNone || - edgeType == kLowerInvalid || edgeType == kNoneInValid)) { - DumpDotEdges(irMap, *iterConstEdges, out, from); - } - } - } - for (auto iterVarEdges = iter->second.get()->GetOutWithVarEdgeMap().begin(); - iterVarEdges != iter->second.get()->GetOutWithVarEdgeMap().end(); ++iterVarEdges) { - EdgeType edgeType = iterVarEdges->second->GetEdgeType(); - if (dumpType == kDumpNone) { - DumpDotEdges(irMap, *iterVarEdges, out, from); - } else if ((dumpType == kDumpUpperAndNone) && - (edgeType == kUpper || edgeType == kNone || edgeType == kUpperInvalid || edgeType == kNoneInValid)) { - DumpDotEdges(irMap, *iterVarEdges, out, from); - } else if ((dumpType == kDumpLowerAndNone) && - (edgeType == kLower || edgeType == kNone || edgeType == kLowerInvalid || edgeType == kNoneInValid)) { - DumpDotEdges(irMap, *iterVarEdges, out, from); - } + } + for (auto iterVarEdges = iter->second.get()->GetOutWithVarEdgeMap().begin(); + iterVarEdges != iter->second.get()->GetOutWithVarEdgeMap().end(); ++iterVarEdges) { + EdgeType edgeType = iterVarEdges->second->GetEdgeType(); + if (dumpType == kDumpNone) { + DumpDotEdges(irMap, *iterVarEdges, out, from); + } else if ((dumpType == kDumpUpperAndNone) && + (edgeType == kUpper || edgeType == kNone || edgeType == kUpperInvalid || edgeType == kNoneInValid)) { + DumpDotEdges(irMap, *iterVarEdges, out, from); + } else if ((dumpType == kDumpLowerAndNone) && + (edgeType == kLower || edgeType == kNone || edgeType == kLowerInvalid || edgeType == kNoneInValid)) { + DumpDotEdges(irMap, *iterVarEdges, out, from); } } } +} - void InequalityGraph::DumpDotFile(IRMap &irMap, DumpType dumpType) const { - std::filebuf fileBuf; - std::string dumpT = dumpType == kDumpUpperAndNone ? "Upper_" : "Lower_"; - std::string outFile = dumpT + meFunction->GetName() + "-inequalityGraph.dot"; - fileBuf.open(outFile, std::ios::trunc | std::ios::out); - std::ostream essaDotFile(&fileBuf); - essaDotFile << "digraph InequalityGraph {\n"; - DumpDotNodes(irMap, essaDotFile, dumpType, constNodes); - DumpDotNodes(irMap, essaDotFile, dumpType, varNodes); - essaDotFile << "}\n"; - fileBuf.close(); - } +void InequalityGraph::DumpDotFile(IRMap &irMap, DumpType dumpType) const { + std::filebuf fileBuf; + std::string dumpT = dumpType == kDumpUpperAndNone ? "Upper_" : "Lower_"; + std::string outFile = dumpT + meFunction->GetName() + "-inequalityGraph.dot"; + fileBuf.open(outFile, std::ios::trunc | std::ios::out); + std::ostream essaDotFile(&fileBuf); + essaDotFile << "digraph InequalityGraph {\n"; + DumpDotNodes(irMap, essaDotFile, dumpType, constNodes); + DumpDotNodes(irMap, essaDotFile, dumpType, varNodes); + essaDotFile << "}\n"; + fileBuf.close(); +} - bool ABCD::DemandProve(const MeExpr &arrayNode, const MeExpr &idx) { - ESSABaseNode &aNode = inequalityGraph->GetNode(arrayNode); - ESSABaseNode *idxNode = nullptr; - if (idx.GetMeOp() == kMeOpVar) { - idxNode = &(inequalityGraph->GetNode(idx)); - } else { - CHECK_FATAL(idx.GetMeOp() == kMeOpConst, "must be"); - idxNode = &(inequalityGraph->GetNode(static_cast(idx).GetIntValue())); - } - ESSABaseNode &zNode = inequalityGraph->GetNode(0); - bool upperResult = ABCD::DemandProve(aNode, *idxNode, kUpper); - bool lowerResult = ABCD::DemandProve(zNode, *idxNode, kLower); - return upperResult && lowerResult; +bool ABCD::DemandProve(const MeExpr &arrayNode, const MeExpr &idx) { + ESSABaseNode &aNode = inequalityGraph->GetNode(arrayNode); + ESSABaseNode *idxNode = nullptr; + if (idx.GetMeOp() == kMeOpVar) { + idxNode = &(inequalityGraph->GetNode(idx)); + } else { + CHECK_FATAL(idx.GetMeOp() == kMeOpConst, "must be"); + idxNode = &(inequalityGraph->GetNode(static_cast(idx).GetIntValue())); } + ESSABaseNode &zNode = inequalityGraph->GetNode(0); + bool upperResult = ABCD::DemandProve(aNode, *idxNode, kUpper); + bool lowerResult = ABCD::DemandProve(zNode, *idxNode, kLower); + return upperResult && lowerResult; +} - bool ABCD::DemandProve(ESSABaseNode &firstNode, ESSABaseNode &secondNode, EdgeType edgeType) { - std::unique_ptr e = - std::make_unique(edgeType == kUpper ? kUpperBound : kLowerBound, edgeType); - active.clear(); - ProveResult res = Prove(firstNode, secondNode, *e.get()); - return res == kTrue; +bool ABCD::DemandProve(ESSABaseNode &firstNode, ESSABaseNode &secondNode, EdgeType edgeType) { + std::unique_ptr e = + std::make_unique(edgeType == kUpper ? kUpperBound : kLowerBound, edgeType); + active.clear(); + ProveResult res = Prove(firstNode, secondNode, *e.get()); + return res == kTrue; +} + +void ABCD::PrintTracing() const { + for (size_t i = 0; i < tracing.size(); i++) { + std::cout << "Traversing Node : " << tracing[i]->GetExprID() << '\n'; } + std::cout << '\n'; +} - void ABCD::PrintTracing() { - for (size_t i = 0; i < tracing.size(); i++) { - std::cout << "Traversing Node : " << tracing[i]->GetExprID() << '\n'; - } - std::cout << '\n'; +ProveResult ABCD::Prove(ESSABaseNode &aNode, ESSABaseNode &bNode, InequalEdge &edge) { + ++recursiveCount; + if (recursiveCount > kDFSLimit) { + return kFalse; } - ProveResult ABCD::Prove(ESSABaseNode &aNode, ESSABaseNode &bNode, InequalEdge &edge) { - ++recursiveCount; - if (recursiveCount > kDFSLimit) { + tracing.push_back(&bNode); + if (&aNode == &bNode) { + if (edge.GreaterEqual(0)) { + tracing.pop_back(); + return kTrue; + } else { + tracing.pop_back(); return kFalse; } - - tracing.push_back(&bNode); - if (&aNode == &bNode) { - if (edge.GreaterEqual(0)) { - tracing.pop_back(); - return kTrue; - } else { - tracing.pop_back(); - return kFalse; - } - } - bool hasPreNode = false; - auto constEdge = (edge.GetEdgeType() == kUpper) ? bNode.GetInWithConstEdgeMap() : bNode.GetOutWithConstEdgeMap(); - for (auto iter = constEdge.begin(); iter != constEdge.end(); ++iter) { - if (iter->second->GetEdgeType() == edge.GetEdgeType() || iter->second->GetEdgeType() == EdgeType::kNone) { - hasPreNode = true; - break; - } - } - if (bNode.GetKind() == kPhiNode) { + } + bool hasPreNode = false; + auto constEdge = (edge.GetEdgeType() == kUpper) ? bNode.GetInWithConstEdgeMap() : bNode.GetOutWithConstEdgeMap(); + for (auto iter = constEdge.begin(); iter != constEdge.end(); ++iter) { + if (iter->second->GetEdgeType() == edge.GetEdgeType() || iter->second->GetEdgeType() == EdgeType::kNone) { hasPreNode = true; + break; } - if (!hasPreNode) { + } + if (bNode.GetKind() == kPhiNode) { + hasPreNode = true; + } + if (!hasPreNode) { + tracing.pop_back(); + return kFalse; + } + + if (active.find(&bNode) != active.end()) { + if (active.find(&bNode)->second->LessEqual(edge)) { + tracing.pop_back(); + return kReduced; + } else { tracing.pop_back(); return kFalse; } - - if (active.find(&bNode) != active.end()) { - if (active.find(&bNode)->second->LessEqual(edge)) { - tracing.pop_back(); - return kReduced; - } else { - tracing.pop_back(); - return kFalse; - } - } - - active[&bNode] = &edge; - ProveResult res = bNode.GetKind() == kPhiNode ? UpdateCacheResult(aNode, bNode, edge, Min) - : UpdateCacheResult(aNode, bNode, edge, Max); - active.erase(&bNode); - tracing.pop_back(); - return res; } - ProveResult ABCD::UpdateCacheResult(ESSABaseNode &aNode, ESSABaseNode &bNode, InequalEdge &edge, MeetFunction meet) { - ProveResult res = meet == Min ? kReduced : kFalse; - if (meet == Min) { - CHECK_FATAL(bNode.GetKind() == kPhiNode, "must be"); - auto& bPhiNode = static_cast(bNode); - auto constEdgeMap = (edge.GetEdgeType() == kUpper) ? bPhiNode.GetInPhiEdgeMap() : bPhiNode.GetOutPhiEdgeMap(); - for (auto iter = constEdgeMap.begin(); iter != constEdgeMap.end(); ++iter) { - if (((res == kTrue) && (meet == Max)) || ((res == kFalse) && (meet == Min))) { - break; - } - InequalEdge *in = iter->second; - if (in->GetEdgeType() == edge.GetEdgeType() || in->GetEdgeType() == kNone) { - InequalEdge nextEdge(edge, *in); - if (in->GetPairEdge()) { - in->GetPairEdge()->SetEdgeTypeInValid(); - } - res = meet(res, Prove(aNode, *(iter->first), nextEdge)); - if (in->GetPairEdge()) { - in->GetPairEdge()->SetEdgeTypeValid(); - } - } - } - } - auto constEdgeMap = (edge.GetEdgeType() == kUpper) ? bNode.GetInWithConstEdgeMap() : bNode.GetOutWithConstEdgeMap(); + active[&bNode] = &edge; + ProveResult res = bNode.GetKind() == kPhiNode ? UpdateCacheResult(aNode, bNode, edge, Min) + : UpdateCacheResult(aNode, bNode, edge, Max); + active.erase(&bNode); + tracing.pop_back(); + return res; +} + +ProveResult ABCD::UpdateCacheResult(ESSABaseNode &aNode, ESSABaseNode &bNode, InequalEdge &edge, MeetFunction meet) { + ProveResult res = meet == Min ? kReduced : kFalse; + if (meet == Min) { + CHECK_FATAL(bNode.GetKind() == kPhiNode, "must be"); + auto& bPhiNode = static_cast(bNode); + auto constEdgeMap = (edge.GetEdgeType() == kUpper) ? bPhiNode.GetInPhiEdgeMap() : bPhiNode.GetOutPhiEdgeMap(); for (auto iter = constEdgeMap.begin(); iter != constEdgeMap.end(); ++iter) { - if (res == kTrue) { + if (((res == kTrue) && (meet == Max)) || ((res == kFalse) && (meet == Min))) { break; } InequalEdge *in = iter->second; @@ -434,13 +416,30 @@ namespace maple { if (in->GetPairEdge()) { in->GetPairEdge()->SetEdgeTypeInValid(); } - res = Max(res, Prove(aNode, *(iter->first), nextEdge)); + res = meet(res, Prove(aNode, *(iter->first), nextEdge)); if (in->GetPairEdge()) { in->GetPairEdge()->SetEdgeTypeValid(); } } } - - return res; } + auto constEdgeMap = (edge.GetEdgeType() == kUpper) ? bNode.GetInWithConstEdgeMap() : bNode.GetOutWithConstEdgeMap(); + for (auto iter = constEdgeMap.begin(); iter != constEdgeMap.end(); ++iter) { + if (res == kTrue) { + break; + } + InequalEdge *in = iter->second; + if (in->GetEdgeType() == edge.GetEdgeType() || in->GetEdgeType() == kNone) { + InequalEdge nextEdge(edge, *in); + if (in->GetPairEdge()) { + in->GetPairEdge()->SetEdgeTypeInValid(); + } + res = Max(res, Prove(aNode, *(iter->first), nextEdge)); + if (in->GetPairEdge()) { + in->GetPairEdge()->SetEdgeTypeValid(); + } + } + } + return res; +} } // namespace maple diff --git a/src/maple_me/src/me_ir.cpp b/src/maple_me/src/me_ir.cpp index 7d61832692ddde89a8db9e50779b6de5e06e72c7..a75f98106f27e895a1ec7ee9f0c102ae0e6e0f13 100644 --- a/src/maple_me/src/me_ir.cpp +++ b/src/maple_me/src/me_ir.cpp @@ -355,6 +355,7 @@ bool IvarMeExpr::IsUseSameSymbol(const MeExpr &expr) const { return false; } auto &ivarMeExpr = static_cast(expr); + CHECK_FATAL(base != nullptr, "base is null"); if (base->IsUseSameSymbol(*ivarMeExpr.base) && fieldID == ivarMeExpr.fieldID) { return true; } @@ -396,6 +397,7 @@ bool IvarMeExpr::IsRCWeak() const { // If self is the first use of the same ivar coming from an iassign // (argument expr), then update its mu: expr->mu = this->mu. bool IvarMeExpr::IsIdentical(IvarMeExpr &expr) const { + CHECK_FATAL(expr.base != nullptr, "null ptr check"); if (base->GetExprID() != expr.base->GetExprID() || fieldID != expr.fieldID || tyIdx != expr.tyIdx) { return false; } @@ -560,6 +562,7 @@ bool ConstMeExpr::GeZero() const { } bool ConstMeExpr::GtZero() const { + CHECK_FATAL(constVal != nullptr, "constVal is null"); if (constVal->GetKind() != kConstInt) { return false; } @@ -571,6 +574,7 @@ bool ConstMeExpr::IsZero() const { } bool ConstMeExpr::IsOne() const { + CHECK_FATAL(constVal != nullptr, "constVal is null"); if (constVal->GetKind() != kConstInt) { return false; } @@ -578,6 +582,7 @@ bool ConstMeExpr::IsOne() const { } int64 ConstMeExpr::GetIntValue() const { + CHECK_FATAL(constVal != nullptr, "constVal is null"); CHECK_FATAL(constVal->GetKind() == kConstInt, "expect int const"); return safe_cast(constVal)->GetValue(); } @@ -696,6 +701,7 @@ void MeVarPhiNode::Dump(const IRMap *irMap) const { LogInfo::MapleLogger() << "PI_ADD VAR:"; } LogInfo::MapleLogger() << "VAR:"; + CHECK_FATAL(lhs != nullptr, "lsh is null"); irMap->GetSSATab().GetOriginalStFromID(lhs->GetOStIdx())->Dump(); LogInfo::MapleLogger() << " mx" << lhs->GetExprID(); LogInfo::MapleLogger() << " = MEPHI{"; @@ -713,6 +719,7 @@ void MeVarPhiNode::Dump(const IRMap *irMap) const { } void MeRegPhiNode::Dump(const IRMap *irMap) const { + CHECK_FATAL(lhs != nullptr, "lhs is null"); LogInfo::MapleLogger() << "REGVAR: " << lhs->GetRegIdx(); LogInfo::MapleLogger() << "(%" << irMap->GetMIRModule().CurFunction() @@ -732,6 +739,7 @@ void MeRegPhiNode::Dump(const IRMap *irMap) const { } void VarMeExpr::Dump(const IRMap *irMap, int32) const { + CHECK_NULL_FATAL(irMap); LogInfo::MapleLogger() << "VAR "; irMap->GetSSATab().GetOriginalStFromID(ostIdx)->Dump(); LogInfo::MapleLogger() << " (field)" << fieldID; @@ -742,6 +750,7 @@ void VarMeExpr::Dump(const IRMap *irMap, int32) const { } void RegMeExpr::Dump(const IRMap *irMap, int32) const { + CHECK_NULL_FATAL(irMap); LogInfo::MapleLogger() << "REGINDX:" << regIdx; LogInfo::MapleLogger() << " %" @@ -766,6 +775,7 @@ void GcmallocMeExpr::Dump(const IRMap*, int32) const { void ConstMeExpr::Dump(const IRMap*, int32) const { LogInfo::MapleLogger() << "CONST"; LogInfo::MapleLogger() << " "; + CHECK_FATAL(constVal != nullptr, "constVal is null"); constVal->Dump(); LogInfo::MapleLogger() << " mx" << GetExprID(); } @@ -803,6 +813,7 @@ void FieldsDistMeExpr::Dump(const IRMap*, int32) const { } void AddrofMeExpr::Dump(const IRMap *irMap, int32) const { + CHECK_NULL_FATAL(irMap); LogInfo::MapleLogger() << "ADDROF:"; irMap->GetSSATab().GetOriginalStFromID(ostIdx)->Dump(); LogInfo::MapleLogger() << " (field)" << fieldID; @@ -844,6 +855,7 @@ void IvarMeExpr::Dump(const IRMap *irMap, int32 indent) const { LogInfo::MapleLogger() << " (field)" << fieldID << '\n'; PrintIndentation(indent + 1); LogInfo::MapleLogger() << "base = "; + CHECK_FATAL(base != nullptr, "base is null"); base->Dump(irMap, indent + 1); LogInfo::MapleLogger() << '\n'; PrintIndentation(indent + 1); @@ -906,6 +918,7 @@ MeExpr *MaydassignMeStmt::GetLHSRef(SSATab &ssaTab, bool excludeLocalRefVar) { } MeExpr *IassignMeStmt::GetLHSRef(SSATab&, bool) { + CHECK_FATAL(lhsVar != nullptr, "lhsVar is null"); MIRType *baseType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(lhsVar->GetTyIdx()); ASSERT(baseType != nullptr, "null ptr check"); auto *pType = static_cast(baseType)->GetPointedType(); @@ -969,6 +982,7 @@ void MeStmt::Dump(const IRMap *irMap) const { if (op == OP_comment) { return; } + CHECK_NULL_FATAL(irMap); irMap->GetMIRModule().GetOut() << "||MEIR|| " << kOpcodeInfo.GetTableItemAt(op).name << '\n'; } @@ -983,6 +997,7 @@ MeStmt *MeStmt::GetNextMeStmt() const { void PiassignMeStmt::Dump(const IRMap *irMap) const { LogInfo::MapleLogger() << "||MEIR PI|| " << kOpcodeInfo.GetTableItemAt(GetOp()).name << " "; + CHECK_FATAL(lhs != nullptr, "lhs is null"); lhs->Dump(irMap); LogInfo::MapleLogger() << '\n'; PrintIndentation(kDefaultPrintIndentNum); @@ -993,10 +1008,12 @@ void PiassignMeStmt::Dump(const IRMap *irMap) const { void DassignMeStmt::Dump(const IRMap *irMap) const { LogInfo::MapleLogger() << "||MEIR|| " << kOpcodeInfo.GetTableItemAt(GetOp()).name << " "; + CHECK_FATAL(lhs != nullptr, "lhs is null"); lhs->Dump(irMap); LogInfo::MapleLogger() << '\n'; PrintIndentation(kDefaultPrintIndentNum); LogInfo::MapleLogger() << "rhs = "; + CHECK_FATAL(rhs != nullptr, "rhs is null"); rhs->Dump(irMap, kDefaultPrintIndentNum); if (needIncref) { LogInfo::MapleLogger() << " [RC+]"; @@ -1010,10 +1027,12 @@ void DassignMeStmt::Dump(const IRMap *irMap) const { void RegassignMeStmt::Dump(const IRMap *irMap) const { LogInfo::MapleLogger() << "||MEIR|| " << kOpcodeInfo.GetTableItemAt(GetOp()).name << " "; + CHECK_FATAL(lhs != nullptr, "lhs is null"); lhs->Dump(irMap); LogInfo::MapleLogger() << '\n'; PrintIndentation(kDefaultPrintIndentNum); LogInfo::MapleLogger() << "rhs = "; + CHECK_FATAL(rhs != nullptr, "rhs is null"); rhs->Dump(irMap, kDefaultPrintIndentNum); if (needIncref) { LogInfo::MapleLogger() << " [RC+]"; @@ -1025,6 +1044,7 @@ void MaydassignMeStmt::Dump(const IRMap *irMap) const { LogInfo::MapleLogger() << "||MEIR|| " << kOpcodeInfo.GetTableItemAt(GetOp()).name << '\n'; PrintIndentation(kDefaultPrintIndentNum); LogInfo::MapleLogger() << "rhs = "; + CHECK_FATAL(rhs != nullptr, "rhs is null"); rhs->Dump(irMap, kDefaultPrintIndentNum); if (needIncref) { LogInfo::MapleLogger() << " [RC+]"; @@ -1037,6 +1057,7 @@ void MaydassignMeStmt::Dump(const IRMap *irMap) const { } void ChiMeNode::Dump(const IRMap *irMap) const { + CHECK_NULL_FATAL(irMap); auto *meLHS = static_cast(lhs); auto *meRHS = static_cast(rhs); CHECK_FATAL(meLHS != nullptr, "Node doesn't have lhs?"); @@ -1101,10 +1122,12 @@ void IassignMeStmt::Dump(const IRMap *irMap) const { LogInfo::MapleLogger() << "||MEIR|| " << kOpcodeInfo.GetTableItemAt(GetOp()).name << '\n'; PrintIndentation(kDefaultPrintIndentNum); LogInfo::MapleLogger() << "lhs = "; + CHECK_FATAL(lhsVar != nullptr, "lhsVar is null"); lhsVar->Dump(irMap, kDefaultPrintIndentNum); LogInfo::MapleLogger() << '\n'; PrintIndentation(kDefaultPrintIndentNum); LogInfo::MapleLogger() << "rhs = "; + CHECK_FATAL(rhs != nullptr, "rhs is null"); rhs->Dump(irMap, kDefaultPrintIndentNum); if (needIncref) { LogInfo::MapleLogger() << " [RC+]"; @@ -1202,6 +1225,7 @@ void UnaryMeStmt::Dump(const IRMap *irMap) const { LogInfo::MapleLogger() << "||MEIR|| " << kOpcodeInfo.GetTableItemAt(GetOp()).name << '\n'; PrintIndentation(kDefaultPrintIndentNum); LogInfo::MapleLogger() << " unaryopnd: "; + CHECK_FATAL(opnd != nullptr, "opnd is null"); opnd->Dump(irMap, kDefaultPrintIndentNum); LogInfo::MapleLogger() << '\n'; } @@ -1224,6 +1248,7 @@ void ThrowMeStmt::Dump(const IRMap *irMap) const { LogInfo::MapleLogger() << "||MEIR|| " << kOpcodeInfo.GetTableItemAt(GetOp()).name << '\n'; PrintIndentation(kDefaultPrintIndentNum); LogInfo::MapleLogger() << "throwopnd: "; + CHECK_FATAL(opnd != nullptr, "opnd is null"); opnd->Dump(irMap, kDefaultPrintIndentNum); LogInfo::MapleLogger() << '\n'; DumpMuList(irMap, *GetMuList()); diff --git a/src/maple_me/src/me_loop_analysis.cpp b/src/maple_me/src/me_loop_analysis.cpp index ccc3abe8f9d3f71c4d86c0c984e00353b5ba455c..142151587c3991dedac934fc90b8afcafa0461d5 100644 --- a/src/maple_me/src/me_loop_analysis.cpp +++ b/src/maple_me/src/me_loop_analysis.cpp @@ -72,7 +72,7 @@ void IdentifyLoops::ProcessBB(BB *bb) { } } -void IdentifyLoops::Dump() { +void IdentifyLoops::Dump() const { for (LoopDesc *mploop : meLoops) { // loop LogInfo::MapleLogger() << "nest depth: " << mploop->nestDepth << " loop head BB: " << mploop->head->GetBBId() diff --git a/src/maple_me/src/me_phase_manager.cpp b/src/maple_me/src/me_phase_manager.cpp index 691e6b4de64d0074cd321f658523f3cd33fe3d16..f509126fa0954bca95f5f4b6c8642d566f82ea29 100644 --- a/src/maple_me/src/me_phase_manager.cpp +++ b/src/maple_me/src/me_phase_manager.cpp @@ -122,6 +122,7 @@ bool MeFuncPhaseManager::FuncFilter(const std::string &filter, const std::string } void MeFuncPhaseManager::IPACleanUp(MeFunction *func) { + ASSERT(func != nullptr, "null ptr check"); GetAnalysisResultManager()->InvalidAllResults(); memPoolCtrler.DeleteMemPool(func->GetMemPool()); } diff --git a/src/maple_me/src/me_rename2preg.cpp b/src/maple_me/src/me_rename2preg.cpp index d151715df391e5b5691b12829e95a31f16192667..f73cfa62fb4db0b9f8ffe06fa898b99b84e8cf17 100644 --- a/src/maple_me/src/me_rename2preg.cpp +++ b/src/maple_me/src/me_rename2preg.cpp @@ -170,7 +170,6 @@ class FormalRenaming final { private: MIRFunction &irFunc; - std::vector paramUsed; // if parameter is not used, it's false, otherwise true // if the parameter got promoted, the nth of func->mirfunc->_formal is the nth of reg_formal_vec, otherwise nullptr; std::vector renamedReg; @@ -237,7 +236,8 @@ class SSARename2Preg { Rename2PregExpr(aliasClass, irMap, stmt, utils::ToRef(stmt.GetOpnd(i))); } Rename2PregCallReturn(aliasClass, utils::ToRef(stmt.GetMustDefList())); - } else if (auto *iAssignStmt = safe_cast(stmt)) { + } else if (instance_of(stmt)) { + auto *iAssignStmt = static_cast(&stmt); Rename2PregExpr(aliasClass, irMap, stmt, utils::ToRef(iAssignStmt->GetRHS())); Rename2PregExpr(aliasClass, irMap, stmt, utils::ToRef(utils::ToRef(iAssignStmt->GetLHSVal()).GetBase())); } else { @@ -270,21 +270,25 @@ class SSARename2Preg { // only handle the leaf of load, because all other expressions has been done by previous SSAPre void Rename2PregExpr(const AliasClass &aliasClass, MeIRMap &irMap, MeStmt &stmt, MeExpr &expr) { - if (auto *opExpr = safe_cast(expr)) { + if (instance_of(expr)) { + auto *opExpr = static_cast(&expr); for (size_t i = 0; i < kOperandNumTernary; ++i) { MeExpr *opnd = opExpr->GetOpnd(i); if (opnd != nullptr) { Rename2PregExpr(aliasClass, irMap, stmt, *opnd); } } - } else if (auto *naryExpr = safe_cast(expr)) { + } else if (instance_of(expr)) { + auto *naryExpr = static_cast(&expr); MapleVector &opnds = naryExpr->GetOpnds(); for (auto *opnd : opnds) { Rename2PregExpr(aliasClass, irMap, stmt, utils::ToRef(opnd)); } - } else if (auto *ivarExpr = safe_cast(expr)) { + } else if (instance_of(expr)) { + auto *ivarExpr = static_cast(&expr); Rename2PregExpr(aliasClass, irMap, stmt, utils::ToRef(ivarExpr->GetBase())); - } else if (auto *varExpr = safe_cast(expr)) { + } else if (instance_of(expr)) { + auto *varExpr = static_cast(&expr); Rename2PregLeafRHS(aliasClass, irMap, stmt, *varExpr); } } @@ -303,9 +307,11 @@ class SSARename2Preg { RegMeExpr *regExpr = RenameVar(aliasClass, varExpr); if (regExpr != nullptr) { MeExpr *oldRhs = nullptr; - if (auto *dAStmt = safe_cast(stmt)) { + if (instance_of(stmt)) { + auto *dAStmt = static_cast(&stmt); oldRhs = dAStmt->GetRHS(); - } else if (auto *mayDAStmt = safe_cast(stmt)) { + } else if (instance_of(stmt)) { + auto *mayDAStmt = static_cast(&stmt); oldRhs = mayDAStmt->GetRHS(); } else { CHECK_FATAL(false, "NYI"); diff --git a/src/maple_me/src/me_ssa_update.cpp b/src/maple_me/src/me_ssa_update.cpp index 2845e99e78cf98481195d863cfd9a942c2d7355e..83d0685b1ea9dc67071cf6e9b4cad142d6c58a28 100644 --- a/src/maple_me/src/me_ssa_update.cpp +++ b/src/maple_me/src/me_ssa_update.cpp @@ -174,7 +174,13 @@ void MeSSAUpdate::RenameStmts(BB &bb) { // rename the expressions for (size_t i = 0; i < stmt.NumMeStmtOpnds(); ++i) { bool changed = false; - stmt.SetOpnd(i, RenameExpr(*stmt.GetOpnd(i), changed /* dummy */)); + stmt.SetOpnd(static_cast(i), RenameExpr(*stmt.GetOpnd(i), changed)); + // if base of iassign's ivar is changed, a new ivar is needed + if (stmt.GetOp() == OP_iassign && i == 0 && changed) { + auto &iAssign = static_cast(stmt); + IvarMeExpr *iVar = irMap.BuildLHSIvarFromIassMeStmt(iAssign); + iAssign.SetLHSVal(iVar); + } } // process mayDef MapleMap *chiList = stmt.GetChiList(); @@ -205,8 +211,7 @@ void MeSSAUpdate::RenameStmts(BB &bb) { if (it == renameStacks.end()) { continue; } - MapleStack *renameStack = it->second; - renameStack->push(lhsVar); + it->second->push(lhsVar); } } diff --git a/src/maple_me/src/orig_symbol.cpp b/src/maple_me/src/orig_symbol.cpp index 0f4aa35ad93bcb378de0b6d11bfff87d54730b93..e29b8ddb9b768953e771fbeef4ba129a72431962 100644 --- a/src/maple_me/src/orig_symbol.cpp +++ b/src/maple_me/src/orig_symbol.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. @@ -65,7 +65,7 @@ void OriginalStTable::Dump() { } OriginalSt *OriginalStTable::FindOrCreateSymbolOriginalSt(MIRSymbol &mirst, PUIdx pidx, FieldID fld) { - auto it = mirSt2Ost.find(&mirst); + auto it = mirSt2Ost.find(SymbolFieldPair(mirst.GetStIndex(), fld)); if (it == mirSt2Ost.end()) { // create a new OriginalSt return CreateSymbolOriginalSt(mirst, pidx, fld); @@ -96,7 +96,7 @@ OriginalSt *OriginalStTable::CreateSymbolOriginalSt(MIRSymbol &mirst, PUIdx pidx ost->SetIsPrivate(fattrs.GetAttr(FLDATTR_private)); } originalStVector.push_back(ost); - mirSt2Ost[&mirst] = ost->GetIndex(); + mirSt2Ost[SymbolFieldPair(mirst.GetStIndex(), fld)] = ost->GetIndex(); return ost; } @@ -113,7 +113,7 @@ OriginalSt *OriginalStTable::CreatePregOriginalSt(PregIdx regidx, PUIdx pidx) { } OriginalSt *OriginalStTable::FindSymbolOriginalSt(MIRSymbol &mirst) { - auto it = mirSt2Ost.find(&mirst); + auto it = mirSt2Ost.find(SymbolFieldPair(mirst.GetStIndex(), 0)); if (it == mirSt2Ost.end()) { return nullptr; } diff --git a/src/maple_me/src/ssa_devirtual.cpp b/src/maple_me/src/ssa_devirtual.cpp index 4e560d4fa3c99cae1b081a8166c49eb43c03d334..4d8e78833c91d36007e1cd5ba0ca33d08a4c356f 100644 --- a/src/maple_me/src/ssa_devirtual.cpp +++ b/src/maple_me/src/ssa_devirtual.cpp @@ -369,7 +369,7 @@ void SSADevirtual::VisitMeExpr(MeExpr *meExpr) const { } case kMeOpOp: { auto *meOpExpr = static_cast(meExpr); - for (uint32 i = 0; i < 3; ++i) { + for (uint32 i = 0; i < kOperandNumTernary; ++i) { VisitMeExpr(meOpExpr->GetOpnd(i)); } break; diff --git a/src/maple_me/src/ssa_epre.cpp b/src/maple_me/src/ssa_epre.cpp index 20b745052807f1df09d3454410996787845f8db7..8fc603e022adb59ac759af6705bd2a30d9388d4e 100644 --- a/src/maple_me/src/ssa_epre.cpp +++ b/src/maple_me/src/ssa_epre.cpp @@ -312,8 +312,10 @@ void SSAEPre::BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, b if (meExpr.GetPrimType() == PTY_agg) { isHypo = false; } + constexpr uint32 minTypeSizeRequired = 4; if (isHypo && (!isRebuild || hasTempVarAs1Opnd) && naryMeExpr->GetPrimType() != PTY_u1 && - (GetPrimTypeSize(naryMeExpr->GetPrimType()) >= 4 || IsPrimitivePoint(naryMeExpr->GetPrimType()) || + (GetPrimTypeSize(naryMeExpr->GetPrimType()) >= minTypeSizeRequired || + IsPrimitivePoint(naryMeExpr->GetPrimType()) || (naryMeExpr->GetOp() == OP_intrinsicop && IntrinDesc::intrinTable[naryMeExpr->GetIntrinsic()].IsPure())) && (epreIncludeRef || naryMeExpr->GetPrimType() != PTY_ref)) { if (meExpr.GetOp() == OP_array) { diff --git a/src/maple_me/src/ssa_mir_nodes.cpp b/src/maple_me/src/ssa_mir_nodes.cpp index 6af8a8c91f4783f9cf4a7a47c0123bf955073011..2cc75157671d26a2cce56f5e35344402ec131ace 100644 --- a/src/maple_me/src/ssa_mir_nodes.cpp +++ b/src/maple_me/src/ssa_mir_nodes.cpp @@ -28,12 +28,14 @@ void GenericSSAPrint(const MIRModule &mod, const StmtNode &stmtNode, int32 inden case OP_maydassign: case OP_dassign: { mod.GetOut() << " "; + CHECK_NULL_FATAL(ssaPart->GetSSAVar()); ssaPart->GetSSAVar()->Dump(); ssaPart->DumpMayDefNodes(mod); return; } case OP_regassign: { mod.GetOut() << " "; + CHECK_NULL_FATAL(ssaPart->GetSSAVar()); ssaPart->GetSSAVar()->Dump(); return; } diff --git a/src/maple_util/include/error_code.h b/src/maple_util/include/error_code.h index e5c387b95ac5bb99a52bb4826beb9077abe9e3d1..d883edff72366aa98c2e4eec6a31feda17d65623 100644 --- a/src/maple_util/include/error_code.h +++ b/src/maple_util/include/error_code.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. @@ -15,6 +15,8 @@ #ifndef MAPLE_UTIL_INCLUDE_ERROR_CODE_H #define MAPLE_UTIL_INCLUDE_ERROR_CODE_H +#include + namespace maple { enum ErrorCode { kErrorNoError, @@ -27,5 +29,7 @@ enum ErrorCode { kErrorCompileFail, kErrorNotImplement }; + +void PrintErrorMessage(int ret); } // namespace maple #endif // MAPLE_UTIL_INCLUDE_ERROR_CODE_H diff --git a/src/maple_util/include/file_layout.h b/src/maple_util/include/file_layout.h index dea8fb88cf631bc8620069b4f4a50ce8a84c982f..aa19f67ce3d12750fdb16b880d0d9ab3037c7d03 100644 --- a/src/maple_util/include/file_layout.h +++ b/src/maple_util/include/file_layout.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. diff --git a/src/maple_util/include/itab_util.h b/src/maple_util/include/itab_util.h index 168a2275c8444c7fc4285f473e9c016ab12d59a8..7c94546249a514006f0cf9203ab4802aa86eb890 100644 --- a/src/maple_util/include/itab_util.h +++ b/src/maple_util/include/itab_util.h @@ -29,6 +29,5 @@ unsigned int DJBHash(const char *str); unsigned int GetHashIndex(const char *name); unsigned int GetSecondHashIndex(const char *name); - } // namespace maple #endif diff --git a/src/maple_util/include/mpl_logging.h b/src/maple_util/include/mpl_logging.h index 736aea7393f72a8b2be5743e0415c746f5d78042..ad20ff175b4d6310b99f88c0c90174c86e04ea60 100644 --- a/src/maple_util/include/mpl_logging.h +++ b/src/maple_util/include/mpl_logging.h @@ -164,7 +164,7 @@ class LogInfo { } static std::ostream &MapleLogger(LogLevel l = kLlLog); - + static std::ios::fmtflags flags(); void EmitLogForUser(enum LogNumberCode num, enum LogLevel ll, const char *fmt, ...) const; void EmitLogForUser(enum LogNumberCode num, enum LogLevel ll, const std::string &message) const; void EmitErrorMessage(const std::string &cond, const std::string &file, unsigned int line, diff --git a/src/maple_util/include/mpl_number.h b/src/maple_util/include/mpl_number.h index c362b1e8ab011ab685d4711173af17d07ba8f4ee..bd47ce3c34f034e3417141c65fd9fc4cfd26c843 100644 --- a/src/maple_util/include/mpl_number.h +++ b/src/maple_util/include/mpl_number.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. @@ -108,7 +108,7 @@ class Number { return *this; } - Number operator++(int) { + const Number operator++(int) { auto tmp = val; this->operator++(); return Number(tmp); @@ -119,7 +119,7 @@ class Number { return *this; } - Number operator--(int) { + const Number operator--(int) { auto tmp = val; this->operator--; return Number(tmp); diff --git a/src/maple_util/include/muid.h b/src/maple_util/include/muid.h index f598032f5885154281a440977c882cf9c1ad07b4..1ff056234909f93bbefe93f1db48032d80717257 100644 --- a/src/maple_util/include/muid.h +++ b/src/maple_util/include/muid.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. diff --git a/src/maple_util/include/name_mangler.h b/src/maple_util/include/name_mangler.h index ef7d93eec114ea146fd512204124676f8c352496..3b84b42b2a5c2fa36665add926f6f78f7a6d58d3 100644 --- a/src/maple_util/include/name_mangler.h +++ b/src/maple_util/include/name_mangler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. diff --git a/src/maple_util/include/profile_type.h b/src/maple_util/include/profile_type.h index 2e45d3389484111d8200bd117a70dfeb3ee0727b..90b73c0ddc2565dc81d584fb7478d61d8476b226 100644 --- a/src/maple_util/include/profile_type.h +++ b/src/maple_util/include/profile_type.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. diff --git a/src/maple_util/include/ptr_list_ref.h b/src/maple_util/include/ptr_list_ref.h index 4465ffdcaaab9dd52583ac4c89498b154ae2ca1a..8a6be435b66a864636de7dc8a9f99ce21f0bb009 100644 --- a/src/maple_util/include/ptr_list_ref.h +++ b/src/maple_util/include/ptr_list_ref.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. @@ -289,6 +289,7 @@ class PtrListRef { _Value->SetPrev(nullptr); _Value->SetNext(nullptr); } else { + ASSERT(this->first != nullptr, "null ptr check"); this->first->SetPrev(_Value); _Value->SetPrev(nullptr); _Value->SetNext(this->first); @@ -385,6 +386,7 @@ class PtrListRef { this->first = &(_Other.front()); this->last = &(_Other.back()); } else if (_Where == this->cend() || _Where == const_iterator(this->last)) { + ASSERT(this->last != nullptr, "null ptr check"); this->last->SetNext(&(_Other.front())); _Other.front().SetPrev(this->last); this->last = &(_Other.back()); diff --git a/src/maple_util/include/version.h b/src/maple_util/include/version.h index 4524cfebf077786192fc3316192606acbe2322ee..24c043563e12c3e7c7fe3c2886f37242c9e3ff0c 100644 --- a/src/maple_util/include/version.h +++ b/src/maple_util/include/version.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. @@ -16,11 +16,9 @@ #define MAPLE_UTIL_INCLUDE_VERSION_H namespace Version { - static constexpr const int kMajorMplVersion = 3; static constexpr const int kMinorCompilerVersion = 0; static constexpr const int kMinorRuntimeVersion = 0; - } #endif diff --git a/src/maple_util/src/profile.cpp b/src/maple_util/src/profile.cpp index 0e62b6e618b9a04ebab39ab589d6b525ceebd970..c98cf444d4f87e017e77215f85344bc4d0ccce7a 100644 --- a/src/maple_util/src/profile.cpp +++ b/src/maple_util/src/profile.cpp @@ -82,7 +82,7 @@ bool Profile::CheckDexValid(uint32 idx) { void Profile::ParseLiteral(const char *data, const char *end) { if(data > end) { - LogInfo::MapleLogger() << "parse Literal error" << std::endl; + LogInfo::MapleLogger() << "parse Literal error" << '\n';; } std::string str(data,end-data); std::stringstream ss; @@ -134,7 +134,7 @@ void Profile::ParseMeta(const char *data, int fileNum, std::unordered_set*>(data + offset); if (CheckDexValid(metaProf->idx)) { if (debug) { - LogInfo::MapleLogger() << "dex name " << strMap.at(metaProf->idx) << std::endl; + LogInfo::MapleLogger() << "dex name " << strMap.at(metaProf->idx) << '\n';; } for (uint32 item = 0; item < metaProf->num; item++) { const MetaItem *metaItem = &(metaProf->items[item]); @@ -152,7 +152,7 @@ void Profile::ParseReflectionStr(const char *data, int fileNum) { metaProf = reinterpret_cast*>(data + offset); if (CheckDexValid(metaProf->idx)) { if (debug) { - LogInfo::MapleLogger() << "dex name " << strMap.at(metaProf->idx) << std::endl; + LogInfo::MapleLogger() << "dex name " << strMap.at(metaProf->idx) << '\n';; } for (uint32 item = 0; item < metaProf->num; item++) { const ReflectionStrItem *strItem = &(metaProf->items[item]); @@ -181,33 +181,33 @@ bool Profile::DeCompress(const std::string &path, const std::string &dexNameInne if (!in) { if (errno != ENOENT && errno != EACCES) { LogInfo::MapleLogger() << "WARN: DeCompress(" - << "), failed to open " << path << ", " << strerror(errno) << std::endl; + << "), failed to open " << path << ", " << strerror(errno) << '\n';; } res = false; return res; } in.seekg(0, std::ios::end); - size_t byteCount = in.tellg(); + size_t byteCount = static_cast(in.tellg()); in.seekg(0, std::ios::beg); std::vector bufVector; bufVector.resize(byteCount); char *buf = reinterpret_cast(bufVector.data()); if (!in.read(buf, byteCount)) { LogInfo::MapleLogger() << "WARN: DeCompress(" - << "), failed to read all data for " << path << ", " << strerror(errno) << std::endl; + << "), failed to read all data for " << path << ", " << strerror(errno) << '\n';; res = false; return res; } if (byteCount < sizeof(Header)) { LogInfo::MapleLogger() << "WARN: DeCompress(" - << "), failed, read no data for " << path << ", " << strerror(errno) << std::endl; + << "), failed, read no data for " << path << ", " << strerror(errno) << '\n';; res = false; return res; } Header *header = reinterpret_cast(buf); if (!CheckProfileHeader(header)) { if (debug) { - LogInfo::MapleLogger() << "invalid maigc number " << reinterpret_cast(header->magic) << std::endl; + LogInfo::MapleLogger() << "invalid maigc number " << header->magic << '\n';; } res = false; return res; @@ -217,7 +217,7 @@ bool Profile::DeCompress(const std::string &path, const std::string &dexNameInne if (debug) { LogInfo::MapleLogger() << "Header summary " << "profile num " << static_cast(header->profileNum) << "string table size" << stringTabSize - << std::endl; + << '\n';; } const char *strBuf = buf + header->stringTabOff; const char *cursor = strBuf; @@ -230,21 +230,21 @@ bool Profile::DeCompress(const std::string &path, const std::string &dexNameInne } ASSERT(strMap.size() == header->stringCount, "string count doesn't match"); if (debug) { - LogInfo::MapleLogger() << "str size " << strMap.size() << std::endl; - for (auto item : strMap) { - LogInfo::MapleLogger() << item << std::endl; + LogInfo::MapleLogger() << "str size " << strMap.size() << '\n';; + for (const auto &item : strMap) { + LogInfo::MapleLogger() << item << '\n';; } - LogInfo::MapleLogger() << "str size print end " << std::endl; + LogInfo::MapleLogger() << "str size print end " << '\n';; } size_t idx = 0; for (idx = 0; idx < header->profileNum; idx++) { ProfileDataInfo *profileDataInfo = &(header->data[idx]); if (debug) { LogInfo::MapleLogger() << "profile file num for type " << GetProfileNameByType(profileDataInfo->profileType) << " " - << static_cast(profileDataInfo->mapleFileNum) << std::endl; + << static_cast(profileDataInfo->mapleFileNum) << '\n';; } if (debug) { - LogInfo::MapleLogger() << GetProfileNameByType(profileDataInfo->profileType) << " Start" << std::endl; + LogInfo::MapleLogger() << GetProfileNameByType(profileDataInfo->profileType) << " Start" << '\n';; } char *proFileData = buf + profileDataInfo->profileDataOff; if (type != kAll && type != profileDataInfo->profileType) { @@ -274,17 +274,17 @@ bool Profile::DeCompress(const std::string &path, const std::string &dexNameInne this->appPackageName = strMap.at(appPackageNameIdx); if (!appPackageName.empty() && this->appPackageName != appPackageName) { LogInfo::MapleLogger() << "app profile doesnt match expect " << this->appPackageName - << " but got " << appPackageName << std::endl; + << " but got " << appPackageName << '\n';; return false; } break; } default: - LogInfo::MapleLogger() << "unsupported tag " << profileDataInfo->profileType << std::endl; + LogInfo::MapleLogger() << "unsupported tag " << profileDataInfo->profileType << '\n';; break; } } - LogInfo::MapleLogger() << "SUCC parse " << path << std::endl; + LogInfo::MapleLogger() << "SUCC parse " << path << '\n';; valid = true; return res; } @@ -307,7 +307,7 @@ bool Profile::CheckFuncHot(const std::string &funcName) const { hotFuncCountThreshold = Options::profileHotCount; } else { std::vector times; - for (auto item : funcProfData) { + for (auto &item : funcProfData) { times.push_back((item.second).callTimes); } std::sort(times.begin(), times.end(), std::greater()); @@ -411,35 +411,35 @@ std::unordered_set &Profile::GetMeta(uint8 type) { void Profile::Dump() const { std::ofstream outfile; outfile.open("prof.dump"); - outfile << "classMeta profile start " <((item.second).type) << " " << (item.second).callTimes << std::endl; + << static_cast((item.second).type) << " " << (item.second).callTimes << '\n';; } - outfile << "reflectStr profile start " <(item.second) << std::endl; + outfile << "reflectStr profile start " <<'\n';; + for (const auto &item : reflectionStrData) { + outfile << item.first << " " << static_cast(item.second) << '\n';; } } diff --git a/src/mempool/include/mempool_allocator.h b/src/mempool/include/mempool_allocator.h index 9c000ed1cc3eafb7028d0742f13c76b41b2a7888..6688eef95e8a55798d59026707609160cab8b369 100644 --- a/src/mempool/include/mempool_allocator.h +++ b/src/mempool/include/mempool_allocator.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. @@ -210,6 +210,7 @@ class MapleAllocatorAdapter { } void destroy(const pointer p) { + CHECK_NULL_FATAL(p); p->~value_type(); } diff --git a/src/mpl2mpl/include/class_hierarchy.h b/src/mpl2mpl/include/class_hierarchy.h index 612291a161eaef57a8ae5c17a2ded7a1d5586552..b2b740d6c22bcb717cc641830bb26a844434d634 100644 --- a/src/mpl2mpl/include/class_hierarchy.h +++ b/src/mpl2mpl/include/class_hierarchy.h @@ -47,6 +47,8 @@ class Klass { public: struct KlassComparator { bool operator()(const Klass *lhs, const Klass *rhs) const { + CHECK_NULL_FATAL(rhs); + CHECK_NULL_FATAL(lhs); return lhs->GetKlassName() < rhs->GetKlassName(); } }; diff --git a/src/mpl2mpl/include/muid_replacement.h b/src/mpl2mpl/include/muid_replacement.h index 122f4e663e73c0f4b72fdf6065804770bf931569..cf22a78bd1a3dac567e05e254d7b4644d6caab63 100644 --- a/src/mpl2mpl/include/muid_replacement.h +++ b/src/mpl2mpl/include/muid_replacement.h @@ -106,7 +106,7 @@ class MUIDReplacement : public FuncOptimizeImpl { void GenerateGlobalRootList(); void CollectImplicitUndefClassInfo(StmtNode &stmt); void ReplaceMethodMetaFuncAddr(MIRSymbol &funcSymbol, int64 index); - void ReplaceFieldMetaStaticAddr(MIRSymbol &mirSymbol, int64 index); + void ReplaceFieldMetaStaticAddr(MIRSymbol &mirSymbol, uint32 index); void CollectFuncAndDataFromKlasses(); void CollectFuncAndDataFromGlobalTab(); void CollectFuncAndDataFromFuncList(); diff --git a/src/mpl2mpl/include/native_stub_func.h b/src/mpl2mpl/include/native_stub_func.h index 722e73bf659f4dd1a907a62f25fbaa91636d0930..bb74a8a0939d9fd4c73d2066ebf301cfeef9e97b 100644 --- a/src/mpl2mpl/include/native_stub_func.h +++ b/src/mpl2mpl/include/native_stub_func.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. @@ -18,7 +18,11 @@ #include "phase_impl.h" namespace maple { +#ifdef USE_ARM32_MACRO +constexpr int kSlownativeFuncnum = 5; +#else constexpr int kSlownativeFuncnum = 9; +#endif constexpr int kJniTypeNormal = 0; constexpr int kJniTypeMapleCriticalNative = 1; constexpr int kJnitTypeCriticalNative = 2; @@ -69,8 +73,7 @@ class NativeStubFuncGeneration : public FuncOptimizeImpl { bool IsStaticBindingMethod(const std::string &methodName) const; MIRFunction &GetOrCreateDefaultNativeFunc(MIRFunction &stubFunc); void GenerateRegisteredNativeFuncCall(MIRFunction &func, const MIRFunction &nativeFunc, MapleVector &args, - const MIRSymbol *ret, bool needNativeCall, CallNode &preNativeFuncCall, - CallNode &postNativeFuncCall); + const MIRSymbol *ret); StmtNode *CreateNativeWrapperCallNode(MIRFunction &func, BaseNode *funcPtr, MapleVector &args, const MIRSymbol *ret); void GenerateNativeWrapperFuncCall(MIRFunction &func, const MIRFunction &nativeFunc, MapleVector &args, diff --git a/src/mpl2mpl/src/analyzector.cpp b/src/mpl2mpl/src/analyzector.cpp index fb521b55bfb2c294d747dde19b823eb1fe78b9d0..333a5ebbb2c10c90edee22785377686a1941c5de 100644 --- a/src/mpl2mpl/src/analyzector.cpp +++ b/src/mpl2mpl/src/analyzector.cpp @@ -15,7 +15,7 @@ #include "analyzector.h" #include "utils.h" -// AnalyzeCtor analyzes which fields are assigned inside of of each constructor +// AnalyzeCtor analyzes which fields are assigned inside of each constructor namespace maple { void AnalyzeCtor::ProcessFunc(MIRFunction *func) { if (!func->IsConstructor() || func->IsEmpty() || func->GetParamSize() == 0) { diff --git a/src/mpl2mpl/src/class_hierarchy.cpp b/src/mpl2mpl/src/class_hierarchy.cpp index 40b7fafe08d3e0d6a284b013e6807bdbd3e2a4eb..cef1f53a509e38ce7a6e56e271b93e233c4b3f87 100644 --- a/src/mpl2mpl/src/class_hierarchy.cpp +++ b/src/mpl2mpl/src/class_hierarchy.cpp @@ -410,6 +410,9 @@ bool KlassHierarchy::UpdateFieldID(TyIdx baseTypeIdx, TyIdx targetTypeIdx, Field } bool KlassHierarchy::NeedClinitCheckRecursively(const Klass &kl) const { + if (kl.HasFlag(kClassRuntimeVerify)) { + return true; + } const Klass *klass = &kl; if (klass->IsClass()) { while (klass != nullptr) { diff --git a/src/mpl2mpl/src/constantfold.cpp b/src/mpl2mpl/src/constantfold.cpp index c86d4b7dcb176040dd5348c27a5a5fd86be381c0..a37652fff116cd092289ae83393077003d97e683 100644 --- a/src/mpl2mpl/src/constantfold.cpp +++ b/src/mpl2mpl/src/constantfold.cpp @@ -409,15 +409,15 @@ ConstvalNode *ConstantFold::FoldIntConstBinary(Opcode opcode, PrimType resultTyp } case OP_ashr: { if (useResult64) { - result64 = intValueOfConst0 >> intValueOfConst1; + result64 = intValueOfConst0 >> static_cast(intValueOfConst1); } else { - result32 = static_cast(intValueOfConst0) >> static_cast(intValueOfConst1); + result32 = static_cast(intValueOfConst0) >> static_cast(intValueOfConst1); } break; } case OP_lshr: { if (useResult64) { - result64 = static_cast(intValueOfConst0) >> intValueOfConst1; + result64 = static_cast(intValueOfConst0) >> static_cast(intValueOfConst1); } else { result32 = static_cast(intValueOfConst0) >> static_cast(intValueOfConst1); } @@ -764,8 +764,11 @@ MIRConst *ConstantFold::FoldConstComparisonMIRConst(Opcode opcode, PrimType resu const MIRConst &const0, const MIRConst &const1) { MIRConst *returnValue = nullptr; if (IsPrimitiveInteger(opndType) || IsPrimitiveDynInteger(opndType)) { - returnValue = FoldIntConstComparisonMIRConst(opcode, resultType, *safe_cast(&const0), - *safe_cast(&const1)); + const auto *intConst0 = safe_cast(&const0); + const auto *intConst1 = safe_cast(&const1); + ASSERT_NOT_NULL(intConst0); + ASSERT_NOT_NULL(intConst1); + returnValue = FoldIntConstComparisonMIRConst(opcode, resultType, *intConst0, *intConst1); } else if (opndType == PTY_f32 || opndType == PTY_f64) { returnValue = FoldFPConstComparisonMIRConst(opcode, resultType, opndType, const0, const1); } else { @@ -803,6 +806,7 @@ ConstvalNode *ConstantFold::FoldConstBinary(Opcode opcode, PrimType resultType, ConstvalNode *ConstantFold::FoldIntConstUnary(Opcode opcode, PrimType resultType, const ConstvalNode *constNode) const { CHECK_NULL_FATAL(constNode); const MIRIntConst *cst = safe_cast(constNode->GetConstVal()); + ASSERT_NOT_NULL(cst); uint32 result32 = 0; uint64 result64 = 0; bool useResult64 = (GetPrimTypeSize(resultType) == kByteSizeOfBit64); @@ -1015,11 +1019,13 @@ ConstvalNode *ConstantFold::FoldCeil(const ConstvalNode *cst, PrimType fromType, CHECK_NULL_FATAL(cst); if (fromType == PTY_f32) { const MIRFloatConst *constValue = safe_cast(cst->GetConstVal()); + ASSERT_NOT_NULL(constValue); float floutValue = ceil(constValue->GetValue()); resultConst->SetConstVal(GlobalTables::GetIntConstTable().GetOrCreateIntConst( static_cast(floutValue), resultType)); } else { const MIRDoubleConst *constValue = safe_cast(cst->GetConstVal()); + ASSERT_NOT_NULL(constValue); double doubleValue = ceil(constValue->GetValue()); resultConst->SetConstVal(GlobalTables::GetIntConstTable().GetOrCreateIntConst( static_cast(doubleValue), resultType)); @@ -1032,10 +1038,12 @@ MIRConst *ConstantFold::FoldFloorMIRConst(const MIRConst *cst, PrimType fromType CHECK_NULL_FATAL(cst); if (fromType == PTY_f32) { const MIRFloatConst *constValue = safe_cast(cst); + ASSERT_NOT_NULL(constValue); float floutValue = floor(constValue->GetValue()); return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(floutValue), resultType); } else { const MIRDoubleConst *constValue = safe_cast(cst); + ASSERT_NOT_NULL(constValue); double doubleValue = floor(constValue->GetValue()); return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(doubleValue), resultType); } @@ -1052,14 +1060,17 @@ MIRConst *ConstantFold::FoldRoundMIRConst(const MIRConst *cst, PrimType fromType MIRType &resultType = *GlobalTables::GetTypeTable().GetPrimType(toType); if (fromType == PTY_f32) { const MIRFloatConst *constValue = safe_cast(cst); + ASSERT_NOT_NULL(constValue); float floatValue = round(constValue->GetValue()); return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(floatValue), resultType); } else if (fromType == PTY_f64) { const MIRDoubleConst *constValue = safe_cast(cst); + ASSERT_NOT_NULL(constValue); double doubleValue = round(constValue->GetValue()); return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(doubleValue), resultType); } else if (toType == PTY_f32 && IsPrimitiveInteger(fromType)) { const MIRIntConst *constValue = safe_cast(cst); + ASSERT_NOT_NULL(constValue); int64 fromValue = constValue->GetValue(); float floatValue = round(static_cast(fromValue)); if (static_cast(floatValue) == fromValue) { @@ -1067,6 +1078,7 @@ MIRConst *ConstantFold::FoldRoundMIRConst(const MIRConst *cst, PrimType fromType } } else if (toType == PTY_f64 && IsPrimitiveInteger(fromType)) { const MIRIntConst *constValue = safe_cast(cst); + ASSERT_NOT_NULL(constValue); int64 fromValue = constValue->GetValue(); double doubleValue = round(static_cast(fromValue)); if (static_cast(doubleValue) == fromValue) { @@ -1091,11 +1103,13 @@ ConstvalNode *ConstantFold::FoldTrunk(const ConstvalNode *cst, PrimType fromType CHECK_NULL_FATAL(cst); if (fromType == PTY_f32) { const MIRFloatConst *constValue = safe_cast(cst->GetConstVal()); + CHECK_NULL_FATAL(constValue); float floutValue = trunc(constValue->GetValue()); resultConst->SetConstVal(GlobalTables::GetIntConstTable().GetOrCreateIntConst( static_cast(floutValue), resultType)); } else { const MIRDoubleConst *constValue = safe_cast(cst->GetConstVal()); + CHECK_NULL_FATAL(constValue); double doubleValue = trunc(constValue->GetValue()); resultConst->SetConstVal(GlobalTables::GetIntConstTable().GetOrCreateIntConst( static_cast(doubleValue), resultType)); @@ -1119,9 +1133,10 @@ MIRConst *ConstantFold::FoldTypeCvtMIRConst(const MIRConst *cst, PrimType fromTy } toConst = FoldSignExtendMIRConst(op, toType, fromSize, cst); } else { - const MIRIntConst *c = safe_cast(cst); + const MIRIntConst *constVal = safe_cast(cst); + ASSERT_NOT_NULL(constVal); MIRType &type = *GlobalTables::GetTypeTable().GetPrimType(toType); - toConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(c->GetValue(), type); + toConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(constVal->GetValue(), type); } return toConst; } @@ -1130,12 +1145,14 @@ MIRConst *ConstantFold::FoldTypeCvtMIRConst(const MIRConst *cst, PrimType fromTy if (GetPrimTypeBitSize(toType) < GetPrimTypeBitSize(fromType)) { ASSERT(GetPrimTypeBitSize(toType) == 32, "We suppot F32 and F64"); const MIRDoubleConst *fromValue = safe_cast(cst); + ASSERT_NOT_NULL(fromValue); float floutValue = static_cast(fromValue->GetValue()); MIRFloatConst *toValue = GlobalTables::GetFpConstTable().GetOrCreateFloatConst(floutValue); 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); toConst = toValue; @@ -1212,12 +1229,13 @@ std::pair ConstantFold::FoldTypeCvt(TypeCvtNode *node) { MIRConst *ConstantFold::FoldSignExtendMIRConst(Opcode opcode, PrimType resultType, uint8 size, const MIRConst *cst) const { - const MIRIntConst *c = safe_cast(cst); + const MIRIntConst *constVal = safe_cast(cst); + ASSERT_NOT_NULL(constVal); uint64 result64 = 0; if (opcode == OP_sext) { - result64 = (c->GetValue() << (64u - size)) >> (64u - size); + result64 = (constVal->GetValue() << (64u - size)) >> (64u - size); } else { - result64 = ((static_cast(c->GetValue())) << (64u - size)) >> (64u - size); + result64 = ((static_cast(constVal->GetValue())) << (64u - size)) >> (64u - size); } MIRType &type = *GlobalTables::GetTypeTable().GetPrimType(resultType); MIRIntConst *constValue = GlobalTables::GetIntConstTable().GetOrCreateIntConst(result64, type); @@ -1307,11 +1325,15 @@ std::pair ConstantFold::FoldBinary(BinaryNode *node) { ConstvalNode *rConst = safe_cast(r); bool isInt = IsPrimitiveInteger(primType); if (lConst != nullptr && rConst != nullptr) { + MIRIntConst *lConstVal = safe_cast(lConst->GetConstVal()); + MIRIntConst *rConstVal = safe_cast(rConst->GetConstVal()); + ASSERT_NOT_NULL(lConstVal); + ASSERT_NOT_NULL(rConstVal); // Don't fold div by 0, for floats div by 0 is well defined. if ((op == OP_div || op == OP_rem) && isInt && - (safe_cast(rConst->GetConstVal())->GetValue() == 0 || - safe_cast(lConst->GetConstVal())->GetValue() == LONG_MIN || - safe_cast(lConst->GetConstVal())->GetValue() == INT_MIN)) { + (rConstVal->GetValue() == 0 || + lConstVal->GetValue() == LONG_MIN || + lConstVal->GetValue() == INT_MIN)) { result = NewBinaryNode(node, op, primType, lConst, rConst); sum = 0; } else { @@ -1325,6 +1347,7 @@ std::pair ConstantFold::FoldBinary(BinaryNode *node) { } } else if (lConst != nullptr && isInt) { MIRIntConst *mcst = safe_cast(lConst->GetConstVal()); + ASSERT_NOT_NULL(mcst); PrimType cstTyp = mcst->GetType().GetPrimType(); int64 cst = mcst->GetValue(); if (op == OP_add) { @@ -1378,6 +1401,7 @@ std::pair ConstantFold::FoldBinary(BinaryNode *node) { } } else if (rConst != nullptr && isInt) { MIRIntConst *mcst = safe_cast(rConst->GetConstVal()); + ASSERT_NOT_NULL(mcst); PrimType cstTyp = mcst->GetType().GetPrimType(); int64 cst = mcst->GetValue(); if (op == OP_add) { @@ -1584,6 +1608,8 @@ std::pair ConstantFold::FoldDepositbits(DepositbitsNode *node) if (leftConst != nullptr && rightConst != nullptr) { MIRIntConst *intConst0 = safe_cast(leftConst->GetConstVal()); MIRIntConst *intConst1 = safe_cast(rightConst->GetConstVal()); + ASSERT_NOT_NULL(intConst0); + ASSERT_NOT_NULL(intConst1); ConstvalNode *resultConst = mirModule->CurFuncCodeMemPool()->New(); resultConst->SetPrimType(node->GetPrimType()); MIRType &type = *GlobalTables::GetTypeTable().GetPrimType(node->GetPrimType()); @@ -1656,6 +1682,7 @@ std::pair ConstantFold::FoldTernary(TernaryNode *node) { ConstvalNode *const0 = safe_cast(p[0].first); if (const0 != nullptr) { MIRIntConst *intConst0 = safe_cast(const0->GetConstVal()); + ASSERT_NOT_NULL(intConst0); // Selecting the first value if not 0, selecting the second value otherwise. if (intConst0->GetValue()) { result = PairToExpr(primTypes[1], p[1]); @@ -1667,8 +1694,10 @@ std::pair ConstantFold::FoldTernary(TernaryNode *node) { ConstvalNode *const2 = safe_cast(p[2].first); if (const1 != nullptr && const2 != nullptr) { MIRIntConst *intConst1 = safe_cast(const1->GetConstVal()); - MIRIntConst *int2 = safe_cast(const2->GetConstVal()); - if (intConst1->GetValue() == 1 && int2->GetValue() == 0) { + MIRIntConst *intConst2 = safe_cast(const2->GetConstVal()); + ASSERT_NOT_NULL(intConst1); + ASSERT_NOT_NULL(intConst2); + if (intConst1->GetValue() == 1 && intConst2->GetValue() == 0) { BaseNode *tmpNode = node->Opnd(0); if (node->GetPrimType() != PTY_u1) { tmpNode = mirModule->CurFuncCodeMemPool()->New(OP_cvt, PrimType(node->GetPrimType()), @@ -1676,7 +1705,7 @@ std::pair ConstantFold::FoldTernary(TernaryNode *node) { } std::pair pairTemp = DispatchFold(tmpNode); result = PairToExpr(node->GetPrimType(), pairTemp); - } else if (intConst1->GetValue() == 0 && int2->GetValue() == 1) { + } else if (intConst1->GetValue() == 0 && intConst2->GetValue() == 1) { BaseNode *lnot = mirModule->CurFuncCodeMemPool()->New(OP_lnot, PTY_u1, node->Opnd(0)); BaseNode *tmpNode = lnot; if (node->GetPrimType() != PTY_u1) { @@ -1758,6 +1787,7 @@ StmtNode *ConstantFold::SimplifyCondGoto(CondGotoNode *node) { return node; } MIRIntConst *intConst = safe_cast(cst->GetConstVal()); + ASSERT_NOT_NULL(intConst); if ((node->GetOpCode() == OP_brtrue && intConst->GetValueUnderType() != 0) || (node->GetOpCode() == OP_brfalse && intConst->GetValueUnderType() == 0)) { GotoNode *gotoNode = mirModule->CurFuncCodeMemPool()->New(OP_goto); @@ -1782,10 +1812,12 @@ StmtNode *ConstantFold::SimplifyCondGotoSelect(CondGotoNode *node) const { ConstvalNode *const2 = safe_cast(sel->Opnd(2)); if (const1 != nullptr && const2 != nullptr) { MIRIntConst *intConst1 = safe_cast(const1->GetConstVal()); - MIRIntConst *int2 = safe_cast(const2->GetConstVal()); - if (intConst1->GetValue() == 1 && int2->GetValue() == 0) { + MIRIntConst *intConst2 = safe_cast(const2->GetConstVal()); + ASSERT_NOT_NULL(intConst1); + ASSERT_NOT_NULL(intConst2); + if (intConst1->GetValue() == 1 && intConst2->GetValue() == 0) { node->SetOpnd(sel->Opnd(0), 0); - } else if (intConst1->GetValue() == 0 && int2->GetValue() == 1) { + } else if (intConst1->GetValue() == 0 && intConst2->GetValue() == 1) { node->SetOpCode((node->GetOpCode() == OP_brfalse) ? OP_brtrue : OP_brfalse); node->SetOpnd(sel->Opnd(0), 0); } @@ -1804,6 +1836,7 @@ StmtNode *ConstantFold::SimplifySwitch(SwitchNode *node) { return node; } MIRIntConst *intConst = safe_cast(cst->GetConstVal()); + ASSERT_NOT_NULL(intConst); GotoNode *gotoNode = mirModule->CurFuncCodeMemPool()->New(OP_goto); bool isdefault = true; for (unsigned i = 0; i < node->GetSwitchTable().size(); i++) { @@ -1905,6 +1938,7 @@ StmtNode *ConstantFold::SimplifyIf(IfStmtNode *node) { return node; } MIRIntConst *intConst = safe_cast(cst->GetConstVal()); + ASSERT_NOT_NULL(intConst); if (intConst->GetValue() == 0) { return node->GetElsePart(); } else { diff --git a/src/mpl2mpl/src/gen_check_cast.cpp b/src/mpl2mpl/src/gen_check_cast.cpp index b8a4370a6641dc177ff498e345f36b0d5ff7f408..112c455e13f835c6aff0c16d78711e1f773a1821 100644 --- a/src/mpl2mpl/src/gen_check_cast.cpp +++ b/src/mpl2mpl/src/gen_check_cast.cpp @@ -129,14 +129,16 @@ void CheckCastGenerator::GenCheckCast(StmtNode &stmt) { CHECK_FATAL(callNodeNopndSize2 > 0, "container check"); BaseNode *cond = builder->CreateExprCompare(OP_ne, *GlobalTables::GetTypeTable().GetUInt1(), - *GlobalTables::GetTypeTable().GetPtr(), callNode->GetNopndAt(0), nullPtrConst); + *GlobalTables::GetTypeTable().GetPtrType(), callNode->GetNopndAt(0), + nullPtrConst); auto *ifStmt = static_cast(builder->CreateStmtIf(cond)); MIRType *mVoidPtr = GlobalTables::GetTypeTable().GetVoidPtr(); CHECK_FATAL(mVoidPtr != nullptr, "builder->GetVoidPtr() is null in CheckCastGenerator::GenCheckCast"); BaseNode *opnd = callNode->GetNopndAt(0); BaseNode *ireadExpr = GetObjectShadow(opnd); BaseNode *innerCond = builder->CreateExprCompare(OP_ne, *GlobalTables::GetTypeTable().GetUInt1(), - *GlobalTables::GetTypeTable().GetPtr(), valueExpr, ireadExpr); + *GlobalTables::GetTypeTable().GetPtrType(), valueExpr, + ireadExpr); auto *innerIfStmt = static_cast(builder->CreateStmtIf(innerCond)); MapleVector args(builder->GetCurrentFuncCodeMpAllocator()->Adapter()); args.push_back(valueExpr); diff --git a/src/mpl2mpl/src/muid_replacement.cpp b/src/mpl2mpl/src/muid_replacement.cpp index 49bdaacf73cff754d2faae98bad251f17d2350da..1d78e30ddd2c718547ad45cad1e72b0ca2718c74 100644 --- a/src/mpl2mpl/src/muid_replacement.cpp +++ b/src/mpl2mpl/src/muid_replacement.cpp @@ -483,7 +483,7 @@ void MUIDReplacement::GenerateDataDefTable() { } } -void MUIDReplacement::ReplaceFieldMetaStaticAddr(MIRSymbol &mirSymbol, int64 index) { +void MUIDReplacement::ReplaceFieldMetaStaticAddr(MIRSymbol &mirSymbol, uint32 index) { std::string symbolName = mirSymbol.GetName(); MIRSymbol *fieldOffsetDataSt = GlobalTables::GetGsymTable().GetSymbolFromStrIdx( GlobalTables::GetStrTable().GetStrIdxFromName(NameMangler::kFieldOffsetDataPrefixStr + symbolName)); diff --git a/src/mpl2mpl/src/native_stub_func.cpp b/src/mpl2mpl/src/native_stub_func.cpp index 341bb1c8ec19a7815bcd18312013fb1fc7c8ad47..c0d2de888ea59b36fddb9b1513a17e29b1239e48 100644 --- a/src/mpl2mpl/src/native_stub_func.cpp +++ b/src/mpl2mpl/src/native_stub_func.cpp @@ -220,8 +220,7 @@ void NativeStubFuncGeneration::ProcessFunc(MIRFunction *func) { MIRFunction &nativeFunc = GetOrCreateDefaultNativeFunc(*func); if (Options::regNativeFunc) { - GenerateRegisteredNativeFuncCall(*func, nativeFunc, allocCallArgs, stubFuncRet, needNativeCall, *preFuncCall, - *postFuncCall); + GenerateRegisteredNativeFuncCall(*func, nativeFunc, allocCallArgs, stubFuncRet); } else if (Options::nativeWrapper) { GenerateNativeWrapperFuncCall(*func, nativeFunc, allocCallArgs, stubFuncRet); } else { @@ -328,9 +327,7 @@ void NativeStubFuncGeneration::GenerateRegTabEntry(const MIRFunction &func) { } void NativeStubFuncGeneration::GenerateRegisteredNativeFuncCall(MIRFunction &func, const MIRFunction &nativeFunc, - MapleVector &args, const MIRSymbol *ret, - bool needNativeCall, CallNode &preNativeFuncCall, - CallNode &postNativeFuncCall) { + MapleVector &args, const MIRSymbol *ret) { // Generate registration table entry. GenerateRegTabEntry(func); GenerateRegFuncTabEntry(); @@ -422,13 +419,7 @@ void NativeStubFuncGeneration::GenerateRegisteredNativeFuncCall(MIRFunction &fun *GlobalTables::GetTypeTable().GetOrCreatePointerType(*elemType), 0, arrayExpr, nativeMethodPtr); subIfStmt->GetThenPart()->AddStatement(nativeFuncTableEntry); // Add if-statement to function body - if (!needNativeCall) { - ifStmt->GetThenPart()->AddStatement(&preNativeFuncCall); - } ifStmt->GetThenPart()->AddStatement(callGetFindNativeFunc); - if (!needNativeCall) { - ifStmt->GetThenPart()->AddStatement(&postNativeFuncCall); - } ifStmt->GetThenPart()->AddStatement(callDummyNativeFunc); ifStmt->GetThenPart()->AddStatement(subIfStmt); if (needCheckThrowPendingExceptionFunc) { @@ -458,13 +449,7 @@ void NativeStubFuncGeneration::GenerateRegisteredNativeFuncCall(MIRFunction &fun CallNode *callGetFindNativeFunc = builder->CreateStmtCallRegassigned(findNativeFunc->GetPuidx(), dynamicStubOpnds, funcptrPreg, OP_callassigned); // Add if-statement to function body - if (!needNativeCall) { - ifStmt->GetThenPart()->AddStatement(&preNativeFuncCall); - } ifStmt->GetThenPart()->AddStatement(callGetFindNativeFunc); - if (!needNativeCall) { - ifStmt->GetThenPart()->AddStatement(&postNativeFuncCall); - } if (!needCheckThrowPendingExceptionFunc) { MapleVector opnds(builder->GetCurrentFuncCodeMpAllocator()->Adapter()); CallNode *callGetExceptFunc = builder->CreateStmtCallAssigned(MRTCheckThrowPendingExceptionFunc->GetPuidx(), @@ -514,7 +499,12 @@ StmtNode *NativeStubFuncGeneration::CreateNativeWrapperCallNode(MIRFunction &fun auto isFast = (func.GetAttr(FUNCATTR_fast_native) || func.GetAttr(FUNCATTR_critical_native)); // Do not need native wrapper for critical natives // if num_of_args < 8 +#ifdef USE_ARM32_MACRO + constexpr size_t numOfArgs = 4; +#else constexpr size_t numOfArgs = 8; +#endif + if (func.GetAttr(FUNCATTR_critical_native) && args.size() < numOfArgs) { auto *icall = func.GetCodeMempool()->New(GetMIRModule(), OP_icallassigned); CallReturnVector nrets(func.GetCodeMempoolAllocator().Adapter()); @@ -677,8 +667,14 @@ void NativeStubFuncGeneration::Finish() { } } +#ifdef USE_ARM32_MACRO +const std::string NativeStubFuncGeneration::callSlowNativeFuncs[kSlownativeFuncnum] = { + "MCC_CallSlowNative0", "MCC_CallSlowNative1", "MCC_CallSlowNative2", "MCC_CallSlowNative3", "MCC_CallSlowNative4" +}; +#else const std::string NativeStubFuncGeneration::callSlowNativeFuncs[kSlownativeFuncnum] = { "MCC_CallSlowNative0", "MCC_CallSlowNative1", "MCC_CallSlowNative2", "MCC_CallSlowNative3", "MCC_CallSlowNative4", "MCC_CallSlowNative5", "MCC_CallSlowNative6", "MCC_CallSlowNative7", "MCC_CallSlowNative8" }; +#endif } // namespace maple diff --git a/src/mpl2mpl/src/reflection_analysis.cpp b/src/mpl2mpl/src/reflection_analysis.cpp index 4d44bf37c0eafb287224b93c2541cb74c2f2a905..08abf832cb3950ac6fcf1dde891e69051a1b9767 100644 --- a/src/mpl2mpl/src/reflection_analysis.cpp +++ b/src/mpl2mpl/src/reflection_analysis.cpp @@ -615,8 +615,8 @@ uint16 ReflectionAnalysis::GetMethodInVtabIndex(const Klass &klass, const MIRFun void ReflectionAnalysis::GetSignatureTypeNames(std::string &signature, std::vector &typeNames) { ConvertMethodSig(signature); - int sigLen = signature.length(); - int i = 0; + size_t sigLen = signature.length(); + size_t i = 0; const char *methodSignature = signature.c_str(); ++i; while (i < sigLen && methodSignature[i] != ')') { @@ -860,6 +860,7 @@ void ReflectionAnalysis::GenFieldOffsetConst(MIRAggConst &newConst, const Klass FieldID fldID = mirBuilder.GetStructFieldIDFromNameAndTypeParentFirstFoundInChild( *mirClassType, originFieldname, fieldP.second.first); // set LSB 0, and set LSB 1 in muid_replacement + CHECK_FATAL(fldID <= UINT32_MAX / 2, "filedId out of range"); fldID = fldID * 2; mirBuilder.AddIntFieldConst(type, newConst, metaFieldID, fldID); } @@ -1280,7 +1281,7 @@ uint32 ReflectionAnalysis::GetAnnoCstrIndex(std::map &idxNumMap, const subStr += annoDelimiter; }); subStr += annoArr; - signatureIdx = GetDeflateStringIdx(subStr, !isField); + signatureIdx = static_cast(GetDeflateStringIdx(subStr, !isField)); } return signatureIdx; } @@ -1365,7 +1366,7 @@ void ReflectionAnalysis::GenClassMetaData(Klass &klass) { uint32 nameIdx = FindOrInsertReflectString(klassJavaDescriptor); mirBuilder.AddIntFieldConst(classMetadataROType, *newConst, fieldID++, nameIdx); // @iFields: All instance fields. - int numOfFields = 0; + uint32 numOfFields = 0; bool hasAdded = false; if (klass.GetKlassName() == NameMangler::GetInternalNameLiteral(NameMangler::kJavaLangObjectStr)) { const GStrIdx stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName( @@ -1387,7 +1388,7 @@ void ReflectionAnalysis::GenClassMetaData(Klass &klass) { } } // @methods: All methods. - int numOfMethods = 0; + uint32 numOfMethods = 0; MIRSymbol *methodsSt; methodsSt = GenMethodsMetaData(klass); if (methodsSt != nullptr) {