diff --git a/ecmascript/compiler/codegen/maple/BUILD.gn b/ecmascript/compiler/codegen/maple/BUILD.gn index 911f21b9c728d35e40b5acf61af5bf607934d09d..965bde60364aa89633a628b1dc1a66d22c477d10 100644 --- a/ecmascript/compiler/codegen/maple/BUILD.gn +++ b/ecmascript/compiler/codegen/maple/BUILD.gn @@ -86,12 +86,9 @@ config("mapleallcompilecfg") { cflags_cc += [ "-fno-stack-protector" ] } - if (TARGET == "aarch64") { - cflags_cc += [ "-DTARGAARCH64" ] - } - - if (TARGET == "x86_64") { + if (TARGET == "aarch64" || TARGET == "x86_64") { cflags_cc += [ "-DTARGX86_64" ] + cflags_cc += [ "-DTARGAARCH64" ] } if (TARGET == "riscv64") { diff --git a/ecmascript/compiler/codegen/maple/maple_be/BUILD.gn b/ecmascript/compiler/codegen/maple/maple_be/BUILD.gn index 2527d7b885fb50cdebaf0813ebf335f073988f84..e4279f5c2b0d368d2109da7678f85ff3219860a4 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/BUILD.gn +++ b/ecmascript/compiler/codegen/maple/maple_be/BUILD.gn @@ -44,29 +44,21 @@ deps_libcg = [ deps_libmplbe = [ ":libcglowerer" ] -if (TARGET == "aarch64") { +if (TARGET == "aarch64" || TARGET == "x86_64") { include_directories += [ + "${MAPLEALL_ROOT}/maple_be/include/cg/x86_64", + "${MAPLEALL_ROOT}/maple_be/include/be/x86_64", "${MAPLEALL_ROOT}/maple_be/include/cg/aarch64", "${MAPLEALL_ROOT}/maple_be/include/be/aarch64", ] deps_libcg += [ + ":libcgx8664", ":libcgaarch64", ":libcgphases", "${MAPLEALL_ROOT}/maple_driver:libmaple_driver", ] } -if (TARGET == "x86_64") { - include_directories += [ - "${MAPLEALL_ROOT}/maple_be/include/cg/x86_64", - "${MAPLEALL_ROOT}/maple_be/include/be/x86_64", - ] - deps_libcg += [ - ":libcgx8664", - ":libcgx86phases", - ] -} - if (TARGET == "riscv64") { include_directories += [ "${MAPLEALL_ROOT}/maple_be/include/cg/riscv64", @@ -98,6 +90,7 @@ src_libmplbe = [ ] src_libcgaarch64 = [ + "src/cg/aarch64/aarch64_targetinfo.cpp", "src/cg/aarch64/aarch64_abi.cpp", "src/cg/aarch64/aarch64_call_conv.cpp", "src/cg/aarch64/mpl_atomic.cpp", @@ -151,6 +144,7 @@ src_libcgx86phases = [ ] src_libcgx8664 = [ + "src/cg/x86_64/x64_targetinfo.cpp", "src/cg/x86_64/x64_cg.cpp", "src/cg/x86_64/x64_MPIsel.cpp", "src/cg/x86_64/x64_cgfunc.cpp", @@ -270,6 +264,8 @@ src_libcg = [ "src/cg/cg_phasemanager.cpp", "src/litecg/litecg.cpp", "src/litecg/lmir_builder.cpp", + "src/cg/target_registry.cpp", + "src/cg/target_select.cpp", ] ohos_static_library("libmplad") { diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_args.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_args.h index 4c183c11799aab1d2ed2ab1939e5175dcc5abb09..89bdbc8335e28c735967f79aff8956547bf60c60 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_args.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_args.h @@ -22,7 +22,7 @@ namespace maplebe { using namespace maple; -struct ArgInfo { +struct AArch64ArgInfo { AArch64reg reg; MIRType *mirTy; uint32 symSize; @@ -48,13 +48,13 @@ private: void CollectRegisterArgs(std::map &argsList, std::vector &indexList, std::map &pairReg, std::vector &numFpRegs, std::vector &fpSize) const; - ArgInfo GetArgInfo(std::map &argsList, std::vector &numFpRegs, + AArch64ArgInfo GetArgInfo(std::map &argsList, std::vector &numFpRegs, std::vector &fpSize, uint32 argIndex) const; - bool IsInSameSegment(const ArgInfo &firstArgInfo, const ArgInfo &secondArgInfo) const; - void GenOneInsn(const ArgInfo &argInfo, RegOperand &baseOpnd, uint32 stBitSize, AArch64reg dest, + bool IsInSameSegment(const AArch64ArgInfo &firstArgInfo, const AArch64ArgInfo &secondArgInfo) const; + void GenOneInsn(const AArch64ArgInfo &argInfo, RegOperand &baseOpnd, uint32 stBitSize, AArch64reg dest, int32 offset) const; - void GenerateStpInsn(const ArgInfo &firstArgInfo, const ArgInfo &secondArgInfo); - void GenerateStrInsn(const ArgInfo &argInfo, AArch64reg reg2, uint32 numFpRegs, uint32 fpSize); + void GenerateStpInsn(const AArch64ArgInfo &firstArgInfo, const AArch64ArgInfo &secondArgInfo); + void GenerateStrInsn(const AArch64ArgInfo &argInfo, AArch64reg reg2, uint32 numFpRegs, uint32 fpSize); void MoveRegisterArgs(); void MoveVRegisterArgs(); void MoveLocalRefVarToRefLocals(MIRSymbol &mirSym) const; diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_cg.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_cg.h index 185f4ab950fb5aa71a9d58d68687e561b73f5dcd..b0045867b7b10fb055ca4c92f6d598fc45c99002 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_cg.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_cg.h @@ -29,6 +29,8 @@ #include "aarch64_validbit_opt.h" #include "aarch64_reg_coalesce.h" #include "aarch64_cfgo.h" +#include "aarch64_peep.h" +#include "aarch64_proepilog.h" namespace maplebe { constexpr int64 kShortBRDistance = (8 * 1024); @@ -38,98 +40,6 @@ constexpr uint32 kAlignPseudoSize = 3; constexpr uint32 kInsnSize = 4; constexpr uint32 kAlignMovedFlag = 31; -/* Supporting classes for GCTIB merging */ -class GCTIBKey { -public: - GCTIBKey(MapleAllocator &allocator, uint32 rcHeader, std::vector &patternWords) - : header(rcHeader), bitMapWords(allocator.Adapter()) - { - (void)bitMapWords.insert(bitMapWords.begin(), patternWords.begin(), patternWords.end()); - } - - ~GCTIBKey() = default; - - uint32 GetHeader() const - { - return header; - } - - const MapleVector &GetBitmapWords() const - { - return bitMapWords; - } - -private: - uint32 header; - MapleVector bitMapWords; -}; - -class Hasher { -public: - size_t operator()(const GCTIBKey *key) const - { - CHECK_NULL_FATAL(key); - size_t hash = key->GetHeader(); - return hash; - } -}; - -class EqualFn { -public: - bool operator()(const GCTIBKey *firstKey, const GCTIBKey *secondKey) const - { - CHECK_NULL_FATAL(firstKey); - CHECK_NULL_FATAL(secondKey); - const MapleVector &firstWords = firstKey->GetBitmapWords(); - const MapleVector &secondWords = secondKey->GetBitmapWords(); - - if ((firstKey->GetHeader() != secondKey->GetHeader()) || (firstWords.size() != secondWords.size())) { - return false; - } - - for (size_t i = 0; i < firstWords.size(); ++i) { - if (firstWords[i] != secondWords[i]) { - return false; - } - } - return true; - } -}; - -class GCTIBPattern { -public: - GCTIBPattern(GCTIBKey &patternKey, MemPool &mp) : name(&mp) - { - key = &patternKey; - id = GetId(); - name = GCTIB_PREFIX_STR + std::string("PTN_") + std::to_string(id); - } - - ~GCTIBPattern() = default; - - int GetId() const - { - static int id = 0; - return id++; - } - - std::string GetName() const - { - DEBUG_ASSERT(!name.empty(), "null name check!"); - return std::string(name.c_str()); - } - - void SetName(const std::string &ptnName) - { - name = ptnName; - } - -private: - int id; - MapleString name; - GCTIBKey *key; -}; - /* sub Target info & implement */ class AArch64CG : public CG { public: @@ -180,6 +90,14 @@ public: { return mp.New(f, mp); } + GenProEpilog *CreateGenProEpilog(CGFunc &f, MemPool &mp, MemPool *tempMemPool = nullptr) const override + { + return mp.New(f, *tempMemPool); + } + CGPeepHole *CreateCGPeepHole(MemPool &mp, CGFunc &f) const override + { + return mp.New(f, &mp); + } MoveRegArgs *CreateMoveRegArgs(MemPool &mp, CGFunc &f) const override { return mp.New(f); diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_cgfunc.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_cgfunc.h index 8bcab4f7649d7e8cd6aba2e8739c6c8f17e82599..555b77deb76d9d56d2c195af40a987af1c11b75b 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_cgfunc.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_cgfunc.h @@ -559,7 +559,7 @@ public: /* npairs = num / 2 + num % 2 */ uint32 nPairs = (numIntregToCalleeSave >> 1) + (numIntregToCalleeSave & 0x1); nPairs += (numFpregToCalleeSave >> 1) + (numFpregToCalleeSave & 0x1); - return (nPairs * (kIntregBytelen << 1)); + return (nPairs * (kAarch64IntregBytelen << 1)); } void DBGFixCallFrameLocationOffsets() override; diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_isa.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_isa.h index c78b8d7af384facda70b914c1e5497d596f7d58a..55e5b8e84e8bb91fb94fed6c23b32428adb97282 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_isa.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_isa.h @@ -33,10 +33,10 @@ namespace maplebe { */ constexpr int kAarch64StackPtrAlignment = 16; -constexpr int32 kOffsetAlign = 8; -constexpr uint32 kIntregBytelen = 8; /* 64-bit */ -constexpr uint32 kFpregBytelen = 8; /* only lower 64 bits are used */ -constexpr int kSizeOfFplr = 16; +constexpr int32 kAarch64OffsetAlign = 8; +constexpr uint32 kAarch64IntregBytelen = 8; /* 64-bit */ +constexpr uint32 kAarch64FpregBytelen = 8; /* only lower 64 bits are used */ +constexpr int kAarch64SizeOfFplr = 16; enum StpLdpImmBound : int { kStpLdpImm64LowerBound = -512, @@ -175,6 +175,11 @@ int64 GetMemOpndOffsetValue(Operand *o); int32 GetTail0BitNum(int64 val); int32 GetHead0BitNum(int64 val); + +inline void GetNextOffsetCalleeSaved(int &offset) +{ + offset += (kAarch64IntregBytelen << 1); +} } /* namespace AArch64isa */ /* @@ -183,10 +188,6 @@ int32 GetHead0BitNum(int64 val); * The Stack Pointer has to be aligned at 16-byte boundary. * On AArch64, kIntregBytelen == 8 (see the above) */ -inline void GetNextOffsetCalleeSaved(int &offset) -{ - offset += (kIntregBytelen << 1); -} MOperator GetMopPair(MOperator mop, bool isIncludeStrbStrh); } /* namespace maplebe */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_peep.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_peep.h index 59c32faccb34071df7342f0e6420263d47ff98d0..f31ac74d4050eaaab0ff043b976edb5c76ef1210 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_peep.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_peep.h @@ -18,7 +18,8 @@ #include #include "peep.h" -#include "aarch64_cg.h" +#include "aarch64_isa.h" +#include "cg_ssa.h" #include "optimize_common.h" #include "mir_builder.h" diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_targetinfo.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_targetinfo.h new file mode 100644 index 0000000000000000000000000000000000000000..0177665e1b15d71c0dc4785aa2e9a6a45b51db4e --- /dev/null +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_targetinfo.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MAPLEBE_INCLUDE_CG_AARCH64TARGETINFO_H +#define MAPLEBE_INCLUDE_CG_AARCH64TARGETINFO_H + +namespace maplebe { + +class Target; + +Target &getTheAArch64Target(); + +} + +#endif diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_targetmachine.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_targetmachine.h new file mode 100644 index 0000000000000000000000000000000000000000..95d05dafea5e29a2cbce7870e9bc3b098a3afb9a --- /dev/null +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/aarch64/aarch64_targetmachine.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MAPLEBE_INCLUDE_AARCH64_TARGET_MACHINE_H +#define MAPLEBE_INCLUDE_AARCH64_TARGET_MACHINE_H +#include "aarch64_targetinfo.h" +#include "target_registry.h" +#include "target_machine.h" +#include +namespace maplebe { +class AArch64TargetMachine : public TargetMachine { +public: + AArch64TargetMachine() : TargetMachine(kAArch64) {} +}; +} +#endif /* MAPLEBE_INCLUDE_AARCH64_TARGET_MACHINE_H */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg.h index a8350679f09a1cef09f083c9e833cf021c03f000..0bacc31734ebd62c6a16ae52306f9c82783f4038 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg.h @@ -29,6 +29,8 @@ #include "global_tables.h" #include "mir_function.h" #include "mad.h" +#include "target_machine.h" +#include "proepilog.h" namespace maplebe { #define ADDTARGETPHASE(PhaseName, condition) \ @@ -50,6 +52,8 @@ class ValidBitOpt; class CG; class LocalOpt; class CFGOptimizer; +class CGPeepHole; +class GenProEpilog; class Globals { public: @@ -112,6 +116,98 @@ private: Globals() = default; }; +class GCTIBKey { +public: + GCTIBKey(MapleAllocator &allocator, uint32 rcHeader, const std::vector &patternWords) + : header(rcHeader), + bitMapWords(allocator.Adapter()) + { + (void)bitMapWords.insert(bitMapWords.cbegin(), patternWords.cbegin(), patternWords.cend()); + } + + ~GCTIBKey() = default; + + uint32 GetHeader() const + { + return header; + } + + const MapleVector &GetBitmapWords() const + { + return bitMapWords; + } + +private: + uint32 header; + MapleVector bitMapWords; +}; + +class Hasher { +public: + size_t operator()(const GCTIBKey *key) const + { + CHECK_NULL_FATAL(key); + size_t hash = key->GetHeader(); + return hash; + } +}; + +class EqualFn { +public: + bool operator()(const GCTIBKey *firstKey, const GCTIBKey *secondKey) const + { + CHECK_NULL_FATAL(firstKey); + CHECK_NULL_FATAL(secondKey); + const MapleVector &firstWords = firstKey->GetBitmapWords(); + const MapleVector &secondWords = secondKey->GetBitmapWords(); + + if ((firstKey->GetHeader() != secondKey->GetHeader()) || (firstWords.size() != secondWords.size())) { + return false; + } + + for (size_t i = 0; i < firstWords.size(); ++i) { + if (firstWords[i] != secondWords[i]) { + return false; + } + } + return true; + } +}; + +class GCTIBPattern { +public: + GCTIBPattern(GCTIBKey &patternKey, MemPool &mp) + : name(&mp) + { + key = &patternKey; + id = GetId(); + name = GCTIB_PREFIX_STR + std::string("PTN_") + std::to_string(id); + } + + ~GCTIBPattern() = default; + + int GetId() const + { + static int createNum = 0; + return createNum++; + } + + std::string GetName() const + { + return std::string(name.c_str()); + } + + void SetName(const std::string &ptnName) + { + name = ptnName; + } + +private: + int id = 0; + MapleString name; + GCTIBKey *key = nullptr; +}; + class CG { public: using GenerateFlag = uint64; @@ -285,6 +381,16 @@ public: return mirModule; } + void SetTargetMachine(TargetMachine &targetMachine) + { + this->targetMachine = &targetMachine; + } + + TargetMachine *GetTargetMachine() const + { + return targetMachine; + } + void IncreaseLabelOrderCnt() { labelOrderCnt++; @@ -349,6 +455,8 @@ public: { return nullptr; }; + virtual GenProEpilog *CreateGenProEpilog(CGFunc &func, MemPool &mp, MemPool *tempMemPool = nullptr) const = 0; + virtual CGPeepHole *CreateCGPeepHole(MemPool &mp, CGFunc &f) const = 0; virtual MoveRegArgs *CreateMoveRegArgs(MemPool &mp, CGFunc &f) const { return nullptr; @@ -457,6 +565,7 @@ protected: private: MIRModule *mirModule; Emitter *emitter; + TargetMachine *targetMachine = nullptr; LabelIDOrder labelOrderCnt; static CGFunc *currentCGFunction; /* current cg function being compiled */ CGOptions cgOption; diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_option.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_option.h index 52070bf2925dc1e473da2db4a093f03516f42d3c..b269a53036e217a4ddddbb3a23873468683d3754 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_option.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_option.h @@ -997,6 +997,11 @@ public: return targetArch == "x86_64"; }; + static bool IsTargetAArch64() + { + return targetArch == "aarch64"; + }; + static void EnableVregRename() { doVregRename = true; diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_options.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_options.h index 6aca1170d88c8d1a6d8d7c774472b631cc83be35..ebe4d75f0600814410c413e59d4c31c076229c11 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_options.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_options.h @@ -114,6 +114,7 @@ extern maplecl::Option bruteforceSchedule; extern maplecl::Option simulateSchedule; extern maplecl::Option crossLoc; extern maplecl::Option floatAbi; +extern maplecl::Option archType; extern maplecl::Option filetype; extern maplecl::Option longCalls; extern maplecl::Option functionSections; diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_phasemanager.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_phasemanager.h index 72c5261bb676825ffe91f5eb3e410dad30728e77..b9dcf03da0637cc1d9f154412674b707213dbc1b 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_phasemanager.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg_phasemanager.h @@ -27,6 +27,8 @@ #include "cgfunc.h" #include "cg_phase.h" #include "cg_option.h" +#include "target_select.h" +#include "target_registry.h" namespace maplebe { using cgFuncOptTy = MapleFunctionPhase; @@ -64,7 +66,7 @@ public: private: bool FuncLevelRun(CGFunc &cgFunc, AnalysisDataManager &serialADM); void GenerateOutPutFile(MIRModule &m); - void CreateCGAndBeCommon(MIRModule &m); + void CreateCGAndBeCommon(MIRModule &m, const Target *T); void PrepareLower(MIRModule &m); void PostOutPut(MIRModule &m); void DoFuncCGLower(const MIRModule &m, MIRFunction &mirFunc); diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cgfunc.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cgfunc.h index a77842f57968002e213a9a98aec3a1499470ac76..ec453b799a0ad3b52dfcb69ca0872212ffa5733f 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cgfunc.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cgfunc.h @@ -36,6 +36,7 @@ /* Maple MP header */ #include "mempool_allocator.h" +#include "triple.h" namespace maplebe { constexpr int32 kBBLimit = 100000; @@ -511,10 +512,12 @@ public: size = k4ByteSize; } #if TARGAARCH64 + if (Triple::GetTriple().GetArch() == Triple::ArchType::aarch64) { /* cannot handle 128 size register */ if (regType == kRegTyInt && size > k8ByteSize) { size = k8ByteSize; } + } #endif DEBUG_ASSERT(size == k4ByteSize || size == k8ByteSize || size == k16ByteSize, "check size"); #endif @@ -580,17 +583,13 @@ public: return vRegTable[rNum].GetType(); } -#if TARGX86_64 - uint32 GetMaxVReg() const - { - return vRegCount + opndBuilder->GetCurrentVRegNum(); - } -#else uint32 GetMaxVReg() const { + if (Triple::GetTriple().GetArch() == Triple::ArchType::x64) { + return vRegCount + opndBuilder->GetCurrentVRegNum(); + } return vRegCount; } -#endif uint32 GetSSAvRegCount() const { diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/target_machine.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/target_machine.h new file mode 100644 index 0000000000000000000000000000000000000000..4c699a31c19041039e8a9e45e66c873bcf3e7706 --- /dev/null +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/target_machine.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MAPLEBE_INCLUDE_TARGET_MACHINE_H +#define MAPLEBE_INCLUDE_TARGET_MACHINE_H +#include "types_def.h" +#include "cg.h" +#include "target_registry.h" + +namespace maplebe { +using namespace maple; +enum TargetKind : uint8 { + kAArch64, + kX8664, + kRiscV, + kArm32, + kArk +}; + +class TargetMachine { +public: + TargetMachine(TargetKind kind) : kind(kind) {} + bool isAArch64() + { + return kind == kAArch64; + } + + bool isX8664() + { + return kind == kX8664; + } + + bool isRiscV() + { + return kind == kRiscV; + } + + bool isArm32() + { + return kind == kArm32; + } + + bool isArk() + { + return kind == kArk; + } + +private: + TargetKind kind; +}; +} /* namespace maplebe */ + +#endif /* MAPLEBE_INCLUDE_TARGET_MACHINE_H */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/target_registry.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/target_registry.h new file mode 100644 index 0000000000000000000000000000000000000000..799abac4c3f011fe81690fd91ec05dfdfcdc337e --- /dev/null +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/target_registry.h @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MAPLEBE_INCLUDE_TARGET_REGISTRY_H +#define MAPLEBE_INCLUDE_TARGET_REGISTRY_H +#include "types_def.h" +#include "cg.h" +#if TARGX86_64 +#include "x86_64/assembler/assembler.h" +#endif +#include "target_machine.h" +#include "mempool.h" + + +namespace maplebe { +using namespace maple; +class TargetMachine; +class Target { +using CGCtorFnTy = CG *(*)(MIRModule &mod, const CGOptions &opts, const std::vector &nameVec, + const std::unordered_map> &patternMap); +using EmitterCtorFnTy = std::function; +#if TARGX86_64 +using DecoupledEmitterCtorFnTy = std::function; +#endif +using TargetMachineCtorFnTy = std::function; +friend struct TargetRegistry; + +public: + Target() = default; + + const Target *getNext() const + { + return next; + } + + const std::string getName() const + { + return name; + } + + CG *createCG(MIRModule &mod, const CGOptions &opts, const std::vector &nameVec, + const std::unordered_map> &patternMap) const + { + if (!CGCtorFn) { + return nullptr; + } + return CGCtorFn(mod, opts, nameVec, patternMap); + } + + Emitter *createEmitter(CG &cg, const std::string &asmFileName) const + { + if (!EmitterCtorFn) { + return nullptr; + } + return EmitterCtorFn(cg, asmFileName); + } + +#if TARGX86_64 + Emitter *createDecoupledEmitter(CG &cg, assembler::Assembler &newAssembler) const + { + if (!DecoupedEmitterCtorFn) { + return nullptr; + } + return DecoupedEmitterCtorFn(cg, newAssembler); + } +#endif + TargetMachine *createTargetMachine() const + { + if (!TargetMachineCtorFn) { + return nullptr; + } + return TargetMachineCtorFn(); + } + +private: + // Next - The next registered target in the linked list, maintained by the + // TargetRegistry. + Target *next = nullptr; + // Name - The target name. + std::string name; + // Construction function for this target's CG, if + // registered (default = nullptr). + CGCtorFnTy CGCtorFn; + // Construction function for this target's Emitter, if + // registered (default = nullptr). + EmitterCtorFnTy EmitterCtorFn; +#if TARGX86_64 + // Construction function for this target's DecoupledEmitter, if + // registered (default = nullptr). + DecoupledEmitterCtorFnTy DecoupedEmitterCtorFn; +#endif + // Construction function for this target's TargetMachine, if + // registered (default = nullptr). + TargetMachineCtorFnTy TargetMachineCtorFn; +}; + +struct TargetRegistry { + TargetRegistry() = delete; + static void RegisterTarget(Target &t, const std::string name); + static Target *lookupTarget(const std::string &targetName); + + static void RegisterCGFunc(Target &t, Target::CGCtorFnTy Fn) + { + t.CGCtorFn = Fn; + } + + static void RegisterEmitter(Target &t, Target::EmitterCtorFnTy Fn) + { + t.EmitterCtorFn = Fn; + } +#if TARGX86_64 + static void RegisterDecoupledEmitter(Target &t, Target::DecoupledEmitterCtorFnTy Fn) + { + t.DecoupedEmitterCtorFn = Fn; + } +#endif + static void RegisterTargetMachine(Target &t, Target::TargetMachineCtorFnTy Fn) + { + t.TargetMachineCtorFn = Fn; + } +}; + + +struct RegisterTarget { + RegisterTarget(Target &t, const std::string name) + { + TargetRegistry::RegisterTarget(t, name); + } +}; + +template +struct RegisterCGFUnc { + RegisterCGFUnc(Target &T) + { + TargetRegistry::RegisterCGFunc(T, &Allocator); + } + +private: + static CG *Allocator(MIRModule &mod, const CGOptions &opts, const std::vector &nameVec, + const std::unordered_map> &patternMap) + { + return new CGImpl(mod, opts, nameVec, patternMap); + } +}; + +template +struct RegisterEmitter { + RegisterEmitter(Target &T, MemPool *m) + { + std::function Allocator = [m](CG &cg, const std::string &asmFileName) { + return m->New(cg, asmFileName); + }; + TargetRegistry::RegisterEmitter(T, Allocator); + } +}; + +#if TARGX86_64 +template +struct RegisterDecoupledEmitter { + RegisterDecoupledEmitter(Target &T, MemPool *m) + { + std::function Allocator = [m](CG &cg, + assembler::Assembler &newAssembler) { + return m->New(cg, newAssembler); + }; + TargetRegistry::RegisterDecoupledEmitter(T, Allocator); + } +}; +#endif + +template +struct RegisterTargetMachine { + RegisterTargetMachine(Target &T, MemPool *m) + { + std::function Allocator = [m]() { + return m->New(); + }; + TargetRegistry::RegisterTargetMachine(T, Allocator); + } +}; + +} /* namespace maplebe */ + +#endif /* MAPLEBE_INCLUDE_TARGET_REGISTRY_H */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/target_select.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/target_select.h new file mode 100644 index 0000000000000000000000000000000000000000..2f27985979cd4a5222028333121341b0c77522ac --- /dev/null +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/target_select.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MAPLEBE_INCLUDE_TARGET_SELECT_H +#define MAPLEBE_INCLUDE_TARGET_SELECT_H +#include "mempool.h" +#include "mempool_allocator.h" + +extern "C" { + // Declare all of the target-initialization functions that are available. +#define MAPLE_TARGET(TargetName) void MAPLEInitialize##TargetName##TargetInfo(maple::MemPool * m) +MAPLE_TARGET(AArch64); +MAPLE_TARGET(X64); +#undef MAPLE_TARGET + +#define MAPLE_TARGET(TargetName) void MAPLEInitialize##TargetName##Target() +MAPLE_TARGET(AArch64); +MAPLE_TARGET(X64); +#undef MAPLE_TARGET +} + +static inline void InitializeAllTargetInfos(maple::MemPool * m) +{ + #define MAPLE_TARGET(TargetName) MAPLEInitialize##TargetName##TargetInfo(m) + MAPLE_TARGET(AArch64); + MAPLE_TARGET(X64); + #undef MAPLE_TARGET +} + +static inline void InitializeAllTargets() +{ + #define MAPLE_TARGET(TargetName) MAPLEInitialize##TargetName##Target() + MAPLE_TARGET(AArch64); + MAPLE_TARGET(X64); + #undef MAPLE_TARGET +} +#endif diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/targets.def b/ecmascript/compiler/codegen/maple/maple_be/include/cg/targets.def new file mode 100644 index 0000000000000000000000000000000000000000..0878fc39d0234a8366cf80f0add0fd26f3c9686d --- /dev/null +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/targets.def @@ -0,0 +1,6 @@ +#ifndef MAPLE_TARGET +# error +#endif +MAPLE_TARGET(AArch64); +MAPLE_TARGET(X64); +#undef MAPLE_TARGET diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/assembler/operand.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/assembler/operand.h index 630599437588a5bab1afd1ffbb8de6f1c78ec2e4..3f52fd73ab21a427cd435c358b660fbe28e4fbfd 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/assembler/operand.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/assembler/operand.h @@ -18,6 +18,7 @@ #include #include +#include #include "util.h" namespace assembler { diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_args.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_args.h index 7398efd0a3a999651acfb5712663608f6be2ae70..116ebabf4732a81bcac548784138bb4a51e4ba52 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_args.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_args.h @@ -24,8 +24,7 @@ namespace maplebe { using namespace maple; using namespace x64; - -struct ArgInfo { +struct X64ArgInfo { X64reg reg; MIRType *mirTy; uint32 symSize; @@ -48,9 +47,9 @@ private: void CollectRegisterArgs(std::map &argsList, std::vector &indexList, std::map &pairReg, std::vector &numFpRegs, std::vector &fpSize) const; - ArgInfo GetArgInfo(std::map &argsList, uint32 argIndex, std::vector &numFpRegs, + X64ArgInfo GetArgInfo(std::map &argsList, uint32 argIndex, std::vector &numFpRegs, std::vector &fpSize) const; - void GenerateMovInsn(ArgInfo &argInfo, X64reg reg2); + void GenerateMovInsn(X64ArgInfo &argInfo, X64reg reg2); void MoveRegisterArgs(); void MoveVRegisterArgs(); void LoadStackArgsToVReg(MIRSymbol &mirSym); diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_call_conv.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_call_conv.h index 904fb0b8393f9d1ac8cf7e3d3ac5fde3dc807b2f..a02bfc1a32deb14762bb92edf9dfccc21a3b5cff 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_call_conv.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_call_conv.h @@ -96,26 +96,34 @@ public: ; CALL_CONVENTION_INFO_SUBCLASS_DECLARE_BEGIN(WebKitJSCallConventionInfo) -const std::vector intParmRegs {R0}; -const std::vector intReturnRegs {R0}; -const std::vector floatParmRegs {}; -const std::vector floatReturnRegs {}; + +const std::vector intParmRegs { + RAX}; +const std::vector intReturnRegs { + RAX}; +const std::vector floatParmRegs{}; +const std::vector floatReturnRegs{}; CALL_CONVENTION_INFO_SUBCLASS_DECLARE_END CALL_CONVENTION_INFO_SUBCLASS_DECLARE_BEGIN(CCallConventionInfo) -const std::vector intParmRegs {R7, R6, R2, R1, R8, R9}; -const std::vector intReturnRegs {R0, R2}; -const std::vector floatParmRegs {V0, V1, V2, V3, V4, V5, V6, V7}; -const std::vector floatReturnRegs {V0, V1}; +const std::vector intParmRegs { + RDI, RSI, RDX, RCX, X64reg::R8, X64reg::R9}; +const std::vector intReturnRegs { + RAX, RDX}; +const std::vector floatParmRegs = { + X64reg::V0, X64reg::V1, X64reg::V2, X64reg::V3, X64reg::V4, X64reg::V5, X64reg::V6, X64reg::V7}; +const std::vector floatReturnRegs = { + X64reg::V0, X64reg::V1 }; int32 ClassifyAggregate(MIRType &mirType, uint64 sizeOfTy, std::vector &classes) const; CALL_CONVENTION_INFO_SUBCLASS_DECLARE_END CALL_CONVENTION_INFO_SUBCLASS_DECLARE_BEGIN(GHCCallConventionInfo) -const std::vector intParmRegs {R13, RBP, R12, RBX, R14, RSI, RDI, R8, R9, R15}; -const std::vector intReturnRegs {}; -const std::vector floatParmRegs {}; -const std::vector floatReturnRegs {}; +const std::vector intParmRegs { + X64reg::R13, RBP, X64reg::R12, RBX, X64reg::R14, RSI, RDI, X64reg::R8, X64reg::R9, X64reg::R15}; +const std::vector intReturnRegs{}; +const std::vector floatParmRegs{}; +const std::vector floatReturnRegs{}; CALL_CONVENTION_INFO_SUBCLASS_DECLARE_END class X64CallConvImpl { @@ -185,7 +193,7 @@ private: X64reg AllocateGPParmRegister() { const std::vector &intParamRegs = GetCallConvInfo().GetIntParamRegs(); - return (nextGeneralParmRegNO < intParamRegs.size()) ? intParamRegs[nextGeneralParmRegNO++] : kRinvalid; + return (nextGeneralParmRegNO < intParamRegs.size()) ? intParamRegs[nextGeneralParmRegNO++] : X64reg::kRinvalid; } void AllocateTwoGPParmRegisters(CCLocInfo &pLoc) @@ -195,19 +203,20 @@ private: pLoc.reg0 = intParamRegs[nextGeneralParmRegNO++]; pLoc.reg1 = intParamRegs[nextGeneralParmRegNO++]; } else { - pLoc.reg0 = kRinvalid; + pLoc.reg0 = X64reg::kRinvalid; } } X64reg AllocateSIMDFPRegister() { - return (nextFloatRegNO < kNumFloatParmRegs) ? kFloatParmRegs[nextFloatRegNO++] : kRinvalid; + return (nextFloatRegNO < kNumFloatParmRegs) ? kFloatParmRegs[nextFloatRegNO++] : X64reg::kRinvalid; } X64reg AllocateGPReturnRegister() { const std::vector &intReturnRegs = GetCallConvInfo().GetIntReturnRegs(); - return (nextGeneralReturnRegNO < intReturnRegs.size()) ? intReturnRegs[nextGeneralReturnRegNO++] : kRinvalid; + return (nextGeneralReturnRegNO < intReturnRegs.size()) ? + intReturnRegs[nextGeneralReturnRegNO++] : X64reg::kRinvalid; } void AllocateTwoGPReturnRegisters(CCLocInfo &pLoc) @@ -217,14 +226,14 @@ private: pLoc.reg0 = intReturnRegs[nextGeneralReturnRegNO++]; pLoc.reg1 = intReturnRegs[nextGeneralReturnRegNO++]; } else { - pLoc.reg0 = kRinvalid; + pLoc.reg0 = X64reg::kRinvalid; } } X64reg AllocateSIMDFPReturnRegister() { return (nextFloatRetRegNO < kNumFloatReturnRegs) ? - kFloatReturnRegs[nextFloatRetRegNO++] : kRinvalid; + kFloatReturnRegs[nextFloatRetRegNO++] : X64reg::kRinvalid; } BECommon &beCommon; diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_cg.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_cg.h index a9490a8b89725cc30be5d810bf7d469fd49b9d24..3711672a9b54da50db247f0e0775d67f92d5d3bd 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_cg.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_cg.h @@ -26,13 +26,19 @@ #include "x64_args.h" #include "x64_local_opt.h" #include "x64_cfgo.h" +#include "x64_peep.h" +#include "x64_proepilog.h" namespace maplebe { -constexpr int32 kIntRegTypeNum = 5; - class X64CG : public CG { public: - X64CG(MIRModule &mod, const CGOptions &opts) : CG(mod, opts) {} + X64CG(MIRModule &mod, const CGOptions &opts, const std::vector &nameVec, + const std::unordered_map> &patternMap) + : CG(mod, opts), + ehExclusiveNameVec(nameVec), + cyclePatternMap(patternMap), + keyPatternMap(allocator.Adapter()), + symbolPatternMap(allocator.Adapter()) {} static const InsnDesc kMd[x64::kMopLast]; void EnrollTargetPhases(MaplePhaseManager *pm) const override; @@ -47,6 +53,14 @@ public: { return mp.New(f, mp); } + CGPeepHole *CreateCGPeepHole(MemPool &mp, CGFunc &f) const override + { + return mp.New(f, &mp); + } + virtual GenProEpilog *CreateGenProEpilog(CGFunc &f, MemPool &mp, MemPool *tempMemPool = nullptr) const override + { + return mp.New(f); + } LocalOpt *CreateLocalOpt(MemPool &mp, CGFunc &f, ReachingDefinition &rd) const override { return mp.New(mp, f, rd); @@ -84,6 +98,14 @@ public: /* NOTE: Consider making be_common a field of CG. */ void GenerateObjectMaps(BECommon &beCommon) override; + + void DoNothing() + { + (void)ehExclusiveNameVec; + (void)cyclePatternMap; + (void)keyPatternMap; + (void)symbolPatternMap; + } /* Used for GCTIB pattern merging */ std::string FindGCTIBPatternName(const std::string &name) const override; @@ -97,6 +119,11 @@ public: { return kMd[mOp]; } +private: + const std::vector &ehExclusiveNameVec; + const std::unordered_map> &cyclePatternMap; + MapleUnorderedMap keyPatternMap; + MapleUnorderedMap symbolPatternMap; }; } // namespace maplebe #endif /* MAPLEBE_INCLUDE_CG_X86_64_CG_H */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_cgfunc.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_cgfunc.h index d3d2c57a0464c8e3e278baf37525caaf2f7c6334..a0521f6d4d1031381c8c00d1059f3ac5f96f024c 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_cgfunc.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_cgfunc.h @@ -251,7 +251,7 @@ public: uint32 SizeOfCalleeSaved() const { - uint32 size = numIntregToCalleeSave * kIntregBytelen + numFpregToCalleeSave * kFpregBytelen; + uint32 size = numIntregToCalleeSave * kX64IntregBytelen + numFpregToCalleeSave * kX64FpregBytelen; return RoundUp(size, GetMemlayout()->GetStackPtrAlignment()); } diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_isa.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_isa.h index d8b993b2992f1ed075f04b1739eb4fcc33801b5b..b57bd0c95569cd1514e977091c76934b3ae6bbdc 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_isa.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_isa.h @@ -26,10 +26,10 @@ namespace maplebe { */ constexpr int kX64StackPtrAlignment = 16; -constexpr int32 kOffsetAlign = 8; -constexpr uint32 kIntregBytelen = 8; /* 64-bit */ -constexpr uint32 kFpregBytelen = 8; /* only lower 64 bits are used */ -constexpr int kSizeOfFplr = 16; +constexpr int32 kX64OffsetAlign = 8; +constexpr uint32 kX64IntregBytelen = 8; /* 64-bit */ +constexpr uint32 kX64FpregBytelen = 8; /* only lower 64 bits are used */ +constexpr int kX64SizeOfFplr = 16; class Insn; @@ -120,11 +120,11 @@ MOperator FlipConditionOp(MOperator flippedOp); * We save callee-saved registers from lower stack area to upper stack area. * If possible, we store a pair of registers (int/int and fp/fp) in the stack. * The Stack Pointer has to be aligned at 16-byte boundary. - * On X64, kIntregBytelen == 8 (see the above) + * On X64, kX64IntregBytelen == 8 (see the above) */ inline void GetNextOffsetCalleeSaved(int &offset) { - offset += (kIntregBytelen << 1); + offset += (kX64IntregBytelen << 1); } } /* namespace maplebe */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_local_opt.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_local_opt.h index 00d044051c2712484dbc702d2c4edcdbd47755bb..c0bd44762d027d6dd869bda169d182424df4271a 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_local_opt.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_local_opt.h @@ -27,10 +27,10 @@ private: void DoLocalCopyProp() override; }; -class CopyRegProp : public LocalPropOptimizePattern { +class LocalCopyRegProp : public LocalPropOptimizePattern { public: - CopyRegProp(CGFunc &cgFunc, ReachingDefinition &rd) : LocalPropOptimizePattern(cgFunc, rd) {} - ~CopyRegProp() override = default; + LocalCopyRegProp (CGFunc &cgFunc, ReachingDefinition &rd) : LocalPropOptimizePattern(cgFunc, rd) {} + ~LocalCopyRegProp () override = default; bool CheckCondition(Insn &insn) final; void Optimize(BB &bb, Insn &insn) final; diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_peep.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_peep.h index f637054c3e8db4ac542175a8d0c801d3c0f92032..1e8ea31f9c6dcd73414c202202c4982929e0e88a 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_peep.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_peep.h @@ -20,7 +20,7 @@ #include "peep.h" namespace maplebe { -class X64CGPeepHole : CGPeepHole { +class X64CGPeepHole : public CGPeepHole { public: /* normal constructor */ X64CGPeepHole(CGFunc &f, MemPool *memPool) : CGPeepHole(f, memPool) {}; @@ -32,17 +32,18 @@ public: void DoNormalOptimize(BB &bb, Insn &insn) override; }; -class RemoveMovingtoSameRegPattern : public CGPeepPattern { +class X64RemoveMovingtoSameRegPattern : public CGPeepPattern { public: - RemoveMovingtoSameRegPattern(CGFunc &cgFunc, BB &currBB, Insn &currInsn) : CGPeepPattern(cgFunc, currBB, currInsn) + X64RemoveMovingtoSameRegPattern(CGFunc &cgFunc, + BB &currBB, Insn &currInsn) : CGPeepPattern(cgFunc, currBB, currInsn) { } - ~RemoveMovingtoSameRegPattern() override = default; + ~X64RemoveMovingtoSameRegPattern() override = default; void Run(BB &bb, Insn &insn) override; bool CheckCondition(Insn &insn) override; std::string GetPatternName() override { - return "RemoveMovingtoSameRegPattern"; + return "X64RemoveMovingtoSameRegPattern"; } }; diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_proepilog.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_proepilog.h index 1ea56d2d0d596db3b5d6683d48420b65f99f7503..c2a0474e3d51827589fd78a36e3312912dd304c0 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_proepilog.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_proepilog.h @@ -17,7 +17,6 @@ #define MAPLEBE_INCLUDE_CG_X64_X64_PROEPILOG_H #include "proepilog.h" -#include "x64_cgfunc.h" namespace maplebe { using namespace maple; diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_reg_info.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_reg_info.h index a5b08f9ef92014d2f2ba1d4d53b0bf6b22cee90f..32ac2b8a11ef9e66da5d7ace4ede80490abb6307 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_reg_info.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_reg_info.h @@ -10,7 +10,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. +* limitations under the License. */ #ifndef MAPLEBE_INCLUDE_CG_X64_X64_REG_INFO_H @@ -116,11 +116,11 @@ public: } bool IsVirtualRegister(const RegOperand ®Opnd) override { - return regOpnd.GetRegisterNumber() > kAllRegNum; + return regOpnd.GetRegisterNumber() > x64::kAllRegNum; } bool IsVirtualRegister(regno_t regno) override { - return regno > kAllRegNum; + return regno > x64::kAllRegNum; } uint32 GetReservedSpillReg() override { diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_targetinfo.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_targetinfo.h new file mode 100644 index 0000000000000000000000000000000000000000..5d8cc8cf39bf2967dd3ce8632249756b253b0a13 --- /dev/null +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_targetinfo.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MAPLEBE_INCLUDE_CG_X64TARGETINFO_H +#define MAPLEBE_INCLUDE_CG_X64TARGETINFO_H + +namespace maplebe { + +class Target; + +Target &getTheTarget(); + +} + +#endif diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_targetmachine.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_targetmachine.h new file mode 100644 index 0000000000000000000000000000000000000000..ad5506911178a9d1132f81f9b1464e1b319e6f32 --- /dev/null +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_targetmachine.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MAPLEBE_INCLUDE_X64_TARGET_MACHINE_H +#define MAPLEBE_INCLUDE_X64_TARGET_MACHINE_H +#include "target_registry.h" +#include "target_machine.h" +#include + +namespace maplebe { +class X64TargetMachine : public TargetMachine { +public: + X64TargetMachine() : TargetMachine(kX8664) {} +}; +} +#endif /* MAPLEBE_INCLUDE_X64_TARGET_MACHINE_H */ \ No newline at end of file diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/ad/mad.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/ad/mad.cpp index 0e1069a3fc9fdc8c61ba1d8da4372ca05eff248f..35af78d5460b335bcde119894487d1ce6859c3de 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/ad/mad.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/ad/mad.cpp @@ -18,7 +18,8 @@ #include #if TARGAARCH64 #include "aarch64_operand.h" -#elif defined(TARGRISCV64) && TARGRISCV64 +#endif +#if defined(TARGRISCV64) && TARGRISCV64 #include "riscv64_operand.h" #endif #include "schedule.h" diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/be/becommon.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/be/becommon.cpp index ae11f9e1474e59382cedccfa101105b33572be12..7c3c0bcebe817a8e0ef220d788011243ba439669 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/be/becommon.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/be/becommon.cpp @@ -777,10 +777,6 @@ BaseNode *BECommon::GetAddressOfNode(const BaseNode &node) MIRType *pointedType = GlobalTables::GetTypeTable().GetTypeTable().at(index); std::pair byteBitOffset = GetFieldOffset(static_cast(*pointedType), iNode.GetFieldID()); -#if TARGAARCH64 || TARGRISCV64 - DEBUG_ASSERT(GetAddressPrimType() == GetLoweredPtrType(), - "incorrect address type, expect a GetLoweredPtrType()"); -#endif return mirModule.GetMIRBuilder()->CreateExprBinary( OP_add, *GlobalTables::GetTypeTable().GetPrimType(GetAddressPrimType()), static_cast(iNode.Opnd(0)), diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/be/lower.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/be/lower.cpp index dd54ec7f57ec581a1c8f9c5a768881984eadaa79..a23f525189275c3a0f500a46bb3ddabcaada2c65 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/be/lower.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/be/lower.cpp @@ -1525,9 +1525,11 @@ bool CGLowerer::LowerStructReturn(BlockNode &newBlk, StmtNode *stmt, StmtNode *& DreadNode *dnode = static_cast(bnode); MIRType *dtype = mirModule.CurFunction()->GetLocalOrGlobalSymbol(dnode->GetStIdx())->GetType(); #if TARGAARCH64 - PrimType ty = IsStructElementSame(dtype); - if (ty == PTY_f32 || ty == PTY_f64 || IsPrimitiveVector(ty)) { - return false; + if (Triple::GetTriple().GetArch() == Triple::ArchType::aarch64) { + PrimType ty = IsStructElementSame(dtype); + if (ty == PTY_f32 || ty == PTY_f64 || IsPrimitiveVector(ty)) { + return false; + } } #endif if (dnode->GetPrimType() != PTY_agg) { @@ -2264,11 +2266,13 @@ void CGLowerer::LowerEntry(MIRFunction &func) if (func.IsReturnStruct()) { MIRType *retType = func.GetReturnType(); #if TARGAARCH64 + if (Triple::GetTriple().GetArch() == Triple::ArchType::aarch64) { PrimType pty = IsStructElementSame(retType); if (pty == PTY_f32 || pty == PTY_f64 || IsPrimitiveVector(pty)) { func.SetStructReturnedInRegs(); return; } + } #endif if (retType->GetPrimType() != PTY_agg) { return; diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_args.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_args.cpp index 1aaa55867bba6a1bd5c603b6c3d2845d9677a55c..5c10c2c49492c0ea4be539287c3f875aa1e46062 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_args.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_args.cpp @@ -73,11 +73,11 @@ void AArch64MoveRegArgs::CollectRegisterArgs(std::map &argsL } } -ArgInfo AArch64MoveRegArgs::GetArgInfo(std::map &argsList, std::vector &numFpRegs, - std::vector &fpSize, uint32 argIndex) const +AArch64ArgInfo AArch64MoveRegArgs::GetArgInfo(std::map &argsList, std::vector &numFpRegs, + std::vector &fpSize, uint32 argIndex) const { AArch64CGFunc *aarchCGFunc = static_cast(cgFunc); - ArgInfo argInfo; + AArch64ArgInfo argInfo; argInfo.reg = argsList[argIndex]; argInfo.mirTy = aarchCGFunc->GetFunction().GetNthParamType(argIndex); argInfo.symSize = aarchCGFunc->GetBecommon().GetTypeSize(argInfo.mirTy->GetTypeIndex()); @@ -147,7 +147,7 @@ ArgInfo AArch64MoveRegArgs::GetArgInfo(std::map &argsList, s return argInfo; } -bool AArch64MoveRegArgs::IsInSameSegment(const ArgInfo &firstArgInfo, const ArgInfo &secondArgInfo) const +bool AArch64MoveRegArgs::IsInSameSegment(const AArch64ArgInfo &firstArgInfo, const AArch64ArgInfo &secondArgInfo) const { if (firstArgInfo.symLoc->GetMemSegment() != secondArgInfo.symLoc->GetMemSegment()) { return false; @@ -164,7 +164,7 @@ bool AArch64MoveRegArgs::IsInSameSegment(const ArgInfo &firstArgInfo, const ArgI return firstArgInfo.symLoc->GetOffset() + firstArgInfo.stkSize == secondArgInfo.symLoc->GetOffset(); } -void AArch64MoveRegArgs::GenerateStpInsn(const ArgInfo &firstArgInfo, const ArgInfo &secondArgInfo) +void AArch64MoveRegArgs::GenerateStpInsn(const AArch64ArgInfo &firstArgInfo, const AArch64ArgInfo &secondArgInfo) { AArch64CGFunc *aarchCGFunc = static_cast(cgFunc); RegOperand *baseOpnd = static_cast(aarchCGFunc->GetBaseReg(*firstArgInfo.symLoc)); @@ -215,7 +215,8 @@ void AArch64MoveRegArgs::GenerateStpInsn(const ArgInfo &firstArgInfo, const ArgI aarchCGFunc->GetCurBB()->AppendInsn(pushInsn); } -void AArch64MoveRegArgs::GenOneInsn(const ArgInfo &argInfo, RegOperand &baseOpnd, uint32 stBitSize, AArch64reg dest, +void AArch64MoveRegArgs::GenOneInsn(const AArch64ArgInfo &argInfo, RegOperand &baseOpnd, + uint32 stBitSize, AArch64reg dest, int32 offset) const { AArch64CGFunc *aarchCGFunc = static_cast(cgFunc); @@ -235,7 +236,8 @@ void AArch64MoveRegArgs::GenOneInsn(const ArgInfo &argInfo, RegOperand &baseOpnd aarchCGFunc->GetCurBB()->AppendInsn(insn); } -void AArch64MoveRegArgs::GenerateStrInsn(const ArgInfo &argInfo, AArch64reg reg2, uint32 numFpRegs, uint32 fpSize) +void AArch64MoveRegArgs::GenerateStrInsn(const AArch64ArgInfo &argInfo, + AArch64reg reg2, uint32 numFpRegs, uint32 fpSize) { AArch64CGFunc *aarchCGFunc = static_cast(cgFunc); int32 stOffset = aarchCGFunc->GetBaseOffset(*argInfo.symLoc); @@ -313,12 +315,12 @@ void AArch64MoveRegArgs::MoveRegisterArgs() std::vector::iterator next; for (it = moveParaIndex.begin(); it != moveParaIndex.end(); ++it) { uint32 firstIndex = *it; - ArgInfo firstArgInfo = GetArgInfo(movePara, numFpRegs, fpSize, firstIndex); + AArch64ArgInfo firstArgInfo = GetArgInfo(movePara, numFpRegs, fpSize, firstIndex); next = it; ++next; if ((next != moveParaIndex.end()) || (firstArgInfo.doMemPairOpt)) { uint32 secondIndex = (firstArgInfo.doMemPairOpt) ? firstIndex : *next; - ArgInfo secondArgInfo = GetArgInfo(movePara, numFpRegs, fpSize, secondIndex); + AArch64ArgInfo secondArgInfo = GetArgInfo(movePara, numFpRegs, fpSize, secondIndex); secondArgInfo.reg = (firstArgInfo.doMemPairOpt) ? pairReg[firstIndex] : movePara[secondIndex]; secondArgInfo.symSize = (firstArgInfo.doMemPairOpt) ? firstArgInfo.memPairSecondRegSize : secondArgInfo.symSize; diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_cfi_generator.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_cfi_generator.cpp index 6fb3c1b3183c6d726220efe1edd15e6d7506dd92..a9e396a7a282d00bf3afa795feb53bc065336fe1 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_cfi_generator.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_cfi_generator.cpp @@ -75,7 +75,7 @@ void AArch64GenCfi::GenerateRegisterSaveDirective(BB &bb, Insn &stackDefInsn) cfiOffset = stackFrameSize - offset; curInsn = bb.InsertInsnAfter(*curInsn, aarchCGFunc.CreateCfiOffsetInsn(reg, -cfiOffset, k64BitSize)); /* On AArch64, kIntregBytelen == 8 */ - offset += static_cast(kIntregBytelen); + offset += static_cast(kAarch64IntregBytelen); } } diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp index 91384a462bf6a524fc80accfa331990499691cfb..a9d96161d9544c1b20e3854f1b912bd2bc348959 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -844,7 +844,7 @@ bool AArch64CGFunc::IsImmediateOffsetOutOfRange(const MemOperand &memOpnd, uint3 offsetValue += static_cast(static_cast(GetMemlayout())->RealStackFrameSize() + 0xff); } - offsetValue += kIntregBytelen << 1; /* Refer to the above comment */ + offsetValue += kAarch64IntregBytelen << 1; /* Refer to the above comment */ return MemOperand::IsPIMMOffsetOutOfRange(offsetValue, bitLen); } else { return false; @@ -7464,25 +7464,26 @@ bool AArch64CGFunc::GenRetCleanup(const IntrinsiccallNode *cleanupNode, bool for LogInfo::MapleLogger() << "skip " << skipSym->GetName() << " offset " << skipOffset << '\n'; #endif - skipIndex = symLoc->GetOffset() / kOffsetAlign; + skipIndex = symLoc->GetOffset() / kAarch64OffsetAlign; } /* call runtime cleanup */ if (minByteOffset < INT_MAX) { int32 refLocBase = memLayout->GetRefLocBaseLoc(); - uint32 refNum = memLayout->GetSizeOfRefLocals() / kOffsetAlign; - CHECK_FATAL((refLocBase + (refNum - 1) * kIntregBytelen) < std::numeric_limits::max(), "out of range"); - int32 refLocEnd = refLocBase + (refNum - 1) * kIntregBytelen; + uint32 refNum = memLayout->GetSizeOfRefLocals() / kAarch64OffsetAlign; + CHECK_FATAL((refLocBase +(refNum - 1) * kAarch64IntregBytelen) < std::numeric_limits::max(), + "out of range"); + int32 refLocEnd = refLocBase + (refNum - 1) * kAarch64IntregBytelen; int32 realMin = minByteOffset < refLocBase ? refLocBase : minByteOffset; int32 realMax = maxByteOffset > refLocEnd ? refLocEnd : maxByteOffset; if (forEA) { std::sort(offsets.begin(), offsets.end()); int32 prev = offsets[0]; for (size_t i = 1; i < offsets.size(); i++) { - CHECK_FATAL((offsets[i] == prev) || ((offsets[i] - prev) == kIntregBytelen), "must be"); + CHECK_FATAL((offsets[i] == prev) || ((offsets[i] - prev) == kAarch64IntregBytelen), "must be"); prev = offsets[i]; } - CHECK_FATAL((refLocBase - prev) == kIntregBytelen, "must be"); + CHECK_FATAL((refLocBase - prev) == kAarch64IntregBytelen, "must be"); realMin = minByteOffset; realMax = maxByteOffset; } @@ -7528,7 +7529,7 @@ bool AArch64CGFunc::GenRetCleanup(const IntrinsiccallNode *cleanupNode, bool for srcOpnds->PushOpnd(parmRegOpnd1); SelectCopy(parmRegOpnd1, PTY_a64, vReg0, PTY_a64); - uint32 realRefNum = (realMax - realMin) / kOffsetAlign + 1; + uint32 realRefNum = (realMax - realMin) / kAarch64OffsetAlign + 1; ImmOperand &countOpnd = CreateImmOperand(realRefNum, k64BitSize, true); @@ -7539,7 +7540,7 @@ bool AArch64CGFunc::GenRetCleanup(const IntrinsiccallNode *cleanupNode, bool for MIRSymbol *funcSym = GlobalTables::GetGsymTable().CreateSymbol(kScopeGlobal); if ((skipSym != nullptr) && (skipOffset >= realMin) && (skipOffset <= realMax)) { /* call cleanupskip */ - uint32 stOffset = (skipOffset - realMin) / kOffsetAlign; + uint32 stOffset = (skipOffset - realMin) / kAarch64OffsetAlign; ImmOperand &retLoc = CreateImmOperand(stOffset, k64BitSize, true); RegOperand &parmRegOpnd3 = GetOrCreatePhysicalRegisterOperand(R2, k64BitSize, GetRegTyFromPrimTy(PTY_a64)); @@ -7631,7 +7632,7 @@ void AArch64CGFunc::HandleRCCall(bool begin, const MIRSymbol *retRef) } AArch64MemLayout *memLayout = static_cast(this->GetMemlayout()); - int32 refNum = static_cast(memLayout->GetSizeOfRefLocals() / kOffsetAlign); + int32 refNum = static_cast(memLayout->GetSizeOfRefLocals() / kAarch64OffsetAlign); if (!refNum) { if (begin) { GenerateYieldpoint(*GetCurBB()); @@ -7665,13 +7666,14 @@ void AArch64CGFunc::HandleRCCall(bool begin, const MIRSymbol *retRef) * if the number of local refvar is less than 12, use stp or str to init local refvar * else call function MCC_InitializeLocalStackRef to init. */ - if (begin && (refNum <= kRefNum12) && ((refLocBase + kIntregBytelen * (refNum - 1)) < kStpLdpImm64UpperBound)) { + if (begin && (refNum <= kRefNum12) && + ((refLocBase + kAarch64IntregBytelen * (refNum - 1)) < kStpLdpImm64UpperBound)) { int32 pairNum = refNum / kDivide2; int32 singleNum = refNum % kDivide2; const int32 pairRefBytes = 16; /* the size of each pair of ref is 16 bytes */ int32 ind = 0; while (ind < pairNum) { - int32 offset = memLayout->GetRefLocBaseLoc() + kIntregBytelen * formalRef + pairRefBytes * ind; + int32 offset = memLayout->GetRefLocBaseLoc() + kAarch64IntregBytelen * formalRef + pairRefBytes * ind; Operand &zeroOp = GetZeroOpnd(k64BitSize); Operand &stackLoc = CreateStkTopOpnd(static_cast(offset), GetPointerSize() * kBitsPerByte); Insn &setInc = GetInsnBuilder()->BuildInsn(MOP_xstp, zeroOp, zeroOp, stackLoc); @@ -7679,7 +7681,9 @@ void AArch64CGFunc::HandleRCCall(bool begin, const MIRSymbol *retRef) ind++; } if (singleNum > 0) { - int32 offset = memLayout->GetRefLocBaseLoc() + kIntregBytelen * formalRef + kIntregBytelen * (refNum - 1); + int32 offset = + memLayout->GetRefLocBaseLoc() + + kAarch64IntregBytelen * formalRef + kAarch64IntregBytelen * (refNum - 1); Operand &zeroOp = GetZeroOpnd(k64BitSize); Operand &stackLoc = CreateStkTopOpnd(static_cast(offset), GetPointerSize() * kBitsPerByte); Insn &setInc = GetInsnBuilder()->BuildInsn(MOP_xstr, zeroOp, stackLoc); @@ -7719,12 +7723,12 @@ void AArch64CGFunc::HandleRCCall(bool begin, const MIRSymbol *retRef) if ((refNum == 2) && !begin && retRef != nullptr) { AArch64SymbolAlloc *symLoc = static_cast(memLayout->GetSymAllocInfo(retRef->GetStIndex())); - int32 stOffset = symLoc->GetOffset() / kOffsetAlign; + int32 stOffset = symLoc->GetOffset() / kAarch64OffsetAlign; RegOperand &phyOpnd = GetOrCreatePhysicalRegisterOperand(R0, k64BitSize, GetRegTyFromPrimTy(PTY_a64)); Operand *stackLoc = nullptr; if (stOffset == 0) { /* just have to Dec the next one. */ - stackLoc = &CreateStkTopOpnd(static_cast(memLayout->GetRefLocBaseLoc()) + kIntregBytelen, + stackLoc = &CreateStkTopOpnd(static_cast(memLayout->GetRefLocBaseLoc()) + kAarch64IntregBytelen, GetPointerSize() * kBitsPerByte); } else { /* just have to Dec the current one. */ @@ -7754,17 +7758,17 @@ void AArch64CGFunc::HandleRCCall(bool begin, const MIRSymbol *retRef) ListOperand *srcOpnds = CreateListOpnd(*GetFuncScopeAllocator()); ImmOperand *beginOpnd = - &CreateImmOperand(memLayout->GetRefLocBaseLoc() + kIntregBytelen * formalRef, k64BitSize, true); + &CreateImmOperand(memLayout->GetRefLocBaseLoc() + kAarch64IntregBytelen * formalRef, k64BitSize, true); ImmOperand *countOpnd = &CreateImmOperand(refNum, k64BitSize, true); int32 refSkipIndex = -1; if (!begin && retRef != nullptr) { AArch64SymbolAlloc *symLoc = static_cast(memLayout->GetSymAllocInfo(retRef->GetStIndex())); - int32 stOffset = symLoc->GetOffset() / kOffsetAlign; + int32 stOffset = symLoc->GetOffset() / kAarch64OffsetAlign; refSkipIndex = stOffset; if (stOffset == 0) { /* ret_ref at begin. */ - beginOpnd = &CreateImmOperand(memLayout->GetRefLocBaseLoc() + kIntregBytelen, k64BitSize, true); + beginOpnd = &CreateImmOperand(memLayout->GetRefLocBaseLoc() + kAarch64IntregBytelen, k64BitSize, true); countOpnd = &CreateImmOperand(refNum - 1, k64BitSize, true); } else if (stOffset == (refNum - 1)) { /* ret_ref at end. */ @@ -7808,7 +7812,7 @@ void AArch64CGFunc::HandleRCCall(bool begin, const MIRSymbol *retRef) } AArch64SymbolAlloc *symLoc = static_cast(memLayout->GetSymAllocInfo(retRef->GetStIndex())); - int32 stOffset = symLoc->GetOffset() / kOffsetAlign; + int32 stOffset = symLoc->GetOffset() / kAarch64OffsetAlign; ImmOperand &retLoc = CreateImmOperand(stOffset, k64BitSize, true); regno_t vRegNO2 = NewVReg(GetRegTyFromPrimTy(PTY_a64), GetPrimTypeSize(PTY_a64)); @@ -10102,7 +10106,7 @@ int32 AArch64CGFunc::GetBaseOffset(const SymbolAlloc &symbolAlloc) // Refer to V2 in aarch64_memlayout.h. // Do Not change this unless you know what you do // O2 mode refer to V2.1 in aarch64_memlayout.cpp - const int32 sizeofFplr = static_cast(2 * kIntregBytelen); + const int32 sizeofFplr = static_cast(2 * kAarch64IntregBytelen); MemSegmentKind sgKind = symAlloc->GetMemSegment()->GetMemSegmentKind(); AArch64MemLayout *memLayout = static_cast(this->GetMemlayout()); if (sgKind == kMsArgsStkPassed) { /* for callees */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_emitter.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_emitter.cpp index 5da8054945f28819688f0f37ae4daf4de92569f7..7a543a3923a9cffba096b3e415c5a9192574b953 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_emitter.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_emitter.cpp @@ -81,13 +81,13 @@ void AArch64AsmEmitter::EmitMethodDesc(FuncEmitInfo &funcEmitInfo, Emitter &emit /* local reference area */ AArch64MemLayout *memLayout = static_cast(cgFunc.GetMemlayout()); int32 refOffset = memLayout->GetRefLocBaseLoc(); - uint32 refNum = memLayout->GetSizeOfRefLocals() / kOffsetAlign; + uint32 refNum = memLayout->GetSizeOfRefLocals() / kAarch64OffsetAlign; /* for ea usage */ AArch64CGFunc &aarchCGFunc = static_cast(cgFunc); IntrinsiccallNode *cleanEANode = aarchCGFunc.GetCleanEANode(); if (cleanEANode != nullptr) { refNum += static_cast(cleanEANode->NumOpnds()); - refOffset -= static_cast(cleanEANode->NumOpnds() * kIntregBytelen); + refOffset -= static_cast(cleanEANode->NumOpnds() * kAarch64IntregBytelen); } (void)emitter.Emit("\t.short ").Emit(refOffset).Emit("\n"); (void)emitter.Emit("\t.short ").Emit(refNum).Emit("\n"); @@ -2074,24 +2074,4 @@ bool AArch64AsmEmitter::CheckInsnRefField(const Insn &insn, size_t opndIndex) co } return false; } - -/* new phase manager */ -bool CgEmission::PhaseRun(maplebe::CGFunc &f) -{ - Emitter *emitter = f.GetCG()->GetEmitter(); - CHECK_NULL_FATAL(emitter); - if (CGOptions::GetEmitFileType() == CGOptions::kAsm) { - AsmFuncEmitInfo funcEmitInfo(f); - emitter->EmitLocalVariable(f); - static_cast(emitter)->Run(funcEmitInfo); - emitter->EmitHugeSoRoutines(); - } else { - FuncEmitInfo &funcEmitInfo = static_cast(emitter)->CreateFuncEmitInfo(f); - static_cast(emitter)->Run(funcEmitInfo); - f.SetFuncEmitInfo(&funcEmitInfo); - } - - return false; -} -MAPLE_TRANSFORM_PHASE_REGISTER(CgEmission, cgemit) } /* namespace maplebe */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_memlayout.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_memlayout.cpp index 698f0356765b7367d2dd5034dfd9936d7e7f826e..6eea76bcfd6ca4698173b47df0a0d6325e8cd4d2 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_memlayout.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_memlayout.cpp @@ -582,7 +582,7 @@ int32 AArch64MemLayout::GetRefLocBaseLoc() const if (aarchCGFunc->UsedStpSubPairForCallFrameAllocation()) { return static_cast(beforeSize); } - return static_cast(beforeSize + kSizeOfFplr); + return static_cast(beforeSize + kAarch64SizeOfFplr); } int32 AArch64MemLayout::GetGRSaveAreaBaseLoc() @@ -608,7 +608,7 @@ int32 AArch64MemLayout::GetVRSaveAreaBaseLoc() int32 AArch64MemLayout::GetCalleeSaveBaseLoc() const { uint32 offset = RealStackFrameSize() - static_cast(cgFunc)->SizeOfCalleeSaved(); - offset = (offset - SizeOfArgsToStackPass()) + kSizeOfFplr - cgFunc->GetFunction().GetFrameReseverdSlot(); + offset = (offset - SizeOfArgsToStackPass()) + kAarch64SizeOfFplr - cgFunc->GetFunction().GetFrameReseverdSlot(); if (cgFunc->GetMirModule().IsCModule() && cgFunc->GetFunction().GetAttr(FUNCATTR_varargs)) { /* GR/VR save areas are above the callee save area */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_proepilog.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_proepilog.cpp index 32a4132a5614f5ca45eec5870dc8f3f1e8b92651..91624c8ca41a4e397de52843ccde617ff25d021e 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_proepilog.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_proepilog.cpp @@ -1271,9 +1271,8 @@ void AArch64GenProEpilog::GeneratePushRegs() memLayout->GetSizeOfLocals()); } else { offset = (static_cast(memLayout->RealStackFrameSize() - - (aarchCGFunc.SizeOfCalleeSaved() - (kDivide2 * kIntregBytelen))) - /* for FP/LR */ - memLayout->SizeOfArgsToStackPass() - - cgFunc.GetFunction().GetFrameReseverdSlot()); + (aarchCGFunc.SizeOfCalleeSaved() - (kDivide2 * kAarch64IntregBytelen))) - /* for FP/LR */ + memLayout->SizeOfArgsToStackPass() - cgFunc.GetFunction().GetFrameReseverdSlot()); } if (cgFunc.GetCG()->IsStackProtectorStrong() || cgFunc.GetCG()->IsStackProtectorAll()) { @@ -1307,19 +1306,19 @@ void AArch64GenProEpilog::GeneratePushRegs() uint16 regNO = (regType == kRegTyInt) ? static_cast(reg - 1) : static_cast(reg - V8 + 72); calleeRegAndOffsetVec.push_back(std::pair(regNO, offset + k8ByteSize)); AppendInstructionPushPair(cgFunc, firstHalf, reg, regType, offset); - GetNextOffsetCalleeSaved(offset); + AArch64isa::GetNextOffsetCalleeSaved(offset); firstHalf = kRinvalid; } } if (intRegFirstHalf != kRinvalid) { AppendInstructionPushSingle(cgFunc, intRegFirstHalf, kRegTyInt, offset); - GetNextOffsetCalleeSaved(offset); + AArch64isa::GetNextOffsetCalleeSaved(offset); } if (fpRegFirstHalf != kRinvalid) { AppendInstructionPushSingle(cgFunc, fpRegFirstHalf, kRegTyFloat, offset); - GetNextOffsetCalleeSaved(offset); + AArch64isa::GetNextOffsetCalleeSaved(offset); } /* @@ -1809,7 +1808,7 @@ void AArch64GenProEpilog::GeneratePopRegs() memLayout->GetSizeOfLocals()); } else { offset = (static_cast(cgFunc.GetMemlayout())->RealStackFrameSize() - - (aarchCGFunc.SizeOfCalleeSaved() - (kDivide2 * kIntregBytelen))) - /* for FP/LR */ + (aarchCGFunc.SizeOfCalleeSaved() - (kDivide2 * kAarch64IntregBytelen))) - memLayout->SizeOfArgsToStackPass() - cgFunc.GetFunction().GetFrameReseverdSlot(); } @@ -1843,19 +1842,19 @@ void AArch64GenProEpilog::GeneratePopRegs() } else { /* flush the pair */ AppendInstructionPopPair(cgFunc, firstHalf, reg, regType, offset); - GetNextOffsetCalleeSaved(offset); + AArch64isa::GetNextOffsetCalleeSaved(offset); firstHalf = kRinvalid; } } if (intRegFirstHalf != kRinvalid) { AppendInstructionPopSingle(cgFunc, intRegFirstHalf, kRegTyInt, offset); - GetNextOffsetCalleeSaved(offset); + AArch64isa::GetNextOffsetCalleeSaved(offset); } if (fpRegFirstHalf != kRinvalid) { AppendInstructionPopSingle(cgFunc, fpRegFirstHalf, kRegTyFloat, offset); - GetNextOffsetCalleeSaved(offset); + AArch64isa::GetNextOffsetCalleeSaved(offset); } if (!currCG->GenerateDebugFriendlyCode()) { diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_reaching.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_reaching.cpp index 9cd461a373ce85db73ee608e19d6fd1421271d59..1231b8ab59d858ba6f99e642af248243d8a92118 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_reaching.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_reaching.cpp @@ -1243,7 +1243,7 @@ void AArch64ReachingDefinition::InitInfoForRegOpnd(const BB &bb, Operand &opnd, int32 AArch64ReachingDefinition::GetStackSize() const { - const int sizeofFplr = kDivide2 * kIntregBytelen; + const int sizeofFplr = kDivide2 * kAarch64IntregBytelen; return static_cast(static_cast(cgFunc->GetMemlayout())->RealStackFrameSize() + sizeofFplr); } diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_regsaves.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_regsaves.cpp index 3166cdf639dde1bff5a29fe13712d735555b4e11..52bb38a4364e996e8301a609ab148665d90d5052 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_regsaves.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_regsaves.cpp @@ -544,7 +544,7 @@ int32 AArch64RegSavesOpt::FindNextOffsetForCalleeSave() const { int32 offset = static_cast( static_cast(cgFunc->GetMemlayout())->RealStackFrameSize() - - (static_cast(cgFunc)->SizeOfCalleeSaved() - (kDivide2 * kIntregBytelen) /* FP/LR */) - + (static_cast(cgFunc)->SizeOfCalleeSaved() - (kDivide2 * kAarch64IntregBytelen) /* FP/LR */) - cgFunc->GetMemlayout()->SizeOfArgsToStackPass() - cgFunc->GetFunction().GetFrameReseverdSlot()); if (cgFunc->GetFunction().GetAttr(FUNCATTR_varargs)) { @@ -585,7 +585,7 @@ void AArch64RegSavesOpt::InsertCalleeSaveCode() /* If reg not seen before, record offset and then update */ if (regOffset.find(areg) == regOffset.end()) { regOffset[areg] = static_cast(offset); - offset += static_cast(kIntregBytelen); + offset += static_cast(kAarch64IntregBytelen); } if (firstHalf == kRinvalid) { /* 1st half in reg pair */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_schedule.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_schedule.cpp index f97a3d65945439878eaa5cb5628f1ed34fb044f1..9be3d3ef5ff4185d43760ac3aaffa517d69af705 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_schedule.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_schedule.cpp @@ -110,7 +110,7 @@ bool AArch64Schedule::CanCombine(const Insn &insn) const uint32 size = regOpnd.GetSize() >> kLog2BitsPerByte; #ifdef USE_32BIT_REF - if (insn.IsAccessRefField() && (size > (kIntregBytelen >> 1))) { + if (insn.IsAccessRefField() && (size > (kAarch64IntregBytelen >> 1))) { return false; } #endif /* USE_32BIT_REF */ @@ -120,11 +120,11 @@ bool AArch64Schedule::CanCombine(const Insn &insn) const return false; } int32 offsetValue = static_cast(offset->GetOffsetValue()); - if (size == kIntregBytelen) { /* 64 bit */ + if (size == kAarch64IntregBytelen) { /* 64 bit */ if ((offsetValue <= kStpLdpImm64LowerBound) || (offsetValue >= kStpLdpImm64UpperBound)) { return false; } - } else if (size == (kIntregBytelen >> 1)) { /* 32 bit */ + } else if (size == (kAarch64IntregBytelen >> 1)) { /* 32 bit */ if ((offsetValue <= kStpLdpImm32LowerBound) || (offsetValue >= kStpLdpImm32UpperBound)) { return false; } diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_targetinfo.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_targetinfo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6ea29568e3a816bae371bb1ca137f1a66f9aa15a --- /dev/null +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_targetinfo.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "aarch64_targetinfo.h" +#include "target_registry.h" +#include "aarch64_cg.h" +#include "aarch64_emitter.h" +#include "aarch64_targetmachine.h" +#include +namespace maplebe { + +Target &getTheAArch64Target() +{ + static Target TheAArch64Target; + return TheAArch64Target; +} + +extern "C" void MAPLEInitializeAArch64TargetInfo(MemPool *m) +{ + RegisterTarget X(getTheAArch64Target(), "aarch64"); + RegisterCGFUnc Y(getTheAArch64Target()); + RegisterEmitter Z(getTheAArch64Target(), m); + RegisterTargetMachine A(getTheAArch64Target(), m); +} + +} diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_cfg.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_cfg.cpp index 322772ff8f9c79c13b3bd98385cf77b270efbd8a..4980bf208f85a034d9e889e55b741d4bd78fe867 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_cfg.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_cfg.cpp @@ -16,7 +16,8 @@ #include "cg_cfg.h" #if TARGAARCH64 #include "aarch64_insn.h" -#elif TARGRISCV64 +#endif +#if defined(TARGRISCV64) && TARGRISCV64 #include "riscv64_insn.h" #endif #if TARGARM32 @@ -28,6 +29,7 @@ #include "x64_cgfunc.h" #include "cg.h" #endif +#include "triple.h" #include namespace { @@ -665,8 +667,9 @@ BB *CGCFG::GetTargetSuc(BB &curBB, bool branchOnly, bool isGotoIf) case BB::kBBIgoto: { for (Insn *insn = curBB.GetLastInsn(); insn != nullptr; insn = insn->GetPrev()) { #if TARGAARCH64 - if (insn->GetMachineOpcode() == MOP_adrp_label) { - int64 label = static_cast(insn->GetOperand(1)).GetValue(); + if (Triple::GetTriple().IsAarch64BeOrLe() && + insn->GetMachineOpcode() == MOP_adrp_label) { + int64 label = static_cast(insn->GetOperand(1)).GetValue(); for (BB *bb : curBB.GetSuccs()) { if (bb->GetLabIdx() == static_cast(label)) { return bb; diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_option.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_option.cpp index b0f6da7e4d4ba953193ee7d335ee113aaf3fb7c3..695d1a06ddc9ca69d98e9b3cfa442e9d71388524 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_option.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_option.cpp @@ -802,12 +802,14 @@ void CGOptions::EnableLiteCG() void CGOptions::SetTargetMachine(const std::string &str) { - if (str == "aarch64") { + // this is a temporary plan, all ilp32 logic follow the same path with aarch64 + if (str == "aarch64" || str == "aarch64_be-linux-gnu_ilp32" || str == "aarch64_be-linux-gnu") { targetArch = "aarch64"; } else if (str == "x86_64") { targetArch = "x86_64"; + } else { + CHECK_FATAL_FALSE("unsupported target!!"); } - CHECK_FATAL(false, "unknown target. not implement yet"); } void CGOptions::SplitPhases(const std::string &str, std::unordered_set &set) diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_phasemanager.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_phasemanager.cpp index 188a093eb6dd2c934f3feb11ebd5b3fee8312233..b7510473dd5d3f7a61217cb08428f76eb3792cd2 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_phasemanager.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_phasemanager.cpp @@ -29,13 +29,16 @@ #include "aarch64_emitter.h" #include "aarch64_obj_emitter.h" #include "aarch64_cg.h" -#elif TARGRISCV64 +#endif +#if defined(TARGRISCV64) #include "riscv64_emitter.h" -#elif TARGX86_64 +#endif +#if defined(TARGX86_64) #include "x64_cg.h" #include "x64_emitter.h" #include "string_utils.h" #endif +#include "triple.h" namespace maplebe { #define JAVALANG (module.IsJavaModule()) @@ -72,24 +75,27 @@ void CgFuncPM::GenerateOutPutFile(MIRModule &m) { CHECK_FATAL(cg != nullptr, "cg is null"); CHECK_FATAL(cg->GetEmitter(), "emitter is null"); -#if TARGX86_64 - assembler::Assembler &assm = static_cast(*cg->GetEmitter()).GetAssembler(); - if (!cgOptions->SuppressFileInfo()) { - assm.InitialFileInfo(m.GetInputFileName()); - } - if (cgOptions->WithDwarf()) { - assm.EmitDIHeader(); - } -#else - if (CGOptions::GetEmitFileType() == CGOptions::kAsm) { + CHECK_FATAL(Triple::GetTriple().GetArch() != Triple::ArchType::UnknownArch, "should have triple init before!"); + if (Triple::GetTriple().GetArch() == Triple::ArchType::x64) { + assembler::Assembler &assm = static_cast(*cg->GetEmitter()).GetAssembler(); if (!cgOptions->SuppressFileInfo()) { - cg->GetEmitter()->EmitFileInfo(m.GetInputFileName()); + assm.InitialFileInfo(m.GetInputFileName()); } if (cgOptions->WithDwarf()) { - cg->GetEmitter()->EmitDIHeader(); + assm.EmitDIHeader(); } + } else if (Triple::GetTriple().GetArch() == Triple::ArchType::aarch64) { + if (CGOptions::GetEmitFileType() == CGOptions::kAsm) { + if (!cgOptions->SuppressFileInfo()) { + cg->GetEmitter()->EmitFileInfo(m.GetInputFileName()); + } + if (cgOptions->WithDwarf()) { + cg->GetEmitter()->EmitDIHeader(); + } + } + } else { + CHECK_FATAL(false, "unsupportted target!"); } -#endif InitProfile(m); } @@ -116,29 +122,31 @@ bool CgFuncPM::FuncLevelRun(CGFunc &cgFunc, AnalysisDataManager &serialADM) void CgFuncPM::PostOutPut(MIRModule &m) { -#if TARGX86_64 - X64Emitter *x64Emitter = static_cast(cg->GetEmitter()); - assembler::Assembler &assm = x64Emitter->GetAssembler(); - if (cgOptions->WithDwarf()) { - assm.EmitDIFooter(); - } - x64Emitter->EmitGlobalVariable(*cg); - x64Emitter->EmitDebugInfo(*cg); - assm.FinalizeFileInfo(); - assm.CloseOutput(); -#else - if (CGOptions::GetEmitFileType() == CGOptions::kAsm) { - cg->GetEmitter()->EmitHugeSoRoutines(true); + if (Triple::GetTriple().GetArch() == Triple::ArchType::x64) { + X64Emitter *x64Emitter = static_cast(cg->GetEmitter()); + assembler::Assembler &assm = x64Emitter->GetAssembler(); if (cgOptions->WithDwarf()) { - cg->GetEmitter()->EmitDIFooter(); + assm.EmitDIFooter(); + } + x64Emitter->EmitGlobalVariable(*cg); + x64Emitter->EmitDebugInfo(*cg); + assm.FinalizeFileInfo(); + assm.CloseOutput(); + } else if (Triple::GetTriple().GetArch() == Triple::ArchType::aarch64) { + if (CGOptions::GetEmitFileType() == CGOptions::kAsm) { + cg->GetEmitter()->EmitHugeSoRoutines(true); + if (cgOptions->WithDwarf()) { + cg->GetEmitter()->EmitDIFooter(); + } + /* Emit global info */ + EmitGlobalInfo(m); + } else { + cg->GetEmitter()->Finish(); + cg->GetEmitter()->CloseOutput(); } - /* Emit global info */ - EmitGlobalInfo(m); } else { - cg->GetEmitter()->Finish(); - cg->GetEmitter()->CloseOutput(); + CHECK_FATAL(false, "unsupported target"); } -#endif } void MarkUsedStaticSymbol(const StIdx &symbolIdx); @@ -282,7 +290,21 @@ extern void printRATime(); bool CgFuncPM::PhaseRun(MIRModule &m) { - CreateCGAndBeCommon(m); + // registry target based on build, cgfunc, emitter need to be registried. + InitializeAllTargetInfos(m.GetMemPool()); + std::string compileTarget = ""; + if (Triple::GetTriple().IsAarch64BeOrLe()) { + compileTarget = "aarch64"; + } else if (Triple::GetTriple().GetArch() == Triple::ArchType::x64) { + compileTarget = "x86"; + } else { + CHECK_FATAL(false, "unsupport"); + } + const Target *TheTarget = nullptr; + TheTarget = + TargetRegistry::lookupTarget(compileTarget); + // get target based on option + CreateCGAndBeCommon(m, TheTarget); bool changed = false; /* reserve static symbol for debugging */ if (!cgOptions->WithDwarf()) { @@ -406,34 +428,37 @@ void CgFuncPM::InitProfile(MIRModule &m) const } } -void CgFuncPM::CreateCGAndBeCommon(MIRModule &m) +void CgFuncPM::CreateCGAndBeCommon(MIRModule &m, const Target *t) { DEBUG_ASSERT(cgOptions != nullptr, "New cg phase manager running FAILED :: cgOptions unset"); auto outputFileName = m.GetOutputFileName(); -#if TARGAARCH64 || TARGRISCV64 - cg = new AArch64CG(m, *cgOptions, cgOptions->GetEHExclusiveFunctionNameVec(), CGOptions::GetCyclePatternMap()); - if (CGOptions::GetEmitFileType() == CGOptions::kAsm) { - cg->SetEmitter(*m.GetMemPool()->New(*cg, outputFileName)); - } else { - outputFileName = outputFileName.replace(outputFileName.length() - 1, 1, 1, 'o'); - cg->SetEmitter(*m.GetMemPool()->New(*cg, outputFileName)); - } -#elif TARGARM32 - cg = new Arm32CG(m, *cgOptions, cgOptions->GetEHExclusiveFunctionNameVec(), CGOptions::GetCyclePatternMap()); - cg->SetEmitter(*m.GetMemPool()->New(*cg, outputFileName)); -#elif TARGX86_64 - cg = new X64CG(m, *cgOptions); - if (CGOptions::GetEmitFileType() == CGOptions::kAsm) { - assembler::Assembler *assembler = new assembler::AsmAssembler(outputFileName); - cg->SetEmitter(*m.GetMemPool()->New(*cg, *assembler)); + Emitter *emitter = nullptr; + cg = t->createCG(m, *cgOptions, cgOptions->GetEHExclusiveFunctionNameVec(), CGOptions::GetCyclePatternMap()); + CHECK_FATAL(cg, "you may not register the target"); + if (Triple::GetTriple().GetArch() == Triple::ArchType::x64) { + assembler::Assembler *assembler = nullptr; + if (CGOptions::GetEmitFileType() == CGOptions::kAsm) { + assembler = new assembler::AsmAssembler(outputFileName); + } else { + outputFileName = outputFileName.replace(outputFileName.length() - 1, 1, 1, 'o'); + assembler = new assembler::ElfAssembler(outputFileName); + } + emitter = t->createDecoupledEmitter(*cg, *assembler); + } else if (Triple::GetTriple().GetArch() == Triple::ArchType::aarch64) { + if (CGOptions::GetEmitFileType() == CGOptions::kAsm) { + emitter = m.GetMemPool()->New(*cg, outputFileName); + } else { + outputFileName = outputFileName.replace(outputFileName.length() - 1, 1, 1, 'o'); + emitter = m.GetMemPool()->New(*cg, outputFileName); + } } else { - outputFileName = outputFileName.replace(outputFileName.length() - 1, 1, 1, 'o'); - assembler::Assembler *assembler = new assembler::ElfAssembler(outputFileName); - cg->SetEmitter(*m.GetMemPool()->New(*cg, *assembler)); + CHECK_FATAL(false, "unsupportted"); } -#else -#error "unknown platform" -#endif + CHECK_FATAL(emitter, "you may not register emitter"); + cg->SetEmitter(*emitter); + TargetMachine *targetMachine = t->createTargetMachine(); + CHECK_FATAL(targetMachine, "you may not register targetMachine"); + cg->SetTargetMachine(*targetMachine); /* * Must be done before creating any BECommon instances. @@ -458,11 +483,9 @@ void CgFuncPM::CreateCGAndBeCommon(MIRModule &m) CHECK_FATAL(cgOptions->IsInsertCall(), "handling of --insert-call is not correct"); cg->SetInstrumentationFunction(cgOptions->GetInstrumentationFunction()); } -#if TARGAARCH64 - if (!m.IsCModule()) { + if (!m.IsCModule() && Triple::GetTriple().IsAarch64BeOrLe()) { CGOptions::EnableFramePointer(); } -#endif } void CgFuncPM::PrepareLower(MIRModule &m) diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/ebo.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/ebo.cpp index a82a01eb4ced4fc1660bf1bfe5f495e96ca047a1..085f7ed1751e69dc0eac248e1c1a6e29c4d28aa4 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/ebo.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/ebo.cpp @@ -15,7 +15,8 @@ #if TARGAARCH64 #include "aarch64_ebo.h" -#elif TARGRISCV64 +#endif +#if TARGRISCV64 #include "riscv64_ebo.h" #endif #if TARGARM32 diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/emit.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/emit.cpp index 90c0fd87800595530cafd4087ae0d57987b83415..46fb93db00147b4772f15c9c030787ec1157d1c2 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/emit.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/emit.cpp @@ -14,6 +14,14 @@ */ #include "emit.h" +#include "asm_emit.h" +#if TARGAARCH64 +#include "aarch64_obj_emitter.h" +#include "aarch64_emitter.h" +#endif +#if TARGX86_64 +#include "x64_emitter.h" +#endif #include #ifdef _WIN32 #include @@ -165,11 +173,11 @@ AsmLabel Emitter::GetTypeAsmInfoName(PrimType primType) const case k1ByteSize: return kAsmByte; case k2ByteSize: -#if TARGAARCH64 || TARGRISCV64 - return kAsmShort; -#else - return kAsmValue; -#endif + if (GetCG()->GetTargetMachine()->isAArch64() || GetCG()->GetTargetMachine()->isRiscV()) { + return kAsmShort; + } else { + return kAsmValue; + } case k4ByteSize: return kAsmLong; case k8ByteSize: @@ -402,13 +410,16 @@ void Emitter::EmitAsmLabel(const MIRSymbol &mirSymbol, AsmLabel label) } (void)Emit(asmInfo->GetComm()).Emit(symName).Emit(", ").Emit(size).Emit(", "); #if PECOFF -#if TARGARM || TARGAARCH64 || TARGARK || TARGRISCV64 - std::string align = std::to_string( - static_cast(log2(Globals::GetInstance()->GetBECommon()->GetTypeAlign(mirType->GetTypeIndex())))); -#else - std::string align = - std::to_string(Globals::GetInstance()->GetBECommon()->GetTypeAlign(mirType->GetTypeIndex())); -#endif + if (GetCG()->GetTargetMachine()->isAArch64() || + GetCG()->GetTargetMachine()->isRiscV() || GetCG()->GetTargetMachine()->isArm32() || + GetCG()->GetTargetMachine()->isArk()) { + std::string align = std::to_string( + static_cast( + log2(Globals::GetInstance()->GetBECommon()->GetTypeAlign(mirType->GetTypeIndex())))); + else { + std::string align = + std::to_string(Globals::GetInstance()->GetBECommon()->GetTypeAlign(mirType->GetTypeIndex())); + } emit(align.c_str()); #else /* ELF */ /* output align, symbol name begin with "classInitProtectRegion" align is 4096 */ @@ -438,20 +449,21 @@ void Emitter::EmitAsmLabel(const MIRSymbol &mirSymbol, AsmLabel label) if (align == 0) { if (mirSymbol.GetType()->GetKind() == kTypeStruct || mirSymbol.GetType()->GetKind() == kTypeClass || mirSymbol.GetType()->GetKind() == kTypeArray || mirSymbol.GetType()->GetKind() == kTypeUnion) { -#if TARGX86 || TARGX86_64 - return; -#else - align = kAlignOfU8; -#endif + if (GetCG()->GetTargetMachine()->isX8664()) { + return; + } else { + align = kAlignOfU8; + } } else { align = Globals::GetInstance()->GetBECommon()->GetTypeAlign(mirSymbol.GetType()->GetTypeIndex()); -#if TARGARM32 || TARGAARCH64 || TARGARK || TARGRISCV64 - if (CGOptions::IsArm64ilp32() && mirSymbol.GetType()->GetPrimType() == PTY_a32) { - align = kAlignOfU8; - } else { - align = static_cast(log2(align)); + if (GetCG()->GetTargetMachine()->isAArch64() || GetCG()->GetTargetMachine()->isRiscV() || + GetCG()->GetTargetMachine()->isArm32() || GetCG()->GetTargetMachine()->isArk()) { + if (CGOptions::IsArm64ilp32() && mirSymbol.GetType()->GetPrimType() == PTY_a32) { + align = kAlignOfU8; + } else { + align = static_cast(log2(align)); + } } -#endif } } Emit(asmInfo->GetAlign()); @@ -468,19 +480,19 @@ void Emitter::EmitAsmLabel(const MIRSymbol &mirSymbol, AsmLabel label) Emit(asmInfo->GetSize()); Emit(symName); Emit(", "); -#if TARGX86 || TARGX86_64 - Emit(".-"); - Emit(symName); -#else - std::string size; - if (isFlexibleArray) { - size = std::to_string(Globals::GetInstance()->GetBECommon()->GetTypeSize(mirType->GetTypeIndex()) + - arraySize); + if (GetCG()->GetTargetMachine()->isX8664()) { + Emit(".-"); + Emit(symName); } else { - size = std::to_string(Globals::GetInstance()->GetBECommon()->GetTypeSize(mirType->GetTypeIndex())); + std::string size; + if (isFlexibleArray) { + size = std::to_string(Globals::GetInstance()->GetBECommon()->GetTypeSize(mirType->GetTypeIndex()) + + arraySize); + } else { + size = std::to_string(Globals::GetInstance()->GetBECommon()->GetTypeSize(mirType->GetTypeIndex())); + } + Emit(size); } - Emit(size); -#endif Emit("\n"); return; } @@ -1909,11 +1921,11 @@ void Emitter::EmitBlockMarker(const std::string &markerName, const std::string & EmitAsmLabel(kAsmData); } Emit(asmInfo->GetAlign()); -#if TARGX86 || TARGX86_64 - Emit("8\n" + markerName + ":\n"); -#else - Emit("3\n" + markerName + ":\n"); -#endif + if (GetCG()->GetTargetMachine()->isX8664()) { + Emit("8\n" + markerName + ":\n"); + } else { + Emit("3\n" + markerName + ":\n"); + } EmitAsmLabel(kAsmQuad); if (withAddr) { Emit(addrName + "\n"); @@ -1985,13 +1997,13 @@ void Emitter::EmitFuncLayoutInfo(const MIRSymbol &layout) Emit(asmInfo->GetGlobal()); Emit(markerName + "\n"); EmitAsmLabel(kAsmData); -#if TARGX86 || TARGX86_64 - EmitAsmLabel(layout, kAsmAlign); - Emit(markerName + ":\n"); -#else - Emit(asmInfo->GetAlign()); - Emit("3\n" + markerName + ":\n"); -#endif + if (GetCG()->GetTargetMachine()->isX8664()) { + EmitAsmLabel(layout, kAsmAlign); + Emit(markerName + ":\n"); + } else { + Emit(asmInfo->GetAlign()); + Emit("3\n" + markerName + ":\n"); + } #if TARGAARCH64 || TARGRISCV64 || TARGX86_64 EmitAsmLabel(kAsmQuad); @@ -2151,11 +2163,11 @@ void Emitter::EmitStringPointers() { if (CGOptions::OptimizeForSize()) { (void)Emit(asmInfo->GetSection()).Emit(".rodata,\"aMS\",@progbits,1").Emit("\n"); -#if TARGX86 || TARGX86_64 - Emit("\t.align 8\n"); -#else - Emit("\t.align 3\n"); -#endif + if (GetCG()->GetTargetMachine()->isX8664()) { + Emit("\t.align 8\n"); + } else { + Emit("\t.align 3\n"); + } } else { (void)Emit(asmInfo->GetSection()).Emit(".rodata").Emit("\n"); } @@ -2164,11 +2176,11 @@ void Emitter::EmitStringPointers() continue; } if (!CGOptions::OptimizeForSize()) { -#if TARGX86 || TARGX86_64 - Emit("\t.align 8\n"); -#else - Emit("\t.align 3\n"); -#endif + if (GetCG()->GetTargetMachine()->isX8664()) { + Emit("\t.align 8\n"); + } else { + Emit("\t.align 3\n"); + } } uint32 strId = idx.GetIdx(); std::string str = GlobalTables::GetUStrTable().GetStringFromStrIdx(idx); @@ -2181,20 +2193,20 @@ void Emitter::EmitStringPointers() continue; } if (!CGOptions::OptimizeForSize()) { -#if TARGX86 || TARGX86_64 - Emit("\t.align 8\n"); -#else - Emit("\t.align 3\n"); -#endif + if (GetCG()->GetTargetMachine()->isX8664()) { + Emit("\t.align 8\n"); + } else { + Emit("\t.align 3\n"); + } } uint32 strId = idx.GetIdx(); std::string str = GlobalTables::GetUStrTable().GetStringFromStrIdx(idx); Emit(asmInfo->GetAlign()); -#if TARGX86 || TARGX86_64 - Emit("8\n"); -#else - Emit("3\n"); -#endif + if (GetCG()->GetTargetMachine()->isX8664()) { + Emit("8\n"); + } else { + Emit("3\n"); + } Emit(".LSTR__").Emit(strId).Emit(":\n"); std::string mplstr(str); EmitStr(mplstr, false, true); @@ -2418,7 +2430,7 @@ void Emitter::EmitGlobalVariable() if (mirSymbol == nullptr || mirSymbol->IsDeleted() || mirSymbol->GetStorageClass() == kScUnused) { continue; } - if (mirSymbol->GetSKind() == kStFunc) { + if (mirSymbol->GetSKind() == maple::MIRSymKind::kStFunc) { EmitAliasAndRef(*mirSymbol); } @@ -2509,7 +2521,7 @@ void Emitter::EmitGlobalVariable() continue; } /* symbols we do not emit here. */ - if (mirSymbol->GetSKind() == kStFunc || mirSymbol->GetSKind() == kStJavaClass || + if (mirSymbol->GetSKind() == maple::MIRSymKind::kStFunc || mirSymbol->GetSKind() == kStJavaClass || mirSymbol->GetSKind() == kStJavaInterface) { continue; } @@ -2639,11 +2651,11 @@ void Emitter::EmitGlobalVariable() } if (mirSymbol->IsReflectionStrTab()) { /* reflection-string-tab also aligned to 8B boundaries. */ Emit(asmInfo->GetAlign()); -#if TARGX86 || TARGX86_64 - Emit("8\n"); -#else - Emit("3\n"); -#endif + if (GetCG()->GetTargetMachine()->isX8664()) { + Emit("8\n"); + } else { + Emit("3\n"); + } } else { EmitAsmLabel(*mirSymbol, kAsmAlign); } @@ -3074,19 +3086,19 @@ void Emitter::EmitDWRef(const std::string &name) Emit("\t.section .data.DW.ref." + name + ",\"awG\",%progbits,DW.ref."); Emit(name + ",comdat\n"); Emit(asmInfo->GetAlign()); -#if TARGX86 || TARGX86_64 - Emit("8\n"); -#else - Emit("3\n"); -#endif + if (GetCG()->GetTargetMachine()->isX8664()) { + Emit("8\n"); + } else { + Emit("3\n"); + } Emit("\t.type DW.ref." + name + ", \%object\n"); Emit("\t.size DW.ref." + name + ",8\n"); Emit("DW.ref." + name + ":\n"); -#if TARGAARCH64 || TARGRISCV64 - Emit("\t.xword " + name + "\n"); -#else - Emit("\t.word " + name + "\n"); -#endif + if (GetCG()->GetTargetMachine()->isAArch64()) { + Emit("\t.xword " + name + "\n"); + } else { + Emit("\t.word " + name + "\n"); + } } void Emitter::EmitDecSigned(int64 num) @@ -3110,7 +3122,9 @@ void Emitter::EmitHexUnsigned(uint64 num) fileStream.flags(flag); } +#ifndef TARGX86_64 #define XSTR(s) str(s) +#endif #define str(s) #s void Emitter::EmitDIHeader() @@ -3731,11 +3745,11 @@ void Emitter::EmitHugeSoRoutines(bool lastRoutine) } for (auto &target : hugeSoTargets) { (void)Emit("\t.section\t." + std::string(namemangler::kMuidJavatextPrefixStr) + ",\"ax\"\n"); -#if TARGX86 || TARGX86_64 +if (GetCG()->GetTargetMachine()->isX8664()) { Emit("\t.align\t8\n"); -#else +} else { Emit("\t.align 3\n"); -#endif +} std::string routineName = target + HugeSoPostFix(); Emit("\t.type\t" + routineName + ", %function\n"); Emit(routineName + ":\n"); @@ -3757,4 +3771,31 @@ void LabelOperand::Dump() const { LogInfo::MapleLogger() << "label:" << labelIndex; } + +/* new phase manager */ +bool CgEmission::PhaseRun(maplebe::CGFunc &f) { + Emitter *emitter = f.GetCG()->GetEmitter(); + CHECK_NULL_FATAL(emitter); + + if (Triple::GetTriple().IsAarch64BeOrLe()) { + if (CGOptions::GetEmitFileType() == CGOptions::kAsm) { + AsmFuncEmitInfo funcEmitInfo(f); + emitter->EmitLocalVariable(f); + static_cast(emitter)->Run(funcEmitInfo); + emitter->EmitHugeSoRoutines(); + } else { + FuncEmitInfo &funcEmitInfo = static_cast(emitter)->CreateFuncEmitInfo(f); + static_cast(emitter)->Run(funcEmitInfo); + f.SetFuncEmitInfo(&funcEmitInfo); + } + } else if (Triple::GetTriple().GetArch() == Triple::ArchType::x64) { + Emitter *emitter = f.GetCG()->GetEmitter(); + CHECK_NULL_FATAL(emitter); + static_cast(emitter)->Run(f); + } else { + CHECK_FATAL(false, "unsupportted"); + } + return false; +} +MAPLE_TRANSFORM_PHASE_REGISTER(CgEmission, cgemit) } /* namespace maplebe */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/global.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/global.cpp index 6f43efe3236b9eb73b2ad9faa2a7d0e18f716432..bbdff517f9011dec5db0af37d5a0887e4337b736 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/global.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/global.cpp @@ -15,7 +15,8 @@ #if TARGAARCH64 #include "aarch64_global.h" -#elif TARGRISCV64 +#endif +#if TARGRISCV64 #include "riscv64_global.h" #endif #if TARGARM32 diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/live.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/live.cpp index 2e8f1aed1fe4f39317ebe859b0a821db3d1ab7fe..f0b273d811c3184c9bf10415157622dae196bf08 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/live.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/live.cpp @@ -468,7 +468,9 @@ void LiveAnalysis::EnlargeSpaceForLiveAnalysis(BB &currBB) void CgLiveAnalysis::GetAnalysisDependence(AnalysisDep &aDep) const { #if TARGX86_64 - aDep.AddRequired(); + if (Triple::GetTriple().GetArch() == Triple::ArchType::x64) { + aDep.AddRequired(); + } #endif aDep.SetPreservedAll(); } diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/peep.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/peep.cpp index 64dfb84c7842f1c10baf062e548d5a0b3f42578a..0837b1724780ffb1dbfd96c10524483e7a65b24f 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/peep.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/peep.cpp @@ -19,9 +19,11 @@ #include "common_utils.h" #if TARGAARCH64 #include "aarch64_peep.h" -#elif TARGRISCV64 +#endif +#if TARGRISCV64 #include "riscv64_peep.h" -#elif defined TARGX86_64 +#endif +#if defined TARGX86_64 #include "x64_peep.h" #endif #if TARGARM32 @@ -707,11 +709,7 @@ MAPLE_TRANSFORM_PHASE_REGISTER_CANSKIP(CgPeepHole, cgpeephole) bool CgPrePeepHole::PhaseRun(maplebe::CGFunc &f) { MemPool *mp = GetPhaseMemPool(); -#if defined TARGAARCH64 - auto *cgpeep = mp->New(f, mp); -#elif defined TARGX86_64 - auto *cgpeep = mp->New(f, mp); -#endif + CGPeepHole *cgpeep = f.GetCG()->CreateCGPeepHole(*mp, f); CHECK_FATAL(cgpeep != nullptr, "PeepHoleOptimizer instance create failure"); cgpeep->Run(); return false; @@ -722,11 +720,7 @@ MAPLE_TRANSFORM_PHASE_REGISTER_CANSKIP(CgPrePeepHole, cgprepeephole) bool CgPostPeepHole::PhaseRun(maplebe::CGFunc &f) { MemPool *mp = GetPhaseMemPool(); -#if defined TARGAARCH64 - auto *cgpeep = mp->New(f, mp); -#elif defined TARGX86_64 - auto *cgpeep = mp->New(f, mp); -#endif + CGPeepHole *cgpeep = f.GetCG()->CreateCGPeepHole(*mp, f); CHECK_FATAL(cgpeep != nullptr, "PeepHoleOptimizer instance create failure"); cgpeep->Run(); return false; diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/pressure.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/pressure.cpp index 94db0144963e230d9b68deafca9db2758f08cbe2..9a3bede1e2df619dc5d14d17e0aaa85567e8eb0b 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/pressure.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/pressure.cpp @@ -14,11 +14,6 @@ */ #include "pressure.h" -#if TARGAARCH64 -#include "aarch64_schedule.h" -#elif TARGRISCV64 -#include "riscv64_schedule.h" -#endif #include "deps.h" namespace maplebe { diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/proepilog.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/proepilog.cpp index d146bc3b74f9b3b8bb0f1bdc93f862731bf8b48e..3149d9e9b8fcdf16b39a43214adfd49d90d58745 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/proepilog.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/proepilog.cpp @@ -14,17 +14,6 @@ */ #include "proepilog.h" -#if TARGAARCH64 -#include "aarch64_proepilog.h" -#elif TARGRISCV64 -#include "riscv64_proepilog.h" -#endif -#if TARGARM32 -#include "arm32_proepilog.h" -#endif -#if TARGX86_64 -#include "x64_proepilog.h" -#endif #include "cgfunc.h" #include "cg.h" @@ -121,15 +110,7 @@ bool GenProEpilog::IncludeArray(const MIRType &type) const bool CgGenProEpiLog::PhaseRun(maplebe::CGFunc &f) { GenProEpilog *genPE = nullptr; -#if TARGAARCH64 || TARGRISCV64 - genPE = GetPhaseAllocator()->New(f, *ApplyTempMemPool()); -#endif -#if TARGARM32 - genPE = GetPhaseAllocator()->New(f); -#endif -#if TARGX86_64 - genPE = GetPhaseAllocator()->New(f); -#endif + genPE = f.GetCG()->CreateGenProEpilog(f, *GetPhaseMemPool(), ApplyTempMemPool()); genPE->Run(); return false; } diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/reaching.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/reaching.cpp index 0d5a5ecb380ecc13b4b0aaf685e91a4ad222d031..098cc93a1ad23e3a814b2a0b1464728b176acd6f 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/reaching.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/reaching.cpp @@ -82,9 +82,11 @@ void ReachingDefinition::ClearDefUseInfo() * Backward propagation can move the return register definition far from the return. */ #ifndef TARGX86_64 + if (Triple::GetTriple().GetArch() == Triple::ArchType::x64) { if (insn->GetMachineOpcode() == MOP_pseudo_ret_int || insn->GetMachineOpcode() == MOP_pseudo_ret_float) { continue; } + } #endif insn->GetBB()->RemoveInsn(*insn); } diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/reg_alloc.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/reg_alloc.cpp index 68122fad0a325dc9190f9ba301a0ddffbd008e7e..05cf9936004a37b97aa970d0d443b87a7c32e889 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/reg_alloc.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/reg_alloc.cpp @@ -68,15 +68,17 @@ bool CgRegAlloc::PhaseRun(maplebe::CGFunc &f) regAllocator = phaseMp->New(f, *phaseMp, bfs); #if TARGAARCH64 } else if (f.GetCG()->GetCGOptions().DoColoringBasedRegisterAllocation()) { - MaplePhase *it = GetAnalysisInfoHook()->ForceRunAnalysisPhase, CGFunc>( - &CgLiveAnalysis::id, f); - live = static_cast(it)->GetResult(); - CHECK_FATAL(live != nullptr, "null ptr check"); - /* revert liveanalysis result container. */ - live->ResetLiveSet(); - DomAnalysis *dom = GET_ANALYSIS(CgDomAnalysis, f); - CHECK_FATAL(dom != nullptr, "null ptr check"); - regAllocator = phaseMp->New(f, *tempMP, *dom); + if (Triple::GetTriple().GetArch() == Triple::ArchType::aarch64) { + MaplePhase *it = GetAnalysisInfoHook()->ForceRunAnalysisPhase, CGFunc>( + &CgLiveAnalysis::id, f); + live = static_cast(it)->GetResult(); + CHECK_FATAL(live != nullptr, "null ptr check"); + /* revert liveanalysis result container. */ + live->ResetLiveSet(); + DomAnalysis *dom = GET_ANALYSIS(CgDomAnalysis, f); + CHECK_FATAL(dom != nullptr, "null ptr check"); + regAllocator = phaseMp->New(f, *tempMP, *dom); + } #endif } else { maple::LogInfo::MapleLogger(kLlErr) diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/target_registry.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/target_registry.cpp new file mode 100644 index 0000000000000000000000000000000000000000..665c0316de3807875041276541577cb856f84aa5 --- /dev/null +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/target_registry.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "target_registry.h" +#include "becommon.h" + +namespace maplebe { +using namespace maple; +static Target *firstTarget = nullptr; +void TargetRegistry::RegisterTarget(Target &t, const std::string name) +{ + // Add to the list of targets. + t.next = firstTarget; + firstTarget = &t; + t.name = name; +} + +// todo: this is an ugly implementation, when there is time, fix this to iterator and findif +Target *TargetRegistry::lookupTarget(const std::string &targetName) +{ + Target* cur = firstTarget; + while (cur != nullptr) { + if (cur->getName() == targetName) { + return cur; + } + cur = cur->next; + } + CHECK_FATAL_FALSE("I did not find the target! maybe you did not build the target?"); +} + + +} /* namespace maplebe */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/target_select.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/target_select.cpp new file mode 100644 index 0000000000000000000000000000000000000000..db2e3f75670400f55e269215f24f26423f9ab3c3 --- /dev/null +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/target_select.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "target_select.h" +#include "becommon.h" + +namespace maplebe { +using namespace maple; + +} /* namespace maplebe */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/asm_assembler.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/asm_assembler.cpp index 2153f21b884cf36d0cbe5a094660851808945b85..4fbf3dc0ffe93ff7b55b2fce190b5f960c8addc7 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/asm_assembler.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/asm_assembler.cpp @@ -21,8 +21,7 @@ namespace assembler { void AsmAssembler::InitialFileInfo(const std::string &inputFileName) { - std::string curDirName = get_current_dir_name(); - assert(curDirName != "" && "InitialFileInfo: curDirName is nullptr"); + std::string curDirName = "."; std::string path(curDirName); std::string cgFile(path.append("/mplcg")); EmitComment(cgFile); diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_args.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_args.cpp index feecd95167db534389512a09d0ad73e958e3eb4a..2adc142f75257448a31f2322be1af385afc79e5c 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_args.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_args.cpp @@ -72,11 +72,12 @@ void X64MoveRegArgs::CollectRegisterArgs(std::map &argsList, std } } -ArgInfo X64MoveRegArgs::GetArgInfo(std::map &argsList, uint32 argIndex, std::vector &numFpRegs, - std::vector &fpSize) const +X64ArgInfo X64MoveRegArgs::GetArgInfo(std::map &argsList, + uint32 argIndex, std::vector &numFpRegs, + std::vector &fpSize) const { X64CGFunc *x64CGFunc = static_cast(cgFunc); - ArgInfo argInfo; + X64ArgInfo argInfo; argInfo.reg = argsList[argIndex]; argInfo.mirTy = x64CGFunc->GetFunction().GetNthParamType(argIndex); argInfo.symSize = x64CGFunc->GetBecommon().GetTypeSize(argInfo.mirTy->GetTypeIndex()); @@ -123,7 +124,7 @@ ArgInfo X64MoveRegArgs::GetArgInfo(std::map &argsList, uint32 ar return argInfo; } -void X64MoveRegArgs::GenerateMovInsn(ArgInfo &argInfo, X64reg reg2) +void X64MoveRegArgs::GenerateMovInsn(X64ArgInfo &argInfo, X64reg reg2) { /* reg2 is required when the struct size is between 8-16 bytes */ X64CGFunc *x64CGFunc = static_cast(cgFunc); @@ -176,7 +177,7 @@ void X64MoveRegArgs::MoveRegisterArgs() for (auto indexItem = moveParaIndex.begin(); indexItem != moveParaIndex.end(); ++indexItem) { uint32 index = *indexItem; - ArgInfo argInfo = GetArgInfo(movePara, index, numFpRegs, fpSize); + X64ArgInfo argInfo = GetArgInfo(movePara, index, numFpRegs, fpSize); GenerateMovInsn(argInfo, pairReg[index]); } diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_cgfunc.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_cgfunc.cpp index 45f5c9d8bc4b87d6ab1a16cd0b766ffd3d029fd3..6bf42ec9f4b9ed8011fc51ed2913e68f8e87c9a7 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_cgfunc.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_cgfunc.cpp @@ -879,7 +879,7 @@ int32 X64CGFunc::GetBaseOffset(const SymbolAlloc &symbolAlloc) * Spill | * ArgsStk -- */ - constexpr const int32 sizeofFplr = 2 * kIntregBytelen; + constexpr const int32 sizeofFplr = 2 * kX64IntregBytelen; // baseOffset is the offset of this symbol based on the rbp position. int32 baseOffset = symAlloc->GetOffset(); MemSegmentKind sgKind = symAlloc->GetMemSegment()->GetMemSegmentKind(); diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_emitter.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_emitter.cpp index 006dd1499a47f52d10a97b438246f4851bc7708c..d8e6a2b17f178b962300eaa676e871a0b9b5543a 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_emitter.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_emitter.cpp @@ -2196,14 +2196,6 @@ void X64Emitter::Run(CGFunc &cgFunc) assmbler.ClearLocalSymMap(); } -bool CgEmission::PhaseRun(CGFunc &f) -{ - Emitter *emitter = f.GetCG()->GetEmitter(); - CHECK_NULL_FATAL(emitter); - static_cast(emitter)->Run(f); - return false; -} - void X64Emitter::EmitDwFormAddr(const DBGDie &die, const DBGDieAttr &attr, DwAt attrName, DwTag tagName, DebugInfo &di) { MapleVector attrvec = die.GetAttrVec(); @@ -2552,5 +2544,4 @@ void X64Emitter::EmitDebugInfo(CG &cg) EmitDIDebugStrSection(); } -MAPLE_TRANSFORM_PHASE_REGISTER(CgEmission, cgemit) } /* namespace maplebe */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_local_opt.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_local_opt.cpp index dff836a7fb1a9f27b3f63655eb302aa36accae63..a52a510477d1e48bd661389843ea72a5e1512e6e 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_local_opt.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_local_opt.cpp @@ -22,11 +22,11 @@ namespace maplebe { void X64LocalOpt::DoLocalCopyProp() { LocalOptimizeManager optManager(*cgFunc, *GetRDInfo()); - optManager.Optimize(); + optManager.Optimize(); optManager.Optimize(); } -bool CopyRegProp::CheckCondition(Insn &insn) +bool LocalCopyRegProp::CheckCondition(Insn &insn) { MOperator mOp = insn.GetMachineOpcode(); if (mOp != MOP_movb_r_r && mOp != MOP_movw_r_r && mOp != MOP_movl_r_r && mOp != MOP_movq_r_r) { @@ -46,7 +46,7 @@ bool CopyRegProp::CheckCondition(Insn &insn) return true; } -void CopyRegProp::Optimize(BB &bb, Insn &insn) +void LocalCopyRegProp::Optimize(BB &bb, Insn &insn) { InsnSet useInsnSet; Insn *nextInsn = insn.GetNextMachineInsn(); @@ -71,7 +71,7 @@ void CopyRegProp::Optimize(BB &bb, Insn &insn) return; } -bool CopyRegProp::propagateOperand(Insn &insn, RegOperand &oldOpnd, RegOperand &replaceOpnd) +bool LocalCopyRegProp::propagateOperand(Insn &insn, RegOperand &oldOpnd, RegOperand &replaceOpnd) { bool propagateSuccess = false; uint32 opndNum = insn.GetOperandSize(); diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_peep.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_peep.cpp index aa91e62bc3829e0b9895e47a8fc679661acb42d6..505ad3550843e2a2d8cbf0e937a193cb0e936b17 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_peep.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_peep.cpp @@ -41,7 +41,7 @@ bool X64CGPeepHole::DoSSAOptimize(BB &bb, Insn &insn) return false; } -bool RemoveMovingtoSameRegPattern::CheckCondition(Insn &insn) +bool X64RemoveMovingtoSameRegPattern::CheckCondition(Insn &insn) { DEBUG_ASSERT(insn.GetOperand(kInsnFirstOpnd).IsRegister(), "expects registers"); DEBUG_ASSERT(insn.GetOperand(kInsnSecondOpnd).IsRegister(), "expects registers"); @@ -54,7 +54,7 @@ bool RemoveMovingtoSameRegPattern::CheckCondition(Insn &insn) return false; } -void RemoveMovingtoSameRegPattern::Run(BB &bb, Insn &insn) +void X64RemoveMovingtoSameRegPattern::Run(BB &bb, Insn &insn) { /* remove mov x0,x0 when it cast i32 to i64 */ if (CheckCondition(insn)) { @@ -71,7 +71,7 @@ void X64CGPeepHole::DoNormalOptimize(BB &bb, Insn &insn) case MOP_movw_r_r: case MOP_movl_r_r: case MOP_movq_r_r: { - manager->NormalPatternOpt(true); + manager->NormalPatternOpt(true); break; } default: diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_proepilog.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_proepilog.cpp index fe675fb48025e3dfa166bdfa976277ab0162d9ee..9da7b326335a54f0f036c4eff4bccb76c72c363d 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_proepilog.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_proepilog.cpp @@ -50,7 +50,7 @@ void X64GenProEpilog::GenerateCalleeSavedRegs(bool isPush) std::vector> calleeRegAndOffsetVec; for (const auto ® : calleeSavedRegs) { RegType regType = IsGPRegister(reg) ? kRegTyInt : kRegTyFloat; - uint32 regByteSize = IsGPRegister(reg) ? kIntregBytelen : kFpregBytelen; + uint32 regByteSize = IsGPRegister(reg) ? kX64IntregBytelen : kX64FpregBytelen; uint32 regSize = regByteSize * kBitsPerByte; DEBUG_ASSERT((regSize == k32BitSize || regSize == k64BitSize), "only supported 32/64-bits"); RegOperand &calleeReg = cgFunc.GetOpndBuilder()->CreatePReg(reg, regSize, regType); diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_targetinfo.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_targetinfo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4b947f7e55eed69d18bab66b7fdd59508cd00ed7 --- /dev/null +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_targetinfo.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "x64_targetinfo.h" +#include "target_registry.h" +#include "x64_cg.h" +#include "x64_emitter.h" +#include "x64_targetmachine.h" +#include +namespace maplebe { + +Target &getTheX64Target() +{ + static Target TheX64Target; + return TheX64Target; +} + +extern "C" void MAPLEInitializeX64TargetInfo(MemPool *m) +{ + RegisterTarget X(getTheX64Target(), "x86"); + RegisterCGFUnc Y(getTheX64Target()); + RegisterDecoupledEmitter A(getTheX64Target(), m); + RegisterTargetMachine B(getTheX64Target(), m); +} + +} + diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/litecg/litecg.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/litecg/litecg.cpp index d2869fa65b163dfb8cd0e7f201502e705ca6c2d0..22f079dac333d3d8d0a99832366a8ad6bc49a816 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/litecg/litecg.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/litecg/litecg.cpp @@ -38,9 +38,7 @@ LiteCG::LiteCG(Module &mirModule) : module(mirModule) cgOptions->EnableLiteCG(); cgOptions->SetEmitFileType("obj"); cgOptions->SetQuiet(true); -#if TARGAARCH64 - Triple::GetTriple().Init(); -#endif + Triple::GetTriple().Init(module.IsAArch64()); // module information prepare std::string moduleName = module.GetFileName(); GStrIdx fileNameStrIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(moduleName); diff --git a/ecmascript/compiler/codegen/maple/maple_driver/include/triple.h b/ecmascript/compiler/codegen/maple/maple_driver/include/triple.h index 7bac8bd907752fbf92b725c25470cb4e0d805106..1bffb8ca470640882640b995b627d12045ff3229 100644 --- a/ecmascript/compiler/codegen/maple/maple_driver/include/triple.h +++ b/ecmascript/compiler/codegen/maple/maple_driver/include/triple.h @@ -28,7 +28,7 @@ namespace maple { class Triple { public: /* Currently, only aarch64 is supported */ - enum ArchType { UnknownArch, aarch64, aarch64_be, X64, LastArchType }; + enum ArchType { UnknownArch, aarch64, aarch64_be, x64, LastArchType }; /* Currently, only ILP32 and LP64 are supported */ enum EnvironmentType { UnknownEnvironment, GNU, GNUILP32, LastEnvironmentType }; @@ -49,7 +49,7 @@ public: bool IsAarch64BeOrLe() const { - return (GetArch() == ArchType::aarch64_be || GetArch() == ArchType::aarch64); + return (GetArch() == ArchType::aarch64_be) || (GetArch() == ArchType::aarch64); } std::string Str() const; @@ -65,7 +65,7 @@ public: Triple &operator=(const Triple &) = delete; void Init(const std::string &target); - void Init(); + void Init(bool isAArch64); private: std::string data; diff --git a/ecmascript/compiler/codegen/maple/maple_driver/src/triple.cpp b/ecmascript/compiler/codegen/maple/maple_driver/src/triple.cpp index 4bab33fe6f58e172ccbf97a848964865098400a6..dd0268bfe731c48fd8dd0df133f65b76752f1ef2 100644 --- a/ecmascript/compiler/codegen/maple/maple_driver/src/triple.cpp +++ b/ecmascript/compiler/codegen/maple/maple_driver/src/triple.cpp @@ -42,14 +42,17 @@ Triple::EnvironmentType Triple::ParseEnvironment(std::string_view archStr) return Triple::UnknownEnvironment; } -void Triple::Init() +void Triple::Init(bool isAArch64) { /* Currently Triple is used only to configure aarch64: be/le, ILP32/LP64 * Other architectures (TARGX86_64, TARGX86, TARGARM32, TARGVM) are configured with compiler build config */ -#if TARGAARCH64 - arch = Triple::ArchType::aarch64; - environment = Triple::EnvironmentType::GNU; -#endif + if (isAArch64) { + arch = Triple::ArchType::aarch64; + environment = Triple::EnvironmentType::GNU; + } else { + arch = Triple::ArchType::x64; + environment = Triple::EnvironmentType::GNU; + } } void Triple::Init(const std::string &target) @@ -59,7 +62,7 @@ void Triple::Init(const std::string &target) /* Currently Triple is used only to configure aarch64: be/le, ILP32/LP64. * Other architectures (TARGX86_64, TARGX86, TARGARM32, TARGVM) are configured with compiler build config */ #if TARGAARCH64 - Init(); + Init(true); std::vector components; maple::StringUtils::SplitSV(data, components, '-'); diff --git a/ecmascript/compiler/codegen/maple/maple_ir/include/mir_module.h b/ecmascript/compiler/codegen/maple/maple_ir/include/mir_module.h index efb80cb3378c2731f44a16093e53f5ceea6764d7..5fc258f5157201e5a4088a32d5212f750b232350 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/include/mir_module.h +++ b/ecmascript/compiler/codegen/maple/maple_ir/include/mir_module.h @@ -855,6 +855,16 @@ public: return lastModulePC; } + void SetIsAArch64(bool isAArch) + { + isAArch64 = isAArch; + } + + bool IsAArch64() const + { + return isAArch64; + } + bool HasNotWarned(uint32 postion, uint32 stmtOriginalID); private: @@ -954,6 +964,7 @@ private: std::map> funcImportantExpr; uint32 lastModulePC = 0; uint32 curModulePC = 0; + bool isAArch64 = false; }; #endif // MIR_FEATURE_FULL } // namespace maple diff --git a/ecmascript/compiler/codegen/maple/maple_ir/include/mir_symbol.h b/ecmascript/compiler/codegen/maple/maple_ir/include/mir_symbol.h index 92b7cbe334b42d78081d92facc7786036da3166a..d1fe45854e3d03a7e6055779603f066d18a551d8 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/include/mir_symbol.h +++ b/ecmascript/compiler/codegen/maple/maple_ir/include/mir_symbol.h @@ -582,8 +582,7 @@ public: if (GetType()->GetKind() == kTypeStruct || GetType()->GetKind() == kTypeClass || GetType()->GetKind() == kTypeArray || GetType()->GetKind() == kTypeUnion) { // when x64 does not driver, there is no triple init, this is a temporary plan - if (Triple::GetTriple().GetArch() == Triple::ArchType::X64 || - Triple::GetTriple().GetArch() == Triple::ArchType::UnknownArch) { + if (Triple::GetTriple().GetArch() == Triple::ArchType::x64) { return align; } uint8 alignMin = 0; diff --git a/ecmascript/compiler/codegen/maple/maple_ir/src/mir_type.cpp b/ecmascript/compiler/codegen/maple/maple_ir/src/mir_type.cpp index 277d6cd72c252b706d75ed082eeb86b24abce40e..8ffaac1da58c5efb2fa078be740c056093377c1c 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/src/mir_type.cpp +++ b/ecmascript/compiler/codegen/maple/maple_ir/src/mir_type.cpp @@ -206,13 +206,15 @@ uint8 GetPointerSize() { #if TARGX86 || TARGARM32 || TARGVM return k4ByteSize; -#elif TARGX86_64 - return k8ByteSize; -#elif TARGAARCH64 - DEBUG_ASSERT(Triple::GetTriple().GetEnvironment() != Triple::UnknownEnvironment, - "Triple must be initialized before using"); - uint8 size = (Triple::GetTriple().GetEnvironment() == Triple::GNUILP32) ? k4ByteSize : k8ByteSize; - return size; +#elif TARGX86_64 || TARGAARCH64 + if (Triple::GetTriple().GetArch() == Triple::ArchType::x64) { + return k8ByteSize; + } else if (Triple::GetTriple().GetArch() == Triple::ArchType::aarch64) { + uint8 size = (Triple::GetTriple().GetEnvironment() == Triple::GNUILP32) ? k4ByteSize : k8ByteSize; + return size; + } else { + CHECK_FATAL(false, "Unsupported target"); + } #else #error "Unsupported target" #endif @@ -222,13 +224,15 @@ uint8 GetP2Size() { #if TARGX86 || TARGARM32 || TARGVM return k2ByteSize; -#elif TARGX86_64 - return k3ByteSize; -#elif TARGAARCH64 - DEBUG_ASSERT(Triple::GetTriple().GetEnvironment() != Triple::UnknownEnvironment, - "Triple must be initialized before using"); - uint8 size = (Triple::GetTriple().GetEnvironment() == Triple::GNUILP32) ? k2ByteSize : k3ByteSize; - return size; +#elif TARGX86_64 || TARGAARCH64 + if (Triple::GetTriple().GetArch() == Triple::ArchType::x64) { + return k3ByteSize; + } else if (Triple::GetTriple().GetArch() == Triple::ArchType::aarch64) { + uint8 size = (Triple::GetTriple().GetEnvironment() == Triple::GNUILP32) ? k2ByteSize : k3ByteSize; + return size; + } else { + CHECK_FATAL(false, "Unsupported target"); + } #else #error "Unsupported target" #endif @@ -238,13 +242,15 @@ PrimType GetLoweredPtrType() { #if TARGX86 || TARGARM32 || TARGVM return PTY_a32; -#elif TARGX86_64 - return PTY_a64; -#elif TARGAARCH64 - DEBUG_ASSERT(Triple::GetTriple().GetEnvironment() != Triple::UnknownEnvironment, - "Triple must be initialized before using"); - auto pty = (Triple::GetTriple().GetEnvironment() == Triple::GNUILP32) ? PTY_a32 : PTY_a64; - return pty; +#elif TARGX86_64 || TARGAARCH64 + if (Triple::GetTriple().GetArch() == Triple::ArchType::x64) { + return PTY_a64; + } else if (Triple::GetTriple().GetArch() == Triple::ArchType::aarch64) { + auto pty = (Triple::GetTriple().GetEnvironment() == Triple::GNUILP32) ? PTY_a32 : PTY_a64; + return pty; + } else { + CHECK_FATAL(false, "Unsupported target"); + } #else #error "Unsupported target" #endif diff --git a/ecmascript/compiler/file_generators.cpp b/ecmascript/compiler/file_generators.cpp index fb94bb07631a95e6e702144dec1f1bebdad9e9e0..db57885dbf0d064539d73bdfaf96883780bdf968 100644 --- a/ecmascript/compiler/file_generators.cpp +++ b/ecmascript/compiler/file_generators.cpp @@ -507,6 +507,8 @@ void AOTFileGenerator::CompileLatestModuleThenDestroy() LMIRModule *lmirModule = static_cast(latestModule->GetModule()); lastModulePC = AlignUp(lastModulePC, AOTFileInfo::PAGE_ALIGN); lmirModule->GetModule()->SetLastModulePC(lastModulePC); + // pass triple to litecg + lmirModule->GetModule()->SetIsAArch64(isAArch64()); } #endif uint32_t latestModuleIdx = GetModuleVecSize() - 1; @@ -645,6 +647,11 @@ void AOTFileGenerator::JitCreateLitecgModule() #endif } +bool AOTFileGenerator::isAArch64() const +{ + return cfg_.IsAArch64(); +} + void AOTFileGenerator::SaveSnapshotFile() { TimeScope timescope("LLVMCodeGenPass-AI", const_cast(log_)); diff --git a/ecmascript/compiler/file_generators.h b/ecmascript/compiler/file_generators.h index 57425cd637a6d46b51deb3262ba48e0e10703d07..d48859dcab7a30dafb6ce986a23ef638e75c2570 100644 --- a/ecmascript/compiler/file_generators.h +++ b/ecmascript/compiler/file_generators.h @@ -212,6 +212,7 @@ public: void GetMemoryCodeInfos(MachineCodeDesc *machineCodeDesc); void JitCreateLitecgModule(); + bool isAArch64() const; private: // collect aot component info