diff --git a/Makefile b/Makefile index fab8b569bf1b8a4f7fe42cd70baaef28a6bcb26a..6a00054a803dc2d404b95d4a5e9ac812c006194a 100644 --- a/Makefile +++ b/Makefile @@ -53,8 +53,10 @@ mplfe: .PHONY: install install: maple - $(shell cp -rf $(MAPLE_ROOT)/src/bin/java2jar $(MAPLE_ROOT)/output/bin/) - $(shell cp -rf $(MAPLE_ROOT)/src/bin/jbc2mpl $(MAPLE_ROOT)/output/bin/) + $(shell mkdir -p $(MAPLE_ROOT)/output/ops/linker/; \ + cp -rf $(MAPLE_ROOT)/build/maplelld.so.lds $(MAPLE_ROOT)/output/ops/linker/; \ + cp -rf $(MAPLE_ROOT)/src/bin/java2jar $(MAPLE_ROOT)/output/bin/; \ + cp -rf $(MAPLE_ROOT)/src/bin/jbc2mpl $(MAPLE_ROOT)/output/bin/) .PHONY: clean clean: diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn index 455c055bf2eea4ea22cd456840bd4d90674cd5e2..2f4cb8c658d33c0b243b27bd4123b5d27219c5c4 100644 --- a/build/config/BUILDCONFIG.gn +++ b/build/config/BUILDCONFIG.gn @@ -62,11 +62,13 @@ if (GN_BUILD_TYPE == "RELEASE") { cflags_cc += [ "-O0", "-g3", + "-ftrapv", "-fstack-check", ] cflags_c += [ "-O0", "-g3", + "-ftrapv", "-fstack-check", ] } else { diff --git a/build/maplelld.so.lds b/build/maplelld.so.lds new file mode 100644 index 0000000000000000000000000000000000000000..76480328f67d8b6fa0545cf7e83f13c8c41c33c0 --- /dev/null +++ b/build/maplelld.so.lds @@ -0,0 +1,426 @@ +/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */ +/* + * Copyright (c) [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. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + */ +OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64", + "elf64-littleaarch64") +OUTPUT_ARCH(aarch64) +SEARCH_DIR("=/usr/local/lib/aarch64-linux-gnu"); SEARCH_DIR("=/lib/aarch64-linux-gnu"); SEARCH_DIR("=/usr/lib/aarch64-linux-gnu"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib"); SEARCH_DIR("=/usr/aarch64-linux-gnu/lib"); +PHDRS +{ + text PT_LOAD FILEHDR PHDRS; + data PT_LOAD; + dynamic PT_DYNAMIC; + note PT_NOTE; + gnu_eh_frame PT_GNU_EH_FRAME; + gnu_stack PT_GNU_STACK; + gnu_relro PT_GNU_RELRO; + /* headers PT_PHDR PHDRS; */ /* Reserve segment for lld */ + /* interp PT_INTERP; */ /* Reserve segment for lld */ + thread_local PT_TLS; /* Reserve segment for lld */ +} + +SECTIONS +{ + PROVIDE_HIDDEN(__maple_start__ = .); + /* Read-only sections, merged into text segment: */ + PROVIDE (__executable_start = SEGMENT_START("text-segment", 0)); . = SEGMENT_START("text-segment", 0) + SIZEOF_HEADERS; + .interp : { *(.interp) } + .note.gnu.build-id : + { + PROVIDE_HIDDEN (__linkerHashSo_begin = .); + KEEP (*(.note.gnu.build-id)) + PROVIDE_HIDDEN (__linkerHashSo_end = .); + } :text :note + .hash : { *(.hash) } :text + .gnu.hash : { *(.gnu.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rela.dyn : + { + *(.rela.init) + *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) + *(.rela.fini) + *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) + *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) + *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) + *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) + *(.rela.ctors) + *(.rela.dtors) + *(.rela.got) + *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) + *(.rela.ifunc) + } + .rela.plt : + { + *(.rela.plt) + PROVIDE_HIDDEN (__rela_iplt_start = .); + *(.rela.iplt) + PROVIDE_HIDDEN (__rela_iplt_end = .); + } + .init : + { + KEEP (*(.init)) + } =0 + .plt : ALIGN(16) { *(.plt) *(.iplt) } + .text : + { + *(.text.unlikely .text.*_unlikely .text.unlikely.*) + *(.text.exit .text.exit.*) + *(.text.startup .text.startup.*) + *(.text.hot .text.hot.*) + *(.text .stub .text.* .gnu.linkonce.t.*) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + } =0 + .java_text : + { + PROVIDE_HIDDEN (java_text_begin = .); + KEEP (*(.java_text)) + PROVIDE_HIDDEN (java_text_end = .); + } + .fini : + { + KEEP (*(.fini)) + } =0 + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } + .rometadata : + { + mfile_rometadata_method_start = .; + KEEP (*(.rometadata.method)) + mfile_rometadata_method_end = .; + + mfile_rometadata_field_start = .; + KEEP (*(.rometadata.field)) + mfile_rometadata_field_end = .; + } + .romuidtab : + { + mfile_romuidtab_start = .; + KEEP (*(.__muid_ro_func_def_orig_tab)) + KEEP (*(.__muid_ro_data_def_orig_tab)) + /* madvised */ + KEEP (*(.__muid_ro_func_inf_tab)) + /* madvised */ + KEEP (*(.__muid_ro_func_def_muid_tab)) + /* madvised */ + KEEP (*(.__muid_ro_data_def_muid_tab)) + KEEP (*(.__muid_ro_func_undef_muid_tab)) + KEEP (*(.__muid_ro_data_undef_muid_tab)) + /* madvised */ + KEEP (*(.__muid_ro_func_muid_idx_tab)) + mfile_romuidtab_end = .; + } + .rodata1 : { *(.rodata1) } + .eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) } :text :gnu_eh_frame + .eh_frame : ONLY_IF_RO + { + PROVIDE_HIDDEN ( __eh_frame_start = .); + KEEP (*(.eh_frame)) *(.eh_frame.*) + PROVIDE_HIDDEN ( __eh_frame_end = .); + } :text + .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table + .gcc_except_table.*) } + .gnu_extab : ONLY_IF_RO { *(.gnu_extab*) } + /* These sections are generated by the Sun/Oracle C++ compiler. */ + .exception_ranges : ONLY_IF_RO { *(.exception_ranges + .exception_ranges*) } + + /* Adjust the address for the data segment. We want to adjust up to + the same address within the page on the next page up. */ + . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); + /* Exception handling */ + .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) } + .gnu_extab : ONLY_IF_RW { *(.gnu_extab) } + .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } + .exception_ranges : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) } + /* Thread Local Storage sections */ + .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } :thread_local + .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } :thread_local + .dynamic : { *(.dynamic) } :data :gnu_relro :dynamic + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(.init_array.* .ctors.*)) + KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors)) + PROVIDE_HIDDEN (__init_array_end = .); + } :data :gnu_relro + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(.fini_array.* .dtors.*)) + KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors)) + PROVIDE_HIDDEN (__fini_array_end = .); + } :data :gnu_relro + .ctors : + { + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + } + .dtors : + { + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + } + .jcr : { KEEP (*(.jcr)) } + .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) } + .got : { *(.got) *(.igot) } :data :gnu_relro + . = DATA_SEGMENT_RELRO_END (24, .); + .got.plt : { *(.got.plt) *(.igot.plt) } :data + .data : + { + PROVIDE_HIDDEN (__data_section_begin = .); + *(.data .data.* .gnu.linkonce.d.*) + SORT(CONSTRUCTORS) + PROVIDE_HIDDEN (__data_section_end = .); + } + .data1 : { *(.data1) } + _edata = .; PROVIDE (edata = .); + /* maple specific sections */ + . = ALIGN( 8 ); + .maple.gcrootsmap : + { + KEEP (*(.maple.gcrootsmap)) + } + + . = ALIGN( 8 ); + .reg_jni_tab : + { + PROVIDE_HIDDEN (__reg_jni_tab_begin = .); + KEEP (*(.reg_jni_tab)) + PROVIDE_HIDDEN (__reg_jni_tab_end = .); + } + + . = ALIGN( 8 ); + .reg_jni_func_tab : + { + PROVIDE_HIDDEN (__reg_jni_func_tab_begin = .); + KEEP (*(.reg_jni_func_tab)) + PROVIDE_HIDDEN (__reg_jni_func_tab_end = .); + } + + . = ALIGN( 8 ); + .bb_profile_strtab : + { + PROVIDE_HIDDEN (__bb_profile_strtab_begin = .); + KEEP (*(.__bb_profile_strtab)) + PROVIDE_HIDDEN (__bb_profile_strtab_end = .); + } + + . = ALIGN( 8 ); + .bb_profile_tab : + { + PROVIDE_HIDDEN (__bb_profile_tab_begin = .); + KEEP (*(.__bb_profile_tab)) + PROVIDE_HIDDEN (__bb_profile_tab_end = .); + } + + . = ALIGN( 8 ); + .muid_tab : + { + PROVIDE_HIDDEN (__muid_tab_start = .); + + PROVIDE_HIDDEN (__decouple_start__ = .); + KEEP (*(.__decouple)) + PROVIDE_HIDDEN (__decouple_end__ = .); + + PROVIDE_HIDDEN (__muid_range_tab_begin__ = .); + KEEP (*(.__muid_range_tab)) + PROVIDE_HIDDEN (__muid_range_tab_end__ = .); + + PROVIDE_HIDDEN (__muid_conststr_start__ = .); + KEEP (*(.__muid_conststr)) + PROVIDE_HIDDEN (__muid_conststr_end__ = .); + + KEEP (*(.__muid_func_def_tab)) + KEEP (*(.__muid_func_undef_tab)) + KEEP (*(.__muid_data_def_tab)) + KEEP (*(.__muid_data_undef_tab)) + KEEP (*(.__muid_itab)) + KEEP (*(.__muid_vtab)) + KEEP (*(.__muid_vtab_offset_tab)) + KEEP (*(.__muid_field_offset_tab)) + KEEP (*(.__muid_superclass)) + KEEP (*(.__muid_offset_value_table)) + KEEP (*(.__muid_local_classinfo_tab)) + + PROVIDE_HIDDEN (__muid_tab_end = .); + } + + . = ALIGN( 8 ); + .mpl_version : + { + PROVIDE_HIDDEN (__compilerVersionNumTab_begin__ = .); + KEEP (*(.__compilerVersionNumTab)) + PROVIDE_HIDDEN (__compilerVersionNumTab_end__ = .); + + KEEP (*(.__sourceMuidTab)) + + PROVIDE_HIDDEN (__compiler_mfile_status_begin__ = .); + KEEP (*(.__compiler_mfile_status)) + PROVIDE_HIDDEN (__compiler_mfile_status_end__ = .); + } + + . = ALIGN( 8 ); + .profile_tab : + { + KEEP (*(.__profile_func_tab)) + } + + . = ALIGN( 8 ); + .classmetadata : + { + KEEP (*(.__muid_classmetadata)) + } + + . = ALIGN( 8 ); + .classmetadata_bucket : + { + PROVIDE_HIDDEN (__muid_classmetadata_bucket_begin = .); + *(.__muid_classmetadata_bucket) + PROVIDE_HIDDEN (__muid_classmetadata_bucket_end = .); + } + + .refl_strtab : + { + . = ALIGN( 8 ); + PROVIDE_HIDDEN(__reflection_strtab_start__ = .); + KEEP (*(.reflection_strtab)) + PROVIDE_HIDDEN(__reflection_strtab_end__ = .); + } + + .refl_strtab.hot : + { + . = ALIGN( 8 ); + PROVIDE_HIDDEN(__reflection_start_hot_strtab_start__ = .); + KEEP (*(.reflection_start_hot_strtab)) + PROVIDE_HIDDEN(__reflection_start_hot_strtab_end__ = .); + + . = ALIGN( 8 ); + PROVIDE_HIDDEN(__reflection_both_hot_strtab_start__ = .); + KEEP (*(.reflection_both_hot_strtab)) + PROVIDE_HIDDEN(__reflection_both_hot_strtab_end__ = .); + + . = ALIGN( 8 ); + PROVIDE_HIDDEN(__reflection_run_hot_strtab_start__ = .); + KEEP (*(.reflection_run_hot_strtab)) + PROVIDE_HIDDEN(__reflection_run_hot_strtab_end__ = .); + } + + . = ALIGN( 4096 ); + __bss_start = . ; __bss_start__ = . ; + .bss : + { + PROVIDE_HIDDEN(__bss_section_begin = .); + *(.dynbss) + *(.bss .bss.* .gnu.linkonce.b.*) + *(COMMON) + /* Align here to ensure that the .bss section occupies space up to + _end. Align after .bss to ensure correct alignment even if the + .bss section disappears because there are no input sections. + FIXME: Why do we need it? When there is no .bss section, we don't + pad the .data section. */ + . = ALIGN(. != 0 ? 64 / 8 : 1); + PROVIDE_HIDDEN(__bss_section_end = .); + } + _bss_end__ = . ; __bss_end__ = . ; + + . = ALIGN(64 / 8); + . = SEGMENT_START("ldata-segment", .); + . = ALIGN(64 / 8); + __end__ = .; + PROVIDE_HIDDEN(__maple_end__ = .); + _end = .; PROVIDE (end = .); + . = DATA_SEGMENT_END (.); + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .maple_java_debug_aranges 0 : { KEEP(*(.maple_java_debug_aranges)) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } + .maple_java_debug_info 0 : { KEEP(*(.maple_java_debug_info)) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .maple_java_debug_abbrev 0 : { KEEP(*(.maple_java_debug_abbrev)) } + .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end ) } + .maple_java_debug_line 0 : { KEEP(*(.maple_java_debug_line)) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } + /* DWARF 3 */ + .debug_pubtypes 0 : { *(.debug_pubtypes) } + .debug_ranges 0 : { *(.debug_ranges) } + .maple_java_debug_ranges 0 : { KEEP(*(.maple_java_debug_ranges)) } + /* DWARF Extension. */ + .debug_macro 0 : { *(.debug_macro) } + .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) } + .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) } + /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) } +} diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index bcf4d096870b98b4e98e1afd7e939fb6527e7d63..42c3412f56dfc5531219a755e318f97a372ba615 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index ae98f86e8e5ef3a5180e96aad1ca9ddab3c8e3a3..ce73d9ba0a6443b28a3d53d4535155339a6dd2de 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/deplibs/libmplphase.a b/src/deplibs/libmplphase.a index 1baa57c362ae927ee8a4343c64e990a8b3206f3c..8052303ccf5d7f038c1d36a71c31f8680ef9b168 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 1f51965b115af3d8be38ecb093e6d15f55306c86..6c8c5359f60aeb376f586b45863caa57df8befb1 100644 Binary files a/src/deplibs/libmplutil.a and b/src/deplibs/libmplutil.a differ diff --git a/src/maple_driver/src/jbc2mpl_compiler.cpp b/src/maple_driver/src/jbc2mpl_compiler.cpp index 02c75f96c368c7f635c35e8e55b740ec5f31f930..5f261ea9599fa307a47e1970c69a5f78a2e6af9c 100644 --- a/src/maple_driver/src/jbc2mpl_compiler.cpp +++ b/src/maple_driver/src/jbc2mpl_compiler.cpp @@ -33,8 +33,8 @@ void Jbc2MplCompiler::GetTmpFilesToDelete(const MplOptions &mplOptions, std::vec std::unordered_set Jbc2MplCompiler::GetFinalOutputs(const MplOptions &mplOptions) const { std::unordered_set finalOutputs; - finalOutputs.insert(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mpl"); - finalOutputs.insert(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mplt"); + (void)finalOutputs.insert(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mpl"); + (void)finalOutputs.insert(mplOptions.GetOutputFolder() + mplOptions.GetOutputName() + ".mplt"); return finalOutputs; } } // namespace maple diff --git a/src/maple_ir/include/global_tables.h b/src/maple_ir/include/global_tables.h index 8f3a61c6057f99a49568fdee72cc37918695748c..d3c8a5b5074b1568f048c4d37dbc46ebfaa8e474 100644 --- a/src/maple_ir/include/global_tables.h +++ b/src/maple_ir/include/global_tables.h @@ -107,12 +107,12 @@ class TypeTable { return typeTable.at(index); } - PrimType GetPrimTypeFromTyIdx(TyIdx tyIdx) const { + PrimType GetPrimTypeFromTyIdx(const TyIdx &tyIdx) const { CHECK_FATAL(tyIdx < typeTable.size(), "array index out of range"); return typeTable.at(tyIdx)->GetPrimType(); } - void SetTypeWithTyIdx(TyIdx tyIdx, MIRType *type); + void SetTypeWithTyIdx(const TyIdx &tyIdx, MIRType &type); TyIdx GetOrCreateMIRType(MIRType *pType); diff --git a/src/maple_ir/include/mir_pragma.h b/src/maple_ir/include/mir_pragma.h index 5c5647a1865030e860e022c2ffbf220a8317615e..165c2a1555e9fd10ade8fca2e41d4f6523ab8043 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{ 0 }, subElemVec(subElemAllocator.Adapter()) { + : subElemVec(subElemAllocator.Adapter()) { subElemVec.clear(); } @@ -169,7 +169,7 @@ class MIRPragmaElement { uint64 u; float f; double d; - } val; + } val { 0 }; MapleVector subElemVec; }; diff --git a/src/maple_ir/include/mir_type.h b/src/maple_ir/include/mir_type.h index e6f57ce5f1f2a8fff9a478e7dce154cdbe2b8c39..c6166c550a128e09dea8107b2aa338b0a3b7ad91 100644 --- a/src/maple_ir/include/mir_type.h +++ b/src/maple_ir/include/mir_type.h @@ -1354,12 +1354,13 @@ class MIRFuncType : public MIRType { paramTypeList(ma.Adapter()), paramAttrsList(ma.Adapter()) {} - explicit MIRFuncType(GStrIdx strIdx, MapleAllocator &ma) + explicit MIRFuncType(const GStrIdx &strIdx, MapleAllocator &ma) : MIRType(kTypeFunction, PTY_ptr, strIdx), paramTypeList(ma.Adapter()), paramAttrsList(ma.Adapter()) {} - MIRFuncType(TyIdx retTyIdx, const std::vector &vecTy, const std::vector &vecAt, MapleAllocator &ma) + MIRFuncType(const TyIdx &retTyIdx, const std::vector &vecTy, + const std::vector &vecAt, MapleAllocator &ma) : MIRType(kTypeFunction, PTY_ptr), retTyIdx(retTyIdx), paramTypeList(ma.Adapter()), diff --git a/src/maple_ir/src/bin_mpl_export.cpp b/src/maple_ir/src/bin_mpl_export.cpp index 204325a220608ed25268c10d75ca35c0e7bcedc5..081d011d38129db7dc39372f82f0fa90985e88d6 100644 --- a/src/maple_ir/src/bin_mpl_export.cpp +++ b/src/maple_ir/src/bin_mpl_export.cpp @@ -293,10 +293,8 @@ int BinaryMplExport::typeMarkOffset = 0; BinaryMplExport::BinaryMplExport(MIRModule &md) : mod(md) { Init(); - static auto constPolicyLoader = InitOutputConstFactory(); - (void)constPolicyLoader; - static auto typePolicyLoader = InitOutputTypeFactory(); - (void)typePolicyLoader; + (void)InitOutputConstFactory(); + (void)InitOutputTypeFactory(); } uint8 BinaryMplExport::Read() { diff --git a/src/maple_ir/src/bin_mpl_import.cpp b/src/maple_ir/src/bin_mpl_import.cpp index 683be89188789265db770aeda8949553b830dfc5..214816c6791b00d9fadae35aa320fb65da08010a 100644 --- a/src/maple_ir/src/bin_mpl_import.cpp +++ b/src/maple_ir/src/bin_mpl_import.cpp @@ -86,7 +86,7 @@ void BinaryMplImport::ReadFileAt(const std::string &name, int32 offset) { CHECK_FATAL(seekRet == 0, "call fseek failed"); buf.resize(size); - size_t result = fread(&buf[0], sizeof(uint8), size, f); + size_t result = fread(&buf[0], sizeof(uint8), static_cast(size), f); fclose(f); CHECK_FATAL(result == static_cast(size), "Error while reading the binary file: %s", name.c_str()); } @@ -716,7 +716,7 @@ MIRType &BinaryMplImport::InsertInTypeTables(MIRType &type) { // New definition wins type.SetTypeIndex(prevTyIdx); CHECK_FATAL(GlobalTables::GetTypeTable().GetTypeTable().empty() == false, "container check"); - GlobalTables::GetTypeTable().SetTypeWithTyIdx(prevTyIdx, type.CopyMIRTypeNode()); + GlobalTables::GetTypeTable().SetTypeWithTyIdx(prevTyIdx, *type.CopyMIRTypeNode()); resultTypePtr = GlobalTables::GetTypeTable().GetTypeFromTyIdx(prevTyIdx); if (!IsIncomplete(*resultTypePtr)) { GlobalTables::GetTypeNameTable().SetGStrIdxToTyIdx(resultTypePtr->GetNameStrIdx(), diff --git a/src/maple_ir/src/global_tables.cpp b/src/maple_ir/src/global_tables.cpp index 8c26e21eb0b5649ef67321d5dcc97eb7713b7b8d..c79abe988e4cad1e81ebaa7208a093ca0f0b40fc 100644 --- a/src/maple_ir/src/global_tables.cpp +++ b/src/maple_ir/src/global_tables.cpp @@ -42,11 +42,11 @@ TypeTable::TypeTable() { } } -void TypeTable::SetTypeWithTyIdx(TyIdx tyIdx, MIRType *type) { +void TypeTable::SetTypeWithTyIdx(const TyIdx &tyIdx, MIRType &type) { CHECK_FATAL(tyIdx < typeTable.size(), "array index out of range"); MIRType *oldType = typeTable.at(tyIdx); - typeTable.at(tyIdx) = type; - if (oldType != nullptr && oldType != type) { + typeTable.at(tyIdx) = &type; + if (oldType != nullptr && oldType != &type) { typeHashTable.erase(oldType); delete oldType; } diff --git a/src/maple_ir/src/lexer.cpp b/src/maple_ir/src/lexer.cpp index 5536ee915774fb57f92ce00db27d3ad4d78b5bc2..533b33f25a22d9d9ef9fb836fe299b42311420d9 100644 --- a/src/maple_ir/src/lexer.cpp +++ b/src/maple_ir/src/lexer.cpp @@ -22,8 +22,8 @@ #include "utils.h" namespace maple { -int32_t HexCharToDigit(char c) { - int32_t ret = utils::ToDigit<16, int32_t>(c); +int32 HexCharToDigit(char c) { + int32 ret = utils::ToDigit<16, int32>(c); return (ret != INT32_MAX ? ret : 0); } @@ -205,20 +205,22 @@ TokenKind MIRLexer::GetIntConst(uint32 valStart, bool negative) { char c = GetCharAtWithUpperCheck(curIdx); theIntVal = HexCharToDigit(c); c = GetNextCurrentCharWithUpperCheck(); - if (theIntVal == 0) { // octal - while (isdigit(c)) { - theIntVal = ((static_cast(theIntVal)) << 3) + HexCharToDigit(c); - c = GetNextCurrentCharWithUpperCheck(); - } - } else { - while (isdigit(c)) { - theIntVal = (theIntVal * 10) + HexCharToDigit(c); - c = GetNextCurrentCharWithUpperCheck(); - } + uint8 hexValue = 10; + if (theIntVal == 0) { + // octal + hexValue = 8; } if (negative) { theIntVal = -theIntVal; } + while (isdigit(c)) { + int32 val = HexCharToDigit(c); + if (negative) { + val = -val; + } + theIntVal = (theIntVal * hexValue) + val; + c = GetNextCurrentCharWithUpperCheck(); + } if (c == 'u' || c == 'U') { // skip 'u' or 'U' c = GetNextCurrentCharWithUpperCheck(); if (c == 'l' || c == 'L') { diff --git a/src/maple_ir/src/mir_const.cpp b/src/maple_ir/src/mir_const.cpp index 3749c4a220dcc87332807b93d2ef0e5a7a0c53e7..bba5c5bc9b35ef8e91b1704db6cc719e7d42a0bc 100644 --- a/src/maple_ir/src/mir_const.cpp +++ b/src/maple_ir/src/mir_const.cpp @@ -62,7 +62,7 @@ uint8 MIRIntConst::GetBitWidth() const { } void MIRIntConst::Trunc(uint8 width) { - const int32 shiftBitNum = 64u - width; + const int32 shiftBitNum = static_cast(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())); - const int32 shiftBitNum = 64u - bitSize; + const int32 shiftBitNum = static_cast(64u - bitSize); if (shiftBitNum < 0) { CHECK_FATAL(false, "shiftBitNum should not be less than zero"); } diff --git a/src/maple_ir/src/parser.cpp b/src/maple_ir/src/parser.cpp index e727391c1af3ce486659c5cd74debe7a8de03d5b..329c6b4145ae56fc7e869d3dc9f85bc1cd718446 100644 --- a/src/maple_ir/src/parser.cpp +++ b/src/maple_ir/src/parser.cpp @@ -852,7 +852,7 @@ bool MIRParser::ParseStructType(TyIdx &styIdx) { if (static_cast(prevType)->IsIncomplete() && !(structType.IsIncomplete())) { structType.SetNameStrIdx(prevType->GetNameStrIdx()); structType.SetTypeIndex(styIdx); - GlobalTables::GetTypeTable().SetTypeWithTyIdx(styIdx, structType.CopyMIRTypeNode()); + GlobalTables::GetTypeTable().SetTypeWithTyIdx(styIdx, *structType.CopyMIRTypeNode()); } } else { styIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&structType); @@ -883,7 +883,7 @@ bool MIRParser::ParseClassType(TyIdx &styidx) { if (static_cast(prevType)->IsIncomplete() && !(classType.IsIncomplete())) { classType.SetNameStrIdx(prevType->GetNameStrIdx()); classType.SetTypeIndex(styidx); - GlobalTables::GetTypeTable().SetTypeWithTyIdx(styidx, classType.CopyMIRTypeNode()); + GlobalTables::GetTypeTable().SetTypeWithTyIdx(styidx, *classType.CopyMIRTypeNode()); } } else { styidx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&classType); @@ -926,7 +926,7 @@ bool MIRParser::ParseInterfaceType(TyIdx &sTyIdx) { if (static_cast(prevType)->IsIncomplete() && !(interfaceType.IsIncomplete())) { interfaceType.SetNameStrIdx(prevType->GetNameStrIdx()); interfaceType.SetTypeIndex(sTyIdx); - GlobalTables::GetTypeTable().SetTypeWithTyIdx(sTyIdx, interfaceType.CopyMIRTypeNode()); + GlobalTables::GetTypeTable().SetTypeWithTyIdx(sTyIdx, *interfaceType.CopyMIRTypeNode()); } } else { sTyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&interfaceType); diff --git a/src/maple_me/include/bb.h b/src/maple_me/include/bb.h index a1d461b991994c3b46cbfa4cac87b73a726317dc..50df279479abfea0542973fd107a0a21cf01da48 100644 --- a/src/maple_me/include/bb.h +++ b/src/maple_me/include/bb.h @@ -117,16 +117,56 @@ class BB { return GetAttributes(kBBAttrIsTryEnd); } - void Dump(MIRModule *mod); - void DumpHeader(MIRModule *mod) const; + void Dump(const MIRModule *mod); + void DumpHeader(const MIRModule *mod) const; void DumpPhi(); void DumpBBAttribute(const MIRModule *mod) const; std::string StrAttribute() const; - void AddPredBB(BB *predVal) { - ASSERT(predVal != nullptr, "null ptr check"); - pred.push_back(predVal); - predVal->succ.push_back(this); + // Only use for common entry bb + void AddEntry(BB &bb) { + succ.push_back(&bb); + } + + // Only use for common entry bb + void RemoveEntry(const BB &bb) { + bb.RemoveBBFromVector(succ); + } + + // Only use for common exit bb + void AddExit(BB &bb) { + pred.push_back(&bb); + } + + // Only use for common exit bb + void RemoveExit(const BB &bb) { + bb.RemoveBBFromVector(pred); + } + + void AddPred(BB &predBB, size_t pos = UINT32_MAX) { + ASSERT((pos <= pred.size() || pos == UINT32_MAX), "Invalid position."); + ASSERT((!predBB.IsInList(pred) && !IsInList(predBB.succ)), "BB already has been Added."); + ASSERT((id != 0 && id != 1), "CommonEntry or CommonEntry should not be here."); + ASSERT((predBB.id != 0 && predBB.id != 1), "CommonEntry or CommonEntry should not be here."); + if (pos == UINT32_MAX) { + pred.push_back(&predBB); + } else { + pred.insert(pred.begin() + pos, &predBB); + } + predBB.succ.push_back(this); + } + + void AddSucc(BB &succBB, size_t pos = UINT32_MAX) { + ASSERT((pos <= succ.size() || pos == UINT32_MAX), "Invalid position."); + ASSERT((!succBB.IsInList(succ) && !IsInList(succBB.pred)), "BB already has been Added."); + ASSERT((id != 0 && id != 1), "CommonEntry or CommonEntry should not be here."); + ASSERT((succBB.id != 0 && succBB.id != 1), "CommonEntry or CommonEntry should not be here."); + if (pos == UINT32_MAX) { + succ.push_back(&succBB); + } else { + succ.insert(succ.begin() + pos, &succBB); + } + succBB.pred.push_back(this); } // This is to help new bb to keep some flags from original bb after logically splitting. @@ -183,7 +223,6 @@ class BB { void SetFirstMe(MeStmt *stmt); void SetLastMe(MeStmt *stmt); MeStmt *GetLastMe(); - bool IsInList(const MapleVector &bbList) const; bool IsPredBB(const BB &bb) const { // if this is a pred of bb return true; // otherwise return false; @@ -194,35 +233,38 @@ class BB { return IsInList(bb.succ); } void DumpMeBB(const IRMap &irMap); - - void AddSuccBB(BB *succPara) { - succ.push_back(succPara); - succPara->pred.push_back(this); - } - void ReplacePred(const BB *old, BB *newPred); void ReplaceSucc(const BB *old, BB *newSucc); - void ReplaceSuccOfCommonEntryBB(const BB *old, BB *newSucc); void AddStmtNode(StmtNode *stmt); void PrependStmtNode(StmtNode *stmt); void RemoveStmtNode(StmtNode *stmt); void RemoveLastStmt(); void InsertStmtBefore(StmtNode *stmt, StmtNode *newStmt); void ReplaceStmt(StmtNode *stmt, StmtNode *newStmt); - int RemoveBBFromVector(MapleVector &bbVec) const; - void RemoveBBFromPred(BB *bb); - void RemoveBBFromSucc(BB *bb); - void RemovePred(BB *predBB) { - predBB->RemoveBBFromSucc(this); - RemoveBBFromPred(predBB); + void RemovePred(BB &predBB, bool updatePhi = true) { + ASSERT((id != 0 && id != 1), "CommonEntry or CommonEntry should not be here."); + ASSERT((predBB.id != 0 && predBB.id != 1), "CommonEntry or CommonEntry should not be here."); + RemoveBBFromPred(predBB, updatePhi); + predBB.RemoveBBFromSucc(*this); } - void RemoveSucc(BB *succBB) { - succBB->RemoveBBFromPred(this); + void RemoveSucc(BB &succBB, bool updatePhi = true) { + ASSERT((id != 0 && id != 1), "CommonEntry or CommonEntry should not be here."); + ASSERT((succBB.id != 0 && succBB.id != 1), "CommonEntry or CommonEntry should not be here."); + succBB.RemoveBBFromPred(*this, updatePhi); RemoveBBFromSucc(succBB); } + void RemoveAllPred() { + pred.clear(); + } + + void RemoveAllSucc() { + succ.clear(); + succFreq.clear(); + } + void InsertPi(BB &bb, PiassignMeStmt &s) { if (meVarPiList.find(&bb) == meVarPiList.end()) { std::vector tmp; @@ -299,10 +341,6 @@ class BB { SetAttributes(kBBAttrIsExit); } - MapleVector &GetPred() { - return pred; - } - const MapleVector &GetPred() const { return pred; } @@ -322,10 +360,6 @@ class BB { pred[cnt] = pp; } - MapleVector &GetSucc() { - return succ; - } - MapleVector &GetSuccFreq() { return succFreq; } @@ -413,7 +447,14 @@ class BB { void ClearGroup() { group = this; } + private: + bool IsInList(const MapleVector &bbList) const; + int RemoveBBFromVector(MapleVector &bbVec) const; + void RemovePhiOpnd(int index); + void RemoveBBFromPred(const BB &bb, bool updatePhi); + void RemoveBBFromSucc(const BB &bb); + BBId id; LabelIdx bbLabel = 0; // the BB's label MapleVector pred; // predecessor list diff --git a/src/maple_me/include/hdse.h b/src/maple_me/include/hdse.h index e0eda7c81bd8d4d219297645aeeb1101ca7310d0..22d8701efd2385e93d04af10ae61ab5f79940928 100644 --- a/src/maple_me/include/hdse.h +++ b/src/maple_me/include/hdse.h @@ -62,7 +62,7 @@ class HDSE { void MarkControlDependenceLive(BB &bb); void MarkLastBranchStmtInBBRequired(BB &bb); void MarkLastStmtInPDomBBRequired(const BB &bb); - void MarkLastUnconditionalGotoInPredBBRequired(BB &bb); + void MarkLastUnconditionalGotoInPredBBRequired(const BB &bb); void MarkVarDefByStmt(VarMeExpr &varMeExpr); void MarkRegDefByStmt(RegMeExpr ®MeExpr); diff --git a/src/maple_me/include/me_builder.h b/src/maple_me/include/me_builder.h index 83e85c7beab8b636d3d73c0e330fdd1b336f6417..d6ceff4d710f46a35d577249dc75332b84e8542b 100644 --- a/src/maple_me/include/me_builder.h +++ b/src/maple_me/include/me_builder.h @@ -20,8 +20,7 @@ namespace maple { class MeBuilder { public: explicit MeBuilder(MapleAllocator &allocator) : allocator(allocator) { - static auto exprBuildPolicyLoader = InitMeExprBuildFactory(); - (void)exprBuildPolicyLoader; + (void)InitMeExprBuildFactory(); } virtual ~MeBuilder() = default; diff --git a/src/maple_me/include/me_inequality_graph.h b/src/maple_me/include/me_inequality_graph.h index 498c778a3a1b782c7e9ee027047aca86c1e629ef..e24525e538dc4aa7c13ec4f8b5c79b6a8b87a4c7 100644 --- a/src/maple_me/include/me_inequality_graph.h +++ b/src/maple_me/include/me_inequality_graph.h @@ -68,7 +68,7 @@ class VarValue { class InequalEdge { public: - InequalEdge(int v, EdgeType t) : edgeType(t), isVarValue(false), pairEdge(nullptr) { + InequalEdge(int64 v, EdgeType t) : edgeType(t), isVarValue(false), pairEdge(nullptr) { value.constValue = v; } @@ -108,7 +108,7 @@ class InequalEdge { return edgeType; } - int GetConstValue() const { + int64 GetConstValue() const { return value.constValue; } @@ -136,7 +136,7 @@ class InequalEdge { return edgeType == kUpper ? value.constValue <= edge.GetConstValue() : value.constValue >= edge.GetConstValue(); } - bool GreaterEqual(int32 val) const { + bool GreaterEqual(int64 val) const { return edgeType == kUpper ? value.constValue >= val : value.constValue <= val; } @@ -157,7 +157,7 @@ class InequalEdge { private: union { - int32 constValue; + int64 constValue; VarValue *varValue; } value; EdgeType edgeType; @@ -174,7 +174,7 @@ class ESSABaseNode { return lhs->GetID() < rhs->GetID(); } }; - ESSABaseNode(int i, MeExpr *expr, ESSANodeKind k) : id(i), meExpr(expr), kind(k) {} + ESSABaseNode(int64 i, MeExpr *expr, ESSANodeKind k) : id(i), meExpr(expr), kind(k) {} virtual ~ESSABaseNode() = default; virtual const MeExpr &GetMeExpr() const { @@ -226,12 +226,12 @@ class ESSABaseNode { return std::to_string(meExpr->GetExprID()); } - int GetID() const { + int64 GetID() const { return id; } protected: - int id; + int64 id; MeExpr *meExpr; ESSANodeKind kind; std::vector> edges; @@ -243,16 +243,16 @@ class ESSABaseNode { class ESSAVarNode : public ESSABaseNode { public: - ESSAVarNode(int i, MeExpr &e) : ESSABaseNode(i, &e, kVarNode) {} + ESSAVarNode(int64 i, MeExpr &e) : ESSABaseNode(i, &e, kVarNode) {} ~ESSAVarNode() = default; }; class ESSAConstNode : public ESSABaseNode { public: - ESSAConstNode(int i, int v) : ESSABaseNode(i, nullptr, kConstNode), value(v) {} + ESSAConstNode(int64 i, int64 v) : ESSABaseNode(i, nullptr, kConstNode), value(v) {} ~ESSAConstNode() = default; - int GetValue() const { + int64 GetValue() const { return value; } @@ -261,18 +261,18 @@ class ESSAConstNode : public ESSABaseNode { } private: - int value; + int64 value; }; class ESSAArrayNode : public ESSABaseNode { public: - ESSAArrayNode(int i, MeExpr &e) : ESSABaseNode(i, &e, kArrayNode) {} + ESSAArrayNode(int64 i, MeExpr &e) : ESSABaseNode(i, &e, kArrayNode) {} ~ESSAArrayNode() = default; }; class ESSAPhiNode : public ESSABaseNode { public: - ESSAPhiNode(int i, MeExpr &e) : ESSABaseNode(i, &e, kPhiNode) {} + ESSAPhiNode(int64 i, MeExpr &e) : ESSABaseNode(i, &e, kPhiNode) {} ~ESSAPhiNode() = default; const std::vector &GetPhiOpnds() const { @@ -312,17 +312,17 @@ class InequalityGraph { } ~InequalityGraph() = default; - ESSAConstNode *GetOrCreateConstNode(int value); + ESSAConstNode *GetOrCreateConstNode(int64 value); ESSAVarNode *GetOrCreateVarNode(MeExpr &meExpr); ESSAPhiNode *GetOrCreatePhiNode(MeVarPhiNode &phiNode); ESSAArrayNode *GetOrCreateArrayNode(MeExpr &meExpr); - InequalEdge *AddEdge(ESSABaseNode &from, ESSABaseNode &to, int value, EdgeType type); + InequalEdge *AddEdge(ESSABaseNode &from, ESSABaseNode &to, int64 value, EdgeType type); void AddPhiEdge(ESSABaseNode &from, ESSABaseNode &to, EdgeType type); void AddEdge(ESSABaseNode &from, ESSABaseNode &to, MeExpr &value, bool positive, EdgeType type); void ConnectTrivalEdge(); void DumpDotFile(IRMap &irMap, DumpType dumpType) const; ESSABaseNode &GetNode(const MeExpr &meExpr); - ESSABaseNode &GetNode(int32 value); + ESSABaseNode &GetNode(int64 value); bool HasNode(const MeExpr &meExpr) const; int GetValidID() { ++nodeCount; @@ -331,18 +331,18 @@ class InequalityGraph { private: std::string GetColor(EdgeType type) const; - bool HasNode(int value) const; + bool HasNode(int64 value) const; InequalEdge *HasEdge(ESSABaseNode &from, ESSABaseNode &to, InequalEdge &type) const; std::string GetName(ESSABaseNode &node, IRMap &irMap) const; std::string GetName(const MeExpr &meExpr, IRMap &irMap) const; void DumpDotNodes(IRMap &irMap, std::ostream &out, DumpType dumpType, - const std::map> &nodes) const; + const std::map> &nodes) const; void DumpDotEdges(IRMap &irMap, const std::pair &map, std::ostream &out, std::string &from) const; MeFunction *meFunction; - std::map> varNodes; - std::map> constNodes; + std::map> varNodes; + std::map> constNodes; int nodeCount; }; diff --git a/src/maple_me/src/bb.cpp b/src/maple_me/src/bb.cpp index e4a77572801b321773cab47c57b3358996fa1532..74088e86c1a38d5308b0fe37b15f793c84538c82 100644 --- a/src/maple_me/src/bb.cpp +++ b/src/maple_me/src/bb.cpp @@ -75,7 +75,7 @@ void BB::DumpBBAttribute(const MIRModule *mod) const { } } -void BB::DumpHeader(MIRModule *mod) const { +void BB::DumpHeader(const MIRModule *mod) const { mod->GetOut() << "============BB id:" << GetBBId() << " " << StrAttribute() << " ["; DumpBBAttribute(mod); mod->GetOut() << "]===============\n"; @@ -96,7 +96,7 @@ void BB::DumpHeader(MIRModule *mod) const { } } -void BB::Dump(MIRModule *mod) { +void BB::Dump(const MIRModule *mod) { DumpHeader(mod); DumpPhi(); for (auto &stmt : stmtNodeList) { @@ -149,28 +149,32 @@ int BB::RemoveBBFromVector(MapleVector &bbVec) const { return i; } -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"); +void BB::RemovePhiOpnd(int index) { for (auto &phi : phiList) { - ASSERT(phi.second.GetPhiOpnds().size() > index, "index out of range in BB::RemoveBBFromPred"); + ASSERT(phi.second.GetPhiOpnds().size() > index, "index out of range in BB::RemovePhiOpnd"); phi.second.GetPhiOpnds().erase(phi.second.GetPhiOpnds().cbegin() + index); } for (auto &phi : meVarPhiList) { - ASSERT(phi.second->GetOpnds().size() > index, "index out of range in BB::RemoveBBFromPred"); + ASSERT(phi.second->GetOpnds().size() > index, "index out of range in BB::RemovePhiOpnd"); phi.second->GetOpnds().erase(phi.second->GetOpnds().cbegin() + index); } for (auto &phi : meRegPhiList) { - ASSERT(phi.second->GetOpnds().size() > index, "index out of range in BB::RemoveBBFromPred"); + ASSERT(phi.second->GetOpnds().size() > index, "index out of range in BB::RemovePhiOpnd"); phi.second->GetOpnds().erase(phi.second->GetOpnds().cbegin() + index); } } -void BB::RemoveBBFromSucc(BB *bb) { - CHECK_NULL_FATAL(bb); - int ret = bb->RemoveBBFromVector(succ); - if (ret != -1 && !succFreq.empty()) { +void BB::RemoveBBFromPred(const BB &bb, bool updatePhi) { + int index = bb.RemoveBBFromVector(pred); + ASSERT(index != -1, "-1 is a very large number in BB::RemoveBBFromPred"); + if (updatePhi) { + RemovePhiOpnd(index); + } +} + +void BB::RemoveBBFromSucc(const BB &bb) { + int ret = bb.RemoveBBFromVector(succ); + if (ret != -1 && frequency != 0) { succFreq.erase(succFreq.cbegin() + ret); } } @@ -230,31 +234,29 @@ void BB::RemoveLastStmt() { } // replace pred with newbb to keep position and add this as succ of newpred +// and remove itself from succ of old void BB::ReplacePred(const BB *old, BB *newPred) { + ASSERT((old != nullptr && newPred != nullptr), "Nullptr check."); + ASSERT((old->IsInList(pred) && IsInList(old->succ)), "Nullptr check."); for (auto &predElement : pred) { if (predElement == old) { - predElement = newPred; + predElement->RemoveBBFromSucc(*this); newPred->succ.push_back(this); + predElement = newPred; break; } } } // replace succ in current position with newsucc and add this as pred of newsucc +// and remove itself from pred of old void BB::ReplaceSucc(const BB *old, BB *newSucc) { + ASSERT((old != nullptr && newSucc != nullptr), "Nullptr check."); + ASSERT((old->IsInList(succ) && IsInList(old->pred)), "Nullptr check."); for (auto &succElement : succ) { if (succElement == old) { - succElement = newSucc; + succElement->RemoveBBFromPred(*this, false); newSucc->pred.push_back(this); - break; - } - } -} - -// this is common_entry_bb, so newsucc's pred is left as is -void BB::ReplaceSuccOfCommonEntryBB(const BB *old, BB *newSucc) { - for (auto &succElement : succ) { - if (succElement == old) { succElement = newSucc; break; } diff --git a/src/maple_me/src/dse.cpp b/src/maple_me/src/dse.cpp index 3c0e82eb5be3dc8574cdc1c8a9343428e074abb5..7f3ac83fde28acb86756c1b0a0e16b20cc179616 100644 --- a/src/maple_me/src/dse.cpp +++ b/src/maple_me/src/dse.cpp @@ -167,8 +167,7 @@ void DSE::OnRemoveBranchStmt(BB &bb, const StmtNode &stmt) { for (size_t i = 0; i < bb.GetSucc().size(); ++i) { if (bb.GetSucc(i)->GetBBLabel() == labelIdx) { BB *succBB = bb.GetSucc(i); - bb.RemoveBBFromSucc(succBB); - succBB->RemoveBBFromPred(&bb); + bb.RemoveSucc(*succBB); break; } } diff --git a/src/maple_me/src/hdse.cpp b/src/maple_me/src/hdse.cpp index 45e4ac20e884d786bf0203708ca83571f1a4e7c8..580ae0ce47372d42d644f79a6461fa5a0a45dbeb 100644 --- a/src/maple_me/src/hdse.cpp +++ b/src/maple_me/src/hdse.cpp @@ -47,8 +47,7 @@ void HDSE::RemoveNotRequiredStmtsInBB(BB &bb) { // update CFG while (bb.GetSucc().size() != 1) { BB *succ = bb.GetSucc().back(); - succ->RemoveBBFromPred(&bb); - bb.GetSucc().pop_back(); + succ->RemovePred(bb); } bb.SetKind(kBBFallthru); } @@ -257,7 +256,7 @@ bool HDSE::HasNonDeletableExpr(const MeStmt &meStmt) const { } } -void HDSE::MarkLastUnconditionalGotoInPredBBRequired(BB &bb) { +void HDSE::MarkLastUnconditionalGotoInPredBBRequired(const BB &bb) { for (auto predIt = bb.GetPred().begin(); predIt != bb.GetPred().end(); ++predIt) { BB *predBB = *predIt; if (predBB == &bb || predBB->GetMeStmts().empty()) { diff --git a/src/maple_me/src/me_bb_layout.cpp b/src/maple_me/src/me_bb_layout.cpp index 49bcd01039a80ff802fb3b07a0749d3beef55803..0fe4042962db3b6d3773a52acd8c7a469b83d79e 100644 --- a/src/maple_me/src/me_bb_layout.cpp +++ b/src/maple_me/src/me_bb_layout.cpp @@ -325,7 +325,6 @@ void BBLayout::OptimizeBranchTarget(BB &bb) { } // update CFG bb.ReplaceSucc(brTargetBB, newTargetBB); - bb.RemoveBBFromVector(brTargetBB->GetPred()); if (brTargetBB->GetPred().empty()) { laidOut[brTargetBB->GetBBId()] = true; RemoveUnreachable(*brTargetBB); @@ -389,7 +388,6 @@ BB *BBLayout::GetFallThruBBSkippingEmpty(BB &bb) { BB *oldFallThru = fallthru; fallthru = fallthru->GetSucc().front(); bb.ReplaceSucc(oldFallThru, fallthru); - oldFallThru->RemoveBBFromPred(&bb); if (oldFallThru->GetPred().empty()) { RemoveUnreachable(*oldFallThru); if (needDealWithTryBB) { @@ -447,11 +445,11 @@ void BBLayout::FixEndTryBB(BB &bb) { } void BBLayout::FixTryBB(BB &startTryBB, BB &nextBB) { - startTryBB.GetPred().clear(); + startTryBB.RemoveAllPred(); for (size_t i = 0; i < nextBB.GetPred().size(); ++i) { nextBB.GetPred(i)->ReplaceSucc(&nextBB, &startTryBB); } - nextBB.GetPred().clear(); + nextBB.RemoveAllPred(); startTryBB.ReplaceSucc(startTryBB.GetSucc(0), &nextBB); } @@ -468,12 +466,12 @@ void BBLayout::DealWithStartTryBB() { if (nextBB->GetAttributes(kBBAttrIsTry)) { FixTryBB(*curBB, *nextBB); } else { - curBB->GetSucc().clear(); + curBB->RemoveAllSucc(); func.NullifyBBByID(curBB->GetBBId()); } break; } else if (j == size - 1) { - curBB->GetSucc().clear(); + curBB->RemoveAllSucc(); func.NullifyBBByID(curBB->GetBBId()); } } @@ -488,11 +486,10 @@ void BBLayout::RemoveUnreachable(BB &bb) { if (bb.GetAttributes(kBBAttrIsEntry)) { return; } - MapleVector succBBs = bb.GetSucc(); - for (BB *succ : succBBs) { - MapleVector &preds = succ->GetPred(); - bb.RemoveBBFromVector(preds); - if (preds.empty()) { + while (bb.GetSucc().size() > 0) { + BB *succ = bb.GetSucc(0); + succ->RemovePred(bb, false); + if (succ->GetPred().empty()) { RemoveUnreachable(*succ); } } @@ -508,7 +505,7 @@ void BBLayout::RemoveUnreachable(BB &bb) { if (bb.GetAttributes(kBBAttrIsTryEnd)) { FixEndTryBB(bb); } - succBBs.clear(); + bb.RemoveAllSucc(); func.NullifyBBByID(bb.GetBBId()); } @@ -539,8 +536,18 @@ BB *BBLayout::CreateGotoBBAfterCondBB(BB &bb, BB &fallthru) { newFallthru->SetLast(newFallthru->GetStmtNodes().begin().d()); } // replace pred and succ + size_t index = fallthru.GetPred().size(); + while (index > 0) { + if (fallthru.GetPred(index - 1) == &bb) { + break; + } + index--; + } bb.ReplaceSucc(&fallthru, newFallthru); - fallthru.ReplacePred(&bb, newFallthru); + // pred has been remove for pred vector of succ + // means size reduced, so index reduced + index--; + fallthru.AddPred(*newFallthru, index); newFallthru->SetFrequency(fallthru.GetFrequency()); if (enabledDebug) { LogInfo::MapleLogger() << "Created fallthru and goto original fallthru" << '\n'; diff --git a/src/maple_me/src/me_bypath_eh.cpp b/src/maple_me/src/me_bypath_eh.cpp index a95ff3d5a3f8e441cf93a88c80bc504793369ae9..b29df12427382b040e5cec5fa8cae4a9e892acd2 100644 --- a/src/maple_me/src/me_bypath_eh.cpp +++ b/src/maple_me/src/me_bypath_eh.cpp @@ -74,8 +74,7 @@ bool MeDoBypathEH::DoBypathException(BB *tryBB, BB *catchBB, const Klass *catchC bb->InsertStmtBefore(gotoNode, syncExitStmt->CloneTree(func.GetMIRModule().GetCurFuncCodeMPAllocator())); } transformed = true; - bb->GetSucc().insert(bb->GetSucc().begin(), catchBB); - catchBB->GetPred().push_back(bb); + bb->AddSucc(*catchBB, 0); } } // Add fall through bb diff --git a/src/maple_me/src/me_cfg.cpp b/src/maple_me/src/me_cfg.cpp index 6e6617f09a318d7198c6de5b13eadb5ae3fe7294..f5dd09577c652d9691f82ca68230a947f28dda06 100644 --- a/src/maple_me/src/me_cfg.cpp +++ b/src/maple_me/src/me_cfg.cpp @@ -52,8 +52,7 @@ void MeCFG::BuildMirCFG() { auto &gotoStmt = static_cast(lastStmt); LabelIdx lblIdx = gotoStmt.GetOffset(); BB *meBB = func.GetLabelBBAt(lblIdx); - bb->GetSucc().push_back(meBB); - meBB->GetPred().push_back(bb); + bb->AddSucc(*meBB); break; } case kBBCondGoto: { @@ -63,14 +62,12 @@ void MeCFG::BuildMirCFG() { auto rightNextBB = bIt; ++rightNextBB; CHECK_FATAL(rightNextBB != eIt, "null ptr check "); - (*rightNextBB)->GetPred().push_back(bb); - bb->GetSucc().push_back(*rightNextBB); + bb->AddSucc(**rightNextBB); // link goto auto &gotoStmt = static_cast(lastStmt); LabelIdx lblIdx = gotoStmt.GetOffset(); BB *meBB = func.GetLabelBBAt(lblIdx); - bb->GetSucc().push_back(meBB); - meBB->GetPred().push_back(bb); + bb->AddSucc(*meBB); break; } case kBBSwitch: { @@ -79,16 +76,14 @@ void MeCFG::BuildMirCFG() { auto &switchStmt = static_cast(lastStmt); LabelIdx lblIdx = switchStmt.GetDefaultLabel(); BB *mirBB = func.GetLabelBBAt(lblIdx); - bb->GetSucc().push_back(mirBB); - mirBB->GetPred().push_back(bb); + bb->AddSucc(*mirBB); for (size_t j = 0; j < switchStmt.GetSwitchTable().size(); ++j) { lblIdx = switchStmt.GetCasePair(j).second; BB *meBB = func.GetLabelBBAt(lblIdx); // Avoid duplicate succs. auto it = std::find(bb->GetSucc().begin(), bb->GetSucc().end(), meBB); if (it == bb->GetSucc().end()) { - bb->GetSucc().push_back(meBB); - meBB->GetPred().push_back(bb); + bb->AddSucc(*meBB); } } break; @@ -100,8 +95,7 @@ void MeCFG::BuildMirCFG() { auto rightNextBB = bIt; ++rightNextBB; if (rightNextBB != eIt) { - (*rightNextBB)->GetPred().push_back(bb); - bb->GetSucc().push_back(*rightNextBB); + bb->AddSucc(**rightNextBB); } break; } @@ -120,19 +114,12 @@ void MeCFG::BuildMirCFG() { BB *meBB = func.GetLabelBBAt(labelIdx); CHECK_FATAL(meBB != nullptr, "null ptr check"); ASSERT(meBB->GetAttributes(kBBAttrIsCatch), "runtime check error"); - size_t si = 0; if (meBB->GetAttributes(kBBAttrIsJSFinally) || meBB->GetAttributes(kBBAttrIsCatch)) { hasFinallyHandler = true; } // avoid redundant succ - for (; si < bb->GetSucc().size(); ++si) { - if (meBB == bb->GetSucc(si)) { - break; - } - } - if (si == bb->GetSucc().size()) { - bb->GetSucc().push_back(meBB); - meBB->GetPred().push_back(bb); + if (!meBB->IsSuccBB(*bb)) { + bb->AddSucc(*meBB); } } // if try block don't have finally catch handler, add common_exit_bb as its succ @@ -154,11 +141,11 @@ void MeCFG::BuildMirCFG() { } // merge all blocks in entryBlocks for (BB *bb : entryBlocks) { - func.GetCommonEntryBB()->GetSucc().push_back(bb); + func.GetCommonEntryBB()->AddEntry(*bb); } // merge all blocks in exitBlocks for (BB *bb : exitBlocks) { - func.GetCommonExitBB()->GetPred().push_back(bb); + func.GetCommonExitBB()->AddExit(*bb); } } @@ -383,7 +370,7 @@ void MeCFG::FixMirCFG() { for (size_t si = 0; si < newBB.GetSucc().size(); ++si) { BB *sucBB = newBB.GetSucc(si); if (sucBB->GetAttributes(kBBAttrIsCatch)) { - bb->AddSuccBB(sucBB); + bb->AddSucc(*sucBB); } } break; @@ -405,8 +392,7 @@ void MeCFG::FixMirCFG() { for (size_t si = 0; si < bb->GetSucc().size(); ++si) { BB *sucBB = bb->GetSucc(si); if (sucBB->GetAttributes(kBBAttrIsCatch)) { - sucBB->RemoveBBFromPred(bb); - bb->RemoveBBFromSucc(sucBB); + sucBB->RemovePred(*bb); --si; } } @@ -429,7 +415,6 @@ void MeCFG::FixMirCFG() { BB *sucBB = newBB.GetSucc(si); if (sucBB->GetAttributes(kBBAttrIsCatch)) { sucBB->ReplacePred(&newBB, bb); - newBB.RemoveBBFromSucc(sucBB); --si; } } @@ -447,11 +432,11 @@ bool MeCFG::IsStartTryBB(maple::BB &meBB) const { } void MeCFG::FixTryBB(maple::BB &startBB, maple::BB &nextBB) { - startBB.GetPred().clear(); + startBB.RemoveAllPred(); for (size_t i = 0; i < nextBB.GetPred().size(); ++i) { nextBB.GetPred(i)->ReplaceSucc(&nextBB, &startBB); } - nextBB.GetPred().clear(); + nextBB.RemoveAllPred(); startBB.ReplaceSucc(startBB.GetSucc(0), &nextBB); } @@ -501,7 +486,7 @@ void MeCFG::UnreachCodeAnalysis(bool updatePhi) { } } if (pi == func.GetCommonExitBB()->GetPred().size()) { - func.GetCommonExitBB()->GetPred().push_back(bb); + func.GetCommonExitBB()->AddExit(*bb); } if (!MeOption::quiet) { LogInfo::MapleLogger() << "#### BB " << bb->GetBBId() << " deleted because unreachable\n"; @@ -523,12 +508,10 @@ void MeCFG::UnreachCodeAnalysis(bool updatePhi) { } func.DeleteBasicBlock(*bb); // remove the bb from its succ's pred_ list - for (auto it = bb->GetSucc().begin(); it != bb->GetSucc().end(); ++it) { - BB *sucBB = *it; - if (!updatePhi) { - bb->RemoveBBFromVector(sucBB->GetPred()); - } else { - sucBB->RemoveBBFromPred(bb); + while (bb->GetSucc().size() > 0) { + BB *sucBB = bb->GetSucc(0); + sucBB->RemovePred(*bb, updatePhi); + if (updatePhi) { if (sucBB->GetPred().empty()) { sucBB->ClearPhiList(); } else if (sucBB->GetPred().size() == 1) { @@ -540,7 +523,7 @@ void MeCFG::UnreachCodeAnalysis(bool updatePhi) { for (auto it = func.GetCommonExitBB()->GetPred().begin(); it != func.GetCommonExitBB()->GetPred().end(); ++it) { if (*it == bb) { - func.GetCommonExitBB()->RemoveBBFromPred(bb); + func.GetCommonExitBB()->RemoveExit(*bb); break; } } @@ -654,9 +637,8 @@ void MeCFG::WontExitAnalysis() { eIt = func.valid_end(); newBB->SetKindReturn(); newBB->SetAttributes(kBBAttrArtificial); - bb->GetSucc().push_back(newBB); - newBB->GetPred().push_back(bb); - func.GetCommonExitBB()->GetPred().push_back(newBB); + bb->AddSucc(*newBB); + func.GetCommonExitBB()->AddExit(*newBB); } } } diff --git a/src/maple_me/src/me_critical_edge.cpp b/src/maple_me/src/me_critical_edge.cpp index 5fa21f1916522c286ff2fc9df52d8c814a6e81c9..6fba7f6fe2f589f7577ee8536cc52188dd7eb91a 100644 --- a/src/maple_me/src/me_critical_edge.cpp +++ b/src/maple_me/src/me_critical_edge.cpp @@ -43,18 +43,27 @@ void MeDoSplitCEdge::BreakCriticalEdge(MeFunction &func, BB &pred, BB &succ) con // create newBB and set pred/succ BB *newBB = nullptr; // use replace instead of remove/add to keep position in pred/succ + size_t index = succ.GetPred().size(); if (&pred == func.GetCommonEntryBB()) { newBB = &func.InsertNewBasicBlock(*func.GetFirstBB()); - pred.ReplaceSuccOfCommonEntryBB(&succ, newBB); - newBB->GetSucc().push_back(&succ); - succ.GetPred().push_back(newBB); newBB->SetAttributes(kBBAttrIsEntry); succ.ClearAttributes(kBBAttrIsEntry); + pred.RemoveEntry(succ); + pred.AddEntry(*newBB); } else { newBB = func.NewBasicBlock(); + while (index > 0) { + if (succ.GetPred(index - 1) == &pred) { + break; + } + index--; + } pred.ReplaceSucc(&succ, newBB); - succ.ReplacePred(&pred, newBB); } + // pred has been remove for pred vector of succ + // means size reduced, so index reduced + index--; + succ.AddPred(*newBB, index); newBB->SetKind(kBBFallthru); // default kind newBB->SetAttributes(kBBAttrArtificial); @@ -104,7 +113,7 @@ AnalysisResult *MeDoSplitCEdge::Run(MeFunction *func, MeFuncResultMgr *m, Module continue; } auto *bb = *bIt; - MapleVector &preds = bb->GetPred(); + const MapleVector &preds = bb->GetPred(); // skip fallthrough bb or bb is handler block if (preds.size() < 2 || bb->GetAttributes(kBBAttrIsCatch)) { continue; diff --git a/src/maple_me/src/me_function.cpp b/src/maple_me/src/me_function.cpp index a7344d654ac8818a789efb951687a0f1614d2206..c8158680ff21899f72f1f4328e01588c8750645d 100644 --- a/src/maple_me/src/me_function.cpp +++ b/src/maple_me/src/me_function.cpp @@ -538,19 +538,15 @@ BB &MeFunction::SplitBB(BB &bb, StmtNode &splitPoint, BB *newBB) { } // Special Case: commonExitBB is orig bb's succ auto *commonExitBB = *common_exit(); - for (size_t i = 0; i < commonExitBB->GetPred().size(); ++i) { - if (commonExitBB->GetPred(i) == &bb) { - commonExitBB->SetPred(i, newBB); - break; - } + if (bb.IsPredBB(*commonExitBB)) { + commonExitBB->RemoveExit(bb); + commonExitBB->AddExit(*newBB); } - for (size_t i = 0; i < bb.GetSucc().size(); ++i) { - BB *succ = bb.GetSucc(i); + while (bb.GetSucc().size() > 0) { + BB *succ = bb.GetSucc(0); succ->ReplacePred(&bb, newBB); } - bb.GetSucc().clear(); - bb.GetSucc().push_back(newBB); - newBB->GetPred().push_back(&bb); + bb.AddSucc(*newBB); // Setup flags newBB->CopyFlagsAfterSplit(bb); if (newBB->GetAttributes(kBBAttrIsTryEnd)) { @@ -699,7 +695,7 @@ void MeFunction::SCCTopologicalSort(std::vector &sccNodes) { for (SCCOfBBs *node : sccNodes) { if (!node->HasPred()) { sccTopologicalVec.push_back(node); - inQueue.insert(node); + (void)inQueue.insert(node); } } @@ -719,7 +715,7 @@ void MeFunction::SCCTopologicalSort(std::vector &sccNodes) { } if (predAllVisited) { sccTopologicalVec.push_back(succ); - inQueue.insert(succ); + (void)inQueue.insert(succ); } } } @@ -734,7 +730,7 @@ void MeFunction::BBTopologicalSort(SCCOfBBs &scc) { } scc.Clear(); scc.AddBBNode(scc.GetEntry()); - inQueue.insert(scc.GetEntry()); + (void)inQueue.insert(scc.GetEntry()); for (size_t i = 0; i < scc.GetBBs().size(); ++i) { BB *bb = scc.GetBBs()[i]; @@ -764,7 +760,7 @@ void MeFunction::BBTopologicalSort(SCCOfBBs &scc) { } if (predAllVisited) { scc.AddBBNode(succ); - inQueue.insert(succ); + (void)inQueue.insert(succ); } } } diff --git a/src/maple_me/src/me_hdse.cpp b/src/maple_me/src/me_hdse.cpp index b14c3c7cd6a28e44d9ea89f98b0cbb5f25221693..2c2aa69dcdd4cbcf199f447ce8b1c8c5a9b2dd9d 100644 --- a/src/maple_me/src/me_hdse.cpp +++ b/src/maple_me/src/me_hdse.cpp @@ -38,40 +38,23 @@ void MeDoHDSE::MakeEmptyTrysUnreachable(MeFunction &func) { tryBB->GetMeRegPhiList().empty() && endTry->GetAttributes(kBBAttrIsTryEnd) && endTry->IsMeStmtEmpty()) { // we found a try BB followed by an empty endtry BB BB *targetBB = endTry->GetSucc(0); - std::vector toDeleteTryPreds; - int32 indexOfEndTryInTargetBBPreds = -1; for (auto *tryPred : tryBB->GetPred()) { - MapleVector &allSucc = tryPred->GetSucc(); - toDeleteTryPreds.push_back(tryPred); - // replace tryBB in the pred's succ list by targetbb - size_t j = 0; - for (; j < allSucc.size(); ++j) { - if (allSucc[j] == tryBB) { - break; - } - } - CHECK_FATAL(j != allSucc.size(), - "MakeEmptyTrysUnreachable: cannot find tryBB among the succ list of one of its pred BB"); - allSucc[j] = targetBB; // update targetbb's predecessors - size_t k = 0; - for (; k < targetBB->GetPred().size(); ++k) { - if (targetBB->GetPred(k) == endTry) { - indexOfEndTryInTargetBBPreds = k; - } else if (targetBB->GetPred(k) == tryPred) { - break; - } - } - if (k == targetBB->GetPred().size()) { - targetBB->GetPred().push_back(tryPred); - CHECK_FATAL(indexOfEndTryInTargetBBPreds != -1, "MakeEmptyTrysUnreachable: processing error"); - // push additional phi operand for each phi at targetbb - auto phiIter = targetBB->GetMevarPhiList().begin(); - for (; phiIter != targetBB->GetMevarPhiList().end(); ++phiIter) { - MeVarPhiNode *meVarPhi = phiIter->second; - meVarPhi->GetOpnds().push_back(meVarPhi->GetOpnds()[indexOfEndTryInTargetBBPreds]); + if (!tryPred->IsPredBB(*targetBB)) { + ASSERT(endTry->IsPredBB(*targetBB), "MakeEmptyTrysUnreachable: processing error"); + for (size_t k = 0; k < targetBB->GetPred().size(); ++k) { + if (targetBB->GetPred(k) == endTry) { + // push additional phi operand for each phi at targetbb + auto phiIter = targetBB->GetMevarPhiList().begin(); + for (; phiIter != targetBB->GetMevarPhiList().end(); ++phiIter) { + MeVarPhiNode *meVarPhi = phiIter->second; + meVarPhi->GetOpnds().push_back(meVarPhi->GetOpnds()[k]); + } + } } } + // replace tryBB in the pred's succ list by targetbb + tryPred->ReplaceSucc(tryBB, targetBB); // if needed, update branch label MeStmt *br = to_ptr(tryPred->GetMeStmts().rbegin()); if (br != nullptr) { @@ -100,10 +83,6 @@ void MeDoHDSE::MakeEmptyTrysUnreachable(MeFunction &func) { } } } - // tryBB has no phis, no need to update them - for (auto bb : toDeleteTryPreds) { - (void)bb->RemoveBBFromVector(tryBB->GetPred()); - } } } } diff --git a/src/maple_me/src/me_inequality_graph.cpp b/src/maple_me/src/me_inequality_graph.cpp index 38b6b7ad964d427d2278e7fd035d4e0652ede100..7e11677faa966b2721d7d0cab904751c7a874692 100644 --- a/src/maple_me/src/me_inequality_graph.cpp +++ b/src/maple_me/src/me_inequality_graph.cpp @@ -20,7 +20,7 @@ constexpr maple::int32 kLowerBound = 0; } // namespace namespace maple { -ESSAConstNode *InequalityGraph::GetOrCreateConstNode(int value) { +ESSAConstNode *InequalityGraph::GetOrCreateConstNode(int64 value) { if (HasNode(value)) { return static_cast(constNodes[value].get()); } @@ -82,7 +82,7 @@ ESSAArrayNode *InequalityGraph::GetOrCreateArrayNode(MeExpr &meExpr) { return newArray; } -InequalEdge *InequalityGraph::AddEdge(ESSABaseNode &from, ESSABaseNode &to, int value, EdgeType type) { +InequalEdge *InequalityGraph::AddEdge(ESSABaseNode &from, ESSABaseNode &to, int64 value, EdgeType type) { InequalEdge tmpEdge = InequalEdge(value, type); InequalEdge *edge = HasEdge(from, to, tmpEdge); if (edge != nullptr) { @@ -129,15 +129,15 @@ bool InequalityGraph::HasNode(const MeExpr &meExpr) const { return varNodes.find(meExpr.GetExprID()) != varNodes.end(); } -bool InequalityGraph::HasNode(int32 value) const { +bool InequalityGraph::HasNode(int64 value) const { return constNodes.find(value) != constNodes.end(); } void InequalityGraph::ConnectTrivalEdge() { - int32 prevValue = 0; + int64 prevValue = 0; ESSABaseNode* prevNode = nullptr; for (auto &pair : constNodes) { - int32 value = pair.first; + int64 value = pair.first; ESSABaseNode* node = pair.second.get(); if (prevNode == nullptr) { prevValue = value; @@ -159,7 +159,7 @@ ESSABaseNode &InequalityGraph::GetNode(const MeExpr &meExpr) { return *varNodes[meExpr.GetExprID()]; } -ESSABaseNode &InequalityGraph::GetNode(int32 value) { +ESSABaseNode &InequalityGraph::GetNode(int64 value) { CHECK_FATAL(HasNode(value), "node is not created"); return *constNodes[value]; } @@ -262,7 +262,7 @@ void InequalityGraph::DumpDotEdges(IRMap &irMap, const std::pair> &nodes) const { + const std::map> &nodes) const { for (auto iter = nodes.begin(); iter != nodes.end(); ++iter) { std::string from = GetName(*(iter->second), irMap); out << "\"" << from << "\";\n"; diff --git a/src/maple_me/src/me_loop_canon.cpp b/src/maple_me/src/me_loop_canon.cpp index 108503e18b6d5921e8990c43fd20c7cb4b87de5d..a75d378f4b96bc090956d026685d5a5f7f26a1c5 100644 --- a/src/maple_me/src/me_loop_canon.cpp +++ b/src/maple_me/src/me_loop_canon.cpp @@ -113,7 +113,6 @@ void MeDoLoopCanon::Convert(MeFunction &func, BB &bb, BB &pred, MapleMapSetAttributes(kBBAttrArtificial); // update pred bb - bb.RemoveBBFromPred(&pred); pred.ReplaceSucc(&bb, latchBB); // replace pred.succ with latchBB and set pred of latchBB // update pred stmt if needed if (pred.GetKind() == kBBGoto) { @@ -160,7 +159,7 @@ void MeDoLoopCanon::Convert(MeFunction &func, BB &bb, BB &pred, MapleMapGetAttributes(kBBAttrIsTry) || latchBB->GetSucc().empty(), "loopcanon : tryblock should insert succ before handler"); - latchBB->AddSuccBB(succ); + latchBB->AddSucc(*succ); } latchBB->SetKind(bb.GetKind()); // swap latchBB's succ if needed @@ -218,7 +217,7 @@ AnalysisResult *MeDoLoopCanon::Run(MeFunction *func, MeFuncResultMgr *m, ModuleR continue; } auto *bb = *bIt; - MapleVector &preds = bb->GetPred(); + const MapleVector &preds = bb->GetPred(); for (BB *pred : preds) { ASSERT(func->GetCommonEntryBB() != nullptr, "impossible"); ASSERT_NOT_NULL(pred); diff --git a/src/maple_util/include/profile.h b/src/maple_util/include/profile.h index 046a5738d6abc74dfbf7dbc6c29dfcd9150f4539..bd570830cf6e2f96945ae0b0b9e0e3170ec52676 100644 --- a/src/maple_util/include/profile.h +++ b/src/maple_util/include/profile.h @@ -76,7 +76,8 @@ class Profile { ~Profile() = default; private: - bool valid; + bool valid = false; + bool initialized = false; bool profileMode = false; bool isCoreSo = false; bool isAppProfile = false; diff --git a/src/maple_util/src/profile.cpp b/src/maple_util/src/profile.cpp index a756face677079363168bd229b6b700f315294c5..100c3beb883aad8a5847899eec16c89d4c4fe368 100644 --- a/src/maple_util/src/profile.cpp +++ b/src/maple_util/src/profile.cpp @@ -45,7 +45,7 @@ static const std::string preClassHot[] = { }; -Profile::Profile() : valid(false) {} +Profile::Profile() {} bool Profile::CheckProfileHeader(const Header *header) const { return (memcmp(header->magic, kProfileMagic, sizeof(kProfileMagic)) == 0); @@ -230,6 +230,11 @@ void Profile::InitPreHot() { } bool Profile::DeCompress(const std::string &path, const std::string &dexNameInner, ProfileType type) { + if (initialized) { + return valid; + } + initialized = true; + this->dexName = dexNameInner; InitPreHot(); bool res = true; diff --git a/src/mpl2mpl/include/muid_replacement.h b/src/mpl2mpl/include/muid_replacement.h index 01a3572e5fd96029f47e467ee288fda1ba42b66a..6ac7965e7257b5a2ff8a7b84909d2eb2a8700d93 100644 --- a/src/mpl2mpl/include/muid_replacement.h +++ b/src/mpl2mpl/include/muid_replacement.h @@ -108,7 +108,7 @@ class MUIDReplacement : public FuncOptimizeImpl { void GenerateGlobalRootList(); void CollectImplicitUndefClassInfo(StmtNode &stmt); void ReplaceMethodMetaFuncAddr(MIRSymbol &funcSymbol, int64 index); - void ReplaceFieldMetaStaticAddr(MIRSymbol &mirSymbol, uint32 index); + void ReplaceFieldMetaStaticAddr(const 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 76e659cba8c2a58d3d2e3e8399022f13cb0b8116..e6a0c0abff7c1f47efe86e48be5f16e0939ea12d 100644 --- a/src/mpl2mpl/include/native_stub_func.h +++ b/src/mpl2mpl/include/native_stub_func.h @@ -23,8 +23,13 @@ constexpr int kSlownativeFuncnum = 5; #else constexpr int kSlownativeFuncnum = 9; #endif +// May not use Env or ClassObj constexpr int kJniTypeNormal = 0; +// Not equal to real critical native, but no need for pre/post/eh. +// Need SetReliableUnwindContext, because the native code may call other java code constexpr int kJniTypeMapleCriticalNative = 1; +// Equal to real critical native, func will be set critical attribute. +// In theory it's incorrect because passing incorrect args. Ex. Linux.getuid constexpr int kJniTypeCriticalNative = 2; constexpr int kInvalidCode = 0x01; @@ -38,6 +43,8 @@ class NativeFuncProperty { std::string nativeFile; std::string nativeFunc; int jniType = kJniTypeNormal; + int useEnv = 1; + int useClassObj = 1; friend class NativeStubFuncGeneration; }; diff --git a/src/mpl2mpl/src/constantfold.cpp b/src/mpl2mpl/src/constantfold.cpp index 528335a0c3c7b68a09a480c94ea77d4a05303d0a..aaceb5240893d054df7cae5df63c65a094176a9a 100644 --- a/src/mpl2mpl/src/constantfold.cpp +++ b/src/mpl2mpl/src/constantfold.cpp @@ -76,7 +76,7 @@ BaseNode *ConstantFold::PairToExpr(PrimType resultType, const std::pair(pair.first)->Opnd(0); result = mirModule->CurFuncCodeMemPool()->New(OP_sub, resultType, val, r); } else { - if (pair.second > 0) { + if (pair.second > 0 || pair.second == LLONG_MIN) { // +-a, 5 -> a + 5 ConstvalNode *val = mirModule->GetMIRBuilder()->CreateIntConst(pair.second, resultType); result = mirModule->CurFuncCodeMemPool()->New(OP_add, resultType, pair.first, val); diff --git a/src/mpl2mpl/src/muid_replacement.cpp b/src/mpl2mpl/src/muid_replacement.cpp index 89b0019fa23350e16a68aa05153e48699dd74223..0ba83a15c10b7cf2532ea23c59dbfc078793775c 100644 --- a/src/mpl2mpl/src/muid_replacement.cpp +++ b/src/mpl2mpl/src/muid_replacement.cpp @@ -528,7 +528,7 @@ void MUIDReplacement::GenerateDataDefTable() { } } -void MUIDReplacement::ReplaceFieldMetaStaticAddr(MIRSymbol &mirSymbol, uint32 index) { +void MUIDReplacement::ReplaceFieldMetaStaticAddr(const MIRSymbol &mirSymbol, uint32 index) { std::string symbolName = mirSymbol.GetName(); MIRSymbol *fieldOffsetDataSt = GlobalTables::GetGsymTable().GetSymbolFromStrIdx( GlobalTables::GetStrTable().GetStrIdxFromName(NameMangler::kFieldOffsetDataPrefixStr + symbolName)); @@ -856,7 +856,7 @@ void MUIDReplacement::ReplaceAddroffuncConst(MIRConst *&entry, uint32 fieldID, b // this is an index into the funcDefTab constexpr uint64 idxIntoFuncDefTabFlag = 2u; constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - ((offset + 1) << reservedBits) + idxIntoFuncDefTabFlag, voidType); + static_cast(((offset + 1) << reservedBits) + idxIntoFuncDefTabFlag), voidType); } else if (isVtab && func->IsAbstract()) { MIRType &type = *GlobalTables::GetTypeTable().GetVoidPtr(); constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type); @@ -865,7 +865,8 @@ void MUIDReplacement::ReplaceAddroffuncConst(MIRConst *&entry, uint32 fieldID, b offset = FindIndexFromUndefTable(*(func->GetFuncSymbol()), true); // The second least significant bit is set to 0, indicating // this is an index into the funcUndefTab - constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst((offset + 1) << reservedBits, voidType); + constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast((offset + 1) << reservedBits), + voidType); } if (fieldID != 0xffffffff) { constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(constNode->GetValue(), @@ -893,8 +894,8 @@ void MUIDReplacement::ReplaceDataTable(const std::string &name) { MIRConstPtr mirConst = aggrC->GetConstVecItem(i); if (mirConst->GetKind() == kConstInt) { MIRIntConst *newIntConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(mirConst)->GetValue(), mirConst->GetType(), i + 1); - aggrC->SetConstVecItem(i, *newIntConst); + static_cast(mirConst)->GetValue(), mirConst->GetType(), static_cast(i + 1)); + aggrC->SetConstVecItem(static_cast(i), *newIntConst); } else { aggrC->GetConstVecItem(i)->SetFieldID(i + 1); } @@ -922,8 +923,8 @@ void MUIDReplacement::ReplaceDecoupleKeyTable(MIRAggConst* oldConst) { MIRConstPtr mirConst = aggrC->GetConstVecItem(i); if (mirConst->GetKind() == kConstInt) { MIRIntConst *newIntConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(mirConst)->GetValue(), mirConst->GetType(), i + 1); - aggrC->SetConstVecItem(i, *newIntConst); + static_cast(mirConst)->GetValue(), mirConst->GetType(), static_cast(i + 1)); + aggrC->SetConstVecItem(static_cast(i), *newIntConst); } else { aggrC->GetConstVecItem(i)->SetFieldID(i + 1); } @@ -950,10 +951,12 @@ void MUIDReplacement::ReplaceAddrofConst(MIRConst *&entry) { MIRIntConst *constNode = nullptr; if (addrSym->GetStorageClass() != kScExtern) { offset = FindIndexFromDefTable(*addrSym, false); - constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(offset | kFromDefIndexMask, voidType); + constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(offset | kFromDefIndexMask), + voidType); } else { offset = FindIndexFromUndefTable(*addrSym, false); - constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(offset | kFromUndefIndexMask, voidType); + constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(offset | kFromUndefIndexMask), + voidType); } entry = constNode; } diff --git a/src/mpl2mpl/src/native_stub_func.cpp b/src/mpl2mpl/src/native_stub_func.cpp index 9009e31f7e0a64d33379c13d3a4283877a230882..c9f59277f9942aa9c7c79609784cc2a6df40735e 100644 --- a/src/mpl2mpl/src/native_stub_func.cpp +++ b/src/mpl2mpl/src/native_stub_func.cpp @@ -173,11 +173,14 @@ void NativeStubFuncGeneration::ProcessFunc(MIRFunction *func) { if (!func->GetAttr(FUNCATTR_critical_native)) { if (needNativeCall) { func->GetBody()->AddStatement(preFuncCall); + // set up env + allocCallArgs.push_back(Options::usePreg + ? (static_cast(builder->CreateExprRegread(PTY_ptr, envPregIdx))) + : (static_cast(builder->CreateExprDread(*envPtrSym)))); + } else { + // set up env + allocCallArgs.push_back(builder->CreateIntConst(0, PTY_i32)); } - // set up env - allocCallArgs.push_back(Options::usePreg - ? (static_cast(builder->CreateExprRegread(PTY_ptr, envPregIdx))) - : (static_cast(builder->CreateExprDread(*envPtrSym)))); // set up class if (func->GetAttr(FUNCATTR_static)) { allocCallArgs.push_back(builder->CreateExprAddrof(0, *classObjSymbol)); @@ -200,15 +203,8 @@ void NativeStubFuncGeneration::ProcessFunc(MIRFunction *func) { stubFuncRet = builder->CreateSymbol(func->GetReturnTyIdx(), "retvar_stubfunc", kStVar, kScAuto, func, kScopeLocal); } MIRFunction &nativeFunc = GetOrCreateDefaultNativeFunc(*func); - if (Options::regNativeFunc) { GenerateRegisteredNativeFuncCall(*func, nativeFunc, allocCallArgs, stubFuncRet); - } else if (Options::nativeWrapper) { - GenerateNativeWrapperFuncCall(*func, nativeFunc, allocCallArgs, stubFuncRet); - } else { - CallNode *callAssign = - builder->CreateStmtCallAssigned(nativeFunc.GetPuidx(), allocCallArgs, stubFuncRet, OP_callassigned); - func->GetBody()->AddStatement(callAssign); } if (func->GetReturnType()->GetPrimType() == PTY_ref) { MapleVector decodeArgs(func->GetCodeMempoolAllocator().Adapter()); @@ -247,10 +243,7 @@ void NativeStubFuncGeneration::ProcessFunc(MIRFunction *func) { CallNode *callGetExceptFunc = builder->CreateStmtCallAssigned(MRTCheckThrowPendingExceptionFunc->GetPuidx(), getExceptArgs, nullptr, OP_callassigned); func->GetBody()->AddStatement(callGetExceptFunc); - } - // this function is a bridge function generated for Java Genetic - if ((func->GetAttr(FUNCATTR_native) || func->GetAttr(FUNCATTR_fast_native)) && - !func->GetAttr(FUNCATTR_critical_native) && !func->GetAttr(FUNCATTR_bridge)) { + } else if (!func->GetAttr(FUNCATTR_critical_native)) { MapleVector frameStatusArgs(func->GetCodeMempoolAllocator().Adapter()); CallNode *callSetFrameStatusFunc = builder->CreateStmtCallAssigned(MCCSetReliableUnwindContextFunc->GetPuidx(), frameStatusArgs, nullptr, OP_callassigned); @@ -280,7 +273,7 @@ void NativeStubFuncGeneration::GenerateRegFuncTabEntry() { constexpr uint64 locIdxMask = 0x01; uint64 locIdx = regFuncTabConst->GetConstVec().size(); auto *newConst = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast((locIdx << locIdxShift) | locIdxMask), + GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast((locIdx << locIdxShift) | locIdxMask), *GlobalTables::GetTypeTable().GetVoidPtr()); regFuncTabConst->PushBack(newConst); } @@ -509,12 +502,6 @@ StmtNode *NativeStubFuncGeneration::CreateNativeWrapperCallNode(MIRFunction &fun } } -void NativeStubFuncGeneration::GenerateNativeWrapperFuncCall(MIRFunction &func, const MIRFunction &nativeFunc, - MapleVector &args, const MIRSymbol *ret) { - func.GetBody()->AddStatement( - CreateNativeWrapperCallNode(func, builder->CreateExprAddroffunc(nativeFunc.GetPuidx()), args, ret)); -} - void NativeStubFuncGeneration::GenerateRegTableEntryType() { MIRArrayType &arrayType = *GlobalTables::GetTypeTable().GetOrCreateArrayType(*GlobalTables::GetTypeTable().GetVoidPtr(), 0); diff --git a/src/mpl2mpl/src/reflection_analysis.cpp b/src/mpl2mpl/src/reflection_analysis.cpp index 468155bfe5b250dddf148326f2d720fd16d16468..c9335daa4f295badc592e96ca9820956eaafa7f3 100644 --- a/src/mpl2mpl/src/reflection_analysis.cpp +++ b/src/mpl2mpl/src/reflection_analysis.cpp @@ -862,7 +862,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"); + CHECK_FATAL(fldID <= INT32_MAX, "filedId out of range"); fldID = fldID * 2; mirBuilder.AddIntFieldConst(type, newConst, metaFieldID, fldID); } diff --git a/src/mpl2mpl/src/vtable_analysis.cpp b/src/mpl2mpl/src/vtable_analysis.cpp index 98dcedf29f9751f82ce858ca5af2a620fbf1c7fb..f8b1b941e64e9c5a95a7be24b4c44766a622cdfe 100644 --- a/src/mpl2mpl/src/vtable_analysis.cpp +++ b/src/mpl2mpl/src/vtable_analysis.cpp @@ -296,7 +296,8 @@ void VtableAnalysis::GenItableDefinition(const Klass &klass) { auto *secondItabEmitArray = GetMIRModule().GetMemPool()->New(GetMIRModule(), *voidPtrType); // remember count in secondItabVec count = ((secondConflictList.size() | (1ULL << (kShiftCountBit - 1))) << kShiftCountBit) + count; - secondItabEmitArray->PushBack(GlobalTables::GetIntConstTable().GetOrCreateIntConst(count, *voidPtrType)); + secondItabEmitArray->PushBack(GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(count), + *voidPtrType)); secondItabEmitArray->PushBack(oneConst); // padding for (uint32 i = 0; i < kItabSecondHashSize; ++i) { if (!secondItab[i] && !secondConflictFlag[i]) { diff --git a/src/mpl2mpl/src/vtable_impl.cpp b/src/mpl2mpl/src/vtable_impl.cpp index f870542a286f49eee8b7b57d60a8fe3334e7421a..7ea995dc00375ff92bcb48a7ebbd7d814f54b4e9 100644 --- a/src/mpl2mpl/src/vtable_impl.cpp +++ b/src/mpl2mpl/src/vtable_impl.cpp @@ -32,7 +32,7 @@ VtableImpl::VtableImpl(MIRModule &mod, KlassHierarchy *kh, bool dump) mccItabFunc = builder->GetOrCreateFunction(kInterfaceMethod, TyIdx(PTY_ptr)); mccItabFunc->SetAttr(FUNCATTR_nosideeffect); } -#if TARGARM || TARGAARCH64 +#if defined(TARGARM) || defined(TARGAARCH64) bool VtableImpl::Intrinsify(MIRFunction &func, CallNode &cnode) { MIRFunction *calleeFunc = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(cnode.GetPUIdx()); const std::string funcName = calleeFunc->GetName(); @@ -81,7 +81,7 @@ void VtableImpl::ProcessFunc(MIRFunction *func) { while (stmt != nullptr) { next = stmt->GetNext(); Opcode opcode = stmt->GetOpCode(); -#if TARGARM || TARGAARCH64 +#if defined(TARGARM) || defined(TARGAARCH64) if (kOpcodeInfo.IsCallAssigned(opcode)) { CallNode *cnode = static_cast(stmt); MIRFunction *calleefunc = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(cnode->GetPUIdx());