diff --git a/build/third_party/llvm_001.patch b/build/third_party/llvm_001.patch new file mode 100644 index 0000000000000000000000000000000000000000..5e5b0f1511a2913b8acae4e72076b0d86f8c6432 --- /dev/null +++ b/build/third_party/llvm_001.patch @@ -0,0 +1,684 @@ +diff -ur include/llvm/BinaryFormat/Dwarf.def include_mod/llvm/BinaryFormat/Dwarf.def +--- include/llvm/BinaryFormat/Dwarf.def 2021-05-08 10:21:04.431120848 +0800 ++++ include_mod/llvm/BinaryFormat/Dwarf.def 2021-05-08 10:23:51.667120848 +0800 +@@ -17,11 +17,12 @@ + defined HANDLE_DW_VIRTUALITY || defined HANDLE_DW_DEFAULTED || \ + defined HANDLE_DW_CC || defined HANDLE_DW_LNS || defined HANDLE_DW_LNE || \ + defined HANDLE_DW_LNCT || defined HANDLE_DW_MACRO || \ ++ defined HANDLE_MACRO_FLAG || \ + defined HANDLE_DW_RLE || defined HANDLE_DW_LLE || \ + (defined HANDLE_DW_CFA && defined HANDLE_DW_CFA_PRED) || \ + defined HANDLE_DW_APPLE_PROPERTY || defined HANDLE_DW_UT || \ + defined HANDLE_DWARF_SECTION || defined HANDLE_DW_IDX || \ +- defined HANDLE_DW_END) ++ defined HANDLE_DW_END || defined HANDLE_DW_SECT) + #error "Missing macro definition of HANDLE_DW*" + #endif + +@@ -87,6 +88,10 @@ + #define HANDLE_DW_MACRO(ID, NAME) + #endif + ++#ifndef HANDLE_MACRO_FLAG ++#define HANDLE_MACRO_FLAG(ID, NAME) ++#endif ++ + #ifndef HANDLE_DW_RLE + #define HANDLE_DW_RLE(ID, NAME) + #endif +@@ -112,7 +117,7 @@ + #endif + + #ifndef HANDLE_DWARF_SECTION +-#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) ++#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME, OPTION) + #endif + + #ifndef HANDLE_DW_IDX +@@ -123,6 +128,10 @@ + #define HANDLE_DW_END(ID, NAME) + #endif + ++#ifndef HANDLE_DW_SECT ++#define HANDLE_DW_SECT(ID, NAME) ++#endif ++ + HANDLE_DW_TAG(0x0000, null, 2, DWARF, DW_KIND_NONE) + HANDLE_DW_TAG(0x0001, array_type, 2, DWARF, DW_KIND_TYPE) + HANDLE_DW_TAG(0x0002, class_type, 2, DWARF, DW_KIND_TYPE) +@@ -407,7 +416,11 @@ + HANDLE_DW_AT(0x3e01, LLVM_config_macros, 0, LLVM) + HANDLE_DW_AT(0x3e02, LLVM_sysroot, 0, LLVM) + HANDLE_DW_AT(0x3e03, LLVM_tag_offset, 0, LLVM) ++// The missing numbers here are reserved for ptrauth support. ++HANDLE_DW_AT(0x3e07, LLVM_apinotes, 0, APPLE) ++ + // Apple extensions. ++ + HANDLE_DW_AT(0x3fe1, APPLE_optimized, 0, APPLE) + HANDLE_DW_AT(0x3fe2, APPLE_flags, 0, APPLE) + HANDLE_DW_AT(0x3fe3, APPLE_isa, 0, APPLE) +@@ -422,6 +435,7 @@ + HANDLE_DW_AT(0x3fec, APPLE_objc_complete_type, 0, APPLE) + HANDLE_DW_AT(0x3fed, APPLE_property, 0, APPLE) + HANDLE_DW_AT(0x3fee, APPLE_objc_direct, 0, APPLE) ++HANDLE_DW_AT(0x3fef, APPLE_sdk, 0, APPLE) + + // Attribute form encodings. + HANDLE_DW_FORM(0x01, addr, 2, DWARF) +@@ -650,6 +664,7 @@ + HANDLE_DW_OP(0xe0, GNU_push_tls_address, 0, GNU) + // Extensions for WebAssembly. + HANDLE_DW_OP(0xed, WASM_location, 0, WASM) ++HANDLE_DW_OP(0xee, WASM_location_int, 0, WASM) + // The GNU entry value extension. + HANDLE_DW_OP(0xf3, GNU_entry_value, 0, GNU) + // Extensions for Fission proposal. +@@ -822,6 +837,11 @@ + HANDLE_DW_MACRO(0x0b, define_strx) + HANDLE_DW_MACRO(0x0c, undef_strx) + ++// DWARF v5 Macro header flags. ++HANDLE_MACRO_FLAG(0x01, OFFSET_SIZE) ++HANDLE_MACRO_FLAG(0x02, DEBUG_LINE_OFFSET) ++HANDLE_MACRO_FLAG(0x04, OPCODE_OPERANDS_TABLE) ++ + // DWARF v5 Range List Entry encoding values. + HANDLE_DW_RLE(0x00, end_of_list) + HANDLE_DW_RLE(0x01, base_addressx) +@@ -873,12 +893,13 @@ + HANDLE_DW_CFA(0x16, val_expression) + // Vendor extensions: + HANDLE_DW_CFA_PRED(0x1d, MIPS_advance_loc8, SELECT_MIPS64) +-HANDLE_DW_CFA_PRED(0x2d, GNU_window_save, SELECT_SPARC) ++//HANDLE_DW_CFA_PRED(0x2d, GNU_window_save, SELECT_SPARC) + HANDLE_DW_CFA_PRED(0x2d, AARCH64_negate_ra_state, SELECT_AARCH64) + HANDLE_DW_CFA_PRED(0x2e, GNU_args_size, SELECT_X86) + + // Apple Objective-C Property Attributes. +-// Keep this list in sync with clang's DeclSpec.h ObjCPropertyAttributeKind! ++// Keep this list in sync with clang's DeclObjCCommon.h ++// ObjCPropertyAttribute::Kind! + HANDLE_DW_APPLE_PROPERTY(0x01, readonly) + HANDLE_DW_APPLE_PROPERTY(0x02, getter) + HANDLE_DW_APPLE_PROPERTY(0x04, assign) +@@ -903,38 +924,38 @@ + HANDLE_DW_UT(0x05, split_compile) + HANDLE_DW_UT(0x06, split_type) + +-// DWARF section types. (enum name, ELF name, ELF DWO name, cmdline name) ++// DWARF section types. (enum name, ELF name, ELF DWO name, cmdline name, option) + // Note that these IDs don't mean anything. + // TODO: Add Mach-O and COFF names. + // Official DWARF sections. +-HANDLE_DWARF_SECTION(DebugAbbrev, ".debug_abbrev", "debug-abbrev") +-HANDLE_DWARF_SECTION(DebugAddr, ".debug_addr", "debug-addr") +-HANDLE_DWARF_SECTION(DebugAranges, ".debug_aranges", "debug-aranges") +-HANDLE_DWARF_SECTION(DebugInfo, ".debug_info", "debug-info") +-HANDLE_DWARF_SECTION(DebugTypes, ".debug_types", "debug-types") +-HANDLE_DWARF_SECTION(DebugLine, ".debug_line", "debug-line") +-HANDLE_DWARF_SECTION(DebugLineStr, ".debug_line_str", "debug-line-str") +-HANDLE_DWARF_SECTION(DebugLoc, ".debug_loc", "debug-loc") +-HANDLE_DWARF_SECTION(DebugLoclists, ".debug_loclists", "debug-loclists") +-HANDLE_DWARF_SECTION(DebugFrame, ".debug_frame", "debug-frame") +-HANDLE_DWARF_SECTION(DebugMacro, ".debug_macro", "debug-macro") +-HANDLE_DWARF_SECTION(DebugNames, ".debug_names", "debug-names") +-HANDLE_DWARF_SECTION(DebugPubnames, ".debug_pubnames", "debug-pubnames") +-HANDLE_DWARF_SECTION(DebugPubtypes, ".debug_pubtypes", "debug-pubtypes") +-HANDLE_DWARF_SECTION(DebugGnuPubnames, ".debug_gnu_pubnames", "debug-gnu-pubnames") +-HANDLE_DWARF_SECTION(DebugGnuPubtypes, ".debug_gnu_pubtypes", "debug-gnu-pubtypes") +-HANDLE_DWARF_SECTION(DebugRanges, ".debug_ranges", "debug-ranges") +-HANDLE_DWARF_SECTION(DebugRnglists, ".debug_rnglists", "debug-rnglists") +-HANDLE_DWARF_SECTION(DebugStr, ".debug_str", "debug-str") +-HANDLE_DWARF_SECTION(DebugStrOffsets, ".debug_str_offsets", "debug-str-offsets") +-HANDLE_DWARF_SECTION(DebugCUIndex, ".debug_cu_index", "debug-cu-index") +-HANDLE_DWARF_SECTION(DebugTUIndex, ".debug_tu_index", "debug-tu-index") ++HANDLE_DWARF_SECTION(DebugAbbrev, ".debug_abbrev", "debug-abbrev", BoolOption) ++HANDLE_DWARF_SECTION(DebugAddr, ".debug_addr", "debug-addr", BoolOption) ++HANDLE_DWARF_SECTION(DebugAranges, ".debug_aranges", "debug-aranges", BoolOption) ++HANDLE_DWARF_SECTION(DebugInfo, ".debug_info", "debug-info", OffsetOption) ++HANDLE_DWARF_SECTION(DebugTypes, ".debug_types", "debug-types", OffsetOption) ++HANDLE_DWARF_SECTION(DebugLine, ".debug_line", "debug-line", OffsetOption) ++HANDLE_DWARF_SECTION(DebugLineStr, ".debug_line_str", "debug-line-str", BoolOption) ++HANDLE_DWARF_SECTION(DebugLoc, ".debug_loc", "debug-loc", OffsetOption) ++HANDLE_DWARF_SECTION(DebugLoclists, ".debug_loclists", "debug-loclists", OffsetOption) ++HANDLE_DWARF_SECTION(DebugFrame, ".debug_frame", "debug-frame", OffsetOption) ++HANDLE_DWARF_SECTION(DebugMacro, ".debug_macro", "debug-macro", BoolOption) ++HANDLE_DWARF_SECTION(DebugNames, ".debug_names", "debug-names", BoolOption) ++HANDLE_DWARF_SECTION(DebugPubnames, ".debug_pubnames", "debug-pubnames", BoolOption) ++HANDLE_DWARF_SECTION(DebugPubtypes, ".debug_pubtypes", "debug-pubtypes", BoolOption) ++HANDLE_DWARF_SECTION(DebugGnuPubnames, ".debug_gnu_pubnames", "debug-gnu-pubnames", BoolOption) ++HANDLE_DWARF_SECTION(DebugGnuPubtypes, ".debug_gnu_pubtypes", "debug-gnu-pubtypes", BoolOption) ++HANDLE_DWARF_SECTION(DebugRanges, ".debug_ranges", "debug-ranges", BoolOption) ++HANDLE_DWARF_SECTION(DebugRnglists, ".debug_rnglists", "debug-rnglists", BoolOption) ++HANDLE_DWARF_SECTION(DebugStr, ".debug_str", "debug-str", BoolOption) ++HANDLE_DWARF_SECTION(DebugStrOffsets, ".debug_str_offsets", "debug-str-offsets", BoolOption) ++HANDLE_DWARF_SECTION(DebugCUIndex, ".debug_cu_index", "debug-cu-index", BoolOption) ++HANDLE_DWARF_SECTION(DebugTUIndex, ".debug_tu_index", "debug-tu-index", BoolOption) + // Vendor extensions. +-HANDLE_DWARF_SECTION(AppleNames, ".apple_names", "apple-names") +-HANDLE_DWARF_SECTION(AppleTypes, ".apple_types", "apple-types") +-HANDLE_DWARF_SECTION(AppleNamespaces, ".apple_namespaces", "apple-namespaces") +-HANDLE_DWARF_SECTION(AppleObjC, ".apple_objc", "apple-objc") +-HANDLE_DWARF_SECTION(GdbIndex, ".gdb_index", "gdb-index") ++HANDLE_DWARF_SECTION(AppleNames, ".apple_names", "apple-names", BoolOption) ++HANDLE_DWARF_SECTION(AppleTypes, ".apple_types", "apple-types", BoolOption) ++HANDLE_DWARF_SECTION(AppleNamespaces, ".apple_namespaces", "apple-namespaces", BoolOption) ++HANDLE_DWARF_SECTION(AppleObjC, ".apple_objc", "apple-objc", BoolOption) ++HANDLE_DWARF_SECTION(GdbIndex, ".gdb_index", "gdb-index", BoolOption) + + HANDLE_DW_IDX(0x01, compile_unit) + HANDLE_DW_IDX(0x02, type_unit) +@@ -942,6 +963,15 @@ + HANDLE_DW_IDX(0x04, parent) + HANDLE_DW_IDX(0x05, type_hash) + ++// DWARF package file section identifiers. ++// DWARFv5, section 7.3.5.3, table 7.1. ++HANDLE_DW_SECT(1, INFO) ++HANDLE_DW_SECT(3, ABBREV) ++HANDLE_DW_SECT(4, LINE) ++HANDLE_DW_SECT(5, LOCLISTS) ++HANDLE_DW_SECT(6, STR_OFFSETS) ++HANDLE_DW_SECT(7, MACRO) ++HANDLE_DW_SECT(8, RNGLISTS) + + #undef HANDLE_DW_TAG + #undef HANDLE_DW_AT +@@ -956,6 +986,7 @@ + #undef HANDLE_DW_LNE + #undef HANDLE_DW_LNCT + #undef HANDLE_DW_MACRO ++#undef HANDLE_MACRO_FLAG + #undef HANDLE_DW_RLE + #undef HANDLE_DW_LLE + #undef HANDLE_DW_CFA +@@ -965,3 +996,4 @@ + #undef HANDLE_DWARF_SECTION + #undef HANDLE_DW_IDX + #undef HANDLE_DW_END ++#undef HANDLE_DW_SECT +diff -ur include/llvm/BinaryFormat/Dwarf.h include_mod/llvm/BinaryFormat/Dwarf.h +--- include/llvm/BinaryFormat/Dwarf.h 2021-05-08 10:21:04.431120848 +0800 ++++ include_mod/llvm/BinaryFormat/Dwarf.h 2021-05-08 10:23:51.667120848 +0800 +@@ -1,4 +1,4 @@ +-//===-- llvm/BinaryFormat/Dwarf.h ---Dwarf Constants-------------*- C++ -*-===// ++//===-- Dwarf.h ---Dwarf Constants-------------*- C++ -*-===// + // + // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. + // See https://llvm.org/LICENSE.txt for license information. +@@ -19,19 +19,6 @@ + #ifndef LLVM_BINARYFORMAT_DWARF_H + #define LLVM_BINARYFORMAT_DWARF_H + +-#include "llvm/ADT/Optional.h" +-#include "llvm/Support/Compiler.h" +-#include "llvm/Support/DataTypes.h" +-#include "llvm/Support/ErrorHandling.h" +-#include "llvm/Support/Format.h" +-#include "llvm/Support/FormatVariadicDetails.h" +-#include "llvm/ADT/Triple.h" +- +-namespace llvm { +-class StringRef; +- +-namespace dwarf { +- + //===----------------------------------------------------------------------===// + // DWARF constants as gleaned from the DWARF Debugging Information Format V.5 + // reference manual http://www.dwarfstd.org/. +@@ -41,7 +28,7 @@ + // enumeration base type. + + enum LLVMConstants : uint32_t { +- // LLVM mock tags (see also llvm/BinaryFormat/Dwarf.def). ++ // LLVM mock tags (see also Dwarf.def). + DW_TAG_invalid = ~0U, // Tag for invalid results. + DW_VIRTUALITY_invalid = ~0U, // Virtuality for invalid results. + DW_MACINFO_invalid = ~0U, // Macinfo type for invalid results. +@@ -82,7 +69,7 @@ + + enum Tag : uint16_t { + #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) DW_TAG_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + DW_TAG_lo_user = 0x4080, + DW_TAG_hi_user = 0xffff, + DW_TAG_user_base = 0x1000 ///< Recommended base for user tags. +@@ -95,27 +82,27 @@ + #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) \ + case DW_TAG_##NAME: \ + return (KIND == DW_KIND_TYPE); +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + } + } + + /// Attributes. + enum Attribute : uint16_t { + #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) DW_AT_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + DW_AT_lo_user = 0x2000, + DW_AT_hi_user = 0x3fff, + }; + + enum Form : uint16_t { + #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) DW_FORM_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + DW_FORM_lo_user = 0x1f00, ///< Not specified by DWARF. + }; + + enum LocationAtom { + #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) DW_OP_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + DW_OP_lo_user = 0xe0, + DW_OP_hi_user = 0xff, + DW_OP_LLVM_fragment = 0x1000, ///< Only used in LLVM metadata. +@@ -126,7 +113,7 @@ + + enum TypeKind : uint8_t { + #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) DW_ATE_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + DW_ATE_lo_user = 0x80, + DW_ATE_hi_user = 0xff + }; +@@ -143,7 +130,7 @@ + enum EndianityEncoding { + // Endianity attribute values + #define HANDLE_DW_END(ID, NAME) DW_END_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + DW_END_lo_user = 0x40, + DW_END_hi_user = 0xff + }; +@@ -164,20 +151,20 @@ + + enum VirtualityAttribute { + #define HANDLE_DW_VIRTUALITY(ID, NAME) DW_VIRTUALITY_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + DW_VIRTUALITY_max = 0x02 + }; + + enum DefaultedMemberAttribute { + #define HANDLE_DW_DEFAULTED(ID, NAME) DW_DEFAULTED_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + DW_DEFAULTED_max = 0x02 + }; + + enum SourceLanguage { + #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \ + DW_LANG_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + DW_LANG_lo_user = 0x8000, + DW_LANG_hi_user = 0xffff + }; +@@ -232,7 +219,6 @@ + case DW_LANG_hi_user: + return false; + } +- llvm_unreachable("Invalid source language"); + } + + enum CaseSensitivity { +@@ -246,7 +232,7 @@ + enum CallingConvention { + // Calling convention codes + #define HANDLE_DW_CC(ID, NAME) DW_CC_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + DW_CC_lo_user = 0x40, + DW_CC_hi_user = 0xff + }; +@@ -274,20 +260,20 @@ + /// Line Number Standard Opcode Encodings. + enum LineNumberOps : uint8_t { + #define HANDLE_DW_LNS(ID, NAME) DW_LNS_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + }; + + /// Line Number Extended Opcode Encodings. + enum LineNumberExtendedOps { + #define HANDLE_DW_LNE(ID, NAME) DW_LNE_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + DW_LNE_lo_user = 0x80, + DW_LNE_hi_user = 0xff + }; + + enum LineNumberEntryFormat { + #define HANDLE_DW_LNCT(ID, NAME) DW_LNCT_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + DW_LNCT_lo_user = 0x2000, + DW_LNCT_hi_user = 0x3fff, + }; +@@ -304,7 +290,7 @@ + /// DWARF v5 macro information entry type encodings. + enum MacroEntryType { + #define HANDLE_DW_MACRO(ID, NAME) DW_MACRO_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + DW_MACRO_lo_user = 0xe0, + DW_MACRO_hi_user = 0xff + }; +@@ -312,20 +298,20 @@ + /// DWARF v5 range list entry encoding values. + enum RnglistEntries { + #define HANDLE_DW_RLE(ID, NAME) DW_RLE_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + }; + + /// DWARF v5 loc list entry encoding values. + enum LoclistEntries { + #define HANDLE_DW_LLE(ID, NAME) DW_LLE_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + }; + + /// Call frame instruction encodings. + enum CallFrameInfo { + #define HANDLE_DW_CFA(ID, NAME) DW_CFA_##NAME = ID, + #define HANDLE_DW_CFA_PRED(ID, NAME, ARCH) DW_CFA_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + DW_CFA_extended = 0x00, + + DW_CFA_lo_user = 0x1c, +@@ -357,23 +343,24 @@ + }; + + /// Constants for the DW_APPLE_PROPERTY_attributes attribute. +-/// Keep this list in sync with clang's DeclSpec.h ObjCPropertyAttributeKind! ++/// Keep this list in sync with clang's DeclObjCCommon.h ++/// ObjCPropertyAttribute::Kind! + enum ApplePropertyAttributes { + #define HANDLE_DW_APPLE_PROPERTY(ID, NAME) DW_APPLE_PROPERTY_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + }; + + /// Constants for unit types in DWARF v5. + enum UnitType : unsigned char { + #define HANDLE_DW_UT(ID, NAME) DW_UT_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + DW_UT_lo_user = 0x80, + DW_UT_hi_user = 0xff + }; + + enum Index { + #define HANDLE_DW_IDX(ID, NAME) DW_IDX_##NAME = ID, +-#include "llvm/BinaryFormat/Dwarf.def" ++#include "Dwarf.def" + DW_IDX_lo_user = 0x2000, + DW_IDX_hi_user = 0x3fff + }; +@@ -392,7 +379,7 @@ + } + } + +-inline bool isUnitType(dwarf::Tag T) { ++inline bool isUnitType(Tag T) { + switch (T) { + case DW_TAG_compile_unit: + case DW_TAG_type_unit: +@@ -429,250 +416,6 @@ + DW_hash_function_djb = 0u + }; + +-// Constants for the GNU pubnames/pubtypes extensions supporting gdb index. +-enum GDBIndexEntryKind { +- GIEK_NONE, +- GIEK_TYPE, +- GIEK_VARIABLE, +- GIEK_FUNCTION, +- GIEK_OTHER, +- GIEK_UNUSED5, +- GIEK_UNUSED6, +- GIEK_UNUSED7 +-}; +- + enum GDBIndexEntryLinkage { GIEL_EXTERNAL, GIEL_STATIC }; + +-/// \defgroup DwarfConstantsDumping Dwarf constants dumping functions +-/// +-/// All these functions map their argument's value back to the +-/// corresponding enumerator name or return an empty StringRef if the value +-/// isn't known. +-/// +-/// @{ +-StringRef TagString(unsigned Tag); +-StringRef ChildrenString(unsigned Children); +-StringRef AttributeString(unsigned Attribute); +-StringRef FormEncodingString(unsigned Encoding); +-StringRef OperationEncodingString(unsigned Encoding); +-StringRef AttributeEncodingString(unsigned Encoding); +-StringRef DecimalSignString(unsigned Sign); +-StringRef EndianityString(unsigned Endian); +-StringRef AccessibilityString(unsigned Access); +-StringRef DefaultedMemberString(unsigned DefaultedEncodings); +-StringRef VisibilityString(unsigned Visibility); +-StringRef VirtualityString(unsigned Virtuality); +-StringRef LanguageString(unsigned Language); +-StringRef CaseString(unsigned Case); +-StringRef ConventionString(unsigned Convention); +-StringRef InlineCodeString(unsigned Code); +-StringRef ArrayOrderString(unsigned Order); +-StringRef LNStandardString(unsigned Standard); +-StringRef LNExtendedString(unsigned Encoding); +-StringRef MacinfoString(unsigned Encoding); +-StringRef RangeListEncodingString(unsigned Encoding); +-StringRef LocListEncodingString(unsigned Encoding); +-StringRef CallFrameString(unsigned Encoding, Triple::ArchType Arch); +-StringRef ApplePropertyString(unsigned); +-StringRef UnitTypeString(unsigned); +-StringRef AtomTypeString(unsigned Atom); +-StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind); +-StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage); +-StringRef IndexString(unsigned Idx); +-/// @} +- +-/// \defgroup DwarfConstantsParsing Dwarf constants parsing functions +-/// +-/// These functions map their strings back to the corresponding enumeration +-/// value or return 0 if there is none, except for these exceptions: +-/// +-/// \li \a getTag() returns \a DW_TAG_invalid on invalid input. +-/// \li \a getVirtuality() returns \a DW_VIRTUALITY_invalid on invalid input. +-/// \li \a getMacinfo() returns \a DW_MACINFO_invalid on invalid input. +-/// +-/// @{ +-unsigned getTag(StringRef TagString); +-unsigned getOperationEncoding(StringRef OperationEncodingString); +-unsigned getVirtuality(StringRef VirtualityString); +-unsigned getLanguage(StringRef LanguageString); +-unsigned getCallingConvention(StringRef LanguageString); +-unsigned getAttributeEncoding(StringRef EncodingString); +-unsigned getMacinfo(StringRef MacinfoString); +-/// @} +- +-/// \defgroup DwarfConstantsVersioning Dwarf version for constants +-/// +-/// For constants defined by DWARF, returns the DWARF version when the constant +-/// was first defined. For vendor extensions, if there is a version-related +-/// policy for when to emit it, returns a version number for that policy. +-/// Otherwise returns 0. +-/// +-/// @{ +-unsigned TagVersion(Tag T); +-unsigned AttributeVersion(Attribute A); +-unsigned FormVersion(Form F); +-unsigned OperationVersion(LocationAtom O); +-unsigned AttributeEncodingVersion(TypeKind E); +-unsigned LanguageVersion(SourceLanguage L); +-/// @} +- +-/// \defgroup DwarfConstantsVendor Dwarf "vendor" for constants +-/// +-/// These functions return an identifier describing "who" defined the constant, +-/// either the DWARF standard itself or the vendor who defined the extension. +-/// +-/// @{ +-unsigned TagVendor(Tag T); +-unsigned AttributeVendor(Attribute A); +-unsigned FormVendor(Form F); +-unsigned OperationVendor(LocationAtom O); +-unsigned AttributeEncodingVendor(TypeKind E); +-unsigned LanguageVendor(SourceLanguage L); +-/// @} +- +-Optional LanguageLowerBound(SourceLanguage L); +- +-/// A helper struct providing information about the byte size of DW_FORM +-/// values that vary in size depending on the DWARF version, address byte +-/// size, or DWARF32/DWARF64. +-struct FormParams { +- uint16_t Version; +- uint8_t AddrSize; +- DwarfFormat Format; +- +- /// The definition of the size of form DW_FORM_ref_addr depends on the +- /// version. In DWARF v2 it's the size of an address; after that, it's the +- /// size of a reference. +- uint8_t getRefAddrByteSize() const { +- if (Version == 2) +- return AddrSize; +- return getDwarfOffsetByteSize(); +- } +- +- /// The size of a reference is determined by the DWARF 32/64-bit format. +- uint8_t getDwarfOffsetByteSize() const { +- switch (Format) { +- case DwarfFormat::DWARF32: +- return 4; +- case DwarfFormat::DWARF64: +- return 8; +- } +- llvm_unreachable("Invalid Format value"); +- } +- +- explicit operator bool() const { return Version && AddrSize; } +-}; +- +-/// Get the byte size of the unit length field depending on the DWARF format. +-inline uint8_t getUnitLengthFieldByteSize(DwarfFormat Format) { +- switch (Format) { +- case DwarfFormat::DWARF32: +- return 4; +- case DwarfFormat::DWARF64: +- return 12; +- } +- llvm_unreachable("Invalid Format value"); +-} +- +-/// Get the fixed byte size for a given form. +-/// +-/// If the form has a fixed byte size, then an Optional with a value will be +-/// returned. If the form is always encoded using a variable length storage +-/// format (ULEB or SLEB numbers or blocks) then None will be returned. +-/// +-/// \param Form DWARF form to get the fixed byte size for. +-/// \param Params DWARF parameters to help interpret forms. +-/// \returns Optional value with the fixed byte size or None if +-/// \p Form doesn't have a fixed byte size. +-Optional getFixedFormByteSize(dwarf::Form Form, FormParams Params); +- +-/// Tells whether the specified form is defined in the specified version, +-/// or is an extension if extensions are allowed. +-bool isValidFormForVersion(Form F, unsigned Version, bool ExtensionsOk = true); +- +-/// Returns the symbolic string representing Val when used as a value +-/// for attribute Attr. +-StringRef AttributeValueString(uint16_t Attr, unsigned Val); +- +-/// Returns the symbolic string representing Val when used as a value +-/// for atom Atom. +-StringRef AtomValueString(uint16_t Atom, unsigned Val); +- +-/// Describes an entry of the various gnu_pub* debug sections. +-/// +-/// The gnu_pub* kind looks like: +-/// +-/// 0-3 reserved +-/// 4-6 symbol kind +-/// 7 0 == global, 1 == static +-/// +-/// A gdb_index descriptor includes the above kind, shifted 24 bits up with the +-/// offset of the cu within the debug_info section stored in those 24 bits. +-struct PubIndexEntryDescriptor { +- GDBIndexEntryKind Kind; +- GDBIndexEntryLinkage Linkage; +- PubIndexEntryDescriptor(GDBIndexEntryKind Kind, GDBIndexEntryLinkage Linkage) +- : Kind(Kind), Linkage(Linkage) {} +- /* implicit */ PubIndexEntryDescriptor(GDBIndexEntryKind Kind) +- : Kind(Kind), Linkage(GIEL_EXTERNAL) {} +- explicit PubIndexEntryDescriptor(uint8_t Value) +- : Kind( +- static_cast((Value & KIND_MASK) >> KIND_OFFSET)), +- Linkage(static_cast((Value & LINKAGE_MASK) >> +- LINKAGE_OFFSET)) {} +- uint8_t toBits() const { +- return Kind << KIND_OFFSET | Linkage << LINKAGE_OFFSET; +- } +- +-private: +- enum { +- KIND_OFFSET = 4, +- KIND_MASK = 7 << KIND_OFFSET, +- LINKAGE_OFFSET = 7, +- LINKAGE_MASK = 1 << LINKAGE_OFFSET +- }; +-}; +- +-template struct EnumTraits : public std::false_type {}; +- +-template <> struct EnumTraits : public std::true_type { +- static constexpr char Type[3] = "AT"; +- static constexpr StringRef (*StringFn)(unsigned) = &AttributeString; +-}; +- +-template <> struct EnumTraits
: public std::true_type { +- static constexpr char Type[5] = "FORM"; +- static constexpr StringRef (*StringFn)(unsigned) = &FormEncodingString; +-}; +- +-template <> struct EnumTraits : public std::true_type { +- static constexpr char Type[4] = "IDX"; +- static constexpr StringRef (*StringFn)(unsigned) = &IndexString; +-}; +- +-template <> struct EnumTraits : public std::true_type { +- static constexpr char Type[4] = "TAG"; +- static constexpr StringRef (*StringFn)(unsigned) = &TagString; +-}; +-} // End of namespace dwarf +- +-/// Dwarf constants format_provider +-/// +-/// Specialization of the format_provider template for dwarf enums. Unlike the +-/// dumping functions above, these format unknown enumerator values as +-/// DW_TYPE_unknown_1234 (e.g. DW_TAG_unknown_ffff). +-template +-struct format_provider< +- Enum, typename std::enable_if::value>::type> { +- static void format(const Enum &E, raw_ostream &OS, StringRef Style) { +- StringRef Str = dwarf::EnumTraits::StringFn(E); +- if (Str.empty()) { +- OS << "DW_" << dwarf::EnumTraits::Type << "_unknown_" +- << llvm::format("%x", E); +- } else +- OS << Str; +- } +-}; +-} // End of namespace llvm +- + #endif diff --git a/build/third_party/patch.sh b/build/third_party/patch.sh index 8d06a6c1df34bad60339453f7ac0926ded37c16d..8b20cec1482fd740f833d56b45492daec55525f7 100644 --- a/build/third_party/patch.sh +++ b/build/third_party/patch.sh @@ -18,8 +18,9 @@ THIRD_PARTY_PATH=$MAPLE_ROOT/third_party TOOLS_PATH=$MAPLE_ROOT/build/third_party AOSP_PATH=$THIRD_PARTY_PATH/aosp_10.0.0_r35 AOSP_GN_PATH=$TOOLS_PATH/aosp_gn -TEMP_PATH=$THIRD_PARTY_PATH/temp +LLVM_PATH=$THIRD_PARTY_PATH/llvm-10.0.0.src MODIFIED_AOSP_PATH=$THIRD_PARTY_PATH/aosp_modified +MODIFIED_LLVM_PATH=$THIRD_PARTY_PATH/llvm_modified function install_patch { if [ -d $MODIFIED_AOSP_PATH ];then @@ -30,7 +31,9 @@ function install_patch { echo "Preparing the build environment..." #backup source code + cd $THIRD_PARTY_PATH cp -rH $AOSP_PATH $MODIFIED_AOSP_PATH + cp -rH $LLVM_PATH $MODIFIED_LLVM_PATH #patch cd $MODIFIED_AOSP_PATH @@ -39,15 +42,18 @@ function install_patch { mkdir -p include/ cp -r ${MAPLE_ROOT}/src/mplfe/dex_input/include/string_view_format.h include/ + cd $MODIFIED_LLVM_PATH + patch -p0 < $TOOLS_PATH/llvm_001.patch + #add third_party gn - cp -f $AOSP_GN_PATH/art/libdexfile/BUILD.gn art/libdexfile/ - cp -f $AOSP_GN_PATH/system/core/libziparchive/BUILD.gn system/core/libziparchive/ - cp -f $AOSP_GN_PATH/system/core/base/BUILD.gn system/core/base/ + cp -f $AOSP_GN_PATH/art/libdexfile/BUILD.gn $MODIFIED_AOSP_PATH/art/libdexfile/ + cp -f $AOSP_GN_PATH/system/core/libziparchive/BUILD.gn $MODIFIED_AOSP_PATH/system/core/libziparchive/ + cp -f $AOSP_GN_PATH/system/core/base/BUILD.gn $MODIFIED_AOSP_PATH/system/core/base/ } function uninstall_patch { - rm -rf $MODIFIED_AOSP_PATH + rm -rf $MODIFIED_AOSP_PATH $MODIFIED_LLVM_PATH } function main { diff --git a/src/mapleall/bin/dex2mpl b/src/mapleall/bin/dex2mpl index a9bdb1465f7151bd3b9d2d0a88816b541bc86139..b602ad47b27403c4dc150d87325cb3c3688e5114 100755 Binary files a/src/mapleall/bin/dex2mpl and b/src/mapleall/bin/dex2mpl differ diff --git a/src/mapleall/bin/dex2mpl_android b/src/mapleall/bin/dex2mpl_android index 9e07bd06951ad686380837ef6a8605a7b3c0b800..5ef3ac904ca550c14e9c011aeb2d2a2cd22e02f7 100755 Binary files a/src/mapleall/bin/dex2mpl_android and b/src/mapleall/bin/dex2mpl_android differ diff --git a/src/mapleall/bin/jbc2mpl b/src/mapleall/bin/jbc2mpl index fe0f8795d5d4f5919d66b4e6dbc1ed2179ead7ad..0baefe58f577f524bca2f9a0f51c27ca21e546e3 100755 Binary files a/src/mapleall/bin/jbc2mpl and b/src/mapleall/bin/jbc2mpl differ diff --git a/src/mapleall/maple_be/include/cg/aarch64/aarch64_color_ra.h b/src/mapleall/maple_be/include/cg/aarch64/aarch64_color_ra.h index b4f478147b084a1f8c66b837447c8d73966cda94..efc896fcc2f9e03f30964e9f85ce2c0a151dc946 100644 --- a/src/mapleall/maple_be/include/cg/aarch64/aarch64_color_ra.h +++ b/src/mapleall/maple_be/include/cg/aarch64/aarch64_color_ra.h @@ -1099,7 +1099,7 @@ class GraphColorRegAllocator : public AArch64RegAllocator { localRegVec.resize(cgFunc.NumBBs()); bbRegInfo.resize(cgFunc.NumBBs()); if (CGOptions::DoMultiPassColorRA()) { - int32 cnt = 0; + uint32 cnt = 0; FOR_ALL_BB(bb, &cgFunc) { FOR_BB_INSNS(insn, bb) { ++cnt; @@ -1230,10 +1230,10 @@ class GraphColorRegAllocator : public AArch64RegAllocator { void MarkCalleeSaveRegs(); void MarkUsedRegs(Operand &opnd, uint64 &usedRegMask); uint64 FinalizeRegisterPreprocess(FinalizeRegisterInfo &fInfo, Insn &insn); + void FinalizeRegisters(); void GenerateSpillFillRegs(Insn &insn); RegOperand *CreateSpillFillCode(RegOperand &opnd, Insn &insn, uint32 spillCnt, bool isdef = false); void SpillLiveRangeForSpills(); - void FinalizeRegisters(); MapleVector::iterator GetHighPriorityLr(MapleVector &lrSet) const; void UpdateForbiddenForNeighbors(LiveRange &lr) const; diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp index 1278fe1903384f106bd1bf762adc8e5cfdc838f6..e5b0c26ffc2a6e73449887d8735d3fc084d906bb 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -2825,7 +2825,7 @@ void AArch64CGFunc::SelectRem(Operand &resOpnd, Operand &lhsOpnd, Operand &rhsOp * and wRespond, wRespond, #1 * sub wRespond, wRespond, w2 */ - if ((Globals::GetInstance()->GetOptimLevel() >= CGOptions::kLevel2) && movImmInsn && + if ((Globals::GetInstance()->GetOptimLevel() >= CGOptions::kLevel2) && movImmInsn && isSigned && ((movImmInsn->GetMachineOpcode() == MOP_xmovri32) || (movImmInsn->GetMachineOpcode() == MOP_xmovri64)) && movImmInsn->GetOperand(0).Equals(opnd1)) { auto &imm = static_cast(movImmInsn->GetOperand(kInsnSecondOpnd)); @@ -3492,10 +3492,17 @@ Operand *AArch64CGFunc::SelectExtractbits(ExtractbitsNode &node, Operand &srcOpn * operand fits in MOVK if * is64Bits && boffst == 0, 16, 32, 48 && bSize == 16, so boffset / 16 == 0, 1, 2, 3; (boffset / 16 ) & (~3) == 0 * or is32Bits && boffset == 0, 16 && bSize == 16, so boffset / 16 == 0, 1; (boffset / 16) & (~1) == 0 + * imm range of aarch64-movk [0 - 65536] imm16 */ -inline bool IsMoveWideKeepable(uint32 bitOffset, uint32 bitSize, bool is64Bits) { +inline bool IsMoveWideKeepable(int64 offsetVal, uint32 bitOffset, uint32 bitSize, bool is64Bits) { ASSERT(is64Bits || (bitOffset < k32BitSize), ""); - return (bitSize == k16BitSize && ((bitOffset >> k16BitShift) & ~static_cast(is64Bits ? 0x3 : 0x1)) == 0); + bool isOutOfRange = offsetVal < 0; + if (!isOutOfRange) { + isOutOfRange = (static_cast(offsetVal) >> k16BitSize) > 0; + } + return (!isOutOfRange) && + bitSize == k16BitSize && + ((bitOffset >> k16BitShift) & ~static_cast(is64Bits ? 0x3 : 0x1)) == 0; } /* we use the fact that A ^ B ^ A == B, A ^ 0 = A */ @@ -3504,12 +3511,14 @@ Operand *AArch64CGFunc::SelectDepositBits(DepositbitsNode &node, Operand &opnd0, uint32 bitSize = node.GetBitsSize(); PrimType regType = node.GetPrimType(); bool is64Bits = GetPrimTypeBitSize(regType) == k64BitSize; + /* * if operand 1 is immediate and fits in MOVK, use it * MOVK Wd, #imm{, LSL #shift} ; 32-bit general registers * MOVK Xd, #imm{, LSL #shift} ; 64-bit general registers */ - if (opnd1.IsIntImmediate() && IsMoveWideKeepable(bitOffset, bitSize, is64Bits)) { + if (opnd1.IsIntImmediate() && + IsMoveWideKeepable(static_cast(opnd1).GetValue(), bitOffset, bitSize, is64Bits)) { RegOperand &resOpnd = CreateRegisterOperandOfType(regType); SelectCopy(resOpnd, regType, opnd0, regType); GetCurBB()->AppendInsn(GetCG()->BuildInstruction((is64Bits ? MOP_xmovkri16 : MOP_wmovkri16), diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_color_ra.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_color_ra.cpp index 479d7332520b872ddd87da1ec40b266114722f26..61c0387109a65d7919b0d1893ac2a3e1447b541e 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_color_ra.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_color_ra.cpp @@ -2971,7 +2971,7 @@ uint64 GraphColorRegAllocator::FinalizeRegisterPreprocess(FinalizeRegisterInfo & const AArch64MD *md = &AArch64CG::kMd[static_cast(&insn)->GetMachineOpcode()]; uint32 opndNum = insn.GetOperandSize(); for (uint32 i = 0; i < opndNum; ++i) { - Operand &opnd = insn.GetOperand(i); + Operand &opnd = insn.GetOperand(static_cast(i)); ASSERT(md->GetOperand(i) != nullptr, "pointer is null in GraphColorRegAllocator::FinalizeRegisters"); if (opnd.IsList()) { @@ -3015,16 +3015,16 @@ void GraphColorRegAllocator::GenerateSpillFillRegs(Insn &insn) { uint32 intUseCnt = 0; uint32 fpUseCnt = 0; uint32 opndNum = insn.GetOperandSize(); - for (uint32 i = 0; i < opndNum; ++i) { - Operand *opnd = &insn.GetOperand(i); - if (!opnd) { + for (uint32 opndIdx = 0; opndIdx < opndNum; ++opndIdx) { + Operand *opnd = &insn.GetOperand(static_cast(opndIdx)); + if (opnd == nullptr) { continue; } if (opnd->IsList()) { // call parameters } else if (opnd->IsMemoryAccessOperand()) { - MemOperand *memopnd = static_cast(opnd); - AArch64RegOperand *base = static_cast(memopnd->GetBaseRegister()); + MemOperand *memopnd = static_cast(opnd); + AArch64RegOperand *base = static_cast(memopnd->GetBaseRegister()); if (base != nullptr && base->IsPhysicalRegister()) { regno_t regno = base->GetRegisterNumber(); for (uint32 i = 0; i < kSpillMemOpndNum; ++i) { @@ -3033,11 +3033,8 @@ void GraphColorRegAllocator::GenerateSpillFillRegs(Insn &insn) { break; } } -// if (regno == intRegs[0] || regno == intRegs[1] || regno == intRegs[2]) { -// intUseCnt++; -// } } - AArch64RegOperand *offset = static_cast(memopnd->GetIndexRegister()); + AArch64RegOperand *offset = static_cast(memopnd->GetIndexRegister()); if (offset != nullptr && offset->IsPhysicalRegister()) { regno_t regno = offset->GetRegisterNumber(); for (uint32 i = 0; i < kSpillMemOpndNum; ++i) { @@ -3046,13 +3043,10 @@ void GraphColorRegAllocator::GenerateSpillFillRegs(Insn &insn) { break; } } -// if (regno == intRegs[0] || regno == intRegs[1] || regno == intRegs[2]) { -// intUseCnt++; -// } } } else if (opnd->IsRegister()) { - RegOperand *ropnd = static_cast(opnd); - if (ropnd && ropnd->IsVirtualRegister() == false) { + RegOperand *ropnd = static_cast(opnd); + if (ropnd != nullptr && ropnd->IsVirtualRegister() == false) { regno_t regno = ropnd->GetRegisterNumber(); if (regno >= V0) { for (uint32 i = 0; i < kSpillMemOpndNum; ++i) { @@ -3061,9 +3055,6 @@ void GraphColorRegAllocator::GenerateSpillFillRegs(Insn &insn) { break; } } -// if (regno == fpregs[0] || regno == fpregs[1] || regno == fpregs[2]) { -// fpUseCnt++; -// } } else { for (uint32 i = 0; i < kSpillMemOpndNum; ++i) { if (regno == intRegs[i]) { @@ -3071,9 +3062,6 @@ void GraphColorRegAllocator::GenerateSpillFillRegs(Insn &insn) { break; } } -// if (regno == intregs[0] || regno == intregs[1] || regno == intregs[2]) { -// intUseCnt++; -// } } } } @@ -3082,19 +3070,13 @@ void GraphColorRegAllocator::GenerateSpillFillRegs(Insn &insn) { intSpillFillRegs[i] = intRegs[i] + intUseCnt; fpSpillFillRegs[i] = fpRegs[i] + fpUseCnt; } -// intSpillFillRegs[0] = intregs[0] + intUseCnt; -// intSpillFillRegs[1] = intregs[1] + intUseCnt; -// intSpillFillRegs[2] = intregs[2] + intUseCnt; -// fpSpillFillRegs[0] = fpregs[0] + fpUseCnt; -// fpSpillFillRegs[1] = fpregs[1] + fpUseCnt; -// fpSpillFillRegs[2] = fpregs[2] + fpUseCnt; } RegOperand *GraphColorRegAllocator::CreateSpillFillCode(RegOperand &opnd, Insn &insn, uint32 spillCnt, bool isdef) { regno_t vregno = opnd.GetRegisterNumber(); LiveRange *lr = lrVec[vregno]; - if (lr && lr->IsSpilled()) { - AArch64CGFunc *a64cgfunc = static_cast(cgFunc); + if (lr != nullptr && lr->IsSpilled()) { + AArch64CGFunc *a64cgfunc = static_cast(cgFunc); CG *cg = a64cgfunc->GetCG(); uint32 bits = opnd.GetValidBitsNum(); if (bits < k32BitSize) { @@ -3113,8 +3095,8 @@ RegOperand *GraphColorRegAllocator::CreateSpillFillCode(RegOperand &opnd, Insn & } CHECK_FATAL(spillCnt < kSpillMemOpndNum, "spill count exceeded"); spreg = (rtype == kRegTyInt) ? intSpillFillRegs[spillCnt] : fpSpillFillRegs[spillCnt]; - RegOperand *regopnd = &a64cgfunc->GetOrCreatePhysicalRegisterOperand(static_cast(spreg), opnd.GetSize(), rtype); - + RegOperand *regopnd = + &a64cgfunc->GetOrCreatePhysicalRegisterOperand(static_cast(spreg), opnd.GetSize(), rtype); Insn *memInsn; if (isdef) { memInsn = &cg->BuildInstruction(a64cgfunc->PickStInsn(bits, pty), *regopnd, *loadmem); @@ -3145,35 +3127,35 @@ void GraphColorRegAllocator::SpillLiveRangeForSpills() { continue; } spillCnt = 0; - const AArch64MD *md = &AArch64CG::kMd[static_cast(insn)->GetMachineOpcode()]; + const AArch64MD *md = &AArch64CG::kMd[static_cast(insn)->GetMachineOpcode()]; uint32 opndNum = insn->GetOperandSize(); for (uint32 i = 0; i < opndNum; ++i) { Operand *opnd = &insn->GetOperand(i); - if (!opnd) { + if (opnd == nullptr) { continue; } if (opnd->IsList()) { // call parameters } else if (opnd->IsMemoryAccessOperand()) { MemOperand *newmemopnd = nullptr; - MemOperand *memopnd = static_cast(opnd); - RegOperand *base = static_cast(memopnd->GetBaseRegister()); + MemOperand *memopnd = static_cast(opnd); + RegOperand *base = static_cast(memopnd->GetBaseRegister()); if (base != nullptr && base->IsVirtualRegister()) { RegOperand *replace = CreateSpillFillCode(*base, *insn, spillCnt); - if (replace) { + if (replace != nullptr) { spillCnt++; - newmemopnd = static_cast(static_cast(opnd)->Clone(*cgFunc->GetMemoryPool())); + newmemopnd = static_cast(static_cast(opnd)->Clone(*cgFunc->GetMemoryPool())); newmemopnd->SetBaseRegister(*replace); insn->SetOperand(i, *newmemopnd); } } - RegOperand *offset = static_cast(memopnd->GetIndexRegister()); + RegOperand *offset = static_cast(memopnd->GetIndexRegister()); if (offset != nullptr && offset->IsVirtualRegister()) { RegOperand *replace = CreateSpillFillCode(*offset, *insn, spillCnt); - if (replace) { + if (replace != nullptr) { spillCnt++; if (newmemopnd == nullptr) { - newmemopnd = static_cast(static_cast(opnd)->Clone(*cgFunc->GetMemoryPool())); + newmemopnd = static_cast(static_cast(opnd)->Clone(*cgFunc->GetMemoryPool())); } newmemopnd->SetIndexRegister(*replace); insn->SetOperand(i, *newmemopnd); @@ -3181,8 +3163,8 @@ void GraphColorRegAllocator::SpillLiveRangeForSpills() { } } else if (opnd->IsRegister()) { bool isdef = static_cast(md->operand[i])->IsRegDef(); - RegOperand *replace = CreateSpillFillCode(*static_cast(opnd), *insn, spillCnt, isdef); - if (replace) { + RegOperand *replace = CreateSpillFillCode(*static_cast(opnd), *insn, spillCnt, isdef); + if (replace != nullptr) { if (isdef == false) { spillCnt++; } @@ -3194,6 +3176,7 @@ void GraphColorRegAllocator::SpillLiveRangeForSpills() { } } + /* Iterate through all instructions and change the vreg to preg. */ void GraphColorRegAllocator::FinalizeRegisters() { if (doMultiPass && hasSpill) { @@ -3284,6 +3267,16 @@ bool GraphColorRegAllocator::AllocateRegisters() { a64CGFunc->AddtoCalleeSaved(RLR); a64CGFunc->NoteFPLRAddedToCalleeSavedList(); +#if DEBUG + int32 cnt = 0; + FOR_ALL_BB(bb, cgFunc) { + FOR_BB_INSNS(insn, bb) { + ++cnt; + } + } + ASSERT(cnt <= cgFunc->GetTotalNumberOfInstructions(), "Incorrect insn count"); +#endif + cgFunc->SetIsAfterRegAlloc(); /* EBO propgation extent the live range and might need to be turned off. */ ComputeBlockOrder(); @@ -3301,6 +3294,7 @@ bool GraphColorRegAllocator::AllocateRegisters() { SplitAndColor(); #ifdef USE_LRA + LocalRegisterAllocator(true); if (doLRA) { LocalRegisterAllocator(true); } diff --git a/src/mapleall/maple_driver/BUILD.gn b/src/mapleall/maple_driver/BUILD.gn index cefe33a40140275b0f160e951a0b19bc067ef4fe..35f4d77129aa97cc69dcc5b475596d6e9518f607 100644 --- a/src/mapleall/maple_driver/BUILD.gn +++ b/src/mapleall/maple_driver/BUILD.gn @@ -35,7 +35,7 @@ include_directories = [ "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/mempool/include", "${THIRD_PARTY_ROOT}/bounds_checking_function/include", - "${THIRD_PARTY_ROOT}/dwarf_h/include", + "${THIRD_PARTY_ROOT}/llvm_modified/include/llvm/BinaryFormat", ] executable("maple") { diff --git a/src/mapleall/maple_ipa/src/inline.cpp b/src/mapleall/maple_ipa/src/inline.cpp index 9714344d2ceb4ca1f2d26598b4c8704d5b6293c3..fd52719f406d443e12d4808e592e1b550ac63576 100644 --- a/src/mapleall/maple_ipa/src/inline.cpp +++ b/src/mapleall/maple_ipa/src/inline.cpp @@ -248,6 +248,18 @@ void MInline::ReplaceSymbols(BaseNode *baseNode, uint32 stIdxOff, if (baseNode == nullptr) { return; } + // IfStmtNode's `numOpnds` and actual operands number are different, so we treat it as a special case + if (baseNode->GetOpCode() == OP_if) { + IfStmtNode *ifStmtNode = static_cast(baseNode); + ReplaceSymbols(baseNode->Opnd(0), stIdxOff, staticOld2New); + if (ifStmtNode->GetThenPart() != nullptr) { + ReplaceSymbols(ifStmtNode->GetThenPart(), stIdxOff, staticOld2New); + } + if (ifStmtNode->GetElsePart() != nullptr) { + ReplaceSymbols(ifStmtNode->GetElsePart(), stIdxOff, staticOld2New); + } + return; + } CallReturnVector *returnVector = baseNode->GetCallReturnVector(); if (baseNode->GetOpCode() == OP_block) { BlockNode *blockNode = static_cast(baseNode); diff --git a/src/mapleall/maple_ir/BUILD.gn b/src/mapleall/maple_ir/BUILD.gn index 58cd39e7df37956cb6f13d8517ffb059e5051606..e82727b14cda85c331b69dc432e059e825069a60 100755 --- a/src/mapleall/maple_ir/BUILD.gn +++ b/src/mapleall/maple_ir/BUILD.gn @@ -22,7 +22,7 @@ include_directories = [ "${MAPLEALL_ROOT}/maple_ipa/include", "${MAPLEALL_ROOT}/maple_me/include", "${MAPLEALL_ROOT}/maple_phase/include", - "${THIRD_PARTY_ROOT}/dwarf_h/include", + "${THIRD_PARTY_ROOT}/llvm_modified/include/llvm/BinaryFormat", ] src_libmplir = [ diff --git a/src/mapleall/maple_ir/src/mir_const.cpp b/src/mapleall/maple_ir/src/mir_const.cpp index f7b4e8974a5c8330ff1f12e11dbca1da93f52c6e..e170cc1082984c336efceb57a8b7b0485ea112ab 100644 --- a/src/mapleall/maple_ir/src/mir_const.cpp +++ b/src/mapleall/maple_ir/src/mir_const.cpp @@ -157,7 +157,11 @@ bool MIRFloatConst::operator==(const MIRConst &rhs) const { if (std::isnan(value.floatValue)) { return std::isnan(floatConst.value.floatValue); } - return (fabs(floatConst.value.floatValue - value.floatValue) <= 1e-6); + if (floatConst.value.floatValue == 0.0 && value.floatValue == 0.0) { + return floatConst.IsNeg() == IsNeg(); + } + // Use bitwise comparison instead of approximate comparison for FP to avoid treating 0.0 and FLT_MIN as equal + return (floatConst.value.intValue == value.intValue); } bool MIRDoubleConst::operator==(const MIRConst &rhs) const { @@ -174,7 +178,11 @@ bool MIRDoubleConst::operator==(const MIRConst &rhs) const { if (std::isnan(value.dValue)) { return std::isnan(floatConst.value.dValue); } - return (fabs(floatConst.value.dValue - value.dValue) <= 1e-15); + if (floatConst.value.dValue == 0.0 && value.dValue == 0.0) { + return floatConst.IsNeg() == IsNeg(); + } + // Use bitwise comparison instead of approximate comparison for FP to avoid treating 0.0 and DBL_MIN as equal + return (floatConst.value.intValue == value.intValue); } bool MIRFloat128Const::operator==(const MIRConst &rhs) const { diff --git a/src/mapleall/maple_me/include/me_fsaa.h b/src/mapleall/maple_me/include/me_fsaa.h index 86334575e570e7d9cc0489c297ad19f83f0af375..6474c78e747a9197be9d27c2851b8f152279f1ca 100644 --- a/src/mapleall/maple_me/include/me_fsaa.h +++ b/src/mapleall/maple_me/include/me_fsaa.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2021] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -21,10 +21,10 @@ #include "ssa_tab.h" namespace maple { - class FSAA { public: - explicit FSAA(MeFunction *f, Dominance *dm): func(f), mirModule(&f->GetMIRModule()), ssaTab(f->GetMeSSATab()), dom(dm) {} + FSAA(MeFunction *f, Dominance *dm) + : func(f), mirModule(&f->GetMIRModule()), ssaTab(f->GetMeSSATab()), dom(dm) {} ~FSAA() {} BB *FindUniquePointerValueDefBB(VersionSt *vst); @@ -48,7 +48,7 @@ class MeDoFSAA : public MeFuncPhase { ~MeDoFSAA() {} - AnalysisResult *Run(MeFunction *ir, MeFuncResultMgr *m, ModuleResultMgr *mrm) override; + AnalysisResult *Run(MeFunction *ir, MeFuncResultMgr *m, ModuleResultMgr*) override; std::string PhaseName() const override { return "fsaa"; } diff --git a/src/mapleall/maple_me/include/me_ir.h b/src/mapleall/maple_me/include/me_ir.h index 10c8ab7cc31f54fd84b1dcd2e6c6aabeb7285dc2..dbc62decfe9ff21c5c04b3c02ea27d90b5e8b287 100644 --- a/src/mapleall/maple_me/include/me_ir.h +++ b/src/mapleall/maple_me/include/me_ir.h @@ -1707,7 +1707,7 @@ class MaydassignMeStmt : public MeStmt { void Dump(const IRMap*) const; VarMeExpr *GetLHS() const { - return chiList.begin()->second->GetLHS(); + return chiList.find(mayDSSym->GetIndex())->second->GetLHS(); } MeExpr *GetRHS() const { @@ -1719,11 +1719,11 @@ class MaydassignMeStmt : public MeStmt { } VarMeExpr *GetVarLHS() const { - return chiList.begin()->second->GetLHS(); + return chiList.find(mayDSSym->GetIndex())->second->GetLHS(); } VarMeExpr *GetVarLHS() { - return chiList.begin()->second->GetLHS(); + return chiList.find(mayDSSym->GetIndex())->second->GetLHS(); } MeExpr *GetLHSRef(bool excludeLocalRefVar); diff --git a/src/mapleall/maple_me/include/ssa_mir_nodes.h b/src/mapleall/maple_me/include/ssa_mir_nodes.h index 6b5af97e954732db7e89d26bacdd9b69bd00b6ae..4d0926b0f6cd46b66fe85d102574c7b853f9cd62 100644 --- a/src/mapleall/maple_me/include/ssa_mir_nodes.h +++ b/src/mapleall/maple_me/include/ssa_mir_nodes.h @@ -131,7 +131,7 @@ class MustDefNode { }; using TypeOfMayUseList = MapleVector; -using TypeOfMayDefList = MapleVector; +using TypeOfMayDefList = MapleList; using TypeOfMustDefList = MapleVector; class AccessSSANodes { public: diff --git a/src/mapleall/maple_me/src/alias_class.cpp b/src/mapleall/maple_me/src/alias_class.cpp index 43ceb930742bf570221b1af466cba0fcc197ac00..bf931d8c77a8053fd1f7fcfc522f1b3984630900 100644 --- a/src/mapleall/maple_me/src/alias_class.cpp +++ b/src/mapleall/maple_me/src/alias_class.cpp @@ -1415,7 +1415,7 @@ void AliasClass::CollectMayDefForIassign(StmtNode &stmt, std::set & // get the next-level-ost that will be assigned to if (mirModule.IsCModule() && baseAinfo.ae->GetOriginalSt().GetTyIdx() != iassignNode.GetTyIdx()) { // in case of type incompatible, set fieldId to zero of the mayDefed virtual-var - lhsAe = FindOrCreateExtraLevAliasElem(*iassignNode.Opnd(0), baseAinfo.ae->GetOriginalSt().GetTyIdx(), 0); + lhsAe = FindOrCreateExtraLevAliasElem(*iassignNode.Opnd(0), iassignNode.GetTyIdx(), 0); } else if (!mirModule.IsCModule() || iassignNode.GetFieldID() == 0 || baseAinfo.ae->GetOriginalSt().GetIndirectLev() == -1 || baseAinfo.ae->GetOriginalSt().GetTyIdx() == iassignNode.GetTyIdx()) { diff --git a/src/mapleall/maple_me/src/dse.cpp b/src/mapleall/maple_me/src/dse.cpp index d945fe4e49f59ddc1f2db7ebc3010d0d4f4e41af..1483aa88b71e0a5676c6df7b97e6aa38865e8a08 100644 --- a/src/mapleall/maple_me/src/dse.cpp +++ b/src/mapleall/maple_me/src/dse.cpp @@ -401,7 +401,7 @@ void DSE::CollectNotNullNode(StmtNode &stmt, BB &bb) { } } else if (i == 0 && stmt.GetOpCode() == OP_iassign) { // A iass stmt, mark and save - BaseNode &base = static_cast(stmt).GetAddrExprBase(); + BaseNode &base = *static_cast(stmt).Opnd(0); stmt2NotNullExpr[&stmt].push_back(&base); MarkSingleUseLive(base); notNullExpr2Stmt[&base].push_back(std::make_pair(&stmt, &bb)); @@ -432,7 +432,7 @@ void DSE::CollectNotNullNode(StmtNode &stmt, BaseNode &node, BB &bb, uint8 nodeT break; } case OP_iread: { - BaseNode &base = static_cast(node).GetAddrExprBase(); + BaseNode &base = *static_cast(node).Opnd(0); if (nodeType != kNodeTypeIvar) { stmt2NotNullExpr[&stmt].push_back(&base); MarkSingleUseLive(base); diff --git a/src/mapleall/maple_me/src/irmap.cpp b/src/mapleall/maple_me/src/irmap.cpp index 930f8657f3636daea077f953257e05cdfecaf6c9..ea5a67319e3a5bd973166e31903ad5c5179bf97a 100644 --- a/src/mapleall/maple_me/src/irmap.cpp +++ b/src/mapleall/maple_me/src/irmap.cpp @@ -555,7 +555,7 @@ static bool IgnoreInnerTypeCvt(PrimType typeA, PrimType typeB, PrimType typeC) { if (IsPrimitiveInteger(typeC)) { return GetPrimTypeSize(typeB) >= GetPrimTypeSize(typeA) || GetPrimTypeSize(typeB) >= GetPrimTypeSize(typeC); } else if (IsPrimitiveFloat(typeC)) { - return GetPrimTypeSize(typeB) >= GetPrimTypeSize(typeA); + return GetPrimTypeSize(typeB) >= GetPrimTypeSize(typeA) && IsSignedInteger(typeB) == IsSignedInteger(typeA); } } else if (IsPrimitiveFloat(typeB)) { if (IsPrimitiveFloat(typeC)) { @@ -594,7 +594,8 @@ MeExpr *IRMap::SimplifyOpMeExpr(OpMeExpr *opmeexpr) { if (maple::GetPrimTypeSize(cvtopnd0->GetPrimType()) >= maple::GetPrimTypeSize(cvtopnd0->GetOpnd(0)->GetPrimType())) { if ((maple::IsPrimitiveInteger(cvtopnd0->GetPrimType()) && - maple::IsPrimitiveInteger(cvtopnd0->GetOpnd(0)->GetPrimType())) || + maple::IsPrimitiveInteger(cvtopnd0->GetOpnd(0)->GetPrimType()) && + !maple::IsPrimitiveFloat(cvtmeexpr->GetPrimType())) || (maple::IsPrimitiveFloat(cvtopnd0->GetPrimType()) && maple::IsPrimitiveFloat(cvtopnd0->GetOpnd(0)->GetPrimType()))) { if (cvtmeexpr->GetPrimType() == cvtopnd0->GetOpndType()) { @@ -606,7 +607,8 @@ MeExpr *IRMap::SimplifyOpMeExpr(OpMeExpr *opmeexpr) { } if (maple::GetPrimTypeSize(cvtopnd0->GetPrimType()) >= maple::GetPrimTypeSize(cvtmeexpr->GetPrimType())) { if ((maple::IsPrimitiveInteger(cvtopnd0->GetPrimType()) && - maple::IsPrimitiveInteger(cvtmeexpr->GetPrimType())) || + maple::IsPrimitiveInteger(cvtmeexpr->GetPrimType()) && + !maple::IsPrimitiveFloat(cvtopnd0->GetOpnd(0)->GetPrimType())) || (maple::IsPrimitiveFloat(cvtopnd0->GetPrimType()) && maple::IsPrimitiveFloat(cvtmeexpr->GetPrimType()))) { return CreateMeExprTypeCvt(cvtmeexpr->GetPrimType(), cvtopnd0->GetOpndType(), *cvtopnd0->GetOpnd(0)); diff --git a/src/mapleall/maple_me/src/me_dse.cpp b/src/mapleall/maple_me/src/me_dse.cpp index 5c7d54c5cbaf72a4f82b7cf2215dffbda7aa81f5..632c5f855e7125f895859a51b20b68d312f97a84 100644 --- a/src/mapleall/maple_me/src/me_dse.cpp +++ b/src/mapleall/maple_me/src/me_dse.cpp @@ -79,7 +79,7 @@ AnalysisResult *MeDoDSE::Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultM if (!MeOption::quiet) { LogInfo::MapleLogger() << " == " << PhaseName() << " invokes [ " << doFSAA.PhaseName() << " ] ==\n"; } - doFSAA.Run(func, m, mrm); + (void)doFSAA.Run(func, m, mrm); } return nullptr; diff --git a/src/mapleall/maple_me/src/me_fsaa.cpp b/src/mapleall/maple_me/src/me_fsaa.cpp index 438ac3f0005b700fbcb5656812654427a479215b..c54bf1d47ff86f64a4b6f867683f62a98b6293a5 100644 --- a/src/mapleall/maple_me/src/me_fsaa.cpp +++ b/src/mapleall/maple_me/src/me_fsaa.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2021] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -32,7 +32,6 @@ using namespace std; namespace maple { - // if the pointer represented by vst is found to have a unique pointer value, // return the BB of the definition BB *FSAA::FindUniquePointerValueDefBB(VersionSt *vst) { @@ -58,7 +57,8 @@ BB *FSAA::FindUniquePointerValueDefBB(VersionSt *vst) { } return nullptr; } else if (rhs->GetOpCode() == OP_iread) { - if (func->GetMirFunc()->IsConstructor() || func->GetMirFunc()->IsStatic() || func->GetMirFunc()->GetFormalDefVec().empty()) { + if (func->GetMirFunc()->IsConstructor() || func->GetMirFunc()->IsStatic() || + func->GetMirFunc()->GetFormalDefVec().empty()) { return nullptr; } // check if rhs is reading a final field thru this @@ -107,7 +107,7 @@ void FSAA::ProcessBB(BB *bb) { hasErase = false; TypeOfMayDefList::iterator it = mayDefNodes->begin(); // due to use of iterator, can do at most 1 erasion each iterator usage - for (; it != mayDefNodes->end(); it++) { + for (; it != mayDefNodes->end(); ++it) { if ((*it).base == nullptr) { } else { BB *aliasedDefBB = (*it).base->GetDefBB(); @@ -120,11 +120,11 @@ void FSAA::ProcessBB(BB *bb) { if (hasErase) { if (DEBUGFUNC(func)) { LogInfo::MapleLogger() << "FSAA deletes mayDef of "; - (*it).GetResult()->Dump(mirModule); + (*it).GetResult()->Dump(); LogInfo::MapleLogger() << " in BB " << bb->GetBBId() << " at:" << endl; itStmt->Dump(); } - mayDefNodes->erase(it); + (void)mayDefNodes->erase(it); needUpdateSSA = true; CHECK_FATAL(!mayDefNodes->empty(), "FSAA::ProcessBB: mayDefNodes of iassign rendered empty"); break; @@ -135,7 +135,7 @@ void FSAA::ProcessBB(BB *bb) { } } -AnalysisResult *MeDoFSAA::Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr *mrm) { +AnalysisResult *MeDoFSAA::Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr*) { SSATab *ssaTab = static_cast(m->GetAnalysisResult(MeFuncPhase_SSATAB, func)); ASSERT(ssaTab != nullptr, "ssaTab phase has problem"); @@ -172,5 +172,4 @@ AnalysisResult *MeDoFSAA::Run(MeFunction *func, MeFuncResultMgr *m, ModuleResult return nullptr; } - } // namespace maple diff --git a/src/mplfe/BUILD.gn b/src/mplfe/BUILD.gn index 35ba2cf82b0a49284de71007492853c40883ce92..bd674d1fd3395a887de98f38d29d999eb6aa25c2 100644 --- a/src/mplfe/BUILD.gn +++ b/src/mplfe/BUILD.gn @@ -212,19 +212,19 @@ static_library("lib_mplfe_dex_input") { # for libdexfile include_dirs_dex = [ - "${AOSP_ROOT}/system/core/include", + "${THIRD_PARTY_ROOT}/aosp_modified/system/core/include", ] include_dirs_libdexfile = [ #for libdexfile -start - "${AOSP_ROOT}/system/core/liblog/include", - "${AOSP_ROOT}/system/core/libutils/include", - "${AOSP_ROOT}/system/core/base/include", - "${AOSP_ROOT}/system/core/libziparchive/include", - "${AOSP_ROOT}/art/libartpalette/include", - "${AOSP_ROOT}/art/libartbase", - "${AOSP_ROOT}/art/libdexfile", - "${AOSP_ROOT}/include", - "${AOSP_ROOT}/libnativehelper/include_jni", + "${THIRD_PARTY_ROOT}/aosp_modified/system/core/liblog/include", + "${THIRD_PARTY_ROOT}/aosp_modified/system/core/libutils/include", + "${THIRD_PARTY_ROOT}/aosp_modified/system/core/base/include", + "${THIRD_PARTY_ROOT}/aosp_modified/system/core/libziparchive/include", + "${THIRD_PARTY_ROOT}/aosp_modified/art/libartpalette/include", + "${THIRD_PARTY_ROOT}/aosp_modified/art/libartbase", + "${THIRD_PARTY_ROOT}/aosp_modified/art/libdexfile", + "${THIRD_PARTY_ROOT}/aosp_modified/include", + "${THIRD_PARTY_ROOT}/aosp_modified/libnativehelper/include_jni", #for libdexfile -end ] @@ -236,12 +236,12 @@ static_library("lib_mplfe_dex_input") { "${MPLFE_ROOT}/dex_input/src/dexfile_libdexfile.cpp", ] deps_libdexfile = [ - "${AOSP_ROOT}/art/libdexfile:libdexfile", - "${AOSP_ROOT}/system/core/libziparchive:libziparchive", - "${AOSP_ROOT}/system/core/base:libbase", + "${THIRD_PARTY_ROOT}/aosp_modified/art/libdexfile:libdexfile", + "${THIRD_PARTY_ROOT}/aosp_modified/system/core/libziparchive:libziparchive", + "${THIRD_PARTY_ROOT}/aosp_modified/system/core/base:libbase", ] lib_dex = [ - "${AOSP_ROOT}/system/core/liblog/liblog.a", + "${THIRD_PARTY_ROOT}/aosp_modified/system/core/liblog/liblog.a", ] deps = deps_libdexfile libs = lib_dex diff --git a/src/mplfe/ast_input/include/ast_expr.h b/src/mplfe/ast_input/include/ast_expr.h index 0f4c4090bc768a5c4e85ca3cf5110a33aa3a0374..5625146c23e67dee63cde459ca88bbad396176af 100644 --- a/src/mplfe/ast_input/include/ast_expr.h +++ b/src/mplfe/ast_input/include/ast_expr.h @@ -25,6 +25,7 @@ class ASTExpr { explicit ASTExpr(ASTOp o) : op(o) {} virtual ~ASTExpr() = default; UniqueFEIRExpr Emit2FEExpr(std::list &stmts) const; + UniqueFEIRExpr ImplicitInitFieldValue(MIRType *type, std::list &stmts) const; virtual MIRType *GetType() { return mirType; @@ -92,6 +93,22 @@ class ASTImplicitCastExpr : public ASTExpr { bool IsNeededCvt(const UniqueFEIRExpr &expr) const; + void SetComplexType(MIRType *type) { + complexType = type; + } + + void SetComplexCastKind(bool flag) { + imageZero = flag; + } + + bool IsBuilinFunc() const { + return isBuilinFunc; + } + + void SetBuilinFunc(bool flag) { + isBuilinFunc = flag; + } + protected: UniqueFEIRExpr Emit2FEExprImpl(std::list &stmts) const override; @@ -100,6 +117,9 @@ class ASTImplicitCastExpr : public ASTExpr { MIRType *src = nullptr; MIRType *dst = nullptr; bool isNeededCvt = false; + MIRType *complexType = nullptr; + bool imageZero = false; + bool isBuilinFunc = false; }; class ASTDeclRefExpr : public ASTExpr { @@ -126,7 +146,7 @@ class ASTUnaryOperatorExpr : public ASTExpr { return uoType = type; } - MIRType *GetUOType() { + const MIRType *GetUOType() const { return uoType; } @@ -410,6 +430,7 @@ class ASTBinaryOperatorExpr : public ASTExpr { protected: UniqueFEIRExpr Emit2FEExprImpl(std::list &stmts) const override; + Opcode opcode; MIRType *retType; ASTExpr *leftExpr = nullptr; @@ -483,9 +504,18 @@ class ASTArraySubscriptExpr : public ASTExpr { return idxExprs; } + void SetMemberExpr(ASTExpr &astExpr) { + memberExpr = &astExpr; + } + + ASTExpr* GetMemberExpr() const { + return memberExpr; + } + private: UniqueFEIRExpr Emit2FEExprImpl(std::list &stmts) const override; ASTExpr *baseExpr; + ASTExpr *memberExpr = nullptr; std::vector idxExprs; }; @@ -522,10 +552,18 @@ class ASTMemberExpr : public ASTExpr { baseExpr = astExpr; } + ASTExpr *GetBaseExpr() const { + return baseExpr; + } + void SetMemberName(std::string name) { memberName = std::move(name); } + std::string GetMemberName() const { + return memberName; + } + void SetMemberType(MIRType *type) { memberType = type; } @@ -534,6 +572,14 @@ class ASTMemberExpr : public ASTExpr { baseType = type; } + MIRType *GetMemberType() const { + return memberType; + } + + MIRType *GetBaseType() const { + return baseType; + } + void SetIsArrow(bool arrow) { isArrow = arrow; } @@ -661,10 +707,13 @@ class ASTCallExpr : public ASTExpr { } private: + using FuncPtrBuiltinFunc = UniqueFEIRExpr (ASTCallExpr::*)(std::list &stmts) const; + static std::map InitFuncPtrMap(); UniqueFEIRExpr Emit2FEExprImpl(std::list &stmts) const override; UniqueFEIRExpr Emit2FEExprCall(std::list &stmts) const; UniqueFEIRExpr Emit2FEExprICall(std::list &stmts) const; + static std::map funcPtrMap; std::vector args; ASTExpr *calleeExpr = nullptr; MIRType *retType = nullptr; diff --git a/src/mplfe/ast_input/include/ast_op.h b/src/mplfe/ast_input/include/ast_op.h index 896373e061517a992285fcfb8abefdbd56d6f6d5..dac9b2ad93f2d2e71477d8535fb1f085280ff479 100644 --- a/src/mplfe/ast_input/include/ast_op.h +++ b/src/mplfe/ast_input/include/ast_op.h @@ -158,7 +158,8 @@ enum ASTStmtOp { kASTStmtStmtExpr, kASTStmtCStyleCastExpr, kASTStmtCallExpr, - kASTStmtAtomicExpr + kASTStmtAtomicExpr, + kASTStmtGCCAsmStmt, }; } // namespace maple #endif // MPLFE_AST_INPUT_INCLUDE_AST_OP_H diff --git a/src/mplfe/ast_input/include/ast_parser.h b/src/mplfe/ast_input/include/ast_parser.h index 3e85331e31ec6dbfc1f2224043156b6775f6a6ed..cabb972b9610f32036022727100437e24c73bbcc 100644 --- a/src/mplfe/ast_input/include/ast_parser.h +++ b/src/mplfe/ast_input/include/ast_parser.h @@ -24,20 +24,23 @@ namespace maple { class ASTInput; class ASTParser { public: - ASTParser(MapleAllocator &allocatorIn, uint32 fileIdxIn, const std::string &fileNameIn) + ASTParser(MapleAllocator &allocatorIn, uint32 fileIdxIn, const std::string &fileNameIn, + MapleList &astStructsIn, MapleList &astFuncsIn, MapleList &astVarsIn) : fileIdx(fileIdxIn), fileName(fileNameIn), globalVarDecles(allocatorIn.Adapter()), funcDecles(allocatorIn.Adapter()), recordDecles(allocatorIn.Adapter()), - globalEnumDecles(allocatorIn.Adapter()) {} + globalEnumDecles(allocatorIn.Adapter()), globalTypeDefDecles(allocatorIn.Adapter()), + astStructs(astStructsIn), astFuncs(astFuncsIn), astVars(astVarsIn) {} virtual ~ASTParser() = default; bool OpenFile(); bool Verify(); bool PreProcessAST(); - bool RetrieveStructs(MapleAllocator &allocator, MapleList &structs); - bool RetrieveFuncs(MapleAllocator &allocator, MapleList &funcs); - bool RetrieveGlobalVars(MapleAllocator &allocator, MapleList &vars); + bool RetrieveStructs(MapleAllocator &allocator); + bool RetrieveFuncs(MapleAllocator &allocator); + bool RetrieveGlobalVars(MapleAllocator &allocator); - bool ProcessGlobalEnums(MapleAllocator &allocator, MapleList &vars); + bool ProcessGlobalEnums(MapleAllocator &allocator); + bool ProcessGlobalTypeDef(MapleAllocator &allocator); const std::string &GetSourceFileName() const; const uint32 GetFileIdx() const; @@ -76,6 +79,7 @@ class ASTParser { ASTStmt *PROCESS_STMT(CStyleCastExpr); ASTStmt *PROCESS_STMT(DeclStmt); ASTStmt *PROCESS_STMT(AtomicExpr); + ASTStmt *PROCESS_STMT(GCCAsmStmt); bool HasDefault(const clang::Stmt &stmt); // ProcessExpr @@ -126,13 +130,14 @@ class ASTParser { ASTExpr *PROCESS_EXPR(DependentScopeDeclRefExpr); ASTExpr *PROCESS_EXPR(AtomicExpr); -ASTDecl *ProcessDecl(MapleAllocator &allocator, const clang::Decl &decl); + ASTDecl *ProcessDecl(MapleAllocator &allocator, const clang::Decl &decl); #define PROCESS_DECL(CLASS) ProcessDecl##CLASS##Decl(MapleAllocator &allocator, const clang::CLASS##Decl&) ASTDecl *PROCESS_DECL(Field); ASTDecl *PROCESS_DECL(Function); ASTDecl *PROCESS_DECL(Record); ASTDecl *PROCESS_DECL(Var); ASTDecl *PROCESS_DECL(Enum); + ASTDecl *PROCESS_DECL(Typedef); private: void TraverseDecl(const clang::Decl *decl, std::function const &functor); @@ -147,6 +152,12 @@ ASTDecl *ProcessDecl(MapleAllocator &allocator, const clang::Decl &decl); MapleList funcDecles; MapleList recordDecles; MapleList globalEnumDecles; + MapleList globalTypeDefDecles; + + MapleList &astStructs; + MapleList &astFuncs; + MapleList &astVars; + ASTInput *astIn = nullptr; uint32 srcFileNum = 2; // src files start from 2, 1 is mpl file diff --git a/src/mplfe/ast_input/include/ast_stmt.h b/src/mplfe/ast_input/include/ast_stmt.h index 6798815f5106a9e19b46f37b5271ba65b801dc92..bc52466432c38e7611a6ca53fac89f8672132ff6 100644 --- a/src/mplfe/ast_input/include/ast_stmt.h +++ b/src/mplfe/ast_input/include/ast_stmt.h @@ -467,9 +467,15 @@ class ASTCallExprStmt : public ASTStmt { ~ASTCallExprStmt() override = default; private: + using FuncPtrBuiltinFunc = std::list (ASTCallExprStmt::*)() const; + static std::map InitFuncPtrMap(); std::list Emit2FEStmtImpl() const override; std::list Emit2FEStmtCall() const; std::list Emit2FEStmtICall() const; + std::list ProcessBuiltinVaStart() const; + std::list ProcessBuiltinVaEnd() const; + + static std::map funcPtrMap; }; class ASTAtomicExprStmt : public ASTStmt { @@ -480,5 +486,52 @@ class ASTAtomicExprStmt : public ASTStmt { private: std::list Emit2FEStmtImpl() const override; }; + +class ASTGCCAsmStmt : public ASTStmt { + public: + ASTGCCAsmStmt() : ASTStmt(kASTStmtGCCAsmStmt) {} + ~ASTGCCAsmStmt() override = default; + + void SetAsmStmts(const std::string &asmStr) { + asmStmts = asmStr; + } + + void SetOutputsNum(uint32 num) { + numOfOutputs = num; + } + + void SetInputsNum(uint32 num) { + numOfInputs = num; + } + + void SetClobbersNum(uint32 num) { + numOfClobbers = num; + } + + void InsertOutput(std::pair &&output) { + outputs.emplace_back(output); + } + + void InsertInput(std::pair &&input) { + inputs.emplace_back(input); + } + + void InsertClobber(std::string &&clobber) { + clobbers.emplace_back(clobber); + } + + private: + std::list Emit2FEStmtImpl() const override; + // Retrieving and parsing asm info in following order: + // asm instructions, outputs [output name, constrain, expr], inputs [input name, constrain, expr], clobbers + std::string asmStmts; + uint32 numOfOutputs = 0; + std::vector> outputs; + uint32 numOfInputs = 0; + std::vector> inputs; + uint32 numOfClobbers = 0; + std::vector clobbers; + // Not parsing asm label here, asm label info is enclosed in `Decl attr` +}; } // namespace maple #endif // MPLFE_AST_INPUT_INCLUDE_AST_STMT_H diff --git a/src/mplfe/ast_input/lib/ast_interface.cpp b/src/mplfe/ast_input/lib/ast_interface.cpp index 3e743b1447ea720ad16c3982e7baa50fe475546c..251ec9a58edd9a5ef1bfca8675c5f2fae45edbeb 100644 --- a/src/mplfe/ast_input/lib/ast_interface.cpp +++ b/src/mplfe/ast_input/lib/ast_interface.cpp @@ -287,5 +287,10 @@ void LibAstFile::EmitTypeName(const clang::RecordType &recoType, std::stringstre uint32_t id = recoType.getDecl()->getLocation().getRawEncoding(); ss << GetOrCreateMappedUnnamedName(id); } + + if (!recoDecl->isDefinedOutsideFunctionOrMethod()) { + Pos p = GetDeclPosInfo(*recoDecl); + ss << "_" << p.first << "_" << p.second; + } } } // namespace maple diff --git a/src/mplfe/ast_input/lib/ast_interface.h b/src/mplfe/ast_input/lib/ast_interface.h index baf79b0b7efcf9edf74b18b21edecf29e53fd2a8..ff8a4aeb1397432b8a7872cc04cf0b9f24451569 100644 --- a/src/mplfe/ast_input/lib/ast_interface.h +++ b/src/mplfe/ast_input/lib/ast_interface.h @@ -32,7 +32,7 @@ enum AccessKind { class LibAstFile { public: - LibAstFile() = default; + explicit LibAstFile(MapleList &recordDeclesIn) : recordDecles(recordDeclesIn) {} ~LibAstFile() = default; bool Open(const std::string &fileName, @@ -80,9 +80,12 @@ class LibAstFile { private: using RecordDeclMap = std::map; RecordDeclMap recordDeclMap; + std::set recordDeclSet; std::map unnamedSymbolMap; MIRModule *module; + MapleList &recordDecles; + clang::ASTContext *astContext = nullptr; clang::TranslationUnitDecl *astUnitDecl = nullptr; clang::MangleContext *mangleContext = nullptr; diff --git a/src/mplfe/ast_input/lib/ast_type.cpp b/src/mplfe/ast_input/lib/ast_type.cpp index d1274f42f4ff0b84043dc970d3058349156f6536..ff0d0e1583239cb9356dd966319532696c454e6a 100644 --- a/src/mplfe/ast_input/lib/ast_type.cpp +++ b/src/mplfe/ast_input/lib/ast_type.cpp @@ -128,6 +128,9 @@ MIRType *LibAstFile::CvtOtherType(const clang::QualType srcType) { MIRType *LibAstFile::CvtRecordType(const clang::QualType srcType) { const auto *recordType = llvm::cast(srcType); clang::RecordDecl *recordDecl = recordType->getDecl(); + if (!recordDecl->isLambda() && recordDecl->isImplicit() && recordDeclSet.emplace(recordDecl).second == true) { + recordDecles.emplace_back(recordDecl); + } MIRStructType *type = nullptr; std::stringstream ss; EmitTypeName(srcType, ss); diff --git a/src/mplfe/ast_input/src/ast_decl.cpp b/src/mplfe/ast_input/src/ast_decl.cpp index 3c2b347ec7144683544ba2a4631b529d05147c4c..c0efad941454df188cf178bd4bdc9e2cfa706dcc 100644 --- a/src/mplfe/ast_input/src/ast_decl.cpp +++ b/src/mplfe/ast_input/src/ast_decl.cpp @@ -52,21 +52,23 @@ std::unique_ptr ASTVar::Translate2FEIRVar() { } void ASTVar::GenerateInitStmtImpl(std::list &stmts) { - if (GetInitExpr() != nullptr) { - UniqueFEIRVar feirVar = Translate2FEIRVar(); - UniqueFEIRExpr expr = GetInitExpr()->Emit2FEExpr(stmts); - if (expr != nullptr) { // InitListExpr array not emit here - PrimType srcPrimType = expr->GetPrimType(); - UniqueFEIRStmt stmt; - if (srcPrimType != feirVar->GetType()->GetPrimType() && srcPrimType != PTY_agg && srcPrimType != PTY_void) { - UniqueFEIRExpr cvtExpr = FEIRBuilder::CreateExprCvtPrim(std::move(expr), feirVar->GetType()->GetPrimType()); - stmt = FEIRBuilder::CreateStmtDAssign(std::move(feirVar), std::move(cvtExpr)); - } else { - stmt = FEIRBuilder::CreateStmtDAssign(std::move(feirVar), std::move(expr)); - } - stmts.emplace_back(std::move(stmt)); - } + if (GetInitExpr() == nullptr) { + return; + } + UniqueFEIRVar feirVar = Translate2FEIRVar(); + UniqueFEIRExpr expr = GetInitExpr()->Emit2FEExpr(stmts); + if (expr == nullptr) { + return; + } + PrimType srcPrimType = expr->GetPrimType(); + UniqueFEIRStmt stmt; + if (srcPrimType != feirVar->GetType()->GetPrimType() && srcPrimType != PTY_agg && srcPrimType != PTY_void) { + UniqueFEIRExpr cvtExpr = FEIRBuilder::CreateExprCvtPrim(std::move(expr), feirVar->GetType()->GetPrimType()); + stmt = FEIRBuilder::CreateStmtDAssign(std::move(feirVar), std::move(cvtExpr)); + } else { + stmt = FEIRBuilder::CreateStmtDAssign(std::move(feirVar), std::move(expr)); } + stmts.emplace_back(std::move(stmt)); } // ---------- ASTLocalEnumDecl ---------- diff --git a/src/mplfe/ast_input/src/ast_expr.cpp b/src/mplfe/ast_input/src/ast_expr.cpp index 92c80f9206038d5a970c5abbd26c3ef51f37953c..90e706323dfbda6bb3ee3c6faa8fdddc1165aff9 100644 --- a/src/mplfe/ast_input/src/ast_expr.cpp +++ b/src/mplfe/ast_input/src/ast_expr.cpp @@ -29,6 +29,51 @@ UniqueFEIRExpr ASTExpr::Emit2FEExpr(std::list &stmts) const { return Emit2FEExprImpl(stmts); } +UniqueFEIRExpr ASTExpr::ImplicitInitFieldValue(MIRType *type, std::list &stmts) const { + UniqueFEIRExpr implicitInitFieldExpr; + MIRTypeKind noInitExprKind = type->GetKind(); + if (noInitExprKind == kTypeStruct || noInitExprKind == kTypeUnion) { + auto *structType = static_cast(type); + std::string tmpName = FEUtils::GetSequentialName("implicitInitStruct_"); + UniqueFEIRVar tmpVar = FEIRBuilder::CreateVarNameForC(tmpName, *type); + for (size_t i = 0; i < structType->GetFieldsSize(); ++i) { + uint32 fieldID = 0; + FEManager::GetMIRBuilder().TraverseToNamedField(*structType, structType->GetElemStrIdx(i), fieldID); + MIRType *fieldType = structType->GetFieldType(fieldID); + UniqueFEIRExpr fieldExpr = ImplicitInitFieldValue(fieldType, stmts); + UniqueFEIRStmt fieldStmt = std::make_unique(tmpVar->Clone(), std::move(fieldExpr), fieldID); + stmts.emplace_back(std::move(fieldStmt)); + } + implicitInitFieldExpr = FEIRBuilder::CreateExprDRead(std::move(tmpVar)); + } else if (noInitExprKind == kTypeArray) { + auto *arrayType = static_cast(type); + size_t elemSize = arrayType->GetElemType()->GetSize(); + CHECK_FATAL(elemSize != 0, "elemSize is 0"); + size_t numElems = arrayType->GetSize() / elemSize; + UniqueFEIRType typeNative = FEIRTypeHelper::CreateTypeNative(*type); + std::string tmpName = FEUtils::GetSequentialName("implicitInitArray_"); + UniqueFEIRVar tmpVar = FEIRBuilder::CreateVarNameForC(tmpName, *type); + UniqueFEIRExpr arrayExpr = FEIRBuilder::CreateExprDRead(tmpVar->Clone()); + for (size_t i = 0; i < numElems; ++i) { + UniqueFEIRExpr exprIndex = FEIRBuilder::CreateExprConstI32(i); + MIRType *fieldType = arrayType->GetElemType(); + UniqueFEIRExpr exprElem = ImplicitInitFieldValue(fieldType, stmts); + UniqueFEIRType typeNativeTmp = typeNative->Clone(); + UniqueFEIRExpr arrayExprTmp = arrayExpr->Clone(); + auto stmt = FEIRBuilder::CreateStmtArrayStoreOneStmtForC(std::move(exprElem), std::move(arrayExprTmp), + std::move(exprIndex), std::move(typeNativeTmp)); + stmts.emplace_back(std::move(stmt)); + } + implicitInitFieldExpr = FEIRBuilder::CreateExprDRead(std::move(tmpVar)); + } else if (noInitExprKind == kTypePointer) { + implicitInitFieldExpr = std::make_unique(static_cast(0), PTY_ptr); + } else { + CHECK_FATAL(noInitExprKind == kTypeScalar, "noInitExprKind isn't kTypeScalar"); + implicitInitFieldExpr = FEIRBuilder::CreateExprConstAnyScalar(type->GetPrimType(), 0); + } + return implicitInitFieldExpr; +} + // ---------- ASTDeclRefExpr --------- UniqueFEIRExpr ASTDeclRefExpr::Emit2FEExprImpl(std::list &stmts) const { MIRType *mirType = refedDecl->GetTypeDesc().front(); @@ -45,6 +90,13 @@ UniqueFEIRExpr ASTDeclRefExpr::Emit2FEExprImpl(std::list &stmts) } // ---------- ASTCallExpr ---------- +std::map ASTCallExpr::funcPtrMap = ASTCallExpr::InitFuncPtrMap(); + +std::map ASTCallExpr::InitFuncPtrMap() { + std::map ans; + return ans; +} + UniqueFEIRExpr ASTCallExpr::Emit2FEExprCall(std::list &stmts) const { // callassigned &funcName StructElemNameIdx *nameIdx = FEManager::GetManager().GetStructElemMempool()->New(funcName); @@ -95,6 +147,12 @@ UniqueFEIRExpr ASTCallExpr::Emit2FEExprImpl(std::list &stmts) co if (isIcall) { return Emit2FEExprICall(stmts); } else { + if (calleeExpr != nullptr && calleeExpr->GetASTOp() == kASTOpCast && + static_cast(calleeExpr)->IsBuilinFunc()) { + auto ptrFunc = funcPtrMap.find(funcName); + CHECK_FATAL(ptrFunc != funcPtrMap.end(), "unsupported BuiltinFunc: %s", funcName.c_str()); + return (this->*(ptrFunc->second))(stmts); + } return Emit2FEExprCall(stmts); } } @@ -103,19 +161,61 @@ UniqueFEIRExpr ASTCallExpr::Emit2FEExprImpl(std::list &stmts) co UniqueFEIRExpr ASTImplicitCastExpr::Emit2FEExprImpl(std::list &stmts) const { const ASTExpr *childExpr = child; CHECK_FATAL(childExpr != nullptr, "childExpr is nullptr"); - UniqueFEIRExpr feirImplicitCastExpr = childExpr->Emit2FEExpr(stmts); - if (IsNeededCvt(feirImplicitCastExpr)) { - return FEIRBuilder::CreateExprCvtPrim(std::move(feirImplicitCastExpr), dst->GetPrimType()); + UniqueFEIRExpr subExpr = childExpr->Emit2FEExpr(stmts); + if (complexType == nullptr) { + if (IsNeededCvt(subExpr)) { + return FEIRBuilder::CreateExprCvtPrim(std::move(subExpr), dst->GetPrimType()); + } + } else { + std::string tmpName = FEUtils::GetSequentialName("Complex_"); + UniqueFEIRVar tmpVar = FEIRBuilder::CreateVarNameForC(tmpName, *complexType); + UniqueFEIRExpr dreadAgg; + if (imageZero) { + UniqueFEIRStmt realStmtNode = std::make_unique(tmpVar->Clone(), + subExpr->Clone(), kComplexRealID); + stmts.emplace_back(std::move(realStmtNode)); + UniqueFEIRExpr imagExpr = FEIRBuilder::CreateExprConstAnyScalar(src->GetPrimType(), 0); + UniqueFEIRStmt imagStmtNode = std::make_unique(tmpVar->Clone(), + imagExpr->Clone(), kComplexImagID); + stmts.emplace_back(std::move(imagStmtNode)); + dreadAgg = FEIRBuilder::CreateExprDRead(std::move(tmpVar)); + static_cast(dreadAgg.get())->SetFieldType(src); + } else { + UniqueFEIRExpr realExpr; + UniqueFEIRExpr imagExpr; + FEIRNodeKind subNodeKind = subExpr->GetKind(); + UniqueFEIRExpr cloneSubExpr = subExpr->Clone(); + if (subNodeKind == kExprIRead) { + static_cast(subExpr.get())->SetFieldID(kComplexRealID); + static_cast(cloneSubExpr.get())->SetFieldID(kComplexImagID); + } else if (subNodeKind == kExprDRead) { + static_cast(subExpr.get())->SetFieldID(kComplexRealID); + static_cast(cloneSubExpr.get())->SetFieldID(kComplexImagID); + } + if (IsPrimitiveFloat(src->GetPrimType()) && IsPrimitiveInteger(dst->GetPrimType())) { + realExpr = FEIRBuilder::CreateExprCvtPrim(OP_trunc, subExpr->Clone(), dst->GetPrimType()); + imagExpr = FEIRBuilder::CreateExprCvtPrim(OP_trunc, cloneSubExpr->Clone(), dst->GetPrimType()); + } else { + realExpr = FEIRBuilder::CreateExprCvtPrim(OP_trunc, subExpr->Clone(), dst->GetPrimType()); + imagExpr = FEIRBuilder::CreateExprCvtPrim(OP_trunc, cloneSubExpr->Clone(), dst->GetPrimType()); + } + UniqueFEIRStmt realStmt = std::make_unique(tmpVar->Clone(), std::move(realExpr), kComplexRealID); + stmts.emplace_back(std::move(realStmt)); + UniqueFEIRStmt imagStmt = std::make_unique(tmpVar->Clone(), std::move(imagExpr), kComplexImagID); + stmts.emplace_back(std::move(imagStmt)); + dreadAgg = FEIRBuilder::CreateExprDRead(std::move(tmpVar)); + } + return dreadAgg; } - return feirImplicitCastExpr; + return subExpr; } bool ASTImplicitCastExpr::IsNeededCvt(const UniqueFEIRExpr &expr) const { - if (expr == nullptr || dst == nullptr) { + if (!isNeededCvt || expr == nullptr || dst == nullptr) { return false; } PrimType srcPrimType = expr->GetPrimType(); - return isNeededCvt && srcPrimType != dst->GetPrimType() && srcPrimType != PTY_agg && srcPrimType != PTY_void; + return srcPrimType != dst->GetPrimType() && srcPrimType != PTY_agg && srcPrimType != PTY_void; } // ---------- ASTUnaryOperatorExpr ---------- @@ -131,8 +231,12 @@ UniqueFEIRExpr ASTUOMinusExpr::Emit2FEExprImpl(std::list &stmts) ASTExpr *childExpr = expr; CHECK_FATAL(childExpr != nullptr, "childExpr is nullptr"); UniqueFEIRExpr childFEIRExpr = childExpr->Emit2FEExpr(stmts); - UniqueFEIRExpr minusExpr = FEIRBuilder::CreateExprMathUnary(OP_neg, std::move(childFEIRExpr)); - return minusExpr; + PrimType dstType = uoType->GetPrimType(); + if (childFEIRExpr->GetPrimType() != dstType) { + UniqueFEIRExpr minusExpr = FEIRBuilder::CreateExprMathUnary(OP_neg, std::move(childFEIRExpr)); + return FEIRBuilder::CreateExprCvtPrim(std::move(minusExpr), dstType); + } + return FEIRBuilder::CreateExprMathUnary(OP_neg, std::move(childFEIRExpr)); } UniqueFEIRExpr ASTUOPlusExpr::Emit2FEExprImpl(std::list &stmts) const { @@ -146,16 +250,24 @@ UniqueFEIRExpr ASTUONotExpr::Emit2FEExprImpl(std::list &stmts) c ASTExpr *childExpr = expr; CHECK_FATAL(childExpr != nullptr, "childExpr is nullptr"); UniqueFEIRExpr childFEIRExpr = childExpr->Emit2FEExpr(stmts); - UniqueFEIRExpr notExpr = FEIRBuilder::CreateExprMathUnary(OP_bnot, std::move(childFEIRExpr)); - return notExpr; + PrimType dstType = uoType->GetPrimType(); + if (childFEIRExpr->GetPrimType() != dstType) { + UniqueFEIRExpr notExpr = FEIRBuilder::CreateExprMathUnary(OP_bnot, std::move(childFEIRExpr)); + return FEIRBuilder::CreateExprCvtPrim(std::move(notExpr), dstType); + } + return FEIRBuilder::CreateExprMathUnary(OP_bnot, std::move(childFEIRExpr)); } UniqueFEIRExpr ASTUOLNotExpr::Emit2FEExprImpl(std::list &stmts) const { ASTExpr *childExpr = expr; CHECK_FATAL(childExpr != nullptr, "childExpr is nullptr"); UniqueFEIRExpr childFEIRExpr = childExpr->Emit2FEExpr(stmts); - UniqueFEIRExpr lnotExpr = FEIRBuilder::CreateExprMathUnary(OP_lnot, std::move(childFEIRExpr)); - return lnotExpr; + PrimType dstType = uoType->GetPrimType(); + if (childFEIRExpr->GetPrimType() != dstType) { + UniqueFEIRExpr lnotExpr = FEIRBuilder::CreateExprMathUnary(OP_lnot, std::move(childFEIRExpr)); + return FEIRBuilder::CreateExprCvtPrim(std::move(lnotExpr), dstType); + } + return FEIRBuilder::CreateExprMathUnary(OP_lnot, std::move(childFEIRExpr)); } UniqueFEIRExpr ASTUOPostIncExpr::Emit2FEExprImpl(std::list &stmts) const { @@ -412,7 +524,7 @@ void ASTBinaryConditionalOperator::SetFalseExpr(ASTExpr *expr) { // ---------- ASTNoInitExpr ---------- UniqueFEIRExpr ASTNoInitExpr::Emit2FEExprImpl(std::list &stmts) const { - return FEIRBuilder::CreateExprConstAnyScalar(noInitType->GetPrimType(), 0); + return ImplicitInitFieldValue(noInitType, stmts); } void ASTNoInitExpr::SetNoInitType(MIRType *type) { @@ -541,8 +653,7 @@ void ASTInitListExpr::SetInitListType(MIRType *type) { } UniqueFEIRExpr ASTImplicitValueInitExpr::Emit2FEExprImpl(std::list &stmts) const { - // Other MIRTypeKind should enable - return FEIRBuilder::CreateExprConstAnyScalar(type->GetPrimType(), 0); + return ImplicitInitFieldValue(type, stmts); } UniqueFEIRExpr ASTStringLiteral::Emit2FEExprImpl(std::list &stmts) const { @@ -559,7 +670,15 @@ UniqueFEIRExpr ASTArraySubscriptExpr::Emit2FEExprImpl(std::list UniqueFEIRExpr feirExpr = expr->Emit2FEExpr(stmts); indexExprs.emplace_front(std::move(feirExpr)); } - return FEIRBuilder::CreateExprArrayStoreForC(std::move(baseFEExpr), indexExprs, std::move(typeNative)); + if (memberExpr != nullptr) { + auto memExpr = static_cast(memberExpr)->Emit2FEExpr(stmts); + auto memType = FEIRTypeHelper::CreateTypeNative(*static_cast(memberExpr)->GetMemberType()); + UniqueFEIRType typeArrayNative = FEIRTypeHelper::CreateTypeNative(*baseExpr->GetType()); + return FEIRBuilder::CreateExprArrayStoreForC(std::move(memExpr), indexExprs, std::move(memType), + std::move(baseFEExpr), std::move(typeNative)); + } else { + return FEIRBuilder::CreateExprArrayStoreForC(std::move(baseFEExpr), indexExprs, std::move(typeNative)); + } } UniqueFEIRExpr ASTExprUnaryExprOrTypeTraitExpr::Emit2FEExprImpl(std::list &stmts) const { @@ -636,11 +755,25 @@ UniqueFEIRExpr ASTAssignExpr::ProcessAssign(std::list &stmts, Un FEIRType &typeArray = arrayStoreForC->GetTypeArray(); UniqueFEIRExpr uExprArray = exprArray.Clone(); UniqueFEIRType uTypeArray = typeArray.Clone(); - UniqueFEIRStmt stmt = std::make_unique(std::move(rightFEExpr), - std::move(uExprArray), - indexsExpr, - std::move(uTypeArray)); - stmts.emplace_back(std::move(stmt)); + if (arrayStoreForC->IsMember()) { + FEIRExpr &exprStruct = arrayStoreForC->GetExprStruct(); + FEIRType &typeStruct = arrayStoreForC->GetTypeSruct(); + UniqueFEIRExpr uExprStruct = exprStruct.Clone(); + UniqueFEIRType uTypeStruct = typeStruct.Clone(); + UniqueFEIRStmt stmt = std::make_unique(std::move(rightFEExpr), + std::move(uExprArray), + indexsExpr, + std::move(uTypeArray), + std::move(uExprStruct), + std::move(uTypeStruct)); + stmts.emplace_back(std::move(stmt)); + } else { + UniqueFEIRStmt stmt = std::make_unique(std::move(rightFEExpr), + std::move(uExprArray), + indexsExpr, + std::move(uTypeArray)); + stmts.emplace_back(std::move(stmt)); + } } return nullptr; } @@ -765,13 +898,17 @@ UniqueFEIRExpr ASTImaginaryLiteral::Emit2FEExprImpl(std::list &s UniqueFEIRExpr ASTCompoundAssignOperatorExpr::Emit2FEExprImpl(std::list &stmts) const { UniqueFEIRExpr leftFEExpr = leftExpr->Emit2FEExpr(stmts); UniqueFEIRExpr rightFEExpr = rightExpr->Emit2FEExpr(stmts); + PrimType leftPrimType = leftFEExpr->GetPrimType(); + PrimType rightPrimType = rightFEExpr->GetPrimType(); + if (rightPrimType != leftPrimType) { + rightFEExpr = FEIRBuilder::CreateExprCvtPrim(std::move(rightFEExpr), leftPrimType); + } rightFEExpr = FEIRBuilder::CreateExprBinary(opForCompoundAssign, leftFEExpr->Clone(), std::move(rightFEExpr)); return ProcessAssign(stmts, std::move(leftFEExpr), std::move(rightFEExpr)); } // ---------- ASTVAArgExpr ---------- UniqueFEIRExpr ASTVAArgExpr::Emit2FEExprImpl(std::list &stmts) const { - CHECK_FATAL(false, "NIY"); return nullptr; } diff --git a/src/mplfe/ast_input/src/ast_input.cpp b/src/mplfe/ast_input/src/ast_input.cpp index f2303dbb2d2e7352d950c9b5ba0c3ee34f6701cd..4ee5fbf09bfc23b54a987bb148fd40d6d8fc6c4a 100644 --- a/src/mplfe/ast_input/src/ast_input.cpp +++ b/src/mplfe/ast_input/src/ast_input.cpp @@ -21,15 +21,18 @@ ASTInput::ASTInput(MIRModule &moduleIn, MapleAllocator &allocatorIn) astStructs(allocatorIn.Adapter()), astFuncs(allocatorIn.Adapter()), astVars(allocatorIn.Adapter()) {} bool ASTInput::ReadASTFile(MapleAllocator &allocatorIn, uint32 index, const std::string &fileName) { - ASTParser *astParser = allocator.GetMemPool()->New(allocator, index, fileName); + ASTParser *astParser = + allocator.GetMemPool()->New(allocator, index, fileName, astStructs, astFuncs, astVars); astParser->SetAstIn(this); TRY_DO(astParser->OpenFile()); TRY_DO(astParser->Verify()); TRY_DO(astParser->PreProcessAST()); - TRY_DO(astParser->ProcessGlobalEnums(allocatorIn, astVars)); - TRY_DO(astParser->RetrieveStructs(allocatorIn, astStructs)); - TRY_DO(astParser->RetrieveFuncs(allocatorIn, astFuncs)); - TRY_DO(astParser->RetrieveGlobalVars(allocatorIn, astVars)); + TRY_DO(astParser->ProcessGlobalEnums(allocatorIn)); + // Some implicit record decl would be retrieved in func body at use, + // so we put `RetrieveFuncs` before `RetrieveStructs` + TRY_DO(astParser->RetrieveFuncs(allocatorIn)); + TRY_DO(astParser->RetrieveStructs(allocatorIn)); + TRY_DO(astParser->RetrieveGlobalVars(allocatorIn)); astParserMap.emplace(fileName, astParser); return true; } diff --git a/src/mplfe/ast_input/src/ast_parser.cpp b/src/mplfe/ast_input/src/ast_parser.cpp index 0cc3e97e23c1e2e9747eaf83f1b617ee71546a50..16ee1dad626c5452cf57e64744b12e4f821728be 100644 --- a/src/mplfe/ast_input/src/ast_parser.cpp +++ b/src/mplfe/ast_input/src/ast_parser.cpp @@ -26,7 +26,7 @@ namespace maple { bool ASTParser::OpenFile() { - astFile = std::make_unique(); + astFile = std::make_unique(recordDecles); bool res = astFile->Open(fileName, 0, 0); if (!res) { return false; @@ -122,8 +122,11 @@ ASTStmt *ASTParser::ProcessStmt(MapleAllocator &allocator, const clang::Stmt &st STMT_CASE(DeclStmt); STMT_CASE(NullStmt); STMT_CASE(AtomicExpr); - default: + STMT_CASE(GCCAsmStmt); + default: { + CHECK_FATAL(false, "ASTStmt: %d NIY", stmt.getStmtClass()); return nullptr; + } } } @@ -279,9 +282,6 @@ ASTStmt *ASTParser::ProcessStmtReturnStmt(MapleAllocator &allocator, const clang ASTReturnStmt *astStmt = ASTDeclsBuilder::ASTStmtBuilder(allocator); CHECK_FATAL(astStmt != nullptr, "astStmt is nullptr"); ASTExpr *astExpr = ProcessExpr(allocator, retStmt.getRetValue()); - if (astExpr == nullptr) { - return nullptr; - } astStmt->SetASTExpr(astExpr); return astStmt; } @@ -372,6 +372,30 @@ ASTStmt *ASTParser::ProcessStmtGotoStmt(MapleAllocator &allocator, const clang:: return astStmt; } +ASTStmt *ASTParser::ProcessStmtGCCAsmStmt(MapleAllocator &allocator, const clang::GCCAsmStmt &asmStmt) { + ASTGCCAsmStmt *astStmt = ASTDeclsBuilder::ASTStmtBuilder(allocator); + CHECK_FATAL(astStmt != nullptr, "astStmt is nullptr"); + astStmt->SetAsmStmts(asmStmt.generateAsmString(*(astFile->GetAstContext()))); + unsigned numOfOutputs = asmStmt.getNumOutputs(); + astStmt->SetOutputsNum(static_cast(numOfOutputs)); + for (unsigned i = 0; i < numOfOutputs; ++i) { + astStmt->InsertOutput(std::make_pair(asmStmt.getOutputName(i).str(), asmStmt.getOutputConstraint(i).str())); + astStmt->SetASTExpr(ProcessExpr(allocator, asmStmt.getOutputExpr(i))); + } + unsigned numOfInputs = asmStmt.getNumInputs(); + astStmt->SetInputsNum(static_cast(numOfInputs)); + for (unsigned i = 0; i < numOfInputs; ++i) { + astStmt->InsertInput(std::make_pair(asmStmt.getInputName(i).str(), asmStmt.getInputConstraint(i).str())); + astStmt->SetASTExpr(ProcessExpr(allocator, asmStmt.getInputExpr(i))); + } + unsigned numOfClobbers = asmStmt.getNumClobbers(); + astStmt->SetClobbersNum(static_cast(numOfClobbers)); + for (unsigned i = 0; i < numOfClobbers; ++i) { + astStmt->InsertClobber(asmStmt.getClobber(i).str()); + } + return astStmt; +} + bool ASTParser::HasDefault(const clang::Stmt &stmt) { if (llvm::isa(stmt)) { return true; @@ -494,7 +518,6 @@ ASTStmt *ASTParser::ProcessStmtDeclStmt(MapleAllocator &allocator, const clang:: const clang::Decl *decl = declStmt.getSingleDecl(); if (decl != nullptr) { ASTDecl *ad = ProcessDecl(allocator, *decl); - ad->SetDeclPos(astFile->GetDeclPosInfo(*decl)); if (ad != nullptr) { astStmt->SetSubDecl(ad); } @@ -505,7 +528,6 @@ ASTStmt *ASTParser::ProcessStmtDeclStmt(MapleAllocator &allocator, const clang:: clang::DeclGroupRef::const_iterator it; for (it = declGroupRef.begin(); it != declGroupRef.end(); ++it) { ASTDecl *ad = ProcessDecl(allocator, **it); - ad->SetDeclPos(astFile->GetDeclPosInfo(**it)); if (ad != nullptr) { astStmt->SetSubDecl(ad); } @@ -827,12 +849,23 @@ ASTExpr *ASTParser::ProcessExprArraySubscriptExpr(MapleAllocator &allocator, con base = static_cast(base)->getSubExpr(); exprTmp = static_cast(base); } - // base is DeclRefExpr - ASTExpr *baseExpr = ProcessExpr(allocator, base); - if (baseExpr == nullptr) { - return nullptr; + // array in struct + if (base->getStmtClass() == clang::Stmt::MemberExprClass) { + ASTExpr *memberExpr = ProcessExpr(allocator, base); + ASTExpr *declRefExpr = static_cast(memberExpr)->GetBaseExpr(); + if (declRefExpr == nullptr) { + return nullptr; + } + astArraySubscriptExpr->SetBaseExpr(declRefExpr); + astArraySubscriptExpr->SetMemberExpr(*memberExpr); + } else { + // base is DeclRefExpr + ASTExpr *baseExpr = ProcessExpr(allocator, base); + if (baseExpr == nullptr) { + return nullptr; + } + astArraySubscriptExpr->SetBaseExpr(baseExpr); } - astArraySubscriptExpr->SetBaseExpr(baseExpr); return astArraySubscriptExpr; } @@ -861,7 +894,7 @@ ASTExpr *ASTParser::ProcessExprUnaryExprOrTypeTraitExpr(MapleAllocator &allocato } } auto integerExpr = ASTDeclsBuilder::ASTExprBuilder(allocator); - integerExpr->SetType(PTY_i32); + integerExpr->SetType(PTY_u64); integerExpr->SetVal(size); return integerExpr; } @@ -1135,19 +1168,47 @@ ASTExpr *ASTParser::ProcessExprImplicitCastExpr(MapleAllocator &allocator, const ASTImplicitCastExpr *astImplicitCastExpr = ASTDeclsBuilder::ASTExprBuilder(allocator); CHECK_FATAL(astImplicitCastExpr != nullptr, "astImplicitCastExpr is nullptr"); switch (expr.getCastKind()) { - case clang::CK_IntegralRealToComplex: case clang::CK_NoOp: case clang::CK_ArrayToPointerDecay: case clang::CK_FunctionToPointerDecay: case clang::CK_LValueToRValue: + case clang::CK_BitCast: + break; + case clang::CK_BuiltinFnToFnPtr: + astImplicitCastExpr->SetBuilinFunc(true); break; case clang::CK_FloatingToIntegral: + case clang::CK_IntegralToFloating: case clang::CK_FloatingCast: case clang::CK_IntegralCast: astImplicitCastExpr->SetSrcType(astFile->CvtType(expr.getSubExpr()->getType())); astImplicitCastExpr->SetDstType(astFile->CvtType(expr.getType())); astImplicitCastExpr->SetNeededCvt(true); break; + case clang::CK_IntegralRealToComplex: + case clang::CK_FloatingRealToComplex: + case clang::CK_IntegralComplexCast: + case clang::CK_FloatingComplexCast: + case clang::CK_IntegralComplexToFloatingComplex: + case clang::CK_FloatingComplexToIntegralComplex: + case clang::CK_FloatingComplexToReal: + case clang::CK_IntegralComplexToReal: + case clang::CK_FloatingComplexToBoolean: + case clang::CK_IntegralComplexToBoolean: { + clang::QualType qualType = expr.getType().getCanonicalType(); + astImplicitCastExpr->SetComplexType(astFile->CvtType(qualType)); + clang::QualType dstQualType = llvm::cast(qualType)->getElementType(); + astImplicitCastExpr->SetDstType(astFile->CvtType(dstQualType)); + clang::QualType subQualType = expr.getSubExpr()->getType().getCanonicalType(); + clang::QualType srcQualType = llvm::cast(subQualType)->getElementType(); + astImplicitCastExpr->SetSrcType(astFile->CvtType(srcQualType)); + astImplicitCastExpr->SetNeededCvt(true); + if (expr.getCastKind() == clang::CK_IntegralRealToComplex || + expr.getCastKind() == clang::CK_FloatingRealToComplex) { + astImplicitCastExpr->SetComplexCastKind(true); + } + break; + } default: CHECK_FATAL(false, "NIY"); return nullptr; @@ -1171,20 +1232,10 @@ ASTExpr *ASTParser::ProcessExprDeclRefExpr(MapleAllocator &allocator, const clan MIRType *refType = astFile->CvtType(qualType); ASTDecl *astDecl = ASTDeclsBuilder::ASTDeclBuilder(allocator, fileName, refName, std::vector{refType}); astDecl->SetDeclPos(astFile->GetDeclPosInfo(*namedDecl)); - auto declKind = expr.getDecl()->getKind(); - if (declKind == clang::Decl::Var) { - const auto *varDecl = llvm::cast(expr.getDecl()->getCanonicalDecl()); - astDecl->SetGlobal(!varDecl->isLocalVarDeclOrParm()); - } else if (declKind == clang::Decl::Function) { - const auto *funcDecl = llvm::cast(expr.getDecl()->getCanonicalDecl()); - astDecl->SetGlobal(!funcDecl->isGlobal()); - } else { - // For comes from `EnumConstant` - astDecl->SetGlobal(expr.getDecl()->getParentFunctionOrMethod() == nullptr); - } - astDecl->SetIsParam(declKind == clang::Decl::ParmVar); + astDecl->SetGlobal(expr.getDecl()->getCanonicalDecl()->isDefinedOutsideFunctionOrMethod()); + astDecl->SetIsParam(expr.getDecl()->getKind() == clang::Decl::ParmVar); astRefExpr->SetASTDecl(astDecl); - astRefExpr->SetType(refType); + astRefExpr->SetType(astDecl->GetTypeDesc().front()); return astRefExpr; } default: @@ -1413,6 +1464,7 @@ bool ASTParser::PreProcessAST() { break; } case clang::Decl::Typedef: + globalTypeDefDecles.emplace_back(child); break; case clang::Decl::Enum: globalEnumDecles.emplace_back(child); @@ -1425,9 +1477,15 @@ bool ASTParser::PreProcessAST() { return true; } -#define DECL_CASE(CLASS) \ - case clang::Decl::CLASS: \ - return ProcessDecl##CLASS##Decl(allocator, llvm::cast(decl)); +#define DECL_CASE(CLASS) \ + case clang::Decl::CLASS: { \ + ASTDecl *astDecl = ProcessDecl##CLASS##Decl(allocator, llvm::cast(decl)); \ + if (astDecl != nullptr) { \ + astDecl->SetDeclPos(astFile->GetDeclPosInfo(decl)); \ + astDecl->SetGlobal(decl.isDefinedOutsideFunctionOrMethod()); \ + } \ + return astDecl; \ + } ASTDecl *ASTParser::ProcessDecl(MapleAllocator &allocator, const clang::Decl &decl) { switch (decl.getKind()) { DECL_CASE(Function); @@ -1435,8 +1493,9 @@ ASTDecl *ASTParser::ProcessDecl(MapleAllocator &allocator, const clang::Decl &de DECL_CASE(Record); DECL_CASE(Var); DECL_CASE(Enum); + DECL_CASE(Typedef); default: - CHECK_FATAL(false, "NIY"); + CHECK_FATAL(false, " Decl: %d NIY", decl.getKind()); return nullptr; } return nullptr; @@ -1488,6 +1547,10 @@ ASTDecl *ASTParser::ProcessDeclRecordDecl(MapleAllocator &allocator, const clang curStructOrUnion->SetField(af); } } + if (!recDecl.isDefinedOutsideFunctionOrMethod()) { + // Record function scope type decl in global with unique suffix identified + astStructs.emplace_back(curStructOrUnion); + } return curStructOrUnion; } @@ -1572,10 +1635,9 @@ ASTDecl *ASTParser::ProcessDeclVarDecl(MapleAllocator &allocator, const clang::V GenericAttrs attrs; astFile->CollectAttrs(varDecl, attrs, kPublic); ASTVar *astVar = ASTDeclsBuilder::ASTVarBuilder(allocator, fileName, varName, std::vector{varType}, attrs); - astVar->SetDeclPos(astFile->GetDeclPosInfo(varDecl)); - astVar->SetGlobal(!varDecl.isLocalVarDecl()); if (varDecl.hasInit()) { + astVar->SetDeclPos(astFile->GetDeclPosInfo(varDecl)); auto initExpr = varDecl.getInit(); auto astInitExpr = ProcessExpr(allocator, initExpr); if (initExpr->getStmtClass() == clang::Stmt::InitListExprClass) { @@ -1615,7 +1677,21 @@ ASTDecl *ASTParser::ProcessDeclEnumDecl(MapleAllocator &allocator, const clang:: return localEnumDecl; } -bool ASTParser::RetrieveStructs(MapleAllocator &allocator, MapleList &structs) { +ASTDecl *ASTParser::ProcessDeclTypedefDecl(MapleAllocator &allocator, const clang::TypedefDecl &typeDefDecl) { + clang::QualType underlyCanonicalTy = typeDefDecl.getCanonicalDecl()->getUnderlyingType().getCanonicalType(); + // For used type completeness + // Only process implicit record type here + if (underlyCanonicalTy->isRecordType()) { + const auto *recordType = llvm::cast(underlyCanonicalTy); + clang::RecordDecl *recordDecl = recordType->getDecl(); + if (recordDecl->isImplicit()) { + return ProcessDecl(allocator, *recordDecl); + } + } + return nullptr; // skip primitive type and explicit declared type +} + +bool ASTParser::RetrieveStructs(MapleAllocator &allocator) { for (auto &decl : recordDecles) { clang::RecordDecl *recDecl = llvm::cast(decl->getCanonicalDecl()); if (!recDecl->isCompleteDefinition()) { @@ -1626,12 +1702,12 @@ bool ASTParser::RetrieveStructs(MapleAllocator &allocator, MapleList return false; } curStructOrUnion->SetGlobal(true); - structs.emplace_back(curStructOrUnion); + astStructs.emplace_back(curStructOrUnion); } return true; } -bool ASTParser::RetrieveFuncs(MapleAllocator &allocator, MapleList &funcs) { +bool ASTParser::RetrieveFuncs(MapleAllocator &allocator) { for (auto &func : funcDecles) { clang::FunctionDecl *funcDecl = llvm::cast(func); ASTFunc *af = static_cast(ProcessDecl(allocator, *funcDecl)); @@ -1639,13 +1715,13 @@ bool ASTParser::RetrieveFuncs(MapleAllocator &allocator, MapleList &fu return false; } af->SetGlobal(true); - funcs.emplace_back(af); + astFuncs.emplace_back(af); } return true; } // seperate MP with astparser -bool ASTParser::RetrieveGlobalVars(MapleAllocator &allocator, MapleList &vars) { +bool ASTParser::RetrieveGlobalVars(MapleAllocator &allocator) { for (auto &decl : globalVarDecles) { clang::VarDecl *varDecl = llvm::cast(decl); ASTVar *val = static_cast(ProcessDecl(allocator, *varDecl)); @@ -1653,12 +1729,12 @@ bool ASTParser::RetrieveGlobalVars(MapleAllocator &allocator, MapleList return false; } val->SetGlobal(true); - vars.emplace_back(val); + astVars.emplace_back(val); } return true; } -bool ASTParser::ProcessGlobalEnums(MapleAllocator &allocator, MapleList &vars) { +bool ASTParser::ProcessGlobalEnums(MapleAllocator &allocator) { for (auto gEnumDecl : globalEnumDecles) { TraverseDecl(gEnumDecl, [&](clang::Decl *child) { CHECK_FATAL(child->getKind() == clang::Decl::EnumConstant, "Unsupported decl kind: %u", child->getKind()); @@ -1674,12 +1750,19 @@ bool ASTParser::ProcessGlobalEnums(MapleAllocator &allocator, MapleList constExpr->SetType(mirType->GetPrimType()); astVar->SetInitExpr(constExpr); astVar->SetGlobal(true); - vars.emplace_back(astVar); + astVars.emplace_back(astVar); }); } return true; } +bool ASTParser::ProcessGlobalTypeDef(MapleAllocator &allocator) { + for (auto gTypeDefDecl : globalTypeDefDecles) { + (void)ProcessDecl(allocator, *gTypeDefDecl); + } + return true; +} + const std::string &ASTParser::GetSourceFileName() const { return fileName; } diff --git a/src/mplfe/ast_input/src/ast_stmt.cpp b/src/mplfe/ast_input/src/ast_stmt.cpp index 864baa1d9a1eaea7f839da3ba306bf31d28a0b38..39c412d60e58729ba397a469af4e24e69d11e521 100644 --- a/src/mplfe/ast_input/src/ast_stmt.cpp +++ b/src/mplfe/ast_input/src/ast_stmt.cpp @@ -47,7 +47,7 @@ std::list ASTCompoundStmt::Emit2FEStmtImpl() const { std::list ASTReturnStmt::Emit2FEStmtImpl() const { std::list stmts; auto astExpr = exprs.front(); - UniqueFEIRExpr feExpr = astExpr->Emit2FEExpr(stmts); + UniqueFEIRExpr feExpr = astExpr != nullptr ? astExpr->Emit2FEExpr(stmts) : nullptr; UniqueFEIRStmt stmt = std::make_unique(std::move(feExpr)); stmts.emplace_back(std::move(stmt)); return stmts; @@ -244,6 +244,16 @@ std::list ASTDeclStmt::Emit2FEStmtImpl() const { } // ---------- ASTCallExprStmt ---------- +std::map ASTCallExprStmt::funcPtrMap = + ASTCallExprStmt::InitFuncPtrMap(); + +std::map ASTCallExprStmt::InitFuncPtrMap() { + std::map ans; + ans["__builtin_va_start"] = &ASTCallExprStmt::ProcessBuiltinVaStart; + ans["__builtin_va_end"] = &ASTCallExprStmt::ProcessBuiltinVaEnd; + return ans; +} + std::list ASTCallExprStmt::Emit2FEStmtCall() const { std::list stmts; ASTCallExpr *callExpr = static_cast(exprs.front()); @@ -298,10 +308,61 @@ std::list ASTCallExprStmt::Emit2FEStmtImpl() const { if (callExpr->IsIcall()) { return Emit2FEStmtICall(); } else { + if (callExpr->GetCalleeExpr() != nullptr && callExpr->GetCalleeExpr()->GetASTOp() == kASTOpCast && + static_cast(callExpr->GetCalleeExpr())->IsBuilinFunc()) { + auto ptrFunc = funcPtrMap.find(callExpr->GetFuncName()); + CHECK_FATAL(ptrFunc != funcPtrMap.end(), "unsupported BuiltinFunc: %s", callExpr->GetFuncName().c_str()); + return (this->*(ptrFunc->second))(); + } return Emit2FEStmtCall(); } } +std::list ASTCallExprStmt::ProcessBuiltinVaStart() const { + std::list stmts; + ASTCallExpr *callExpr = static_cast(exprs.front()); + // args + std::vector argsExprs = callExpr->GetArgsExpr(); + auto exprArgList = std::make_unique>(); + for (int32 i = argsExprs.size() - 1; i >= 0; --i) { + UniqueFEIRExpr expr = argsExprs[i]->Emit2FEExpr(stmts); + // addrof va_list instead of dread va_list + if (i == 0 && expr->GetKind() == kExprDRead) { + UniqueFEIRVar var = static_cast(expr.get())->GetVar()->Clone(); + expr = FEIRBuilder::CreateExprAddrofVar(std::move(var)); + } + exprArgList->push_front(std::move(expr)); + } +#ifndef USE_OPS + CHECK_FATAL(false, "implemention in ops branch"); +#else + std::unique_ptr stmt = std::make_unique( + INTRN_C_va_start, nullptr /* type */, nullptr /* retVar */, std::move(exprArgList)); + stmts.emplace_back(std::move(stmt)); +#endif + return stmts; +} + +std::list ASTCallExprStmt::ProcessBuiltinVaEnd() const { + std::list stmts; + ASTCallExpr *callExpr = static_cast(exprs.front()); + // args + std::vector argsExprs = callExpr->GetArgsExpr(); + std::list exprArgList; + for (int32 i = argsExprs.size() - 1; i >= 0; --i) { + UniqueFEIRExpr expr = argsExprs[i]->Emit2FEExpr(stmts); + // addrof va_list instead of dread va_list + if (i == 0 && expr->GetKind() == kExprDRead) { + UniqueFEIRVar var = static_cast(expr.get())->GetVar()->Clone(); + expr = FEIRBuilder::CreateExprAddrofVar(std::move(var)); + } + exprArgList.push_front(std::move(expr)); + } + auto stmt = std::make_unique(OP_eval, std::move(exprArgList)); + stmts.emplace_back(std::move(stmt)); + return stmts; +} + // ---------- ASTImplicitCastExprStmt ---------- std::list ASTImplicitCastExprStmt::Emit2FEStmtImpl() const { CHECK_FATAL(exprs.size() == 1, "Only one sub expr supported!"); @@ -330,7 +391,6 @@ std::list ASTIntegerLiteralStmt::Emit2FEStmtImpl() const { // ---------- ASTVAArgExprStmt ---------- std::list ASTVAArgExprStmt::Emit2FEStmtImpl() const { - CHECK_FATAL(false, "NYI"); std::list stmts; return stmts; } @@ -398,4 +458,19 @@ std::list ASTAtomicExprStmt::Emit2FEStmtImpl() const { stmts.emplace_back(std::move(stmt)); return stmts; } + +// ---------- ASTGCCAsmStmt ---------- +std::list ASTGCCAsmStmt::Emit2FEStmtImpl() const { + std::list stmts; + std::vector outputsExprs; + std::vector inputsExprs; + for (uint32 i = 0; i < numOfOutputs; ++i) { + outputsExprs.emplace_back(exprs[i]->Emit2FEExpr(stmts)); + } + for (uint32 i = 0; i < numOfInputs; ++i) { + inputsExprs.emplace_back(exprs[i + numOfOutputs]->Emit2FEExpr(stmts)); + } + // Translate asm info to FEIR and MIR. + return stmts; +} } // namespace maple diff --git a/src/mplfe/common/include/feir_builder.h b/src/mplfe/common/include/feir_builder.h index 922e34457485f1fcefa6e152e8a6864b2f92a8ea..e8423df65343422030da9e70c8c7654f85b3a15d 100644 --- a/src/mplfe/common/include/feir_builder.h +++ b/src/mplfe/common/include/feir_builder.h @@ -84,6 +84,10 @@ class FEIRBuilder { UniqueFEIRType argTypeNative); static UniqueFEIRExpr CreateExprArrayStoreForC(UniqueFEIRExpr argExprArray, std::list &argExprIndexs, UniqueFEIRType argTypeNative); + static UniqueFEIRExpr CreateExprArrayStoreForC(UniqueFEIRExpr argExprArray, std::list &argExprIndexs, + UniqueFEIRType argArrayTypeNative, + UniqueFEIRExpr argExprStruct, + UniqueFEIRType argStructTypeNative); // Stmt static UniqueFEIRStmt CreateStmtDAssign(UniqueFEIRVar dstVar, UniqueFEIRExpr srcExpr, bool hasException = false); static UniqueFEIRStmt CreateStmtGoto(uint32 targetLabelIdx); diff --git a/src/mplfe/common/include/feir_node_kind.def b/src/mplfe/common/include/feir_node_kind.def index 4877152e73f26dfe366301448bf669f773b8489a..cb2f11c874279c2e643798d54f8866a9e00805ef 100644 --- a/src/mplfe/common/include/feir_node_kind.def +++ b/src/mplfe/common/include/feir_node_kind.def @@ -42,6 +42,7 @@ FEIR_NODE_KIND(ExprArray, "ExprArray") FEIR_NODE_KIND(ExprAddrof, "ExprAddrof") FEIR_NODE_KIND(ExprAddrofVar, "ExprAddrofVar") FEIR_NODE_KIND(ExprAddrofFunc, "ExprAddrofFunc") +FEIR_NODE_KIND(ExprAddrofStruct, "ExprAddrofStruct") FEIR_NODE_KIND(ExprIntrinsicop, "ExprIntrinsicop") FEIR_NODE_KIND(FEIRExprJavaMerge, "FEIRExprJavaMerge") FEIR_NODE_KIND(ExprTypeCvt, "ExprTypeCvt") diff --git a/src/mplfe/common/include/feir_stmt.h b/src/mplfe/common/include/feir_stmt.h index e7403382cbe174ed660a1b0fb116c371598c3de1..69f048a6b6f2f8b60602a5be8daed19db415e2d9 100644 --- a/src/mplfe/common/include/feir_stmt.h +++ b/src/mplfe/common/include/feir_stmt.h @@ -304,7 +304,7 @@ class FEIRExpr { } PrimType GetPrimType() const { - return type->GetPrimType(); + return GetPrimTypeImpl(); } void RegisterDFGNodes2CheckPoint(FEIRStmtCheckPoint &checkPoint) { @@ -324,6 +324,10 @@ class FEIRExpr { return true; } + virtual PrimType GetPrimTypeImpl() const { + return type->GetPrimType(); + } + virtual bool IsNestableImpl() const; virtual bool IsAddrofImpl() const; virtual bool HasExceptionImpl() const; @@ -381,6 +385,7 @@ class FEIRExprDRead : public FEIRExpr { public: explicit FEIRExprDRead(std::unique_ptr argVarSrc); FEIRExprDRead(std::unique_ptr argType, std::unique_ptr argVarSrc); + FEIRExprDRead(std::unique_ptr argType, std::unique_ptr argVarSrc, const std::string &argFieldName); ~FEIRExprDRead() = default; void SetVarSrc(std::unique_ptr argVarSrc); void SetTrans(UniqueFEIRVarTrans argTrans) { @@ -436,12 +441,13 @@ class FEIRExprDRead : public FEIRExpr { bool CalculateDefs4AllUsesImpl(FEIRStmtCheckPoint &checkPoint, FEIRUseDefChain &udChain) override; BaseNode *GenMIRNodeImpl(MIRBuilder &mirBuilder) const override; std::vector GetVarUsesImpl() const override; + PrimType GetPrimTypeImpl() const override; private: std::unique_ptr varSrc; FieldID fieldID = 0; std::string fieldName; - MIRType *fieldType; + MIRType *fieldType = nullptr; }; // ---------- FEIRExprRegRead ---------- @@ -612,6 +618,10 @@ class FEIRExprIRead : public FEIRExpr { return fieldID; } + const UniqueFEIRType &GetRetType() const { + return retType; + } + void SetFieldName(const std::string &argFieldName) { fieldName = argFieldName; } @@ -631,12 +641,13 @@ class FEIRExprIRead : public FEIRExpr { protected: std::unique_ptr CloneImpl() const override; BaseNode *GenMIRNodeImpl(MIRBuilder &mirBuilder) const override; + PrimType GetPrimTypeImpl() const override; private: - UniqueFEIRType retType; - UniqueFEIRType ptrType; - FieldID fieldID; - UniqueFEIRExpr subExpr; + UniqueFEIRType retType = nullptr; + UniqueFEIRType ptrType = nullptr; + FieldID fieldID = 0; + UniqueFEIRExpr subExpr = nullptr; std::string fieldName; }; @@ -858,6 +869,11 @@ class FEIRExprArrayStoreForC : public FEIRExpr { public: FEIRExprArrayStoreForC(UniqueFEIRExpr argExprArray, std::list &argExprIndexs, UniqueFEIRType argTypeNative); + // for array in struct + FEIRExprArrayStoreForC(UniqueFEIRExpr argExprArray, std::list &argExprIndexs, + UniqueFEIRType argArrayTypeNative, + UniqueFEIRExpr argExprStruct, + UniqueFEIRType argStructTypeNative); ~FEIRExprArrayStoreForC() = default; FEIRExpr &GetExprArray() const { @@ -874,19 +890,38 @@ class FEIRExprArrayStoreForC : public FEIRExpr { std::move(begin(exprs), end(exprs), std::inserter(exprIndexs, end(exprIndexs))); } + FEIRExpr &GetExprStruct() const { + ASSERT(exprStruct != nullptr, "exprStruct is nullptr"); + return *exprStruct.get(); + } + FEIRType &GetTypeArray() const { ASSERT(typeNative != nullptr, "typeNative is nullptr"); return *typeNative.get(); } + FEIRType &GetTypeSruct() const { + ASSERT(typeNativeStruct != nullptr, "typeNativeStruct is nullptr"); + return *typeNativeStruct.get(); + } + + bool IsMember() const { + return typeNativeStruct != nullptr; + } + protected: std::unique_ptr CloneImpl() const override; BaseNode *GenMIRNodeImpl(MIRBuilder &mirBuilder) const override; + PrimType GetPrimTypeImpl() const override; private: UniqueFEIRExpr exprArray; mutable std::list exprIndexs; - UniqueFEIRType typeNative; + UniqueFEIRType typeNative = nullptr; + + // for array in struct + UniqueFEIRExpr exprStruct = nullptr; + UniqueFEIRType typeNativeStruct = nullptr; }; // ---------- FEIRExprArrayLoad ---------- @@ -1639,9 +1674,10 @@ class FEIRStmtCaseForC : public FEIRStmt { void AddFeirStmt(UniqueFEIRStmt stmt) { subStmts.emplace_back(std::move(stmt)); } - std::map &GetPesudoLabelMap() { + const std::map &GetPesudoLabelMap() const { return pesudoLabelMap; } + protected: std::string DumpDotStringImpl() const override; std::list GenMIRStmtsImpl(MIRBuilder &mirBuilder) const override; @@ -1679,6 +1715,10 @@ class FEIRStmtArrayStore : public FEIRStmt { FEIRStmtArrayStore(UniqueFEIRExpr argExprElem, UniqueFEIRExpr argExprArray, std::list &argExprIndexs, UniqueFEIRType argTypeArray); + // for C array in struct + FEIRStmtArrayStore(UniqueFEIRExpr argExprElem, UniqueFEIRExpr argExprArray, std::list &argExprIndexs, + UniqueFEIRType argTypeArray, UniqueFEIRExpr argExprStruct, UniqueFEIRType argTypeStruct); + ~FEIRStmtArrayStore() = default; void SetIndexsExprs(std::list &exprs) { @@ -1702,6 +1742,10 @@ class FEIRStmtArrayStore : public FEIRStmt { mutable std::list exprIndexs; UniqueFEIRType typeArray; mutable UniqueFEIRType typeElem = nullptr; + + // for C array in struct + UniqueFEIRExpr exprStruct; + UniqueFEIRType typeStruct; }; // ---------- FEIRStmtFieldStore ---------- diff --git a/src/mplfe/common/src/feir_builder.cpp b/src/mplfe/common/src/feir_builder.cpp index 74b962212ede170e5a9595787558dc992e0282f0..f9300b86320056116375469af5f71b10b9684d0e 100644 --- a/src/mplfe/common/src/feir_builder.cpp +++ b/src/mplfe/common/src/feir_builder.cpp @@ -303,6 +303,19 @@ UniqueFEIRExpr FEIRBuilder::CreateExprArrayStoreForC(UniqueFEIRExpr argExprArray return expr; } +UniqueFEIRExpr FEIRBuilder::CreateExprArrayStoreForC(UniqueFEIRExpr argExprArray, + std::list &argExprIndexs, + UniqueFEIRType argArrayTypeNative, + UniqueFEIRExpr argExprStruct, + UniqueFEIRType argStructTypeNative) { + UniqueFEIRExpr expr = std::make_unique(std::move(argExprArray), argExprIndexs, + std::move(argArrayTypeNative), + std::move(argExprStruct), + std::move(argStructTypeNative)); + CHECK_NULL_FATAL(expr); + return expr; +} + UniqueFEIRStmt FEIRBuilder::CreateStmtDAssign(UniqueFEIRVar dstVar, UniqueFEIRExpr srcExpr, bool hasException) { UniqueFEIRStmt stmt = std::make_unique(std::move(dstVar), std::move(srcExpr)); FEIRStmtDAssign *ptrStmt = static_cast(stmt.get()); diff --git a/src/mplfe/common/src/feir_stmt.cpp b/src/mplfe/common/src/feir_stmt.cpp index 73c5e0626c293d2c4642fd927b5d98a2953d6f92..964c9a5ab815b7cba7f440cce2f6b2399f44523b 100644 --- a/src/mplfe/common/src/feir_stmt.cpp +++ b/src/mplfe/common/src/feir_stmt.cpp @@ -986,26 +986,23 @@ std::list FEIRStmtSwitchForC::GenMIRStmtsImpl(MIRBuilder &mirBuilder) AstSwitchUtil::Instance().PushNestedBreakLabels(exitName); // exit label AstSwitchUtil::Instance().PushNestedCaseVectors(std::pair(caseVec, swDefaultLabel)); BaseNode *exprNode = expr->GenMIRNode(mirBuilder); + BlockNode *tempBlock = module.CurFuncCodeMemPool()->New(); CaseVector &switchTable = *AstSwitchUtil::Instance().GetTopOfNestedCaseVectors().first; for (auto &sub : subStmts) { - if (sub.get()->GetKind() == kStmtCaseForC) { - auto caseStmt = static_cast(sub.get()); - for (auto targetPair : caseStmt->GetPesudoLabelMap()) { - targetPair.second->GenerateLabelIdx(mirBuilder); - switchTable.push_back(std::make_pair(targetPair.first, targetPair.second->GetMIRLabelIdx())); - } - } if (sub.get()->GetKind() == FEIRNodeKind::kStmtBreak) { AstSwitchUtil::Instance().MarkLabelUsed(exitName); auto feirStmtBreak = static_cast(sub.get()); feirStmtBreak->SetSwitchLabelName(exitName); feirStmtBreak->SetIsFromSwitch(true); } + for (auto mirStmt : sub->GenMIRStmts(mirBuilder)) { + tempBlock->AddStatement(mirStmt); + } } SwitchNode *mirSwitchStmt = mirBuilder.CreateStmtSwitch(exprNode, swDefaultLabel, switchTable); ans.push_back(mirSwitchStmt); - for (auto &sub : subStmts) { - ans.splice(ans.end(), sub.get()->GenMIRStmts(mirBuilder)); + for (auto &it : tempBlock->GetStmtNodes()) { + ans.emplace_back(&it); } if (!hasDefault) { LabelIdx endLab = mirBuilder.GetOrCreateMIRLabel(endName); @@ -1044,13 +1041,16 @@ std::list FEIRStmtCaseForC::GenMIRStmtsImpl(MIRBuilder &mirBuilder) c std::list ans; CaseVector &caseVec = *AstSwitchUtil::Instance().GetTopOfNestedCaseVectors().first; StmtNode *mirLabelStmt = nullptr; + for (auto targetPair : GetPesudoLabelMap()) { + targetPair.second->GenerateLabelIdx(mirBuilder); + caseVec.push_back(std::make_pair(targetPair.first, targetPair.second->GetMIRLabelIdx())); + } for (auto it : caseVec) { if (lCaseLabel == it.first) { mirLabelStmt = mirBuilder.CreateStmtLabel(it.second); ans.emplace_back(mirLabelStmt); } } - for (auto &sub : subStmts) { if (sub.get()->GetKind() == FEIRNodeKind::kStmtBreak) { std::string switchBreakLabelName = AstSwitchUtil::Instance().GetTopOfBreakLabels(); @@ -1124,6 +1124,18 @@ FEIRStmtArrayStore::FEIRStmtArrayStore(UniqueFEIRExpr argExprElem, UniqueFEIRExp SetIndexsExprs(argExprIndexs); } +FEIRStmtArrayStore::FEIRStmtArrayStore(UniqueFEIRExpr argExprElem, UniqueFEIRExpr argExprArray, + std::list &argExprIndexs, UniqueFEIRType argTypeArray, + UniqueFEIRExpr argExprStruct, UniqueFEIRType argTypeStruct) + : FEIRStmt(FEIRNodeKind::kStmtArrayStore), + exprElem(std::move(argExprElem)), + exprArray(std::move(argExprArray)), + typeArray(std::move(argTypeArray)), + exprStruct(std::move(argExprStruct)), + typeStruct(std::move(argTypeStruct)) { + SetIndexsExprs(argExprIndexs); +} + void FEIRStmtArrayStore::RegisterDFGNodes2CheckPointImpl(FEIRStmtCheckPoint &checkPoint) { exprArray->RegisterDFGNodes2CheckPoint(checkPoint); exprIndex->RegisterDFGNodes2CheckPoint(checkPoint); @@ -1152,7 +1164,7 @@ std::list FEIRStmtArrayStore::GenMIRStmtsImpl(MIRBuilder &mirBuilder) CHECK_FATAL(((exprIndex == nullptr) && (exprIndexs.size() != 0))|| (exprIndex->GetKind() == kExprDRead) || (exprIndex->GetKind() == kExprConst), "only support dread/const expr for exprIndex"); - CHECK_FATAL(exprElem == nullptr || + CHECK_FATAL(exprElem == nullptr || exprElem->GetKind() == kExprUnary || (exprElem->GetKind() == kExprDRead) || (exprElem->GetKind() == kExprConst), "only support dread/const expr for exprElem"); MIRType *ptrMIRArrayType = typeArray->GenerateMIRType(false); @@ -1189,9 +1201,18 @@ void FEIRStmtArrayStore::GenMIRStmtsImplForCPart(MIRBuilder &mirBuilder, MIRType if (typeElem == nullptr) { typeElem = std::make_unique(*static_cast(ptrMIRArrayType)->GetElemType()); } + uint32 fieldID = 0; + // array in struct + if (typeStruct != nullptr) { + GStrIdx fieldNameIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName( + static_cast(exprArray.get())->GetFieldName()); + MIRType *ptrMIRStructType = typeStruct->GenerateMIRType(false); + MIRStructType* mirStructType = static_cast(ptrMIRStructType); + FEManager::GetMIRBuilder().TraverseToNamedField(*mirStructType, fieldNameIdx, fieldID); + } *mIRElemType = typeElem->GenerateMIRType(true); MIRSymbol *mirSymbol = exprArray->GetVarUses().front()->GenerateLocalMIRSymbol(mirBuilder); - BaseNode *arrayAddrOfExpr = mirBuilder.CreateExprAddrof(0, *mirSymbol); + BaseNode *arrayAddrOfExpr = mirBuilder.CreateExprAddrof(fieldID, *mirSymbol); if (exprIndex == nullptr) { std::vector nds; nds.push_back(arrayAddrOfExpr); @@ -1833,9 +1854,8 @@ std::list FEIRStmtIntrinsicCallAssign::GenMIRStmtsImpl(MIRBuilder &mi BaseNode *argNumExpr = mirBuilder.CreateIntConst(static_cast(typeID), PTY_i32); args.push_back(argNumExpr); } - stmtCall = - mirBuilder.CreateStmtIntrinsicCall(INTRN_JAVA_CLINIT_CHECK, std::move(args), - type->GenerateMIRType()->GetTypeIndex()); + stmtCall = mirBuilder.CreateStmtIntrinsicCall(INTRN_JAVA_CLINIT_CHECK, std::move(args), + type->GenerateMIRType()->GetTypeIndex()); } else if (intrinsicId == INTRN_JAVA_FILL_NEW_ARRAY) { MapleVector args(mirBuilder.GetCurrentFuncCodeMpAllocator()->Adapter()); if (exprList != nullptr) { @@ -1853,6 +1873,18 @@ std::list FEIRStmtIntrinsicCallAssign::GenMIRStmtsImpl(MIRBuilder &mi } else if (intrinsicId == INTRN_JAVA_POLYMORPHIC_CALL) { return GenMIRStmtsForInvokePolyMorphic(mirBuilder); } +#ifdef USE_OPS + else if (intrinsicId == INTRN_C_va_start) { + MapleVector args(mirBuilder.GetCurrentFuncCodeMpAllocator()->Adapter()); + if (exprList != nullptr) { + for (const auto &expr : *exprList) { + BaseNode *node = expr->GenMIRNode(mirBuilder); + args.push_back(node); + } + } + stmtCall = mirBuilder.CreateStmtIntrinsicCall(INTRN_C_va_start, std::move(args), TyIdx(0)); + } +#endif // other intrinsic call should be implemented ans.emplace_back(stmtCall); return ans; @@ -2062,13 +2094,20 @@ FEIRExprDRead::FEIRExprDRead(std::unique_ptr argVarSrc) SetVarSrc(std::move(argVarSrc)); } +FEIRExprDRead::FEIRExprDRead(std::unique_ptr argType, std::unique_ptr argVarSrc, + const std::string &argFieldName) + : FEIRExpr(FEIRNodeKind::kExprDRead, std::move(argType)), + fieldName(argFieldName) { + SetVarSrc(std::move(argVarSrc)); +} + FEIRExprDRead::FEIRExprDRead(std::unique_ptr argType, std::unique_ptr argVarSrc) : FEIRExpr(FEIRNodeKind::kExprDRead, std::move(argType)) { SetVarSrc(std::move(argVarSrc)); } std::unique_ptr FEIRExprDRead::CloneImpl() const { - std::unique_ptr expr = std::make_unique(type->Clone(), varSrc->Clone()); + std::unique_ptr expr = std::make_unique(type->Clone(), varSrc->Clone(), fieldName); return expr; } @@ -2098,6 +2137,15 @@ std::vector FEIRExprDRead::GetVarUsesImpl() const { return std::vector({ varSrc.get() }); } +PrimType FEIRExprDRead::GetPrimTypeImpl() const { + PrimType primType = type->GetPrimType(); + MIRType *mirType = GetFieldType(); + if (primType == PTY_agg && mirType != nullptr) { + return mirType->GetPrimType(); + } + return primType; +} + // ---------- FEIRExprIRead ---------- std::unique_ptr FEIRExprIRead::CloneImpl() const { std::unique_ptr expr = std::make_unique(retType->Clone(), ptrType->Clone(), @@ -2105,6 +2153,11 @@ std::unique_ptr FEIRExprIRead::CloneImpl() const { return expr; } +PrimType FEIRExprIRead::GetPrimTypeImpl() const { + CHECK_NULL_FATAL(retType); + return retType->GetPrimType(); +} + BaseNode *FEIRExprIRead::GenMIRNodeImpl(MIRBuilder &mirBuilder) const { MIRType *returnType = retType->GenerateMIRTypeAuto(); MIRType *pointerType = ptrType->GenerateMIRTypeAuto(); @@ -2314,7 +2367,8 @@ BaseNode *FEIRExprTypeCvt::GenMIRNodeMode1(MIRBuilder &mirBuilder) const { // MIR: op () MIRType *mirTypeDst = GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(static_cast(GetTypeRef().GetPrimType()))); - MIRType *mirTypeSrc = GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(static_cast(opnd->GetPrimType()))); + MIRType *mirTypeSrc = nullptr; + mirTypeSrc = GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(static_cast(opnd->GetPrimType()))); BaseNode *nodeOpnd = opnd->GenMIRNode(mirBuilder); BaseNode *expr = mirBuilder.CreateExprTypeCvt(op, *mirTypeDst, *mirTypeSrc, nodeOpnd); return expr; @@ -2662,12 +2716,6 @@ void FEIRExprBinary::SetExprTypeByOpLogic() { } void FEIRExprBinary::SetExprTypeByOpCompare() { - PrimType primTypeOpnd0 = opnd0->GetPrimType(); - PrimType primTypeOpnd1 = opnd1->GetPrimType(); - CHECK_FATAL(primTypeOpnd0 == primTypeOpnd1 || - (opnd0->GetKind() == kExprConst && static_cast(opnd0.get())->GetValue().u64 == 0) || - (opnd1->GetKind() == kExprConst && static_cast(opnd1.get())->GetValue().u64 == 0), - "primtype of opnds must be the same"); if (op == OP_cmp || op == OP_cmpl || op == OP_cmpg) { type->SetPrimType(PTY_i32); } else { @@ -3072,14 +3120,34 @@ FEIRExprArrayStoreForC::FEIRExprArrayStoreForC(UniqueFEIRExpr argExprArray, std: SetIndexsExprs(argExprIndexs); } +FEIRExprArrayStoreForC::FEIRExprArrayStoreForC(UniqueFEIRExpr argExprArray, std::list &argExprIndexs, + UniqueFEIRType argArrayTypeNative, + UniqueFEIRExpr argExprStruct, + UniqueFEIRType argStructTypeNative) + : FEIRExpr(FEIRNodeKind::kExprArrayStoreForC), + exprArray(std::move(argExprArray)), + typeNative(std::move(argArrayTypeNative)), + exprStruct(std::move(argExprStruct)), + typeNativeStruct(std::move(argStructTypeNative)) { + SetIndexsExprs(argExprIndexs); +} + // only ArraySubscriptExpr is right value, left not need BaseNode *FEIRExprArrayStoreForC::GenMIRNodeImpl(MIRBuilder &mirBuilder) const { MIRType *ptrMIRArrayType = typeNative->GenerateMIRType(false); std::unique_ptr tmpVar = std::make_unique(exprArray->GetVarUses().front()->GetNameRaw(), typeNative->Clone()); - MIRSymbol *mirSymbol = tmpVar->GenerateLocalMIRSymbol(mirBuilder); - BaseNode *nodeAddrof = mirBuilder.CreateExprAddrof(0, *mirSymbol); std::vector nds; + uint32 fieldID = 0; + if (IsMember()) { + GStrIdx fieldNameIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName( + static_cast(exprArray.get())->GetFieldName()); + MIRType *ptrMIRStructType = typeNativeStruct->GenerateMIRType(false); + MIRStructType* mirStructType = static_cast(ptrMIRStructType); + FEManager::GetMIRBuilder().TraverseToNamedField(*mirStructType, fieldNameIdx, fieldID); + } + MIRSymbol *mirSymbol = tmpVar->GenerateLocalMIRSymbol(mirBuilder); + BaseNode *nodeAddrof = mirBuilder.CreateExprAddrof(fieldID, *mirSymbol); nds.push_back(nodeAddrof); for (auto &e : exprIndexs) { BaseNode *no = e->GenMIRNode(mirBuilder); @@ -3100,6 +3168,12 @@ std::unique_ptr FEIRExprArrayStoreForC::CloneImpl() const { return expr; } +PrimType FEIRExprArrayStoreForC::GetPrimTypeImpl() const { + CHECK_NULL_FATAL(typeNative); + MIRType *ptrMIRArrayType = typeNative->GenerateMIRType(false); + return static_cast(ptrMIRArrayType)->GetElemType()->GetPrimType(); +} + // ---------- FEIRExprArrayLoad ---------- FEIRExprArrayLoad::FEIRExprArrayLoad(UniqueFEIRExpr argExprArray, UniqueFEIRExpr argExprIndex, UniqueFEIRType argTypeArray) diff --git a/src/mplfe/common/src/feir_type.cpp b/src/mplfe/common/src/feir_type.cpp index 9a5e08ea89f04012278ec1c60aa1f93232578e69..2726357ec381a7f5fb74ffc4e0b229e70bf9cbeb 100644 --- a/src/mplfe/common/src/feir_type.cpp +++ b/src/mplfe/common/src/feir_type.cpp @@ -456,7 +456,7 @@ PrimType FEIRTypeNative::GetPrimTypeImpl() const { } void FEIRTypeNative::SetPrimTypeImpl(PrimType pt) { - CHECK_FATAL(false, "Should not get here"); + mirType.SetPrimType(pt); } void FEIRTypeNative::CopyFromImpl(const FEIRType &type) { diff --git a/src/mrt/deplibs/libmplandroid.so b/src/mrt/deplibs/libmplandroid.so index 48552d4c7d630b5a718984b1cd2a20c40f042154..69ce02e3388c0780bc66cfed65f426cc7e61ec6c 100755 Binary files a/src/mrt/deplibs/libmplandroid.so and b/src/mrt/deplibs/libmplandroid.so differ diff --git a/third_party/llvm-10.0.0.src b/third_party/llvm-10.0.0.src new file mode 120000 index 0000000000000000000000000000000000000000..ca7c8cf6bf2fe8695021acaceb71951271d42245 --- /dev/null +++ b/third_party/llvm-10.0.0.src @@ -0,0 +1 @@ +../../ThirdParty/llvm-10.0.0.src \ No newline at end of file